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