@ghostry/fabricator 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/esm/Distribution/index.js +1 -1
  2. package/dist/esm/Primitive/null/Registry.js +2 -3
  3. package/dist/esm/Primitive/undefined/Registry.js +2 -3
  4. package/dist/esm/index.js +1 -0
  5. package/dist/esm/internal.js +2 -2
  6. package/dist/types/Adapter/Types.d.ts +3 -2
  7. package/dist/types/Distribution/index.d.ts +10 -0
  8. package/dist/types/Enumeration/Types.d.ts +3 -3
  9. package/dist/types/Fabricator/Types.d.ts +8 -8
  10. package/dist/types/Primitive/always/Types.d.ts +2 -2
  11. package/dist/types/Primitive/array/Types.d.ts +4 -4
  12. package/dist/types/Primitive/bigint/Types.d.ts +2 -2
  13. package/dist/types/Primitive/boolean/Types.d.ts +2 -2
  14. package/dist/types/Primitive/choice/Types.d.ts +4 -4
  15. package/dist/types/Primitive/date/Types.d.ts +2 -2
  16. package/dist/types/Primitive/derive/Types.d.ts +2 -2
  17. package/dist/types/Primitive/enum/Types.d.ts +2 -2
  18. package/dist/types/Primitive/null/Types.d.ts +2 -2
  19. package/dist/types/Primitive/nullable/Types.d.ts +4 -4
  20. package/dist/types/Primitive/nullish/Types.d.ts +4 -4
  21. package/dist/types/Primitive/number/Types.d.ts +2 -2
  22. package/dist/types/Primitive/object/Types.d.ts +9 -9
  23. package/dist/types/Primitive/object/compute/Types.d.ts +4 -4
  24. package/dist/types/Primitive/object/omittable/Types.d.ts +4 -4
  25. package/dist/types/Primitive/object/optional/Types.d.ts +4 -4
  26. package/dist/types/Primitive/opaque/Types.d.ts +2 -2
  27. package/dist/types/Primitive/record/Types.d.ts +11 -6
  28. package/dist/types/Primitive/recursive/Types.d.ts +12 -8
  29. package/dist/types/Primitive/recursive/self/Schema.d.ts +4 -4
  30. package/dist/types/Primitive/recursive/self/Types.d.ts +7 -5
  31. package/dist/types/Primitive/string/Constants.d.ts +7 -31
  32. package/dist/types/Primitive/string/Types.d.ts +2 -2
  33. package/dist/types/Primitive/symbol/Types.d.ts +2 -2
  34. package/dist/types/Primitive/tuple/Types.d.ts +7 -7
  35. package/dist/types/Primitive/undefinable/Types.d.ts +4 -4
  36. package/dist/types/Primitive/undefined/Types.d.ts +2 -2
  37. package/dist/types/Schema/Core.d.ts +10 -6
  38. package/dist/types/Schema/Satisfies.d.ts +31 -23
  39. package/dist/types/Schema/Types.d.ts +31 -18
  40. package/dist/types/Types.d.ts +24 -0
  41. package/dist/types/index.d.ts +24 -10
  42. package/dist/types/internal.d.ts +24 -4
  43. package/package.json +3 -3
@@ -1,19 +1,21 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
- import type { AnySchema, ValueOf } from "../../Schema/Types";
3
- import { Produces, type Adaptation, type Kind, type Meta } from "../../Types";
2
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
3
+ import { Produces, type Adaptation, type Kind, type Meta, type Produced } from "../../Types";
4
4
  /**
5
5
  * Fixed point of a recursive schema. A self-referential alias, normally
6
6
  * `TS2456` ("`RecursiveValue` circularly references itself") — legal _only_
7
- * because `ValueOf`'s second argument is read through an interface member
7
+ * because `FabricatedBy`'s second argument is read through an interface member
8
8
  * (`this["bindings"]` on every composite `Core`), which TypeScript defers. Do
9
9
  * not rewrite as a conditional; that reintroduces the error. See `AGENTS.md`'s
10
- * "`ValueOf`'s `$Bindings`".
10
+ * "`Fabricated<$Schema>`'s `$Bindings`".
11
11
  *
12
12
  * Wherever `self` sits in `$Body` (nested through `array`/`object`/`tuple`/
13
13
  * etc., each forwarding `this["bindings"]`), it reads `bindings[0]` —
14
14
  * `RecursiveValue<$Body>` itself, closing the loop.
15
15
  */
16
- export type RecursiveValue<$Body> = ValueOf<$Body, [RecursiveValue<$Body>]>;
16
+ export type RecursiveValue<$Body> = FabricatedBy<$Body, [
17
+ RecursiveValue<$Body>
18
+ ]>;
17
19
  export type Fabricated<$Body> = RecursiveValue<$Body>;
18
20
  /**
19
21
  * `terminal` is what `self` expands into at `depth.max`, in place of `body`.
@@ -24,7 +26,9 @@ export type Fabricated<$Body> = RecursiveValue<$Body>;
24
26
  * already rejects a wrong terminal (e.g. missing a required field `body` has),
25
27
  * and nothing downstream needs `terminal`'s precise type (`Core`'s `[Produces]`
26
28
  * depends only on `$Body`). A bare-vs-generic comparison rejects the same wrong
27
- * terminal either way.
29
+ * terminal either way. The constraint matches through the box (`Produced<…>`,
30
+ * `Types.ts`): unboxed, a caller compiling without `exactOptionalPropertyTypes`
31
+ * could pass a terminal producing `undefined` for any body at all.
28
32
  *
29
33
  * Omitted, `terminal` is derived from `body` (`Terminate.ts`): every `self`
30
34
  * behind a declining kind is rewritten into a stop (empty array/record,
@@ -52,7 +56,7 @@ export type Whereby<$Body> = {
52
56
  max: number;
53
57
  };
54
58
  terminal?: (AnySchema & {
55
- readonly [Produces]?: RecursiveValue<$Body>;
59
+ readonly [Produces]?: Produced<RecursiveValue<$Body>>;
56
60
  }) | undefined;
57
61
  };
58
62
  /**
@@ -77,6 +81,6 @@ export type Meta<$Body = unknown> = {
77
81
  export type Core<$Body = unknown, $Adaptations extends Adaptations = {}> = {
78
82
  [Kind]: "recursive";
79
83
  [Meta]: Meta<$Body>;
80
- readonly [Produces]?: Fabricated<$Body>;
84
+ readonly [Produces]?: Produced<Fabricated<$Body>>;
81
85
  readonly [Adaptation]?: $Adaptations;
82
86
  };
@@ -19,10 +19,10 @@ export interface Schema<$Adaptations extends Adaptations = {}> extends Core<$Ada
19
19
  /**
20
20
  * Check that this schema's fabricated value type is assignable to `$Target`.
21
21
  * Identity at runtime; the target is not carried into later chained calls —
22
- * see `object/Schema.ts`'s `satisfies`. Outside `ValueOf`'s `$Bindings`,
23
- * `Fabricated` is `unknown` — a `self` has no value of its own. Put
24
- * `.satisfies` on the enclosing `T.recursive(...).whereby(...)` to check the
25
- * tree.
22
+ * see `object/Schema.ts`'s `satisfies`. Outside `Schema/Types.ts`'s
23
+ * `$Bindings`, this kind's `Fabricated` is `unknown` — a `self` has no value
24
+ * of its own. Put `.satisfies` on the enclosing
25
+ * `T.recursive(...).whereby(...)` to check the tree.
26
26
  */
27
27
  satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Adaptations>;
28
28
  adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Adaptations>>) => $Returnable) => Schema<WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
@@ -1,10 +1,11 @@
1
1
  import type { Adaptations } from "../../../Adapter/Types";
2
- import { Produces, type Adaptation, type Kind, type Meta } from "../../../Types";
2
+ import { Produces, type Adaptation, type Produced, type Kind, type Meta } from "../../../Types";
3
3
  /**
4
4
  * The value a `self` reference resolves to at this position — whatever the
5
5
  * enclosing `T.recursive`'s current expansion binds it to. Reads `bindings[0]`,
6
6
  * the analogue of TypeBox's `TThis` reading `this['params'][0]`; see
7
- * `Schema/Types.ts`'s `ValueOf` for what `bindings` is and why it's a tuple.
7
+ * `Schema/Types.ts`'s `Fabricated` for what `bindings` is and why it's a
8
+ * tuple.
8
9
  *
9
10
  * Unlike every other kind, `self` has no type parameter of its own — its whole
10
11
  * value comes from outside, threaded in structurally by whatever composite
@@ -15,13 +16,14 @@ export type Fabricated<$Bindings extends unknown[] = []> = $Bindings[0];
15
16
  export type Meta = Record<string, never>;
16
17
  /**
17
18
  * An `interface`, not a `type` alias, so `this["bindings"]` resolves — the
18
- * entire mechanism this kind exists for. See `AGENTS.md`'s "`ValueOf`'s
19
- * `$Bindings`" section for why threading requires this.
19
+ * entire mechanism this kind exists for. See `AGENTS.md`'s
20
+ * "`Fabricated<$Schema>`'s `$Bindings`" section for why threading requires
21
+ * this.
20
22
  */
21
23
  export interface Core<$Adaptations extends Adaptations = {}> {
22
24
  [Kind]: "recursive.self";
23
25
  [Meta]: Meta;
24
26
  bindings?: unknown[];
25
- readonly [Produces]?: Fabricated<NonNullable<this["bindings"]>>;
27
+ readonly [Produces]?: Produced<Fabricated<NonNullable<this["bindings"]>>>;
26
28
  readonly [Adaptation]?: $Adaptations;
27
29
  }
@@ -8,39 +8,15 @@ import type { CodepointRange } from "./Types";
8
8
  * export alongside `export type Fabricated = string` makes the module a value
9
9
  * module, and `export * as string` in `Primitive/namespace.ts` then resolves
10
10
  * `string` to the namespace — a cycle that drops `[Kind]`/`[Meta]` off `Core`.
11
+ *
12
+ * Annotated member-by-member, like `classes`, because it is public API and JSR
13
+ * rejects an inferred `const` type there.
11
14
  */
12
15
  export declare const unicode: {
13
- /**
14
- * All Unicode scalar values: the codespace minus the surrogate block
15
- * (U+D800–U+DFFF). Always well-formed UTF-16, so it round-trips cleanly
16
- * through encoders, URLs, and datastores.
17
- *
18
- * This is the default composition for strings.
19
- */
20
- scalars: {
21
- from: number;
22
- to: number;
23
- }[];
24
- /**
25
- * The entire Unicode codespace, U+0000–U+10FFFF, including the surrogate
26
- * block — so it can yield lone surrogates and thus ill-formed UTF-16. Opt in
27
- * for lone surrogates and other ill-formed UTF-16 when fuzzing.
28
- */
29
- codespace: {
30
- from: number;
31
- to: number;
32
- };
33
- /** The Basic Multilingual Plane, U+0000–U+FFFF. */
34
- bmp: {
35
- from: number;
36
- to: number;
37
- };
38
- /** Printable ASCII, U+0020–U+007E. */
39
- ascii: {
40
- from: number;
41
- to: number;
42
- };
43
- /** An arbitrary inclusive code point range. */
16
+ scalars: ReadonlyArray<CodepointRange>;
17
+ codespace: CodepointRange;
18
+ bmp: CodepointRange;
19
+ ascii: CodepointRange;
44
20
  range: (from: number, to: number) => CodepointRange;
45
21
  };
46
22
  /**
@@ -1,7 +1,7 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { InputLength, Length } from "../../Bound";
3
3
  import type { Produce } from "../../Random/Types";
4
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
4
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
5
5
  import type { classes } from "./Constants";
6
6
  /** An inclusive range of Unicode code points. */
7
7
  export type CodepointRange = {
@@ -68,6 +68,6 @@ export type Meta = {
68
68
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
69
69
  [Kind]: "string";
70
70
  [Meta]: $Meta;
71
- readonly [Produces]?: Fabricated;
71
+ readonly [Produces]?: Produced<Fabricated>;
72
72
  readonly [Adaptation]?: $Adaptations;
73
73
  };
@@ -1,6 +1,6 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { Produce } from "../../Random/Types";
3
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
3
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
4
4
  export type Fabricated = symbol;
5
5
  /**
6
6
  * A symbol keyed via `keyed`, or unkeyed if `key` is absent, optionally
@@ -14,6 +14,6 @@ export type Meta = {
14
14
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
15
15
  [Kind]: "symbol";
16
16
  [Meta]: $Meta;
17
- readonly [Produces]?: Fabricated;
17
+ readonly [Produces]?: Produced<Fabricated>;
18
18
  readonly [Adaptation]?: $Adaptations;
19
19
  };
@@ -1,7 +1,7 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { Produce } from "../../Random/Types";
3
- import type { AnySchema, ValueOf } from "../../Schema/Types";
4
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
3
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
4
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
5
5
  /** The schema occupying a single tuple slot. */
6
6
  export type Item = AnySchema;
7
7
  /**
@@ -19,9 +19,9 @@ export type Items = ReadonlyArray<Item>;
19
19
  * `keyof` a still-abstract `ReadonlyArray<Item>` (this type's default, and what
20
20
  * a kind-local `Fabrication<$Fabricator>` resolves against for the _bare_,
21
21
  * unparameterized `Fabricator`) pulls in `"length"`/method keys that don't
22
- * resolve to a sensible `ValueOf`. A homomorphic version type-checks for any
23
- * concrete tuple but silently produces a malformed bare type, which then fails
24
- * `.schema.as`'s contravariant parameter check against any concrete
22
+ * resolve to a sensible `FabricatedBy`. A homomorphic version type-checks for
23
+ * any concrete tuple but silently produces a malformed bare type, which then
24
+ * fails `.schema.as`'s contravariant parameter check against any concrete
25
25
  * instantiation (`Fabrication.types.test.ts`). Matching a fixed-length tuple
26
26
  * pattern at every step avoids it, as `TupleItems` does for `ToTypeBox`. The
27
27
  * fallback (a genuinely widened, arity-less array) is a plain `Array<...>`,
@@ -30,7 +30,7 @@ export type Items = ReadonlyArray<Item>;
30
30
  export type Fabricated<$Items extends Items = Items, $Bindings extends unknown[] = []> = $Items extends readonly [] ? [] : $Items extends readonly [
31
31
  infer $Head extends Item,
32
32
  ...infer $Rest extends Items
33
- ] ? [ValueOf<$Head, $Bindings>, ...Fabricated<$Rest, $Bindings>] : Array<ValueOf<$Items[number], $Bindings>>;
33
+ ] ? [FabricatedBy<$Head, $Bindings>, ...Fabricated<$Rest, $Bindings>] : Array<FabricatedBy<$Items[number], $Bindings>>;
34
34
  /**
35
35
  * No `whereby`: arity is fixed at `T.tuple([...])` and there is nothing left to
36
36
  * configure. Unlike `array`'s two-variant union this needs no "config or
@@ -47,6 +47,6 @@ export interface Core<$Items extends Items = Items, $Adaptations extends Adaptat
47
47
  [Kind]: "tuple";
48
48
  [Meta]: Meta<$Items>;
49
49
  bindings?: unknown[];
50
- readonly [Produces]?: Fabricated<$Items, NonNullable<this["bindings"]>>;
50
+ readonly [Produces]?: Produced<Fabricated<$Items, NonNullable<this["bindings"]>>>;
51
51
  readonly [Adaptation]?: $Adaptations;
52
52
  }
@@ -1,10 +1,10 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { Produce } from "../../Random/Types";
3
- import type { AnySchema, ValueOf } from "../../Schema/Types";
4
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
3
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
4
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
5
5
  /** The wrapped schema — the value type produced when the roll isn't `undefined`. */
6
6
  export type Definition = AnySchema;
7
- export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = ValueOf<$Definition, $Bindings> | undefined;
7
+ export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings> | undefined;
8
8
  export type { Outcome } from "./Outcomes";
9
9
  /**
10
10
  * Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional — an
@@ -43,6 +43,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
43
43
  [Kind]: "undefinable";
44
44
  [Meta]: Meta<$Definition>;
45
45
  bindings?: unknown[];
46
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
46
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
47
47
  readonly [Adaptation]?: $Adaptations;
48
48
  }
@@ -1,5 +1,5 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
2
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
3
3
  export type Fabricated = undefined;
4
4
  /**
5
5
  * Nothing to configure: `undefined` has exactly one possible value, so there is
@@ -10,6 +10,6 @@ export type Meta = Record<string, never>;
10
10
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
11
11
  [Kind]: "undefined";
12
12
  [Meta]: $Meta;
13
- readonly [Produces]?: Fabricated;
13
+ readonly [Produces]?: Produced<Fabricated>;
14
14
  readonly [Adaptation]?: $Adaptations;
15
15
  };
@@ -1,6 +1,6 @@
1
1
  import type { Adaptations } from "../Adapter/Types";
2
2
  import type { Kind as SchemaKind } from "../Primitive";
3
- import { Adaptation, Kind, Meta, type Produces } from "../Types";
3
+ import { Adaptation, Kind, Meta, type Produced, type Produces } from "../Types";
4
4
  import { type PlainObject } from "../Utility/Types";
5
5
  /**
6
6
  * Normalize a Schema, a builder namespace, or an already-built Fabricator into
@@ -16,20 +16,24 @@ import { type PlainObject } from "../Utility/Types";
16
16
  * enclosing `object`/`array`, which is where every adapter actually reads it
17
17
  * from (see `Adapter/TypeBox`'s `build`, which walks `[Meta].definition`).
18
18
  *
19
- * `$SchemaProduces` is threaded through in the type only (never read or written
20
- * at runtime) so `ValueOf` stays precise across a `toSchema` call — dropping it
19
+ * `$Produces` is threaded through in the type only (never read or written at
20
+ * runtime) so `Fabricated` stays precise across a `toSchema` call — dropping it
21
21
  * would make every normalized field (e.g. every `object`/`array` element) fall
22
- * back to `unknown`.
22
+ * back to `unknown`. It is inferred through the box (`Produced<$Produces>`,
23
+ * `Types.ts`), not as the brand's whole type: inferred against a bare
24
+ * `[Produces]?: $Produces`, a value type's own `undefined` is absorbed into the
25
+ * optional slot whenever the caller compiles without
26
+ * `exactOptionalPropertyTypes`.
23
27
  */
24
28
  export declare function toSchema<$Kind extends string, $Meta extends PlainObject, $Produces = unknown, $Adaptations extends Adaptations = Adaptations>(value: {
25
29
  [Kind]: $Kind;
26
30
  [Meta]: $Meta;
27
- [Produces]?: $Produces;
31
+ [Produces]?: Produced<$Produces>;
28
32
  [Adaptation]?: $Adaptations;
29
33
  }): {
30
34
  [Kind]: $Kind;
31
35
  [Meta]: $Meta;
32
- readonly [Produces]?: $Produces;
36
+ readonly [Produces]?: Produced<$Produces>;
33
37
  readonly [Adaptation]?: $Adaptations;
34
38
  };
35
39
  /**
@@ -1,6 +1,6 @@
1
1
  import type { NaiveFabricator } from "../Fabricator/Types";
2
- import type { Buildable, Produces } from "../Types";
3
- import type { ValueOf } from "./Types";
2
+ import type { Buildable, Produced, Produces } from "../Types";
3
+ import type { Fabricated } from "./Types";
4
4
  /**
5
5
  * The `this`-parameter constraint every kind's `.satisfies<$Target>()`
6
6
  * intersects onto the receiver, so a mismatch names both sides on the call that
@@ -8,13 +8,14 @@ import type { ValueOf } from "./Types";
8
8
  * where the error lands on `inner` rather than the outer object.
9
9
  *
10
10
  * `$Produced` is each kind's own `Fabricated<…>` (or `Resolved<…>` for `derive`
11
- * / `object.compute`, which have no `Fabricated` alias). A shared
12
- * `ValueOf<this>` form errors in the same place but reports `"schema produces":
13
- * any`, which is why each kind still names its own produced type. The check is
14
- * wrapped in a 1-tuple so it does not distribute over unions: a bare `$Produced
15
- * extends $Target ? unknown : Error` on `"x" | null` becomes `unknown | Error`,
16
- * which is `unknown`, and `T.nullable(…).satisfies<string>()` would pass. Other
17
- * signatures that were considered, and why they are not this:
11
+ * / `object.compute`, which have no `Fabricated` alias). A shared schema-level
12
+ * `Fabricated<this>` form errors in the same place but reports `"schema
13
+ * produces": any`, which is why each kind still names its own produced type.
14
+ * The check is wrapped in a 1-tuple so it does not distribute over unions: a
15
+ * bare `$Produced extends $Target ? unknown : Error` on `"x" | null` becomes
16
+ * `unknown | Error`, which is `unknown`, and
17
+ * `T.nullable(…).satisfies<string>()` would pass. Other signatures that were
18
+ * considered, and why they are not this:
18
19
  *
19
20
  * - A rest tuple `...check: D extends T ? [] : [error]` errors in the right place
20
21
  * but says "Expected 1 arguments, but got 0".
@@ -26,11 +27,12 @@ import type { ValueOf } from "./Types";
26
27
  * that changes a field's type is not re-checked. Put `.satisfies` last to check
27
28
  * the final shape. Carrying `$Target` on every `Schema` interface would add a
28
29
  * type parameter to all 25 kinds, and `.as`'s contravariant parameter check is
29
- * where a variance shift on those interfaces surfaces — `Types.ts`'s `ValueOf`
30
- * note records that same check breaking from a constraint on `$Schema`. The
31
- * return is `Schema`, not polymorphic `this`, because `T.date.past` /
32
- * `T.number.integer` / `T.symbol` are `Schema & { whereby, … }` and a `this`
33
- * return is not assignable into those extra members — same as `.as()`.
30
+ * where a variance shift on those interfaces surfaces — `Types.ts`'s
31
+ * `Fabricated` note records that same check breaking from a constraint on
32
+ * `$Schema`. The return is `Schema`, not polymorphic `this`, because
33
+ * `T.date.past` / `T.number.integer` / `T.symbol` are `Schema & { whereby, … }`
34
+ * and a `this` return is not assignable into those extra members — same as
35
+ * `.as()`.
34
36
  */
35
37
  export type SatisfiesThis<$Produced, $Target> = [$Produced] extends [$Target] ? unknown : {
36
38
  "schema produces": $Produced;
@@ -60,8 +62,8 @@ export declare function schemaSatisfies<$Receiver>(this: $Receiver): $Receiver;
60
62
  * `note?: string | undefined` (present, present-as-`undefined`, or omitted).
61
63
  * `T.omittable` produces `note?: string` and does.
62
64
  */
63
- export type SatisfiedBy<$Target, $Buildable> = ValueOf<$Buildable> extends $Target ? true : {
64
- produces: ValueOf<$Buildable>;
65
+ export type SatisfiedBy<$Target, $Buildable> = Fabricated<$Buildable> extends $Target ? true : {
66
+ produces: Fabricated<$Buildable>;
65
67
  required: $Target;
66
68
  };
67
69
  /**
@@ -71,14 +73,20 @@ export type SatisfiedBy<$Target, $Buildable> = ValueOf<$Buildable> extends $Targ
71
73
  *
72
74
  * `fabricate?: never` on the Schema arm is required. A built Fabricator has no
73
75
  * `[Produces]`, and a type that lacks an optional property still matches `{
74
- * readonly [Produces]?: $Target }` — the same trap `ValueOf` documents at
75
- * `Types.ts`. Without the exclusion, a non-conforming Fabricator would pass the
76
- * Schema arm unchecked. Ordered overloads do not replace this: overload
77
- * resolution falls through a failing overload onto the next one, so a
78
- * Fabricator rejected by `NaiveFabricator<$Target>` would still be accepted by
79
- * the Schema arm.
76
+ * readonly [Produces]?: Produced<$Target> }` — the same trap `Types.ts`'s
77
+ * `Fabricated` documents at `Types.ts`. Without the exclusion, a non-conforming
78
+ * Fabricator would pass the Schema arm unchecked. Ordered overloads do not
79
+ * replace this: overload resolution falls through a failing overload onto the
80
+ * next one, so a Fabricator rejected by `NaiveFabricator<$Target>` would still
81
+ * be accepted by the Schema arm.
82
+ *
83
+ * The Schema arm matches through the box (`Produced<$Target>`, `../Types.ts`),
84
+ * never `[Produces]?: $Target`: a caller compiling without
85
+ * `exactOptionalPropertyTypes` reads that optional slot as `$Target |
86
+ * undefined`, so a schema that may produce `undefined` would pass a target that
87
+ * excludes it.
80
88
  */
81
89
  export declare function satisfies<$Target>(buildable: NaiveFabricator<$Target> | (Buildable & {
82
90
  fabricate?: never;
83
- readonly [Produces]?: $Target;
91
+ readonly [Produces]?: Produced<$Target>;
84
92
  })): void;
@@ -1,7 +1,7 @@
1
1
  import type { Adaptations } from "../Adapter/Types";
2
2
  import type { NaiveFabricator } from "../Fabricator/Types";
3
3
  import type { Kind as SchemaKind } from "../Primitive";
4
- import type { Adaptation, Kind, Meta, Produces } from "../Types";
4
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../Types";
5
5
  import type { PlainObject } from "../Utility/Types";
6
6
  /**
7
7
  * The broadest Schema constraint: some kind, some config. Used by compound
@@ -25,7 +25,8 @@ export type AnySchema = {
25
25
  * `fabricate: () => $T` already plays for `NaiveFabricator<infer $T>`, one step
26
26
  * earlier, before a Schema has been built. `[Produces]` is always optional
27
27
  * (never assigned at runtime — see `DeepMerge`'s handling of optional-only keys
28
- * for why that matters).
28
+ * for why that matters), and what it holds is the value type boxed,
29
+ * `Produced<…>` (`Types.ts`), never the value type itself.
29
30
  *
30
31
  * A built Fabricator carries no `[Produces]` — its value type lives on
31
32
  * `fabricate: () => $T` (`Fabricator/Types.ts`) — yet `toSchema` lets one stand
@@ -55,25 +56,37 @@ export type AnySchema = {
55
56
  * this is closer to a de-Bruijn-style resolution environment — kept as a tuple,
56
57
  * as TypeBox's is, so a second bound self-reference could occupy index 1 later
57
58
  * without restructuring, though nothing today defines what that would mean.
58
- * `test/ValueOfBindings.types.test.ts` is the only thing asserting any of it.
59
+ * `test/FabricatedBindings.types.test.ts` is the only thing asserting any of
60
+ * it.
59
61
  *
60
62
  * Three details here are load-bearing, and each looks simplifiable:
61
63
  *
62
64
  * - **Indexed access, not a conditional `infer`.** Writing this as `($Schema & {
63
- * bindings: $Bindings }) extends { [Produces]?: infer $T } ? ...` fails with
64
- * `TS2615` — the bindings do not collapse, and the error surfaces as
65
- * `unknown[] & [...]`.
66
- * - **`Required<>`, never `Exclude<..., undefined>`.** Both strip the `|
67
- * undefined` that indexing an optional property adds, but `Exclude` also
68
- * strips the _legitimate_ `undefined` out of
69
- * `nullish`/`undefinable`/`object.optional`/`undefined`'s own value types.
70
- * - **The `extends` guard belongs inside, not on the parameter.** Constraining
71
- * `$Schema` instead would force `[Produces]` onto `AnySchema` (which
72
- * deliberately omits it), and that shifts variance enough to break `.as`'s
73
- * contravariant parameter check in `Fabrication.types.test.ts`.
65
+ * bindings: $Bindings }) extends { [Produces]?: Produced<infer $T> } ? ...`
66
+ * fails with `TS2615` — the bindings do not collapse, and the error surfaces
67
+ * as `unknown[] & [...]`.
68
+ * - **`Exclude<…, undefined>` is applied to the box, never to a value type.**
69
+ * Indexing an optional property adds `| undefined`, and `Exclude` strips
70
+ * every `undefined` in the union it is handed. That is exact only because the
71
+ * union is `Produced<…> | undefined`: the box is never `undefined`, so the
72
+ * one stripped is the modifier's, and the _legitimate_ `undefined` in
73
+ * `nullish`/`undefinable`/`object.optional`/`undefined`'s own value types
74
+ * sits inside the box, out of reach. No reader of an _unboxed_ value type can
75
+ * be exact: `Required<>` spares a declared `undefined` only when the consumer
76
+ * compiles with `exactOptionalPropertyTypes`, and strips it like `Exclude`
77
+ * when they do not. `Required<…>[typeof Produces]["value"]` is not a way to
78
+ * keep `Required<>` either — it fails `TS2536`.
79
+ * `test/Fabricated.types.test.ts`, compiled with the flag off by
80
+ * `tsconfig.inexact.json`, is the guard.
81
+ * - **The `extends` guard names the box, and belongs inside, not on the
82
+ * parameter.** Matched against `{ [Produces]?: unknown }`, the read has no
83
+ * `"value"` to index (`TS2536`). Constraining `$Schema` instead would force
84
+ * `[Produces]` onto `AnySchema` (which deliberately omits it), and that
85
+ * shifts variance enough to break `.as`'s contravariant parameter check in
86
+ * `Fabrication.types.test.ts`.
74
87
  */
75
- export type ValueOf<$Schema, $Bindings extends unknown[] = []> = $Schema extends NaiveFabricator<infer $T> ? $T : $Schema extends {
76
- readonly [Produces]?: unknown;
77
- } ? Required<$Schema & {
88
+ export type Fabricated<$Schema, $Bindings extends unknown[] = []> = $Schema extends NaiveFabricator<infer $T> ? $T : $Schema extends {
89
+ readonly [Produces]?: Produced<unknown>;
90
+ } ? Exclude<($Schema & {
78
91
  bindings: $Bindings;
79
- }>[typeof Produces] : unknown;
92
+ })[typeof Produces], undefined>["value"] : unknown;
@@ -5,6 +5,30 @@ export declare const Meta: unique symbol;
5
5
  export declare const Produces: unique symbol;
6
6
  export declare const Replace: unique symbol;
7
7
  export declare const Fixed: unique symbol;
8
+ /**
9
+ * What a Schema's phantom `[Produces]` holds: its value type, boxed.
10
+ *
11
+ * `[Produces]` is optional, and reading an optional property always yields `|
12
+ * undefined`. Whether that `undefined` can be told apart from one the value
13
+ * type itself contains depends on the _reader's_ `exactOptionalPropertyTypes`.
14
+ * With the flag on, the modifier contributes a distinct "missing" marker that
15
+ * `Required<>` strips on its own. With it off, the property is a plain `X |
16
+ * undefined`, and nothing recovers whether `X` held an `undefined` of its own —
17
+ * `Required<>` strips it exactly as `Exclude<…, undefined>` does, and inferring
18
+ * `$T` against `{ [Produces]?: $T }` absorbs it into the optional slot. A
19
+ * consumer compiles this library's declarations under their own tsconfig, so
20
+ * the flag is not this package's to choose.
21
+ *
22
+ * Boxed, the modifier's `undefined` sits beside the box and the value type's
23
+ * sits inside it, so the two never share a union. Stripping `undefined` off
24
+ * `Produced<X> | undefined` is exact under either setting — for `Fabricated`
25
+ * (`Schema/Types.ts`), and for anything that matches or infers through the
26
+ * brand, which has to name the box too: `{ readonly [Produces]?: Produced<$T>
27
+ * }`, never `{ readonly [Produces]?: $T }`.
28
+ */
29
+ export type Produced<$T> = {
30
+ readonly value: $T;
31
+ };
8
32
  /**
9
33
  * Tags a `Salt` as composing onto whatever base is in effect, rather than
10
34
  * replacing it — the reading a bare `salt` has everywhere else in this library.
@@ -97,6 +97,26 @@ export { registry } from "./Schema/Registry";
97
97
  */
98
98
  export { effectiveDiscrete, toBound } from "./Bound";
99
99
  export type { Bound, InputBound } from "./Bound";
100
+ /**
101
+ * The `length` shapes `T.string`/`T.array`'s `.whereby(...)` accept and store,
102
+ * and the `distribution` every range-bearing `whereby` takes. Exported so a
103
+ * `whereby` argument built programmatically, or read back off a schema's `meta`
104
+ * in an `.adapt` producer, can be typed — the same rationale as `Bound`.
105
+ * `Distribution` is type-only: a distribution is written as its plain tagged
106
+ * object (`{ kind: "skew", exponent: 4 }`), and the type's namespace members
107
+ * (`Distribution.Normal`, …) name each variant.
108
+ */
109
+ export type { Distribution, Range } from "./Distribution";
110
+ export type { InputLength, Length } from "./Bound";
111
+ /**
112
+ * `T.string`'s `composition` vocabulary: the class-weighting and `[weight,
113
+ * source]` forms, and the sources the second form draws from. `classes` holds
114
+ * each built-in class as its code point ranges, so the pair form can mix a
115
+ * class with an arbitrary range (`[[3, classes.lowercase], [1, unicode.bmp]]`);
116
+ * `unicode` holds codespace presets and `range(from, to)`.
117
+ */
118
+ export type { CharacterClass, CharacterSource, CodepointRange, Composition, } from "./Primitive/string/Types";
119
+ export { classes, unicode } from "./Primitive/string/Constants";
100
120
  /**
101
121
  * Public because it is the type of `ProduceContext`'s `random` member — the
102
122
  * seeded stream every kind's `.as(produce)` and `T.opaque`'s producer are
@@ -138,17 +158,11 @@ export type { Adapting } from "./Adapter/Types";
138
158
  */
139
159
  export type { Salt } from "./Random/Types";
140
160
  /**
141
- * Reads the value type a built Fabricator produces straight off its `fabricate`
142
- * signature — `Fabrication<typeof Product>` instead of `ReturnType<typeof
143
- * Product.fabricate>`.
144
- */
145
- export type { Fabrication } from "./Fabricator/Types";
146
- /**
147
- * Reads the value type a Schema (not yet built) will eventually produce, via
148
- * its phantom `[Produces]` marker. Mostly useful for a helper that accepts a
149
- * Schema before it's built into a Fabricator.
161
+ * Reads the value type a Schema produces, via its phantom `[Produces]` marker —
162
+ * before it is built, which is what a helper accepting a Schema needs — or the
163
+ * value type a built Fabricator produces, off its `fabricate` signature.
150
164
  */
151
- export type { ValueOf } from "./Schema/Types";
165
+ export type { Fabricated } from "./Schema/Types";
152
166
  /**
153
167
  * Check that a Schema or built Fabricator produces a value assignable to a
154
168
  * supplied type — `.satisfies<T>()` on every kind's Schema is the main form;
@@ -35,15 +35,22 @@ export type { Fabrication, NaiveFabricator } from "./Fabricator/Types";
35
35
  * a per-kind stand-in — a second copy of this mapping, susceptible to drift.
36
36
  */
37
37
  export type { AsFabricator } from "./Fabricator/Types";
38
- export { Children, Kind, Meta, Produces, type Buildable } from "./Types";
39
- export { isPlainObject } from "./Utility/Core";
38
+ /**
39
+ * `Produced` travels with `Produces`: `[Produces]` holds a Schema's value type
40
+ * boxed, so anything outside this package that matches or infers through the
41
+ * brand has to name the box — `{ readonly [Produces]?: Produced<$T> }`. See
42
+ * `Types.ts` for why an unboxed `{ readonly [Produces]?: $T }` cannot be read
43
+ * exactly.
44
+ */
45
+ export { Children, Kind, Meta, Produces, type Buildable, type Produced, } from "./Types";
46
+ export { isArray, isPlainObject } from "./Utility/Core";
40
47
  export type * as Primitive from "./Primitive/namespace";
41
48
  /**
42
49
  * `Schema/Types.ts`'s own value-type resolution, needed by tests asserting
43
- * `ValueOf<...>` directly rather than through a built Fabricator's
50
+ * `Fabricated<...>` directly rather than through a built Fabricator's
44
51
  * `Fabrication<...>`.
45
52
  */
46
- export type { ValueOf } from "./Schema/Types";
53
+ export type { Fabricated } from "./Schema/Types";
47
54
  /**
48
55
  * `Constructor` is `Instance.Fabricator`'s own type — public in effect (every
49
56
  * `initialize()` caller receives one), just never named directly by the `.`
@@ -71,6 +78,19 @@ export type { Algorithm, ConstructionPins, ConstructionTrace, ConstructorOptions
71
78
  * registry guards or `.fabricate()` in between.
72
79
  */
73
80
  export { weighted } from "./Distribution";
81
+ /**
82
+ * The normal CDF the `normal` distribution's truncation is computed with. The
83
+ * docs site's distribution explorer draws each variant's exact density, and a
84
+ * truncated normal's density divides by the mass this function measures —
85
+ * importing it rather than restating the approximation keeps the plotted curve
86
+ * normalized exactly as `sampler` truncates.
87
+ *
88
+ * `normalInv` is its inverse, the quantile `sampler` maps a truncated unit draw
89
+ * through. `@ghostry/fabricator-census` imports both to score a fitted `normal`
90
+ * against the exact curve fabrication will draw from, rather than against a
91
+ * second approximation that could disagree with it in the tails.
92
+ */
93
+ export { normalCdf, normalInv } from "./Distribution";
74
94
  /**
75
95
  * The synchronous ambient carrier. `#stack` (`package.json`) selects it only
76
96
  * where there is no `node:async_hooks` — in practice a browser bundle — so on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostry/fabricator",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "description": "Fabricate typed data from composable schemas.",
6
6
  "keywords": [
@@ -76,8 +76,8 @@
76
76
  "build:clean": "find ./dist -type f -name '*.tsbuildinfo' -delete",
77
77
  "build": "bun run build:reset && bun run build:compile && bun run build:types && bun run build:verify && bun run build:clean",
78
78
  "build:rsdoctor": "bun run build:reset && bun run build:compile:rsdoctor && bun run build:types && bun run build:verify && bun run build:clean",
79
- "check": "tsc --noEmit",
80
- "check:ts5": "bun --bun ../../node_modules/typescript-5/lib/tsc.js --noEmit",
79
+ "check": "tsc --noEmit && tsc --noEmit -p ./tsconfig.inexact.json",
80
+ "check:ts5": "bun --bun ../../node_modules/typescript-5/lib/tsc.js --noEmit && bun --bun ../../node_modules/typescript-5/lib/tsc.js --noEmit -p ./tsconfig.inexact.json",
81
81
  "check:jsr": "DENO_BIN_PATH=$PWD/../../node_modules/.bin/deno bunx --no-install jsr publish --dry-run --allow-dirty",
82
82
  "format": "bunx --no-install oxfmt .",
83
83
  "test": "bun run check && bun run check:ts5 && bun run check:jsr && bun test"