import { type FirestoreDocument, type SingleItemFirestoreCollectionDocumentIdentifierRef } from './accessor/document'; import { type FirestoreCollection, type FirestoreCollectionConfig, type FirestoreCollectionWithParent, type SingleItemFirestoreCollection, type FirestoreCollectionGroup, type RootSingleItemFirestoreCollection } from './collection'; import { type FirestoreContextCacheFactoryRef, type FirestoreContextCacheRef } from './cache/cache'; import { type FirestoreDrivers } from './driver/driver'; import { type WriteBatchFactoryReference, type RunTransactionFactoryReference } from './driver'; import { type DocumentReference, type CollectionReference, type DocumentData, type Firestore, type CollectionGroup } from './types'; import { type QueryLikeReferenceRef } from './reference'; /** * A high-level context for Firestore operations that wraps the Firestore instance and its drivers. * * This context provides a unified interface for working with Firestore, offering convenience methods * for accessing collections, creating documents, and managing transactions and batches. It serves as * the main entry point for Firestore operations throughout the application. * * The context abstracts away the low-level Firestore implementation details, offering type-safe * methods for creating various collection types (standard, group, with parent, single-item) and * managing document operations within different execution contexts (standard, transaction, batch). * * @template F - The Firestore implementation type (defaults to standard Firestore) */ export interface FirestoreContext extends RunTransactionFactoryReference, WriteBatchFactoryReference, FirestoreContextCacheRef { /** * The underlying Firestore instance. */ readonly firestore: F; /** * The Firestore drivers used by this context. * Contains implementations for queries, accessories, and other Firestore operations. */ readonly drivers: FirestoreDrivers; /** * Gets a reference to a collection at the specified path. * * @template T - The document data type in the collection * @param path - The initial path segment * @param pathSegments - Additional path segments * @returns A reference to the specified collection */ collection(path: string, ...pathSegments: string[]): CollectionReference; /** * Gets a query for all documents in collections with the specified ID. * * @template T - The document data type in the collection group * @param collectionId - The collection ID to query across all document paths * @returns A query across all collections with the given ID */ collectionGroup(collectionId: string): CollectionGroup; /** * Gets a reference to a subcollection within a document. * * @template T - The document data type in the subcollection * @param parent - The parent document reference * @param path - The initial path segment * @param pathSegments - Additional path segments * @returns A reference to the specified subcollection */ subcollection(parent: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference; /** * Creates a FirestoreCollection for working with documents in a collection. * * @template T - The document data type * @template D - The FirestoreDocument implementation type * @param config - Configuration for the collection * @returns A FirestoreCollection instance for the specified collection */ firestoreCollection>(config: FirestoreContextFirestoreCollectionConfig): FirestoreCollection; /** * Creates a RootSingleItemFirestoreCollection for working with a single document in a collection. * * @template T - The document data type * @template D - The FirestoreDocument implementation type * @param config - Configuration for the collection * @returns A RootSingleItemFirestoreCollection instance */ rootSingleItemFirestoreCollection>(config: FirestoreContextFirestoreCollectionConfig): RootSingleItemFirestoreCollection; /** * Creates a FirestoreCollectionGroup for working with documents across collections with the same ID. * * @template T - The document data type * @template D - The FirestoreDocument implementation type * @param config - Configuration for the collection group * @returns A FirestoreCollectionGroup instance for the specified collection ID */ firestoreCollectionGroup>(config: FirestoreContextFirestoreCollectionGroupConfig): FirestoreCollectionGroup; /** * Creates a FirestoreCollectionWithParent for working with documents in a subcollection. * * @template T - The document data type * @template PT - The parent document data type * @template D - The FirestoreDocument implementation type * @template PD - The parent FirestoreDocument implementation type * @param config - Configuration for the collection with parent * @returns A FirestoreCollectionWithParent instance for the specified subcollection */ firestoreCollectionWithParent = FirestoreDocument, PD extends FirestoreDocument = FirestoreDocument>(config: FirestoreContextFirestoreCollectionWithParentConfig): FirestoreCollectionWithParent; /** * Creates a SingleItemFirestoreCollection for working with a single document in a subcollection. * * @template T - The document data type * @template PT - The parent document data type * @template D - The FirestoreDocument implementation type * @template PD - The parent FirestoreDocument implementation type * @param config - Configuration for the single-item collection * @returns A SingleItemFirestoreCollection instance for the specified document */ singleItemFirestoreCollection = FirestoreDocument, PD extends FirestoreDocument = FirestoreDocument>(config: FirestoreContextSingleItemFirestoreCollectionConfig): SingleItemFirestoreCollection; } /** * Configuration for creating a FirestoreCollection through a FirestoreContext. * * This type omits driver-related properties from FirestoreCollectionConfig since they will be * automatically provided by the FirestoreContext when creating the collection. * * @template T - The document data type in the collection * @template D - The FirestoreDocument implementation type */ export type FirestoreContextFirestoreCollectionConfig> = Omit, 'firestoreDriverIdentifier' | 'firestoreDriverType' | 'firestoreQueryDriver' | 'firestoreAccessorDriver' | 'cache'>; /** * Configuration for creating a RootSingleItemFirestoreCollection through a FirestoreContext. * * This configuration extends the standard collection config and optionally allows specifying * a custom document identifier for the single item in the collection. * * @template T - The document data type * @template D - The FirestoreDocument implementation type */ export interface FirestoreContextRootSingleItemFirestoreCollectionConfig = FirestoreDocument> extends FirestoreContextFirestoreCollectionConfig, Partial { } /** * Configuration for creating a FirestoreCollectionGroup through a FirestoreContext. * * Unlike standard collection configurations, collection group configs use a queryLike reference * instead of a collection reference since they span multiple collections with the same ID. * * @template T - The document data type in the collection group * @template D - The FirestoreDocument implementation type */ export type FirestoreContextFirestoreCollectionGroupConfig> = Omit, 'collection'> & QueryLikeReferenceRef; /** * Configuration for creating a FirestoreCollectionWithParent through a FirestoreContext. * * This configuration extends the standard collection config but uses a parent document reference * instead of a direct collection reference, enabling access to subcollections within documents. * * @template T - The document data type in the subcollection * @template PT - The parent document data type * @template D - The FirestoreDocument implementation type for subcollection documents * @template PD - The FirestoreDocument implementation type for the parent document */ export interface FirestoreContextFirestoreCollectionWithParentConfig = FirestoreDocument, PD extends FirestoreDocument = FirestoreDocument> extends Omit, 'queryLike'> { /** * The parent document that contains the subcollection. */ readonly parent: PD; } /** * Configuration for creating a SingleItemFirestoreCollection through a FirestoreContext. * * This configuration extends the collection with parent config and optionally allows specifying * a custom document identifier for the single item in the subcollection. * * @template T - The document data type in the subcollection * @template PT - The parent document data type * @template D - The FirestoreDocument implementation type for subcollection documents * @template PD - The FirestoreDocument implementation type for the parent document */ export interface FirestoreContextSingleItemFirestoreCollectionConfig = FirestoreDocument, PD extends FirestoreDocument = FirestoreDocument> extends FirestoreContextFirestoreCollectionWithParentConfig, Partial { } /** * Optional parameters for {@link FirestoreContextFactory} that configure context-level * features like caching. These are separate from the platform drivers because they * are app-level concerns, not platform-level concerns. * * @example * ```ts * const params: FirestoreContextFactoryParams = { * firestoreContextCacheFactory: inMemoryFirestoreContextCacheFactory() * }; * const context = contextFactory(firestore, params); * ``` */ export interface FirestoreContextFactoryParams extends FirestoreContextCacheFactoryRef { } /** * Factory function type for creating FirestoreContext instances. * * Takes a Firestore instance and optional params, and returns a fully configured * FirestoreContext. The params allow app-level configuration (e.g. caching) to be * provided at the DI injection site rather than at driver creation time. * * @template F - The Firestore implementation type * @param firestore - The Firestore instance to wrap * @param params - Optional context-level configuration (e.g. cache factory) * @returns A FirestoreContext instance for the specified Firestore */ export type FirestoreContextFactory = (firestore: F, params?: FirestoreContextFactoryParams) => FirestoreContext; /** * Creates a factory function for generating FirestoreContext instances. * * This function takes a set of FirestoreDrivers and returns a factory function that can * create FirestoreContext instances for specific Firestore instances. The resulting contexts * will use the provided drivers for all Firestore operations. * * @template F - The Firestore implementation type * @param drivers - The Firestore drivers to use in created contexts * @returns A factory function that creates FirestoreContext instances */ export declare function firestoreContextFactory(drivers: FirestoreDrivers): FirestoreContextFactory;