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 './cloud_redis_client_config.json' ;
41- import { operationsProtos } from 'google-gax' ;
4240const version = require ( '../../../package.json' ) . version ;
4341
4442/**
@@ -113,8 +111,18 @@ export class CloudRedisClient {
113111 * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
114112 * For more information, please check the
115113 * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
114+ * @param {gax } [gaxInstance]: loaded instance of `google-gax`. Useful if you
115+ * need to avoid loading the default gRPC version and want to use the fallback
116+ * HTTP implementation. Load only fallback version and pass it to the constructor:
117+ * ```
118+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
119+ * const client = new CloudRedisClient({fallback: 'rest'}, gax);
120+ * ```
116121 */
117- constructor ( opts ?: ClientOptions ) {
122+ constructor (
123+ opts ?: ClientOptions ,
124+ gaxInstance ?: typeof gax | typeof gax . fallback
125+ ) {
118126 // Ensure that options include all the required fields.
119127 const staticMembers = this . constructor as typeof CloudRedisClient ;
120128 const servicePath =
@@ -134,8 +142,13 @@ export class CloudRedisClient {
134142 opts [ 'scopes' ] = staticMembers . scopes ;
135143 }
136144
145+ // Load google-gax module synchronously if needed
146+ if ( ! gaxInstance ) {
147+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
148+ }
149+
137150 // Choose either gRPC or proto-over-HTTP implementation of google-gax.
138- this . _gaxModule = opts . fallback ? gax . fallback : gax ;
151+ this . _gaxModule = opts . fallback ? gaxInstance . fallback : gaxInstance ;
139152
140153 // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
141154 this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -346,7 +359,7 @@ export class CloudRedisClient {
346359 this . innerApiCalls = { } ;
347360
348361 // Add a warn function to the client constructor so it can be easily tested.
349- this . warn = gax . warn ;
362+ this . warn = this . _gaxModule . warn ;
350363 }
351364
352365 /**
@@ -558,7 +571,7 @@ export class CloudRedisClient {
558571 options . otherArgs = options . otherArgs || { } ;
559572 options . otherArgs . headers = options . otherArgs . headers || { } ;
560573 options . otherArgs . headers [ 'x-goog-request-params' ] =
561- gax . routingHeader . fromParams ( {
574+ this . _gaxModule . routingHeader . fromParams ( {
562575 name : request . name || '' ,
563576 } ) ;
564577 this . initialize ( ) ;
@@ -653,7 +666,7 @@ export class CloudRedisClient {
653666 options . otherArgs = options . otherArgs || { } ;
654667 options . otherArgs . headers = options . otherArgs . headers || { } ;
655668 options . otherArgs . headers [ 'x-goog-request-params' ] =
656- gax . routingHeader . fromParams ( {
669+ this . _gaxModule . routingHeader . fromParams ( {
657670 name : request . name || '' ,
658671 } ) ;
659672 this . initialize ( ) ;
@@ -781,7 +794,7 @@ export class CloudRedisClient {
781794 options . otherArgs = options . otherArgs || { } ;
782795 options . otherArgs . headers = options . otherArgs . headers || { } ;
783796 options . otherArgs . headers [ 'x-goog-request-params' ] =
784- gax . routingHeader . fromParams ( {
797+ this . _gaxModule . routingHeader . fromParams ( {
785798 parent : request . parent || '' ,
786799 } ) ;
787800 this . initialize ( ) ;
@@ -807,11 +820,12 @@ export class CloudRedisClient {
807820 protos . google . cloud . redis . v1 . OperationMetadata
808821 >
809822 > {
810- const request = new operationsProtos . google . longrunning . GetOperationRequest (
811- { name}
812- ) ;
823+ const request =
824+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
825+ { name}
826+ ) ;
813827 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
814- const decodeOperation = new gax . Operation (
828+ const decodeOperation = new this . _gaxModule . Operation (
815829 operation ,
816830 this . descriptors . longrunning . createInstance ,
817831 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -933,7 +947,7 @@ export class CloudRedisClient {
933947 options . otherArgs = options . otherArgs || { } ;
934948 options . otherArgs . headers = options . otherArgs . headers || { } ;
935949 options . otherArgs . headers [ 'x-goog-request-params' ] =
936- gax . routingHeader . fromParams ( {
950+ this . _gaxModule . routingHeader . fromParams ( {
937951 'instance.name' : request . instance ! . name || '' ,
938952 } ) ;
939953 this . initialize ( ) ;
@@ -959,11 +973,12 @@ export class CloudRedisClient {
959973 protos . google . cloud . redis . v1 . OperationMetadata
960974 >
961975 > {
962- const request = new operationsProtos . google . longrunning . GetOperationRequest (
963- { name}
964- ) ;
976+ const request =
977+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
978+ { name}
979+ ) ;
965980 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
966- const decodeOperation = new gax . Operation (
981+ const decodeOperation = new this . _gaxModule . Operation (
967982 operation ,
968983 this . descriptors . longrunning . updateInstance ,
969984 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1075,7 +1090,7 @@ export class CloudRedisClient {
10751090 options . otherArgs = options . otherArgs || { } ;
10761091 options . otherArgs . headers = options . otherArgs . headers || { } ;
10771092 options . otherArgs . headers [ 'x-goog-request-params' ] =
1078- gax . routingHeader . fromParams ( {
1093+ this . _gaxModule . routingHeader . fromParams ( {
10791094 name : request . name || '' ,
10801095 } ) ;
10811096 this . initialize ( ) ;
@@ -1101,11 +1116,12 @@ export class CloudRedisClient {
11011116 protos . google . cloud . redis . v1 . OperationMetadata
11021117 >
11031118 > {
1104- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1105- { name}
1106- ) ;
1119+ const request =
1120+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1121+ { name}
1122+ ) ;
11071123 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1108- const decodeOperation = new gax . Operation (
1124+ const decodeOperation = new this . _gaxModule . Operation (
11091125 operation ,
11101126 this . descriptors . longrunning . upgradeInstance ,
11111127 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1223,7 +1239,7 @@ export class CloudRedisClient {
12231239 options . otherArgs = options . otherArgs || { } ;
12241240 options . otherArgs . headers = options . otherArgs . headers || { } ;
12251241 options . otherArgs . headers [ 'x-goog-request-params' ] =
1226- gax . routingHeader . fromParams ( {
1242+ this . _gaxModule . routingHeader . fromParams ( {
12271243 name : request . name || '' ,
12281244 } ) ;
12291245 this . initialize ( ) ;
@@ -1249,11 +1265,12 @@ export class CloudRedisClient {
12491265 protos . google . cloud . redis . v1 . OperationMetadata
12501266 >
12511267 > {
1252- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1253- { name}
1254- ) ;
1268+ const request =
1269+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1270+ { name}
1271+ ) ;
12551272 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1256- const decodeOperation = new gax . Operation (
1273+ const decodeOperation = new this . _gaxModule . Operation (
12571274 operation ,
12581275 this . descriptors . longrunning . importInstance ,
12591276 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1369,7 +1386,7 @@ export class CloudRedisClient {
13691386 options . otherArgs = options . otherArgs || { } ;
13701387 options . otherArgs . headers = options . otherArgs . headers || { } ;
13711388 options . otherArgs . headers [ 'x-goog-request-params' ] =
1372- gax . routingHeader . fromParams ( {
1389+ this . _gaxModule . routingHeader . fromParams ( {
13731390 name : request . name || '' ,
13741391 } ) ;
13751392 this . initialize ( ) ;
@@ -1395,11 +1412,12 @@ export class CloudRedisClient {
13951412 protos . google . cloud . redis . v1 . OperationMetadata
13961413 >
13971414 > {
1398- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1399- { name}
1400- ) ;
1415+ const request =
1416+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1417+ { name}
1418+ ) ;
14011419 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1402- const decodeOperation = new gax . Operation (
1420+ const decodeOperation = new this . _gaxModule . Operation (
14031421 operation ,
14041422 this . descriptors . longrunning . exportInstance ,
14051423 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1512,7 +1530,7 @@ export class CloudRedisClient {
15121530 options . otherArgs = options . otherArgs || { } ;
15131531 options . otherArgs . headers = options . otherArgs . headers || { } ;
15141532 options . otherArgs . headers [ 'x-goog-request-params' ] =
1515- gax . routingHeader . fromParams ( {
1533+ this . _gaxModule . routingHeader . fromParams ( {
15161534 name : request . name || '' ,
15171535 } ) ;
15181536 this . initialize ( ) ;
@@ -1538,11 +1556,12 @@ export class CloudRedisClient {
15381556 protos . google . cloud . redis . v1 . OperationMetadata
15391557 >
15401558 > {
1541- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1542- { name}
1543- ) ;
1559+ const request =
1560+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1561+ { name}
1562+ ) ;
15441563 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1545- const decodeOperation = new gax . Operation (
1564+ const decodeOperation = new this . _gaxModule . Operation (
15461565 operation ,
15471566 this . descriptors . longrunning . failoverInstance ,
15481567 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1652,7 +1671,7 @@ export class CloudRedisClient {
16521671 options . otherArgs = options . otherArgs || { } ;
16531672 options . otherArgs . headers = options . otherArgs . headers || { } ;
16541673 options . otherArgs . headers [ 'x-goog-request-params' ] =
1655- gax . routingHeader . fromParams ( {
1674+ this . _gaxModule . routingHeader . fromParams ( {
16561675 name : request . name || '' ,
16571676 } ) ;
16581677 this . initialize ( ) ;
@@ -1678,11 +1697,12 @@ export class CloudRedisClient {
16781697 protos . google . cloud . redis . v1 . OperationMetadata
16791698 >
16801699 > {
1681- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1682- { name}
1683- ) ;
1700+ const request =
1701+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1702+ { name}
1703+ ) ;
16841704 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1685- const decodeOperation = new gax . Operation (
1705+ const decodeOperation = new this . _gaxModule . Operation (
16861706 operation ,
16871707 this . descriptors . longrunning . deleteInstance ,
16881708 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1798,7 +1818,7 @@ export class CloudRedisClient {
17981818 options . otherArgs = options . otherArgs || { } ;
17991819 options . otherArgs . headers = options . otherArgs . headers || { } ;
18001820 options . otherArgs . headers [ 'x-goog-request-params' ] =
1801- gax . routingHeader . fromParams ( {
1821+ this . _gaxModule . routingHeader . fromParams ( {
18021822 name : request . name || '' ,
18031823 } ) ;
18041824 this . initialize ( ) ;
@@ -1824,11 +1844,12 @@ export class CloudRedisClient {
18241844 protos . google . cloud . redis . v1 . OperationMetadata
18251845 >
18261846 > {
1827- const request = new operationsProtos . google . longrunning . GetOperationRequest (
1828- { name}
1829- ) ;
1847+ const request =
1848+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
1849+ { name}
1850+ ) ;
18301851 const [ operation ] = await this . operationsClient . getOperation ( request ) ;
1831- const decodeOperation = new gax . Operation (
1852+ const decodeOperation = new this . _gaxModule . Operation (
18321853 operation ,
18331854 this . descriptors . longrunning . rescheduleMaintenance ,
18341855 this . _gaxModule . createDefaultBackoffSettings ( )
@@ -1941,7 +1962,7 @@ export class CloudRedisClient {
19411962 options . otherArgs = options . otherArgs || { } ;
19421963 options . otherArgs . headers = options . otherArgs . headers || { } ;
19431964 options . otherArgs . headers [ 'x-goog-request-params' ] =
1944- gax . routingHeader . fromParams ( {
1965+ this . _gaxModule . routingHeader . fromParams ( {
19451966 parent : request . parent || '' ,
19461967 } ) ;
19471968 this . initialize ( ) ;
@@ -1988,7 +2009,7 @@ export class CloudRedisClient {
19882009 options . otherArgs = options . otherArgs || { } ;
19892010 options . otherArgs . headers = options . otherArgs . headers || { } ;
19902011 options . otherArgs . headers [ 'x-goog-request-params' ] =
1991- gax . routingHeader . fromParams ( {
2012+ this . _gaxModule . routingHeader . fromParams ( {
19922013 parent : request . parent || '' ,
19932014 } ) ;
19942015 const defaultCallSettings = this . _defaults [ 'listInstances' ] ;
@@ -2044,7 +2065,7 @@ export class CloudRedisClient {
20442065 options . otherArgs = options . otherArgs || { } ;
20452066 options . otherArgs . headers = options . otherArgs . headers || { } ;
20462067 options . otherArgs . headers [ 'x-goog-request-params' ] =
2047- gax . routingHeader . fromParams ( {
2068+ this . _gaxModule . routingHeader . fromParams ( {
20482069 parent : request . parent || '' ,
20492070 } ) ;
20502071 const defaultCallSettings = this . _defaults [ 'listInstances' ] ;
0 commit comments