/** * Override the user id attached to subsequent audit rows. Useful in queue * workers, scheduled jobs, and CLI commands where there is no current HTTP * request to extract the user from. Pass `null` to clear the override and * fall back to the request-derived id. * * @example * ```ts * import { setAuditUser } from '@stacksjs/orm' * * // In a queue job that's running on behalf of user 42: * setAuditUser(42) * try { await processOrder(orderId) } finally { setAuditUser(null) } * ``` */ export declare function setAuditUser(id: number | string | null): void; /** * Build the public-facing audit helper(s). Right now that's just * `audits(id)` — the rest is wired up via `applyAudit()` which intercepts * the model's write methods. */ export declare function createAuditMethods(modelName: string): AuditHelpers; /** * Resolve the transactional opt-in from a model's `traits.useAudit` * declaration. Accepts both `true` (default, best-effort) and * `{ transactional: true }` (audit failures roll back the user's * write). Centralized so the wrapper functions below have a single * boolean to check. */ export declare function resolveAuditOptions(useAudit: unknown): { transactional: boolean }; /** * Wire the audit trait into a model's static surface. Wraps `create`, * `update`, and `delete` so each one writes a `model_audits` row after a * successful operation. Idempotent against the proxy machinery — relies on * the same wrapping pattern used by `applySoftDeletes`. * * Must run AFTER the static-helpers / cast / soft-delete wrappers have * installed their own versions of `create` / `update` / `delete`, so that * we wrap the final composed function rather than something that gets * shadowed later. * * **Transactional opt-in (stacksjs/stacks#1876 X-2):** pass * `{ transactional: true }` to wrap each create/update/delete in a * `db.transaction(...)` so audit-row write failures roll back the * underlying user write. Default is best-effort (audit failures are * logged but don't abort the operation) — appropriate for a debug / * change-log use case but NOT for compliance scenarios where a missing * audit entry is itself a failure mode. * * @example * ```ts * // Best-effort (default): audit failures don't abort writes. * defineModel({ traits: { useAudit: true } }) * * // Transactional (compliance): audit failures roll back the write. * defineModel({ traits: { useAudit: { transactional: true } } }) * ``` */ export declare function applyAudit(baseModel: Record, modelName: string, primaryKey?: string, opts?: { transactional?: boolean }): void; export declare interface AuditHelpers { audits: (id: number | string) => Promise>> }