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 IamClient ,
2929 IamProtos ,
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 './ekm_service_client_config.json' ;
41-
4240const version = require ( '../../../package.json' ) . version ;
4341
4442/**
@@ -103,8 +101,18 @@ export class EkmServiceClient {
103101 * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
104102 * For more information, please check the
105103 * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
104+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
105+ * need to avoid loading the default gRPC version and want to use the fallback
106+ * HTTP implementation. Load only fallback version and pass it to the constructor:
107+ * ```
108+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
109+ * const client = new EkmServiceClient({fallback: 'rest'}, gax);
110+ * ```
106111 */
107- constructor ( opts ?: ClientOptions ) {
112+ constructor (
113+ opts ?: ClientOptions ,
114+ gaxInstance ?: typeof gax | typeof gax . fallback
115+ ) {
108116 // Ensure that options include all the required fields.
109117 const staticMembers = this . constructor as typeof EkmServiceClient ;
110118 const servicePath =
@@ -124,8 +132,13 @@ export class EkmServiceClient {
124132 opts [ 'scopes' ] = staticMembers . scopes ;
125133 }
126134
135+ // Load google-gax module synchronously if needed
136+ if ( ! gaxInstance ) {
137+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
138+ }
139+
127140 // Choose either gRPC or proto-over-HTTP implementation of google-gax.
128- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
141+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
129142
130143 // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
131144 this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -146,7 +159,7 @@ export class EkmServiceClient {
146159 if ( servicePath === staticMembers . servicePath ) {
147160 this . auth . defaultScopes = staticMembers . scopes ;
148161 }
149- this . iamClient = new IamClient ( this . _gaxGrpc , opts ) ;
162+ this . iamClient = new this . _gaxModule . IamClient ( this . _gaxGrpc , opts ) ;
150163
151164 // Determine the client header string.
152165 const clientHeader = [ `gax/${ this . _gaxModule . version } ` , `gapic/${ version } ` ] ;
@@ -218,7 +231,7 @@ export class EkmServiceClient {
218231 this . innerApiCalls = { } ;
219232
220233 // Add a warn function to the client constructor so it can be easily tested.
221- this . warn = gax . warn ;
234+ this . warn = this . _gaxModule . warn ;
222235 }
223236
224237 /**
@@ -425,7 +438,7 @@ export class EkmServiceClient {
425438 options . otherArgs = options . otherArgs || { } ;
426439 options . otherArgs . headers = options . otherArgs . headers || { } ;
427440 options . otherArgs . headers [ 'x-goog-request-params' ] =
428- gax . routingHeader . fromParams ( {
441+ this . _gaxModule . routingHeader . fromParams ( {
429442 name : request . name || '' ,
430443 } ) ;
431444 this . initialize ( ) ;
@@ -519,7 +532,7 @@ export class EkmServiceClient {
519532 options . otherArgs = options . otherArgs || { } ;
520533 options . otherArgs . headers = options . otherArgs . headers || { } ;
521534 options . otherArgs . headers [ 'x-goog-request-params' ] =
522- gax . routingHeader . fromParams ( {
535+ this . _gaxModule . routingHeader . fromParams ( {
523536 parent : request . parent || '' ,
524537 } ) ;
525538 this . initialize ( ) ;
@@ -607,7 +620,7 @@ export class EkmServiceClient {
607620 options . otherArgs = options . otherArgs || { } ;
608621 options . otherArgs . headers = options . otherArgs . headers || { } ;
609622 options . otherArgs . headers [ 'x-goog-request-params' ] =
610- gax . routingHeader . fromParams ( {
623+ this . _gaxModule . routingHeader . fromParams ( {
611624 'ekm_connection.name' : request . ekmConnection ! . name || '' ,
612625 } ) ;
613626 this . initialize ( ) ;
@@ -719,7 +732,7 @@ export class EkmServiceClient {
719732 options . otherArgs = options . otherArgs || { } ;
720733 options . otherArgs . headers = options . otherArgs . headers || { } ;
721734 options . otherArgs . headers [ 'x-goog-request-params' ] =
722- gax . routingHeader . fromParams ( {
735+ this . _gaxModule . routingHeader . fromParams ( {
723736 parent : request . parent || '' ,
724737 } ) ;
725738 this . initialize ( ) ;
@@ -776,7 +789,7 @@ export class EkmServiceClient {
776789 options . otherArgs = options . otherArgs || { } ;
777790 options . otherArgs . headers = options . otherArgs . headers || { } ;
778791 options . otherArgs . headers [ 'x-goog-request-params' ] =
779- gax . routingHeader . fromParams ( {
792+ this . _gaxModule . routingHeader . fromParams ( {
780793 parent : request . parent || '' ,
781794 } ) ;
782795 const defaultCallSettings = this . _defaults [ 'listEkmConnections' ] ;
@@ -842,7 +855,7 @@ export class EkmServiceClient {
842855 options . otherArgs = options . otherArgs || { } ;
843856 options . otherArgs . headers = options . otherArgs . headers || { } ;
844857 options . otherArgs . headers [ 'x-goog-request-params' ] =
845- gax . routingHeader . fromParams ( {
858+ this . _gaxModule . routingHeader . fromParams ( {
846859 parent : request . parent || '' ,
847860 } ) ;
848861 const defaultCallSettings = this . _defaults [ 'listEkmConnections' ] ;
0 commit comments