@@ -61,8 +61,10 @@ export class PredictionServiceClient {
61
61
/**
62
62
* Construct an instance of PredictionServiceClient.
63
63
*
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:
66
68
* @param {object } [options.credentials] - Credentials object.
67
69
* @param {string } [options.credentials.client_email]
68
70
* @param {string } [options.credentials.private_key]
@@ -82,42 +84,33 @@ export class PredictionServiceClient {
82
84
* your project ID will be detected automatically.
83
85
* @param {string } [options.apiEndpoint] - The domain name of the
84
86
* 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.
85
94
*/
86
-
87
95
constructor ( opts ?: ClientOptions ) {
88
- // Ensure that options include the service address and port .
96
+ // Ensure that options include all the required fields .
89
97
const staticMembers = this . constructor as typeof PredictionServiceClient ;
90
98
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 ;
100
108
}
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 PredictionServiceClient constructor.
109
+
110
+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
116
111
this . _gaxModule = opts . fallback ? gax . fallback : gax ;
117
112
118
- // Create a `gaxGrpc` object, with any grpc-specific options
119
- // sent to the client.
120
- opts . scopes = ( this . constructor as typeof PredictionServiceClient ) . scopes ;
113
+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
121
114
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
122
115
123
116
// Save options to use in initialize() method.
@@ -126,6 +119,11 @@ export class PredictionServiceClient {
126
119
// Save the auth object to the client, for use by other methods.
127
120
this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ;
128
121
122
+ // Set the default scopes in auth client if needed.
123
+ if ( servicePath === staticMembers . servicePath ) {
124
+ this . auth . defaultScopes = staticMembers . scopes ;
125
+ }
126
+
129
127
// Determine the client header string.
130
128
const clientHeader = [ `gax/${ this . _gaxModule . version } ` , `gapic/${ version } ` ] ;
131
129
if ( typeof process !== 'undefined' && 'versions' in process ) {
@@ -281,6 +279,7 @@ export class PredictionServiceClient {
281
279
282
280
/**
283
281
* The DNS address for this API service.
282
+ * @returns {string } The DNS address for this service.
284
283
*/
285
284
static get servicePath ( ) {
286
285
return 'automl.googleapis.com' ;
@@ -289,13 +288,15 @@ export class PredictionServiceClient {
289
288
/**
290
289
* The DNS address for this API service - same as servicePath(),
291
290
* exists for compatibility reasons.
291
+ * @returns {string } The DNS address for this service.
292
292
*/
293
293
static get apiEndpoint ( ) {
294
294
return 'automl.googleapis.com' ;
295
295
}
296
296
297
297
/**
298
298
* The port for this API service.
299
+ * @returns {number } The default port for this service.
299
300
*/
300
301
static get port ( ) {
301
302
return 443 ;
@@ -304,6 +305,7 @@ export class PredictionServiceClient {
304
305
/**
305
306
* The scopes needed to make gRPC calls for every method defined
306
307
* in this service.
308
+ * @returns {string[] } List of default scopes.
307
309
*/
308
310
static get scopes ( ) {
309
311
return [ 'https://www.googleapis.com/auth/cloud-platform' ] ;
@@ -313,8 +315,7 @@ export class PredictionServiceClient {
313
315
getProjectId ( callback : Callback < string , undefined , undefined > ) : void ;
314
316
/**
315
317
* Return the project ID used by this class.
316
- * @param {function(Error, string) } callback - the callback to
317
- * be called with the current project Id.
318
+ * @returns {Promise } A promise that resolves to string containing the project ID.
318
319
*/
319
320
getProjectId (
320
321
callback ?: Callback < string , undefined , undefined >
@@ -437,7 +438,11 @@ export class PredictionServiceClient {
437
438
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
438
439
* @returns {Promise } - The promise which resolves to an array.
439
440
* The first element of the array is an object representing [PredictResponse]{@link google.cloud.automl.v1.PredictResponse}.
440
- * The promise has a method named "cancel" which cancels the ongoing API call.
441
+ * Please see the
442
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
443
+ * for more details and examples.
444
+ * @example
445
+ * const [response] = await client.predict(request);
441
446
*/
442
447
predict (
443
448
request : protos . google . cloud . automl . v1 . IPredictRequest ,
@@ -630,8 +635,15 @@ export class PredictionServiceClient {
630
635
* @param {object } [options]
631
636
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
632
637
* @returns {Promise } - The promise which resolves to an array.
633
- * The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
634
- * The promise has a method named "cancel" which cancels the ongoing API call.
638
+ * The first element of the array is an object representing
639
+ * a long running operation. Its `promise()` method returns a promise
640
+ * you can `await` for.
641
+ * Please see the
642
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
643
+ * for more details and examples.
644
+ * @example
645
+ * const [operation] = await client.batchPredict(request);
646
+ * const [response] = await operation.promise();
635
647
*/
636
648
batchPredict (
637
649
request : protos . google . cloud . automl . v1 . IBatchPredictRequest ,
@@ -683,18 +695,19 @@ export class PredictionServiceClient {
683
695
return this . innerApiCalls . batchPredict ( request , options , callback ) ;
684
696
}
685
697
/**
686
- * Check the status of the long running operation returned by the batchPredict() method .
698
+ * Check the status of the long running operation returned by ` batchPredict()` .
687
699
* @param {String } name
688
700
* The operation name that will be passed.
689
701
* @returns {Promise } - The promise which resolves to an object.
690
702
* The decoded operation object has result and metadata field to get information from.
691
- *
692
- * @example :
693
- * const decodedOperation = await checkBatchPredictProgress(name);
694
- * console.log(decodedOperation.result);
695
- * console.log(decodedOperation.done);
696
- * console.log(decodedOperation.metadata);
697
- *
703
+ * Please see the
704
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
705
+ * for more details and examples.
706
+ * @example
707
+ * const decodedOperation = await checkBatchPredictProgress(name);
708
+ * console.log(decodedOperation.result);
709
+ * console.log(decodedOperation.done);
710
+ * console.log(decodedOperation.metadata);
698
711
*/
699
712
async checkBatchPredictProgress (
700
713
name : string
@@ -971,9 +984,10 @@ export class PredictionServiceClient {
971
984
}
972
985
973
986
/**
974
- * Terminate the GRPC channel and close the client.
987
+ * Terminate the gRPC channel and close the client.
975
988
*
976
989
* The client will no longer be usable and all future behavior is undefined.
990
+ * @returns {Promise } A promise that resolves when the client is closed.
977
991
*/
978
992
close ( ) : Promise < void > {
979
993
this . initialize ( ) ;
0 commit comments