@google-cloud/storage-control 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +59 -74
  2. package/build/protos/google/storage/v2/storage.proto +3161 -0
  3. package/build/protos/protos.d.ts +10641 -0
  4. package/build/protos/protos.js +28904 -0
  5. package/build/protos/protos.json +4286 -4
  6. package/build/src/index.d.ts +2 -3
  7. package/build/src/index.js +3 -3
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/storage_control_client.d.ts +2035 -0
  10. package/build/src/storage_control_client.js +1387 -0
  11. package/build/src/storage_control_client.js.map +1 -0
  12. package/build/src/util/ast_utils.d.ts +22 -0
  13. package/build/src/util/ast_utils.js +352 -0
  14. package/build/src/util/ast_utils.js.map +1 -0
  15. package/build/src/util/index_fix_utils.d.ts +15 -0
  16. package/build/src/util/index_fix_utils.js +86 -0
  17. package/build/src/util/index_fix_utils.js.map +1 -0
  18. package/build/src/util/proto_utils.d.ts +13 -0
  19. package/build/src/util/proto_utils.js +53 -0
  20. package/build/src/util/proto_utils.js.map +1 -0
  21. package/build/src/util/storage_control_utils.d.ts +1 -0
  22. package/build/src/util/storage_control_utils.js +31 -0
  23. package/build/src/util/storage_control_utils.js.map +1 -0
  24. package/build/src/util/uber_client_builder.d.ts +12 -0
  25. package/build/src/util/uber_client_builder.js +187 -0
  26. package/build/src/util/uber_client_builder.js.map +1 -0
  27. package/build/src/v2/index.d.ts +1 -0
  28. package/build/src/v2/index.js +3 -1
  29. package/build/src/v2/index.js.map +1 -1
  30. package/build/src/v2/storage_client.d.ts +614 -0
  31. package/build/src/v2/storage_client.js +911 -0
  32. package/build/src/v2/storage_client.js.map +1 -0
  33. package/build/src/v2/storage_client_config.json +65 -0
  34. package/build/src/v2/storage_control_client.d.ts +138 -138
  35. package/build/src/v2/storage_control_client.js +485 -231
  36. package/build/src/v2/storage_control_client.js.map +1 -1
  37. package/build/src/v2/storage_proto_list.json +3 -0
  38. package/package.json +4 -2
@@ -0,0 +1,911 @@
1
+ "use strict";
2
+ // Copyright 2025 Google LLC
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+ // ** This file is automatically generated by gapic-generator-typescript. **
17
+ // ** https://github.com/googleapis/gapic-generator-typescript **
18
+ // ** All changes to this file may be overwritten. **
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.StorageClient = void 0;
21
+ const jsonProtos = require("../../protos/protos.json");
22
+ const google_gax_1 = require("google-gax");
23
+ /**
24
+ * Client JSON configuration object, loaded from
25
+ * `src/v2/storage_client_config.json`.
26
+ * This file defines retry strategy and timeouts for all API methods in this library.
27
+ */
28
+ const gapicConfig = require("./storage_client_config.json");
29
+ const version = require('../../../package.json').version;
30
+ /**
31
+ * ## API Overview and Naming Syntax
32
+ *
33
+ * The Cloud Storage gRPC API allows applications to read and write data through
34
+ * the abstractions of buckets and objects. For a description of these
35
+ * abstractions please see [Cloud Storage
36
+ * documentation](https://cloud.google.com/storage/docs).
37
+ *
38
+ * Resources are named as follows:
39
+ *
40
+ * - Projects are referred to as they are defined by the Resource Manager API,
41
+ * using strings like `projects/123456` or `projects/my-string-id`.
42
+ * - Buckets are named using string names of the form:
43
+ * `projects/{project}/buckets/{bucket}`.
44
+ * For globally unique buckets, `_` might be substituted for the project.
45
+ * - Objects are uniquely identified by their name along with the name of the
46
+ * bucket they belong to, as separate strings in this API. For example:
47
+ *
48
+ * ```
49
+ * ReadObjectRequest {
50
+ * bucket: 'projects/_/buckets/my-bucket'
51
+ * object: 'my-object'
52
+ * }
53
+ * ```
54
+ *
55
+ * Note that object names can contain `/` characters, which are treated as
56
+ * any other character (no special directory semantics).
57
+ * @class
58
+ * @memberof v2
59
+ */
60
+ class StorageClient {
61
+ _terminated = false;
62
+ _opts;
63
+ _providedCustomServicePath;
64
+ _gaxModule;
65
+ _gaxGrpc;
66
+ _protos;
67
+ _defaults;
68
+ _universeDomain;
69
+ _servicePath;
70
+ _log = google_gax_1.loggingUtils.log('storage');
71
+ auth;
72
+ descriptors = {
73
+ page: {},
74
+ stream: {},
75
+ longrunning: {},
76
+ batching: {},
77
+ };
78
+ warn;
79
+ innerApiCalls;
80
+ pathTemplates;
81
+ storageStub;
82
+ /**
83
+ * Construct an instance of StorageClient.
84
+ *
85
+ * @param {object} [options] - The configuration object.
86
+ * The options accepted by the constructor are described in detail
87
+ * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
88
+ * The common options are:
89
+ * @param {object} [options.credentials] - Credentials object.
90
+ * @param {string} [options.credentials.client_email]
91
+ * @param {string} [options.credentials.private_key]
92
+ * @param {string} [options.email] - Account email address. Required when
93
+ * using a .pem or .p12 keyFilename.
94
+ * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
95
+ * .p12 key downloaded from the Google Developers Console. If you provide
96
+ * a path to a JSON file, the projectId option below is not necessary.
97
+ * NOTE: .pem and .p12 require you to specify options.email as well.
98
+ * @param {number} [options.port] - The port on which to connect to
99
+ * the remote host.
100
+ * @param {string} [options.projectId] - The project ID from the Google
101
+ * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
102
+ * the environment variable GCLOUD_PROJECT for your project ID. If your
103
+ * app is running in an environment which supports
104
+ * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials},
105
+ * your project ID will be detected automatically.
106
+ * @param {string} [options.apiEndpoint] - The domain name of the
107
+ * API remote host.
108
+ * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
109
+ * Follows the structure of {@link gapicConfig}.
110
+ * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
111
+ * For more information, please check the
112
+ * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
113
+ * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
114
+ * need to avoid loading the default gRPC version and want to use the fallback
115
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
116
+ * ```
117
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
118
+ * const client = new StorageClient({fallback: true}, gax);
119
+ * ```
120
+ */
121
+ constructor(opts, gaxInstance) {
122
+ // Ensure that options include all the required fields.
123
+ const staticMembers = this.constructor;
124
+ if (opts?.universe_domain &&
125
+ opts?.universeDomain &&
126
+ opts?.universe_domain !== opts?.universeDomain) {
127
+ throw new Error('Please set either universe_domain or universeDomain, but not both.');
128
+ }
129
+ const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object'
130
+ ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
131
+ : undefined;
132
+ this._universeDomain =
133
+ opts?.universeDomain ??
134
+ opts?.universe_domain ??
135
+ universeDomainEnvVar ??
136
+ 'googleapis.com';
137
+ this._servicePath = 'storage.' + this._universeDomain;
138
+ const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath;
139
+ this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint);
140
+ const port = opts?.port || staticMembers.port;
141
+ const clientConfig = opts?.clientConfig ?? {};
142
+ const fallback = opts?.fallback ??
143
+ (typeof window !== 'undefined' && typeof window?.fetch === 'function');
144
+ opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
145
+ // Request numeric enum values if REST transport is used.
146
+ opts.numericEnums = true;
147
+ // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
148
+ if (servicePath !== this._servicePath && !('scopes' in opts)) {
149
+ opts['scopes'] = staticMembers.scopes;
150
+ }
151
+ // Load google-gax module synchronously if needed
152
+ if (!gaxInstance) {
153
+ gaxInstance = require('google-gax');
154
+ }
155
+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
156
+ this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
157
+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
158
+ this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
159
+ // Save options to use in initialize() method.
160
+ this._opts = opts;
161
+ // Save the auth object to the client, for use by other methods.
162
+ this.auth = this._gaxGrpc.auth;
163
+ // Set useJWTAccessWithScope on the auth object.
164
+ this.auth.useJWTAccessWithScope = true;
165
+ // Set defaultServicePath on the auth object.
166
+ this.auth.defaultServicePath = this._servicePath;
167
+ // Set the default scopes in auth client if needed.
168
+ if (servicePath === this._servicePath) {
169
+ this.auth.defaultScopes = staticMembers.scopes;
170
+ }
171
+ // Determine the client header string.
172
+ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
173
+ if (typeof process === 'object' && 'versions' in process) {
174
+ clientHeader.push(`gl-node/${process.versions.node}`);
175
+ }
176
+ else {
177
+ clientHeader.push(`gl-web/${this._gaxModule.version}`);
178
+ }
179
+ if (!opts.fallback) {
180
+ clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
181
+ }
182
+ else {
183
+ clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
184
+ }
185
+ if (opts.libName && opts.libVersion) {
186
+ clientHeader.push(`${opts.libName}/${opts.libVersion}`);
187
+ }
188
+ // Load the applicable protos.
189
+ this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
190
+ // This API contains "path templates"; forward-slash-separated
191
+ // identifiers to uniquely identify resources within the API.
192
+ // Create useful helper objects for these.
193
+ this.pathTemplates = {
194
+ bucketPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/buckets/{bucket}'),
195
+ cryptoKeyPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}'),
196
+ projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
197
+ };
198
+ // Some of the methods on this service return "paged" results,
199
+ // (e.g. 50 results at a time, with tokens to get subsequent
200
+ // pages). Denote the keys used for pagination and results.
201
+ this.descriptors.page = {
202
+ listBuckets: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'buckets'),
203
+ };
204
+ // Put together the default options sent with requests.
205
+ this._defaults = this._gaxGrpc.constructSettings('google.storage.v2.Storage', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
206
+ // Set up a dictionary of "inner API calls"; the core implementation
207
+ // of calling the API is handled in `google-gax`, with this code
208
+ // merely providing the destination and request information.
209
+ this.innerApiCalls = {};
210
+ // Add a warn function to the client constructor so it can be easily tested.
211
+ this.warn = this._gaxModule.warn;
212
+ }
213
+ /**
214
+ * Initialize the client.
215
+ * Performs asynchronous operations (such as authentication) and prepares the client.
216
+ * This function will be called automatically when any class method is called for the
217
+ * first time, but if you need to initialize it before calling an actual method,
218
+ * feel free to call initialize() directly.
219
+ *
220
+ * You can await on this method if you want to make sure the client is initialized.
221
+ *
222
+ * @returns {Promise} A promise that resolves to an authenticated service stub.
223
+ */
224
+ initialize() {
225
+ // If the client stub promise is already initialized, return immediately.
226
+ if (this.storageStub) {
227
+ return this.storageStub;
228
+ }
229
+ // Put together the "service stub" for
230
+ // google.storage.v2.Storage.
231
+ this.storageStub = this._gaxGrpc.createStub(this._opts.fallback
232
+ ? this._protos.lookupService('google.storage.v2.Storage')
233
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
+ this._protos.google.storage.v2.Storage, this._opts, this._providedCustomServicePath);
235
+ // Iterate over each of the methods that the service provides
236
+ // and create an API call method for each.
237
+ const storageStubMethods = [
238
+ 'deleteBucket',
239
+ 'getBucket',
240
+ 'createBucket',
241
+ 'listBuckets',
242
+ 'lockBucketRetentionPolicy',
243
+ 'updateBucket',
244
+ ];
245
+ for (const methodName of storageStubMethods) {
246
+ const callPromise = this.storageStub.then(stub => (...args) => {
247
+ if (this._terminated) {
248
+ return Promise.reject('The client has already been closed.');
249
+ }
250
+ const func = stub[methodName];
251
+ return func.apply(stub, args);
252
+ }, (err) => () => {
253
+ throw err;
254
+ });
255
+ const descriptor = this.descriptors.page[methodName] || undefined;
256
+ const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
257
+ this.innerApiCalls[methodName] = apiCall;
258
+ }
259
+ return this.storageStub;
260
+ }
261
+ /**
262
+ * The DNS address for this API service.
263
+ * @deprecated Use the apiEndpoint method of the client instance.
264
+ * @returns {string} The DNS address for this service.
265
+ */
266
+ static get servicePath() {
267
+ if (typeof process === 'object' &&
268
+ typeof process.emitWarning === 'function') {
269
+ process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
270
+ }
271
+ return 'storage.googleapis.com';
272
+ }
273
+ /**
274
+ * The DNS address for this API service - same as servicePath.
275
+ * @deprecated Use the apiEndpoint method of the client instance.
276
+ * @returns {string} The DNS address for this service.
277
+ */
278
+ static get apiEndpoint() {
279
+ if (typeof process === 'object' &&
280
+ typeof process.emitWarning === 'function') {
281
+ process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
282
+ }
283
+ return 'storage.googleapis.com';
284
+ }
285
+ /**
286
+ * The DNS address for this API service.
287
+ * @returns {string} The DNS address for this service.
288
+ */
289
+ get apiEndpoint() {
290
+ return this._servicePath;
291
+ }
292
+ get universeDomain() {
293
+ return this._universeDomain;
294
+ }
295
+ /**
296
+ * The port for this API service.
297
+ * @returns {number} The default port for this service.
298
+ */
299
+ static get port() {
300
+ return 443;
301
+ }
302
+ /**
303
+ * The scopes needed to make gRPC calls for every method defined
304
+ * in this service.
305
+ * @returns {string[]} List of default scopes.
306
+ */
307
+ static get scopes() {
308
+ return [
309
+ 'https://www.googleapis.com/auth/cloud-platform',
310
+ 'https://www.googleapis.com/auth/cloud-platform.read-only',
311
+ 'https://www.googleapis.com/auth/devstorage.full_control',
312
+ 'https://www.googleapis.com/auth/devstorage.read_only',
313
+ 'https://www.googleapis.com/auth/devstorage.read_write',
314
+ ];
315
+ }
316
+ /**
317
+ * Return the project ID used by this class.
318
+ * @returns {Promise} A promise that resolves to string containing the project ID.
319
+ */
320
+ getProjectId(callback) {
321
+ if (callback) {
322
+ this.auth.getProjectId(callback);
323
+ return;
324
+ }
325
+ return this.auth.getProjectId();
326
+ }
327
+ deleteBucket(request, optionsOrCallback, callback) {
328
+ request = request || {};
329
+ let options;
330
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
331
+ callback = optionsOrCallback;
332
+ options = {};
333
+ }
334
+ else {
335
+ options = optionsOrCallback;
336
+ }
337
+ options = options || {};
338
+ options.otherArgs = options.otherArgs || {};
339
+ options.otherArgs.headers = options.otherArgs.headers || {};
340
+ const routingParameter = {};
341
+ {
342
+ const fieldValue = request.name;
343
+ if (fieldValue !== undefined && fieldValue !== null) {
344
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
345
+ if (match) {
346
+ const parameterValue = match.groups?.['bucket'] ?? fieldValue;
347
+ Object.assign(routingParameter, { bucket: parameterValue });
348
+ }
349
+ }
350
+ }
351
+ options.otherArgs.headers['x-goog-request-params'] =
352
+ this._gaxModule.routingHeader.fromParams(routingParameter);
353
+ this.initialize().catch(err => {
354
+ throw err;
355
+ });
356
+ this._log.info('deleteBucket request %j', request);
357
+ const wrappedCallback = callback
358
+ ? (error, response, options, rawResponse) => {
359
+ this._log.info('deleteBucket response %j', response);
360
+ callback(error, response, options, rawResponse); // We verified callback above.
361
+ }
362
+ : undefined;
363
+ return this.innerApiCalls
364
+ .deleteBucket(request, options, wrappedCallback)
365
+ ?.then(([response, options, rawResponse]) => {
366
+ this._log.info('deleteBucket response %j', response);
367
+ return [response, options, rawResponse];
368
+ })
369
+ .catch((error) => {
370
+ if (error &&
371
+ 'statusDetails' in error &&
372
+ error.statusDetails instanceof Array) {
373
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
374
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
375
+ }
376
+ throw error;
377
+ });
378
+ }
379
+ getBucket(request, optionsOrCallback, callback) {
380
+ request = request || {};
381
+ let options;
382
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
383
+ callback = optionsOrCallback;
384
+ options = {};
385
+ }
386
+ else {
387
+ options = optionsOrCallback;
388
+ }
389
+ options = options || {};
390
+ options.otherArgs = options.otherArgs || {};
391
+ options.otherArgs.headers = options.otherArgs.headers || {};
392
+ const routingParameter = {};
393
+ {
394
+ const fieldValue = request.name;
395
+ if (fieldValue !== undefined && fieldValue !== null) {
396
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
397
+ if (match) {
398
+ const parameterValue = match.groups?.['bucket'] ?? fieldValue;
399
+ Object.assign(routingParameter, { bucket: parameterValue });
400
+ }
401
+ }
402
+ }
403
+ options.otherArgs.headers['x-goog-request-params'] =
404
+ this._gaxModule.routingHeader.fromParams(routingParameter);
405
+ this.initialize().catch(err => {
406
+ throw err;
407
+ });
408
+ this._log.info('getBucket request %j', request);
409
+ const wrappedCallback = callback
410
+ ? (error, response, options, rawResponse) => {
411
+ this._log.info('getBucket response %j', response);
412
+ callback(error, response, options, rawResponse); // We verified callback above.
413
+ }
414
+ : undefined;
415
+ return this.innerApiCalls
416
+ .getBucket(request, options, wrappedCallback)
417
+ ?.then(([response, options, rawResponse]) => {
418
+ this._log.info('getBucket response %j', response);
419
+ return [response, options, rawResponse];
420
+ })
421
+ .catch((error) => {
422
+ if (error &&
423
+ 'statusDetails' in error &&
424
+ error.statusDetails instanceof Array) {
425
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
426
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
427
+ }
428
+ throw error;
429
+ });
430
+ }
431
+ createBucket(request, optionsOrCallback, callback) {
432
+ request = request || {};
433
+ let options;
434
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
435
+ callback = optionsOrCallback;
436
+ options = {};
437
+ }
438
+ else {
439
+ options = optionsOrCallback;
440
+ }
441
+ options = options || {};
442
+ options.otherArgs = options.otherArgs || {};
443
+ options.otherArgs.headers = options.otherArgs.headers || {};
444
+ const routingParameter = {};
445
+ {
446
+ const fieldValue = request.parent;
447
+ if (fieldValue !== undefined && fieldValue !== null) {
448
+ const match = fieldValue
449
+ .toString()
450
+ .match(RegExp('(?<project>(?:.*)?)'));
451
+ if (match) {
452
+ const parameterValue = match.groups?.['project'] ?? fieldValue;
453
+ Object.assign(routingParameter, { project: parameterValue });
454
+ }
455
+ }
456
+ }
457
+ {
458
+ const fieldValue = request.bucket?.project;
459
+ if (fieldValue !== undefined && fieldValue !== null) {
460
+ const match = fieldValue
461
+ .toString()
462
+ .match(RegExp('(?<project>(?:.*)?)'));
463
+ if (match) {
464
+ const parameterValue = match.groups?.['project'] ?? fieldValue;
465
+ Object.assign(routingParameter, { project: parameterValue });
466
+ }
467
+ }
468
+ }
469
+ options.otherArgs.headers['x-goog-request-params'] =
470
+ this._gaxModule.routingHeader.fromParams(routingParameter);
471
+ this.initialize().catch(err => {
472
+ throw err;
473
+ });
474
+ this._log.info('createBucket request %j', request);
475
+ const wrappedCallback = callback
476
+ ? (error, response, options, rawResponse) => {
477
+ this._log.info('createBucket response %j', response);
478
+ callback(error, response, options, rawResponse); // We verified callback above.
479
+ }
480
+ : undefined;
481
+ return this.innerApiCalls
482
+ .createBucket(request, options, wrappedCallback)
483
+ ?.then(([response, options, rawResponse]) => {
484
+ this._log.info('createBucket response %j', response);
485
+ return [response, options, rawResponse];
486
+ })
487
+ .catch((error) => {
488
+ if (error &&
489
+ 'statusDetails' in error &&
490
+ error.statusDetails instanceof Array) {
491
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
492
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
493
+ }
494
+ throw error;
495
+ });
496
+ }
497
+ lockBucketRetentionPolicy(request, optionsOrCallback, callback) {
498
+ request = request || {};
499
+ let options;
500
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
501
+ callback = optionsOrCallback;
502
+ options = {};
503
+ }
504
+ else {
505
+ options = optionsOrCallback;
506
+ }
507
+ options = options || {};
508
+ options.otherArgs = options.otherArgs || {};
509
+ options.otherArgs.headers = options.otherArgs.headers || {};
510
+ const routingParameter = {};
511
+ {
512
+ const fieldValue = request.bucket;
513
+ if (fieldValue !== undefined && fieldValue !== null) {
514
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
515
+ if (match) {
516
+ const parameterValue = match.groups?.['bucket'] ?? fieldValue;
517
+ Object.assign(routingParameter, { bucket: parameterValue });
518
+ }
519
+ }
520
+ }
521
+ options.otherArgs.headers['x-goog-request-params'] =
522
+ this._gaxModule.routingHeader.fromParams(routingParameter);
523
+ this.initialize().catch(err => {
524
+ throw err;
525
+ });
526
+ this._log.info('lockBucketRetentionPolicy request %j', request);
527
+ const wrappedCallback = callback
528
+ ? (error, response, options, rawResponse) => {
529
+ this._log.info('lockBucketRetentionPolicy response %j', response);
530
+ callback(error, response, options, rawResponse); // We verified callback above.
531
+ }
532
+ : undefined;
533
+ return this.innerApiCalls
534
+ .lockBucketRetentionPolicy(request, options, wrappedCallback)
535
+ ?.then(([response, options, rawResponse]) => {
536
+ this._log.info('lockBucketRetentionPolicy response %j', response);
537
+ return [response, options, rawResponse];
538
+ })
539
+ .catch((error) => {
540
+ if (error &&
541
+ 'statusDetails' in error &&
542
+ error.statusDetails instanceof Array) {
543
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
544
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
545
+ }
546
+ throw error;
547
+ });
548
+ }
549
+ updateBucket(request, optionsOrCallback, callback) {
550
+ request = request || {};
551
+ let options;
552
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
553
+ callback = optionsOrCallback;
554
+ options = {};
555
+ }
556
+ else {
557
+ options = optionsOrCallback;
558
+ }
559
+ options = options || {};
560
+ options.otherArgs = options.otherArgs || {};
561
+ options.otherArgs.headers = options.otherArgs.headers || {};
562
+ const routingParameter = {};
563
+ {
564
+ const fieldValue = request.bucket?.name;
565
+ if (fieldValue !== undefined && fieldValue !== null) {
566
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
567
+ if (match) {
568
+ const parameterValue = match.groups?.['bucket'] ?? fieldValue;
569
+ Object.assign(routingParameter, { bucket: parameterValue });
570
+ }
571
+ }
572
+ }
573
+ options.otherArgs.headers['x-goog-request-params'] =
574
+ this._gaxModule.routingHeader.fromParams(routingParameter);
575
+ this.initialize().catch(err => {
576
+ throw err;
577
+ });
578
+ this._log.info('updateBucket request %j', request);
579
+ const wrappedCallback = callback
580
+ ? (error, response, options, rawResponse) => {
581
+ this._log.info('updateBucket response %j', response);
582
+ callback(error, response, options, rawResponse); // We verified callback above.
583
+ }
584
+ : undefined;
585
+ return this.innerApiCalls
586
+ .updateBucket(request, options, wrappedCallback)
587
+ ?.then(([response, options, rawResponse]) => {
588
+ this._log.info('updateBucket response %j', response);
589
+ return [response, options, rawResponse];
590
+ })
591
+ .catch((error) => {
592
+ if (error &&
593
+ 'statusDetails' in error &&
594
+ error.statusDetails instanceof Array) {
595
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
596
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
597
+ }
598
+ throw error;
599
+ });
600
+ }
601
+ listBuckets(request, optionsOrCallback, callback) {
602
+ request = request || {};
603
+ let options;
604
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
605
+ callback = optionsOrCallback;
606
+ options = {};
607
+ }
608
+ else {
609
+ options = optionsOrCallback;
610
+ }
611
+ options = options || {};
612
+ options.otherArgs = options.otherArgs || {};
613
+ options.otherArgs.headers = options.otherArgs.headers || {};
614
+ const routingParameter = {};
615
+ {
616
+ const fieldValue = request.parent;
617
+ if (fieldValue !== undefined && fieldValue !== null) {
618
+ const match = fieldValue
619
+ .toString()
620
+ .match(RegExp('(?<project>(?:.*)?)'));
621
+ if (match) {
622
+ const parameterValue = match.groups?.['project'] ?? fieldValue;
623
+ Object.assign(routingParameter, { project: parameterValue });
624
+ }
625
+ }
626
+ }
627
+ options.otherArgs.headers['x-goog-request-params'] =
628
+ this._gaxModule.routingHeader.fromParams(routingParameter);
629
+ this.initialize().catch(err => {
630
+ throw err;
631
+ });
632
+ const wrappedCallback = callback
633
+ ? (error, values, nextPageRequest, rawResponse) => {
634
+ this._log.info('listBuckets values %j', values);
635
+ callback(error, values, nextPageRequest, rawResponse); // We verified callback above.
636
+ }
637
+ : undefined;
638
+ this._log.info('listBuckets request %j', request);
639
+ return this.innerApiCalls
640
+ .listBuckets(request, options, wrappedCallback)
641
+ ?.then(([response, input, output]) => {
642
+ this._log.info('listBuckets values %j', response);
643
+ return [response, input, output];
644
+ });
645
+ }
646
+ /**
647
+ * Equivalent to `listBuckets`, but returns a NodeJS Stream object.
648
+ * @param {Object} request
649
+ * The request object that will be sent.
650
+ * @param {string} request.parent
651
+ * Required. The project whose buckets we are listing.
652
+ * @param {number} [request.pageSize]
653
+ * Optional. Maximum number of buckets to return in a single response. The
654
+ * service uses this parameter or `1,000` items, whichever is smaller. If
655
+ * `acl` is present in the `read_mask`, the service uses this parameter of
656
+ * `200` items, whichever is smaller.
657
+ * @param {string} [request.pageToken]
658
+ * Optional. A previously-returned page token representing part of the larger
659
+ * set of results to view.
660
+ * @param {string} [request.prefix]
661
+ * Optional. Filter results to buckets whose names begin with this prefix.
662
+ * @param {google.protobuf.FieldMask} request.readMask
663
+ * Mask specifying which fields to read from each result.
664
+ * If no mask is specified, it defaults to all fields except `items.
665
+ * owner`, `items.acl`, and `items.default_object_acl`.
666
+ * `*` might be used to mean "all fields".
667
+ * @param {boolean} [request.returnPartialSuccess]
668
+ * Optional. Allows listing of buckets, even if there are buckets that are
669
+ * unreachable.
670
+ * @param {object} [options]
671
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
672
+ * @returns {Stream}
673
+ * An object stream which emits an object representing {@link protos.google.storage.v2.Bucket|Bucket} on 'data' event.
674
+ * The client library will perform auto-pagination by default: it will call the API as many
675
+ * times as needed. Note that it can affect your quota.
676
+ * We recommend using `listBucketsAsync()`
677
+ * method described below for async iteration which you can stop as needed.
678
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
679
+ * for more details and examples.
680
+ */
681
+ listBucketsStream(request, options) {
682
+ request = request || {};
683
+ options = options || {};
684
+ options.otherArgs = options.otherArgs || {};
685
+ options.otherArgs.headers = options.otherArgs.headers || {};
686
+ const routingParameter = {};
687
+ {
688
+ const fieldValue = request.parent;
689
+ if (fieldValue !== undefined && fieldValue !== null) {
690
+ const match = fieldValue
691
+ .toString()
692
+ .match(RegExp('(?<project>(?:.*)?)'));
693
+ if (match) {
694
+ const parameterValue = match.groups?.['project'] ?? fieldValue;
695
+ Object.assign(routingParameter, { project: parameterValue });
696
+ }
697
+ }
698
+ }
699
+ options.otherArgs.headers['x-goog-request-params'] =
700
+ this._gaxModule.routingHeader.fromParams(routingParameter);
701
+ const defaultCallSettings = this._defaults['listBuckets'];
702
+ const callSettings = defaultCallSettings.merge(options);
703
+ this.initialize().catch(err => {
704
+ throw err;
705
+ });
706
+ this._log.info('listBuckets stream %j', request);
707
+ return this.descriptors.page.listBuckets.createStream(this.innerApiCalls.listBuckets, request, callSettings);
708
+ }
709
+ /**
710
+ * Equivalent to `listBuckets`, but returns an iterable object.
711
+ *
712
+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
713
+ * @param {Object} request
714
+ * The request object that will be sent.
715
+ * @param {string} request.parent
716
+ * Required. The project whose buckets we are listing.
717
+ * @param {number} [request.pageSize]
718
+ * Optional. Maximum number of buckets to return in a single response. The
719
+ * service uses this parameter or `1,000` items, whichever is smaller. If
720
+ * `acl` is present in the `read_mask`, the service uses this parameter of
721
+ * `200` items, whichever is smaller.
722
+ * @param {string} [request.pageToken]
723
+ * Optional. A previously-returned page token representing part of the larger
724
+ * set of results to view.
725
+ * @param {string} [request.prefix]
726
+ * Optional. Filter results to buckets whose names begin with this prefix.
727
+ * @param {google.protobuf.FieldMask} request.readMask
728
+ * Mask specifying which fields to read from each result.
729
+ * If no mask is specified, it defaults to all fields except `items.
730
+ * owner`, `items.acl`, and `items.default_object_acl`.
731
+ * `*` might be used to mean "all fields".
732
+ * @param {boolean} [request.returnPartialSuccess]
733
+ * Optional. Allows listing of buckets, even if there are buckets that are
734
+ * unreachable.
735
+ * @param {object} [options]
736
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
737
+ * @returns {Object}
738
+ * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }.
739
+ * When you iterate the returned iterable, each element will be an object representing
740
+ * {@link protos.google.storage.v2.Bucket|Bucket}. The API will be called under the hood as needed, once per the page,
741
+ * so you can stop the iteration when you don't need more results.
742
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
743
+ * for more details and examples.
744
+ * @example <caption>include:samples/generated/v2/storage.list_buckets.js</caption>
745
+ * region_tag:storage_v2_generated_Storage_ListBuckets_async
746
+ */
747
+ listBucketsAsync(request, options) {
748
+ request = request || {};
749
+ options = options || {};
750
+ options.otherArgs = options.otherArgs || {};
751
+ options.otherArgs.headers = options.otherArgs.headers || {};
752
+ const routingParameter = {};
753
+ {
754
+ const fieldValue = request.parent;
755
+ if (fieldValue !== undefined && fieldValue !== null) {
756
+ const match = fieldValue
757
+ .toString()
758
+ .match(RegExp('(?<project>(?:.*)?)'));
759
+ if (match) {
760
+ const parameterValue = match.groups?.['project'] ?? fieldValue;
761
+ Object.assign(routingParameter, { project: parameterValue });
762
+ }
763
+ }
764
+ }
765
+ options.otherArgs.headers['x-goog-request-params'] =
766
+ this._gaxModule.routingHeader.fromParams(routingParameter);
767
+ const defaultCallSettings = this._defaults['listBuckets'];
768
+ const callSettings = defaultCallSettings.merge(options);
769
+ this.initialize().catch(err => {
770
+ throw err;
771
+ });
772
+ this._log.info('listBuckets iterate %j', request);
773
+ return this.descriptors.page.listBuckets.asyncIterate(this.innerApiCalls['listBuckets'], request, callSettings);
774
+ }
775
+ // --------------------
776
+ // -- Path templates --
777
+ // --------------------
778
+ /**
779
+ * Return a fully-qualified bucket resource name string.
780
+ *
781
+ * @param {string} project
782
+ * @param {string} bucket
783
+ * @returns {string} Resource name string.
784
+ */
785
+ bucketPath(project, bucket) {
786
+ return this.pathTemplates.bucketPathTemplate.render({
787
+ project: project,
788
+ bucket: bucket,
789
+ });
790
+ }
791
+ /**
792
+ * Parse the project from Bucket resource.
793
+ *
794
+ * @param {string} bucketName
795
+ * A fully-qualified path representing Bucket resource.
796
+ * @returns {string} A string representing the project.
797
+ */
798
+ matchProjectFromBucketName(bucketName) {
799
+ return this.pathTemplates.bucketPathTemplate.match(bucketName).project;
800
+ }
801
+ /**
802
+ * Parse the bucket from Bucket resource.
803
+ *
804
+ * @param {string} bucketName
805
+ * A fully-qualified path representing Bucket resource.
806
+ * @returns {string} A string representing the bucket.
807
+ */
808
+ matchBucketFromBucketName(bucketName) {
809
+ return this.pathTemplates.bucketPathTemplate.match(bucketName).bucket;
810
+ }
811
+ /**
812
+ * Return a fully-qualified cryptoKey resource name string.
813
+ *
814
+ * @param {string} project
815
+ * @param {string} location
816
+ * @param {string} key_ring
817
+ * @param {string} crypto_key
818
+ * @returns {string} Resource name string.
819
+ */
820
+ cryptoKeyPath(project, location, keyRing, cryptoKey) {
821
+ return this.pathTemplates.cryptoKeyPathTemplate.render({
822
+ project: project,
823
+ location: location,
824
+ key_ring: keyRing,
825
+ crypto_key: cryptoKey,
826
+ });
827
+ }
828
+ /**
829
+ * Parse the project from CryptoKey resource.
830
+ *
831
+ * @param {string} cryptoKeyName
832
+ * A fully-qualified path representing CryptoKey resource.
833
+ * @returns {string} A string representing the project.
834
+ */
835
+ matchProjectFromCryptoKeyName(cryptoKeyName) {
836
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
837
+ .project;
838
+ }
839
+ /**
840
+ * Parse the location from CryptoKey resource.
841
+ *
842
+ * @param {string} cryptoKeyName
843
+ * A fully-qualified path representing CryptoKey resource.
844
+ * @returns {string} A string representing the location.
845
+ */
846
+ matchLocationFromCryptoKeyName(cryptoKeyName) {
847
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
848
+ .location;
849
+ }
850
+ /**
851
+ * Parse the key_ring from CryptoKey resource.
852
+ *
853
+ * @param {string} cryptoKeyName
854
+ * A fully-qualified path representing CryptoKey resource.
855
+ * @returns {string} A string representing the key_ring.
856
+ */
857
+ matchKeyRingFromCryptoKeyName(cryptoKeyName) {
858
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
859
+ .key_ring;
860
+ }
861
+ /**
862
+ * Parse the crypto_key from CryptoKey resource.
863
+ *
864
+ * @param {string} cryptoKeyName
865
+ * A fully-qualified path representing CryptoKey resource.
866
+ * @returns {string} A string representing the crypto_key.
867
+ */
868
+ matchCryptoKeyFromCryptoKeyName(cryptoKeyName) {
869
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
870
+ .crypto_key;
871
+ }
872
+ /**
873
+ * Return a fully-qualified project resource name string.
874
+ *
875
+ * @param {string} project
876
+ * @returns {string} Resource name string.
877
+ */
878
+ projectPath(project) {
879
+ return this.pathTemplates.projectPathTemplate.render({
880
+ project: project,
881
+ });
882
+ }
883
+ /**
884
+ * Parse the project from Project resource.
885
+ *
886
+ * @param {string} projectName
887
+ * A fully-qualified path representing Project resource.
888
+ * @returns {string} A string representing the project.
889
+ */
890
+ matchProjectFromProjectName(projectName) {
891
+ return this.pathTemplates.projectPathTemplate.match(projectName).project;
892
+ }
893
+ /**
894
+ * Terminate the gRPC channel and close the client.
895
+ *
896
+ * The client will no longer be usable and all future behavior is undefined.
897
+ * @returns {Promise} A promise that resolves when the client is closed.
898
+ */
899
+ close() {
900
+ if (this.storageStub && !this._terminated) {
901
+ return this.storageStub.then(stub => {
902
+ this._log.info('ending gRPC channel');
903
+ this._terminated = true;
904
+ stub.close();
905
+ });
906
+ }
907
+ return Promise.resolve();
908
+ }
909
+ }
910
+ exports.StorageClient = StorageClient;
911
+ //# sourceMappingURL=storage_client.js.map