import type { GuardStrategy, GuardContext, GuardChange } from './types.js'; /** * Per-record metadata attached to every entry in an amendment's * change-set. Carried in a parallel map alongside `_amendmentChanges` * so the public {@link GuardChange} shape (`{ before, after }`) stays * clean for invariant authors — the audit ledger reads this side * structure to produce the `{ collection, id, vBefore, vAfter }` * tuples for the amendment entry. * * @internal */ export interface AmendmentChangeMeta { readonly id: string; readonly vBefore: number; readonly vAfter: number; } /** * Vault-internal singleton that holds the guard graph and dispatches * per-collection guard execution. Owned by `Vault`; not exported. * * @internal */ type AnyGuard = GuardStrategy>; type AnyChange = GuardChange>; export declare class GuardRegistry { private readonly _byCollection; private _amendmentChanges; private _amendmentMeta; /** Register a guard. Multiple guards per collection are allowed. */ register>(spec: GuardStrategy): void; /** All guards registered against `collection` in registration order. */ guardsFor(collection: string): ReadonlyArray; /** Per-collection guard counts, for introspection. */ summary(): { collection: string; count: number; }[]; /** * Run every guard's `check` for this collection. First throw wins — * remaining guards are not invoked. Guards without a `check` skip. */ runChecks(collection: string, incoming: T, ctx: GuardContext): Promise; /** * Run every guard's `onDelete` for this collection. First throw wins — * remaining guards are not invoked. Guards without an `onDelete` skip. * Mirrors {@link runChecks} but for the delete path. */ runOnDelete(collection: string, existing: T, ctx: GuardContext): Promise; /** True if any guard for `collection` declares an `amendment` block. */ hasAmendment(collection: string): boolean; /** Open a new amendment change-collection window. */ beginAmendment(): void; /** True iff we're currently inside an amendment transaction. */ isAmendmentActive(): boolean; /** * Record a {before, after} pair for the active amendment. `vBefore` * and `vAfter` are stored in a parallel meta structure so the public * {@link GuardChange} shape handed to invariant callbacks stays * `{ before, after }` only — the audit ledger reads version metadata * via {@link consumeMeta}. */ collectChange(collection: string, id: string, before: T | null, after: T, vBefore?: number, vAfter?: number): void; /** * Drain the change-set and close the amendment window. The caller * (transaction commit) feeds these to each affected guard's invariant. */ consumeChanges(): ReadonlyMap>; /** * Drain the parallel id/version metadata captured during the * amendment. Returned as a flat list with `collection` denormalised * so the audit ledger can emit one `{ collection, id, vBefore, * vAfter }` tuple per record. Must be called AFTER * {@link consumeChanges} (or independently) — calling it closes the * meta window in the same way. */ consumeMeta(): ReadonlyArray<{ collection: string; id: string; vBefore: number; vAfter: number; }>; } export {};