From 8dba01a63f0ae71b2e42696d68363dbec2068cb0 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 11 Nov 2019 11:05:36 -0800 Subject: [PATCH 1/5] feat: add close() API --- .../src/$version/$service_client.ts.njk | 29 ++++++++++++++++--- .../key_management_service_client.ts.baseline | 28 +++++++++++++++--- .../src/v1beta1/echo_client.ts.baseline | 28 +++++++++++++++--- .../src/v1/text_to_speech_client.ts.baseline | 28 +++++++++++++++--- .../translation_service_client.ts.baseline | 29 ++++++++++++++++--- typescript/test/util.ts | 21 ++++++++++++++ 6 files changed, 143 insertions(+), 20 deletions(-) diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 60ca43dc4..c172b16b5 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -76,9 +76,11 @@ export interface PaginationResponse< */ export class {{ service.name }}Client { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _{{ service.name.toCamelCase() }}Stub: ClientStub; private _innerApiCalls: {[name: string]: Function}; {%- if (service.pathTemplates.length > 0) %} private _pathTemplates: {[name: string]: gax.PathTemplate}; + private _terminated: false; {%- endif %} auth: gax.GoogleAuth; @@ -255,7 +257,7 @@ export class {{ service.name }}Client { // Put together the "service stub" for // {{api.naming.protoPackage}}.{{ service.name }}. - const {{ service.name.toCamelCase() }}Stub = gaxGrpc.createStub( + this._{{ service.name.toCamelCase() }}Stub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('{{api.naming.protoPackage}}.{{ service.name }}') : // tslint:disable-next-line no-any @@ -274,7 +276,7 @@ export class {{ service.name }}Client { ]; for (const methodName of {{ service.name.toCamelCase() }}StubMethods) { - const innerCallPromise = {{ service.name.toCamelCase() }}Stub.then( + const innerCallPromise = this._{{ service.name.toCamelCase() }}Stub.then( (stub: {[method: string]: Function}) => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, @@ -282,13 +284,20 @@ export class {{ service.name }}Client { throw err; }); - this._innerApiCalls[methodName] = gaxModule.createApiCall( + const apiCall = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || + this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] ); + + this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + if (!this._terminated) { + return Promise.reject('The client has already been closed.'); + } + return apiCall(arguments, callOptions, callback); + }; } } @@ -609,4 +618,16 @@ export class {{ service.name }}Client { {%- endfor %} {%- endfor %} {%- endif %} + + /** + * Terminate the GRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + */ + close(): void { + if (!this._terminated) { + this._terminated = true; + this._{{ service.name.toCamelCase() }}Stub.then(stub => stub.close()); + } + } } diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 74737a1c5..791642d56 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -78,6 +78,7 @@ export interface PaginationResponse< */ export class KeyManagementServiceClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _keyManagementServiceStub: ClientStub; private _innerApiCalls: {[name: string]: Function}; auth: gax.GoogleAuth; @@ -195,7 +196,7 @@ export class KeyManagementServiceClient { // Put together the "service stub" for // google.cloud.kms.v1.KeyManagementService. - const keyManagementServiceStub = gaxGrpc.createStub( + this._keyManagementServiceStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.cloud.kms.v1.KeyManagementService') : // tslint:disable-next-line no-any @@ -208,7 +209,7 @@ export class KeyManagementServiceClient { ['listKeyRings', 'listCryptoKeys', 'listCryptoKeyVersions', 'listImportJobs', 'getKeyRing', 'getCryptoKey', 'getCryptoKeyVersion', 'getPublicKey', 'getImportJob', 'createKeyRing', 'createCryptoKey', 'createCryptoKeyVersion', 'importCryptoKeyVersion', 'createImportJob', 'updateCryptoKey', 'updateCryptoKeyVersion', 'encrypt', 'decrypt', 'asymmetricSign', 'asymmetricDecrypt', 'updateCryptoKeyPrimaryVersion', 'destroyCryptoKeyVersion', 'restoreCryptoKeyVersion']; for (const methodName of keyManagementServiceStubMethods) { - const innerCallPromise = keyManagementServiceStub.then( + const innerCallPromise = this._keyManagementServiceStub.then( (stub: {[method: string]: Function}) => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, @@ -216,13 +217,20 @@ export class KeyManagementServiceClient { throw err; }); - this._innerApiCalls[methodName] = gaxModule.createApiCall( + const apiCall = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || + this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] ); + + this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + if (!this._terminated) { + return Promise.reject('The client has already been closed.'); + } + return apiCall(arguments, callOptions, callback); + }; } } @@ -2088,4 +2096,16 @@ export class KeyManagementServiceClient { callSettings ); } + + /** + * Terminate the GRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + */ + close(): void { + if (!this._terminated) { + this._terminated = true; + this._keyManagementServiceStub.then(stub => stub.close()); + } + } } diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index 54c58e198..889bc0d41 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -74,6 +74,7 @@ export interface PaginationResponse< */ export class EchoClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _echoStub: ClientStub; private _innerApiCalls: {[name: string]: Function}; auth: gax.GoogleAuth; @@ -216,7 +217,7 @@ export class EchoClient { // Put together the "service stub" for // google.showcase.v1beta1.Echo. - const echoStub = gaxGrpc.createStub( + this._echoStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.showcase.v1beta1.Echo') : // tslint:disable-next-line no-any @@ -229,7 +230,7 @@ export class EchoClient { ['echo', 'expand', 'collect', 'chat', 'pagedExpand', 'wait']; for (const methodName of echoStubMethods) { - const innerCallPromise = echoStub.then( + const innerCallPromise = this._echoStub.then( (stub: {[method: string]: Function}) => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, @@ -237,13 +238,20 @@ export class EchoClient { throw err; }); - this._innerApiCalls[methodName] = gaxModule.createApiCall( + const apiCall = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || + this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] ); + + this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + if (!this._terminated) { + return Promise.reject('The client has already been closed.'); + } + return apiCall(arguments, callOptions, callback); + }; } } @@ -603,4 +611,16 @@ export class EchoClient { callSettings ); } + + /** + * Terminate the GRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + */ + close(): void { + if (!this._terminated) { + this._terminated = true; + this._echoStub.then(stub => stub.close()); + } + } } diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index 82cd76ab4..c5b5f6bfa 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -54,6 +54,7 @@ export interface Callback< */ export class TextToSpeechClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _textToSpeechStub: ClientStub; private _innerApiCalls: {[name: string]: Function}; auth: gax.GoogleAuth; @@ -157,7 +158,7 @@ export class TextToSpeechClient { // Put together the "service stub" for // google.cloud.texttospeech.v1.TextToSpeech. - const textToSpeechStub = gaxGrpc.createStub( + this._textToSpeechStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.cloud.texttospeech.v1.TextToSpeech') : // tslint:disable-next-line no-any @@ -170,7 +171,7 @@ export class TextToSpeechClient { ['listVoices', 'synthesizeSpeech']; for (const methodName of textToSpeechStubMethods) { - const innerCallPromise = textToSpeechStub.then( + const innerCallPromise = this._textToSpeechStub.then( (stub: {[method: string]: Function}) => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, @@ -178,13 +179,20 @@ export class TextToSpeechClient { throw err; }); - this._innerApiCalls[methodName] = gaxModule.createApiCall( + const apiCall = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || + this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] ); + + this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + if (!this._terminated) { + return Promise.reject('The client has already been closed.'); + } + return apiCall(arguments, callOptions, callback); + }; } } @@ -356,4 +364,16 @@ export class TextToSpeechClient { return this._innerApiCalls.synthesizeSpeech(request, options, callback); } + + /** + * Terminate the GRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + */ + close(): void { + if (!this._terminated) { + this._terminated = true; + this._textToSpeechStub.then(stub => stub.close()); + } + } } diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index ca2e9409b..fd6eb56c1 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -71,8 +71,10 @@ export interface PaginationResponse< */ export class TranslationServiceClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _translationServiceStub: ClientStub; private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; + private _terminated: false; auth: gax.GoogleAuth; /** @@ -234,7 +236,7 @@ export class TranslationServiceClient { // Put together the "service stub" for // google.cloud.translation.v3beta1.TranslationService. - const translationServiceStub = gaxGrpc.createStub( + this._translationServiceStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.cloud.translation.v3beta1.TranslationService') : // tslint:disable-next-line no-any @@ -247,7 +249,7 @@ export class TranslationServiceClient { ['translateText', 'detectLanguage', 'getSupportedLanguages', 'batchTranslateText', 'createGlossary', 'listGlossaries', 'getGlossary', 'deleteGlossary']; for (const methodName of translationServiceStubMethods) { - const innerCallPromise = translationServiceStub.then( + const innerCallPromise = this._translationServiceStub.then( (stub: {[method: string]: Function}) => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, @@ -255,13 +257,20 @@ export class TranslationServiceClient { throw err; }); - this._innerApiCalls[methodName] = gaxModule.createApiCall( + const apiCall = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || + this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] ); + + this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + if (!this._terminated) { + return Promise.reject('The client has already been closed.'); + } + return apiCall(arguments, callOptions, callback); + }; } } @@ -1078,4 +1087,16 @@ export class TranslationServiceClient { matchGlossaryFromGlossaryName(glossaryName: string){ return this._pathTemplates.glossaryPathTemplate.match(glossaryName).glossary; } + + /** + * Terminate the GRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + */ + close(): void { + if (!this._terminated) { + this._terminated = true; + this._translationServiceStub.then(stub => stub.close()); + } + } } diff --git a/typescript/test/util.ts b/typescript/test/util.ts index c111c3b0a..a1e8ec77c 100644 --- a/typescript/test/util.ts +++ b/typescript/test/util.ts @@ -82,6 +82,27 @@ function checkIdenticalFile( const readOutput = fs.readFileSync(outputFullPath).toString(); const baselineOutput = fs.readFileSync(baselineFullPath).toString(); if (readOutput === baselineOutput) return IDENTICAL_FILE; + + const readOutputLines = readOutput.split('\n'); + const baselineOutputLines = baselineOutput.split('\n'); + + if (readOutputLines.length !== baselineOutputLines.length) { + console.warn( + `Line count for ${outputFullPath} was ${readOutputLines.length}, ` + + `but expected ${baselineOutputLines.length}.` + ); + } else { + for (let i = 0; i < readOutputLines.length; ++i) { + if (readOutputLines[i] !== baselineOutputLines[i]) { + console.warn( + `Line ${i + 1} of ${outputFullPath} was \n\t"${ + readOutputLines[i] + }"\nbut expected\n\t"${baselineOutputLines[i]}"` + ); + } + } + } + return FILE_WITH_DIFF_CONTENT; } From e2a042b5af650e4c6814418fd76b19469cbba11e Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 11 Nov 2019 11:38:55 -0800 Subject: [PATCH 2/5] Return a Promise --- .../typescript_gapic/src/$version/$service_client.ts.njk | 9 ++++++--- .../src/v1/key_management_service_client.ts.baseline | 9 ++++++--- .../showcase/src/v1beta1/echo_client.ts.baseline | 9 ++++++--- .../src/v1/text_to_speech_client.ts.baseline | 9 ++++++--- .../src/v3beta1/translation_service_client.ts.baseline | 9 ++++++--- typescript/test/util.ts | 2 +- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index c172b16b5..fb6f42e37 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -624,10 +624,13 @@ export class {{ service.name }}Client { * * The client will no longer be usable and all future behavior is undefined. */ - close(): void { + close(): Promise { if (!this._terminated) { - this._terminated = true; - this._{{ service.name.toCamelCase() }}Stub.then(stub => stub.close()); + return this._{{ service.name.toCamelCase() }}Stub.then(stub => { + this._terminated = true; + stub.close(); + }); } + return Promise.resolve(); } } diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 791642d56..27e41f135 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -2102,10 +2102,13 @@ export class KeyManagementServiceClient { * * The client will no longer be usable and all future behavior is undefined. */ - close(): void { + close(): Promise { if (!this._terminated) { - this._terminated = true; - this._keyManagementServiceStub.then(stub => stub.close()); + return this._keyManagementServiceStub.then(stub => { + this._terminated = true; + stub.close(); + }); } + return Promise.resolve(); } } diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index 889bc0d41..0103bdd68 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -617,10 +617,13 @@ export class EchoClient { * * The client will no longer be usable and all future behavior is undefined. */ - close(): void { + close(): Promise { if (!this._terminated) { - this._terminated = true; - this._echoStub.then(stub => stub.close()); + return this._echoStub.then(stub => { + this._terminated = true; + stub.close(); + }); } + return Promise.resolve(); } } diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index c5b5f6bfa..82e717ead 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -370,10 +370,13 @@ export class TextToSpeechClient { * * The client will no longer be usable and all future behavior is undefined. */ - close(): void { + close(): Promise { if (!this._terminated) { - this._terminated = true; - this._textToSpeechStub.then(stub => stub.close()); + return this._textToSpeechStub.then(stub => { + this._terminated = true; + stub.close(); + }); } + return Promise.resolve(); } } diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index fd6eb56c1..ace7fe80d 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -1093,10 +1093,13 @@ export class TranslationServiceClient { * * The client will no longer be usable and all future behavior is undefined. */ - close(): void { + close(): Promise { if (!this._terminated) { - this._terminated = true; - this._translationServiceStub.then(stub => stub.close()); + return this._translationServiceStub.then(stub => { + this._terminated = true; + stub.close(); + }); } + return Promise.resolve(); } } diff --git a/typescript/test/util.ts b/typescript/test/util.ts index a1e8ec77c..b7b85d204 100644 --- a/typescript/test/util.ts +++ b/typescript/test/util.ts @@ -89,7 +89,7 @@ function checkIdenticalFile( if (readOutputLines.length !== baselineOutputLines.length) { console.warn( `Line count for ${outputFullPath} was ${readOutputLines.length}, ` + - `but expected ${baselineOutputLines.length}.` + `but expected ${baselineOutputLines.length}.` ); } else { for (let i = 0; i < readOutputLines.length; ++i) { From cf0b1ffca12b9bd3353e6ef1b7f25e861e69689a Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 12 Nov 2019 09:52:33 -0800 Subject: [PATCH 3/5] Make generated code compile --- .../src/$version/$service_client.ts.njk | 18 +++++++++++------- .../key_management_service_client.ts.baseline | 15 ++++++++++----- .../src/v1beta1/echo_client.ts.baseline | 15 ++++++++++----- .../src/v1/text_to_speech_client.ts.baseline | 15 ++++++++++----- .../translation_service_client.ts.baseline | 16 ++++++++++------ 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 80069eba2..d36fa5ac8 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -21,9 +21,9 @@ limitations under the License. import * as gax from 'google-gax'; {% if service.longRunning.length > 0 -%} -import {Callback, LROperation, Descriptors, ClientOptions} from 'google-gax'; +import {APICallback, Callback, CallOptions, LROperation, Descriptors, ClientOptions} from 'google-gax'; {%- else -%} -import {Callback, Descriptors, ClientOptions} from 'google-gax'; +import {APICallback, Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax'; {%- endif %} import * as path from 'path'; {% if (service.paging.length > 0) %} @@ -54,12 +54,12 @@ export interface PaginationResponse< */ export class {{ service.name }}Client { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _{{ service.name.toCamelCase() }}Stub: ClientStub; + private _{{ service.name.toCamelCase() }}Stub: Promise<{[name: string]: Function}>; private _innerApiCalls: {[name: string]: Function}; {%- if (service.pathTemplates.length > 0) %} private _pathTemplates: {[name: string]: gax.PathTemplate}; - private _terminated: false; {%- endif %} + private _terminated = false; auth: gax.GoogleAuth; /** @@ -255,7 +255,7 @@ export class {{ service.name }}Client { for (const methodName of {{ service.name.toCamelCase() }}StubMethods) { const innerCallPromise = this._{{ service.name.toCamelCase() }}Stub.then( - (stub: {[method: string]: Function}) => (...args: Array<{}>) => { + stub => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -270,11 +270,15 @@ export class {{ service.name }}Client { this._descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + this._innerApiCalls[methodName] = ( + argument: {}, + callOptions?: CallOptions, + callback?: APICallback + ) => { if (!this._terminated) { return Promise.reject('The client has already been closed.'); } - return apiCall(arguments, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 2c5eb18ab..6a3662f73 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -17,7 +17,7 @@ // ** All changes to this file may be overwritten. ** import * as gax from 'google-gax'; -import {Callback, Descriptors, ClientOptions} from 'google-gax'; +import {APICallback, Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax'; import * as path from 'path'; import { Transform } from 'stream'; @@ -56,8 +56,9 @@ export interface PaginationResponse< */ export class KeyManagementServiceClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _keyManagementServiceStub: ClientStub; + private _keyManagementServiceStub: Promise<{[name: string]: Function}>; private _innerApiCalls: {[name: string]: Function}; + private _terminated = false; auth: gax.GoogleAuth; /** @@ -188,7 +189,7 @@ export class KeyManagementServiceClient { for (const methodName of keyManagementServiceStubMethods) { const innerCallPromise = this._keyManagementServiceStub.then( - (stub: {[method: string]: Function}) => (...args: Array<{}>) => { + stub => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -203,11 +204,15 @@ export class KeyManagementServiceClient { this._descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + this._innerApiCalls[methodName] = ( + argument: {}, + callOptions?: CallOptions, + callback?: APICallback + ) => { if (!this._terminated) { return Promise.reject('The client has already been closed.'); } - return apiCall(arguments, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index 651b4a2c4..3d8d1f32f 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -17,7 +17,7 @@ // ** All changes to this file may be overwritten. ** import * as gax from 'google-gax'; -import {Callback, LROperation, Descriptors, ClientOptions} from 'google-gax'; +import {APICallback, Callback, CallOptions, LROperation, Descriptors, ClientOptions} from 'google-gax'; import * as path from 'path'; import { Transform } from 'stream'; @@ -49,8 +49,9 @@ export interface PaginationResponse< */ export class EchoClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _echoStub: ClientStub; + private _echoStub: Promise<{[name: string]: Function}>; private _innerApiCalls: {[name: string]: Function}; + private _terminated = false; auth: gax.GoogleAuth; /** @@ -206,7 +207,7 @@ export class EchoClient { for (const methodName of echoStubMethods) { const innerCallPromise = this._echoStub.then( - (stub: {[method: string]: Function}) => (...args: Array<{}>) => { + stub => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -221,11 +222,15 @@ export class EchoClient { this._descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + this._innerApiCalls[methodName] = ( + argument: {}, + callOptions?: CallOptions, + callback?: APICallback + ) => { if (!this._terminated) { return Promise.reject('The client has already been closed.'); } - return apiCall(arguments, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index a081a60d7..4db5c7446 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -17,7 +17,7 @@ // ** All changes to this file may be overwritten. ** import * as gax from 'google-gax'; -import {Callback, Descriptors, ClientOptions} from 'google-gax'; +import {APICallback, Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax'; import * as path from 'path'; import * as protosTypes from '../../protos/protos'; @@ -32,8 +32,9 @@ const version = require('../../../package.json').version; */ export class TextToSpeechClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _textToSpeechStub: ClientStub; + private _textToSpeechStub: Promise<{[name: string]: Function}>; private _innerApiCalls: {[name: string]: Function}; + private _terminated = false; auth: gax.GoogleAuth; /** @@ -150,7 +151,7 @@ export class TextToSpeechClient { for (const methodName of textToSpeechStubMethods) { const innerCallPromise = this._textToSpeechStub.then( - (stub: {[method: string]: Function}) => (...args: Array<{}>) => { + stub => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -165,11 +166,15 @@ export class TextToSpeechClient { this._descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + this._innerApiCalls[methodName] = ( + argument: {}, + callOptions?: CallOptions, + callback?: APICallback + ) => { if (!this._terminated) { return Promise.reject('The client has already been closed.'); } - return apiCall(arguments, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index 35f13c2f2..dadaf7910 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -17,7 +17,7 @@ // ** All changes to this file may be overwritten. ** import * as gax from 'google-gax'; -import {Callback, LROperation, Descriptors, ClientOptions} from 'google-gax'; +import {APICallback, Callback, CallOptions, LROperation, Descriptors, ClientOptions} from 'google-gax'; import * as path from 'path'; import { Transform } from 'stream'; @@ -46,10 +46,10 @@ export interface PaginationResponse< */ export class TranslationServiceClient { private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _translationServiceStub: ClientStub; + private _translationServiceStub: Promise<{[name: string]: Function}>; private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; - private _terminated: false; + private _terminated = false; auth: gax.GoogleAuth; /** @@ -225,7 +225,7 @@ export class TranslationServiceClient { for (const methodName of translationServiceStubMethods) { const innerCallPromise = this._translationServiceStub.then( - (stub: {[method: string]: Function}) => (...args: Array<{}>) => { + stub => (...args: Array<{}>) => { return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -240,11 +240,15 @@ export class TranslationServiceClient { this._descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = (arguments, callOptions, callback) => { + this._innerApiCalls[methodName] = ( + argument: {}, + callOptions?: CallOptions, + callback?: APICallback + ) => { if (!this._terminated) { return Promise.reject('The client has already been closed.'); } - return apiCall(arguments, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } From fd60a63cee47c4d8f8d558d8e66272ba2f7dfe8d Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 12 Nov 2019 10:13:10 -0800 Subject: [PATCH 4/5] Udpate google-gax --- templates/typescript_gapic/package.json.njk | 2 +- typescript/test/testdata/keymanager/package.json.baseline | 2 +- typescript/test/testdata/showcase/package.json.baseline | 2 +- typescript/test/testdata/texttospeech/package.json.baseline | 2 +- typescript/test/testdata/translate/package.json.baseline | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/typescript_gapic/package.json.njk b/templates/typescript_gapic/package.json.njk index bb6f6480e..7d952b8b7 100644 --- a/templates/typescript_gapic/package.json.njk +++ b/templates/typescript_gapic/package.json.njk @@ -27,7 +27,7 @@ limitations under the License. "build/protos" ], "dependencies": { - "google-gax": "^1.9.0" + "google-gax": "^1.10.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/typescript/test/testdata/keymanager/package.json.baseline b/typescript/test/testdata/keymanager/package.json.baseline index 6efdd7e3f..b3f5d46c7 100644 --- a/typescript/test/testdata/keymanager/package.json.baseline +++ b/typescript/test/testdata/keymanager/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.9.0" + "google-gax": "^1.10.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/typescript/test/testdata/showcase/package.json.baseline b/typescript/test/testdata/showcase/package.json.baseline index 5d690961e..dbacca51d 100644 --- a/typescript/test/testdata/showcase/package.json.baseline +++ b/typescript/test/testdata/showcase/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.9.0" + "google-gax": "^1.10.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/typescript/test/testdata/texttospeech/package.json.baseline b/typescript/test/testdata/texttospeech/package.json.baseline index 84e222e36..9a39365f2 100644 --- a/typescript/test/testdata/texttospeech/package.json.baseline +++ b/typescript/test/testdata/texttospeech/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.9.0" + "google-gax": "^1.10.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/typescript/test/testdata/translate/package.json.baseline b/typescript/test/testdata/translate/package.json.baseline index c34b51122..a94a226c7 100644 --- a/typescript/test/testdata/translate/package.json.baseline +++ b/typescript/test/testdata/translate/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.9.0" + "google-gax": "^1.10.0" }, "devDependencies": { "@types/mocha": "^5.2.5", From 3e5b8c26d1858401e163aca2c7d7f531587ad4d4 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 12 Nov 2019 12:10:19 -0800 Subject: [PATCH 5/5] Apply an obvious fix --- templates/typescript_gapic/src/$version/$service_client.ts.njk | 2 +- .../keymanager/src/v1/key_management_service_client.ts.baseline | 2 +- .../test/testdata/showcase/src/v1beta1/echo_client.ts.baseline | 2 +- .../texttospeech/src/v1/text_to_speech_client.ts.baseline | 2 +- .../src/v3beta1/translation_service_client.ts.baseline | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index d36fa5ac8..fd84568d0 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -275,7 +275,7 @@ export class {{ service.name }}Client { callOptions?: CallOptions, callback?: APICallback ) => { - if (!this._terminated) { + if (this._terminated) { return Promise.reject('The client has already been closed.'); } return apiCall(argument, callOptions, callback); diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 6a3662f73..713b47c53 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -209,7 +209,7 @@ export class KeyManagementServiceClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (!this._terminated) { + if (this._terminated) { return Promise.reject('The client has already been closed.'); } return apiCall(argument, callOptions, callback); diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index 3d8d1f32f..25146c010 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -227,7 +227,7 @@ export class EchoClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (!this._terminated) { + if (this._terminated) { return Promise.reject('The client has already been closed.'); } return apiCall(argument, callOptions, callback); diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index 4db5c7446..1b48ab4ef 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -171,7 +171,7 @@ export class TextToSpeechClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (!this._terminated) { + if (this._terminated) { return Promise.reject('The client has already been closed.'); } return apiCall(argument, callOptions, callback); diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index dadaf7910..d2b8592d1 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -245,7 +245,7 @@ export class TranslationServiceClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (!this._terminated) { + if (this._terminated) { return Promise.reject('The client has already been closed.'); } return apiCall(argument, callOptions, callback);