Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions core/packages/gax/src/apitypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export interface GRPCCallResult {
// when it might be useful for users.
export interface RequestType {
[index: string]:
| string
| number
| RequestType
| Array<string | number | RequestType>;
string | number | RequestType | Array<string | number | RequestType>;
}
export type ResponseType = {} | null;
export type NextPageRequestType = {
Expand Down Expand Up @@ -85,10 +82,7 @@ export type BiDiStreamingCall = (
options: {},
) => Duplex & GRPCCallResult;
export type GRPCCall =
| UnaryCall
| ServerStreamingCall
| ClientStreamingCall
| BiDiStreamingCall;
UnaryCall | ServerStreamingCall | ClientStreamingCall | BiDiStreamingCall;

// GAX wraps gRPC calls so that the wrapper functions return either a
// cancellable promise, or a stream (also cancellable!)
Expand Down
7 changes: 4 additions & 3 deletions core/packages/gax/src/fallbackServiceStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import type {Response as NodeFetchResponse} from 'node-fetch' with {'resolution-mode': 'import'};
import type {Response as NodeFetchResponse} from 'node-fetch' with {
'resolution-mode': 'import',
};

import {AuthClient, GoogleAuth, gaxios} from 'google-auth-library';
import * as serializer from 'proto3-json-serializer';
Expand All @@ -35,8 +37,7 @@
// - https://github.com/node-fetch/node-fetch#custom-agent
// - https://github.com/googleapis/gax-nodejs/pull/1534
let agentOption:
| ((parsedUrl: {protocol: string}) => HttpAgent | HttpsAgent)
| null = null;
((parsedUrl: {protocol: string}) => HttpAgent | HttpsAgent) | null = null;
if (isNodeJS()) {
const http = require('http');
const https = require('https');
Expand Down Expand Up @@ -418,7 +419,7 @@
// state, as the handlers below do.
if (err && (timedOut || !cancelRequested)) {
if (callback) {
callback(err);

Check warning on line 422 in core/packages/gax/src/fallbackServiceStub.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
}
streamArrayParser.emit('error', err);
}
Expand All @@ -430,12 +431,12 @@
Promise.resolve(response.ok),
response.arrayBuffer(),
])
.then(([ok, buffer]: [boolean, Buffer | ArrayBuffer]) => {

Check warning on line 434 in core/packages/gax/src/fallbackServiceStub.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid nesting promises
const response = responseDecoder(rpc, ok, buffer);
callback!(null, response);
return;
})
.catch((err: Error) => {

Check warning on line 439 in core/packages/gax/src/fallbackServiceStub.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid nesting promises
// The deadline can expire after the response headers arrive but
// before the body is fully read, which rejects here rather than
// in the outer handler.
Expand All @@ -458,7 +459,7 @@
// state we recorded.
if (timedOut || !cancelRequested) {
if (callback) {
callback(callErr);

Check warning on line 462 in core/packages/gax/src/fallbackServiceStub.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
}
streamArrayParser.emit('error', callErr);
}
Expand Down Expand Up @@ -516,12 +517,12 @@
// nobody is listening to any more.
if (timedOut || !cancelRequested) {
if (callback) {
callback(err);

Check warning on line 520 in core/packages/gax/src/fallbackServiceStub.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
}
streamArrayParser.emit('error', err);
}
} else if (callback) {
callback(err);

Check warning on line 525 in core/packages/gax/src/fallbackServiceStub.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
} else {
throw err;
}
Expand Down
10 changes: 4 additions & 6 deletions core/packages/gax/src/iamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,13 @@ export class IamClient {
*
* The client will no longer be usable and all future behavior is undefined.
*/
close(): Promise<void> {
async close(): Promise<void> {
this.initialize().catch(console.error);
if (!this._terminated) {
return this.iamPolicyStub!.then(stub => {
this._terminated = true;
stub.close();
});
const stub = await this.iamPolicyStub!;
this._terminated = true;
stub.close();
}
return Promise.resolve();
}
}
export interface IamClient {
Expand Down
10 changes: 4 additions & 6 deletions core/packages/gax/src/locationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,13 @@ export class LocationsClient {
* The client will no longer be usable and all future behavior is undefined.
* @returns {Promise} A promise that resolves when the client is closed.
*/
close(): Promise<void> {
async close(): Promise<void> {
this.initialize().catch(console.error);
if (!this._terminated) {
return this.locationsStub!.then(stub => {
this._terminated = true;
stub.close();
});
const stub = await this.locationsStub!;
this._terminated = true;
stub.close();
}
return Promise.resolve();
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/packages/gax/src/longRunningCalls/longrunning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@
},
(err: Error) => {
if (callback) {
callback(err);

Check warning on line 200 in core/packages/gax/src/longRunningCalls/longrunning.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
return;
}
return Promise.reject(err);
throw err;
},
);

Expand Down
13 changes: 8 additions & 5 deletions core/packages/gax/src/paginationCalls/pagedApiCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
SimpleCallbackFunction,
UnaryCall,
RequestType,
APICallback,
} from '../apitypes';
import {APICallback} from '../apitypes';
import {OngoingCall, OngoingCallPromise} from '../call';
import {CallOptions} from '../gax';
import {GoogleError} from '../googleError';
Expand Down Expand Up @@ -164,10 +164,13 @@ export class PagedApiCaller implements APICaller {
const maxResults = settings.maxResults || -1;

const resourceCollector = new ResourceCollector(apiCall, maxResults);
resourceCollector.processAllPages(request).then(
resources => ongoingCall.callback(null, resources),
err => ongoingCall.callback(err),
);
resourceCollector
.processAllPages(request)
.then(resources => {
ongoingCall.callback(null, resources);
return null;
})
.catch(err => ongoingCall.callback(err));
}

fail(ongoingCall: OngoingCallPromise, err: GoogleError): void {
Expand Down
12 changes: 9 additions & 3 deletions core/packages/gax/src/streamingCalls/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@

/* This file describes the gRPC-streaming. */

import {Duplex, DuplexOptions, Readable, Stream, Writable} from 'stream';
import {
Duplex,
DuplexOptions,
Readable,
Stream,
Writable,
PassThrough,
} from 'stream';

import {
APICallback,
CancellableStream,
GRPCCallResult,
RequestType,
SimpleCallbackFunction,
ResponseType,
} from '../apitypes';
import {
RetryOptions,
Expand All @@ -32,8 +40,6 @@ import {
} from '../gax';
import {GoogleError} from '../googleError';
import {Status} from '../status';
import {PassThrough} from 'stream';
import {ResponseType} from '../apitypes';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const duplexify: DuplexifyConstructor = require('duplexify');
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
10 changes: 7 additions & 3 deletions core/packages/gax/src/transcoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ function validateUriPath(propertyName: string, value: string): void {
// valid domain-scoped resource segments (e.g. projects/example.com:project-id).
const segments = value.split('/');
if (segments.some(segment => segment === '.' || segment === '..')) {
throw new Error(`Value for ${propertyName} must not contain segments that are exactly . or ..`);
throw new Error(
`Value for ${propertyName} must not contain segments that are exactly . or ..`,
);
}
}
}
Expand All @@ -164,7 +166,9 @@ export function buildQueryStringComponents(
} else {
resultList.push(
`${prefix}${encodeWithoutSlashes(key)}=${encodeWithoutSlashes(
requestValue === null || requestValue === undefined ? 'null' : requestValue.toString(),
requestValue === null || requestValue === undefined
? 'null'
: requestValue.toString(),
)}`,
);
}
Expand All @@ -187,7 +191,7 @@ export function buildQueryStringComponents(
export function encodeWithSlashes(str: string): string {
return encodeURIComponent(str).replace(
/[!'()*]/g, // Characters preserved by encodeURIComponent
character => '%' + character.charCodeAt(0).toString(16).toUpperCase()
character => '%' + character.charCodeAt(0).toString(16).toUpperCase(),
);
}

Expand Down
Loading
Loading