@@ -62,8 +62,10 @@ export class CloudCatalogClient {
6262 /**
6363 * Construct an instance of CloudCatalogClient.
6464 *
65- * @param {object } [options] - The configuration object. See the subsequent
66- * parameters for more details.
65+ * @param {object } [options] - The configuration object.
66+ * The options accepted by the constructor are described in detail
67+ * in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
68+ * The common options are:
6769 * @param {object } [options.credentials] - Credentials object.
6870 * @param {string } [options.credentials.client_email]
6971 * @param {string } [options.credentials.private_key]
@@ -83,42 +85,33 @@ export class CloudCatalogClient {
8385 * your project ID will be detected automatically.
8486 * @param {string } [options.apiEndpoint] - The domain name of the
8587 * API remote host.
88+ * @param {gax.ClientConfig } [options.clientConfig] - client configuration override.
89+ * TODO(@alexander-fenster): link to gax documentation.
90+ * @param {boolean } fallback - Use HTTP fallback mode.
91+ * In fallback mode, a special browser-compatible transport implementation is used
92+ * instead of gRPC transport. In browser context (if the `window` object is defined)
93+ * the fallback mode is enabled automatically; set `options.fallback` to `false`
94+ * if you need to override this behavior.
8695 */
87-
8896 constructor ( opts ?: ClientOptions ) {
89- // Ensure that options include the service address and port .
97+ // Ensure that options include all the required fields .
9098 const staticMembers = this . constructor as typeof CloudCatalogClient ;
9199 const servicePath =
92- opts && opts . servicePath
93- ? opts . servicePath
94- : opts && opts . apiEndpoint
95- ? opts . apiEndpoint
96- : staticMembers . servicePath ;
97- const port = opts && opts . port ? opts . port : staticMembers . port ;
98-
99- if ( ! opts ) {
100- opts = { servicePath , port } ;
100+ opts ?. servicePath || opts ?. apiEndpoint || staticMembers . servicePath ;
101+ const port = opts ?. port || staticMembers . port ;
102+ const clientConfig = opts ?. clientConfig ?? { } ;
103+ const fallback = opts ?. fallback ?? typeof window !== 'undefined' ;
104+ opts = Object . assign ( { servicePath , port , clientConfig , fallback } , opts ) ;
105+
106+ // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
107+ if ( servicePath !== staticMembers . servicePath && ! ( 'scopes' in opts ) ) {
108+ opts [ 'scopes' ] = staticMembers . scopes ;
101109 }
102- opts . servicePath = opts . servicePath || servicePath ;
103- opts . port = opts . port || port ;
104-
105- // users can override the config from client side, like retry codes name.
106- // The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
107- // The way to override client config for Showcase API:
108- //
109- // const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
110- // const showcaseClient = new showcaseClient({ projectId, customConfig });
111- opts . clientConfig = opts . clientConfig || { } ;
112-
113- // If we're running in browser, it's OK to omit `fallback` since
114- // google-gax has `browser` field in its `package.json`.
115- // For Electron (which does not respect `browser` field),
116- // pass `{fallback: true}` to the CloudCatalogClient constructor.
110+
111+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
117112 this . _gaxModule = opts . fallback ? gax . fallback : gax ;
118113
119- // Create a `gaxGrpc` object, with any grpc-specific options
120- // sent to the client.
121- opts . scopes = ( this . constructor as typeof CloudCatalogClient ) . scopes ;
114+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
122115 this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
123116
124117 // Save options to use in initialize() method.
@@ -127,6 +120,11 @@ export class CloudCatalogClient {
127120 // Save the auth object to the client, for use by other methods.
128121 this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ;
129122
123+ // Set the default scopes in auth client if needed.
124+ if ( servicePath === staticMembers . servicePath ) {
125+ this . auth . defaultScopes = staticMembers . scopes ;
126+ }
127+
130128 // Determine the client header string.
131129 const clientHeader = [ `gax/${ this . _gaxModule . version } ` , `gapic/${ version } ` ] ;
132130 if ( typeof process !== 'undefined' && 'versions' in process ) {
@@ -261,6 +259,7 @@ export class CloudCatalogClient {
261259
262260 /**
263261 * The DNS address for this API service.
262+ * @returns {string } The DNS address for this service.
264263 */
265264 static get servicePath ( ) {
266265 return 'cloudbilling.googleapis.com' ;
@@ -269,13 +268,15 @@ export class CloudCatalogClient {
269268 /**
270269 * The DNS address for this API service - same as servicePath(),
271270 * exists for compatibility reasons.
271+ * @returns {string } The DNS address for this service.
272272 */
273273 static get apiEndpoint ( ) {
274274 return 'cloudbilling.googleapis.com' ;
275275 }
276276
277277 /**
278278 * The port for this API service.
279+ * @returns {number } The default port for this service.
279280 */
280281 static get port ( ) {
281282 return 443 ;
@@ -284,6 +285,7 @@ export class CloudCatalogClient {
284285 /**
285286 * The scopes needed to make gRPC calls for every method defined
286287 * in this service.
288+ * @returns {string[] } List of default scopes.
287289 */
288290 static get scopes ( ) {
289291 return [ 'https://www.googleapis.com/auth/cloud-platform' ] ;
@@ -293,8 +295,7 @@ export class CloudCatalogClient {
293295 getProjectId ( callback : Callback < string , undefined , undefined > ) : void ;
294296 /**
295297 * Return the project ID used by this class.
296- * @param {function(Error, string) } callback - the callback to
297- * be called with the current project Id.
298+ * @returns {Promise } A promise that resolves to string containing the project ID.
298299 */
299300 getProjectId (
300301 callback ?: Callback < string , undefined , undefined >
@@ -352,19 +353,14 @@ export class CloudCatalogClient {
352353 * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
353354 * @returns {Promise } - The promise which resolves to an array.
354355 * The first element of the array is Array of [Service]{@link google.cloud.billing.v1.Service}.
355- * The client library support auto-pagination by default: it will call the API as many
356+ * The client library will perform auto-pagination by default: it will call the API as many
356357 * times as needed and will merge results from all the pages into this array.
357- *
358- * When autoPaginate: false is specified through options, the array has three elements.
359- * The first element is Array of [Service]{@link google.cloud.billing.v1.Service} that corresponds to
360- * the one page received from the API server.
361- * If the second element is not null it contains the request object of type [ListServicesRequest]{@link google.cloud.billing.v1.ListServicesRequest}
362- * that can be used to obtain the next page of the results.
363- * If it is null, the next page does not exist.
364- * The third element contains the raw response received from the API server. Its type is
365- * [ListServicesResponse]{@link google.cloud.billing.v1.ListServicesResponse}.
366- *
367- * The promise has a method named "cancel" which cancels the ongoing API call.
358+ * Note that it can affect your quota.
359+ * We recommend using `listServicesAsync()`
360+ * method described below for async iteration which you can stop as needed.
361+ * Please see the
362+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
363+ * for more details and examples.
368364 */
369365 listServices (
370366 request : protos . google . cloud . billing . v1 . IListServicesRequest ,
@@ -403,18 +399,7 @@ export class CloudCatalogClient {
403399 }
404400
405401 /**
406- * Equivalent to {@link listServices}, but returns a NodeJS Stream object.
407- *
408- * This fetches the paged responses for {@link listServices} continuously
409- * and invokes the callback registered for 'data' event for each element in the
410- * responses.
411- *
412- * The returned object has 'end' method when no more elements are required.
413- *
414- * autoPaginate option will be ignored.
415- *
416- * @see {@link https://nodejs.org/api/stream.html }
417- *
402+ * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
418403 * @param {Object } request
419404 * The request object that will be sent.
420405 * @param {number } request.pageSize
@@ -427,6 +412,13 @@ export class CloudCatalogClient {
427412 * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
428413 * @returns {Stream }
429414 * An object stream which emits an object representing [Service]{@link google.cloud.billing.v1.Service} on 'data' event.
415+ * The client library will perform auto-pagination by default: it will call the API as many
416+ * times as needed. Note that it can affect your quota.
417+ * We recommend using `listServicesAsync()`
418+ * method described below for async iteration which you can stop as needed.
419+ * Please see the
420+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
421+ * for more details and examples.
430422 */
431423 listServicesStream (
432424 request ?: protos . google . cloud . billing . v1 . IListServicesRequest ,
@@ -444,10 +436,9 @@ export class CloudCatalogClient {
444436 }
445437
446438 /**
447- * Equivalent to {@link listServices}, but returns an iterable object.
448- *
449- * for-await-of syntax is used with the iterable to recursively get response element on-demand.
439+ * Equivalent to `listServices`, but returns an iterable object.
450440 *
441+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
451442 * @param {Object } request
452443 * The request object that will be sent.
453444 * @param {number } request.pageSize
@@ -459,7 +450,18 @@ export class CloudCatalogClient {
459450 * @param {object } [options]
460451 * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
461452 * @returns {Object }
462- * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
453+ * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
454+ * When you iterate the returned iterable, each element will be an object representing
455+ * [Service]{@link google.cloud.billing.v1.Service}. The API will be called under the hood as needed, once per the page,
456+ * so you can stop the iteration when you don't need more results.
457+ * Please see the
458+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
459+ * for more details and examples.
460+ * @example
461+ * const iterable = client.listServicesAsync(request);
462+ * for await (const response of iterable) {
463+ * // process response
464+ * }
463465 */
464466 listServicesAsync (
465467 request ?: protos . google . cloud . billing . v1 . IListServicesRequest ,
@@ -539,19 +541,14 @@ export class CloudCatalogClient {
539541 * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
540542 * @returns {Promise } - The promise which resolves to an array.
541543 * The first element of the array is Array of [Sku]{@link google.cloud.billing.v1.Sku}.
542- * The client library support auto-pagination by default: it will call the API as many
544+ * The client library will perform auto-pagination by default: it will call the API as many
543545 * times as needed and will merge results from all the pages into this array.
544- *
545- * When autoPaginate: false is specified through options, the array has three elements.
546- * The first element is Array of [Sku]{@link google.cloud.billing.v1.Sku} that corresponds to
547- * the one page received from the API server.
548- * If the second element is not null it contains the request object of type [ListSkusRequest]{@link google.cloud.billing.v1.ListSkusRequest}
549- * that can be used to obtain the next page of the results.
550- * If it is null, the next page does not exist.
551- * The third element contains the raw response received from the API server. Its type is
552- * [ListSkusResponse]{@link google.cloud.billing.v1.ListSkusResponse}.
553- *
554- * The promise has a method named "cancel" which cancels the ongoing API call.
546+ * Note that it can affect your quota.
547+ * We recommend using `listSkusAsync()`
548+ * method described below for async iteration which you can stop as needed.
549+ * Please see the
550+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
551+ * for more details and examples.
555552 */
556553 listSkus (
557554 request : protos . google . cloud . billing . v1 . IListSkusRequest ,
@@ -595,18 +592,7 @@ export class CloudCatalogClient {
595592 }
596593
597594 /**
598- * Equivalent to {@link listSkus}, but returns a NodeJS Stream object.
599- *
600- * This fetches the paged responses for {@link listSkus} continuously
601- * and invokes the callback registered for 'data' event for each element in the
602- * responses.
603- *
604- * The returned object has 'end' method when no more elements are required.
605- *
606- * autoPaginate option will be ignored.
607- *
608- * @see {@link https://nodejs.org/api/stream.html }
609- *
595+ * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
610596 * @param {Object } request
611597 * The request object that will be sent.
612598 * @param {string } request.parent
@@ -640,6 +626,13 @@ export class CloudCatalogClient {
640626 * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
641627 * @returns {Stream }
642628 * An object stream which emits an object representing [Sku]{@link google.cloud.billing.v1.Sku} on 'data' event.
629+ * The client library will perform auto-pagination by default: it will call the API as many
630+ * times as needed. Note that it can affect your quota.
631+ * We recommend using `listSkusAsync()`
632+ * method described below for async iteration which you can stop as needed.
633+ * Please see the
634+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
635+ * for more details and examples.
643636 */
644637 listSkusStream (
645638 request ?: protos . google . cloud . billing . v1 . IListSkusRequest ,
@@ -664,10 +657,9 @@ export class CloudCatalogClient {
664657 }
665658
666659 /**
667- * Equivalent to {@link listSkus}, but returns an iterable object.
668- *
669- * for-await-of syntax is used with the iterable to recursively get response element on-demand.
660+ * Equivalent to `listSkus`, but returns an iterable object.
670661 *
662+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
671663 * @param {Object } request
672664 * The request object that will be sent.
673665 * @param {string } request.parent
@@ -700,7 +692,18 @@ export class CloudCatalogClient {
700692 * @param {object } [options]
701693 * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
702694 * @returns {Object }
703- * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
695+ * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
696+ * When you iterate the returned iterable, each element will be an object representing
697+ * [Sku]{@link google.cloud.billing.v1.Sku}. The API will be called under the hood as needed, once per the page,
698+ * so you can stop the iteration when you don't need more results.
699+ * Please see the
700+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
701+ * for more details and examples.
702+ * @example
703+ * const iterable = client.listSkusAsync(request);
704+ * for await (const response of iterable) {
705+ * // process response
706+ * }
704707 */
705708 listSkusAsync (
706709 request ?: protos . google . cloud . billing . v1 . IListSkusRequest ,
@@ -788,9 +791,10 @@ export class CloudCatalogClient {
788791 }
789792
790793 /**
791- * Terminate the GRPC channel and close the client.
794+ * Terminate the gRPC channel and close the client.
792795 *
793796 * The client will no longer be usable and all future behavior is undefined.
797+ * @returns {Promise } A promise that resolves when the client is closed.
794798 */
795799 close ( ) : Promise < void > {
796800 this . initialize ( ) ;
0 commit comments