@@ -44,8 +44,13 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
44
44
private _innerApiCalls : { [ name : string ] : Function } ;
45
45
private _pathTemplates : { [ name : string ] : gax . PathTemplate } ;
46
46
private _terminated = false ;
47
+ private _opts : ClientOptions ;
48
+ private _gaxModule : typeof gax | typeof gax . fallback ;
49
+ private _gaxGrpc : gax . GrpcClient | gax . fallback . GrpcClient ;
50
+ private _protos : { } ;
51
+ private _defaults : { [ method : string ] : gax . CallSettings } ;
47
52
auth : gax . GoogleAuth ;
48
- recaptchaEnterpriseServiceV1Beta1Stub : Promise < { [ name : string ] : Function } > ;
53
+ recaptchaEnterpriseServiceV1Beta1Stub ? : Promise < { [ name : string ] : Function } > ;
49
54
50
55
/**
51
56
* Construct an instance of RecaptchaEnterpriseServiceV1Beta1Client.
@@ -69,8 +74,6 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
69
74
* app is running in an environment which supports
70
75
* {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
71
76
* your project ID will be detected automatically.
72
- * @param {function } [options.promise] - Custom promise module to use instead
73
- * of native Promises.
74
77
* @param {string } [options.apiEndpoint] - The domain name of the
75
78
* API remote host.
76
79
*/
@@ -101,26 +104,29 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
101
104
// If we are in browser, we are already using fallback because of the
102
105
// "browser" field in package.json.
103
106
// But if we were explicitly requested to use fallback, let's do it now.
104
- const gaxModule = ! isBrowser && opts . fallback ? gax . fallback : gax ;
107
+ this . _gaxModule = ! isBrowser && opts . fallback ? gax . fallback : gax ;
105
108
106
109
// Create a `gaxGrpc` object, with any grpc-specific options
107
110
// sent to the client.
108
111
opts . scopes = ( this
109
112
. constructor as typeof RecaptchaEnterpriseServiceV1Beta1Client ) . scopes ;
110
- const gaxGrpc = new gaxModule . GrpcClient ( opts ) ;
113
+ this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
114
+
115
+ // Save options to use in initialize() method.
116
+ this . _opts = opts ;
111
117
112
118
// Save the auth object to the client, for use by other methods.
113
- this . auth = gaxGrpc . auth as gax . GoogleAuth ;
119
+ this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ;
114
120
115
121
// Determine the client header string.
116
- const clientHeader = [ `gax/${ gaxModule . version } ` , `gapic/${ version } ` ] ;
122
+ const clientHeader = [ `gax/${ this . _gaxModule . version } ` , `gapic/${ version } ` ] ;
117
123
if ( typeof process !== 'undefined' && 'versions' in process ) {
118
124
clientHeader . push ( `gl-node/${ process . versions . node } ` ) ;
119
125
} else {
120
- clientHeader . push ( `gl-web/${ gaxModule . version } ` ) ;
126
+ clientHeader . push ( `gl-web/${ this . _gaxModule . version } ` ) ;
121
127
}
122
128
if ( ! opts . fallback ) {
123
- clientHeader . push ( `grpc/${ gaxGrpc . grpcVersion } ` ) ;
129
+ clientHeader . push ( `grpc/${ this . _gaxGrpc . grpcVersion } ` ) ;
124
130
}
125
131
if ( opts . libName && opts . libVersion ) {
126
132
clientHeader . push ( `${ opts . libName } /${ opts . libVersion } ` ) ;
@@ -136,36 +142,38 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
136
142
'protos' ,
137
143
'protos.json'
138
144
) ;
139
- const protos = gaxGrpc . loadProto (
145
+ this . _protos = this . _gaxGrpc . loadProto (
140
146
opts . fallback ? require ( '../../protos/protos.json' ) : nodejsProtoPath
141
147
) ;
142
148
143
149
// This API contains "path templates"; forward-slash-separated
144
150
// identifiers to uniquely identify resources within the API.
145
151
// Create useful helper objects for these.
146
152
this . _pathTemplates = {
147
- assessmentPathTemplate : new gaxModule . PathTemplate (
153
+ assessmentPathTemplate : new this . _gaxModule . PathTemplate (
148
154
'projects/{project}/assessments/{assessment}'
149
155
) ,
150
- keyPathTemplate : new gaxModule . PathTemplate (
156
+ keyPathTemplate : new this . _gaxModule . PathTemplate (
151
157
'projects/{project}/keys/{key}'
152
158
) ,
153
- projectPathTemplate : new gaxModule . PathTemplate ( 'projects/{project}' ) ,
159
+ projectPathTemplate : new this . _gaxModule . PathTemplate (
160
+ 'projects/{project}'
161
+ ) ,
154
162
} ;
155
163
156
164
// Some of the methods on this service return "paged" results,
157
165
// (e.g. 50 results at a time, with tokens to get subsequent
158
166
// pages). Denote the keys used for pagination and results.
159
167
this . _descriptors . page = {
160
- listKeys : new gaxModule . PageDescriptor (
168
+ listKeys : new this . _gaxModule . PageDescriptor (
161
169
'pageToken' ,
162
170
'nextPageToken' ,
163
171
'keys'
164
172
) ,
165
173
} ;
166
174
167
175
// Put together the default options sent with requests.
168
- const defaults = gaxGrpc . constructSettings (
176
+ this . _defaults = this . _gaxGrpc . constructSettings (
169
177
'google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1' ,
170
178
gapicConfig as gax . ClientConfig ,
171
179
opts . clientConfig || { } ,
@@ -176,18 +184,36 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
176
184
// of calling the API is handled in `google-gax`, with this code
177
185
// merely providing the destination and request information.
178
186
this . _innerApiCalls = { } ;
187
+ }
188
+
189
+ /**
190
+ * Initialize the client.
191
+ * Performs asynchronous operations (such as authentication) and prepares the client.
192
+ * This function will be called automatically when any class method is called for the
193
+ * first time, but if you need to initialize it before calling an actual method,
194
+ * feel free to call initialize() directly.
195
+ *
196
+ * You can await on this method if you want to make sure the client is initialized.
197
+ *
198
+ * @returns {Promise } A promise that resolves to an authenticated service stub.
199
+ */
200
+ initialize ( ) {
201
+ // If the client stub promise is already initialized, return immediately.
202
+ if ( this . recaptchaEnterpriseServiceV1Beta1Stub ) {
203
+ return this . recaptchaEnterpriseServiceV1Beta1Stub ;
204
+ }
179
205
180
206
// Put together the "service stub" for
181
207
// google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1.
182
- this . recaptchaEnterpriseServiceV1Beta1Stub = gaxGrpc . createStub (
183
- opts . fallback
184
- ? ( protos as protobuf . Root ) . lookupService (
208
+ this . recaptchaEnterpriseServiceV1Beta1Stub = this . _gaxGrpc . createStub (
209
+ this . _opts . fallback
210
+ ? ( this . _protos as protobuf . Root ) . lookupService (
185
211
'google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1'
186
212
)
187
213
: // tslint:disable-next-line no-any
188
- ( protos as any ) . google . cloud . recaptchaenterprise . v1beta1
214
+ ( this . _protos as any ) . google . cloud . recaptchaenterprise . v1beta1
189
215
. RecaptchaEnterpriseServiceV1Beta1 ,
190
- opts
216
+ this . _opts
191
217
) as Promise < { [ method : string ] : Function } > ;
192
218
193
219
// Iterate over each of the methods that the service provides
@@ -215,9 +241,9 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
215
241
}
216
242
) ;
217
243
218
- const apiCall = gaxModule . createApiCall (
244
+ const apiCall = this . _gaxModule . createApiCall (
219
245
innerCallPromise ,
220
- defaults [ methodName ] ,
246
+ this . _defaults [ methodName ] ,
221
247
this . _descriptors . page [ methodName ] ||
222
248
this . _descriptors . stream [ methodName ] ||
223
249
this . _descriptors . longrunning [ methodName ]
@@ -231,6 +257,8 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
231
257
return apiCall ( argument , callOptions , callback ) ;
232
258
} ;
233
259
}
260
+
261
+ return this . recaptchaEnterpriseServiceV1Beta1Stub ;
234
262
}
235
263
236
264
/**
@@ -364,6 +392,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
364
392
] = gax . routingHeader . fromParams ( {
365
393
parent : request . parent || '' ,
366
394
} ) ;
395
+ this . initialize ( ) ;
367
396
return this . _innerApiCalls . createAssessment ( request , options , callback ) ;
368
397
}
369
398
annotateAssessment (
@@ -448,6 +477,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
448
477
] = gax . routingHeader . fromParams ( {
449
478
name : request . name || '' ,
450
479
} ) ;
480
+ this . initialize ( ) ;
451
481
return this . _innerApiCalls . annotateAssessment ( request , options , callback ) ;
452
482
}
453
483
createKey (
@@ -531,6 +561,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
531
561
] = gax . routingHeader . fromParams ( {
532
562
parent : request . parent || '' ,
533
563
} ) ;
564
+ this . initialize ( ) ;
534
565
return this . _innerApiCalls . createKey ( request , options , callback ) ;
535
566
}
536
567
getKey (
@@ -612,6 +643,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
612
643
] = gax . routingHeader . fromParams ( {
613
644
name : request . name || '' ,
614
645
} ) ;
646
+ this . initialize ( ) ;
615
647
return this . _innerApiCalls . getKey ( request , options , callback ) ;
616
648
}
617
649
updateKey (
@@ -695,6 +727,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
695
727
] = gax . routingHeader . fromParams ( {
696
728
'key.name' : request . key ! . name || '' ,
697
729
} ) ;
730
+ this . initialize ( ) ;
698
731
return this . _innerApiCalls . updateKey ( request , options , callback ) ;
699
732
}
700
733
deleteKey (
@@ -776,6 +809,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
776
809
] = gax . routingHeader . fromParams ( {
777
810
name : request . name || '' ,
778
811
} ) ;
812
+ this . initialize ( ) ;
779
813
return this . _innerApiCalls . deleteKey ( request , options , callback ) ;
780
814
}
781
815
@@ -867,6 +901,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
867
901
] = gax . routingHeader . fromParams ( {
868
902
parent : request . parent || '' ,
869
903
} ) ;
904
+ this . initialize ( ) ;
870
905
return this . _innerApiCalls . listKeys ( request , options , callback ) ;
871
906
}
872
907
@@ -913,6 +948,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
913
948
parent : request . parent || '' ,
914
949
} ) ;
915
950
const callSettings = new gax . CallSettings ( options ) ;
951
+ this . initialize ( ) ;
916
952
return this . _descriptors . page . listKeys . createStream (
917
953
this . _innerApiCalls . listKeys as gax . GaxCall ,
918
954
request ,
@@ -1026,8 +1062,9 @@ export class RecaptchaEnterpriseServiceV1Beta1Client {
1026
1062
* The client will no longer be usable and all future behavior is undefined.
1027
1063
*/
1028
1064
close ( ) : Promise < void > {
1065
+ this . initialize ( ) ;
1029
1066
if ( ! this . _terminated ) {
1030
- return this . recaptchaEnterpriseServiceV1Beta1Stub . then ( stub => {
1067
+ return this . recaptchaEnterpriseServiceV1Beta1Stub ! . then ( stub => {
1031
1068
this . _terminated = true ;
1032
1069
stub . close ( ) ;
1033
1070
} ) ;
0 commit comments