@@ -47,8 +47,13 @@ export class DataTransferServiceClient {
47
47
private _innerApiCalls : { [ name : string ] : Function } ;
48
48
private _pathTemplates : { [ name : string ] : gax . PathTemplate } ;
49
49
private _terminated = false ;
50
+ private _opts : ClientOptions ;
51
+ private _gaxModule : typeof gax | typeof gax . fallback ;
52
+ private _gaxGrpc : gax . GrpcClient | gax . fallback . GrpcClient ;
53
+ private _protos : { } ;
54
+ private _defaults : { [ method : string ] : gax . CallSettings } ;
50
55
auth : gax . GoogleAuth ;
51
- dataTransferServiceStub : Promise < { [ name : string ] : Function } > ;
56
+ dataTransferServiceStub ? : Promise < { [ name : string ] : Function } > ;
52
57
53
58
/**
54
59
* Construct an instance of DataTransferServiceClient.
@@ -72,8 +77,6 @@ export class DataTransferServiceClient {
72
77
* app is running in an environment which supports
73
78
* {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
74
79
* your project ID will be detected automatically.
75
- * @param {function } [options.promise] - Custom promise module to use instead
76
- * of native Promises.
77
80
* @param {string } [options.apiEndpoint] - The domain name of the
78
81
* API remote host.
79
82
*/
@@ -103,25 +106,28 @@ export class DataTransferServiceClient {
103
106
// If we are in browser, we are already using fallback because of the
104
107
// "browser" field in package.json.
105
108
// But if we were explicitly requested to use fallback, let's do it now.
106
- const gaxModule = ! isBrowser && opts . fallback ? gax . fallback : gax ;
109
+ this . _gaxModule = ! isBrowser && opts . fallback ? gax . fallback : gax ;
107
110
108
111
// Create a `gaxGrpc` object, with any grpc-specific options
109
112
// sent to the client.
110
113
opts . scopes = ( this . constructor as typeof DataTransferServiceClient ) . scopes ;
111
- const gaxGrpc = new gaxModule . GrpcClient ( opts ) ;
114
+ this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
115
+
116
+ // Save options to use in initialize() method.
117
+ this . _opts = opts ;
112
118
113
119
// Save the auth object to the client, for use by other methods.
114
- this . auth = gaxGrpc . auth as gax . GoogleAuth ;
120
+ this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ;
115
121
116
122
// Determine the client header string.
117
- const clientHeader = [ `gax/${ gaxModule . version } ` , `gapic/${ version } ` ] ;
123
+ const clientHeader = [ `gax/${ this . _gaxModule . version } ` , `gapic/${ version } ` ] ;
118
124
if ( typeof process !== 'undefined' && 'versions' in process ) {
119
125
clientHeader . push ( `gl-node/${ process . versions . node } ` ) ;
120
126
} else {
121
- clientHeader . push ( `gl-web/${ gaxModule . version } ` ) ;
127
+ clientHeader . push ( `gl-web/${ this . _gaxModule . version } ` ) ;
122
128
}
123
129
if ( ! opts . fallback ) {
124
- clientHeader . push ( `grpc/${ gaxGrpc . grpcVersion } ` ) ;
130
+ clientHeader . push ( `grpc/${ this . _gaxGrpc . grpcVersion } ` ) ;
125
131
}
126
132
if ( opts . libName && opts . libVersion ) {
127
133
clientHeader . push ( `${ opts . libName } /${ opts . libVersion } ` ) ;
@@ -137,31 +143,33 @@ export class DataTransferServiceClient {
137
143
'protos' ,
138
144
'protos.json'
139
145
) ;
140
- const protos = gaxGrpc . loadProto (
146
+ this . _protos = this . _gaxGrpc . loadProto (
141
147
opts . fallback ? require ( '../../protos/protos.json' ) : nodejsProtoPath
142
148
) ;
143
149
144
150
// This API contains "path templates"; forward-slash-separated
145
151
// identifiers to uniquely identify resources within the API.
146
152
// Create useful helper objects for these.
147
153
this . _pathTemplates = {
148
- projectPathTemplate : new gaxModule . PathTemplate ( 'projects/{project}' ) ,
149
- projectDataSourcePathTemplate : new gaxModule . PathTemplate (
154
+ projectPathTemplate : new this . _gaxModule . PathTemplate (
155
+ 'projects/{project}'
156
+ ) ,
157
+ projectDataSourcePathTemplate : new this . _gaxModule . PathTemplate (
150
158
'projects/{project}/dataSources/{data_source}'
151
159
) ,
152
- projectLocationDataSourcePathTemplate : new gaxModule . PathTemplate (
160
+ projectLocationDataSourcePathTemplate : new this . _gaxModule . PathTemplate (
153
161
'projects/{project}/locations/{location}/dataSources/{data_source}'
154
162
) ,
155
- projectLocationTransferConfigPathTemplate : new gaxModule . PathTemplate (
163
+ projectLocationTransferConfigPathTemplate : new this . _gaxModule . PathTemplate (
156
164
'projects/{project}/locations/{location}/transferConfigs/{transfer_config}'
157
165
) ,
158
- projectLocationTransferConfigRunPathTemplate : new gaxModule . PathTemplate (
166
+ projectLocationTransferConfigRunPathTemplate : new this . _gaxModule . PathTemplate (
159
167
'projects/{project}/locations/{location}/transferConfigs/{transfer_config}/runs/{run}'
160
168
) ,
161
- projectTransferConfigPathTemplate : new gaxModule . PathTemplate (
169
+ projectTransferConfigPathTemplate : new this . _gaxModule . PathTemplate (
162
170
'projects/{project}/transferConfigs/{transfer_config}'
163
171
) ,
164
- projectTransferConfigRunPathTemplate : new gaxModule . PathTemplate (
172
+ projectTransferConfigRunPathTemplate : new this . _gaxModule . PathTemplate (
165
173
'projects/{project}/transferConfigs/{transfer_config}/runs/{run}'
166
174
) ,
167
175
} ;
@@ -170,30 +178,30 @@ export class DataTransferServiceClient {
170
178
// (e.g. 50 results at a time, with tokens to get subsequent
171
179
// pages). Denote the keys used for pagination and results.
172
180
this . _descriptors . page = {
173
- listDataSources : new gaxModule . PageDescriptor (
181
+ listDataSources : new this . _gaxModule . PageDescriptor (
174
182
'pageToken' ,
175
183
'nextPageToken' ,
176
184
'dataSources'
177
185
) ,
178
- listTransferConfigs : new gaxModule . PageDescriptor (
186
+ listTransferConfigs : new this . _gaxModule . PageDescriptor (
179
187
'pageToken' ,
180
188
'nextPageToken' ,
181
189
'transferConfigs'
182
190
) ,
183
- listTransferRuns : new gaxModule . PageDescriptor (
191
+ listTransferRuns : new this . _gaxModule . PageDescriptor (
184
192
'pageToken' ,
185
193
'nextPageToken' ,
186
194
'transferRuns'
187
195
) ,
188
- listTransferLogs : new gaxModule . PageDescriptor (
196
+ listTransferLogs : new this . _gaxModule . PageDescriptor (
189
197
'pageToken' ,
190
198
'nextPageToken' ,
191
199
'transferMessages'
192
200
) ,
193
201
} ;
194
202
195
203
// Put together the default options sent with requests.
196
- const defaults = gaxGrpc . constructSettings (
204
+ this . _defaults = this . _gaxGrpc . constructSettings (
197
205
'google.cloud.bigquery.datatransfer.v1.DataTransferService' ,
198
206
gapicConfig as gax . ClientConfig ,
199
207
opts . clientConfig || { } ,
@@ -204,18 +212,36 @@ export class DataTransferServiceClient {
204
212
// of calling the API is handled in `google-gax`, with this code
205
213
// merely providing the destination and request information.
206
214
this . _innerApiCalls = { } ;
215
+ }
216
+
217
+ /**
218
+ * Initialize the client.
219
+ * Performs asynchronous operations (such as authentication) and prepares the client.
220
+ * This function will be called automatically when any class method is called for the
221
+ * first time, but if you need to initialize it before calling an actual method,
222
+ * feel free to call initialize() directly.
223
+ *
224
+ * You can await on this method if you want to make sure the client is initialized.
225
+ *
226
+ * @returns {Promise } A promise that resolves to an authenticated service stub.
227
+ */
228
+ initialize ( ) {
229
+ // If the client stub promise is already initialized, return immediately.
230
+ if ( this . dataTransferServiceStub ) {
231
+ return this . dataTransferServiceStub ;
232
+ }
207
233
208
234
// Put together the "service stub" for
209
235
// google.cloud.bigquery.datatransfer.v1.DataTransferService.
210
- this . dataTransferServiceStub = gaxGrpc . createStub (
211
- opts . fallback
212
- ? ( protos as protobuf . Root ) . lookupService (
236
+ this . dataTransferServiceStub = this . _gaxGrpc . createStub (
237
+ this . _opts . fallback
238
+ ? ( this . _protos as protobuf . Root ) . lookupService (
213
239
'google.cloud.bigquery.datatransfer.v1.DataTransferService'
214
240
)
215
241
: // tslint:disable-next-line no-any
216
- ( protos as any ) . google . cloud . bigquery . datatransfer . v1
242
+ ( this . _protos as any ) . google . cloud . bigquery . datatransfer . v1
217
243
. DataTransferService ,
218
- opts
244
+ this . _opts
219
245
) as Promise < { [ method : string ] : Function } > ;
220
246
221
247
// Iterate over each of the methods that the service provides
@@ -250,9 +276,9 @@ export class DataTransferServiceClient {
250
276
}
251
277
) ;
252
278
253
- const apiCall = gaxModule . createApiCall (
279
+ const apiCall = this . _gaxModule . createApiCall (
254
280
innerCallPromise ,
255
- defaults [ methodName ] ,
281
+ this . _defaults [ methodName ] ,
256
282
this . _descriptors . page [ methodName ] ||
257
283
this . _descriptors . stream [ methodName ] ||
258
284
this . _descriptors . longrunning [ methodName ]
@@ -266,6 +292,8 @@ export class DataTransferServiceClient {
266
292
return apiCall ( argument , callOptions , callback ) ;
267
293
} ;
268
294
}
295
+
296
+ return this . dataTransferServiceStub ;
269
297
}
270
298
271
299
/**
@@ -399,6 +427,7 @@ export class DataTransferServiceClient {
399
427
] = gax . routingHeader . fromParams ( {
400
428
name : request . name || '' ,
401
429
} ) ;
430
+ this . initialize ( ) ;
402
431
return this . _innerApiCalls . getDataSource ( request , options , callback ) ;
403
432
}
404
433
createTransferConfig (
@@ -513,6 +542,7 @@ export class DataTransferServiceClient {
513
542
] = gax . routingHeader . fromParams ( {
514
543
parent : request . parent || '' ,
515
544
} ) ;
545
+ this . initialize ( ) ;
516
546
return this . _innerApiCalls . createTransferConfig ( request , options , callback ) ;
517
547
}
518
548
updateTransferConfig (
@@ -626,6 +656,7 @@ export class DataTransferServiceClient {
626
656
] = gax . routingHeader . fromParams ( {
627
657
'transfer_config.name' : request . transferConfig ! . name || '' ,
628
658
} ) ;
659
+ this . initialize ( ) ;
629
660
return this . _innerApiCalls . updateTransferConfig ( request , options , callback ) ;
630
661
}
631
662
deleteTransferConfig (
@@ -709,6 +740,7 @@ export class DataTransferServiceClient {
709
740
] = gax . routingHeader . fromParams ( {
710
741
name : request . name || '' ,
711
742
} ) ;
743
+ this . initialize ( ) ;
712
744
return this . _innerApiCalls . deleteTransferConfig ( request , options , callback ) ;
713
745
}
714
746
getTransferConfig (
@@ -791,6 +823,7 @@ export class DataTransferServiceClient {
791
823
] = gax . routingHeader . fromParams ( {
792
824
name : request . name || '' ,
793
825
} ) ;
826
+ this . initialize ( ) ;
794
827
return this . _innerApiCalls . getTransferConfig ( request , options , callback ) ;
795
828
}
796
829
scheduleTransferRuns (
@@ -883,6 +916,7 @@ export class DataTransferServiceClient {
883
916
] = gax . routingHeader . fromParams ( {
884
917
parent : request . parent || '' ,
885
918
} ) ;
919
+ this . initialize ( ) ;
886
920
return this . _innerApiCalls . scheduleTransferRuns ( request , options , callback ) ;
887
921
}
888
922
startManualTransferRuns (
@@ -973,6 +1007,7 @@ export class DataTransferServiceClient {
973
1007
] = gax . routingHeader . fromParams ( {
974
1008
parent : request . parent || '' ,
975
1009
} ) ;
1010
+ this . initialize ( ) ;
976
1011
return this . _innerApiCalls . startManualTransferRuns (
977
1012
request ,
978
1013
options ,
@@ -1059,6 +1094,7 @@ export class DataTransferServiceClient {
1059
1094
] = gax . routingHeader . fromParams ( {
1060
1095
name : request . name || '' ,
1061
1096
} ) ;
1097
+ this . initialize ( ) ;
1062
1098
return this . _innerApiCalls . getTransferRun ( request , options , callback ) ;
1063
1099
}
1064
1100
deleteTransferRun (
@@ -1141,6 +1177,7 @@ export class DataTransferServiceClient {
1141
1177
] = gax . routingHeader . fromParams ( {
1142
1178
name : request . name || '' ,
1143
1179
} ) ;
1180
+ this . initialize ( ) ;
1144
1181
return this . _innerApiCalls . deleteTransferRun ( request , options , callback ) ;
1145
1182
}
1146
1183
checkValidCreds (
@@ -1228,6 +1265,7 @@ export class DataTransferServiceClient {
1228
1265
] = gax . routingHeader . fromParams ( {
1229
1266
name : request . name || '' ,
1230
1267
} ) ;
1268
+ this . initialize ( ) ;
1231
1269
return this . _innerApiCalls . checkValidCreds ( request , options , callback ) ;
1232
1270
}
1233
1271
@@ -1323,6 +1361,7 @@ export class DataTransferServiceClient {
1323
1361
] = gax . routingHeader . fromParams ( {
1324
1362
parent : request . parent || '' ,
1325
1363
} ) ;
1364
+ this . initialize ( ) ;
1326
1365
return this . _innerApiCalls . listDataSources ( request , options , callback ) ;
1327
1366
}
1328
1367
@@ -1372,6 +1411,7 @@ export class DataTransferServiceClient {
1372
1411
parent : request . parent || '' ,
1373
1412
} ) ;
1374
1413
const callSettings = new gax . CallSettings ( options ) ;
1414
+ this . initialize ( ) ;
1375
1415
return this . _descriptors . page . listDataSources . createStream (
1376
1416
this . _innerApiCalls . listDataSources as gax . GaxCall ,
1377
1417
request ,
@@ -1471,6 +1511,7 @@ export class DataTransferServiceClient {
1471
1511
] = gax . routingHeader . fromParams ( {
1472
1512
parent : request . parent || '' ,
1473
1513
} ) ;
1514
+ this . initialize ( ) ;
1474
1515
return this . _innerApiCalls . listTransferConfigs ( request , options , callback ) ;
1475
1516
}
1476
1517
@@ -1522,6 +1563,7 @@ export class DataTransferServiceClient {
1522
1563
parent : request . parent || '' ,
1523
1564
} ) ;
1524
1565
const callSettings = new gax . CallSettings ( options ) ;
1566
+ this . initialize ( ) ;
1525
1567
return this . _descriptors . page . listTransferConfigs . createStream (
1526
1568
this . _innerApiCalls . listTransferConfigs as gax . GaxCall ,
1527
1569
request ,
@@ -1624,6 +1666,7 @@ export class DataTransferServiceClient {
1624
1666
] = gax . routingHeader . fromParams ( {
1625
1667
parent : request . parent || '' ,
1626
1668
} ) ;
1669
+ this . initialize ( ) ;
1627
1670
return this . _innerApiCalls . listTransferRuns ( request , options , callback ) ;
1628
1671
}
1629
1672
@@ -1678,6 +1721,7 @@ export class DataTransferServiceClient {
1678
1721
parent : request . parent || '' ,
1679
1722
} ) ;
1680
1723
const callSettings = new gax . CallSettings ( options ) ;
1724
+ this . initialize ( ) ;
1681
1725
return this . _descriptors . page . listTransferRuns . createStream (
1682
1726
this . _innerApiCalls . listTransferRuns as gax . GaxCall ,
1683
1727
request ,
@@ -1778,6 +1822,7 @@ export class DataTransferServiceClient {
1778
1822
] = gax . routingHeader . fromParams ( {
1779
1823
parent : request . parent || '' ,
1780
1824
} ) ;
1825
+ this . initialize ( ) ;
1781
1826
return this . _innerApiCalls . listTransferLogs ( request , options , callback ) ;
1782
1827
}
1783
1828
@@ -1830,6 +1875,7 @@ export class DataTransferServiceClient {
1830
1875
parent : request . parent || '' ,
1831
1876
} ) ;
1832
1877
const callSettings = new gax . CallSettings ( options ) ;
1878
+ this . initialize ( ) ;
1833
1879
return this . _descriptors . page . listTransferLogs . createStream (
1834
1880
this . _innerApiCalls . listTransferLogs as gax . GaxCall ,
1835
1881
request ,
@@ -2233,8 +2279,9 @@ export class DataTransferServiceClient {
2233
2279
* The client will no longer be usable and all future behavior is undefined.
2234
2280
*/
2235
2281
close ( ) : Promise < void > {
2282
+ this . initialize ( ) ;
2236
2283
if ( ! this . _terminated ) {
2237
- return this . dataTransferServiceStub . then ( stub => {
2284
+ return this . dataTransferServiceStub ! . then ( stub => {
2238
2285
this . _terminated = true ;
2239
2286
stub . close ( ) ;
2240
2287
} ) ;
0 commit comments