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 './service_manager_client_config.json' ;
41- import { operationsProtos } from 'google-gax' ;
4240const version = require ( '../../../package.json' ) . version ;
4341
4442/**
@@ -99,8 +97,18 @@ export class ServiceManagerClient {
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 ServiceManagerClient({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 ServiceManagerClient ;
106114 const servicePath =
@@ -120,8 +128,13 @@ export class ServiceManagerClient {
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 ) ;
@@ -308,7 +321,7 @@ export class ServiceManagerClient {
308321 this . innerApiCalls = { } ;
309322
310323 // Add a warn function to the client constructor so it can be easily tested.
311- this . warn = gax . warn ;
324+ this . warn = this . _gaxModule . warn ;
312325 }
313326
314327 /**
@@ -535,7 +548,7 @@ export class ServiceManagerClient {
535548 options . otherArgs = options . otherArgs || { } ;
536549 options . otherArgs . headers = options . otherArgs . headers || { } ;
537550 options . otherArgs . headers [ 'x-goog-request-params' ] =
538- gax . routingHeader . fromParams ( {
551+ this . _gaxModule . routingHeader . fromParams ( {
539552 service_name : request . serviceName || '' ,
540553 } ) ;
541554 this . initialize ( ) ;
@@ -642,7 +655,7 @@ export class ServiceManagerClient {
642655 options . otherArgs = options . otherArgs || { } ;
643656 options . otherArgs . headers = options . otherArgs . headers || { } ;
644657 options . otherArgs . headers [ 'x-goog-request-params' ] =
645- gax . routingHeader . fromParams ( {
658+ this . _gaxModule . routingHeader . fromParams ( {
646659 service_name : request . serviceName || '' ,
647660 config_id : request . configId || '' ,
648661 } ) ;
@@ -751,7 +764,7 @@ export class ServiceManagerClient {
751764 options . otherArgs = options . otherArgs || { } ;
752765 options . otherArgs . headers = options . otherArgs . headers || { } ;
753766 options . otherArgs . headers [ 'x-goog-request-params' ] =
754- gax . routingHeader . fromParams ( {
767+ this . _gaxModule . routingHeader . fromParams ( {
755768 service_name : request . serviceName || '' ,
756769 } ) ;
757770 this . initialize ( ) ;
@@ -853,7 +866,7 @@ export class ServiceManagerClient {
853866 options . otherArgs = options . otherArgs || { } ;
854867 options . otherArgs . headers = options . otherArgs . headers || { } ;
855868 options . otherArgs . headers [ 'x-goog-request-params' ] =
856- gax . routingHeader . fromParams ( {
869+ this . _gaxModule . routingHeader . fromParams ( {
857870 service_name : request . serviceName || '' ,
858871 rollout_id : request . rolloutId || '' ,
859872 } ) ;
@@ -1103,11 +1116,12 @@ export class ServiceManagerClient {
11031116 protos . google . api . servicemanagement . v1 . OperationMetadata
11041117 >
11051118 > {
1106- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1107- { name}
1108- ) ;
1119+ const request =
1120+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1121+ { name}
1122+ ) ;
11091123 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1110- const decodeOperation = new gax . Operation (
1124+ const decodeOperation = new this . _gaxModule . Operation (
11111125 operation ,
11121126 this . descriptors . longrunning . createService ,
11131127 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1223,7 +1237,7 @@ export class ServiceManagerClient {
12231237 options . otherArgs = options . otherArgs || { } ;
12241238 options . otherArgs . headers = options . otherArgs . headers || { } ;
12251239 options . otherArgs . headers [ 'x-goog-request-params' ] =
1226- gax . routingHeader . fromParams ( {
1240+ this . _gaxModule . routingHeader . fromParams ( {
12271241 service_name : request . serviceName || '' ,
12281242 } ) ;
12291243 this . initialize ( ) ;
@@ -1249,11 +1263,12 @@ export class ServiceManagerClient {
12491263 protos . google . api . servicemanagement . v1 . OperationMetadata
12501264 >
12511265 > {
1252- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1253- { name}
1254- ) ;
1266+ const request =
1267+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1268+ { name}
1269+ ) ;
12551270 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1256- const decodeOperation = new gax . Operation (
1271+ const decodeOperation = new this . _gaxModule . Operation (
12571272 operation ,
12581273 this . descriptors . longrunning . deleteService ,
12591274 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1367,7 +1382,7 @@ export class ServiceManagerClient {
13671382 options . otherArgs = options . otherArgs || { } ;
13681383 options . otherArgs . headers = options . otherArgs . headers || { } ;
13691384 options . otherArgs . headers [ 'x-goog-request-params' ] =
1370- gax . routingHeader . fromParams ( {
1385+ this . _gaxModule . routingHeader . fromParams ( {
13711386 service_name : request . serviceName || '' ,
13721387 } ) ;
13731388 this . initialize ( ) ;
@@ -1393,11 +1408,12 @@ export class ServiceManagerClient {
13931408 protos . google . api . servicemanagement . v1 . OperationMetadata
13941409 >
13951410 > {
1396- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1397- { name}
1398- ) ;
1411+ const request =
1412+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1413+ { name}
1414+ ) ;
13991415 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1400- const decodeOperation = new gax . Operation (
1416+ const decodeOperation = new this . _gaxModule . Operation (
14011417 operation ,
14021418 this . descriptors . longrunning . undeleteService ,
14031419 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1525,7 +1541,7 @@ export class ServiceManagerClient {
15251541 options . otherArgs = options . otherArgs || { } ;
15261542 options . otherArgs . headers = options . otherArgs . headers || { } ;
15271543 options . otherArgs . headers [ 'x-goog-request-params' ] =
1528- gax . routingHeader . fromParams ( {
1544+ this . _gaxModule . routingHeader . fromParams ( {
15291545 service_name : request . serviceName || '' ,
15301546 } ) ;
15311547 this . initialize ( ) ;
@@ -1551,11 +1567,12 @@ export class ServiceManagerClient {
15511567 protos . google . api . servicemanagement . v1 . OperationMetadata
15521568 >
15531569 > {
1554- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1555- { name}
1556- ) ;
1570+ const request =
1571+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1572+ { name}
1573+ ) ;
15571574 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1558- const decodeOperation = new gax . Operation (
1575+ const decodeOperation = new this . _gaxModule . Operation (
15591576 operation ,
15601577 this . descriptors . longrunning . submitConfigSource ,
15611578 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1679,7 +1696,7 @@ export class ServiceManagerClient {
16791696 options . otherArgs = options . otherArgs || { } ;
16801697 options . otherArgs . headers = options . otherArgs . headers || { } ;
16811698 options . otherArgs . headers [ 'x-goog-request-params' ] =
1682- gax . routingHeader . fromParams ( {
1699+ this . _gaxModule . routingHeader . fromParams ( {
16831700 service_name : request . serviceName || '' ,
16841701 } ) ;
16851702 this . initialize ( ) ;
@@ -1705,11 +1722,12 @@ export class ServiceManagerClient {
17051722 protos . google . api . servicemanagement . v1 . OperationMetadata
17061723 >
17071724 > {
1708- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1709- { name}
1710- ) ;
1725+ const request =
1726+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1727+ { name}
1728+ ) ;
17111729 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1712- const decodeOperation = new gax . Operation (
1730+ const decodeOperation = new this . _gaxModule . Operation (
17131731 operation ,
17141732 this . descriptors . longrunning . createServiceRollout ,
17151733 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -2020,7 +2038,7 @@ export class ServiceManagerClient {
20202038 options . otherArgs = options . otherArgs || { } ;
20212039 options . otherArgs . headers = options . otherArgs . headers || { } ;
20222040 options . otherArgs . headers [ 'x-goog-request-params' ] =
2023- gax . routingHeader . fromParams ( {
2041+ this . _gaxModule . routingHeader . fromParams ( {
20242042 service_name : request . serviceName || '' ,
20252043 } ) ;
20262044 this . initialize ( ) ;
@@ -2061,7 +2079,7 @@ export class ServiceManagerClient {
20612079 options . otherArgs = options . otherArgs || { } ;
20622080 options . otherArgs . headers = options . otherArgs . headers || { } ;
20632081 options . otherArgs . headers [ 'x-goog-request-params' ] =
2064- gax . routingHeader . fromParams ( {
2082+ this . _gaxModule . routingHeader . fromParams ( {
20652083 service_name : request . serviceName || '' ,
20662084 } ) ;
20672085 const defaultCallSettings = this . _defaults [ 'listServiceConfigs' ] ;
@@ -2111,7 +2129,7 @@ export class ServiceManagerClient {
21112129 options . otherArgs = options . otherArgs || { } ;
21122130 options . otherArgs . headers = options . otherArgs . headers || { } ;
21132131 options . otherArgs . headers [ 'x-goog-request-params' ] =
2114- gax . routingHeader . fromParams ( {
2132+ this . _gaxModule . routingHeader . fromParams ( {
21152133 service_name : request . serviceName || '' ,
21162134 } ) ;
21172135 const defaultCallSettings = this . _defaults [ 'listServiceConfigs' ] ;
@@ -2228,7 +2246,7 @@ export class ServiceManagerClient {
22282246 options . otherArgs = options . otherArgs || { } ;
22292247 options . otherArgs . headers = options . otherArgs . headers || { } ;
22302248 options . otherArgs . headers [ 'x-goog-request-params' ] =
2231- gax . routingHeader . fromParams ( {
2249+ this . _gaxModule . routingHeader . fromParams ( {
22322250 service_name : request . serviceName || '' ,
22332251 } ) ;
22342252 this . initialize ( ) ;
@@ -2278,7 +2296,7 @@ export class ServiceManagerClient {
22782296 options . otherArgs = options . otherArgs || { } ;
22792297 options . otherArgs . headers = options . otherArgs . headers || { } ;
22802298 options . otherArgs . headers [ 'x-goog-request-params' ] =
2281- gax . routingHeader . fromParams ( {
2299+ this . _gaxModule . routingHeader . fromParams ( {
22822300 service_name : request . serviceName || '' ,
22832301 } ) ;
22842302 const defaultCallSettings = this . _defaults [ 'listServiceRollouts' ] ;
@@ -2337,7 +2355,7 @@ export class ServiceManagerClient {
23372355 options . otherArgs = options . otherArgs || { } ;
23382356 options . otherArgs . headers = options . otherArgs . headers || { } ;
23392357 options . otherArgs . headers [ 'x-goog-request-params' ] =
2340- gax . routingHeader . fromParams ( {
2358+ this . _gaxModule . routingHeader . fromParams ( {
23412359 service_name : request . serviceName || '' ,
23422360 } ) ;
23432361 const defaultCallSettings = this . _defaults [ 'listServiceRollouts' ] ;
0 commit comments