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 './api_keys_client_config.json' ;
41- import { operationsProtos } from 'google-gax' ;
4240const version = require ( '../../../package.json' ) . version ;
4341
4442/**
@@ -99,8 +97,18 @@ export class ApiKeysClient {
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 ApiKeysClient({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 ApiKeysClient ;
106114 const servicePath =
@@ -120,8 +128,13 @@ export class ApiKeysClient {
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 ApiKeysClient {
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 /**
@@ -483,7 +496,7 @@ export class ApiKeysClient {
483496 options . otherArgs = options . otherArgs || { } ;
484497 options . otherArgs . headers = options . otherArgs . headers || { } ;
485498 options . otherArgs . headers [ 'x-goog-request-params' ] =
486- gax . routingHeader . fromParams ( {
499+ this . _gaxModule . routingHeader . fromParams ( {
487500 name : request . name || '' ,
488501 } ) ;
489502 this . initialize ( ) ;
@@ -569,7 +582,7 @@ export class ApiKeysClient {
569582 options . otherArgs = options . otherArgs || { } ;
570583 options . otherArgs . headers = options . otherArgs . headers || { } ;
571584 options . otherArgs . headers [ 'x-goog-request-params' ] =
572- gax . routingHeader . fromParams ( {
585+ this . _gaxModule . routingHeader . fromParams ( {
573586 name : request . name || '' ,
574587 } ) ;
575588 this . initialize ( ) ;
@@ -773,7 +786,7 @@ export class ApiKeysClient {
773786 options . otherArgs = options . otherArgs || { } ;
774787 options . otherArgs . headers = options . otherArgs . headers || { } ;
775788 options . otherArgs . headers [ 'x-goog-request-params' ] =
776- gax . routingHeader . fromParams ( {
789+ this . _gaxModule . routingHeader . fromParams ( {
777790 parent : request . parent || '' ,
778791 } ) ;
779792 this . initialize ( ) ;
@@ -796,11 +809,12 @@ export class ApiKeysClient {
796809 ) : Promise <
797810 LROperation < protos . google . api . apikeys . v2 . Key , protos . google . protobuf . Empty >
798811 > {
799- const request = new operationsProtos . google . longrunning . GetOperationRequest (
800- { name}
801- ) ;
812+ const request =
813+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
814+ { name}
815+ ) ;
802816 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
803- const decodeOperation = new gax . Operation (
817+ const decodeOperation = new this . _gaxModule . Operation (
804818 operation ,
805819 this . descriptors . longrunning . createKey ,
806820 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -921,7 +935,7 @@ export class ApiKeysClient {
921935 options . otherArgs = options . otherArgs || { } ;
922936 options . otherArgs . headers = options . otherArgs . headers || { } ;
923937 options . otherArgs . headers [ 'x-goog-request-params' ] =
924- gax . routingHeader . fromParams ( {
938+ this . _gaxModule . routingHeader . fromParams ( {
925939 'key.name' : request . key ! . name || '' ,
926940 } ) ;
927941 this . initialize ( ) ;
@@ -944,11 +958,12 @@ export class ApiKeysClient {
944958 ) : Promise <
945959 LROperation < protos . google . api . apikeys . v2 . Key , protos . google . protobuf . Empty >
946960 > {
947- const request = new operationsProtos . google . longrunning . GetOperationRequest (
948- { name}
949- ) ;
961+ const request =
962+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
963+ { name}
964+ ) ;
950965 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
951- const decodeOperation = new gax . Operation (
966+ const decodeOperation = new this . _gaxModule . Operation (
952967 operation ,
953968 this . descriptors . longrunning . updateKey ,
954969 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1062,7 +1077,7 @@ export class ApiKeysClient {
10621077 options . otherArgs = options . otherArgs || { } ;
10631078 options . otherArgs . headers = options . otherArgs . headers || { } ;
10641079 options . otherArgs . headers [ 'x-goog-request-params' ] =
1065- gax . routingHeader . fromParams ( {
1080+ this . _gaxModule . routingHeader . fromParams ( {
10661081 name : request . name || '' ,
10671082 } ) ;
10681083 this . initialize ( ) ;
@@ -1085,11 +1100,12 @@ export class ApiKeysClient {
10851100 ) : Promise <
10861101 LROperation < protos . google . api . apikeys . v2 . Key , protos . google . protobuf . Empty >
10871102 > {
1088- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1089- { name}
1090- ) ;
1103+ const request =
1104+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1105+ { name}
1106+ ) ;
10911107 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1092- const decodeOperation = new gax . Operation (
1108+ const decodeOperation = new this . _gaxModule . Operation (
10931109 operation ,
10941110 this . descriptors . longrunning . deleteKey ,
10951111 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1199,7 +1215,7 @@ export class ApiKeysClient {
11991215 options . otherArgs = options . otherArgs || { } ;
12001216 options . otherArgs . headers = options . otherArgs . headers || { } ;
12011217 options . otherArgs . headers [ 'x-goog-request-params' ] =
1202- gax . routingHeader . fromParams ( {
1218+ this . _gaxModule . routingHeader . fromParams ( {
12031219 name : request . name || '' ,
12041220 } ) ;
12051221 this . initialize ( ) ;
@@ -1222,11 +1238,12 @@ export class ApiKeysClient {
12221238 ) : Promise <
12231239 LROperation < protos . google . api . apikeys . v2 . Key , protos . google . protobuf . Empty >
12241240 > {
1225- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1226- { name}
1227- ) ;
1241+ const request =
1242+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1243+ { name}
1244+ ) ;
12281245 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1229- const decodeOperation = new gax . Operation (
1246+ const decodeOperation = new this . _gaxModule . Operation (
12301247 operation ,
12311248 this . descriptors . longrunning . undeleteKey ,
12321249 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1327,7 +1344,7 @@ export class ApiKeysClient {
13271344 options . otherArgs = options . otherArgs || { } ;
13281345 options . otherArgs . headers = options . otherArgs . headers || { } ;
13291346 options . otherArgs . headers [ 'x-goog-request-params' ] =
1330- gax . routingHeader . fromParams ( {
1347+ this . _gaxModule . routingHeader . fromParams ( {
13311348 parent : request . parent || '' ,
13321349 } ) ;
13331350 this . initialize ( ) ;
@@ -1368,7 +1385,7 @@ export class ApiKeysClient {
13681385 options . otherArgs = options . otherArgs || { } ;
13691386 options . otherArgs . headers = options . otherArgs . headers || { } ;
13701387 options . otherArgs . headers [ 'x-goog-request-params' ] =
1371- gax . routingHeader . fromParams ( {
1388+ this . _gaxModule . routingHeader . fromParams ( {
13721389 parent : request . parent || '' ,
13731390 } ) ;
13741391 const defaultCallSettings = this . _defaults [ 'listKeys' ] ;
@@ -1418,7 +1435,7 @@ export class ApiKeysClient {
14181435 options . otherArgs = options . otherArgs || { } ;
14191436 options . otherArgs . headers = options . otherArgs . headers || { } ;
14201437 options . otherArgs . headers [ 'x-goog-request-params' ] =
1421- gax . routingHeader . fromParams ( {
1438+ this . _gaxModule . routingHeader . fromParams ( {
14221439 parent : request . parent || '' ,
14231440 } ) ;
14241441 const defaultCallSettings = this . _defaults [ 'listKeys' ] ;
0 commit comments