import { DocumentData } from 'firebase-admin/firestore'; import { DataAccessor, DatabaseStats, DocumentQuery, MergeGranularity, MetaDocument, MetaDocumentExists, NormalizedWriteResult, Trigger } from './_internal/data-accessor.js'; import { StructuralDatabase } from './structural-database.js'; /** * A convenience shape for bulk `set` operations that pairs a document * path with its strongly-typed data. * * @template T - Firestore document data type. */ export interface DatabaseDocument { /** Canonical document path, e.g. `"col/doc/sub/doc2"`. */ path: string; /** The document data to write. */ data: T; } /** * Thin, synchronous façade over the internal {@link DataAccessor} that * exposes ergonomic helpers for tests and tools that interact with the * in-memory database directly (bypassing Admin SDK objects). * * Notes: * - All write operations are executed atomically (single commit) and * use {@link WriteMode.Atomic}. * - Trigger registration/dispatch is delegated to the underlying {@link DataAccessor}. * - Methods returning `MetaDocument` / `MetaDocumentExists` include metadata such as * update times and existence state to aid fidelity testing. */ export declare class DatabaseDirect { private _accessor; /** * Create a direct database adapter bound to an existing {@link DataAccessor}. * * @param accessor - The backing in-memory data accessor. */ constructor(accessor: DataAccessor); /** * Register a low-level trigger callback that will be invoked for document * changes produced by atomic commits. Automatically unregistered whenever `reset()` * is called. * * @param trigger - Trigger descriptor. * @returns A function that unregisters the trigger when called. */ registerTrigger(trigger: Trigger): () => void; /** * Retrieve aggregate database statistics (document count, bytes, etc.). * * @returns Current {@link DatabaseStats}. */ stats(): DatabaseStats; /** * Remove all user documents from the database, preserving indexes and * internal structures. */ clear(): void; /** * Reset the database to a pristine state, clearing documents, triggers, and internal * state (timestamps, counters, version) as defined by the accessor. */ reset(): void; /** * Snapshot all **existing** documents as an ordered array of document paths. * * @remarks * The ordering matches the meta snapshot returned by {@link toMetaArray}, * with each entry mapped to its `path` property. * * @returns Array of Firestore document paths (for example, * `"users/alice"` or `"users/alice/settings/profile"`). */ toDocumentPaths(): string[]; /** * Snapshot all **existing** documents as an ordered array of meta records. * * @returns Array of {@link MetaDocumentExists}. */ toMetaArray(): MetaDocumentExists[]; /** * Snapshot all **existing** documents keyed by document path. * * @returns Map of path ⇒ {@link MetaDocumentExists}. */ toMetaMap(): Record; /** * Snapshot all **existing** documents as plain data keyed by document path. * * @returns Map of path ⇒ {@link DocumentData}. */ toMap(): Record; /** * Produce a structural view of the database suitable for serialization * or coarse-grained merges. * * @returns A {@link StructuralDatabase} snapshot. */ toStructuralDatabase(): StructuralDatabase; /** * Import/merge a {@link StructuralDatabase} into this database. * * @param src - Source structural snapshot. * @param merge - Merge granularity; defaults to `'root'`. * @returns A normalized result describing applied writes. */ fromStructuralDatabase(src: StructuralDatabase, merge?: MergeGranularity): NormalizedWriteResult; /** * List direct child collection IDs of a document. * * @param documentPath - Parent document path. * @returns Array of collection IDs (no paths). */ listCollectionIds(documentPath: string): string[]; /** * List documents within a collection. * * @param collectionPath - Collection path. * @param showMissing - If `true`, include placeholders for missing * documents (non-existent meta entries). * @returns Array of {@link MetaDocument} (existing or missing). */ listDocuments(collectionPath: string, showMissing: boolean): MetaDocument[]; /** * Execute an in-memory query over existing documents. * * @template T - Result document data type. * @param q - A normalized {@link DocumentQuery}. * @returns Array of existing meta documents that match the query. */ query(q: DocumentQuery): MetaDocumentExists[]; /** * Get a single document by path, returning an existing or missing meta * record. * * @template T - Document data type. * @param documentPath - Canonical document path. * @returns {@link MetaDocument} describing existence and data. */ getDocument(documentPath: string): MetaDocument; /** * Set (create or replace) a single document at the given path. * Equivalent to a normalized `'set'` with `merge: 'root'`. * * @template T - Document data type. * @param documentPath - Document path. * @param data - Document payload to write. * @returns The resulting {@link MetaDocument}. */ setDocument(documentPath: string, data: T): MetaDocument; /** * Atomically set multiple documents. Each item is written as a `'set'` * with `merge: 'root'`. * * @template T - Document data type. * @param documents - One or more `{ path, data }` tuples. * @returns Resulting {@link MetaDocument} array, in the same order. */ batchSet(...documents: DatabaseDocument[]): MetaDocument[]; /** * Atomically delete multiple documents. * * @template T - Document data type (for return shape only). * @param paths - One or more document paths to delete. * @returns Resulting {@link MetaDocument} array, in the same order. */ batchDelete(...paths: string[]): MetaDocument[]; /** * Atomically apply a heterogeneous set of writes where each entry is either: * - a `{ path, data }` object → normalized to a `'set'` with `merge: 'root'`, or * - a `string` path → normalized to a `'delete'`. * * @template T - Document data type (for return shape only). * @param writes - `(DatabaseDocument | string)[]` describing mixed writes. * @returns Resulting {@link MetaDocument} array, in the same order. */ batchWrite(writes: (DatabaseDocument | string)[]): MetaDocument[]; /** * Delete a single document by path. * * @template T - Document data type (for return shape only). * @param documentPath - Document path to delete. * @returns The resulting {@link MetaDocument}. */ deleteDocument(documentPath: string): MetaDocument; /** * Helper to execute a single normalized write as an atomic batch and * return its sole {@link MetaDocument} result. * * @template T - Document data type. * @param op - A normalized write operation. * @returns The resulting {@link MetaDocument}. * @internal */ private singleWriteOp; } //# sourceMappingURL=database-direct.d.ts.map