import type { TCoreOriginDocument, TCoreOriginLink, TCoreOriginAnchor, TOriginAnchorTargetType } from "../schemata/origin.js"; import type { TCoreChecksumConfig } from "../types/checksum.js"; import type { TOriginLibraryManagement, TOriginLibrarySnapshot } from "./interfaces/library.interfaces.js"; import type { TInvariantValidationResult } from "../types/validation.js"; /** * Holds the source texts arguments were built from, their per-version * associations, and the spans of those texts individual argument parts derive * from. * * Documents are immutable: there is no update path, because every anchor is * an offset into a document's exact text. Correcting a source means replacing * the document, which invalidates its anchors by design. * * The text is opaque content. This class digests it, measures it, and slices * it by index; it never parses, renders, or interprets it. * * An anchor is only meaningful alongside a link: the link carries the stance. * `validate()` therefore requires every anchor's * `(argumentId, argumentVersion, documentId)` to have a matching link, which * fixes the persistence order for consumers — document, then link, then * anchors — and makes removing a link that still has anchors a violation. * * Like the claim-connection libraries, this one mints no identifiers — * callers supply them — and takes no argument lookup: an argument library is * constructed after this one, so cross-checking argument existence here would * invert the dependency order. What it does enforce is everything decidable * from its own contents, most importantly that an anchor's span slices out * the anchor's own quote. */ export declare class OriginLibrary implements TOriginLibraryManagement { private documents; private links; private anchors; private linksByArgument; private anchorsByArgument; private anchorsByTarget; /** * Documents whose stored text has been confirmed normalized and matching * its digest, keyed by id and pinned to the exact text that passed. A * document is immutable, so a body that has been checked once cannot * change — but keying on the text rather than the id alone is what stops a * tampered snapshot from inheriting a previous instance's verdict. */ private verifiedDocumentBodies; /** Code-point index per document, reused across that document's anchors. */ private documentIndexes; /** * Violations present as of the last accepted state, so a mutation can be * judged on what it *introduced* rather than on whether everything is * clean afterwards. Carried between mutations rather than recomputed, so * this costs no extra `validate()` pass. */ private knownViolationKeys; private checksumConfig?; constructor(options?: { checksumConfig?: TCoreChecksumConfig; }); /** Stable identity for a violation, so two validation runs can be compared. */ private static violationKey; private static addToIndex; private reindex; private restoreFromSnapshot; /** * Runs a mutation, then rolls back and throws if the mutation *introduced* * a violation. * * Introduced, not "left the library inconsistent". Demanding a clean * library after every mutation makes an already-inconsistent one * unrepairable: two anchors that both violate the same invariant each keep * the other's removal from being accepted, and every mutation fails * forever. A library that validates has to stay repairable, and a snapshot * assembled by a consumer — or written by an older build — can arrive * inconsistent through no fault of the mutation being attempted. * * One rule covers both directions: an `addAnchor` with no link introduces a * violation and is still refused on a broken library as on a clean one, and * a `removeLink` that orphans existing anchors introduces theirs. * * ponytail: validating the whole library after every mutation is O(n²) in * anchor count across a bulk import — each of n `addAnchor` calls re-checks * the n anchors already present. Each check is one short slice comparison * against a cached index, so a few thousand anchors is still milliseconds; * scope the validation to the entity that changed if a caller ever needs * tens of thousands. The document-body checks, which scaled with document * *size* rather than count, are already skipped once verified. * * ponytail: the code-point indexes those checks rely on are retained for * the life of every document, uncapped — roughly 10x the text size, so 10 MB * of documents holds about 100 MB of heap. Peak is unchanged; steady state * is not. If it bites, index only documents that have anchors and drop the * index with their last anchor. */ private withValidation; /** * Creates a document from raw text. The text is normalized and digested * here rather than by the caller, so every document in the library shares * one coordinate system and one identity rule. */ addDocument(document: Omit): TDocument; addLink(link: Omit): TLink; addAnchor(anchor: Omit): TAnchor; /** * Removes a document. Refuses while a link or an anchor still references * it — dropping it silently would leave dangling references that only * `validate()` would notice, and only later. */ removeDocument(id: string): TDocument; removeLink(id: string): TLink; removeAnchor(id: string): TAnchor; getDocument(id: string): TDocument | undefined; getLink(id: string): TLink | undefined; getAnchor(id: string): TAnchor | undefined; getLinksForArgument(argumentId: string, argumentVersion: number): TLink[]; getAnchorsForArgument(argumentId: string, argumentVersion: number): TAnchor[]; getAnchorsForTarget(targetType: TOriginAnchorTargetType, targetId: string): TAnchor[]; getAllDocuments(): TDocument[]; getAllLinks(): TLink[]; getAllAnchors(): TAnchor[]; snapshot(): TOriginLibrarySnapshot; /** Restores an origin library from a snapshot, rebuilding its indexes. */ static fromSnapshot(snapshot: TOriginLibrarySnapshot, options?: { checksumConfig?: TCoreChecksumConfig; }): OriginLibrary; validate(): TInvariantValidationResult; private fieldsFor; } //# sourceMappingURL=origin-library.d.ts.map