1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { GoogleAuth } from 'google-auth-library';
|
18 | import * as gax from 'google-gax';
|
19 | import { Snapshot } from './snapshot';
|
20 | import { Subscription, SubscriptionOptions, CreateSubscriptionOptions, CreateSubscriptionCallback, CreateSubscriptionResponse, DetachSubscriptionCallback, DetachSubscriptionResponse } from './subscription';
|
21 | import { Topic, GetTopicSubscriptionsCallback, GetTopicSubscriptionsResponse, CreateTopicCallback, CreateTopicResponse } from './topic';
|
22 | import { PublishOptions } from './publisher';
|
23 | import { CallOptions } from 'google-gax';
|
24 | import { Transform } from 'stream';
|
25 | import { google } from '../protos/protos';
|
26 | export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
27 | export interface ClientConfig extends gax.GrpcClientOptions {
|
28 | apiEndpoint?: string;
|
29 | servicePath?: string;
|
30 | port?: string | number;
|
31 | sslCreds?: gax.grpc.ChannelCredentials;
|
32 | }
|
33 | export interface PageOptions {
|
34 | gaxOpts?: CallOptions;
|
35 | pageSize?: number;
|
36 | pageToken?: string;
|
37 | autoPaginate?: boolean;
|
38 | }
|
39 | export declare type GetSnapshotsCallback = RequestCallback<Snapshot, google.pubsub.v1.IListSnapshotsResponse>;
|
40 | export declare type GetSnapshotsResponse = PagedResponse<Snapshot, google.pubsub.v1.IListSnapshotsResponse>;
|
41 | export declare type GetSubscriptionsOptions = PageOptions & {
|
42 | topic?: string | Topic;
|
43 | };
|
44 | declare type GetAllSubscriptionsCallback = RequestCallback<Subscription, google.pubsub.v1.IListSubscriptionsResponse>;
|
45 | declare type GetAllSubscriptionsResponse = PagedResponse<Subscription, google.pubsub.v1.IListSubscriptionsResponse>;
|
46 | export declare type GetSubscriptionsCallback = GetAllSubscriptionsCallback | GetTopicSubscriptionsCallback;
|
47 | export declare type GetSubscriptionsResponse = GetAllSubscriptionsResponse | GetTopicSubscriptionsResponse;
|
48 | export declare type GetTopicsCallback = RequestCallback<Topic, google.pubsub.v1.IListTopicsResponse>;
|
49 | export declare type GetTopicsResponse = PagedResponse<Topic, google.pubsub.v1.IListTopicsResponse>;
|
50 | export declare type EmptyCallback = RequestCallback<google.protobuf.IEmpty>;
|
51 | export declare type EmptyResponse = [google.protobuf.IEmpty];
|
52 | export declare type ExistsCallback = RequestCallback<boolean>;
|
53 | export declare type ExistsResponse = [boolean];
|
54 | export declare type DetachedCallback = RequestCallback<boolean>;
|
55 | export declare type DetachedResponse = [boolean];
|
56 | export interface GetClientConfig {
|
57 | client: 'PublisherClient' | 'SubscriberClient';
|
58 | }
|
59 | export interface RequestConfig extends GetClientConfig {
|
60 | method: string;
|
61 | reqOpts?: object;
|
62 | gaxOpts?: CallOptions;
|
63 | }
|
64 | export interface ResourceCallback<Resource, Response> {
|
65 | (err: gax.grpc.ServiceError | null, resource?: Resource | null, response?: Response | null): void;
|
66 | }
|
67 | export declare type RequestCallback<T, R = void> = R extends void ? NormalCallback<T> : PagedCallback<T, R>;
|
68 | export interface NormalCallback<TResponse> {
|
69 | (err: gax.grpc.ServiceError | null, res?: TResponse | null): void;
|
70 | }
|
71 | export interface PagedCallback<Item, Response> {
|
72 | (err: gax.grpc.ServiceError | null, results?: Item[] | null, nextQuery?: {} | null, response?: Response | null): void;
|
73 | }
|
74 | export declare type PagedResponse<Item, Response> = [Item[]] | [Item[], {} | null, Response];
|
75 | export declare type ObjectStream<O> = {
|
76 | addListener(event: 'data', listener: (data: O) => void): ObjectStream<O>;
|
77 | emit(event: 'data', data: O): boolean;
|
78 | on(event: 'data', listener: (data: O) => void): ObjectStream<O>;
|
79 | once(event: 'data', listener: (data: O) => void): ObjectStream<O>;
|
80 | prependListener(event: 'data', listener: (data: O) => void): ObjectStream<O>;
|
81 | prependOnceListener(event: 'data', listener: (data: O) => void): ObjectStream<O>;
|
82 | } & Transform;
|
83 | interface GetClientCallback {
|
84 | (err: Error | null, gaxClient?: gax.ClientStub): void;
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | export declare class PubSub {
|
144 | options: ClientConfig;
|
145 | isEmulator: boolean;
|
146 | api: {
|
147 | [key: string]: gax.ClientStub;
|
148 | };
|
149 | auth: GoogleAuth;
|
150 | projectId: string;
|
151 | Promise?: PromiseConstructor;
|
152 | getSubscriptionsStream: () => ObjectStream<Subscription>;
|
153 | getSnapshotsStream: () => ObjectStream<Snapshot>;
|
154 | getTopicsStream: () => ObjectStream<Topic>;
|
155 | isOpen: boolean;
|
156 | constructor(options?: ClientConfig);
|
157 | close(): Promise<void>;
|
158 | close(callback: EmptyCallback): void;
|
159 | createSubscription(topic: Topic | string, name: string, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
|
160 | createSubscription(topic: Topic | string, name: string, callback: CreateSubscriptionCallback): void;
|
161 | createSubscription(topic: Topic | string, name: string, options: CreateSubscriptionOptions, callback: CreateSubscriptionCallback): void;
|
162 | createTopic(name: string, gaxOpts?: CallOptions): Promise<CreateTopicResponse>;
|
163 | createTopic(name: string, callback: CreateTopicCallback): void;
|
164 | createTopic(name: string, gaxOpts: CallOptions, callback: CreateTopicCallback): void;
|
165 | detachSubscription(name: string, gaxOpts?: CallOptions): Promise<DetachSubscriptionResponse>;
|
166 | detachSubscription(name: string, callback: DetachSubscriptionCallback): void;
|
167 | detachSubscription(name: string, gaxOpts: CallOptions, callback: DetachSubscriptionCallback): void;
|
168 | /**
|
169 | * Determine the appropriate endpoint to use for API requests, first trying
|
170 | * the `apiEndpoint` parameter. If that isn't set, we try the Pub/Sub emulator
|
171 | * environment variable (PUBSUB_EMULATOR_HOST). If that is also null, we try
|
172 | * the standard `gcloud alpha pubsub` environment variable
|
173 | * (CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB). Otherwise the default production
|
174 | * API is used.
|
175 | *
|
176 | * Note that if the URL doesn't end in '.googleapis.com', we will assume that
|
177 | * it's an emulator and disable strict SSL checks.
|
178 | *
|
179 | * @private
|
180 | */
|
181 | determineBaseUrl_(): void;
|
182 | getSnapshots(options?: PageOptions): Promise<GetSnapshotsResponse>;
|
183 | getSnapshots(callback: GetSnapshotsCallback): void;
|
184 | getSnapshots(options: PageOptions, callback: GetSnapshotsCallback): void;
|
185 | getSubscriptions(options?: GetSubscriptionsOptions): Promise<GetSubscriptionsResponse>;
|
186 | getSubscriptions(callback: GetSubscriptionsCallback): void;
|
187 | getSubscriptions(options: GetSubscriptionsOptions, callback: GetSubscriptionsCallback): void;
|
188 | getTopics(options?: PageOptions): Promise<GetTopicsResponse>;
|
189 | getTopics(callback: GetTopicsCallback): void;
|
190 | getTopics(options: PageOptions, callback: GetTopicsCallback): void;
|
191 | /**
|
192 | * Callback function to PubSub.getClient_().
|
193 | * @private
|
194 | * @callback GetClientCallback
|
195 | * @param err - Error, if any.
|
196 | * @param gaxClient - The gax client specified in RequestConfig.client.
|
197 | * Typed any since it's importing Javascript source.
|
198 | */
|
199 | /**
|
200 | * Get the PubSub client object.
|
201 | *
|
202 | * @private
|
203 | *
|
204 | * @param {object} config Configuration object.
|
205 | * @param {object} config.gaxOpts GAX options.
|
206 | * @param {function} config.method The gax method to call.
|
207 | * @param {object} config.reqOpts Request options.
|
208 | * @param {function} [callback] The callback function.
|
209 | */
|
210 | getClient_(config: GetClientConfig, callback: GetClientCallback): void;
|
211 | /**
|
212 | * Get the PubSub client object.
|
213 | *
|
214 | * @private
|
215 | *
|
216 | * @param {object} config Configuration object.
|
217 | * @param {object} config.gaxOpts GAX options.
|
218 | * @param {function} config.method The gax method to call.
|
219 | * @param {object} config.reqOpts Request options.
|
220 | * @returns {Promise}
|
221 | */
|
222 | getClientAsync_(config: GetClientConfig): Promise<gax.ClientStub>;
|
223 | |
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | closeAllClients_(): Promise<void>;
|
231 | |
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | request<T, R = void>(config: RequestConfig, callback: RequestCallback<T, R>): void;
|
244 | |
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | snapshot(name: string): Snapshot;
|
260 | |
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | subscription(name: string, options?: SubscriptionOptions): Subscription;
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | topic(name: string, options?: PublishOptions): Topic;
|
304 | }
|
305 | export {};
|