From 17963fb5d6263fd1cb97961b1835cb3157148066 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Tue, 10 Dec 2019 15:23:05 -0800 Subject: [PATCH] fix: export this.operationsClient (#166) * fix: export this.operationsClient * fix: do not expose operationsClient if no LRO --- templates/typescript_gapic/package.json.njk | 2 +- .../src/$version/$service_client.ts.njk | 7 +++++-- .../testdata/keymanager/package.json.baseline | 2 +- .../test/testdata/redis/package.json.baseline | 2 +- .../src/v1beta1/cloud_redis_client.ts.baseline | 15 ++++++++------- .../test/testdata/showcase/package.json.baseline | 2 +- .../showcase/src/v1beta1/echo_client.ts.baseline | 5 +++-- .../testdata/texttospeech/package.json.baseline | 2 +- .../test/testdata/translate/package.json.baseline | 2 +- .../translation_service_client.ts.baseline | 9 +++++---- 10 files changed, 27 insertions(+), 21 deletions(-) diff --git a/templates/typescript_gapic/package.json.njk b/templates/typescript_gapic/package.json.njk index 2f7c13885..b46657f1b 100644 --- a/templates/typescript_gapic/package.json.njk +++ b/templates/typescript_gapic/package.json.njk @@ -41,7 +41,7 @@ limitations under the License. "test": "c8 mocha build/test" }, "dependencies": { - "google-gax": "^1.11.0" + "google-gax": "^1.12.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index cf07a1c09..03059694c 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -46,6 +46,9 @@ export class {{ service.name }}Client { {%- endif %} private _terminated = false; auth: gax.GoogleAuth; +{%- if (service.longRunning.length > 0) %} + operationsClient: gax.OperationsClient; +{%- endif %} {{ service.name.toCamelCase() }}Stub: Promise<{[name: string]: Function}>; /** @@ -185,7 +188,7 @@ export class {{ service.name }}Client { gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : gaxModule.protobuf.loadSync(nodejsProtoPath); - const operationsClient = gaxModule.lro({ + this.operationsClient = gaxModule.lro({ auth: this.auth, grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined }).operationsClient(opts); @@ -202,7 +205,7 @@ export class {{ service.name }}Client { {%- for method in service.longRunning %} {{- longRunningJoiner() }} {{ method.name.toCamelCase() }}: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, {{ method.name.toCamelCase() }}Response.decode.bind({{ method.name.toCamelCase() }}Response), {{ method.name.toCamelCase() }}Metadata.decode.bind({{ method.name.toCamelCase() }}Metadata)) {%- endfor %} diff --git a/typescript/test/testdata/keymanager/package.json.baseline b/typescript/test/testdata/keymanager/package.json.baseline index f93fff108..8c3a18582 100644 --- a/typescript/test/testdata/keymanager/package.json.baseline +++ b/typescript/test/testdata/keymanager/package.json.baseline @@ -24,7 +24,7 @@ "test": "c8 mocha build/test" }, "dependencies": { - "google-gax": "^1.11.0" + "google-gax": "^1.12.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/typescript/test/testdata/redis/package.json.baseline b/typescript/test/testdata/redis/package.json.baseline index 3ab97e27f..60c0ef4d2 100644 --- a/typescript/test/testdata/redis/package.json.baseline +++ b/typescript/test/testdata/redis/package.json.baseline @@ -24,7 +24,7 @@ "test": "c8 mocha build/test" }, "dependencies": { - "google-gax": "^1.11.0" + "google-gax": "^1.12.0" }, "devDependencies": { "@types/mocha": "^5.2.5", diff --git a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline index 150db8769..16f7f8bc3 100644 --- a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline +++ b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline @@ -51,6 +51,7 @@ export class CloudRedisClient { private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; auth: gax.GoogleAuth; + operationsClient: gax.OperationsClient; cloudRedisStub: Promise<{[name: string]: Function}>; /** @@ -168,7 +169,7 @@ export class CloudRedisClient { gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : gaxModule.protobuf.loadSync(nodejsProtoPath); - const operationsClient = gaxModule.lro({ + this.operationsClient = gaxModule.lro({ auth: this.auth, grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined }).operationsClient(opts); @@ -199,27 +200,27 @@ export class CloudRedisClient { this._descriptors.longrunning = { createInstance: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, createInstanceResponse.decode.bind(createInstanceResponse), createInstanceMetadata.decode.bind(createInstanceMetadata)), updateInstance: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, updateInstanceResponse.decode.bind(updateInstanceResponse), updateInstanceMetadata.decode.bind(updateInstanceMetadata)), importInstance: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, importInstanceResponse.decode.bind(importInstanceResponse), importInstanceMetadata.decode.bind(importInstanceMetadata)), exportInstance: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, exportInstanceResponse.decode.bind(exportInstanceResponse), exportInstanceMetadata.decode.bind(exportInstanceMetadata)), failoverInstance: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, failoverInstanceResponse.decode.bind(failoverInstanceResponse), failoverInstanceMetadata.decode.bind(failoverInstanceMetadata)), deleteInstance: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, deleteInstanceResponse.decode.bind(deleteInstanceResponse), deleteInstanceMetadata.decode.bind(deleteInstanceMetadata)) }; diff --git a/typescript/test/testdata/showcase/package.json.baseline b/typescript/test/testdata/showcase/package.json.baseline index ba3101627..4bd4ad2ba 100644 --- a/typescript/test/testdata/showcase/package.json.baseline +++ b/typescript/test/testdata/showcase/package.json.baseline @@ -24,7 +24,7 @@ "test": "c8 mocha build/test" }, "dependencies": { - "google-gax": "^1.11.0" + "google-gax": "^1.12.0" }, "devDependencies": { "@types/mocha": "^5.2.5", 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 e544363b0..390326de3 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -39,6 +39,7 @@ export class EchoClient { private _innerApiCalls: {[name: string]: Function}; private _terminated = false; auth: gax.GoogleAuth; + operationsClient: gax.OperationsClient; echoStub: Promise<{[name: string]: Function}>; /** @@ -152,7 +153,7 @@ export class EchoClient { gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : gaxModule.protobuf.loadSync(nodejsProtoPath); - const operationsClient = gaxModule.lro({ + this.operationsClient = gaxModule.lro({ auth: this.auth, grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined }).operationsClient(opts); @@ -163,7 +164,7 @@ export class EchoClient { this._descriptors.longrunning = { wait: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, waitResponse.decode.bind(waitResponse), waitMetadata.decode.bind(waitMetadata)) }; diff --git a/typescript/test/testdata/texttospeech/package.json.baseline b/typescript/test/testdata/texttospeech/package.json.baseline index 408f21457..cbb862242 100644 --- a/typescript/test/testdata/texttospeech/package.json.baseline +++ b/typescript/test/testdata/texttospeech/package.json.baseline @@ -24,7 +24,7 @@ "test": "c8 mocha build/test" }, "dependencies": { - "google-gax": "^1.11.0" + "google-gax": "^1.12.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 8188b1afb..0c885bf9c 100644 --- a/typescript/test/testdata/translate/package.json.baseline +++ b/typescript/test/testdata/translate/package.json.baseline @@ -24,7 +24,7 @@ "test": "c8 mocha build/test" }, "dependencies": { - "google-gax": "^1.11.0" + "google-gax": "^1.12.0" }, "devDependencies": { "@types/mocha": "^5.2.5", 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 2d34a0858..411cad67d 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 @@ -37,6 +37,7 @@ export class TranslationServiceClient { private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; auth: gax.GoogleAuth; + operationsClient: gax.OperationsClient; translationServiceStub: Promise<{[name: string]: Function}>; /** @@ -154,7 +155,7 @@ export class TranslationServiceClient { gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : gaxModule.protobuf.loadSync(nodejsProtoPath); - const operationsClient = gaxModule.lro({ + this.operationsClient = gaxModule.lro({ auth: this.auth, grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined }).operationsClient(opts); @@ -173,15 +174,15 @@ export class TranslationServiceClient { this._descriptors.longrunning = { batchTranslateText: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, batchTranslateTextResponse.decode.bind(batchTranslateTextResponse), batchTranslateTextMetadata.decode.bind(batchTranslateTextMetadata)), createGlossary: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, createGlossaryResponse.decode.bind(createGlossaryResponse), createGlossaryMetadata.decode.bind(createGlossaryMetadata)), deleteGlossary: new gaxModule.LongrunningDescriptor( - operationsClient, + this.operationsClient, deleteGlossaryResponse.decode.bind(deleteGlossaryResponse), deleteGlossaryMetadata.decode.bind(deleteGlossaryMetadata)) };