verax · contract

vērāx — the exact contract

What verax guarantees for any input, where it stops, and how each schema reads a value. The docs show it running.

Guarantees and limits

For any input, validation never throws and never returns a wrong verdict: a throwing callback, hostile getter or proxy, or exhausted stack becomes an issue. Every limit below fails closed: it is an issue (and is is false), never an accept. For plain data — what JSON.parse or structuredClone produce, shared subtrees and holes included — the limits bound time and memory. Other objects cost in proportion to their structure: verax reads only what the schema asks for, but an engine may step over an object's non-enumerable or symbol keys, uncounted, on every visit.

Semantics

Recursive schemas

Make the field a getter and annotate the schema with its type, which TypeScript cannot infer through a cycle — a bare Schema infers unknown. The shape is read once, on first use: its getters run then, def.shape is a frozen copy, and later changes to the object passed in have no effect.

import type { Schema } from 'verax';

type Node = {
  next: Node | null;
  note?: string | undefined;
};

const Node: Schema<Node> = object('Node', {
  get next() {
    return nullable(Node);
  },
  note: optional(string()),
});