Executable, TypeScript-first schemas with deterministic OpenAPI 3.1 projection.
The same declaration validates runtime input through safeParse() and exposes
its deeply immutable documentation shape through jsonSchema.
import { schema, type InferSchema } from "@askrjs/schema";
const User = schema.object({
id: schema.uuid(),
name: schema.string({ minLength: 1 }),
nickname: schema.optional(schema.string()),
});
type User = InferSchema<typeof User>;
const result = User.safeParse({ id: crypto.randomUUID(), name: "Ada" });Validation failures contain stable path arrays, codes, and messages. Objects
reject undeclared keys by default; opt into additional keys with
additionalProperties: true or validate them with another schema.
schema.object() and schema.record() return ObjectSchema, the transport-safe
schema subtype used by action inputs, route search, and server operation inputs.
String formats are limited to the formats the runtime implements. Use
schema.raw() when an integration intentionally owns a custom format.
schema.raw(projection, safeParse) is the explicit extension seam. It requires an
executable parser so a documentation-only declaration cannot masquerade as a
runtime schema. Named component references are created by @askrjs/server
while retaining the original schema parser.
See docs/schema.md for the complete built-in vocabulary and projection guarantees.
Constructor options, enum members and object declarations are snapshotted.
Counts must be non-negative integers, numeric limits finite, and multipleOf
positive. Empty combinators, duplicate enums and non-finite literals are
rejected during construction. Projections must be acyclic and no deeper than
256 nested containers; use JSON Schema $ref with raw() for manual recursion.
Declared maximum sizes reject oversized inputs before visiting their children.
See the complete API decisions and migration and executed boundary evidence. The manifest remains on 0.4.x until coordinated release qualification.
npm ci
npm run check
npm run pack:checkThe package uses Vite Plus and publishes ESM JavaScript and declarations from
dist/, plus its changelog and contract/migration documentation.