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 './adaptation_client_config.json' ;
39
-
40
38
const version = require ( '../../../package.json' ) . version ;
41
39
42
40
/**
@@ -96,8 +94,18 @@ export class AdaptationClient {
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 AdaptationClient({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 AdaptationClient ;
103
111
const servicePath =
@@ -117,8 +125,13 @@ export class AdaptationClient {
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 ) ;
@@ -206,7 +219,7 @@ export class AdaptationClient {
206
219
this . innerApiCalls = { } ;
207
220
208
221
// Add a warn function to the client constructor so it can be easily tested.
209
- this . warn = gax . warn ;
222
+ this . warn = this . _gaxModule . warn ;
210
223
}
211
224
212
225
/**
@@ -432,7 +445,7 @@ export class AdaptationClient {
432
445
options . otherArgs = options . otherArgs || { } ;
433
446
options . otherArgs . headers = options . otherArgs . headers || { } ;
434
447
options . otherArgs . headers [ 'x-goog-request-params' ] =
435
- gax . routingHeader . fromParams ( {
448
+ this . _gaxModule . routingHeader . fromParams ( {
436
449
parent : request . parent || '' ,
437
450
} ) ;
438
451
this . initialize ( ) ;
@@ -523,7 +536,7 @@ export class AdaptationClient {
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
name : request . name || '' ,
528
541
} ) ;
529
542
this . initialize ( ) ;
@@ -621,7 +634,7 @@ export class AdaptationClient {
621
634
options . otherArgs = options . otherArgs || { } ;
622
635
options . otherArgs . headers = options . otherArgs . headers || { } ;
623
636
options . otherArgs . headers [ 'x-goog-request-params' ] =
624
- gax . routingHeader . fromParams ( {
637
+ this . _gaxModule . routingHeader . fromParams ( {
625
638
'phrase_set.name' : request . phraseSet ! . name || '' ,
626
639
} ) ;
627
640
this . initialize ( ) ;
@@ -708,7 +721,7 @@ export class AdaptationClient {
708
721
options . otherArgs = options . otherArgs || { } ;
709
722
options . otherArgs . headers = options . otherArgs . headers || { } ;
710
723
options . otherArgs . headers [ 'x-goog-request-params' ] =
711
- gax . routingHeader . fromParams ( {
724
+ this . _gaxModule . routingHeader . fromParams ( {
712
725
name : request . name || '' ,
713
726
} ) ;
714
727
this . initialize ( ) ;
@@ -815,7 +828,7 @@ export class AdaptationClient {
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
parent : request . parent || '' ,
820
833
} ) ;
821
834
this . initialize ( ) ;
@@ -902,7 +915,7 @@ export class AdaptationClient {
902
915
options . otherArgs = options . otherArgs || { } ;
903
916
options . otherArgs . headers = options . otherArgs . headers || { } ;
904
917
options . otherArgs . headers [ 'x-goog-request-params' ] =
905
- gax . routingHeader . fromParams ( {
918
+ this . _gaxModule . routingHeader . fromParams ( {
906
919
name : request . name || '' ,
907
920
} ) ;
908
921
this . initialize ( ) ;
@@ -1006,7 +1019,7 @@ export class AdaptationClient {
1006
1019
options . otherArgs = options . otherArgs || { } ;
1007
1020
options . otherArgs . headers = options . otherArgs . headers || { } ;
1008
1021
options . otherArgs . headers [ 'x-goog-request-params' ] =
1009
- gax . routingHeader . fromParams ( {
1022
+ this . _gaxModule . routingHeader . fromParams ( {
1010
1023
'custom_class.name' : request . customClass ! . name || '' ,
1011
1024
} ) ;
1012
1025
this . initialize ( ) ;
@@ -1105,7 +1118,7 @@ export class AdaptationClient {
1105
1118
options . otherArgs = options . otherArgs || { } ;
1106
1119
options . otherArgs . headers = options . otherArgs . headers || { } ;
1107
1120
options . otherArgs . headers [ 'x-goog-request-params' ] =
1108
- gax . routingHeader . fromParams ( {
1121
+ this . _gaxModule . routingHeader . fromParams ( {
1109
1122
name : request . name || '' ,
1110
1123
} ) ;
1111
1124
this . initialize ( ) ;
@@ -1213,7 +1226,7 @@ export class AdaptationClient {
1213
1226
options . otherArgs = options . otherArgs || { } ;
1214
1227
options . otherArgs . headers = options . otherArgs . headers || { } ;
1215
1228
options . otherArgs . headers [ 'x-goog-request-params' ] =
1216
- gax . routingHeader . fromParams ( {
1229
+ this . _gaxModule . routingHeader . fromParams ( {
1217
1230
parent : request . parent || '' ,
1218
1231
} ) ;
1219
1232
this . initialize ( ) ;
@@ -1266,7 +1279,7 @@ export class AdaptationClient {
1266
1279
options . otherArgs = options . otherArgs || { } ;
1267
1280
options . otherArgs . headers = options . otherArgs . headers || { } ;
1268
1281
options . otherArgs . headers [ 'x-goog-request-params' ] =
1269
- gax . routingHeader . fromParams ( {
1282
+ this . _gaxModule . routingHeader . fromParams ( {
1270
1283
parent : request . parent || '' ,
1271
1284
} ) ;
1272
1285
const defaultCallSettings = this . _defaults [ 'listPhraseSet' ] ;
@@ -1328,7 +1341,7 @@ export class AdaptationClient {
1328
1341
options . otherArgs = options . otherArgs || { } ;
1329
1342
options . otherArgs . headers = options . otherArgs . headers || { } ;
1330
1343
options . otherArgs . headers [ 'x-goog-request-params' ] =
1331
- gax . routingHeader . fromParams ( {
1344
+ this . _gaxModule . routingHeader . fromParams ( {
1332
1345
parent : request . parent || '' ,
1333
1346
} ) ;
1334
1347
const defaultCallSettings = this . _defaults [ 'listPhraseSet' ] ;
@@ -1447,7 +1460,7 @@ export class AdaptationClient {
1447
1460
options . otherArgs = options . otherArgs || { } ;
1448
1461
options . otherArgs . headers = options . otherArgs . headers || { } ;
1449
1462
options . otherArgs . headers [ 'x-goog-request-params' ] =
1450
- gax . routingHeader . fromParams ( {
1463
+ this . _gaxModule . routingHeader . fromParams ( {
1451
1464
parent : request . parent || '' ,
1452
1465
} ) ;
1453
1466
this . initialize ( ) ;
@@ -1500,7 +1513,7 @@ export class AdaptationClient {
1500
1513
options . otherArgs = options . otherArgs || { } ;
1501
1514
options . otherArgs . headers = options . otherArgs . headers || { } ;
1502
1515
options . otherArgs . headers [ 'x-goog-request-params' ] =
1503
- gax . routingHeader . fromParams ( {
1516
+ this . _gaxModule . routingHeader . fromParams ( {
1504
1517
parent : request . parent || '' ,
1505
1518
} ) ;
1506
1519
const defaultCallSettings = this . _defaults [ 'listCustomClasses' ] ;
@@ -1562,7 +1575,7 @@ export class AdaptationClient {
1562
1575
options . otherArgs = options . otherArgs || { } ;
1563
1576
options . otherArgs . headers = options . otherArgs . headers || { } ;
1564
1577
options . otherArgs . headers [ 'x-goog-request-params' ] =
1565
- gax . routingHeader . fromParams ( {
1578
+ this . _gaxModule . routingHeader . fromParams ( {
1566
1579
parent : request . parent || '' ,
1567
1580
} ) ;
1568
1581
const defaultCallSettings = this . _defaults [ 'listCustomClasses' ] ;
0 commit comments