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 './device_manager_client_config.json' ;
39
-
40
38
const version = require ( '../../../package.json' ) . version ;
41
39
42
40
/**
@@ -96,8 +94,18 @@ export class DeviceManagerClient {
96
94
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
97
95
* For more information, please check the
98
96
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
97
+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
98
+ * need to avoid loading the default gRPC version and want to use the fallback
99
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
100
+ * ```
101
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
102
+ * const client = new DeviceManagerClient({fallback: 'rest'}, gax);
103
+ * ```
99
104
*/
100
- constructor ( opts ?: ClientOptions ) {
105
+ constructor (
106
+ opts ?: ClientOptions ,
107
+ gaxInstance ?: typeof gax | typeof gax . fallback
108
+ ) {
101
109
// Ensure that options include all the required fields.
102
110
const staticMembers = this . constructor as typeof DeviceManagerClient ;
103
111
const servicePath =
@@ -117,8 +125,13 @@ export class DeviceManagerClient {
117
125
opts [ 'scopes' ] = staticMembers . scopes ;
118
126
}
119
127
128
+ // Load google-gax module synchronously if needed
129
+ if ( ! gaxInstance ) {
130
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
131
+ }
132
+
120
133
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
121
- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
134
+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
122
135
123
136
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
124
137
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -203,7 +216,7 @@ export class DeviceManagerClient {
203
216
this . innerApiCalls = { } ;
204
217
205
218
// Add a warn function to the client constructor so it can be easily tested.
206
- this . warn = gax . warn ;
219
+ this . warn = this . _gaxModule . warn ;
207
220
}
208
221
209
222
/**
@@ -434,7 +447,7 @@ export class DeviceManagerClient {
434
447
options . otherArgs = options . otherArgs || { } ;
435
448
options . otherArgs . headers = options . otherArgs . headers || { } ;
436
449
options . otherArgs . headers [ 'x-goog-request-params' ] =
437
- gax . routingHeader . fromParams ( {
450
+ this . _gaxModule . routingHeader . fromParams ( {
438
451
parent : request . parent || '' ,
439
452
} ) ;
440
453
this . initialize ( ) ;
@@ -520,7 +533,7 @@ export class DeviceManagerClient {
520
533
options . otherArgs = options . otherArgs || { } ;
521
534
options . otherArgs . headers = options . otherArgs . headers || { } ;
522
535
options . otherArgs . headers [ 'x-goog-request-params' ] =
523
- gax . routingHeader . fromParams ( {
536
+ this . _gaxModule . routingHeader . fromParams ( {
524
537
name : request . name || '' ,
525
538
} ) ;
526
539
this . initialize ( ) ;
@@ -619,7 +632,7 @@ export class DeviceManagerClient {
619
632
options . otherArgs = options . otherArgs || { } ;
620
633
options . otherArgs . headers = options . otherArgs . headers || { } ;
621
634
options . otherArgs . headers [ 'x-goog-request-params' ] =
622
- gax . routingHeader . fromParams ( {
635
+ this . _gaxModule . routingHeader . fromParams ( {
623
636
'device_registry.name' : request . deviceRegistry ! . name || '' ,
624
637
} ) ;
625
638
this . initialize ( ) ;
@@ -711,7 +724,7 @@ export class DeviceManagerClient {
711
724
options . otherArgs = options . otherArgs || { } ;
712
725
options . otherArgs . headers = options . otherArgs . headers || { } ;
713
726
options . otherArgs . headers [ 'x-goog-request-params' ] =
714
- gax . routingHeader . fromParams ( {
727
+ this . _gaxModule . routingHeader . fromParams ( {
715
728
name : request . name || '' ,
716
729
} ) ;
717
730
this . initialize ( ) ;
@@ -800,7 +813,7 @@ export class DeviceManagerClient {
800
813
options . otherArgs = options . otherArgs || { } ;
801
814
options . otherArgs . headers = options . otherArgs . headers || { } ;
802
815
options . otherArgs . headers [ 'x-goog-request-params' ] =
803
- gax . routingHeader . fromParams ( {
816
+ this . _gaxModule . routingHeader . fromParams ( {
804
817
parent : request . parent || '' ,
805
818
} ) ;
806
819
this . initialize ( ) ;
@@ -889,7 +902,7 @@ export class DeviceManagerClient {
889
902
options . otherArgs = options . otherArgs || { } ;
890
903
options . otherArgs . headers = options . otherArgs . headers || { } ;
891
904
options . otherArgs . headers [ 'x-goog-request-params' ] =
892
- gax . routingHeader . fromParams ( {
905
+ this . _gaxModule . routingHeader . fromParams ( {
893
906
name : request . name || '' ,
894
907
} ) ;
895
908
this . initialize ( ) ;
@@ -980,7 +993,7 @@ export class DeviceManagerClient {
980
993
options . otherArgs = options . otherArgs || { } ;
981
994
options . otherArgs . headers = options . otherArgs . headers || { } ;
982
995
options . otherArgs . headers [ 'x-goog-request-params' ] =
983
- gax . routingHeader . fromParams ( {
996
+ this . _gaxModule . routingHeader . fromParams ( {
984
997
'device.name' : request . device ! . name || '' ,
985
998
} ) ;
986
999
this . initialize ( ) ;
@@ -1065,7 +1078,7 @@ export class DeviceManagerClient {
1065
1078
options . otherArgs = options . otherArgs || { } ;
1066
1079
options . otherArgs . headers = options . otherArgs . headers || { } ;
1067
1080
options . otherArgs . headers [ 'x-goog-request-params' ] =
1068
- gax . routingHeader . fromParams ( {
1081
+ this . _gaxModule . routingHeader . fromParams ( {
1069
1082
name : request . name || '' ,
1070
1083
} ) ;
1071
1084
this . initialize ( ) ;
@@ -1168,7 +1181,7 @@ export class DeviceManagerClient {
1168
1181
options . otherArgs = options . otherArgs || { } ;
1169
1182
options . otherArgs . headers = options . otherArgs . headers || { } ;
1170
1183
options . otherArgs . headers [ 'x-goog-request-params' ] =
1171
- gax . routingHeader . fromParams ( {
1184
+ this . _gaxModule . routingHeader . fromParams ( {
1172
1185
name : request . name || '' ,
1173
1186
} ) ;
1174
1187
this . initialize ( ) ;
@@ -1270,7 +1283,7 @@ export class DeviceManagerClient {
1270
1283
options . otherArgs = options . otherArgs || { } ;
1271
1284
options . otherArgs . headers = options . otherArgs . headers || { } ;
1272
1285
options . otherArgs . headers [ 'x-goog-request-params' ] =
1273
- gax . routingHeader . fromParams ( {
1286
+ this . _gaxModule . routingHeader . fromParams ( {
1274
1287
name : request . name || '' ,
1275
1288
} ) ;
1276
1289
this . initialize ( ) ;
@@ -1366,7 +1379,7 @@ export class DeviceManagerClient {
1366
1379
options . otherArgs = options . otherArgs || { } ;
1367
1380
options . otherArgs . headers = options . otherArgs . headers || { } ;
1368
1381
options . otherArgs . headers [ 'x-goog-request-params' ] =
1369
- gax . routingHeader . fromParams ( {
1382
+ this . _gaxModule . routingHeader . fromParams ( {
1370
1383
name : request . name || '' ,
1371
1384
} ) ;
1372
1385
this . initialize ( ) ;
@@ -1462,7 +1475,7 @@ export class DeviceManagerClient {
1462
1475
options . otherArgs = options . otherArgs || { } ;
1463
1476
options . otherArgs . headers = options . otherArgs . headers || { } ;
1464
1477
options . otherArgs . headers [ 'x-goog-request-params' ] =
1465
- gax . routingHeader . fromParams ( {
1478
+ this . _gaxModule . routingHeader . fromParams ( {
1466
1479
resource : request . resource || '' ,
1467
1480
} ) ;
1468
1481
this . initialize ( ) ;
@@ -1551,7 +1564,7 @@ export class DeviceManagerClient {
1551
1564
options . otherArgs = options . otherArgs || { } ;
1552
1565
options . otherArgs . headers = options . otherArgs . headers || { } ;
1553
1566
options . otherArgs . headers [ 'x-goog-request-params' ] =
1554
- gax . routingHeader . fromParams ( {
1567
+ this . _gaxModule . routingHeader . fromParams ( {
1555
1568
resource : request . resource || '' ,
1556
1569
} ) ;
1557
1570
this . initialize ( ) ;
@@ -1642,7 +1655,7 @@ export class DeviceManagerClient {
1642
1655
options . otherArgs = options . otherArgs || { } ;
1643
1656
options . otherArgs . headers = options . otherArgs . headers || { } ;
1644
1657
options . otherArgs . headers [ 'x-goog-request-params' ] =
1645
- gax . routingHeader . fromParams ( {
1658
+ this . _gaxModule . routingHeader . fromParams ( {
1646
1659
resource : request . resource || '' ,
1647
1660
} ) ;
1648
1661
this . initialize ( ) ;
@@ -1749,7 +1762,7 @@ export class DeviceManagerClient {
1749
1762
options . otherArgs = options . otherArgs || { } ;
1750
1763
options . otherArgs . headers = options . otherArgs . headers || { } ;
1751
1764
options . otherArgs . headers [ 'x-goog-request-params' ] =
1752
- gax . routingHeader . fromParams ( {
1765
+ this . _gaxModule . routingHeader . fromParams ( {
1753
1766
name : request . name || '' ,
1754
1767
} ) ;
1755
1768
this . initialize ( ) ;
@@ -1842,7 +1855,7 @@ export class DeviceManagerClient {
1842
1855
options . otherArgs = options . otherArgs || { } ;
1843
1856
options . otherArgs . headers = options . otherArgs . headers || { } ;
1844
1857
options . otherArgs . headers [ 'x-goog-request-params' ] =
1845
- gax . routingHeader . fromParams ( {
1858
+ this . _gaxModule . routingHeader . fromParams ( {
1846
1859
parent : request . parent || '' ,
1847
1860
} ) ;
1848
1861
this . initialize ( ) ;
@@ -1941,7 +1954,7 @@ export class DeviceManagerClient {
1941
1954
options . otherArgs = options . otherArgs || { } ;
1942
1955
options . otherArgs . headers = options . otherArgs . headers || { } ;
1943
1956
options . otherArgs . headers [ 'x-goog-request-params' ] =
1944
- gax . routingHeader . fromParams ( {
1957
+ this . _gaxModule . routingHeader . fromParams ( {
1945
1958
parent : request . parent || '' ,
1946
1959
} ) ;
1947
1960
this . initialize ( ) ;
@@ -2050,7 +2063,7 @@ export class DeviceManagerClient {
2050
2063
options . otherArgs = options . otherArgs || { } ;
2051
2064
options . otherArgs . headers = options . otherArgs . headers || { } ;
2052
2065
options . otherArgs . headers [ 'x-goog-request-params' ] =
2053
- gax . routingHeader . fromParams ( {
2066
+ this . _gaxModule . routingHeader . fromParams ( {
2054
2067
parent : request . parent || '' ,
2055
2068
} ) ;
2056
2069
this . initialize ( ) ;
@@ -2094,7 +2107,7 @@ export class DeviceManagerClient {
2094
2107
options . otherArgs = options . otherArgs || { } ;
2095
2108
options . otherArgs . headers = options . otherArgs . headers || { } ;
2096
2109
options . otherArgs . headers [ 'x-goog-request-params' ] =
2097
- gax . routingHeader . fromParams ( {
2110
+ this . _gaxModule . routingHeader . fromParams ( {
2098
2111
parent : request . parent || '' ,
2099
2112
} ) ;
2100
2113
const defaultCallSettings = this . _defaults [ 'listDeviceRegistries' ] ;
@@ -2147,7 +2160,7 @@ export class DeviceManagerClient {
2147
2160
options . otherArgs = options . otherArgs || { } ;
2148
2161
options . otherArgs . headers = options . otherArgs . headers || { } ;
2149
2162
options . otherArgs . headers [ 'x-goog-request-params' ] =
2150
- gax . routingHeader . fromParams ( {
2163
+ this . _gaxModule . routingHeader . fromParams ( {
2151
2164
parent : request . parent || '' ,
2152
2165
} ) ;
2153
2166
const defaultCallSettings = this . _defaults [ 'listDeviceRegistries' ] ;
@@ -2262,7 +2275,7 @@ export class DeviceManagerClient {
2262
2275
options . otherArgs = options . otherArgs || { } ;
2263
2276
options . otherArgs . headers = options . otherArgs . headers || { } ;
2264
2277
options . otherArgs . headers [ 'x-goog-request-params' ] =
2265
- gax . routingHeader . fromParams ( {
2278
+ this . _gaxModule . routingHeader . fromParams ( {
2266
2279
parent : request . parent || '' ,
2267
2280
} ) ;
2268
2281
this . initialize ( ) ;
@@ -2319,7 +2332,7 @@ export class DeviceManagerClient {
2319
2332
options . otherArgs = options . otherArgs || { } ;
2320
2333
options . otherArgs . headers = options . otherArgs . headers || { } ;
2321
2334
options . otherArgs . headers [ 'x-goog-request-params' ] =
2322
- gax . routingHeader . fromParams ( {
2335
+ this . _gaxModule . routingHeader . fromParams ( {
2323
2336
parent : request . parent || '' ,
2324
2337
} ) ;
2325
2338
const defaultCallSettings = this . _defaults [ 'listDevices' ] ;
@@ -2385,7 +2398,7 @@ export class DeviceManagerClient {
2385
2398
options . otherArgs = options . otherArgs || { } ;
2386
2399
options . otherArgs . headers = options . otherArgs . headers || { } ;
2387
2400
options . otherArgs . headers [ 'x-goog-request-params' ] =
2388
- gax . routingHeader . fromParams ( {
2401
+ this . _gaxModule . routingHeader . fromParams ( {
2389
2402
parent : request . parent || '' ,
2390
2403
} ) ;
2391
2404
const defaultCallSettings = this . _defaults [ 'listDevices' ] ;
0 commit comments