Skip to content

Commit

Permalink
feat: respect pageSize and pageToken from gaxOptions (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman committed Aug 7, 2020
1 parent 09c03f5 commit 3ca5de3
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 18 deletions.
78 changes: 67 additions & 11 deletions src/instance.ts
Expand Up @@ -16,6 +16,7 @@ import {promisifyAll} from '@google-cloud/promisify';
import {Transform} from 'stream';
import arrify = require('arrify');
import * as is from 'is';
import * as extend from 'extend';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pumpify = require('pumpify');

Expand Down Expand Up @@ -653,21 +654,33 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
optionsOrCallback?: CallOptions | GetAppProfilesCallback,
cb?: GetAppProfilesCallback
): void | Promise<GetAppProfilesResponse> {
const gaxOptions =
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
const gaxOpts =
typeof optionsOrCallback === 'object'
? extend(true, {}, optionsOrCallback)
: {};
const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;

const reqOpts = {
const reqOpts: google.bigtable.admin.v2.IListAppProfilesRequest = {
parent: this.name,
};

if (is.number(gaxOpts.pageSize)) {
reqOpts.pageSize = gaxOpts.pageSize;
}
delete gaxOpts.pageSize;

if (gaxOpts.pageToken) {
reqOpts.pageToken = gaxOpts.pageToken;
}
delete gaxOpts.pageToken;

this.bigtable.request<google.bigtable.admin.v2.IAppProfile[]>(
{
client: 'BigtableInstanceAdminClient',
method: 'listAppProfiles',
reqOpts,
gaxOpts: gaxOptions,
gaxOpts,
},
(err, resp) => {
if (err) {
Expand Down Expand Up @@ -718,10 +731,21 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
* this.end();
* });
*/
getAppProfilesStream(gaxOptions?: CallOptions): NodeJS.ReadableStream {
const reqOpts = {
getAppProfilesStream(gaxOptions: CallOptions = {}): NodeJS.ReadableStream {
const reqOpts: google.bigtable.admin.v2.IListAppProfilesRequest = {
parent: this.name,
};
const gaxOpts = extend(true, {}, gaxOptions);

if (is.number(gaxOpts.pageSize)) {
reqOpts.pageSize = gaxOpts.pageSize;
}
delete gaxOpts.pageSize;

if (gaxOpts.pageToken) {
reqOpts.pageToken = gaxOpts.pageToken;
}
delete gaxOpts.pageToken;

// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
Expand All @@ -739,7 +763,7 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
client: 'BigtableInstanceAdminClient',
method: 'listAppProfilesStream',
reqOpts,
gaxOpts: gaxOptions,
gaxOpts,
}),
new Transform({objectMode: true, transform: transformToAppProfile}),
]);
Expand Down Expand Up @@ -938,19 +962,35 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;

const reqOpts = Object.assign({}, options, {
const gaxOpts = extend(true, {}, options.gaxOptions);
let reqOpts = Object.assign({}, options, {
parent: this.name,
view: Table.VIEWS[options.view || 'unspecified'],
});

// Copy over pageSize and pageToken values from gaxOptions.
// However values set on options take precedence.
if (gaxOpts) {
reqOpts = extend(
{},
{
pageSize: gaxOpts.pageSize,
pageToken: gaxOpts.pageToken,
},
reqOpts
);
delete gaxOpts.pageSize;
delete gaxOpts.pageToken;
}

delete (reqOpts as GetTablesOptions).gaxOptions;

this.bigtable.request<Table[]>(
{
client: 'BigtableTableAdminClient',
method: 'listTables',
reqOpts,
gaxOpts: options.gaxOptions,
gaxOpts,
},
(...args) => {
if (args[1]) {
Expand Down Expand Up @@ -998,14 +1038,30 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
* });
*/
getTablesStream(options: GetTablesOptions = {}): NodeJS.ReadableStream {
const reqOpts = Object.assign({}, options, {
const gaxOpts = extend(true, {}, options.gaxOptions);
let reqOpts = Object.assign({}, options, {
parent: this.name,
view: Table.VIEWS[options.view || 'unspecified'],
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (reqOpts as any).gaxOptions;

// Copy over pageSize and pageToken values from gaxOptions.
// However values set on options take precedence.
if (gaxOpts) {
reqOpts = extend(
{},
{
pageSize: gaxOpts.pageSize,
pageToken: gaxOpts.pageToken,
},
reqOpts
);
delete gaxOpts.pageSize;
delete gaxOpts.pageToken;
}

// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
const transformToTable = (
Expand All @@ -1022,7 +1078,7 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
client: 'BigtableTableAdminClient',
method: 'listTablesStream',
reqOpts,
gaxOpts: options.gaxOptions,
gaxOpts,
}),
new Transform({objectMode: true, transform: transformToTable}),
]);
Expand Down
2 changes: 2 additions & 0 deletions src/table.ts
Expand Up @@ -180,6 +180,8 @@ export interface GetTablesOptions {
* 'full'. Default: 'name'.
*/
view?: 'name' | 'schema' | 'full';
pageSize?: number;
pageToken?: string;
}

export interface GetRowsOptions {
Expand Down

0 comments on commit 3ca5de3

Please sign in to comment.