@ghostry/fabricator 0.0.1 → 0.0.2

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 (124) hide show
  1. package/README.md +1 -7
  2. package/dist/esm/Error/index.js +8 -0
  3. package/dist/esm/Instance/Core.js +8 -17
  4. package/dist/esm/Instance/Stack/Async.js +10 -0
  5. package/dist/esm/Instance/Stack/Sync.js +16 -0
  6. package/dist/esm/Primitive/bigint/Registry.js +12 -12
  7. package/dist/esm/Primitive/boolean/Registry.js +2 -1
  8. package/dist/esm/Primitive/date/Registry.js +15 -14
  9. package/dist/esm/Primitive/null/Registry.js +2 -1
  10. package/dist/esm/Primitive/number/Registry.js +18 -17
  11. package/dist/esm/Primitive/symbol/Registry.js +2 -1
  12. package/dist/esm/Primitive/undefined/Registry.js +2 -1
  13. package/dist/esm/Random/CallSite.js +27 -13
  14. package/dist/esm/Utility/Core.js +6 -1
  15. package/dist/esm/index.js +4 -2
  16. package/dist/esm/internal.js +2 -1
  17. package/dist/types/Adapter/Core.d.ts +29 -32
  18. package/dist/types/Adapter/Types.d.ts +78 -88
  19. package/dist/types/Bound.d.ts +15 -15
  20. package/dist/types/Distribution/index.d.ts +54 -61
  21. package/dist/types/Enumeration/Enumerate.d.ts +21 -23
  22. package/dist/types/Enumeration/Plan.d.ts +22 -26
  23. package/dist/types/Enumeration/Types.d.ts +38 -43
  24. package/dist/types/Error/index.d.ts +94 -76
  25. package/dist/types/Fabricator/Constructor.d.ts +23 -25
  26. package/dist/types/Fabricator/Types.d.ts +73 -81
  27. package/dist/types/Instance/Core.d.ts +54 -73
  28. package/dist/types/Instance/Stack/Async.d.ts +14 -0
  29. package/dist/types/Instance/Stack/Sync.d.ts +14 -0
  30. package/dist/types/Instance/Types.d.ts +91 -89
  31. package/dist/types/Primitive/always/Schema.d.ts +8 -8
  32. package/dist/types/Primitive/always/Types.d.ts +7 -7
  33. package/dist/types/Primitive/array/Registry.d.ts +10 -8
  34. package/dist/types/Primitive/array/Schema.d.ts +4 -5
  35. package/dist/types/Primitive/array/Types.d.ts +6 -6
  36. package/dist/types/Primitive/bigint/Registry.d.ts +6 -6
  37. package/dist/types/Primitive/bigint/Schema.d.ts +8 -8
  38. package/dist/types/Primitive/bigint/Types.d.ts +5 -5
  39. package/dist/types/Primitive/boolean/Outcomes.d.ts +8 -8
  40. package/dist/types/Primitive/boolean/Registry.d.ts +2 -12
  41. package/dist/types/Primitive/boolean/Schema.d.ts +8 -8
  42. package/dist/types/Primitive/boolean/Types.d.ts +3 -3
  43. package/dist/types/Primitive/choice/Fabricator.d.ts +6 -7
  44. package/dist/types/Primitive/choice/Registry.d.ts +13 -13
  45. package/dist/types/Primitive/choice/Schema.d.ts +6 -6
  46. package/dist/types/Primitive/choice/Types.d.ts +11 -11
  47. package/dist/types/Primitive/date/Registry.d.ts +25 -48
  48. package/dist/types/Primitive/date/Schema.d.ts +9 -10
  49. package/dist/types/Primitive/date/Types.d.ts +4 -4
  50. package/dist/types/Primitive/enum/Registry.d.ts +13 -13
  51. package/dist/types/Primitive/enum/Schema.d.ts +5 -5
  52. package/dist/types/Primitive/enum/Types.d.ts +17 -19
  53. package/dist/types/Primitive/namespace.d.ts +10 -10
  54. package/dist/types/Primitive/null/Registry.d.ts +2 -2
  55. package/dist/types/Primitive/null/Schema.d.ts +2 -2
  56. package/dist/types/Primitive/null/Types.d.ts +3 -3
  57. package/dist/types/Primitive/nullable/Fabricator.d.ts +7 -7
  58. package/dist/types/Primitive/nullable/Schema.d.ts +13 -13
  59. package/dist/types/Primitive/nullable/Types.d.ts +9 -10
  60. package/dist/types/Primitive/nullish/Fabricator.d.ts +12 -13
  61. package/dist/types/Primitive/nullish/Schema.d.ts +8 -8
  62. package/dist/types/Primitive/nullish/Types.d.ts +12 -13
  63. package/dist/types/Primitive/number/Registry.d.ts +20 -38
  64. package/dist/types/Primitive/number/Schema.d.ts +11 -12
  65. package/dist/types/Primitive/number/Types.d.ts +13 -13
  66. package/dist/types/Primitive/number/defaults.d.ts +3 -3
  67. package/dist/types/Primitive/object/Fabricator.d.ts +15 -15
  68. package/dist/types/Primitive/object/Registry.d.ts +8 -8
  69. package/dist/types/Primitive/object/Schema.d.ts +10 -10
  70. package/dist/types/Primitive/object/Types.d.ts +20 -22
  71. package/dist/types/Primitive/object/compute/Fabricator.d.ts +4 -5
  72. package/dist/types/Primitive/object/compute/Schema.d.ts +4 -4
  73. package/dist/types/Primitive/object/compute/Types.d.ts +19 -20
  74. package/dist/types/Primitive/object/omittable/Fabricator.d.ts +10 -10
  75. package/dist/types/Primitive/object/omittable/Outcomes.d.ts +2 -2
  76. package/dist/types/Primitive/object/omittable/Schema.d.ts +11 -11
  77. package/dist/types/Primitive/object/omittable/Types.d.ts +14 -15
  78. package/dist/types/Primitive/object/optional/Fabricator.d.ts +16 -18
  79. package/dist/types/Primitive/object/optional/Outcomes.d.ts +2 -2
  80. package/dist/types/Primitive/object/optional/Schema.d.ts +4 -4
  81. package/dist/types/Primitive/object/optional/Types.d.ts +17 -17
  82. package/dist/types/Primitive/opaque/Registry.d.ts +3 -3
  83. package/dist/types/Primitive/opaque/Schema.d.ts +8 -9
  84. package/dist/types/Primitive/record/Registry.d.ts +8 -6
  85. package/dist/types/Primitive/record/Schema.d.ts +9 -11
  86. package/dist/types/Primitive/record/Types.d.ts +25 -25
  87. package/dist/types/Primitive/recursive/Fabricator.d.ts +16 -17
  88. package/dist/types/Primitive/recursive/Registry.d.ts +6 -7
  89. package/dist/types/Primitive/recursive/Schema.d.ts +8 -8
  90. package/dist/types/Primitive/recursive/Terminate.d.ts +13 -14
  91. package/dist/types/Primitive/recursive/Types.d.ts +31 -31
  92. package/dist/types/Primitive/recursive/self/Fabricator.d.ts +11 -12
  93. package/dist/types/Primitive/recursive/self/Schema.d.ts +10 -10
  94. package/dist/types/Primitive/recursive/self/Types.d.ts +7 -8
  95. package/dist/types/Primitive/string/Constants.d.ts +12 -13
  96. package/dist/types/Primitive/string/Fabricator.d.ts +2 -2
  97. package/dist/types/Primitive/string/Registry.d.ts +10 -16
  98. package/dist/types/Primitive/string/Schema.d.ts +5 -5
  99. package/dist/types/Primitive/string/Types.d.ts +17 -17
  100. package/dist/types/Primitive/symbol/Fabricator.d.ts +2 -2
  101. package/dist/types/Primitive/symbol/Registry.d.ts +4 -11
  102. package/dist/types/Primitive/symbol/Schema.d.ts +6 -6
  103. package/dist/types/Primitive/symbol/Types.d.ts +2 -2
  104. package/dist/types/Primitive/tuple/Fabricator.d.ts +7 -8
  105. package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
  106. package/dist/types/Primitive/tuple/Types.d.ts +24 -25
  107. package/dist/types/Primitive/undefinable/Fabricator.d.ts +7 -7
  108. package/dist/types/Primitive/undefinable/Schema.d.ts +13 -13
  109. package/dist/types/Primitive/undefinable/Types.d.ts +10 -10
  110. package/dist/types/Primitive/undefined/Registry.d.ts +2 -2
  111. package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
  112. package/dist/types/Primitive/undefined/Types.d.ts +3 -3
  113. package/dist/types/Random/CallSite.d.ts +63 -44
  114. package/dist/types/Random/Generator/sfc32.d.ts +4 -4
  115. package/dist/types/Random/Types.d.ts +214 -236
  116. package/dist/types/Random/index.d.ts +63 -70
  117. package/dist/types/Schema/Core.d.ts +19 -21
  118. package/dist/types/Schema/Registry.d.ts +3 -3
  119. package/dist/types/Schema/Types.d.ts +41 -48
  120. package/dist/types/Types.d.ts +39 -45
  121. package/dist/types/Utility/Core.d.ts +18 -9
  122. package/dist/types/index.d.ts +110 -108
  123. package/dist/types/internal.d.ts +68 -37
  124. package/package.json +17 -5
@@ -5,35 +5,32 @@ import type { ValueOf } from "../Schema/Types";
5
5
  import type { Adaptation, Kind, Meta, Produces } from "../Types";
6
6
  import type { PlainObject } from "../Utility/Types";
7
7
  /**
8
- * Threaded through `Constructor.ts`'s `make` for every dispatch of one
9
- * `new Fabricator(...)` construction — every branch forwards it
10
- * (extending `path`, never `algorithm`/`self`) into its own nested
11
- * `make(...)` calls, so it reaches however deeply a leaf sits nested
12
- * through `array`/`object`/`tuple`/etc.
8
+ * Threaded through `Constructor.ts`'s `make` for every dispatch of one `new
9
+ * Fabricator(...)` construction — every branch forwards it (extending `path`,
10
+ * never `algorithm`/`self`) into its own nested `make(...)` calls, so it
11
+ * reaches however deeply a leaf sits nested through
12
+ * `array`/`object`/`tuple`/etc.
13
13
  *
14
- * `toTrace` records this node's {@link Trace} — a plain object literal,
15
- * no hashing. Hashing is paid only where a kind actually calls
16
- * `toStreamFromTrace(algorithm, trace)`. Bound once in `construct()` to
17
- * this one construction's already-resolved `RandomSource`/
18
- * `ConstructionTrace` pair (see `Constructor.ts`'s `resolveScope`) —
19
- * every leaf calls `toTrace` with only its own structural `path` and
20
- * kind, never re-resolving the construction's root itself.
21
- * `T.recursive` is the one kind that rebinds `toTrace`: each lazy
22
- * expansion opens its own scope on the node's own private forked
23
- * `RandomSource` (see `recursive/Fabricator.ts`), so a data-dependent
24
- * expansion count can never perturb, or be perturbed by, anything else
25
- * built from the same `initialize()` instance —
26
- * `RandomSource.fork` (`Random/Types.ts`) is the isolation primitive.
14
+ * `toTrace` records this node's {@link Trace} — a plain object literal, no
15
+ * hashing. Hashing is paid only where a kind actually calls
16
+ * `toStreamFromTrace(algorithm, trace)`. Bound once in `construct()` to this
17
+ * one construction's already-resolved `RandomSource`/ `ConstructionTrace` pair
18
+ * (see `Constructor.ts`'s `resolveScope`) — every leaf calls `toTrace` with
19
+ * only its own structural `path` and kind, never re-resolving the
20
+ * construction's root itself. `T.recursive` is the one kind that rebinds
21
+ * `toTrace`: each lazy expansion opens its own scope on the node's own private
22
+ * forked `RandomSource` (see `recursive/Fabricator.ts`), so a data-dependent
23
+ * expansion count can never perturb, or be perturbed by, anything else built
24
+ * from the same `initialize()` instance `RandomSource.fork`
25
+ * (`Random/Types.ts`) is the isolation primitive.
27
26
  *
28
- * `algorithm` rather than the `RandomSource` itself: stream derivation
29
- * depends on no per-source state, and a leaf has no business with
30
- * `toRoot`/`fork`. `clock` is not a field of its own — it is always
31
- * `trace.clock`.
27
+ * `algorithm` rather than the `RandomSource` itself: stream derivation depends
28
+ * on no per-source state, and a leaf has no business with `toRoot`/`fork`.
29
+ * `clock` is not a field of its own — it is always `trace.clock`.
32
30
  *
33
- * `self` is what makes `case "recursive.self"` resolve to "recurse one
34
- * level deeper, right now" — absent outside any active recursion, which
35
- * is how `case "recursive.self"` detects and rejects a `self` node used
36
- * where none applies.
31
+ * `self` is what makes `case "recursive.self"` resolve to "recurse one level
32
+ * deeper, right now" — absent outside any active recursion, which is how `case
33
+ * "recursive.self"` detects and rejects a `self` node used where none applies.
37
34
  */
38
35
  export type ConstructionContext = {
39
36
  toTrace: (path: ReadonlyArray<string>, kind: string) => Trace;
@@ -41,22 +38,20 @@ export type ConstructionContext = {
41
38
  self?: (() => unknown) | undefined;
42
39
  };
43
40
  /**
44
- * What every kind's `Fabricator(...)` receives in place of a repeated
45
- * `(schema, algorithm, trace)` positional list — `Constructor.ts`'s
46
- * `make` builds one per dispatched node from its own
47
- * `ConstructionContext`. `trace` is already path-bound and built
48
- * eagerly, so a kind that never draws still records one without calling
49
- * `toStreamFromTrace`. Laziness is load-bearing: `toTrace` is a plain
50
- * object literal, and hashing is paid only where a kind actually calls
51
- * `toStreamFromTrace(algorithm, trace)`. The guard is the call site's
52
- * own `if (meta.produce)` branch (or the equivalent drawing path), not
53
- * an unevaluated closure. `algorithm` rather than the `RandomSource`:
54
- * derivation depends on no per-source state, and a leaf has no business
55
- * with `toRoot`/`fork`. No `clock`: it is `trace.clock`, always. A
56
- * kind-specific extra an array's `element`, an object's `fields`, a
57
- * choice's `weightings` still follows as its own trailing parameter:
58
- * those vary per kind and were never part of the shared prefix this
59
- * replaces.
41
+ * What every kind's `Fabricator(...)` receives in place of a repeated `(schema,
42
+ * algorithm, trace)` positional list — `Constructor.ts`'s `make` builds one per
43
+ * dispatched node from its own `ConstructionContext`. `trace` is already
44
+ * path-bound and built eagerly, so a kind that never draws still records one
45
+ * without calling `toStreamFromTrace`. Laziness is load-bearing: `toTrace` is a
46
+ * plain object literal, and hashing is paid only where a kind actually calls
47
+ * `toStreamFromTrace(algorithm, trace)`. The guard is the call site's own `if
48
+ * (meta.produce)` branch (or the equivalent drawing path), not an unevaluated
49
+ * closure. `algorithm` rather than the `RandomSource`: derivation depends on no
50
+ * per-source state, and a leaf has no business with `toRoot`/`fork`. No
51
+ * `clock`: it is `trace.clock`, always. A kind-specific extra an array's
52
+ * `element`, an object's `fields`, a choice's `weightings` still follows as
53
+ * its own trailing parameter: those vary per kind and were never part of the
54
+ * shared prefix this replaces.
60
55
  */
61
56
  export type FabricatorContext<$Schema> = {
62
57
  schema: $Schema;
@@ -64,18 +59,18 @@ export type FabricatorContext<$Schema> = {
64
59
  trace: Trace;
65
60
  };
66
61
  /**
67
- * The most basic interface for a typed Fabricator.
68
- * No type introspection is possible.
62
+ * The most basic interface for a typed Fabricator. No type introspection is
63
+ * possible.
69
64
  */
70
65
  export type NaiveFabricator<$T> = {
71
66
  fabricate: () => $T;
72
67
  };
73
68
  /**
74
- * What every kind's `construct()` produces: a `NaiveFabricator` that
75
- * also hands back the Schema it was built from, via the same
76
- * `[Kind]`/`[Meta]` a Schema itself carries — so a built Fabricator
77
- * can be passed back into `object`/`array`/a registry `.extend()`
78
- * anywhere a Schema is expected (see `toSchema`).
69
+ * What every kind's `construct()` produces: a `NaiveFabricator` that also hands
70
+ * back the Schema it was built from, via the same `[Kind]`/`[Meta]` a Schema
71
+ * itself carries — so a built Fabricator can be passed back into
72
+ * `object`/`array`/a registry `.extend()` anywhere a Schema is expected (see
73
+ * `toSchema`).
79
74
  */
80
75
  export type Fabricator<$T> = NaiveFabricator<$T> & {
81
76
  [Kind]: SchemaKind;
@@ -83,48 +78,45 @@ export type Fabricator<$T> = NaiveFabricator<$T> & {
83
78
  readonly trace: Trace;
84
79
  /**
85
80
  * Carried over from the Schema by `Constructor.ts`'s `make` — inert to
86
- * fabrication, but it has to survive building for an adapter handed a
87
- * built Fabricator to see what the Schema declared (see
88
- * `Adapter/Types.ts`).
81
+ * fabrication, but it has to survive building for an adapter handed a built
82
+ * Fabricator to see what the Schema declared (see `Adapter/Types.ts`).
89
83
  */
90
84
  readonly [Adaptation]?: Adaptations;
91
85
  };
92
86
  /**
93
87
  * The value type a built Fabricator produces — read directly off its
94
- * `fabricate` signature. Every kind's `construct()` output shares the
95
- * exact same shape (`NaiveFabricator<$T>` plus `[Kind]`/`[Meta]`, see
96
- * this file's `Fabricator<$T>`), so there's nothing to dispatch per
97
- * kind here — unlike `ValueOf`, which reads a Schema's phantom
98
- * `[Produces]` marker for the pre-`construct()` case, this only ever
99
- * needs to unwrap an already-uniform `fabricate: () => $T`.
88
+ * `fabricate` signature. Every kind's `construct()` output shares the exact
89
+ * same shape (`NaiveFabricator<$T>` plus `[Kind]`/`[Meta]`, see this file's
90
+ * `Fabricator<$T>`), so there's nothing to dispatch per kind here — unlike
91
+ * `ValueOf`, which reads a Schema's phantom `[Produces]` marker for the
92
+ * pre-`construct()` case, this only ever needs to unwrap an already-uniform
93
+ * `fabricate: () => $T`.
100
94
  */
101
95
  export type Fabrication<$Fabricator extends NaiveFabricator<any>> = $Fabricator extends NaiveFabricator<infer $T> ? $T : never;
102
96
  /**
103
- * Maps a Schema (or an already-built Fabricator of the same kind — see
104
- * the `object` branch, and every other branch below since each kind's
105
- * `Schema` also carries a required `as` method a built Fabricator never
106
- * has) to the precise, kind-specific `Fabricator<...>` type it builds
107
- * into. Mirrors `Adapter/TypeBox/index.ts`'s `ToTypeBox` dispatch.
108
- * Falls back to the loose base `Fabricator<ValueOf<$Schema>>` for
109
- * anything unmatched.
97
+ * Maps a Schema (or an already-built Fabricator of the same kind — see the
98
+ * `object` branch, and every other branch below since each kind's `Schema` also
99
+ * carries a required `as` method a built Fabricator never has) to the precise,
100
+ * kind-specific `Fabricator<...>` type it builds into. Mirrors
101
+ * `Adapter/TypeBox/index.ts`'s `ToTypeBox` dispatch. Falls back to the loose
102
+ * base `Fabricator<ValueOf<$Schema>>` for anything unmatched.
110
103
  *
111
- * No branch here needs to do anything about `[Adaptation]`: each
112
- * kind's own `Fabricator<$Schema>` reads it back off `$Schema` via
113
- * `AdaptationsOf`, so an adapted Schema's Fabricator carries the map
114
- * without this dispatch (or an intersection on top of it, which the
115
- * warning below would otherwise apply to) having to mention it.
116
- * `object.compute` is the one exception, taking its `$Adaptations`
117
- * explicitly because its Fabricator is parameterized by the computed
118
- * value and source rather than by the Schema.
104
+ * No branch here needs to do anything about `[Adaptation]`: each kind's own
105
+ * `Fabricator<$Schema>` reads it back off `$Schema` via `AdaptationsOf`, so an
106
+ * adapted Schema's Fabricator carries the map without this dispatch (or an
107
+ * intersection on top of it, which the warning below would otherwise apply to)
108
+ * having to mention it. `object.compute` is the one exception, taking its
109
+ * `$Adaptations` explicitly because its Fabricator is parameterized by the
110
+ * computed value and source rather than by the Schema.
119
111
  *
120
- * Every branch's own `Fabricator<$Schema>` type already carries a
121
- * `.schema` field (see each kind's `Core.ts`) — *not* added here via an
122
- * extra `& { schema: ... }` intersection: wrapping an already-named
123
- * type in a fresh intersection defeats a later `infer` over it (e.g.
124
- * each kind's own `Fabrication<$Fabricator>` helper, which narrows via
125
- * `extends Fabricator<infer $Schema>`) — TypeScript can't always
126
- * decompose the intersection back to recover `$Schema`, and silently
127
- * widens to the generic's constraint instead.
112
+ * Every branch's own `Fabricator<$Schema>` type already carries a `.schema`
113
+ * field (see each kind's `Core.ts`) — _not_ added here via an extra `& {
114
+ * schema: ... }` intersection: wrapping an already-named type in a fresh
115
+ * intersection defeats a later `infer` over it (e.g. each kind's own
116
+ * `Fabrication<$Fabricator>` helper, which narrows via `extends
117
+ * Fabricator<infer $Schema>`) — TypeScript can't always decompose the
118
+ * intersection back to recover `$Schema`, and silently widens to the generic's
119
+ * constraint instead.
128
120
  */
129
121
  export type AsFabricator<$Schema> =
130
122
  /**
@@ -2,95 +2,76 @@ import type { RandomSource } from "../Random/Types";
2
2
  import type { PlainObject } from "../Utility/Types";
3
3
  import type { Config, Instance, Overlay, Stack } from "./Types";
4
4
  /**
5
- * `combinatorial`'s default limit — `2**10`, so it admits ten
6
- * independent binary axes before requiring the caller to raise it
7
- * explicitly. Each enumerated instance costs a full build and
8
- * fabricate, so this is as much a wall-clock guard as a combinatorial
9
- * one.
5
+ * `combinatorial`'s default limit — `2**10`, so it admits ten independent
6
+ * binary axes before requiring the caller to raise it explicitly. Each
7
+ * enumerated instance costs a full build and fabricate, so this is as much a
8
+ * wall-clock guard as a combinatorial one.
10
9
  */
11
10
  export declare const DEFAULT_COMBINATORIAL_LIMIT = 1024;
12
11
  /**
13
- * The single place a `Config` inherits from a base — `initialize` lays
14
- * its own config over an empty `{}` base (nothing to inherit, so every
15
- * field falls through to a hardcoded default: an empty seed, wall-clock
16
- * `clock`, the built-in algorithm, `resolveAttribution(undefined)`'s
17
- * `"call site"` resolution, the default registry, the default
18
- * combinatorial limit), and `fork` lays its overlay over the instance
19
- * it was called on (a full, already-resolved `Config`, so every field
20
- * has a real value to fall back to). `base` is typed
21
- * `Partial<Config<PlainObject>>` rather than `Config` specifically so
22
- * both calls go through the same function.
12
+ * The single place a `Config` inherits from a base — `initialize` lays its own
13
+ * config over an empty `{}` base (nothing to inherit, so every field falls
14
+ * through to a hardcoded default: an empty seed, wall-clock `clock`, the
15
+ * built-in algorithm, `resolveAttribution(undefined)`'s `"call site"`
16
+ * resolution, the default registry, the default combinatorial limit), and
17
+ * `fork` lays its overlay over the instance it was called on (a full,
18
+ * already-resolved `Config`, so every field has a real value to fall back to).
19
+ * `base` is typed `Partial<Config<PlainObject>>` rather than `Config`
20
+ * specifically so both calls go through the same function.
23
21
  *
24
- * `seed` composes onto the base rather than replacing it only when
25
- * tagged with `layer(...)` (`{@link isLayered}`) — a bare `seed` (the
26
- * ordinary meaning everywhere else in this library) replaces the
27
- * base's outright, and an omitted `seed` inherits the base's unchanged
28
- * (or, at the root, an empty mixer via `normalizeSeed(undefined)`,
29
- * unless an env var supplies one). Wall-clock `clock` is the default
30
- * entropy; `seed` is an optional mixer.
22
+ * `seed` composes onto the base rather than replacing it only when tagged with
23
+ * `layer(...)` (`{@link isLayered}`) — a bare `seed` (the ordinary meaning
24
+ * everywhere else in this library) replaces the base's outright, and an omitted
25
+ * `seed` inherits the base's unchanged (or, at the root, an empty mixer via
26
+ * `normalizeSeed(undefined)`, unless an env var supplies one). Wall-clock
27
+ * `clock` is the default entropy; `seed` is an optional mixer.
31
28
  *
32
- * `attribution` resolves through `resolveAttribution` at most once per
33
- * call, and only when it's actually needed:
34
- * - an explicit `over.attribution` always wins (resolved fresh, so
35
- * `fork({ attribution: { kind: "call site" } })` roots at *that*
36
- * call);
37
- * - otherwise an already-resolved `base.attribution` is reused as-is
38
- * — never re-resolved, which keeps a fork from silently re-rooting
39
- * `"call site"` at wherever `fork()` itself happens to be called
40
- * (`resolveCallerFile()` skips this library's own frames, so calling
41
- * it from here still lands on the user's call site either way);
42
- * - only when neither is available (the root case, `base.attribution`
43
- * absent) does this fall back to resolving the `"call site"`
44
- * default.
45
- * That also keeps `initialize({ attribution: { kind: "none" } })` or
46
- * any other explicit override — from paying for a stack walk whose
47
- * result would be immediately discarded.
29
+ * `attribution` resolves through `resolveAttribution` at most once per call,
30
+ * and only when it's actually needed:
31
+ *
32
+ * - an explicit `over.attribution` always wins (resolved fresh, so `fork({
33
+ * attribution: { kind: "call site" } })` roots at _that_ call);
34
+ * - otherwise an already-resolved `base.attribution` is reused as-is — never
35
+ * re-resolved, which keeps a fork from silently re-rooting `"call site"` at
36
+ * wherever `fork()` itself happens to be called (`resolveCallerFile()` skips
37
+ * this library's own frames, so calling it from here still lands on the
38
+ * user's call site either way);
39
+ * - only when neither is available (the root case, `base.attribution` absent)
40
+ * does this fall back to resolving the `"call site"` default. That also keeps
41
+ * `initialize({ attribution: { kind: "none" } })` — or any other explicit
42
+ * override from paying for a stack walk whose result would be immediately
43
+ * discarded.
48
44
  *
49
45
  * `algorithm`/`types`: wholesale replacement when given, matching how
50
46
  * `initialize({ types })` already behaves — no deep merge;
51
47
  * `registry.extend(...)` is the existing tool for that. `limits` is
52
48
  * re-validated through `resolveCombinatorialLimit` whenever given (or
53
- * inherited, or defaulted), so a bad limit fails at
54
- * `fork()`/`initialize()` time rather than at first use. `clock`
55
- * follows the given → inherited → default shape `algorithm` does, but
56
- * stays *unresolved* only for the explicit `"seeded"` sentinel: an
57
- * explicit `Date` and the unconfigured wall-clock default are stored
58
- * as epoch milliseconds (a stated instant, inherited as-is from then
59
- * on), while `"seeded"` is left as the sentinel rather than collapsed
60
- * to a number, so `resolveClock` can re-derive it from whichever
61
- * `seed` is actually in effect at read time. An omitted `clock` on a
62
- * `fork`/`wrap` whose seed changed therefore keeps the parent's
63
- * instant unless that parent was itself `"seeded"`.
49
+ * inherited, or defaulted), so a bad limit fails at `fork()`/`initialize()`
50
+ * time rather than at first use. `clock` follows the given → inherited →
51
+ * default shape `algorithm` does, but stays _unresolved_ only for the explicit
52
+ * `"seeded"` sentinel: an explicit `Date` and the unconfigured wall-clock
53
+ * default are stored as epoch milliseconds (a stated instant, inherited as-is
54
+ * from then on), while `"seeded"` is left as the sentinel rather than collapsed
55
+ * to a number, so `resolveClock` can re-derive it from whichever `seed` is
56
+ * actually in effect at read time. An omitted `clock` on a `fork`/`wrap` whose
57
+ * seed changed therefore keeps the parent's instant unless that parent was
58
+ * itself `"seeded"`.
64
59
  */
65
60
  export declare function overlay<$Registry extends PlainObject>(base: Partial<Config<PlainObject>>, over: Overlay<$Registry>): Config<$Registry>;
66
- /**
67
- * Builds a `Stack`: closes over a private `Frame[]`, pushing on `enter`
68
- * and popping in a `finally` — correct even around a `throw` from
69
- * `block`. One per root `initialize()`, threaded — never re-created —
70
- * through every `fork`/`wrap` descended from it, so it stays
71
- * per-lineage rather than module-level: two unrelated `initialize()`
72
- * calls each get their own stack and can never perturb each other,
73
- * while every instance sharing one stack (a fork included, no matter
74
- * where in the lineage it was created) resolves against the same
75
- * active frame.
76
- */
77
- export declare function toStack(): Stack;
78
61
  /**
79
62
  * The shared body `initialize` and `fork` both reduce to: build a
80
63
  * `RandomSource` from an already-resolved `Config`, then everything an
81
- * `Instance` exposes off of it. Returns the `RandomSource` alongside
82
- * the `Instance` — `initialize`/`fork` discard it, `wrap` keeps it to
83
- * stash on the `Frame` it pushes, so implicit (ambient) and explicit
84
- * (`scope.Fabricator`) construction inside one `wrap` resolve against
85
- * the very same source rather than each independently re-deriving one
86
- * from the same config (and so silently diverging/duplicating
87
- * construction ordinals).
64
+ * `Instance` exposes off of it. Returns the `RandomSource` alongside the
65
+ * `Instance` — `initialize`/`fork` discard it, `wrap` keeps it to stash on the
66
+ * `Frame` it pushes, so implicit (ambient) and explicit (`scope.Fabricator`)
67
+ * construction inside one `wrap` resolve against the very same source rather
68
+ * than each independently re-deriving one from the same config (and so silently
69
+ * diverging/duplicating construction ordinals).
88
70
  *
89
- * `stack` is threaded straight through to `Constructor`/`enumerables`
90
- * — this function never reads or writes it itself, only passes it
91
- * along so every built `Fabricator`/`combinatorial`/`coverage` can
92
- * consult whichever frame is active *at the moment each is called*,
93
- * not at this moment.
71
+ * `stack` is threaded straight through to `Constructor`/`enumerables` — this
72
+ * function never reads or writes it itself, only passes it along so every built
73
+ * `Fabricator`/`combinatorial`/`coverage` can consult whichever frame is active
74
+ * _at the moment each is called_, not at this moment.
94
75
  */
95
76
  export declare function instantiate<$Registry extends PlainObject>(config: Config<$Registry>, stack: Stack): {
96
77
  instance: Instance<$Registry>;
@@ -0,0 +1,14 @@
1
+ import type { Stack } from "../Types";
2
+ /**
3
+ * The asynchronous carrier, and the **only** module in this package importing
4
+ * anything from `node:`. Nothing imports it directly: `Instance/Core.ts`
5
+ * imports `#stack`, whose `node`/`bun`/`deno` conditions (`package.json`)
6
+ * resolve here while `default` resolves to `./sync.ts`. That is what keeps the
7
+ * package importable on a runtime with no `node:async_hooks` while every
8
+ * runtime that has one gets async-safe `wrap` with nothing to configure.
9
+ *
10
+ * `AsyncLocalStorage.run` returns whatever `block` returns, so this satisfies
11
+ * `enter`'s sync-preserving `<$Return>` signature exactly as the sync carrier
12
+ * does — a synchronous `wrap` is unaffected by which carrier is in play.
13
+ */
14
+ export declare function toStack(): Stack;
@@ -0,0 +1,14 @@
1
+ import type { Stack } from "../Types";
2
+ /**
3
+ * The synchronous carrier: a private `Frame[]`, pushed on `enter` and popped in
4
+ * a `finally` — correct even around a `throw` from `block`.
5
+ *
6
+ * Selected by the `#stack` `default` condition (`package.json`), i.e. on any
7
+ * runtime without `node:async_hooks` — in practice a browser bundle. Its frame
8
+ * cannot survive an `await`: `enter` returns `block()` without awaiting, so an
9
+ * async block's frame unwinds at the block's first suspension point, and a
10
+ * shared LIFO could not represent two overlapping scopes even if it did await.
11
+ * Both are why `asynchronous` is `false` and `wrap` refuses an async block here
12
+ * rather than resolving it against the base instance with no signal.
13
+ */
14
+ export declare function toStack(): Stack;