@ghostry/fabricator 0.0.9 → 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 (45) hide show
  1. package/dist/esm/Distribution/index.js +43 -11
  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 -1
  6. package/dist/types/Adapter/Types.d.ts +3 -2
  7. package/dist/types/Distribution/index.d.ts +32 -2
  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/Registry.d.ts +3 -3
  15. package/dist/types/Primitive/choice/Types.d.ts +4 -4
  16. package/dist/types/Primitive/date/Types.d.ts +2 -2
  17. package/dist/types/Primitive/derive/Types.d.ts +2 -2
  18. package/dist/types/Primitive/enum/Registry.d.ts +3 -3
  19. package/dist/types/Primitive/enum/Types.d.ts +2 -2
  20. package/dist/types/Primitive/null/Types.d.ts +2 -2
  21. package/dist/types/Primitive/nullable/Types.d.ts +4 -4
  22. package/dist/types/Primitive/nullish/Types.d.ts +4 -4
  23. package/dist/types/Primitive/number/Types.d.ts +2 -2
  24. package/dist/types/Primitive/object/Types.d.ts +9 -9
  25. package/dist/types/Primitive/object/compute/Types.d.ts +4 -4
  26. package/dist/types/Primitive/object/omittable/Types.d.ts +4 -4
  27. package/dist/types/Primitive/object/optional/Types.d.ts +4 -4
  28. package/dist/types/Primitive/opaque/Types.d.ts +2 -2
  29. package/dist/types/Primitive/record/Types.d.ts +11 -6
  30. package/dist/types/Primitive/recursive/Types.d.ts +12 -8
  31. package/dist/types/Primitive/recursive/self/Schema.d.ts +4 -4
  32. package/dist/types/Primitive/recursive/self/Types.d.ts +7 -5
  33. package/dist/types/Primitive/string/Constants.d.ts +7 -31
  34. package/dist/types/Primitive/string/Types.d.ts +2 -2
  35. package/dist/types/Primitive/symbol/Types.d.ts +2 -2
  36. package/dist/types/Primitive/tuple/Types.d.ts +7 -7
  37. package/dist/types/Primitive/undefinable/Types.d.ts +4 -4
  38. package/dist/types/Primitive/undefined/Types.d.ts +2 -2
  39. package/dist/types/Schema/Core.d.ts +10 -6
  40. package/dist/types/Schema/Satisfies.d.ts +31 -23
  41. package/dist/types/Schema/Types.d.ts +31 -18
  42. package/dist/types/Types.d.ts +24 -0
  43. package/dist/types/index.d.ts +24 -10
  44. package/dist/types/internal.d.ts +31 -4
  45. package/package.json +3 -3
@@ -144,7 +144,10 @@ function normalInv(p) {
144
144
  }
145
145
  function sample(list, stream) {
146
146
  if (0 === list.length) throw new FabricatorError.EmptyItemsError("sample", "item");
147
- const index = Math.floor(stream.next() * list.length);
147
+ const index = discreteSampler(void 0, {
148
+ min: 0,
149
+ max: list.length - 1
150
+ }, stream)();
148
151
  const item = list[index];
149
152
  return item;
150
153
  }
@@ -193,17 +196,46 @@ function assertDrawableKeyedWeights(label, outcomes, weights) {
193
196
  if (0 === drawableOutcomes(outcomes, weights).length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
194
197
  }
195
198
  function weighted(weights, stream, label) {
196
- let sum = 0;
197
- const weightings = weights.filter(([weight])=>isDrawable(weight)).map(([weight, item])=>[
198
- sum += weight,
199
- item
200
- ]);
201
- if (0 === weightings.length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
199
+ const drawable = weights.filter(([weight])=>isDrawable(weight));
200
+ if (0 === drawable.length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
201
+ const items = drawable.map(([, item])=>item);
202
+ const column = discreteSampler(void 0, {
203
+ min: 0,
204
+ max: items.length - 1
205
+ }, stream);
206
+ const [first] = drawable[0];
207
+ if (drawable.every(([weight])=>weight === first)) return ()=>items[column()];
208
+ const table = toAliasTable(drawable.map(([weight])=>weight));
202
209
  return ()=>{
203
- const x = stream.next() * sum;
204
- const chosen = weightings.find(([weight])=>x < weight);
205
- return chosen[1];
210
+ const i = column();
211
+ const probability = table.probability[i];
212
+ if (1 === probability) return items[i];
213
+ return items[stream.next() < probability ? i : table.alias[i]];
214
+ };
215
+ }
216
+ function toAliasTable(weights) {
217
+ const n = weights.length;
218
+ const sum = weights.reduce((total, weight)=>total + weight, 0);
219
+ const scaled = weights.map((weight)=>weight * n / sum);
220
+ const probability = new Float64Array(n);
221
+ const aliases = new Uint32Array(n);
222
+ const small = [];
223
+ const large = [];
224
+ for(let i = 0; i < n; i++)(scaled[i] < 1 ? small : large).push(i);
225
+ while(small.length > 0 && large.length > 0){
226
+ const less = small.pop();
227
+ const more = large.pop();
228
+ probability[less] = scaled[less];
229
+ aliases[less] = more;
230
+ scaled[more] = scaled[more] + scaled[less] - 1;
231
+ (scaled[more] < 1 ? small : large).push(more);
232
+ }
233
+ for (const i of large)probability[i] = 1;
234
+ for (const i of small)probability[i] = 1;
235
+ return {
236
+ probability,
237
+ alias: aliases
206
238
  };
207
239
  }
208
240
  var Distribution_Distribution;
209
- export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, discreteSampler, drawableOutcomes, isDrawable, isValidWeight, sample, sampler, shuffle, weighted };
241
+ export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, discreteSampler, drawableOutcomes, isDrawable, isValidWeight, normalCdf, normalInv, sample, sampler, shuffle, weighted };
@@ -1,9 +1,8 @@
1
- import { Kind, Meta, Produces } from "../../Types.js";
1
+ import { Kind, Meta } from "../../Types.js";
2
2
  import { Schema } from "./Schema.js";
3
3
  const registry = Schema({
4
4
  [Kind]: "null",
5
- [Meta]: {},
6
- [Produces]: null
5
+ [Meta]: {}
7
6
  });
8
7
  const Registry = registry;
9
8
  export default Registry;
@@ -1,9 +1,8 @@
1
- import { Kind, Meta, Produces } from "../../Types.js";
1
+ import { Kind, Meta } from "../../Types.js";
2
2
  import { Schema } from "./Schema.js";
3
3
  const registry = Schema({
4
4
  [Kind]: "undefined",
5
- [Meta]: {},
6
- [Produces]: void 0
5
+ [Meta]: {}
7
6
  });
8
7
  const Registry = registry;
9
8
  export default Registry;
package/dist/esm/index.js CHANGED
@@ -9,6 +9,7 @@ export { layer } from "./Random/index.js";
9
9
  export { FabricatorError } from "./Error/index.js";
10
10
  export { registry } from "./Schema/Registry.js";
11
11
  export { effectiveDiscrete, toBound } from "./Bound.js";
12
+ export { classes, unicode } from "./Primitive/string/Constants.js";
12
13
  export { sample, shuffle } from "./Distribution/index.js";
13
14
  export { satisfies } from "./Schema/Satisfies.js";
14
15
  export { initialize };
@@ -1,5 +1,6 @@
1
1
  export { Children, Kind, Meta, Produces } from "./Types.js";
2
- export { isPlainObject } from "./Utility/Core.js";
2
+ export { isArray, isPlainObject } from "./Utility/Core.js";
3
3
  export { plan, resolve } from "./Enumeration/Plan.js";
4
4
  export { defaultAlgorithm, encode, randomSalt, toRandomSource, toStream, toStreamFromTrace } from "./Random/index.js";
5
+ export { normalCdf, normalInv, weighted } from "./Distribution/index.js";
5
6
  export { toStack as toSynchronousStack } from "./Instance/Stack/Sync.js";
@@ -101,7 +101,8 @@ export type Recurse<$Context, $Returnable> = (schema: any, context: $Context) =>
101
101
  * package declares its own conversion entry point with its own return type
102
102
  * (`toTypeBox<$S>(schema: $S): ToTypeBox<$S>`), so nothing has to compute a
103
103
  * type-level mapping out of a stored value — which would need the
104
- * interface-member-lookup encoding `ValueOf`'s `$Bindings` uses, for no gain.
104
+ * interface-member-lookup encoding `Fabricated`'s `$Bindings` uses, for no
105
+ * gain.
105
106
  */
106
107
  export interface Adapter<$Key extends string = string, $Context = unknown, $Returnable = unknown> {
107
108
  readonly key: $Key;
@@ -115,7 +116,7 @@ export interface Adapter<$Key extends string = string, $Context = unknown, $Retu
115
116
  * and why no adapter matches `{ [Adaptation]?: Record<Key, ...> }` directly.
116
117
  * Every kind's `Core` declares `[Adaptation]` as _optional_, and a conditional
117
118
  * matching an optional property against a schema that lacks it entirely still
118
- * _succeeds_, inferring `unknown` (the same behavior `ValueOf` relies on for
119
+ * _succeeds_, inferring `unknown` (the same behavior `Fabricated` relies on for
119
120
  * `[Produces]`) — so a direct match would resolve every unadapted schema to
120
121
  * whatever the adapter's adaptation branch produces. Constraining the `infer`
121
122
  * sends that case here, to `{}`, which then fails each adapter's `Record<Key,
@@ -110,6 +110,16 @@ export declare function discreteSampler(distribution: Distribution | undefined,
110
110
  * clamped.
111
111
  */
112
112
  export declare function sampler(distribution: Distribution, range: Range, stream: Stream): () => number;
113
+ /**
114
+ * Standard normal CDF via the Abramowitz & Stegun 7.1.26 approximation of the
115
+ * error function (|error| < 1.5e-7).
116
+ */
117
+ export declare function normalCdf(x: number): number;
118
+ /**
119
+ * Inverse of the standard normal CDF (quantile function) via Peter Acklam's
120
+ * rational approximation (relative error < 1.15e-9).
121
+ */
122
+ export declare function normalInv(p: number): number;
113
123
  /**
114
124
  * A uniform pick from `list`. One `stream.next()` per call; `list` is not
115
125
  * mutated. An empty list throws {@link FabricatorError.EmptyItemsError} — there
@@ -134,8 +144,9 @@ export declare function isDrawable(weight: number): boolean;
134
144
  * Whether a weight is _expressible_ at all, as opposed to whether it is
135
145
  * drawable. `0` is valid and disables the outcome; a negative weight or `NaN`
136
146
  * is a mistake. `Infinity` is rejected because it cannot be summed into a
137
- * usable draw table — every cumulative bound becomes `Infinity`, so
138
- * `weighted()`'s `x < weight` scan matches nothing.
147
+ * usable draw table — the sum becomes `Infinity`, so `weighted()`'s alias
148
+ * scaling (`weight * n / sum`) yields `NaN` for the infinite entry and `0` for
149
+ * every other.
139
150
  */
140
151
  export declare function isValidWeight(weight: number): boolean;
141
152
  /**
@@ -166,4 +177,23 @@ export declare function assertDrawableWeights(label: string, noun: string, items
166
177
  * defaulted in stage 2.
167
178
  */
168
179
  export declare function assertDrawableKeyedWeights<$Outcome extends string>(label: string, outcomes: ReadonlyArray<$Outcome>, weights: Readonly<Record<string, number | undefined>>): void;
180
+ /**
181
+ * A pick over `weights`, in O(1) per call regardless of table size. The table
182
+ * is built once, here, during `new Fabricator(...)`; the returned closure is
183
+ * what `.fabricate()` calls.
184
+ *
185
+ * Two paths, chosen at construction:
186
+ *
187
+ * - **Equal weights** (every `.uniform(...)` registry, every default-weighted
188
+ * presence wrapper) need no table at all: the pick is `discreteSampler`'s
189
+ * uniform index draw, one `stream.next()` per call.
190
+ * - **Unequal weights** use Vose's alias method (see {@link toAliasTable}): draw
191
+ * a column with that same index draw, then a second `stream.next()` as a coin
192
+ * between the column's own item and its alias. The coin is a separate draw
193
+ * rather than the fractional remainder of the first, because that remainder
194
+ * keeps only `53 - log2(n)` bits, which coarsens the probabilities as the
195
+ * table grows. A column whose probability is `1` returns without drawing the
196
+ * coin; the draw count stays a pure function of the stream, so this is still
197
+ * replayable.
198
+ */
169
199
  export declare function weighted<const $Item>(weights: ReadonlyArray<readonly [number, $Item]>, stream: Stream, label: string): () => $Item;
@@ -1,5 +1,5 @@
1
1
  import type { Kind as SchemaKind } from "../Primitive";
2
- import type { AnySchema, ValueOf } from "../Schema/Types";
2
+ import type { AnySchema, Fabricated } from "../Schema/Types";
3
3
  import type { Children, Kind, Meta } from "../Types";
4
4
  import type { PlainObject } from "../Utility/Types";
5
5
  /**
@@ -71,9 +71,9 @@ export type Limits = {
71
71
  * The shape both `combinatorial` and `coverage` share — strategy and limit
72
72
  * differ internally, neither visible here. Takes a Schema, not a built
73
73
  * Fabricator: `AnySchema` excludes `Fabricator<any>` (which carries no
74
- * `[Produces]`), so `ValueOf` can't silently degrade to `unknown`.
74
+ * `[Produces]`), so `Fabricated` can't silently degrade to `unknown`.
75
75
  */
76
- export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Iterable<ValueOf<$Schema>>;
76
+ export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Iterable<Fabricated<$Schema>>;
77
77
  export type Resolvable = {
78
78
  [Kind]: SchemaKind;
79
79
  [Meta]: PlainObject<any>;
@@ -1,8 +1,8 @@
1
1
  import type { Adaptations, AdaptationsOf } from "../Adapter/Types";
2
2
  import type { Primitive, Kind as SchemaKind } from "../Primitive";
3
3
  import type { Algorithm, Trace } from "../Random/Types";
4
- import type { ValueOf } from "../Schema/Types";
5
- import type { Adaptation, Kind, Meta, Produces } from "../Types";
4
+ import type { Fabricated } from "../Schema/Types";
5
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../Types";
6
6
  import type { PlainObject } from "../Utility/Types";
7
7
  /**
8
8
  * Threaded through `Constructor.ts`'s `make` for every dispatch of one `new
@@ -89,9 +89,9 @@ export type Fabricator<$T> = NaiveFabricator<$T> & {
89
89
  * `fabricate` signature. Every kind's `construct()` output shares the exact
90
90
  * same shape (`NaiveFabricator<$T>` plus `[Kind]`/`[Meta]`, see this file's
91
91
  * `Fabricator<$T>`), so there's nothing to dispatch per kind here — unlike
92
- * `ValueOf`, which reads a Schema's phantom `[Produces]` marker for the
93
- * pre-`construct()` case, this only ever needs to unwrap an already-uniform
94
- * `fabricate: () => $T`.
92
+ * `Schema/Types.ts`'s `Fabricated`, which reads a Schema's phantom `[Produces]`
93
+ * marker for the pre-`construct()` case, this only ever needs to unwrap an
94
+ * already-uniform `fabricate: () => $T`.
95
95
  */
96
96
  export type Fabrication<$Fabricator extends NaiveFabricator<any>> = $Fabricator extends NaiveFabricator<infer $T> ? $T : never;
97
97
  /**
@@ -100,7 +100,7 @@ export type Fabrication<$Fabricator extends NaiveFabricator<any>> = $Fabricator
100
100
  * carries a required `as` method a built Fabricator never has) to the precise,
101
101
  * kind-specific `Fabricator<...>` type it builds into. Mirrors
102
102
  * `Adapter/TypeBox/index.ts`'s `ToTypeBox` dispatch. Falls back to the loose
103
- * base `Fabricator<ValueOf<$Schema>>` for anything unmatched.
103
+ * base `Fabricator<Fabricated<$Schema>>` for anything unmatched.
104
104
  *
105
105
  * No branch here needs to do anything about `[Adaptation]`: each kind's own
106
106
  * `Fabricator<$Schema>` reads it back off `$Schema` via `AdaptationsOf`, so an
@@ -139,5 +139,5 @@ $Schema extends Primitive.object.Core ? Primitive.object.Fabricator<$Schema> : $
139
139
  * (unbound) is the same default `self.Core` itself falls back to.
140
140
  */
141
141
  $Schema extends Primitive.recursive.self.Core ? Primitive.recursive.self.Fabricator<[]> : $Schema extends Primitive.tuple.Core ? Primitive.tuple.Fabricator<$Schema> : $Schema extends Primitive.derive.Core ? Primitive.derive.Fabricator<$Schema> : $Schema extends Primitive.always.Core ? Primitive.always.Fabricator<$Schema> : $Schema extends Primitive.bigint.Core ? Primitive.bigint.Fabricator<$Schema> : $Schema extends Primitive.boolean.Core ? Primitive.boolean.Fabricator<$Schema> : $Schema extends Primitive.choice.Core ? Primitive.choice.Fabricator<$Schema> : $Schema extends Primitive.enum.Core ? Primitive.enum.Fabricator<$Schema> : $Schema extends Primitive.date.Core ? Primitive.date.Fabricator<$Schema> : $Schema extends Primitive.number.Core ? Primitive.number.Fabricator<$Schema> : $Schema extends Primitive.string.Core ? Primitive.string.Fabricator<$Schema> : $Schema extends Primitive.symbol.Core ? Primitive.symbol.Fabricator<$Schema> : $Schema extends Primitive.undefined.Core ? Primitive.undefined.Fabricator<$Schema> : $Schema extends Primitive.undefinable.Core ? Primitive.undefinable.Fabricator<$Schema> : $Schema extends Primitive.null.Core ? Primitive.null.Fabricator<$Schema> : $Schema extends Primitive.nullable.Core ? Primitive.nullable.Fabricator<$Schema> : $Schema extends Primitive.nullish.Core ? Primitive.nullish.Fabricator<$Schema> : $Schema extends {
142
- readonly [Produces]?: unknown;
143
- } ? Fabricator<ValueOf<$Schema>> : Fabricator<unknown>;
142
+ readonly [Produces]?: Produced<unknown>;
143
+ } ? Fabricator<Fabricated<$Schema>> : Fabricator<unknown>;
@@ -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
  /**
4
4
  * Any value at all. Deliberately unconstrained: fabricating a fixed value needs
5
5
  * nothing of it. A `string | number | boolean` cap would be TypeBox's
@@ -18,6 +18,6 @@ export type Meta<$Value extends Value = Value> = {
18
18
  export type Core<$Value extends Value = Value, $Adaptations extends Adaptations = {}> = {
19
19
  [Kind]: "always";
20
20
  [Meta]: Meta<$Value>;
21
- readonly [Produces]?: Fabricated<$Value>;
21
+ readonly [Produces]?: Produced<Fabricated<$Value>>;
22
22
  readonly [Adaptation]?: $Adaptations;
23
23
  };
@@ -1,10 +1,10 @@
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 { AnySchema, ValueOf } from "../../Schema/Types";
5
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
4
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
5
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
6
6
  export type Definition = AnySchema;
7
- export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Array<ValueOf<$Definition, $Bindings>>;
7
+ export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Array<FabricatedBy<$Definition, $Bindings>>;
8
8
  export type InputWhereby = {
9
9
  length: InputLength;
10
10
  };
@@ -33,6 +33,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
33
33
  [Kind]: "array";
34
34
  [Meta]: Meta<$Definition>;
35
35
  bindings?: unknown[];
36
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
36
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
37
37
  readonly [Adaptation]?: $Adaptations;
38
38
  }
@@ -1,7 +1,7 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { Bound, InputBound } 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
  export type InputWhereby = {
6
6
  min?: InputBound<bigint> | undefined;
7
7
  max: InputBound<bigint>;
@@ -28,6 +28,6 @@ export type Meta = {
28
28
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
29
29
  [Kind]: "bigint";
30
30
  [Meta]: $Meta;
31
- readonly [Produces]?: Fabricated;
31
+ readonly [Produces]?: Produced<Fabricated>;
32
32
  readonly [Adaptation]?: $Adaptations;
33
33
  };
@@ -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 = boolean;
5
5
  export type Weights = {
6
6
  true: number;
@@ -21,6 +21,6 @@ export type Meta = {
21
21
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
22
22
  [Kind]: "boolean";
23
23
  [Meta]: $Meta;
24
- readonly [Produces]?: Fabricated;
24
+ readonly [Produces]?: Produced<Fabricated>;
25
25
  readonly [Adaptation]?: $Adaptations;
26
26
  };
@@ -13,9 +13,9 @@ type Weighted<$Items extends ReadonlyArray<Item>> = {
13
13
  };
14
14
  /**
15
15
  * At least one element — a `choice` with no option has nothing to draw, which
16
- * would otherwise fail inside `weighted()` (`Distribution/index.ts`) with an
17
- * opaque `TypeError` at fabricate time (weight sum is `0`, so `.find` returns
18
- * `undefined` and `chosen![1]` throws).
16
+ * would otherwise surface only as `weighted()`'s (`Distribution/index.ts`)
17
+ * generic `NoDrawableOutcomesError` at construction, naming an "outcome" rather
18
+ * than this registry's own `EmptyItemsError` for an option.
19
19
  *
20
20
  * Only a _statically_ empty tuple (a literal `[]`) is a compile error. A
21
21
  * dynamically built array — e.g. `.map()` over an `as const` array — is
@@ -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 schemas a `choice` can draw from. */
6
6
  export type Item = AnySchema;
7
7
  /**
@@ -14,7 +14,7 @@ export type Item = AnySchema;
14
14
  * instead of always wrapping regardless of count.
15
15
  */
16
16
  export type Items = ReadonlyArray<readonly [number, Item]>;
17
- export type Fabricated<$Items extends Items = Items, $Bindings extends unknown[] = []> = ValueOf<$Items[number][1], $Bindings>;
17
+ export type Fabricated<$Items extends Items = Items, $Bindings extends unknown[] = []> = FabricatedBy<$Items[number][1], $Bindings>;
18
18
  /**
19
19
  * Always stored as weighted pairs — `.uniform(...)` (`Registry.ts`) is
20
20
  * `.weighted(...)` with every item given weight `1`, so there is only one shape
@@ -30,6 +30,6 @@ export interface Core<$Items extends Items = Items, $Adaptations extends Adaptat
30
30
  [Kind]: "choice";
31
31
  [Meta]: Meta<$Items>;
32
32
  bindings?: unknown[];
33
- readonly [Produces]?: Fabricated<$Items, NonNullable<this["bindings"]>>;
33
+ readonly [Produces]?: Produced<Fabricated<$Items, NonNullable<this["bindings"]>>>;
34
34
  readonly [Adaptation]?: $Adaptations;
35
35
  }
@@ -2,7 +2,7 @@ import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { Bound, InputBound } from "../../Bound";
3
3
  import type { Distribution } from "../../Distribution";
4
4
  import type { Produce } from "../../Random/Types";
5
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
5
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
6
6
  export type InputWhereby = {
7
7
  min?: InputBound<Date> | undefined;
8
8
  max?: InputBound<Date> | undefined;
@@ -29,6 +29,6 @@ export type Meta = {
29
29
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
30
30
  [Kind]: "date";
31
31
  [Meta]: $Meta;
32
- readonly [Produces]?: Fabricated;
32
+ readonly [Produces]?: Produced<Fabricated>;
33
33
  readonly [Adaptation]?: $Adaptations;
34
34
  };
@@ -1,6 +1,6 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { ProduceContext } from "../../Random/Types";
3
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
3
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
4
4
  import type { Resolved, Source } from "../object/compute/Types";
5
5
  import type * as tuple from "../tuple/Types";
6
6
  /**
@@ -33,6 +33,6 @@ export interface Core<$From extends From = From, $To extends Source = Source, $A
33
33
  [Kind]: "derive";
34
34
  [Meta]: Meta<$From, $To>;
35
35
  bindings?: unknown[];
36
- readonly [Produces]?: Resolved<$To, NonNullable<this["bindings"]>>;
36
+ readonly [Produces]?: Produced<Resolved<$To, NonNullable<this["bindings"]>>>;
37
37
  readonly [Adaptation]?: $Adaptations;
38
38
  }
@@ -14,9 +14,9 @@ type Weighted<$Items extends ReadonlyArray<Item>> = {
14
14
  };
15
15
  /**
16
16
  * At least one element — an `enum` with no member has nothing to draw, which
17
- * would otherwise fail inside `weighted()` (`Distribution/index.ts`) with an
18
- * opaque `TypeError` at fabricate time (weight sum is `0`, so `.find` returns
19
- * `undefined` and `chosen![1]` throws).
17
+ * would otherwise surface only as `weighted()`'s (`Distribution/index.ts`)
18
+ * generic `NoDrawableOutcomesError` at construction, naming an "outcome" rather
19
+ * than this registry's own `EmptyItemsError` for a member.
20
20
  *
21
21
  * Only a _statically_ empty tuple (a literal `[]`) is a compile error. A
22
22
  * dynamically built array — e.g. `.map()` over an `as const` array — is
@@ -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
  /**
5
5
  * The values an `enum` can draw from — any value at all, for the same reason
6
6
  * `always.Value` is unconstrained (see its doc).
@@ -37,6 +37,6 @@ export type Meta<$Items extends Items = Items> = {
37
37
  export type Core<$Items extends Items = Items, $Adaptations extends Adaptations = {}> = {
38
38
  [Kind]: "enum";
39
39
  [Meta]: Meta<$Items>;
40
- readonly [Produces]?: Fabricated<$Items>;
40
+ readonly [Produces]?: Produced<Fabricated<$Items>>;
41
41
  readonly [Adaptation]?: $Adaptations;
42
42
  };
@@ -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 = null;
4
4
  /**
5
5
  * Nothing to configure: `null` has exactly one possible value, so there is no
@@ -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]: "null";
12
12
  [Meta]: $Meta;
13
- readonly [Produces]?: Fabricated;
13
+ readonly [Produces]?: Produced<Fabricated>;
14
14
  readonly [Adaptation]?: $Adaptations;
15
15
  };
@@ -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 `null`. */
6
6
  export type Definition = AnySchema;
7
- export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = ValueOf<$Definition, $Bindings> | null;
7
+ export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings> | null;
8
8
  export type { Outcome } from "./Outcomes";
9
9
  /**
10
10
  * Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional — an
@@ -42,6 +42,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
42
42
  [Kind]: "nullable";
43
43
  [Meta]: Meta<$Definition>;
44
44
  bindings?: unknown[];
45
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
45
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
46
46
  readonly [Adaptation]?: $Adaptations;
47
47
  }
@@ -1,13 +1,13 @@
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
  /**
6
6
  * The wrapped schema — the value type produced when the roll lands on neither
7
7
  * `null` nor `undefined`.
8
8
  */
9
9
  export type Definition = AnySchema;
10
- export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = ValueOf<$Definition, $Bindings> | null | undefined;
10
+ export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings> | null | undefined;
11
11
  export type { Outcome } from "./Outcomes";
12
12
  /**
13
13
  * Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional — an
@@ -52,6 +52,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
52
52
  [Kind]: "nullish";
53
53
  [Meta]: Meta<$Definition>;
54
54
  bindings?: unknown[];
55
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
55
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
56
56
  readonly [Adaptation]?: $Adaptations;
57
57
  }
@@ -2,7 +2,7 @@ import type { Adaptations } from "../../Adapter/Types";
2
2
  import type { Bound, InputBound } from "../../Bound";
3
3
  import type { Distribution } from "../../Distribution";
4
4
  import type { Produce } from "../../Random/Types";
5
- import type { Adaptation, Kind, Meta, Produces } from "../../Types";
5
+ import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
6
6
  /**
7
7
  * Call-site `{ min, max }` — scalars are inclusive. Either end may be omitted;
8
8
  * a missing end is unbounded (the same policy as a bare `T.number`), not a
@@ -51,6 +51,6 @@ export type Meta = {
51
51
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
52
52
  [Kind]: "number";
53
53
  [Meta]: $Meta;
54
- readonly [Produces]?: Fabricated;
54
+ readonly [Produces]?: Produced<Fabricated>;
55
55
  readonly [Adaptation]?: $Adaptations;
56
56
  };
@@ -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 { Kind, Meta, type Adaptation, type Omitted, type Produces } from "../../Types";
3
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
4
+ import { Kind, Meta, type Adaptation, type Omitted, type Produced, type Produces } from "../../Types";
5
5
  import { type Pretty } from "../../Utility/Types";
6
6
  import type { Schema as ComputeSchema } from "./compute/Schema";
7
7
  export type Definition<$Schema = AnySchema> = {
@@ -23,7 +23,7 @@ export type Refinements = ReadonlyArray<Definition>;
23
23
  * `Fabricated` can mark exactly those `?:` instead of required — matching
24
24
  * runtime, where a field whose roll lands on omission never has its key appear
25
25
  * (`object/omittable/Fabricator.ts`, `object/optional/Fabricator.ts`).
26
- * `object.optional`'s `ValueOf` already carries `| undefined` (its
26
+ * `object.optional`'s `FabricatedBy` already carries `| undefined` (its
27
27
  * `Fabricated`), so combined with the `?:` here a field lands on `{ a?: T |
28
28
  * undefined }` — omitted, present-as-`undefined`, or present-with-a-value.
29
29
  */
@@ -33,9 +33,9 @@ type OmittableKeys<$Definition extends Definition> = {
33
33
  } ? $K : never;
34
34
  }[keyof $Definition];
35
35
  export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Pretty<{
36
- [$K in Exclude<keyof $Definition, OmittableKeys<$Definition>>]: ValueOf<$Definition[$K], $Bindings>;
36
+ [$K in Exclude<keyof $Definition, OmittableKeys<$Definition>>]: FabricatedBy<$Definition[$K], $Bindings>;
37
37
  } & {
38
- [$K in OmittableKeys<$Definition>]?: ValueOf<$Definition[$K], $Bindings>;
38
+ [$K in OmittableKeys<$Definition>]?: FabricatedBy<$Definition[$K], $Bindings>;
39
39
  }>;
40
40
  /**
41
41
  * The shape `.override()` accepts: every field optional, so a present key skips
@@ -43,8 +43,8 @@ export type Fabricated<$Definition extends Definition, $Bindings extends unknown
43
43
  * `Override` (deep-merge); an `object.omittable` or `object.optional` field
44
44
  * additionally accepts `Omitted`, to force that field off rather than only
45
45
  * forcing a value on (`object.optional` already accepts `undefined` via
46
- * `ValueOf`); every other field — including `object.compute` — is a
47
- * full-replacement leaf, typed as whatever it fabricates to (`ValueOf`).
46
+ * `FabricatedBy`); every other field — including `object.compute` — is a
47
+ * full-replacement leaf, typed as whatever it fabricates to (`FabricatedBy`).
48
48
  *
49
49
  * Checked via a bare structural `[Kind]`/`[Meta]` shape, never `Schema`/
50
50
  * `Fabricator` — either carries `refine`'s contravariant use of `$Definition`,
@@ -59,7 +59,7 @@ export type Override<$Definition extends Definition> = Pretty<{
59
59
  };
60
60
  } ? Override<$Nested> : $Definition[$K] extends {
61
61
  [Kind]: "object.omittable" | "object.optional";
62
- } ? ValueOf<$Definition[$K]> | typeof Omitted : ValueOf<$Definition[$K]>;
62
+ } ? FabricatedBy<$Definition[$K]> | typeof Omitted : FabricatedBy<$Definition[$K]>;
63
63
  }>;
64
64
  /**
65
65
  * `definition`/`refinements` stay required regardless of `produce` — an opaque
@@ -77,7 +77,7 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
77
77
  [Kind]: "object";
78
78
  [Meta]: Meta<$Definition>;
79
79
  bindings?: unknown[];
80
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
80
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
81
81
  readonly [Adaptation]?: $Adaptations;
82
82
  }
83
83
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { Adaptations } from "../../../Adapter/Types";
2
- import type { AnySchema, ValueOf } from "../../../Schema/Types";
3
- import { Kind, type Adaptation, type Meta, type Produces } from "../../../Types";
2
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../../Schema/Types";
3
+ import { Kind, type Adaptation, type Meta, type Produced, type Produces } from "../../../Types";
4
4
  /**
5
5
  * A builder that can mint a Schema via `as` — e.g. `T.string`, `T.bigint`.
6
6
  * `compute` accepts one alongside a plain Schema so a caller needn't satisfy a
@@ -24,7 +24,7 @@ export type Denoted<$Source> = $Source extends AnySchema ? $Source : $Source ext
24
24
  /**
25
25
  * The value a source resolves to: what the Schema it denotes fabricates to.
26
26
  */
27
- export type Resolved<$Source, $Bindings extends unknown[] = []> = ValueOf<Denoted<$Source>, $Bindings>;
27
+ export type Resolved<$Source, $Bindings extends unknown[] = []> = FabricatedBy<Denoted<$Source>, $Bindings>;
28
28
  /**
29
29
  * Source and resolver are stored raw — the source whether a Schema or a builder
30
30
  * (both carry a `[Kind]`, which is all schema derivation needs), and the
@@ -50,6 +50,6 @@ export interface Core<$Fabricated, $Source extends Source, $Adaptations extends
50
50
  [Kind]: "object.compute";
51
51
  [Meta]: Meta<$Fabricated, $Source>;
52
52
  bindings?: unknown[];
53
- readonly [Produces]?: Resolved<$Source, NonNullable<this["bindings"]>>;
53
+ readonly [Produces]?: Produced<Resolved<$Source, NonNullable<this["bindings"]>>>;
54
54
  readonly [Adaptation]?: $Adaptations;
55
55
  }
@@ -1,13 +1,13 @@
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 { Kind, Meta, Omitted, type Adaptation, type Produces } from "../../../Types";
3
+ import type { AnySchema, Fabricated as FabricatedBy } from "../../../Schema/Types";
4
+ import { Kind, Meta, Omitted, type Adaptation, type Produced, type Produces } from "../../../Types";
5
5
  /**
6
6
  * The wrapped field's own Schema — the value type an omittable field produces
7
7
  * when its presence roll comes up present.
8
8
  */
9
9
  export type Definition = AnySchema;
10
- export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = ValueOf<$Definition, $Bindings>;
10
+ export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings>;
11
11
  /**
12
12
  * What an omittable field's Fabricator returns: the wrapped value, or `Omitted`
13
13
  * when it should not appear — whether from the built-in presence roll or, via
@@ -51,6 +51,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
51
51
  [Kind]: "object.omittable";
52
52
  [Meta]: Meta<$Definition>;
53
53
  bindings?: unknown[];
54
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
54
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
55
55
  readonly [Adaptation]?: $Adaptations;
56
56
  }