UNPKG

92.5 kBTypeScriptView Raw
1/**
2 * Cloud Firestore
3 *
4 * @packageDocumentation
5 */
6import { FirebaseApp } from '@firebase/app';
7import { LogLevelString as LogLevel } from '@firebase/logger';
8import { EmulatorMockTokenOptions } from '@firebase/util';
9import { FirebaseError } from '@firebase/util';
10
11/**
12 * Add a new document to specified `CollectionReference` with the given data,
13 * assigning it a document ID automatically.
14 *
15 * @param reference - A reference to the collection to add this document to.
16 * @param data - An Object containing the data for the new document.
17 * @returns A `Promise` resolved with a `DocumentReference` pointing to the
18 * newly created document after it has been written to the backend (Note that it
19 * won't resolve while you're offline).
20 */
21export declare function addDoc<T>(reference: CollectionReference<T>, data: WithFieldValue<T>): Promise<DocumentReference<T>>;
22/**
23 * Returns a new map where every key is prefixed with the outer key appended
24 * to a dot.
25 */
26export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
27 [K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
28};
29/**
30 * Returns a special value that can be used with {@link (setDoc:1)} or {@link
31 * updateDoc:1} that tells the server to remove the given elements from any
32 * array value that already exists on the server. All instances of each element
33 * specified will be removed from the array. If the field being modified is not
34 * already an array it will be overwritten with an empty array.
35 *
36 * @param elements - The elements to remove from the array.
37 * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
38 * `updateDoc()`
39 */
40export declare function arrayRemove(...elements: unknown[]): FieldValue;
41/**
42 * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
43 * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array
44 * value that already exists on the server. Each specified element that doesn't
45 * already exist in the array will be added to the end. If the field being
46 * modified is not already an array it will be overwritten with an array
47 * containing exactly the specified elements.
48 *
49 * @param elements - The elements to union into the array.
50 * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
51 * `updateDoc()`.
52 */
53export declare function arrayUnion(...elements: unknown[]): FieldValue;
54/**
55 * An immutable object representing an array of bytes.
56 */
57export declare class Bytes {
58 private constructor();
59 /**
60 * Creates a new `Bytes` object from the given Base64 string, converting it to
61 * bytes.
62 *
63 * @param base64 - The Base64 string used to create the `Bytes` object.
64 */
65 static fromBase64String(base64: string): Bytes;
66 /**
67 * Creates a new `Bytes` object from the given Uint8Array.
68 *
69 * @param array - The Uint8Array used to create the `Bytes` object.
70 */
71 static fromUint8Array(array: Uint8Array): Bytes;
72 /**
73 * Returns the underlying bytes as a Base64-encoded string.
74 *
75 * @returns The Base64-encoded string created from the `Bytes` object.
76 */
77 toBase64(): string;
78 /**
79 * Returns the underlying bytes in a new `Uint8Array`.
80 *
81 * @returns The Uint8Array created from the `Bytes` object.
82 */
83 toUint8Array(): Uint8Array;
84 /**
85 * Returns a string representation of the `Bytes` object.
86 *
87 * @returns A string representation of the `Bytes` object.
88 */
89 toString(): string;
90 /**
91 * Returns true if this `Bytes` object is equal to the provided one.
92 *
93 * @param other - The `Bytes` object to compare against.
94 * @returns true if this `Bytes` object is equal to the provided one.
95 */
96 isEqual(other: Bytes): boolean;
97}
98/* Excluded from this release type: _ByteString */
99/**
100 * Constant used to indicate the LRU garbage collection should be disabled.
101 * Set this value as the `cacheSizeBytes` on the settings passed to the
102 * {@link Firestore} instance.
103 */
104export declare const CACHE_SIZE_UNLIMITED = -1;
105/**
106 * Helper for calculating the nested fields for a given type T1. This is needed
107 * to distribute union types such as `undefined | {...}` (happens for optional
108 * props) or `{a: A} | {b: B}`.
109 *
110 * In this use case, `V` is used to distribute the union types of `T[K]` on
111 * `Record`, since `T[K]` is evaluated as an expression and not distributed.
112 *
113 * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
114 */
115export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;
116/**
117 * Clears the persistent storage. This includes pending writes and cached
118 * documents.
119 *
120 * Must be called while the {@link Firestore} instance is not started (after the app is
121 * terminated or when the app is first initialized). On startup, this function
122 * must be called before other functions (other than {@link
123 * initializeFirestore} or {@link getFirestore})). If the {@link Firestore}
124 * instance is still running, the promise will be rejected with the error code
125 * of `failed-precondition`.
126 *
127 * Note: `clearIndexedDbPersistence()` is primarily intended to help write
128 * reliable tests that use Cloud Firestore. It uses an efficient mechanism for
129 * dropping existing data but does not attempt to securely overwrite or
130 * otherwise make cached data unrecoverable. For applications that are sensitive
131 * to the disclosure of cached data in between user sessions, we strongly
132 * recommend not enabling persistence at all.
133 *
134 * @param firestore - The {@link Firestore} instance to clear persistence for.
135 * @returns A `Promise` that is resolved when the persistent storage is
136 * cleared. Otherwise, the promise is rejected with an error.
137 */
138export declare function clearIndexedDbPersistence(firestore: Firestore): Promise<void>;
139/**
140 * Gets a `CollectionReference` instance that refers to the collection at
141 * the specified absolute path.
142 *
143 * @param firestore - A reference to the root `Firestore` instance.
144 * @param path - A slash-separated path to a collection.
145 * @param pathSegments - Additional path segments to apply relative to the first
146 * argument.
147 * @throws If the final path has an even number of segments and does not point
148 * to a collection.
149 * @returns The `CollectionReference` instance.
150 */
151export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
152/**
153 * Gets a `CollectionReference` instance that refers to a subcollection of
154 * `reference` at the the specified relative path.
155 *
156 * @param reference - A reference to a collection.
157 * @param path - A slash-separated path to a collection.
158 * @param pathSegments - Additional path segments to apply relative to the first
159 * argument.
160 * @throws If the final path has an even number of segments and does not point
161 * to a collection.
162 * @returns The `CollectionReference` instance.
163 */
164export declare function collection(reference: CollectionReference<unknown>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
165/**
166 * Gets a `CollectionReference` instance that refers to a subcollection of
167 * `reference` at the the specified relative path.
168 *
169 * @param reference - A reference to a Firestore document.
170 * @param path - A slash-separated path to a collection.
171 * @param pathSegments - Additional path segments that will be applied relative
172 * to the first argument.
173 * @throws If the final path has an even number of segments and does not point
174 * to a collection.
175 * @returns The `CollectionReference` instance.
176 */
177export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
178/**
179 * Creates and returns a new `Query` instance that includes all documents in the
180 * database that are contained in a collection or subcollection with the
181 * given `collectionId`.
182 *
183 * @param firestore - A reference to the root `Firestore` instance.
184 * @param collectionId - Identifies the collections to query over. Every
185 * collection or subcollection with this ID as the last segment of its path
186 * will be included. Cannot contain a slash.
187 * @returns The created `Query`.
188 */
189export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData>;
190/**
191 * A `CollectionReference` object can be used for adding documents, getting
192 * document references, and querying for documents (using {@link query}).
193 */
194export declare class CollectionReference<T = DocumentData> extends Query<T> {
195 /** The type of this Firestore reference. */
196 readonly type = "collection";
197 private constructor();
198 /** The collection's identifier. */
199 get id(): string;
200 /**
201 * A string representing the path of the referenced collection (relative
202 * to the root of the database).
203 */
204 get path(): string;
205 /**
206 * A reference to the containing `DocumentReference` if this is a
207 * subcollection. If this isn't a subcollection, the reference is null.
208 */
209 get parent(): DocumentReference<DocumentData> | null;
210 /**
211 * Applies a custom data converter to this `CollectionReference`, allowing you
212 * to use your own custom model objects with Firestore. When you call {@link
213 * addDoc} with the returned `CollectionReference` instance, the provided
214 * converter will convert between Firestore data and your custom type `U`.
215 *
216 * @param converter - Converts objects to and from Firestore.
217 * @returns A `CollectionReference<U>` that uses the provided converter.
218 */
219 withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>;
220 /**
221 * Removes the current converter.
222 *
223 * @param converter - `null` removes the current converter.
224 * @returns A `CollectionReference<DocumentData>` that does not use a
225 * converter.
226 */
227 withConverter(converter: null): CollectionReference<DocumentData>;
228}
229/**
230 * Modify this instance to communicate with the Cloud Firestore emulator.
231 *
232 * Note: This must be called before this instance has been used to do any
233 * operations.
234 *
235 * @param firestore - The `Firestore` instance to configure to connect to the
236 * emulator.
237 * @param host - the emulator host (ex: localhost).
238 * @param port - the emulator port (ex: 9000).
239 * @param options.mockUserToken - the mock auth token to use for unit testing
240 * Security Rules.
241 */
242export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
243 mockUserToken?: EmulatorMockTokenOptions | string;
244}): void;
245/**
246 * Deletes the document referred to by the specified `DocumentReference`.
247 *
248 * @param reference - A reference to the document to delete.
249 * @returns A Promise resolved once the document has been successfully
250 * deleted from the backend (note that it won't resolve while you're offline).
251 */
252export declare function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
253/**
254 * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or
255 * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion.
256 */
257export declare function deleteField(): FieldValue;
258/**
259 * Disables network usage for this instance. It can be re-enabled via {@link
260 * enableNetwork}. While the network is disabled, any snapshot listeners,
261 * `getDoc()` or `getDocs()` calls will return results from cache, and any write
262 * operations will be queued until the network is restored.
263 *
264 * @returns A `Promise` that is resolved once the network has been disabled.
265 */
266export declare function disableNetwork(firestore: Firestore): Promise<void>;
267/**
268 * Gets a `DocumentReference` instance that refers to the document at the
269 * specified absolute path.
270 *
271 * @param firestore - A reference to the root `Firestore` instance.
272 * @param path - A slash-separated path to a document.
273 * @param pathSegments - Additional path segments that will be applied relative
274 * to the first argument.
275 * @throws If the final path has an odd number of segments and does not point to
276 * a document.
277 * @returns The `DocumentReference` instance.
278 */
279export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
280/**
281 * Gets a `DocumentReference` instance that refers to a document within
282 * `reference` at the specified relative path. If no path is specified, an
283 * automatically-generated unique ID will be used for the returned
284 * `DocumentReference`.
285 *
286 * @param reference - A reference to a collection.
287 * @param path - A slash-separated path to a document. Has to be omitted to use
288 * auto-genrated IDs.
289 * @param pathSegments - Additional path segments that will be applied relative
290 * to the first argument.
291 * @throws If the final path has an odd number of segments and does not point to
292 * a document.
293 * @returns The `DocumentReference` instance.
294 */
295export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;
296/**
297 * Gets a `DocumentReference` instance that refers to a document within
298 * `reference` at the specified relative path.
299 *
300 * @param reference - A reference to a Firestore document.
301 * @param path - A slash-separated path to a document.
302 * @param pathSegments - Additional path segments that will be applied relative
303 * to the first argument.
304 * @throws If the final path has an odd number of segments and does not point to
305 * a document.
306 * @returns The `DocumentReference` instance.
307 */
308export declare function doc(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
309/**
310 * A `DocumentChange` represents a change to the documents matching a query.
311 * It contains the document affected and the type of change that occurred.
312 */
313export declare interface DocumentChange<T = DocumentData> {
314 /** The type of change ('added', 'modified', or 'removed'). */
315 readonly type: DocumentChangeType;
316 /** The document affected by this change. */
317 readonly doc: QueryDocumentSnapshot<T>;
318 /**
319 * The index of the changed document in the result set immediately prior to
320 * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects
321 * have been applied). Is `-1` for 'added' events.
322 */
323 readonly oldIndex: number;
324 /**
325 * The index of the changed document in the result set immediately after
326 * this `DocumentChange` (i.e. supposing that all prior `DocumentChange`
327 * objects and the current `DocumentChange` object have been applied).
328 * Is -1 for 'removed' events.
329 */
330 readonly newIndex: number;
331}
332/**
333 * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'.
334 */
335export declare type DocumentChangeType = 'added' | 'removed' | 'modified';
336/**
337 * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to
338 * values.
339 */
340export declare interface DocumentData {
341 /** A mapping between a field and its value. */
342 [field: string]: any;
343}
344/**
345 * Returns a special sentinel `FieldPath` to refer to the ID of a document.
346 * It can be used in queries to sort or filter by the document ID.
347 */
348export declare function documentId(): FieldPath;
349/**
350 * A `DocumentReference` refers to a document location in a Firestore database
351 * and can be used to write, read, or listen to the location. The document at
352 * the referenced location may or may not exist.
353 */
354export declare class DocumentReference<T = DocumentData> {
355 /**
356 * If provided, the `FirestoreDataConverter` associated with this instance.
357 */
358 readonly converter: FirestoreDataConverter<T> | null;
359 /** The type of this Firestore reference. */
360 readonly type = "document";
361 /**
362 * The {@link Firestore} instance the document is in.
363 * This is useful for performing transactions, for example.
364 */
365 readonly firestore: Firestore;
366 private constructor();
367 /**
368 * The document's identifier within its collection.
369 */
370 get id(): string;
371 /**
372 * A string representing the path of the referenced document (relative
373 * to the root of the database).
374 */
375 get path(): string;
376 /**
377 * The collection this `DocumentReference` belongs to.
378 */
379 get parent(): CollectionReference<T>;
380 /**
381 * Applies a custom data converter to this `DocumentReference`, allowing you
382 * to use your own custom model objects with Firestore. When you call {@link
383 * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference`
384 * instance, the provided converter will convert between Firestore data and
385 * your custom type `U`.
386 *
387 * @param converter - Converts objects to and from Firestore.
388 * @returns A `DocumentReference<U>` that uses the provided converter.
389 */
390 withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
391 /**
392 * Removes the current converter.
393 *
394 * @param converter - `null` removes the current converter.
395 * @returns A `DocumentReference<DocumentData>` that does not use a converter.
396 */
397 withConverter(converter: null): DocumentReference<DocumentData>;
398}
399/**
400 * A `DocumentSnapshot` contains data read from a document in your Firestore
401 * database. The data can be extracted with `.data()` or `.get(<field>)` to
402 * get a specific field.
403 *
404 * For a `DocumentSnapshot` that points to a non-existing document, any data
405 * access will return 'undefined'. You can use the `exists()` method to
406 * explicitly verify a document's existence.
407 */
408export declare class DocumentSnapshot<T = DocumentData> {
409 /**
410 * Metadata about the `DocumentSnapshot`, including information about its
411 * source and local modifications.
412 */
413 readonly metadata: SnapshotMetadata;
414 protected constructor();
415 /**
416 * Returns whether or not the data exists. True if the document exists.
417 */
418 exists(): this is QueryDocumentSnapshot<T>;
419 /**
420 * Retrieves all fields in the document as an `Object`. Returns `undefined` if
421 * the document doesn't exist.
422 *
423 * By default, `serverTimestamp()` values that have not yet been
424 * set to their final value will be returned as `null`. You can override
425 * this by passing an options object.
426 *
427 * @param options - An options object to configure how data is retrieved from
428 * the snapshot (for example the desired behavior for server timestamps that
429 * have not yet been set to their final value).
430 * @returns An `Object` containing all fields in the document or `undefined` if
431 * the document doesn't exist.
432 */
433 data(options?: SnapshotOptions): T | undefined;
434 /**
435 * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
436 * document or field doesn't exist.
437 *
438 * By default, a `serverTimestamp()` that has not yet been set to
439 * its final value will be returned as `null`. You can override this by
440 * passing an options object.
441 *
442 * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
443 * field.
444 * @param options - An options object to configure how the field is retrieved
445 * from the snapshot (for example the desired behavior for server timestamps
446 * that have not yet been set to their final value).
447 * @returns The data at the specified field location or undefined if no such
448 * field exists in the document.
449 */
450 get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
451 /**
452 * Property of the `DocumentSnapshot` that provides the document's ID.
453 */
454 get id(): string;
455 /**
456 * The `DocumentReference` for the document included in the `DocumentSnapshot`.
457 */
458 get ref(): DocumentReference<T>;
459}
460/* Excluded from this release type: _EmptyAppCheckTokenProvider */
461/* Excluded from this release type: _EmptyAuthCredentialsProvider */
462export { EmulatorMockTokenOptions };
463/**
464 * Attempts to enable persistent storage, if possible.
465 *
466 * Must be called before any other functions (other than
467 * {@link initializeFirestore}, {@link getFirestore} or
468 * {@link clearIndexedDbPersistence}.
469 *
470 * If this fails, `enableIndexedDbPersistence()` will reject the promise it
471 * returns. Note that even after this failure, the {@link Firestore} instance will
472 * remain usable, however offline persistence will be disabled.
473 *
474 * There are several reasons why this can fail, which can be identified by
475 * the `code` on the error.
476 *
477 * * failed-precondition: The app is already open in another browser tab.
478 * * unimplemented: The browser is incompatible with the offline
479 * persistence implementation.
480 *
481 * @param firestore - The {@link Firestore} instance to enable persistence for.
482 * @param persistenceSettings - Optional settings object to configure
483 * persistence.
484 * @returns A `Promise` that represents successfully enabling persistent storage.
485 */
486export declare function enableIndexedDbPersistence(firestore: Firestore, persistenceSettings?: PersistenceSettings): Promise<void>;
487/**
488 * Attempts to enable multi-tab persistent storage, if possible. If enabled
489 * across all tabs, all operations share access to local persistence, including
490 * shared execution of queries and latency-compensated local document updates
491 * across all connected instances.
492 *
493 * If this fails, `enableMultiTabIndexedDbPersistence()` will reject the promise
494 * it returns. Note that even after this failure, the {@link Firestore} instance will
495 * remain usable, however offline persistence will be disabled.
496 *
497 * There are several reasons why this can fail, which can be identified by
498 * the `code` on the error.
499 *
500 * * failed-precondition: The app is already open in another browser tab and
501 * multi-tab is not enabled.
502 * * unimplemented: The browser is incompatible with the offline
503 * persistence implementation.
504 *
505 * @param firestore - The {@link Firestore} instance to enable persistence for.
506 * @returns A `Promise` that represents successfully enabling persistent
507 * storage.
508 */
509export declare function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promise<void>;
510/**
511 * Re-enables use of the network for this {@link Firestore} instance after a prior
512 * call to {@link disableNetwork}.
513 *
514 * @returns A `Promise` that is resolved once the network has been enabled.
515 */
516export declare function enableNetwork(firestore: Firestore): Promise<void>;
517/**
518 * Creates a {@link QueryConstraint} that modifies the result set to end at the
519 * provided document (inclusive). The end position is relative to the order of
520 * the query. The document must contain all of the fields provided in the
521 * orderBy of the query.
522 *
523 * @param snapshot - The snapshot of the document to end at.
524 * @returns A {@link QueryConstraint} to pass to `query()`
525 */
526export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
527/**
528 * Creates a {@link QueryConstraint} that modifies the result set to end at the
529 * provided fields relative to the order of the query. The order of the field
530 * values must match the order of the order by clauses of the query.
531 *
532 * @param fieldValues - The field values to end this query at, in order
533 * of the query's order by.
534 * @returns A {@link QueryConstraint} to pass to `query()`
535 */
536export declare function endAt(...fieldValues: unknown[]): QueryConstraint;
537/**
538 * Creates a {@link QueryConstraint} that modifies the result set to end before the
539 * provided document (exclusive). The end position is relative to the order of
540 * the query. The document must contain all of the fields provided in the
541 * orderBy of the query.
542 *
543 * @param snapshot - The snapshot of the document to end before.
544 * @returns A {@link QueryConstraint} to pass to `query()`
545 */
546export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
547/**
548 * Creates a {@link QueryConstraint} that modifies the result set to end before the
549 * provided fields relative to the order of the query. The order of the field
550 * values must match the order of the order by clauses of the query.
551 *
552 * @param fieldValues - The field values to end this query before, in order
553 * of the query's order by.
554 * @returns A {@link QueryConstraint} to pass to `query()`
555 */
556export declare function endBefore(...fieldValues: unknown[]): QueryConstraint;
557/**
558 * A `FieldPath` refers to a field in a document. The path may consist of a
559 * single field name (referring to a top-level field in the document), or a
560 * list of field names (referring to a nested field in the document).
561 *
562 * Create a `FieldPath` by providing field names. If more than one field
563 * name is provided, the path will point to a nested field in a document.
564 */
565export declare class FieldPath {
566 /**
567 * Creates a `FieldPath` from the provided field names. If more than one field
568 * name is provided, the path will point to a nested field in a document.
569 *
570 * @param fieldNames - A list of field names.
571 */
572 constructor(...fieldNames: string[]);
573 /**
574 * Returns true if this `FieldPath` is equal to the provided one.
575 *
576 * @param other - The `FieldPath` to compare against.
577 * @returns true if this `FieldPath` is equal to the provided one.
578 */
579 isEqual(other: FieldPath): boolean;
580}
581/**
582 * Sentinel values that can be used when writing document fields with `set()`
583 * or `update()`.
584 */
585export declare abstract class FieldValue {
586 private constructor();
587 /** Compares `FieldValue`s for equality. */
588 abstract isEqual(other: FieldValue): boolean;
589}
590/* Excluded from this release type: _FirebaseService */
591/**
592 * The Cloud Firestore service interface.
593 *
594 * Do not call this constructor directly. Instead, use {@link getFirestore}.
595 */
596export declare class Firestore {
597 /**
598 * Whether it's a {@link Firestore} or Firestore Lite instance.
599 */
600 type: 'firestore-lite' | 'firestore';
601 private constructor();
602 /**
603 * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
604 * instance.
605 */
606 get app(): FirebaseApp;
607 /**
608 * Returns a JSON-serializable representation of this `Firestore` instance.
609 */
610 toJSON(): object;
611}
612/**
613 * Converter used by `withConverter()` to transform user objects of type `T`
614 * into Firestore data.
615 *
616 * Using the converter allows you to specify generic type arguments when
617 * storing and retrieving objects from Firestore.
618 *
619 * @example
620 * ```typescript
621 * class Post {
622 * constructor(readonly title: string, readonly author: string) {}
623 *
624 * toString(): string {
625 * return this.title + ', by ' + this.author;
626 * }
627 * }
628 *
629 * const postConverter = {
630 * toFirestore(post: WithFieldValue<Post>): DocumentData {
631 * return {title: post.title, author: post.author};
632 * },
633 * fromFirestore(
634 * snapshot: QueryDocumentSnapshot,
635 * options: SnapshotOptions
636 * ): Post {
637 * const data = snapshot.data(options)!;
638 * return new Post(data.title, data.author);
639 * }
640 * };
641 *
642 * const postSnap = await firebase.firestore()
643 * .collection('posts')
644 * .withConverter(postConverter)
645 * .doc().get();
646 * const post = postSnap.data();
647 * if (post !== undefined) {
648 * post.title; // string
649 * post.toString(); // Should be defined
650 * post.someNonExistentProperty; // TS error
651 * }
652 * ```
653 */
654export declare interface FirestoreDataConverter<T> {
655 /**
656 * Called by the Firestore SDK to convert a custom model object of type `T`
657 * into a plain JavaScript object (suitable for writing directly to the
658 * Firestore database). To use `set()` with `merge` and `mergeFields`,
659 * `toFirestore()` must be defined with `PartialWithFieldValue<T>`.
660 *
661 * The `WithFieldValue<T>` type extends `T` to also allow FieldValues such as
662 * {@link (deleteField:1)} to be used as property values.
663 */
664 toFirestore(modelObject: WithFieldValue<T>): DocumentData;
665 /**
666 * Called by the Firestore SDK to convert a custom model object of type `T`
667 * into a plain JavaScript object (suitable for writing directly to the
668 * Firestore database). Used with {@link (setDoc:1)}, {@link (WriteBatch.set:1)}
669 * and {@link (Transaction.set:1)} with `merge:true` or `mergeFields`.
670 *
671 * The `PartialWithFieldValue<T>` type extends `Partial<T>` to allow
672 * FieldValues such as {@link (arrayUnion:1)} to be used as property values.
673 * It also supports nested `Partial` by allowing nested fields to be
674 * omitted.
675 */
676 toFirestore(modelObject: PartialWithFieldValue<T>, options: SetOptions): DocumentData;
677 /**
678 * Called by the Firestore SDK to convert Firestore data into an object of
679 * type T. You can access your data by calling: `snapshot.data(options)`.
680 *
681 * @param snapshot - A `QueryDocumentSnapshot` containing your data and metadata.
682 * @param options - The `SnapshotOptions` from the initial call to `data()`.
683 */
684 fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>, options?: SnapshotOptions): T;
685}
686/** An error returned by a Firestore operation. */
687export declare class FirestoreError extends FirebaseError {
688 /**
689 * The backend error code associated with this error.
690 */
691 readonly code: FirestoreErrorCode;
692 /**
693 * A custom error description.
694 */
695 readonly message: string;
696 /** The stack of the error. */
697 readonly stack?: string;
698 private constructor();
699}
700/**
701 * The set of Firestore status codes. The codes are the same at the ones
702 * exposed by gRPC here:
703 * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
704 *
705 * Possible values:
706 * - 'cancelled': The operation was cancelled (typically by the caller).
707 * - 'unknown': Unknown error or an error from a different error domain.
708 * - 'invalid-argument': Client specified an invalid argument. Note that this
709 * differs from 'failed-precondition'. 'invalid-argument' indicates
710 * arguments that are problematic regardless of the state of the system
711 * (e.g. an invalid field name).
712 * - 'deadline-exceeded': Deadline expired before operation could complete.
713 * For operations that change the state of the system, this error may be
714 * returned even if the operation has completed successfully. For example,
715 * a successful response from a server could have been delayed long enough
716 * for the deadline to expire.
717 * - 'not-found': Some requested document was not found.
718 * - 'already-exists': Some document that we attempted to create already
719 * exists.
720 * - 'permission-denied': The caller does not have permission to execute the
721 * specified operation.
722 * - 'resource-exhausted': Some resource has been exhausted, perhaps a
723 * per-user quota, or perhaps the entire file system is out of space.
724 * - 'failed-precondition': Operation was rejected because the system is not
725 * in a state required for the operation's execution.
726 * - 'aborted': The operation was aborted, typically due to a concurrency
727 * issue like transaction aborts, etc.
728 * - 'out-of-range': Operation was attempted past the valid range.
729 * - 'unimplemented': Operation is not implemented or not supported/enabled.
730 * - 'internal': Internal errors. Means some invariants expected by
731 * underlying system has been broken. If you see one of these errors,
732 * something is very broken.
733 * - 'unavailable': The service is currently unavailable. This is most likely
734 * a transient condition and may be corrected by retrying with a backoff.
735 * - 'data-loss': Unrecoverable data loss or corruption.
736 * - 'unauthenticated': The request does not have valid authentication
737 * credentials for the operation.
738 */
739export declare type FirestoreErrorCode = 'cancelled' | 'unknown' | 'invalid-argument' | 'deadline-exceeded' | 'not-found' | 'already-exists' | 'permission-denied' | 'resource-exhausted' | 'failed-precondition' | 'aborted' | 'out-of-range' | 'unimplemented' | 'internal' | 'unavailable' | 'data-loss' | 'unauthenticated';
740/**
741 * Specifies custom configurations for your Cloud Firestore instance.
742 * You must set these before invoking any other methods.
743 */
744export declare interface FirestoreSettings {
745 /**
746 * An approximate cache size threshold for the on-disk data. If the cache
747 * grows beyond this size, Firestore will start removing data that hasn't been
748 * recently used. The size is not a guarantee that the cache will stay below
749 * that size, only that if the cache exceeds the given size, cleanup will be
750 * attempted.
751 *
752 * The default value is 40 MB. The threshold must be set to at least 1 MB, and
753 * can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection.
754 */
755 cacheSizeBytes?: number;
756 /**
757 * Forces the SDK’s underlying network transport (WebChannel) to use
758 * long-polling. Each response from the backend will be closed immediately
759 * after the backend sends data (by default responses are kept open in
760 * case the backend has more data to send). This avoids incompatibility
761 * issues with certain proxies, antivirus software, etc. that incorrectly
762 * buffer traffic indefinitely. Use of this option will cause some
763 * performance degradation though.
764 *
765 * This setting cannot be used with `experimentalAutoDetectLongPolling` and
766 * may be removed in a future release. If you find yourself using it to
767 * work around a specific network reliability issue, please tell us about
768 * it in https://github.com/firebase/firebase-js-sdk/issues/1674.
769 */
770 experimentalForceLongPolling?: boolean;
771 /**
772 * Configures the SDK's underlying transport (WebChannel) to automatically
773 * detect if long-polling should be used. This is very similar to
774 * `experimentalForceLongPolling`, but only uses long-polling if required.
775 *
776 * This setting will likely be enabled by default in future releases and
777 * cannot be combined with `experimentalForceLongPolling`.
778 */
779 experimentalAutoDetectLongPolling?: boolean;
780 /**
781 * The hostname to connect to.
782 */
783 host?: string;
784 /**
785 * Whether to use SSL when connecting.
786 */
787 ssl?: boolean;
788 /**
789 * Whether to skip nested properties that are set to `undefined` during
790 * object serialization. If set to `true`, these properties are skipped
791 * and not written to Firestore. If set to `false` or omitted, the SDK
792 * throws an exception when it encounters properties of type `undefined`.
793 */
794 ignoreUndefinedProperties?: boolean;
795}
796/**
797 * @license
798 * Copyright 2017 Google LLC
799 *
800 * Licensed under the Apache License, Version 2.0 (the "License");
801 * you may not use this file except in compliance with the License.
802 * You may obtain a copy of the License at
803 *
804 * http://www.apache.org/licenses/LICENSE-2.0
805 *
806 * Unless required by applicable law or agreed to in writing, software
807 * distributed under the License is distributed on an "AS IS" BASIS,
808 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
809 * See the License for the specific language governing permissions and
810 * limitations under the License.
811 */
812/**
813 * An immutable object representing a geographic location in Firestore. The
814 * location is represented as latitude/longitude pair.
815 *
816 * Latitude values are in the range of [-90, 90].
817 * Longitude values are in the range of [-180, 180].
818 */
819export declare class GeoPoint {
820 /**
821 * Creates a new immutable `GeoPoint` object with the provided latitude and
822 * longitude values.
823 * @param latitude - The latitude as number between -90 and 90.
824 * @param longitude - The longitude as number between -180 and 180.
825 */
826 constructor(latitude: number, longitude: number);
827 /**
828 * The latitude of this `GeoPoint` instance.
829 */
830 get latitude(): number;
831 /**
832 * The longitude of this `GeoPoint` instance.
833 */
834 get longitude(): number;
835 /**
836 * Returns true if this `GeoPoint` is equal to the provided one.
837 *
838 * @param other - The `GeoPoint` to compare against.
839 * @returns true if this `GeoPoint` is equal to the provided one.
840 */
841 isEqual(other: GeoPoint): boolean;
842 /** Returns a JSON-serializable representation of this GeoPoint. */
843 toJSON(): {
844 latitude: number;
845 longitude: number;
846 };
847}
848/**
849 * Reads the document referred to by this `DocumentReference`.
850 *
851 * Note: `getDoc()` attempts to provide up-to-date data when possible by waiting
852 * for data from the server, but it may return cached data or fail if you are
853 * offline and the server cannot be reached. To specify this behavior, invoke
854 * {@link getDocFromCache} or {@link getDocFromServer}.
855 *
856 * @param reference - The reference of the document to fetch.
857 * @returns A Promise resolved with a `DocumentSnapshot` containing the
858 * current document contents.
859 */
860export declare function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
861/**
862 * Reads the document referred to by this `DocumentReference` from cache.
863 * Returns an error if the document is not currently cached.
864 *
865 * @returns A `Promise` resolved with a `DocumentSnapshot` containing the
866 * current document contents.
867 */
868export declare function getDocFromCache<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
869/**
870 * Reads the document referred to by this `DocumentReference` from the server.
871 * Returns an error if the network is not available.
872 *
873 * @returns A `Promise` resolved with a `DocumentSnapshot` containing the
874 * current document contents.
875 */
876export declare function getDocFromServer<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
877/**
878 * Executes the query and returns the results as a `QuerySnapshot`.
879 *
880 * Note: `getDocs()` attempts to provide up-to-date data when possible by
881 * waiting for data from the server, but it may return cached data or fail if
882 * you are offline and the server cannot be reached. To specify this behavior,
883 * invoke {@link getDocsFromCache} or {@link getDocsFromServer}.
884 *
885 * @returns A `Promise` that will be resolved with the results of the query.
886 */
887export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
888/**
889 * Executes the query and returns the results as a `QuerySnapshot` from cache.
890 * Returns an error if the document is not currently cached.
891 *
892 * @returns A `Promise` that will be resolved with the results of the query.
893 */
894export declare function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
895/**
896 * Executes the query and returns the results as a `QuerySnapshot` from the
897 * server. Returns an error if the network is not available.
898 *
899 * @returns A `Promise` that will be resolved with the results of the query.
900 */
901export declare function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
902/**
903 * Returns the existing {@link Firestore} instance that is associated with the
904 * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
905 * instance with default settings.
906 *
907 * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
908 * instance is associated with.
909 * @returns The {@link Firestore} instance of the provided app.
910 */
911export declare function getFirestore(app?: FirebaseApp): Firestore;
912/**
913 * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
914 * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
915 * the given value.
916 *
917 * If either the operand or the current field value uses floating point
918 * precision, all arithmetic follows IEEE 754 semantics. If both values are
919 * integers, values outside of JavaScript's safe number range
920 * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to
921 * precision loss. Furthermore, once processed by the Firestore backend, all
922 * integer operations are capped between -2^63 and 2^63-1.
923 *
924 * If the current field value is not of type `number`, or if the field does not
925 * yet exist, the transformation sets the field to the given value.
926 *
927 * @param n - The value to increment by.
928 * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
929 * `updateDoc()`
930 */
931export declare function increment(n: number): FieldValue;
932/**
933 * Initializes a new instance of {@link Firestore} with the provided settings.
934 * Can only be called before any other function, including
935 * {@link getFirestore}. If the custom settings are empty, this function is
936 * equivalent to calling {@link getFirestore}.
937 *
938 * @param app - The {@link @firebase/app#FirebaseApp} with which the {@link Firestore} instance will
939 * be associated.
940 * @param settings - A settings object to configure the {@link Firestore} instance.
941 * @returns A newly initialized {@link Firestore} instance.
942 */
943export declare function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings): Firestore;
944/* Excluded from this release type: _isBase64Available */
945/**
946 * Creates a {@link QueryConstraint} that only returns the first matching documents.
947 *
948 * @param limit - The maximum number of items to return.
949 * @returns The created {@link Query}.
950 */
951export declare function limit(limit: number): QueryConstraint;
952/**
953 * Creates a {@link QueryConstraint} that only returns the last matching documents.
954 *
955 * You must specify at least one `orderBy` clause for `limitToLast` queries,
956 * otherwise an exception will be thrown during execution.
957 *
958 * @param limit - The maximum number of items to return.
959 * @returns The created {@link Query}.
960 */
961export declare function limitToLast(limit: number): QueryConstraint;
962/**
963 * Loads a Firestore bundle into the local cache.
964 *
965 * @param firestore - The {@link Firestore} instance to load bundles for.
966 * @param bundleData - An object representing the bundle to be loaded. Valid
967 * objects are `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
968 *
969 * @returns A `LoadBundleTask` object, which notifies callers with progress
970 * updates, and completion or error events. It can be used as a
971 * `Promise<LoadBundleTaskProgress>`.
972 */
973export declare function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;
974/**
975 * Represents the task of loading a Firestore bundle. It provides progress of bundle
976 * loading, as well as task completion and error events.
977 *
978 * The API is compatible with `Promise<LoadBundleTaskProgress>`.
979 */
980export declare class LoadBundleTask implements PromiseLike<LoadBundleTaskProgress> {
981 /**
982 * Registers functions to listen to bundle loading progress events.
983 * @param next - Called when there is a progress update from bundle loading. Typically `next` calls occur
984 * each time a Firestore document is loaded from the bundle.
985 * @param error - Called when an error occurs during bundle loading. The task aborts after reporting the
986 * error, and there should be no more updates after this.
987 * @param complete - Called when the loading task is complete.
988 */
989 onProgress(next?: (progress: LoadBundleTaskProgress) => unknown, error?: (err: Error) => unknown, complete?: () => void): void;
990 /**
991 * Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
992 *
993 * @param onRejected - Called when an error occurs during bundle loading.
994 */
995 catch<R>(onRejected: (a: Error) => R | PromiseLike<R>): Promise<R | LoadBundleTaskProgress>;
996 /**
997 * Implements the `Promise<LoadBundleTaskProgress>.then` interface.
998 *
999 * @param onFulfilled - Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
1000 * The update will always have its `taskState` set to `"Success"`.
1001 * @param onRejected - Called when an error occurs during bundle loading.
1002 */
1003 then<T, R>(onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, onRejected?: (a: Error) => R | PromiseLike<R>): Promise<T | R>;
1004}
1005/**
1006 * Represents a progress update or a final state from loading bundles.
1007 */
1008export declare interface LoadBundleTaskProgress {
1009 /** How many documents have been loaded. */
1010 documentsLoaded: number;
1011 /** How many documents are in the bundle being loaded. */
1012 totalDocuments: number;
1013 /** How many bytes have been loaded. */
1014 bytesLoaded: number;
1015 /** How many bytes are in the bundle being loaded. */
1016 totalBytes: number;
1017 /** Current task state. */
1018 taskState: TaskState;
1019}
1020export { LogLevel };
1021/**
1022 * Reads a Firestore {@link Query} from local cache, identified by the given
1023 * name.
1024 *
1025 * The named queries are packaged into bundles on the server side (along
1026 * with resulting documents), and loaded to local cache using `loadBundle`. Once
1027 * in local cache, use this method to extract a {@link Query} by name.
1028 *
1029 * @param firestore - The {@link Firestore} instance to read the query from.
1030 * @param name - The name of the query.
1031 * @returns A `Promise` that is resolved with the Query or `null`.
1032 */
1033export declare function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;
1034/**
1035 * For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1,
1036 * 'bar.qux': T2}). Intersect them together to make a single map containing
1037 * all possible keys that are all marked as optional
1038 */
1039export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
1040 [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
1041}[keyof T & string]>;
1042/**
1043 * Attaches a listener for `DocumentSnapshot` events. You may either pass
1044 * individual `onNext` and `onError` callbacks or pass a single observer
1045 * object with `next` and `error` callbacks.
1046 *
1047 * NOTE: Although an `onCompletion` callback can be provided, it will
1048 * never be called because the snapshot stream is never-ending.
1049 *
1050 * @param reference - A reference to the document to listen to.
1051 * @param observer - A single object containing `next` and `error` callbacks.
1052 * @returns An unsubscribe function that can be called to cancel
1053 * the snapshot listener.
1054 */
1055export declare function onSnapshot<T>(reference: DocumentReference<T>, observer: {
1056 next?: (snapshot: DocumentSnapshot<T>) => void;
1057 error?: (error: FirestoreError) => void;
1058 complete?: () => void;
1059}): Unsubscribe;
1060/**
1061 * Attaches a listener for `DocumentSnapshot` events. You may either pass
1062 * individual `onNext` and `onError` callbacks or pass a single observer
1063 * object with `next` and `error` callbacks.
1064 *
1065 * NOTE: Although an `onCompletion` callback can be provided, it will
1066 * never be called because the snapshot stream is never-ending.
1067 *
1068 * @param reference - A reference to the document to listen to.
1069 * @param options - Options controlling the listen behavior.
1070 * @param observer - A single object containing `next` and `error` callbacks.
1071 * @returns An unsubscribe function that can be called to cancel
1072 * the snapshot listener.
1073 */
1074export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, observer: {
1075 next?: (snapshot: DocumentSnapshot<T>) => void;
1076 error?: (error: FirestoreError) => void;
1077 complete?: () => void;
1078}): Unsubscribe;
1079/**
1080 * Attaches a listener for `DocumentSnapshot` events. You may either pass
1081 * individual `onNext` and `onError` callbacks or pass a single observer
1082 * object with `next` and `error` callbacks.
1083 *
1084 * NOTE: Although an `onCompletion` callback can be provided, it will
1085 * never be called because the snapshot stream is never-ending.
1086 *
1087 * @param reference - A reference to the document to listen to.
1088 * @param onNext - A callback to be called every time a new `DocumentSnapshot`
1089 * is available.
1090 * @param onError - A callback to be called if the listen fails or is
1091 * cancelled. No further callbacks will occur.
1092 * @param onCompletion - Can be provided, but will not be called since streams are
1093 * never ending.
1094 * @returns An unsubscribe function that can be called to cancel
1095 * the snapshot listener.
1096 */
1097export declare function onSnapshot<T>(reference: DocumentReference<T>, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
1098/**
1099 * Attaches a listener for `DocumentSnapshot` events. You may either pass
1100 * individual `onNext` and `onError` callbacks or pass a single observer
1101 * object with `next` and `error` callbacks.
1102 *
1103 * NOTE: Although an `onCompletion` callback can be provided, it will
1104 * never be called because the snapshot stream is never-ending.
1105 *
1106 * @param reference - A reference to the document to listen to.
1107 * @param options - Options controlling the listen behavior.
1108 * @param onNext - A callback to be called every time a new `DocumentSnapshot`
1109 * is available.
1110 * @param onError - A callback to be called if the listen fails or is
1111 * cancelled. No further callbacks will occur.
1112 * @param onCompletion - Can be provided, but will not be called since streams are
1113 * never ending.
1114 * @returns An unsubscribe function that can be called to cancel
1115 * the snapshot listener.
1116 */
1117export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
1118/**
1119 * Attaches a listener for `QuerySnapshot` events. You may either pass
1120 * individual `onNext` and `onError` callbacks or pass a single observer
1121 * object with `next` and `error` callbacks. The listener can be cancelled by
1122 * calling the function that is returned when `onSnapshot` is called.
1123 *
1124 * NOTE: Although an `onCompletion` callback can be provided, it will
1125 * never be called because the snapshot stream is never-ending.
1126 *
1127 * @param query - The query to listen to.
1128 * @param observer - A single object containing `next` and `error` callbacks.
1129 * @returns An unsubscribe function that can be called to cancel
1130 * the snapshot listener.
1131 */
1132export declare function onSnapshot<T>(query: Query<T>, observer: {
1133 next?: (snapshot: QuerySnapshot<T>) => void;
1134 error?: (error: FirestoreError) => void;
1135 complete?: () => void;
1136}): Unsubscribe;
1137/**
1138 * Attaches a listener for `QuerySnapshot` events. You may either pass
1139 * individual `onNext` and `onError` callbacks or pass a single observer
1140 * object with `next` and `error` callbacks. The listener can be cancelled by
1141 * calling the function that is returned when `onSnapshot` is called.
1142 *
1143 * NOTE: Although an `onCompletion` callback can be provided, it will
1144 * never be called because the snapshot stream is never-ending.
1145 *
1146 * @param query - The query to listen to.
1147 * @param options - Options controlling the listen behavior.
1148 * @param observer - A single object containing `next` and `error` callbacks.
1149 * @returns An unsubscribe function that can be called to cancel
1150 * the snapshot listener.
1151 */
1152export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, observer: {
1153 next?: (snapshot: QuerySnapshot<T>) => void;
1154 error?: (error: FirestoreError) => void;
1155 complete?: () => void;
1156}): Unsubscribe;
1157/**
1158 * Attaches a listener for `QuerySnapshot` events. You may either pass
1159 * individual `onNext` and `onError` callbacks or pass a single observer
1160 * object with `next` and `error` callbacks. The listener can be cancelled by
1161 * calling the function that is returned when `onSnapshot` is called.
1162 *
1163 * NOTE: Although an `onCompletion` callback can be provided, it will
1164 * never be called because the snapshot stream is never-ending.
1165 *
1166 * @param query - The query to listen to.
1167 * @param onNext - A callback to be called every time a new `QuerySnapshot`
1168 * is available.
1169 * @param onCompletion - Can be provided, but will not be called since streams are
1170 * never ending.
1171 * @param onError - A callback to be called if the listen fails or is
1172 * cancelled. No further callbacks will occur.
1173 * @returns An unsubscribe function that can be called to cancel
1174 * the snapshot listener.
1175 */
1176export declare function onSnapshot<T>(query: Query<T>, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
1177/**
1178 * Attaches a listener for `QuerySnapshot` events. You may either pass
1179 * individual `onNext` and `onError` callbacks or pass a single observer
1180 * object with `next` and `error` callbacks. The listener can be cancelled by
1181 * calling the function that is returned when `onSnapshot` is called.
1182 *
1183 * NOTE: Although an `onCompletion` callback can be provided, it will
1184 * never be called because the snapshot stream is never-ending.
1185 *
1186 * @param query - The query to listen to.
1187 * @param options - Options controlling the listen behavior.
1188 * @param onNext - A callback to be called every time a new `QuerySnapshot`
1189 * is available.
1190 * @param onCompletion - Can be provided, but will not be called since streams are
1191 * never ending.
1192 * @param onError - A callback to be called if the listen fails or is
1193 * cancelled. No further callbacks will occur.
1194 * @returns An unsubscribe function that can be called to cancel
1195 * the snapshot listener.
1196 */
1197export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;
1198/**
1199 * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
1200 * event indicates that all listeners affected by a given change have fired,
1201 * even if a single server-generated change affects multiple listeners.
1202 *
1203 * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
1204 * with each other, but does not relate to whether those snapshots are in sync
1205 * with the server. Use SnapshotMetadata in the individual listeners to
1206 * determine if a snapshot is from the cache or the server.
1207 *
1208 * @param firestore - The instance of Firestore for synchronizing snapshots.
1209 * @param observer - A single object containing `next` and `error` callbacks.
1210 * @returns An unsubscribe function that can be called to cancel the snapshot
1211 * listener.
1212 */
1213export declare function onSnapshotsInSync(firestore: Firestore, observer: {
1214 next?: (value: void) => void;
1215 error?: (error: FirestoreError) => void;
1216 complete?: () => void;
1217}): Unsubscribe;
1218/**
1219 * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
1220 * event indicates that all listeners affected by a given change have fired,
1221 * even if a single server-generated change affects multiple listeners.
1222 *
1223 * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
1224 * with each other, but does not relate to whether those snapshots are in sync
1225 * with the server. Use `SnapshotMetadata` in the individual listeners to
1226 * determine if a snapshot is from the cache or the server.
1227 *
1228 * @param firestore - The `Firestore` instance for synchronizing snapshots.
1229 * @param onSync - A callback to be called every time all snapshot listeners are
1230 * in sync with each other.
1231 * @returns An unsubscribe function that can be called to cancel the snapshot
1232 * listener.
1233 */
1234export declare function onSnapshotsInSync(firestore: Firestore, onSync: () => void): Unsubscribe;
1235/**
1236 * Creates a {@link QueryConstraint} that sorts the query result by the
1237 * specified field, optionally in descending order instead of ascending.
1238 *
1239 * @param fieldPath - The field to sort by.
1240 * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
1241 * not specified, order will be ascending.
1242 * @returns The created {@link Query}.
1243 */
1244export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryConstraint;
1245/**
1246 * The direction of a {@link orderBy} clause is specified as 'desc' or 'asc'
1247 * (descending or ascending).
1248 */
1249export declare type OrderByDirection = 'desc' | 'asc';
1250/**
1251 * Similar to Typescript's `Partial<T>`, but allows nested fields to be
1252 * omitted and FieldValues to be passed in as property values.
1253 */
1254export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
1255 [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
1256} : never);
1257/**
1258 * Settings that can be passed to `enableIndexedDbPersistence()` to configure
1259 * Firestore persistence.
1260 */
1261export declare interface PersistenceSettings {
1262 /**
1263 * Whether to force enable persistence for the client. This cannot be used
1264 * with multi-tab synchronization and is primarily intended for use with Web
1265 * Workers. Setting this to `true` will enable persistence, but cause other
1266 * tabs using persistence to fail.
1267 */
1268 forceOwnership?: boolean;
1269}
1270/**
1271 * These types primarily exist to support the `UpdateData`,
1272 * `WithFieldValue`, and `PartialWithFieldValue` types and are not consumed
1273 * directly by the end developer.
1274 */
1275/** Primitive types. */
1276export declare type Primitive = string | number | boolean | undefined | null;
1277/**
1278 * A `Query` refers to a query which you can read or listen to. You can also
1279 * construct refined `Query` objects by adding filters and ordering.
1280 */
1281export declare class Query<T = DocumentData> {
1282 /**
1283 * If provided, the `FirestoreDataConverter` associated with this instance.
1284 */
1285 readonly converter: FirestoreDataConverter<T> | null;
1286 /** The type of this Firestore reference. */
1287 readonly type: 'query' | 'collection';
1288 /**
1289 * The `Firestore` instance for the Firestore database (useful for performing
1290 * transactions, etc.).
1291 */
1292 readonly firestore: Firestore;
1293 protected constructor();
1294 /**
1295 * Removes the current converter.
1296 *
1297 * @param converter - `null` removes the current converter.
1298 * @returns A `Query<DocumentData>` that does not use a converter.
1299 */
1300 withConverter(converter: null): Query<DocumentData>;
1301 /**
1302 * Applies a custom data converter to this query, allowing you to use your own
1303 * custom model objects with Firestore. When you call {@link getDocs} with
1304 * the returned query, the provided converter will convert between Firestore
1305 * data and your custom type `U`.
1306 *
1307 * @param converter - Converts objects to and from Firestore.
1308 * @returns A `Query<U>` that uses the provided converter.
1309 */
1310 withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
1311}
1312/**
1313 * Creates a new immutable instance of {@link Query} that is extended to also include
1314 * additional query constraints.
1315 *
1316 * @param query - The {@link Query} instance to use as a base for the new constraints.
1317 * @param queryConstraints - The list of {@link QueryConstraint}s to apply.
1318 * @throws if any of the provided query constraints cannot be combined with the
1319 * existing or new constraints.
1320 */
1321export declare function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
1322/**
1323 * A `QueryConstraint` is used to narrow the set of documents returned by a
1324 * Firestore query. `QueryConstraint`s are created by invoking {@link where},
1325 * {@link orderBy}, {@link (startAt:1)}, {@link (startAfter:1)}, {@link
1326 * endBefore:1}, {@link (endAt:1)}, {@link limit} or {@link limitToLast} and
1327 * can then be passed to {@link query} to create a new query instance that
1328 * also contains this `QueryConstraint`.
1329 */
1330export declare abstract class QueryConstraint {
1331 /** The type of this query constraints */
1332 abstract readonly type: QueryConstraintType;
1333}
1334/** Describes the different query constraints available in this SDK. */
1335export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';
1336/**
1337 * A `QueryDocumentSnapshot` contains data read from a document in your
1338 * Firestore database as part of a query. The document is guaranteed to exist
1339 * and its data can be extracted with `.data()` or `.get(<field>)` to get a
1340 * specific field.
1341 *
1342 * A `QueryDocumentSnapshot` offers the same API surface as a
1343 * `DocumentSnapshot`. Since query results contain only existing documents, the
1344 * `exists` property will always be true and `data()` will never return
1345 * 'undefined'.
1346 */
1347export declare class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<T> {
1348 /**
1349 * Retrieves all fields in the document as an `Object`.
1350 *
1351 * By default, `serverTimestamp()` values that have not yet been
1352 * set to their final value will be returned as `null`. You can override
1353 * this by passing an options object.
1354 *
1355 * @override
1356 * @param options - An options object to configure how data is retrieved from
1357 * the snapshot (for example the desired behavior for server timestamps that
1358 * have not yet been set to their final value).
1359 * @returns An `Object` containing all fields in the document.
1360 */
1361 data(options?: SnapshotOptions): T;
1362}
1363/**
1364 * Returns true if the provided queries point to the same collection and apply
1365 * the same constraints.
1366 *
1367 * @param left - A `Query` to compare.
1368 * @param right - A `Query` to compare.
1369 * @returns true if the references point to the same location in the same
1370 * Firestore database.
1371 */
1372export declare function queryEqual<T>(left: Query<T>, right: Query<T>): boolean;
1373/**
1374 * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
1375 * representing the results of a query. The documents can be accessed as an
1376 * array via the `docs` property or enumerated using the `forEach` method. The
1377 * number of documents can be determined via the `empty` and `size`
1378 * properties.
1379 */
1380export declare class QuerySnapshot<T = DocumentData> {
1381 /**
1382 * Metadata about this snapshot, concerning its source and if it has local
1383 * modifications.
1384 */
1385 readonly metadata: SnapshotMetadata;
1386 /**
1387 * The query on which you called `get` or `onSnapshot` in order to get this
1388 * `QuerySnapshot`.
1389 */
1390 readonly query: Query<T>;
1391 private constructor();
1392 /** An array of all the documents in the `QuerySnapshot`. */
1393 get docs(): Array<QueryDocumentSnapshot<T>>;
1394 /** The number of documents in the `QuerySnapshot`. */
1395 get size(): number;
1396 /** True if there are no documents in the `QuerySnapshot`. */
1397 get empty(): boolean;
1398 /**
1399 * Enumerates all of the documents in the `QuerySnapshot`.
1400 *
1401 * @param callback - A callback to be called with a `QueryDocumentSnapshot` for
1402 * each document in the snapshot.
1403 * @param thisArg - The `this` binding for the callback.
1404 */
1405 forEach(callback: (result: QueryDocumentSnapshot<T>) => void, thisArg?: unknown): void;
1406 /**
1407 * Returns an array of the documents changes since the last snapshot. If this
1408 * is the first snapshot, all documents will be in the list as 'added'
1409 * changes.
1410 *
1411 * @param options - `SnapshotListenOptions` that control whether metadata-only
1412 * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
1413 * snapshot events.
1414 */
1415 docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
1416}
1417/**
1418 * Returns true if the provided references are equal.
1419 *
1420 * @param left - A reference to compare.
1421 * @param right - A reference to compare.
1422 * @returns true if the references point to the same location in the same
1423 * Firestore database.
1424 */
1425export declare function refEqual<T>(left: DocumentReference<T> | CollectionReference<T>, right: DocumentReference<T> | CollectionReference<T>): boolean;
1426/* Excluded from this release type: _ResourcePath */
1427/**
1428 * Executes the given `updateFunction` and then attempts to commit the changes
1429 * applied within the transaction. If any document read within the transaction
1430 * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
1431 * commit after 5 attempts, the transaction fails.
1432 *
1433 * The maximum number of writes allowed in a single transaction is 500.
1434 *
1435 * @param firestore - A reference to the Firestore database to run this
1436 * transaction against.
1437 * @param updateFunction - The function to execute within the transaction
1438 * context.
1439 * @returns If the transaction completed successfully or was explicitly aborted
1440 * (the `updateFunction` returned a failed promise), the promise returned by the
1441 * `updateFunction `is returned here. Otherwise, if the transaction failed, a
1442 * rejected promise with the corresponding failure error is returned.
1443 */
1444export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
1445/**
1446 * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
1447 * include a server-generated timestamp in the written data.
1448 */
1449export declare function serverTimestamp(): FieldValue;
1450/**
1451 * Writes to the document referred to by this `DocumentReference`. If the
1452 * document does not yet exist, it will be created.
1453 *
1454 * @param reference - A reference to the document to write.
1455 * @param data - A map of the fields and values for the document.
1456 * @returns A `Promise` resolved once the data has been successfully written
1457 * to the backend (note that it won't resolve while you're offline).
1458 */
1459export declare function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<T>): Promise<void>;
1460/**
1461 * Writes to the document referred to by the specified `DocumentReference`. If
1462 * the document does not yet exist, it will be created. If you provide `merge`
1463 * or `mergeFields`, the provided data can be merged into an existing document.
1464 *
1465 * @param reference - A reference to the document to write.
1466 * @param data - A map of the fields and values for the document.
1467 * @param options - An object to configure the set behavior.
1468 * @returns A Promise resolved once the data has been successfully written
1469 * to the backend (note that it won't resolve while you're offline).
1470 */
1471export declare function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;
1472/* Excluded from this release type: _setIndexConfiguration */
1473/**
1474 * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
1475 *
1476 * @param logLevel - The verbosity you set for activity and error logging. Can
1477 * be any of the following values:
1478 *
1479 * <ul>
1480 * <li>`debug` for the most verbose logging level, primarily for
1481 * debugging.</li>
1482 * <li>`error` to log errors only.</li>
1483 * <li><code>`silent` to turn off logging.</li>
1484 * </ul>
1485 */
1486export declare function setLogLevel(logLevel: LogLevel): void;
1487/**
1488 * An options object that configures the behavior of {@link @firebase/firestore/lite#(setDoc:1)}, {@link
1489 * @firebase/firestore/lite#(WriteBatch.set:1)} and {@link @firebase/firestore/lite#(Transaction.set:1)} calls. These calls can be
1490 * configured to perform granular merges instead of overwriting the target
1491 * documents in their entirety by providing a `SetOptions` with `merge: true`.
1492 *
1493 * @param merge - Changes the behavior of a `setDoc()` call to only replace the
1494 * values specified in its data argument. Fields omitted from the `setDoc()`
1495 * call remain untouched. If your input sets any field to an empty map, all
1496 * nested fields are overwritten.
1497 * @param mergeFields - Changes the behavior of `setDoc()` calls to only replace
1498 * the specified field paths. Any field path that is not specified is ignored
1499 * and remains untouched. If your input sets any field to an empty map, all
1500 * nested fields are overwritten.
1501 */
1502export declare type SetOptions = {
1503 readonly merge?: boolean;
1504} | {
1505 readonly mergeFields?: Array<string | FieldPath>;
1506};
1507/**
1508 * Returns true if the provided snapshots are equal.
1509 *
1510 * @param left - A snapshot to compare.
1511 * @param right - A snapshot to compare.
1512 * @returns true if the snapshots are equal.
1513 */
1514export declare function snapshotEqual<T>(left: DocumentSnapshot<T> | QuerySnapshot<T>, right: DocumentSnapshot<T> | QuerySnapshot<T>): boolean;
1515/**
1516 * An options object that can be passed to {@link (onSnapshot:1)} and {@link
1517 * QuerySnapshot.docChanges} to control which types of changes to include in the
1518 * result set.
1519 */
1520export declare interface SnapshotListenOptions {
1521 /**
1522 * Include a change even if only the metadata of the query or of a document
1523 * changed. Default is false.
1524 */
1525 readonly includeMetadataChanges?: boolean;
1526}
1527/**
1528 * Metadata about a snapshot, describing the state of the snapshot.
1529 */
1530export declare class SnapshotMetadata {
1531 /**
1532 * True if the snapshot contains the result of local writes (for example
1533 * `set()` or `update()` calls) that have not yet been committed to the
1534 * backend. If your listener has opted into metadata updates (via
1535 * `SnapshotListenOptions`) you will receive another snapshot with
1536 * `hasPendingWrites` equal to false once the writes have been committed to
1537 * the backend.
1538 */
1539 readonly hasPendingWrites: boolean;
1540 /**
1541 * True if the snapshot was created from cached data rather than guaranteed
1542 * up-to-date server data. If your listener has opted into metadata updates
1543 * (via `SnapshotListenOptions`) you will receive another snapshot with
1544 * `fromCache` set to false once the client has received up-to-date data from
1545 * the backend.
1546 */
1547 readonly fromCache: boolean;
1548 private constructor();
1549 /**
1550 * Returns true if this `SnapshotMetadata` is equal to the provided one.
1551 *
1552 * @param other - The `SnapshotMetadata` to compare against.
1553 * @returns true if this `SnapshotMetadata` is equal to the provided one.
1554 */
1555 isEqual(other: SnapshotMetadata): boolean;
1556}
1557/**
1558 * Options that configure how data is retrieved from a `DocumentSnapshot` (for
1559 * example the desired behavior for server timestamps that have not yet been set
1560 * to their final value).
1561 */
1562export declare interface SnapshotOptions {
1563 /**
1564 * If set, controls the return value for server timestamps that have not yet
1565 * been set to their final value.
1566 *
1567 * By specifying 'estimate', pending server timestamps return an estimate
1568 * based on the local clock. This estimate will differ from the final value
1569 * and cause these values to change once the server result becomes available.
1570 *
1571 * By specifying 'previous', pending timestamps will be ignored and return
1572 * their previous value instead.
1573 *
1574 * If omitted or set to 'none', `null` will be returned by default until the
1575 * server value becomes available.
1576 */
1577 readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
1578}
1579/**
1580 * Creates a {@link QueryConstraint} that modifies the result set to start after the
1581 * provided document (exclusive). The starting position is relative to the order
1582 * of the query. The document must contain all of the fields provided in the
1583 * orderBy of the query.
1584 *
1585 * @param snapshot - The snapshot of the document to start after.
1586 * @returns A {@link QueryConstraint} to pass to `query()`
1587 */
1588export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
1589/**
1590 * Creates a {@link QueryConstraint} that modifies the result set to start after the
1591 * provided fields relative to the order of the query. The order of the field
1592 * values must match the order of the order by clauses of the query.
1593 *
1594 * @param fieldValues - The field values to start this query after, in order
1595 * of the query's order by.
1596 * @returns A {@link QueryConstraint} to pass to `query()`
1597 */
1598export declare function startAfter(...fieldValues: unknown[]): QueryConstraint;
1599/**
1600 * Creates a {@link QueryConstraint} that modifies the result set to start at the
1601 * provided document (inclusive). The starting position is relative to the order
1602 * of the query. The document must contain all of the fields provided in the
1603 * `orderBy` of this query.
1604 *
1605 * @param snapshot - The snapshot of the document to start at.
1606 * @returns A {@link QueryConstraint} to pass to `query()`.
1607 */
1608export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
1609/**
1610 * Creates a {@link QueryConstraint} that modifies the result set to start at the
1611 * provided fields relative to the order of the query. The order of the field
1612 * values must match the order of the order by clauses of the query.
1613 *
1614 * @param fieldValues - The field values to start this query at, in order
1615 * of the query's order by.
1616 * @returns A {@link QueryConstraint} to pass to `query()`.
1617 */
1618export declare function startAt(...fieldValues: unknown[]): QueryConstraint;
1619/**
1620 * Represents the state of bundle loading tasks.
1621 *
1622 * Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
1623 * be no more updates after they are reported.
1624 */
1625export declare type TaskState = 'Error' | 'Running' | 'Success';
1626/**
1627 * Terminates the provided {@link Firestore} instance.
1628 *
1629 * After calling `terminate()` only the `clearIndexedDbPersistence()` function
1630 * may be used. Any other function will throw a `FirestoreError`.
1631 *
1632 * To restart after termination, create a new instance of FirebaseFirestore with
1633 * {@link getFirestore}.
1634 *
1635 * Termination does not cancel any pending writes, and any promises that are
1636 * awaiting a response from the server will not be resolved. If you have
1637 * persistence enabled, the next time you start this instance, it will resume
1638 * sending these writes to the server.
1639 *
1640 * Note: Under normal circumstances, calling `terminate()` is not required. This
1641 * function is useful only when you want to force this instance to release all
1642 * of its resources or in combination with `clearIndexedDbPersistence()` to
1643 * ensure that all local state is destroyed between test runs.
1644 *
1645 * @returns A `Promise` that is resolved when the instance has been successfully
1646 * terminated.
1647 */
1648export declare function terminate(firestore: Firestore): Promise<void>;
1649/**
1650 * @license
1651 * Copyright 2017 Google LLC
1652 *
1653 * Licensed under the Apache License, Version 2.0 (the "License");
1654 * you may not use this file except in compliance with the License.
1655 * You may obtain a copy of the License at
1656 *
1657 * http://www.apache.org/licenses/LICENSE-2.0
1658 *
1659 * Unless required by applicable law or agreed to in writing, software
1660 * distributed under the License is distributed on an "AS IS" BASIS,
1661 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1662 * See the License for the specific language governing permissions and
1663 * limitations under the License.
1664 */
1665/**
1666 * A `Timestamp` represents a point in time independent of any time zone or
1667 * calendar, represented as seconds and fractions of seconds at nanosecond
1668 * resolution in UTC Epoch time.
1669 *
1670 * It is encoded using the Proleptic Gregorian Calendar which extends the
1671 * Gregorian calendar backwards to year one. It is encoded assuming all minutes
1672 * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
1673 * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
1674 * 9999-12-31T23:59:59.999999999Z.
1675 *
1676 * For examples and further specifications, refer to the
1677 * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
1678 */
1679export declare class Timestamp {
1680 /**
1681 * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
1682 */
1683 readonly seconds: number;
1684 /**
1685 * The fractions of a second at nanosecond resolution.*
1686 */
1687 readonly nanoseconds: number;
1688 /**
1689 * Creates a new timestamp with the current date, with millisecond precision.
1690 *
1691 * @returns a new timestamp representing the current date.
1692 */
1693 static now(): Timestamp;
1694 /**
1695 * Creates a new timestamp from the given date.
1696 *
1697 * @param date - The date to initialize the `Timestamp` from.
1698 * @returns A new `Timestamp` representing the same point in time as the given
1699 * date.
1700 */
1701 static fromDate(date: Date): Timestamp;
1702 /**
1703 * Creates a new timestamp from the given number of milliseconds.
1704 *
1705 * @param milliseconds - Number of milliseconds since Unix epoch
1706 * 1970-01-01T00:00:00Z.
1707 * @returns A new `Timestamp` representing the same point in time as the given
1708 * number of milliseconds.
1709 */
1710 static fromMillis(milliseconds: number): Timestamp;
1711 /**
1712 * Creates a new timestamp.
1713 *
1714 * @param seconds - The number of seconds of UTC time since Unix epoch
1715 * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
1716 * 9999-12-31T23:59:59Z inclusive.
1717 * @param nanoseconds - The non-negative fractions of a second at nanosecond
1718 * resolution. Negative second values with fractions must still have
1719 * non-negative nanoseconds values that count forward in time. Must be
1720 * from 0 to 999,999,999 inclusive.
1721 */
1722 constructor(
1723 /**
1724 * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
1725 */
1726 seconds: number,
1727 /**
1728 * The fractions of a second at nanosecond resolution.*
1729 */
1730 nanoseconds: number);
1731 /**
1732 * Converts a `Timestamp` to a JavaScript `Date` object. This conversion
1733 * causes a loss of precision since `Date` objects only support millisecond
1734 * precision.
1735 *
1736 * @returns JavaScript `Date` object representing the same point in time as
1737 * this `Timestamp`, with millisecond precision.
1738 */
1739 toDate(): Date;
1740 /**
1741 * Converts a `Timestamp` to a numeric timestamp (in milliseconds since
1742 * epoch). This operation causes a loss of precision.
1743 *
1744 * @returns The point in time corresponding to this timestamp, represented as
1745 * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
1746 */
1747 toMillis(): number;
1748 /**
1749 * Returns true if this `Timestamp` is equal to the provided one.
1750 *
1751 * @param other - The `Timestamp` to compare against.
1752 * @returns true if this `Timestamp` is equal to the provided one.
1753 */
1754 isEqual(other: Timestamp): boolean;
1755 /** Returns a textual representation of this `Timestamp`. */
1756 toString(): string;
1757 /** Returns a JSON-serializable representation of this `Timestamp`. */
1758 toJSON(): {
1759 seconds: number;
1760 nanoseconds: number;
1761 };
1762 /**
1763 * Converts this object to a primitive string, which allows `Timestamp` objects
1764 * to be compared using the `>`, `<=`, `>=` and `>` operators.
1765 */
1766 valueOf(): string;
1767}
1768/**
1769 * A reference to a transaction.
1770 *
1771 * The `Transaction` object passed to a transaction's `updateFunction` provides
1772 * the methods to read and write data within the transaction context. See
1773 * {@link runTransaction}.
1774 */
1775export declare class Transaction {
1776 private constructor();
1777 /**
1778 * Reads the document referenced by the provided {@link DocumentReference}.
1779 *
1780 * @param documentRef - A reference to the document to be read.
1781 * @returns A `DocumentSnapshot` with the read data.
1782 */
1783 get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
1784 /**
1785 * Writes to the document referred to by the provided {@link
1786 * DocumentReference}. If the document does not exist yet, it will be created.
1787 *
1788 * @param documentRef - A reference to the document to be set.
1789 * @param data - An object of the fields and values for the document.
1790 * @throws Error - If the provided input is not a valid Firestore document.
1791 * @returns This `Transaction` instance. Used for chaining method calls.
1792 */
1793 set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): this;
1794 /**
1795 * Writes to the document referred to by the provided {@link
1796 * DocumentReference}. If the document does not exist yet, it will be created.
1797 * If you provide `merge` or `mergeFields`, the provided data can be merged
1798 * into an existing document.
1799 *
1800 * @param documentRef - A reference to the document to be set.
1801 * @param data - An object of the fields and values for the document.
1802 * @param options - An object to configure the set behavior.
1803 * @throws Error - If the provided input is not a valid Firestore document.
1804 * @returns This `Transaction` instance. Used for chaining method calls.
1805 */
1806 set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): this;
1807 /**
1808 * Updates fields in the document referred to by the provided {@link
1809 * DocumentReference}. The update will fail if applied to a document that does
1810 * not exist.
1811 *
1812 * @param documentRef - A reference to the document to be updated.
1813 * @param data - An object containing the fields and values with which to
1814update the document. Fields can contain dots to reference nested fields
1815within the document.
1816 * @throws Error - If the provided input is not valid Firestore data.
1817 * @returns This `Transaction` instance. Used for chaining method calls.
1818 */
1819 update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): this;
1820 /**
1821 * Updates fields in the document referred to by the provided {@link
1822 * DocumentReference}. The update will fail if applied to a document that does
1823 * not exist.
1824 *
1825 * Nested fields can be updated by providing dot-separated field path
1826 * strings or by providing `FieldPath` objects.
1827 *
1828 * @param documentRef - A reference to the document to be updated.
1829 * @param field - The first field to update.
1830 * @param value - The first value.
1831 * @param moreFieldsAndValues - Additional key/value pairs.
1832 * @throws Error - If the provided input is not valid Firestore data.
1833 * @returns This `Transaction` instance. Used for chaining method calls.
1834 */
1835 update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
1836 /**
1837 * Deletes the document referred to by the provided {@link DocumentReference}.
1838 *
1839 * @param documentRef - A reference to the document to be deleted.
1840 * @returns This `Transaction` instance. Used for chaining method calls.
1841 */
1842 delete(documentRef: DocumentReference<unknown>): this;
1843}
1844/**
1845 * @license
1846 * Copyright 2022 Google LLC
1847 *
1848 * Licensed under the Apache License, Version 2.0 (the "License");
1849 * you may not use this file except in compliance with the License.
1850 * You may obtain a copy of the License at
1851 *
1852 * http://www.apache.org/licenses/LICENSE-2.0
1853 *
1854 * Unless required by applicable law or agreed to in writing, software
1855 * distributed under the License is distributed on an "AS IS" BASIS,
1856 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1857 * See the License for the specific language governing permissions and
1858 * limitations under the License.
1859 */
1860/**
1861 * Options to customize transaction behavior.
1862 */
1863export declare interface TransactionOptions {
1864 /** Maximum number of attempts to commit, after which transaction fails. Default is 5. */
1865 readonly maxAttempts?: number;
1866}
1867/**
1868 * Given a union type `U = T1 | T2 | ...`, returns an intersected type
1869 * `(T1 & T2 & ...)`.
1870 *
1871 * Uses distributive conditional types and inference from conditional types.
1872 * This works because multiple candidates for the same type variable in
1873 * contra-variant positions causes an intersection type to be inferred.
1874 * https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types
1875 * https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
1876 */
1877export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
1878/**
1879 * A function returned by `onSnapshot()` that removes the listener when invoked.
1880 */
1881export declare interface Unsubscribe {
1882 /** Removes the listener when invoked. */
1883 (): void;
1884}
1885/**
1886 * Update data (for use with {@link (updateDoc:1)}) that consists of field paths
1887 * (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
1888 * reference nested fields within the document. FieldValues can be passed in
1889 * as property values.
1890 */
1891export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
1892 [K in keyof T]?: UpdateData<T[K]> | FieldValue;
1893} & NestedUpdateFields<T> : Partial<T>;
1894/**
1895 * Updates fields in the document referred to by the specified
1896 * `DocumentReference`. The update will fail if applied to a document that does
1897 * not exist.
1898 *
1899 * @param reference - A reference to the document to update.
1900 * @param data - An object containing the fields and values with which to
1901 * update the document. Fields can contain dots to reference nested fields
1902 * within the document.
1903 * @returns A `Promise` resolved once the data has been successfully written
1904 * to the backend (note that it won't resolve while you're offline).
1905 */
1906export declare function updateDoc<T>(reference: DocumentReference<T>, data: UpdateData<T>): Promise<void>;
1907/**
1908 * Updates fields in the document referred to by the specified
1909 * `DocumentReference` The update will fail if applied to a document that does
1910 * not exist.
1911 *
1912 * Nested fields can be updated by providing dot-separated field path
1913 * strings or by providing `FieldPath` objects.
1914 *
1915 * @param reference - A reference to the document to update.
1916 * @param field - The first field to update.
1917 * @param value - The first value.
1918 * @param moreFieldsAndValues - Additional key value pairs.
1919 * @returns A `Promise` resolved once the data has been successfully written
1920 * to the backend (note that it won't resolve while you're offline).
1921 */
1922export declare function updateDoc(reference: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;
1923/**
1924 * Waits until all currently pending writes for the active user have been
1925 * acknowledged by the backend.
1926 *
1927 * The returned promise resolves immediately if there are no outstanding writes.
1928 * Otherwise, the promise waits for all previously issued writes (including
1929 * those written in a previous app session), but it does not wait for writes
1930 * that were added after the function is called. If you want to wait for
1931 * additional writes, call `waitForPendingWrites()` again.
1932 *
1933 * Any outstanding `waitForPendingWrites()` promises are rejected during user
1934 * changes.
1935 *
1936 * @returns A `Promise` which resolves when all currently pending writes have been
1937 * acknowledged by the backend.
1938 */
1939export declare function waitForPendingWrites(firestore: Firestore): Promise<void>;
1940/**
1941 * Creates a {@link QueryConstraint} that enforces that documents must contain the
1942 * specified field and that the value should satisfy the relation constraint
1943 * provided.
1944 *
1945 * @param fieldPath - The path to compare
1946 * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
1947 * "&lt;=", "!=").
1948 * @param value - The value for comparison
1949 * @returns The created {@link Query}.
1950 */
1951export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryConstraint;
1952/**
1953 * Filter conditions in a {@link where} clause are specified using the
1954 * strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in',
1955 * 'array-contains-any', and 'not-in'.
1956 */
1957export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
1958/**
1959 * Allows FieldValues to be passed in as a property value while maintaining
1960 * type safety.
1961 */
1962export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
1963 [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
1964} : never);
1965/**
1966 * A write batch, used to perform multiple writes as a single atomic unit.
1967 *
1968 * A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
1969 * provides methods for adding writes to the write batch. None of the writes
1970 * will be committed (or visible locally) until {@link WriteBatch.commit} is
1971 * called.
1972 */
1973export declare class WriteBatch {
1974 private constructor();
1975 /**
1976 * Writes to the document referred to by the provided {@link
1977 * DocumentReference}. If the document does not exist yet, it will be created.
1978 *
1979 * @param documentRef - A reference to the document to be set.
1980 * @param data - An object of the fields and values for the document.
1981 * @returns This `WriteBatch` instance. Used for chaining method calls.
1982 */
1983 set<T>(documentRef: DocumentReference<T>, data: WithFieldValue<T>): WriteBatch;
1984 /**
1985 * Writes to the document referred to by the provided {@link
1986 * DocumentReference}. If the document does not exist yet, it will be created.
1987 * If you provide `merge` or `mergeFields`, the provided data can be merged
1988 * into an existing document.
1989 *
1990 * @param documentRef - A reference to the document to be set.
1991 * @param data - An object of the fields and values for the document.
1992 * @param options - An object to configure the set behavior.
1993 * @throws Error - If the provided input is not a valid Firestore document.
1994 * @returns This `WriteBatch` instance. Used for chaining method calls.
1995 */
1996 set<T>(documentRef: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): WriteBatch;
1997 /**
1998 * Updates fields in the document referred to by the provided {@link
1999 * DocumentReference}. The update will fail if applied to a document that does
2000 * not exist.
2001 *
2002 * @param documentRef - A reference to the document to be updated.
2003 * @param data - An object containing the fields and values with which to
2004 * update the document. Fields can contain dots to reference nested fields
2005 * within the document.
2006 * @throws Error - If the provided input is not valid Firestore data.
2007 * @returns This `WriteBatch` instance. Used for chaining method calls.
2008 */
2009 update<T>(documentRef: DocumentReference<T>, data: UpdateData<T>): WriteBatch;
2010 /**
2011 * Updates fields in the document referred to by this {@link
2012 * DocumentReference}. The update will fail if applied to a document that does
2013 * not exist.
2014 *
2015 * Nested fields can be update by providing dot-separated field path strings
2016 * or by providing `FieldPath` objects.
2017 *
2018 * @param documentRef - A reference to the document to be updated.
2019 * @param field - The first field to update.
2020 * @param value - The first value.
2021 * @param moreFieldsAndValues - Additional key value pairs.
2022 * @throws Error - If the provided input is not valid Firestore data.
2023 * @returns This `WriteBatch` instance. Used for chaining method calls.
2024 */
2025 update(documentRef: DocumentReference<unknown>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch;
2026 /**
2027 * Deletes the document referred to by the provided {@link DocumentReference}.
2028 *
2029 * @param documentRef - A reference to the document to be deleted.
2030 * @returns This `WriteBatch` instance. Used for chaining method calls.
2031 */
2032 delete(documentRef: DocumentReference<unknown>): WriteBatch;
2033 /**
2034 * Commits all of the writes in this write batch as a single atomic unit.
2035 *
2036 * The result of these writes will only be reflected in document reads that
2037 * occur after the returned promise resolves. If the client is offline, the
2038 * write fails. If you would like to see local modifications or buffer writes
2039 * until the client is online, use the full Firestore SDK.
2040 *
2041 * @returns A `Promise` resolved once all of the writes in the batch have been
2042 * successfully written to the backend as an atomic unit (note that it won't
2043 * resolve while you're offline).
2044 */
2045 commit(): Promise<void>;
2046}
2047/**
2048 * Creates a write batch, used for performing multiple writes as a single
2049 * atomic operation. The maximum number of writes allowed in a single {@link WriteBatch}
2050 * is 500.
2051 *
2052 * Unlike transactions, write batches are persisted offline and therefore are
2053 * preferable when you don't need to condition your writes on read data.
2054 *
2055 * @returns A {@link WriteBatch} that can be used to atomically execute multiple
2056 * writes.
2057 */
2058export declare function writeBatch(firestore: Firestore): WriteBatch;
2059export {};