export type UnknownFirestore = GenericFirestore; export type CollectionReference = GenericCollectionReference; export type DocumentReference = GenericDocumentReference; export type DocumentData = GenericDocumentData; export type QuerySnapshot = GenericQuerySnapshot; export type QueryDocumentSnapshot = GenericQueryDocumentSnapshot; export type DocumentSnapshot = GenericDocumentSnapshot; export type Query = GenericQuery; export type QueryConstraint = GenericQueryConstraint; export type QueryConstraintType = GenericQueryConstraintType; export type QueryFieldFilterConstraint = GenericQueryFieldFilterConstraint; export type QueryLike = GenericQueryLike; export interface GenericFirestore> { collection(path: string, ...pathSegments: string[]): GenericCollectionReference; doc(path: string, ...pathSegments: string[]): GenericDocumentReference; getDocs(collectionReference: GenericQueryLike): Promise>; getDoc(documentReference: GenericDocumentReference): Promise>; addDoc(collectionReference: GenericCollectionReference, data: GenericDocumentData): Promise>; setDoc(documentReference: GenericDocumentReference, data: GenericDocumentData): Promise; deleteDoc(documentReference: GenericDocumentReference): Promise; query(query: GenericQueryLike, ...queryConstraints: GenericQueryConstraint[]): GenericQueryLike; onSnapshotQuery(query: GenericQuery, options: SnapshotListenOptions, onNext: ((snapshot: GenericQuerySnapshot) => void) | undefined, onError: ((error: Error) => void) | undefined, onCompletion: (() => void) | undefined): UnsubscribeFirestore; onSnapshot(documentReference: GenericDocumentReference, options: SnapshotListenOptions, onNext: ((snapshot: GenericDocumentSnapshot) => void) | undefined, onError: ((error: Error) => void) | undefined, onCompletion: (() => void) | undefined): UnsubscribeFirestore; } export declare abstract class GenericCollectionReference> implements GenericQueryLike { abstract get database(): DB; abstract get handle(): unknown; readonly type: "collection"; abstract get id(): string; abstract get path(): string; abstract get parent(): GenericDocumentReference | null; } export interface GenericDocumentReference> { get id(): string; get path(): string; get parent(): GenericCollectionReference; get firestore(): GenericFirestore; } export interface GenericDocumentData { /** A mapping between a field and its value. */ [field: string]: unknown; } export declare abstract class GenericQuerySnapshot> { abstract get docs(): Array>; /** The number of documents in the `QuerySnapshot`. */ abstract get size(): number; /** True if there are no documents in the `QuerySnapshot`. */ abstract get empty(): boolean; forEach(callback: (result: GenericQueryDocumentSnapshot) => void, thisArg?: unknown): void; } export interface GenericQueryDocumentSnapshot> extends GenericDocumentSnapshot { data(): GenericDocumentData; } export declare abstract class GenericDocumentSnapshot> { /** * Returns whether or not the data exists. True if the document exists. */ abstract exists(): this is GenericQueryDocumentSnapshot; /** * Retrieves all fields in the document as an `Object`. Returns `undefined` if * the document doesn't exist. * * By default, `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. */ abstract data(): GenericDocumentData | undefined; /** * Retrieves the field specified by `fieldPath`. Returns `undefined` if the * document or field doesn't exist. * * By default, a `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. */ abstract get(fieldPath: string): unknown; /** * Property of the `DocumentSnapshot` that provides the document's ID. */ abstract get id(): string; /** * The `DocumentReference` for the document included in the `DocumentSnapshot`. */ abstract get ref(): GenericDocumentReference; } export interface GenericQueryLike> { get database(): DB; get handle(): unknown; readonly type: "query" | "collection"; } export declare abstract class GenericQuery> implements GenericQueryLike { readonly type = "query"; abstract get handle(): unknown; abstract get database(): DB; abstract where(fieldPath: string, opStr: WhereFilterOp, value: unknown): GenericQuery; abstract orderBy(fieldPath: string, directionStr?: OrderByDirection): GenericQuery; abstract limit(limit: number): GenericQuery; } export interface GenericQueryConstraint { readonly type: GenericQueryConstraintType; apply>(query: GenericQuery): GenericQuery; } export declare class GenericQueryFieldFilterConstraint implements GenericQueryConstraint { /** The type of this query constraint */ readonly type = "where"; private readonly fieldPath; private readonly opStr; private readonly value; constructor(fieldPath: string, opStr: WhereFilterOp, value: unknown); apply>(query: GenericQuery): GenericQuery; } export declare class GenericQueryOrderByConstraint implements GenericQueryConstraint { /** The type of this query constraint */ readonly type = "orderBy"; private readonly fieldPath; private readonly directionStr?; constructor(fieldPath: string, directionStr?: OrderByDirection); apply>(query: GenericQuery): GenericQuery; } export declare class GenericQueryLimitConstraint implements GenericQueryConstraint { /** The type of this query constraint */ readonly type = "limit"; private readonly limit; constructor(limit: number); apply>(query: GenericQuery): GenericQuery; } export type OrderByDirection = "desc" | "asc"; export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-contains" | "in" | "array-contains-any" | "not-in"; export type GenericQueryConstraintType = "where" | "orderBy" | "limit" | "limitToLast" | "startAt" | "startAfter" | "endAt" | "endBefore"; /** * An options object that can be passed to {@link (onSnapshot:1)} and {@link * QuerySnapshot.docChanges} to control which types of changes to include in the * result set. */ export interface SnapshotListenOptions { /** * Include a change even if only the metadata of the query or of a document * changed. Default is false. */ readonly includeMetadataChanges?: boolean; } /** * A function returned by `onSnapshot()` that removes the listener when invoked. */ export interface UnsubscribeFirestore { /** Removes the listener when invoked. */ (): void; } export declare function collection>(firestore: GenericFirestore, path: string, ...pathSegments: string[]): GenericCollectionReference; export declare function doc>(firestore: GenericFirestore, path: string, ...pathSegments: string[]): GenericDocumentReference; export declare function getDocs>(query: GenericQueryLike): Promise>; export declare function getDoc>(documentReference: GenericDocumentReference): Promise>; export declare function addDoc>(collectionReference: GenericCollectionReference, data: GenericDocumentData): Promise>; export declare function deleteDoc>(documentReference: GenericDocumentReference): Promise; export declare function setDoc>(documentReference: GenericDocumentReference, data: GenericDocumentData): Promise; export declare function query>(query: GenericQueryLike, ...queryConstraints: GenericQueryConstraint[]): GenericQueryLike; export declare function where(fieldPath: string, opStr: WhereFilterOp, value: unknown): GenericQueryConstraint; export declare function orderBy(fieldPath: string, directionStr?: OrderByDirection): GenericQueryConstraint; export declare function limit(limit: number): GenericQueryConstraint; /** * 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>(reference: GenericDocumentReference, options: SnapshotListenOptions | undefined, observer: { next?: (snapshot: GenericDocumentSnapshot) => void; error?: (error: Error) => void; complete?: () => void; }): UnsubscribeFirestore; /** * 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 onSnapshotQuery>(query: GenericQuery, options: SnapshotListenOptions, onNext: (snapshot: GenericQuerySnapshot) => void, onError?: (error: Error) => void, onCompletion?: () => void): UnsubscribeFirestore; //# sourceMappingURL=firestore.d.ts.map