mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import type { ResidualUnknownGraphConstraint } from "./residualUnknownGraphError.js";
|
|
import { AnalysisError } from "./analysisErrorBase.js";
|
|
|
|
/** Registry facts only the refusing ledger knows, for the caller's next step. */
|
|
export interface UnknownRegistryFacts {
|
|
/** the stored head's revision for a duplicate creation or revision conflict. */
|
|
readonly currentRevision?: number;
|
|
/** The stored unknown that a duplicate record would have created. */
|
|
readonly existingUnknownId?: string;
|
|
}
|
|
|
|
/** Residual-unknown mutation failed a lifecycle, reference, or CAS invariant. */
|
|
export class UnknownRegistryError extends AnalysisError {
|
|
readonly _tag = "UnknownRegistryError";
|
|
|
|
readonly constraint: ResidualUnknownGraphConstraint | undefined;
|
|
readonly facts: UnknownRegistryFacts;
|
|
readonly reason:
|
|
| "not-found"
|
|
| "already-exists"
|
|
| "revision-conflict"
|
|
| "invalid-transition"
|
|
| "integrity"
|
|
| "limit"
|
|
| "constraint";
|
|
|
|
constructor(
|
|
failure:
|
|
| "not-found"
|
|
| "already-exists"
|
|
| "revision-conflict"
|
|
| "invalid-transition"
|
|
| "integrity"
|
|
| "limit"
|
|
| ResidualUnknownGraphConstraint,
|
|
options?: ErrorOptions & UnknownRegistryFacts,
|
|
) {
|
|
const reason =
|
|
typeof failure === "string"
|
|
? failure
|
|
: failure.kind === "history_gap" || failure.kind === "revision_chain"
|
|
? "integrity"
|
|
: "constraint";
|
|
super(`Residual unknown registry mutation failed: ${reason}`, options);
|
|
this.reason = reason;
|
|
this.constraint = typeof failure === "string" ? undefined : failure;
|
|
this.facts = {
|
|
...(options?.currentRevision === undefined
|
|
? {}
|
|
: { currentRevision: options.currentRevision }),
|
|
...(options?.existingUnknownId === undefined
|
|
? {}
|
|
: { existingUnknownId: options.existingUnknownId }),
|
|
};
|
|
}
|
|
}
|