1717// ** All changes to this file may be overwritten. **
1818
1919/* global window */
20- import * as gax from 'google-gax' ;
21- import {
20+ import type * as gax from 'google-gax' ;
21+ import type {
2222 Callback ,
2323 CallOptions ,
2424 Descriptors ,
@@ -28,7 +28,6 @@ import {
2828 PaginationCallback ,
2929 GaxCall ,
3030} from 'google-gax' ;
31-
3231import { Transform } from 'stream' ;
3332import * as protos from '../../protos/protos' ;
3433import jsonProtos = require( '../../protos/protos.json' ) ;
@@ -38,7 +37,6 @@ import jsonProtos = require('../../protos/protos.json');
3837 * This file defines retry strategy and timeouts for all API methods in this library.
3938 */
4039import * as gapicConfig from './services_client_config.json' ;
41- import { operationsProtos } from 'google-gax' ;
4240const version = require ( '../../../package.json' ) . version ;
4341
4442/**
@@ -99,8 +97,18 @@ export class ServicesClient {
9997 * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
10098 * For more information, please check the
10199 * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
100+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
101+ * need to avoid loading the default gRPC version and want to use the fallback
102+ * HTTP implementation. Load only fallback version and pass it to the constructor:
103+ * ```
104+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
105+ * const client = new ServicesClient({fallback: 'rest'}, gax);
106+ * ```
102107 */
103- constructor ( opts ?: ClientOptions ) {
108+ constructor (
109+ opts ?: ClientOptions ,
110+ gaxInstance ?: typeof gax | typeof gax . fallback
111+ ) {
104112 // Ensure that options include all the required fields.
105113 const staticMembers = this . constructor as typeof ServicesClient ;
106114 const servicePath =
@@ -120,8 +128,13 @@ export class ServicesClient {
120128 opts [ 'scopes' ] = staticMembers . scopes ;
121129 }
122130
131+ // Load google-gax module synchronously if needed
132+ if ( ! gaxInstance ) {
133+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
134+ }
135+
123136 // Choose either gRPC or proto-over-HTTP implementation of google-gax.
124- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
137+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
125138
126139 // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
127140 this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -269,7 +282,7 @@ export class ServicesClient {
269282 this . innerApiCalls = { } ;
270283
271284 // Add a warn function to the client constructor so it can be easily tested.
272- this . warn = gax . warn ;
285+ this . warn = this . _gaxModule . warn ;
273286 }
274287
275288 /**
@@ -490,7 +503,7 @@ export class ServicesClient {
490503 }
491504 }
492505 options . otherArgs . headers [ 'x-goog-request-params' ] =
493- gax . routingHeader . fromParams ( routingParameter ) ;
506+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
494507 this . initialize ( ) ;
495508 return this . innerApiCalls . getService ( request , options , callback ) ;
496509 }
@@ -576,7 +589,7 @@ export class ServicesClient {
576589 options . otherArgs = options . otherArgs || { } ;
577590 options . otherArgs . headers = options . otherArgs . headers || { } ;
578591 options . otherArgs . headers [ 'x-goog-request-params' ] =
579- gax . routingHeader . fromParams ( {
592+ this . _gaxModule . routingHeader . fromParams ( {
580593 resource : request . resource || '' ,
581594 } ) ;
582595 this . initialize ( ) ;
@@ -672,7 +685,7 @@ export class ServicesClient {
672685 options . otherArgs = options . otherArgs || { } ;
673686 options . otherArgs . headers = options . otherArgs . headers || { } ;
674687 options . otherArgs . headers [ 'x-goog-request-params' ] =
675- gax . routingHeader . fromParams ( {
688+ this . _gaxModule . routingHeader . fromParams ( {
676689 resource : request . resource || '' ,
677690 } ) ;
678691 this . initialize ( ) ;
@@ -763,7 +776,7 @@ export class ServicesClient {
763776 options . otherArgs = options . otherArgs || { } ;
764777 options . otherArgs . headers = options . otherArgs . headers || { } ;
765778 options . otherArgs . headers [ 'x-goog-request-params' ] =
766- gax . routingHeader . fromParams ( {
779+ this . _gaxModule . routingHeader . fromParams ( {
767780 resource : request . resource || '' ,
768781 } ) ;
769782 this . initialize ( ) ;
@@ -889,7 +902,7 @@ export class ServicesClient {
889902 }
890903 }
891904 options . otherArgs . headers [ 'x-goog-request-params' ] =
892- gax . routingHeader . fromParams ( routingParameter ) ;
905+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
893906 this . initialize ( ) ;
894907 return this . innerApiCalls . createService ( request , options , callback ) ;
895908 }
@@ -913,11 +926,12 @@ export class ServicesClient {
913926 protos . google . cloud . run . v2 . Service
914927 >
915928 > {
916- const request = new operationsProtos . google . longrunning . GetOperationRequest (
917- { name}
918- ) ;
929+ const request =
930+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
931+ { name}
932+ ) ;
919933 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
920- const decodeOperation = new gax . Operation (
934+ const decodeOperation = new this . _gaxModule . Operation (
921935 operation ,
922936 this . descriptors . longrunning . createService ,
923937 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1044,7 +1058,7 @@ export class ServicesClient {
10441058 }
10451059 }
10461060 options . otherArgs . headers [ 'x-goog-request-params' ] =
1047- gax . routingHeader . fromParams ( routingParameter ) ;
1061+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
10481062 this . initialize ( ) ;
10491063 return this . innerApiCalls . updateService ( request , options , callback ) ;
10501064 }
@@ -1068,11 +1082,12 @@ export class ServicesClient {
10681082 protos . google . cloud . run . v2 . Service
10691083 >
10701084 > {
1071- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1072- { name}
1073- ) ;
1085+ const request =
1086+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1087+ { name}
1088+ ) ;
10741089 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1075- const decodeOperation = new gax . Operation (
1090+ const decodeOperation = new this . _gaxModule . Operation (
10761091 operation ,
10771092 this . descriptors . longrunning . updateService ,
10781093 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1201,7 +1216,7 @@ export class ServicesClient {
12011216 }
12021217 }
12031218 options . otherArgs . headers [ 'x-goog-request-params' ] =
1204- gax . routingHeader . fromParams ( routingParameter ) ;
1219+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
12051220 this . initialize ( ) ;
12061221 return this . innerApiCalls . deleteService ( request , options , callback ) ;
12071222 }
@@ -1225,11 +1240,12 @@ export class ServicesClient {
12251240 protos . google . cloud . run . v2 . Service
12261241 >
12271242 > {
1228- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1229- { name}
1230- ) ;
1243+ const request =
1244+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1245+ { name}
1246+ ) ;
12311247 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1232- const decodeOperation = new gax . Operation (
1248+ const decodeOperation = new this . _gaxModule . Operation (
12331249 operation ,
12341250 this . descriptors . longrunning . deleteService ,
12351251 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1341,7 +1357,7 @@ export class ServicesClient {
13411357 }
13421358 }
13431359 options . otherArgs . headers [ 'x-goog-request-params' ] =
1344- gax . routingHeader . fromParams ( routingParameter ) ;
1360+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
13451361 this . initialize ( ) ;
13461362 return this . innerApiCalls . listServices ( request , options , callback ) ;
13471363 }
@@ -1395,7 +1411,7 @@ export class ServicesClient {
13951411 }
13961412 }
13971413 options . otherArgs . headers [ 'x-goog-request-params' ] =
1398- gax . routingHeader . fromParams ( routingParameter ) ;
1414+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
13991415 const defaultCallSettings = this . _defaults [ 'listServices' ] ;
14001416 const callSettings = defaultCallSettings . merge ( options ) ;
14011417 this . initialize ( ) ;
@@ -1458,7 +1474,7 @@ export class ServicesClient {
14581474 }
14591475 }
14601476 options . otherArgs . headers [ 'x-goog-request-params' ] =
1461- gax . routingHeader . fromParams ( routingParameter ) ;
1477+ this . _gaxModule . routingHeader . fromParams ( routingParameter ) ;
14621478 const defaultCallSettings = this . _defaults [ 'listServices' ] ;
14631479 const callSettings = defaultCallSettings . merge ( options ) ;
14641480 this . initialize ( ) ;
0 commit comments