import type { BaseFirestoreDocument } from './document.js'; import { type CollectionReference, type DocumentChange, type DocumentReference, type Query, type QueryDocumentSnapshot, type QuerySnapshot, type Transaction } from 'firebase-admin/firestore'; import { FirestoreDocument } from './document.js'; import { type Condition } from './query.js'; import { type FirestoreData, type FirestoreKey } from './types.js'; import { AsyncQueue } from '../shared/async-queue.js'; export declare class FirestoreCollection = FirestoreDocument> { get static(): typeof FirestoreCollection; /** * Path template for building collection paths (e.g., "users/{userId}/posts") * Override in subclasses to define the collection path structure */ static pathTemplate: string; /** * Database ID to use for this collection class * Override in subclasses to use a specific database (default: '') */ static databaseId: string; /** * Document class constructor for creating document instances * Override in subclasses to define the document type */ static documentClass: typeof BaseFirestoreDocument; /** * Collection key used to identify this collection */ get key(): CollectionKey | undefined; set key(key: Readonly | undefined); /** * Query condition for filtering documents */ get condition(): Readonly | undefined; set condition(condition: Readonly | undefined); /** * Map of loaded documents keyed by document ID */ get documents(): Map; /** * Converts the documents map to an array * @returns Array of all documents in this collection */ toArray(): Document[]; /** * Returns an iterator for the documents in this collection * Enables for...of iteration * @returns Iterator of documents */ [Symbol.iterator](): Iterator; protected _ctor: { new (key?: Key | string | DocumentReference, data?: Data | QueryDocumentSnapshot | null, exists?: boolean): Document; readonly defaultData: FirestoreData; readonly defaultKey?: FirestoreKey | string[]; }; protected _key?: CollectionKey | string[]; protected _condition: Condition | undefined; protected _documents: Map; protected _snapshotQueues: AsyncQueue[]; protected _cachedDocuments?: Document[]; protected _unwatch?: () => void; protected _snapshotGenerator?: AsyncGenerator; reference?: CollectionReference; protected query?: Query; isLoaded: boolean; /** * Initializes query from reference and condition */ protected initializeQuery(): void; constructor(keyOrCondition?: CollectionKey | string[] | string | Condition, condition?: Condition); /** * Initializes collection with reference and query * @param reference - Collection reference * @param query - Optional query */ initialize(reference?: CollectionReference, query?: Query): void; /** * Applies query snapshot documents to the collection * @param docs - Query document snapshots */ protected applyDocs(docs: QueryDocumentSnapshot[]): void; /** * Applies document changes from snapshot listener * @param docChanges - Document changes */ protected applyDocChanges(docChanges: DocumentChange[]): void; /** * Prepares collection for snapshot * Override in subclasses to add custom preparation logic * @param cache - Whether to use cached data * @returns true if ready, false otherwise */ protected prepare(_cache?: boolean): Promise; /** * Gets documents from Firestore * @param cache - If true and already loaded, skip loading * @returns Array of documents */ get(cache?: boolean): Promise; /** * Saves all documents in the collection * @param transaction - Optional transaction to use */ save(transaction?: Transaction): Promise; /** * Returns the first document in the collection * @returns First document or undefined if empty */ first(): Document | undefined; /** * Finds a document by ID from the loaded documents (cache only) * @param id - Document ID * @returns Document or undefined if not found */ find(id: string): Document | undefined; /** * Sets a document with a specific ID * @param id - Document ID * @param data - Document data * @param transaction - Optional transaction to use * @returns Created document or undefined if no reference */ set(id: string, data: Data, transaction?: Transaction): Promise; /** * Generates a new document ID * Override in subclasses to customize ID generation (e.g., use timeId) * @param _data - Document data (unused in default implementation) * @returns Generated document ID */ protected generateNewId(_data: Data): string; /** * Adds a new document with auto-generated ID * @param data - Document data (uses defaultData if not provided) * @param transaction - Optional transaction to use * @returns Created document or undefined if no reference */ add(data?: Data, transaction?: Transaction): Promise; /** * Deletes a document by ID * @param id - Document ID * @param transaction - Optional transaction to use */ delete(id: string, transaction?: Transaction): Promise; /** * Gets all documents as an array, loading if necessary * @param force - If true, reload even if already loaded * @returns Array of all documents */ docs(force?: boolean): Promise; /** * Gets an async generator for real-time document updates * Returns the same generator instance on subsequent calls * @yields Array of documents on each change */ get snapshot(): AsyncGenerator; /** * Watches collection for real-time updates * @param callback - Called on each snapshot update * @throws {FirestoreDocumentError} If watch is already active */ watch(callback: (snapshot?: QuerySnapshot) => void): void; /** * Cancels all active snapshot listeners */ unwatch(): void; /** * Sets the collection key from a Key object, string array, or path string * @param keyOrPath - Collection key object, string array, or path string */ protected setKey(keyOrPath: CollectionKey | string[] | string): void; /** * Sets the collection reference and extracts the key from its path * @param ref - Firestore collection reference */ protected setReference(ref: CollectionReference): void; } //# sourceMappingURL=collection.d.ts.map