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 ,
@@ -30,7 +30,6 @@ import {
3030 LocationsClient ,
3131 LocationProtos ,
3232} from 'google-gax' ;
33-
3433import { Transform } from 'stream' ;
3534import * as protos from '../../protos/protos' ;
3635import jsonProtos = require( '../../protos/protos.json' ) ;
@@ -40,7 +39,6 @@ import jsonProtos = require('../../protos/protos.json');
4039 * This file defines retry strategy and timeouts for all API methods in this library.
4140 */
4241import * as gapicConfig from './agents_client_config.json' ;
43- import { operationsProtos } from 'google-gax' ;
4442const version = require ( '../../../package.json' ) . version ;
4543
4644/**
@@ -102,8 +100,18 @@ export class AgentsClient {
102100 * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
103101 * For more information, please check the
104102 * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
105- */
106- constructor ( opts ?: ClientOptions ) {
103+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
104+ * need to avoid loading the default gRPC version and want to use the fallback
105+ * HTTP implementation. Load only fallback version and pass it to the constructor:
106+ * ```
107+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
108+ * const client = new AgentsClient({fallback: 'rest'}, gax);
109+ * ```
110+ */
111+ constructor (
112+ opts ?: ClientOptions ,
113+ gaxInstance ?: typeof gax | typeof gax . fallback
114+ ) {
107115 // Ensure that options include all the required fields.
108116 const staticMembers = this . constructor as typeof AgentsClient ;
109117 const servicePath =
@@ -123,8 +131,13 @@ export class AgentsClient {
123131 opts [ 'scopes' ] = staticMembers . scopes ;
124132 }
125133
134+ // Load google-gax module synchronously if needed
135+ if ( ! gaxInstance ) {
136+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
137+ }
138+
126139 // Choose either gRPC or proto-over-HTTP implementation of google-gax.
127- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
140+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
128141
129142 // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
130143 this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -145,7 +158,10 @@ export class AgentsClient {
145158 if ( servicePath === staticMembers . servicePath ) {
146159 this . auth . defaultScopes = staticMembers . scopes ;
147160 }
148- this . locationsClient = new LocationsClient ( this . _gaxGrpc , opts ) ;
161+ this . locationsClient = new this . _gaxModule . LocationsClient (
162+ this . _gaxGrpc ,
163+ opts
164+ ) ;
149165
150166 // Determine the client header string.
151167 const clientHeader = [ `gax/${ this . _gaxModule . version } ` , `gapic/${ version } ` ] ;
@@ -335,7 +351,7 @@ export class AgentsClient {
335351 this . innerApiCalls = { } ;
336352
337353 // Add a warn function to the client constructor so it can be easily tested.
338- this . warn = gax . warn ;
354+ this . warn = this . _gaxModule . warn ;
339355 }
340356
341357 /**
@@ -549,7 +565,7 @@ export class AgentsClient {
549565 options . otherArgs = options . otherArgs || { } ;
550566 options . otherArgs . headers = options . otherArgs . headers || { } ;
551567 options . otherArgs . headers [ 'x-goog-request-params' ] =
552- gax . routingHeader . fromParams ( {
568+ this . _gaxModule . routingHeader . fromParams ( {
553569 name : request . name || '' ,
554570 } ) ;
555571 this . initialize ( ) ;
@@ -647,7 +663,7 @@ export class AgentsClient {
647663 options . otherArgs = options . otherArgs || { } ;
648664 options . otherArgs . headers = options . otherArgs . headers || { } ;
649665 options . otherArgs . headers [ 'x-goog-request-params' ] =
650- gax . routingHeader . fromParams ( {
666+ this . _gaxModule . routingHeader . fromParams ( {
651667 parent : request . parent || '' ,
652668 } ) ;
653669 this . initialize ( ) ;
@@ -745,7 +761,7 @@ export class AgentsClient {
745761 options . otherArgs = options . otherArgs || { } ;
746762 options . otherArgs . headers = options . otherArgs . headers || { } ;
747763 options . otherArgs . headers [ 'x-goog-request-params' ] =
748- gax . routingHeader . fromParams ( {
764+ this . _gaxModule . routingHeader . fromParams ( {
749765 'agent.name' : request . agent ! . name || '' ,
750766 } ) ;
751767 this . initialize ( ) ;
@@ -837,7 +853,7 @@ export class AgentsClient {
837853 options . otherArgs = options . otherArgs || { } ;
838854 options . otherArgs . headers = options . otherArgs . headers || { } ;
839855 options . otherArgs . headers [ 'x-goog-request-params' ] =
840- gax . routingHeader . fromParams ( {
856+ this . _gaxModule . routingHeader . fromParams ( {
841857 name : request . name || '' ,
842858 } ) ;
843859 this . initialize ( ) ;
@@ -933,7 +949,7 @@ export class AgentsClient {
933949 options . otherArgs = options . otherArgs || { } ;
934950 options . otherArgs . headers = options . otherArgs . headers || { } ;
935951 options . otherArgs . headers [ 'x-goog-request-params' ] =
936- gax . routingHeader . fromParams ( {
952+ this . _gaxModule . routingHeader . fromParams ( {
937953 name : request . name || '' ,
938954 } ) ;
939955 this . initialize ( ) ;
@@ -1035,7 +1051,7 @@ export class AgentsClient {
10351051 options . otherArgs = options . otherArgs || { } ;
10361052 options . otherArgs . headers = options . otherArgs . headers || { } ;
10371053 options . otherArgs . headers [ 'x-goog-request-params' ] =
1038- gax . routingHeader . fromParams ( {
1054+ this . _gaxModule . routingHeader . fromParams ( {
10391055 name : request . name || '' ,
10401056 } ) ;
10411057 this . initialize ( ) ;
@@ -1169,7 +1185,7 @@ export class AgentsClient {
11691185 options . otherArgs = options . otherArgs || { } ;
11701186 options . otherArgs . headers = options . otherArgs . headers || { } ;
11711187 options . otherArgs . headers [ 'x-goog-request-params' ] =
1172- gax . routingHeader . fromParams ( {
1188+ this . _gaxModule . routingHeader . fromParams ( {
11731189 name : request . name || '' ,
11741190 } ) ;
11751191 this . initialize ( ) ;
@@ -1195,11 +1211,12 @@ export class AgentsClient {
11951211 protos . google . protobuf . Struct
11961212 >
11971213 > {
1198- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1199- { name}
1200- ) ;
1214+ const request =
1215+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1216+ { name}
1217+ ) ;
12011218 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1202- const decodeOperation = new gax . Operation (
1219+ const decodeOperation = new this . _gaxModule . Operation (
12031220 operation ,
12041221 this . descriptors . longrunning . exportAgent ,
12051222 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1337,7 +1354,7 @@ export class AgentsClient {
13371354 options . otherArgs = options . otherArgs || { } ;
13381355 options . otherArgs . headers = options . otherArgs . headers || { } ;
13391356 options . otherArgs . headers [ 'x-goog-request-params' ] =
1340- gax . routingHeader . fromParams ( {
1357+ this . _gaxModule . routingHeader . fromParams ( {
13411358 name : request . name || '' ,
13421359 } ) ;
13431360 this . initialize ( ) ;
@@ -1360,11 +1377,12 @@ export class AgentsClient {
13601377 ) : Promise <
13611378 LROperation < protos . google . protobuf . Empty , protos . google . protobuf . Struct >
13621379 > {
1363- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1364- { name}
1365- ) ;
1380+ const request =
1381+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1382+ { name}
1383+ ) ;
13661384 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1367- const decodeOperation = new gax . Operation (
1385+ const decodeOperation = new this . _gaxModule . Operation (
13681386 operation ,
13691387 this . descriptors . longrunning . restoreAgent ,
13701388 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1468,7 +1486,7 @@ export class AgentsClient {
14681486 options . otherArgs = options . otherArgs || { } ;
14691487 options . otherArgs . headers = options . otherArgs . headers || { } ;
14701488 options . otherArgs . headers [ 'x-goog-request-params' ] =
1471- gax . routingHeader . fromParams ( {
1489+ this . _gaxModule . routingHeader . fromParams ( {
14721490 parent : request . parent || '' ,
14731491 } ) ;
14741492 this . initialize ( ) ;
@@ -1508,7 +1526,7 @@ export class AgentsClient {
15081526 options . otherArgs = options . otherArgs || { } ;
15091527 options . otherArgs . headers = options . otherArgs . headers || { } ;
15101528 options . otherArgs . headers [ 'x-goog-request-params' ] =
1511- gax . routingHeader . fromParams ( {
1529+ this . _gaxModule . routingHeader . fromParams ( {
15121530 parent : request . parent || '' ,
15131531 } ) ;
15141532 const defaultCallSettings = this . _defaults [ 'listAgents' ] ;
@@ -1557,7 +1575,7 @@ export class AgentsClient {
15571575 options . otherArgs = options . otherArgs || { } ;
15581576 options . otherArgs . headers = options . otherArgs . headers || { } ;
15591577 options . otherArgs . headers [ 'x-goog-request-params' ] =
1560- gax . routingHeader . fromParams ( {
1578+ this . _gaxModule . routingHeader . fromParams ( {
15611579 parent : request . parent || '' ,
15621580 } ) ;
15631581 const defaultCallSettings = this . _defaults [ 'listAgents' ] ;
0 commit comments