Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 17f1b3d

Browse files
fix: do not modify options object, use defaultScopes (#88)
Regenerated the library using [gapic-generator-typescript](https://github.com/googleapis/gapic-generator-typescript) v1.2.1.
1 parent c636b30 commit 17f1b3d

7 files changed

Lines changed: 270 additions & 189 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"api-documenter": "api-documenter yaml --input-folder=temp"
3030
},
3131
"dependencies": {
32-
"google-gax": "^2.1.0",
32+
"google-gax": "^2.9.2",
3333
"json-schema": "^0.2.5"
3434
},
3535
"devDependencies": {

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import * as v1beta1 from './v1beta1';
2020
const LookupServiceClient = v1beta1.LookupServiceClient;
21+
type LookupServiceClient = v1beta1.LookupServiceClient;
2122
const RegistrationServiceClient = v1beta1.RegistrationServiceClient;
23+
type RegistrationServiceClient = v1beta1.RegistrationServiceClient;
2224
export {v1beta1, LookupServiceClient, RegistrationServiceClient};
2325
export default {v1beta1, LookupServiceClient, RegistrationServiceClient};
2426
import * as protos from '../protos/protos';

src/v1beta1/lookup_service_client.ts

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ export class LookupServiceClient {
5151
/**
5252
* Construct an instance of LookupServiceClient.
5353
*
54-
* @param {object} [options] - The configuration object. See the subsequent
55-
* parameters for more details.
54+
* @param {object} [options] - The configuration object.
55+
* The options accepted by the constructor are described in detail
56+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
57+
* The common options are:
5658
* @param {object} [options.credentials] - Credentials object.
5759
* @param {string} [options.credentials.client_email]
5860
* @param {string} [options.credentials.private_key]
@@ -72,42 +74,33 @@ export class LookupServiceClient {
7274
* your project ID will be detected automatically.
7375
* @param {string} [options.apiEndpoint] - The domain name of the
7476
* API remote host.
77+
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
78+
* TODO(@alexander-fenster): link to gax documentation.
79+
* @param {boolean} fallback - Use HTTP fallback mode.
80+
* In fallback mode, a special browser-compatible transport implementation is used
81+
* instead of gRPC transport. In browser context (if the `window` object is defined)
82+
* the fallback mode is enabled automatically; set `options.fallback` to `false`
83+
* if you need to override this behavior.
7584
*/
76-
7785
constructor(opts?: ClientOptions) {
78-
// Ensure that options include the service address and port.
86+
// Ensure that options include all the required fields.
7987
const staticMembers = this.constructor as typeof LookupServiceClient;
8088
const servicePath =
81-
opts && opts.servicePath
82-
? opts.servicePath
83-
: opts && opts.apiEndpoint
84-
? opts.apiEndpoint
85-
: staticMembers.servicePath;
86-
const port = opts && opts.port ? opts.port : staticMembers.port;
87-
88-
if (!opts) {
89-
opts = {servicePath, port};
89+
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
90+
const port = opts?.port || staticMembers.port;
91+
const clientConfig = opts?.clientConfig ?? {};
92+
const fallback = opts?.fallback ?? typeof window !== 'undefined';
93+
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
94+
95+
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
96+
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
97+
opts['scopes'] = staticMembers.scopes;
9098
}
91-
opts.servicePath = opts.servicePath || servicePath;
92-
opts.port = opts.port || port;
93-
94-
// users can override the config from client side, like retry codes name.
95-
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
96-
// The way to override client config for Showcase API:
97-
//
98-
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
99-
// const showcaseClient = new showcaseClient({ projectId, customConfig });
100-
opts.clientConfig = opts.clientConfig || {};
101-
102-
// If we're running in browser, it's OK to omit `fallback` since
103-
// google-gax has `browser` field in its `package.json`.
104-
// For Electron (which does not respect `browser` field),
105-
// pass `{fallback: true}` to the LookupServiceClient constructor.
99+
100+
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
106101
this._gaxModule = opts.fallback ? gax.fallback : gax;
107102

108-
// Create a `gaxGrpc` object, with any grpc-specific options
109-
// sent to the client.
110-
opts.scopes = (this.constructor as typeof LookupServiceClient).scopes;
103+
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
111104
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
112105

113106
// Save options to use in initialize() method.
@@ -116,6 +109,11 @@ export class LookupServiceClient {
116109
// Save the auth object to the client, for use by other methods.
117110
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
118111

112+
// Set the default scopes in auth client if needed.
113+
if (servicePath === staticMembers.servicePath) {
114+
this.auth.defaultScopes = staticMembers.scopes;
115+
}
116+
119117
// Determine the client header string.
120118
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
121119
if (typeof process !== 'undefined' && 'versions' in process) {
@@ -238,6 +236,7 @@ export class LookupServiceClient {
238236

239237
/**
240238
* The DNS address for this API service.
239+
* @returns {string} The DNS address for this service.
241240
*/
242241
static get servicePath() {
243242
return 'servicedirectory.googleapis.com';
@@ -246,13 +245,15 @@ export class LookupServiceClient {
246245
/**
247246
* The DNS address for this API service - same as servicePath(),
248247
* exists for compatibility reasons.
248+
* @returns {string} The DNS address for this service.
249249
*/
250250
static get apiEndpoint() {
251251
return 'servicedirectory.googleapis.com';
252252
}
253253

254254
/**
255255
* The port for this API service.
256+
* @returns {number} The default port for this service.
256257
*/
257258
static get port() {
258259
return 443;
@@ -261,6 +262,7 @@ export class LookupServiceClient {
261262
/**
262263
* The scopes needed to make gRPC calls for every method defined
263264
* in this service.
265+
* @returns {string[]} List of default scopes.
264266
*/
265267
static get scopes() {
266268
return ['https://www.googleapis.com/auth/cloud-platform'];
@@ -270,8 +272,7 @@ export class LookupServiceClient {
270272
getProjectId(callback: Callback<string, undefined, undefined>): void;
271273
/**
272274
* Return the project ID used by this class.
273-
* @param {function(Error, string)} callback - the callback to
274-
* be called with the current project Id.
275+
* @returns {Promise} A promise that resolves to string containing the project ID.
275276
*/
276277
getProjectId(
277278
callback?: Callback<string, undefined, undefined>
@@ -356,7 +357,11 @@ export class LookupServiceClient {
356357
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
357358
* @returns {Promise} - The promise which resolves to an array.
358359
* The first element of the array is an object representing [ResolveServiceResponse]{@link google.cloud.servicedirectory.v1beta1.ResolveServiceResponse}.
359-
* The promise has a method named "cancel" which cancels the ongoing API call.
360+
* Please see the
361+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
362+
* for more details and examples.
363+
* @example
364+
* const [response] = await client.resolveService(request);
360365
*/
361366
resolveService(
362367
request: protos.google.cloud.servicedirectory.v1beta1.IResolveServiceRequest,
@@ -612,9 +617,10 @@ export class LookupServiceClient {
612617
}
613618

614619
/**
615-
* Terminate the GRPC channel and close the client.
620+
* Terminate the gRPC channel and close the client.
616621
*
617622
* The client will no longer be usable and all future behavior is undefined.
623+
* @returns {Promise} A promise that resolves when the client is closed.
618624
*/
619625
close(): Promise<void> {
620626
this.initialize();

0 commit comments

Comments
 (0)