import type { google } from '@gcf/firestore-protos'; import { InternalTransaction, WriteMode } from '../../data-accessor.js'; import { GapicContext } from '../gapic-context.js'; /** * Minimal subset of transaction selector fields accepted by * {@link TransactionHelper.resolve}. Mirrors GAPIC request shapes. */ export interface ResolveTransactionShape { /** Optional read-only/read-write options to begin a new transaction. */ newTransaction?: google.firestore.v1.ITransactionOptions | null | undefined; /** Optional existing transaction id (GAPIC bytes). */ transaction?: Uint8Array | null | undefined; } /** * Helper that adapts GAPIC transaction requests to the mock's internal * transaction API and provides convenience methods for begin/commit/batchRead. * * Behavior notes: * - `resolve()` will either fetch an existing transaction (when `transaction` * is provided) or request that a new transaction be created (when * `newTransaction` is provided). If neither is provided, it returns `undefined` * (no transaction). * - `commit()` uses an existing transaction when the request provides one, * otherwise a new transaction is started implicitly for the commit. * - `batchRead()` ensures a point-in-time `readTime` and includes it in all * responses; when a transaction is present, it is echoed back and read locks * are registered as appropriate. */ export declare class TransactionHelper { readonly context: GapicContext; /** * @param context GAPIC context exposing accessors, serializer, and path utils. */ constructor(context: GapicContext); /** * Resolves a transaction from a request selector. * * - If `resolver.newTransaction` is present, returns a newly started * {@link InternalTransaction} configured with the converted options. * - If `resolver.transaction` is present, returns the fetched * {@link InternalTransaction} for that id. * - If neither is present or `resolver` is undefined, returns `undefined`. * * @param resolver The request's transaction selector. * @returns The resolved transaction or `undefined`. */ resolve(resolver: ResolveTransactionShape | undefined): InternalTransaction | undefined; /** * Fetches an existing transaction by its GAPIC id (bytes). * * @param transactionId GAPIC transaction id as a byte array. * @returns The fetched {@link InternalTransaction}. */ fetch(transactionId: Uint8Array): InternalTransaction; /** * Begins a new transaction with optional read-only / read-write options. * * The options are converted to internal shape; invalid combinations are * deferred to the transaction manager for validation and error surfacing. * * @param options GAPIC transaction options or `null`/`undefined`. * @returns GAPIC {@link google.firestore.v1.IBeginTransactionResponse} * containing the new transaction id (bytes). */ begin(options: google.firestore.v1.ITransactionOptions | null | undefined): google.firestore.v1.IBeginTransactionResponse; /** * Commits a set of writes, optionally under an existing transaction. * * - If `request.transaction` is present, it is asserted and fetched. * - Otherwise a new transaction is implicitly begun for the commit. * - Each incoming GAPIC write is normalized via {@link transformWrites} * (e.g., preconditions, transforms) before being passed to the internal commit. * - Returned `writeResults[i]` carry the per-write commit time; when transform * results were produced, they are included in `transformResults`. * * @param mode Write mode (e.g., transactional vs non-transactional). * @param request GAPIC commit request containing writes and optional transaction id. * @returns GAPIC {@link google.firestore.v1.ICommitResponse} with `commitTime` * and per-write `writeResults`. * @throws {GoogleError} {Status.INVALID_ARGUMENT} when `transaction` is present but invalid * (surfaced by {@link assertRequestArgument} or downstream fetch/validation). */ commit(mode: WriteMode, request: google.firestore.v1.ICommitRequest): google.firestore.v1.ICommitResponse; /** * Batch-reads a set of documents at a consistent read time, optionally under * a transaction. For each requested document path, emits a corresponding * GAPIC {@link google.firestore.v1.IBatchGetDocumentsResponse} item: * * - If the document exists at `readTime`, `found` is populated with a * serialized document. * - Otherwise `missing` is set to the requested path. * - `readTime` is included in every item. * - When a transaction is used, its id (bytes) is echoed back and the read * is registered on the transaction to support conflict detection. * * @param request GAPIC batch-get request with `documents` and optional * transaction/readTime selectors. * @returns Array of GAPIC batch-get responses aligned with `documents` order. */ batchRead(request: google.firestore.v1.IBatchGetDocumentsRequest): google.firestore.v1.IBatchGetDocumentsResponse[]; /** * Converts an internal transaction id to its GAPIC byte-array form. * * @param tx Internal transaction. * @returns GAPIC transaction id as Uint8Array. */ toGapicId(tx: InternalTransaction): Uint8Array; } //# sourceMappingURL=transaction-helper.d.ts.map