import { type JsonSchema } from "./subschemas.js"; import { UnusableSchemaError } from "./unusable-schema.js"; /** * A reference the schema rewriters cannot follow. Dropping or skipping it * would advertise a contract the source never declared, so callers either * refuse the schema or report the tool as unusable. */ export declare class SchemaReferenceError extends UnusableSchemaError { constructor(path: string, reason: string); } /** The value a local `#/...` JSON pointer names in `root`, or undefined. */ export declare function resolveLocalRef(root: unknown, ref: string): unknown; /** * Checks every reference in `schema` against the document and rewrites each * one to a plain `#/...` pointer, before anything else touches the schema. * The rewriters below match and rebuild references textually, so an * equivalent spelling (`#%2F$defs%2FItem`, an `$anchor` name) would survive * until its target moved and then dangle, and a reference that never resolved * would be dropped along with the composition holding it. * * Throws `SchemaReferenceError` for a reference that does not resolve here: a * missing target, a non-local URI, an `$id` below the root (which re-scopes * every reference inside it), or a dynamic reference. Removes `$anchor` and * `$dynamicAnchor` once no reference names them, since rebasing copies a * target and a duplicated anchor does not compile. Returns `schema` itself * when nothing changes; never mutates it. */ export declare function canonicalLocalRefs(schema: T): T; /** Local references whose target does not exist in `root`. */ export declare function unresolvedLocalRefs(root: JsonSchema): string[]; /** * Moves every local reference target that is not a whole root definition * into root `$defs` and points the reference there. Removing a root * composition, or rewriting `oneOf` to `anyOf`, deletes or renumbers the * paths a reference like `#/anyOf/0/$defs/Item` names, which turns a valid * schema into one no validator can compile. A root `#` reference and * `#/$defs/` survive both rewrites, so they are left alone. * * References are made canonical first, so this throws `SchemaReferenceError` * for any `canonicalLocalRefs` refuses. Targets are copied from the original * document, and a reference cycle reuses the name already given to that * pointer. Returns `schema` itself when nothing changes; never mutates it. */ export declare function rebaseLocalRefs(schema: T): T;