import { google } from '@gcf/firestore-protos'; import { Firestore } from 'firebase-admin/firestore'; import { DataAccessor, MetaDocument } from '../data-accessor.js'; import { DatabasePool } from '../database-pool.js'; import { Serializer } from '../firestore/serializer.js'; /** * Context helper for GAPIC-shaped operations backed by the in-memory DataAccessor. * * @remarks * - Resolves `projectId` / `databaseId` from the Admin SDK `Firestore` instance * (falling back to {@link DEFAULT_PROJECT_ID} / {@link DEFAULT_DATABASE_ID}). * - Provides path conversion between Admin SDK internal paths (e.g. `users/u1`) * and GAPIC resource names (e.g. `projects/{p}/databases/{d}/documents/users/u1`). * - Surfaces a {@link Serializer} consistent with the Admin SDK to produce * wire-compatible `google.firestore.v1.Document` payloads. */ export declare class GapicContext { private readonly _pool; /** Project ID used for resource names. */ readonly projectId: string; /** Database ID (usually `'(default)'`). */ readonly databaseId: string; /** Admin SDK serializer used for encode/decode of Firestore values. */ readonly serializer: Serializer; /** GAPIC resource root: `projects/{project}/databases/{database}/documents`. */ readonly gapicRoot: string; /** * Creates a GAPIC context bound to a Firestore instance and a database pool. * * @param firestore - The Admin SDK `Firestore` whose settings define project/database. * @param _pool - Backing {@link DatabasePool} from which `DataAccessor` instances are resolved. * * @throws {GoogleError} If the `projectId` is invalid (via {@link assertValidProjectId}). */ constructor(firestore: Firestore, _pool: DatabasePool); /** * Returns whether a `DataAccessor` exists for the bound project/database. */ hasAccessor(): boolean; /** * Retrieves the {@link DataAccessor} for the bound project/database. * * @returns The accessor associated with this context. * @throws {Error} If no accessor exists for the pair (asserted by the pool). */ getAccessor(): DataAccessor; /** * Converts an Admin-style internal path to a GAPIC resource name. * * @param internalPath - Path like `''` (root), `users/u1`, or `users/u1/posts/p1`. * @returns A GAPIC resource: either `gapicRoot` for `''`, or `gapicRoot/{internalPath}`. * @throws {GoogleError} If `internalPath` fails validation. * * @remarks * Validation is performed by {@link validateInternalPath}. */ toGapicPath(internalPath: string): string; /** * Builds a collection path by appending a collection ID to a parent path. * * @param parentPath - Parent internal path (document or root). * @param id - Collection ID to append. * @returns The combined **internal** collection path. */ collectionPath(parentPath: string, id: string): string; /** * Converts a GAPIC resource name to an Admin-style internal path with type checking. * * @param gapicPath - Full resource path starting with {@link gapicRoot}. * @param guard - Expected path kind for the returned internal path (`'collection' | 'document'`). * @returns The internal path with the root prefix stripped. * * @throws {GoogleError} * - `INVALID_ARGUMENT` if `gapicPath` is missing, has a mismatched prefix, fails validation, * or does not match the `guard` (except that `'root'` is allowed when `guard === 'document'`). * * @remarks * Uses {@link pathType} to enforce the requested guard. */ toInternalPath(gapicPath: string | null | undefined, guard: 'collection' | 'document'): string; /** * Serializes a meta-document to a `google.firestore.v1.Document`, optionally applying a field mask. * * @param doc - The source {@link MetaDocument}. * @param fieldMask - Optional list of field paths to include (Admin SDK semantics). * @returns A `google.firestore.v1.IDocument` with `name`, `fields`, `createTime`, and `updateTime`. * * @remarks * - `name` is built via {@link toGapicPath}. * - `fields` are encoded using the Admin SDK {@link Serializer}; when `fieldMask` is provided, * encoding is filtered by {@link applyFieldMask}. * - `createTime` / `updateTime` are sourced from the meta and converted via `ToProto#toProto()`. */ serializeDoc(doc: MetaDocument, fieldMask?: string[]): google.firestore.v1.IDocument; } //# sourceMappingURL=gapic-context.d.ts.map