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 './private_catalog_client_config.json' ;
39
-
40
38
const version = require ( '../../../package.json' ) . version ;
41
39
42
40
/**
@@ -116,8 +114,18 @@ export class PrivateCatalogClient {
116
114
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
117
115
* For more information, please check the
118
116
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
117
+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
118
+ * need to avoid loading the default gRPC version and want to use the fallback
119
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
120
+ * ```
121
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
122
+ * const client = new PrivateCatalogClient({fallback: 'rest'}, gax);
123
+ * ```
119
124
*/
120
- constructor ( opts ?: ClientOptions ) {
125
+ constructor (
126
+ opts ?: ClientOptions ,
127
+ gaxInstance ?: typeof gax | typeof gax . fallback
128
+ ) {
121
129
// Ensure that options include all the required fields.
122
130
const staticMembers = this . constructor as typeof PrivateCatalogClient ;
123
131
const servicePath =
@@ -137,8 +145,13 @@ export class PrivateCatalogClient {
137
145
opts [ 'scopes' ] = staticMembers . scopes ;
138
146
}
139
147
148
+ // Load google-gax module synchronously if needed
149
+ if ( ! gaxInstance ) {
150
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
151
+ }
152
+
140
153
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
141
- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
154
+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
142
155
143
156
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
144
157
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -228,7 +241,7 @@ export class PrivateCatalogClient {
228
241
this . innerApiCalls = { } ;
229
242
230
243
// Add a warn function to the client constructor so it can be easily tested.
231
- this . warn = gax . warn ;
244
+ this . warn = this . _gaxModule . warn ;
232
245
}
233
246
234
247
/**
@@ -454,7 +467,7 @@ export class PrivateCatalogClient {
454
467
options . otherArgs = options . otherArgs || { } ;
455
468
options . otherArgs . headers = options . otherArgs . headers || { } ;
456
469
options . otherArgs . headers [ 'x-goog-request-params' ] =
457
- gax . routingHeader . fromParams ( {
470
+ this . _gaxModule . routingHeader . fromParams ( {
458
471
resource : request . resource || '' ,
459
472
} ) ;
460
473
this . initialize ( ) ;
@@ -501,7 +514,7 @@ export class PrivateCatalogClient {
501
514
options . otherArgs = options . otherArgs || { } ;
502
515
options . otherArgs . headers = options . otherArgs . headers || { } ;
503
516
options . otherArgs . headers [ 'x-goog-request-params' ] =
504
- gax . routingHeader . fromParams ( {
517
+ this . _gaxModule . routingHeader . fromParams ( {
505
518
resource : request . resource || '' ,
506
519
} ) ;
507
520
const defaultCallSettings = this . _defaults [ 'searchCatalogs' ] ;
@@ -557,7 +570,7 @@ export class PrivateCatalogClient {
557
570
options . otherArgs = options . otherArgs || { } ;
558
571
options . otherArgs . headers = options . otherArgs . headers || { } ;
559
572
options . otherArgs . headers [ 'x-goog-request-params' ] =
560
- gax . routingHeader . fromParams ( {
573
+ this . _gaxModule . routingHeader . fromParams ( {
561
574
resource : request . resource || '' ,
562
575
} ) ;
563
576
const defaultCallSettings = this . _defaults [ 'searchCatalogs' ] ;
@@ -672,7 +685,7 @@ export class PrivateCatalogClient {
672
685
options . otherArgs = options . otherArgs || { } ;
673
686
options . otherArgs . headers = options . otherArgs . headers || { } ;
674
687
options . otherArgs . headers [ 'x-goog-request-params' ] =
675
- gax . routingHeader . fromParams ( {
688
+ this . _gaxModule . routingHeader . fromParams ( {
676
689
resource : request . resource || '' ,
677
690
} ) ;
678
691
this . initialize ( ) ;
@@ -720,7 +733,7 @@ export class PrivateCatalogClient {
720
733
options . otherArgs = options . otherArgs || { } ;
721
734
options . otherArgs . headers = options . otherArgs . headers || { } ;
722
735
options . otherArgs . headers [ 'x-goog-request-params' ] =
723
- gax . routingHeader . fromParams ( {
736
+ this . _gaxModule . routingHeader . fromParams ( {
724
737
resource : request . resource || '' ,
725
738
} ) ;
726
739
const defaultCallSettings = this . _defaults [ 'searchProducts' ] ;
@@ -777,7 +790,7 @@ export class PrivateCatalogClient {
777
790
options . otherArgs = options . otherArgs || { } ;
778
791
options . otherArgs . headers = options . otherArgs . headers || { } ;
779
792
options . otherArgs . headers [ 'x-goog-request-params' ] =
780
- gax . routingHeader . fromParams ( {
793
+ this . _gaxModule . routingHeader . fromParams ( {
781
794
resource : request . resource || '' ,
782
795
} ) ;
783
796
const defaultCallSettings = this . _defaults [ 'searchProducts' ] ;
@@ -892,7 +905,7 @@ export class PrivateCatalogClient {
892
905
options . otherArgs = options . otherArgs || { } ;
893
906
options . otherArgs . headers = options . otherArgs . headers || { } ;
894
907
options . otherArgs . headers [ 'x-goog-request-params' ] =
895
- gax . routingHeader . fromParams ( {
908
+ this . _gaxModule . routingHeader . fromParams ( {
896
909
resource : request . resource || '' ,
897
910
} ) ;
898
911
this . initialize ( ) ;
@@ -940,7 +953,7 @@ export class PrivateCatalogClient {
940
953
options . otherArgs = options . otherArgs || { } ;
941
954
options . otherArgs . headers = options . otherArgs . headers || { } ;
942
955
options . otherArgs . headers [ 'x-goog-request-params' ] =
943
- gax . routingHeader . fromParams ( {
956
+ this . _gaxModule . routingHeader . fromParams ( {
944
957
resource : request . resource || '' ,
945
958
} ) ;
946
959
const defaultCallSettings = this . _defaults [ 'searchVersions' ] ;
@@ -997,7 +1010,7 @@ export class PrivateCatalogClient {
997
1010
options . otherArgs = options . otherArgs || { } ;
998
1011
options . otherArgs . headers = options . otherArgs . headers || { } ;
999
1012
options . otherArgs . headers [ 'x-goog-request-params' ] =
1000
- gax . routingHeader . fromParams ( {
1013
+ this . _gaxModule . routingHeader . fromParams ( {
1001
1014
resource : request . resource || '' ,
1002
1015
} ) ;
1003
1016
const defaultCallSettings = this . _defaults [ 'searchVersions' ] ;
0 commit comments