diff --git a/templates/typescript_gapic/package.json.njk b/templates/typescript_gapic/package.json.njk index 6eb9cc0d6..bc92170c5 100644 --- a/templates/typescript_gapic/package.json.njk +++ b/templates/typescript_gapic/package.json.njk @@ -11,15 +11,14 @@ "!build/src/**/*.map" ], "dependencies": { - "google-gax": "^1.3.0" + "google-gax": "^1.5.0" }, "devDependencies": { "@types/mocha": "^5.2.5", "@types/through2": "^2.0.34", "gts": "^0.9.0", "mocha": "^6.0.0", - "typescript": "~3.5.3", - "google-gax": "^1.3.0" + "typescript": "~3.5.3" }, "scripts": { "lint": "gts check", diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 8f91e981e..3cacf1a72 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -174,23 +174,24 @@ export class {{ service.name }}Client { {%- endfor -%} ]; - for (const methodName of echoStubMethods) { + for (const methodName of {{ service.name.toCamelCase() }}StubMethods) { + const innerCallPromise = {{ service.name.toCamelCase() }}Stub.then( + stub => (...args: Array<{}>) => { + return stub[methodName].apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + this._innerApiCalls[methodName] = gax.createApiCall( - {{ service.name.toCamelCase() }}Stub.then( - // @ts-ignore - stub => (...args) => { - stub[methodName].apply(stub, args); - }, - (err: Error|null|undefined) => () => { - throw err; - }), - defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName]); + innerCallPromise, + defaults[methodName], + this._descriptors.page[methodName] || + this._descriptors.stream[methodName] || + this._descriptors.longrunning[methodName] + ); } } - /** * The DNS address for this API service. */ @@ -271,9 +272,7 @@ export class {{ service.name }}Client { protos{{ method.outputInterface }}, protos{{ method.inputInterface }}|undefined, {}|undefined ]>|void { -{%- if (method.streaming == 'SERVER_STREAMING' or method.streaming == 'NON_STREAMING') %} request = request || {}; -{%- endif %} let options = optionsOrCallback; if (typeof options === 'function' && callback === undefined) { callback = options; @@ -283,4 +282,50 @@ export class {{ service.name }}Client { return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options, callback); } {%- endfor %} +{% for method in service.streaming %} +{%- if method.serverStreaming and method.clientStreaming %} + {{ method.name.toCamelCase() }}( + options?: gax.CallOptions): + gax.BiDiStreamingCall{ + options = options || {}; + return this._innerApiCalls.{{ method.name.toCamelCase() }}(options); + } +{%- elif method.serverStreaming %} + {{ method.name.toCamelCase() }}( + request?: protos{{ method.inputInterface }}, + options?: gax.CallOptions): + gax.ServerStreamingCall{ + request = request || {}; + options = options || {}; + return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options); + } +{%- elif method.clientStreaming %} + {{ method.name.toCamelCase() }}( + options: gax.CallOptions, + callback: Callback< + protos{{ method.outputInterface }}, + protos{{ method.inputInterface }}|undefined, {}|undefined>): + gax.ClientStreamingCall; + {{ method.name.toCamelCase() }}( + callback: Callback< + protos{{ method.outputInterface }}, + protos{{ method.inputInterface }}|undefined, {}|undefined>): + gax.ClientStreamingCall; + {{ method.name.toCamelCase() }}( + optionsOrCallback: gax.CallOptions|Callback< + protos{{ method.outputInterface }}, + protos{{ method.inputInterface }}|undefined, {}|undefined>, + callback?: Callback< + protos{{ method.outputInterface }}, + protos{{ method.inputInterface }}|undefined, {}|undefined>): + gax.ClientStreamingCall { + if (optionsOrCallback instanceof Function && callback === undefined) { + callback = optionsOrCallback; + optionsOrCallback = {}; + } + optionsOrCallback = optionsOrCallback || {}; + return this._innerApiCalls.{{ method.name.toCamelCase() }}(null, optionsOrCallback, callback); + } +{%- endif %} +{% endfor %} } diff --git a/typescript/test/testdata/echo_client_baseline.ts.txt b/typescript/test/testdata/echo_client_baseline.ts.txt index 3c7c68f6d..efa02f718 100644 --- a/typescript/test/testdata/echo_client_baseline.ts.txt +++ b/typescript/test/testdata/echo_client_baseline.ts.txt @@ -135,22 +135,23 @@ export class EchoClient { ['echo', 'expand', 'collect', 'chat', 'pagedExpand', 'wait']; for (const methodName of echoStubMethods) { + const innerCallPromise = echoStub.then( + stub => (...args: Array<{}>) => { + return stub[methodName].apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + this._innerApiCalls[methodName] = gax.createApiCall( - echoStub.then( - // @ts-ignore - stub => (...args) => { - stub[methodName].apply(stub, args); - }, - (err: Error|null|undefined) => () => { - throw err; - }), - defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName]); + innerCallPromise, + defaults[methodName], + this._descriptors.page[methodName] || + this._descriptors.stream[methodName] || + this._descriptors.longrunning[methodName] + ); } } - /** * The DNS address for this API service. */ @@ -219,6 +220,7 @@ export class EchoClient { protos.google.showcase.v1beta1.IEchoResponse, protos.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined ]>|void { + request = request || {}; let options = optionsOrCallback; if (typeof options === 'function' && callback === undefined) { callback = options; @@ -227,4 +229,48 @@ export class EchoClient { options = options || {}; return this._innerApiCalls.echo(request, options, callback); } + + expand( + request?: protos.google.showcase.v1beta1.IExpandRequest, + options?: gax.CallOptions): + gax.ServerStreamingCall{ + request = request || {}; + options = options || {}; + return this._innerApiCalls.expand(request, options); + } + + collect( + options: gax.CallOptions, + callback: Callback< + protos.google.showcase.v1beta1.IEchoResponse, + protos.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>): + gax.ClientStreamingCall; + collect( + callback: Callback< + protos.google.showcase.v1beta1.IEchoResponse, + protos.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>): + gax.ClientStreamingCall; + collect( + optionsOrCallback: gax.CallOptions|Callback< + protos.google.showcase.v1beta1.IEchoResponse, + protos.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>, + callback?: Callback< + protos.google.showcase.v1beta1.IEchoResponse, + protos.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>): + gax.ClientStreamingCall { + if (optionsOrCallback instanceof Function && callback === undefined) { + callback = optionsOrCallback; + optionsOrCallback = {}; + } + optionsOrCallback = optionsOrCallback || {}; + return this._innerApiCalls.collect(null, optionsOrCallback, callback); + } + + chat( + options?: gax.CallOptions): + gax.BiDiStreamingCall{ + options = options || {}; + return this._innerApiCalls.chat(options); + } + }