@orkestrel/contract
v0.0.9
Published
Zero-dependency contract toolkit — type guards, combinators, parsers, and a shape DSL that compiles one contract shape into a guard, parser, JSON Schema, and generator. The foundation package of the @orkestrel line.
Maintainers
Readme
@orkestrel/contract
The zero-dependency contract toolkit — runtime type guards, guard combinators, coerce-and-extract
parsers, and a shape DSL that compiles once into a guard, parser, fault report, JSON Schema, and
generator that can never drift. The foundation package of the @orkestrel line.
Install
npm install @orkestrel/contractRequirements
- Node.js >= 22.12
- TypeScript-first (ships its own
.d.tstypes)
Usage
import {
createContract,
integerShape,
objectShape,
seededRandom,
stringShape,
} from '@orkestrel/contract'
const user = createContract(
objectShape({
name: stringShape({ min: 1 }),
age: integerShape({ min: 0, max: 120 }),
}),
)
user.is({ name: 'Ada', age: 36 }) // true
user.parse({ name: 'Ada', age: '36' }) // { name: 'Ada', age: 36 } — coerces, or undefined
user.explain({ name: '', age: 36 }) // [{ reason: 'constraint', path: ['name'], constraint: 'min', limit: 1, … }]
user.schema // the owned, deeply frozen compiled JSON Schema
user.generate(seededRandom(42)) // reproducible seed data; omit the arg for a wall-clock-seeded sourceGuide
For the full surface — guards, combinators, parsers, the JSON boundary, and the shape DSL — see
guides/src/contract.md.
Package
Published as a single typed entry point per the exports field in package.json.
