Skip to content
Logo

Limitations

No validation

Fabricator doesn't validate data against a schema. Its own output doesn't need it, since fabricated data always has the right shape. To validate other data at runtime, convert the schema to TypeBox and validate there.

Uniqueness is per schema

T.unique keeps one schema from repeating its own values. Nothing makes two schemas distinct from each other. Two T.unique.number fields on one object are each unique on their own, but can share a value.

.rebase() can't name a field only a hidden field reads

T.pick and T.omit keep fabricating a field you dropped when a computed field you kept reads it. .rebase() can still replace that hidden field, but only when a field in the result reads it. A hidden field that only another hidden field reads is rejected by type:

const Schema = T.object({ a: T.number })
  .refine(({ compute }) => ({
    b: compute(T.number)
      .from(["a"])
      .as(({ fabricated }) => fabricated.a * 10),
  }))
  .refine(({ compute }) => ({
    c: compute(T.number)
      .from(["b"])
      .as(({ fabricated }) => fabricated.b + 1),
  }));
 
const Picked = T.pick(Schema, ["c"]);
 
Picked.rebase({ b: T.always(5) }); // fine: c reads b
Picked.rebase({ a: T.always(2) }); // type error: only the hidden b reads a

The type of Picked only describes c and what c reads, so it has no record of a. At runtime the call works. To type-check it, rebase before picking:

T.pick(Schema.rebase({ a: T.always(2) }), ["c"]);

T.string.uuid doesn't exist

There's no built-in UUID primitive. Use this instead:

T.string.as(() => crypto.randomUUID()).admits({ format: "uuid" });

This field is not reproducible. .as(produce) itself is fine: its producer receives the same { random, clock } context as T.opaque's. But crypto.randomUUID() ignores that and uses its own randomness. A producer that draws from random replays like anything else. See T.opaque, or use the faker extension's T.faker.string.uuid(), which is reproducible and has the same format hint.

Schema adaptation is one-way (for now)

An adapter converts a fabricator Schema outward: toTypeBox(ProductSchema) gives you a TypeBox schema. There is no reverse. Nothing turns an existing TypeBox, Zod, or JSON Schema definition into a fabricator Schema, and nothing fabricates data from one directly.

This follows from how adapters work, not from a missing feature. An Adapter is { key, convert }, and convert handles fabricator's primitive kinds (see @ghostry/fabricator/adapting). It can read a fabricator Schema and nothing else. .adapt(adapter, produce) works in the same direction: it changes what a schema converts to, never what it can be built from.

So fabricator has to own the shape definition. If your schemas already exist in another library and you want test data from them without redefining anything, that isn't supported yet, though it likely will be eventually.

Conversion isn't always exact in the forward direction either. T.opaque becomes Type.Unknown(), a symbol-keyed T.record throws instead of producing a schema nothing can pass, and Static<ToTypeBox<S>> can differ from the fabricated value's type. See that section of the TypeBox guide for when and why.

TypeBox version support

Only @sinclair/typebox 0.34.x, the scoped package, has an adapter. It is likely frozen. The unscoped typebox 1.x package is a separate rewrite, not a continuation, and would need its own adapter. Several things the current adapter maps to (Type.Date, Type.Const, Type.Uint8Array, Type.Recursive) don't exist in 1.x. The two adapters could coexist: each adapter carries its own key, so one schema can hold an override for each.

Not cryptographically secure

Fabricated data is predictable by design and is not safe to use as a secret. See Security.