@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
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
import type { Adaptation, Meta } from "../Types";
|
|
2
2
|
/**
|
|
3
|
-
* One adapter's override for one schema,
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* One adapter's override for one schema, _as stored_ in `[Adaptation]` — the
|
|
4
|
+
* loosest signature the mechanism needs. An adapter states its real return type
|
|
5
|
+
* on {@link Adapter.convert}, and `.adapt(...)` checks a supplied adaptation
|
|
6
|
+
* against that; nothing here reads either end.
|
|
7
7
|
*
|
|
8
|
-
* Not the shape a caller writes: a kind's `.adapt(...)` takes a producer
|
|
9
|
-
*
|
|
10
|
-
* `mergeAdaptations` wrap into this one entry point-side. The stored
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* account of what a schema carries.
|
|
8
|
+
* Not the shape a caller writes: a kind's `.adapt(...)` takes a producer of
|
|
9
|
+
* {@link Adapting}, which `Adapter/Core.ts`'s `withAdaptations`/
|
|
10
|
+
* `mergeAdaptations` wrap into this one entry point-side. The stored form stays
|
|
11
|
+
* schema-taking so `patched`/`layer` treat an incoming producer and a prior
|
|
12
|
+
* layered entry as one type, and so `AdaptationEntry`'s `(schema: any) =>
|
|
13
|
+
* $Returnable` is an accurate account of what a schema carries.
|
|
15
14
|
*/
|
|
16
15
|
export type SchemaAdaptation = (schema: any) => unknown;
|
|
17
16
|
/**
|
|
18
|
-
* What a kind's `.adapt(adapter, produce)` hands its producer: the schema
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* What a kind's `.adapt(adapter, produce)` hands its producer: the schema being
|
|
18
|
+
* adapted, and that schema's `[Meta]` — one object rather than two parameters,
|
|
19
|
+
* so destructuring picks whichever half is needed and neither is reachable only
|
|
20
|
+
* through a well-known symbol.
|
|
22
21
|
*
|
|
23
|
-
* `schema` carries whichever adaptation for this same adapter it
|
|
24
|
-
*
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* describe one object.
|
|
22
|
+
* `schema` carries whichever adaptation for this same adapter it replaced,
|
|
23
|
+
* absent at the bottom of the stack (see `Adapter/Core.ts`'s `layer`) — so
|
|
24
|
+
* `toTypeBox(schema)` inside a producer resolves to the previous layer, or to
|
|
25
|
+
* the kind's ordinary mapping when there is none. `meta` is read off that same
|
|
26
|
+
* substituted schema, so the two keys describe one object.
|
|
29
27
|
*
|
|
30
|
-
* `meta`'s shape is the kind's own config blob, derived by indexed
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
28
|
+
* `meta`'s shape is the kind's own config blob, derived by indexed access
|
|
29
|
+
* rather than named separately so no kind states its own `Meta` twice in an
|
|
30
|
+
* `adapt` signature. **Readable but not stabilized**: an adaptation may read
|
|
31
|
+
* it; a kind stays free to restructure it — nothing outside a kind's own files
|
|
32
|
+
* should _interpret_ another kind's `[Meta]`.
|
|
35
33
|
*
|
|
36
34
|
* A kind with no bare-form default carries no `[Meta]` at runtime until
|
|
37
35
|
* configured (`string`/`bigint`'s registry exports — see "Anatomy of a
|
|
38
|
-
* primitive"), so `meta` can be `undefined` there despite this type.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
36
|
+
* primitive"), so `meta` can be `undefined` there despite this type. Same
|
|
37
|
+
* imprecision `Schema<$Meta>` already states, and why the TypeBox adapter reads
|
|
38
|
+
* `[Meta]` defensively for those kinds.
|
|
41
39
|
*/
|
|
42
40
|
export type Adapting<$Schema extends {
|
|
43
41
|
[Meta]: unknown;
|
|
@@ -46,70 +44,64 @@ export type Adapting<$Schema extends {
|
|
|
46
44
|
readonly meta: $Schema[typeof Meta];
|
|
47
45
|
};
|
|
48
46
|
/**
|
|
49
|
-
* What a Schema's `[Adaptation]` holds: each adapter's override, under
|
|
50
|
-
*
|
|
47
|
+
* What a Schema's `[Adaptation]` holds: each adapter's override, under that
|
|
48
|
+
* adapter's own key.
|
|
51
49
|
*
|
|
52
|
-
* Open rather than a closed registry of known libraries: an adapter is
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* nothing.
|
|
50
|
+
* Open rather than a closed registry of known libraries: an adapter is a value
|
|
51
|
+
* (see {@link Adapter}), not a name this package knows. Nothing has to be
|
|
52
|
+
* declared for a third party's adapter to work, and two adapters for different
|
|
53
|
+
* versions of the same library collide with nothing.
|
|
57
54
|
*/
|
|
58
55
|
export type Adaptations = {
|
|
59
56
|
readonly [key: string]: SchemaAdaptation;
|
|
60
57
|
};
|
|
61
58
|
/**
|
|
62
59
|
* An {@link Adaptations} update as `withAdaptations` accepts it. Identical
|
|
63
|
-
* except that an explicitly-`undefined` entry
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* at the bottom of the stack.
|
|
60
|
+
* except that an explicitly-`undefined` entry _removes_ that adapter's override
|
|
61
|
+
* — how the layering hands an adaptation the schema it is adapting with its own
|
|
62
|
+
* entry replaced by the previous one, or absent at the bottom of the stack.
|
|
67
63
|
*
|
|
68
|
-
* Not what a kind's `.adapt(...)` accepts: removal is an internal need
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* {@link Adaptations}.
|
|
64
|
+
* Not what a kind's `.adapt(...)` accepts: removal is an internal need of the
|
|
65
|
+
* layering, and letting a caller express it would produce a `[Adaptation]` type
|
|
66
|
+
* that `exactOptionalPropertyTypes` rejects against {@link Adaptations}.
|
|
72
67
|
*/
|
|
73
68
|
export type Patch = {
|
|
74
69
|
readonly [key: string]: SchemaAdaptation | undefined;
|
|
75
70
|
};
|
|
76
71
|
/**
|
|
77
72
|
* How an adapter recurses into a nested schema — handed to
|
|
78
|
-
* {@link Adapter.convert} by `Adapter/Core.ts`'s `drive` rather than
|
|
79
|
-
*
|
|
80
|
-
*
|
|
73
|
+
* {@link Adapter.convert} by `Adapter/Core.ts`'s `drive` rather than being the
|
|
74
|
+
* adapter's own private recursion, so every nested node goes back through the
|
|
75
|
+
* adaptation lookup, not only the outermost one.
|
|
81
76
|
*
|
|
82
|
-
* `$Context` is the adapter's own, and opaque here: an adapter that
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* (`Type.Array(recurse(element, context))`) with no cast at any call
|
|
77
|
+
* `$Context` is the adapter's own, and opaque here: an adapter that needs to
|
|
78
|
+
* carry something down its recursion (the enclosing `T.recursive`'s
|
|
79
|
+
* placeholder, say) threads it through unchanged. `$Returnable` is likewise the
|
|
80
|
+
* adapter's own — stated so a nested node's result drops straight into a
|
|
81
|
+
* composite (`Type.Array(recurse(element, context))`) with no cast at any call
|
|
88
82
|
* site.
|
|
89
83
|
*/
|
|
90
84
|
export type Recurse<$Context, $Returnable> = (schema: any, context: $Context) => $Returnable;
|
|
91
85
|
/**
|
|
92
|
-
* An adapter to one external schema library: a plain value, imported
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
86
|
+
* An adapter to one external schema library: a plain value, imported directly
|
|
87
|
+
* by whoever adapts a schema (`schema.adapt(typebox, ...)`) and by whoever
|
|
88
|
+
* converts one. Nothing to register — no global interface to declaration-merge,
|
|
89
|
+
* and no name chosen anywhere but here.
|
|
96
90
|
*
|
|
97
|
-
* `key` is the adapter's `[Adaptation]` namespace. Read off the value
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* adapters can coexist.
|
|
91
|
+
* `key` is the adapter's `[Adaptation]` namespace. Read off the value as a
|
|
92
|
+
* literal type, so a wrong one is an import error rather than an entry nothing
|
|
93
|
+
* looks up. Give it something collision-proof — a package specifier, versioned
|
|
94
|
+
* when a library's major rewrite means two adapters can coexist.
|
|
102
95
|
*
|
|
103
|
-
* `convert`'s declared return type is this adapter's external bound:
|
|
104
|
-
*
|
|
105
|
-
*
|
|
96
|
+
* `convert`'s declared return type is this adapter's external bound: the type
|
|
97
|
+
* every `.adapt(...)` against it must produce, and why an adaptation that
|
|
98
|
+
* returns the wrong thing fails at the call site.
|
|
106
99
|
*
|
|
107
|
-
* Deliberately
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* `$Bindings` uses, for no gain.
|
|
100
|
+
* Deliberately _not_ carrying the adapter's type-level mapping. An adapter
|
|
101
|
+
* package declares its own conversion entry point with its own return type
|
|
102
|
+
* (`toTypeBox<$S>(schema: $S): ToTypeBox<$S>`), so nothing has to compute a
|
|
103
|
+
* type-level mapping out of a stored value — which would need the
|
|
104
|
+
* interface-member-lookup encoding `ValueOf`'s `$Bindings` uses, for no gain.
|
|
113
105
|
*/
|
|
114
106
|
export interface Adapter<$Key extends string = string, $Context = unknown, $Returnable = unknown> {
|
|
115
107
|
readonly key: $Key;
|
|
@@ -119,27 +111,25 @@ export interface Adapter<$Key extends string = string, $Context = unknown, $Retu
|
|
|
119
111
|
* The adaptations a Schema (or a built Fabricator, which carries them
|
|
120
112
|
* identically) declares, or `{}` for one that declares none.
|
|
121
113
|
*
|
|
122
|
-
* The two steps — extract the map, then match against it — are
|
|
123
|
-
*
|
|
124
|
-
* `
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* which then fails each adapter's `Record<Key, ...>` check as it
|
|
132
|
-
* should.
|
|
114
|
+
* The two steps — extract the map, then match against it — are load-bearing,
|
|
115
|
+
* and why no adapter matches `{ [Adaptation]?: Record<Key, ...> }` directly.
|
|
116
|
+
* Every kind's `Core` declares `[Adaptation]` as _optional_, and a conditional
|
|
117
|
+
* matching an optional property against a schema that lacks it entirely still
|
|
118
|
+
* _succeeds_, inferring `unknown` (the same behavior `ValueOf` relies on for
|
|
119
|
+
* `[Produces]`) — so a direct match would resolve every unadapted schema to
|
|
120
|
+
* whatever the adapter's adaptation branch produces. Constraining the `infer`
|
|
121
|
+
* sends that case here, to `{}`, which then fails each adapter's `Record<Key,
|
|
122
|
+
* ...>` check as it should.
|
|
133
123
|
*/
|
|
134
124
|
export type AdaptationsOf<$Schema> = $Schema extends {
|
|
135
125
|
[Adaptation]?: infer $Adaptations extends Adaptations;
|
|
136
126
|
} ? $Adaptations : {};
|
|
137
127
|
/**
|
|
138
|
-
* `$Prior` with `$Map` applied: an adapter named in `$Map` takes its new
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
128
|
+
* `$Prior` with `$Map` applied: an adapter named in `$Map` takes its new entry;
|
|
129
|
+
* one it doesn't name is carried forward. `Omit` first (rather than a plain
|
|
130
|
+
* `$Prior & $Map`) so a replaced entry is genuinely replaced — intersecting two
|
|
131
|
+
* call signatures for the same adapter would produce an overload, from which an
|
|
132
|
+
* adapter's `infer` would read whichever member TypeScript happens to resolve
|
|
133
|
+
* last.
|
|
144
134
|
*/
|
|
145
135
|
export type WithAdaptations<$Prior extends Adaptations, $Map extends Adaptations> = Omit<$Prior, keyof $Map> & $Map;
|
package/dist/types/Bound.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Canonical endpoint stored on `[Meta].whereby`. Call sites still accept a
|
|
3
|
-
* scalar (inclusive) via {@link InputBound}; `.whereby()` runs {@link toBound}
|
|
4
|
-
*
|
|
3
|
+
* scalar (inclusive) via {@link InputBound}; `.whereby()` runs {@link toBound} so
|
|
4
|
+
* adapters always see this shape — never a scalar/object union.
|
|
5
5
|
*/
|
|
6
6
|
export type Bound<$T> = {
|
|
7
7
|
value: $T;
|
|
8
8
|
exclusive: boolean;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* What `.whereby({ min, max })` accepts: a scalar is inclusive, an object
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* What `.whereby({ min, max })` accepts: a scalar is inclusive, an object names
|
|
12
|
+
* an endpoint policy. `exclusive` is required on the object form so that form
|
|
13
|
+
* exists only to state one.
|
|
14
14
|
*/
|
|
15
15
|
export type InputBound<$T> = $T | Bound<$T>;
|
|
16
16
|
/**
|
|
@@ -20,8 +20,8 @@ export type InputBound<$T> = $T | Bound<$T>;
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function toBound<$T>(input: InputBound<$T>): Bound<$T>;
|
|
22
22
|
/**
|
|
23
|
-
* Inclusive integer interval implied by a discrete Bound pair. Exclusive min
|
|
24
|
-
*
|
|
23
|
+
* Inclusive integer interval implied by a discrete Bound pair. Exclusive min is
|
|
24
|
+
* `value + 1`, exclusive max is `value - 1` — the same unit the length/
|
|
25
25
|
* integer/bigint draws already use. Empty iff `min > max`.
|
|
26
26
|
*/
|
|
27
27
|
export declare function effectiveDiscrete(min: Bound<number>, max: Bound<number>): {
|
|
@@ -37,15 +37,15 @@ export declare function assertNonemptyDiscreteBigint(label: string, min: Bound<b
|
|
|
37
37
|
/**
|
|
38
38
|
* Continuous emptiness: inverted bounds, a point range with either end
|
|
39
39
|
* exclusive, or both ends exclusive with no float strictly between them.
|
|
40
|
-
* Sampling still uses the closed interval and {@link constrainContinuous}
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* Sampling still uses the closed interval and {@link constrainContinuous} steps
|
|
41
|
+
* off an exclusive endpoint — this check is what makes that step always have
|
|
42
|
+
* somewhere to land.
|
|
43
43
|
*/
|
|
44
44
|
export declare function assertNonemptyContinuous(label: string, min: Bound<number>, max: Bound<number>): void;
|
|
45
45
|
/**
|
|
46
|
-
* One ulp toward `toward` from `value`. Approximate, and enough to leave
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* One ulp toward `toward` from `value`. Approximate, and enough to leave an
|
|
47
|
+
* exclusive endpoint without rejection-looping a truncated distribution that
|
|
48
|
+
* clamped onto it.
|
|
49
49
|
*/
|
|
50
50
|
export declare function towardInterior(value: number, toward: number): number;
|
|
51
51
|
/**
|
|
@@ -56,8 +56,8 @@ export declare function towardInterior(value: number, toward: number): number;
|
|
|
56
56
|
export declare function constrainContinuous(next: () => number, min: Bound<number>, max: Bound<number>): () => number;
|
|
57
57
|
export declare function epochBound(bound: Bound<Date>): Bound<number>;
|
|
58
58
|
/**
|
|
59
|
-
* Array/string `length`: a bare number is an exact count; an omitted `min`
|
|
60
|
-
*
|
|
59
|
+
* Array/string `length`: a bare number is an exact count; an omitted `min` is
|
|
60
|
+
* inclusive `0`. Always stored as a Bound pair so adapters have one path.
|
|
61
61
|
*/
|
|
62
62
|
export declare function toLengthRange(length: number | {
|
|
63
63
|
max: InputBound<number>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { Stream } from "../Random/Types";
|
|
2
2
|
/**
|
|
3
|
-
* How randomly generated values cluster within a `{ min, max }` range.
|
|
4
|
-
*
|
|
5
|
-
* equally likely.
|
|
3
|
+
* How randomly generated values cluster within a `{ min, max }` range. Without
|
|
4
|
+
* one, generation is uniform — every value in the range is equally likely.
|
|
6
5
|
*
|
|
7
|
-
* Each variant is a tagged object so distributions stay
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Each variant is a tagged object so distributions stay introspectable and
|
|
7
|
+
* serializable. The `custom` variant is the escape hatch: a shaping function
|
|
8
|
+
* `(u) => p` mapping a uniform draw in `[0, 1)` to a position in `[0, 1)`
|
|
9
|
+
* within the range.
|
|
11
10
|
*/
|
|
12
11
|
export type Distribution = Distribution.Uniform | Distribution.Normal | Distribution.Skew | Distribution.Triangular | Distribution.Logarithmic | Distribution.Multi | Distribution.Custom;
|
|
13
12
|
export type Range = {
|
|
@@ -25,9 +24,9 @@ export declare namespace Distribution {
|
|
|
25
24
|
spread?: number | undefined;
|
|
26
25
|
};
|
|
27
26
|
/**
|
|
28
|
-
* Bell curve truncated to the range. `mean` defaults to the range's
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* Bell curve truncated to the range. `mean` defaults to the range's center;
|
|
28
|
+
* `spread` (standard deviation) defaults to a sixth of the span, placing the
|
|
29
|
+
* bounds at roughly ±3σ before truncation.
|
|
31
30
|
*/
|
|
32
31
|
const normal: (params?: {
|
|
33
32
|
mean?: number;
|
|
@@ -38,8 +37,8 @@ export declare namespace Distribution {
|
|
|
38
37
|
exponent: number;
|
|
39
38
|
};
|
|
40
39
|
/**
|
|
41
|
-
* Power curve. `exponent > 1` biases toward `min`, `exponent < 1`
|
|
42
|
-
*
|
|
40
|
+
* Power curve. `exponent > 1` biases toward `min`, `exponent < 1` biases
|
|
41
|
+
* toward `max`, and `exponent === 1` is uniform.
|
|
43
42
|
*/
|
|
44
43
|
const skew: (exponent: number) => Distribution;
|
|
45
44
|
type Triangular = {
|
|
@@ -56,10 +55,9 @@ export declare namespace Distribution {
|
|
|
56
55
|
kind: "logarithmic";
|
|
57
56
|
};
|
|
58
57
|
/**
|
|
59
|
-
* Log-uniform (reciprocal): density proportional to `1/x`, so values
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* or below zero.
|
|
58
|
+
* Log-uniform (reciprocal): density proportional to `1/x`, so values spread
|
|
59
|
+
* evenly across orders of magnitude and cluster toward `min`. Requires a
|
|
60
|
+
* strictly positive range — the logarithm is undefined at or below zero.
|
|
63
61
|
*/
|
|
64
62
|
const logarithmic: () => Distribution;
|
|
65
63
|
type Multi = {
|
|
@@ -70,11 +68,10 @@ export declare namespace Distribution {
|
|
|
70
68
|
}>;
|
|
71
69
|
};
|
|
72
70
|
/**
|
|
73
|
-
* A weighted blend of component distributions, each drawn over the
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* to 1.
|
|
71
|
+
* A weighted blend of component distributions, each drawn over the same
|
|
72
|
+
* range. Localized components with distinct centers (e.g. two `normal`s at
|
|
73
|
+
* different means) produce the separate peaks of a multimodal distribution.
|
|
74
|
+
* Weights are relative — they need not sum to 1.
|
|
78
75
|
*/
|
|
79
76
|
const multi: (components: ReadonlyArray<{
|
|
80
77
|
weight: number;
|
|
@@ -85,73 +82,69 @@ export declare namespace Distribution {
|
|
|
85
82
|
shape: (u: number) => number;
|
|
86
83
|
};
|
|
87
84
|
/**
|
|
88
|
-
* Escape hatch: `shape` maps a uniform draw in `[0, 1)` to a
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* bounds.
|
|
85
|
+
* Escape hatch: `shape` maps a uniform draw in `[0, 1)` to a position in `[0,
|
|
86
|
+
* 1)` within the range (an inverse CDF). The output is clamped to `[0, 1]` so
|
|
87
|
+
* the result always lands within the bounds.
|
|
92
88
|
*/
|
|
93
89
|
const custom: (shape: (u: number) => number) => Distribution;
|
|
94
90
|
}
|
|
95
91
|
/**
|
|
96
|
-
* Build a sampler that draws values within `range` following
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
92
|
+
* Build a sampler that draws values within `range` following `distribution`.
|
|
93
|
+
* Each call consumes one fresh uniform draw and, by construction, returns a
|
|
94
|
+
* value within `[min, max]` — distributions with mass outside the range (e.g. a
|
|
95
|
+
* normal's tails) are truncated via their inverse CDF rather than rejected or
|
|
96
|
+
* clamped.
|
|
101
97
|
*/
|
|
102
98
|
export declare function sampler(distribution: Distribution, range: Range, stream: Stream): () => number;
|
|
103
99
|
export declare function sample<$T>(list: ReadonlyArray<$T>, stream: Stream): $T;
|
|
104
100
|
/**
|
|
105
101
|
* Fisher–Yates (Durstenfeld) shuffle: a new array holding `items` in a
|
|
106
|
-
* uniformly random order — every permutation is equally likely. Does
|
|
107
|
-
*
|
|
108
|
-
* convention.
|
|
102
|
+
* uniformly random order — every permutation is equally likely. Does not mutate
|
|
103
|
+
* `items`, matching `sample`/`weighted`'s read-only convention.
|
|
109
104
|
*/
|
|
110
105
|
export declare function shuffle<$T>(items: ReadonlyArray<$T>, stream: Stream): $T[];
|
|
111
106
|
/**
|
|
112
|
-
* `weighted()`'s own inclusion rule: whether this entry stays in the
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* `weight > 0`.
|
|
107
|
+
* `weighted()`'s own inclusion rule: whether this entry stays in the draw
|
|
108
|
+
* table. `0` is valid and disables the outcome; negative/`NaN` are rejected
|
|
109
|
+
* earlier by {@link isValidWeight}. Exposed so `Enumeration/Plan.ts` and the
|
|
110
|
+
* construction guards share one definition of "will this be drawn" rather than
|
|
111
|
+
* each writing `weight > 0`.
|
|
118
112
|
*/
|
|
119
113
|
export declare function isDrawable(weight: number): boolean;
|
|
120
114
|
/**
|
|
121
|
-
* Whether a weight is
|
|
122
|
-
* drawable. `0` is valid and disables the outcome; a negative weight or
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
115
|
+
* Whether a weight is _expressible_ at all, as opposed to whether it is
|
|
116
|
+
* drawable. `0` is valid and disables the outcome; a negative weight or `NaN`
|
|
117
|
+
* is a mistake. `Infinity` is rejected because it cannot be summed into a
|
|
118
|
+
* usable draw table — every cumulative bound becomes `Infinity`, so
|
|
119
|
+
* `weighted()`'s `x < weight` scan matches nothing.
|
|
126
120
|
*/
|
|
127
121
|
export declare function isValidWeight(weight: number): boolean;
|
|
128
122
|
/**
|
|
129
|
-
* Outcomes that still have a positive weight after applying the
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* `
|
|
123
|
+
* Outcomes that still have a positive weight after applying the baseline of `1`
|
|
124
|
+
* for any unspecified (missing or explicitly `undefined`) key. The one home of
|
|
125
|
+
* that `?? 1` default, so `assertDrawableKeyedWeights` and
|
|
126
|
+
* `Enumeration/Plan.ts` cannot drift.
|
|
133
127
|
*/
|
|
134
128
|
export declare function drawableOutcomes<$Outcome extends string>(outcomes: ReadonlyArray<$Outcome>, weights: Readonly<Record<string, number | undefined>> | undefined): ReadonlyArray<$Outcome>;
|
|
135
129
|
/**
|
|
136
|
-
* Two-stage guard for a `[weight, item]` list (`enum`/`choice`'s
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* (`"T.enum.weighted"`/`"T.choice.weighted"`), `noun` the kind of
|
|
130
|
+
* Two-stage guard for a `[weight, item]` list (`enum`/`choice`'s `.weighted()`
|
|
131
|
+
* registries). Stage 1 rejects any entry that is not {@link isValidWeight};
|
|
132
|
+
* stage 2 rejects a list with no {@link isDrawable} entry left. `label` names
|
|
133
|
+
* the call site (`"T.enum.weighted"`/`"T.choice.weighted"`), `noun` the kind of
|
|
141
134
|
* entry (`"member"`/`"option"`).
|
|
142
135
|
*/
|
|
143
136
|
export declare function assertDrawableWeights(label: string, noun: string, items: ReadonlyArray<readonly [number, unknown]>): void;
|
|
144
137
|
/**
|
|
145
|
-
* The same two-stage guard as {@link assertDrawableWeights}, for the
|
|
146
|
-
*
|
|
147
|
-
*
|
|
138
|
+
* The same two-stage guard as {@link assertDrawableWeights}, for the kinds
|
|
139
|
+
* whose `.weighted(...)` weighs a _fixed, named_ outcome set (`boolean`'s
|
|
140
|
+
* `true`/`false`; `nullable`/`nullish`/`undefinable`/
|
|
148
141
|
* `object.omittable`/`object.optional`'s presence outcomes) rather than a
|
|
149
|
-
* caller-supplied list. Stage 2 must see the kind's **full** outcome list
|
|
150
|
-
*
|
|
142
|
+
* caller-supplied list. Stage 2 must see the kind's **full** outcome list — an
|
|
143
|
+
* omitted key still defaults to `1` — hence `outcomes`.
|
|
151
144
|
*
|
|
152
|
-
* An explicitly-`undefined` value means "unspecified" — `Weights`'
|
|
153
|
-
*
|
|
154
|
-
*
|
|
145
|
+
* An explicitly-`undefined` value means "unspecified" — `Weights`' keys are all
|
|
146
|
+
* optional and fall back to a baseline of `1` — so it is skipped in stage 1 and
|
|
147
|
+
* defaulted in stage 2.
|
|
155
148
|
*/
|
|
156
149
|
export declare function assertDrawableKeyedWeights<$Outcome extends string>(label: string, outcomes: ReadonlyArray<$Outcome>, weights: Readonly<Record<string, number | undefined>>): void;
|
|
157
150
|
export declare function weighted<const $Item>(weights: ReadonlyArray<readonly [number, $Item]>, stream: Stream, label: string): () => $Item;
|
|
@@ -2,32 +2,30 @@ import type { Stack } from "../Instance/Types";
|
|
|
2
2
|
import type { RandomSource } from "../Random/Types";
|
|
3
3
|
import type { Enumerable, Limits } from "./Types";
|
|
4
4
|
/**
|
|
5
|
-
* Typed `combinatorial`/`coverage` boundary, closing over one
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* one precisely-typed layer, mirroring `Constructor.ts`'s `make`/
|
|
5
|
+
* Typed `combinatorial`/`coverage` boundary, closing over one instance's
|
|
6
|
+
* `source` and its already-validated `limits` — same shape as
|
|
7
|
+
* `Constructor(source, stack)`. No separate `clock`: `source` already carries
|
|
8
|
+
* its resolved clock (`Random/Types.ts`'s `Options.clock`), so `Constructor`'s
|
|
9
|
+
* `toConstructionContext` reads it off whichever root a construction resolves
|
|
10
|
+
* against. `plan`/ `resolve` (`./Plan.ts`) do the untyped recursive work; this
|
|
11
|
+
* is the one precisely-typed layer, mirroring `Constructor.ts`'s `make`/
|
|
13
12
|
* `construct` split.
|
|
14
13
|
*
|
|
15
|
-
* Two derived seeds — one per API — each an independent, deterministic
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* `new Fabricator(schema, { seed })` (see `Constructor.ts`'s
|
|
14
|
+
* Two derived seeds — one per API — each an independent, deterministic fork off
|
|
15
|
+
* the _effective_ source's seed (`effectiveSource()` below — the active `wrap`
|
|
16
|
+
* frame's, or this instance's `source`; read fresh on every
|
|
17
|
+
* `combinatorial(...)`/`coverage(...)` call, not once when `enumerables()` was
|
|
18
|
+
* built, so the same `combinatorial` reference behaves differently inside an
|
|
19
|
+
* active `wrap`). `new Fabricator(schema, { seed })` (see `Constructor.ts`'s
|
|
22
20
|
* `construct()`) forks a fully isolated `RandomSource` and opens an
|
|
23
|
-
* `"unattributed"` scope, so `resolveCallerFile()` is never called —
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
21
|
+
* `"unattributed"` scope, so `resolveCallerFile()` is never called — the
|
|
22
|
+
* lazy-generator attribution hazard a plain `function*` would invite simply
|
|
23
|
+
* doesn't arise — the instance's construction counters are never touched, and
|
|
24
|
+
* the same seed reproduces regardless of which file
|
|
25
|
+
* `combinatorial(...)`/`coverage(...)` is called from. Each `fork()` starts
|
|
26
|
+
* from a fresh source, so reusing one seed across many builds (different
|
|
27
|
+
* schemas, or the same schema rebuilt per iteration) never lets one build's
|
|
28
|
+
* draws leak into another's.
|
|
31
29
|
*/
|
|
32
30
|
export declare function enumerables(source: RandomSource, limits: Limits, stack: Stack): {
|
|
33
31
|
combinatorial: Enumerable;
|
|
@@ -7,38 +7,34 @@ type Planning = {
|
|
|
7
7
|
orderer: Orderer;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
* Enumerable shape of a built Fabricator tree: how many distinct
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* widen/narrow rules.
|
|
10
|
+
* Enumerable shape of a built Fabricator tree: how many distinct combinations,
|
|
11
|
+
* and how to reproduce the `index`-th as a `Pin`. Exhaustive kind dispatch
|
|
12
|
+
* lives in `axisFor`; this wrapper applies `"cycle"` permutation uniformly,
|
|
13
|
+
* once, to whatever axis `axisFor` computes — so every recursive call
|
|
14
|
+
* (`axisFor` cases call back into `plan`, never `axisFor` directly) gets its
|
|
15
|
+
* _own_ independent permutation, decorrelating equal-width siblings without any
|
|
16
|
+
* per-kind case needing to know strategy beyond `Strategy`'s own widen/narrow
|
|
17
|
+
* rules.
|
|
19
18
|
*
|
|
20
|
-
* Width is a function of schema shape
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* re-implemented here.
|
|
19
|
+
* Width is a function of schema shape _and_ weights: a zero-weighted outcome is
|
|
20
|
+
* not fabricable, so `axisFor` filters through `isDrawable` /
|
|
21
|
+
* `drawableOutcomes` rather than treating the declared branch set as the axis.
|
|
22
|
+
* Without that, `coverage()` would pin a value `fabricate()` can never produce.
|
|
23
|
+
* Defaulting of unspecified keyed weights goes through `drawableOutcomes` so
|
|
24
|
+
* the `?? 1` baseline is never re-implemented here.
|
|
27
25
|
*
|
|
28
26
|
* Skipped for width-1 axes (nothing to permute) and under `"product"`
|
|
29
|
-
* (mixed-radix decode already visits every combination, so permuting
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* omit otherwise.
|
|
27
|
+
* (mixed-radix decode already visits every combination, so permuting would only
|
|
28
|
+
* reorder identical output — see `Orderer`). `orders` is therefore only ever
|
|
29
|
+
* read when `strategy === "cycle"` and is safe to omit otherwise.
|
|
33
30
|
*/
|
|
34
31
|
export declare function plan(node: Resolvable, planning: Planning): Axis;
|
|
35
32
|
/**
|
|
36
|
-
* Reproduce the value a `Pin` describes against the built Fabricator
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* be exhaustive the way `plan()`'s is.
|
|
33
|
+
* Reproduce the value a `Pin` describes against the built Fabricator it was
|
|
34
|
+
* planned from. `pin === undefined` is universal — `plan()` gave this node a
|
|
35
|
+
* width-1 axis, so there is nothing to pin and it fabricates normally. Every
|
|
36
|
+
* other case only arises for kinds `plan()` treats as enumerable axes, so this
|
|
37
|
+
* switch does not need to be exhaustive the way `plan()`'s is.
|
|
42
38
|
*/
|
|
43
39
|
export declare function resolve(node: Resolvable, pin: Pin): unknown;
|
|
44
40
|
export {};
|