@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,38 +3,35 @@ import type { AnySchema, ValueOf } from "../Schema/Types";
|
|
|
3
3
|
import type { Children, Kind, Meta } from "../Types";
|
|
4
4
|
import type { PlainObject } from "../Utility/Types";
|
|
5
5
|
/**
|
|
6
|
-
* How a composite with more than one child combines their widths.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* strategy.
|
|
6
|
+
* How a composite with more than one child combines their widths. `"product"`
|
|
7
|
+
* is the cartesian product — width is the product of every child's width;
|
|
8
|
+
* `at(index)` mixed-radix decodes to a full combination (`combinatorial`).
|
|
9
|
+
* `"cycle"` (`coverage`) takes the widest child as the composite's width,
|
|
10
|
+
* cycling narrower children to fill it — see CLAUDE.md's "sum vs product" note
|
|
11
|
+
* for why cycling only ever applies to `object`/`tuple` and never to a sum node
|
|
12
|
+
* (`choice`, the presence wrappers), which always total their children's widths
|
|
13
|
+
* regardless of strategy.
|
|
15
14
|
*/
|
|
16
15
|
export type Strategy = "product" | "cycle";
|
|
17
16
|
/**
|
|
18
|
-
* A fresh, reproducible permutation of `0..width-1` each call — one
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
* imports randomness.
|
|
17
|
+
* A fresh, reproducible permutation of `0..width-1` each call — one per
|
|
18
|
+
* width-`>1` node `plan()` visits, in walk order, so two nodes of the same
|
|
19
|
+
* width never receive the same permutation (which would otherwise iterate them
|
|
20
|
+
* in lockstep — see CLAUDE.md's note on why a constant phase offset isn't
|
|
21
|
+
* enough). Only consulted under `"cycle"`; `"product"`'s mixed-radix decode
|
|
22
|
+
* already visits every combination, so permuting there would only reorder
|
|
23
|
+
* identical output. Built in `Enumerate.ts` (which can reach `Random/`), then
|
|
24
|
+
* threaded through `plan()` as data — `Plan.ts` stays a total function and
|
|
25
|
+
* never imports randomness.
|
|
28
26
|
*/
|
|
29
27
|
export type Orderer = (width: bigint) => ReadonlyArray<bigint>;
|
|
30
28
|
/**
|
|
31
|
-
* Recipe for one enumerated combination against a built Fabricator
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* recursing into whichever child was picked.
|
|
29
|
+
* Recipe for one enumerated combination against a built Fabricator tree:
|
|
30
|
+
* `undefined` for a drawn (not chosen) node — fabricate normally; `{ value }`
|
|
31
|
+
* for a literal (enum member, boolean, `null`, `undefined`, `Omitted`); `{
|
|
32
|
+
* slots }`/`{ fields }` for a tuple/object, recursing per position/key; `{
|
|
33
|
+
* branch, inner }` for a choice's chosen option, or a presence wrapper's
|
|
34
|
+
* "present" arm, recursing into whichever child was picked.
|
|
38
35
|
*/
|
|
39
36
|
export type Pin = undefined | {
|
|
40
37
|
value: unknown;
|
|
@@ -47,35 +44,33 @@ export type Pin = undefined | {
|
|
|
47
44
|
inner: Pin;
|
|
48
45
|
};
|
|
49
46
|
/**
|
|
50
|
-
* One enumerable dimension: how many distinct outcomes, and the `Pin`
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
47
|
+
* One enumerable dimension: how many distinct outcomes, and the `Pin` for the
|
|
48
|
+
* `index`-th (`0 <= index < width`). Widths are `bigint` so a schema with many
|
|
49
|
+
* combined axes can be counted exactly — a `number` would silently lose
|
|
50
|
+
* precision past `Number.MAX_SAFE_INTEGER` and eventually overflow to
|
|
51
|
+
* `Infinity`, which would make a combinatorial limit's error message state a
|
|
52
|
+
* false count.
|
|
56
53
|
*/
|
|
57
54
|
export type Axis = {
|
|
58
55
|
readonly width: bigint;
|
|
59
56
|
readonly at: (index: bigint) => Pin;
|
|
60
57
|
};
|
|
61
58
|
/**
|
|
62
|
-
* Resolved, already-validated enumeration limits — `initialize()` is
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* axis, linear in the schema as written rather than a product, so
|
|
59
|
+
* Resolved, already-validated enumeration limits — `initialize()` is where
|
|
60
|
+
* `limits.combinatorial` is defaulted and checked (`Number.isSafeInteger(limit)
|
|
61
|
+
* && limit >= 1`), so `Enumerate()` always receives a value it can trust
|
|
62
|
+
* without re-validating. `coverage` carries no limit here: its count is the
|
|
63
|
+
* widest single axis, linear in the schema as written rather than a product, so
|
|
68
64
|
* there is nothing for a limit to protect against.
|
|
69
65
|
*/
|
|
70
66
|
export type Limits = {
|
|
71
67
|
combinatorial: number;
|
|
72
68
|
};
|
|
73
69
|
/**
|
|
74
|
-
* The shape both `combinatorial` and `coverage` share — strategy and
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* `unknown`.
|
|
70
|
+
* The shape both `combinatorial` and `coverage` share — strategy and limit
|
|
71
|
+
* differ internally, neither visible here. Takes a Schema, not a built
|
|
72
|
+
* Fabricator: `AnySchema` excludes `Fabricator<any>` (which carries no
|
|
73
|
+
* `[Produces]`), so `ValueOf` can't silently degrade to `unknown`.
|
|
79
74
|
*/
|
|
80
75
|
export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Iterable<ValueOf<$Schema>>;
|
|
81
76
|
export type Resolvable = {
|
|
@@ -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,12 +46,12 @@ export declare namespace FabricatorError {
|
|
|
47
46
|
limit: unknown);
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
|
-
* `initialize({ attribution: { kind: "rooted", root } })` when `root` is
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* eagerly at `initialize()`, not deferred to wherever that would first
|
|
55
|
-
*
|
|
49
|
+
* `initialize({ attribution: { kind: "rooted", root } })` when `root` is not
|
|
50
|
+
* an absolute path or a `file://` URL. A relative root can never prefix a
|
|
51
|
+
* resolved caller file, so `relativize` would leave every file unchanged —
|
|
52
|
+
* the option would look configured while silently doing nothing. Thrown
|
|
53
|
+
* eagerly at `initialize()`, not deferred to wherever that would first become
|
|
54
|
+
* observable.
|
|
56
55
|
*/
|
|
57
56
|
class InvalidAttributionRootError extends FabricatorError {
|
|
58
57
|
/**
|
|
@@ -66,9 +65,9 @@ export declare namespace FabricatorError {
|
|
|
66
65
|
root: string);
|
|
67
66
|
}
|
|
68
67
|
/**
|
|
69
|
-
* A `self` placeholder resolved with no `T.recursive` expanding around it
|
|
70
|
-
*
|
|
71
|
-
*
|
|
68
|
+
* A `self` placeholder resolved with no `T.recursive` expanding around it —
|
|
69
|
+
* only reachable by holding a `self` reference outside the `T.recursive(...)`
|
|
70
|
+
* callback it was handed to.
|
|
72
71
|
*/
|
|
73
72
|
class DetachedSelfError extends FabricatorError {
|
|
74
73
|
/**
|
|
@@ -82,36 +81,37 @@ export declare namespace FabricatorError {
|
|
|
82
81
|
during: Phase);
|
|
83
82
|
}
|
|
84
83
|
/**
|
|
85
|
-
* `T.recursive(body).whereby({ depth })` with no `terminal`, when `body`
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
84
|
+
* `T.recursive(body).whereby({ depth })` with no `terminal`, when `body` has
|
|
85
|
+
* a `self` that is not behind a kind that can stop recursing — a required
|
|
86
|
+
* object field, a tuple slot, the body itself, or a `choice` whose every
|
|
87
|
+
* option still contains `self`. Thrown at `.whereby()`, not at fabricate
|
|
88
|
+
* time. An explicit `terminal` is the way out.
|
|
90
89
|
*/
|
|
91
90
|
class UnterminableRecursiveError extends FabricatorError {
|
|
92
91
|
/**
|
|
93
|
-
* Structural path from the recursive body to the unterminable
|
|
94
|
-
*
|
|
95
|
-
*
|
|
92
|
+
* Structural path from the recursive body to the unterminable `self` (or
|
|
93
|
+
* to the `choice` that had no remaining non-`self` option), as field
|
|
94
|
+
* names / slot indices.
|
|
96
95
|
*/
|
|
97
96
|
readonly path: ReadonlyArray<string>;
|
|
98
97
|
constructor(
|
|
99
98
|
/**
|
|
100
|
-
* Structural path from the recursive body to the unterminable
|
|
101
|
-
*
|
|
102
|
-
*
|
|
99
|
+
* Structural path from the recursive body to the unterminable `self` (or
|
|
100
|
+
* to the `choice` that had no remaining non-`self` option), as field
|
|
101
|
+
* names / slot indices.
|
|
103
102
|
*/
|
|
104
103
|
path: ReadonlyArray<string>);
|
|
105
104
|
}
|
|
106
105
|
/**
|
|
107
|
-
* A walk reached a node whose `[Kind]` it has no case for — a Schema built
|
|
108
|
-
*
|
|
109
|
-
*
|
|
106
|
+
* A walk reached a node whose `[Kind]` it has no case for — a Schema built by
|
|
107
|
+
* hand or cast past the type system, or a kind added to `Primitive/index.ts`
|
|
108
|
+
* without wiring it into every dispatch site.
|
|
110
109
|
*/
|
|
111
110
|
class UnknownKindError extends FabricatorError {
|
|
112
111
|
/**
|
|
113
|
-
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
114
|
-
* since reaching this error means the type system was already
|
|
112
|
+
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
113
|
+
* all, since reaching this error means the type system was already
|
|
114
|
+
* bypassed.
|
|
115
115
|
*/
|
|
116
116
|
readonly kind: string;
|
|
117
117
|
/**
|
|
@@ -120,8 +120,9 @@ export declare namespace FabricatorError {
|
|
|
120
120
|
readonly during: Phase;
|
|
121
121
|
constructor(
|
|
122
122
|
/**
|
|
123
|
-
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
124
|
-
* since reaching this error means the type system was already
|
|
123
|
+
* The unrecognized `[Kind]` tag, stringified — it may be any value at
|
|
124
|
+
* all, since reaching this error means the type system was already
|
|
125
|
+
* bypassed.
|
|
125
126
|
*/
|
|
126
127
|
kind: string,
|
|
127
128
|
/**
|
|
@@ -154,10 +155,9 @@ export declare namespace FabricatorError {
|
|
|
154
155
|
noun: string);
|
|
155
156
|
}
|
|
156
157
|
/**
|
|
157
|
-
* An object's definition names a key that would reach `Object.prototype` —
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* rejected).
|
|
158
|
+
* An object's definition names a key that would reach `Object.prototype` — a
|
|
159
|
+
* developer-written key, where throwing is actionable (contrast `record`'s
|
|
160
|
+
* _drawn_ keys, written with `Object.defineProperty` instead of rejected).
|
|
161
161
|
*/
|
|
162
162
|
class PrototypePollutionError extends FabricatorError {
|
|
163
163
|
/**
|
|
@@ -179,8 +179,8 @@ export declare namespace FabricatorError {
|
|
|
179
179
|
constructor();
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
|
-
* A `.refine()`-computed field's resolver returned a value of the wrong
|
|
183
|
-
*
|
|
182
|
+
* A `.refine()`-computed field's resolver returned a value of the wrong shape
|
|
183
|
+
* for the source schema it was declared against.
|
|
184
184
|
*/
|
|
185
185
|
class ComputeResultMismatchError extends FabricatorError {
|
|
186
186
|
/**
|
|
@@ -202,8 +202,8 @@ export declare namespace FabricatorError {
|
|
|
202
202
|
value: unknown);
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
|
-
* An override names a field the object schema does not define — most
|
|
206
|
-
*
|
|
205
|
+
* An override names a field the object schema does not define — most often a
|
|
206
|
+
* typo, which is why the known fields are listed.
|
|
207
207
|
*/
|
|
208
208
|
class UnknownOverrideFieldError extends FabricatorError {
|
|
209
209
|
/**
|
|
@@ -225,8 +225,8 @@ export declare namespace FabricatorError {
|
|
|
225
225
|
available: ReadonlyArray<string>);
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
|
-
* An override value does not fit the field it is meant to replace. Raised
|
|
229
|
-
*
|
|
228
|
+
* An override value does not fit the field it is meant to replace. Raised for
|
|
229
|
+
* every field shape — a plain field, a nested object, and each presence
|
|
230
230
|
* wrapper unwrapped to its inner kind — the same failure in each case.
|
|
231
231
|
*/
|
|
232
232
|
class InvalidOverrideValueError extends FabricatorError {
|
|
@@ -236,7 +236,7 @@ export declare namespace FabricatorError {
|
|
|
236
236
|
readonly field: string;
|
|
237
237
|
/**
|
|
238
238
|
* The `[Kind]` the value was checked against — for a wrapper field, the
|
|
239
|
-
*
|
|
239
|
+
* _inner_ kind, since the wrapper's own absent/null outcomes are accepted
|
|
240
240
|
* separately.
|
|
241
241
|
*/
|
|
242
242
|
readonly kind: string;
|
|
@@ -251,7 +251,7 @@ export declare namespace FabricatorError {
|
|
|
251
251
|
field: string,
|
|
252
252
|
/**
|
|
253
253
|
* The `[Kind]` the value was checked against — for a wrapper field, the
|
|
254
|
-
*
|
|
254
|
+
* _inner_ kind, since the wrapper's own absent/null outcomes are accepted
|
|
255
255
|
* separately.
|
|
256
256
|
*/
|
|
257
257
|
kind: string,
|
|
@@ -261,9 +261,8 @@ export declare namespace FabricatorError {
|
|
|
261
261
|
value: unknown);
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
|
-
* Thrown when `Omitted` is passed to override a field that has no
|
|
265
|
-
*
|
|
266
|
-
* off.
|
|
264
|
+
* Thrown when `Omitted` is passed to override a field that has no absent
|
|
265
|
+
* outcome. Only `T.omittable`/`T.optional` fields can be forced off.
|
|
267
266
|
*/
|
|
268
267
|
class IllegalOmittedOverrideError extends FabricatorError {
|
|
269
268
|
/**
|
|
@@ -310,8 +309,8 @@ export declare namespace FabricatorError {
|
|
|
310
309
|
width: bigint);
|
|
311
310
|
}
|
|
312
311
|
/**
|
|
313
|
-
* `resolve()` handed a pin for a kind `plan()` never produces one for —
|
|
314
|
-
*
|
|
312
|
+
* `resolve()` handed a pin for a kind `plan()` never produces one for — the
|
|
313
|
+
* two must stay in agreement; internal invariant, not caller-reachable.
|
|
315
314
|
*/
|
|
316
315
|
class UnpinnableKindError extends FabricatorError {
|
|
317
316
|
/**
|
|
@@ -352,8 +351,8 @@ export declare namespace FabricatorError {
|
|
|
352
351
|
}
|
|
353
352
|
/**
|
|
354
353
|
* 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
|
-
*
|
|
354
|
+
* being adapted to — a symbol key, for TypeBox, whose `Type.Record` silently
|
|
355
|
+
* yields a schema nothing can satisfy rather than raising.
|
|
357
356
|
*/
|
|
358
357
|
class UnrepresentableRecordKeyError extends FabricatorError {
|
|
359
358
|
/**
|
|
@@ -367,10 +366,10 @@ export declare namespace FabricatorError {
|
|
|
367
366
|
kind: string);
|
|
368
367
|
}
|
|
369
368
|
/**
|
|
370
|
-
* A `{ min, max }` range contains no fabricable value — inverted bounds,
|
|
371
|
-
*
|
|
372
|
-
* effective integers are none. Thrown at `.whereby()` (or at construction
|
|
373
|
-
*
|
|
369
|
+
* A `{ min, max }` range contains no fabricable value — inverted bounds, a
|
|
370
|
+
* point range with an exclusive end, or a discrete exclusive pair whose
|
|
371
|
+
* effective integers are none. Thrown at `.whereby()` (or at construction for
|
|
372
|
+
* `T.date.past`/`future`, whose other end is the instance clock).
|
|
374
373
|
*/
|
|
375
374
|
class EmptyRangeError extends FabricatorError {
|
|
376
375
|
/**
|
|
@@ -413,8 +412,8 @@ export declare namespace FabricatorError {
|
|
|
413
412
|
}
|
|
414
413
|
/**
|
|
415
414
|
* 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
|
-
*
|
|
415
|
+
* distribution's density is proportional to `1/x`, so it is undefined at or
|
|
416
|
+
* below zero.
|
|
418
417
|
*/
|
|
419
418
|
class InvalidDistributionBoundError extends FabricatorError {
|
|
420
419
|
/**
|
|
@@ -444,8 +443,8 @@ export declare namespace FabricatorError {
|
|
|
444
443
|
max: number);
|
|
445
444
|
}
|
|
446
445
|
/**
|
|
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.
|
|
446
|
+
* Which entry of a `.weighted(...)` call carried the bad weight: a position
|
|
447
|
+
* in a caller-supplied list, or one of a fixed, named outcome set.
|
|
449
448
|
*/
|
|
450
449
|
type WeightEntry = {
|
|
451
450
|
readonly kind: "index";
|
|
@@ -456,10 +455,10 @@ export declare namespace FabricatorError {
|
|
|
456
455
|
readonly name: string;
|
|
457
456
|
};
|
|
458
457
|
/**
|
|
459
|
-
* A `.weighted(...)` call gives an outcome a weight that is not
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
458
|
+
* A `.weighted(...)` call gives an outcome a weight that is not expressible:
|
|
459
|
+
* negative, `NaN`, or `Infinity`. Zero is valid — it disables the outcome —
|
|
460
|
+
* so this is not "anything `weighted()` would drop." An empty drawable set is
|
|
461
|
+
* {@link NoDrawableOutcomesError}.
|
|
463
462
|
*/
|
|
464
463
|
class InvalidWeightError extends FabricatorError {
|
|
465
464
|
/**
|
|
@@ -489,9 +488,9 @@ export declare namespace FabricatorError {
|
|
|
489
488
|
entry: WeightEntry);
|
|
490
489
|
}
|
|
491
490
|
/**
|
|
492
|
-
* A weighted draw table has nothing left to pick: every weight is
|
|
493
|
-
*
|
|
494
|
-
*
|
|
491
|
+
* A weighted draw table has nothing left to pick: every weight is zero (or
|
|
492
|
+
* the list was empty of drawable entries). Zeroing an outcome disables it, so
|
|
493
|
+
* at least one must keep a positive weight.
|
|
495
494
|
*/
|
|
496
495
|
class NoDrawableOutcomesError extends FabricatorError {
|
|
497
496
|
/**
|
|
@@ -515,9 +514,9 @@ export declare namespace FabricatorError {
|
|
|
515
514
|
noun: string);
|
|
516
515
|
}
|
|
517
516
|
/**
|
|
518
|
-
* `new Fabricator(schema, trace)` when `trace.kind` names a different
|
|
519
|
-
*
|
|
520
|
-
*
|
|
517
|
+
* `new Fabricator(schema, trace)` when `trace.kind` names a different kind
|
|
518
|
+
* than `schema`. A trace reproduces the node it was taken from, so its kind
|
|
519
|
+
* must match the schema it is replayed against.
|
|
521
520
|
*/
|
|
522
521
|
class TraceKindMismatchError extends FabricatorError {
|
|
523
522
|
/**
|
|
@@ -538,4 +537,23 @@ export declare namespace FabricatorError {
|
|
|
538
537
|
*/
|
|
539
538
|
given: string);
|
|
540
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* `wrap(overlay, block)` handed an `async` block while the lineage's ambient
|
|
542
|
+
* carrier is the synchronous one (`Instance/Stack/Sync.ts`).
|
|
543
|
+
*
|
|
544
|
+
* Its frame cannot outlive the block's first `await`, so a build reached
|
|
545
|
+
* after one would resolve against the base instance rather than the wrap —
|
|
546
|
+
* plausible data, quietly drawn from the wrong configuration. Raised instead
|
|
547
|
+
* of allowing that, which is why it fires even when `block` only ever uses
|
|
548
|
+
* `scope`: whether a later build reads the ambient frame is not knowable from
|
|
549
|
+
* here.
|
|
550
|
+
*
|
|
551
|
+
* Reachable only where `#stack` resolved to `default` — a runtime with no
|
|
552
|
+
* `node:async_hooks`, in practice a browser bundle — or where `initialize({
|
|
553
|
+
* stack })` supplied a synchronous carrier explicitly. Node, Bun, and Deno
|
|
554
|
+
* all resolve to the `AsyncLocalStorage` carrier and never raise this.
|
|
555
|
+
*/
|
|
556
|
+
class SynchronousStackError extends FabricatorError {
|
|
557
|
+
constructor();
|
|
558
|
+
}
|
|
541
559
|
}
|
|
@@ -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
|
-
* pin this one build to an explicit seed, independent of the file it's
|
|
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, { seed
|
|
15
|
+
* })` to pin this one build to an explicit seed, independent of the file it's
|
|
17
16
|
* constructed in (see `construct()` for what `options.seed` 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
|
+
* seed/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;
|