@google-cloud/pubsub-api 0.2.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,1491 @@
1
+ "use strict";
2
+ // Copyright 2026 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.SubscriberClient = void 0;
21
+ const stream_1 = require("stream");
22
+ const jsonProtos = require("../../protos/protos.json");
23
+ const google_gax_1 = require("google-gax");
24
+ /**
25
+ * Client JSON configuration object, loaded from
26
+ * `src/v1/subscriber_client_config.json`.
27
+ * This file defines retry strategy and timeouts for all API methods in this library.
28
+ */
29
+ const gapicConfig = require("./subscriber_client_config.json");
30
+ const version = require('../../../package.json').version;
31
+ /**
32
+ * The service that an application uses to manipulate subscriptions and to
33
+ * consume messages from a subscription via the `Pull` method or by
34
+ * establishing a bi-directional stream using the `StreamingPull` method.
35
+ * @class
36
+ * @memberof v1
37
+ */
38
+ class SubscriberClient {
39
+ _terminated = false;
40
+ _opts;
41
+ _providedCustomServicePath;
42
+ _gaxModule;
43
+ _gaxGrpc;
44
+ _protos;
45
+ _defaults;
46
+ _universeDomain;
47
+ _servicePath;
48
+ _log = google_gax_1.loggingUtils.log('pubsub-api');
49
+ auth;
50
+ descriptors = {
51
+ page: {},
52
+ stream: {},
53
+ longrunning: {},
54
+ batching: {},
55
+ };
56
+ warn;
57
+ innerApiCalls;
58
+ iamClient;
59
+ pathTemplates;
60
+ subscriberStub;
61
+ /**
62
+ * Construct an instance of SubscriberClient.
63
+ *
64
+ * @param {object} [options] - The configuration object.
65
+ * The options accepted by the constructor are described in detail
66
+ * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
67
+ * The common options are:
68
+ * @param {object} [options.credentials] - Credentials object.
69
+ * @param {string} [options.credentials.client_email]
70
+ * @param {string} [options.credentials.private_key]
71
+ * @param {string} [options.email] - Account email address. Required when
72
+ * using a .pem or .p12 keyFilename.
73
+ * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
74
+ * .p12 key downloaded from the Google Developers Console. If you provide
75
+ * a path to a JSON file, the projectId option below is not necessary.
76
+ * NOTE: .pem and .p12 require you to specify options.email as well.
77
+ * @param {number} [options.port] - The port on which to connect to
78
+ * the remote host.
79
+ * @param {string} [options.projectId] - The project ID from the Google
80
+ * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
81
+ * the environment variable GCLOUD_PROJECT for your project ID. If your
82
+ * app is running in an environment which supports
83
+ * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials},
84
+ * your project ID will be detected automatically.
85
+ * @param {string} [options.apiEndpoint] - The domain name of the
86
+ * API remote host.
87
+ * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
88
+ * Follows the structure of {@link gapicConfig}.
89
+ * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
90
+ * For more information, please check the
91
+ * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
92
+ * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
93
+ * need to avoid loading the default gRPC version and want to use the fallback
94
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
95
+ * ```
96
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
97
+ * const client = new SubscriberClient({fallback: true}, gax);
98
+ * ```
99
+ */
100
+ constructor(opts, gaxInstance) {
101
+ // Ensure that options include all the required fields.
102
+ const staticMembers = this.constructor;
103
+ if (opts?.universe_domain &&
104
+ opts?.universeDomain &&
105
+ opts?.universe_domain !== opts?.universeDomain) {
106
+ throw new Error('Please set either universe_domain or universeDomain, but not both.');
107
+ }
108
+ const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object'
109
+ ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
110
+ : undefined;
111
+ this._universeDomain =
112
+ opts?.universeDomain ??
113
+ opts?.universe_domain ??
114
+ universeDomainEnvVar ??
115
+ 'googleapis.com';
116
+ this._servicePath = 'pubsub.' + this._universeDomain;
117
+ const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath;
118
+ this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint);
119
+ const port = opts?.port || staticMembers.port;
120
+ const clientConfig = opts?.clientConfig ?? {};
121
+ const fallback = opts?.fallback ??
122
+ (typeof window !== 'undefined' && typeof window?.fetch === 'function');
123
+ opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
124
+ // Request numeric enum values if REST transport is used.
125
+ opts.numericEnums = true;
126
+ // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
127
+ if (servicePath !== this._servicePath && !('scopes' in opts)) {
128
+ opts['scopes'] = staticMembers.scopes;
129
+ }
130
+ // Load google-gax module synchronously if needed
131
+ if (!gaxInstance) {
132
+ gaxInstance = require('google-gax');
133
+ }
134
+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
135
+ this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
136
+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
137
+ this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
138
+ // Save options to use in initialize() method.
139
+ this._opts = opts;
140
+ // Save the auth object to the client, for use by other methods.
141
+ this.auth = this._gaxGrpc.auth;
142
+ // Set useJWTAccessWithScope on the auth object.
143
+ this.auth.useJWTAccessWithScope = true;
144
+ // Set defaultServicePath on the auth object.
145
+ this.auth.defaultServicePath = this._servicePath;
146
+ // Set the default scopes in auth client if needed.
147
+ if (servicePath === this._servicePath) {
148
+ this.auth.defaultScopes = staticMembers.scopes;
149
+ }
150
+ this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts);
151
+ // Determine the client header string.
152
+ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
153
+ if (typeof process === 'object' && 'versions' in process) {
154
+ clientHeader.push(`gl-node/${process.versions.node}`);
155
+ }
156
+ else {
157
+ clientHeader.push(`gl-web/${this._gaxModule.version}`);
158
+ }
159
+ if (!opts.fallback) {
160
+ clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
161
+ }
162
+ else {
163
+ clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
164
+ }
165
+ if (opts.libName && opts.libVersion) {
166
+ clientHeader.push(`${opts.libName}/${opts.libVersion}`);
167
+ }
168
+ // Load the applicable protos.
169
+ this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
170
+ // This API contains "path templates"; forward-slash-separated
171
+ // identifiers to uniquely identify resources within the API.
172
+ // Create useful helper objects for these.
173
+ this.pathTemplates = {
174
+ cryptoKeyPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}'),
175
+ projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
176
+ projectTopicsPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/topics/{topic}'),
177
+ schemaPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/schemas/{schema}'),
178
+ snapshotPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/snapshots/{snapshot}'),
179
+ subscriptionPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/subscriptions/{subscription}'),
180
+ };
181
+ // Some of the methods on this service return "paged" results,
182
+ // (e.g. 50 results at a time, with tokens to get subsequent
183
+ // pages). Denote the keys used for pagination and results.
184
+ this.descriptors.page = {
185
+ listSubscriptions: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'),
186
+ listSnapshots: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots'),
187
+ };
188
+ // Some of the methods on this service provide streaming responses.
189
+ // Provide descriptors for these.
190
+ this.descriptors.stream = {
191
+ streamingPull: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
192
+ };
193
+ // Put together the default options sent with requests.
194
+ this._defaults = this._gaxGrpc.constructSettings('google.pubsub.v1.Subscriber', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
195
+ // Set up a dictionary of "inner API calls"; the core implementation
196
+ // of calling the API is handled in `google-gax`, with this code
197
+ // merely providing the destination and request information.
198
+ this.innerApiCalls = {};
199
+ // Add a warn function to the client constructor so it can be easily tested.
200
+ this.warn = this._gaxModule.warn;
201
+ }
202
+ /**
203
+ * Initialize the client.
204
+ * Performs asynchronous operations (such as authentication) and prepares the client.
205
+ * This function will be called automatically when any class method is called for the
206
+ * first time, but if you need to initialize it before calling an actual method,
207
+ * feel free to call initialize() directly.
208
+ *
209
+ * You can await on this method if you want to make sure the client is initialized.
210
+ *
211
+ * @returns {Promise} A promise that resolves to an authenticated service stub.
212
+ */
213
+ initialize() {
214
+ // If the client stub promise is already initialized, return immediately.
215
+ if (this.subscriberStub) {
216
+ return this.subscriberStub;
217
+ }
218
+ // Put together the "service stub" for
219
+ // google.pubsub.v1.Subscriber.
220
+ this.subscriberStub = this._gaxGrpc.createStub(this._opts.fallback
221
+ ? this._protos.lookupService('google.pubsub.v1.Subscriber')
222
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
+ this._protos.google.pubsub.v1.Subscriber, this._opts, this._providedCustomServicePath);
224
+ // Iterate over each of the methods that the service provides
225
+ // and create an API call method for each.
226
+ const subscriberStubMethods = [
227
+ 'createSubscription',
228
+ 'getSubscription',
229
+ 'updateSubscription',
230
+ 'listSubscriptions',
231
+ 'deleteSubscription',
232
+ 'modifyAckDeadline',
233
+ 'acknowledge',
234
+ 'pull',
235
+ 'streamingPull',
236
+ 'modifyPushConfig',
237
+ 'getSnapshot',
238
+ 'listSnapshots',
239
+ 'createSnapshot',
240
+ 'updateSnapshot',
241
+ 'deleteSnapshot',
242
+ 'seek',
243
+ ];
244
+ for (const methodName of subscriberStubMethods) {
245
+ const callPromise = this.subscriberStub.then((stub) => (...args) => {
246
+ if (this._terminated) {
247
+ if (methodName in this.descriptors.stream) {
248
+ const stream = new stream_1.PassThrough({ objectMode: true });
249
+ setImmediate(() => {
250
+ stream.emit('error', new this._gaxModule.GoogleError('The client has already been closed.'));
251
+ });
252
+ return stream;
253
+ }
254
+ return Promise.reject('The client has already been closed.');
255
+ }
256
+ const func = stub[methodName];
257
+ return func.apply(stub, args);
258
+ }, (err) => () => {
259
+ throw err;
260
+ });
261
+ const descriptor = this.descriptors.page[methodName] ||
262
+ this.descriptors.stream[methodName] ||
263
+ undefined;
264
+ const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
265
+ this.innerApiCalls[methodName] = apiCall;
266
+ }
267
+ return this.subscriberStub;
268
+ }
269
+ /**
270
+ * The DNS address for this API service.
271
+ * @deprecated Use the apiEndpoint method of the client instance.
272
+ * @returns {string} The DNS address for this service.
273
+ */
274
+ static get servicePath() {
275
+ if (typeof process === 'object' &&
276
+ typeof process.emitWarning === 'function') {
277
+ process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
278
+ }
279
+ return 'pubsub.googleapis.com';
280
+ }
281
+ /**
282
+ * The DNS address for this API service - same as servicePath.
283
+ * @deprecated Use the apiEndpoint method of the client instance.
284
+ * @returns {string} The DNS address for this service.
285
+ */
286
+ static get apiEndpoint() {
287
+ if (typeof process === 'object' &&
288
+ typeof process.emitWarning === 'function') {
289
+ process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
290
+ }
291
+ return 'pubsub.googleapis.com';
292
+ }
293
+ /**
294
+ * The DNS address for this API service.
295
+ * @returns {string} The DNS address for this service.
296
+ */
297
+ get apiEndpoint() {
298
+ return this._servicePath;
299
+ }
300
+ get universeDomain() {
301
+ return this._universeDomain;
302
+ }
303
+ /**
304
+ * The port for this API service.
305
+ * @returns {number} The default port for this service.
306
+ */
307
+ static get port() {
308
+ return 443;
309
+ }
310
+ /**
311
+ * The scopes needed to make gRPC calls for every method defined
312
+ * in this service.
313
+ * @returns {string[]} List of default scopes.
314
+ */
315
+ static get scopes() {
316
+ return [
317
+ 'https://www.googleapis.com/auth/cloud-platform',
318
+ 'https://www.googleapis.com/auth/pubsub',
319
+ ];
320
+ }
321
+ /**
322
+ * Return the project ID used by this class.
323
+ * @returns {Promise} A promise that resolves to string containing the project ID.
324
+ */
325
+ getProjectId(callback) {
326
+ if (callback) {
327
+ this.auth.getProjectId(callback);
328
+ return;
329
+ }
330
+ return this.auth.getProjectId();
331
+ }
332
+ createSubscription(request, optionsOrCallback, callback) {
333
+ request = request || {};
334
+ let options;
335
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
336
+ callback = optionsOrCallback;
337
+ options = {};
338
+ }
339
+ else {
340
+ options = optionsOrCallback;
341
+ }
342
+ options = options || {};
343
+ options.otherArgs = options.otherArgs || {};
344
+ options.otherArgs.headers = options.otherArgs.headers || {};
345
+ options.otherArgs.headers['x-goog-request-params'] =
346
+ this._gaxModule.routingHeader.fromParams({
347
+ name: request.name ?? '',
348
+ });
349
+ this.initialize().catch((err) => {
350
+ throw err;
351
+ });
352
+ this._log.info('createSubscription request %j', request);
353
+ const wrappedCallback = callback
354
+ ? (error, response, options, rawResponse) => {
355
+ this._log.info('createSubscription response %j', response);
356
+ callback(error, response, options, rawResponse); // We verified callback above.
357
+ }
358
+ : undefined;
359
+ return this.innerApiCalls
360
+ .createSubscription(request, options, wrappedCallback)
361
+ ?.then(([response, options, rawResponse]) => {
362
+ this._log.info('createSubscription response %j', response);
363
+ return [response, options, rawResponse];
364
+ })
365
+ .catch((error) => {
366
+ if (error &&
367
+ 'statusDetails' in error &&
368
+ error.statusDetails instanceof Array) {
369
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
370
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
371
+ }
372
+ throw error;
373
+ });
374
+ }
375
+ getSubscription(request, optionsOrCallback, callback) {
376
+ request = request || {};
377
+ let options;
378
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
379
+ callback = optionsOrCallback;
380
+ options = {};
381
+ }
382
+ else {
383
+ options = optionsOrCallback;
384
+ }
385
+ options = options || {};
386
+ options.otherArgs = options.otherArgs || {};
387
+ options.otherArgs.headers = options.otherArgs.headers || {};
388
+ options.otherArgs.headers['x-goog-request-params'] =
389
+ this._gaxModule.routingHeader.fromParams({
390
+ subscription: request.subscription ?? '',
391
+ });
392
+ this.initialize().catch((err) => {
393
+ throw err;
394
+ });
395
+ this._log.info('getSubscription request %j', request);
396
+ const wrappedCallback = callback
397
+ ? (error, response, options, rawResponse) => {
398
+ this._log.info('getSubscription response %j', response);
399
+ callback(error, response, options, rawResponse); // We verified callback above.
400
+ }
401
+ : undefined;
402
+ return this.innerApiCalls
403
+ .getSubscription(request, options, wrappedCallback)
404
+ ?.then(([response, options, rawResponse]) => {
405
+ this._log.info('getSubscription response %j', response);
406
+ return [response, options, rawResponse];
407
+ })
408
+ .catch((error) => {
409
+ if (error &&
410
+ 'statusDetails' in error &&
411
+ error.statusDetails instanceof Array) {
412
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
413
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
414
+ }
415
+ throw error;
416
+ });
417
+ }
418
+ updateSubscription(request, optionsOrCallback, callback) {
419
+ request = request || {};
420
+ let options;
421
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
422
+ callback = optionsOrCallback;
423
+ options = {};
424
+ }
425
+ else {
426
+ options = optionsOrCallback;
427
+ }
428
+ options = options || {};
429
+ options.otherArgs = options.otherArgs || {};
430
+ options.otherArgs.headers = options.otherArgs.headers || {};
431
+ options.otherArgs.headers['x-goog-request-params'] =
432
+ this._gaxModule.routingHeader.fromParams({
433
+ 'subscription.name': request.subscription.name ?? '',
434
+ });
435
+ this.initialize().catch((err) => {
436
+ throw err;
437
+ });
438
+ this._log.info('updateSubscription request %j', request);
439
+ const wrappedCallback = callback
440
+ ? (error, response, options, rawResponse) => {
441
+ this._log.info('updateSubscription response %j', response);
442
+ callback(error, response, options, rawResponse); // We verified callback above.
443
+ }
444
+ : undefined;
445
+ return this.innerApiCalls
446
+ .updateSubscription(request, options, wrappedCallback)
447
+ ?.then(([response, options, rawResponse]) => {
448
+ this._log.info('updateSubscription response %j', response);
449
+ return [response, options, rawResponse];
450
+ })
451
+ .catch((error) => {
452
+ if (error &&
453
+ 'statusDetails' in error &&
454
+ error.statusDetails instanceof Array) {
455
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
456
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
457
+ }
458
+ throw error;
459
+ });
460
+ }
461
+ deleteSubscription(request, optionsOrCallback, callback) {
462
+ request = request || {};
463
+ let options;
464
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
465
+ callback = optionsOrCallback;
466
+ options = {};
467
+ }
468
+ else {
469
+ options = optionsOrCallback;
470
+ }
471
+ options = options || {};
472
+ options.otherArgs = options.otherArgs || {};
473
+ options.otherArgs.headers = options.otherArgs.headers || {};
474
+ options.otherArgs.headers['x-goog-request-params'] =
475
+ this._gaxModule.routingHeader.fromParams({
476
+ subscription: request.subscription ?? '',
477
+ });
478
+ this.initialize().catch((err) => {
479
+ throw err;
480
+ });
481
+ this._log.info('deleteSubscription request %j', request);
482
+ const wrappedCallback = callback
483
+ ? (error, response, options, rawResponse) => {
484
+ this._log.info('deleteSubscription response %j', response);
485
+ callback(error, response, options, rawResponse); // We verified callback above.
486
+ }
487
+ : undefined;
488
+ return this.innerApiCalls
489
+ .deleteSubscription(request, options, wrappedCallback)
490
+ ?.then(([response, options, rawResponse]) => {
491
+ this._log.info('deleteSubscription response %j', response);
492
+ return [response, options, rawResponse];
493
+ })
494
+ .catch((error) => {
495
+ if (error &&
496
+ 'statusDetails' in error &&
497
+ error.statusDetails instanceof Array) {
498
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
499
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
500
+ }
501
+ throw error;
502
+ });
503
+ }
504
+ modifyAckDeadline(request, optionsOrCallback, callback) {
505
+ request = request || {};
506
+ let options;
507
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
508
+ callback = optionsOrCallback;
509
+ options = {};
510
+ }
511
+ else {
512
+ options = optionsOrCallback;
513
+ }
514
+ options = options || {};
515
+ options.otherArgs = options.otherArgs || {};
516
+ options.otherArgs.headers = options.otherArgs.headers || {};
517
+ options.otherArgs.headers['x-goog-request-params'] =
518
+ this._gaxModule.routingHeader.fromParams({
519
+ subscription: request.subscription ?? '',
520
+ });
521
+ this.initialize().catch((err) => {
522
+ throw err;
523
+ });
524
+ this._log.info('modifyAckDeadline request %j', request);
525
+ const wrappedCallback = callback
526
+ ? (error, response, options, rawResponse) => {
527
+ this._log.info('modifyAckDeadline response %j', response);
528
+ callback(error, response, options, rawResponse); // We verified callback above.
529
+ }
530
+ : undefined;
531
+ return this.innerApiCalls
532
+ .modifyAckDeadline(request, options, wrappedCallback)
533
+ ?.then(([response, options, rawResponse]) => {
534
+ this._log.info('modifyAckDeadline response %j', response);
535
+ return [response, options, rawResponse];
536
+ })
537
+ .catch((error) => {
538
+ if (error &&
539
+ 'statusDetails' in error &&
540
+ error.statusDetails instanceof Array) {
541
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
542
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
543
+ }
544
+ throw error;
545
+ });
546
+ }
547
+ acknowledge(request, optionsOrCallback, callback) {
548
+ request = request || {};
549
+ let options;
550
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
551
+ callback = optionsOrCallback;
552
+ options = {};
553
+ }
554
+ else {
555
+ options = optionsOrCallback;
556
+ }
557
+ options = options || {};
558
+ options.otherArgs = options.otherArgs || {};
559
+ options.otherArgs.headers = options.otherArgs.headers || {};
560
+ options.otherArgs.headers['x-goog-request-params'] =
561
+ this._gaxModule.routingHeader.fromParams({
562
+ subscription: request.subscription ?? '',
563
+ });
564
+ this.initialize().catch((err) => {
565
+ throw err;
566
+ });
567
+ this._log.info('acknowledge request %j', request);
568
+ const wrappedCallback = callback
569
+ ? (error, response, options, rawResponse) => {
570
+ this._log.info('acknowledge response %j', response);
571
+ callback(error, response, options, rawResponse); // We verified callback above.
572
+ }
573
+ : undefined;
574
+ return this.innerApiCalls
575
+ .acknowledge(request, options, wrappedCallback)
576
+ ?.then(([response, options, rawResponse]) => {
577
+ this._log.info('acknowledge response %j', response);
578
+ return [response, options, rawResponse];
579
+ })
580
+ .catch((error) => {
581
+ if (error &&
582
+ 'statusDetails' in error &&
583
+ error.statusDetails instanceof Array) {
584
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
585
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
586
+ }
587
+ throw error;
588
+ });
589
+ }
590
+ pull(request, optionsOrCallback, callback) {
591
+ request = request || {};
592
+ let options;
593
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
594
+ callback = optionsOrCallback;
595
+ options = {};
596
+ }
597
+ else {
598
+ options = optionsOrCallback;
599
+ }
600
+ options = options || {};
601
+ options.otherArgs = options.otherArgs || {};
602
+ options.otherArgs.headers = options.otherArgs.headers || {};
603
+ options.otherArgs.headers['x-goog-request-params'] =
604
+ this._gaxModule.routingHeader.fromParams({
605
+ subscription: request.subscription ?? '',
606
+ });
607
+ this.initialize().catch((err) => {
608
+ throw err;
609
+ });
610
+ this._log.info('pull request %j', request);
611
+ const wrappedCallback = callback
612
+ ? (error, response, options, rawResponse) => {
613
+ this._log.info('pull response %j', response);
614
+ callback(error, response, options, rawResponse); // We verified callback above.
615
+ }
616
+ : undefined;
617
+ return this.innerApiCalls
618
+ .pull(request, options, wrappedCallback)
619
+ ?.then(([response, options, rawResponse]) => {
620
+ this._log.info('pull response %j', response);
621
+ return [response, options, rawResponse];
622
+ })
623
+ .catch((error) => {
624
+ if (error &&
625
+ 'statusDetails' in error &&
626
+ error.statusDetails instanceof Array) {
627
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
628
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
629
+ }
630
+ throw error;
631
+ });
632
+ }
633
+ modifyPushConfig(request, optionsOrCallback, callback) {
634
+ request = request || {};
635
+ let options;
636
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
637
+ callback = optionsOrCallback;
638
+ options = {};
639
+ }
640
+ else {
641
+ options = optionsOrCallback;
642
+ }
643
+ options = options || {};
644
+ options.otherArgs = options.otherArgs || {};
645
+ options.otherArgs.headers = options.otherArgs.headers || {};
646
+ options.otherArgs.headers['x-goog-request-params'] =
647
+ this._gaxModule.routingHeader.fromParams({
648
+ subscription: request.subscription ?? '',
649
+ });
650
+ this.initialize().catch((err) => {
651
+ throw err;
652
+ });
653
+ this._log.info('modifyPushConfig request %j', request);
654
+ const wrappedCallback = callback
655
+ ? (error, response, options, rawResponse) => {
656
+ this._log.info('modifyPushConfig response %j', response);
657
+ callback(error, response, options, rawResponse); // We verified callback above.
658
+ }
659
+ : undefined;
660
+ return this.innerApiCalls
661
+ .modifyPushConfig(request, options, wrappedCallback)
662
+ ?.then(([response, options, rawResponse]) => {
663
+ this._log.info('modifyPushConfig response %j', response);
664
+ return [response, options, rawResponse];
665
+ })
666
+ .catch((error) => {
667
+ if (error &&
668
+ 'statusDetails' in error &&
669
+ error.statusDetails instanceof Array) {
670
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
671
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
672
+ }
673
+ throw error;
674
+ });
675
+ }
676
+ getSnapshot(request, optionsOrCallback, callback) {
677
+ request = request || {};
678
+ let options;
679
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
680
+ callback = optionsOrCallback;
681
+ options = {};
682
+ }
683
+ else {
684
+ options = optionsOrCallback;
685
+ }
686
+ options = options || {};
687
+ options.otherArgs = options.otherArgs || {};
688
+ options.otherArgs.headers = options.otherArgs.headers || {};
689
+ options.otherArgs.headers['x-goog-request-params'] =
690
+ this._gaxModule.routingHeader.fromParams({
691
+ snapshot: request.snapshot ?? '',
692
+ });
693
+ this.initialize().catch((err) => {
694
+ throw err;
695
+ });
696
+ this._log.info('getSnapshot request %j', request);
697
+ const wrappedCallback = callback
698
+ ? (error, response, options, rawResponse) => {
699
+ this._log.info('getSnapshot response %j', response);
700
+ callback(error, response, options, rawResponse); // We verified callback above.
701
+ }
702
+ : undefined;
703
+ return this.innerApiCalls
704
+ .getSnapshot(request, options, wrappedCallback)
705
+ ?.then(([response, options, rawResponse]) => {
706
+ this._log.info('getSnapshot response %j', response);
707
+ return [response, options, rawResponse];
708
+ })
709
+ .catch((error) => {
710
+ if (error &&
711
+ 'statusDetails' in error &&
712
+ error.statusDetails instanceof Array) {
713
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
714
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
715
+ }
716
+ throw error;
717
+ });
718
+ }
719
+ createSnapshot(request, optionsOrCallback, callback) {
720
+ request = request || {};
721
+ let options;
722
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
723
+ callback = optionsOrCallback;
724
+ options = {};
725
+ }
726
+ else {
727
+ options = optionsOrCallback;
728
+ }
729
+ options = options || {};
730
+ options.otherArgs = options.otherArgs || {};
731
+ options.otherArgs.headers = options.otherArgs.headers || {};
732
+ options.otherArgs.headers['x-goog-request-params'] =
733
+ this._gaxModule.routingHeader.fromParams({
734
+ name: request.name ?? '',
735
+ });
736
+ this.initialize().catch((err) => {
737
+ throw err;
738
+ });
739
+ this._log.info('createSnapshot request %j', request);
740
+ const wrappedCallback = callback
741
+ ? (error, response, options, rawResponse) => {
742
+ this._log.info('createSnapshot response %j', response);
743
+ callback(error, response, options, rawResponse); // We verified callback above.
744
+ }
745
+ : undefined;
746
+ return this.innerApiCalls
747
+ .createSnapshot(request, options, wrappedCallback)
748
+ ?.then(([response, options, rawResponse]) => {
749
+ this._log.info('createSnapshot response %j', response);
750
+ return [response, options, rawResponse];
751
+ })
752
+ .catch((error) => {
753
+ if (error &&
754
+ 'statusDetails' in error &&
755
+ error.statusDetails instanceof Array) {
756
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
757
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
758
+ }
759
+ throw error;
760
+ });
761
+ }
762
+ updateSnapshot(request, optionsOrCallback, callback) {
763
+ request = request || {};
764
+ let options;
765
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
766
+ callback = optionsOrCallback;
767
+ options = {};
768
+ }
769
+ else {
770
+ options = optionsOrCallback;
771
+ }
772
+ options = options || {};
773
+ options.otherArgs = options.otherArgs || {};
774
+ options.otherArgs.headers = options.otherArgs.headers || {};
775
+ options.otherArgs.headers['x-goog-request-params'] =
776
+ this._gaxModule.routingHeader.fromParams({
777
+ 'snapshot.name': request.snapshot.name ?? '',
778
+ });
779
+ this.initialize().catch((err) => {
780
+ throw err;
781
+ });
782
+ this._log.info('updateSnapshot request %j', request);
783
+ const wrappedCallback = callback
784
+ ? (error, response, options, rawResponse) => {
785
+ this._log.info('updateSnapshot response %j', response);
786
+ callback(error, response, options, rawResponse); // We verified callback above.
787
+ }
788
+ : undefined;
789
+ return this.innerApiCalls
790
+ .updateSnapshot(request, options, wrappedCallback)
791
+ ?.then(([response, options, rawResponse]) => {
792
+ this._log.info('updateSnapshot response %j', response);
793
+ return [response, options, rawResponse];
794
+ })
795
+ .catch((error) => {
796
+ if (error &&
797
+ 'statusDetails' in error &&
798
+ error.statusDetails instanceof Array) {
799
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
800
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
801
+ }
802
+ throw error;
803
+ });
804
+ }
805
+ deleteSnapshot(request, optionsOrCallback, callback) {
806
+ request = request || {};
807
+ let options;
808
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
809
+ callback = optionsOrCallback;
810
+ options = {};
811
+ }
812
+ else {
813
+ options = optionsOrCallback;
814
+ }
815
+ options = options || {};
816
+ options.otherArgs = options.otherArgs || {};
817
+ options.otherArgs.headers = options.otherArgs.headers || {};
818
+ options.otherArgs.headers['x-goog-request-params'] =
819
+ this._gaxModule.routingHeader.fromParams({
820
+ snapshot: request.snapshot ?? '',
821
+ });
822
+ this.initialize().catch((err) => {
823
+ throw err;
824
+ });
825
+ this._log.info('deleteSnapshot request %j', request);
826
+ const wrappedCallback = callback
827
+ ? (error, response, options, rawResponse) => {
828
+ this._log.info('deleteSnapshot response %j', response);
829
+ callback(error, response, options, rawResponse); // We verified callback above.
830
+ }
831
+ : undefined;
832
+ return this.innerApiCalls
833
+ .deleteSnapshot(request, options, wrappedCallback)
834
+ ?.then(([response, options, rawResponse]) => {
835
+ this._log.info('deleteSnapshot response %j', response);
836
+ return [response, options, rawResponse];
837
+ })
838
+ .catch((error) => {
839
+ if (error &&
840
+ 'statusDetails' in error &&
841
+ error.statusDetails instanceof Array) {
842
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
843
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
844
+ }
845
+ throw error;
846
+ });
847
+ }
848
+ seek(request, optionsOrCallback, callback) {
849
+ request = request || {};
850
+ let options;
851
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
852
+ callback = optionsOrCallback;
853
+ options = {};
854
+ }
855
+ else {
856
+ options = optionsOrCallback;
857
+ }
858
+ options = options || {};
859
+ options.otherArgs = options.otherArgs || {};
860
+ options.otherArgs.headers = options.otherArgs.headers || {};
861
+ options.otherArgs.headers['x-goog-request-params'] =
862
+ this._gaxModule.routingHeader.fromParams({
863
+ subscription: request.subscription ?? '',
864
+ });
865
+ this.initialize().catch((err) => {
866
+ throw err;
867
+ });
868
+ this._log.info('seek request %j', request);
869
+ const wrappedCallback = callback
870
+ ? (error, response, options, rawResponse) => {
871
+ this._log.info('seek response %j', response);
872
+ callback(error, response, options, rawResponse); // We verified callback above.
873
+ }
874
+ : undefined;
875
+ return this.innerApiCalls
876
+ .seek(request, options, wrappedCallback)
877
+ ?.then(([response, options, rawResponse]) => {
878
+ this._log.info('seek response %j', response);
879
+ return [response, options, rawResponse];
880
+ })
881
+ .catch((error) => {
882
+ if (error &&
883
+ 'statusDetails' in error &&
884
+ error.statusDetails instanceof Array) {
885
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
886
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
887
+ }
888
+ throw error;
889
+ });
890
+ }
891
+ /**
892
+ * Establishes a stream with the server, which sends messages down to the
893
+ * client. The client streams acknowledgments and ack deadline modifications
894
+ * back to the server. The server will close the stream and return the status
895
+ * on any error. The server may close the stream with status `UNAVAILABLE` to
896
+ * reassign server-side resources, in which case, the client should
897
+ * re-establish the stream. Flow control can be achieved by configuring the
898
+ * underlying RPC channel.
899
+ *
900
+ * @param {object} [options]
901
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
902
+ * @returns {Stream}
903
+ * An object stream which is both readable and writable. It accepts objects
904
+ * representing {@link protos.google.pubsub.v1.StreamingPullRequest|StreamingPullRequest} for write() method, and
905
+ * will emit objects representing {@link protos.google.pubsub.v1.StreamingPullResponse|StreamingPullResponse} on 'data' event asynchronously.
906
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation }
907
+ * for more details and examples.
908
+ * @example <caption>include:samples/generated/v1/subscriber.streaming_pull.js</caption>
909
+ * region_tag:pubsub_v1_generated_Subscriber_StreamingPull_async
910
+ */
911
+ streamingPull(options) {
912
+ this.initialize().catch((err) => {
913
+ throw err;
914
+ });
915
+ this._log.info('streamingPull stream %j', options);
916
+ return this.innerApiCalls.streamingPull(null, options);
917
+ }
918
+ listSubscriptions(request, optionsOrCallback, callback) {
919
+ request = request || {};
920
+ let options;
921
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
922
+ callback = optionsOrCallback;
923
+ options = {};
924
+ }
925
+ else {
926
+ options = optionsOrCallback;
927
+ }
928
+ options = options || {};
929
+ options.otherArgs = options.otherArgs || {};
930
+ options.otherArgs.headers = options.otherArgs.headers || {};
931
+ options.otherArgs.headers['x-goog-request-params'] =
932
+ this._gaxModule.routingHeader.fromParams({
933
+ project: request.project ?? '',
934
+ });
935
+ this.initialize().catch((err) => {
936
+ throw err;
937
+ });
938
+ const wrappedCallback = callback
939
+ ? (error, values, nextPageRequest, rawResponse) => {
940
+ this._log.info('listSubscriptions values %j', values);
941
+ callback(error, values, nextPageRequest, rawResponse); // We verified callback above.
942
+ }
943
+ : undefined;
944
+ this._log.info('listSubscriptions request %j', request);
945
+ return this.innerApiCalls
946
+ .listSubscriptions(request, options, wrappedCallback)
947
+ ?.then(([response, input, output]) => {
948
+ this._log.info('listSubscriptions values %j', response);
949
+ return [response, input, output];
950
+ });
951
+ }
952
+ /**
953
+ * Equivalent to `listSubscriptions`, but returns a NodeJS Stream object.
954
+ * @param {Object} request
955
+ * The request object that will be sent.
956
+ * @param {string} request.project
957
+ * Required. The name of the project in which to list subscriptions.
958
+ * Format is `projects/{project-id}`.
959
+ * @param {number} [request.pageSize]
960
+ * Optional. Maximum number of subscriptions to return.
961
+ * @param {string} [request.pageToken]
962
+ * Optional. The value returned by the last `ListSubscriptionsResponse`;
963
+ * indicates that this is a continuation of a prior `ListSubscriptions` call,
964
+ * and that the system should return the next page of data.
965
+ * @param {object} [options]
966
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
967
+ * @returns {Stream}
968
+ * An object stream which emits an object representing {@link protos.google.pubsub.v1.Subscription|Subscription} on 'data' event.
969
+ * The client library will perform auto-pagination by default: it will call the API as many
970
+ * times as needed. Note that it can affect your quota.
971
+ * We recommend using `listSubscriptionsAsync()`
972
+ * method described below for async iteration which you can stop as needed.
973
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
974
+ * for more details and examples.
975
+ */
976
+ listSubscriptionsStream(request, options) {
977
+ request = request || {};
978
+ options = options || {};
979
+ options.otherArgs = options.otherArgs || {};
980
+ options.otherArgs.headers = options.otherArgs.headers || {};
981
+ options.otherArgs.headers['x-goog-request-params'] =
982
+ this._gaxModule.routingHeader.fromParams({
983
+ project: request.project ?? '',
984
+ });
985
+ const defaultCallSettings = this._defaults['listSubscriptions'];
986
+ const callSettings = defaultCallSettings.merge(options);
987
+ this.initialize().catch((err) => {
988
+ throw err;
989
+ });
990
+ this._log.info('listSubscriptions stream %j', request);
991
+ return this.descriptors.page.listSubscriptions.createStream(this.innerApiCalls.listSubscriptions, request, callSettings);
992
+ }
993
+ /**
994
+ * Equivalent to `listSubscriptions`, but returns an iterable object.
995
+ *
996
+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
997
+ * @param {Object} request
998
+ * The request object that will be sent.
999
+ * @param {string} request.project
1000
+ * Required. The name of the project in which to list subscriptions.
1001
+ * Format is `projects/{project-id}`.
1002
+ * @param {number} [request.pageSize]
1003
+ * Optional. Maximum number of subscriptions to return.
1004
+ * @param {string} [request.pageToken]
1005
+ * Optional. The value returned by the last `ListSubscriptionsResponse`;
1006
+ * indicates that this is a continuation of a prior `ListSubscriptions` call,
1007
+ * and that the system should return the next page of data.
1008
+ * @param {object} [options]
1009
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1010
+ * @returns {Object}
1011
+ * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }.
1012
+ * When you iterate the returned iterable, each element will be an object representing
1013
+ * {@link protos.google.pubsub.v1.Subscription|Subscription}. The API will be called under the hood as needed, once per the page,
1014
+ * so you can stop the iteration when you don't need more results.
1015
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
1016
+ * for more details and examples.
1017
+ * @example <caption>include:samples/generated/v1/subscriber.list_subscriptions.js</caption>
1018
+ * region_tag:pubsub_v1_generated_Subscriber_ListSubscriptions_async
1019
+ */
1020
+ listSubscriptionsAsync(request, options) {
1021
+ request = request || {};
1022
+ options = options || {};
1023
+ options.otherArgs = options.otherArgs || {};
1024
+ options.otherArgs.headers = options.otherArgs.headers || {};
1025
+ options.otherArgs.headers['x-goog-request-params'] =
1026
+ this._gaxModule.routingHeader.fromParams({
1027
+ project: request.project ?? '',
1028
+ });
1029
+ const defaultCallSettings = this._defaults['listSubscriptions'];
1030
+ const callSettings = defaultCallSettings.merge(options);
1031
+ this.initialize().catch((err) => {
1032
+ throw err;
1033
+ });
1034
+ this._log.info('listSubscriptions iterate %j', request);
1035
+ return this.descriptors.page.listSubscriptions.asyncIterate(this.innerApiCalls['listSubscriptions'], request, callSettings);
1036
+ }
1037
+ listSnapshots(request, optionsOrCallback, callback) {
1038
+ request = request || {};
1039
+ let options;
1040
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
1041
+ callback = optionsOrCallback;
1042
+ options = {};
1043
+ }
1044
+ else {
1045
+ options = optionsOrCallback;
1046
+ }
1047
+ options = options || {};
1048
+ options.otherArgs = options.otherArgs || {};
1049
+ options.otherArgs.headers = options.otherArgs.headers || {};
1050
+ options.otherArgs.headers['x-goog-request-params'] =
1051
+ this._gaxModule.routingHeader.fromParams({
1052
+ project: request.project ?? '',
1053
+ });
1054
+ this.initialize().catch((err) => {
1055
+ throw err;
1056
+ });
1057
+ const wrappedCallback = callback
1058
+ ? (error, values, nextPageRequest, rawResponse) => {
1059
+ this._log.info('listSnapshots values %j', values);
1060
+ callback(error, values, nextPageRequest, rawResponse); // We verified callback above.
1061
+ }
1062
+ : undefined;
1063
+ this._log.info('listSnapshots request %j', request);
1064
+ return this.innerApiCalls
1065
+ .listSnapshots(request, options, wrappedCallback)
1066
+ ?.then(([response, input, output]) => {
1067
+ this._log.info('listSnapshots values %j', response);
1068
+ return [response, input, output];
1069
+ });
1070
+ }
1071
+ /**
1072
+ * Equivalent to `listSnapshots`, but returns a NodeJS Stream object.
1073
+ * @param {Object} request
1074
+ * The request object that will be sent.
1075
+ * @param {string} request.project
1076
+ * Required. The name of the project in which to list snapshots.
1077
+ * Format is `projects/{project-id}`.
1078
+ * @param {number} [request.pageSize]
1079
+ * Optional. Maximum number of snapshots to return.
1080
+ * @param {string} [request.pageToken]
1081
+ * Optional. The value returned by the last `ListSnapshotsResponse`; indicates
1082
+ * that this is a continuation of a prior `ListSnapshots` call, and that the
1083
+ * system should return the next page of data.
1084
+ * @param {object} [options]
1085
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1086
+ * @returns {Stream}
1087
+ * An object stream which emits an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot} on 'data' event.
1088
+ * The client library will perform auto-pagination by default: it will call the API as many
1089
+ * times as needed. Note that it can affect your quota.
1090
+ * We recommend using `listSnapshotsAsync()`
1091
+ * method described below for async iteration which you can stop as needed.
1092
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
1093
+ * for more details and examples.
1094
+ */
1095
+ listSnapshotsStream(request, options) {
1096
+ request = request || {};
1097
+ options = options || {};
1098
+ options.otherArgs = options.otherArgs || {};
1099
+ options.otherArgs.headers = options.otherArgs.headers || {};
1100
+ options.otherArgs.headers['x-goog-request-params'] =
1101
+ this._gaxModule.routingHeader.fromParams({
1102
+ project: request.project ?? '',
1103
+ });
1104
+ const defaultCallSettings = this._defaults['listSnapshots'];
1105
+ const callSettings = defaultCallSettings.merge(options);
1106
+ this.initialize().catch((err) => {
1107
+ throw err;
1108
+ });
1109
+ this._log.info('listSnapshots stream %j', request);
1110
+ return this.descriptors.page.listSnapshots.createStream(this.innerApiCalls.listSnapshots, request, callSettings);
1111
+ }
1112
+ /**
1113
+ * Equivalent to `listSnapshots`, but returns an iterable object.
1114
+ *
1115
+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
1116
+ * @param {Object} request
1117
+ * The request object that will be sent.
1118
+ * @param {string} request.project
1119
+ * Required. The name of the project in which to list snapshots.
1120
+ * Format is `projects/{project-id}`.
1121
+ * @param {number} [request.pageSize]
1122
+ * Optional. Maximum number of snapshots to return.
1123
+ * @param {string} [request.pageToken]
1124
+ * Optional. The value returned by the last `ListSnapshotsResponse`; indicates
1125
+ * that this is a continuation of a prior `ListSnapshots` call, and that the
1126
+ * system should return the next page of data.
1127
+ * @param {object} [options]
1128
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1129
+ * @returns {Object}
1130
+ * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }.
1131
+ * When you iterate the returned iterable, each element will be an object representing
1132
+ * {@link protos.google.pubsub.v1.Snapshot|Snapshot}. The API will be called under the hood as needed, once per the page,
1133
+ * so you can stop the iteration when you don't need more results.
1134
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation }
1135
+ * for more details and examples.
1136
+ * @example <caption>include:samples/generated/v1/subscriber.list_snapshots.js</caption>
1137
+ * region_tag:pubsub_v1_generated_Subscriber_ListSnapshots_async
1138
+ */
1139
+ listSnapshotsAsync(request, options) {
1140
+ request = request || {};
1141
+ options = options || {};
1142
+ options.otherArgs = options.otherArgs || {};
1143
+ options.otherArgs.headers = options.otherArgs.headers || {};
1144
+ options.otherArgs.headers['x-goog-request-params'] =
1145
+ this._gaxModule.routingHeader.fromParams({
1146
+ project: request.project ?? '',
1147
+ });
1148
+ const defaultCallSettings = this._defaults['listSnapshots'];
1149
+ const callSettings = defaultCallSettings.merge(options);
1150
+ this.initialize().catch((err) => {
1151
+ throw err;
1152
+ });
1153
+ this._log.info('listSnapshots iterate %j', request);
1154
+ return this.descriptors.page.listSnapshots.asyncIterate(this.innerApiCalls['listSnapshots'], request, callSettings);
1155
+ }
1156
+ /**
1157
+ * Gets the access control policy for a resource. Returns an empty policy
1158
+ * if the resource exists and does not have a policy set.
1159
+ *
1160
+ * @param {Object} request
1161
+ * The request object that will be sent.
1162
+ * @param {string} request.resource
1163
+ * REQUIRED: The resource for which the policy is being requested.
1164
+ * See the operation documentation for the appropriate value for this field.
1165
+ * @param {Object} [request.options]
1166
+ * OPTIONAL: A `GetPolicyOptions` object for specifying options to
1167
+ * `GetIamPolicy`. This field is only used by Cloud IAM.
1168
+ *
1169
+ * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}.
1170
+ * @param {Object} [options]
1171
+ * Optional parameters. You can override the default settings for this call, e.g, timeout,
1172
+ * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details.
1173
+ * @param {function(?Error, ?Object)} [callback]
1174
+ * The function which will be called with the result of the API call.
1175
+ *
1176
+ * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}.
1177
+ * @returns {Promise} - The promise which resolves to an array.
1178
+ * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}.
1179
+ * The promise has a method named "cancel" which cancels the ongoing API call.
1180
+ */
1181
+ getIamPolicy(request, options, callback) {
1182
+ return this.iamClient.getIamPolicy(request, options, callback);
1183
+ }
1184
+ /**
1185
+ * Returns permissions that a caller has on the specified resource. If the
1186
+ * resource does not exist, this will return an empty set of
1187
+ * permissions, not a NOT_FOUND error.
1188
+ *
1189
+ * Note: This operation is designed to be used for building
1190
+ * permission-aware UIs and command-line tools, not for authorization
1191
+ * checking. This operation may "fail open" without warning.
1192
+ *
1193
+ * @param {Object} request
1194
+ * The request object that will be sent.
1195
+ * @param {string} request.resource
1196
+ * REQUIRED: The resource for which the policy detail is being requested.
1197
+ * See the operation documentation for the appropriate value for this field.
1198
+ * @param {string[]} request.permissions
1199
+ * The set of permissions to check for the `resource`. Permissions with
1200
+ * wildcards (such as '*' or 'storage.*') are not allowed. For more
1201
+ * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }.
1202
+ * @param {Object} [options]
1203
+ * Optional parameters. You can override the default settings for this call, e.g, timeout,
1204
+ * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details.
1205
+ * @param {function(?Error, ?Object)} [callback]
1206
+ * The function which will be called with the result of the API call.
1207
+ *
1208
+ * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}.
1209
+ * @returns {Promise} - The promise which resolves to an array.
1210
+ * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}.
1211
+ * The promise has a method named "cancel" which cancels the ongoing API call.
1212
+ */
1213
+ setIamPolicy(request, options, callback) {
1214
+ return this.iamClient.setIamPolicy(request, options, callback);
1215
+ }
1216
+ /**
1217
+ * Returns permissions that a caller has on the specified resource. If the
1218
+ * resource does not exist, this will return an empty set of
1219
+ * permissions, not a NOT_FOUND error.
1220
+ *
1221
+ * Note: This operation is designed to be used for building
1222
+ * permission-aware UIs and command-line tools, not for authorization
1223
+ * checking. This operation may "fail open" without warning.
1224
+ *
1225
+ * @param {Object} request
1226
+ * The request object that will be sent.
1227
+ * @param {string} request.resource
1228
+ * REQUIRED: The resource for which the policy detail is being requested.
1229
+ * See the operation documentation for the appropriate value for this field.
1230
+ * @param {string[]} request.permissions
1231
+ * The set of permissions to check for the `resource`. Permissions with
1232
+ * wildcards (such as '*' or 'storage.*') are not allowed. For more
1233
+ * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }.
1234
+ * @param {Object} [options]
1235
+ * Optional parameters. You can override the default settings for this call, e.g, timeout,
1236
+ * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details.
1237
+ * @param {function(?Error, ?Object)} [callback]
1238
+ * The function which will be called with the result of the API call.
1239
+ *
1240
+ * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}.
1241
+ * @returns {Promise} - The promise which resolves to an array.
1242
+ * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}.
1243
+ * The promise has a method named "cancel" which cancels the ongoing API call.
1244
+ *
1245
+ */
1246
+ testIamPermissions(request, options, callback) {
1247
+ return this.iamClient.testIamPermissions(request, options, callback);
1248
+ }
1249
+ // --------------------
1250
+ // -- Path templates --
1251
+ // --------------------
1252
+ /**
1253
+ * Return a fully-qualified cryptoKey resource name string.
1254
+ *
1255
+ * @param {string} project
1256
+ * @param {string} location
1257
+ * @param {string} key_ring
1258
+ * @param {string} crypto_key
1259
+ * @returns {string} Resource name string.
1260
+ */
1261
+ cryptoKeyPath(project, location, keyRing, cryptoKey) {
1262
+ return this.pathTemplates.cryptoKeyPathTemplate.render({
1263
+ project: project,
1264
+ location: location,
1265
+ key_ring: keyRing,
1266
+ crypto_key: cryptoKey,
1267
+ });
1268
+ }
1269
+ /**
1270
+ * Parse the project from CryptoKey resource.
1271
+ *
1272
+ * @param {string} cryptoKeyName
1273
+ * A fully-qualified path representing CryptoKey resource.
1274
+ * @returns {string} A string representing the project.
1275
+ */
1276
+ matchProjectFromCryptoKeyName(cryptoKeyName) {
1277
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
1278
+ .project;
1279
+ }
1280
+ /**
1281
+ * Parse the location from CryptoKey resource.
1282
+ *
1283
+ * @param {string} cryptoKeyName
1284
+ * A fully-qualified path representing CryptoKey resource.
1285
+ * @returns {string} A string representing the location.
1286
+ */
1287
+ matchLocationFromCryptoKeyName(cryptoKeyName) {
1288
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
1289
+ .location;
1290
+ }
1291
+ /**
1292
+ * Parse the key_ring from CryptoKey resource.
1293
+ *
1294
+ * @param {string} cryptoKeyName
1295
+ * A fully-qualified path representing CryptoKey resource.
1296
+ * @returns {string} A string representing the key_ring.
1297
+ */
1298
+ matchKeyRingFromCryptoKeyName(cryptoKeyName) {
1299
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
1300
+ .key_ring;
1301
+ }
1302
+ /**
1303
+ * Parse the crypto_key from CryptoKey resource.
1304
+ *
1305
+ * @param {string} cryptoKeyName
1306
+ * A fully-qualified path representing CryptoKey resource.
1307
+ * @returns {string} A string representing the crypto_key.
1308
+ */
1309
+ matchCryptoKeyFromCryptoKeyName(cryptoKeyName) {
1310
+ return this.pathTemplates.cryptoKeyPathTemplate.match(cryptoKeyName)
1311
+ .crypto_key;
1312
+ }
1313
+ /**
1314
+ * Return a fully-qualified project resource name string.
1315
+ *
1316
+ * @param {string} project
1317
+ * @returns {string} Resource name string.
1318
+ */
1319
+ projectPath(project) {
1320
+ return this.pathTemplates.projectPathTemplate.render({
1321
+ project: project,
1322
+ });
1323
+ }
1324
+ /**
1325
+ * Parse the project from Project resource.
1326
+ *
1327
+ * @param {string} projectName
1328
+ * A fully-qualified path representing Project resource.
1329
+ * @returns {string} A string representing the project.
1330
+ */
1331
+ matchProjectFromProjectName(projectName) {
1332
+ return this.pathTemplates.projectPathTemplate.match(projectName).project;
1333
+ }
1334
+ /**
1335
+ * Return a fully-qualified projectTopics resource name string.
1336
+ *
1337
+ * @param {string} project
1338
+ * @param {string} topic
1339
+ * @returns {string} Resource name string.
1340
+ */
1341
+ projectTopicsPath(project, topic) {
1342
+ return this.pathTemplates.projectTopicsPathTemplate.render({
1343
+ project: project,
1344
+ topic: topic,
1345
+ });
1346
+ }
1347
+ /**
1348
+ * Parse the project from ProjectTopics resource.
1349
+ *
1350
+ * @param {string} projectTopicsName
1351
+ * A fully-qualified path representing project_topics resource.
1352
+ * @returns {string} A string representing the project.
1353
+ */
1354
+ matchProjectFromProjectTopicsName(projectTopicsName) {
1355
+ return this.pathTemplates.projectTopicsPathTemplate.match(projectTopicsName)
1356
+ .project;
1357
+ }
1358
+ /**
1359
+ * Parse the topic from ProjectTopics resource.
1360
+ *
1361
+ * @param {string} projectTopicsName
1362
+ * A fully-qualified path representing project_topics resource.
1363
+ * @returns {string} A string representing the topic.
1364
+ */
1365
+ matchTopicFromProjectTopicsName(projectTopicsName) {
1366
+ return this.pathTemplates.projectTopicsPathTemplate.match(projectTopicsName)
1367
+ .topic;
1368
+ }
1369
+ /**
1370
+ * Return a fully-qualified schema resource name string.
1371
+ *
1372
+ * @param {string} project
1373
+ * @param {string} schema
1374
+ * @returns {string} Resource name string.
1375
+ */
1376
+ schemaPath(project, schema) {
1377
+ return this.pathTemplates.schemaPathTemplate.render({
1378
+ project: project,
1379
+ schema: schema,
1380
+ });
1381
+ }
1382
+ /**
1383
+ * Parse the project from Schema resource.
1384
+ *
1385
+ * @param {string} schemaName
1386
+ * A fully-qualified path representing Schema resource.
1387
+ * @returns {string} A string representing the project.
1388
+ */
1389
+ matchProjectFromSchemaName(schemaName) {
1390
+ return this.pathTemplates.schemaPathTemplate.match(schemaName).project;
1391
+ }
1392
+ /**
1393
+ * Parse the schema from Schema resource.
1394
+ *
1395
+ * @param {string} schemaName
1396
+ * A fully-qualified path representing Schema resource.
1397
+ * @returns {string} A string representing the schema.
1398
+ */
1399
+ matchSchemaFromSchemaName(schemaName) {
1400
+ return this.pathTemplates.schemaPathTemplate.match(schemaName).schema;
1401
+ }
1402
+ /**
1403
+ * Return a fully-qualified snapshot resource name string.
1404
+ *
1405
+ * @param {string} project
1406
+ * @param {string} snapshot
1407
+ * @returns {string} Resource name string.
1408
+ */
1409
+ snapshotPath(project, snapshot) {
1410
+ return this.pathTemplates.snapshotPathTemplate.render({
1411
+ project: project,
1412
+ snapshot: snapshot,
1413
+ });
1414
+ }
1415
+ /**
1416
+ * Parse the project from Snapshot resource.
1417
+ *
1418
+ * @param {string} snapshotName
1419
+ * A fully-qualified path representing Snapshot resource.
1420
+ * @returns {string} A string representing the project.
1421
+ */
1422
+ matchProjectFromSnapshotName(snapshotName) {
1423
+ return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project;
1424
+ }
1425
+ /**
1426
+ * Parse the snapshot from Snapshot resource.
1427
+ *
1428
+ * @param {string} snapshotName
1429
+ * A fully-qualified path representing Snapshot resource.
1430
+ * @returns {string} A string representing the snapshot.
1431
+ */
1432
+ matchSnapshotFromSnapshotName(snapshotName) {
1433
+ return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot;
1434
+ }
1435
+ /**
1436
+ * Return a fully-qualified subscription resource name string.
1437
+ *
1438
+ * @param {string} project
1439
+ * @param {string} subscription
1440
+ * @returns {string} Resource name string.
1441
+ */
1442
+ subscriptionPath(project, subscription) {
1443
+ return this.pathTemplates.subscriptionPathTemplate.render({
1444
+ project: project,
1445
+ subscription: subscription,
1446
+ });
1447
+ }
1448
+ /**
1449
+ * Parse the project from Subscription resource.
1450
+ *
1451
+ * @param {string} subscriptionName
1452
+ * A fully-qualified path representing Subscription resource.
1453
+ * @returns {string} A string representing the project.
1454
+ */
1455
+ matchProjectFromSubscriptionName(subscriptionName) {
1456
+ return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName)
1457
+ .project;
1458
+ }
1459
+ /**
1460
+ * Parse the subscription from Subscription resource.
1461
+ *
1462
+ * @param {string} subscriptionName
1463
+ * A fully-qualified path representing Subscription resource.
1464
+ * @returns {string} A string representing the subscription.
1465
+ */
1466
+ matchSubscriptionFromSubscriptionName(subscriptionName) {
1467
+ return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName)
1468
+ .subscription;
1469
+ }
1470
+ /**
1471
+ * Terminate the gRPC channel and close the client.
1472
+ *
1473
+ * The client will no longer be usable and all future behavior is undefined.
1474
+ * @returns {Promise} A promise that resolves when the client is closed.
1475
+ */
1476
+ close() {
1477
+ if (this.subscriberStub && !this._terminated) {
1478
+ return this.subscriberStub.then((stub) => {
1479
+ this._log.info('ending gRPC channel');
1480
+ this._terminated = true;
1481
+ stub.close();
1482
+ this.iamClient.close().catch((err) => {
1483
+ throw err;
1484
+ });
1485
+ });
1486
+ }
1487
+ return Promise.resolve();
1488
+ }
1489
+ }
1490
+ exports.SubscriberClient = SubscriberClient;
1491
+ //# sourceMappingURL=subscriber_client.js.map