@glissandoo/lib 1.32.4 → 1.32.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helpers/ts-extras/firestore.d.ts +1759 -0
- package/helpers/ts-extras/firestore.js +16 -0
- package/models/Communication/Comment/index.d.ts +2 -2
- package/models/Communication/Comment/types.d.ts +1 -1
- package/models/Communication/index.d.ts +5 -4
- package/models/Communication/types.d.ts +1 -1
- package/models/Counters/Group/Analytics/index.d.ts +4 -3
- package/models/Counters/Group/Analytics/index.js +1 -2
- package/models/Counters/Group/Analytics/types.d.ts +1 -1
- package/models/Counters/Group/index.d.ts +3 -2
- package/models/Counters/Group/types.d.ts +1 -1
- package/models/Counters/event.d.ts +1 -1
- package/models/Counters/index.d.ts +1 -1
- package/models/Evento/Player/index.d.ts +1 -1
- package/models/Evento/Player/index.js +1 -2
- package/models/Evento/Player/types.d.ts +1 -1
- package/models/Evento/Repertory/index.d.ts +1 -1
- package/models/Evento/Repertory/index.js +1 -2
- package/models/Evento/Repertory/types.d.ts +1 -1
- package/models/Evento/basic.d.ts +4 -3
- package/models/Evento/index.d.ts +8 -7
- package/models/Evento/promoter.d.ts +1 -1
- package/models/Evento/tiny.d.ts +1 -1
- package/models/Evento/types.d.ts +1 -1
- package/models/Federation/Partnership/index.d.ts +4 -3
- package/models/Federation/Partnership/index.js +1 -2
- package/models/Federation/Partnership/types.d.ts +2 -2
- package/models/Federation/index.d.ts +5 -4
- package/models/Federation/types.d.ts +1 -1
- package/models/Group/Analytics/index.d.ts +1 -1
- package/models/Group/Analytics/index.js +1 -2
- package/models/Group/Analytics/types.d.ts +1 -1
- package/models/Group/Event/index.d.ts +3 -2
- package/models/Group/Event/types.d.ts +1 -1
- package/models/Group/Player/Event/index.d.ts +3 -2
- package/models/Group/Player/Event/index.js +2 -3
- package/models/Group/Player/Event/types.d.ts +1 -1
- package/models/Group/Player/Log/index.d.ts +3 -2
- package/models/Group/Player/Log/types.d.ts +1 -1
- package/models/Group/Player/index.d.ts +1 -1
- package/models/Group/Player/index.js +1 -1
- package/models/Group/Player/types.d.ts +1 -1
- package/models/Group/Repertory/index.d.ts +1 -1
- package/models/Group/Repertory/index.js +1 -2
- package/models/Group/Repertory/types.d.ts +1 -1
- package/models/Group/basic.d.ts +3 -2
- package/models/Group/index.d.ts +1 -1
- package/models/Group/index.js +2 -2
- package/models/Group/types.d.ts +1 -1
- package/models/Metrics/index.d.ts +1 -1
- package/models/Metrics/types.d.ts +1 -1
- package/models/Model/index.d.ts +1 -1
- package/models/Model/lang.d.ts +1 -1
- package/models/Notification/index.d.ts +1 -1
- package/models/Notification/types.d.ts +1 -1
- package/models/Partner/basic.d.ts +5 -4
- package/models/Partner/index.d.ts +3 -2
- package/models/Partner/tiny.d.ts +1 -1
- package/models/Partner/types.d.ts +1 -1
- package/models/Partnership/Group/index.d.ts +6 -5
- package/models/Partnership/Group/index.js +1 -2
- package/models/Partnership/Group/types.d.ts +1 -1
- package/models/Partnership/Partner/Subscription/index.d.ts +6 -5
- package/models/Partnership/Partner/Subscription/index.js +2 -3
- package/models/Partnership/Partner/Subscription/types.d.ts +1 -1
- package/models/Partnership/Partner/index.d.ts +1 -1
- package/models/Partnership/Partner/index.js +1 -2
- package/models/Partnership/Payment/index.d.ts +1 -1
- package/models/Partnership/Plan/basic.d.ts +1 -1
- package/models/Partnership/Plan/index.d.ts +4 -3
- package/models/Partnership/Plan/index.js +1 -2
- package/models/Partnership/Plan/types.d.ts +1 -1
- package/models/Partnership/basic.d.ts +1 -1
- package/models/Partnership/index.d.ts +3 -2
- package/models/Partnership/types.d.ts +1 -1
- package/models/Payment/basic.d.ts +1 -1
- package/models/Payment/index.d.ts +1 -1
- package/models/Payment/types.d.ts +1 -1
- package/models/Player/basic.d.ts +1 -1
- package/models/Repertory/basic.d.ts +1 -1
- package/models/User/Group/index.d.ts +3 -2
- package/models/User/Group/index.js +1 -2
- package/models/User/Group/types.d.ts +1 -1
- package/models/User/Notification/index.d.ts +1 -1
- package/models/User/Notification/types.d.ts +1 -1
- package/models/User/basic.d.ts +1 -1
- package/models/User/index.d.ts +7 -6
- package/models/User/types.d.ts +1 -1
- package/package.json +2 -3
- package/models/Model.d.ts +0 -10
- package/models/Model.js +0 -21
|
@@ -0,0 +1,1759 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2020 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
|
+
* 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" />
|
|
17
|
+
declare namespace FirebaseFirestoreTypes {
|
|
18
|
+
/**
|
|
19
|
+
* Document data (for use with `DocumentReference.set()`) consists of fields
|
|
20
|
+
* mapped to values.
|
|
21
|
+
*/
|
|
22
|
+
type DocumentData = {
|
|
23
|
+
[field: string]: any;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Update data (for use with `DocumentReference.update()`) consists of field
|
|
27
|
+
* paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
|
|
28
|
+
* reference nested fields within the document.
|
|
29
|
+
*/
|
|
30
|
+
type UpdateData = {
|
|
31
|
+
[fieldPath: string]: any;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Sets or disables the log function for all active Firestore instances.
|
|
35
|
+
*
|
|
36
|
+
* @param logger A log function that takes a message (such as `console.log`) or
|
|
37
|
+
* `null` to turn off logging.
|
|
38
|
+
*/
|
|
39
|
+
function setLogFunction(logger: ((msg: string) => void) | null): void;
|
|
40
|
+
/**
|
|
41
|
+
* Converter used by `withConverter()` to transform user objects of type T
|
|
42
|
+
* into Firestore data.
|
|
43
|
+
*
|
|
44
|
+
* Using the converter allows you to specify generic type arguments when
|
|
45
|
+
* storing and retrieving objects from Firestore.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* class Post {
|
|
49
|
+
* constructor(readonly title: string, readonly author: string) {}
|
|
50
|
+
*
|
|
51
|
+
* toString(): string {
|
|
52
|
+
* return this.title + ', by ' + this.author;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* const postConverter = {
|
|
57
|
+
* toFirestore(post: Post): FirebaseFirestore.DocumentData {
|
|
58
|
+
* return {title: post.title, author: post.author};
|
|
59
|
+
* },
|
|
60
|
+
* fromFirestore(
|
|
61
|
+
* snapshot: FirebaseFirestore.QueryDocumentSnapshot
|
|
62
|
+
* ): Post {
|
|
63
|
+
* const data = snapshot.data();
|
|
64
|
+
* return new Post(data.title, data.author);
|
|
65
|
+
* }
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* const postSnap = await Firestore()
|
|
69
|
+
* .collection('posts')
|
|
70
|
+
* .withConverter(postConverter)
|
|
71
|
+
* .doc().get();
|
|
72
|
+
* const post = postSnap.data();
|
|
73
|
+
* if (post !== undefined) {
|
|
74
|
+
* post.title; // string
|
|
75
|
+
* post.toString(); // Should be defined
|
|
76
|
+
* post.someNonExistentProperty; // TS error
|
|
77
|
+
* }
|
|
78
|
+
*/
|
|
79
|
+
interface FirestoreDataConverter<T> {
|
|
80
|
+
/**
|
|
81
|
+
* Called by the Firestore SDK to convert a custom model object of type T
|
|
82
|
+
* into a plain Javascript object (suitable for writing directly to the
|
|
83
|
+
* Firestore database). To use set() with `merge` and `mergeFields`,
|
|
84
|
+
* toFirestore() must be defined with `Partial<T>`.
|
|
85
|
+
*/
|
|
86
|
+
toFirestore(modelObject: T): DocumentData;
|
|
87
|
+
toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData;
|
|
88
|
+
/**
|
|
89
|
+
* Called by the Firestore SDK to convert Firestore data into an object of
|
|
90
|
+
* type T.
|
|
91
|
+
*/
|
|
92
|
+
fromFirestore(snapshot: QueryDocumentSnapshot): T;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Settings used to directly configure a `Firestore` instance.
|
|
96
|
+
*/
|
|
97
|
+
interface Settings {
|
|
98
|
+
/**
|
|
99
|
+
* The project ID from the Google Developer's Console, e.g.
|
|
100
|
+
* 'grape-spaceship-123'. We will also check the environment variable
|
|
101
|
+
* GCLOUD_PROJECT for your project ID. Can be omitted in environments that
|
|
102
|
+
* support {@link https://cloud.google.com/docs/authentication Application
|
|
103
|
+
* Default Credentials}
|
|
104
|
+
*/
|
|
105
|
+
projectId?: string;
|
|
106
|
+
/** The hostname to connect to. */
|
|
107
|
+
host?: string;
|
|
108
|
+
/** The port to connect to. */
|
|
109
|
+
port?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Local file containing the Service Account credentials as downloaded from
|
|
112
|
+
* the Google Developers Console. Can be omitted in environments that
|
|
113
|
+
* support {@link https://cloud.google.com/docs/authentication Application
|
|
114
|
+
* Default Credentials}. To configure Firestore with custom credentials, use
|
|
115
|
+
* the `credentials` property to provide the `client_email` and
|
|
116
|
+
* `private_key` of your service account.
|
|
117
|
+
*/
|
|
118
|
+
keyFilename?: string;
|
|
119
|
+
/**
|
|
120
|
+
* The 'client_email' and 'private_key' properties of the service account
|
|
121
|
+
* to use with your Firestore project. Can be omitted in environments that
|
|
122
|
+
* support {@link https://cloud.google.com/docs/authentication Application
|
|
123
|
+
* Default Credentials}. If your credentials are stored in a JSON file, you
|
|
124
|
+
* can specify a `keyFilename` instead.
|
|
125
|
+
*/
|
|
126
|
+
credentials?: {
|
|
127
|
+
client_email?: string;
|
|
128
|
+
private_key?: string;
|
|
129
|
+
};
|
|
130
|
+
/** Whether to use SSL when connecting. */
|
|
131
|
+
ssl?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* The maximum number of idle GRPC channels to keep. A smaller number of idle
|
|
134
|
+
* channels reduces memory usage but increases request latency for clients
|
|
135
|
+
* with fluctuating request rates. If set to 0, shuts down all GRPC channels
|
|
136
|
+
* when the client becomes idle. Defaults to 1.
|
|
137
|
+
*/
|
|
138
|
+
maxIdleChannels?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Whether to use `BigInt` for integer types when deserializing Firestore
|
|
141
|
+
* Documents. Regardless of magnitude, all integer values are returned as
|
|
142
|
+
* `BigInt` to match the precision of the Firestore backend. Floating point
|
|
143
|
+
* numbers continue to use JavaScript's `number` type.
|
|
144
|
+
*/
|
|
145
|
+
useBigInt?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Whether to skip nested properties that are set to `undefined` during
|
|
148
|
+
* object serialization. If set to `true`, these properties are skipped
|
|
149
|
+
* and not written to Firestore. If set `false` or omitted, the SDK throws
|
|
150
|
+
* an exception when it encounters properties of type `undefined`.
|
|
151
|
+
*/
|
|
152
|
+
ignoreUndefinedProperties?: boolean;
|
|
153
|
+
[key: string]: any;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* `Firestore` represents a Firestore Database and is the entry point for all
|
|
157
|
+
* Firestore operations.
|
|
158
|
+
*/
|
|
159
|
+
class Firestore {
|
|
160
|
+
/**
|
|
161
|
+
* @param settings Configuration object. See [Firestore Documentation]
|
|
162
|
+
* {@link https://firebase.google.com/docs/firestore/}
|
|
163
|
+
*/
|
|
164
|
+
constructor(settings?: Settings);
|
|
165
|
+
/**
|
|
166
|
+
* Specifies custom settings to be used to configure the `Firestore`
|
|
167
|
+
* instance. Can only be invoked once and before any other Firestore
|
|
168
|
+
* method.
|
|
169
|
+
*
|
|
170
|
+
* If settings are provided via both `settings()` and the `Firestore`
|
|
171
|
+
* constructor, both settings objects are merged and any settings provided
|
|
172
|
+
* via `settings()` take precedence.
|
|
173
|
+
*
|
|
174
|
+
* @param {object} settings The settings to use for all Firestore
|
|
175
|
+
* operations.
|
|
176
|
+
*/
|
|
177
|
+
settings(settings: Settings): void;
|
|
178
|
+
/**
|
|
179
|
+
* Gets a `CollectionReference` instance that refers to the collection at
|
|
180
|
+
* the specified path.
|
|
181
|
+
*
|
|
182
|
+
* @param collectionPath A slash-separated path to a collection.
|
|
183
|
+
* @return The `CollectionReference` instance.
|
|
184
|
+
*/
|
|
185
|
+
collection(collectionPath: string): CollectionReference<DocumentData>;
|
|
186
|
+
/**
|
|
187
|
+
* Gets a `DocumentReference` instance that refers to the document at the
|
|
188
|
+
* specified path.
|
|
189
|
+
*
|
|
190
|
+
* @param documentPath A slash-separated path to a document.
|
|
191
|
+
* @return The `DocumentReference` instance.
|
|
192
|
+
*/
|
|
193
|
+
doc(documentPath: string): DocumentReference<DocumentData>;
|
|
194
|
+
/**
|
|
195
|
+
* Creates and returns a new Query that includes all documents in the
|
|
196
|
+
* database that are contained in a collection or subcollection with the
|
|
197
|
+
* given collectionId.
|
|
198
|
+
*
|
|
199
|
+
* @param collectionId Identifies the collections to query over. Every
|
|
200
|
+
* collection or subcollection with this ID as the last segment of its path
|
|
201
|
+
* will be included. Cannot contain a slash.
|
|
202
|
+
* @return The created `CollectionGroup`.
|
|
203
|
+
*/
|
|
204
|
+
collectionGroup(collectionId: string): CollectionGroup<DocumentData>;
|
|
205
|
+
/**
|
|
206
|
+
* Retrieves multiple documents from Firestore.
|
|
207
|
+
*
|
|
208
|
+
* The first argument is required and must be of type `DocumentReference`
|
|
209
|
+
* followed by any additional `DocumentReference` documents. If used, the
|
|
210
|
+
* optional `ReadOptions` must be the last argument.
|
|
211
|
+
*
|
|
212
|
+
* @param {Array.<DocumentReference|ReadOptions>} documentRefsOrReadOptions
|
|
213
|
+
* The `DocumentReferences` to receive, followed by an optional field
|
|
214
|
+
* mask.
|
|
215
|
+
* @return A Promise that resolves with an array of resulting document
|
|
216
|
+
* snapshots.
|
|
217
|
+
*/
|
|
218
|
+
getAll(...documentRefsOrReadOptions: Array<DocumentReference<DocumentData> | ReadOptions>): Promise<Array<DocumentSnapshot<DocumentData>>>;
|
|
219
|
+
/**
|
|
220
|
+
* Recursively deletes all documents and subcollections at and under the
|
|
221
|
+
* specified level.
|
|
222
|
+
*
|
|
223
|
+
* If any delete fails, the promise is rejected with an error message
|
|
224
|
+
* containing the number of failed deletes and the stack trace of the last
|
|
225
|
+
* failed delete. The provided reference is deleted regardless of whether
|
|
226
|
+
* all deletes succeeded.
|
|
227
|
+
*
|
|
228
|
+
* `recursiveDelete()` uses a BulkWriter instance with default settings to
|
|
229
|
+
* perform the deletes. To customize throttling rates or add success/error
|
|
230
|
+
* callbacks, pass in a custom BulkWriter instance.
|
|
231
|
+
*
|
|
232
|
+
* @param ref The reference of a document or collection to delete.
|
|
233
|
+
* @param bulkWriter A custom BulkWriter instance used to perform the
|
|
234
|
+
* deletes.
|
|
235
|
+
* @return A promise that resolves when all deletes have been performed.
|
|
236
|
+
* The promise is rejected if any of the deletes fail.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* // Recursively delete a reference and log the references of failures.
|
|
240
|
+
* const bulkWriter = firestore.bulkWriter();
|
|
241
|
+
* bulkWriter
|
|
242
|
+
* .onWriteError((error) => {
|
|
243
|
+
* if (
|
|
244
|
+
* error.failedAttempts < MAX_RETRY_ATTEMPTS
|
|
245
|
+
* ) {
|
|
246
|
+
* return true;
|
|
247
|
+
* } else {
|
|
248
|
+
* console.log('Failed write at document: ', error.documentRef.path);
|
|
249
|
+
* return false;
|
|
250
|
+
* }
|
|
251
|
+
* });
|
|
252
|
+
* await firestore.recursiveDelete(docRef, bulkWriter);
|
|
253
|
+
*/
|
|
254
|
+
recursiveDelete(ref: CollectionReference<unknown> | DocumentReference<unknown>, bulkWriter?: BulkWriter): Promise<void>;
|
|
255
|
+
/**
|
|
256
|
+
* Terminates the Firestore client and closes all open streams.
|
|
257
|
+
*
|
|
258
|
+
* @return A Promise that resolves when the client is terminated.
|
|
259
|
+
*/
|
|
260
|
+
terminate(): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* Fetches the root collections that are associated with this Firestore
|
|
263
|
+
* database.
|
|
264
|
+
*
|
|
265
|
+
* @returns A Promise that resolves with an array of CollectionReferences.
|
|
266
|
+
*/
|
|
267
|
+
listCollections(): Promise<Array<CollectionReference<DocumentData>>>;
|
|
268
|
+
/**
|
|
269
|
+
* Executes the given updateFunction and commits the changes applied within
|
|
270
|
+
* the transaction.
|
|
271
|
+
*
|
|
272
|
+
* You can use the transaction object passed to 'updateFunction' to read and
|
|
273
|
+
* modify Firestore documents under lock. Transactions are committed once
|
|
274
|
+
* 'updateFunction' resolves and attempted up to five times on failure.
|
|
275
|
+
*
|
|
276
|
+
* @param updateFunction The function to execute within the transaction
|
|
277
|
+
* context.
|
|
278
|
+
* @param {object=} transactionOptions Transaction options.
|
|
279
|
+
* @param {number=} transactionOptions.maxAttempts The maximum number of
|
|
280
|
+
* attempts for this transaction.
|
|
281
|
+
* @return If the transaction completed successfully or was explicitly
|
|
282
|
+
* aborted (by the updateFunction returning a failed Promise), the Promise
|
|
283
|
+
* returned by the updateFunction will be returned here. Else if the
|
|
284
|
+
* transaction failed, a rejected Promise with the corresponding failure
|
|
285
|
+
* error will be returned.
|
|
286
|
+
*/
|
|
287
|
+
runTransaction<T>(updateFunction: (transaction: Transaction) => Promise<T>, transactionOptions?: {
|
|
288
|
+
maxAttempts?: number;
|
|
289
|
+
}): Promise<T>;
|
|
290
|
+
/**
|
|
291
|
+
* Creates a write batch, used for performing multiple writes as a single
|
|
292
|
+
* atomic operation.
|
|
293
|
+
*/
|
|
294
|
+
batch(): WriteBatch;
|
|
295
|
+
/**
|
|
296
|
+
* Creates a [BulkWriter]{@link BulkWriter}, used for performing
|
|
297
|
+
* multiple writes in parallel. Gradually ramps up writes as specified
|
|
298
|
+
* by the 500/50/5 rule.
|
|
299
|
+
*
|
|
300
|
+
* @see https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic
|
|
301
|
+
*
|
|
302
|
+
* @param options An options object used to configure the throttling
|
|
303
|
+
* behavior for the underlying BulkWriter.
|
|
304
|
+
*/
|
|
305
|
+
bulkWriter(options?: BulkWriterOptions): BulkWriter;
|
|
306
|
+
/**
|
|
307
|
+
* Creates a new `BundleBuilder` instance to package selected Firestore data into
|
|
308
|
+
* a bundle.
|
|
309
|
+
*
|
|
310
|
+
* @param bundleId The ID of the bundle. When loaded on clients, client SDKs use this ID
|
|
311
|
+
* and the timestamp associated with the bundle to tell if it has been loaded already.
|
|
312
|
+
* If not specified, a random identifier will be used.
|
|
313
|
+
*
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* const bundle = firestore.bundle('data-bundle');
|
|
317
|
+
* const docSnapshot = await firestore.doc('abc/123').get();
|
|
318
|
+
* const querySnapshot = await firestore.collection('coll').get();
|
|
319
|
+
*
|
|
320
|
+
* const bundleBuffer = bundle.add(docSnapshot); // Add a document
|
|
321
|
+
* .add('coll-query', querySnapshot) // Add a named query.
|
|
322
|
+
* .build()
|
|
323
|
+
* // Save `bundleBuffer` to CDN or stream it to clients.
|
|
324
|
+
*/
|
|
325
|
+
bundle(bundleId?: string): BundleBuilder;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* An immutable object representing a geo point in Firestore. The geo point
|
|
329
|
+
* is represented as latitude/longitude pair.
|
|
330
|
+
*
|
|
331
|
+
* Latitude values are in the range of [-90, 90].
|
|
332
|
+
* Longitude values are in the range of [-180, 180].
|
|
333
|
+
*/
|
|
334
|
+
class GeoPoint {
|
|
335
|
+
/**
|
|
336
|
+
* Creates a new immutable GeoPoint object with the provided latitude and
|
|
337
|
+
* longitude values.
|
|
338
|
+
* @param latitude The latitude as number between -90 and 90.
|
|
339
|
+
* @param longitude The longitude as number between -180 and 180.
|
|
340
|
+
*/
|
|
341
|
+
constructor(latitude: number, longitude: number);
|
|
342
|
+
readonly latitude: number;
|
|
343
|
+
readonly longitude: number;
|
|
344
|
+
/**
|
|
345
|
+
* Returns true if this `GeoPoint` is equal to the provided one.
|
|
346
|
+
*
|
|
347
|
+
* @param other The `GeoPoint` to compare against.
|
|
348
|
+
* @return true if this `GeoPoint` is equal to the provided one.
|
|
349
|
+
*/
|
|
350
|
+
isEqual(other: GeoPoint): boolean;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* A reference to a transaction.
|
|
354
|
+
* The `Transaction` object passed to a transaction's updateFunction provides
|
|
355
|
+
* the methods to read and write data within the transaction context. See
|
|
356
|
+
* `Firestore.runTransaction()`.
|
|
357
|
+
*/
|
|
358
|
+
class Transaction {
|
|
359
|
+
private constructor();
|
|
360
|
+
/**
|
|
361
|
+
* Retrieves a query result. Holds a pessimistic lock on all returned
|
|
362
|
+
* documents.
|
|
363
|
+
*
|
|
364
|
+
* @param query A query to execute.
|
|
365
|
+
* @return A QuerySnapshot for the retrieved data.
|
|
366
|
+
*/
|
|
367
|
+
get<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
|
|
368
|
+
/**
|
|
369
|
+
* Reads the document referenced by the provided `DocumentReference.`
|
|
370
|
+
* Holds a pessimistic lock on the returned document.
|
|
371
|
+
*
|
|
372
|
+
* @param documentRef A reference to the document to be read.
|
|
373
|
+
* @return A DocumentSnapshot for the read data.
|
|
374
|
+
*/
|
|
375
|
+
get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
|
|
376
|
+
/**
|
|
377
|
+
* Retrieves multiple documents from Firestore. Holds a pessimistic lock on
|
|
378
|
+
* all returned documents.
|
|
379
|
+
*
|
|
380
|
+
* The first argument is required and must be of type `DocumentReference`
|
|
381
|
+
* followed by any additional `DocumentReference` documents. If used, the
|
|
382
|
+
* optional `ReadOptions` must be the last argument.
|
|
383
|
+
*
|
|
384
|
+
* @param {Array.<DocumentReference|ReadOptions>} documentRefsOrReadOptions
|
|
385
|
+
* The `DocumentReferences` to receive, followed by an optional field
|
|
386
|
+
* mask.
|
|
387
|
+
* @return A Promise that resolves with an array of resulting document
|
|
388
|
+
* snapshots.
|
|
389
|
+
*/
|
|
390
|
+
getAll<T>(...documentRefsOrReadOptions: Array<DocumentReference<T> | ReadOptions>): Promise<Array<DocumentSnapshot<T>>>;
|
|
391
|
+
/**
|
|
392
|
+
* Create the document referred to by the provided `DocumentReference`.
|
|
393
|
+
* The operation will fail the transaction if a document exists at the
|
|
394
|
+
* specified location.
|
|
395
|
+
*
|
|
396
|
+
* @param documentRef A reference to the document to be create.
|
|
397
|
+
* @param data The object data to serialize as the document.
|
|
398
|
+
* @return This `Transaction` instance. Used for chaining method calls.
|
|
399
|
+
*/
|
|
400
|
+
create<T>(documentRef: DocumentReference<T>, data: T): Transaction;
|
|
401
|
+
/**
|
|
402
|
+
* Writes to the document referred to by the provided `DocumentReference`.
|
|
403
|
+
* If the document does not exist yet, it will be created. If you pass
|
|
404
|
+
* `SetOptions`, the provided data can be merged into the existing document.
|
|
405
|
+
*
|
|
406
|
+
* @param documentRef A reference to the document to be set.
|
|
407
|
+
* @param data An object of the fields and values for the document.
|
|
408
|
+
* @param options An object to configure the set behavior.
|
|
409
|
+
* @return This `Transaction` instance. Used for chaining method calls.
|
|
410
|
+
*/
|
|
411
|
+
set<T>(documentRef: DocumentReference<T>, data: Partial<T>, options: SetOptions): Transaction;
|
|
412
|
+
set<T>(documentRef: DocumentReference<T>, data: T): Transaction;
|
|
413
|
+
/**
|
|
414
|
+
* Updates fields in the document referred to by the provided
|
|
415
|
+
* `DocumentReference`. The update will fail if applied to a document that
|
|
416
|
+
* does not exist.
|
|
417
|
+
*
|
|
418
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
419
|
+
* strings.
|
|
420
|
+
*
|
|
421
|
+
* @param documentRef A reference to the document to be updated.
|
|
422
|
+
* @param data An object containing the fields and values with which to
|
|
423
|
+
* update the document.
|
|
424
|
+
* @param precondition A Precondition to enforce on this update.
|
|
425
|
+
* @return This `Transaction` instance. Used for chaining method calls.
|
|
426
|
+
*/
|
|
427
|
+
update(documentRef: DocumentReference<any>, data: UpdateData, precondition?: Precondition): Transaction;
|
|
428
|
+
/**
|
|
429
|
+
* Updates fields in the document referred to by the provided
|
|
430
|
+
* `DocumentReference`. The update will fail if applied to a document that
|
|
431
|
+
* does not exist.
|
|
432
|
+
*
|
|
433
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
434
|
+
* strings or by providing FieldPath objects.
|
|
435
|
+
*
|
|
436
|
+
* A `Precondition` restricting this update can be specified as the last
|
|
437
|
+
* argument.
|
|
438
|
+
*
|
|
439
|
+
* @param documentRef A reference to the document to be updated.
|
|
440
|
+
* @param field The first field to update.
|
|
441
|
+
* @param value The first value
|
|
442
|
+
* @param fieldsOrPrecondition An alternating list of field paths and values
|
|
443
|
+
* to update, optionally followed by a `Precondition` to enforce on this
|
|
444
|
+
* update.
|
|
445
|
+
* @return This `Transaction` instance. Used for chaining method calls.
|
|
446
|
+
*/
|
|
447
|
+
update(documentRef: DocumentReference<any>, field: string | FieldPath, value: any, ...fieldsOrPrecondition: any[]): Transaction;
|
|
448
|
+
/**
|
|
449
|
+
* Deletes the document referred to by the provided `DocumentReference`.
|
|
450
|
+
*
|
|
451
|
+
* @param documentRef A reference to the document to be deleted.
|
|
452
|
+
* @param precondition A Precondition to enforce for this delete.
|
|
453
|
+
* @return This `Transaction` instance. Used for chaining method calls.
|
|
454
|
+
*/
|
|
455
|
+
delete(documentRef: DocumentReference<any>, precondition?: Precondition): Transaction;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* A Firestore BulkWriter than can be used to perform a large number of writes
|
|
459
|
+
* in parallel. Writes to the same document will be executed sequentially.
|
|
460
|
+
*
|
|
461
|
+
* @class
|
|
462
|
+
*/
|
|
463
|
+
class BulkWriter {
|
|
464
|
+
private constructor();
|
|
465
|
+
/**
|
|
466
|
+
* Create a document with the provided data. This single operation will fail
|
|
467
|
+
* if a document exists at its location.
|
|
468
|
+
*
|
|
469
|
+
* @param documentRef A reference to the document to be
|
|
470
|
+
* created.
|
|
471
|
+
* @param data The object to serialize as the document.
|
|
472
|
+
* @returns A promise that resolves with the result of the write. If the
|
|
473
|
+
* write fails, the promise is rejected with a
|
|
474
|
+
* [BulkWriterError]{@link BulkWriterError}.
|
|
475
|
+
*/
|
|
476
|
+
create<T>(documentRef: DocumentReference<T>, data: T): Promise<WriteResult>;
|
|
477
|
+
/**
|
|
478
|
+
* Delete a document from the database.
|
|
479
|
+
*
|
|
480
|
+
* @param documentRef A reference to the document to be
|
|
481
|
+
* deleted.
|
|
482
|
+
* @param precondition A precondition to enforce for this
|
|
483
|
+
* delete.
|
|
484
|
+
* @param precondition.lastUpdateTime If set, enforces that the
|
|
485
|
+
* document was last updated at lastUpdateTime. Fails the batch if the
|
|
486
|
+
* document doesn't exist or was last updated at a different time.
|
|
487
|
+
* @param precondition.exists If set, enforces that the target document
|
|
488
|
+
* must or must not exist.
|
|
489
|
+
* @returns A promise that resolves with the result of the delete. If the
|
|
490
|
+
* delete fails, the promise is rejected with a
|
|
491
|
+
* [BulkWriterError]{@link BulkWriterError}.
|
|
492
|
+
*/
|
|
493
|
+
delete(documentRef: DocumentReference<any>, precondition?: Precondition): Promise<WriteResult>;
|
|
494
|
+
/**
|
|
495
|
+
* Write to the document referred to by the provided
|
|
496
|
+
* [DocumentReference]{@link DocumentReference}. If the document does not
|
|
497
|
+
* exist yet, it will be created. If you pass
|
|
498
|
+
* [SetOptions]{@link SetOptions}., the provided data can be merged into the
|
|
499
|
+
* existing document.
|
|
500
|
+
*
|
|
501
|
+
* @param documentRef A reference to the document to be
|
|
502
|
+
* set.
|
|
503
|
+
* @param data The object to serialize as the document.
|
|
504
|
+
* @param options An object to configure the set behavior.
|
|
505
|
+
* @param options.merge - If true, set() merges the values
|
|
506
|
+
* specified in its data argument. Fields omitted from this set() call
|
|
507
|
+
* remain untouched.
|
|
508
|
+
* @param options.mergeFields - If provided,
|
|
509
|
+
* set() only replaces the specified field paths. Any field path that is not
|
|
510
|
+
* specified is ignored and remains untouched.
|
|
511
|
+
* @returns A promise that resolves with the result of the write. If the
|
|
512
|
+
* write fails, the promise is rejected with a
|
|
513
|
+
* [BulkWriterError]{@link BulkWriterError}.
|
|
514
|
+
*/
|
|
515
|
+
set<T>(documentRef: DocumentReference<T>, data: Partial<T>, options: SetOptions): Promise<WriteResult>;
|
|
516
|
+
set<T>(documentRef: DocumentReference<T>, data: T): Promise<WriteResult>;
|
|
517
|
+
/**
|
|
518
|
+
* Update fields of the document referred to by the provided
|
|
519
|
+
* [DocumentReference]{@link DocumentReference}. If the document doesn't yet
|
|
520
|
+
* exist, the update fails and the entire batch will be rejected.
|
|
521
|
+
*
|
|
522
|
+
* The update() method accepts either an object with field paths encoded as
|
|
523
|
+
* keys and field values encoded as values, or a variable number of
|
|
524
|
+
* arguments that alternate between field paths and field values. Nested
|
|
525
|
+
* fields can be updated by providing dot-separated field path strings or by
|
|
526
|
+
* providing FieldPath objects.
|
|
527
|
+
*
|
|
528
|
+
*
|
|
529
|
+
* A Precondition restricting this update can be specified as the last
|
|
530
|
+
* argument.
|
|
531
|
+
*
|
|
532
|
+
* @param documentRef A reference to the document to be updated.
|
|
533
|
+
* @param data An object containing the fields and values with which to
|
|
534
|
+
* update the document.
|
|
535
|
+
* @param precondition A Precondition to enforce on this update.
|
|
536
|
+
* @returns A promise that resolves with the result of the write. If the
|
|
537
|
+
* write fails, the promise is rejected with a
|
|
538
|
+
* [BulkWriterError]{@link BulkWriterError}.
|
|
539
|
+
*/
|
|
540
|
+
update(documentRef: DocumentReference<any>, data: UpdateData, precondition?: Precondition): Promise<WriteResult>;
|
|
541
|
+
/**
|
|
542
|
+
* Update fields of the document referred to by the provided
|
|
543
|
+
* [DocumentReference]{@link DocumentReference}. If the document doesn't yet
|
|
544
|
+
* exist, the update fails and the entire batch will be rejected.
|
|
545
|
+
*
|
|
546
|
+
* The update() method accepts either an object with field paths encoded as
|
|
547
|
+
* keys and field values encoded as values, or a variable number of
|
|
548
|
+
* arguments that alternate between field paths and field values. Nested
|
|
549
|
+
* fields can be updated by providing dot-separated field path strings or by
|
|
550
|
+
* providing FieldPath objects.
|
|
551
|
+
*
|
|
552
|
+
*
|
|
553
|
+
* A Precondition restricting this update can be specified as the last
|
|
554
|
+
* argument.
|
|
555
|
+
*
|
|
556
|
+
* @param documentRef A reference to the document to be updated.
|
|
557
|
+
* @param field The first field to update.
|
|
558
|
+
* @param value The first value
|
|
559
|
+
* @param fieldsOrPrecondition An alternating list of field paths and values
|
|
560
|
+
* to update, optionally followed a `Precondition` to enforce on this update.
|
|
561
|
+
* @returns A promise that resolves with the result of the write. If the
|
|
562
|
+
* write fails, the promise is rejected with a
|
|
563
|
+
* [BulkWriterError]{@link BulkWriterError}.
|
|
564
|
+
*/
|
|
565
|
+
update(documentRef: DocumentReference<any>, field: string | FieldPath, value: any, ...fieldsOrPrecondition: any[]): Promise<WriteResult>;
|
|
566
|
+
/**
|
|
567
|
+
* Attaches a listener that is run every time a BulkWriter operation
|
|
568
|
+
* successfully completes.
|
|
569
|
+
*
|
|
570
|
+
* @param callback A callback to be called every time a BulkWriter operation
|
|
571
|
+
* successfully completes.
|
|
572
|
+
*/
|
|
573
|
+
onWriteResult(callback: (documentRef: DocumentReference<any>, result: WriteResult) => void): void;
|
|
574
|
+
/**
|
|
575
|
+
* Attaches an error handler listener that is run every time a BulkWriter
|
|
576
|
+
* operation fails.
|
|
577
|
+
*
|
|
578
|
+
* BulkWriter has a default error handler that retries UNAVAILABLE and
|
|
579
|
+
* ABORTED errors up to a maximum of 10 failed attempts. When an error
|
|
580
|
+
* handler is specified, the default error handler will be overwritten.
|
|
581
|
+
*
|
|
582
|
+
* @param shouldRetryCallback A callback to be called every time a BulkWriter
|
|
583
|
+
* operation fails. Returning `true` will retry the operation. Returning
|
|
584
|
+
* `false` will stop the retry loop.
|
|
585
|
+
*/
|
|
586
|
+
onWriteError(shouldRetryCallback: (error: BulkWriterError) => boolean): void;
|
|
587
|
+
/**
|
|
588
|
+
* Commits all writes that have been enqueued up to this point in parallel.
|
|
589
|
+
*
|
|
590
|
+
* Returns a Promise that resolves when all currently queued operations have
|
|
591
|
+
* been committed. The Promise will never be rejected since the results for
|
|
592
|
+
* each individual operation are conveyed via their individual Promises.
|
|
593
|
+
*
|
|
594
|
+
* The Promise resolves immediately if there are no pending writes.
|
|
595
|
+
* Otherwise, the Promise waits for all previously issued writes, but it
|
|
596
|
+
* does not wait for writes that were added after the method is called. If
|
|
597
|
+
* you want to wait for additional writes, call `flush()` again.
|
|
598
|
+
*
|
|
599
|
+
* @return A promise that resolves when all enqueued writes
|
|
600
|
+
* up to this point have been committed.
|
|
601
|
+
*/
|
|
602
|
+
flush(): Promise<void>;
|
|
603
|
+
/**
|
|
604
|
+
* Commits all enqueued writes and marks the BulkWriter instance as closed.
|
|
605
|
+
*
|
|
606
|
+
* After calling `close()`, calling any method will throw an error. Any
|
|
607
|
+
* retries scheduled as part of an `onWriteError()` handler will be run
|
|
608
|
+
* before the `close()` promise resolves.
|
|
609
|
+
*
|
|
610
|
+
* Returns a Promise that resolves when all writes have been committed. The
|
|
611
|
+
* Promise will never be rejected. Calling this method will send all
|
|
612
|
+
* requests. The promise resolves immediately if there are no pending
|
|
613
|
+
* writes.
|
|
614
|
+
*
|
|
615
|
+
* @return A promise that resolves when all enqueued writes
|
|
616
|
+
* up to this point have been committed.
|
|
617
|
+
*/
|
|
618
|
+
close(): Promise<void>;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* An options object to configure throttling on BulkWriter.
|
|
622
|
+
*/
|
|
623
|
+
interface BulkWriterOptions {
|
|
624
|
+
/**
|
|
625
|
+
* Whether to disable or configure throttling. By default, throttling is
|
|
626
|
+
* enabled. This field can be set to either a boolean or a config
|
|
627
|
+
* object. Setting it to `true` will use default values. You can override
|
|
628
|
+
* the defaults by setting it to `false` to disable throttling, or by
|
|
629
|
+
* setting the config values to enable throttling with the provided values.
|
|
630
|
+
*
|
|
631
|
+
* @see https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic
|
|
632
|
+
*
|
|
633
|
+
* @param initialOpsPerSecond The initial maximum number of operations per
|
|
634
|
+
* second allowed by the throttler. If this field is not set, the default
|
|
635
|
+
* is 500 operations per second.
|
|
636
|
+
* @param maxOpsPerSecond The maximum number of operations per second
|
|
637
|
+
* allowed by the throttler. If this field is set, the throttler's allowed
|
|
638
|
+
* operations per second does not ramp up past the specified operations per
|
|
639
|
+
* second.
|
|
640
|
+
*/
|
|
641
|
+
readonly throttling?: boolean | {
|
|
642
|
+
initialOpsPerSecond?: number;
|
|
643
|
+
maxOpsPerSecond?: number;
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* The error thrown when a BulkWriter operation fails.
|
|
648
|
+
*/
|
|
649
|
+
class BulkWriterError extends Error {
|
|
650
|
+
/** The status code of the error. */
|
|
651
|
+
readonly code: GrpcStatus;
|
|
652
|
+
/** The error message of the error. */
|
|
653
|
+
readonly message: string;
|
|
654
|
+
/** The document reference the operation was performed on. */
|
|
655
|
+
readonly documentRef: DocumentReference<any>;
|
|
656
|
+
/** The type of operation performed. */
|
|
657
|
+
readonly operationType: 'create' | 'set' | 'update' | 'delete';
|
|
658
|
+
/** How many times this operation has been attempted unsuccessfully. */
|
|
659
|
+
readonly failedAttempts: number;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* A write batch, used to perform multiple writes as a single atomic unit.
|
|
663
|
+
*
|
|
664
|
+
* A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It
|
|
665
|
+
* provides methods for adding writes to the write batch. None of the
|
|
666
|
+
* writes will be committed (or visible locally) until `WriteBatch.commit()`
|
|
667
|
+
* is called.
|
|
668
|
+
*
|
|
669
|
+
* Unlike transactions, write batches are persisted offline and therefore are
|
|
670
|
+
* preferable when you don't need to condition your writes on read data.
|
|
671
|
+
*/
|
|
672
|
+
class WriteBatch {
|
|
673
|
+
private constructor();
|
|
674
|
+
/**
|
|
675
|
+
* Create the document referred to by the provided `DocumentReference`. The
|
|
676
|
+
* operation will fail the batch if a document exists at the specified
|
|
677
|
+
* location.
|
|
678
|
+
*
|
|
679
|
+
* @param documentRef A reference to the document to be created.
|
|
680
|
+
* @param data The object data to serialize as the document.
|
|
681
|
+
* @return This `WriteBatch` instance. Used for chaining method calls.
|
|
682
|
+
*/
|
|
683
|
+
create<T>(documentRef: DocumentReference<T>, data: T): WriteBatch;
|
|
684
|
+
/**
|
|
685
|
+
* Write to the document referred to by the provided `DocumentReference`.
|
|
686
|
+
* If the document does not exist yet, it will be created. If you pass
|
|
687
|
+
* `SetOptions`, the provided data can be merged into the existing document.
|
|
688
|
+
*
|
|
689
|
+
* @param documentRef A reference to the document to be set.
|
|
690
|
+
* @param data An object of the fields and values for the document.
|
|
691
|
+
* @param options An object to configure the set behavior.
|
|
692
|
+
* @return This `WriteBatch` instance. Used for chaining method calls.
|
|
693
|
+
*/
|
|
694
|
+
set<T>(documentRef: DocumentReference<T>, data: Partial<T>, options: SetOptions): WriteBatch;
|
|
695
|
+
set<T>(documentRef: DocumentReference<T>, data: T): WriteBatch;
|
|
696
|
+
/**
|
|
697
|
+
* Update fields of the document referred to by the provided
|
|
698
|
+
* `DocumentReference`. If the document doesn't yet exist, the update fails
|
|
699
|
+
* and the entire batch will be rejected.
|
|
700
|
+
*
|
|
701
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
702
|
+
* strings.
|
|
703
|
+
*
|
|
704
|
+
* @param documentRef A reference to the document to be updated.
|
|
705
|
+
* @param data An object containing the fields and values with which to
|
|
706
|
+
* update the document.
|
|
707
|
+
* @param precondition A Precondition to enforce on this update.
|
|
708
|
+
* @return This `WriteBatch` instance. Used for chaining method calls.
|
|
709
|
+
*/
|
|
710
|
+
update(documentRef: DocumentReference<any>, data: UpdateData, precondition?: Precondition): WriteBatch;
|
|
711
|
+
/**
|
|
712
|
+
* Updates fields in the document referred to by the provided
|
|
713
|
+
* `DocumentReference`. The update will fail if applied to a document that
|
|
714
|
+
* does not exist.
|
|
715
|
+
*
|
|
716
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
717
|
+
* strings or by providing FieldPath objects.
|
|
718
|
+
*
|
|
719
|
+
* A `Precondition` restricting this update can be specified as the last
|
|
720
|
+
* argument.
|
|
721
|
+
*
|
|
722
|
+
* @param documentRef A reference to the document to be updated.
|
|
723
|
+
* @param field The first field to update.
|
|
724
|
+
* @param value The first value
|
|
725
|
+
* @param fieldsOrPrecondition An alternating list of field paths and values
|
|
726
|
+
* to update, optionally followed a `Precondition` to enforce on this update.
|
|
727
|
+
* @return This `WriteBatch` instance. Used for chaining method calls.
|
|
728
|
+
*/
|
|
729
|
+
update(documentRef: DocumentReference<any>, field: string | FieldPath, value: any, ...fieldsOrPrecondition: any[]): WriteBatch;
|
|
730
|
+
/**
|
|
731
|
+
* Deletes the document referred to by the provided `DocumentReference`.
|
|
732
|
+
*
|
|
733
|
+
* @param documentRef A reference to the document to be deleted.
|
|
734
|
+
* @param precondition A Precondition to enforce for this delete.
|
|
735
|
+
* @return This `WriteBatch` instance. Used for chaining method calls.
|
|
736
|
+
*/
|
|
737
|
+
delete(documentRef: DocumentReference<any>, precondition?: Precondition): WriteBatch;
|
|
738
|
+
/**
|
|
739
|
+
* Commits all of the writes in this write batch as a single atomic unit.
|
|
740
|
+
*
|
|
741
|
+
* @return A Promise resolved once all of the writes in the batch have been
|
|
742
|
+
* successfully written to the backend as an atomic unit.
|
|
743
|
+
*/
|
|
744
|
+
commit(): Promise<WriteResult[]>;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* An options object that configures conditional behavior of `update()` and
|
|
748
|
+
* `delete()` calls in `DocumentReference`, `WriteBatch`, and `Transaction`.
|
|
749
|
+
* Using Preconditions, these calls can be restricted to only apply to
|
|
750
|
+
* documents that match the specified restrictions.
|
|
751
|
+
*/
|
|
752
|
+
interface Precondition {
|
|
753
|
+
/**
|
|
754
|
+
* If set, the last update time to enforce.
|
|
755
|
+
*/
|
|
756
|
+
readonly lastUpdateTime?: Timestamp;
|
|
757
|
+
/**
|
|
758
|
+
* If set, enforces that the target document must or must not exist.
|
|
759
|
+
*/
|
|
760
|
+
readonly exists?: boolean;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* An options object that configures the behavior of `set()` calls in
|
|
764
|
+
* `DocumentReference`, `WriteBatch` and `Transaction`. These calls can be
|
|
765
|
+
* configured to perform granular merges instead of overwriting the target
|
|
766
|
+
* documents in their entirety.
|
|
767
|
+
*/
|
|
768
|
+
interface SetOptions {
|
|
769
|
+
/**
|
|
770
|
+
* Changes the behavior of a set() call to only replace the values specified
|
|
771
|
+
* in its data argument. Fields omitted from the set() call remain
|
|
772
|
+
* untouched.
|
|
773
|
+
*/
|
|
774
|
+
readonly merge?: boolean;
|
|
775
|
+
/**
|
|
776
|
+
* Changes the behavior of set() calls to only replace the specified field
|
|
777
|
+
* paths. Any field path that is not specified is ignored and remains
|
|
778
|
+
* untouched.
|
|
779
|
+
*
|
|
780
|
+
* It is an error to pass a SetOptions object to a set() call that is
|
|
781
|
+
* missing a value for any of the fields specified here.
|
|
782
|
+
*/
|
|
783
|
+
readonly mergeFields?: (string | FieldPath)[];
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* An options object that can be used to configure the behavior of `getAll()`
|
|
787
|
+
* calls. By providing a `fieldMask`, these calls can be configured to only
|
|
788
|
+
* return a subset of fields.
|
|
789
|
+
*/
|
|
790
|
+
interface ReadOptions {
|
|
791
|
+
/**
|
|
792
|
+
* Specifies the set of fields to return and reduces the amount of data
|
|
793
|
+
* transmitted by the backend.
|
|
794
|
+
*
|
|
795
|
+
* Adding a field mask does not filter results. Documents do not need to
|
|
796
|
+
* contain values for all the fields in the mask to be part of the result
|
|
797
|
+
* set.
|
|
798
|
+
*/
|
|
799
|
+
readonly fieldMask?: (string | FieldPath)[];
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* A WriteResult wraps the write time set by the Firestore servers on `sets()`,
|
|
803
|
+
* `updates()`, and `creates()`.
|
|
804
|
+
*/
|
|
805
|
+
class WriteResult {
|
|
806
|
+
private constructor();
|
|
807
|
+
/**
|
|
808
|
+
* The write time as set by the Firestore servers.
|
|
809
|
+
*/
|
|
810
|
+
readonly writeTime: Timestamp;
|
|
811
|
+
/**
|
|
812
|
+
* Returns true if this `WriteResult` is equal to the provided one.
|
|
813
|
+
*
|
|
814
|
+
* @param other The `WriteResult` to compare against.
|
|
815
|
+
* @return true if this `WriteResult` is equal to the provided one.
|
|
816
|
+
*/
|
|
817
|
+
isEqual(other: WriteResult): boolean;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* A `DocumentReference` refers to a document location in a Firestore database
|
|
821
|
+
* and can be used to write, read, or listen to the location. The document at
|
|
822
|
+
* the referenced location may or may not exist. A `DocumentReference` can
|
|
823
|
+
* also be used to create a `CollectionReference` to a subcollection.
|
|
824
|
+
*/
|
|
825
|
+
class DocumentReference<T = DocumentData> {
|
|
826
|
+
private constructor();
|
|
827
|
+
/** The identifier of the document within its collection. */
|
|
828
|
+
readonly id: string;
|
|
829
|
+
/**
|
|
830
|
+
* The `Firestore` for the Firestore database (useful for performing
|
|
831
|
+
* transactions, etc.).
|
|
832
|
+
*/
|
|
833
|
+
readonly firestore: Firestore;
|
|
834
|
+
/**
|
|
835
|
+
* A reference to the Collection to which this DocumentReference belongs.
|
|
836
|
+
*/
|
|
837
|
+
readonly parent: CollectionReference<T>;
|
|
838
|
+
/**
|
|
839
|
+
* A string representing the path of the referenced document (relative
|
|
840
|
+
* to the root of the database).
|
|
841
|
+
*/
|
|
842
|
+
readonly path: string;
|
|
843
|
+
/**
|
|
844
|
+
* Gets a `CollectionReference` instance that refers to the collection at
|
|
845
|
+
* the specified path.
|
|
846
|
+
*
|
|
847
|
+
* @param collectionPath A slash-separated path to a collection.
|
|
848
|
+
* @return The `CollectionReference` instance.
|
|
849
|
+
*/
|
|
850
|
+
collection(collectionPath: string): CollectionReference<DocumentData>;
|
|
851
|
+
/**
|
|
852
|
+
* Fetches the subcollections that are direct children of this document.
|
|
853
|
+
*
|
|
854
|
+
* @returns A Promise that resolves with an array of CollectionReferences.
|
|
855
|
+
*/
|
|
856
|
+
listCollections(): Promise<Array<CollectionReference<DocumentData>>>;
|
|
857
|
+
/**
|
|
858
|
+
* Creates a document referred to by this `DocumentReference` with the
|
|
859
|
+
* provided object values. The write fails if the document already exists
|
|
860
|
+
*
|
|
861
|
+
* @param data The object data to serialize as the document.
|
|
862
|
+
* @return A Promise resolved with the write time of this create.
|
|
863
|
+
*/
|
|
864
|
+
create(data: T): Promise<WriteResult>;
|
|
865
|
+
/**
|
|
866
|
+
* Writes to the document referred to by this `DocumentReference`. If the
|
|
867
|
+
* document does not yet exist, it will be created. If you pass
|
|
868
|
+
* `SetOptions`, the provided data can be merged into an existing document.
|
|
869
|
+
*
|
|
870
|
+
* @param data A map of the fields and values for the document.
|
|
871
|
+
* @param options An object to configure the set behavior.
|
|
872
|
+
* @return A Promise resolved with the write time of this set.
|
|
873
|
+
*/
|
|
874
|
+
set(data: Partial<T>, options: SetOptions): Promise<WriteResult>;
|
|
875
|
+
set(data: T): Promise<WriteResult>;
|
|
876
|
+
/**
|
|
877
|
+
* Updates fields in the document referred to by this `DocumentReference`.
|
|
878
|
+
* The update will fail if applied to a document that does not exist.
|
|
879
|
+
*
|
|
880
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
881
|
+
* strings.
|
|
882
|
+
*
|
|
883
|
+
* @param data An object containing the fields and values with which to
|
|
884
|
+
* update the document.
|
|
885
|
+
* @param precondition A Precondition to enforce on this update.
|
|
886
|
+
* @return A Promise resolved with the write time of this update.
|
|
887
|
+
*/
|
|
888
|
+
update(data: UpdateData, precondition?: Precondition): Promise<WriteResult>;
|
|
889
|
+
/**
|
|
890
|
+
* Updates fields in the document referred to by this `DocumentReference`.
|
|
891
|
+
* The update will fail if applied to a document that does not exist.
|
|
892
|
+
*
|
|
893
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
894
|
+
* strings or by providing FieldPath objects.
|
|
895
|
+
*
|
|
896
|
+
* A `Precondition` restricting this update can be specified as the last
|
|
897
|
+
* argument.
|
|
898
|
+
*
|
|
899
|
+
* @param field The first field to update.
|
|
900
|
+
* @param value The first value.
|
|
901
|
+
* @param moreFieldsOrPrecondition An alternating list of field paths and
|
|
902
|
+
* values to update, optionally followed by a `Precondition` to enforce on
|
|
903
|
+
* this update.
|
|
904
|
+
* @return A Promise resolved with the write time of this update.
|
|
905
|
+
*/
|
|
906
|
+
update(field: string | FieldPath, value: any, ...moreFieldsOrPrecondition: any[]): Promise<WriteResult>;
|
|
907
|
+
/**
|
|
908
|
+
* Deletes the document referred to by this `DocumentReference`.
|
|
909
|
+
*
|
|
910
|
+
* @param precondition A Precondition to enforce for this delete.
|
|
911
|
+
* @return A Promise resolved with the write time of this delete.
|
|
912
|
+
*/
|
|
913
|
+
delete(precondition?: Precondition): Promise<WriteResult>;
|
|
914
|
+
/**
|
|
915
|
+
* Reads the document referred to by this `DocumentReference`.
|
|
916
|
+
*
|
|
917
|
+
* @return A Promise resolved with a DocumentSnapshot containing the
|
|
918
|
+
* current document contents.
|
|
919
|
+
*/
|
|
920
|
+
get(): Promise<DocumentSnapshot<T>>;
|
|
921
|
+
/**
|
|
922
|
+
* Attaches a listener for DocumentSnapshot events.
|
|
923
|
+
*
|
|
924
|
+
* @param onNext A callback to be called every time a new `DocumentSnapshot`
|
|
925
|
+
* is available.
|
|
926
|
+
* @param onError A callback to be called if the listen fails or is
|
|
927
|
+
* cancelled. No further callbacks will occur.
|
|
928
|
+
* @return An unsubscribe function that can be called to cancel
|
|
929
|
+
* the snapshot listener.
|
|
930
|
+
*/
|
|
931
|
+
onSnapshot(onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: Error) => void): () => void;
|
|
932
|
+
/**
|
|
933
|
+
* Returns true if this `DocumentReference` is equal to the provided one.
|
|
934
|
+
*
|
|
935
|
+
* @param other The `DocumentReference` to compare against.
|
|
936
|
+
* @return true if this `DocumentReference` is equal to the provided one.
|
|
937
|
+
*/
|
|
938
|
+
isEqual(other: DocumentReference<T>): boolean;
|
|
939
|
+
/**
|
|
940
|
+
* Applies a custom data converter to this DocumentReference, allowing you
|
|
941
|
+
* to use your own custom model objects with Firestore. When you call
|
|
942
|
+
* set(), get(), etc. on the returned DocumentReference instance, the
|
|
943
|
+
* provided converter will convert between Firestore data and your custom
|
|
944
|
+
* type U.
|
|
945
|
+
*
|
|
946
|
+
* @param converter Converts objects to and from Firestore. Passing in
|
|
947
|
+
* `null` removes the current converter.
|
|
948
|
+
* @return A DocumentReference<U> that uses the provided converter.
|
|
949
|
+
*/
|
|
950
|
+
withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
|
|
951
|
+
withConverter(converter: null): DocumentReference<DocumentData>;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* A `DocumentSnapshot` contains data read from a document in your Firestore
|
|
955
|
+
* database. The data can be extracted with `.data()` or `.get(<field>)` to
|
|
956
|
+
* get a specific field.
|
|
957
|
+
*
|
|
958
|
+
* For a `DocumentSnapshot` that points to a non-existing document, any data
|
|
959
|
+
* access will return 'undefined'. You can use the `exists` property to
|
|
960
|
+
* explicitly verify a document's existence.
|
|
961
|
+
*/
|
|
962
|
+
class DocumentSnapshot<T = DocumentData> {
|
|
963
|
+
protected constructor();
|
|
964
|
+
/** True if the document exists. */
|
|
965
|
+
readonly exists: boolean;
|
|
966
|
+
/** A `DocumentReference` to the document location. */
|
|
967
|
+
readonly ref: DocumentReference<T>;
|
|
968
|
+
/**
|
|
969
|
+
* The ID of the document for which this `DocumentSnapshot` contains data.
|
|
970
|
+
*/
|
|
971
|
+
readonly id: string;
|
|
972
|
+
/**
|
|
973
|
+
* The time the document was created. Not set for documents that don't
|
|
974
|
+
* exist.
|
|
975
|
+
*/
|
|
976
|
+
readonly createTime?: Timestamp;
|
|
977
|
+
/**
|
|
978
|
+
* The time the document was last updated (at the time the snapshot was
|
|
979
|
+
* generated). Not set for documents that don't exist.
|
|
980
|
+
*/
|
|
981
|
+
readonly updateTime?: Timestamp;
|
|
982
|
+
/**
|
|
983
|
+
* The time this snapshot was read.
|
|
984
|
+
*/
|
|
985
|
+
readonly readTime: Timestamp;
|
|
986
|
+
/**
|
|
987
|
+
* Retrieves all fields in the document as an Object. Returns 'undefined' if
|
|
988
|
+
* the document doesn't exist.
|
|
989
|
+
*
|
|
990
|
+
* @return An Object containing all fields in the document.
|
|
991
|
+
*/
|
|
992
|
+
data(): T | undefined;
|
|
993
|
+
/**
|
|
994
|
+
* Retrieves the field specified by `fieldPath`.
|
|
995
|
+
*
|
|
996
|
+
* @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field.
|
|
997
|
+
* @return The data at the specified field location or undefined if no such
|
|
998
|
+
* field exists in the document.
|
|
999
|
+
*/
|
|
1000
|
+
get(fieldPath: string | FieldPath): any;
|
|
1001
|
+
/**
|
|
1002
|
+
* Returns true if the document's data and path in this `DocumentSnapshot`
|
|
1003
|
+
* is equal to the provided one.
|
|
1004
|
+
*
|
|
1005
|
+
* @param other The `DocumentSnapshot` to compare against.
|
|
1006
|
+
* @return true if this `DocumentSnapshot` is equal to the provided one.
|
|
1007
|
+
*/
|
|
1008
|
+
isEqual(other: DocumentSnapshot<T>): boolean;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* A `QueryDocumentSnapshot` contains data read from a document in your
|
|
1012
|
+
* Firestore database as part of a query. The document is guaranteed to exist
|
|
1013
|
+
* and its data can be extracted with `.data()` or `.get(<field>)` to get a
|
|
1014
|
+
* specific field.
|
|
1015
|
+
*
|
|
1016
|
+
* A `QueryDocumentSnapshot` offers the same API surface as a
|
|
1017
|
+
* `DocumentSnapshot`. Since query results contain only existing documents, the
|
|
1018
|
+
* `exists` property will always be true and `data()` will never return
|
|
1019
|
+
* 'undefined'.
|
|
1020
|
+
*/
|
|
1021
|
+
class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<T> {
|
|
1022
|
+
private constructor();
|
|
1023
|
+
/**
|
|
1024
|
+
* The time the document was created.
|
|
1025
|
+
*/
|
|
1026
|
+
readonly createTime: Timestamp;
|
|
1027
|
+
/**
|
|
1028
|
+
* The time the document was last updated (at the time the snapshot was
|
|
1029
|
+
* generated).
|
|
1030
|
+
*/
|
|
1031
|
+
readonly updateTime: Timestamp;
|
|
1032
|
+
/**
|
|
1033
|
+
* Retrieves all fields in the document as an Object.
|
|
1034
|
+
*
|
|
1035
|
+
* @override
|
|
1036
|
+
* @return An Object containing all fields in the document.
|
|
1037
|
+
*/
|
|
1038
|
+
data(): T;
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc'
|
|
1042
|
+
* (descending or ascending).
|
|
1043
|
+
*/
|
|
1044
|
+
type OrderByDirection = 'desc' | 'asc';
|
|
1045
|
+
/**
|
|
1046
|
+
* Filter conditions in a `Query.where()` clause are specified using the
|
|
1047
|
+
* strings '<', '<=', '==', '!=', '>=', '>', 'array-contains', 'in', 'not-in',
|
|
1048
|
+
* and 'array-contains-any'.
|
|
1049
|
+
*/
|
|
1050
|
+
type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'not-in' | 'array-contains-any';
|
|
1051
|
+
/**
|
|
1052
|
+
* A `Query` refers to a Query which you can read or listen to. You can also
|
|
1053
|
+
* construct refined `Query` objects by adding filters and ordering.
|
|
1054
|
+
*/
|
|
1055
|
+
class Query<T = DocumentData> {
|
|
1056
|
+
protected constructor();
|
|
1057
|
+
/**
|
|
1058
|
+
* The `Firestore` for the Firestore database (useful for performing
|
|
1059
|
+
* transactions, etc.).
|
|
1060
|
+
*/
|
|
1061
|
+
readonly firestore: Firestore;
|
|
1062
|
+
/**
|
|
1063
|
+
* Creates and returns a new Query with the additional filter that documents
|
|
1064
|
+
* must contain the specified field and that its value should satisfy the
|
|
1065
|
+
* relation constraint provided.
|
|
1066
|
+
*
|
|
1067
|
+
* This function returns a new (immutable) instance of the Query (rather
|
|
1068
|
+
* than modify the existing instance) to impose the filter.
|
|
1069
|
+
*
|
|
1070
|
+
* @param fieldPath The path to compare
|
|
1071
|
+
* @param opStr The operation string (e.g "<", "<=", "==", ">", ">=").
|
|
1072
|
+
* @param value The value for comparison
|
|
1073
|
+
* @return The created Query.
|
|
1074
|
+
*/
|
|
1075
|
+
where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: any): Query<T>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Creates and returns a new Query that's additionally sorted by the
|
|
1078
|
+
* specified field, optionally in descending order instead of ascending.
|
|
1079
|
+
*
|
|
1080
|
+
* This function returns a new (immutable) instance of the Query (rather
|
|
1081
|
+
* than modify the existing instance) to impose the order.
|
|
1082
|
+
*
|
|
1083
|
+
* @param fieldPath The field to sort by.
|
|
1084
|
+
* @param directionStr Optional direction to sort by ('asc' or 'desc'). If
|
|
1085
|
+
* not specified, order will be ascending.
|
|
1086
|
+
* @return The created Query.
|
|
1087
|
+
*/
|
|
1088
|
+
orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): Query<T>;
|
|
1089
|
+
/**
|
|
1090
|
+
* Creates and returns a new Query that only returns the first matching
|
|
1091
|
+
* documents.
|
|
1092
|
+
*
|
|
1093
|
+
* This function returns a new (immutable) instance of the Query (rather
|
|
1094
|
+
* than modify the existing instance) to impose the limit.
|
|
1095
|
+
*
|
|
1096
|
+
* @param limit The maximum number of items to return.
|
|
1097
|
+
* @return The created Query.
|
|
1098
|
+
*/
|
|
1099
|
+
limit(limit: number): Query<T>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Creates and returns a new Query that only returns the last matching
|
|
1102
|
+
* documents.
|
|
1103
|
+
*
|
|
1104
|
+
* You must specify at least one orderBy clause for limitToLast queries,
|
|
1105
|
+
* otherwise an exception will be thrown during execution.
|
|
1106
|
+
*
|
|
1107
|
+
* Results for limitToLast queries cannot be streamed via the `stream()`
|
|
1108
|
+
* API.
|
|
1109
|
+
*
|
|
1110
|
+
* @param limit The maximum number of items to return.
|
|
1111
|
+
* @return The created Query.
|
|
1112
|
+
*/
|
|
1113
|
+
limitToLast(limit: number): Query<T>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Specifies the offset of the returned results.
|
|
1116
|
+
*
|
|
1117
|
+
* This function returns a new (immutable) instance of the Query (rather
|
|
1118
|
+
* than modify the existing instance) to impose the offset.
|
|
1119
|
+
*
|
|
1120
|
+
* @param offset The offset to apply to the Query results.
|
|
1121
|
+
* @return The created Query.
|
|
1122
|
+
*/
|
|
1123
|
+
offset(offset: number): Query<T>;
|
|
1124
|
+
/**
|
|
1125
|
+
* Creates and returns a new Query instance that applies a field mask to
|
|
1126
|
+
* the result and returns only the specified subset of fields. You can
|
|
1127
|
+
* specify a list of field paths to return, or use an empty list to only
|
|
1128
|
+
* return the references of matching documents.
|
|
1129
|
+
*
|
|
1130
|
+
* Queries that contain field masks cannot be listened to via `onSnapshot()`
|
|
1131
|
+
* listeners.
|
|
1132
|
+
*
|
|
1133
|
+
* This function returns a new (immutable) instance of the Query (rather
|
|
1134
|
+
* than modify the existing instance) to impose the field mask.
|
|
1135
|
+
*
|
|
1136
|
+
* @param field The field paths to return.
|
|
1137
|
+
* @return The created Query.
|
|
1138
|
+
*/
|
|
1139
|
+
select(...field: (string | FieldPath)[]): Query<DocumentData>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Creates and returns a new Query that starts at the provided document
|
|
1142
|
+
* (inclusive). The starting position is relative to the order of the query.
|
|
1143
|
+
* The document must contain all of the fields provided in the orderBy of
|
|
1144
|
+
* this query.
|
|
1145
|
+
*
|
|
1146
|
+
* @param snapshot The snapshot of the document to start after.
|
|
1147
|
+
* @return The created Query.
|
|
1148
|
+
*/
|
|
1149
|
+
startAt(snapshot: DocumentSnapshot<any>): Query<T>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Creates and returns a new Query that starts at the provided fields
|
|
1152
|
+
* relative to the order of the query. The order of the field values
|
|
1153
|
+
* must match the order of the order by clauses of the query.
|
|
1154
|
+
*
|
|
1155
|
+
* @param fieldValues The field values to start this query at, in order
|
|
1156
|
+
* of the query's order by.
|
|
1157
|
+
* @return The created Query.
|
|
1158
|
+
*/
|
|
1159
|
+
startAt(...fieldValues: any[]): Query<T>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Creates and returns a new Query that starts after the provided document
|
|
1162
|
+
* (exclusive). The starting position is relative to the order of the query.
|
|
1163
|
+
* The document must contain all of the fields provided in the orderBy of
|
|
1164
|
+
* this query.
|
|
1165
|
+
*
|
|
1166
|
+
* @param snapshot The snapshot of the document to start after.
|
|
1167
|
+
* @return The created Query.
|
|
1168
|
+
*/
|
|
1169
|
+
startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
|
|
1170
|
+
/**
|
|
1171
|
+
* Creates and returns a new Query that starts after the provided fields
|
|
1172
|
+
* relative to the order of the query. The order of the field values
|
|
1173
|
+
* must match the order of the order by clauses of the query.
|
|
1174
|
+
*
|
|
1175
|
+
* @param fieldValues The field values to start this query after, in order
|
|
1176
|
+
* of the query's order by.
|
|
1177
|
+
* @return The created Query.
|
|
1178
|
+
*/
|
|
1179
|
+
startAfter(...fieldValues: any[]): Query<T>;
|
|
1180
|
+
/**
|
|
1181
|
+
* Creates and returns a new Query that ends before the provided document
|
|
1182
|
+
* (exclusive). The end position is relative to the order of the query. The
|
|
1183
|
+
* document must contain all of the fields provided in the orderBy of this
|
|
1184
|
+
* query.
|
|
1185
|
+
*
|
|
1186
|
+
* @param snapshot The snapshot of the document to end before.
|
|
1187
|
+
* @return The created Query.
|
|
1188
|
+
*/
|
|
1189
|
+
endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
|
|
1190
|
+
/**
|
|
1191
|
+
* Creates and returns a new Query that ends before the provided fields
|
|
1192
|
+
* relative to the order of the query. The order of the field values
|
|
1193
|
+
* must match the order of the order by clauses of the query.
|
|
1194
|
+
*
|
|
1195
|
+
* @param fieldValues The field values to end this query before, in order
|
|
1196
|
+
* of the query's order by.
|
|
1197
|
+
* @return The created Query.
|
|
1198
|
+
*/
|
|
1199
|
+
endBefore(...fieldValues: any[]): Query<T>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Creates and returns a new Query that ends at the provided document
|
|
1202
|
+
* (inclusive). The end position is relative to the order of the query. The
|
|
1203
|
+
* document must contain all of the fields provided in the orderBy of this
|
|
1204
|
+
* query.
|
|
1205
|
+
*
|
|
1206
|
+
* @param snapshot The snapshot of the document to end at.
|
|
1207
|
+
* @return The created Query.
|
|
1208
|
+
*/
|
|
1209
|
+
endAt(snapshot: DocumentSnapshot<any>): Query<T>;
|
|
1210
|
+
/**
|
|
1211
|
+
* Creates and returns a new Query that ends at the provided fields
|
|
1212
|
+
* relative to the order of the query. The order of the field values
|
|
1213
|
+
* must match the order of the order by clauses of the query.
|
|
1214
|
+
*
|
|
1215
|
+
* @param fieldValues The field values to end this query at, in order
|
|
1216
|
+
* of the query's order by.
|
|
1217
|
+
* @return The created Query.
|
|
1218
|
+
*/
|
|
1219
|
+
endAt(...fieldValues: any[]): Query<T>;
|
|
1220
|
+
/**
|
|
1221
|
+
* Executes the query and returns the results as a `QuerySnapshot`.
|
|
1222
|
+
*
|
|
1223
|
+
* @return A Promise that will be resolved with the results of the Query.
|
|
1224
|
+
*/
|
|
1225
|
+
get(): Promise<QuerySnapshot<T>>;
|
|
1226
|
+
stream(): NodeJS.ReadableStream;
|
|
1227
|
+
/**
|
|
1228
|
+
* Attaches a listener for `QuerySnapshot `events.
|
|
1229
|
+
*
|
|
1230
|
+
* @param onNext A callback to be called every time a new `QuerySnapshot`
|
|
1231
|
+
* is available.
|
|
1232
|
+
* @param onError A callback to be called if the listen fails or is
|
|
1233
|
+
* cancelled. No further callbacks will occur.
|
|
1234
|
+
* @return An unsubscribe function that can be called to cancel
|
|
1235
|
+
* the snapshot listener.
|
|
1236
|
+
*/
|
|
1237
|
+
onSnapshot(onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: Error) => void): () => void;
|
|
1238
|
+
/**
|
|
1239
|
+
* Returns true if this `Query` is equal to the provided one.
|
|
1240
|
+
*
|
|
1241
|
+
* @param other The `Query` to compare against.
|
|
1242
|
+
* @return true if this `Query` is equal to the provided one.
|
|
1243
|
+
*/
|
|
1244
|
+
isEqual(other: Query<T>): boolean;
|
|
1245
|
+
/**
|
|
1246
|
+
* Applies a custom data converter to this Query, allowing you to use your
|
|
1247
|
+
* own custom model objects with Firestore. When you call get() on the
|
|
1248
|
+
* returned Query, the provided converter will convert between Firestore
|
|
1249
|
+
* data and your custom type U.
|
|
1250
|
+
*
|
|
1251
|
+
* @param converter Converts objects to and from Firestore. Passing in
|
|
1252
|
+
* `null` removes the current converter.
|
|
1253
|
+
* @return A Query<U> that uses the provided converter.
|
|
1254
|
+
*/
|
|
1255
|
+
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
|
|
1256
|
+
withConverter(converter: null): Query<DocumentData>;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* A `QuerySnapshot` contains zero or more `QueryDocumentSnapshot` objects
|
|
1260
|
+
* representing the results of a query. The documents can be accessed as an
|
|
1261
|
+
* array via the `docs` property or enumerated using the `forEach` method. The
|
|
1262
|
+
* number of documents can be determined via the `empty` and `size`
|
|
1263
|
+
* properties.
|
|
1264
|
+
*/
|
|
1265
|
+
class QuerySnapshot<T = DocumentData> {
|
|
1266
|
+
private constructor();
|
|
1267
|
+
/**
|
|
1268
|
+
* The query on which you called `get` or `onSnapshot` in order to get this
|
|
1269
|
+
* `QuerySnapshot`.
|
|
1270
|
+
*/
|
|
1271
|
+
readonly query: Query<T>;
|
|
1272
|
+
/** An array of all the documents in the QuerySnapshot. */
|
|
1273
|
+
readonly docs: Array<QueryDocumentSnapshot<T>>;
|
|
1274
|
+
/** The number of documents in the QuerySnapshot. */
|
|
1275
|
+
readonly size: number;
|
|
1276
|
+
/** True if there are no documents in the QuerySnapshot. */
|
|
1277
|
+
readonly empty: boolean;
|
|
1278
|
+
/** The time this query snapshot was obtained. */
|
|
1279
|
+
readonly readTime: Timestamp;
|
|
1280
|
+
/**
|
|
1281
|
+
* Returns an array of the documents changes since the last snapshot. If
|
|
1282
|
+
* this is the first snapshot, all documents will be in the list as added
|
|
1283
|
+
* changes.
|
|
1284
|
+
*/
|
|
1285
|
+
docChanges(): DocumentChange<T>[];
|
|
1286
|
+
/**
|
|
1287
|
+
* Enumerates all of the documents in the QuerySnapshot.
|
|
1288
|
+
*
|
|
1289
|
+
* @param callback A callback to be called with a `DocumentSnapshot` for
|
|
1290
|
+
* each document in the snapshot.
|
|
1291
|
+
* @param thisArg The `this` binding for the callback.
|
|
1292
|
+
*/
|
|
1293
|
+
forEach(callback: (result: QueryDocumentSnapshot<T>) => void, thisArg?: any): void;
|
|
1294
|
+
/**
|
|
1295
|
+
* Returns true if the document data in this `QuerySnapshot` is equal to the
|
|
1296
|
+
* provided one.
|
|
1297
|
+
*
|
|
1298
|
+
* @param other The `QuerySnapshot` to compare against.
|
|
1299
|
+
* @return true if this `QuerySnapshot` is equal to the provided one.
|
|
1300
|
+
*/
|
|
1301
|
+
isEqual(other: QuerySnapshot<T>): boolean;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* The type of of a `DocumentChange` may be 'added', 'removed', or 'modified'.
|
|
1305
|
+
*/
|
|
1306
|
+
type DocumentChangeType = 'added' | 'removed' | 'modified';
|
|
1307
|
+
/**
|
|
1308
|
+
* A `DocumentChange` represents a change to the documents matching a query.
|
|
1309
|
+
* It contains the document affected and the type of change that occurred.
|
|
1310
|
+
*/
|
|
1311
|
+
interface DocumentChange<T = DocumentData> {
|
|
1312
|
+
/** The type of change ('added', 'modified', or 'removed'). */
|
|
1313
|
+
readonly type: DocumentChangeType;
|
|
1314
|
+
/** The document affected by this change. */
|
|
1315
|
+
readonly doc: QueryDocumentSnapshot<T>;
|
|
1316
|
+
/**
|
|
1317
|
+
* The index of the changed document in the result set immediately prior to
|
|
1318
|
+
* this DocumentChange (i.e. supposing that all prior DocumentChange objects
|
|
1319
|
+
* have been applied). Is -1 for 'added' events.
|
|
1320
|
+
*/
|
|
1321
|
+
readonly oldIndex: number;
|
|
1322
|
+
/**
|
|
1323
|
+
* The index of the changed document in the result set immediately after
|
|
1324
|
+
* this DocumentChange (i.e. supposing that all prior DocumentChange
|
|
1325
|
+
* objects and the current DocumentChange object have been applied).
|
|
1326
|
+
* Is -1 for 'removed' events.
|
|
1327
|
+
*/
|
|
1328
|
+
readonly newIndex: number;
|
|
1329
|
+
/**
|
|
1330
|
+
* Returns true if the data in this `DocumentChange` is equal to the
|
|
1331
|
+
* provided one.
|
|
1332
|
+
*
|
|
1333
|
+
* @param other The `DocumentChange` to compare against.
|
|
1334
|
+
* @return true if this `DocumentChange` is equal to the provided one.
|
|
1335
|
+
*/
|
|
1336
|
+
isEqual(other: DocumentChange<T>): boolean;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* A `CollectionReference` object can be used for adding documents, getting
|
|
1340
|
+
* document references, and querying for documents (using the methods
|
|
1341
|
+
* inherited from `Query`).
|
|
1342
|
+
*/
|
|
1343
|
+
class CollectionReference<T = DocumentData> extends Query<T> {
|
|
1344
|
+
private constructor();
|
|
1345
|
+
/** The identifier of the collection. */
|
|
1346
|
+
readonly id: string;
|
|
1347
|
+
/**
|
|
1348
|
+
* A reference to the containing Document if this is a subcollection, else
|
|
1349
|
+
* null.
|
|
1350
|
+
*/
|
|
1351
|
+
readonly parent: DocumentReference<DocumentData> | null;
|
|
1352
|
+
/**
|
|
1353
|
+
* A string representing the path of the referenced collection (relative
|
|
1354
|
+
* to the root of the database).
|
|
1355
|
+
*/
|
|
1356
|
+
readonly path: string;
|
|
1357
|
+
/**
|
|
1358
|
+
* Retrieves the list of documents in this collection.
|
|
1359
|
+
*
|
|
1360
|
+
* The document references returned may include references to "missing
|
|
1361
|
+
* documents", i.e. document locations that have no document present but
|
|
1362
|
+
* which contain subcollections with documents. Attempting to read such a
|
|
1363
|
+
* document reference (e.g. via `.get()` or `.onSnapshot()`) will return a
|
|
1364
|
+
* `DocumentSnapshot` whose `.exists` property is false.
|
|
1365
|
+
*
|
|
1366
|
+
* @return {Promise<DocumentReference[]>} The list of documents in this
|
|
1367
|
+
* collection.
|
|
1368
|
+
*/
|
|
1369
|
+
listDocuments(): Promise<Array<DocumentReference<T>>>;
|
|
1370
|
+
/**
|
|
1371
|
+
* Get a `DocumentReference` for a randomly-named document within this
|
|
1372
|
+
* collection. An automatically-generated unique ID will be used as the
|
|
1373
|
+
* document ID.
|
|
1374
|
+
*
|
|
1375
|
+
* @return The `DocumentReference` instance.
|
|
1376
|
+
*/
|
|
1377
|
+
doc(): DocumentReference<T>;
|
|
1378
|
+
/**
|
|
1379
|
+
* Get a `DocumentReference` for the document within the collection at the
|
|
1380
|
+
* specified path.
|
|
1381
|
+
*
|
|
1382
|
+
* @param documentPath A slash-separated path to a document.
|
|
1383
|
+
* @return The `DocumentReference` instance.
|
|
1384
|
+
*/
|
|
1385
|
+
doc(documentPath: string): DocumentReference<T>;
|
|
1386
|
+
/**
|
|
1387
|
+
* Add a new document to this collection with the specified data, assigning
|
|
1388
|
+
* it a document ID automatically.
|
|
1389
|
+
*
|
|
1390
|
+
* @param data An Object containing the data for the new document.
|
|
1391
|
+
* @return A Promise resolved with a `DocumentReference` pointing to the
|
|
1392
|
+
* newly created document after it has been written to the backend.
|
|
1393
|
+
*/
|
|
1394
|
+
add(data: T): Promise<DocumentReference<T>>;
|
|
1395
|
+
/**
|
|
1396
|
+
* Returns true if this `CollectionReference` is equal to the provided one.
|
|
1397
|
+
*
|
|
1398
|
+
* @param other The `CollectionReference` to compare against.
|
|
1399
|
+
* @return true if this `CollectionReference` is equal to the provided one.
|
|
1400
|
+
*/
|
|
1401
|
+
isEqual(other: CollectionReference<T>): boolean;
|
|
1402
|
+
/**
|
|
1403
|
+
* Applies a custom data converter to this CollectionReference, allowing you
|
|
1404
|
+
* to use your own custom model objects with Firestore. When you call add()
|
|
1405
|
+
* on the returned CollectionReference instance, the provided converter will
|
|
1406
|
+
* convert between Firestore data and your custom type U.
|
|
1407
|
+
*
|
|
1408
|
+
* @param converter Converts objects to and from Firestore. Passing in
|
|
1409
|
+
* `null` removes the current converter.
|
|
1410
|
+
* @return A CollectionReference<U> that uses the provided converter.
|
|
1411
|
+
*/
|
|
1412
|
+
withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>;
|
|
1413
|
+
withConverter(converter: null): CollectionReference<DocumentData>;
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* A `CollectionGroup` refers to all documents that are contained in a
|
|
1417
|
+
* collection or subcollection with a specific collection ID.
|
|
1418
|
+
*/
|
|
1419
|
+
class CollectionGroup<T = DocumentData> extends Query<T> {
|
|
1420
|
+
private constructor();
|
|
1421
|
+
/**
|
|
1422
|
+
* Partitions a query by returning partition cursors that can be used to run
|
|
1423
|
+
* the query in parallel. The returned cursors are split points that can be
|
|
1424
|
+
* used as starting and end points for individual query invocations.
|
|
1425
|
+
*
|
|
1426
|
+
* @param desiredPartitionCount The desired maximum number of partition
|
|
1427
|
+
* points. The number must be strictly positive. The actual number of
|
|
1428
|
+
* partitions returned may be fewer.
|
|
1429
|
+
* @return An AsyncIterable of `QueryPartition`s.
|
|
1430
|
+
*/
|
|
1431
|
+
getPartitions(desiredPartitionCount: number): AsyncIterable<QueryPartition<T>>;
|
|
1432
|
+
/**
|
|
1433
|
+
* Applies a custom data converter to this `CollectionGroup`, allowing you
|
|
1434
|
+
* to use your own custom model objects with Firestore. When you call get()
|
|
1435
|
+
* on the returned `CollectionGroup`, the provided converter will convert
|
|
1436
|
+
* between Firestore data and your custom type U.
|
|
1437
|
+
*
|
|
1438
|
+
* Using the converter allows you to specify generic type arguments when
|
|
1439
|
+
* storing and retrieving objects from Firestore.
|
|
1440
|
+
*
|
|
1441
|
+
* @example
|
|
1442
|
+
* class Post {
|
|
1443
|
+
* constructor(readonly title: string, readonly author: string) {}
|
|
1444
|
+
*
|
|
1445
|
+
* toString(): string {
|
|
1446
|
+
* return this.title + ', by ' + this.author;
|
|
1447
|
+
* }
|
|
1448
|
+
* }
|
|
1449
|
+
*
|
|
1450
|
+
* const postConverter = {
|
|
1451
|
+
* toFirestore(post: Post): FirebaseFirestore.DocumentData {
|
|
1452
|
+
* return {title: post.title, author: post.author};
|
|
1453
|
+
* },
|
|
1454
|
+
* fromFirestore(
|
|
1455
|
+
* snapshot: FirebaseFirestore.QueryDocumentSnapshot
|
|
1456
|
+
* ): Post {
|
|
1457
|
+
* const data = snapshot.data();
|
|
1458
|
+
* return new Post(data.title, data.author);
|
|
1459
|
+
* }
|
|
1460
|
+
* };
|
|
1461
|
+
*
|
|
1462
|
+
* const querySnapshot = await Firestore()
|
|
1463
|
+
* .collectionGroup('posts')
|
|
1464
|
+
* .withConverter(postConverter)
|
|
1465
|
+
* .get();
|
|
1466
|
+
* for (const doc of querySnapshot.docs) {
|
|
1467
|
+
* const post = doc.data();
|
|
1468
|
+
* post.title; // string
|
|
1469
|
+
* post.toString(); // Should be defined
|
|
1470
|
+
* post.someNonExistentProperty; // TS error
|
|
1471
|
+
* }
|
|
1472
|
+
*
|
|
1473
|
+
* @param converter Converts objects to and from Firestore. Passing in
|
|
1474
|
+
* `null` removes the current converter.
|
|
1475
|
+
* @return A `CollectionGroup<U>` that uses the provided converter.
|
|
1476
|
+
*/
|
|
1477
|
+
withConverter<U>(converter: FirestoreDataConverter<U>): CollectionGroup<U>;
|
|
1478
|
+
withConverter(converter: null): CollectionGroup<DocumentData>;
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* A split point that can be used in a query as a starting and/or end point for
|
|
1482
|
+
* the query results. The cursors returned by {@link #startAt} and {@link
|
|
1483
|
+
* #endBefore} can only be used in a query that matches the constraint of query
|
|
1484
|
+
* that produced this partition.
|
|
1485
|
+
*/
|
|
1486
|
+
class QueryPartition<T = DocumentData> {
|
|
1487
|
+
private constructor();
|
|
1488
|
+
/**
|
|
1489
|
+
* The cursor that defines the first result for this partition or
|
|
1490
|
+
* `undefined` if this is the first partition. The cursor value must be
|
|
1491
|
+
* destructured when passed to `startAt()` (for example with
|
|
1492
|
+
* `query.startAt(...queryPartition.startAt)`).
|
|
1493
|
+
*
|
|
1494
|
+
* @return Cursor values that can be used with {@link Query#startAt} or
|
|
1495
|
+
* `undefined` if this is the first partition.
|
|
1496
|
+
*/
|
|
1497
|
+
get startAt(): unknown[] | undefined;
|
|
1498
|
+
/**
|
|
1499
|
+
* The cursor that defines the first result after this partition or
|
|
1500
|
+
* `undefined` if this is the last partition. The cursor value must be
|
|
1501
|
+
* destructured when passed to `endBefore()` (for example with
|
|
1502
|
+
* `query.endBefore(...queryPartition.endBefore)`).
|
|
1503
|
+
*
|
|
1504
|
+
* @return Cursor values that can be used with {@link Query#endBefore} or
|
|
1505
|
+
* `undefined` if this is the last partition.
|
|
1506
|
+
*/
|
|
1507
|
+
get endBefore(): unknown[] | undefined;
|
|
1508
|
+
/**
|
|
1509
|
+
* Returns a query that only returns the documents for this partition.
|
|
1510
|
+
*
|
|
1511
|
+
* @return A query partitioned by a {@link Query#startAt} and {@link
|
|
1512
|
+
* Query#endBefore} cursor.
|
|
1513
|
+
*/
|
|
1514
|
+
toQuery(): Query<T>;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Sentinel values that can be used when writing document fields with set(),
|
|
1518
|
+
* create() or update().
|
|
1519
|
+
*/
|
|
1520
|
+
class FieldValue {
|
|
1521
|
+
private constructor();
|
|
1522
|
+
/**
|
|
1523
|
+
* Returns a sentinel used with set(), create() or update() to include a
|
|
1524
|
+
* server-generated timestamp in the written data.
|
|
1525
|
+
*
|
|
1526
|
+
* @return The FieldValue sentinel for use in a call to set(), create() or
|
|
1527
|
+
* update().
|
|
1528
|
+
*/
|
|
1529
|
+
static serverTimestamp(): FieldValue;
|
|
1530
|
+
/**
|
|
1531
|
+
* Returns a sentinel for use with update() or set() with {merge:true} to
|
|
1532
|
+
* mark a field for deletion.
|
|
1533
|
+
*
|
|
1534
|
+
* @return The FieldValue sentinel for use in a call to set() or update().
|
|
1535
|
+
*/
|
|
1536
|
+
static delete(): FieldValue;
|
|
1537
|
+
/**
|
|
1538
|
+
* Returns a special value that can be used with set(), create() or update()
|
|
1539
|
+
* that tells the server to increment the field's current value by the given
|
|
1540
|
+
* value.
|
|
1541
|
+
*
|
|
1542
|
+
* If either current field value or the operand uses floating point
|
|
1543
|
+
* precision, both values will be interpreted as floating point numbers and
|
|
1544
|
+
* all arithmetic will follow IEEE 754 semantics. Otherwise, integer
|
|
1545
|
+
* precision is kept and the result is capped between -2^63 and 2^63-1.
|
|
1546
|
+
*
|
|
1547
|
+
* If the current field value is not of type 'number', or if the field does
|
|
1548
|
+
* not yet exist, the transformation will set the field to the given value.
|
|
1549
|
+
*
|
|
1550
|
+
* @param n The value to increment by.
|
|
1551
|
+
* @return The FieldValue sentinel for use in a call to set(), create() or
|
|
1552
|
+
* update().
|
|
1553
|
+
*/
|
|
1554
|
+
static increment(n: number): FieldValue;
|
|
1555
|
+
/**
|
|
1556
|
+
* Returns a special value that can be used with set(), create() or update()
|
|
1557
|
+
* that tells the server to union the given elements with any array value
|
|
1558
|
+
* that already exists on the server. Each specified element that doesn't
|
|
1559
|
+
* already exist in the array will be added to the end. If the field being
|
|
1560
|
+
* modified is not already an array it will be overwritten with an array
|
|
1561
|
+
* containing exactly the specified elements.
|
|
1562
|
+
*
|
|
1563
|
+
* @param elements The elements to union into the array.
|
|
1564
|
+
* @return The FieldValue sentinel for use in a call to set(), create() or
|
|
1565
|
+
* update().
|
|
1566
|
+
*/
|
|
1567
|
+
static arrayUnion(...elements: any[]): FieldValue;
|
|
1568
|
+
/**
|
|
1569
|
+
* Returns a special value that can be used with set(), create() or update()
|
|
1570
|
+
* that tells the server to remove the given elements from any array value
|
|
1571
|
+
* that already exists on the server. All instances of each element
|
|
1572
|
+
* specified will be removed from the array. If the field being modified is
|
|
1573
|
+
* not already an array it will be overwritten with an empty array.
|
|
1574
|
+
*
|
|
1575
|
+
* @param elements The elements to remove from the array.
|
|
1576
|
+
* @return The FieldValue sentinel for use in a call to set(), create() or
|
|
1577
|
+
* update().
|
|
1578
|
+
*/
|
|
1579
|
+
static arrayRemove(...elements: any[]): FieldValue;
|
|
1580
|
+
/**
|
|
1581
|
+
* Returns true if this `FieldValue` is equal to the provided one.
|
|
1582
|
+
*
|
|
1583
|
+
* @param other The `FieldValue` to compare against.
|
|
1584
|
+
* @return true if this `FieldValue` is equal to the provided one.
|
|
1585
|
+
*/
|
|
1586
|
+
isEqual(other: FieldValue): boolean;
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* A FieldPath refers to a field in a document. The path may consist of a
|
|
1590
|
+
* single field name (referring to a top-level field in the document), or a
|
|
1591
|
+
* list of field names (referring to a nested field in the document).
|
|
1592
|
+
*/
|
|
1593
|
+
class FieldPath {
|
|
1594
|
+
/**
|
|
1595
|
+
* Creates a FieldPath from the provided field names. If more than one field
|
|
1596
|
+
* name is provided, the path will point to a nested field in a document.
|
|
1597
|
+
*
|
|
1598
|
+
* @param fieldNames A list of field names.
|
|
1599
|
+
*/
|
|
1600
|
+
constructor(...fieldNames: string[]);
|
|
1601
|
+
/**
|
|
1602
|
+
* Returns a special sentinel FieldPath to refer to the ID of a document.
|
|
1603
|
+
* It can be used in queries to sort or filter by the document ID.
|
|
1604
|
+
*/
|
|
1605
|
+
static documentId(): FieldPath;
|
|
1606
|
+
/**
|
|
1607
|
+
* Returns true if this `FieldPath` is equal to the provided one.
|
|
1608
|
+
*
|
|
1609
|
+
* @param other The `FieldPath` to compare against.
|
|
1610
|
+
* @return true if this `FieldPath` is equal to the provided one.
|
|
1611
|
+
*/
|
|
1612
|
+
isEqual(other: FieldPath): boolean;
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* A Timestamp represents a point in time independent of any time zone or
|
|
1616
|
+
* calendar, represented as seconds and fractions of seconds at nanosecond
|
|
1617
|
+
* resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian
|
|
1618
|
+
* Calendar which extends the Gregorian calendar backwards to year one. It is
|
|
1619
|
+
* encoded assuming all minutes are 60 seconds long, i.e. leap seconds are
|
|
1620
|
+
* "smeared" so that no leap second table is needed for interpretation. Range
|
|
1621
|
+
* is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
|
|
1622
|
+
*
|
|
1623
|
+
* @see https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto
|
|
1624
|
+
*/
|
|
1625
|
+
class Timestamp {
|
|
1626
|
+
/**
|
|
1627
|
+
* Creates a new timestamp with the current date, with millisecond precision.
|
|
1628
|
+
*
|
|
1629
|
+
* @return A new `Timestamp` representing the current date.
|
|
1630
|
+
*/
|
|
1631
|
+
static now(): Timestamp;
|
|
1632
|
+
/**
|
|
1633
|
+
* Creates a new timestamp from the given date.
|
|
1634
|
+
*
|
|
1635
|
+
* @param date The date to initialize the `Timestamp` from.
|
|
1636
|
+
* @return A new `Timestamp` representing the same point in time as the
|
|
1637
|
+
* given date.
|
|
1638
|
+
*/
|
|
1639
|
+
static fromDate(date: Date): Timestamp;
|
|
1640
|
+
/**
|
|
1641
|
+
* Creates a new timestamp from the given number of milliseconds.
|
|
1642
|
+
*
|
|
1643
|
+
* @param milliseconds Number of milliseconds since Unix epoch
|
|
1644
|
+
* 1970-01-01T00:00:00Z.
|
|
1645
|
+
* @return A new `Timestamp` representing the same point in time as the
|
|
1646
|
+
* given number of milliseconds.
|
|
1647
|
+
*/
|
|
1648
|
+
static fromMillis(milliseconds: number): Timestamp;
|
|
1649
|
+
/**
|
|
1650
|
+
* Creates a new timestamp.
|
|
1651
|
+
*
|
|
1652
|
+
* @param seconds The number of seconds of UTC time since Unix epoch
|
|
1653
|
+
* 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
|
1654
|
+
* 9999-12-31T23:59:59Z inclusive.
|
|
1655
|
+
* @param nanoseconds The non-negative fractions of a second at nanosecond
|
|
1656
|
+
* resolution. Negative second values with fractions must still have
|
|
1657
|
+
* non-negative nanoseconds values that count forward in time. Must be from
|
|
1658
|
+
* 0 to 999,999,999 inclusive.
|
|
1659
|
+
*/
|
|
1660
|
+
constructor(seconds: number, nanoseconds: number);
|
|
1661
|
+
/**
|
|
1662
|
+
* The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
|
|
1663
|
+
*/
|
|
1664
|
+
readonly seconds: number;
|
|
1665
|
+
/** The non-negative fractions of a second at nanosecond resolution. */
|
|
1666
|
+
readonly nanoseconds: number;
|
|
1667
|
+
/**
|
|
1668
|
+
* Returns a new `Date` corresponding to this timestamp. This may lose
|
|
1669
|
+
* precision.
|
|
1670
|
+
*
|
|
1671
|
+
* @return JavaScript `Date` object representing the same point in time as
|
|
1672
|
+
* this `Timestamp`, with millisecond precision.
|
|
1673
|
+
*/
|
|
1674
|
+
toDate(): Date;
|
|
1675
|
+
/**
|
|
1676
|
+
* Returns the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
|
|
1677
|
+
*
|
|
1678
|
+
* @return The point in time corresponding to this timestamp, represented as
|
|
1679
|
+
* the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
|
|
1680
|
+
*/
|
|
1681
|
+
toMillis(): number;
|
|
1682
|
+
/**
|
|
1683
|
+
* Returns true if this `Timestamp` is equal to the provided one.
|
|
1684
|
+
*
|
|
1685
|
+
* @param other The `Timestamp` to compare against.
|
|
1686
|
+
* @return 'true' if this `Timestamp` is equal to the provided one.
|
|
1687
|
+
*/
|
|
1688
|
+
isEqual(other: Timestamp): boolean;
|
|
1689
|
+
/**
|
|
1690
|
+
* Converts this object to a primitive `string`, which allows `Timestamp` objects to be compared
|
|
1691
|
+
* using the `>`, `<=`, `>=` and `>` operators.
|
|
1692
|
+
*
|
|
1693
|
+
* @return a string encoding of this object.
|
|
1694
|
+
*/
|
|
1695
|
+
valueOf(): string;
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Builds a Firestore data bundle with results from the given document and query snapshots.
|
|
1699
|
+
*/
|
|
1700
|
+
class BundleBuilder {
|
|
1701
|
+
/** The ID of this bundle. */
|
|
1702
|
+
readonly bundleId: string;
|
|
1703
|
+
/**
|
|
1704
|
+
* Adds a Firestore `DocumentSnapshot` to the bundle. Both the documents data and the document
|
|
1705
|
+
* read time will be included in the bundle.
|
|
1706
|
+
*
|
|
1707
|
+
* @param documentSnapshot A `DocumentSnapshot` to add.
|
|
1708
|
+
* @returns This instance.
|
|
1709
|
+
*/
|
|
1710
|
+
add<T>(documentSnapshot: DocumentSnapshot<T>): BundleBuilder;
|
|
1711
|
+
/**
|
|
1712
|
+
* Adds a Firestore `QuerySnapshot` to the bundle. Both the documents in the query results and
|
|
1713
|
+
* the query read time will be included in the bundle.
|
|
1714
|
+
*
|
|
1715
|
+
* @param queryName The name of the query to add.
|
|
1716
|
+
* @param querySnapshot A `QuerySnapshot` to add to the bundle.
|
|
1717
|
+
* @returns This instance.
|
|
1718
|
+
*/
|
|
1719
|
+
add<T>(queryName: string, querySnapshot: QuerySnapshot<T>): BundleBuilder;
|
|
1720
|
+
/**
|
|
1721
|
+
* Builds the bundle and returns the result as a `Buffer` instance.
|
|
1722
|
+
*/
|
|
1723
|
+
build(): Buffer;
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* The v1beta1 Veneer client. This client provides access to to the underlying
|
|
1727
|
+
* Firestore v1beta1 RPCs.
|
|
1728
|
+
* @deprecated Use v1 instead.
|
|
1729
|
+
*/
|
|
1730
|
+
/**
|
|
1731
|
+
* The v1 Veneer clients. These clients provide access to the Firestore Admin
|
|
1732
|
+
* API and the underlying Firestore v1 RPCs.
|
|
1733
|
+
*/
|
|
1734
|
+
/**
|
|
1735
|
+
* Status codes returned by Firestore's gRPC calls.
|
|
1736
|
+
*/
|
|
1737
|
+
enum GrpcStatus {
|
|
1738
|
+
OK = 0,
|
|
1739
|
+
CANCELLED = 1,
|
|
1740
|
+
UNKNOWN = 2,
|
|
1741
|
+
INVALID_ARGUMENT = 3,
|
|
1742
|
+
DEADLINE_EXCEEDED = 4,
|
|
1743
|
+
NOT_FOUND = 5,
|
|
1744
|
+
ALREADY_EXISTS = 6,
|
|
1745
|
+
PERMISSION_DENIED = 7,
|
|
1746
|
+
RESOURCE_EXHAUSTED = 8,
|
|
1747
|
+
FAILED_PRECONDITION = 9,
|
|
1748
|
+
ABORTED = 10,
|
|
1749
|
+
OUT_OF_RANGE = 11,
|
|
1750
|
+
UNIMPLEMENTED = 12,
|
|
1751
|
+
INTERNAL = 13,
|
|
1752
|
+
UNAVAILABLE = 14,
|
|
1753
|
+
DATA_LOSS = 15,
|
|
1754
|
+
UNAUTHENTICATED = 16
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
declare module 'firestore-types' {
|
|
1758
|
+
export = FirebaseFirestoreTypes;
|
|
1759
|
+
}
|