import type { EntityName, EntityMetadata } from '../typings.js'; import type { EntityManager } from '../EntityManager.js'; import type { UnitOfWork } from '../unit-of-work/UnitOfWork.js'; import type { ChangeSet } from '../unit-of-work/ChangeSet.js'; import type { Transaction } from '../connections/Connection.js'; /** Arguments passed to entity lifecycle event hooks. */ export interface EventArgs { entity: T; em: EntityManager; meta: EntityMetadata; changeSet?: ChangeSet; } /** Arguments passed to flush lifecycle event hooks (beforeFlush, onFlush, afterFlush). */ export interface FlushEventArgs extends Omit, 'entity' | 'changeSet' | 'meta'> { uow: UnitOfWork; } /** Arguments passed to transaction lifecycle event hooks (start, commit, rollback). */ export interface TransactionEventArgs extends Omit, 'entity' | 'meta' | 'changeSet'> { transaction?: Transaction & { savepointName?: string; }; uow?: UnitOfWork; } /** Interface for subscribing to entity and transaction lifecycle events. */ export interface EventSubscriber { getSubscribedEntities?(): EntityName[]; onInit?(args: EventArgs): void; onLoad?(args: EventArgs): void | Promise; beforeCreate?(args: EventArgs): void | Promise; afterCreate?(args: EventArgs): void | Promise; beforeUpdate?(args: EventArgs): void | Promise; afterUpdate?(args: EventArgs): void | Promise; beforeUpsert?(args: EventArgs): void | Promise; afterUpsert?(args: EventArgs): void | Promise; beforeDelete?(args: EventArgs): void | Promise; afterDelete?(args: EventArgs): void | Promise; beforeFlush?(args: FlushEventArgs): void | Promise; onFlush?(args: FlushEventArgs): void | Promise; afterFlush?(args: FlushEventArgs): void | Promise; beforeTransactionStart?(args: TransactionEventArgs): void | Promise; afterTransactionStart?(args: TransactionEventArgs): void | Promise; beforeTransactionCommit?(args: TransactionEventArgs): void | Promise; afterTransactionCommit?(args: TransactionEventArgs): void | Promise; beforeTransactionRollback?(args: TransactionEventArgs): void | Promise; afterTransactionRollback?(args: TransactionEventArgs): void | Promise; }