UNPKG

6.07 kBTypeScriptView Raw
1/*!
2 * Copyright 2017 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 */
16import { CallOptions } from 'google-gax';
17import { google } from '../protos/protos';
18import { PubSub } from './pubsub';
19import { EmptyCallback, EmptyResponse, RequestCallback, ResourceCallback } from './pubsub';
20import { Subscription } from './subscription';
21export declare type CreateSnapshotCallback = ResourceCallback<Snapshot, google.pubsub.v1.ISnapshot>;
22export declare type CreateSnapshotResponse = [Snapshot, google.pubsub.v1.ISnapshot];
23export declare type SeekCallback = RequestCallback<google.pubsub.v1.ISeekResponse>;
24export declare type SeekResponse = [google.pubsub.v1.ISeekResponse];
25/**
26 * A Snapshot object will give you access to your Cloud Pub/Sub snapshot.
27 *
28 * Snapshots are sometimes retrieved when using various methods:
29 *
30 * - {@link PubSub#getSnapshots}
31 * - {@link PubSub#getSnapshotsStream}
32 * - {@link PubSub#snapshot}
33 *
34 * Snapshots may be created with:
35 *
36 * - {@link Subscription#createSnapshot}
37 *
38 * You can use snapshots to seek a subscription to a specific point in time.
39 *
40 * - {@link Subscription#seek}
41 *
42 * @class
43 *
44 * @example
45 * ```
46 * //-
47 * // From {@link PubSub#getSnapshots}:
48 * //-
49 * pubsub.getSnapshots((err, snapshots) => {
50 * // `snapshots` is an array of Snapshot objects.
51 * });
52 *
53 * //-
54 * // From {@link PubSub#getSnapshotsStream}:
55 * //-
56 * pubsub.getSnapshotsStream()
57 * .on('error', console.error)
58 * .on('data', (snapshot) => {
59 * // `snapshot` is a Snapshot object.
60 * });
61 *
62 * //-
63 * // From {@link PubSub#snapshot}:
64 * //-
65 * const snapshot = pubsub.snapshot('my-snapshot');
66 * // snapshot is a Snapshot object.
67 *
68 * //-
69 * // Create a snapshot with {module:pubsub/subscription#createSnapshot}:
70 * //-
71 * const subscription = pubsub.subscription('my-subscription');
72 *
73 * subscription.createSnapshot('my-snapshot', (err, snapshot) => {
74 * if (!err) {
75 * // `snapshot` is a Snapshot object.
76 * }
77 * });
78 *
79 * //-
80 * // Seek to your snapshot:
81 * //-
82 * const subscription = pubsub.subscription('my-subscription');
83 *
84 * subscription.seek('my-snapshot', (err) => {
85 * if (err) {
86 * // Error handling omitted.
87 * }
88 * });
89 * ```
90 */
91export declare class Snapshot {
92 parent: Subscription | PubSub;
93 name: string;
94 metadata?: google.pubsub.v1.ISnapshot;
95 constructor(parent: Subscription | PubSub, name: string);
96 /**
97 * Delete the snapshot.
98 *
99 * @param {function} [callback] The callback function.
100 * @param {?error} callback.err An error returned while making this
101 * request.
102 * @param {object} callback.apiResponse The full API response from the
103 * service.
104 *
105 * @example
106 * ```
107 * snapshot.delete((err, apiResponse) => {});
108 *
109 * //-
110 * // If the callback is omitted, we'll return a Promise.
111 * //-
112 * snapshot.delete().then((data) => {
113 * const apiResponse = data[0];
114 * });
115 * ```
116 */
117 delete(): Promise<EmptyResponse>;
118 delete(callback: EmptyCallback): void;
119 static formatName_(projectId: string, name: string): string;
120 /**
121 * Create a snapshot with the given name.
122 *
123 * **This is only available if you accessed this object through
124 * {@link Subscription#snapshot}.**
125 *
126 * @method Snapshot#create
127 * @param {string} name Name of the snapshot.
128 * @param {function} [callback] The callback function.
129 * @param {?error} callback.err An error from the API call, may be null.
130 * @param {Snapshot} callback.snapshot The newly created
131 * snapshot.
132 * @param {object} callback.apiResponse The full API response from the
133 * service.
134 *
135 * @example
136 * ```
137 * const subscription = pubsub.subscription('my-subscription');
138 * const snapshot = subscription.snapshot('my-snapshot');
139 *
140 * const callback = (err, snapshot, apiResponse) => {
141 * if (!err) {
142 * // The snapshot was created successfully.
143 * }
144 * };
145 *
146 * snapshot.create('my-snapshot', callback);
147 *
148 * //-
149 * // If the callback is omitted, we'll return a Promise.
150 * //-
151 * snapshot.create('my-snapshot').then((data) => {
152 * const snapshot = data[0];
153 * const apiResponse = data[1];
154 * });
155 * ```
156 */
157 create(gaxOpts?: CallOptions): Promise<CreateSnapshotResponse>;
158 create(callback: CreateSnapshotCallback): void;
159 create(gaxOpts: CallOptions, callback: CreateSnapshotCallback): void;
160 /**
161 * Seeks an existing subscription to the snapshot.
162 *
163 * **This is only available if you accessed this object through
164 * {@link Subscription#snapshot}.**
165 *
166 * @method Snapshot#seek
167 * @param {function} callback The callback function.
168 * @param {?error} callback.err An error from the API call, may be null.
169 * @param {object} callback.apiResponse The full API response from the
170 * service.
171 *
172 * @example
173 * ```
174 * const subscription = pubsub.subscription('my-subscription');
175 * const snapshot = subscription.snapshot('my-snapshot');
176 *
177 * snapshot.seek((err, apiResponse) => {});
178 *
179 * //-
180 * // If the callback is omitted, we'll return a Promise.
181 * //-
182 * snapshot.seek().then((data) => {
183 * const apiResponse = data[0];
184 * });
185 * ```
186 */
187 seek(gaxOpts?: CallOptions): Promise<SeekResponse>;
188 seek(callback: SeekCallback): void;
189 seek(gaxOpts: CallOptions, callback: SeekCallback): void;
190}