@ghostry/fabricator 0.0.10 → 0.0.12

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 (86) hide show
  1. package/dist/esm/Distribution/index.js +1 -1
  2. package/dist/esm/Enumeration/Enumerate.js +2 -4
  3. package/dist/esm/Error/index.js +34 -6
  4. package/dist/esm/Fabricator/Constructor.js +40 -33
  5. package/dist/esm/Fabricator/Fabricate.js +28 -0
  6. package/dist/esm/Instance/Core.js +14 -2
  7. package/dist/esm/Instance/Stack/Visible.js +6 -1
  8. package/dist/esm/Primitive/date/Defaults.js +12 -0
  9. package/dist/esm/Primitive/date/Fabricator.js +5 -10
  10. package/dist/esm/Primitive/date/Registry.js +8 -4
  11. package/dist/esm/Primitive/index.js +2 -0
  12. package/dist/esm/Primitive/null/Registry.js +2 -3
  13. package/dist/esm/Primitive/number/Fabricator.js +1 -1
  14. package/dist/esm/Primitive/number/Registry.js +1 -1
  15. package/dist/esm/Primitive/object/Fabricator.js +33 -11
  16. package/dist/esm/Primitive/object/Registry.js +90 -10
  17. package/dist/esm/Primitive/object/compute/Fabricator.js +10 -3
  18. package/dist/esm/Primitive/object/compute/Registry.js +20 -3
  19. package/dist/esm/Primitive/object/omit/Registry.js +5 -0
  20. package/dist/esm/Primitive/object/omit/index.js +2 -0
  21. package/dist/esm/Primitive/object/pick/Registry.js +5 -0
  22. package/dist/esm/Primitive/object/pick/index.js +2 -0
  23. package/dist/esm/Primitive/recursive/Fabricator.js +1 -0
  24. package/dist/esm/Primitive/recursive/Terminate.js +21 -9
  25. package/dist/esm/Primitive/undefined/Registry.js +2 -3
  26. package/dist/esm/index.js +1 -0
  27. package/dist/esm/internal.js +2 -2
  28. package/dist/types/Adapter/Types.d.ts +3 -2
  29. package/dist/types/Distribution/index.d.ts +10 -0
  30. package/dist/types/Enumeration/Types.d.ts +3 -3
  31. package/dist/types/Error/index.d.ts +71 -6
  32. package/dist/types/Fabricator/Fabricate.d.ts +61 -0
  33. package/dist/types/Fabricator/Types.d.ts +21 -11
  34. package/dist/types/Harnessing/Core.d.ts +7 -7
  35. package/dist/types/Instance/Core.d.ts +15 -8
  36. package/dist/types/Instance/Stack/Visible.d.ts +10 -0
  37. package/dist/types/Instance/Types.d.ts +30 -15
  38. package/dist/types/Primitive/always/Types.d.ts +2 -2
  39. package/dist/types/Primitive/array/Types.d.ts +4 -4
  40. package/dist/types/Primitive/bigint/Types.d.ts +2 -2
  41. package/dist/types/Primitive/boolean/Types.d.ts +2 -2
  42. package/dist/types/Primitive/choice/Types.d.ts +4 -4
  43. package/dist/types/Primitive/date/Defaults.d.ts +11 -0
  44. package/dist/types/Primitive/date/Registry.d.ts +6 -8
  45. package/dist/types/Primitive/date/Types.d.ts +12 -2
  46. package/dist/types/Primitive/derive/Types.d.ts +2 -2
  47. package/dist/types/Primitive/enum/Types.d.ts +2 -2
  48. package/dist/types/Primitive/index.d.ts +2 -0
  49. package/dist/types/Primitive/null/Types.d.ts +2 -2
  50. package/dist/types/Primitive/nullable/Types.d.ts +4 -4
  51. package/dist/types/Primitive/nullish/Types.d.ts +4 -4
  52. package/dist/types/Primitive/number/Types.d.ts +2 -2
  53. package/dist/types/Primitive/object/Fabricator.d.ts +13 -5
  54. package/dist/types/Primitive/object/Registry.d.ts +17 -1
  55. package/dist/types/Primitive/object/Types.d.ts +28 -9
  56. package/dist/types/Primitive/object/compute/Fabricator.d.ts +9 -8
  57. package/dist/types/Primitive/object/compute/Registry.d.ts +7 -1
  58. package/dist/types/Primitive/object/compute/Schema.d.ts +20 -0
  59. package/dist/types/Primitive/object/compute/Types.d.ts +14 -4
  60. package/dist/types/Primitive/object/omit/Registry.d.ts +7 -0
  61. package/dist/types/Primitive/object/omit/index.d.ts +2 -0
  62. package/dist/types/Primitive/object/omittable/Types.d.ts +4 -4
  63. package/dist/types/Primitive/object/optional/Types.d.ts +4 -4
  64. package/dist/types/Primitive/object/pick/Registry.d.ts +8 -0
  65. package/dist/types/Primitive/object/pick/index.d.ts +2 -0
  66. package/dist/types/Primitive/opaque/Types.d.ts +2 -2
  67. package/dist/types/Primitive/record/Types.d.ts +11 -6
  68. package/dist/types/Primitive/recursive/Fabricator.d.ts +9 -7
  69. package/dist/types/Primitive/recursive/Types.d.ts +12 -8
  70. package/dist/types/Primitive/recursive/self/Schema.d.ts +4 -4
  71. package/dist/types/Primitive/recursive/self/Types.d.ts +7 -5
  72. package/dist/types/Primitive/string/Constants.d.ts +7 -31
  73. package/dist/types/Primitive/string/Types.d.ts +2 -2
  74. package/dist/types/Primitive/symbol/Types.d.ts +2 -2
  75. package/dist/types/Primitive/tuple/Types.d.ts +7 -7
  76. package/dist/types/Primitive/undefinable/Types.d.ts +4 -4
  77. package/dist/types/Primitive/undefined/Types.d.ts +2 -2
  78. package/dist/types/Schema/Core.d.ts +10 -6
  79. package/dist/types/Schema/Satisfies.d.ts +31 -23
  80. package/dist/types/Schema/Types.d.ts +31 -18
  81. package/dist/types/Types.d.ts +24 -0
  82. package/dist/types/index.d.ts +45 -18
  83. package/dist/types/internal.d.ts +24 -4
  84. package/package.json +5 -5
  85. /package/dist/esm/Primitive/number/{defaults.js → Defaults.js} +0 -0
  86. /package/dist/types/Primitive/number/{defaults.d.ts → Defaults.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  import type { Enumerable, Limits } from "../Enumeration/Types";
2
2
  import type { Constructor } from "../Fabricator/Constructor";
3
+ import type { Fabricate } from "../Fabricator/Fabricate";
3
4
  import type { Algorithm, Layered, RandomSource, Salt } from "../Random/Types";
4
5
  import type { PlainObject } from "../Utility/Types";
5
6
  /**
@@ -13,8 +14,8 @@ import type { PlainObject } from "../Utility/Types";
13
14
  * milliseconds) or the unresolved `"derived"` policy — never collapsed to a
14
15
  * number by `overlay()` when `"derived"`, because that policy must re-derive
15
16
  * whenever the salt it composes changes (a `fork({ salt: layer(...) })`). The
16
- * unconfigured default is a wall- clock number, inherited as-is like an
17
- * explicit `Date`. `resolveClock` (`Instance/Core.ts`) is the one place that
17
+ * unconfigured default is a wall-clock number, inherited as-is like an explicit
18
+ * `Date` or number. `resolveClock` (`Instance/Core.ts`) is the one place that
18
19
  * resolves `"derived"` to a number, called fresh wherever the clock actually
19
20
  * matters (`instantiate`, the `context.clock` getter) rather than once here.
20
21
  */
@@ -33,11 +34,12 @@ export type Config<$Registry extends PlainObject> = {
33
34
  * (`[...base.salt, ...salt]`) — the shape a wrapping integration wants, and
34
35
  * what `ConstructorOptions`' layered form is for a single construction.
35
36
  * Omitting `salt` inherits the base's unchanged. `clock` similarly accepts the
36
- * caller-facing `Date | "derived"` rather than `Config`'s own resolved `number
37
- * | "derived"`, so a caller can hand in a literal instant without converting it
38
- * to epoch milliseconds themselves. `"derived"` is the explicit opt-in that
39
- * derives "now" from the instance salt; omitting `clock` at the root captures
40
- * wall-clock time instead.
37
+ * caller-facing `Date | number | "derived"` rather than `Config`'s own resolved
38
+ * `number | "derived"`, so a caller can hand in a literal instant without
39
+ * converting it to epoch milliseconds themselves, or hand back a logged
40
+ * `context.clock` without wrapping it in a `Date`. `"derived"` is the explicit
41
+ * opt-in that derives "now" from the instance salt; omitting `clock` at the
42
+ * root captures wall-clock time instead.
41
43
  *
42
44
  * `initialize`'s own parameter keeps a plain `salt?: Salt`, so passing
43
45
  * `layer(...)` there is a compile error: there is no base to layer onto at the
@@ -45,7 +47,7 @@ export type Config<$Registry extends PlainObject> = {
45
47
  */
46
48
  export type Overlay<$Registry extends PlainObject> = Partial<Omit<Config<$Registry>, "salt" | "clock">> & {
47
49
  readonly salt?: Salt | Layered;
48
- readonly clock?: Date | "derived" | undefined;
50
+ readonly clock?: Date | number | "derived" | undefined;
49
51
  };
50
52
  declare const Brand: unique symbol;
51
53
  /**
@@ -256,6 +258,19 @@ export interface Instance<$Registry extends PlainObject> extends Pick<RandomSour
256
258
  * it.
257
259
  */
258
260
  Fabricator: Constructor;
261
+ /**
262
+ * `new Fabricator(schema).fabricate()` in one call. The first call with a
263
+ * schema builds; every later call with the same schema object continues that
264
+ * Fabricator, taking no new construction ordinal — so it is safe in a loop.
265
+ *
266
+ * The cache follows the scope in effect, like `new Fabricator` does: inside a
267
+ * `wrap` this instance can see, the frame's source is used and its entries
268
+ * are its own, so each per-test scope starts fresh. The key is identity: hold
269
+ * an overridden or configured schema in a variable to reuse it. Writing
270
+ * `.override(...)` or `.whereby(...)` inline at the call site makes a new
271
+ * schema, and a new build, on every call. See `Fabricator/Fabricate.ts`.
272
+ */
273
+ fabricate: Fabricate;
259
274
  /**
260
275
  * Every combination of every enumerable node in `schema` — every enum member,
261
276
  * both sides of an optional field, and so on — as a cartesian product,
@@ -280,13 +295,13 @@ export interface Instance<$Registry extends PlainObject> extends Pick<RandomSour
280
295
  fork<const $ForkRegistry extends PlainObject = $Registry>(overlay?: Overlay<$ForkRegistry>): Instance<$ForkRegistry>;
281
296
  /**
282
297
  * `fork(overlay)`, made ambient for the synchronous extent of `block`: every
283
- * `new Fabricator(...)`, `combinatorial(...)`, and `coverage(...)` reached
284
- * inside — on this instance, and on this instance's ancestors — resolves
285
- * against the fork instead, with nothing threaded through. The fork is also
286
- * passed to `block`: use it explicitly where that reads better, and
287
- * _necessarily_ for any async work, which the ambient frame does not survive
288
- * — a build reached after an `await` inside `block` sees this instance's own
289
- * configuration again, not the wrap's.
298
+ * `new Fabricator(...)`, `fabricate(...)`, `combinatorial(...)`, and
299
+ * `coverage(...)` reached inside — on this instance, and on this instance's
300
+ * ancestors — resolves against the fork instead, with nothing threaded
301
+ * through. The fork is also passed to `block`: use it explicitly where that
302
+ * reads better, and _necessarily_ for any async work, which the ambient frame
303
+ * does not survive — a build reached after an `await` inside `block` sees
304
+ * this instance's own configuration again, not the wrap's.
290
305
  *
291
306
  * The overlay lays over _this instance's_ config, exactly as `fork`'s does,
292
307
  * whether or not a frame is already open. So a nested `wrap` accumulates when
@@ -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
  };
@@ -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
  }
@@ -0,0 +1,11 @@
1
+ import type { Bound } from "../../Bound";
2
+ /**
3
+ * Inclusive epoch-millisecond caps that a missing `whereby` end draws against —
4
+ * the whole representable `Date` range. Not stored on `[Meta]`: an omitted end
5
+ * stays omitted, and adapters forward only the ends that were named. `past` and
6
+ * `future` fill their one open end from here too.
7
+ */
8
+ export declare const unboundedEpoch: {
9
+ min: Bound<number>;
10
+ max: Bound<number>;
11
+ };
@@ -2,17 +2,15 @@ import type { Adaptations } from "../../Adapter/Types";
2
2
  import { type InputBound } from "../../Bound";
3
3
  import { type Distribution } from "../../Distribution";
4
4
  import { Schema } from "./Schema";
5
- import type { Whereby } from "./Types";
5
+ import type { InputWhereby, Whereby } from "./Types";
6
6
  type ThisRegistry = Schema<{}, Adaptations> & {
7
7
  /**
8
- * A `Date` drawn from `[min, max]`. Pass a `distribution` to shape how values
9
- * cluster within the range; without one, every instant is equally likely.
8
+ * A `Date` drawn from `[min, max]`. Either end may be omitted: `min` defaults
9
+ * to the earliest representable instant and `max` to the latest. Pass a
10
+ * `distribution` to shape how values cluster within the range; without one,
11
+ * every instant is equally likely.
10
12
  */
11
- whereby: (whereby: {
12
- min: InputBound<Date>;
13
- max: InputBound<Date>;
14
- distribution?: Distribution | undefined;
15
- }) => Schema<{
13
+ whereby: (whereby: InputWhereby) => Schema<{
16
14
  whereby: Whereby;
17
15
  }>;
18
16
  /**
@@ -2,12 +2,22 @@ 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
+ /**
7
+ * Call-site `{ min, max }` — scalars are inclusive. Either end may be omitted;
8
+ * a missing `min` is the earliest representable instant and a missing `max` the
9
+ * latest, the same span as a bare `T.date`.
10
+ */
6
11
  export type InputWhereby = {
7
12
  min?: InputBound<Date> | undefined;
8
13
  max?: InputBound<Date> | undefined;
9
14
  distribution?: Distribution | undefined;
10
15
  };
16
+ /**
17
+ * Stored `{ min, max }` — each present end is a canonical {@link Bound}. An
18
+ * omitted end stays omitted (fabricate fills `Defaults.ts`'s `unboundedEpoch`;
19
+ * adapters forward only the ends that were named).
20
+ */
11
21
  export type Whereby = {
12
22
  min?: Bound<Date> | undefined;
13
23
  max?: Bound<Date> | undefined;
@@ -29,6 +39,6 @@ export type Meta = {
29
39
  export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
30
40
  [Kind]: "date";
31
41
  [Meta]: $Meta;
32
- readonly [Produces]?: Fabricated;
42
+ readonly [Produces]?: Produced<Fabricated>;
33
43
  readonly [Adaptation]?: $Adaptations;
34
44
  };
@@ -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
  }
@@ -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
  };
@@ -13,8 +13,10 @@ export { default as nullable } from "./nullable";
13
13
  export { default as nullish } from "./nullish";
14
14
  export { default as number } from "./number";
15
15
  export { default as object } from "./object";
16
+ export { default as omit } from "./object/omit";
16
17
  export { default as omittable } from "./object/omittable";
17
18
  export { default as optional } from "./object/optional";
19
+ export { default as pick } from "./object/pick";
18
20
  export { default as opaque } from "./opaque";
19
21
  export { default as record } from "./record";
20
22
  export { default as recursive } from "./recursive";
@@ -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
  };
@@ -48,9 +48,17 @@ export type Fields = Record<string, BaseFabricator<unknown>>;
48
48
  * A compute-kind field (from `.refine()`) needs the rest of the object already
49
49
  * fabricated (`object/compute/Fabricator.ts`), which isn't available until
50
50
  * every ordinary field has resolved. Two phases: ordinary fields first, then
51
- * compute fields against the accumulated result, in definition order (a compute
52
- * field can see an earlier compute field's value, not a later one) — unless
53
- * covered by `overrides`, in which case it resolves in phase 1 like any other
54
- * overridden field.
51
+ * compute fields against the accumulated result, in dependency order — each
52
+ * after every compute field among its `dependencies` (`compute/Types.ts`) —
53
+ * unless covered by `overrides`, in which case it resolves in phase 1 like any
54
+ * other overridden field. Dependency order rather than definition order is what
55
+ * lets `hidden` live in its own map: a hidden compute field can sit between two
56
+ * visible ones in the chain, and no fixed visible/hidden order resolves that.
57
+ *
58
+ * `hidden` is `[Meta].hidden` built (`Types.ts`'s `Meta`): fabricated in both
59
+ * phases exactly like `fields`, so compute fields can read them, then deleted
60
+ * before returning. Per-call `overrides` only reach `fields` — `.override()`
61
+ * rejects a hidden key, and `{ validate: false }` must not let one through.
62
+ * `[Children]` stays `fields` alone, so enumeration never pins a hidden field.
55
63
  */
56
- export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, fields: Fields): Fabricator<Schema<$Definition>>;
64
+ export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, fields: Fields, hidden?: Fields): Fabricator<Schema<$Definition>>;
@@ -1,7 +1,7 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
2
  import { Adaptation, Meta } from "../../Types";
3
3
  import { Schema } from "./Schema";
4
- import type { Definition, Meta as ThisMeta } from "./Types";
4
+ import type { Definition, Subsettable, Meta as ThisMeta } from "./Types";
5
5
  /**
6
6
  * Rebuild a full `object` Schema — with `extend`/`refine` restored — from
7
7
  * anything already reduced to this kind's `[Meta]` (a bare Schema, or a built
@@ -19,5 +19,21 @@ export declare function rehydrate<$Definition extends Definition, $Adaptations e
19
19
  [Meta]: ThisMeta<$Definition>;
20
20
  readonly [Adaptation]?: $Adaptations;
21
21
  }): Schema<$Definition, $Adaptations>;
22
+ /**
23
+ * Shared body of `T.pick`/`T.omit` (`pick/Registry.ts`, `omit/Registry.ts`),
24
+ * kept here because it rebuilds through `make`. A pure Schema → Schema
25
+ * transform, like `.override()`: the result is an ordinary `object` Schema over
26
+ * the kept fields, in source order. A dependency of a kept compute field that
27
+ * is not itself kept moves to `[Meta].hidden` — fabricated, so the resolver can
28
+ * read it, but never emitted. A dropped field nothing depends on is gone
29
+ * entirely.
30
+ *
31
+ * The source's own `produce` (`.as(...)`) and whole-object `[Adaptation]` are
32
+ * not carried: both describe the source's full shape, not this one. Field
33
+ * entries are reused as they are, so a kept or hidden field's own adaptation
34
+ * and `[Fixed]` override come along. `refinements` is filtered down to the kept
35
+ * fields.
36
+ */
37
+ export declare function subset(source: Subsettable, keys: ReadonlyArray<string>, operation: "pick" | "omit"): Schema<any>;
22
38
  declare const _default: <const $Definition extends Definition>(definition: $Definition) => Schema<$Definition>;
23
39
  export default _default;
@@ -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
@@ -67,17 +67,36 @@ export type Override<$Definition extends Definition> = Pretty<{
67
67
  * `extend`/`refine`/`override` and `ToTypeBox`'s structural derivation keep
68
68
  * working, and a prior definition survives `as` for future validation of
69
69
  * `produce`.
70
+ *
71
+ * `hidden` holds fields that are fabricated but never emitted: the dependencies
72
+ * of a kept compute field that `T.pick`/`T.omit` (`Registry.ts`) dropped from
73
+ * `definition`. Absent when there are none. It sits outside `definition` so
74
+ * that everything reading `definition` — the `Fabricated`/`Override` types,
75
+ * `.override()`'s key check, `[Children]` (and so enumeration), and every
76
+ * adapter — never sees a hidden field. Only `Constructor.ts`'s `make`,
77
+ * `Fabricator.ts`'s `fabricate`, and `recursive/Terminate.ts` read it.
70
78
  */
71
79
  export type Meta<$Definition extends Definition = Definition> = {
72
80
  definition: $Definition;
73
81
  refinements: Refinements;
74
82
  produce?: Produce<Fabricated<$Definition>>;
83
+ hidden?: Definition;
84
+ };
85
+ /**
86
+ * What `T.pick`/`T.omit` accept: an `object` Schema or a built `object`
87
+ * Fabricator — anything already carrying this kind's `[Meta]`, the same input
88
+ * `Registry.ts`'s `rehydrate` takes.
89
+ */
90
+ export type Subsettable = {
91
+ readonly [Kind]: "object";
92
+ readonly [Meta]: Meta<any>;
75
93
  };
94
+ export type DefinitionOf<$Source extends Subsettable> = $Source[typeof Meta]["definition"];
76
95
  export interface Core<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> {
77
96
  [Kind]: "object";
78
97
  [Meta]: Meta<$Definition>;
79
98
  bindings?: unknown[];
80
- readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
99
+ readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
81
100
  readonly [Adaptation]?: $Adaptations;
82
101
  }
83
102
  export {};
@@ -2,17 +2,13 @@ import type { Adaptations } from "../../../Adapter/Types";
2
2
  import type { Fabricator as BaseFabricator, FabricatorContext } from "../../../Fabricator/Types";
3
3
  import type { Trace } from "../../../Random/Types";
4
4
  import { Kind, Meta, type Adaptation } from "../../../Types";
5
+ import { type PlainObject } from "../../../Utility/Types";
5
6
  import type { Schema } from "./Schema";
6
- import type { Resolved, Source } from "./Types";
7
+ import type { Resolved, Source, Meta as ThisMeta } from "./Types";
7
8
  export type Fabrication<$Fabricator extends Fabricator<any, Source>> = $Fabricator extends Fabricator<any, infer $Source> ? Resolved<$Source> : never;
8
9
  export type Fabricator<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}> = {
9
10
  [Kind]: "object.compute";
10
- [Meta]: {
11
- source: $Source;
12
- resolve: (params: {
13
- fabricated: $Fabricated;
14
- }) => Resolved<$Source>;
15
- };
11
+ [Meta]: ThisMeta<$Fabricated, $Source>;
16
12
  readonly trace: Trace;
17
13
  readonly [Adaptation]?: $Adaptations;
18
14
  fabricate: (params?: {
@@ -26,5 +22,10 @@ export declare function isObjectComputeFabricator(candidate: BaseFabricator<unkn
26
22
  * comes entirely from `resolve`, given the rest of the object. The node still
27
23
  * records `trace` so it can be rebuilt from a parent field's captured trace;
28
24
  * `.fabricate()` without the parent object throws `DetachedComputeError`.
25
+ *
26
+ * The parent hands over everything it has fabricated so far; a `narrowed` field
27
+ * (`.from([...])`) passes its resolver only its `dependencies`, and only those
28
+ * present, so an omitted dependency stays absent rather than becoming
29
+ * `undefined`. Narrowing here keeps `object/Fabricator.ts` unaware of it.
29
30
  */
30
- export declare function Fabricator<$Fabricated, $Source extends Source>(context: FabricatorContext<Schema<$Fabricated, $Source>>): Fabricator<$Fabricated, $Source>;
31
+ export declare function Fabricator<$Fabricated extends PlainObject, $Source extends Source>(context: FabricatorContext<Schema<$Fabricated, $Source>>): Fabricator<$Fabricated, $Source>;
@@ -1,4 +1,10 @@
1
1
  import type { Definition } from "../Types";
2
2
  import { type Computer } from "./Schema";
3
- declare function make<$Definition extends Definition>(): Computer<$Definition>;
3
+ /**
4
+ * `base` is the keys of the `.refine()` stage's base definition — what a plain
5
+ * `.as` resolver depends on, and what `.from([...])` may name. Checked at
6
+ * runtime as well as by type, since a cast or a built Fabricator's widened type
7
+ * can reach `.from` with a key the base never had.
8
+ */
9
+ declare function make<$Definition extends Definition>(base: ReadonlyArray<string>): Computer<$Definition>;
4
10
  export default make;
@@ -2,12 +2,32 @@ import { type AdaptationEntry } from "../../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
3
3
  import type { AnySchema } from "../../../Schema/Types";
4
4
  import { type SatisfiesThis } from "../../../Schema/Satisfies";
5
+ import type { Pretty } from "../../../Utility/Types";
5
6
  import type * as object from "../Types";
6
7
  import type { Core, Resolved, Source } from "./Types";
8
+ /**
9
+ * The fields a `.from([...])` resolver is handed: only the named ones, each
10
+ * keeping its own `?:` (an omittable or optional dependency may be absent).
11
+ */
12
+ export type Narrowed<$Definition extends object.Definition, $Keys extends keyof $Definition> = Pretty<Pick<object.Fabricated<$Definition>, $Keys & keyof object.Fabricated<$Definition>>>;
7
13
  export type Computer<$Definition extends object.Definition> = <const $Source extends Source>(source: $Source) => {
14
+ /**
15
+ * Resolve against the whole object fabricated so far. The field depends on
16
+ * every field of this `.refine()` stage's base, so `T.pick`/`T.omit` keep all
17
+ * of them fabricated when this field is kept.
18
+ */
8
19
  as: (resolve: (params: {
9
20
  fabricated: object.Fabricated<$Definition>;
10
21
  }) => NoInfer<Resolved<$Source>>) => Schema<object.Fabricated<$Definition>, $Source>;
22
+ /**
23
+ * Declare the fields this one reads. The resolver is handed only those, and
24
+ * they are all `T.pick`/`T.omit` keep fabricated when this field is kept.
25
+ */
26
+ from: <const $Keys extends ReadonlyArray<keyof $Definition & string>>(keys: $Keys) => {
27
+ as: (resolve: (params: {
28
+ fabricated: Narrowed<$Definition, $Keys[number]>;
29
+ }) => NoInfer<Resolved<$Source>>) => Schema<Narrowed<$Definition, $Keys[number]>, $Source>;
30
+ };
11
31
  };
12
32
  export interface Schema<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}> extends Core<$Fabricated, $Source, $Adaptations> {
13
33
  /**