import type { CasNode, Hash, Store } from "./types.js"; export type JSONSchema = Record; export declare class SchemaValidationError extends Error { readonly name = "SchemaValidationError"; } /** * Store a JSON Schema as a CAS node typed by the meta-schema hash. * The returned hash becomes the typeHash for nodes that conform to this schema. */ export declare function putSchema(store: Store, jsonSchema: JSONSchema): Hash; /** * Retrieve the JSON Schema payload for a given type hash. * Returns null if no node exists at that hash. */ export declare function getSchema(store: Store, typeHash: Hash): JSONSchema | null; /** * Validate a node's payload against the schema identified by node.type. * Returns false if the schema cannot be found or validation fails. */ export declare function validate(store: Store, node: CasNode): boolean; /** * Recursively collect values of all properties whose schema has format: 'ocas_ref'. * Handles: direct format, anyOf/allOf (combinators), oneOf, if/then/else (conditionals), * not, contains, items + prefixItems (arrays), properties (nested objects), * additionalProperties (record refs), and patternProperties (regex-keyed refs). */ export declare function collectRefs(schema: JSONSchema, value: unknown): Hash[]; /** * Callback invoked when traversal discovers a CAS hash that does not exist * in the store. Called at most once per unique missing hash per top-level * call. Purely informational — it cannot abort traversal. Exceptions thrown * inside the callback propagate to the caller. */ export type OnDangling = (hash: Hash) => void; /** * Options accepted by {@link refs}. */ export interface RefsOptions { /** See {@link OnDangling}. */ onDangling?: OnDangling; } /** * Options accepted by {@link walk}. */ export interface WalkOptions { /** * See {@link OnDangling}. * Exceptions thrown inside the callback propagate to the caller. */ onDangling?: OnDangling; /** * When `true` (the default), the traversal enqueues each node's `type` * hash so that the full schema chain is part of the walk. Set to `false` * to traverse only payload `ocas_ref` edges and skip the schema chain. */ followType?: boolean; } /** * Return all hashes referenced by this node via ocas_ref fields in its schema. * Null/undefined values are skipped. * * If `options.onDangling` is provided, the callback is invoked once per unique * referenced hash that is not present in `store.cas`. The returned array is * unchanged regardless of whether the targets exist (it is a static collection * derived from the payload). * * Note: a missing schema (the node's own `type` is not in the store) yields * `[]` silently — `onDangling` is for ref *targets*, not the node's own type. */ export declare function refs(store: Store, node: CasNode, options?: RefsOptions): Hash[]; /** * BFS traversal starting from rootHash. * Calls visitor(hash, node) for each reachable node exactly once. * Handles cycles via a visited set. * * Traversal enqueues both: * 1. payload refs returned by {@link refs} (ocas_ref fields), and * 2. the node's own type hash (so the schema chain is reachable), * unless `followType` is `false`. * * The visited-set dedup naturally handles self-referencing meta-schemas * (where `node.type === hash`). Because schema nodes are traversed like any * other node, refs embedded inside a schema's payload (e.g. via a custom * meta-schema declaring an `ocas_ref` field) are now reached transitively. * * Dangling refs (hashes that resolve to no stored node, including the root * itself, the node's type, and any payload ref target) are silently skipped * by default. Pass `options.onDangling` to be notified once per unique * missing hash discovered during the traversal. */ export declare function walk(store: Store, rootHash: Hash, visitor: (hash: Hash, node: CasNode) => void, options?: WalkOptions): void; //# sourceMappingURL=schema.d.ts.map