Skip to content

Commit 8b39acb

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

File tree

6 files changed

+109
-88
lines changed

6 files changed

+109
-88
lines changed

packages/google-monitoring-dashboard/package.json

+1-1
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
},
3434
"devDependencies": {
3535
"@types/mocha": "^8.0.0",

packages/google-monitoring-dashboard/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import * as v1 from './v1';
2020
const DashboardsServiceClient = v1.DashboardsServiceClient;
21+
type DashboardsServiceClient = v1.DashboardsServiceClient;
2122
export {v1, DashboardsServiceClient};
2223
export default {v1, DashboardsServiceClient};
2324
import * as protos from '../protos/protos';

packages/google-monitoring-dashboard/src/v1/dashboards_service_client.ts

+85-66
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ export class DashboardsServiceClient {
6161
/**
6262
* Construct an instance of DashboardsServiceClient.
6363
*
64-
* @param {object} [options] - The configuration object. See the subsequent
65-
* parameters for more details.
64+
* @param {object} [options] - The configuration object.
65+
* The options accepted by the constructor are described in detail
66+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
67+
* The common options are:
6668
* @param {object} [options.credentials] - Credentials object.
6769
* @param {string} [options.credentials.client_email]
6870
* @param {string} [options.credentials.private_key]
@@ -82,42 +84,33 @@ export class DashboardsServiceClient {
8284
* your project ID will be detected automatically.
8385
* @param {string} [options.apiEndpoint] - The domain name of the
8486
* API remote host.
87+
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
88+
* TODO(@alexander-fenster): link to gax documentation.
89+
* @param {boolean} fallback - Use HTTP fallback mode.
90+
* In fallback mode, a special browser-compatible transport implementation is used
91+
* instead of gRPC transport. In browser context (if the `window` object is defined)
92+
* the fallback mode is enabled automatically; set `options.fallback` to `false`
93+
* if you need to override this behavior.
8594
*/
86-
8795
constructor(opts?: ClientOptions) {
88-
// Ensure that options include the service address and port.
96+
// Ensure that options include all the required fields.
8997
const staticMembers = this.constructor as typeof DashboardsServiceClient;
9098
const servicePath =
91-
opts && opts.servicePath
92-
? opts.servicePath
93-
: opts && opts.apiEndpoint
94-
? opts.apiEndpoint
95-
: staticMembers.servicePath;
96-
const port = opts && opts.port ? opts.port : staticMembers.port;
97-
98-
if (!opts) {
99-
opts = {servicePath, port};
99+
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
100+
const port = opts?.port || staticMembers.port;
101+
const clientConfig = opts?.clientConfig ?? {};
102+
const fallback = opts?.fallback ?? typeof window !== 'undefined';
103+
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
104+
105+
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
106+
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
107+
opts['scopes'] = staticMembers.scopes;
100108
}
101-
opts.servicePath = opts.servicePath || servicePath;
102-
opts.port = opts.port || port;
103-
104-
// users can override the config from client side, like retry codes name.
105-
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
106-
// The way to override client config for Showcase API:
107-
//
108-
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
109-
// const showcaseClient = new showcaseClient({ projectId, customConfig });
110-
opts.clientConfig = opts.clientConfig || {};
111-
112-
// If we're running in browser, it's OK to omit `fallback` since
113-
// google-gax has `browser` field in its `package.json`.
114-
// For Electron (which does not respect `browser` field),
115-
// pass `{fallback: true}` to the DashboardsServiceClient constructor.
109+
110+
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
116111
this._gaxModule = opts.fallback ? gax.fallback : gax;
117112

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

123116
// Save options to use in initialize() method.
@@ -126,6 +119,11 @@ export class DashboardsServiceClient {
126119
// Save the auth object to the client, for use by other methods.
127120
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
128121

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

263261
/**
264262
* The DNS address for this API service.
263+
* @returns {string} The DNS address for this service.
265264
*/
266265
static get servicePath() {
267266
return 'monitoring.googleapis.com';
@@ -270,13 +269,15 @@ export class DashboardsServiceClient {
270269
/**
271270
* The DNS address for this API service - same as servicePath(),
272271
* exists for compatibility reasons.
272+
* @returns {string} The DNS address for this service.
273273
*/
274274
static get apiEndpoint() {
275275
return 'monitoring.googleapis.com';
276276
}
277277

278278
/**
279279
* The port for this API service.
280+
* @returns {number} The default port for this service.
280281
*/
281282
static get port() {
282283
return 443;
@@ -285,6 +286,7 @@ export class DashboardsServiceClient {
285286
/**
286287
* The scopes needed to make gRPC calls for every method defined
287288
* in this service.
289+
* @returns {string[]} List of default scopes.
288290
*/
289291
static get scopes() {
290292
return [
@@ -299,8 +301,7 @@ export class DashboardsServiceClient {
299301
getProjectId(callback: Callback<string, undefined, undefined>): void;
300302
/**
301303
* Return the project ID used by this class.
302-
* @param {function(Error, string)} callback - the callback to
303-
* be called with the current project Id.
304+
* @returns {Promise} A promise that resolves to string containing the project ID.
304305
*/
305306
getProjectId(
306307
callback?: Callback<string, undefined, undefined>
@@ -367,7 +368,11 @@ export class DashboardsServiceClient {
367368
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
368369
* @returns {Promise} - The promise which resolves to an array.
369370
* The first element of the array is an object representing [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard}.
370-
* The promise has a method named "cancel" which cancels the ongoing API call.
371+
* Please see the
372+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
373+
* for more details and examples.
374+
* @example
375+
* const [response] = await client.createDashboard(request);
371376
*/
372377
createDashboard(
373378
request: protos.google.monitoring.dashboard.v1.ICreateDashboardRequest,
@@ -463,7 +468,11 @@ export class DashboardsServiceClient {
463468
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
464469
* @returns {Promise} - The promise which resolves to an array.
465470
* The first element of the array is an object representing [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard}.
466-
* The promise has a method named "cancel" which cancels the ongoing API call.
471+
* Please see the
472+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
473+
* for more details and examples.
474+
* @example
475+
* const [response] = await client.getDashboard(request);
467476
*/
468477
getDashboard(
469478
request: protos.google.monitoring.dashboard.v1.IGetDashboardRequest,
@@ -557,7 +566,11 @@ export class DashboardsServiceClient {
557566
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
558567
* @returns {Promise} - The promise which resolves to an array.
559568
* The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}.
560-
* The promise has a method named "cancel" which cancels the ongoing API call.
569+
* Please see the
570+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
571+
* for more details and examples.
572+
* @example
573+
* const [response] = await client.deleteDashboard(request);
561574
*/
562575
deleteDashboard(
563576
request: protos.google.monitoring.dashboard.v1.IDeleteDashboardRequest,
@@ -649,7 +662,11 @@ export class DashboardsServiceClient {
649662
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
650663
* @returns {Promise} - The promise which resolves to an array.
651664
* The first element of the array is an object representing [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard}.
652-
* The promise has a method named "cancel" which cancels the ongoing API call.
665+
* Please see the
666+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
667+
* for more details and examples.
668+
* @example
669+
* const [response] = await client.updateDashboard(request);
653670
*/
654671
updateDashboard(
655672
request: protos.google.monitoring.dashboard.v1.IUpdateDashboardRequest,
@@ -751,19 +768,14 @@ export class DashboardsServiceClient {
751768
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
752769
* @returns {Promise} - The promise which resolves to an array.
753770
* The first element of the array is Array of [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard}.
754-
* The client library support auto-pagination by default: it will call the API as many
771+
* The client library will perform auto-pagination by default: it will call the API as many
755772
* times as needed and will merge results from all the pages into this array.
756-
*
757-
* When autoPaginate: false is specified through options, the array has three elements.
758-
* The first element is Array of [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard} that corresponds to
759-
* the one page received from the API server.
760-
* If the second element is not null it contains the request object of type [ListDashboardsRequest]{@link google.monitoring.dashboard.v1.ListDashboardsRequest}
761-
* that can be used to obtain the next page of the results.
762-
* If it is null, the next page does not exist.
763-
* The third element contains the raw response received from the API server. Its type is
764-
* [ListDashboardsResponse]{@link google.monitoring.dashboard.v1.ListDashboardsResponse}.
765-
*
766-
* The promise has a method named "cancel" which cancels the ongoing API call.
773+
* Note that it can affect your quota.
774+
* We recommend using `listDashboardsAsync()`
775+
* method described below for async iteration which you can stop as needed.
776+
* Please see the
777+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
778+
* for more details and examples.
767779
*/
768780
listDashboards(
769781
request: protos.google.monitoring.dashboard.v1.IListDashboardsRequest,
@@ -811,18 +823,7 @@ export class DashboardsServiceClient {
811823
}
812824

813825
/**
814-
* Equivalent to {@link listDashboards}, but returns a NodeJS Stream object.
815-
*
816-
* This fetches the paged responses for {@link listDashboards} continuously
817-
* and invokes the callback registered for 'data' event for each element in the
818-
* responses.
819-
*
820-
* The returned object has 'end' method when no more elements are required.
821-
*
822-
* autoPaginate option will be ignored.
823-
*
824-
* @see {@link https://nodejs.org/api/stream.html}
825-
*
826+
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
826827
* @param {Object} request
827828
* The request object that will be sent.
828829
* @param {string} request.parent
@@ -840,6 +841,13 @@ export class DashboardsServiceClient {
840841
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
841842
* @returns {Stream}
842843
* An object stream which emits an object representing [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard} on 'data' event.
844+
* The client library will perform auto-pagination by default: it will call the API as many
845+
* times as needed. Note that it can affect your quota.
846+
* We recommend using `listDashboardsAsync()`
847+
* method described below for async iteration which you can stop as needed.
848+
* Please see the
849+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
850+
* for more details and examples.
843851
*/
844852
listDashboardsStream(
845853
request?: protos.google.monitoring.dashboard.v1.IListDashboardsRequest,
@@ -864,10 +872,9 @@ export class DashboardsServiceClient {
864872
}
865873

866874
/**
867-
* Equivalent to {@link listDashboards}, but returns an iterable object.
868-
*
869-
* for-await-of syntax is used with the iterable to recursively get response element on-demand.
875+
* Equivalent to `listDashboards`, but returns an iterable object.
870876
*
877+
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
871878
* @param {Object} request
872879
* The request object that will be sent.
873880
* @param {string} request.parent
@@ -884,7 +891,18 @@ export class DashboardsServiceClient {
884891
* @param {object} [options]
885892
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
886893
* @returns {Object}
887-
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
894+
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
895+
* When you iterate the returned iterable, each element will be an object representing
896+
* [Dashboard]{@link google.monitoring.dashboard.v1.Dashboard}. The API will be called under the hood as needed, once per the page,
897+
* so you can stop the iteration when you don't need more results.
898+
* Please see the
899+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
900+
* for more details and examples.
901+
* @example
902+
* const iterable = client.listDashboardsAsync(request);
903+
* for await (const response of iterable) {
904+
* // process response
905+
* }
888906
*/
889907
listDashboardsAsync(
890908
request?: protos.google.monitoring.dashboard.v1.IListDashboardsRequest,
@@ -974,9 +992,10 @@ export class DashboardsServiceClient {
974992
}
975993

976994
/**
977-
* Terminate the GRPC channel and close the client.
995+
* Terminate the gRPC channel and close the client.
978996
*
979997
* The client will no longer be usable and all future behavior is undefined.
998+
* @returns {Promise} A promise that resolves when the client is closed.
980999
*/
9811000
close(): Promise<void> {
9821001
this.initialize();

packages/google-monitoring-dashboard/synth.metadata

+5-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
{
44
"git": {
55
"name": ".",
6-
"remote": "https://github.com/googleapis/nodejs-monitoring-dashboards.git",
7-
"sha": "f0e52f5f94e4db1ccaa4c7d7258358a4362ee11e"
8-
}
9-
},
10-
{
11-
"git": {
12-
"name": "googleapis",
13-
"remote": "https://github.com/googleapis/googleapis.git",
14-
"sha": "4c5071b615d96ef9dfd6a63d8429090f1f2872bb",
15-
"internalRef": "327369997"
6+
"remote": "[email protected]:googleapis/nodejs-monitoring-dashboards.git",
7+
"sha": "e167bd3589436f617422a665496934bd5f89f4cc"
168
}
179
},
1810
{
1911
"git": {
2012
"name": "synthtool",
2113
"remote": "https://github.com/googleapis/synthtool.git",
22-
"sha": "ba9918cd22874245b55734f57470c719b577e591"
14+
"sha": "1f1148d3c7a7a52f0c98077f976bd9b3c948ee2b"
2315
}
2416
}
2517
],
@@ -86,6 +78,7 @@
8678
"README.md",
8779
"api-extractor.json",
8880
"linkinator.config.json",
81+
"package-lock.json.3928346606",
8982
"protos/google/monitoring/dashboard/v1/common.proto",
9083
"protos/google/monitoring/dashboard/v1/dashboard.proto",
9184
"protos/google/monitoring/dashboard/v1/dashboards_service.proto",
@@ -102,6 +95,7 @@
10295
"protos/protos.json",
10396
"renovate.json",
10497
"samples/README.md",
98+
"samples/package-lock.json.3115811802",
10599
"src/index.ts",
106100
"src/v1/dashboards_service_client.ts",
107101
"src/v1/dashboards_service_client_config.json",

packages/google-monitoring-dashboard/system-test/fixtures/sample/src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818

1919
import {DashboardsServiceClient} from '@google-cloud/monitoring-dashboards';
2020

21+
// check that the client class type name can be used
22+
function doStuffWithDashboardsServiceClient(client: DashboardsServiceClient) {
23+
client.close();
24+
}
25+
2126
function main() {
22-
new DashboardsServiceClient();
27+
// check that the client instance can be created
28+
const dashboardsServiceClient = new DashboardsServiceClient();
29+
doStuffWithDashboardsServiceClient(dashboardsServiceClient);
2330
}
2431

2532
main();

0 commit comments

Comments
 (0)