1 | ;
|
2 | // Copyright 2022 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 | /* global window */
|
22 | const gax = require("google-gax");
|
23 | const google_gax_1 = require("google-gax");
|
24 | const stream_1 = require("stream");
|
25 | const jsonProtos = require("../../protos/protos.json");
|
26 | /**
|
27 | * Client JSON configuration object, loaded from
|
28 | * `src/v1/subscriber_client_config.json`.
|
29 | * This file defines retry strategy and timeouts for all API methods in this library.
|
30 | */
|
31 | const gapicConfig = require("./subscriber_client_config.json");
|
32 | const version = require('../../../package.json').version;
|
33 | /**
|
34 | * The service that an application uses to manipulate subscriptions and to
|
35 | * consume messages from a subscription via the `Pull` method or by
|
36 | * establishing a bi-directional stream using the `StreamingPull` method.
|
37 | * @class
|
38 | * @memberof v1
|
39 | */
|
40 | class SubscriberClient {
|
41 | /**
|
42 | * Construct an instance of SubscriberClient.
|
43 | *
|
44 | * @param {object} [options] - The configuration object.
|
45 | * The options accepted by the constructor are described in detail
|
46 | * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
|
47 | * The common options are:
|
48 | * @param {object} [options.credentials] - Credentials object.
|
49 | * @param {string} [options.credentials.client_email]
|
50 | * @param {string} [options.credentials.private_key]
|
51 | * @param {string} [options.email] - Account email address. Required when
|
52 | * using a .pem or .p12 keyFilename.
|
53 | * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
|
54 | * .p12 key downloaded from the Google Developers Console. If you provide
|
55 | * a path to a JSON file, the projectId option below is not necessary.
|
56 | * NOTE: .pem and .p12 require you to specify options.email as well.
|
57 | * @param {number} [options.port] - The port on which to connect to
|
58 | * the remote host.
|
59 | * @param {string} [options.projectId] - The project ID from the Google
|
60 | * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
|
61 | * the environment variable GCLOUD_PROJECT for your project ID. If your
|
62 | * app is running in an environment which supports
|
63 | * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
|
64 | * your project ID will be detected automatically.
|
65 | * @param {string} [options.apiEndpoint] - The domain name of the
|
66 | * API remote host.
|
67 | * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
|
68 | * Follows the structure of {@link gapicConfig}.
|
69 | * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
|
70 | * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
|
71 | * For more information, please check the
|
72 | * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
|
73 | */
|
74 | constructor(opts) {
|
75 | var _a, _b;
|
76 | this._terminated = false;
|
77 | this.descriptors = {
|
78 | page: {},
|
79 | stream: {},
|
80 | longrunning: {},
|
81 | batching: {},
|
82 | };
|
83 | // Ensure that options include all the required fields.
|
84 | const staticMembers = this.constructor;
|
85 | const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || staticMembers.servicePath;
|
86 | this._providedCustomServicePath = !!((opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint));
|
87 | const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port;
|
88 | const clientConfig = (_a = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _a !== void 0 ? _a : {};
|
89 | const fallback = (_b = opts === null || opts === void 0 ? void 0 : opts.fallback) !== null && _b !== void 0 ? _b : (typeof window !== 'undefined' && typeof (window === null || window === void 0 ? void 0 : window.fetch) === 'function');
|
90 | opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
|
91 | // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
|
92 | if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
|
93 | opts['scopes'] = staticMembers.scopes;
|
94 | }
|
95 | // Choose either gRPC or proto-over-HTTP implementation of google-gax.
|
96 | this._gaxModule = opts.fallback ? gax.fallback : gax;
|
97 | // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
|
98 | this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
|
99 | // Save options to use in initialize() method.
|
100 | this._opts = opts;
|
101 | // Save the auth object to the client, for use by other methods.
|
102 | this.auth = this._gaxGrpc.auth;
|
103 | // Set useJWTAccessWithScope on the auth object.
|
104 | this.auth.useJWTAccessWithScope = true;
|
105 | // Set defaultServicePath on the auth object.
|
106 | this.auth.defaultServicePath = staticMembers.servicePath;
|
107 | // Set the default scopes in auth client if needed.
|
108 | if (servicePath === staticMembers.servicePath) {
|
109 | this.auth.defaultScopes = staticMembers.scopes;
|
110 | }
|
111 | this.iamClient = new google_gax_1.IamClient(this._gaxGrpc, opts);
|
112 | // Determine the client header string.
|
113 | const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
|
114 | if (typeof process !== 'undefined' && 'versions' in process) {
|
115 | clientHeader.push(`gl-node/${process.versions.node}`);
|
116 | }
|
117 | else {
|
118 | clientHeader.push(`gl-web/${this._gaxModule.version}`);
|
119 | }
|
120 | if (!opts.fallback) {
|
121 | clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
|
122 | }
|
123 | else if (opts.fallback === 'rest') {
|
124 | clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
|
125 | }
|
126 | if (opts.libName && opts.libVersion) {
|
127 | clientHeader.push(`${opts.libName}/${opts.libVersion}`);
|
128 | }
|
129 | // Load the applicable protos.
|
130 | this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
|
131 | // This API contains "path templates"; forward-slash-separated
|
132 | // identifiers to uniquely identify resources within the API.
|
133 | // Create useful helper objects for these.
|
134 | this.pathTemplates = {
|
135 | projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
|
136 | projectTopicPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/topics/{topic}'),
|
137 | schemaPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/schemas/{schema}'),
|
138 | snapshotPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/snapshots/{snapshot}'),
|
139 | subscriptionPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/subscriptions/{subscription}'),
|
140 | };
|
141 | // Some of the methods on this service return "paged" results,
|
142 | // (e.g. 50 results at a time, with tokens to get subsequent
|
143 | // pages). Denote the keys used for pagination and results.
|
144 | this.descriptors.page = {
|
145 | listSubscriptions: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'),
|
146 | listSnapshots: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots'),
|
147 | };
|
148 | // Some of the methods on this service provide streaming responses.
|
149 | // Provide descriptors for these.
|
150 | this.descriptors.stream = {
|
151 | streamingPull: new this._gaxModule.StreamDescriptor(gax.StreamType.BIDI_STREAMING, opts.fallback === 'rest'),
|
152 | };
|
153 | // Put together the default options sent with requests.
|
154 | this._defaults = this._gaxGrpc.constructSettings('google.pubsub.v1.Subscriber', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
|
155 | // Set up a dictionary of "inner API calls"; the core implementation
|
156 | // of calling the API is handled in `google-gax`, with this code
|
157 | // merely providing the destination and request information.
|
158 | this.innerApiCalls = {};
|
159 | // Add a warn function to the client constructor so it can be easily tested.
|
160 | this.warn = gax.warn;
|
161 | }
|
162 | /**
|
163 | * Initialize the client.
|
164 | * Performs asynchronous operations (such as authentication) and prepares the client.
|
165 | * This function will be called automatically when any class method is called for the
|
166 | * first time, but if you need to initialize it before calling an actual method,
|
167 | * feel free to call initialize() directly.
|
168 | *
|
169 | * You can await on this method if you want to make sure the client is initialized.
|
170 | *
|
171 | * @returns {Promise} A promise that resolves to an authenticated service stub.
|
172 | */
|
173 | initialize() {
|
174 | // If the client stub promise is already initialized, return immediately.
|
175 | if (this.subscriberStub) {
|
176 | return this.subscriberStub;
|
177 | }
|
178 | // Put together the "service stub" for
|
179 | // google.pubsub.v1.Subscriber.
|
180 | this.subscriberStub = this._gaxGrpc.createStub(this._opts.fallback
|
181 | ? this._protos.lookupService('google.pubsub.v1.Subscriber')
|
182 | : // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
183 | this._protos.google.pubsub.v1.Subscriber, this._opts, this._providedCustomServicePath);
|
184 | // Iterate over each of the methods that the service provides
|
185 | // and create an API call method for each.
|
186 | const subscriberStubMethods = [
|
187 | 'createSubscription',
|
188 | 'getSubscription',
|
189 | 'updateSubscription',
|
190 | 'listSubscriptions',
|
191 | 'deleteSubscription',
|
192 | 'modifyAckDeadline',
|
193 | 'acknowledge',
|
194 | 'pull',
|
195 | 'streamingPull',
|
196 | 'modifyPushConfig',
|
197 | 'getSnapshot',
|
198 | 'listSnapshots',
|
199 | 'createSnapshot',
|
200 | 'updateSnapshot',
|
201 | 'deleteSnapshot',
|
202 | 'seek',
|
203 | ];
|
204 | for (const methodName of subscriberStubMethods) {
|
205 | const callPromise = this.subscriberStub.then(stub => (...args) => {
|
206 | if (this._terminated) {
|
207 | if (methodName in this.descriptors.stream) {
|
208 | const stream = new stream_1.PassThrough();
|
209 | setImmediate(() => {
|
210 | stream.emit('error', new google_gax_1.GoogleError('The client has already been closed.'));
|
211 | });
|
212 | return stream;
|
213 | }
|
214 | return Promise.reject('The client has already been closed.');
|
215 | }
|
216 | const func = stub[methodName];
|
217 | return func.apply(stub, args);
|
218 | }, (err) => () => {
|
219 | throw err;
|
220 | });
|
221 | const descriptor = this.descriptors.page[methodName] ||
|
222 | this.descriptors.stream[methodName] ||
|
223 | undefined;
|
224 | const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor);
|
225 | this.innerApiCalls[methodName] = apiCall;
|
226 | }
|
227 | return this.subscriberStub;
|
228 | }
|
229 | /**
|
230 | * The DNS address for this API service.
|
231 | * @returns {string} The DNS address for this service.
|
232 | */
|
233 | static get servicePath() {
|
234 | return 'pubsub.googleapis.com';
|
235 | }
|
236 | /**
|
237 | * The DNS address for this API service - same as servicePath(),
|
238 | * exists for compatibility reasons.
|
239 | * @returns {string} The DNS address for this service.
|
240 | */
|
241 | static get apiEndpoint() {
|
242 | return 'pubsub.googleapis.com';
|
243 | }
|
244 | /**
|
245 | * The port for this API service.
|
246 | * @returns {number} The default port for this service.
|
247 | */
|
248 | static get port() {
|
249 | return 443;
|
250 | }
|
251 | /**
|
252 | * The scopes needed to make gRPC calls for every method defined
|
253 | * in this service.
|
254 | * @returns {string[]} List of default scopes.
|
255 | */
|
256 | static get scopes() {
|
257 | return [
|
258 | 'https://www.googleapis.com/auth/cloud-platform',
|
259 | 'https://www.googleapis.com/auth/pubsub',
|
260 | ];
|
261 | }
|
262 | /**
|
263 | * Return the project ID used by this class.
|
264 | * @returns {Promise} A promise that resolves to string containing the project ID.
|
265 | */
|
266 | getProjectId(callback) {
|
267 | if (callback) {
|
268 | this.auth.getProjectId(callback);
|
269 | return;
|
270 | }
|
271 | return this.auth.getProjectId();
|
272 | }
|
273 | createSubscription(request, optionsOrCallback, callback) {
|
274 | request = request || {};
|
275 | let options;
|
276 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
277 | callback = optionsOrCallback;
|
278 | options = {};
|
279 | }
|
280 | else {
|
281 | options = optionsOrCallback;
|
282 | }
|
283 | options = options || {};
|
284 | options.otherArgs = options.otherArgs || {};
|
285 | options.otherArgs.headers = options.otherArgs.headers || {};
|
286 | options.otherArgs.headers['x-goog-request-params'] =
|
287 | gax.routingHeader.fromParams({
|
288 | name: request.name || '',
|
289 | });
|
290 | this.initialize();
|
291 | return this.innerApiCalls.createSubscription(request, options, callback);
|
292 | }
|
293 | getSubscription(request, optionsOrCallback, callback) {
|
294 | request = request || {};
|
295 | let options;
|
296 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
297 | callback = optionsOrCallback;
|
298 | options = {};
|
299 | }
|
300 | else {
|
301 | options = optionsOrCallback;
|
302 | }
|
303 | options = options || {};
|
304 | options.otherArgs = options.otherArgs || {};
|
305 | options.otherArgs.headers = options.otherArgs.headers || {};
|
306 | options.otherArgs.headers['x-goog-request-params'] =
|
307 | gax.routingHeader.fromParams({
|
308 | subscription: request.subscription || '',
|
309 | });
|
310 | this.initialize();
|
311 | return this.innerApiCalls.getSubscription(request, options, callback);
|
312 | }
|
313 | updateSubscription(request, optionsOrCallback, callback) {
|
314 | request = request || {};
|
315 | let options;
|
316 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
317 | callback = optionsOrCallback;
|
318 | options = {};
|
319 | }
|
320 | else {
|
321 | options = optionsOrCallback;
|
322 | }
|
323 | options = options || {};
|
324 | options.otherArgs = options.otherArgs || {};
|
325 | options.otherArgs.headers = options.otherArgs.headers || {};
|
326 | options.otherArgs.headers['x-goog-request-params'] =
|
327 | gax.routingHeader.fromParams({
|
328 | 'subscription.name': request.subscription.name || '',
|
329 | });
|
330 | this.initialize();
|
331 | return this.innerApiCalls.updateSubscription(request, options, callback);
|
332 | }
|
333 | deleteSubscription(request, optionsOrCallback, callback) {
|
334 | request = request || {};
|
335 | let options;
|
336 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
337 | callback = optionsOrCallback;
|
338 | options = {};
|
339 | }
|
340 | else {
|
341 | options = optionsOrCallback;
|
342 | }
|
343 | options = options || {};
|
344 | options.otherArgs = options.otherArgs || {};
|
345 | options.otherArgs.headers = options.otherArgs.headers || {};
|
346 | options.otherArgs.headers['x-goog-request-params'] =
|
347 | gax.routingHeader.fromParams({
|
348 | subscription: request.subscription || '',
|
349 | });
|
350 | this.initialize();
|
351 | return this.innerApiCalls.deleteSubscription(request, options, callback);
|
352 | }
|
353 | modifyAckDeadline(request, optionsOrCallback, callback) {
|
354 | request = request || {};
|
355 | let options;
|
356 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
357 | callback = optionsOrCallback;
|
358 | options = {};
|
359 | }
|
360 | else {
|
361 | options = optionsOrCallback;
|
362 | }
|
363 | options = options || {};
|
364 | options.otherArgs = options.otherArgs || {};
|
365 | options.otherArgs.headers = options.otherArgs.headers || {};
|
366 | options.otherArgs.headers['x-goog-request-params'] =
|
367 | gax.routingHeader.fromParams({
|
368 | subscription: request.subscription || '',
|
369 | });
|
370 | this.initialize();
|
371 | return this.innerApiCalls.modifyAckDeadline(request, options, callback);
|
372 | }
|
373 | acknowledge(request, optionsOrCallback, callback) {
|
374 | request = request || {};
|
375 | let options;
|
376 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
377 | callback = optionsOrCallback;
|
378 | options = {};
|
379 | }
|
380 | else {
|
381 | options = optionsOrCallback;
|
382 | }
|
383 | options = options || {};
|
384 | options.otherArgs = options.otherArgs || {};
|
385 | options.otherArgs.headers = options.otherArgs.headers || {};
|
386 | options.otherArgs.headers['x-goog-request-params'] =
|
387 | gax.routingHeader.fromParams({
|
388 | subscription: request.subscription || '',
|
389 | });
|
390 | this.initialize();
|
391 | return this.innerApiCalls.acknowledge(request, options, callback);
|
392 | }
|
393 | pull(request, optionsOrCallback, callback) {
|
394 | request = request || {};
|
395 | let options;
|
396 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
397 | callback = optionsOrCallback;
|
398 | options = {};
|
399 | }
|
400 | else {
|
401 | options = optionsOrCallback;
|
402 | }
|
403 | options = options || {};
|
404 | options.otherArgs = options.otherArgs || {};
|
405 | options.otherArgs.headers = options.otherArgs.headers || {};
|
406 | options.otherArgs.headers['x-goog-request-params'] =
|
407 | gax.routingHeader.fromParams({
|
408 | subscription: request.subscription || '',
|
409 | });
|
410 | this.initialize();
|
411 | return this.innerApiCalls.pull(request, options, callback);
|
412 | }
|
413 | modifyPushConfig(request, optionsOrCallback, callback) {
|
414 | request = request || {};
|
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 | options.otherArgs.headers['x-goog-request-params'] =
|
427 | gax.routingHeader.fromParams({
|
428 | subscription: request.subscription || '',
|
429 | });
|
430 | this.initialize();
|
431 | return this.innerApiCalls.modifyPushConfig(request, options, callback);
|
432 | }
|
433 | getSnapshot(request, optionsOrCallback, callback) {
|
434 | request = request || {};
|
435 | let options;
|
436 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
437 | callback = optionsOrCallback;
|
438 | options = {};
|
439 | }
|
440 | else {
|
441 | options = optionsOrCallback;
|
442 | }
|
443 | options = options || {};
|
444 | options.otherArgs = options.otherArgs || {};
|
445 | options.otherArgs.headers = options.otherArgs.headers || {};
|
446 | options.otherArgs.headers['x-goog-request-params'] =
|
447 | gax.routingHeader.fromParams({
|
448 | snapshot: request.snapshot || '',
|
449 | });
|
450 | this.initialize();
|
451 | return this.innerApiCalls.getSnapshot(request, options, callback);
|
452 | }
|
453 | createSnapshot(request, optionsOrCallback, callback) {
|
454 | request = request || {};
|
455 | let options;
|
456 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
457 | callback = optionsOrCallback;
|
458 | options = {};
|
459 | }
|
460 | else {
|
461 | options = optionsOrCallback;
|
462 | }
|
463 | options = options || {};
|
464 | options.otherArgs = options.otherArgs || {};
|
465 | options.otherArgs.headers = options.otherArgs.headers || {};
|
466 | options.otherArgs.headers['x-goog-request-params'] =
|
467 | gax.routingHeader.fromParams({
|
468 | name: request.name || '',
|
469 | });
|
470 | this.initialize();
|
471 | return this.innerApiCalls.createSnapshot(request, options, callback);
|
472 | }
|
473 | updateSnapshot(request, optionsOrCallback, callback) {
|
474 | request = request || {};
|
475 | let options;
|
476 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
477 | callback = optionsOrCallback;
|
478 | options = {};
|
479 | }
|
480 | else {
|
481 | options = optionsOrCallback;
|
482 | }
|
483 | options = options || {};
|
484 | options.otherArgs = options.otherArgs || {};
|
485 | options.otherArgs.headers = options.otherArgs.headers || {};
|
486 | options.otherArgs.headers['x-goog-request-params'] =
|
487 | gax.routingHeader.fromParams({
|
488 | 'snapshot.name': request.snapshot.name || '',
|
489 | });
|
490 | this.initialize();
|
491 | return this.innerApiCalls.updateSnapshot(request, options, callback);
|
492 | }
|
493 | deleteSnapshot(request, optionsOrCallback, callback) {
|
494 | request = request || {};
|
495 | let options;
|
496 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
497 | callback = optionsOrCallback;
|
498 | options = {};
|
499 | }
|
500 | else {
|
501 | options = optionsOrCallback;
|
502 | }
|
503 | options = options || {};
|
504 | options.otherArgs = options.otherArgs || {};
|
505 | options.otherArgs.headers = options.otherArgs.headers || {};
|
506 | options.otherArgs.headers['x-goog-request-params'] =
|
507 | gax.routingHeader.fromParams({
|
508 | snapshot: request.snapshot || '',
|
509 | });
|
510 | this.initialize();
|
511 | return this.innerApiCalls.deleteSnapshot(request, options, callback);
|
512 | }
|
513 | seek(request, optionsOrCallback, callback) {
|
514 | request = request || {};
|
515 | let options;
|
516 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
517 | callback = optionsOrCallback;
|
518 | options = {};
|
519 | }
|
520 | else {
|
521 | options = optionsOrCallback;
|
522 | }
|
523 | options = options || {};
|
524 | options.otherArgs = options.otherArgs || {};
|
525 | options.otherArgs.headers = options.otherArgs.headers || {};
|
526 | options.otherArgs.headers['x-goog-request-params'] =
|
527 | gax.routingHeader.fromParams({
|
528 | subscription: request.subscription || '',
|
529 | });
|
530 | this.initialize();
|
531 | return this.innerApiCalls.seek(request, options, callback);
|
532 | }
|
533 | /**
|
534 | * Establishes a stream with the server, which sends messages down to the
|
535 | * client. The client streams acknowledgements and ack deadline modifications
|
536 | * back to the server. The server will close the stream and return the status
|
537 | * on any error. The server may close the stream with status `UNAVAILABLE` to
|
538 | * reassign server-side resources, in which case, the client should
|
539 | * re-establish the stream. Flow control can be achieved by configuring the
|
540 | * underlying RPC channel.
|
541 | *
|
542 | * @param {object} [options]
|
543 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
544 | * @returns {Stream}
|
545 | * An object stream which is both readable and writable. It accepts objects
|
546 | * representing [StreamingPullRequest]{@link google.pubsub.v1.StreamingPullRequest} for write() method, and
|
547 | * will emit objects representing [StreamingPullResponse]{@link google.pubsub.v1.StreamingPullResponse} on 'data' event asynchronously.
|
548 | * Please see the
|
549 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming)
|
550 | * for more details and examples.
|
551 | */
|
552 | streamingPull(options) {
|
553 | this.initialize();
|
554 | return this.innerApiCalls.streamingPull(null, options);
|
555 | }
|
556 | listSubscriptions(request, optionsOrCallback, callback) {
|
557 | request = request || {};
|
558 | let options;
|
559 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
560 | callback = optionsOrCallback;
|
561 | options = {};
|
562 | }
|
563 | else {
|
564 | options = optionsOrCallback;
|
565 | }
|
566 | options = options || {};
|
567 | options.otherArgs = options.otherArgs || {};
|
568 | options.otherArgs.headers = options.otherArgs.headers || {};
|
569 | options.otherArgs.headers['x-goog-request-params'] =
|
570 | gax.routingHeader.fromParams({
|
571 | project: request.project || '',
|
572 | });
|
573 | this.initialize();
|
574 | return this.innerApiCalls.listSubscriptions(request, options, callback);
|
575 | }
|
576 | /**
|
577 | * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
|
578 | * @param {Object} request
|
579 | * The request object that will be sent.
|
580 | * @param {string} request.project
|
581 | * Required. The name of the project in which to list subscriptions.
|
582 | * Format is `projects/{project-id}`.
|
583 | * @param {number} request.pageSize
|
584 | * Maximum number of subscriptions to return.
|
585 | * @param {string} request.pageToken
|
586 | * The value returned by the last `ListSubscriptionsResponse`; indicates that
|
587 | * this is a continuation of a prior `ListSubscriptions` call, and that the
|
588 | * system should return the next page of data.
|
589 | * @param {object} [options]
|
590 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
591 | * @returns {Stream}
|
592 | * An object stream which emits an object representing [Subscription]{@link google.pubsub.v1.Subscription} on 'data' event.
|
593 | * The client library will perform auto-pagination by default: it will call the API as many
|
594 | * times as needed. Note that it can affect your quota.
|
595 | * We recommend using `listSubscriptionsAsync()`
|
596 | * method described below for async iteration which you can stop as needed.
|
597 | * Please see the
|
598 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
599 | * for more details and examples.
|
600 | */
|
601 | listSubscriptionsStream(request, options) {
|
602 | request = request || {};
|
603 | options = options || {};
|
604 | options.otherArgs = options.otherArgs || {};
|
605 | options.otherArgs.headers = options.otherArgs.headers || {};
|
606 | options.otherArgs.headers['x-goog-request-params'] =
|
607 | gax.routingHeader.fromParams({
|
608 | project: request.project || '',
|
609 | });
|
610 | const defaultCallSettings = this._defaults['listSubscriptions'];
|
611 | const callSettings = defaultCallSettings.merge(options);
|
612 | this.initialize();
|
613 | return this.descriptors.page.listSubscriptions.createStream(this.innerApiCalls.listSubscriptions, request, callSettings);
|
614 | }
|
615 | /**
|
616 | * Equivalent to `listSubscriptions`, but returns an iterable object.
|
617 | *
|
618 | * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
|
619 | * @param {Object} request
|
620 | * The request object that will be sent.
|
621 | * @param {string} request.project
|
622 | * Required. The name of the project in which to list subscriptions.
|
623 | * Format is `projects/{project-id}`.
|
624 | * @param {number} request.pageSize
|
625 | * Maximum number of subscriptions to return.
|
626 | * @param {string} request.pageToken
|
627 | * The value returned by the last `ListSubscriptionsResponse`; indicates that
|
628 | * this is a continuation of a prior `ListSubscriptions` call, and that the
|
629 | * system should return the next page of data.
|
630 | * @param {object} [options]
|
631 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
632 | * @returns {Object}
|
633 | * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
|
634 | * When you iterate the returned iterable, each element will be an object representing
|
635 | * [Subscription]{@link google.pubsub.v1.Subscription}. The API will be called under the hood as needed, once per the page,
|
636 | * so you can stop the iteration when you don't need more results.
|
637 | * Please see the
|
638 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
639 | * for more details and examples.
|
640 | */
|
641 | listSubscriptionsAsync(request, options) {
|
642 | request = request || {};
|
643 | options = options || {};
|
644 | options.otherArgs = options.otherArgs || {};
|
645 | options.otherArgs.headers = options.otherArgs.headers || {};
|
646 | options.otherArgs.headers['x-goog-request-params'] =
|
647 | gax.routingHeader.fromParams({
|
648 | project: request.project || '',
|
649 | });
|
650 | const defaultCallSettings = this._defaults['listSubscriptions'];
|
651 | const callSettings = defaultCallSettings.merge(options);
|
652 | this.initialize();
|
653 | return this.descriptors.page.listSubscriptions.asyncIterate(this.innerApiCalls['listSubscriptions'], request, callSettings);
|
654 | }
|
655 | listSnapshots(request, optionsOrCallback, callback) {
|
656 | request = request || {};
|
657 | let options;
|
658 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
659 | callback = optionsOrCallback;
|
660 | options = {};
|
661 | }
|
662 | else {
|
663 | options = optionsOrCallback;
|
664 | }
|
665 | options = options || {};
|
666 | options.otherArgs = options.otherArgs || {};
|
667 | options.otherArgs.headers = options.otherArgs.headers || {};
|
668 | options.otherArgs.headers['x-goog-request-params'] =
|
669 | gax.routingHeader.fromParams({
|
670 | project: request.project || '',
|
671 | });
|
672 | this.initialize();
|
673 | return this.innerApiCalls.listSnapshots(request, options, callback);
|
674 | }
|
675 | /**
|
676 | * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
|
677 | * @param {Object} request
|
678 | * The request object that will be sent.
|
679 | * @param {string} request.project
|
680 | * Required. The name of the project in which to list snapshots.
|
681 | * Format is `projects/{project-id}`.
|
682 | * @param {number} request.pageSize
|
683 | * Maximum number of snapshots to return.
|
684 | * @param {string} request.pageToken
|
685 | * The value returned by the last `ListSnapshotsResponse`; indicates that this
|
686 | * is a continuation of a prior `ListSnapshots` call, and that the system
|
687 | * should return the next page of data.
|
688 | * @param {object} [options]
|
689 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
690 | * @returns {Stream}
|
691 | * An object stream which emits an object representing [Snapshot]{@link google.pubsub.v1.Snapshot} on 'data' event.
|
692 | * The client library will perform auto-pagination by default: it will call the API as many
|
693 | * times as needed. Note that it can affect your quota.
|
694 | * We recommend using `listSnapshotsAsync()`
|
695 | * method described below for async iteration which you can stop as needed.
|
696 | * Please see the
|
697 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
698 | * for more details and examples.
|
699 | */
|
700 | listSnapshotsStream(request, options) {
|
701 | request = request || {};
|
702 | options = options || {};
|
703 | options.otherArgs = options.otherArgs || {};
|
704 | options.otherArgs.headers = options.otherArgs.headers || {};
|
705 | options.otherArgs.headers['x-goog-request-params'] =
|
706 | gax.routingHeader.fromParams({
|
707 | project: request.project || '',
|
708 | });
|
709 | const defaultCallSettings = this._defaults['listSnapshots'];
|
710 | const callSettings = defaultCallSettings.merge(options);
|
711 | this.initialize();
|
712 | return this.descriptors.page.listSnapshots.createStream(this.innerApiCalls.listSnapshots, request, callSettings);
|
713 | }
|
714 | /**
|
715 | * Equivalent to `listSnapshots`, but returns an iterable object.
|
716 | *
|
717 | * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
|
718 | * @param {Object} request
|
719 | * The request object that will be sent.
|
720 | * @param {string} request.project
|
721 | * Required. The name of the project in which to list snapshots.
|
722 | * Format is `projects/{project-id}`.
|
723 | * @param {number} request.pageSize
|
724 | * Maximum number of snapshots to return.
|
725 | * @param {string} request.pageToken
|
726 | * The value returned by the last `ListSnapshotsResponse`; indicates that this
|
727 | * is a continuation of a prior `ListSnapshots` call, and that the system
|
728 | * should return the next page of data.
|
729 | * @param {object} [options]
|
730 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
731 | * @returns {Object}
|
732 | * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
|
733 | * When you iterate the returned iterable, each element will be an object representing
|
734 | * [Snapshot]{@link google.pubsub.v1.Snapshot}. The API will be called under the hood as needed, once per the page,
|
735 | * so you can stop the iteration when you don't need more results.
|
736 | * Please see the
|
737 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
738 | * for more details and examples.
|
739 | */
|
740 | listSnapshotsAsync(request, options) {
|
741 | request = request || {};
|
742 | options = options || {};
|
743 | options.otherArgs = options.otherArgs || {};
|
744 | options.otherArgs.headers = options.otherArgs.headers || {};
|
745 | options.otherArgs.headers['x-goog-request-params'] =
|
746 | gax.routingHeader.fromParams({
|
747 | project: request.project || '',
|
748 | });
|
749 | const defaultCallSettings = this._defaults['listSnapshots'];
|
750 | const callSettings = defaultCallSettings.merge(options);
|
751 | this.initialize();
|
752 | return this.descriptors.page.listSnapshots.asyncIterate(this.innerApiCalls['listSnapshots'], request, callSettings);
|
753 | }
|
754 | /**
|
755 | * Gets the access control policy for a resource. Returns an empty policy
|
756 | * if the resource exists and does not have a policy set.
|
757 | *
|
758 | * @param {Object} request
|
759 | * The request object that will be sent.
|
760 | * @param {string} request.resource
|
761 | * REQUIRED: The resource for which the policy is being requested.
|
762 | * See the operation documentation for the appropriate value for this field.
|
763 | * @param {Object} [request.options]
|
764 | * OPTIONAL: A `GetPolicyOptions` object for specifying options to
|
765 | * `GetIamPolicy`. This field is only used by Cloud IAM.
|
766 | *
|
767 | * This object should have the same structure as [GetPolicyOptions]{@link google.iam.v1.GetPolicyOptions}
|
768 | * @param {Object} [options]
|
769 | * Optional parameters. You can override the default settings for this call, e.g, timeout,
|
770 | * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
|
771 | * @param {function(?Error, ?Object)} [callback]
|
772 | * The function which will be called with the result of the API call.
|
773 | *
|
774 | * The second parameter to the callback is an object representing [Policy]{@link google.iam.v1.Policy}.
|
775 | * @returns {Promise} - The promise which resolves to an array.
|
776 | * The first element of the array is an object representing [Policy]{@link google.iam.v1.Policy}.
|
777 | * The promise has a method named "cancel" which cancels the ongoing API call.
|
778 | */
|
779 | getIamPolicy(request, options, callback) {
|
780 | return this.iamClient.getIamPolicy(request, options, callback);
|
781 | }
|
782 | /**
|
783 | * Returns permissions that a caller has on the specified resource. If the
|
784 | * resource does not exist, this will return an empty set of
|
785 | * permissions, not a NOT_FOUND error.
|
786 | *
|
787 | * Note: This operation is designed to be used for building
|
788 | * permission-aware UIs and command-line tools, not for authorization
|
789 | * checking. This operation may "fail open" without warning.
|
790 | *
|
791 | * @param {Object} request
|
792 | * The request object that will be sent.
|
793 | * @param {string} request.resource
|
794 | * REQUIRED: The resource for which the policy detail is being requested.
|
795 | * See the operation documentation for the appropriate value for this field.
|
796 | * @param {string[]} request.permissions
|
797 | * The set of permissions to check for the `resource`. Permissions with
|
798 | * wildcards (such as '*' or 'storage.*') are not allowed. For more
|
799 | * information see
|
800 | * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
|
801 | * @param {Object} [options]
|
802 | * Optional parameters. You can override the default settings for this call, e.g, timeout,
|
803 | * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
|
804 | * @param {function(?Error, ?Object)} [callback]
|
805 | * The function which will be called with the result of the API call.
|
806 | *
|
807 | * The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
808 | * @returns {Promise} - The promise which resolves to an array.
|
809 | * The first element of the array is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
810 | * The promise has a method named "cancel" which cancels the ongoing API call.
|
811 | */
|
812 | setIamPolicy(request, options, callback) {
|
813 | return this.iamClient.setIamPolicy(request, options, callback);
|
814 | }
|
815 | /**
|
816 | * Returns permissions that a caller has on the specified resource. If the
|
817 | * resource does not exist, this will return an empty set of
|
818 | * permissions, not a NOT_FOUND error.
|
819 | *
|
820 | * Note: This operation is designed to be used for building
|
821 | * permission-aware UIs and command-line tools, not for authorization
|
822 | * checking. This operation may "fail open" without warning.
|
823 | *
|
824 | * @param {Object} request
|
825 | * The request object that will be sent.
|
826 | * @param {string} request.resource
|
827 | * REQUIRED: The resource for which the policy detail is being requested.
|
828 | * See the operation documentation for the appropriate value for this field.
|
829 | * @param {string[]} request.permissions
|
830 | * The set of permissions to check for the `resource`. Permissions with
|
831 | * wildcards (such as '*' or 'storage.*') are not allowed. For more
|
832 | * information see
|
833 | * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
|
834 | * @param {Object} [options]
|
835 | * Optional parameters. You can override the default settings for this call, e.g, timeout,
|
836 | * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
|
837 | * @param {function(?Error, ?Object)} [callback]
|
838 | * The function which will be called with the result of the API call.
|
839 | *
|
840 | * The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
841 | * @returns {Promise} - The promise which resolves to an array.
|
842 | * The first element of the array is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
843 | * The promise has a method named "cancel" which cancels the ongoing API call.
|
844 | *
|
845 | */
|
846 | testIamPermissions(request, options, callback) {
|
847 | return this.iamClient.testIamPermissions(request, options, callback);
|
848 | }
|
849 | // --------------------
|
850 | // -- Path templates --
|
851 | // --------------------
|
852 | /**
|
853 | * Return a fully-qualified project resource name string.
|
854 | *
|
855 | * @param {string} project
|
856 | * @returns {string} Resource name string.
|
857 | */
|
858 | projectPath(project) {
|
859 | return this.pathTemplates.projectPathTemplate.render({
|
860 | project: project,
|
861 | });
|
862 | }
|
863 | /**
|
864 | * Parse the project from Project resource.
|
865 | *
|
866 | * @param {string} projectName
|
867 | * A fully-qualified path representing Project resource.
|
868 | * @returns {string} A string representing the project.
|
869 | */
|
870 | matchProjectFromProjectName(projectName) {
|
871 | return this.pathTemplates.projectPathTemplate.match(projectName).project;
|
872 | }
|
873 | /**
|
874 | * Return a fully-qualified projectTopic resource name string.
|
875 | *
|
876 | * @param {string} project
|
877 | * @param {string} topic
|
878 | * @returns {string} Resource name string.
|
879 | */
|
880 | projectTopicPath(project, topic) {
|
881 | return this.pathTemplates.projectTopicPathTemplate.render({
|
882 | project: project,
|
883 | topic: topic,
|
884 | });
|
885 | }
|
886 | /**
|
887 | * Parse the project from ProjectTopic resource.
|
888 | *
|
889 | * @param {string} projectTopicName
|
890 | * A fully-qualified path representing project_topic resource.
|
891 | * @returns {string} A string representing the project.
|
892 | */
|
893 | matchProjectFromProjectTopicName(projectTopicName) {
|
894 | return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName)
|
895 | .project;
|
896 | }
|
897 | /**
|
898 | * Parse the topic from ProjectTopic resource.
|
899 | *
|
900 | * @param {string} projectTopicName
|
901 | * A fully-qualified path representing project_topic resource.
|
902 | * @returns {string} A string representing the topic.
|
903 | */
|
904 | matchTopicFromProjectTopicName(projectTopicName) {
|
905 | return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName)
|
906 | .topic;
|
907 | }
|
908 | /**
|
909 | * Return a fully-qualified schema resource name string.
|
910 | *
|
911 | * @param {string} project
|
912 | * @param {string} schema
|
913 | * @returns {string} Resource name string.
|
914 | */
|
915 | schemaPath(project, schema) {
|
916 | return this.pathTemplates.schemaPathTemplate.render({
|
917 | project: project,
|
918 | schema: schema,
|
919 | });
|
920 | }
|
921 | /**
|
922 | * Parse the project from Schema resource.
|
923 | *
|
924 | * @param {string} schemaName
|
925 | * A fully-qualified path representing Schema resource.
|
926 | * @returns {string} A string representing the project.
|
927 | */
|
928 | matchProjectFromSchemaName(schemaName) {
|
929 | return this.pathTemplates.schemaPathTemplate.match(schemaName).project;
|
930 | }
|
931 | /**
|
932 | * Parse the schema from Schema resource.
|
933 | *
|
934 | * @param {string} schemaName
|
935 | * A fully-qualified path representing Schema resource.
|
936 | * @returns {string} A string representing the schema.
|
937 | */
|
938 | matchSchemaFromSchemaName(schemaName) {
|
939 | return this.pathTemplates.schemaPathTemplate.match(schemaName).schema;
|
940 | }
|
941 | /**
|
942 | * Return a fully-qualified snapshot resource name string.
|
943 | *
|
944 | * @param {string} project
|
945 | * @param {string} snapshot
|
946 | * @returns {string} Resource name string.
|
947 | */
|
948 | snapshotPath(project, snapshot) {
|
949 | return this.pathTemplates.snapshotPathTemplate.render({
|
950 | project: project,
|
951 | snapshot: snapshot,
|
952 | });
|
953 | }
|
954 | /**
|
955 | * Parse the project from Snapshot resource.
|
956 | *
|
957 | * @param {string} snapshotName
|
958 | * A fully-qualified path representing Snapshot resource.
|
959 | * @returns {string} A string representing the project.
|
960 | */
|
961 | matchProjectFromSnapshotName(snapshotName) {
|
962 | return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project;
|
963 | }
|
964 | /**
|
965 | * Parse the snapshot from Snapshot resource.
|
966 | *
|
967 | * @param {string} snapshotName
|
968 | * A fully-qualified path representing Snapshot resource.
|
969 | * @returns {string} A string representing the snapshot.
|
970 | */
|
971 | matchSnapshotFromSnapshotName(snapshotName) {
|
972 | return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot;
|
973 | }
|
974 | /**
|
975 | * Return a fully-qualified subscription resource name string.
|
976 | *
|
977 | * @param {string} project
|
978 | * @param {string} subscription
|
979 | * @returns {string} Resource name string.
|
980 | */
|
981 | subscriptionPath(project, subscription) {
|
982 | return this.pathTemplates.subscriptionPathTemplate.render({
|
983 | project: project,
|
984 | subscription: subscription,
|
985 | });
|
986 | }
|
987 | /**
|
988 | * Parse the project from Subscription resource.
|
989 | *
|
990 | * @param {string} subscriptionName
|
991 | * A fully-qualified path representing Subscription resource.
|
992 | * @returns {string} A string representing the project.
|
993 | */
|
994 | matchProjectFromSubscriptionName(subscriptionName) {
|
995 | return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName)
|
996 | .project;
|
997 | }
|
998 | /**
|
999 | * Parse the subscription from Subscription resource.
|
1000 | *
|
1001 | * @param {string} subscriptionName
|
1002 | * A fully-qualified path representing Subscription resource.
|
1003 | * @returns {string} A string representing the subscription.
|
1004 | */
|
1005 | matchSubscriptionFromSubscriptionName(subscriptionName) {
|
1006 | return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName)
|
1007 | .subscription;
|
1008 | }
|
1009 | /**
|
1010 | * Terminate the gRPC channel and close the client.
|
1011 | *
|
1012 | * The client will no longer be usable and all future behavior is undefined.
|
1013 | * @returns {Promise} A promise that resolves when the client is closed.
|
1014 | */
|
1015 | close() {
|
1016 | if (this.subscriberStub && !this._terminated) {
|
1017 | return this.subscriberStub.then(stub => {
|
1018 | this._terminated = true;
|
1019 | stub.close();
|
1020 | this.iamClient.close();
|
1021 | });
|
1022 | }
|
1023 | return Promise.resolve();
|
1024 | }
|
1025 | }
|
1026 | exports.SubscriberClient = SubscriberClient;
|
1027 | //# sourceMappingURL=subscriber_client.js.map |
\ | No newline at end of file |