diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index c39465e99..1af956ecf 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -50,6 +50,10 @@ export interface PaginationResponse< } {% endif %} export class {{ service.name }}Client { + private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _innerApiCalls: {[name: string]: Function}; + auth: gax.GoogleAuth; + /** * Construct an instance of {{ service.name }}Client. * @@ -77,13 +81,23 @@ export class {{ service.name }}Client { * @@param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ - private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _innerApiCalls: {[name: string]: Function}; - auth: gax.GoogleAuth; - constructor(opts: ClientOptions) { + constructor(opts?: ClientOptions) { // Ensure that options include the service address and port. - opts = opts || {}; + const staticMembers = this.constructor as typeof {{ service.name }}Client; + const servicePath = opts && opts.servicePath ? + opts.servicePath : + ((opts && opts.apiEndpoint) ? opts.apiEndpoint : + staticMembers.servicePath); + const port = opts && opts.port ? opts.port : staticMembers.port; + + if (!opts) { + opts = {servicePath, port}; + } + opts.servicePath = opts.servicePath || servicePath; + opts.port = opts.port || port; + opts.clientConfig = opts.clientConfig || {}; + const isBrowser = (typeof window !== 'undefined'); if (isBrowser){ opts.fallback = true; @@ -92,18 +106,6 @@ export class {{ service.name }}Client { // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; - const servicePath = - opts.servicePath || - opts.apiEndpoint || - (this.constructor as typeof {{service.name}}Client).servicePath; - - opts = Object.assign( - { - clientConfig: {}, - port: (this.constructor as typeof {{ service.name }}Client).port, - servicePath: servicePath, - }, - opts); // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. diff --git a/typescript/test/testdata/keymanager/src/v1/keymanagementservice_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/keymanagementservice_client.ts.baseline index ce8c6e9c7..67e1e143e 100644 --- a/typescript/test/testdata/keymanager/src/v1/keymanagementservice_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/keymanagementservice_client.ts.baseline @@ -63,6 +63,10 @@ export interface PaginationResponse< } export class KeyManagementServiceClient { + private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _innerApiCalls: {[name: string]: Function}; + auth: gax.GoogleAuth; + /** * Construct an instance of KeyManagementServiceClient. * @@ -90,13 +94,23 @@ export class KeyManagementServiceClient { * @@param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ - private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _innerApiCalls: {[name: string]: Function}; - auth: gax.GoogleAuth; - constructor(opts: ClientOptions) { + constructor(opts?: ClientOptions) { // Ensure that options include the service address and port. - opts = opts || {}; + const staticMembers = this.constructor as typeof KeyManagementServiceClient; + const servicePath = opts && opts.servicePath ? + opts.servicePath : + ((opts && opts.apiEndpoint) ? opts.apiEndpoint : + staticMembers.servicePath); + const port = opts && opts.port ? opts.port : staticMembers.port; + + if (!opts) { + opts = {servicePath, port}; + } + opts.servicePath = opts.servicePath || servicePath; + opts.port = opts.port || port; + opts.clientConfig = opts.clientConfig || {}; + const isBrowser = (typeof window !== 'undefined'); if (isBrowser){ opts.fallback = true; @@ -105,18 +119,6 @@ export class KeyManagementServiceClient { // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; - const servicePath = - opts.servicePath || - opts.apiEndpoint || - (this.constructor as typeof KeyManagementServiceClient).servicePath; - - opts = Object.assign( - { - clientConfig: {}, - port: (this.constructor as typeof KeyManagementServiceClient).port, - servicePath: servicePath, - }, - opts); // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. 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 cf470a5c6..75f09e658 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -66,6 +66,10 @@ export interface PaginationResponse< } export class EchoClient { + private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; + private _innerApiCalls: {[name: string]: Function}; + auth: gax.GoogleAuth; + /** * Construct an instance of EchoClient. * @@ -93,13 +97,23 @@ export class EchoClient { * @@param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ - private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; - private _innerApiCalls: {[name: string]: Function}; - auth: gax.GoogleAuth; - constructor(opts: ClientOptions) { + constructor(opts?: ClientOptions) { // Ensure that options include the service address and port. - opts = opts || {}; + const staticMembers = this.constructor as typeof EchoClient; + const servicePath = opts && opts.servicePath ? + opts.servicePath : + ((opts && opts.apiEndpoint) ? opts.apiEndpoint : + staticMembers.servicePath); + const port = opts && opts.port ? opts.port : staticMembers.port; + + if (!opts) { + opts = {servicePath, port}; + } + opts.servicePath = opts.servicePath || servicePath; + opts.port = opts.port || port; + opts.clientConfig = opts.clientConfig || {}; + const isBrowser = (typeof window !== 'undefined'); if (isBrowser){ opts.fallback = true; @@ -108,18 +122,6 @@ export class EchoClient { // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; - const servicePath = - opts.servicePath || - opts.apiEndpoint || - (this.constructor as typeof EchoClient).servicePath; - - opts = Object.assign( - { - clientConfig: {}, - port: (this.constructor as typeof EchoClient).port, - servicePath: servicePath, - }, - opts); // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client.