17
17
// ** All changes to this file may be overwritten. **
18
18
19
19
/* global window */
20
- import * as gax from 'google-gax' ;
21
- import {
20
+ import type * as gax from 'google-gax' ;
21
+ import type {
22
22
Callback ,
23
23
CallOptions ,
24
24
Descriptors ,
25
25
ClientOptions ,
26
26
PaginationCallback ,
27
27
GaxCall ,
28
28
} from 'google-gax' ;
29
-
30
29
import { Transform } from 'stream' ;
31
30
import * as protos from '../../protos/protos' ;
32
31
import jsonProtos = require( '../../protos/protos.json' ) ;
@@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json');
36
35
* This file defines retry strategy and timeouts for all API methods in this library.
37
36
*/
38
37
import * as gapicConfig from './cloud_tasks_client_config.json' ;
39
-
40
38
const version = require ( '../../../package.json' ) . version ;
41
39
42
40
/**
@@ -97,8 +95,18 @@ export class CloudTasksClient {
97
95
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
98
96
* For more information, please check the
99
97
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
98
+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
99
+ * need to avoid loading the default gRPC version and want to use the fallback
100
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
101
+ * ```
102
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
103
+ * const client = new CloudTasksClient({fallback: 'rest'}, gax);
104
+ * ```
100
105
*/
101
- constructor ( opts ?: ClientOptions ) {
106
+ constructor (
107
+ opts ?: ClientOptions ,
108
+ gaxInstance ?: typeof gax | typeof gax . fallback
109
+ ) {
102
110
// Ensure that options include all the required fields.
103
111
const staticMembers = this . constructor as typeof CloudTasksClient ;
104
112
const servicePath =
@@ -118,8 +126,13 @@ export class CloudTasksClient {
118
126
opts [ 'scopes' ] = staticMembers . scopes ;
119
127
}
120
128
129
+ // Load google-gax module synchronously if needed
130
+ if ( ! gaxInstance ) {
131
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
132
+ }
133
+
121
134
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
122
- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
135
+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
123
136
124
137
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
125
138
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -207,7 +220,7 @@ export class CloudTasksClient {
207
220
this . innerApiCalls = { } ;
208
221
209
222
// Add a warn function to the client constructor so it can be easily tested.
210
- this . warn = gax . warn ;
223
+ this . warn = this . _gaxModule . warn ;
211
224
}
212
225
213
226
/**
@@ -420,7 +433,7 @@ export class CloudTasksClient {
420
433
options . otherArgs = options . otherArgs || { } ;
421
434
options . otherArgs . headers = options . otherArgs . headers || { } ;
422
435
options . otherArgs . headers [ 'x-goog-request-params' ] =
423
- gax . routingHeader . fromParams ( {
436
+ this . _gaxModule . routingHeader . fromParams ( {
424
437
name : request . name || '' ,
425
438
} ) ;
426
439
this . initialize ( ) ;
@@ -523,7 +536,7 @@ export class CloudTasksClient {
523
536
options . otherArgs = options . otherArgs || { } ;
524
537
options . otherArgs . headers = options . otherArgs . headers || { } ;
525
538
options . otherArgs . headers [ 'x-goog-request-params' ] =
526
- gax . routingHeader . fromParams ( {
539
+ this . _gaxModule . routingHeader . fromParams ( {
527
540
parent : request . parent || '' ,
528
541
} ) ;
529
542
this . initialize ( ) ;
@@ -630,7 +643,7 @@ export class CloudTasksClient {
630
643
options . otherArgs = options . otherArgs || { } ;
631
644
options . otherArgs . headers = options . otherArgs . headers || { } ;
632
645
options . otherArgs . headers [ 'x-goog-request-params' ] =
633
- gax . routingHeader . fromParams ( {
646
+ this . _gaxModule . routingHeader . fromParams ( {
634
647
'queue.name' : request . queue ! . name || '' ,
635
648
} ) ;
636
649
this . initialize ( ) ;
@@ -726,7 +739,7 @@ export class CloudTasksClient {
726
739
options . otherArgs = options . otherArgs || { } ;
727
740
options . otherArgs . headers = options . otherArgs . headers || { } ;
728
741
options . otherArgs . headers [ 'x-goog-request-params' ] =
729
- gax . routingHeader . fromParams ( {
742
+ this . _gaxModule . routingHeader . fromParams ( {
730
743
name : request . name || '' ,
731
744
} ) ;
732
745
this . initialize ( ) ;
@@ -815,7 +828,7 @@ export class CloudTasksClient {
815
828
options . otherArgs = options . otherArgs || { } ;
816
829
options . otherArgs . headers = options . otherArgs . headers || { } ;
817
830
options . otherArgs . headers [ 'x-goog-request-params' ] =
818
- gax . routingHeader . fromParams ( {
831
+ this . _gaxModule . routingHeader . fromParams ( {
819
832
name : request . name || '' ,
820
833
} ) ;
821
834
this . initialize ( ) ;
@@ -905,7 +918,7 @@ export class CloudTasksClient {
905
918
options . otherArgs = options . otherArgs || { } ;
906
919
options . otherArgs . headers = options . otherArgs . headers || { } ;
907
920
options . otherArgs . headers [ 'x-goog-request-params' ] =
908
- gax . routingHeader . fromParams ( {
921
+ this . _gaxModule . routingHeader . fromParams ( {
909
922
name : request . name || '' ,
910
923
} ) ;
911
924
this . initialize ( ) ;
@@ -1001,7 +1014,7 @@ export class CloudTasksClient {
1001
1014
options . otherArgs = options . otherArgs || { } ;
1002
1015
options . otherArgs . headers = options . otherArgs . headers || { } ;
1003
1016
options . otherArgs . headers [ 'x-goog-request-params' ] =
1004
- gax . routingHeader . fromParams ( {
1017
+ this . _gaxModule . routingHeader . fromParams ( {
1005
1018
name : request . name || '' ,
1006
1019
} ) ;
1007
1020
this . initialize ( ) ;
@@ -1096,7 +1109,7 @@ export class CloudTasksClient {
1096
1109
options . otherArgs = options . otherArgs || { } ;
1097
1110
options . otherArgs . headers = options . otherArgs . headers || { } ;
1098
1111
options . otherArgs . headers [ 'x-goog-request-params' ] =
1099
- gax . routingHeader . fromParams ( {
1112
+ this . _gaxModule . routingHeader . fromParams ( {
1100
1113
resource : request . resource || '' ,
1101
1114
} ) ;
1102
1115
this . initialize ( ) ;
@@ -1201,7 +1214,7 @@ export class CloudTasksClient {
1201
1214
options . otherArgs = options . otherArgs || { } ;
1202
1215
options . otherArgs . headers = options . otherArgs . headers || { } ;
1203
1216
options . otherArgs . headers [ 'x-goog-request-params' ] =
1204
- gax . routingHeader . fromParams ( {
1217
+ this . _gaxModule . routingHeader . fromParams ( {
1205
1218
resource : request . resource || '' ,
1206
1219
} ) ;
1207
1220
this . initialize ( ) ;
@@ -1296,7 +1309,7 @@ export class CloudTasksClient {
1296
1309
options . otherArgs = options . otherArgs || { } ;
1297
1310
options . otherArgs . headers = options . otherArgs . headers || { } ;
1298
1311
options . otherArgs . headers [ 'x-goog-request-params' ] =
1299
- gax . routingHeader . fromParams ( {
1312
+ this . _gaxModule . routingHeader . fromParams ( {
1300
1313
resource : request . resource || '' ,
1301
1314
} ) ;
1302
1315
this . initialize ( ) ;
@@ -1393,7 +1406,7 @@ export class CloudTasksClient {
1393
1406
options . otherArgs = options . otherArgs || { } ;
1394
1407
options . otherArgs . headers = options . otherArgs . headers || { } ;
1395
1408
options . otherArgs . headers [ 'x-goog-request-params' ] =
1396
- gax . routingHeader . fromParams ( {
1409
+ this . _gaxModule . routingHeader . fromParams ( {
1397
1410
name : request . name || '' ,
1398
1411
} ) ;
1399
1412
this . initialize ( ) ;
@@ -1530,7 +1543,7 @@ export class CloudTasksClient {
1530
1543
options . otherArgs = options . otherArgs || { } ;
1531
1544
options . otherArgs . headers = options . otherArgs . headers || { } ;
1532
1545
options . otherArgs . headers [ 'x-goog-request-params' ] =
1533
- gax . routingHeader . fromParams ( {
1546
+ this . _gaxModule . routingHeader . fromParams ( {
1534
1547
parent : request . parent || '' ,
1535
1548
} ) ;
1536
1549
this . initialize ( ) ;
@@ -1618,7 +1631,7 @@ export class CloudTasksClient {
1618
1631
options . otherArgs = options . otherArgs || { } ;
1619
1632
options . otherArgs . headers = options . otherArgs . headers || { } ;
1620
1633
options . otherArgs . headers [ 'x-goog-request-params' ] =
1621
- gax . routingHeader . fromParams ( {
1634
+ this . _gaxModule . routingHeader . fromParams ( {
1622
1635
name : request . name || '' ,
1623
1636
} ) ;
1624
1637
this . initialize ( ) ;
@@ -1738,7 +1751,7 @@ export class CloudTasksClient {
1738
1751
options . otherArgs = options . otherArgs || { } ;
1739
1752
options . otherArgs . headers = options . otherArgs . headers || { } ;
1740
1753
options . otherArgs . headers [ 'x-goog-request-params' ] =
1741
- gax . routingHeader . fromParams ( {
1754
+ this . _gaxModule . routingHeader . fromParams ( {
1742
1755
name : request . name || '' ,
1743
1756
} ) ;
1744
1757
this . initialize ( ) ;
@@ -1857,7 +1870,7 @@ export class CloudTasksClient {
1857
1870
options . otherArgs = options . otherArgs || { } ;
1858
1871
options . otherArgs . headers = options . otherArgs . headers || { } ;
1859
1872
options . otherArgs . headers [ 'x-goog-request-params' ] =
1860
- gax . routingHeader . fromParams ( {
1873
+ this . _gaxModule . routingHeader . fromParams ( {
1861
1874
parent : request . parent || '' ,
1862
1875
} ) ;
1863
1876
this . initialize ( ) ;
@@ -1921,7 +1934,7 @@ export class CloudTasksClient {
1921
1934
options . otherArgs = options . otherArgs || { } ;
1922
1935
options . otherArgs . headers = options . otherArgs . headers || { } ;
1923
1936
options . otherArgs . headers [ 'x-goog-request-params' ] =
1924
- gax . routingHeader . fromParams ( {
1937
+ this . _gaxModule . routingHeader . fromParams ( {
1925
1938
parent : request . parent || '' ,
1926
1939
} ) ;
1927
1940
const defaultCallSettings = this . _defaults [ 'listQueues' ] ;
@@ -1994,7 +2007,7 @@ export class CloudTasksClient {
1994
2007
options . otherArgs = options . otherArgs || { } ;
1995
2008
options . otherArgs . headers = options . otherArgs . headers || { } ;
1996
2009
options . otherArgs . headers [ 'x-goog-request-params' ] =
1997
- gax . routingHeader . fromParams ( {
2010
+ this . _gaxModule . routingHeader . fromParams ( {
1998
2011
parent : request . parent || '' ,
1999
2012
} ) ;
2000
2013
const defaultCallSettings = this . _defaults [ 'listQueues' ] ;
@@ -2127,7 +2140,7 @@ export class CloudTasksClient {
2127
2140
options . otherArgs = options . otherArgs || { } ;
2128
2141
options . otherArgs . headers = options . otherArgs . headers || { } ;
2129
2142
options . otherArgs . headers [ 'x-goog-request-params' ] =
2130
- gax . routingHeader . fromParams ( {
2143
+ this . _gaxModule . routingHeader . fromParams ( {
2131
2144
parent : request . parent || '' ,
2132
2145
} ) ;
2133
2146
this . initialize ( ) ;
@@ -2194,7 +2207,7 @@ export class CloudTasksClient {
2194
2207
options . otherArgs = options . otherArgs || { } ;
2195
2208
options . otherArgs . headers = options . otherArgs . headers || { } ;
2196
2209
options . otherArgs . headers [ 'x-goog-request-params' ] =
2197
- gax . routingHeader . fromParams ( {
2210
+ this . _gaxModule . routingHeader . fromParams ( {
2198
2211
parent : request . parent || '' ,
2199
2212
} ) ;
2200
2213
const defaultCallSettings = this . _defaults [ 'listTasks' ] ;
@@ -2270,7 +2283,7 @@ export class CloudTasksClient {
2270
2283
options . otherArgs = options . otherArgs || { } ;
2271
2284
options . otherArgs . headers = options . otherArgs . headers || { } ;
2272
2285
options . otherArgs . headers [ 'x-goog-request-params' ] =
2273
- gax . routingHeader . fromParams ( {
2286
+ this . _gaxModule . routingHeader . fromParams ( {
2274
2287
parent : request . parent || '' ,
2275
2288
} ) ;
2276
2289
const defaultCallSettings = this . _defaults [ 'listTasks' ] ;
0 commit comments