Skip to content

Commit

Permalink
fix!: remove pageSize/pageToken from call settings (#1263)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen <stephenplusplus@users.noreply.github.com>
Co-authored-by: Xiaozhen Liu <xiaozhenliu@google.com>
  • Loading branch information
3 people committed May 9, 2022
1 parent 88a180f commit fbf43d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
16 changes: 0 additions & 16 deletions src/gax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ export interface CallOptions {
timeout?: number;
retry?: Partial<RetryOptions> | null;
autoPaginate?: boolean;
pageToken?: string;
pageSize?: number;
maxResults?: number;
maxRetries?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -177,7 +175,6 @@ export class CallSettings {
this.retry = settings.retry as RetryOptions;
this.autoPaginate =
'autoPaginate' in settings ? settings.autoPaginate : true;
this.pageToken = settings.pageToken;
this.maxResults = settings.maxResults;
this.otherArgs = settings.otherArgs || {};
this.bundleOptions = settings.bundleOptions;
Expand All @@ -203,8 +200,6 @@ export class CallSettings {
let timeout = this.timeout;
let retry = this.retry;
let autoPaginate = this.autoPaginate;
let pageToken = this.pageToken;
let pageSize = this.pageSize;
let maxResults = this.maxResults;
let otherArgs = this.otherArgs;
let isBundling = this.isBundling;
Expand Down Expand Up @@ -246,15 +241,6 @@ export class CallSettings {
autoPaginate = false;
}

if ('pageToken' in options) {
autoPaginate = false;
pageToken = options.pageToken;
}

if ('pageSize' in options) {
pageSize = options.pageSize;
}

if ('maxResults' in options) {
maxResults = options.maxResults;
}
Expand Down Expand Up @@ -294,8 +280,6 @@ export class CallSettings {
bundleOptions: this.bundleOptions,
longrunning,
autoPaginate,
pageToken,
pageSize,
maxResults,
otherArgs,
isBundling,
Expand Down
11 changes: 1 addition & 10 deletions src/paginationCalls/pagedApiCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ export class PagedApiCaller implements APICaller {
* It's supposed to be a gRPC service stub function wrapped into several layers of wrappers that make it
* accept just two parameters: (request, callback).
* @param request A request object that came from the user.
* @param settings Call settings. We are interested in `maxResults`, autoPaginate`, `pageToken`, and `pageSize`
* (they are all optional).
* @param settings Call settings. We are interested in `maxResults` and `autoPaginate` (they are optional).
* @param ongoingCall An instance of OngoingCall or OngoingCallPromise that can be used for call cancellation,
* and is used to return results to the user.
*/
Expand All @@ -148,14 +147,6 @@ export class PagedApiCaller implements APICaller {
) {
request = Object.assign({}, request);

// If settings object contain pageToken or pageSize, override the corresponding fields in the request object.
if (settings.pageToken) {
request[this.pageDescriptor.requestPageTokenField] = settings.pageToken;
}
if (settings.pageSize) {
request[this.pageDescriptor.requestPageSizeField!] = settings.pageSize;
}

if (!settings.autoPaginate) {
// they don't want auto-pagination this time - okay, just call once
ongoingCall.call(apiCall, request);
Expand Down
11 changes: 5 additions & 6 deletions test/unit/pagedIteration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,17 @@ describe('paged iteration', () => {
});

it('ignores autoPaginate options, but respects others', done => {
// Specifies autoPaginate: false, which will be ignored, and pageToken:
// pageSize which will be used so that the stream will start from the
// specified token.
const options = {pageToken: pageSize, autoPaginate: false};
// Specifies autoPaginate: false, which will be ignored, and maxResults:
// pageSize which will be used.
const options = {maxResults: pageSize, autoPaginate: false};
streamChecker(
// @ts-ignore incomplete options
descriptor.createStream(apiCall, {}, options),
() => {
assert.strictEqual(spy.callCount, pagesToStream);
assert.strictEqual(spy.callCount, 1);
},
done,
pageSize
0
);
});

Expand Down

0 comments on commit fbf43d2

Please sign in to comment.