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 { Callback , CallOptions , Descriptors , ClientOptions } from 'google-gax' ;
20
+ import type * as gax from 'google-gax' ;
21
+ import type {
22
+ Callback ,
23
+ CallOptions ,
24
+ Descriptors ,
25
+ ClientOptions ,
26
+ } from 'google-gax' ;
22
27
23
28
import * as protos from '../../protos/protos' ;
24
29
import jsonProtos = require( '../../protos/protos.json' ) ;
@@ -28,7 +33,6 @@ import jsonProtos = require('../../protos/protos.json');
28
33
* This file defines retry strategy and timeouts for all API methods in this library.
29
34
*/
30
35
import * as gapicConfig from './phishing_protection_service_v1_beta1_client_config.json' ;
31
-
32
36
const version = require ( '../../../package.json' ) . version ;
33
37
34
38
/**
@@ -88,8 +92,18 @@ export class PhishingProtectionServiceV1Beta1Client {
88
92
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
89
93
* For more information, please check the
90
94
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
95
+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
96
+ * need to avoid loading the default gRPC version and want to use the fallback
97
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
98
+ * ```
99
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
100
+ * const client = new PhishingProtectionServiceV1Beta1Client({fallback: 'rest'}, gax);
101
+ * ```
91
102
*/
92
- constructor ( opts ?: ClientOptions ) {
103
+ constructor (
104
+ opts ?: ClientOptions ,
105
+ gaxInstance ?: typeof gax | typeof gax . fallback
106
+ ) {
93
107
// Ensure that options include all the required fields.
94
108
const staticMembers = this
95
109
. constructor as typeof PhishingProtectionServiceV1Beta1Client ;
@@ -110,8 +124,13 @@ export class PhishingProtectionServiceV1Beta1Client {
110
124
opts [ 'scopes' ] = staticMembers . scopes ;
111
125
}
112
126
127
+ // Load google-gax module synchronously if needed
128
+ if ( ! gaxInstance ) {
129
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
130
+ }
131
+
113
132
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
114
- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
133
+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
115
134
116
135
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
117
136
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -174,7 +193,7 @@ export class PhishingProtectionServiceV1Beta1Client {
174
193
this . innerApiCalls = { } ;
175
194
176
195
// Add a warn function to the client constructor so it can be easily tested.
177
- this . warn = gax . warn ;
196
+ this . warn = this . _gaxModule . warn ;
178
197
}
179
198
180
199
/**
@@ -393,7 +412,7 @@ export class PhishingProtectionServiceV1Beta1Client {
393
412
options . otherArgs = options . otherArgs || { } ;
394
413
options . otherArgs . headers = options . otherArgs . headers || { } ;
395
414
options . otherArgs . headers [ 'x-goog-request-params' ] =
396
- gax . routingHeader . fromParams ( {
415
+ this . _gaxModule . routingHeader . fromParams ( {
397
416
parent : request . parent || '' ,
398
417
} ) ;
399
418
this . initialize ( ) ;
0 commit comments