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 './binauthz_management_service_v1_client_config.json' ;
39-
4038const version = require ( '../../../package.json' ) . version ;
4139
4240/**
@@ -102,8 +100,18 @@ export class BinauthzManagementServiceV1Client {
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}.
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 BinauthzManagementServiceV1Client({fallback: 'rest'}, gax);
109+ * ```
105110 */
106- constructor ( opts ?: ClientOptions ) {
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
109117 . constructor as typeof BinauthzManagementServiceV1Client ;
@@ -124,8 +132,13 @@ export class BinauthzManagementServiceV1Client {
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 ) ;
@@ -208,7 +221,7 @@ export class BinauthzManagementServiceV1Client {
208221 this . innerApiCalls = { } ;
209222
210223 // Add a warn function to the client constructor so it can be easily tested.
211- this . warn = gax . warn ;
224+ this . warn = this . _gaxModule . warn ;
212225 }
213226
214227 /**
@@ -427,7 +440,7 @@ export class BinauthzManagementServiceV1Client {
427440 options . otherArgs = options . otherArgs || { } ;
428441 options . otherArgs . headers = options . otherArgs . headers || { } ;
429442 options . otherArgs . headers [ 'x-goog-request-params' ] =
430- gax . routingHeader . fromParams ( {
443+ this . _gaxModule . routingHeader . fromParams ( {
431444 name : request . name || '' ,
432445 } ) ;
433446 this . initialize ( ) ;
@@ -530,7 +543,7 @@ export class BinauthzManagementServiceV1Client {
530543 options . otherArgs = options . otherArgs || { } ;
531544 options . otherArgs . headers = options . otherArgs . headers || { } ;
532545 options . otherArgs . headers [ 'x-goog-request-params' ] =
533- gax . routingHeader . fromParams ( {
546+ this . _gaxModule . routingHeader . fromParams ( {
534547 'policy.name' : request . policy ! . name || '' ,
535548 } ) ;
536549 this . initialize ( ) ;
@@ -636,7 +649,7 @@ export class BinauthzManagementServiceV1Client {
636649 options . otherArgs = options . otherArgs || { } ;
637650 options . otherArgs . headers = options . otherArgs . headers || { } ;
638651 options . otherArgs . headers [ 'x-goog-request-params' ] =
639- gax . routingHeader . fromParams ( {
652+ this . _gaxModule . routingHeader . fromParams ( {
640653 parent : request . parent || '' ,
641654 } ) ;
642655 this . initialize ( ) ;
@@ -735,7 +748,7 @@ export class BinauthzManagementServiceV1Client {
735748 options . otherArgs = options . otherArgs || { } ;
736749 options . otherArgs . headers = options . otherArgs . headers || { } ;
737750 options . otherArgs . headers [ 'x-goog-request-params' ] =
738- gax . routingHeader . fromParams ( {
751+ this . _gaxModule . routingHeader . fromParams ( {
739752 name : request . name || '' ,
740753 } ) ;
741754 this . initialize ( ) ;
@@ -835,7 +848,7 @@ export class BinauthzManagementServiceV1Client {
835848 options . otherArgs = options . otherArgs || { } ;
836849 options . otherArgs . headers = options . otherArgs . headers || { } ;
837850 options . otherArgs . headers [ 'x-goog-request-params' ] =
838- gax . routingHeader . fromParams ( {
851+ this . _gaxModule . routingHeader . fromParams ( {
839852 'attestor.name' : request . attestor ! . name || '' ,
840853 } ) ;
841854 this . initialize ( ) ;
@@ -934,7 +947,7 @@ export class BinauthzManagementServiceV1Client {
934947 options . otherArgs = options . otherArgs || { } ;
935948 options . otherArgs . headers = options . otherArgs . headers || { } ;
936949 options . otherArgs . headers [ 'x-goog-request-params' ] =
937- gax . routingHeader . fromParams ( {
950+ this . _gaxModule . routingHeader . fromParams ( {
938951 name : request . name || '' ,
939952 } ) ;
940953 this . initialize ( ) ;
@@ -1038,7 +1051,7 @@ export class BinauthzManagementServiceV1Client {
10381051 options . otherArgs = options . otherArgs || { } ;
10391052 options . otherArgs . headers = options . otherArgs . headers || { } ;
10401053 options . otherArgs . headers [ 'x-goog-request-params' ] =
1041- gax . routingHeader . fromParams ( {
1054+ this . _gaxModule . routingHeader . fromParams ( {
10421055 parent : request . parent || '' ,
10431056 } ) ;
10441057 this . initialize ( ) ;
@@ -1080,7 +1093,7 @@ export class BinauthzManagementServiceV1Client {
10801093 options . otherArgs = options . otherArgs || { } ;
10811094 options . otherArgs . headers = options . otherArgs . headers || { } ;
10821095 options . otherArgs . headers [ 'x-goog-request-params' ] =
1083- gax . routingHeader . fromParams ( {
1096+ this . _gaxModule . routingHeader . fromParams ( {
10841097 parent : request . parent || '' ,
10851098 } ) ;
10861099 const defaultCallSettings = this . _defaults [ 'listAttestors' ] ;
@@ -1131,7 +1144,7 @@ export class BinauthzManagementServiceV1Client {
11311144 options . otherArgs = options . otherArgs || { } ;
11321145 options . otherArgs . headers = options . otherArgs . headers || { } ;
11331146 options . otherArgs . headers [ 'x-goog-request-params' ] =
1134- gax . routingHeader . fromParams ( {
1147+ this . _gaxModule . routingHeader . fromParams ( {
11351148 parent : request . parent || '' ,
11361149 } ) ;
11371150 const defaultCallSettings = this . _defaults [ 'listAttestors' ] ;
0 commit comments