17
17
// ** All changes to this file may be overwritten. **
18
18
19
19
/* global window */
20
- import * as gax from 'google-gax' ;
21
- import {
20
+ import type * as gax from 'google-gax' ;
21
+ import type {
22
22
Callback ,
23
23
CallOptions ,
24
24
Descriptors ,
@@ -28,7 +28,6 @@ import {
28
28
PaginationCallback ,
29
29
GaxCall ,
30
30
} from 'google-gax' ;
31
-
32
31
import { Transform } from 'stream' ;
33
32
import * as protos from '../../protos/protos' ;
34
33
import jsonProtos = require( '../../protos/protos.json' ) ;
@@ -38,7 +37,6 @@ import jsonProtos = require('../../protos/protos.json');
38
37
* This file defines retry strategy and timeouts for all API methods in this library.
39
38
*/
40
39
import * as gapicConfig from './asset_service_client_config.json' ;
41
- import { operationsProtos } from 'google-gax' ;
42
40
const version = require ( '../../../package.json' ) . version ;
43
41
44
42
/**
@@ -99,8 +97,18 @@ export class AssetServiceClient {
99
97
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
100
98
* For more information, please check the
101
99
* {@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 AssetServiceClient({fallback: 'rest'}, gax);
106
+ * ```
102
107
*/
103
- constructor ( opts ?: ClientOptions ) {
108
+ constructor (
109
+ opts ?: ClientOptions ,
110
+ gaxInstance ?: typeof gax | typeof gax . fallback
111
+ ) {
104
112
// Ensure that options include all the required fields.
105
113
const staticMembers = this . constructor as typeof AssetServiceClient ;
106
114
const servicePath =
@@ -120,8 +128,13 @@ export class AssetServiceClient {
120
128
opts [ 'scopes' ] = staticMembers . scopes ;
121
129
}
122
130
131
+ // Load google-gax module synchronously if needed
132
+ if ( ! gaxInstance ) {
133
+ gaxInstance = require ( 'google-gax' ) as typeof gax ;
134
+ }
135
+
123
136
// 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 ;
125
138
126
139
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
127
140
this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ;
@@ -290,7 +303,7 @@ export class AssetServiceClient {
290
303
this . innerApiCalls = { } ;
291
304
292
305
// Add a warn function to the client constructor so it can be easily tested.
293
- this . warn = gax . warn ;
306
+ this . warn = this . _gaxModule . warn ;
294
307
}
295
308
296
309
/**
@@ -560,7 +573,7 @@ export class AssetServiceClient {
560
573
options . otherArgs = options . otherArgs || { } ;
561
574
options . otherArgs . headers = options . otherArgs . headers || { } ;
562
575
options . otherArgs . headers [ 'x-goog-request-params' ] =
563
- gax . routingHeader . fromParams ( {
576
+ this . _gaxModule . routingHeader . fromParams ( {
564
577
parent : request . parent || '' ,
565
578
} ) ;
566
579
this . initialize ( ) ;
@@ -656,7 +669,7 @@ export class AssetServiceClient {
656
669
options . otherArgs = options . otherArgs || { } ;
657
670
options . otherArgs . headers = options . otherArgs . headers || { } ;
658
671
options . otherArgs . headers [ 'x-goog-request-params' ] =
659
- gax . routingHeader . fromParams ( {
672
+ this . _gaxModule . routingHeader . fromParams ( {
660
673
parent : request . parent || '' ,
661
674
} ) ;
662
675
this . initialize ( ) ;
@@ -742,7 +755,7 @@ export class AssetServiceClient {
742
755
options . otherArgs = options . otherArgs || { } ;
743
756
options . otherArgs . headers = options . otherArgs . headers || { } ;
744
757
options . otherArgs . headers [ 'x-goog-request-params' ] =
745
- gax . routingHeader . fromParams ( {
758
+ this . _gaxModule . routingHeader . fromParams ( {
746
759
name : request . name || '' ,
747
760
} ) ;
748
761
this . initialize ( ) ;
@@ -827,7 +840,7 @@ export class AssetServiceClient {
827
840
options . otherArgs = options . otherArgs || { } ;
828
841
options . otherArgs . headers = options . otherArgs . headers || { } ;
829
842
options . otherArgs . headers [ 'x-goog-request-params' ] =
830
- gax . routingHeader . fromParams ( {
843
+ this . _gaxModule . routingHeader . fromParams ( {
831
844
parent : request . parent || '' ,
832
845
} ) ;
833
846
this . initialize ( ) ;
@@ -918,7 +931,7 @@ export class AssetServiceClient {
918
931
options . otherArgs = options . otherArgs || { } ;
919
932
options . otherArgs . headers = options . otherArgs . headers || { } ;
920
933
options . otherArgs . headers [ 'x-goog-request-params' ] =
921
- gax . routingHeader . fromParams ( {
934
+ this . _gaxModule . routingHeader . fromParams ( {
922
935
'feed.name' : request . feed ! . name || '' ,
923
936
} ) ;
924
937
this . initialize ( ) ;
@@ -1004,7 +1017,7 @@ export class AssetServiceClient {
1004
1017
options . otherArgs = options . otherArgs || { } ;
1005
1018
options . otherArgs . headers = options . otherArgs . headers || { } ;
1006
1019
options . otherArgs . headers [ 'x-goog-request-params' ] =
1007
- gax . routingHeader . fromParams ( {
1020
+ this . _gaxModule . routingHeader . fromParams ( {
1008
1021
name : request . name || '' ,
1009
1022
} ) ;
1010
1023
this . initialize ( ) ;
@@ -1119,7 +1132,7 @@ export class AssetServiceClient {
1119
1132
options . otherArgs = options . otherArgs || { } ;
1120
1133
options . otherArgs . headers = options . otherArgs . headers || { } ;
1121
1134
options . otherArgs . headers [ 'x-goog-request-params' ] =
1122
- gax . routingHeader . fromParams ( {
1135
+ this . _gaxModule . routingHeader . fromParams ( {
1123
1136
'analysis_query.scope' : request . analysisQuery ! . scope || '' ,
1124
1137
} ) ;
1125
1138
this . initialize ( ) ;
@@ -1218,7 +1231,7 @@ export class AssetServiceClient {
1218
1231
options . otherArgs = options . otherArgs || { } ;
1219
1232
options . otherArgs . headers = options . otherArgs . headers || { } ;
1220
1233
options . otherArgs . headers [ 'x-goog-request-params' ] =
1221
- gax . routingHeader . fromParams ( {
1234
+ this . _gaxModule . routingHeader . fromParams ( {
1222
1235
resource : request . resource || '' ,
1223
1236
} ) ;
1224
1237
this . initialize ( ) ;
@@ -1368,7 +1381,7 @@ export class AssetServiceClient {
1368
1381
options . otherArgs = options . otherArgs || { } ;
1369
1382
options . otherArgs . headers = options . otherArgs . headers || { } ;
1370
1383
options . otherArgs . headers [ 'x-goog-request-params' ] =
1371
- gax . routingHeader . fromParams ( {
1384
+ this . _gaxModule . routingHeader . fromParams ( {
1372
1385
parent : request . parent || '' ,
1373
1386
} ) ;
1374
1387
this . initialize ( ) ;
@@ -1470,7 +1483,7 @@ export class AssetServiceClient {
1470
1483
options . otherArgs = options . otherArgs || { } ;
1471
1484
options . otherArgs . headers = options . otherArgs . headers || { } ;
1472
1485
options . otherArgs . headers [ 'x-goog-request-params' ] =
1473
- gax . routingHeader . fromParams ( {
1486
+ this . _gaxModule . routingHeader . fromParams ( {
1474
1487
parent : request . parent || '' ,
1475
1488
} ) ;
1476
1489
this . initialize ( ) ;
@@ -1557,7 +1570,7 @@ export class AssetServiceClient {
1557
1570
options . otherArgs = options . otherArgs || { } ;
1558
1571
options . otherArgs . headers = options . otherArgs . headers || { } ;
1559
1572
options . otherArgs . headers [ 'x-goog-request-params' ] =
1560
- gax . routingHeader . fromParams ( {
1573
+ this . _gaxModule . routingHeader . fromParams ( {
1561
1574
name : request . name || '' ,
1562
1575
} ) ;
1563
1576
this . initialize ( ) ;
@@ -1651,7 +1664,7 @@ export class AssetServiceClient {
1651
1664
options . otherArgs = options . otherArgs || { } ;
1652
1665
options . otherArgs . headers = options . otherArgs . headers || { } ;
1653
1666
options . otherArgs . headers [ 'x-goog-request-params' ] =
1654
- gax . routingHeader . fromParams ( {
1667
+ this . _gaxModule . routingHeader . fromParams ( {
1655
1668
'saved_query.name' : request . savedQuery ! . name || '' ,
1656
1669
} ) ;
1657
1670
this . initialize ( ) ;
@@ -1741,7 +1754,7 @@ export class AssetServiceClient {
1741
1754
options . otherArgs = options . otherArgs || { } ;
1742
1755
options . otherArgs . headers = options . otherArgs . headers || { } ;
1743
1756
options . otherArgs . headers [ 'x-goog-request-params' ] =
1744
- gax . routingHeader . fromParams ( {
1757
+ this . _gaxModule . routingHeader . fromParams ( {
1745
1758
name : request . name || '' ,
1746
1759
} ) ;
1747
1760
this . initialize ( ) ;
@@ -1854,7 +1867,7 @@ export class AssetServiceClient {
1854
1867
options . otherArgs = options . otherArgs || { } ;
1855
1868
options . otherArgs . headers = options . otherArgs . headers || { } ;
1856
1869
options . otherArgs . headers [ 'x-goog-request-params' ] =
1857
- gax . routingHeader . fromParams ( {
1870
+ this . _gaxModule . routingHeader . fromParams ( {
1858
1871
scope : request . scope || '' ,
1859
1872
} ) ;
1860
1873
this . initialize ( ) ;
@@ -2022,7 +2035,7 @@ export class AssetServiceClient {
2022
2035
options . otherArgs = options . otherArgs || { } ;
2023
2036
options . otherArgs . headers = options . otherArgs . headers || { } ;
2024
2037
options . otherArgs . headers [ 'x-goog-request-params' ] =
2025
- gax . routingHeader . fromParams ( {
2038
+ this . _gaxModule . routingHeader . fromParams ( {
2026
2039
parent : request . parent || '' ,
2027
2040
} ) ;
2028
2041
this . initialize ( ) ;
@@ -2048,11 +2061,12 @@ export class AssetServiceClient {
2048
2061
protos . google . cloud . asset . v1 . ExportAssetsRequest
2049
2062
>
2050
2063
> {
2051
- const request = new operationsProtos . google . longrunning . GetOperationRequest (
2052
- { name}
2053
- ) ;
2064
+ const request =
2065
+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
2066
+ { name}
2067
+ ) ;
2054
2068
const [ operation ] = await this . operationsClient . getOperation ( request ) ;
2055
- const decodeOperation = new gax . Operation (
2069
+ const decodeOperation = new this . _gaxModule . Operation (
2056
2070
operation ,
2057
2071
this . descriptors . longrunning . exportAssets ,
2058
2072
this . _gaxModule . createDefaultBackoffSettings ( )
@@ -2188,7 +2202,7 @@ export class AssetServiceClient {
2188
2202
options . otherArgs = options . otherArgs || { } ;
2189
2203
options . otherArgs . headers = options . otherArgs . headers || { } ;
2190
2204
options . otherArgs . headers [ 'x-goog-request-params' ] =
2191
- gax . routingHeader . fromParams ( {
2205
+ this . _gaxModule . routingHeader . fromParams ( {
2192
2206
'analysis_query.scope' : request . analysisQuery ! . scope || '' ,
2193
2207
} ) ;
2194
2208
this . initialize ( ) ;
@@ -2218,11 +2232,12 @@ export class AssetServiceClient {
2218
2232
protos . google . cloud . asset . v1 . AnalyzeIamPolicyLongrunningMetadata
2219
2233
>
2220
2234
> {
2221
- const request = new operationsProtos . google . longrunning . GetOperationRequest (
2222
- { name}
2223
- ) ;
2235
+ const request =
2236
+ new this . _gaxModule . operationsProtos . google . longrunning . GetOperationRequest (
2237
+ { name}
2238
+ ) ;
2224
2239
const [ operation ] = await this . operationsClient . getOperation ( request ) ;
2225
- const decodeOperation = new gax . Operation (
2240
+ const decodeOperation = new this . _gaxModule . Operation (
2226
2241
operation ,
2227
2242
this . descriptors . longrunning . analyzeIamPolicyLongrunning ,
2228
2243
this . _gaxModule . createDefaultBackoffSettings ( )
@@ -2368,7 +2383,7 @@ export class AssetServiceClient {
2368
2383
options . otherArgs = options . otherArgs || { } ;
2369
2384
options . otherArgs . headers = options . otherArgs . headers || { } ;
2370
2385
options . otherArgs . headers [ 'x-goog-request-params' ] =
2371
- gax . routingHeader . fromParams ( {
2386
+ this . _gaxModule . routingHeader . fromParams ( {
2372
2387
parent : request . parent || '' ,
2373
2388
} ) ;
2374
2389
this . initialize ( ) ;
@@ -2457,7 +2472,7 @@ export class AssetServiceClient {
2457
2472
options . otherArgs = options . otherArgs || { } ;
2458
2473
options . otherArgs . headers = options . otherArgs . headers || { } ;
2459
2474
options . otherArgs . headers [ 'x-goog-request-params' ] =
2460
- gax . routingHeader . fromParams ( {
2475
+ this . _gaxModule . routingHeader . fromParams ( {
2461
2476
parent : request . parent || '' ,
2462
2477
} ) ;
2463
2478
const defaultCallSettings = this . _defaults [ 'listAssets' ] ;
@@ -2555,7 +2570,7 @@ export class AssetServiceClient {
2555
2570
options . otherArgs = options . otherArgs || { } ;
2556
2571
options . otherArgs . headers = options . otherArgs . headers || { } ;
2557
2572
options . otherArgs . headers [ 'x-goog-request-params' ] =
2558
- gax . routingHeader . fromParams ( {
2573
+ this . _gaxModule . routingHeader . fromParams ( {
2559
2574
parent : request . parent || '' ,
2560
2575
} ) ;
2561
2576
const defaultCallSettings = this . _defaults [ 'listAssets' ] ;
@@ -2799,7 +2814,7 @@ export class AssetServiceClient {
2799
2814
options . otherArgs = options . otherArgs || { } ;
2800
2815
options . otherArgs . headers = options . otherArgs . headers || { } ;
2801
2816
options . otherArgs . headers [ 'x-goog-request-params' ] =
2802
- gax . routingHeader . fromParams ( {
2817
+ this . _gaxModule . routingHeader . fromParams ( {
2803
2818
scope : request . scope || '' ,
2804
2819
} ) ;
2805
2820
this . initialize ( ) ;
@@ -2974,7 +2989,7 @@ export class AssetServiceClient {
2974
2989
options . otherArgs = options . otherArgs || { } ;
2975
2990
options . otherArgs . headers = options . otherArgs . headers || { } ;
2976
2991
options . otherArgs . headers [ 'x-goog-request-params' ] =
2977
- gax . routingHeader . fromParams ( {
2992
+ this . _gaxModule . routingHeader . fromParams ( {
2978
2993
scope : request . scope || '' ,
2979
2994
} ) ;
2980
2995
const defaultCallSettings = this . _defaults [ 'searchAllResources' ] ;
@@ -3158,7 +3173,7 @@ export class AssetServiceClient {
3158
3173
options . otherArgs = options . otherArgs || { } ;
3159
3174
options . otherArgs . headers = options . otherArgs . headers || { } ;
3160
3175
options . otherArgs . headers [ 'x-goog-request-params' ] =
3161
- gax . routingHeader . fromParams ( {
3176
+ this . _gaxModule . routingHeader . fromParams ( {
3162
3177
scope : request . scope || '' ,
3163
3178
} ) ;
3164
3179
const defaultCallSettings = this . _defaults [ 'searchAllResources' ] ;
@@ -3355,7 +3370,7 @@ export class AssetServiceClient {
3355
3370
options . otherArgs = options . otherArgs || { } ;
3356
3371
options . otherArgs . headers = options . otherArgs . headers || { } ;
3357
3372
options . otherArgs . headers [ 'x-goog-request-params' ] =
3358
- gax . routingHeader . fromParams ( {
3373
+ this . _gaxModule . routingHeader . fromParams ( {
3359
3374
scope : request . scope || '' ,
3360
3375
} ) ;
3361
3376
this . initialize ( ) ;
@@ -3483,7 +3498,7 @@ export class AssetServiceClient {
3483
3498
options . otherArgs = options . otherArgs || { } ;
3484
3499
options . otherArgs . headers = options . otherArgs . headers || { } ;
3485
3500
options . otherArgs . headers [ 'x-goog-request-params' ] =
3486
- gax . routingHeader . fromParams ( {
3501
+ this . _gaxModule . routingHeader . fromParams ( {
3487
3502
scope : request . scope || '' ,
3488
3503
} ) ;
3489
3504
const defaultCallSettings = this . _defaults [ 'searchAllIamPolicies' ] ;
@@ -3620,7 +3635,7 @@ export class AssetServiceClient {
3620
3635
options . otherArgs = options . otherArgs || { } ;
3621
3636
options . otherArgs . headers = options . otherArgs . headers || { } ;
3622
3637
options . otherArgs . headers [ 'x-goog-request-params' ] =
3623
- gax . routingHeader . fromParams ( {
3638
+ this . _gaxModule . routingHeader . fromParams ( {
3624
3639
scope : request . scope || '' ,
3625
3640
} ) ;
3626
3641
const defaultCallSettings = this . _defaults [ 'searchAllIamPolicies' ] ;
@@ -3735,7 +3750,7 @@ export class AssetServiceClient {
3735
3750
options . otherArgs = options . otherArgs || { } ;
3736
3751
options . otherArgs . headers = options . otherArgs . headers || { } ;
3737
3752
options . otherArgs . headers [ 'x-goog-request-params' ] =
3738
- gax . routingHeader . fromParams ( {
3753
+ this . _gaxModule . routingHeader . fromParams ( {
3739
3754
parent : request . parent || '' ,
3740
3755
} ) ;
3741
3756
this . initialize ( ) ;
@@ -3790,7 +3805,7 @@ export class AssetServiceClient {
3790
3805
options . otherArgs = options . otherArgs || { } ;
3791
3806
options . otherArgs . headers = options . otherArgs . headers || { } ;
3792
3807
options . otherArgs . headers [ 'x-goog-request-params' ] =
3793
- gax . routingHeader . fromParams ( {
3808
+ this . _gaxModule . routingHeader . fromParams ( {
3794
3809
parent : request . parent || '' ,
3795
3810
} ) ;
3796
3811
const defaultCallSettings = this . _defaults [ 'listSavedQueries' ] ;
@@ -3854,7 +3869,7 @@ export class AssetServiceClient {
3854
3869
options . otherArgs = options . otherArgs || { } ;
3855
3870
options . otherArgs . headers = options . otherArgs . headers || { } ;
3856
3871
options . otherArgs . headers [ 'x-goog-request-params' ] =
3857
- gax . routingHeader . fromParams ( {
3872
+ this . _gaxModule . routingHeader . fromParams ( {
3858
3873
parent : request . parent || '' ,
3859
3874
} ) ;
3860
3875
const defaultCallSettings = this . _defaults [ 'listSavedQueries' ] ;
0 commit comments