@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.
- package/README.md +1 -7
- package/dist/esm/Error/index.js +8 -0
- package/dist/esm/Instance/Core.js +8 -17
- package/dist/esm/Instance/Stack/Async.js +10 -0
- package/dist/esm/Instance/Stack/Sync.js +16 -0
- package/dist/esm/Primitive/bigint/Registry.js +12 -12
- package/dist/esm/Primitive/boolean/Registry.js +2 -1
- package/dist/esm/Primitive/date/Registry.js +15 -14
- package/dist/esm/Primitive/null/Registry.js +2 -1
- package/dist/esm/Primitive/number/Registry.js +18 -17
- package/dist/esm/Primitive/symbol/Registry.js +2 -1
- package/dist/esm/Primitive/undefined/Registry.js +2 -1
- package/dist/esm/Random/CallSite.js +27 -13
- package/dist/esm/Utility/Core.js +6 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/internal.js +2 -1
- package/dist/types/Adapter/Core.d.ts +29 -32
- package/dist/types/Adapter/Types.d.ts +78 -88
- package/dist/types/Bound.d.ts +15 -15
- package/dist/types/Distribution/index.d.ts +54 -61
- package/dist/types/Enumeration/Enumerate.d.ts +21 -23
- package/dist/types/Enumeration/Plan.d.ts +22 -26
- package/dist/types/Enumeration/Types.d.ts +38 -43
- package/dist/types/Error/index.d.ts +94 -76
- package/dist/types/Fabricator/Constructor.d.ts +23 -25
- package/dist/types/Fabricator/Types.d.ts +73 -81
- package/dist/types/Instance/Core.d.ts +54 -73
- package/dist/types/Instance/Stack/Async.d.ts +14 -0
- package/dist/types/Instance/Stack/Sync.d.ts +14 -0
- package/dist/types/Instance/Types.d.ts +91 -89
- package/dist/types/Primitive/always/Schema.d.ts +8 -8
- package/dist/types/Primitive/always/Types.d.ts +7 -7
- package/dist/types/Primitive/array/Registry.d.ts +10 -8
- package/dist/types/Primitive/array/Schema.d.ts +4 -5
- package/dist/types/Primitive/array/Types.d.ts +6 -6
- package/dist/types/Primitive/bigint/Registry.d.ts +6 -6
- package/dist/types/Primitive/bigint/Schema.d.ts +8 -8
- package/dist/types/Primitive/bigint/Types.d.ts +5 -5
- package/dist/types/Primitive/boolean/Outcomes.d.ts +8 -8
- package/dist/types/Primitive/boolean/Registry.d.ts +2 -12
- package/dist/types/Primitive/boolean/Schema.d.ts +8 -8
- package/dist/types/Primitive/boolean/Types.d.ts +3 -3
- package/dist/types/Primitive/choice/Fabricator.d.ts +6 -7
- package/dist/types/Primitive/choice/Registry.d.ts +13 -13
- package/dist/types/Primitive/choice/Schema.d.ts +6 -6
- package/dist/types/Primitive/choice/Types.d.ts +11 -11
- package/dist/types/Primitive/date/Registry.d.ts +25 -48
- package/dist/types/Primitive/date/Schema.d.ts +9 -10
- package/dist/types/Primitive/date/Types.d.ts +4 -4
- package/dist/types/Primitive/enum/Registry.d.ts +13 -13
- package/dist/types/Primitive/enum/Schema.d.ts +5 -5
- package/dist/types/Primitive/enum/Types.d.ts +17 -19
- package/dist/types/Primitive/namespace.d.ts +10 -10
- package/dist/types/Primitive/null/Registry.d.ts +2 -2
- package/dist/types/Primitive/null/Schema.d.ts +2 -2
- package/dist/types/Primitive/null/Types.d.ts +3 -3
- package/dist/types/Primitive/nullable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/nullable/Schema.d.ts +13 -13
- package/dist/types/Primitive/nullable/Types.d.ts +9 -10
- package/dist/types/Primitive/nullish/Fabricator.d.ts +12 -13
- package/dist/types/Primitive/nullish/Schema.d.ts +8 -8
- package/dist/types/Primitive/nullish/Types.d.ts +12 -13
- package/dist/types/Primitive/number/Registry.d.ts +20 -38
- package/dist/types/Primitive/number/Schema.d.ts +11 -12
- package/dist/types/Primitive/number/Types.d.ts +13 -13
- package/dist/types/Primitive/number/defaults.d.ts +3 -3
- package/dist/types/Primitive/object/Fabricator.d.ts +15 -15
- package/dist/types/Primitive/object/Registry.d.ts +8 -8
- package/dist/types/Primitive/object/Schema.d.ts +10 -10
- package/dist/types/Primitive/object/Types.d.ts +20 -22
- package/dist/types/Primitive/object/compute/Fabricator.d.ts +4 -5
- package/dist/types/Primitive/object/compute/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/compute/Types.d.ts +19 -20
- package/dist/types/Primitive/object/omittable/Fabricator.d.ts +10 -10
- package/dist/types/Primitive/object/omittable/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/omittable/Schema.d.ts +11 -11
- package/dist/types/Primitive/object/omittable/Types.d.ts +14 -15
- package/dist/types/Primitive/object/optional/Fabricator.d.ts +16 -18
- package/dist/types/Primitive/object/optional/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/optional/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/optional/Types.d.ts +17 -17
- package/dist/types/Primitive/opaque/Registry.d.ts +3 -3
- package/dist/types/Primitive/opaque/Schema.d.ts +8 -9
- package/dist/types/Primitive/record/Registry.d.ts +8 -6
- package/dist/types/Primitive/record/Schema.d.ts +9 -11
- package/dist/types/Primitive/record/Types.d.ts +25 -25
- package/dist/types/Primitive/recursive/Fabricator.d.ts +16 -17
- package/dist/types/Primitive/recursive/Registry.d.ts +6 -7
- package/dist/types/Primitive/recursive/Schema.d.ts +8 -8
- package/dist/types/Primitive/recursive/Terminate.d.ts +13 -14
- package/dist/types/Primitive/recursive/Types.d.ts +31 -31
- package/dist/types/Primitive/recursive/self/Fabricator.d.ts +11 -12
- package/dist/types/Primitive/recursive/self/Schema.d.ts +10 -10
- package/dist/types/Primitive/recursive/self/Types.d.ts +7 -8
- package/dist/types/Primitive/string/Constants.d.ts +12 -13
- package/dist/types/Primitive/string/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/string/Registry.d.ts +10 -16
- package/dist/types/Primitive/string/Schema.d.ts +5 -5
- package/dist/types/Primitive/string/Types.d.ts +17 -17
- package/dist/types/Primitive/symbol/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/symbol/Registry.d.ts +4 -11
- package/dist/types/Primitive/symbol/Schema.d.ts +6 -6
- package/dist/types/Primitive/symbol/Types.d.ts +2 -2
- package/dist/types/Primitive/tuple/Fabricator.d.ts +7 -8
- package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
- package/dist/types/Primitive/tuple/Types.d.ts +24 -25
- package/dist/types/Primitive/undefinable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/undefinable/Schema.d.ts +13 -13
- package/dist/types/Primitive/undefinable/Types.d.ts +10 -10
- package/dist/types/Primitive/undefined/Registry.d.ts +2 -2
- package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
- package/dist/types/Primitive/undefined/Types.d.ts +3 -3
- package/dist/types/Random/CallSite.d.ts +63 -44
- package/dist/types/Random/Generator/sfc32.d.ts +4 -4
- package/dist/types/Random/Types.d.ts +214 -236
- package/dist/types/Random/index.d.ts +63 -70
- package/dist/types/Schema/Core.d.ts +19 -21
- package/dist/types/Schema/Registry.d.ts +3 -3
- package/dist/types/Schema/Types.d.ts +41 -48
- package/dist/types/Types.d.ts +39 -45
- package/dist/types/Utility/Core.d.ts +18 -9
- package/dist/types/index.d.ts +110 -108
- package/dist/types/internal.d.ts +68 -37
- 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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
-
*
|
|
16
|
-
* `toStreamFromTrace(algorithm, trace)`. Bound once in `construct()` to
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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
|
-
*
|
|
30
|
-
* `
|
|
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
|
-
*
|
|
35
|
-
*
|
|
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
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
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
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* `
|
|
117
|
-
*
|
|
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
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* (
|
|
29
|
-
*
|
|
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
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* call);
|
|
37
|
-
* - otherwise an already-resolved `base.attribution` is reused as-is
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - only when neither is available (the root case, `base.attribution`
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* `
|
|
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
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
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
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
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;
|