import type { EntityQueryContextProvider } from './EntityQueryContextProvider.ts'; export type PostCommitCallback = (...args: any) => Promise; export type PreCommitCallback = (queryContext: EntityTransactionalQueryContext, ...args: any) => Promise; /** * Database transaction isolation level. Controls the visibility of changes made by * concurrent transactions, trading off between consistency and performance. */ export declare enum TransactionIsolationLevel { /** * Each statement sees only data committed before it began. Default for most databases. */ READ_COMMITTED = "READ_COMMITTED", /** * All statements in the transaction see the same snapshot taken at the start of the transaction. */ REPEATABLE_READ = "REPEATABLE_READ", /** * Transactions execute as if they were run one at a time. Strongest guarantee but lowest throughput. */ SERIALIZABLE = "SERIALIZABLE" } /** * Controls DataLoader behavior within a transaction. */ export declare enum TransactionalDataLoaderMode { /** * Default mode where DataLoader is fully enabled, providing both batching and caching benefits within the transaction. */ ENABLED = "ENABLED", /** * DataLoader is enabled for batching queries together but does not cache results. Use this mode when you want to benefit from batching but need to ensure that each load reflects the most current database state, even within the same transaction. */ ENABLED_BATCH_ONLY = "ENABLED_BATCH_ONLY", /** * DataLoader is completely disabled for the transaction. Each load will directly query the database without any batching or caching. Use this mode when you need to ensure that every load reflects the most current database state and are not concerned about the performance benefits of batching or caching within the transaction. */ DISABLED = "DISABLED" } /** * Configuration options for running a transaction. This includes the isolation level and DataLoader mode for the transaction. */ export type TransactionConfig = { /** * Transaction isolation level. When omitted, the database default is used (typically READ_COMMITTED). */ isolationLevel?: TransactionIsolationLevel; /** * DataLoader mode for the transaction. When omitted, defaults to ENABLED. */ transactionalDataLoaderMode?: TransactionalDataLoaderMode; }; /** * Resolved transaction configuration with all default values filled in. * This is the configuration that is actually used for a transaction after applying defaults. */ export type ResolvedTransactionConfig = Pick & Required>; /** * Entity framework representation of transactional and non-transactional database * query execution units. * * The behavior of EntityMutator and EntityLoader * differs when in a transactional context. */ export declare abstract class EntityQueryContext { private readonly queryInterface; constructor(queryInterface: any); abstract isInTransaction(): this is EntityTransactionalQueryContext; getQueryInterface(): any; abstract runInTransactionIfNotInTransactionAsync(transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise, transactionConfig?: TransactionConfig): Promise; } /** * Entity framework representation of a non-transactional query execution unit. * When supplied to EntityMutator and EntityLoader methods, they will be * run independently of any running transaction (though mutations start their own * independent transactions internally when not being run in a transaction). */ export declare class EntityNonTransactionalQueryContext extends EntityQueryContext { private readonly entityQueryContextProvider; constructor(queryInterface: any, entityQueryContextProvider: EntityQueryContextProvider); isInTransaction(): this is EntityTransactionalQueryContext; runInTransactionIfNotInTransactionAsync(transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise, transactionConfig?: TransactionConfig): Promise; } /** * Entity framework representation of a transactional query execution unit. When supplied * to EntityMutator and EntityLoader methods, those methods and their * dependent triggers and validators will run within the transaction. */ export declare class EntityTransactionalQueryContext extends EntityQueryContext { private readonly entityQueryContextProvider; /** * @internal */ readonly transactionId: string; readonly transactionConfig: ResolvedTransactionConfig; /** * @internal */ readonly childQueryContexts: EntityNestedTransactionalQueryContext[]; private readonly postCommitInvalidationCallbacks; private readonly postCommitCallbacks; private readonly preCommitCallbacks; private readonly transactionEndCallbacks; constructor(queryInterface: any, entityQueryContextProvider: EntityQueryContextProvider, /** * @internal */ transactionId: string, transactionConfig: ResolvedTransactionConfig); /** * DataLoader mode for this transaction set at time of transaction creation, controlling DataLoader caching and batching behavior within the transaction. */ get transactionalDataLoaderMode(): TransactionalDataLoaderMode; /** * Transaction isolation level for this transaction set at time of transaction creation. * This controls the visibility of changes made by concurrent transactions. * When undefined, the database default isolation level is used (typically READ_COMMITTED). */ get isolationLevel(): TransactionIsolationLevel | undefined; /** * Schedule a pre-commit callback. These will be run within the transaction right before it is * committed, and will be run in the order specified. Ordering of callbacks scheduled with the * same value for the order parameter is undefined within that ordering group. * @param callback - callback to schedule * @param order - order in which this should be run relative to other scheduled pre-commit callbacks, * with higher numbers running later than lower numbers. */ appendPreCommitCallback(callback: PreCommitCallback, order: number): void; /** * Schedule a post-commit cache invalidation callback. These are run before normal * post-commit callbacks in order to have cache consistency in normal post-commit callbacks. * @param callback - callback to schedule */ appendPostCommitInvalidationCallback(callback: PostCommitCallback): void; /** * Schedule a post-commit callback. These will be run after the transaction has * been committed. * @param callback - callback to schedule */ appendPostCommitCallback(callback: PostCommitCallback): void; /** * Schedule a callback to run when the transaction ends, regardless of whether it commits or rolls back. * When the transaction is successful, these run after post-commit callbacks. When the transaction rolls back, * these run after the rollback is complete. Use for resource cleanup tied to the transaction's * lifetime (e.g. dropping per-transaction in-memory state). * @param callback - synchronous cleanup callback to schedule * * @internal */ appendTransactionEndCallback(callback: () => void): void; /** * @internal */ runTransactionEndCallbacks(): void; /** * @internal */ runPreCommitCallbacksAsync(): Promise; /** * @internal */ runPostCommitCallbacksAsync(): Promise; isInTransaction(): this is EntityTransactionalQueryContext; isInNestedTransaction(): this is EntityNestedTransactionalQueryContext; runInTransactionIfNotInTransactionAsync(transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise, transactionConfig?: TransactionConfig): Promise; runInNestedTransactionAsync(transactionScope: (innerQueryContext: EntityTransactionalQueryContext) => Promise): Promise; } /** * Entity framework representation of a nested transactional query execution unit. When supplied * to EntityMutator and EntityLoader methods, those methods and their * dependent triggers and validators will run within the nested transaction. * * This exists to forward post-commit callbacks to the parent query context but only after * successful commit of the nested transaction. */ export declare class EntityNestedTransactionalQueryContext extends EntityTransactionalQueryContext { /** * @internal */ readonly parentQueryContext: EntityTransactionalQueryContext; private readonly postCommitInvalidationCallbacksToTransfer; private readonly postCommitCallbacksToTransfer; constructor(queryInterface: any, /** * @internal */ parentQueryContext: EntityTransactionalQueryContext, entityQueryContextProvider: EntityQueryContextProvider, transactionId: string, transactionConfig: ResolvedTransactionConfig); isInNestedTransaction(): this is EntityNestedTransactionalQueryContext; appendPostCommitCallback(callback: PostCommitCallback): void; appendPostCommitInvalidationCallback(callback: PostCommitCallback): void; /** * The behavior of callbacks for nested transactions are a bit different than for normal * transactions. * - Post-commit (non-invalidation) callbacks are run at the end of the outermost transaction * since they often contain side-effects that only should run if the transaction doesn't roll back. * The outermost transaction has the final say on the commit state of itself and all sub-transactions. * - Invalidation callbacks are run at the end of both the nested transaction iteself but also transferred * to the parent transaction to be run at the end of it (and recurse upwards, accumulating invalations). * This is to ensure the dataloader cache is never stale no matter the DBMS transaction isolation * semantics. See the note in `AuthorizationResultBasedBaseMutator` for more details. * * @internal */ runPostCommitCallbacksAsync(): Promise; }