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

Commit 260b152

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

16 files changed

Lines changed: 994 additions & 725 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"api-documenter": "api-documenter yaml --input-folder=temp"
4646
},
4747
"dependencies": {
48-
"google-gax": "^2.9.0"
48+
"google-gax": "^2.9.2"
4949
},
5050
"devDependencies": {
5151
"@microsoft/api-documenter": "^7.8.10",

src/v4/company_service_client.ts

Lines changed: 83 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ export class CompanyServiceClient {
6060
/**
6161
* Construct an instance of CompanyServiceClient.
6262
*
63-
* @param {object} [options] - The configuration object. See the subsequent
64-
* parameters for more details.
63+
* @param {object} [options] - The configuration object.
64+
* The options accepted by the constructor are described in detail
65+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
66+
* The common options are:
6567
* @param {object} [options.credentials] - Credentials object.
6668
* @param {string} [options.credentials.client_email]
6769
* @param {string} [options.credentials.private_key]
@@ -81,42 +83,33 @@ export class CompanyServiceClient {
8183
* your project ID will be detected automatically.
8284
* @param {string} [options.apiEndpoint] - The domain name of the
8385
* API remote host.
86+
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
87+
* TODO(@alexander-fenster): link to gax documentation.
88+
* @param {boolean} fallback - Use HTTP fallback mode.
89+
* In fallback mode, a special browser-compatible transport implementation is used
90+
* instead of gRPC transport. In browser context (if the `window` object is defined)
91+
* the fallback mode is enabled automatically; set `options.fallback` to `false`
92+
* if you need to override this behavior.
8493
*/
85-
8694
constructor(opts?: ClientOptions) {
87-
// Ensure that options include the service address and port.
95+
// Ensure that options include all the required fields.
8896
const staticMembers = this.constructor as typeof CompanyServiceClient;
8997
const servicePath =
90-
opts && opts.servicePath
91-
? opts.servicePath
92-
: opts && opts.apiEndpoint
93-
? opts.apiEndpoint
94-
: staticMembers.servicePath;
95-
const port = opts && opts.port ? opts.port : staticMembers.port;
98+
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
99+
const port = opts?.port || staticMembers.port;
100+
const clientConfig = opts?.clientConfig ?? {};
101+
const fallback = opts?.fallback ?? typeof window !== 'undefined';
102+
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
96103

97-
if (!opts) {
98-
opts = {servicePath, port};
104+
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
105+
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
106+
opts['scopes'] = staticMembers.scopes;
99107
}
100-
opts.servicePath = opts.servicePath || servicePath;
101-
opts.port = opts.port || port;
102-
103-
// users can override the config from client side, like retry codes name.
104-
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
105-
// The way to override client config for Showcase API:
106-
//
107-
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
108-
// const showcaseClient = new showcaseClient({ projectId, customConfig });
109-
opts.clientConfig = opts.clientConfig || {};
110108

111-
// If we're running in browser, it's OK to omit `fallback` since
112-
// google-gax has `browser` field in its `package.json`.
113-
// For Electron (which does not respect `browser` field),
114-
// pass `{fallback: true}` to the CompanyServiceClient constructor.
109+
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
115110
this._gaxModule = opts.fallback ? gax.fallback : gax;
116111

117-
// Create a `gaxGrpc` object, with any grpc-specific options
118-
// sent to the client.
119-
opts.scopes = (this.constructor as typeof CompanyServiceClient).scopes;
112+
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
120113
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
121114

122115
// Save options to use in initialize() method.
@@ -125,6 +118,11 @@ export class CompanyServiceClient {
125118
// Save the auth object to the client, for use by other methods.
126119
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
127120

121+
// Set the default scopes in auth client if needed.
122+
if (servicePath === staticMembers.servicePath) {
123+
this.auth.defaultScopes = staticMembers.scopes;
124+
}
125+
128126
// Determine the client header string.
129127
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
130128
if (typeof process !== 'undefined' && 'versions' in process) {
@@ -263,6 +261,7 @@ export class CompanyServiceClient {
263261

264262
/**
265263
* The DNS address for this API service.
264+
* @returns {string} The DNS address for this service.
266265
*/
267266
static get servicePath() {
268267
return 'jobs.googleapis.com';
@@ -271,13 +270,15 @@ export class CompanyServiceClient {
271270
/**
272271
* The DNS address for this API service - same as servicePath(),
273272
* exists for compatibility reasons.
273+
* @returns {string} The DNS address for this service.
274274
*/
275275
static get apiEndpoint() {
276276
return 'jobs.googleapis.com';
277277
}
278278

279279
/**
280280
* The port for this API service.
281+
* @returns {number} The default port for this service.
281282
*/
282283
static get port() {
283284
return 443;
@@ -286,6 +287,7 @@ export class CompanyServiceClient {
286287
/**
287288
* The scopes needed to make gRPC calls for every method defined
288289
* in this service.
290+
* @returns {string[]} List of default scopes.
289291
*/
290292
static get scopes() {
291293
return [
@@ -298,8 +300,7 @@ export class CompanyServiceClient {
298300
getProjectId(callback: Callback<string, undefined, undefined>): void;
299301
/**
300302
* Return the project ID used by this class.
301-
* @param {function(Error, string)} callback - the callback to
302-
* be called with the current project Id.
303+
* @returns {Promise} A promise that resolves to string containing the project ID.
303304
*/
304305
getProjectId(
305306
callback?: Callback<string, undefined, undefined>
@@ -357,7 +358,11 @@ export class CompanyServiceClient {
357358
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
358359
* @returns {Promise} - The promise which resolves to an array.
359360
* The first element of the array is an object representing [Company]{@link google.cloud.talent.v4.Company}.
360-
* The promise has a method named "cancel" which cancels the ongoing API call.
361+
* Please see the
362+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
363+
* for more details and examples.
364+
* @example
365+
* const [response] = await client.createCompany(request);
361366
*/
362367
createCompany(
363368
request: protos.google.cloud.talent.v4.ICreateCompanyRequest,
@@ -443,7 +448,11 @@ export class CompanyServiceClient {
443448
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
444449
* @returns {Promise} - The promise which resolves to an array.
445450
* The first element of the array is an object representing [Company]{@link google.cloud.talent.v4.Company}.
446-
* The promise has a method named "cancel" which cancels the ongoing API call.
451+
* Please see the
452+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
453+
* for more details and examples.
454+
* @example
455+
* const [response] = await client.getCompany(request);
447456
*/
448457
getCompany(
449458
request: protos.google.cloud.talent.v4.IGetCompanyRequest,
@@ -531,7 +540,11 @@ export class CompanyServiceClient {
531540
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
532541
* @returns {Promise} - The promise which resolves to an array.
533542
* The first element of the array is an object representing [Company]{@link google.cloud.talent.v4.Company}.
534-
* The promise has a method named "cancel" which cancels the ongoing API call.
543+
* Please see the
544+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
545+
* for more details and examples.
546+
* @example
547+
* const [response] = await client.updateCompany(request);
535548
*/
536549
updateCompany(
537550
request: protos.google.cloud.talent.v4.IUpdateCompanyRequest,
@@ -618,7 +631,11 @@ export class CompanyServiceClient {
618631
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
619632
* @returns {Promise} - The promise which resolves to an array.
620633
* The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}.
621-
* The promise has a method named "cancel" which cancels the ongoing API call.
634+
* Please see the
635+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
636+
* for more details and examples.
637+
* @example
638+
* const [response] = await client.deleteCompany(request);
622639
*/
623640
deleteCompany(
624641
request: protos.google.cloud.talent.v4.IDeleteCompanyRequest,
@@ -716,19 +733,14 @@ export class CompanyServiceClient {
716733
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
717734
* @returns {Promise} - The promise which resolves to an array.
718735
* The first element of the array is Array of [Company]{@link google.cloud.talent.v4.Company}.
719-
* The client library support auto-pagination by default: it will call the API as many
736+
* The client library will perform auto-pagination by default: it will call the API as many
720737
* times as needed and will merge results from all the pages into this array.
721-
*
722-
* When autoPaginate: false is specified through options, the array has three elements.
723-
* The first element is Array of [Company]{@link google.cloud.talent.v4.Company} that corresponds to
724-
* the one page received from the API server.
725-
* If the second element is not null it contains the request object of type [ListCompaniesRequest]{@link google.cloud.talent.v4.ListCompaniesRequest}
726-
* that can be used to obtain the next page of the results.
727-
* If it is null, the next page does not exist.
728-
* The third element contains the raw response received from the API server. Its type is
729-
* [ListCompaniesResponse]{@link google.cloud.talent.v4.ListCompaniesResponse}.
730-
*
731-
* The promise has a method named "cancel" which cancels the ongoing API call.
738+
* Note that it can affect your quota.
739+
* We recommend using `listCompaniesAsync()`
740+
* method described below for async iteration which you can stop as needed.
741+
* Please see the
742+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
743+
* for more details and examples.
732744
*/
733745
listCompanies(
734746
request: protos.google.cloud.talent.v4.IListCompaniesRequest,
@@ -774,18 +786,7 @@ export class CompanyServiceClient {
774786
}
775787

776788
/**
777-
* Equivalent to {@link listCompanies}, but returns a NodeJS Stream object.
778-
*
779-
* This fetches the paged responses for {@link listCompanies} continuously
780-
* and invokes the callback registered for 'data' event for each element in the
781-
* responses.
782-
*
783-
* The returned object has 'end' method when no more elements are required.
784-
*
785-
* autoPaginate option will be ignored.
786-
*
787-
* @see {@link https://nodejs.org/api/stream.html}
788-
*
789+
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
789790
* @param {Object} request
790791
* The request object that will be sent.
791792
* @param {string} request.parent
@@ -809,6 +810,13 @@ export class CompanyServiceClient {
809810
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
810811
* @returns {Stream}
811812
* An object stream which emits an object representing [Company]{@link google.cloud.talent.v4.Company} on 'data' event.
813+
* The client library will perform auto-pagination by default: it will call the API as many
814+
* times as needed. Note that it can affect your quota.
815+
* We recommend using `listCompaniesAsync()`
816+
* method described below for async iteration which you can stop as needed.
817+
* Please see the
818+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
819+
* for more details and examples.
812820
*/
813821
listCompaniesStream(
814822
request?: protos.google.cloud.talent.v4.IListCompaniesRequest,
@@ -833,10 +841,9 @@ export class CompanyServiceClient {
833841
}
834842

835843
/**
836-
* Equivalent to {@link listCompanies}, but returns an iterable object.
837-
*
838-
* for-await-of syntax is used with the iterable to recursively get response element on-demand.
844+
* Equivalent to `listCompanies`, but returns an iterable object.
839845
*
846+
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
840847
* @param {Object} request
841848
* The request object that will be sent.
842849
* @param {string} request.parent
@@ -859,7 +866,18 @@ export class CompanyServiceClient {
859866
* @param {object} [options]
860867
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
861868
* @returns {Object}
862-
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
869+
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
870+
* When you iterate the returned iterable, each element will be an object representing
871+
* [Company]{@link google.cloud.talent.v4.Company}. The API will be called under the hood as needed, once per the page,
872+
* so you can stop the iteration when you don't need more results.
873+
* Please see the
874+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
875+
* for more details and examples.
876+
* @example
877+
* const iterable = client.listCompaniesAsync(request);
878+
* for await (const response of iterable) {
879+
* // process response
880+
* }
863881
*/
864882
listCompaniesAsync(
865883
request?: protos.google.cloud.talent.v4.IListCompaniesRequest,
@@ -1022,9 +1040,10 @@ export class CompanyServiceClient {
10221040
}
10231041

10241042
/**
1025-
* Terminate the GRPC channel and close the client.
1043+
* Terminate the gRPC channel and close the client.
10261044
*
10271045
* The client will no longer be usable and all future behavior is undefined.
1046+
* @returns {Promise} A promise that resolves when the client is closed.
10281047
*/
10291048
close(): Promise<void> {
10301049
this.initialize();

0 commit comments

Comments
 (0)