UNPKG

32.4 kBTypeScriptView Raw
1/*!
2 * Copyright 2014 Google Inc. All Rights Reserved.
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 * http://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/// <reference types="node" />
17import { GoogleAuth } from 'google-auth-library';
18import * as gax from 'google-gax';
19import { Schema, SchemaType, ISchema, SchemaView } from './schema';
20import { Snapshot } from './snapshot';
21import { Subscription, SubscriptionOptions, CreateSubscriptionOptions, CreateSubscriptionCallback, CreateSubscriptionResponse, DetachSubscriptionCallback, DetachSubscriptionResponse } from './subscription';
22import { Topic, GetTopicSubscriptionsCallback, GetTopicSubscriptionsResponse, CreateTopicCallback, CreateTopicResponse, TopicMetadata } from './topic';
23import { PublishOptions } from './publisher';
24import { CallOptions } from 'google-gax';
25import { Transform } from 'stream';
26import { google } from '../protos/protos';
27import { SchemaServiceClient } from './v1';
28export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
29export interface ClientConfig extends gax.GrpcClientOptions {
30 apiEndpoint?: string;
31 servicePath?: string;
32 port?: string | number;
33 sslCreds?: gax.grpc.ChannelCredentials;
34}
35export interface PageOptions {
36 gaxOpts?: CallOptions;
37 pageSize?: number;
38 pageToken?: string;
39 autoPaginate?: boolean;
40}
41export declare type GetSnapshotsCallback = RequestCallback<Snapshot, google.pubsub.v1.IListSnapshotsResponse>;
42export declare type GetSnapshotsResponse = PagedResponse<Snapshot, google.pubsub.v1.IListSnapshotsResponse>;
43export declare type GetSubscriptionsOptions = PageOptions & {
44 topic?: string | Topic;
45};
46declare type GetAllSubscriptionsCallback = RequestCallback<Subscription, google.pubsub.v1.IListSubscriptionsResponse>;
47declare type GetAllSubscriptionsResponse = PagedResponse<Subscription, google.pubsub.v1.IListSubscriptionsResponse>;
48export declare type GetSubscriptionsCallback = GetAllSubscriptionsCallback | GetTopicSubscriptionsCallback;
49export declare type GetSubscriptionsResponse = GetAllSubscriptionsResponse | GetTopicSubscriptionsResponse;
50export declare type GetTopicsCallback = RequestCallback<Topic, google.pubsub.v1.IListTopicsResponse>;
51export declare type GetTopicsResponse = PagedResponse<Topic, google.pubsub.v1.IListTopicsResponse>;
52export declare type EmptyCallback = RequestCallback<google.protobuf.IEmpty>;
53export declare type EmptyResponse = [google.protobuf.IEmpty];
54export declare type ExistsCallback = RequestCallback<boolean>;
55export declare type ExistsResponse = [boolean];
56export declare type DetachedCallback = RequestCallback<boolean>;
57export declare type DetachedResponse = [boolean];
58export interface GetClientConfig {
59 client: 'PublisherClient' | 'SubscriberClient';
60}
61export interface RequestConfig extends GetClientConfig {
62 method: string;
63 reqOpts?: object;
64 gaxOpts?: CallOptions;
65}
66export interface ResourceCallback<Resource, Response> {
67 (err: gax.grpc.ServiceError | null, resource?: Resource | null, response?: Response | null): void;
68}
69export declare type RequestCallback<T, R = void> = R extends void ? NormalCallback<T> : PagedCallback<T, R>;
70export interface NormalCallback<TResponse> {
71 (err: gax.grpc.ServiceError | null, res?: TResponse | null): void;
72}
73export interface PagedCallback<Item, Response> {
74 (err: gax.grpc.ServiceError | null, results?: Item[] | null, nextQuery?: {} | null, response?: Response | null): void;
75}
76export declare type PagedResponse<Item, Response> = [Item[]] | [Item[], {} | null, Response];
77export declare type ObjectStream<O> = {
78 addListener(event: 'data', listener: (data: O) => void): ObjectStream<O>;
79 emit(event: 'data', data: O): boolean;
80 on(event: 'data', listener: (data: O) => void): ObjectStream<O>;
81 once(event: 'data', listener: (data: O) => void): ObjectStream<O>;
82 prependListener(event: 'data', listener: (data: O) => void): ObjectStream<O>;
83 prependOnceListener(event: 'data', listener: (data: O) => void): ObjectStream<O>;
84} & Transform;
85interface GetClientCallback {
86 (err: Error | null, gaxClient?: gax.ClientStub): void;
87}
88/**
89 * @typedef {object} ClientConfig
90 * @property {string} [projectId] The project ID from the Google Developer's
91 * Console, e.g. 'grape-spaceship-123'. We will also check the environment
92 * variable `GCLOUD_PROJECT` for your project ID. If your app is running in
93 * an environment which supports {@link
94 * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
95 * Application Default Credentials}, your project ID will be detected
96 * automatically.
97 * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key
98 * downloaded from the Google Developers Console. If you provide a path to a
99 * JSON file, the `projectId` option above is not necessary. NOTE: .pem and
100 * .p12 require you to specify the `email` option as well.
101 * @property {string} [apiEndpoint] The `apiEndpoint` from options will set the
102 * host. If not set, the `PUBSUB_EMULATOR_HOST` environment variable from the
103 * gcloud SDK is honored. We also check the `CLOUD_API_ENDPOINT_OVERRIDES_PUBSUB`
104 * environment variable used by `gcloud alpha pubsub`. Otherwise the actual API
105 * endpoint will be used. Note that if the URL doesn't end in '.googleapis.com',
106 * we will assume that it's an emulator and disable strict SSL checks.
107 * @property {string} [email] Account email address. Required when using a .pem
108 * or .p12 keyFilename.
109 * @property {object} [credentials] Credentials object.
110 * @property {string} [credentials.client_email]
111 * @property {string} [credentials.private_key]
112 * @property {boolean} [autoRetry=true] Automatically retry requests if the
113 * response is related to rate limits or certain intermittent server errors.
114 * We will exponentially backoff subsequent requests by default.
115 * @property {Constructor} [promise] Custom promise module to use instead of
116 * native Promises.
117 */
118/**
119 * [Cloud Pub/Sub](https://developers.google.com/pubsub/overview) is a
120 * reliable, many-to-many, asynchronous messaging service from Cloud
121 * Platform.
122 *
123 * @class
124 *
125 * @see [Cloud Pub/Sub overview]{@link https://developers.google.com/pubsub/overview}
126 *
127 * @param {ClientConfig} [options] Configuration options.
128 *
129 * @example Import the client library
130 * ```
131 * const {PubSub} = require('@google-cloud/pubsub');
132 *
133 * ```
134 * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
135 * ```
136 * const pubsub = new PubSub();
137 *
138 * ```
139 * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
140 * ```
141 * const pubsub = new PubSub({
142 * projectId: 'your-project-id',
143 * keyFilename: '/path/to/keyfile.json'
144 * });
145 *
146 * ```
147 * @example <caption>include:samples/quickstart.js</caption>
148 * region_tag:pubsub_quickstart_create_topic
149 * Full quickstart example:
150 */
151export declare class PubSub {
152 options: ClientConfig;
153 isEmulator: boolean;
154 api: {
155 [key: string]: gax.ClientStub;
156 };
157 auth: GoogleAuth;
158 projectId: string;
159 name?: string;
160 Promise?: PromiseConstructor;
161 getSubscriptionsStream: () => ObjectStream<Subscription>;
162 getSnapshotsStream: () => ObjectStream<Snapshot>;
163 getTopicsStream: () => ObjectStream<Topic>;
164 isOpen: boolean;
165 private schemaClient?;
166 constructor(options?: ClientConfig);
167 /**
168 * Returns true if we have actually resolved the full project name.
169 *
170 * @returns {boolean} true if the name is resolved.
171 */
172 get isIdResolved(): boolean;
173 /**
174 * Closes out this object, releasing any server connections. Note that once
175 * you close a PubSub object, it may not be used again. Any pending operations
176 * (e.g. queued publish messages) will fail. If you have topic or subscription
177 * objects that may have pending operations, you should call close() on those
178 * first if you want any pending messages to be delivered correctly. The
179 * PubSub class doesn't track those.
180 *
181 * @callback EmptyCallback
182 * @returns {Promise<void>}
183 */
184 close(): Promise<void>;
185 close(callback: EmptyCallback): void;
186 /**
187 * Create a schema in the project.
188 *
189 * @see [Schemas: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/create}
190 * @see {@link Schema#create}
191 *
192 * @throws {Error} If a schema ID or name is not provided.
193 * @throws {Error} If an invalid SchemaType is provided.
194 * @throws {Error} If an invalid schema definition is provided.
195 *
196 * @param {string} schemaId The name or ID of the subscription.
197 * @param {SchemaType} type The type of the schema (Protobuf, Avro, etc).
198 * @param {string} definition The text describing the schema in terms of the type.
199 * @param {object} [options] Request configuration options, outlined
200 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
201 * @returns {Promise<Schema>}
202 *
203 * @example Create a schema.
204 * ```
205 * const {PubSub} = require('@google-cloud/pubsub');
206 * const pubsub = new PubSub();
207 *
208 * await pubsub.createSchema(
209 * 'messageType',
210 * SchemaTypes.Avro,
211 * '{...avro definition...}'
212 * );
213 * ```
214 */
215 createSchema(schemaId: string, type: SchemaType, definition: string, gaxOpts?: CallOptions): Promise<Schema>;
216 /**
217 * @typedef {array} CreateSubscriptionResponse
218 * @property {Subscription} 0 The new {@link Subscription}.
219 * @property {object} 1 The full API response.
220 */
221 /**
222 * @callback CreateSubscriptionCallback
223 * @param {?Error} err Request error, if any.
224 * @param {Subscription} Subscription
225 * @param {object} apiResponse The full API response.
226 */
227 /**
228 * Options for creating a subscription.
229 *
230 * See a [Subscription
231 * resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).
232 *
233 * @typedef {object} CreateSubscriptionRequest
234 * @property {DeadLetterPolicy} [deadLetterPolicy] A policy that specifies the
235 * conditions for dead lettering messages in this subscription.
236 * @property {object} [flowControl] Flow control configurations for
237 * receiving messages. Note that these options do not persist across
238 * subscription instances.
239 * @property {number} [flowControl.maxBytes] The maximum number of bytes
240 * in un-acked messages to allow before the subscription pauses incoming
241 * messages. Defaults to 20% of free memory.
242 * @property {number} [flowControl.maxMessages=Infinity] The maximum number
243 * of un-acked messages to allow before the subscription pauses incoming
244 * messages.
245 * @property {object} [gaxOpts] Request configuration options, outlined
246 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
247 * @property {number|google.protobuf.Duration} [messageRetentionDuration] Set
248 * this to override the default duration of 7 days. This value is expected
249 * in seconds. Acceptable values are in the range of 10 minutes and 7
250 * days.
251 * @property {string} [pushEndpoint] A URL to a custom endpoint that
252 * messages should be pushed to.
253 * @property {object} [oidcToken] If specified, Pub/Sub will generate and
254 * attach an OIDC JWT token as an `Authorization` header in the HTTP
255 * request for every pushed message. This object should have the same
256 * structure as [OidcToken]{@link google.pubsub.v1.OidcToken}
257 * @property {boolean} [retainAckedMessages=false] If set, acked messages
258 * are retained in the subscription's backlog for the length of time
259 * specified by `options.messageRetentionDuration`.
260 * @property {ExpirationPolicy} [expirationPolicy] A policy that specifies
261 * the conditions for this subscription's expiration.
262 */
263 /**
264 * Create a subscription to a topic.
265 *
266 * @see [Subscriptions: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create}
267 * @see {@link Topic#createSubscription}
268 *
269 * @throws {Error} If a Topic instance or topic name is not provided.
270 * @throws {Error} If a subscription name is not provided.
271 *
272 * @param {Topic|string} topic The Topic to create a subscription to.
273 * @param {string} name The name of the subscription.
274 * @param {CreateSubscriptionRequest} [options] See a [Subscription resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).
275 * @param {CreateSubscriptionCallback} [callback] Callback function.
276 * @returns {Promise<CreateSubscriptionResponse>}
277 *
278 * @example Subscribe to a topic.
279 * ```
280 * const {PubSub} = require('@google-cloud/pubsub');
281 * const pubsub = new PubSub();
282 *
283 * const topic = 'messageCenter';
284 * const name = 'newMessages';
285 *
286 * const callback = function(err, subscription, apiResponse) {};
287 *
288 * pubsub.createSubscription(topic, name, callback);
289 *
290 * ```
291 * @example If the callback is omitted, we'll return a Promise.
292 * ```
293 * pubsub.createSubscription(topic, name)
294 * .then(function(data) {
295 * const subscription = data[0];
296 * const apiResponse = data[1];
297 * });
298 * ```
299 */
300 createSubscription(topic: Topic | string, name: string, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
301 createSubscription(topic: Topic | string, name: string, callback: CreateSubscriptionCallback): void;
302 createSubscription(topic: Topic | string, name: string, options: CreateSubscriptionOptions, callback: CreateSubscriptionCallback): void;
303 /**
304 * @typedef {array} CreateTopicResponse
305 * @property {Topic} 0 The new {@link Topic}.
306 * @property {object} 1 The full API response.
307 */
308 /**
309 * @callback CreateTopicCallback
310 * @param {?Error} err Request error, if any.
311 * @param {Topic} topic The new {@link Topic}.
312 * @param {object} apiResponse The full API response.
313 */
314 /**
315 * Create a topic with the given name.
316 *
317 * @see [Topics: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/create}
318 *
319 * @param {string} name Name of the topic.
320 * @param {object} [gaxOpts] Request configuration options, outlined
321 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
322 * @param {CreateTopicCallback} [callback] Callback function.
323 * @returns {Promise<CreateTopicResponse>}
324 *
325 * @example
326 * ```
327 * const {PubSub} = require('@google-cloud/pubsub');
328 * const pubsub = new PubSub();
329 *
330 * pubsub.createTopic('my-new-topic', function(err, topic, apiResponse) {
331 * if (!err) {
332 * // The topic was created successfully.
333 * }
334 * });
335 *
336 * //-
337 * // If the callback is omitted, we'll return a Promise.
338 * //-
339 * pubsub.createTopic('my-new-topic').then(function(data) {
340 * const topic = data[0];
341 * const apiResponse = data[1];
342 * });
343 * ```
344 */
345 createTopic(name: string | TopicMetadata, gaxOpts?: CallOptions): Promise<CreateTopicResponse>;
346 createTopic(name: string | TopicMetadata, callback: CreateTopicCallback): void;
347 createTopic(name: string | TopicMetadata, gaxOpts: CallOptions, callback: CreateTopicCallback): void;
348 /**
349 * Detach a subscription with the given name.
350 *
351 * @see [Admin: Pub/Sub administration API Documentation]{@link https://cloud.google.com/pubsub/docs/admin}
352 *
353 * @param {string} name Name of the subscription.
354 * @param {object} [gaxOpts] Request configuration options, outlined
355 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
356 * @param {DetachSubscriptionCallback} [callback] Callback function.
357 * @returns {Promise<DetachSubscriptionResponse>}
358 *
359 * @example
360 * ```
361 * const {PubSub} = require('@google-cloud/pubsub');
362 * const pubsub = new PubSub();
363 *
364 * pubsub.detachSubscription('my-sub', (err, topic, apiResponse) => {
365 * if (!err) {
366 * // The topic was created successfully.
367 * }
368 * });
369 *
370 * //-
371 * // If the callback is omitted, we'll return a Promise.
372 * //-
373 * pubsub.detachSubscription('my-sub').then(data => {
374 * const apiResponse = data[0];
375 * });
376 * ```
377 */
378 detachSubscription(name: string, gaxOpts?: CallOptions): Promise<DetachSubscriptionResponse>;
379 detachSubscription(name: string, callback: DetachSubscriptionCallback): void;
380 detachSubscription(name: string, gaxOpts: CallOptions, callback: DetachSubscriptionCallback): void;
381 /**
382 * Determine the appropriate endpoint to use for API requests, first trying
383 * the `apiEndpoint` parameter. If that isn't set, we try the Pub/Sub emulator
384 * environment variable (PUBSUB_EMULATOR_HOST). If that is also null, we try
385 * the standard `gcloud alpha pubsub` environment variable
386 * (CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB). Otherwise the default production
387 * API is used.
388 *
389 * Note that if the URL doesn't end in '.googleapis.com', we will assume that
390 * it's an emulator and disable strict SSL checks.
391 *
392 * @private
393 */
394 determineBaseUrl_(): void;
395 /**
396 * Get a list of schemas associated with your project.
397 *
398 * The returned AsyncIterable will resolve to {@link google.pubsub.v1.ISchema} objects.
399 *
400 * This method returns an async iterable. These objects can be adapted
401 * to work in a Promise/then framework, as well as with callbacks, but
402 * this discussion is considered out of scope for these docs.
403 *
404 * @see [Schemas: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/list}
405 * @see [More about async iterators]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of}
406 *
407 * @param {google.pubsub.v1.SchemaView} [view] The type of schema objects
408 * requested, which should be an enum value from {@link SchemaViews}. Defaults
409 * to Full.
410 * @param {object} [options] Request configuration options, outlined
411 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
412 * @returns {AsyncIterable<ISchema>}
413 *
414 * @example
415 * ```
416 * for await (const s of pubsub.listSchemas()) {
417 * const moreInfo = await s.get();
418 * }
419 * ```
420 */
421 listSchemas(view?: SchemaView, options?: CallOptions): AsyncIterable<google.pubsub.v1.ISchema>;
422 /**
423 * Query object for listing snapshots.
424 *
425 * @typedef {object} GetSnapshotsRequest
426 * @property {boolean} [autoPaginate=true] Have pagination handled
427 * automatically.
428 * @property {object} [options.gaxOpts] Request configuration options, outlined
429 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
430 * @property {number} [options.pageSize] Maximum number of results to return.
431 * @property {string} [options.pageToken] Page token.
432 */
433 /**
434 * @typedef {array} GetSnapshotsResponse
435 * @property {Snapshot[]} 0 Array of {@link Snapshot} instances.
436 * @property {object} 1 The full API response.
437 */
438 /**
439 * @callback GetSnapshotsCallback
440 * @param {?Error} err Request error, if any.
441 * @param {Snapshot[]} snapshots Array of {@link Snapshot} instances.
442 * @param {object} apiResponse The full API response.
443 */
444 /**
445 * Get a list of snapshots.
446 *
447 * @param {GetSnapshotsRequest} [query] Query object for listing snapshots.
448 * @param {GetSnapshotsCallback} [callback] Callback function.
449 * @returns {Promise<GetSnapshotsResponse>}
450 *
451 * @example
452 * ```
453 * const {PubSub} = require('@google-cloud/pubsub');
454 * const pubsub = new PubSub();
455 *
456 * pubsub.getSnapshots(function(err, snapshots) {
457 * if (!err) {
458 * // snapshots is an array of Snapshot objects.
459 * }
460 * });
461 *
462 * //-
463 * // If the callback is omitted, we'll return a Promise.
464 * //-
465 * pubsub.getSnapshots().then(function(data) {
466 * const snapshots = data[0];
467 * });
468 * ```
469 */
470 getSnapshots(options?: PageOptions): Promise<GetSnapshotsResponse>;
471 getSnapshots(callback: GetSnapshotsCallback): void;
472 getSnapshots(options: PageOptions, callback: GetSnapshotsCallback): void;
473 /**
474 * Query object for listing subscriptions.
475 *
476 * @typedef {object} GetSubscriptionsRequest
477 * @property {boolean} [autoPaginate=true] Have pagination handled
478 * automatically.
479 * @property {object} [options.gaxOpts] Request configuration options, outlined
480 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
481 * @property {number} [options.pageSize] Maximum number of results to return.
482 * @property {string} [options.pageToken] Page token.
483 * @param {string|Topic} options.topic - The name of the topic to
484 * list subscriptions from.
485 */
486 /**
487 * @typedef {array} GetSubscriptionsResponse
488 * @property {Subscription[]} 0 Array of {@link Subscription} instances.
489 * @property {object} 1 The full API response.
490 */
491 /**
492 * @callback GetSubscriptionsCallback
493 * @param {?Error} err Request error, if any.
494 * @param {Subscription[]} subscriptions Array of {@link Subscription} instances.
495 * @param {object} apiResponse The full API response.
496 */
497 /**
498 * Get a list of the subscriptions registered to all of your project's topics.
499 * You may optionally provide a query object as the first argument to
500 * customize the response.
501 *
502 * Your provided callback will be invoked with an error object if an API error
503 * occurred or an array of {@link Subscription} objects.
504 *
505 * To get subscriptions for a topic, see {@link Topic}.
506 *
507 * @see [Subscriptions: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/list}
508 *
509 * @param {GetSubscriptionsRequest} [query] Query object for listing subscriptions.
510 * @param {GetSubscriptionsCallback} [callback] Callback function.
511 * @returns {Promise<GetSubscriptionsResponse>}
512 *
513 * @example
514 * ```
515 * const {PubSub} = require('@google-cloud/pubsub');
516 * const pubsub = new PubSub();
517 *
518 * pubsub.getSubscriptions(function(err, subscriptions) {
519 * if (!err) {
520 * // subscriptions is an array of Subscription objects.
521 * }
522 * });
523 *
524 * //-
525 * // If the callback is omitted, we'll return a Promise.
526 * //-
527 * pubsub.getSubscriptions().then(function(data) {
528 * const subscriptions = data[0];
529 * });
530 * ```
531 */
532 getSubscriptions(options?: GetSubscriptionsOptions): Promise<GetSubscriptionsResponse>;
533 getSubscriptions(callback: GetSubscriptionsCallback): void;
534 getSubscriptions(options: GetSubscriptionsOptions, callback: GetSubscriptionsCallback): void;
535 /**
536 * Query object for listing topics.
537 *
538 * @typedef {object} GetTopicsRequest
539 * @property {boolean} [autoPaginate=true] Have pagination handled
540 * automatically.
541 * @property {object} [options.gaxOpts] Request configuration options, outlined
542 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
543 * @property {number} [options.pageSize] Maximum number of results to return.
544 * @property {string} [options.pageToken] Page token.
545 */
546 /**
547 * @typedef {array} GetTopicsResponse
548 * @property {Topic[]} 0 Array of {@link Topic} instances.
549 * @property {object} 1 The full API response.
550 */
551 /**
552 * @callback GetTopicsCallback
553 * @param {?Error} err Request error, if any.
554 * @param {Topic[]} topics Array of {@link Topic} instances.
555 * @param {object} apiResponse The full API response.
556 */
557 /**
558 * Get a list of the topics registered to your project. You may optionally
559 * provide a query object as the first argument to customize the response.
560 *
561 * @see [Topics: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/list}
562 *
563 * @param {GetTopicsRequest} [query] Query object for listing topics.
564 * @param {GetTopicsCallback} [callback] Callback function.
565 * @returns {Promise<GetTopicsResponse>}
566 *
567 * @example
568 * ```
569 * const {PubSub} = require('@google-cloud/pubsub');
570 * const pubsub = new PubSub();
571 *
572 * pubsub.getTopics(function(err, topics) {
573 * if (!err) {
574 * // topics is an array of Topic objects.
575 * }
576 * });
577 *
578 * //-
579 * // Customize the query.
580 * //-
581 * pubsub.getTopics({
582 * pageSize: 3
583 * }, function(err, topics) {});
584 *
585 * //-
586 * // If the callback is omitted, we'll return a Promise.
587 * //-
588 * pubsub.getTopics().then(function(data) {
589 * const topics = data[0];
590 * });
591 * ```
592 */
593 getTopics(options?: PageOptions): Promise<GetTopicsResponse>;
594 getTopics(callback: GetTopicsCallback): void;
595 getTopics(options: PageOptions, callback: GetTopicsCallback): void;
596 /**
597 * Retrieve a client configuration, suitable for passing into a GAPIC
598 * 'v1' class constructor. This will fill out projectId, emulator URLs,
599 * and so forth.
600 *
601 * @returns {Promise<ClientConfig>} the filled client configuration.
602 */
603 getClientConfig(): Promise<ClientConfig>;
604 /**
605 * Gets a schema client, creating one if needed.
606 * @private
607 */
608 getSchemaClient_(): Promise<SchemaServiceClient>;
609 /**
610 * Callback function to PubSub.getClient_().
611 * @private
612 * @callback GetClientCallback
613 * @param err - Error, if any.
614 * @param gaxClient - The gax client specified in RequestConfig.client.
615 * Typed any since it's importing Javascript source.
616 */
617 /**
618 * Get the PubSub client object.
619 *
620 * @private
621 *
622 * @param {object} config Configuration object.
623 * @param {object} config.gaxOpts GAX options.
624 * @param {function} config.method The gax method to call.
625 * @param {object} config.reqOpts Request options.
626 * @param {function} [callback] The callback function.
627 */
628 getClient_(config: GetClientConfig, callback: GetClientCallback): void;
629 /**
630 * Get the PubSub client object.
631 *
632 * @private
633 *
634 * @param {object} config Configuration object.
635 * @param {object} config.gaxOpts GAX options.
636 * @param {function} config.method The gax method to call.
637 * @param {object} config.reqOpts Request options.
638 * @returns {Promise}
639 */
640 getClientAsync_(config: GetClientConfig): Promise<gax.ClientStub>;
641 /**
642 * Close all open client objects.
643 *
644 * @private
645 *
646 * @returns {Promise}
647 */
648 closeAllClients_(): Promise<void>;
649 /**
650 * Funnel all API requests through this method, to be sure we have a project
651 * ID.
652 *
653 * @private
654 *
655 * @param {object} config Configuration object.
656 * @param {object} config.gaxOpts GAX options.
657 * @param {function} config.method The gax method to call.
658 * @param {object} config.reqOpts Request options.
659 * @param {function} [callback] The callback function.
660 */
661 request<T, R = void>(config: RequestConfig, callback: RequestCallback<T, R>): void;
662 /**
663 * Create a Schema object, representing a schema within the project.
664 * See {@link PubSub#createSchema} or {@link Schema#create} to create a schema.
665 *
666 * @throws {Error} If a name is not provided.
667 *
668 * @param {string} name The ID or name of the schema.
669 * @returns {Schema} A {@link Schema} instance.
670 *
671 * @example
672 * ```
673 * const {PubSub} = require('@google-cloud/pubsub');
674 * const pubsub = new PubSub();
675 *
676 * const schema = pubsub.schema('my-schema');
677 * ```
678 */
679 schema(idOrName: string): Schema;
680 /**
681 * Create a Snapshot object. See {@link Subscription#createSnapshot} to
682 * create a snapshot.
683 *
684 * @throws {Error} If a name is not provided.
685 *
686 * @param {string} name The name of the snapshot.
687 * @returns {Snapshot} A {@link Snapshot} instance.
688 *
689 * @example
690 * ```
691 * const {PubSub} = require('@google-cloud/pubsub');
692 * const pubsub = new PubSub();
693 *
694 * const snapshot = pubsub.snapshot('my-snapshot');
695 * ```
696 */
697 snapshot(name: string): Snapshot;
698 /**
699 * Create a Subscription object. This command by itself will not run any API
700 * requests. You will receive a {@link Subscription} object,
701 * which will allow you to interact with a subscription.
702 *
703 * @throws {Error} If subscription name is omitted.
704 *
705 * @param {string} name Name of the subscription.
706 * @param {SubscriberOptions} [options] Configuration object.
707 * @returns {Subscription} A {@link Subscription} instance.
708 *
709 * @example
710 * ```
711 * const {PubSub} = require('@google-cloud/pubsub');
712 * const pubsub = new PubSub();
713 *
714 * const subscription = pubsub.subscription('my-subscription');
715 *
716 * // Register a listener for `message` events.
717 * subscription.on('message', function(message) {
718 * // Called every time a message is received.
719 * // message.id = ID of the message.
720 * // message.ackId = ID used to acknowledge the message receival.
721 * // message.data = Contents of the message.
722 * // message.attributes = Attributes of the message.
723 * // message.publishTime = Date when Pub/Sub received the message.
724 * });
725 * ```
726 */
727 subscription(name: string, options?: SubscriptionOptions): Subscription;
728 /**
729 * Create a Topic object. See {@link PubSub#createTopic} to create a topic.
730 *
731 * @throws {Error} If a name is not provided.
732 *
733 * @param {string} name The name of the topic.
734 * @param {PublishOptions} [options] Publisher configuration object.
735 * @returns {Topic} A {@link Topic} instance.
736 *
737 * @example
738 * ```
739 * const {PubSub} = require('@google-cloud/pubsub');
740 * const pubsub = new PubSub();
741 *
742 * const topic = pubsub.topic('my-topic');
743 * ```
744 */
745 topic(name: string, options?: PublishOptions): Topic;
746 /**
747 * Validate a schema definition.
748 *
749 * @see [Schemas: validateSchema API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/validate}
750 *
751 * @throws {Error} if the validation fails.
752 *
753 * @param {ISchema} schema The schema definition you wish to validate.
754 * @param {object} [options] Request configuration options, outlined
755 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
756 * @returns {Promise<void>}
757 */
758 validateSchema(schema: ISchema, gaxOpts?: CallOptions): Promise<void>;
759 /*!
760 * Format the name of a project. A project's full name is in the
761 * format of projects/{projectId}.
762 *
763 * The GAPIC client should do this for us, but since we maintain
764 * names rather than IDs, this is simpler.
765 *
766 * @private
767 */
768 static formatName_(name: string): string;
769}
770export {};