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 './container_analysis_v1_beta1_client_config.json' ;
39
-
40
38
const version = require ( '../../../package.json' ) . version ;
41
39
42
40
/**
@@ -108,8 +106,18 @@ export class ContainerAnalysisV1Beta1Client {
108
106
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
109
107
* For more information, please check the
110
108
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
109
+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
110
+ * need to avoid loading the default gRPC version and want to use the fallback
111
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
112
+ * ```
113
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
114
+ * const client = new ContainerAnalysisV1Beta1Client({fallback: 'rest'}, gax);
115
+ * ```
111
116
*/
112
- constructor ( opts ?: ClientOptions ) {
117
+ constructor (
118
+ opts ?: ClientOptions ,
119
+ gaxInstance ?: typeof gax | typeof gax . fallback
120
+ ) {
113
121
// Ensure that options include all the required fields.
114
122
const staticMembers = this
115
123
. constructor as typeof ContainerAnalysisV1Beta1Client ;
@@ -130,8 +138,13 @@ export class ContainerAnalysisV1Beta1Client {
130
138
opts [ 'scopes' ] = staticMembers . scopes ;
131
139
}
132
140
141
+ // Load google-gax module synchronously if needed
142
+ if ( ! gaxInstance ) {
143
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
144
+ }
145
+
133
146
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
134
- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
147
+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
135
148
136
149
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
137
150
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -208,7 +221,7 @@ export class ContainerAnalysisV1Beta1Client {
208
221
this . innerApiCalls = { } ;
209
222
210
223
// Add a warn function to the client constructor so it can be easily tested.
211
- this . warn = gax . warn ;
224
+ this . warn = this . _gaxModule . warn ;
212
225
}
213
226
214
227
/**
@@ -430,8 +443,8 @@ export class ContainerAnalysisV1Beta1Client {
430
443
options . otherArgs = options . otherArgs || { } ;
431
444
options . otherArgs . headers = options . otherArgs . headers || { } ;
432
445
options . otherArgs . headers [ 'x-goog-request-params' ] =
433
- gax . routingHeader . fromParams ( {
434
- resource : request . resource || '' ,
446
+ this . _gaxModule . routingHeader . fromParams ( {
447
+ resource : request . resource ?? '' ,
435
448
} ) ;
436
449
this . initialize ( ) ;
437
450
return this . innerApiCalls . setIamPolicy ( request , options , callback ) ;
@@ -524,8 +537,8 @@ export class ContainerAnalysisV1Beta1Client {
524
537
options . otherArgs = options . otherArgs || { } ;
525
538
options . otherArgs . headers = options . otherArgs . headers || { } ;
526
539
options . otherArgs . headers [ 'x-goog-request-params' ] =
527
- gax . routingHeader . fromParams ( {
528
- resource : request . resource || '' ,
540
+ this . _gaxModule . routingHeader . fromParams ( {
541
+ resource : request . resource ?? '' ,
529
542
} ) ;
530
543
this . initialize ( ) ;
531
544
return this . innerApiCalls . getIamPolicy ( request , options , callback ) ;
@@ -619,8 +632,8 @@ export class ContainerAnalysisV1Beta1Client {
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 ( {
623
- resource : request . resource || '' ,
635
+ this . _gaxModule . routingHeader . fromParams ( {
636
+ resource : request . resource ?? '' ,
624
637
} ) ;
625
638
this . initialize ( ) ;
626
639
return this . innerApiCalls . testIamPermissions ( request , options , callback ) ;
@@ -717,8 +730,8 @@ export class ContainerAnalysisV1Beta1Client {
717
730
options . otherArgs = options . otherArgs || { } ;
718
731
options . otherArgs . headers = options . otherArgs . headers || { } ;
719
732
options . otherArgs . headers [ 'x-goog-request-params' ] =
720
- gax . routingHeader . fromParams ( {
721
- name : request . name || '' ,
733
+ this . _gaxModule . routingHeader . fromParams ( {
734
+ name : request . name ?? '' ,
722
735
} ) ;
723
736
this . initialize ( ) ;
724
737
return this . innerApiCalls . getScanConfig ( request , options , callback ) ;
@@ -817,8 +830,8 @@ export class ContainerAnalysisV1Beta1Client {
817
830
options . otherArgs = options . otherArgs || { } ;
818
831
options . otherArgs . headers = options . otherArgs . headers || { } ;
819
832
options . otherArgs . headers [ 'x-goog-request-params' ] =
820
- gax . routingHeader . fromParams ( {
821
- name : request . name || '' ,
833
+ this . _gaxModule . routingHeader . fromParams ( {
834
+ name : request . name ?? '' ,
822
835
} ) ;
823
836
this . initialize ( ) ;
824
837
return this . innerApiCalls . updateScanConfig ( request , options , callback ) ;
@@ -919,8 +932,8 @@ export class ContainerAnalysisV1Beta1Client {
919
932
options . otherArgs = options . otherArgs || { } ;
920
933
options . otherArgs . headers = options . otherArgs . headers || { } ;
921
934
options . otherArgs . headers [ 'x-goog-request-params' ] =
922
- gax . routingHeader . fromParams ( {
923
- parent : request . parent || '' ,
935
+ this . _gaxModule . routingHeader . fromParams ( {
936
+ parent : request . parent ?? '' ,
924
937
} ) ;
925
938
this . initialize ( ) ;
926
939
return this . innerApiCalls . listScanConfigs ( request , options , callback ) ;
@@ -960,8 +973,8 @@ export class ContainerAnalysisV1Beta1Client {
960
973
options . otherArgs = options . otherArgs || { } ;
961
974
options . otherArgs . headers = options . otherArgs . headers || { } ;
962
975
options . otherArgs . headers [ 'x-goog-request-params' ] =
963
- gax . routingHeader . fromParams ( {
964
- parent : request . parent || '' ,
976
+ this . _gaxModule . routingHeader . fromParams ( {
977
+ parent : request . parent ?? '' ,
965
978
} ) ;
966
979
const defaultCallSettings = this . _defaults [ 'listScanConfigs' ] ;
967
980
const callSettings = defaultCallSettings . merge ( options ) ;
@@ -1010,8 +1023,8 @@ export class ContainerAnalysisV1Beta1Client {
1010
1023
options . otherArgs = options . otherArgs || { } ;
1011
1024
options . otherArgs . headers = options . otherArgs . headers || { } ;
1012
1025
options . otherArgs . headers [ 'x-goog-request-params' ] =
1013
- gax . routingHeader . fromParams ( {
1014
- parent : request . parent || '' ,
1026
+ this . _gaxModule . routingHeader . fromParams ( {
1027
+ parent : request . parent ?? '' ,
1015
1028
} ) ;
1016
1029
const defaultCallSettings = this . _defaults [ 'listScanConfigs' ] ;
1017
1030
const callSettings = defaultCallSettings . merge ( options ) ;
0 commit comments