UNPKG

@firebase/firestore

Version:

The Cloud Firestore component of the Firebase JS SDK.

1,121 lines (1,120 loc) • 87.4 kB
/** * Cloud Firestore * * @packageDocumentation */ import { FirebaseApp } from '@firebase/app-exp'; import { LogLevelString as LogLevel } from '@firebase/logger'; import { EmulatorMockTokenOptions } from '@firebase/util'; /** * Add a new document to specified `CollectionReference` with the given data, * assigning it a document ID automatically. * * @param reference - A reference to the collection to add this document to. * @param data - An Object containing the data for the new document. * @returns A Promise resolved with a `DocumentReference` pointing to the * newly created document after it has been written to the backend (Note that it * won't resolve while you're offline). */ export declare function addDoc<T>(reference: CollectionReference<T>, data: T): Promise<DocumentReference<T>>; /** * Returns a special value that can be used with {@link (setDoc:1)} or {@link * updateDoc:1} that tells the server to remove the given elements from any * array value that already exists on the server. All instances of each element * specified will be removed from the array. If the field being modified is not * already an array it will be overwritten with an empty array. * * @param elements - The elements to remove from the array. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or * `updateDoc()` */ export declare function arrayRemove(...elements: unknown[]): FieldValue; /** * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array * value that already exists on the server. Each specified element that doesn't * already exist in the array will be added to the end. If the field being * modified is not already an array it will be overwritten with an array * containing exactly the specified elements. * * @param elements - The elements to union into the array. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or * `updateDoc()`. */ export declare function arrayUnion(...elements: unknown[]): FieldValue; /** * An immutable object representing an array of bytes. */ export declare class Bytes { private constructor(); /** * Creates a new `Bytes` object from the given Base64 string, converting it to * bytes. * * @param base64 - The Base64 string used to create the `Bytes` object. */ static fromBase64String(base64: string): Bytes; /** * Creates a new `Bytes` object from the given Uint8Array. * * @param array - The Uint8Array used to create the `Bytes` object. */ static fromUint8Array(array: Uint8Array): Bytes; /** * Returns the underlying bytes as a Base64-encoded string. * * @returns The Base64-encoded string created from the `Bytes` object. */ toBase64(): string; /** * Returns the underlying bytes in a new `Uint8Array`. * * @returns The Uint8Array created from the `Bytes` object. */ toUint8Array(): Uint8Array; /** * Returns a string representation of the `Bytes` object. * * @returns A string representation of the `Bytes` object. */ toString(): string; /** * Returns true if this `Bytes` object is equal to the provided one. * * @param other - The `Bytes` object to compare against. * @returns true if this `Bytes` object is equal to the provided one. */ isEqual(other: Bytes): boolean; } /** * Constant used to indicate the LRU garbage collection should be disabled. * Set this value as the `cacheSizeBytes` on the settings passed to the * `Firestore` instance. */ export declare const CACHE_SIZE_UNLIMITED = -1; /** * Clears the persistent storage. This includes pending writes and cached * documents. * * Must be called while the `Firestore` instance is not started (after the app is * terminated or when the app is first initialized). On startup, this function * must be called before other functions (other than {@link * initializeFirestore} or {@link getFirestore})). If the `Firestore` * instance is still running, the promise will be rejected with the error code * of `failed-precondition`. * * Note: `clearIndexedDbPersistence()` is primarily intended to help write * reliable tests that use Cloud Firestore. It uses an efficient mechanism for * dropping existing data but does not attempt to securely overwrite or * otherwise make cached data unrecoverable. For applications that are sensitive * to the disclosure of cached data in between user sessions, we strongly * recommend not enabling persistence at all. * * @param firestore - The `Firestore` instance to clear persistence for. * @returns A promise that is resolved when the persistent storage is * cleared. Otherwise, the promise is rejected with an error. */ export declare function clearIndexedDbPersistence(firestore: FirebaseFirestore): Promise<void>; /** * Gets a `CollectionReference` instance that refers to the collection at * the specified absolute path. * * @param firestore - A reference to the root Firestore instance. * @param path - A slash-separated path to a collection. * @param pathSegments - Additional path segments to apply relative to the first * argument. * @throws If the final path has an even number of segments and does not point * to a collection. * @returns The `CollectionReference` instance. */ export declare function collection(firestore: FirebaseFirestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>; /** * Gets a `CollectionReference` instance that refers to a subcollection of * `reference` at the the specified relative path. * * @param reference - A reference to a collection. * @param path - A slash-separated path to a collection. * @param pathSegments - Additional path segments to apply relative to the first * argument. * @throws If the final path has an even number of segments and does not point * to a collection. * @returns The `CollectionReference` instance. */ export declare function collection(reference: CollectionReference<unknown>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>; /** * Gets a `CollectionReference` instance that refers to a subcollection of * `reference` at the the specified relative path. * * @param reference - A reference to a Firestore document. * @param path - A slash-separated path to a collection. * @param pathSegments - Additional path segments that will be applied relative * to the first argument. * @throws If the final path has an even number of segments and does not point * to a collection. * @returns The `CollectionReference` instance. */ export declare function collection(reference: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>; /** * Creates and returns a new `Query` instance that includes all documents in the * database that are contained in a collection or subcollection with the * given `collectionId`. * * @param firestore - A reference to the root Firestore instance. * @param collectionId - Identifies the collections to query over. Every * collection or subcollection with this ID as the last segment of its path * will be included. Cannot contain a slash. * @returns The created `Query`. */ export declare function collectionGroup(firestore: FirebaseFirestore, collectionId: string): Query<DocumentData>; /** * A `CollectionReference` object can be used for adding documents, getting * document references, and querying for documents (using {@link query}). */ export declare class CollectionReference<T = DocumentData> extends Query<T> { /** The type of this Firestore reference. */ readonly type = "collection"; private constructor(); /** The collection's identifier. */ get id(): string; /** * A string representing the path of the referenced collection (relative * to the root of the database). */ get path(): string; /** * A reference to the containing `DocumentReference` if this is a * subcollection. If this isn't a subcollection, the reference is null. */ get parent(): DocumentReference<DocumentData> | null; /** * Applies a custom data converter to this CollectionReference, allowing you * to use your own custom model objects with Firestore. When you call {@link * addDoc} with the returned `CollectionReference` instance, the provided * converter will convert between Firestore data and your custom type `U`. * * @param converter - Converts objects to and from Firestore. * @returns A `CollectionReference<U>` that uses the provided converter. */ withConverter<U>(converter: FirestoreDataConverter<U>): CollectionReference<U>; /** * Removes the current converter. * * @param converter - `null` removes the current converter. * @returns A `CollectionReference<DocumentData>` that does not use a * converter. */ withConverter(converter: null): CollectionReference<DocumentData>; } /** * Deletes the document referred to by the specified `DocumentReference`. * * @param reference - A reference to the document to delete. * @returns A Promise resolved once the document has been successfully * deleted from the backend (note that it won't resolve while you're offline). */ export declare function deleteDoc(reference: DocumentReference<unknown>): Promise<void>; /** * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion. */ export declare function deleteField(): FieldValue; /** * Disables network usage for this instance. It can be re-enabled via {@link * enableNetwork}. While the network is disabled, any snapshot listeners, * `getDoc()` or `getDocs()` calls will return results from cache, and any write * operations will be queued until the network is restored. * * @returns A promise that is resolved once the network has been disabled. */ export declare function disableNetwork(firestore: FirebaseFirestore): Promise<void>; /** * Gets a `DocumentReference` instance that refers to the document at the * specified abosulute path. * * @param firestore - A reference to the root Firestore instance. * @param path - A slash-separated path to a document. * @param pathSegments - Additional path segments that will be applied relative * to the first argument. * @throws If the final path has an odd number of segments and does not point to * a document. * @returns The `DocumentReference` instance. */ export declare function doc(firestore: FirebaseFirestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>; /** * Gets a `DocumentReference` instance that refers to a document within * `reference` at the specified relative path. If no path is specified, an * automatically-generated unique ID will be used for the returned * `DocumentReference`. * * @param reference - A reference to a collection. * @param path - A slash-separated path to a document. Has to be omitted to use * auto-genrated IDs. * @param pathSegments - Additional path segments that will be applied relative * to the first argument. * @throws If the final path has an odd number of segments and does not point to * a document. * @returns The `DocumentReference` instance. */ export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>; /** * Gets a `DocumentReference` instance that refers to a document within * `reference` at the specified relative path. * * @param reference - A reference to a Firestore document. * @param path - A slash-separated path to a document. * @param pathSegments - Additional path segments that will be applied relative * to the first argument. * @throws If the final path has an odd number of segments and does not point to * a document. * @returns The `DocumentReference` instance. */ export declare function doc(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>; /** * A `DocumentChange` represents a change to the documents matching a query. * It contains the document affected and the type of change that occurred. */ export declare interface DocumentChange<T = DocumentData> { /** The type of change ('added', 'modified', or 'removed'). */ readonly type: DocumentChangeType; /** The document affected by this change. */ readonly doc: QueryDocumentSnapshot<T>; /** * The index of the changed document in the result set immediately prior to * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects * have been applied). Is `-1` for 'added' events. */ readonly oldIndex: number; /** * The index of the changed document in the result set immediately after * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` * objects and the current `DocumentChange` object have been applied). * Is -1 for 'removed' events. */ readonly newIndex: number; } /** * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'. */ export declare type DocumentChangeType = 'added' | 'removed' | 'modified'; /** * Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to * values. */ export declare interface DocumentData { /** A mapping between a field and its value. */ [field: string]: any; } /** * Returns a special sentinel `FieldPath` to refer to the ID of a document. * It can be used in queries to sort or filter by the document ID. */ export declare function documentId(): FieldPath; /** * A `DocumentReference` refers to a document location in a Firestore database * and can be used to write, read, or listen to the location. The document at * the referenced location may or may not exist. */ export declare class DocumentReference<T = DocumentData> { /** * If provided, the `FirestoreDataConverter` associated with this instance. */ readonly converter: FirestoreDataConverter<T> | null; /** The type of this Firestore reference. */ readonly type = "document"; /** * The {@link FirebaseFirestore} the document is in. * This is useful for performing transactions, for example. */ readonly firestore: FirebaseFirestore; private constructor(); /** * The document's identifier within its collection. */ get id(): string; /** * A string representing the path of the referenced document (relative * to the root of the database). */ get path(): string; /** * The collection this `DocumentReference` belongs to. */ get parent(): CollectionReference<T>; /** * Applies a custom data converter to this `DocumentReference`, allowing you * to use your own custom model objects with Firestore. When you call {@link * @firebase/firestore/lite#(setDoc:1)}, {@link @firebase/firestore/lite#getDoc}, etc. with the returned `DocumentReference` * instance, the provided converter will convert between Firestore data and * your custom type `U`. * * @param converter - Converts objects to and from Firestore. * @returns A `DocumentReference<U>` that uses the provided converter. */ withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>; /** * Removes the current converter. * * @param converter - `null` removes the current converter. * @returns A `DocumentReference<DocumentData>` that does not use a converter. */ withConverter(converter: null): DocumentReference<DocumentData>; } /** * A `DocumentSnapshot` contains data read from a document in your Firestore * database. The data can be extracted with `.data()` or `.get(<field>)` to * get a specific field. * * For a `DocumentSnapshot` that points to a non-existing document, any data * access will return 'undefined'. You can use the `exists()` method to * explicitly verify a document's existence. */ export declare class DocumentSnapshot<T = DocumentData> { /** * Metadata about the `DocumentSnapshot`, including information about its * source and local modifications. */ readonly metadata: SnapshotMetadata; protected constructor(); /** * Property of the `DocumentSnapshot` that signals whether or not the data * exists. True if the document exists. */ exists(): this is QueryDocumentSnapshot<T>; /** * Retrieves all fields in the document as an `Object`. Returns `undefined` if * the document doesn't exist. * * By default, `FieldValue.serverTimestamp()` values that have not yet been * set to their final value will be returned as `null`. You can override * this by passing an options object. * * @param options - An options object to configure how data is retrieved from * the snapshot (for example the desired behavior for server timestamps that * have not yet been set to their final value). * @returns An `Object` containing all fields in the document or `undefined` if * the document doesn't exist. */ data(options?: SnapshotOptions): T | undefined; /** * Retrieves the field specified by `fieldPath`. Returns `undefined` if the * document or field doesn't exist. * * By default, a `FieldValue.serverTimestamp()` that has not yet been set to * its final value will be returned as `null`. You can override this by * passing an options object. * * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific * field. * @param options - An options object to configure how the field is retrieved * from the snapshot (for example the desired behavior for server timestamps * that have not yet been set to their final value). * @returns The data at the specified field location or undefined if no such * field exists in the document. */ get(fieldPath: string | FieldPath, options?: SnapshotOptions): any; /** * Property of the `DocumentSnapshot` that provides the document's ID. */ get id(): string; /** * The `DocumentReference` for the document included in the `DocumentSnapshot`. */ get ref(): DocumentReference<T>; } /** * Attempts to enable persistent storage, if possible. * * Must be called before any other functions (other than * {@link initializeFirestore}, {@link getFirestore} or * {@link clearIndexedDbPersistence}. * * If this fails, `enableIndexedDbPersistence()` will reject the promise it * returns. Note that even after this failure, the `Firestore` instance will * remain usable, however offline persistence will be disabled. * * There are several reasons why this can fail, which can be identified by * the `code` on the error. * * * failed-precondition: The app is already open in another browser tab. * * unimplemented: The browser is incompatible with the offline * persistence implementation. * * @param firestore - The `Firestore` instance to enable persistence for. * @param persistenceSettings - Optional settings object to configure * persistence. * @returns A promise that represents successfully enabling persistent storage. */ export declare function enableIndexedDbPersistence(firestore: FirebaseFirestore, persistenceSettings?: PersistenceSettings): Promise<void>; /** * Attempts to enable multi-tab persistent storage, if possible. If enabled * across all tabs, all operations share access to local persistence, including * shared execution of queries and latency-compensated local document updates * across all connected instances. * * If this fails, `enableMultiTabIndexedDbPersistence()` will reject the promise * it returns. Note that even after this failure, the `Firestore` instance will * remain usable, however offline persistence will be disabled. * * There are several reasons why this can fail, which can be identified by * the `code` on the error. * * * failed-precondition: The app is already open in another browser tab and * multi-tab is not enabled. * * unimplemented: The browser is incompatible with the offline * persistence implementation. * * @param firestore - The `Firestore` instance to enable persistence for. * @returns A promise that represents successfully enabling persistent * storage. */ export declare function enableMultiTabIndexedDbPersistence(firestore: FirebaseFirestore): Promise<void>; /** * Re-enables use of the network for this Firestore instance after a prior * call to {@link disableNetwork}. * * @returns A promise that is resolved once the network has been enabled. */ export declare function enableNetwork(firestore: FirebaseFirestore): Promise<void>; /** * Creates a `QueryConstraint` that modifies the result set to end at the * provided document (inclusive). The end position is relative to the order of * the query. The document must contain all of the fields provided in the * orderBy of the query. * * @param snapshot - The snapshot of the document to end at. * @returns A `QueryConstraint` to pass to `query()` */ export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryConstraint; /** * Creates a `QueryConstraint` that modifies the result set to end at the * provided fields relative to the order of the query. The order of the field * values must match the order of the order by clauses of the query. * * @param fieldValues - The field values to end this query at, in order * of the query's order by. * @returns A `QueryConstraint` to pass to `query()` */ export declare function endAt(...fieldValues: unknown[]): QueryConstraint; /** * Creates a `QueryConstraint` that modifies the result set to end before the * provided document (exclusive). The end position is relative to the order of * the query. The document must contain all of the fields provided in the * orderBy of the query. * * @param snapshot - The snapshot of the document to end before. * @returns A `QueryConstraint` to pass to `query()` */ export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryConstraint; /** * Creates a `QueryConstraint` that modifies the result set to end before the * provided fields relative to the order of the query. The order of the field * values must match the order of the order by clauses of the query. * * @param fieldValues - The field values to end this query before, in order * of the query's order by. * @returns A `QueryConstraint` to pass to `query()` */ export declare function endBefore(...fieldValues: unknown[]): QueryConstraint; /** * A `FieldPath` refers to a field in a document. The path may consist of a * single field name (referring to a top-level field in the document), or a * list of field names (referring to a nested field in the document). * * Create a `FieldPath` by providing field names. If more than one field * name is provided, the path will point to a nested field in a document. */ export declare class FieldPath { /** * Creates a FieldPath from the provided field names. If more than one field * name is provided, the path will point to a nested field in a document. * * @param fieldNames - A list of field names. */ constructor(...fieldNames: string[]); /** * Returns true if this `FieldPath` is equal to the provided one. * * @param other - The `FieldPath` to compare against. * @returns true if this `FieldPath` is equal to the provided one. */ isEqual(other: FieldPath): boolean; } /** * Sentinel values that can be used when writing document fields with `set()` * or `update()`. */ export declare abstract class FieldValue { private constructor(); /** Compares `FieldValue`s for equality. */ abstract isEqual(other: FieldValue): boolean; } /** * The Cloud Firestore service interface. * * Do not call this constructor directly. Instead, use {@link getFirestore}. */ export declare class FirebaseFirestore { type: 'firestore-lite' | 'firestore'; private constructor(); /** * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service * instance. */ get app(): FirebaseApp; /** * Returns a JSON-serializable representation of this Firestore instance. */ toJSON(): object; } /** * Converter used by `withConverter()` to transform user objects of type `T` * into Firestore data. * * Using the converter allows you to specify generic type arguments when * storing and retrieving objects from Firestore. * * @example * ```typescript * class Post { * constructor(readonly title: string, readonly author: string) {} * * toString(): string { * return this.title + ', by ' + this.author; * } * } * * const postConverter = { * toFirestore(post: Post): firebase.firestore.DocumentData { * return {title: post.title, author: post.author}; * }, * fromFirestore( * snapshot: firebase.firestore.QueryDocumentSnapshot, * options: firebase.firestore.SnapshotOptions * ): Post { * const data = snapshot.data(options)!; * return new Post(data.title, data.author); * } * }; * * const postSnap = await firebase.firestore() * .collection('posts') * .withConverter(postConverter) * .doc().get(); * const post = postSnap.data(); * if (post !== undefined) { * post.title; // string * post.toString(); // Should be defined * post.someNonExistentProperty; // TS error * } * ``` */ export declare interface FirestoreDataConverter<T> { /** * Called by the Firestore SDK to convert a custom model object of type `T` * into a plain JavaScript object (suitable for writing directly to the * Firestore database). To use `set()` with `merge` and `mergeFields`, * `toFirestore()` must be defined with `Partial<T>`. */ toFirestore(modelObject: T): DocumentData; /** * Called by the Firestore SDK to convert a custom model object of type `T` * into a plain JavaScript object (suitable for writing directly to the * Firestore database). Used with {@link (setDoc:1)}, {@link (WriteBatch.set:1)} * and {@link (Transaction.set:1)} with `merge:true` or `mergeFields`. */ toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData; /** * Called by the Firestore SDK to convert Firestore data into an object of * type T. You can access your data by calling: `snapshot.data(options)`. * * @param snapshot - A `QueryDocumentSnapshot` containing your data and metadata. * @param options - The `SnapshotOptions` from the initial call to `data()`. */ fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>, options?: SnapshotOptions): T; } /** An error returned by a Firestore operation. */ export declare class FirestoreError extends Error { /** * The backend error code associated with this error. */ readonly code: FirestoreErrorCode; /** * A custom error description. */ readonly message: string; /** The custom name for all FirestoreErrors. */ readonly name: string; /** The stack of the error. */ readonly stack?: string; private constructor(); } /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * The set of Firestore status codes. The codes are the same at the ones * exposed by gRPC here: * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md * * Possible values: * - 'cancelled': The operation was cancelled (typically by the caller). * - 'unknown': Unknown error or an error from a different error domain. * - 'invalid-argument': Client specified an invalid argument. Note that this * differs from 'failed-precondition'. 'invalid-argument' indicates * arguments that are problematic regardless of the state of the system * (e.g. an invalid field name). * - 'deadline-exceeded': Deadline expired before operation could complete. * For operations that change the state of the system, this error may be * returned even if the operation has completed successfully. For example, * a successful response from a server could have been delayed long enough * for the deadline to expire. * - 'not-found': Some requested document was not found. * - 'already-exists': Some document that we attempted to create already * exists. * - 'permission-denied': The caller does not have permission to execute the * specified operation. * - 'resource-exhausted': Some resource has been exhausted, perhaps a * per-user quota, or perhaps the entire file system is out of space. * - 'failed-precondition': Operation was rejected because the system is not * in a state required for the operation's execution. * - 'aborted': The operation was aborted, typically due to a concurrency * issue like transaction aborts, etc. * - 'out-of-range': Operation was attempted past the valid range. * - 'unimplemented': Operation is not implemented or not supported/enabled. * - 'internal': Internal errors. Means some invariants expected by * underlying system has been broken. If you see one of these errors, * something is very broken. * - 'unavailable': The service is currently unavailable. This is most likely * a transient condition and may be corrected by retrying with a backoff. * - 'data-loss': Unrecoverable data loss or corruption. * - 'unauthenticated': The request does not have valid authentication * credentials for the operation. */ export 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'; /** * @license * Copyright 2017 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * An immutable object representing a geographic location in Firestore. The * location is represented as latitude/longitude pair. * * Latitude values are in the range of [-90, 90]. * Longitude values are in the range of [-180, 180]. */ export declare class GeoPoint { /** * Creates a new immutable `GeoPoint` object with the provided latitude and * longitude values. * @param latitude - The latitude as number between -90 and 90. * @param longitude - The longitude as number between -180 and 180. */ constructor(latitude: number, longitude: number); /** * The latitude of this `GeoPoint` instance. */ get latitude(): number; /** * The longitude of this `GeoPoint` instance. */ get longitude(): number; /** * Returns true if this `GeoPoint` is equal to the provided one. * * @param other - The `GeoPoint` to compare against. * @returns true if this `GeoPoint` is equal to the provided one. */ isEqual(other: GeoPoint): boolean; /** Returns a JSON-serializable representation of this GeoPoint. */ toJSON(): { latitude: number; longitude: number; }; } /** * Reads the document referred to by this `DocumentReference`. * * Note: `getDoc()` attempts to provide up-to-date data when possible by waiting * for data from the server, but it may return cached data or fail if you are * offline and the server cannot be reached. To specify this behavior, invoke * {@link getDocFromCache} or {@link getDocFromServer}. * * @param reference - The reference of the document to fetch. * @returns A Promise resolved with a `DocumentSnapshot` containing the * current document contents. */ export declare function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>; /** * Reads the document referred to by this `DocumentReference` from cache. * Returns an error if the document is not currently cached. * * @returns A Promise resolved with a `DocumentSnapshot` containing the * current document contents. */ export declare function getDocFromCache<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>; /** * Reads the document referred to by this `DocumentReference` from the server. * Returns an error if the network is not available. * * @returns A Promise resolved with a `DocumentSnapshot` containing the * current document contents. */ export declare function getDocFromServer<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>; /** * Executes the query and returns the results as a `QuerySnapshot`. * * Note: `getDocs()` attempts to provide up-to-date data when possible by * waiting for data from the server, but it may return cached data or fail if * you are offline and the server cannot be reached. To specify this behavior, * invoke {@link getDocsFromCache} or {@link getDocsFromServer}. * * @returns A Promise that will be resolved with the results of the query. */ export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>; /** * Executes the query and returns the results as a `QuerySnapshot` from cache. * Returns an error if the document is not currently cached. * * @returns A Promise that will be resolved with the results of the query. */ export declare function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>; /** * Executes the query and returns the results as a `QuerySnapshot` from the * server. Returns an error if the network is not available. * * @returns A Promise that will be resolved with the results of the query. */ export declare function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>>; /** * Returns the existing instance of Firestore that is associated with the * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new * instance with default settings. * * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned Firestore * instance is associated with. * @returns The `Firestore` instance of the provided app. */ export declare function getFirestore(app?: FirebaseApp): FirebaseFirestore; /** * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by * the given value. * * If either the operand or the current field value uses floating point * precision, all arithmetic follows IEEE 754 semantics. If both values are * integers, values outside of JavaScript's safe number range * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to * precision loss. Furthermore, once processed by the Firestore backend, all * integer operations are capped between -2^63 and 2^63-1. * * If the current field value is not of type `number`, or if the field does not * yet exist, the transformation sets the field to the given value. * * @param n - The value to increment by. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or * `updateDoc()` */ export declare function increment(n: number): FieldValue; /** * Initializes a new instance of Cloud Firestore with the provided settings. * Can only be called before any other function, including * {@link getFirestore}. If the custom settings are empty, this function is * equivalent to calling {@link getFirestore}. * * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will * be associated. * @param settings - A settings object to configure the `Firestore` instance. * @returns A newly initialized `Firestore` instance. */ export declare function initializeFirestore(app: FirebaseApp, settings: Settings): FirebaseFirestore; /** * Creates a `QueryConstraint` that only returns the first matching documents. * * @param limit - The maximum number of items to return. * @returns The created `Query`. */ export declare function limit(limit: number): QueryConstraint; /** * Creates a `QueryConstraint` that only returns the last matching documents. * * You must specify at least one `orderBy` clause for `limitToLast` queries, * otherwise an exception will be thrown during execution. * * @param limit - The maximum number of items to return. * @returns The created `Query`. */ export declare function limitToLast(limit: number): QueryConstraint; /** * Loads a Firestore bundle into the local cache. * * @param firestore - The `Firestore` instance to load bundles for for. * @param bundleData - An object representing the bundle to be loaded. Valid objects are * `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`. * * @returns * A `LoadBundleTask` object, which notifies callers with progress updates, and completion * or error events. It can be used as a `Promise<LoadBundleTaskProgress>`. */ export declare function loadBundle(firestore: FirebaseFirestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask; /** * Represents the task of loading a Firestore bundle. It provides progress of bundle * loading, as well as task completion and error events. * * The API is compatible with `Promise<LoadBundleTaskProgress>`. */ export declare class LoadBundleTask implements PromiseLike<LoadBundleTaskProgress> { /** * Registers functions to listen to bundle loading progress events. * @param next - Called when there is a progress update from bundle loading. Typically `next` calls occur * each time a Firestore document is loaded from the bundle. * @param error - Called when an error occurs during bundle loading. The task aborts after reporting the * error, and there should be no more updates after this. * @param complete - Called when the loading task is complete. */ onProgress(next?: (progress: LoadBundleTaskProgress) => unknown, error?: (err: Error) => unknown, complete?: () => void): void; /** * Implements the `Promise<LoadBundleTaskProgress>.catch` interface. * * @param onRejected - Called when an error occurs during bundle loading. */ catch<R>(onRejected: (a: Error) => R | PromiseLike<R>): Promise<R | LoadBundleTaskProgress>; /** * Implements the `Promise<LoadBundleTaskProgress>.then` interface. * * @param onFulfilled - Called on the completion of the loading task with a final `LoadBundleTaskProgress` update. * The update will always have its `taskState` set to `"Success"`. * @param onRejected - Called when an error occurs during bundle loading. */ then<T, R>(onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, onRejected?: (a: Error) => R | PromiseLike<R>): Promise<T | R>; } /** * Represents a progress update or a final state from loading bundles. */ export declare interface LoadBundleTaskProgress { /** How many documents have been loaded. */ documentsLoaded: number; /** How many documents are in the bundle being loaded. */ totalDocuments: number; /** How many bytes have been loaded. */ bytesLoaded: number; /** How many bytes are in the bundle being loaded. */ totalBytes: number; /** Current task state. */ taskState: TaskState; } export { LogLevel }; /** * Reads a Firestore `Query` from local cache, identified by the given name. * * The named queries are packaged into bundles on the server side (along * with resulting documents), and loaded to local cache using `loadBundle`. Once in local * cache, use this method to extract a `Query` by name. */ export declare function namedQuery(firestore: FirebaseFirestore, name: string): Promise<Query | null>; /** * Attaches a listener for `DocumentSnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param reference - A reference to the document to listen to. * @param observer - A single object containing `next` and `error` callbacks. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(reference: DocumentReference<T>, observer: { next?: (snapshot: DocumentSnapshot<T>) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; /** * Attaches a listener for `DocumentSnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param reference - A reference to the document to listen to. * @param options - Options controlling the listen behavior. * @param observer - A single object containing `next` and `error` callbacks. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, observer: { next?: (snapshot: DocumentSnapshot<T>) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; /** * Attaches a listener for `DocumentSnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param reference - A reference to the document to listen to. * @param onNext - A callback to be called every time a new `DocumentSnapshot` * is available. * @param onError - A callback to be called if the listen fails or is * cancelled. No further callbacks will occur. * @param onCompletion - Can be provided, but will not be called since streams are * never ending. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(reference: DocumentReference<T>, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; /** * Attaches a listener for `DocumentSnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param reference - A reference to the document to listen to. * @param options - Options controlling the listen behavior. * @param onNext - A callback to be called every time a new `DocumentSnapshot` * is available. * @param onError - A callback to be called if the listen fails or is * cancelled. No further callbacks will occur. * @param onCompletion - Can be provided, but will not be called since streams are * never ending. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(reference: DocumentReference<T>, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; /** * Attaches a listener for `QuerySnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param query - The query to listen to. * @param observer - A single object containing `next` and `error` callbacks. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(query: Query<T>, observer: { next?: (snapshot: QuerySnapshot<T>) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; /** * Attaches a listener for `QuerySnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param query - The query to listen to. * @param options - Options controlling the listen behavior. * @param observer - A single object containing `next` and `error` callbacks. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, observer: { next?: (snapshot: QuerySnapshot<T>) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; /** * Attaches a listener for `QuerySnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param query - The query to listen to. * @param onNext - A callback to be called every time a new `QuerySnapshot` * is available. * @param onCompletion - Can be provided, but will not be called since streams are * never ending. * @param onError - A callback to be called if the listen fails or is * cancelled. No further callbacks will occur. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(query: Query<T>, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; /** * Attaches a listener for `QuerySnapshot` events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param query - The query to listen to. * @param options - Options controlling the listen behavior. * @param onNext - A callback to be called every time a new `QuerySnapshot` * is available. * @param onCompletion - Can be provided, but will not be called since streams are * never ending. * @param onError - A callback to be called if the listen fails or is * cancelled. No further callbacks will occur. * @returns An unsubscribe function that can be called to cancel * the snapshot listener. */ export declare function onSnapshot<T>(query: Query<T>, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe; /** * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync * event indicates that all listeners affected by a given change have fired, * even if a single server-generated change affects multiple listeners. * * NOTE: The snapshots-in-sync event only indicates that listeners are in sync * with each other, but does not relate to whether those snapshots are in sync * with the server. Use SnapshotMetadata in the individual listeners to * determine if a snapshot is from the cache or the server. * * @param firestore - The instance of Firestore for synchronizing snapshots. * @param observer - A single object containing `next` and `error` callbacks. * @returns An unsubscribe function that can be called to cancel the snapshot * listener. */ export declare function onSnapshotsInSync(firestore: FirebaseFirestore, observer: { next?: (value: void) => void; error?: (error: FirestoreError) => void; complete?: () => void; }): Unsubscribe; /** * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync * event indicates that all listeners affected by a given change have fired, * even if a single server-generated change affects multiple listeners. * * NOTE: The snapshots-in