@ghostry/fabricator 0.0.1 → 0.0.3
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 +18 -12
- package/dist/esm/Adapter/Core.js +3 -3
- package/dist/esm/Enumeration/Enumerate.js +16 -13
- package/dist/esm/Error/index.js +16 -8
- package/dist/esm/Fabricator/Constructor.js +12 -14
- package/dist/esm/Harnessing/Core.js +30 -0
- package/dist/esm/Harnessing/Salt.js +12 -0
- package/dist/esm/Harnessing/Types.js +1 -0
- package/dist/esm/Instance/Core.js +25 -41
- 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/recursive/Fabricator.js +1 -1
- package/dist/esm/Primitive/symbol/Registry.js +2 -1
- package/dist/esm/Primitive/undefined/Registry.js +2 -1
- package/dist/esm/Random/index.js +24 -79
- package/dist/esm/Utility/Core.js +6 -1
- package/dist/esm/adapting.js +2 -0
- package/dist/esm/harnessing.js +1 -0
- package/dist/esm/index.js +5 -4
- package/dist/esm/internal.js +2 -2
- package/dist/types/Adapter/Core.d.ts +30 -33
- 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 +24 -24
- 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 +103 -89
- package/dist/types/Fabricator/Constructor.d.ts +24 -26
- package/dist/types/Fabricator/Types.d.ts +73 -81
- package/dist/types/Harnessing/Core.d.ts +43 -0
- package/dist/types/Harnessing/Salt.d.ts +31 -0
- package/dist/types/Harnessing/Types.d.ts +79 -0
- package/dist/types/Instance/Core.d.ts +38 -74
- 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 +98 -102
- 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 +20 -21
- 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/Generator/sfc32.d.ts +4 -4
- package/dist/types/Random/Types.d.ts +151 -293
- package/dist/types/Random/index.d.ts +56 -81
- 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/adapting.d.ts +32 -0
- package/dist/types/harnessing.d.ts +30 -0
- package/dist/types/index.d.ts +95 -128
- package/dist/types/internal.d.ts +53 -40
- package/package.json +39 -7
- package/dist/esm/Random/CallSite.js +0 -56
- package/dist/types/Random/CallSite.d.ts +0 -59
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Every error this library throws is a named subclass of
|
|
3
|
-
* {@link FabricatorError}, kept in one dependency-free module:
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* import.
|
|
3
|
+
* {@link FabricatorError}, kept in one dependency-free module: `instanceof
|
|
4
|
+
* FabricatorError` catches everything the library raises, and no error
|
|
5
|
+
* definition can pull a primitive's module graph into an unrelated import.
|
|
7
6
|
*
|
|
8
|
-
* Kind tags are plain `string`, not the `Kind` union from
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Kind tags are plain `string`, not the `Kind` union from `Primitive/index.ts`
|
|
8
|
+
* — that second reason, and because several of these errors exist precisely
|
|
9
|
+
* because the kind in hand was _not_ a member of it.
|
|
11
10
|
*
|
|
12
11
|
* Context is `public readonly` constructor parameters, but the message still
|
|
13
|
-
* stands on its own: a consumer reading only `.message` should not need a
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* stands on its own: a consumer reading only `.message` should not need a field
|
|
13
|
+
* to understand the failure. Fields are for programmatic access, and for detail
|
|
14
|
+
* too bulky to inline.
|
|
16
15
|
*/
|
|
17
16
|
/**
|
|
18
17
|
* Base error class from which more specific errors inherit.
|
|
@@ -28,8 +27,8 @@ export declare namespace FabricatorError {
|
|
|
28
27
|
*/
|
|
29
28
|
type Phase = "construction" | "adaptation";
|
|
30
29
|
/**
|
|
31
|
-
* `initialize({ limits: { combinatorial } })` when the configured limit
|
|
32
|
-
*
|
|
30
|
+
* `initialize({ limits: { combinatorial } })` when the configured limit could
|
|
31
|
+
* never be a meaningful instance count.
|
|
33
32
|
*/
|
|
34
33
|
class InvalidCombinatorialLimitError extends FabricatorError {
|
|
35
34
|
/**
|
|
@@ -47,28 +46,9 @@ export declare namespace FabricatorError {
|
|
|
47
46
|
limit: unknown);
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
|
-
* `
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* — the option would look configured while silently doing nothing. Thrown
|
|
54
|
-
* eagerly at `initialize()`, not deferred to wherever that would first
|
|
55
|
-
* become observable.
|
|
56
|
-
*/
|
|
57
|
-
class InvalidAttributionRootError extends FabricatorError {
|
|
58
|
-
/**
|
|
59
|
-
* The rejected root, as given.
|
|
60
|
-
*/
|
|
61
|
-
readonly root: string;
|
|
62
|
-
constructor(
|
|
63
|
-
/**
|
|
64
|
-
* The rejected root, as given.
|
|
65
|
-
*/
|
|
66
|
-
root: string);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* A `self` placeholder resolved with no `T.recursive` expanding around it
|
|
70
|
-
* — only reachable by holding a `self` reference outside the
|
|
71
|
-
* `T.recursive(...)` callback it was handed to.
|
|
49
|
+
* A `self` placeholder resolved with no `T.recursive` expanding around it —
|
|
50
|
+
* only reachable by holding a `self` reference outside the `T.recursive(...)`
|
|
51
|
+
* callback it was handed to.
|
|
72
52
|
*/
|
|
73
53
|
class DetachedSelfError extends FabricatorError {
|
|
74
54
|
/**
|
|
@@ -82,36 +62,37 @@ export declare namespace FabricatorError {
|
|
|
82
62
|
during: Phase);
|
|
83
63
|
}
|
|
84
64
|
/**
|
|
85
|
-
* `T.recursive(body).whereby({ depth })` with no `terminal`, when `body`
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
65
|
+
* `T.recursive(body).whereby({ depth })` with no `terminal`, when `body` has
|
|
66
|
+
* a `self` that is not behind a kind that can stop recursing — a required
|
|
67
|
+
* object field, a tuple slot, the body itself, or a `choice` whose every
|
|
68
|
+
* option still contains `self`. Thrown at `.whereby()`, not at fabricate
|
|
69
|
+
* time. An explicit `terminal` is the way out.
|
|
90
70
|
*/
|
|
91
71
|
class UnterminableRecursiveError extends FabricatorError {
|
|
92
72
|
/**
|
|
93
|
-
* Structural path from the recursive body to the unterminable
|
|
94
|
-
*
|
|
95
|
-
*
|
|
73
|
+
* Structural path from the recursive body to the unterminable `self` (or
|
|
74
|
+
* to the `choice` that had no remaining non-`self` option), as field
|
|
75
|
+
* names / slot indices.
|
|
96
76
|
*/
|
|
97
77
|
readonly path: ReadonlyArray<string>;
|
|
98
78
|
constructor(
|
|
99
79
|
/**
|
|
100
|
-
* Structural path from the recursive body to the unterminable
|
|
101
|
-
*
|
|
102
|
-
*
|
|
80
|
+
* Structural path from the recursive body to the unterminable `self` (or
|
|
81
|
+
* to the `choice` that had no remaining non-`self` option), as field
|
|
82
|
+
* names / slot indices.
|
|
103
83
|
*/
|
|
104
84
|
path: ReadonlyArray<string>);
|
|
105
85
|
}
|
|
106
86
|
/**
|
|
107
|
-
* A walk reached a node whose `[Kind]` it has no case for — a Schema built
|
|
108
|
-
*
|
|
109
|
-
*
|
|
87
|
+
* A walk reached a node whose `[Kind]` it has no case for — a Schema built by
|
|
88
|
+
* hand or cast past the type system, or a kind added to `Primitive/index.ts`
|
|
89
|
+
* without wiring it into every dispatch site.
|
|
110
90
|
*/
|
|
111
91
|
class UnknownKindError extends FabricatorError {
|
|
112
92
|
/**
|
|
113
|
-
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
114
|
-
* since reaching this error means the type system was already
|
|
93
|
+
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
94
|
+
* all, since reaching this error means the type system was already
|
|
95
|
+
* bypassed.
|
|
115
96
|
*/
|
|
116
97
|
readonly kind: string;
|
|
117
98
|
/**
|
|
@@ -120,8 +101,9 @@ export declare namespace FabricatorError {
|
|
|
120
101
|
readonly during: Phase;
|
|
121
102
|
constructor(
|
|
122
103
|
/**
|
|
123
|
-
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
124
|
-
* since reaching this error means the type system was already
|
|
104
|
+
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
105
|
+
* all, since reaching this error means the type system was already
|
|
106
|
+
* bypassed.
|
|
125
107
|
*/
|
|
126
108
|
kind: string,
|
|
127
109
|
/**
|
|
@@ -154,10 +136,9 @@ export declare namespace FabricatorError {
|
|
|
154
136
|
noun: string);
|
|
155
137
|
}
|
|
156
138
|
/**
|
|
157
|
-
* An object's definition names a key that would reach `Object.prototype` —
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* rejected).
|
|
139
|
+
* An object's definition names a key that would reach `Object.prototype` — a
|
|
140
|
+
* developer-written key, where throwing is actionable (contrast `record`'s
|
|
141
|
+
* _drawn_ keys, written with `Object.defineProperty` instead of rejected).
|
|
161
142
|
*/
|
|
162
143
|
class PrototypePollutionError extends FabricatorError {
|
|
163
144
|
/**
|
|
@@ -179,8 +160,8 @@ export declare namespace FabricatorError {
|
|
|
179
160
|
constructor();
|
|
180
161
|
}
|
|
181
162
|
/**
|
|
182
|
-
* A `.refine()`-computed field's resolver returned a value of the wrong
|
|
183
|
-
*
|
|
163
|
+
* A `.refine()`-computed field's resolver returned a value of the wrong shape
|
|
164
|
+
* for the source schema it was declared against.
|
|
184
165
|
*/
|
|
185
166
|
class ComputeResultMismatchError extends FabricatorError {
|
|
186
167
|
/**
|
|
@@ -202,8 +183,8 @@ export declare namespace FabricatorError {
|
|
|
202
183
|
value: unknown);
|
|
203
184
|
}
|
|
204
185
|
/**
|
|
205
|
-
* An override names a field the object schema does not define — most
|
|
206
|
-
*
|
|
186
|
+
* An override names a field the object schema does not define — most often a
|
|
187
|
+
* typo, which is why the known fields are listed.
|
|
207
188
|
*/
|
|
208
189
|
class UnknownOverrideFieldError extends FabricatorError {
|
|
209
190
|
/**
|
|
@@ -225,8 +206,8 @@ export declare namespace FabricatorError {
|
|
|
225
206
|
available: ReadonlyArray<string>);
|
|
226
207
|
}
|
|
227
208
|
/**
|
|
228
|
-
* An override value does not fit the field it is meant to replace. Raised
|
|
229
|
-
*
|
|
209
|
+
* An override value does not fit the field it is meant to replace. Raised for
|
|
210
|
+
* every field shape — a plain field, a nested object, and each presence
|
|
230
211
|
* wrapper unwrapped to its inner kind — the same failure in each case.
|
|
231
212
|
*/
|
|
232
213
|
class InvalidOverrideValueError extends FabricatorError {
|
|
@@ -236,7 +217,7 @@ export declare namespace FabricatorError {
|
|
|
236
217
|
readonly field: string;
|
|
237
218
|
/**
|
|
238
219
|
* The `[Kind]` the value was checked against — for a wrapper field, the
|
|
239
|
-
*
|
|
220
|
+
* _inner_ kind, since the wrapper's own absent/null outcomes are accepted
|
|
240
221
|
* separately.
|
|
241
222
|
*/
|
|
242
223
|
readonly kind: string;
|
|
@@ -251,7 +232,7 @@ export declare namespace FabricatorError {
|
|
|
251
232
|
field: string,
|
|
252
233
|
/**
|
|
253
234
|
* The `[Kind]` the value was checked against — for a wrapper field, the
|
|
254
|
-
*
|
|
235
|
+
* _inner_ kind, since the wrapper's own absent/null outcomes are accepted
|
|
255
236
|
* separately.
|
|
256
237
|
*/
|
|
257
238
|
kind: string,
|
|
@@ -261,9 +242,8 @@ export declare namespace FabricatorError {
|
|
|
261
242
|
value: unknown);
|
|
262
243
|
}
|
|
263
244
|
/**
|
|
264
|
-
* Thrown when `Omitted` is passed to override a field that has no
|
|
265
|
-
*
|
|
266
|
-
* off.
|
|
245
|
+
* Thrown when `Omitted` is passed to override a field that has no absent
|
|
246
|
+
* outcome. Only `T.omittable`/`T.optional` fields can be forced off.
|
|
267
247
|
*/
|
|
268
248
|
class IllegalOmittedOverrideError extends FabricatorError {
|
|
269
249
|
/**
|
|
@@ -310,8 +290,8 @@ export declare namespace FabricatorError {
|
|
|
310
290
|
width: bigint);
|
|
311
291
|
}
|
|
312
292
|
/**
|
|
313
|
-
* `resolve()` handed a pin for a kind `plan()` never produces one for —
|
|
314
|
-
*
|
|
293
|
+
* `resolve()` handed a pin for a kind `plan()` never produces one for — the
|
|
294
|
+
* two must stay in agreement; internal invariant, not caller-reachable.
|
|
315
295
|
*/
|
|
316
296
|
class UnpinnableKindError extends FabricatorError {
|
|
317
297
|
/**
|
|
@@ -352,8 +332,8 @@ export declare namespace FabricatorError {
|
|
|
352
332
|
}
|
|
353
333
|
/**
|
|
354
334
|
* A `record`'s key schema has no counterpart in the external schema library
|
|
355
|
-
* being adapted to — a symbol key, for TypeBox, whose `Type.Record`
|
|
356
|
-
*
|
|
335
|
+
* being adapted to — a symbol key, for TypeBox, whose `Type.Record` silently
|
|
336
|
+
* yields a schema nothing can satisfy rather than raising.
|
|
357
337
|
*/
|
|
358
338
|
class UnrepresentableRecordKeyError extends FabricatorError {
|
|
359
339
|
/**
|
|
@@ -367,10 +347,10 @@ export declare namespace FabricatorError {
|
|
|
367
347
|
kind: string);
|
|
368
348
|
}
|
|
369
349
|
/**
|
|
370
|
-
* A `{ min, max }` range contains no fabricable value — inverted bounds,
|
|
371
|
-
*
|
|
372
|
-
* effective integers are none. Thrown at `.whereby()` (or at construction
|
|
373
|
-
*
|
|
350
|
+
* A `{ min, max }` range contains no fabricable value — inverted bounds, a
|
|
351
|
+
* point range with an exclusive end, or a discrete exclusive pair whose
|
|
352
|
+
* effective integers are none. Thrown at `.whereby()` (or at construction for
|
|
353
|
+
* `T.date.past`/`future`, whose other end is the instance clock).
|
|
374
354
|
*/
|
|
375
355
|
class EmptyRangeError extends FabricatorError {
|
|
376
356
|
/**
|
|
@@ -413,8 +393,8 @@ export declare namespace FabricatorError {
|
|
|
413
393
|
}
|
|
414
394
|
/**
|
|
415
395
|
* A distribution's bounds fall outside its own domain — a `logarithmic`
|
|
416
|
-
* distribution's density is proportional to `1/x`, so it is undefined at
|
|
417
|
-
*
|
|
396
|
+
* distribution's density is proportional to `1/x`, so it is undefined at or
|
|
397
|
+
* below zero.
|
|
418
398
|
*/
|
|
419
399
|
class InvalidDistributionBoundError extends FabricatorError {
|
|
420
400
|
/**
|
|
@@ -444,8 +424,8 @@ export declare namespace FabricatorError {
|
|
|
444
424
|
max: number);
|
|
445
425
|
}
|
|
446
426
|
/**
|
|
447
|
-
* Which entry of a `.weighted(...)` call carried the bad weight: a position
|
|
448
|
-
* a caller-supplied list, or one of a fixed, named outcome set.
|
|
427
|
+
* Which entry of a `.weighted(...)` call carried the bad weight: a position
|
|
428
|
+
* in a caller-supplied list, or one of a fixed, named outcome set.
|
|
449
429
|
*/
|
|
450
430
|
type WeightEntry = {
|
|
451
431
|
readonly kind: "index";
|
|
@@ -456,10 +436,10 @@ export declare namespace FabricatorError {
|
|
|
456
436
|
readonly name: string;
|
|
457
437
|
};
|
|
458
438
|
/**
|
|
459
|
-
* A `.weighted(...)` call gives an outcome a weight that is not
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
439
|
+
* A `.weighted(...)` call gives an outcome a weight that is not expressible:
|
|
440
|
+
* negative, `NaN`, or `Infinity`. Zero is valid — it disables the outcome —
|
|
441
|
+
* so this is not "anything `weighted()` would drop." An empty drawable set is
|
|
442
|
+
* {@link NoDrawableOutcomesError}.
|
|
463
443
|
*/
|
|
464
444
|
class InvalidWeightError extends FabricatorError {
|
|
465
445
|
/**
|
|
@@ -489,9 +469,9 @@ export declare namespace FabricatorError {
|
|
|
489
469
|
entry: WeightEntry);
|
|
490
470
|
}
|
|
491
471
|
/**
|
|
492
|
-
* A weighted draw table has nothing left to pick: every weight is
|
|
493
|
-
*
|
|
494
|
-
*
|
|
472
|
+
* A weighted draw table has nothing left to pick: every weight is zero (or
|
|
473
|
+
* the list was empty of drawable entries). Zeroing an outcome disables it, so
|
|
474
|
+
* at least one must keep a positive weight.
|
|
495
475
|
*/
|
|
496
476
|
class NoDrawableOutcomesError extends FabricatorError {
|
|
497
477
|
/**
|
|
@@ -515,9 +495,9 @@ export declare namespace FabricatorError {
|
|
|
515
495
|
noun: string);
|
|
516
496
|
}
|
|
517
497
|
/**
|
|
518
|
-
* `new Fabricator(schema, trace)` when `trace.kind` names a different
|
|
519
|
-
*
|
|
520
|
-
*
|
|
498
|
+
* `new Fabricator(schema, trace)` when `trace.kind` names a different kind
|
|
499
|
+
* than `schema`. A trace reproduces the node it was taken from, so its kind
|
|
500
|
+
* must match the schema it is replayed against.
|
|
521
501
|
*/
|
|
522
502
|
class TraceKindMismatchError extends FabricatorError {
|
|
523
503
|
/**
|
|
@@ -538,4 +518,38 @@ export declare namespace FabricatorError {
|
|
|
538
518
|
*/
|
|
539
519
|
given: string);
|
|
540
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* `wrap(overlay, block)` handed an `async` block while the lineage's ambient
|
|
523
|
+
* carrier is the synchronous one (`Instance/Stack/Sync.ts`).
|
|
524
|
+
*
|
|
525
|
+
* Its frame cannot outlive the block's first `await`, so a build reached
|
|
526
|
+
* after one would resolve against the base instance rather than the wrap —
|
|
527
|
+
* plausible data, quietly drawn from the wrong configuration. Raised instead
|
|
528
|
+
* of allowing that, which is why it fires even when `block` only ever uses
|
|
529
|
+
* `scope`: whether a later build reads the ambient frame is not knowable from
|
|
530
|
+
* here.
|
|
531
|
+
*
|
|
532
|
+
* Reachable only where `#stack` resolved to `default` — a runtime with no
|
|
533
|
+
* `node:async_hooks`, in practice a browser bundle — or where `initialize({
|
|
534
|
+
* stack })` supplied a synchronous carrier explicitly. Node, Bun, and Deno
|
|
535
|
+
* all resolve to the `AsyncLocalStorage` carrier and never raise this.
|
|
536
|
+
*/
|
|
537
|
+
class SynchronousStackError extends FabricatorError {
|
|
538
|
+
constructor();
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* The `fabricator` provider of `integration(instance)`
|
|
542
|
+
* (`@ghostry/fabricator/harnessing`) was called outside that integration's
|
|
543
|
+
* own `around`.
|
|
544
|
+
*
|
|
545
|
+
* The provider hands back the per-test scope `around` just entered, so there
|
|
546
|
+
* is no scope for it to return anywhere else. `@ghostry/harness` never does
|
|
547
|
+
* this — it runs each provider inside its integration's `around` — so this
|
|
548
|
+
* means a composer that breaks the contract. Raised rather than returning the
|
|
549
|
+
* base instance, which would draw plausible data from the wrong configuration
|
|
550
|
+
* with no signal.
|
|
551
|
+
*/
|
|
552
|
+
class HarnessingProviderError extends FabricatorError {
|
|
553
|
+
constructor();
|
|
554
|
+
}
|
|
541
555
|
}
|
|
@@ -3,41 +3,39 @@ import type { ConstructorOptions, RandomSource } from "../Random/Types";
|
|
|
3
3
|
import { type Buildable } from "../Types";
|
|
4
4
|
import { type AsFabricator } from "./Types";
|
|
5
5
|
/**
|
|
6
|
-
* The type of `construct()` itself, as handed back by `Constructor` —
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The type of `construct()` itself, as handed back by `Constructor` — kept
|
|
7
|
+
* separate so `initialize`'s return type (`src/index.ts`) can name it without
|
|
8
|
+
* re-deriving it from `Constructor`'s implementation.
|
|
9
9
|
*
|
|
10
|
-
* Both a call signature and a construct signature: `construct` is a
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* constructed in (see `construct()` for what `options.seed` does).
|
|
10
|
+
* Both a call signature and a construct signature: `construct` is a plain
|
|
11
|
+
* `function` that explicitly returns an object, so `new construct(schema)`
|
|
12
|
+
* behaves identically to `construct(schema)` — a `new` call's returned object
|
|
13
|
+
* always replaces the freshly-created `this`. The construct signature lets
|
|
14
|
+
* callers spell `new T.Fabricator(schema)` — or `new Fabricator(schema, { salt
|
|
15
|
+
* })` to pin this one build's salt slot, leaving every other slot to resolve as
|
|
16
|
+
* usual (see `construct()` for what `options.salt` does).
|
|
18
17
|
*/
|
|
19
18
|
export type Constructor = {
|
|
20
19
|
new <const $Schema extends Buildable>(schema: $Schema, options?: ConstructorOptions): AsFabricator<$Schema>;
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
23
|
-
* Build the untyped recursive core — mirrors `Adapter/TypeBox/index.ts`'s
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* Build the untyped recursive core — mirrors `Adapter/TypeBox/index.ts`'s own
|
|
23
|
+
* internal `convert(schema: any)` — and the precisely-typed `construct()`
|
|
24
|
+
* boundary around it, both closed over a single instance's `source` so every
|
|
25
|
+
* fabricator this `construct()` produces draws from that instance's own
|
|
26
|
+
* salt/streams and never another instance's.
|
|
28
27
|
*
|
|
29
28
|
* `stack` is the instance's own lineage-wide ambient stack
|
|
30
29
|
* (`Instance/Core.ts`'s `toStack()`) — passed straight through to
|
|
31
|
-
* `resolveScope` on every `construct()` call, never read here directly,
|
|
32
|
-
*
|
|
33
|
-
*
|
|
30
|
+
* `resolveScope` on every `construct()` call, never read here directly, so a
|
|
31
|
+
* build reached inside an active `wrap` resolves against that frame
|
|
32
|
+
* automatically, with nothing threaded through by the caller.
|
|
34
33
|
*
|
|
35
|
-
* No separate `clock` parameter: `source` already carries its own
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* rather than threading a second value alongside `source`.
|
|
34
|
+
* No separate `clock` parameter: `source` already carries its own resolved
|
|
35
|
+
* clock intrinsically (`Random/Types.ts`'s `Options.clock`, baked in when the
|
|
36
|
+
* source was built), and `resolveScope`'s chosen source — the active `wrap`
|
|
37
|
+
* frame's, or this one — is exactly the source whose clock a construction
|
|
38
|
+
* should resolve "now" against. `toConstructionContext` reads it straight off
|
|
39
|
+
* the resolved root rather than threading a second value alongside `source`.
|
|
42
40
|
*/
|
|
43
41
|
export declare function Constructor(source: RandomSource, stack: Stack): Constructor;
|
|
@@ -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
|
/**
|