/** * What a module's check said about its own claim, the moment it was asked. * * Three states, not two, for the same reason {@link InvariantOutcome} shares * its shape with NZ-BOOT-02's `CapabilityProbe`: a check that could not run * — no live turn to point it at, a dependency not wired yet — is not the same * fact as a check that ran and found nothing wrong, and collapsing the two * turns "I do not know" into the strongest possible wrong answer. See * "an optional dependency may not degrade a check". */ export type InvariantOutcome = { readonly state: 'holds'; } | { readonly state: 'violated'; readonly detail: string; } | { readonly state: 'unknown'; readonly reason: string; }; /** * A module's claim about its own live state, as a function of whatever * context evaluating it needs. * * Stored on the registry as `InvariantCheck` — see the note on * {@link InvariantDefinition.check} for why the erasure is deliberate rather * than a shortcut. */ export type InvariantCheck = (ctx: TContext) => InvariantOutcome | Promise; /** * Thrown by {@link InvariantRegistry.register} when `:` is * already taken. * * `ManagedRegistry.register` — what this class is built on — warns and * OVERWRITES a duplicate id by default; that is right for a registry of * definitions a later one is meant to supersede, and wrong here. Two * invariants sharing a name is always a bug (two modules picked the same * words, or one module's own top-level registration ran twice), and * overwriting would silently keep whichever registration lost the race while * every reference to the other's `id` kept resolving as if it still existed. * Mirrors `ProbeNameCollisionError`. */ export declare class InvariantNameCollisionError extends Error { readonly moduleName: string; readonly invariantName: string; constructor(moduleName: string, invariantName: string); } /** * Thrown by {@link InvariantRegistry.assert} when the named invariant's * check reports `violated`. Never thrown for `unknown` — a check that could * not answer is not a check that answered no, and `assert` treating the two * alike would turn "ask again with more context" into a hard failure the * check never claimed to be. */ export declare class ModuleInvariantError extends Error { readonly moduleName: string; readonly invariantName: string; readonly detail: string; constructor(moduleName: string, invariantName: string, detail: string); } /** * The place a package registers a claim about its own live state, and the * place an operator or `namzu doctor` reads what this build asserts about * itself. * * Built on {@link ManagedRegistry} for storage and its logging, composed * rather than extended: `ManagedRegistry.register(id, item)` is public, * two-argument, and overwrites — exposing it directly (by extending the * class under the name `register`) would either fail to compile against * this class's three-argument `register(moduleName, name, check)`, or, named * differently, leave the inherited two-argument overwrite-on-collision * method reachable as an unguarded back door around the one guarantee this * class exists to make. */ export declare class InvariantRegistry { private readonly definitions; constructor(); /** * Reserve `:` for `check`, once. Throws * {@link InvariantNameCollisionError} on a second registration under the * same id — see the class doc for why this does not delegate to the base * registry's own collision handling. */ register(moduleName: string, name: string, check: InvariantCheck): void; /** Every registered id, in registration order. */ listIds(): string[]; /** * Run `id`'s check against `ctx` and return what it said. A `violated` * result counts against that invariant's own violation counter; `holds` * and `unknown` do not, so the counter answers "how many times has this * actually been false" and nothing else. */ evaluate(id: string, ctx: TContext): Promise; /** * `evaluate`, but a `violated` outcome throws {@link ModuleInvariantError} * instead of being handed back. `unknown` does not throw — see the error * class's own doc. */ assert(id: string, ctx: TContext): Promise; /** Violations `id` has recorded since this registry was created. */ violationCount(id: string): number; } /** * The process-wide registry. `compaction.ts` and `claim-disk.ts` each * register one invariant against it at import time — see the registration * beside each — which is what makes `listIds()` non-empty from the day this * file lands rather than a registry nothing has ever driven. */ export declare const invariants: InvariantRegistry; /** A scoped registry for a test, or a host that wants its own. */ export declare function createInvariantRegistry(): InvariantRegistry; //# sourceMappingURL=index.d.ts.map