/** * Branded ID types and the `newId(kind)` factory. * * Implements the identifier portion of `wiki/SharedContracts.md` §1 and * `wiki/ArchitectureOverview.md` §3.2. Each branded type is structurally a * `string` but nominally distinct, so passing an `AnnotationId` where a * `DocumentId` is required is a compile-time error. */ declare const __brand: unique symbol; type Brand = K & { readonly [__brand]: T }; export type DocumentId = Brand; export type RepresentationId = Brand; export type AnnotationId = Brand; export type EvidenceItemId = Brand; export type EvidenceSetId = Brand; export type EvidenceLinkId = Brand; export type CitationCardId = Brand; export type CitationRecoveryAttemptId = Brand; export type SessionId = Brand; export type IdKindMap = { document: DocumentId; representation: RepresentationId; annotation: AnnotationId; evidence: EvidenceItemId; "evidence-set": EvidenceSetId; "evidence-link": EvidenceLinkId; "citation-card": CitationCardId; "citation-recovery": CitationRecoveryAttemptId; session: SessionId; }; export type IdKind = keyof IdKindMap; const PREFIXES: Record = { document: "doc", representation: "rep", annotation: "ann", evidence: "ev", "evidence-set": "evset", "evidence-link": "evlink", "citation-card": "card", "citation-recovery": "crec", session: "sess", }; /** * Mint a new branded identifier of the requested kind. * * IDs use the shape `_` so they are human-recognizable when * they show up in logs, URLs, or stored JSON. */ export function newId(kind: K): IdKindMap[K] { return `${PREFIXES[kind]}_${crypto.randomUUID()}` as IdKindMap[K]; }