
fabricator
Fabricate typed data from composable schemas.
Define a shape once and get typed, random test data. Every run can be replayed exactly from one recorded number.
import { } from "@ghostry/fabricator";
const { , } = ();
const = .({
: ..({ : { : 1, : 25 } }),
: ..({ : 1, : 500 }),
: .,
: ..,
: .(..({ : { : 15 } })).({
: { : 5 },
}),
});
const = new ();
const = .();
const createdAt = .;
// Everything random except what you pin:
const = .({ : "Widget", : true });The value's type comes from the schema. No generics to write, no as casts, and no fixture drifting away from its type.
Every value comes from a stream based on the run's clock, its position in the schema, and an optional salt. .trace records exactly where a value came from, so you can replay it.
Each field's data depends on its position in the schema, so adding, removing, or reordering a field changes only that field's data.
.extend(), .refine(), and .override() build new schemas from existing ones. Per-call overrides pin what a test cares about and leave the rest random.
A missing key, a key set to undefined, and a null value are different things. omittable, optional, nullable, nullish, and undefinable describe each precisely.
T.opaque and .as() cover anything without a primitive. registry.extend() adds your own builders. The TypeBox adapter turns a schema into a validator.