Skip to content
Logo

Installation

fabricator ships as ESM only, with zero runtime dependencies.

Requirements

  • An ESM-capable runtime — Bun, Node, Deno, or a bundler that supports ES modules
  • TypeScript — while not strictly required, it is highly recommended (fabricator is TypeScript-first; the value types you get back from .fabricate() are inferred from your schema, not hand-annotated)

Optional: a dynamic data library

By default, fabricator generates fuzzing values, not realistic-looking ones — T.string.whereby({ length: { max: 20 } }) gives you a random string, not a name. When you want output that reads like real data, add the Faker extension:

import { en } from "@faker-js/faker";
import { initialize, registry } from "@ghostry/fabricator";
import { fakerExtension } from "@ghostry/fabricator-extension-faker-v10";
 
const { T } = initialize({
  types: registry.extend(fakerExtension({ locale: en })),
});
 
const schema = T.faker.person.fullName();
// T.string using faker values when fabricated

Faker's generators draw from fabricator's own randomness, so those fields replay like every other one. See the Faker guide for the full surface.

You can also reach any data library by hand through .as(...) or T.opaque — see T.opaque, including what it takes to keep such fields reproducible.

Optional: schema adaptation for runtime validation

fabricator doesn't validate — nothing here checks a value against a schema. When you want the same shape to serve as a validator as well as a generator, add the TypeBox adapter:

import { toTypeBox } from "@ghostry/fabricator-adapter-typebox-v0";
 
const TProduct = toTypeBox(ProductSchema);

It targets @sinclair/typebox (0.34.x) specifically — hence the -v0. See the TypeBox guide for the default-mapping table and how to override it per schema.

Optional: a test harness

When fabricator feeds a test suite, @ghostry/harness wraps your runner's describe/it so each test draws data derived from its own name — reproducible, and independent of which other tests ran:

See the Harness guide for the setup module.

Optional: extern blocks

When a typed extern block uses a fabricator schema, @ghostry/extern-extension-fabricator-v0 makes it self-mocking: inside a testing block it fabricates from its own schema instead of requiring a mock.

See the Extern guide for the setup.