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.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/main/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 | "rest"} [options.fallback] - Use HTTP fallback mode.
|
68 | * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
|
69 | * For more information, please check the
|
70 | * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
|
71 | */
|
72 | constructor(opts) {
|
73 | var _a, _b;
|
74 | this._terminated = false;
|
75 | this.descriptors = {
|
76 | page: {},
|
77 | stream: {},
|
78 | longrunning: {},
|
79 | batching: {},
|
80 | };
|
81 | // Ensure that options include all the required fields.
|
82 | const staticMembers = this.constructor;
|
83 | const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || staticMembers.servicePath;
|
84 | this._providedCustomServicePath = !!((opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint));
|
85 | const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port;
|
86 | const clientConfig = (_a = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _a !== void 0 ? _a : {};
|
87 | 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');
|
88 | opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
|
89 | // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
|
90 | if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
|
91 | opts['scopes'] = staticMembers.scopes;
|
92 | }
|
93 | // Choose either gRPC or proto-over-HTTP implementation of google-gax.
|
94 | this._gaxModule = opts.fallback ? gax.fallback : gax;
|
95 | // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
|
96 | this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
|
97 | // Save options to use in initialize() method.
|
98 | this._opts = opts;
|
99 | // Save the auth object to the client, for use by other methods.
|
100 | this.auth = this._gaxGrpc.auth;
|
101 | // Set useJWTAccessWithScope on the auth object.
|
102 | this.auth.useJWTAccessWithScope = true;
|
103 | // Set defaultServicePath on the auth object.
|
104 | this.auth.defaultServicePath = staticMembers.servicePath;
|
105 | // Set the default scopes in auth client if needed.
|
106 | if (servicePath === staticMembers.servicePath) {
|
107 | this.auth.defaultScopes = staticMembers.scopes;
|
108 | }
|
109 | this.iamClient = new google_gax_1.IamClient(this._gaxGrpc, opts);
|
110 | // Determine the client header string.
|
111 | const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
|
112 | if (typeof process !== 'undefined' && 'versions' in process) {
|
113 | clientHeader.push(`gl-node/${process.versions.node}`);
|
114 | }
|
115 | else {
|
116 | clientHeader.push(`gl-web/${this._gaxModule.version}`);
|
117 | }
|
118 | if (!opts.fallback) {
|
119 | clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
|
120 | }
|
121 | else if (opts.fallback === 'rest') {
|
122 | clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
|
123 | }
|
124 | if (opts.libName && opts.libVersion) {
|
125 | clientHeader.push(`${opts.libName}/${opts.libVersion}`);
|
126 | }
|
127 | // Load the applicable protos.
|
128 | this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
|
129 | // This API contains "path templates"; forward-slash-separated
|
130 | // identifiers to uniquely identify resources within the API.
|
131 | // Create useful helper objects for these.
|
132 | this.pathTemplates = {
|
133 | projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
|
134 | projectTopicPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/topics/{topic}'),
|
135 | schemaPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/schemas/{schema}'),
|
136 | snapshotPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/snapshots/{snapshot}'),
|
137 | subscriptionPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/subscriptions/{subscription}'),
|
138 | };
|
139 | // Some of the methods on this service return "paged" results,
|
140 | // (e.g. 50 results at a time, with tokens to get subsequent
|
141 | // pages). Denote the keys used for pagination and results.
|
142 | this.descriptors.page = {
|
143 | listTopics: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'topics'),
|
144 | listTopicSubscriptions: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'),
|
145 | listTopicSnapshots: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots'),
|
146 | };
|
147 | const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
|
148 | // Some methods on this API support automatically batching
|
149 | // requests; denote this.
|
150 | this.descriptors.batching = {
|
151 | publish: new this._gaxModule.BundleDescriptor('messages', ['topic'], 'message_ids', gax.createByteLengthFunction(
|
152 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
153 | protoFilesRoot.lookupType('google.pubsub.v1.PubsubMessage'))),
|
154 | };
|
155 | // Put together the default options sent with requests.
|
156 | this._defaults = this._gaxGrpc.constructSettings('google.pubsub.v1.Publisher', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
|
157 | // Set up a dictionary of "inner API calls"; the core implementation
|
158 | // of calling the API is handled in `google-gax`, with this code
|
159 | // merely providing the destination and request information.
|
160 | this.innerApiCalls = {};
|
161 | // Add a warn function to the client constructor so it can be easily tested.
|
162 | this.warn = gax.warn;
|
163 | }
|
164 | /**
|
165 | * Initialize the client.
|
166 | * Performs asynchronous operations (such as authentication) and prepares the client.
|
167 | * This function will be called automatically when any class method is called for the
|
168 | * first time, but if you need to initialize it before calling an actual method,
|
169 | * feel free to call initialize() directly.
|
170 | *
|
171 | * You can await on this method if you want to make sure the client is initialized.
|
172 | *
|
173 | * @returns {Promise} A promise that resolves to an authenticated service stub.
|
174 | */
|
175 | initialize() {
|
176 | var _a;
|
177 | // If the client stub promise is already initialized, return immediately.
|
178 | if (this.publisherStub) {
|
179 | return this.publisherStub;
|
180 | }
|
181 | // Put together the "service stub" for
|
182 | // google.pubsub.v1.Publisher.
|
183 | this.publisherStub = this._gaxGrpc.createStub(this._opts.fallback
|
184 | ? this._protos.lookupService('google.pubsub.v1.Publisher')
|
185 | : // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
186 | this._protos.google.pubsub.v1.Publisher, this._opts, this._providedCustomServicePath);
|
187 | // Iterate over each of the methods that the service provides
|
188 | // and create an API call method for each.
|
189 | const publisherStubMethods = [
|
190 | 'createTopic',
|
191 | 'updateTopic',
|
192 | 'publish',
|
193 | 'getTopic',
|
194 | 'listTopics',
|
195 | 'listTopicSubscriptions',
|
196 | 'listTopicSnapshots',
|
197 | 'deleteTopic',
|
198 | 'detachSubscription',
|
199 | ];
|
200 | for (const methodName of publisherStubMethods) {
|
201 | const callPromise = this.publisherStub.then(stub => (...args) => {
|
202 | if (this._terminated) {
|
203 | return Promise.reject('The client has already been closed.');
|
204 | }
|
205 | const func = stub[methodName];
|
206 | return func.apply(stub, args);
|
207 | }, (err) => () => {
|
208 | throw err;
|
209 | });
|
210 | const descriptor = this.descriptors.page[methodName] ||
|
211 | ((_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 | */
|
467 | listTopicsAsync(request, options) {
|
468 | request = request || {};
|
469 | options = options || {};
|
470 | options.otherArgs = options.otherArgs || {};
|
471 | options.otherArgs.headers = options.otherArgs.headers || {};
|
472 | options.otherArgs.headers['x-goog-request-params'] =
|
473 | gax.routingHeader.fromParams({
|
474 | project: request.project || '',
|
475 | });
|
476 | const defaultCallSettings = this._defaults['listTopics'];
|
477 | const callSettings = defaultCallSettings.merge(options);
|
478 | this.initialize();
|
479 | return this.descriptors.page.listTopics.asyncIterate(this.innerApiCalls['listTopics'], request, callSettings);
|
480 | }
|
481 | listTopicSubscriptions(request, optionsOrCallback, callback) {
|
482 | request = request || {};
|
483 | let options;
|
484 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
485 | callback = optionsOrCallback;
|
486 | options = {};
|
487 | }
|
488 | else {
|
489 | options = optionsOrCallback;
|
490 | }
|
491 | options = options || {};
|
492 | options.otherArgs = options.otherArgs || {};
|
493 | options.otherArgs.headers = options.otherArgs.headers || {};
|
494 | options.otherArgs.headers['x-goog-request-params'] =
|
495 | gax.routingHeader.fromParams({
|
496 | topic: request.topic || '',
|
497 | });
|
498 | this.initialize();
|
499 | return this.innerApiCalls.listTopicSubscriptions(request, options, callback);
|
500 | }
|
501 | /**
|
502 | * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
|
503 | * @param {Object} request
|
504 | * The request object that will be sent.
|
505 | * @param {string} request.topic
|
506 | * Required. The name of the topic that subscriptions are attached to.
|
507 | * Format is `projects/{project}/topics/{topic}`.
|
508 | * @param {number} request.pageSize
|
509 | * Maximum number of subscription names to return.
|
510 | * @param {string} request.pageToken
|
511 | * The value returned by the last `ListTopicSubscriptionsResponse`; indicates
|
512 | * that this is a continuation of a prior `ListTopicSubscriptions` call, and
|
513 | * that the system should return the next page of data.
|
514 | * @param {object} [options]
|
515 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
516 | * @returns {Stream}
|
517 | * An object stream which emits an object representing string on 'data' event.
|
518 | * The client library will perform auto-pagination by default: it will call the API as many
|
519 | * times as needed. Note that it can affect your quota.
|
520 | * We recommend using `listTopicSubscriptionsAsync()`
|
521 | * method described below for async iteration which you can stop as needed.
|
522 | * Please see the
|
523 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
524 | * for more details and examples.
|
525 | */
|
526 | listTopicSubscriptionsStream(request, options) {
|
527 | request = request || {};
|
528 | options = options || {};
|
529 | options.otherArgs = options.otherArgs || {};
|
530 | options.otherArgs.headers = options.otherArgs.headers || {};
|
531 | options.otherArgs.headers['x-goog-request-params'] =
|
532 | gax.routingHeader.fromParams({
|
533 | topic: request.topic || '',
|
534 | });
|
535 | const defaultCallSettings = this._defaults['listTopicSubscriptions'];
|
536 | const callSettings = defaultCallSettings.merge(options);
|
537 | this.initialize();
|
538 | return this.descriptors.page.listTopicSubscriptions.createStream(this.innerApiCalls.listTopicSubscriptions, request, callSettings);
|
539 | }
|
540 | /**
|
541 | * Equivalent to `listTopicSubscriptions`, but returns an iterable object.
|
542 | *
|
543 | * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
|
544 | * @param {Object} request
|
545 | * The request object that will be sent.
|
546 | * @param {string} request.topic
|
547 | * Required. The name of the topic that subscriptions are attached to.
|
548 | * Format is `projects/{project}/topics/{topic}`.
|
549 | * @param {number} request.pageSize
|
550 | * Maximum number of subscription names to return.
|
551 | * @param {string} request.pageToken
|
552 | * The value returned by the last `ListTopicSubscriptionsResponse`; indicates
|
553 | * that this is a continuation of a prior `ListTopicSubscriptions` call, and
|
554 | * that the system should return the next page of data.
|
555 | * @param {object} [options]
|
556 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
557 | * @returns {Object}
|
558 | * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
|
559 | * When you iterate the returned iterable, each element will be an object representing
|
560 | * string. The API will be called under the hood as needed, once per the page,
|
561 | * so you can stop the iteration when you don't need more results.
|
562 | * Please see the
|
563 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
564 | * for more details and examples.
|
565 | */
|
566 | listTopicSubscriptionsAsync(request, options) {
|
567 | request = request || {};
|
568 | options = options || {};
|
569 | options.otherArgs = options.otherArgs || {};
|
570 | options.otherArgs.headers = options.otherArgs.headers || {};
|
571 | options.otherArgs.headers['x-goog-request-params'] =
|
572 | gax.routingHeader.fromParams({
|
573 | topic: request.topic || '',
|
574 | });
|
575 | const defaultCallSettings = this._defaults['listTopicSubscriptions'];
|
576 | const callSettings = defaultCallSettings.merge(options);
|
577 | this.initialize();
|
578 | return this.descriptors.page.listTopicSubscriptions.asyncIterate(this.innerApiCalls['listTopicSubscriptions'], request, callSettings);
|
579 | }
|
580 | listTopicSnapshots(request, optionsOrCallback, callback) {
|
581 | request = request || {};
|
582 | let options;
|
583 | if (typeof optionsOrCallback === 'function' && callback === undefined) {
|
584 | callback = optionsOrCallback;
|
585 | options = {};
|
586 | }
|
587 | else {
|
588 | options = optionsOrCallback;
|
589 | }
|
590 | options = options || {};
|
591 | options.otherArgs = options.otherArgs || {};
|
592 | options.otherArgs.headers = options.otherArgs.headers || {};
|
593 | options.otherArgs.headers['x-goog-request-params'] =
|
594 | gax.routingHeader.fromParams({
|
595 | topic: request.topic || '',
|
596 | });
|
597 | this.initialize();
|
598 | return this.innerApiCalls.listTopicSnapshots(request, options, callback);
|
599 | }
|
600 | /**
|
601 | * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
|
602 | * @param {Object} request
|
603 | * The request object that will be sent.
|
604 | * @param {string} request.topic
|
605 | * Required. The name of the topic that snapshots are attached to.
|
606 | * Format is `projects/{project}/topics/{topic}`.
|
607 | * @param {number} request.pageSize
|
608 | * Maximum number of snapshot names to return.
|
609 | * @param {string} request.pageToken
|
610 | * The value returned by the last `ListTopicSnapshotsResponse`; indicates
|
611 | * that this is a continuation of a prior `ListTopicSnapshots` call, and
|
612 | * that the system should return the next page of data.
|
613 | * @param {object} [options]
|
614 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
615 | * @returns {Stream}
|
616 | * An object stream which emits an object representing string on 'data' event.
|
617 | * The client library will perform auto-pagination by default: it will call the API as many
|
618 | * times as needed. Note that it can affect your quota.
|
619 | * We recommend using `listTopicSnapshotsAsync()`
|
620 | * method described below for async iteration which you can stop as needed.
|
621 | * Please see the
|
622 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
623 | * for more details and examples.
|
624 | */
|
625 | listTopicSnapshotsStream(request, options) {
|
626 | request = request || {};
|
627 | options = options || {};
|
628 | options.otherArgs = options.otherArgs || {};
|
629 | options.otherArgs.headers = options.otherArgs.headers || {};
|
630 | options.otherArgs.headers['x-goog-request-params'] =
|
631 | gax.routingHeader.fromParams({
|
632 | topic: request.topic || '',
|
633 | });
|
634 | const defaultCallSettings = this._defaults['listTopicSnapshots'];
|
635 | const callSettings = defaultCallSettings.merge(options);
|
636 | this.initialize();
|
637 | return this.descriptors.page.listTopicSnapshots.createStream(this.innerApiCalls.listTopicSnapshots, request, callSettings);
|
638 | }
|
639 | /**
|
640 | * Equivalent to `listTopicSnapshots`, but returns an iterable object.
|
641 | *
|
642 | * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
|
643 | * @param {Object} request
|
644 | * The request object that will be sent.
|
645 | * @param {string} request.topic
|
646 | * Required. The name of the topic that snapshots are attached to.
|
647 | * Format is `projects/{project}/topics/{topic}`.
|
648 | * @param {number} request.pageSize
|
649 | * Maximum number of snapshot names to return.
|
650 | * @param {string} request.pageToken
|
651 | * The value returned by the last `ListTopicSnapshotsResponse`; indicates
|
652 | * that this is a continuation of a prior `ListTopicSnapshots` call, and
|
653 | * that the system should return the next page of data.
|
654 | * @param {object} [options]
|
655 | * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
656 | * @returns {Object}
|
657 | * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
|
658 | * When you iterate the returned iterable, each element will be an object representing
|
659 | * string. The API will be called under the hood as needed, once per the page,
|
660 | * so you can stop the iteration when you don't need more results.
|
661 | * Please see the
|
662 | * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
|
663 | * for more details and examples.
|
664 | */
|
665 | listTopicSnapshotsAsync(request, options) {
|
666 | request = request || {};
|
667 | options = options || {};
|
668 | options.otherArgs = options.otherArgs || {};
|
669 | options.otherArgs.headers = options.otherArgs.headers || {};
|
670 | options.otherArgs.headers['x-goog-request-params'] =
|
671 | gax.routingHeader.fromParams({
|
672 | topic: request.topic || '',
|
673 | });
|
674 | const defaultCallSettings = this._defaults['listTopicSnapshots'];
|
675 | const callSettings = defaultCallSettings.merge(options);
|
676 | this.initialize();
|
677 | return this.descriptors.page.listTopicSnapshots.asyncIterate(this.innerApiCalls['listTopicSnapshots'], request, callSettings);
|
678 | }
|
679 | /**
|
680 | * Gets the access control policy for a resource. Returns an empty policy
|
681 | * if the resource exists and does not have a policy set.
|
682 | *
|
683 | * @param {Object} request
|
684 | * The request object that will be sent.
|
685 | * @param {string} request.resource
|
686 | * REQUIRED: The resource for which the policy is being requested.
|
687 | * See the operation documentation for the appropriate value for this field.
|
688 | * @param {Object} [request.options]
|
689 | * OPTIONAL: A `GetPolicyOptions` object for specifying options to
|
690 | * `GetIamPolicy`. This field is only used by Cloud IAM.
|
691 | *
|
692 | * This object should have the same structure as [GetPolicyOptions]{@link google.iam.v1.GetPolicyOptions}
|
693 | * @param {Object} [options]
|
694 | * Optional parameters. You can override the default settings for this call, e.g, timeout,
|
695 | * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
|
696 | * @param {function(?Error, ?Object)} [callback]
|
697 | * The function which will be called with the result of the API call.
|
698 | *
|
699 | * The second parameter to the callback is an object representing [Policy]{@link google.iam.v1.Policy}.
|
700 | * @returns {Promise} - The promise which resolves to an array.
|
701 | * The first element of the array is an object representing [Policy]{@link google.iam.v1.Policy}.
|
702 | * The promise has a method named "cancel" which cancels the ongoing API call.
|
703 | */
|
704 | getIamPolicy(request, options, callback) {
|
705 | return this.iamClient.getIamPolicy(request, options, callback);
|
706 | }
|
707 | /**
|
708 | * Returns permissions that a caller has on the specified resource. If the
|
709 | * resource does not exist, this will return an empty set of
|
710 | * permissions, not a NOT_FOUND error.
|
711 | *
|
712 | * Note: This operation is designed to be used for building
|
713 | * permission-aware UIs and command-line tools, not for authorization
|
714 | * checking. This operation may "fail open" without warning.
|
715 | *
|
716 | * @param {Object} request
|
717 | * The request object that will be sent.
|
718 | * @param {string} request.resource
|
719 | * REQUIRED: The resource for which the policy detail is being requested.
|
720 | * See the operation documentation for the appropriate value for this field.
|
721 | * @param {string[]} request.permissions
|
722 | * The set of permissions to check for the `resource`. Permissions with
|
723 | * wildcards (such as '*' or 'storage.*') are not allowed. For more
|
724 | * information see
|
725 | * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
|
726 | * @param {Object} [options]
|
727 | * Optional parameters. You can override the default settings for this call, e.g, timeout,
|
728 | * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
|
729 | * @param {function(?Error, ?Object)} [callback]
|
730 | * The function which will be called with the result of the API call.
|
731 | *
|
732 | * The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
733 | * @returns {Promise} - The promise which resolves to an array.
|
734 | * The first element of the array is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
735 | * The promise has a method named "cancel" which cancels the ongoing API call.
|
736 | */
|
737 | setIamPolicy(request, options, callback) {
|
738 | return this.iamClient.setIamPolicy(request, options, callback);
|
739 | }
|
740 | /**
|
741 | * Returns permissions that a caller has on the specified resource. If the
|
742 | * resource does not exist, this will return an empty set of
|
743 | * permissions, not a NOT_FOUND error.
|
744 | *
|
745 | * Note: This operation is designed to be used for building
|
746 | * permission-aware UIs and command-line tools, not for authorization
|
747 | * checking. This operation may "fail open" without warning.
|
748 | *
|
749 | * @param {Object} request
|
750 | * The request object that will be sent.
|
751 | * @param {string} request.resource
|
752 | * REQUIRED: The resource for which the policy detail is being requested.
|
753 | * See the operation documentation for the appropriate value for this field.
|
754 | * @param {string[]} request.permissions
|
755 | * The set of permissions to check for the `resource`. Permissions with
|
756 | * wildcards (such as '*' or 'storage.*') are not allowed. For more
|
757 | * information see
|
758 | * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
|
759 | * @param {Object} [options]
|
760 | * Optional parameters. You can override the default settings for this call, e.g, timeout,
|
761 | * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html} for the details.
|
762 | * @param {function(?Error, ?Object)} [callback]
|
763 | * The function which will be called with the result of the API call.
|
764 | *
|
765 | * The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
766 | * @returns {Promise} - The promise which resolves to an array.
|
767 | * The first element of the array is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
|
768 | * The promise has a method named "cancel" which cancels the ongoing API call.
|
769 | *
|
770 | */
|
771 | testIamPermissions(request, options, callback) {
|
772 | return this.iamClient.testIamPermissions(request, options, callback);
|
773 | }
|
774 | // --------------------
|
775 | // -- Path templates --
|
776 | // --------------------
|
777 | /**
|
778 | * Return a fully-qualified project resource name string.
|
779 | *
|
780 | * @param {string} project
|
781 | * @returns {string} Resource name string.
|
782 | */
|
783 | projectPath(project) {
|
784 | return this.pathTemplates.projectPathTemplate.render({
|
785 | project: project,
|
786 | });
|
787 | }
|
788 | /**
|
789 | * Parse the project from Project resource.
|
790 | *
|
791 | * @param {string} projectName
|
792 | * A fully-qualified path representing Project resource.
|
793 | * @returns {string} A string representing the project.
|
794 | */
|
795 | matchProjectFromProjectName(projectName) {
|
796 | return this.pathTemplates.projectPathTemplate.match(projectName).project;
|
797 | }
|
798 | /**
|
799 | * Return a fully-qualified projectTopic resource name string.
|
800 | *
|
801 | * @param {string} project
|
802 | * @param {string} topic
|
803 | * @returns {string} Resource name string.
|
804 | */
|
805 | projectTopicPath(project, topic) {
|
806 | return this.pathTemplates.projectTopicPathTemplate.render({
|
807 | project: project,
|
808 | topic: topic,
|
809 | });
|
810 | }
|
811 | /**
|
812 | * Parse the project from ProjectTopic resource.
|
813 | *
|
814 | * @param {string} projectTopicName
|
815 | * A fully-qualified path representing project_topic resource.
|
816 | * @returns {string} A string representing the project.
|
817 | */
|
818 | matchProjectFromProjectTopicName(projectTopicName) {
|
819 | return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName)
|
820 | .project;
|
821 | }
|
822 | /**
|
823 | * Parse the topic from ProjectTopic resource.
|
824 | *
|
825 | * @param {string} projectTopicName
|
826 | * A fully-qualified path representing project_topic resource.
|
827 | * @returns {string} A string representing the topic.
|
828 | */
|
829 | matchTopicFromProjectTopicName(projectTopicName) {
|
830 | return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName)
|
831 | .topic;
|
832 | }
|
833 | /**
|
834 | * Return a fully-qualified schema resource name string.
|
835 | *
|
836 | * @param {string} project
|
837 | * @param {string} schema
|
838 | * @returns {string} Resource name string.
|
839 | */
|
840 | schemaPath(project, schema) {
|
841 | return this.pathTemplates.schemaPathTemplate.render({
|
842 | project: project,
|
843 | schema: schema,
|
844 | });
|
845 | }
|
846 | /**
|
847 | * Parse the project from Schema resource.
|
848 | *
|
849 | * @param {string} schemaName
|
850 | * A fully-qualified path representing Schema resource.
|
851 | * @returns {string} A string representing the project.
|
852 | */
|
853 | matchProjectFromSchemaName(schemaName) {
|
854 | return this.pathTemplates.schemaPathTemplate.match(schemaName).project;
|
855 | }
|
856 | /**
|
857 | * Parse the schema from Schema resource.
|
858 | *
|
859 | * @param {string} schemaName
|
860 | * A fully-qualified path representing Schema resource.
|
861 | * @returns {string} A string representing the schema.
|
862 | */
|
863 | matchSchemaFromSchemaName(schemaName) {
|
864 | return this.pathTemplates.schemaPathTemplate.match(schemaName).schema;
|
865 | }
|
866 | /**
|
867 | * Return a fully-qualified snapshot resource name string.
|
868 | *
|
869 | * @param {string} project
|
870 | * @param {string} snapshot
|
871 | * @returns {string} Resource name string.
|
872 | */
|
873 | snapshotPath(project, snapshot) {
|
874 | return this.pathTemplates.snapshotPathTemplate.render({
|
875 | project: project,
|
876 | snapshot: snapshot,
|
877 | });
|
878 | }
|
879 | /**
|
880 | * Parse the project from Snapshot resource.
|
881 | *
|
882 | * @param {string} snapshotName
|
883 | * A fully-qualified path representing Snapshot resource.
|
884 | * @returns {string} A string representing the project.
|
885 | */
|
886 | matchProjectFromSnapshotName(snapshotName) {
|
887 | return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project;
|
888 | }
|
889 | /**
|
890 | * Parse the snapshot from Snapshot resource.
|
891 | *
|
892 | * @param {string} snapshotName
|
893 | * A fully-qualified path representing Snapshot resource.
|
894 | * @returns {string} A string representing the snapshot.
|
895 | */
|
896 | matchSnapshotFromSnapshotName(snapshotName) {
|
897 | return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot;
|
898 | }
|
899 | /**
|
900 | * Return a fully-qualified subscription resource name string.
|
901 | *
|
902 | * @param {string} project
|
903 | * @param {string} subscription
|
904 | * @returns {string} Resource name string.
|
905 | */
|
906 | subscriptionPath(project, subscription) {
|
907 | return this.pathTemplates.subscriptionPathTemplate.render({
|
908 | project: project,
|
909 | subscription: subscription,
|
910 | });
|
911 | }
|
912 | /**
|
913 | * Parse the project from Subscription resource.
|
914 | *
|
915 | * @param {string} subscriptionName
|
916 | * A fully-qualified path representing Subscription resource.
|
917 | * @returns {string} A string representing the project.
|
918 | */
|
919 | matchProjectFromSubscriptionName(subscriptionName) {
|
920 | return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName)
|
921 | .project;
|
922 | }
|
923 | /**
|
924 | * Parse the subscription from Subscription resource.
|
925 | *
|
926 | * @param {string} subscriptionName
|
927 | * A fully-qualified path representing Subscription resource.
|
928 | * @returns {string} A string representing the subscription.
|
929 | */
|
930 | matchSubscriptionFromSubscriptionName(subscriptionName) {
|
931 | return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName)
|
932 | .subscription;
|
933 | }
|
934 | /**
|
935 | * Terminate the gRPC channel and close the client.
|
936 | *
|
937 | * The client will no longer be usable and all future behavior is undefined.
|
938 | * @returns {Promise} A promise that resolves when the client is closed.
|
939 | */
|
940 | close() {
|
941 | if (this.publisherStub && !this._terminated) {
|
942 | return this.publisherStub.then(stub => {
|
943 | this._terminated = true;
|
944 | stub.close();
|
945 | this.iamClient.close();
|
946 | });
|
947 | }
|
948 | return Promise.resolve();
|
949 | }
|
950 | }
|
951 | exports.PublisherClient = PublisherClient;
|
952 | //# sourceMappingURL=publisher_client.js.map |
\ | No newline at end of file |