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 ,
2525 ClientOptions ,
2626 PaginationCallback ,
2727 GaxCall ,
2828} from 'google-gax' ;
29-
3029import { Transform } from 'stream' ;
3130import * as protos from '../../protos/protos' ;
3231import jsonProtos = require( '../../protos/protos.json' ) ;
@@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json');
3635 * This file defines retry strategy and timeouts for all API methods in this library.
3736 */
3837import * as gapicConfig from './jobs_v1_beta3_client_config.json' ;
39-
4038const version = require ( '../../../package.json' ) . version ;
4139
4240/**
@@ -96,8 +94,18 @@ export class JobsV1Beta3Client {
9694 * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
9795 * For more information, please check the
9896 * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
97+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
98+ * need to avoid loading the default gRPC version and want to use the fallback
99+ * HTTP implementation. Load only fallback version and pass it to the constructor:
100+ * ```
101+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
102+ * const client = new JobsV1Beta3Client({fallback: 'rest'}, gax);
103+ * ```
99104 */
100- constructor ( opts ?: ClientOptions ) {
105+ constructor (
106+ opts ?: ClientOptions ,
107+ gaxInstance ?: typeof gax | typeof gax . fallback
108+ ) {
101109 // Ensure that options include all the required fields.
102110 const staticMembers = this . constructor as typeof JobsV1Beta3Client ;
103111 const servicePath =
@@ -117,8 +125,13 @@ export class JobsV1Beta3Client {
117125 opts [ 'scopes' ] = staticMembers . scopes ;
118126 }
119127
128+ // Load google-gax module synchronously if needed
129+ if ( ! gaxInstance ) {
130+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
131+ }
132+
120133 // Choose either gRPC or proto-over-HTTP implementation of google-gax.
121- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
134+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
122135
123136 // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
124137 this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -188,7 +201,7 @@ export class JobsV1Beta3Client {
188201 this . innerApiCalls = { } ;
189202
190203 // Add a warn function to the client constructor so it can be easily tested.
191- this . warn = gax . warn ;
204+ this . warn = this . _gaxModule . warn ;
192205 }
193206
194207 /**
@@ -412,7 +425,7 @@ export class JobsV1Beta3Client {
412425 options . otherArgs = options . otherArgs || { } ;
413426 options . otherArgs . headers = options . otherArgs . headers || { } ;
414427 options . otherArgs . headers [ 'x-goog-request-params' ] =
415- gax . routingHeader . fromParams ( {
428+ this . _gaxModule . routingHeader . fromParams ( {
416429 project_id : request . projectId || '' ,
417430 location : request . location || '' ,
418431 } ) ;
@@ -510,7 +523,7 @@ export class JobsV1Beta3Client {
510523 options . otherArgs = options . otherArgs || { } ;
511524 options . otherArgs . headers = options . otherArgs . headers || { } ;
512525 options . otherArgs . headers [ 'x-goog-request-params' ] =
513- gax . routingHeader . fromParams ( {
526+ this . _gaxModule . routingHeader . fromParams ( {
514527 project_id : request . projectId || '' ,
515528 location : request . location || '' ,
516529 job_id : request . jobId || '' ,
@@ -610,7 +623,7 @@ export class JobsV1Beta3Client {
610623 options . otherArgs = options . otherArgs || { } ;
611624 options . otherArgs . headers = options . otherArgs . headers || { } ;
612625 options . otherArgs . headers [ 'x-goog-request-params' ] =
613- gax . routingHeader . fromParams ( {
626+ this . _gaxModule . routingHeader . fromParams ( {
614627 project_id : request . projectId || '' ,
615628 location : request . location || '' ,
616629 job_id : request . jobId || '' ,
@@ -786,7 +799,7 @@ export class JobsV1Beta3Client {
786799 options . otherArgs = options . otherArgs || { } ;
787800 options . otherArgs . headers = options . otherArgs . headers || { } ;
788801 options . otherArgs . headers [ 'x-goog-request-params' ] =
789- gax . routingHeader . fromParams ( {
802+ this . _gaxModule . routingHeader . fromParams ( {
790803 project_id : request . projectId || '' ,
791804 location : request . location || '' ,
792805 job_id : request . jobId || '' ,
@@ -898,7 +911,7 @@ export class JobsV1Beta3Client {
898911 options . otherArgs = options . otherArgs || { } ;
899912 options . otherArgs . headers = options . otherArgs . headers || { } ;
900913 options . otherArgs . headers [ 'x-goog-request-params' ] =
901- gax . routingHeader . fromParams ( {
914+ this . _gaxModule . routingHeader . fromParams ( {
902915 project_id : request . projectId || '' ,
903916 location : request . location || '' ,
904917 } ) ;
@@ -949,7 +962,7 @@ export class JobsV1Beta3Client {
949962 options . otherArgs = options . otherArgs || { } ;
950963 options . otherArgs . headers = options . otherArgs . headers || { } ;
951964 options . otherArgs . headers [ 'x-goog-request-params' ] =
952- gax . routingHeader . fromParams ( {
965+ this . _gaxModule . routingHeader . fromParams ( {
953966 project_id : request . projectId || '' ,
954967 location : request . location || '' ,
955968 } ) ;
@@ -1009,7 +1022,7 @@ export class JobsV1Beta3Client {
10091022 options . otherArgs = options . otherArgs || { } ;
10101023 options . otherArgs . headers = options . otherArgs . headers || { } ;
10111024 options . otherArgs . headers [ 'x-goog-request-params' ] =
1012- gax . routingHeader . fromParams ( {
1025+ this . _gaxModule . routingHeader . fromParams ( {
10131026 project_id : request . projectId || '' ,
10141027 location : request . location || '' ,
10151028 } ) ;
@@ -1118,7 +1131,7 @@ export class JobsV1Beta3Client {
11181131 options . otherArgs = options . otherArgs || { } ;
11191132 options . otherArgs . headers = options . otherArgs . headers || { } ;
11201133 options . otherArgs . headers [ 'x-goog-request-params' ] =
1121- gax . routingHeader . fromParams ( {
1134+ this . _gaxModule . routingHeader . fromParams ( {
11221135 project_id : request . projectId || '' ,
11231136 } ) ;
11241137 this . initialize ( ) ;
@@ -1168,7 +1181,7 @@ export class JobsV1Beta3Client {
11681181 options . otherArgs = options . otherArgs || { } ;
11691182 options . otherArgs . headers = options . otherArgs . headers || { } ;
11701183 options . otherArgs . headers [ 'x-goog-request-params' ] =
1171- gax . routingHeader . fromParams ( {
1184+ this . _gaxModule . routingHeader . fromParams ( {
11721185 project_id : request . projectId || '' ,
11731186 } ) ;
11741187 const defaultCallSettings = this . _defaults [ 'aggregatedListJobs' ] ;
@@ -1227,7 +1240,7 @@ export class JobsV1Beta3Client {
12271240 options . otherArgs = options . otherArgs || { } ;
12281241 options . otherArgs . headers = options . otherArgs . headers || { } ;
12291242 options . otherArgs . headers [ 'x-goog-request-params' ] =
1230- gax . routingHeader . fromParams ( {
1243+ this . _gaxModule . routingHeader . fromParams ( {
12311244 project_id : request . projectId || '' ,
12321245 } ) ;
12331246 const defaultCallSettings = this . _defaults [ 'aggregatedListJobs' ] ;
0 commit comments