/** * Middleware-based hooks registry for ORM operations. * Unlike event-based hooks, middleware hooks run sequentially and can halt operations. */ /** Context object passed to before/after hook handlers. */ export interface HookContext { /** Model name (e.g. 'user', 'animal'). */ model: string; /** Operation name: 'create', 'update', 'delete', 'get', or 'list'. */ operation: string; /** The incoming HTTP request object. */ request?: unknown; /** URL route parameters (e.g. { id: '42' }). */ params?: Record; /** Parsed request body for create/update operations. */ body?: Record; /** URL query string parameters. */ query?: Record; /** Mutable state bag shared across hooks within a single request. */ state?: Record; /** Previous record state (available in update hooks). */ oldState?: unknown; /** Target record ID for single-record operations. */ recordId?: string | number; /** Response data (available in after hooks). */ response?: unknown; /** The affected record (available in after hooks for create/update/delete). */ record?: unknown; /** The affected records (available in after hooks for list operations). */ records?: unknown[]; [key: string]: unknown; } type HookHandler = (context: HookContext) => unknown | Promise; /** * Register a before hook middleware that runs before the operation executes. * * @param operation - Operation name: 'create', 'update', 'delete', 'get', or 'list' * @param model - Model name (e.g., 'user', 'animal') * @param handler - Middleware function (context) => any * - Return undefined to continue to next hook/handler * - Return any value to halt operation (integer = HTTP status, object = response body) * @returns Unsubscribe function */ export declare function beforeHook(operation: string, model: string, handler: HookHandler): () => void; /** * Register an after hook middleware that runs after the operation completes. * After hooks cannot halt operations (they run after completion). * * @param operation - Operation name * @param model - Model name * @param handler - Middleware function (context) => void * @returns Unsubscribe function */ export declare function afterHook(operation: string, model: string, handler: HookHandler): () => void; /** * Get all before hooks for an operation:model combination. */ export declare function getBeforeHooks(operation: string, model: string): HookHandler[]; /** * Get all after hooks for an operation:model combination. */ export declare function getAfterHooks(operation: string, model: string): HookHandler[]; /** * Clear registered hooks for a specific operation:model. * * @param operation - Operation name * @param model - Model name * @param type - 'before' or 'after' (if omitted, clears both) */ export declare function clearHook(operation: string, model: string, type?: 'before' | 'after'): void; /** * Clear all hooks (useful for testing). */ export declare function clearAllHooks(): void; export {};