UNPKG

fireodm

Version:

A basic and extensible ODM for the Firestore Admin SDK in Node.js with decorators, relationships, and validation.

36 lines 2.14 kB
import { Transaction as FirestoreTransaction, ReadOnlyTransactionOptions, ReadWriteTransactionOptions, WriteBatch, WriteResult } from "firebase-admin/firestore"; /** * Runs a Firestore transaction with implicit ORM context management. * ORM methods (save, update, delete) called within the callback will automatically use the transaction. * * @template T The return type of the transaction callback. * @param callback The function to execute within the transaction. It receives the Firestore Transaction object. * All reads should occur before writes. * @param transactionOptions Optional Firestore transaction options. * @returns A Promise resolving with the value returned by the callback. * @throws Throws an error if the transaction fails or if the callback throws an error. */ export declare function runInTransaction<T>(callback: (transaction: FirestoreTransaction) => Promise<T>, transactionOptions?: ReadWriteTransactionOptions | ReadOnlyTransactionOptions): Promise<T>; /** * Result structure for runInBatch operation. */ export interface BatchResult<T> { /** The results from Firestore after committing the batch. */ commitResults: WriteResult[]; /** The value returned by the user's callback function. */ callbackResult: T; } /** * Executes a series of ORM operations within a Firestore Batched Write. * ORM methods (save, update, delete) called within the callback will automatically be added to the batch. * The batch is committed automatically after the callback completes successfully. * * @template T The return type of the batch callback function. * @param callback The function to execute. It receives the Firestore WriteBatch object. * This function queues ORM operations using `save`, `update`, `delete`. * It can be sync or async. * @returns A Promise resolving with an object containing the commit results and the callback's return value. * @throws Throws an error if the callback throws or if the batch commit fails. */ export declare function runInBatch<T>(callback: (batch: WriteBatch) => Promise<T> | T): Promise<BatchResult<T>>; //# sourceMappingURL=transaction-manager.d.ts.map