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 './os_login_service_client_config.json' ;
31
-
32
36
const version = require ( '../../../package.json' ) . version ;
33
37
34
38
/**
@@ -91,8 +95,18 @@ export class OsLoginServiceClient {
91
95
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
92
96
* For more information, please check the
93
97
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
98
+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
99
+ * need to avoid loading the default gRPC version and want to use the fallback
100
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
101
+ * ```
102
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
103
+ * const client = new OsLoginServiceClient({fallback: 'rest'}, gax);
104
+ * ```
94
105
*/
95
- constructor ( opts ?: ClientOptions ) {
106
+ constructor (
107
+ opts ?: ClientOptions ,
108
+ gaxInstance ?: typeof gax | typeof gax . fallback
109
+ ) {
96
110
// Ensure that options include all the required fields.
97
111
const staticMembers = this . constructor as typeof OsLoginServiceClient ;
98
112
const servicePath =
@@ -112,8 +126,13 @@ export class OsLoginServiceClient {
112
126
opts [ 'scopes' ] = staticMembers . scopes ;
113
127
}
114
128
129
+ // Load google-gax module synchronously if needed
130
+ if ( ! gaxInstance ) {
131
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
132
+ }
133
+
115
134
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
116
- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
135
+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
117
136
118
137
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
119
138
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -180,7 +199,7 @@ export class OsLoginServiceClient {
180
199
this . innerApiCalls = { } ;
181
200
182
201
// Add a warn function to the client constructor so it can be easily tested.
183
- this . warn = gax . warn ;
202
+ this . warn = this . _gaxModule . warn ;
184
203
}
185
204
186
205
/**
@@ -395,7 +414,7 @@ export class OsLoginServiceClient {
395
414
options . otherArgs = options . otherArgs || { } ;
396
415
options . otherArgs . headers = options . otherArgs . headers || { } ;
397
416
options . otherArgs . headers [ 'x-goog-request-params' ] =
398
- gax . routingHeader . fromParams ( {
417
+ this . _gaxModule . routingHeader . fromParams ( {
399
418
name : request . name || '' ,
400
419
} ) ;
401
420
this . initialize ( ) ;
@@ -488,7 +507,7 @@ export class OsLoginServiceClient {
488
507
options . otherArgs = options . otherArgs || { } ;
489
508
options . otherArgs . headers = options . otherArgs . headers || { } ;
490
509
options . otherArgs . headers [ 'x-goog-request-params' ] =
491
- gax . routingHeader . fromParams ( {
510
+ this . _gaxModule . routingHeader . fromParams ( {
492
511
name : request . name || '' ,
493
512
} ) ;
494
513
this . initialize ( ) ;
@@ -578,7 +597,7 @@ export class OsLoginServiceClient {
578
597
options . otherArgs = options . otherArgs || { } ;
579
598
options . otherArgs . headers = options . otherArgs . headers || { } ;
580
599
options . otherArgs . headers [ 'x-goog-request-params' ] =
581
- gax . routingHeader . fromParams ( {
600
+ this . _gaxModule . routingHeader . fromParams ( {
582
601
name : request . name || '' ,
583
602
} ) ;
584
603
this . initialize ( ) ;
@@ -665,7 +684,7 @@ export class OsLoginServiceClient {
665
684
options . otherArgs = options . otherArgs || { } ;
666
685
options . otherArgs . headers = options . otherArgs . headers || { } ;
667
686
options . otherArgs . headers [ 'x-goog-request-params' ] =
668
- gax . routingHeader . fromParams ( {
687
+ this . _gaxModule . routingHeader . fromParams ( {
669
688
name : request . name || '' ,
670
689
} ) ;
671
690
this . initialize ( ) ;
@@ -762,7 +781,7 @@ export class OsLoginServiceClient {
762
781
options . otherArgs = options . otherArgs || { } ;
763
782
options . otherArgs . headers = options . otherArgs . headers || { } ;
764
783
options . otherArgs . headers [ 'x-goog-request-params' ] =
765
- gax . routingHeader . fromParams ( {
784
+ this . _gaxModule . routingHeader . fromParams ( {
766
785
parent : request . parent || '' ,
767
786
} ) ;
768
787
this . initialize ( ) ;
@@ -860,7 +879,7 @@ export class OsLoginServiceClient {
860
879
options . otherArgs = options . otherArgs || { } ;
861
880
options . otherArgs . headers = options . otherArgs . headers || { } ;
862
881
options . otherArgs . headers [ 'x-goog-request-params' ] =
863
- gax . routingHeader . fromParams ( {
882
+ this . _gaxModule . routingHeader . fromParams ( {
864
883
name : request . name || '' ,
865
884
} ) ;
866
885
this . initialize ( ) ;
0 commit comments