@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
|
@@ -3,25 +3,24 @@ import type { Constructor } from "../Fabricator/Constructor";
|
|
|
3
3
|
import type { Algorithm, Attribution, Layered, RandomSource, Seed } from "../Random/Types";
|
|
4
4
|
import type { PlainObject } from "../Utility/Types";
|
|
5
5
|
/**
|
|
6
|
-
* A fully resolved instance configuration — every field present, nothing
|
|
7
|
-
*
|
|
6
|
+
* A fully resolved instance configuration — every field present, nothing left
|
|
7
|
+
* to default. `Overlay` is what `fork` accepts; `overlay()`
|
|
8
8
|
* (`Instance/Core.ts`) is the only thing producing a complete `Config`.
|
|
9
9
|
*
|
|
10
|
-
* Two fields are declared at their caller-facing type but always hold
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* `
|
|
21
|
-
*
|
|
22
|
-
* (`
|
|
23
|
-
*
|
|
24
|
-
* (`instantiate`, the `context.clock` getter) rather than once here.
|
|
10
|
+
* Two fields are declared at their caller-facing type but always hold their
|
|
11
|
+
* resolved form once `overlay()` has run: `seed` is `Seed` because that is what
|
|
12
|
+
* a caller may supply, but always holds the normalized array (`Instance.seed`
|
|
13
|
+
* is the authoritative read); `attribution` is `Attribution` for the same
|
|
14
|
+
* reason but always holds a `ResolvedAttribution`, a subtype. `clock` is
|
|
15
|
+
* different from both: unlike `seed`/`attribution`, it holds _either_ a
|
|
16
|
+
* resolved instant (epoch milliseconds) or the unresolved `"seeded"` policy —
|
|
17
|
+
* never collapsed to a number by `overlay()` when `"seeded"`, because that
|
|
18
|
+
* policy must re-derive whenever the seed it composes changes (a `fork({ seed:
|
|
19
|
+
* layer(...) })`). The unconfigured default is a wall- clock number, inherited
|
|
20
|
+
* as-is like an explicit `Date`. `resolveClock` (`Instance/Core.ts`) is the one
|
|
21
|
+
* place that resolves `"seeded"` to a number, called fresh wherever the clock
|
|
22
|
+
* actually matters (`instantiate`, the `context.clock` getter) rather than once
|
|
23
|
+
* here.
|
|
25
24
|
*/
|
|
26
25
|
export type Config<$Registry extends PlainObject> = {
|
|
27
26
|
readonly seed: Seed;
|
|
@@ -32,54 +31,60 @@ export type Config<$Registry extends PlainObject> = {
|
|
|
32
31
|
readonly clock: number | "seeded";
|
|
33
32
|
};
|
|
34
33
|
/**
|
|
35
|
-
* What `fork` accepts — a `Config` to lay over a base, every field
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* `
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* instance seed; omitting `clock` at the root captures wall-clock time
|
|
48
|
-
* instead.
|
|
34
|
+
* What `fork` accepts — a `Config` to lay over a base, every field optional.
|
|
35
|
+
* Identical to `Partial<Config>` but for `seed`, which additionally accepts a
|
|
36
|
+
* {@link Layered}: a bare `Seed` replaces the base's seed outright (what `seed`
|
|
37
|
+
* means everywhere else in this library), `layer(seed)` appends onto it
|
|
38
|
+
* (`[...base.seed, ...seed]`) — the shape a wrapping integration wants, and
|
|
39
|
+
* what `ConstructorOptions`' layered form is for a single construction.
|
|
40
|
+
* Omitting `seed` inherits the base's unchanged. `clock` similarly accepts the
|
|
41
|
+
* caller-facing `Date | "seeded"` rather than `Config`'s own resolved `number |
|
|
42
|
+
* "seeded"`, so a caller can hand in a literal instant without converting it to
|
|
43
|
+
* epoch milliseconds themselves. `"seeded"` is the explicit opt-in that derives
|
|
44
|
+
* "now" from the instance seed; omitting `clock` at the root captures
|
|
45
|
+
* wall-clock time instead.
|
|
49
46
|
*
|
|
50
47
|
* `initialize`'s own parameter keeps a plain `seed?: Seed`, so passing
|
|
51
|
-
* `layer(...)` there is a compile error: there is no base to layer onto
|
|
52
|
-
*
|
|
48
|
+
* `layer(...)` there is a compile error: there is no base to layer onto at the
|
|
49
|
+
* root.
|
|
53
50
|
*/
|
|
54
51
|
export type Overlay<$Registry extends PlainObject> = Partial<Omit<Config<$Registry>, "seed" | "clock">> & {
|
|
55
52
|
readonly seed?: Seed | Layered;
|
|
56
53
|
readonly clock?: Date | "seeded" | undefined;
|
|
57
54
|
};
|
|
58
55
|
/**
|
|
59
|
-
* One active `wrap` — its resolved config plus the single `RandomSource`
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* its own.
|
|
56
|
+
* One active `wrap` — its resolved config plus the single `RandomSource` every
|
|
57
|
+
* build reached inside that `wrap` shares, whether reached implicitly (any
|
|
58
|
+
* instance in the lineage consulting the active frame) or explicitly
|
|
59
|
+
* (`scope.Fabricator`, the `Instance` passed to the block). Storing the scope's
|
|
60
|
+
* own already-built `source` here, rather than each consumer re-deriving one
|
|
61
|
+
* from `config`, keeps the two routes resolving against the _same_ source —
|
|
62
|
+
* sharing one set of construction-ordinal counters — instead of each silently
|
|
63
|
+
* starting its own.
|
|
68
64
|
*/
|
|
69
65
|
export type Frame = {
|
|
70
66
|
readonly config: Config<PlainObject>;
|
|
71
67
|
readonly source: RandomSource;
|
|
72
68
|
};
|
|
73
69
|
/**
|
|
74
|
-
* The per-lineage ambient stack. Created once at a root `initialize()`
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* lineage that instance was itself created.
|
|
70
|
+
* The per-lineage ambient stack. Created once at a root `initialize()` and
|
|
71
|
+
* threaded — never re-created — through every `fork`/`wrap` descended from it
|
|
72
|
+
* (see `instantiate`, `Instance/Core.ts`). Two unrelated `initialize()` calls
|
|
73
|
+
* stay fully isolated; one lineage's `wrap` reaches every instance in that
|
|
74
|
+
* lineage — its `Fabricator`, `combinatorial`, and `coverage` alike —
|
|
75
|
+
* regardless of where in the lineage that instance was itself created.
|
|
81
76
|
*/
|
|
82
77
|
export type Stack = {
|
|
78
|
+
/**
|
|
79
|
+
* Whether a frame survives an `await` inside the block it was entered for.
|
|
80
|
+
*
|
|
81
|
+
* `false` means the carrier is a plain LIFO whose frame unwinds at the
|
|
82
|
+
* block's first suspension point — correct for synchronous use, and the
|
|
83
|
+
* reason `wrap` (`Instance/Core.ts`) rejects an async block outright rather
|
|
84
|
+
* than letting a build after the `await` silently resolve against the base
|
|
85
|
+
* instance. See `Instance/Stack/Sync.ts` and `Instance/Stack/Async.ts`.
|
|
86
|
+
*/
|
|
87
|
+
readonly asynchronous: boolean;
|
|
83
88
|
current(): Frame | undefined;
|
|
84
89
|
/**
|
|
85
90
|
* Push `frame`, run `block`, pop — in a `finally`, so a frame unwinds
|
|
@@ -88,11 +93,11 @@ export type Stack = {
|
|
|
88
93
|
enter<$Return>(frame: Frame, block: () => $Return): $Return;
|
|
89
94
|
};
|
|
90
95
|
/**
|
|
91
|
-
* The configuration in effect
|
|
92
|
-
*
|
|
93
|
-
* `ConstructionContext` (`Fabricator/Types.ts`), which is one
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
+
* The configuration in effect _right now_ — the innermost active `wrap` frame,
|
|
97
|
+
* or this instance's own when there is none. Distinct from
|
|
98
|
+
* `ConstructionContext` (`Fabricator/Types.ts`), which is one construction's
|
|
99
|
+
* internal dispatch plumbing; this is the caller-facing "what configuration is
|
|
100
|
+
* in effect."
|
|
96
101
|
*/
|
|
97
102
|
export type Context = {
|
|
98
103
|
readonly seed: ReadonlyArray<string>;
|
|
@@ -101,67 +106,64 @@ export type Context = {
|
|
|
101
106
|
readonly clock: number;
|
|
102
107
|
};
|
|
103
108
|
/**
|
|
104
|
-
* A single initialized library instance: the registry it was given, and
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
+
* A single initialized library instance: the registry it was given, and a
|
|
110
|
+
* `construct()` bound to its own isolated randomness — its own seed, builder,
|
|
111
|
+
* and per-file overrides/streams, held internally and never shared with any
|
|
112
|
+
* other `initialize()` call. Independently initialized instances (e.g. parallel
|
|
113
|
+
* tests) can never perturb each other.
|
|
109
114
|
*/
|
|
110
115
|
export interface Instance<$Registry extends PlainObject> extends Pick<RandomSource, "seed"> {
|
|
111
116
|
/** The registry of type definers this instance was initialized with. */
|
|
112
117
|
readonly T: $Registry;
|
|
113
118
|
/**
|
|
114
119
|
* Turn a Schema built from `T` into a live Fabricator, deriving fresh
|
|
115
|
-
* randomness from this instance's own seed for whichever leaves
|
|
116
|
-
*
|
|
120
|
+
* randomness from this instance's own seed for whichever leaves actually need
|
|
121
|
+
* it.
|
|
117
122
|
*/
|
|
118
123
|
Fabricator: Constructor;
|
|
119
124
|
/**
|
|
120
|
-
* Every combination of every enumerable node in `schema` — every enum
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
125
|
+
* Every combination of every enumerable node in `schema` — every enum member,
|
|
126
|
+
* both sides of an optional field, and so on — as a cartesian product,
|
|
127
|
+
* lazily. Throws eagerly, before producing anything, if the count exceeds
|
|
128
|
+
* `limits.combinatorial` (see `initialize`'s config).
|
|
124
129
|
*/
|
|
125
130
|
combinatorial: Enumerable;
|
|
126
131
|
/**
|
|
127
|
-
* The minimum set of instances such that every option of every
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
+
* The minimum set of instances such that every option of every enumerable
|
|
133
|
+
* node in `schema` appears at least once — count equal to the _widest_ single
|
|
134
|
+
* axis, not the product, with narrower axes cycling to fill it. Unbounded:
|
|
135
|
+
* its count can never exceed the schema as written, so unlike `combinatorial`
|
|
136
|
+
* it carries no limit.
|
|
132
137
|
*/
|
|
133
138
|
coverage: Enumerable;
|
|
134
139
|
/**
|
|
135
140
|
* Derive a new instance laid over this one: anything the overlay names
|
|
136
141
|
* overrides, anything it omits inherits. A bare `seed` replaces this
|
|
137
142
|
* instance's seed; `seed: layer(...)` appends onto it. A peer of an
|
|
138
|
-
* `initialize()` return value in every respect, including its own
|
|
139
|
-
* `fork`.
|
|
143
|
+
* `initialize()` return value in every respect, including its own `fork`.
|
|
140
144
|
*/
|
|
141
145
|
fork<const $ForkRegistry extends PlainObject = $Registry>(overlay?: Overlay<$ForkRegistry>): Instance<$ForkRegistry>;
|
|
142
146
|
/**
|
|
143
|
-
* `fork(overlay)`, made ambient for the synchronous extent of `block`:
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* after an `await` inside `block` sees this instance's own
|
|
147
|
+
* `fork(overlay)`, made ambient for the synchronous extent of `block`: every
|
|
148
|
+
* `new Fabricator(...)`, `combinatorial(...)`, and `coverage(...)` reached
|
|
149
|
+
* inside — on this instance or any other in the same lineage — resolves
|
|
150
|
+
* against the fork instead, with nothing threaded through. The fork is also
|
|
151
|
+
* passed to `block`: use it explicitly where that reads better, and
|
|
152
|
+
* _necessarily_ for any async work, which the ambient frame does not survive
|
|
153
|
+
* — a build reached after an `await` inside `block` sees this instance's own
|
|
151
154
|
* configuration again, not the wrap's.
|
|
152
155
|
*
|
|
153
|
-
* A nested `wrap` lays over whichever frame is currently active, not
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
156
|
+
* A nested `wrap` lays over whichever frame is currently active, not over the
|
|
157
|
+
* instance it was called on — so `overlay.seed: layer(...)` accumulates with
|
|
158
|
+
* nesting depth while a bare `seed` still replaces outright, discarding every
|
|
159
|
+
* enclosing layer.
|
|
157
160
|
*/
|
|
158
161
|
wrap<$Return, const $WrapRegistry extends PlainObject = $Registry>(overlay: Overlay<$WrapRegistry>, block: (scope: Instance<$WrapRegistry>) => $Return): $Return;
|
|
159
162
|
/**
|
|
160
|
-
* The configuration in effect right now: the innermost active `wrap`
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* `wrap`s.
|
|
163
|
+
* The configuration in effect right now: the innermost active `wrap` frame's,
|
|
164
|
+
* or this instance's own outside any `wrap`. A live view, not a snapshot —
|
|
165
|
+
* reflects whichever frame is active at the moment each property is read,
|
|
166
|
+
* since one `Instance` outlives any number of `wrap`s.
|
|
165
167
|
*/
|
|
166
168
|
readonly context: Context;
|
|
167
169
|
}
|
|
@@ -2,17 +2,17 @@ import { type AdaptationEntry } from "../../Adapter/Core";
|
|
|
2
2
|
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
|
|
3
3
|
import type { Core, Value } from "./Types";
|
|
4
4
|
/**
|
|
5
|
-
* A fixed value, so unlike every other kind there is no `.as()` — nothing
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* A fixed value, so unlike every other kind there is no `.as()` — nothing left
|
|
6
|
+
* to override about producing it. `adapt` still applies: what a value _means_
|
|
7
|
+
* to an external schema library is a separate question from what it fabricates
|
|
8
|
+
* to, and for a value TypeBox cannot pin exactly (a `symbol`, or any value's
|
|
9
|
+
* _static_ type — see `Adapter/TypeBox`'s `toConst`) it is the only way to
|
|
10
|
+
* close the gap.
|
|
11
11
|
*/
|
|
12
12
|
export interface Schema<$Value extends Value = Value, $Adaptations extends Adaptations = {}> extends Core<$Value, $Adaptations> {
|
|
13
13
|
/**
|
|
14
|
-
* Override what this schema maps to in one or more external schema
|
|
15
|
-
*
|
|
14
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
15
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
16
16
|
*/
|
|
17
17
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Value, $Adaptations>>) => $Returnable) => Schema<$Value, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
18
18
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
3
|
/**
|
|
4
|
-
* Any value at all. Deliberately unconstrained: fabricating a fixed value
|
|
5
|
-
*
|
|
6
|
-
* `TLiteralValue` leaking into the primitive. Narrowing back to what a
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Any value at all. Deliberately unconstrained: fabricating a fixed value needs
|
|
5
|
+
* nothing of it. A `string | number | boolean` cap would be TypeBox's
|
|
6
|
+
* `TLiteralValue` leaking into the primitive. Narrowing back to what a given
|
|
7
|
+
* external schema library can express is that library's adapter's job — see
|
|
8
|
+
* `Adapter/TypeBox`'s `toConst`.
|
|
9
9
|
*
|
|
10
|
-
* Kept as a named alias: it is the public name for this kind's domain, and
|
|
11
|
-
*
|
|
10
|
+
* Kept as a named alias: it is the public name for this kind's domain, and both
|
|
11
|
+
* `Registry.ts` and `Schema.ts` use it as a bound.
|
|
12
12
|
*/
|
|
13
13
|
export type Value = unknown;
|
|
14
14
|
export type Fabricated<$Value extends Value> = $Value;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { Produce } from "../../Random/Types";
|
|
2
2
|
import { Schema } from "./Schema";
|
|
3
3
|
import type { Definition, Fabricated, InputWhereby } from "./Types";
|
|
4
|
-
|
|
4
|
+
type ThisRegistry<$Definition extends Definition> = {
|
|
5
5
|
/**
|
|
6
|
-
* An array of `definition`, repeated `whereby.length` times — either a
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* An array of `definition`, repeated `whereby.length` times — either a fixed
|
|
7
|
+
* count, or uniformly across `[length.min, length.max]` with `length.min`
|
|
8
|
+
* defaulting to inclusive 0, so an empty array is a legitimate outcome when
|
|
9
|
+
* no `min` is given. Exclusive ends use a Bound object; a bare `length: N` is
|
|
10
|
+
* stored as min = max = N inclusive.
|
|
11
11
|
*/
|
|
12
12
|
whereby: (whereby: InputWhereby) => Schema<$Definition>;
|
|
13
13
|
/**
|
|
14
|
-
* An array whose production is `produce`, in full, instead of drawn
|
|
15
|
-
*
|
|
14
|
+
* An array whose production is `produce`, in full, instead of drawn element
|
|
15
|
+
* by element.
|
|
16
16
|
*/
|
|
17
17
|
as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition>;
|
|
18
18
|
};
|
|
19
|
+
export default function <const $Definition extends Definition>(definition: $Definition): ThisRegistry<$Definition>;
|
|
20
|
+
export {};
|
|
@@ -9,14 +9,13 @@ import type { Core, Definition, Fabricated } from "./Types";
|
|
|
9
9
|
export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
|
|
10
10
|
/**
|
|
11
11
|
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
12
|
-
* `whereby`/`definition` forward, not discarding them, so a later
|
|
13
|
-
*
|
|
14
|
-
* against.
|
|
12
|
+
* `whereby`/`definition` forward, not discarding them, so a later `.as(...)`
|
|
13
|
+
* (or future validation of `produce`) still has them to check against.
|
|
15
14
|
*/
|
|
16
15
|
as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
|
|
17
16
|
/**
|
|
18
|
-
* Override what this schema maps to in one or more external schema
|
|
19
|
-
*
|
|
17
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
18
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
20
19
|
*/
|
|
21
20
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Definition, $Adaptations>>) => $Returnable) => Schema<$Definition, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
22
21
|
}
|
|
@@ -19,12 +19,12 @@ export type Whereby = {
|
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* `whereby` (a length spec — no natural bound to fuzz to, so unlike
|
|
22
|
-
* `number`/`date` there's no bare form), optionally overridden by an
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* `number`/`date` there's no bare form), optionally overridden by an opaque
|
|
23
|
+
* `as` production, carried alongside `whereby` rather than replacing it (when
|
|
24
|
+
* `whereby` was already set) so a prior length spec survives `as` for future
|
|
25
|
+
* validation. `definition` stays required regardless — it's known at
|
|
26
|
+
* `T.array(...)` call time and describes the element shape TypeBox derives
|
|
27
|
+
* either way.
|
|
28
28
|
*/
|
|
29
29
|
export type Meta<$Definition extends Definition = Definition> = {
|
|
30
30
|
definition: $Definition;
|
|
@@ -4,16 +4,16 @@ import { Schema } from "./Schema";
|
|
|
4
4
|
import type { Fabricated, InputWhereby, Whereby } from "./Types";
|
|
5
5
|
declare const _default: {
|
|
6
6
|
/**
|
|
7
|
-
* The builder carries the primitive's `[Kind]` so it can be named directly
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The builder carries the primitive's `[Kind]` so it can be named directly as
|
|
8
|
+
* a `compute` source — which derives its schema by kind — without first
|
|
9
|
+
* satisfying a `whereby`.
|
|
10
10
|
*/
|
|
11
11
|
[Kind]: "bigint";
|
|
12
12
|
whereby: (whereby: InputWhereby) => Schema<{
|
|
13
13
|
whereby: Whereby;
|
|
14
|
-
}
|
|
14
|
+
}>;
|
|
15
15
|
as: (produce: Produce<Fabricated>) => Schema<{
|
|
16
|
-
produce: Produce<
|
|
17
|
-
}
|
|
16
|
+
produce: Produce<Fabricated>;
|
|
17
|
+
}>;
|
|
18
18
|
};
|
|
19
19
|
export default _default;
|
|
@@ -3,13 +3,13 @@ import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adap
|
|
|
3
3
|
import type { Produce } from "../../Random/Types";
|
|
4
4
|
import type { Core, Fabricated, Meta as ThisMeta } from "./Types";
|
|
5
5
|
/**
|
|
6
|
-
* Buildable `bigint` recipe: a range (`whereby` — required, like `string`;
|
|
7
|
-
*
|
|
6
|
+
* Buildable `bigint` recipe: a range (`whereby` — required, like `string`; no
|
|
7
|
+
* natural bound to fuzz to), or opaque production via `as`.
|
|
8
8
|
*
|
|
9
|
-
* `$Meta` is generic (defaulting to the full `Meta` union) so builder
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
9
|
+
* `$Meta` is generic (defaulting to the full `Meta` union) so builder return
|
|
10
|
+
* types stay narrow — see `number/Schema.ts`. `$Adaptations` is threaded
|
|
11
|
+
* through every builder method for the same reason — see `string/Schema.ts`'s
|
|
12
|
+
* `adapt`.
|
|
13
13
|
*/
|
|
14
14
|
export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends Adaptations = {}> extends Core<$Meta, $Adaptations> {
|
|
15
15
|
/**
|
|
@@ -19,8 +19,8 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
|
|
|
19
19
|
*/
|
|
20
20
|
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
21
21
|
/**
|
|
22
|
-
* Override what this schema maps to in one or more external schema
|
|
23
|
-
*
|
|
22
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
23
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
24
24
|
*/
|
|
25
25
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Meta, $Adaptations>>) => $Returnable) => Schema<$Meta, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
26
26
|
}
|
|
@@ -12,11 +12,11 @@ export type Whereby = {
|
|
|
12
12
|
};
|
|
13
13
|
export type Fabricated = bigint;
|
|
14
14
|
/**
|
|
15
|
-
* A ranged bigint, drawn via `whereby` — no natural bound to fuzz to, so
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* A ranged bigint, drawn via `whereby` — no natural bound to fuzz to, so unlike
|
|
16
|
+
* `number`/`date` there's no bare form — optionally overridden by an opaque
|
|
17
|
+
* `as` production, carried alongside `whereby` rather than replacing it (when
|
|
18
|
+
* `whereby` was already set) so a prior range survives `as` for future
|
|
19
|
+
* validation.
|
|
20
20
|
*/
|
|
21
21
|
export type Meta = {
|
|
22
22
|
whereby: Whereby;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Weight
|
|
3
|
-
* Derived so `assertDrawableKeyedWeights` and `Enumeration/Plan.ts`
|
|
4
|
-
*
|
|
2
|
+
* Weight _keys_ for `.weighted(...)`, not the boolean values themselves.
|
|
3
|
+
* Derived so `assertDrawableKeyedWeights` and `Enumeration/Plan.ts` cannot
|
|
4
|
+
* drift from the named outcome set.
|
|
5
5
|
*
|
|
6
|
-
* Lives here rather than `Types.ts` so that file stays type-only. A
|
|
7
|
-
*
|
|
8
|
-
* module
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
6
|
+
* Lives here rather than `Types.ts` so that file stays type-only. A value
|
|
7
|
+
* export alongside `export type Fabricated = boolean` makes the module a value
|
|
8
|
+
* module, and `export * as boolean` in `Primitive/namespace.ts` then resolves
|
|
9
|
+
* `boolean` to the namespace — a cycle that drops `[Kind]`/`[Meta]` off
|
|
10
|
+
* `Core`.
|
|
11
11
|
*/
|
|
12
12
|
export declare const outcomes: readonly ["true", "false"];
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
2
|
import { Schema } from "./Schema";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[Kind]: "boolean";
|
|
7
|
-
[Meta]: {};
|
|
8
|
-
[Produces]?: Fabricated;
|
|
9
|
-
[Adaptation]?: Adaptations;
|
|
10
|
-
as: (produce: import("../../Random/Types").Produce<Fabricated>) => Schema<{}, Adaptations>;
|
|
11
|
-
weighted: (weights: import("./Types").Weights) => Schema<{}, Adaptations>;
|
|
12
|
-
adapt: <const $Adapter extends import("../..").Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: import("../..").Adapting<Schema<{}, Adaptations>>) => $Returnable) => Schema<{}, import("../../Adapter/Types").WithAdaptations<Adaptations, import("../../Adapter/Core").AdaptationEntry<$Adapter, $Returnable>>>;
|
|
13
|
-
};
|
|
14
|
-
export default _default;
|
|
3
|
+
declare const registry: Schema<{}, Adaptations>;
|
|
4
|
+
export default registry;
|
|
@@ -3,13 +3,13 @@ import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adap
|
|
|
3
3
|
import type { Produce } from "../../Random/Types";
|
|
4
4
|
import type { Core, Fabricated, Meta as ThisMeta, Weights } from "./Types";
|
|
5
5
|
/**
|
|
6
|
-
* Buildable `boolean` recipe: an even coin flip, a weighted one
|
|
7
|
-
*
|
|
6
|
+
* Buildable `boolean` recipe: an even coin flip, a weighted one (`weights`), or
|
|
7
|
+
* opaque production via `as`.
|
|
8
8
|
*
|
|
9
|
-
* `$Meta` is generic (defaulting to the full `Meta` union) so builder
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
9
|
+
* `$Meta` is generic (defaulting to the full `Meta` union) so builder return
|
|
10
|
+
* types stay narrow — see `number/Schema.ts`. `$Adaptations` is threaded
|
|
11
|
+
* through every builder method for the same reason — see `string/Schema.ts`'s
|
|
12
|
+
* `adapt`.
|
|
13
13
|
*/
|
|
14
14
|
export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends Adaptations = {}> extends Core<$Meta, $Adaptations> {
|
|
15
15
|
/**
|
|
@@ -20,8 +20,8 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
|
|
|
20
20
|
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
21
21
|
weighted: (weights: Weights) => Schema<$Meta, $Adaptations>;
|
|
22
22
|
/**
|
|
23
|
-
* Override what this schema maps to in one or more external schema
|
|
24
|
-
*
|
|
23
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
24
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
25
25
|
*/
|
|
26
26
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Meta, $Adaptations>>) => $Returnable) => Schema<$Meta, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
27
27
|
}
|
|
@@ -10,9 +10,9 @@ export type Weights = {
|
|
|
10
10
|
false: number;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* An even coin flip, or a weighted one via `weights`, optionally overridden
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* An even coin flip, or a weighted one via `weights`, optionally overridden by
|
|
14
|
+
* an opaque `as` production — carried alongside `weights` rather than replacing
|
|
15
|
+
* it, so a prior weighting survives `as` for future validation.
|
|
16
16
|
*/
|
|
17
17
|
export type Meta = {
|
|
18
18
|
produce?: Produce<Fabricated>;
|
|
@@ -20,13 +20,12 @@ export type Fabricator<$Schema extends {
|
|
|
20
20
|
schema: Schema<$Schema[typeof Meta]["items"], AdaptationsOf<$Schema>>;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* `weightings` are each option's
|
|
23
|
+
* `weightings` are each option's _already-dispatched_ Fabricator, one per
|
|
24
24
|
* `[Meta].items` entry, built by `Constructor.ts`'s `make` before this call —
|
|
25
|
-
* mirrors `array.Fabricator`'s `element`, just one per option instead of
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* "Randomness").
|
|
25
|
+
* mirrors `array.Fabricator`'s `element`, just one per option instead of one
|
|
26
|
+
* shared across every element. The weighted pick happens on this field's
|
|
27
|
+
* private stream; only the chosen option's `fabricate()` is called, so an
|
|
28
|
+
* unpicked option never advances its stream (safe for the same reason skipping
|
|
29
|
+
* `object.omittable`'s inner draw is — see CLAUDE.md's "Randomness").
|
|
31
30
|
*/
|
|
32
31
|
export declare function Fabricator<$Items extends Items>(context: FabricatorContext<Schema<$Items>>, weightings: ReadonlyArray<readonly [number, NaiveFabricator<any>]>): Fabricator<Schema<$Items>>;
|
|
@@ -5,33 +5,33 @@ import type { Item, Items } from "./Types";
|
|
|
5
5
|
* per-position option types (`{ [K in keyof $Items]: ... }` walks a tuple
|
|
6
6
|
* position-by-position, unlike `ReadonlyArray<...>`'s `.map()`, which only
|
|
7
7
|
* remembers the union of every element it saw). This is what lets
|
|
8
|
-
* `Adapter/TypeBox` recover real arity later and mirror TypeBox's
|
|
9
|
-
*
|
|
8
|
+
* `Adapter/TypeBox` recover real arity later and mirror TypeBox's `Union<T>`
|
|
9
|
+
* collapse-for-a-single-option — see `Types.ts`'s `Items`.
|
|
10
10
|
*/
|
|
11
11
|
type Weighted<$Items extends ReadonlyArray<Item>> = {
|
|
12
12
|
[$K in keyof $Items]: readonly [number, $Items[$K]];
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* At least one element — a `choice` with no option has nothing to draw,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* At least one element — a `choice` with no option has nothing to draw, which
|
|
16
|
+
* would otherwise fail inside `weighted()` (`Distribution/index.ts`) with an
|
|
17
|
+
* opaque `TypeError` at fabricate time (weight sum is `0`, so `.find` returns
|
|
18
|
+
* `undefined` and `chosen![1]` throws). Rejecting emptiness here is a
|
|
19
|
+
* construction-time compile error; the runtime check below is the backstop for
|
|
20
|
+
* an `as any` call that bypasses it.
|
|
21
21
|
*/
|
|
22
22
|
type NonEmpty<$T> = readonly [$T, ...$T[]];
|
|
23
23
|
declare const _default: {
|
|
24
24
|
/**
|
|
25
25
|
* Equal probability across every option. Delegates to `weighted` with a
|
|
26
26
|
* uniform weight of `1` per item — a plain `weighted()` draw is already a
|
|
27
|
-
* uniform draw when every weight is equal, so there is no separate
|
|
28
|
-
*
|
|
27
|
+
* uniform draw when every weight is equal, so there is no separate unweighted
|
|
28
|
+
* code path to keep in sync.
|
|
29
29
|
*/
|
|
30
30
|
uniform: <const $Items extends NonEmpty<Item>>(items: $Items) => Schema<Weighted<$Items>>;
|
|
31
31
|
/**
|
|
32
|
-
* Relative probability across options, given as `[weight, schema]` pairs
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* Relative probability across options, given as `[weight, schema]` pairs —
|
|
33
|
+
* the same tuple shape `weighted()` (`Distribution/index.ts`) itself accepts,
|
|
34
|
+
* not an object keyed by option.
|
|
35
35
|
*/
|
|
36
36
|
weighted: <const $Items extends NonEmpty<Items[number]>>(items: $Items) => Schema<$Items>;
|
|
37
37
|
};
|