@google-cloud/storage-control 0.1.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.
@@ -0,0 +1,946 @@
1
+ "use strict";
2
+ // Copyright 2024 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.StorageControlClient = void 0;
21
+ /* global window */
22
+ const gax = require("google-gax");
23
+ const jsonProtos = require("../../protos/protos.json");
24
+ /**
25
+ * Client JSON configuration object, loaded from
26
+ * `src/v2/storage_control_client_config.json`.
27
+ * This file defines retry strategy and timeouts for all API methods in this library.
28
+ */
29
+ const gapicConfig = require("./storage_control_client_config.json");
30
+ const version = require('../../../package.json').version;
31
+ /**
32
+ * StorageControl service includes selected control plane operations.
33
+ * @class
34
+ * @memberof v2
35
+ */
36
+ class StorageControlClient {
37
+ /**
38
+ * Construct an instance of StorageControlClient.
39
+ *
40
+ * @param {object} [options] - The configuration object.
41
+ * The options accepted by the constructor are described in detail
42
+ * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
43
+ * The common options are:
44
+ * @param {object} [options.credentials] - Credentials object.
45
+ * @param {string} [options.credentials.client_email]
46
+ * @param {string} [options.credentials.private_key]
47
+ * @param {string} [options.email] - Account email address. Required when
48
+ * using a .pem or .p12 keyFilename.
49
+ * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
50
+ * .p12 key downloaded from the Google Developers Console. If you provide
51
+ * a path to a JSON file, the projectId option below is not necessary.
52
+ * NOTE: .pem and .p12 require you to specify options.email as well.
53
+ * @param {number} [options.port] - The port on which to connect to
54
+ * the remote host.
55
+ * @param {string} [options.projectId] - The project ID from the Google
56
+ * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
57
+ * the environment variable GCLOUD_PROJECT for your project ID. If your
58
+ * app is running in an environment which supports
59
+ * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
60
+ * your project ID will be detected automatically.
61
+ * @param {string} [options.apiEndpoint] - The domain name of the
62
+ * API remote host.
63
+ * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
64
+ * Follows the structure of {@link gapicConfig}.
65
+ * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
66
+ * For more information, please check the
67
+ * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
68
+ * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
69
+ * need to avoid loading the default gRPC version and want to use the fallback
70
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
71
+ * ```
72
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
73
+ * const client = new StorageControlClient({fallback: true}, gax);
74
+ * ```
75
+ */
76
+ constructor(opts, gaxInstance) {
77
+ var _a, _b, _c, _d;
78
+ this._terminated = false;
79
+ this.descriptors = {
80
+ page: {},
81
+ stream: {},
82
+ longrunning: {},
83
+ batching: {},
84
+ };
85
+ // Ensure that options include all the required fields.
86
+ const staticMembers = this.constructor;
87
+ if ((opts === null || opts === void 0 ? void 0 : opts.universe_domain) &&
88
+ (opts === null || opts === void 0 ? void 0 : opts.universeDomain) &&
89
+ (opts === null || opts === void 0 ? void 0 : opts.universe_domain) !== (opts === null || opts === void 0 ? void 0 : opts.universeDomain)) {
90
+ throw new Error('Please set either universe_domain or universeDomain, but not both.');
91
+ }
92
+ this._universeDomain =
93
+ (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.universeDomain) !== null && _a !== void 0 ? _a : opts === null || opts === void 0 ? void 0 : opts.universe_domain) !== null && _b !== void 0 ? _b : 'googleapis.com';
94
+ this._servicePath = 'storage.' + this._universeDomain;
95
+ const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || this._servicePath;
96
+ this._providedCustomServicePath = !!((opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint));
97
+ const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port;
98
+ const clientConfig = (_c = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _c !== void 0 ? _c : {};
99
+ const fallback = (_d = opts === null || opts === void 0 ? void 0 : opts.fallback) !== null && _d !== void 0 ? _d : (typeof window !== 'undefined' && typeof (window === null || window === void 0 ? void 0 : window.fetch) === 'function');
100
+ opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
101
+ // Request numeric enum values if REST transport is used.
102
+ opts.numericEnums = true;
103
+ // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
104
+ if (servicePath !== this._servicePath && !('scopes' in opts)) {
105
+ opts['scopes'] = staticMembers.scopes;
106
+ }
107
+ // Load google-gax module synchronously if needed
108
+ if (!gaxInstance) {
109
+ gaxInstance = require('google-gax');
110
+ }
111
+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
112
+ this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
113
+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
114
+ this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
115
+ // Save options to use in initialize() method.
116
+ this._opts = opts;
117
+ // Save the auth object to the client, for use by other methods.
118
+ this.auth = this._gaxGrpc.auth;
119
+ // Set useJWTAccessWithScope on the auth object.
120
+ this.auth.useJWTAccessWithScope = true;
121
+ // Set defaultServicePath on the auth object.
122
+ this.auth.defaultServicePath = this._servicePath;
123
+ // Set the default scopes in auth client if needed.
124
+ if (servicePath === this._servicePath) {
125
+ this.auth.defaultScopes = staticMembers.scopes;
126
+ }
127
+ // Determine the client header string.
128
+ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
129
+ if (typeof process !== 'undefined' && 'versions' in process) {
130
+ clientHeader.push(`gl-node/${process.versions.node}`);
131
+ }
132
+ else {
133
+ clientHeader.push(`gl-web/${this._gaxModule.version}`);
134
+ }
135
+ if (!opts.fallback) {
136
+ clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
137
+ }
138
+ else {
139
+ clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
140
+ }
141
+ if (opts.libName && opts.libVersion) {
142
+ clientHeader.push(`${opts.libName}/${opts.libVersion}`);
143
+ }
144
+ // Load the applicable protos.
145
+ this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
146
+ // This API contains "path templates"; forward-slash-separated
147
+ // identifiers to uniquely identify resources within the API.
148
+ // Create useful helper objects for these.
149
+ this.pathTemplates = {
150
+ bucketPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/buckets/{bucket}'),
151
+ folderPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/buckets/{bucket}/folders/{folder=**}'),
152
+ projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
153
+ storageLayoutPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/buckets/{bucket}/storageLayout'),
154
+ };
155
+ // Some of the methods on this service return "paged" results,
156
+ // (e.g. 50 results at a time, with tokens to get subsequent
157
+ // pages). Denote the keys used for pagination and results.
158
+ this.descriptors.page = {
159
+ listFolders: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'folders'),
160
+ };
161
+ const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
162
+ // This API contains "long-running operations", which return a
163
+ // an Operation object that allows for tracking of the operation,
164
+ // rather than holding a request open.
165
+ const lroOptions = {
166
+ auth: this.auth,
167
+ grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
168
+ };
169
+ if (opts.fallback) {
170
+ lroOptions.protoJson = protoFilesRoot;
171
+ lroOptions.httpRules = [];
172
+ }
173
+ this.operationsClient = this._gaxModule
174
+ .lro(lroOptions)
175
+ .operationsClient(opts);
176
+ const renameFolderResponse = protoFilesRoot.lookup('.google.storage.control.v2.Folder');
177
+ const renameFolderMetadata = protoFilesRoot.lookup('.google.storage.control.v2.RenameFolderMetadata');
178
+ this.descriptors.longrunning = {
179
+ renameFolder: new this._gaxModule.LongrunningDescriptor(this.operationsClient, renameFolderResponse.decode.bind(renameFolderResponse), renameFolderMetadata.decode.bind(renameFolderMetadata)),
180
+ };
181
+ // Put together the default options sent with requests.
182
+ this._defaults = this._gaxGrpc.constructSettings('google.storage.control.v2.StorageControl', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
183
+ // Set up a dictionary of "inner API calls"; the core implementation
184
+ // of calling the API is handled in `google-gax`, with this code
185
+ // merely providing the destination and request information.
186
+ this.innerApiCalls = {};
187
+ // Add a warn function to the client constructor so it can be easily tested.
188
+ this.warn = this._gaxModule.warn;
189
+ }
190
+ /**
191
+ * Initialize the client.
192
+ * Performs asynchronous operations (such as authentication) and prepares the client.
193
+ * This function will be called automatically when any class method is called for the
194
+ * first time, but if you need to initialize it before calling an actual method,
195
+ * feel free to call initialize() directly.
196
+ *
197
+ * You can await on this method if you want to make sure the client is initialized.
198
+ *
199
+ * @returns {Promise} A promise that resolves to an authenticated service stub.
200
+ */
201
+ initialize() {
202
+ // If the client stub promise is already initialized, return immediately.
203
+ if (this.storageControlStub) {
204
+ return this.storageControlStub;
205
+ }
206
+ // Put together the "service stub" for
207
+ // google.storage.control.v2.StorageControl.
208
+ this.storageControlStub = this._gaxGrpc.createStub(this._opts.fallback
209
+ ? this._protos.lookupService('google.storage.control.v2.StorageControl')
210
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
211
+ this._protos.google.storage.control.v2.StorageControl, this._opts, this._providedCustomServicePath);
212
+ // Iterate over each of the methods that the service provides
213
+ // and create an API call method for each.
214
+ const storageControlStubMethods = [
215
+ 'createFolder',
216
+ 'deleteFolder',
217
+ 'getFolder',
218
+ 'listFolders',
219
+ 'renameFolder',
220
+ 'getStorageLayout',
221
+ ];
222
+ for (const methodName of storageControlStubMethods) {
223
+ const callPromise = this.storageControlStub.then(stub => (...args) => {
224
+ if (this._terminated) {
225
+ return Promise.reject('The client has already been closed.');
226
+ }
227
+ const func = stub[methodName];
228
+ return func.apply(stub, args);
229
+ }, (err) => () => {
230
+ throw err;
231
+ });
232
+ const descriptor = this.descriptors.page[methodName] ||
233
+ this.descriptors.longrunning[methodName] ||
234
+ undefined;
235
+ const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
236
+ this.innerApiCalls[methodName] = apiCall;
237
+ }
238
+ return this.storageControlStub;
239
+ }
240
+ /**
241
+ * The DNS address for this API service.
242
+ * @deprecated Use the apiEndpoint method of the client instance.
243
+ * @returns {string} The DNS address for this service.
244
+ */
245
+ static get servicePath() {
246
+ if (typeof process !== undefined &&
247
+ typeof process.emitWarning === 'function') {
248
+ process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
249
+ }
250
+ return 'storage.googleapis.com';
251
+ }
252
+ /**
253
+ * The DNS address for this API service - same as servicePath.
254
+ * @deprecated Use the apiEndpoint method of the client instance.
255
+ * @returns {string} The DNS address for this service.
256
+ */
257
+ static get apiEndpoint() {
258
+ if (typeof process !== undefined &&
259
+ typeof process.emitWarning === 'function') {
260
+ process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
261
+ }
262
+ return 'storage.googleapis.com';
263
+ }
264
+ /**
265
+ * The DNS address for this API service.
266
+ * @returns {string} The DNS address for this service.
267
+ */
268
+ get apiEndpoint() {
269
+ return this._servicePath;
270
+ }
271
+ get universeDomain() {
272
+ return this._universeDomain;
273
+ }
274
+ /**
275
+ * The port for this API service.
276
+ * @returns {number} The default port for this service.
277
+ */
278
+ static get port() {
279
+ return 443;
280
+ }
281
+ /**
282
+ * The scopes needed to make gRPC calls for every method defined
283
+ * in this service.
284
+ * @returns {string[]} List of default scopes.
285
+ */
286
+ static get scopes() {
287
+ return [
288
+ 'https://www.googleapis.com/auth/cloud-platform',
289
+ 'https://www.googleapis.com/auth/cloud-platform.read-only',
290
+ 'https://www.googleapis.com/auth/devstorage.full_control',
291
+ 'https://www.googleapis.com/auth/devstorage.read_only',
292
+ 'https://www.googleapis.com/auth/devstorage.read_write',
293
+ ];
294
+ }
295
+ /**
296
+ * Return the project ID used by this class.
297
+ * @returns {Promise} A promise that resolves to string containing the project ID.
298
+ */
299
+ getProjectId(callback) {
300
+ if (callback) {
301
+ this.auth.getProjectId(callback);
302
+ return;
303
+ }
304
+ return this.auth.getProjectId();
305
+ }
306
+ createFolder(request, optionsOrCallback, callback) {
307
+ var _a, _b;
308
+ request = request || {};
309
+ if (!request.requestId) {
310
+ request.requestId = gax.makeUUID();
311
+ }
312
+ let options;
313
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
314
+ callback = optionsOrCallback;
315
+ options = {};
316
+ }
317
+ else {
318
+ options = optionsOrCallback;
319
+ }
320
+ options = options || {};
321
+ options.otherArgs = options.otherArgs || {};
322
+ options.otherArgs.headers = options.otherArgs.headers || {};
323
+ const routingParameter = {};
324
+ {
325
+ const fieldValue = request.parent;
326
+ if (fieldValue !== undefined && fieldValue !== null) {
327
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
328
+ if (match) {
329
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
330
+ Object.assign(routingParameter, { bucket: parameterValue });
331
+ }
332
+ }
333
+ }
334
+ options.otherArgs.headers['x-goog-request-params'] =
335
+ this._gaxModule.routingHeader.fromParams(routingParameter);
336
+ this.initialize();
337
+ return this.innerApiCalls.createFolder(request, options, callback);
338
+ }
339
+ deleteFolder(request, optionsOrCallback, callback) {
340
+ var _a, _b;
341
+ request = request || {};
342
+ if (!request.requestId) {
343
+ request.requestId = gax.makeUUID();
344
+ }
345
+ let options;
346
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
347
+ callback = optionsOrCallback;
348
+ options = {};
349
+ }
350
+ else {
351
+ options = optionsOrCallback;
352
+ }
353
+ options = options || {};
354
+ options.otherArgs = options.otherArgs || {};
355
+ options.otherArgs.headers = options.otherArgs.headers || {};
356
+ const routingParameter = {};
357
+ {
358
+ const fieldValue = request.name;
359
+ if (fieldValue !== undefined && fieldValue !== null) {
360
+ const match = fieldValue
361
+ .toString()
362
+ .match(RegExp('(?<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?'));
363
+ if (match) {
364
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
365
+ Object.assign(routingParameter, { bucket: parameterValue });
366
+ }
367
+ }
368
+ }
369
+ options.otherArgs.headers['x-goog-request-params'] =
370
+ this._gaxModule.routingHeader.fromParams(routingParameter);
371
+ this.initialize();
372
+ return this.innerApiCalls.deleteFolder(request, options, callback);
373
+ }
374
+ getFolder(request, optionsOrCallback, callback) {
375
+ var _a, _b;
376
+ request = request || {};
377
+ if (!request.requestId) {
378
+ request.requestId = gax.makeUUID();
379
+ }
380
+ let options;
381
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
382
+ callback = optionsOrCallback;
383
+ options = {};
384
+ }
385
+ else {
386
+ options = optionsOrCallback;
387
+ }
388
+ options = options || {};
389
+ options.otherArgs = options.otherArgs || {};
390
+ options.otherArgs.headers = options.otherArgs.headers || {};
391
+ const routingParameter = {};
392
+ {
393
+ const fieldValue = request.name;
394
+ if (fieldValue !== undefined && fieldValue !== null) {
395
+ const match = fieldValue
396
+ .toString()
397
+ .match(RegExp('(?<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?'));
398
+ if (match) {
399
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
400
+ Object.assign(routingParameter, { bucket: parameterValue });
401
+ }
402
+ }
403
+ }
404
+ options.otherArgs.headers['x-goog-request-params'] =
405
+ this._gaxModule.routingHeader.fromParams(routingParameter);
406
+ this.initialize();
407
+ return this.innerApiCalls.getFolder(request, options, callback);
408
+ }
409
+ getStorageLayout(request, optionsOrCallback, callback) {
410
+ var _a, _b;
411
+ request = request || {};
412
+ if (!request.requestId) {
413
+ request.requestId = gax.makeUUID();
414
+ }
415
+ let options;
416
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
417
+ callback = optionsOrCallback;
418
+ options = {};
419
+ }
420
+ else {
421
+ options = optionsOrCallback;
422
+ }
423
+ options = options || {};
424
+ options.otherArgs = options.otherArgs || {};
425
+ options.otherArgs.headers = options.otherArgs.headers || {};
426
+ const routingParameter = {};
427
+ {
428
+ const fieldValue = request.name;
429
+ if (fieldValue !== undefined && fieldValue !== null) {
430
+ const match = fieldValue
431
+ .toString()
432
+ .match(RegExp('(?<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?'));
433
+ if (match) {
434
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
435
+ Object.assign(routingParameter, { bucket: parameterValue });
436
+ }
437
+ }
438
+ }
439
+ options.otherArgs.headers['x-goog-request-params'] =
440
+ this._gaxModule.routingHeader.fromParams(routingParameter);
441
+ this.initialize();
442
+ return this.innerApiCalls.getStorageLayout(request, options, callback);
443
+ }
444
+ renameFolder(request, optionsOrCallback, callback) {
445
+ var _a, _b;
446
+ request = request || {};
447
+ if (!request.requestId) {
448
+ request.requestId = gax.makeUUID();
449
+ }
450
+ let options;
451
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
452
+ callback = optionsOrCallback;
453
+ options = {};
454
+ }
455
+ else {
456
+ options = optionsOrCallback;
457
+ }
458
+ options = options || {};
459
+ options.otherArgs = options.otherArgs || {};
460
+ options.otherArgs.headers = options.otherArgs.headers || {};
461
+ const routingParameter = {};
462
+ {
463
+ const fieldValue = request.name;
464
+ if (fieldValue !== undefined && fieldValue !== null) {
465
+ const match = fieldValue
466
+ .toString()
467
+ .match(RegExp('(?<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?'));
468
+ if (match) {
469
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
470
+ Object.assign(routingParameter, { bucket: parameterValue });
471
+ }
472
+ }
473
+ }
474
+ options.otherArgs.headers['x-goog-request-params'] =
475
+ this._gaxModule.routingHeader.fromParams(routingParameter);
476
+ this.initialize();
477
+ return this.innerApiCalls.renameFolder(request, options, callback);
478
+ }
479
+ /**
480
+ * Check the status of the long running operation returned by `renameFolder()`.
481
+ * @param {String} name
482
+ * The operation name that will be passed.
483
+ * @returns {Promise} - The promise which resolves to an object.
484
+ * The decoded operation object has result and metadata field to get information from.
485
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation }
486
+ * for more details and examples.
487
+ * @example <caption>include:samples/generated/v2/storage_control.rename_folder.js</caption>
488
+ * region_tag:storage_v2_generated_StorageControl_RenameFolder_async
489
+ */
490
+ async checkRenameFolderProgress(name) {
491
+ const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({ name });
492
+ const [operation] = await this.operationsClient.getOperation(request);
493
+ const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.renameFolder, this._gaxModule.createDefaultBackoffSettings());
494
+ return decodeOperation;
495
+ }
496
+ listFolders(request, optionsOrCallback, callback) {
497
+ var _a, _b;
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.parent;
513
+ if (fieldValue !== undefined && fieldValue !== null) {
514
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
515
+ if (match) {
516
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : 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();
524
+ return this.innerApiCalls.listFolders(request, options, callback);
525
+ }
526
+ /**
527
+ * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
528
+ * @param {Object} request
529
+ * The request object that will be sent.
530
+ * @param {string} request.parent
531
+ * Required. Name of the bucket in which to look for folders.
532
+ * @param {number} [request.pageSize]
533
+ * Optional. Maximum number of folders to return in a single response. The
534
+ * service will use this parameter or 1,000 items, whichever is smaller.
535
+ * @param {string} [request.pageToken]
536
+ * Optional. A previously-returned page token representing part of the larger
537
+ * set of results to view.
538
+ * @param {string} [request.prefix]
539
+ * Optional. Filter results to folders whose names begin with this prefix.
540
+ * If set, the value must either be an empty string or end with a '/'.
541
+ * @param {string} [request.delimiter]
542
+ * Optional. If set, returns results in a directory-like mode. The results
543
+ * will only include folders that either exactly match the above prefix, or
544
+ * are one level below the prefix. The only supported value is '/'.
545
+ * @param {string} [request.lexicographicStart]
546
+ * Optional. Filter results to folders whose names are lexicographically equal
547
+ * to or after lexicographic_start. If lexicographic_end is also set, the
548
+ * folders listed have names between lexicographic_start (inclusive) and
549
+ * lexicographic_end (exclusive).
550
+ * @param {string} [request.lexicographicEnd]
551
+ * Optional. Filter results to folders whose names are lexicographically
552
+ * before lexicographic_end. If lexicographic_start is also set, the folders
553
+ * listed have names between lexicographic_start (inclusive) and
554
+ * lexicographic_end (exclusive).
555
+ * @param {string} [request.requestId]
556
+ * Optional. A unique identifier for this request. UUID is the recommended
557
+ * format, but other formats are still accepted.
558
+ * @param {object} [options]
559
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
560
+ * @returns {Stream}
561
+ * An object stream which emits an object representing {@link protos.google.storage.control.v2.Folder|Folder} on 'data' event.
562
+ * The client library will perform auto-pagination by default: it will call the API as many
563
+ * times as needed. Note that it can affect your quota.
564
+ * We recommend using `listFoldersAsync()`
565
+ * method described below for async iteration which you can stop as needed.
566
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
567
+ * for more details and examples.
568
+ */
569
+ listFoldersStream(request, options) {
570
+ var _a, _b;
571
+ request = request || {};
572
+ options = options || {};
573
+ options.otherArgs = options.otherArgs || {};
574
+ options.otherArgs.headers = options.otherArgs.headers || {};
575
+ const routingParameter = {};
576
+ {
577
+ const fieldValue = request.parent;
578
+ if (fieldValue !== undefined && fieldValue !== null) {
579
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
580
+ if (match) {
581
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
582
+ Object.assign(routingParameter, { bucket: parameterValue });
583
+ }
584
+ }
585
+ }
586
+ options.otherArgs.headers['x-goog-request-params'] =
587
+ this._gaxModule.routingHeader.fromParams(routingParameter);
588
+ const defaultCallSettings = this._defaults['listFolders'];
589
+ const callSettings = defaultCallSettings.merge(options);
590
+ this.initialize();
591
+ return this.descriptors.page.listFolders.createStream(this.innerApiCalls.listFolders, request, callSettings);
592
+ }
593
+ /**
594
+ * Equivalent to `listFolders`, but returns an iterable object.
595
+ *
596
+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
597
+ * @param {Object} request
598
+ * The request object that will be sent.
599
+ * @param {string} request.parent
600
+ * Required. Name of the bucket in which to look for folders.
601
+ * @param {number} [request.pageSize]
602
+ * Optional. Maximum number of folders to return in a single response. The
603
+ * service will use this parameter or 1,000 items, whichever is smaller.
604
+ * @param {string} [request.pageToken]
605
+ * Optional. A previously-returned page token representing part of the larger
606
+ * set of results to view.
607
+ * @param {string} [request.prefix]
608
+ * Optional. Filter results to folders whose names begin with this prefix.
609
+ * If set, the value must either be an empty string or end with a '/'.
610
+ * @param {string} [request.delimiter]
611
+ * Optional. If set, returns results in a directory-like mode. The results
612
+ * will only include folders that either exactly match the above prefix, or
613
+ * are one level below the prefix. The only supported value is '/'.
614
+ * @param {string} [request.lexicographicStart]
615
+ * Optional. Filter results to folders whose names are lexicographically equal
616
+ * to or after lexicographic_start. If lexicographic_end is also set, the
617
+ * folders listed have names between lexicographic_start (inclusive) and
618
+ * lexicographic_end (exclusive).
619
+ * @param {string} [request.lexicographicEnd]
620
+ * Optional. Filter results to folders whose names are lexicographically
621
+ * before lexicographic_end. If lexicographic_start is also set, the folders
622
+ * listed have names between lexicographic_start (inclusive) and
623
+ * lexicographic_end (exclusive).
624
+ * @param {string} [request.requestId]
625
+ * Optional. A unique identifier for this request. UUID is the recommended
626
+ * format, but other formats are still accepted.
627
+ * @param {object} [options]
628
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
629
+ * @returns {Object}
630
+ * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }.
631
+ * When you iterate the returned iterable, each element will be an object representing
632
+ * {@link protos.google.storage.control.v2.Folder|Folder}. The API will be called under the hood as needed, once per the page,
633
+ * so you can stop the iteration when you don't need more results.
634
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
635
+ * for more details and examples.
636
+ * @example <caption>include:samples/generated/v2/storage_control.list_folders.js</caption>
637
+ * region_tag:storage_v2_generated_StorageControl_ListFolders_async
638
+ */
639
+ listFoldersAsync(request, options) {
640
+ var _a, _b;
641
+ request = request || {};
642
+ options = options || {};
643
+ options.otherArgs = options.otherArgs || {};
644
+ options.otherArgs.headers = options.otherArgs.headers || {};
645
+ const routingParameter = {};
646
+ {
647
+ const fieldValue = request.parent;
648
+ if (fieldValue !== undefined && fieldValue !== null) {
649
+ const match = fieldValue.toString().match(RegExp('(?<bucket>(?:.*)?)'));
650
+ if (match) {
651
+ const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['bucket']) !== null && _b !== void 0 ? _b : fieldValue;
652
+ Object.assign(routingParameter, { bucket: parameterValue });
653
+ }
654
+ }
655
+ }
656
+ options.otherArgs.headers['x-goog-request-params'] =
657
+ this._gaxModule.routingHeader.fromParams(routingParameter);
658
+ const defaultCallSettings = this._defaults['listFolders'];
659
+ const callSettings = defaultCallSettings.merge(options);
660
+ this.initialize();
661
+ return this.descriptors.page.listFolders.asyncIterate(this.innerApiCalls['listFolders'], request, callSettings);
662
+ }
663
+ /**
664
+ * Gets the latest state of a long-running operation. Clients can use this
665
+ * method to poll the operation result at intervals as recommended by the API
666
+ * service.
667
+ *
668
+ * @param {Object} request - The request object that will be sent.
669
+ * @param {string} request.name - The name of the operation resource.
670
+ * @param {Object=} options
671
+ * Optional parameters. You can override the default settings for this call,
672
+ * e.g, timeout, retries, paginations, etc. See {@link
673
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions}
674
+ * for the details.
675
+ * @param {function(?Error, ?Object)=} callback
676
+ * The function which will be called with the result of the API call.
677
+ *
678
+ * The second parameter to the callback is an object representing
679
+ * {@link google.longrunning.Operation | google.longrunning.Operation}.
680
+ * @return {Promise} - The promise which resolves to an array.
681
+ * The first element of the array is an object representing
682
+ * {@link google.longrunning.Operation | google.longrunning.Operation}.
683
+ * The promise has a method named "cancel" which cancels the ongoing API call.
684
+ *
685
+ * @example
686
+ * ```
687
+ * const client = longrunning.operationsClient();
688
+ * const name = '';
689
+ * const [response] = await client.getOperation({name});
690
+ * // doThingsWith(response)
691
+ * ```
692
+ */
693
+ getOperation(request, options, callback) {
694
+ return this.operationsClient.getOperation(request, options, callback);
695
+ }
696
+ /**
697
+ * Lists operations that match the specified filter in the request. If the
698
+ * server doesn't support this method, it returns `UNIMPLEMENTED`. Returns an iterable object.
699
+ *
700
+ * For-await-of syntax is used with the iterable to recursively get response element on-demand.
701
+ *
702
+ * @param {Object} request - The request object that will be sent.
703
+ * @param {string} request.name - The name of the operation collection.
704
+ * @param {string} request.filter - The standard list filter.
705
+ * @param {number=} request.pageSize -
706
+ * The maximum number of resources contained in the underlying API
707
+ * response. If page streaming is performed per-resource, this
708
+ * parameter does not affect the return value. If page streaming is
709
+ * performed per-page, this determines the maximum number of
710
+ * resources in a page.
711
+ * @param {Object=} options
712
+ * Optional parameters. You can override the default settings for this call,
713
+ * e.g, timeout, retries, paginations, etc. See {@link
714
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the
715
+ * details.
716
+ * @returns {Object}
717
+ * An iterable Object that conforms to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | iteration protocols}.
718
+ *
719
+ * @example
720
+ * ```
721
+ * const client = longrunning.operationsClient();
722
+ * for await (const response of client.listOperationsAsync(request));
723
+ * // doThingsWith(response)
724
+ * ```
725
+ */
726
+ listOperationsAsync(request, options) {
727
+ return this.operationsClient.listOperationsAsync(request, options);
728
+ }
729
+ /**
730
+ * Starts asynchronous cancellation on a long-running operation. The server
731
+ * makes a best effort to cancel the operation, but success is not
732
+ * guaranteed. If the server doesn't support this method, it returns
733
+ * `google.rpc.Code.UNIMPLEMENTED`. Clients can use
734
+ * {@link Operations.GetOperation} or
735
+ * other methods to check whether the cancellation succeeded or whether the
736
+ * operation completed despite cancellation. On successful cancellation,
737
+ * the operation is not deleted; instead, it becomes an operation with
738
+ * an {@link Operation.error} value with a {@link google.rpc.Status.code} of
739
+ * 1, corresponding to `Code.CANCELLED`.
740
+ *
741
+ * @param {Object} request - The request object that will be sent.
742
+ * @param {string} request.name - The name of the operation resource to be cancelled.
743
+ * @param {Object=} options
744
+ * Optional parameters. You can override the default settings for this call,
745
+ * e.g, timeout, retries, paginations, etc. See {@link
746
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the
747
+ * details.
748
+ * @param {function(?Error)=} callback
749
+ * The function which will be called with the result of the API call.
750
+ * @return {Promise} - The promise which resolves when API call finishes.
751
+ * The promise has a method named "cancel" which cancels the ongoing API
752
+ * call.
753
+ *
754
+ * @example
755
+ * ```
756
+ * const client = longrunning.operationsClient();
757
+ * await client.cancelOperation({name: ''});
758
+ * ```
759
+ */
760
+ cancelOperation(request, options, callback) {
761
+ return this.operationsClient.cancelOperation(request, options, callback);
762
+ }
763
+ /**
764
+ * Deletes a long-running operation. This method indicates that the client is
765
+ * no longer interested in the operation result. It does not cancel the
766
+ * operation. If the server doesn't support this method, it returns
767
+ * `google.rpc.Code.UNIMPLEMENTED`.
768
+ *
769
+ * @param {Object} request - The request object that will be sent.
770
+ * @param {string} request.name - The name of the operation resource to be deleted.
771
+ * @param {Object=} options
772
+ * Optional parameters. You can override the default settings for this call,
773
+ * e.g, timeout, retries, paginations, etc. See {@link
774
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions}
775
+ * for the details.
776
+ * @param {function(?Error)=} callback
777
+ * The function which will be called with the result of the API call.
778
+ * @return {Promise} - The promise which resolves when API call finishes.
779
+ * The promise has a method named "cancel" which cancels the ongoing API
780
+ * call.
781
+ *
782
+ * @example
783
+ * ```
784
+ * const client = longrunning.operationsClient();
785
+ * await client.deleteOperation({name: ''});
786
+ * ```
787
+ */
788
+ deleteOperation(request, options, callback) {
789
+ return this.operationsClient.deleteOperation(request, options, callback);
790
+ }
791
+ // --------------------
792
+ // -- Path templates --
793
+ // --------------------
794
+ /**
795
+ * Return a fully-qualified bucket resource name string.
796
+ *
797
+ * @param {string} project
798
+ * @param {string} bucket
799
+ * @returns {string} Resource name string.
800
+ */
801
+ bucketPath(project, bucket) {
802
+ return this.pathTemplates.bucketPathTemplate.render({
803
+ project: project,
804
+ bucket: bucket,
805
+ });
806
+ }
807
+ /**
808
+ * Parse the project from Bucket resource.
809
+ *
810
+ * @param {string} bucketName
811
+ * A fully-qualified path representing Bucket resource.
812
+ * @returns {string} A string representing the project.
813
+ */
814
+ matchProjectFromBucketName(bucketName) {
815
+ return this.pathTemplates.bucketPathTemplate.match(bucketName).project;
816
+ }
817
+ /**
818
+ * Parse the bucket from Bucket resource.
819
+ *
820
+ * @param {string} bucketName
821
+ * A fully-qualified path representing Bucket resource.
822
+ * @returns {string} A string representing the bucket.
823
+ */
824
+ matchBucketFromBucketName(bucketName) {
825
+ return this.pathTemplates.bucketPathTemplate.match(bucketName).bucket;
826
+ }
827
+ /**
828
+ * Return a fully-qualified folder resource name string.
829
+ *
830
+ * @param {string} project
831
+ * @param {string} bucket
832
+ * @param {string} folder
833
+ * @returns {string} Resource name string.
834
+ */
835
+ folderPath(project, bucket, folder) {
836
+ return this.pathTemplates.folderPathTemplate.render({
837
+ project: project,
838
+ bucket: bucket,
839
+ folder: folder,
840
+ });
841
+ }
842
+ /**
843
+ * Parse the project from Folder resource.
844
+ *
845
+ * @param {string} folderName
846
+ * A fully-qualified path representing Folder resource.
847
+ * @returns {string} A string representing the project.
848
+ */
849
+ matchProjectFromFolderName(folderName) {
850
+ return this.pathTemplates.folderPathTemplate.match(folderName).project;
851
+ }
852
+ /**
853
+ * Parse the bucket from Folder resource.
854
+ *
855
+ * @param {string} folderName
856
+ * A fully-qualified path representing Folder resource.
857
+ * @returns {string} A string representing the bucket.
858
+ */
859
+ matchBucketFromFolderName(folderName) {
860
+ return this.pathTemplates.folderPathTemplate.match(folderName).bucket;
861
+ }
862
+ /**
863
+ * Parse the folder from Folder resource.
864
+ *
865
+ * @param {string} folderName
866
+ * A fully-qualified path representing Folder resource.
867
+ * @returns {string} A string representing the folder.
868
+ */
869
+ matchFolderFromFolderName(folderName) {
870
+ return this.pathTemplates.folderPathTemplate.match(folderName).folder;
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
+ * Return a fully-qualified storageLayout resource name string.
895
+ *
896
+ * @param {string} project
897
+ * @param {string} bucket
898
+ * @returns {string} Resource name string.
899
+ */
900
+ storageLayoutPath(project, bucket) {
901
+ return this.pathTemplates.storageLayoutPathTemplate.render({
902
+ project: project,
903
+ bucket: bucket,
904
+ });
905
+ }
906
+ /**
907
+ * Parse the project from StorageLayout resource.
908
+ *
909
+ * @param {string} storageLayoutName
910
+ * A fully-qualified path representing StorageLayout resource.
911
+ * @returns {string} A string representing the project.
912
+ */
913
+ matchProjectFromStorageLayoutName(storageLayoutName) {
914
+ return this.pathTemplates.storageLayoutPathTemplate.match(storageLayoutName)
915
+ .project;
916
+ }
917
+ /**
918
+ * Parse the bucket from StorageLayout resource.
919
+ *
920
+ * @param {string} storageLayoutName
921
+ * A fully-qualified path representing StorageLayout resource.
922
+ * @returns {string} A string representing the bucket.
923
+ */
924
+ matchBucketFromStorageLayoutName(storageLayoutName) {
925
+ return this.pathTemplates.storageLayoutPathTemplate.match(storageLayoutName)
926
+ .bucket;
927
+ }
928
+ /**
929
+ * Terminate the gRPC channel and close the client.
930
+ *
931
+ * The client will no longer be usable and all future behavior is undefined.
932
+ * @returns {Promise} A promise that resolves when the client is closed.
933
+ */
934
+ close() {
935
+ if (this.storageControlStub && !this._terminated) {
936
+ return this.storageControlStub.then(stub => {
937
+ this._terminated = true;
938
+ stub.close();
939
+ this.operationsClient.close();
940
+ });
941
+ }
942
+ return Promise.resolve();
943
+ }
944
+ }
945
+ exports.StorageControlClient = StorageControlClient;
946
+ //# sourceMappingURL=storage_control_client.js.map