@react-native-firebase/firestore 18.4.0 → 18.6.0
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/CHANGELOG.md +10 -0
- package/__tests__/firestore.test.ts +9 -9
- package/android/build.gradle +1 -1
- package/lib/index.js +2 -0
- package/lib/modular/Bytes.d.ts +11 -0
- package/lib/modular/Bytes.js +59 -0
- package/lib/modular/FieldPath.d.ts +13 -0
- package/lib/modular/FieldPath.js +3 -0
- package/lib/modular/FieldValue.d.ts +67 -0
- package/lib/modular/FieldValue.js +41 -0
- package/lib/modular/GeoPoint.d.ts +17 -0
- package/lib/modular/GeoPoint.js +3 -0
- package/lib/modular/Timestamp.d.ts +85 -0
- package/lib/modular/Timestamp.js +3 -0
- package/lib/modular/index.d.ts +535 -0
- package/lib/modular/index.js +218 -0
- package/lib/modular/query.d.ts +344 -0
- package/lib/modular/query.js +202 -0
- package/lib/modular/snapshot.d.ts +203 -0
- package/lib/modular/snapshot.js +14 -0
- package/lib/modular/utils/observer.js +16 -0
- package/lib/version.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { ReactNativeFirebase } from '@react-native-firebase/app';
|
|
2
|
+
import { FirebaseFirestoreTypes } from '../index';
|
|
3
|
+
|
|
4
|
+
import FirebaseApp = ReactNativeFirebase.FirebaseApp;
|
|
5
|
+
import Firestore = FirebaseFirestoreTypes.Module;
|
|
6
|
+
import CollectionReference = FirebaseFirestoreTypes.CollectionReference;
|
|
7
|
+
import DocumentReference = FirebaseFirestoreTypes.DocumentReference;
|
|
8
|
+
import DocumentData = FirebaseFirestoreTypes.DocumentData;
|
|
9
|
+
import Query = FirebaseFirestoreTypes.Query;
|
|
10
|
+
import FieldValue = FirebaseFirestoreTypes.FieldValue;
|
|
11
|
+
import FieldPath = FirebaseFirestoreTypes.FieldPath;
|
|
12
|
+
|
|
13
|
+
/** Primitive types. */
|
|
14
|
+
export type Primitive = string | number | boolean | undefined | null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Similar to Typescript's `Partial<T>`, but allows nested fields to be
|
|
18
|
+
* omitted and FieldValues to be passed in as property values.
|
|
19
|
+
*/
|
|
20
|
+
export type PartialWithFieldValue<T> =
|
|
21
|
+
| Partial<T>
|
|
22
|
+
| (T extends Primitive
|
|
23
|
+
? T
|
|
24
|
+
: T extends object
|
|
25
|
+
? { [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue }
|
|
26
|
+
: never);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Given a union type `U = T1 | T2 | ...`, returns an intersected type (`T1 & T2 & ...`).
|
|
30
|
+
*
|
|
31
|
+
* Uses distributive conditional types and inference from conditional types.
|
|
32
|
+
* This works because multiple candidates for the same type variable in contra-variant positions
|
|
33
|
+
* causes an intersection type to be inferred.
|
|
34
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
|
|
35
|
+
* https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
|
|
36
|
+
*/
|
|
37
|
+
export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (
|
|
38
|
+
k: infer I,
|
|
39
|
+
) => void
|
|
40
|
+
? I
|
|
41
|
+
: never;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a new map where every key is prefixed with the outer key appended to a dot.
|
|
45
|
+
*/
|
|
46
|
+
export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
|
|
47
|
+
[K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Helper for calculating the nested fields for a given type `T1`. This is needed to distribute
|
|
52
|
+
* union types such as `undefined | {...}` (happens for optional props) or `{a: A} | {b: B}`.
|
|
53
|
+
*
|
|
54
|
+
* In this use case, `V` is used to distribute the union types of `T[K]` on Record, since `T[K]`
|
|
55
|
+
* is evaluated as an expression and not distributed.
|
|
56
|
+
*
|
|
57
|
+
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
|
|
58
|
+
*/
|
|
59
|
+
export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown>
|
|
60
|
+
? AddPrefixToKeys<K, UpdateData<V>>
|
|
61
|
+
: never;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}).
|
|
65
|
+
* Intersect them together to make a single map containing all possible keys that are all marked as optional
|
|
66
|
+
*/
|
|
67
|
+
export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<
|
|
68
|
+
{
|
|
69
|
+
[K in keyof T & string]: ChildUpdateFields<K, T[K]>;
|
|
70
|
+
}[keyof T & string]
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Update data (for use with {@link updateDoc}) that consists of field paths (e.g. 'foo' or 'foo.baz')
|
|
75
|
+
* mapped to values. Fields that contain dots reference nested fields within the document.
|
|
76
|
+
* FieldValues can be passed in as property values.
|
|
77
|
+
*/
|
|
78
|
+
export declare type UpdateData<T> = T extends Primitive
|
|
79
|
+
? T
|
|
80
|
+
: T extends object
|
|
81
|
+
? {
|
|
82
|
+
[K in keyof T]?: UpdateData<T[K]> | FieldValue;
|
|
83
|
+
} & NestedUpdateFields<T>
|
|
84
|
+
: Partial<T>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Allows FieldValues to be passed in as a property value while maintaining
|
|
88
|
+
* type safety.
|
|
89
|
+
*/
|
|
90
|
+
export type WithFieldValue<T> =
|
|
91
|
+
| T
|
|
92
|
+
| (T extends Primitive
|
|
93
|
+
? T
|
|
94
|
+
: T extends object
|
|
95
|
+
? { [K in keyof T]: WithFieldValue<T[K]> | FieldValue }
|
|
96
|
+
: never);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the existing default {@link Firestore} instance that is associated with the
|
|
100
|
+
* default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
|
|
101
|
+
* instance with default settings.
|
|
102
|
+
*
|
|
103
|
+
* @returns The {@link Firestore} instance of the provided app.
|
|
104
|
+
*/
|
|
105
|
+
export declare function getFirestore(): Firestore;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returns the existing default {@link Firestore} instance that is associated with the
|
|
109
|
+
* provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
|
|
110
|
+
* instance with default settings.
|
|
111
|
+
*
|
|
112
|
+
* @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
|
|
113
|
+
* instance is associated with.
|
|
114
|
+
* @returns The {@link Firestore} instance of the provided app.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
export declare function getFirestore(app: FirebaseApp): Firestore;
|
|
118
|
+
|
|
119
|
+
export function getFirestore(app?: FirebaseApp): Firestore;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Gets a `DocumentReference` instance that refers to the document at the
|
|
123
|
+
* specified absolute path.
|
|
124
|
+
*
|
|
125
|
+
* @param firestore - A reference to the root `Firestore` instance.
|
|
126
|
+
* @param path - A slash-separated path to a document.
|
|
127
|
+
* @param pathSegments - Additional path segments that will be applied relative
|
|
128
|
+
* to the first argument.
|
|
129
|
+
* @throws If the final path has an odd number of segments and does not point to
|
|
130
|
+
* a document.
|
|
131
|
+
* @returns The `DocumentReference` instance.
|
|
132
|
+
*/
|
|
133
|
+
export function doc(
|
|
134
|
+
firestore: Firestore,
|
|
135
|
+
path: string,
|
|
136
|
+
...pathSegments: string[]
|
|
137
|
+
): DocumentReference<DocumentData>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets a `DocumentReference` instance that refers to a document within
|
|
141
|
+
* `reference` at the specified relative path. If no path is specified, an
|
|
142
|
+
* automatically-generated unique ID will be used for the returned
|
|
143
|
+
* `DocumentReference`.
|
|
144
|
+
*
|
|
145
|
+
* @param reference - A reference to a collection.
|
|
146
|
+
* @param path - A slash-separated path to a document. Has to be omitted to use
|
|
147
|
+
* auto-generated IDs.
|
|
148
|
+
* @param pathSegments - Additional path segments that will be applied relative
|
|
149
|
+
* to the first argument.
|
|
150
|
+
* @throws If the final path has an odd number of segments and does not point to
|
|
151
|
+
* a document.
|
|
152
|
+
* @returns The `DocumentReference` instance.
|
|
153
|
+
*/
|
|
154
|
+
export function doc<T>(
|
|
155
|
+
reference: CollectionReference<T>,
|
|
156
|
+
path?: string,
|
|
157
|
+
...pathSegments: string[]
|
|
158
|
+
): DocumentReference<T>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Gets a `DocumentReference` instance that refers to a document within
|
|
162
|
+
* `reference` at the specified relative path.
|
|
163
|
+
*
|
|
164
|
+
* @param reference - A reference to a Firestore document.
|
|
165
|
+
* @param path - A slash-separated path to a document.
|
|
166
|
+
* @param pathSegments - Additional path segments that will be applied relative
|
|
167
|
+
* to the first argument.
|
|
168
|
+
* @throws If the final path has an odd number of segments and does not point to
|
|
169
|
+
* a document.
|
|
170
|
+
* @returns The `DocumentReference` instance.
|
|
171
|
+
*/
|
|
172
|
+
export function doc(
|
|
173
|
+
reference: DocumentReference<unknown>,
|
|
174
|
+
path: string,
|
|
175
|
+
...pathSegments: string[]
|
|
176
|
+
): DocumentReference<DocumentData>;
|
|
177
|
+
|
|
178
|
+
export function doc<T>(
|
|
179
|
+
parent: Firestore | CollectionReference<T> | DocumentReference<unknown>,
|
|
180
|
+
path?: string,
|
|
181
|
+
...pathSegments: string[]
|
|
182
|
+
): DocumentReference;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Gets a `CollectionReference` instance that refers to the collection at
|
|
186
|
+
* the specified absolute path.
|
|
187
|
+
*
|
|
188
|
+
* @param firestore - A reference to the root `Firestore` instance.
|
|
189
|
+
* @param path - A slash-separated path to a collection.
|
|
190
|
+
* @param pathSegments - Additional path segments to apply relative to the first
|
|
191
|
+
* argument.
|
|
192
|
+
* @throws If the final path has an even number of segments and does not point
|
|
193
|
+
* to a collection.
|
|
194
|
+
* @returns The `CollectionReference` instance.
|
|
195
|
+
*/
|
|
196
|
+
export function collection(
|
|
197
|
+
firestore: Firestore,
|
|
198
|
+
path: string,
|
|
199
|
+
...pathSegments: string[]
|
|
200
|
+
): CollectionReference<DocumentData>;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Gets a `CollectionReference` instance that refers to a subcollection of
|
|
204
|
+
* `reference` at the specified relative path.
|
|
205
|
+
*
|
|
206
|
+
* @param reference - A reference to a collection.
|
|
207
|
+
* @param path - A slash-separated path to a collection.
|
|
208
|
+
* @param pathSegments - Additional path segments to apply relative to the first
|
|
209
|
+
* argument.
|
|
210
|
+
* @throws If the final path has an even number of segments and does not point
|
|
211
|
+
* to a collection.
|
|
212
|
+
* @returns The `CollectionReference` instance.
|
|
213
|
+
*/
|
|
214
|
+
export function collection(
|
|
215
|
+
reference: CollectionReference<unknown>,
|
|
216
|
+
path: string,
|
|
217
|
+
...pathSegments: string[]
|
|
218
|
+
): CollectionReference<DocumentData>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Gets a `CollectionReference` instance that refers to a subcollection of
|
|
222
|
+
* `reference` at the specified relative path.
|
|
223
|
+
*
|
|
224
|
+
* @param reference - A reference to a Firestore document.
|
|
225
|
+
* @param path - A slash-separated path to a collection.
|
|
226
|
+
* @param pathSegments - Additional path segments that will be applied relative
|
|
227
|
+
* to the first argument.
|
|
228
|
+
* @throws If the final path has an even number of segments and does not point
|
|
229
|
+
* to a collection.
|
|
230
|
+
* @returns The `CollectionReference` instance.
|
|
231
|
+
*/
|
|
232
|
+
export function collection(
|
|
233
|
+
reference: DocumentReference,
|
|
234
|
+
path: string,
|
|
235
|
+
...pathSegments: string[]
|
|
236
|
+
): CollectionReference<DocumentData>;
|
|
237
|
+
|
|
238
|
+
export function collection(
|
|
239
|
+
parent: Firestore | DocumentReference<unknown> | CollectionReference<unknown>,
|
|
240
|
+
path: string,
|
|
241
|
+
...pathSegments: string[]
|
|
242
|
+
): CollectionReference<DocumentData>;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Creates and returns a new `Query` instance that includes all documents in the
|
|
246
|
+
* database that are contained in a collection or subcollection with the
|
|
247
|
+
* given `collectionId`.
|
|
248
|
+
*
|
|
249
|
+
* @param firestore - A reference to the root `Firestore` instance.
|
|
250
|
+
* @param collectionId - Identifies the collections to query over. Every
|
|
251
|
+
* collection or subcollection with this ID as the last segment of its path
|
|
252
|
+
* will be included. Cannot contain a slash.
|
|
253
|
+
* @returns The created `Query`.
|
|
254
|
+
*/
|
|
255
|
+
export function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData>;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Writes to the document referred to by this `DocumentReference`. If the
|
|
259
|
+
* document does not yet exist, it will be created.
|
|
260
|
+
*
|
|
261
|
+
* @param reference - A reference to the document to write.
|
|
262
|
+
* @param data - A map of the fields and values for the document.
|
|
263
|
+
* @returns A `Promise` resolved once the data has been successfully written
|
|
264
|
+
* to the backend (note that it won't resolve while you're offline).
|
|
265
|
+
*/
|
|
266
|
+
export function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<T>): Promise<void>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Writes to the document referred to by the specified `DocumentReference`. If
|
|
270
|
+
* the document does not yet exist, it will be created. If you provide `merge`
|
|
271
|
+
* or `mergeFields`, the provided data can be merged into an existing document.
|
|
272
|
+
*
|
|
273
|
+
* @param reference - A reference to the document to write.
|
|
274
|
+
* @param data - A map of the fields and values for the document.
|
|
275
|
+
* @param options - An object to configure the set behavior.
|
|
276
|
+
* @returns A Promise resolved once the data has been successfully written
|
|
277
|
+
* to the backend (note that it won't resolve while you're offline).
|
|
278
|
+
*/
|
|
279
|
+
export function setDoc<T>(
|
|
280
|
+
reference: DocumentReference<T>,
|
|
281
|
+
data: PartialWithFieldValue<T>,
|
|
282
|
+
options: FirebaseFirestoreTypes.SetOptions,
|
|
283
|
+
): Promise<void>;
|
|
284
|
+
|
|
285
|
+
export function setDoc<T>(
|
|
286
|
+
reference: DocumentReference<T>,
|
|
287
|
+
data: PartialWithFieldValue<T>,
|
|
288
|
+
options?: FirebaseFirestoreTypes.SetOptions,
|
|
289
|
+
): Promise<void>;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Updates fields in the document referred to by the specified
|
|
293
|
+
* `DocumentReference`. The update will fail if applied to a document that does
|
|
294
|
+
* not exist.
|
|
295
|
+
*
|
|
296
|
+
* @param reference - A reference to the document to update.
|
|
297
|
+
* @param data - An object containing the fields and values with which to
|
|
298
|
+
* update the document. Fields can contain dots to reference nested fields
|
|
299
|
+
* within the document.
|
|
300
|
+
* @returns A `Promise` resolved once the data has been successfully written
|
|
301
|
+
* to the backend (note that it won't resolve while you're offline).
|
|
302
|
+
*/
|
|
303
|
+
export function updateDoc<T>(reference: DocumentReference<T>, data: UpdateData<T>): Promise<void>;
|
|
304
|
+
/**
|
|
305
|
+
* Updates fields in the document referred to by the specified
|
|
306
|
+
* `DocumentReference` The update will fail if applied to a document that does
|
|
307
|
+
* not exist.
|
|
308
|
+
*
|
|
309
|
+
* Nested fields can be updated by providing dot-separated field path
|
|
310
|
+
* strings or by providing `FieldPath` objects.
|
|
311
|
+
*
|
|
312
|
+
* @param reference - A reference to the document to update.
|
|
313
|
+
* @param field - The first field to update.
|
|
314
|
+
* @param value - The first value.
|
|
315
|
+
* @param moreFieldsAndValues - Additional key value pairs.
|
|
316
|
+
* @returns A `Promise` resolved once the data has been successfully written
|
|
317
|
+
* to the backend (note that it won't resolve while you're offline).
|
|
318
|
+
*/
|
|
319
|
+
export function updateDoc(
|
|
320
|
+
reference: DocumentReference<unknown>,
|
|
321
|
+
field: string | FieldPath,
|
|
322
|
+
value: unknown,
|
|
323
|
+
...moreFieldsAndValues: unknown[]
|
|
324
|
+
): Promise<void>;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Add a new document to specified `CollectionReference` with the given data,
|
|
328
|
+
* assigning it a document ID automatically.
|
|
329
|
+
*
|
|
330
|
+
* @param reference - A reference to the collection to add this document to.
|
|
331
|
+
* @param data - An Object containing the data for the new document.
|
|
332
|
+
* @returns A `Promise` resolved with a `DocumentReference` pointing to the
|
|
333
|
+
* newly created document after it has been written to the backend (Note that it
|
|
334
|
+
* won't resolve while you're offline).
|
|
335
|
+
*/
|
|
336
|
+
export function addDoc<T>(
|
|
337
|
+
reference: CollectionReference<T>,
|
|
338
|
+
data: WithFieldValue<T>,
|
|
339
|
+
): Promise<DocumentReference<T>>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Re-enables use of the network for this {@link Firestore} instance after a prior
|
|
343
|
+
* call to {@link disableNetwork}.
|
|
344
|
+
*
|
|
345
|
+
* @returns A `Promise` that is resolved once the network has been enabled.
|
|
346
|
+
*/
|
|
347
|
+
export function enableNetwork(firestore: Firestore): Promise<void>;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Disables network usage for this instance. It can be re-enabled via {@link
|
|
351
|
+
* enableNetwork}. While the network is disabled, any snapshot listeners,
|
|
352
|
+
* `getDoc()` or `getDocs()` calls will return results from cache, and any write
|
|
353
|
+
* operations will be queued until the network is restored.
|
|
354
|
+
*
|
|
355
|
+
* @returns A `Promise` that is resolved once the network has been disabled.
|
|
356
|
+
*/
|
|
357
|
+
export function disableNetwork(firestore: Firestore): Promise<void>;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Aimed primarily at clearing up any data cached from running tests. Needs to be executed before any database calls
|
|
361
|
+
* are made.
|
|
362
|
+
*
|
|
363
|
+
* @param firestore - A reference to the root `Firestore` instance.
|
|
364
|
+
*/
|
|
365
|
+
export function clearPersistence(firestore: Firestore): Promise<void>;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Terminates the provided {@link Firestore} instance.
|
|
369
|
+
*
|
|
370
|
+
* To restart after termination, create a new instance of FirebaseFirestore with
|
|
371
|
+
* {@link (getFirestore:1)}.
|
|
372
|
+
*
|
|
373
|
+
* Termination does not cancel any pending writes, and any promises that are
|
|
374
|
+
* awaiting a response from the server will not be resolved. If you have
|
|
375
|
+
* persistence enabled, the next time you start this instance, it will resume
|
|
376
|
+
* sending these writes to the server.
|
|
377
|
+
*
|
|
378
|
+
* Note: Under normal circumstances, calling `terminate()` is not required. This
|
|
379
|
+
* function is useful only when you want to force this instance to release all
|
|
380
|
+
* of its resources or in combination with `clearIndexedDbPersistence()` to
|
|
381
|
+
* ensure that all local state is destroyed between test runs.
|
|
382
|
+
*
|
|
383
|
+
* @returns A `Promise` that is resolved when the instance has been successfully
|
|
384
|
+
* terminated.
|
|
385
|
+
*/
|
|
386
|
+
export function terminate(firestore: Firestore): Promise<void>;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Waits until all currently pending writes for the active user have been
|
|
390
|
+
* acknowledged by the backend.
|
|
391
|
+
*
|
|
392
|
+
* The returned promise resolves immediately if there are no outstanding writes.
|
|
393
|
+
* Otherwise, the promise waits for all previously issued writes (including
|
|
394
|
+
* those written in a previous app session), but it does not wait for writes
|
|
395
|
+
* that were added after the function is called. If you want to wait for
|
|
396
|
+
* additional writes, call `waitForPendingWrites()` again.
|
|
397
|
+
*
|
|
398
|
+
* Any outstanding `waitForPendingWrites()` promises are rejected during user
|
|
399
|
+
* changes.
|
|
400
|
+
*
|
|
401
|
+
* @returns A `Promise` which resolves when all currently pending writes have been
|
|
402
|
+
* acknowledged by the backend.
|
|
403
|
+
*/
|
|
404
|
+
export function waitForPendingWrites(firestore: Firestore): Promise<void>;
|
|
405
|
+
|
|
406
|
+
/*
|
|
407
|
+
* @param app - The {@link @firebase/app#FirebaseApp} with which the {@link Firestore} instance will
|
|
408
|
+
* be associated.
|
|
409
|
+
* @param settings - A settings object to configure the {@link Firestore} instance.
|
|
410
|
+
* @param databaseId - The name of database.
|
|
411
|
+
* @returns A newly initialized {@link Firestore} instance.
|
|
412
|
+
*/
|
|
413
|
+
export function initializeFirestore(
|
|
414
|
+
app: FirebaseApp,
|
|
415
|
+
settings: FirestoreSettings,
|
|
416
|
+
databaseId?: string,
|
|
417
|
+
): Promise<Firestore>;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The verbosity you set for activity and error logging. Can be any of the following values:
|
|
421
|
+
* - debug for the most verbose logging level, primarily for debugging.
|
|
422
|
+
* - error to log errors only.
|
|
423
|
+
* - silent to turn off logging.
|
|
424
|
+
*/
|
|
425
|
+
type LogLevel = 'debug' | 'error' | 'silent';
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
|
|
429
|
+
* @param logLevel - The verbosity you set for activity and error logging.
|
|
430
|
+
*/
|
|
431
|
+
export function setLogLevel(logLevel: LogLevel): void;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Executes the given `updateFunction` and then attempts to commit the changes
|
|
435
|
+
* applied within the transaction. If any document read within the transaction
|
|
436
|
+
* has changed, Cloud Firestore retries the `updateFunction`. If it fails to
|
|
437
|
+
* commit after 5 attempts, the transaction fails.
|
|
438
|
+
*
|
|
439
|
+
* The maximum number of writes allowed in a single transaction is 500.
|
|
440
|
+
*
|
|
441
|
+
* @param firestore - A reference to the Firestore database to run this
|
|
442
|
+
* transaction against.
|
|
443
|
+
* @param updateFunction - The function to execute within the transaction
|
|
444
|
+
* context.
|
|
445
|
+
* @returns If the transaction completed successfully or was explicitly aborted
|
|
446
|
+
* (the `updateFunction` returned a failed promise), the promise returned by the
|
|
447
|
+
* `updateFunction `is returned here. Otherwise, if the transaction failed, a
|
|
448
|
+
* rejected promise with the corresponding failure error is returned.
|
|
449
|
+
*/
|
|
450
|
+
export function runTransaction<T>(
|
|
451
|
+
firestore: Firestore,
|
|
452
|
+
updateFunction: (transaction: FirebaseFirestoreTypes.Transaction) => Promise<T>,
|
|
453
|
+
): Promise<T>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Calculates the number of documents in the result set of the given query,
|
|
457
|
+
* without actually downloading the documents.
|
|
458
|
+
*
|
|
459
|
+
* Using this function to count the documents is efficient because only the
|
|
460
|
+
* final count, not the documents' data, is downloaded. This function can even
|
|
461
|
+
* count the documents if the result set would be prohibitively large to
|
|
462
|
+
* download entirely (e.g. thousands of documents).
|
|
463
|
+
*
|
|
464
|
+
* The result received from the server is presented, unaltered, without
|
|
465
|
+
* considering any local state. That is, documents in the local cache are not
|
|
466
|
+
* taken into consideration, neither are local modifications not yet
|
|
467
|
+
* synchronized with the server. Previously-downloaded results, if any, are not
|
|
468
|
+
* used: every request using this source necessarily involves a round trip to
|
|
469
|
+
* the server.
|
|
470
|
+
*
|
|
471
|
+
* @param query - The query whose result set size to calculate.
|
|
472
|
+
* @returns A Promise that will be resolved with the count; the count can be
|
|
473
|
+
* retrieved from `snapshot.data().count`, where `snapshot` is the
|
|
474
|
+
* `AggregateQuerySnapshot` to which the returned Promise resolves.
|
|
475
|
+
*/
|
|
476
|
+
export function getCountFromServer<AppModelType, DbModelType extends DocumentData>(
|
|
477
|
+
query: Query<AppModelType, DbModelType>,
|
|
478
|
+
): Promise<
|
|
479
|
+
FirebaseFirestoreTypes.AggregateQuerySnapshot<
|
|
480
|
+
{ count: FirebaseFirestoreTypes.AggregateField<number> },
|
|
481
|
+
AppModelType,
|
|
482
|
+
DbModelType
|
|
483
|
+
>
|
|
484
|
+
>;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Represents the task of loading a Firestore bundle.
|
|
488
|
+
* It provides progress of bundle loading, as well as task completion and error events.
|
|
489
|
+
*/
|
|
490
|
+
type LoadBundleTask = Promise<FirebaseFirestoreTypes.LoadBundleTaskProgress>;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Loads a Firestore bundle into the local cache.
|
|
494
|
+
*
|
|
495
|
+
* @param firestore - The {@link Firestore} instance to load bundles for.
|
|
496
|
+
* @param bundleData - An object representing the bundle to be loaded. Valid
|
|
497
|
+
* objects are `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
|
|
498
|
+
*
|
|
499
|
+
* @returns A `LoadBundleTask` object, which notifies callers with progress
|
|
500
|
+
* updates, and completion or error events. It can be used as a
|
|
501
|
+
* `Promise<LoadBundleTaskProgress>`.
|
|
502
|
+
*/
|
|
503
|
+
export function loadBundle(
|
|
504
|
+
firestore: Firestore,
|
|
505
|
+
bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string,
|
|
506
|
+
): LoadBundleTask;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Reads a Firestore {@link Query} from local cache, identified by the given
|
|
510
|
+
* name.
|
|
511
|
+
*
|
|
512
|
+
* The named queries are packaged into bundles on the server side (along
|
|
513
|
+
* with resulting documents), and loaded to local cache using `loadBundle`. Once
|
|
514
|
+
* in local cache, use this method to extract a {@link Query} by name.
|
|
515
|
+
*
|
|
516
|
+
* @param firestore - The {@link Firestore} instance to read the query from.
|
|
517
|
+
* @param name - The name of the query.
|
|
518
|
+
* @returns A named Query.
|
|
519
|
+
*/
|
|
520
|
+
export function namedQuery(firestore: Firestore, name: string): Query<DocumentData>;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Creates a write batch, used for performing multiple writes as a single
|
|
524
|
+
* atomic operation. The maximum number of writes allowed in a single WriteBatch
|
|
525
|
+
* is 500.
|
|
526
|
+
*
|
|
527
|
+
* The result of these writes will only be reflected in document reads that
|
|
528
|
+
* occur after the returned promise resolves. If the client is offline, the
|
|
529
|
+
* write fails. If you would like to see local modifications or buffer writes
|
|
530
|
+
* until the client is online, use the full Firestore SDK.
|
|
531
|
+
*
|
|
532
|
+
* @returns A `WriteBatch` that can be used to atomically execute multiple
|
|
533
|
+
* writes.
|
|
534
|
+
*/
|
|
535
|
+
export function writeBatch(firestore: Firestore): FirebaseFirestoreTypes.WriteBatch;
|