@ghostry/fabricator 0.0.1
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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/esm/Adapter/Core.js +47 -0
- package/dist/esm/Adapter/Types.js +1 -0
- package/dist/esm/Bound.js +81 -0
- package/dist/esm/Distribution/index.js +200 -0
- package/dist/esm/Enumeration/Enumerate.js +103 -0
- package/dist/esm/Enumeration/Plan.js +286 -0
- package/dist/esm/Enumeration/Types.js +1 -0
- package/dist/esm/Error/index.js +201 -0
- package/dist/esm/Fabricator/Constructor.js +328 -0
- package/dist/esm/Fabricator/Types.js +1 -0
- package/dist/esm/Instance/Core.js +119 -0
- package/dist/esm/Instance/Types.js +1 -0
- package/dist/esm/Primitive/always/Fabricator.js +13 -0
- package/dist/esm/Primitive/always/Registry.js +11 -0
- package/dist/esm/Primitive/always/Schema.js +10 -0
- package/dist/esm/Primitive/always/Types.js +1 -0
- package/dist/esm/Primitive/always/index.js +5 -0
- package/dist/esm/Primitive/array/Fabricator.js +45 -0
- package/dist/esm/Primitive/array/Registry.js +26 -0
- package/dist/esm/Primitive/array/Schema.js +17 -0
- package/dist/esm/Primitive/array/Types.js +1 -0
- package/dist/esm/Primitive/array/index.js +5 -0
- package/dist/esm/Primitive/bigint/Fabricator.js +54 -0
- package/dist/esm/Primitive/bigint/Registry.js +31 -0
- package/dist/esm/Primitive/bigint/Schema.js +17 -0
- package/dist/esm/Primitive/bigint/Types.js +1 -0
- package/dist/esm/Primitive/bigint/index.js +5 -0
- package/dist/esm/Primitive/boolean/Fabricator.js +44 -0
- package/dist/esm/Primitive/boolean/Outcomes.js +5 -0
- package/dist/esm/Primitive/boolean/Registry.js +11 -0
- package/dist/esm/Primitive/boolean/Schema.js +33 -0
- package/dist/esm/Primitive/boolean/Types.js +1 -0
- package/dist/esm/Primitive/boolean/index.js +6 -0
- package/dist/esm/Primitive/choice/Fabricator.js +37 -0
- package/dist/esm/Primitive/choice/Registry.js +38 -0
- package/dist/esm/Primitive/choice/Schema.js +17 -0
- package/dist/esm/Primitive/choice/Types.js +1 -0
- package/dist/esm/Primitive/choice/index.js +5 -0
- package/dist/esm/Primitive/date/Fabricator.js +86 -0
- package/dist/esm/Primitive/date/Registry.js +61 -0
- package/dist/esm/Primitive/date/Schema.js +17 -0
- package/dist/esm/Primitive/date/Types.js +1 -0
- package/dist/esm/Primitive/date/index.js +5 -0
- package/dist/esm/Primitive/enum/Fabricator.js +33 -0
- package/dist/esm/Primitive/enum/Registry.js +33 -0
- package/dist/esm/Primitive/enum/Schema.js +17 -0
- package/dist/esm/Primitive/enum/Types.js +1 -0
- package/dist/esm/Primitive/enum/index.js +5 -0
- package/dist/esm/Primitive/index.js +24 -0
- package/dist/esm/Primitive/namespace.js +21 -0
- package/dist/esm/Primitive/null/Fabricator.js +14 -0
- package/dist/esm/Primitive/null/Registry.js +8 -0
- package/dist/esm/Primitive/null/Schema.js +10 -0
- package/dist/esm/Primitive/null/Types.js +1 -0
- package/dist/esm/Primitive/null/index.js +5 -0
- package/dist/esm/Primitive/nullable/Fabricator.js +58 -0
- package/dist/esm/Primitive/nullable/Outcomes.js +5 -0
- package/dist/esm/Primitive/nullable/Registry.js +13 -0
- package/dist/esm/Primitive/nullable/Schema.js +36 -0
- package/dist/esm/Primitive/nullable/Types.js +1 -0
- package/dist/esm/Primitive/nullable/index.js +6 -0
- package/dist/esm/Primitive/nullish/Fabricator.js +64 -0
- package/dist/esm/Primitive/nullish/Outcomes.js +6 -0
- package/dist/esm/Primitive/nullish/Registry.js +13 -0
- package/dist/esm/Primitive/nullish/Schema.js +36 -0
- package/dist/esm/Primitive/nullish/Types.js +1 -0
- package/dist/esm/Primitive/nullish/index.js +6 -0
- package/dist/esm/Primitive/number/Fabricator.js +73 -0
- package/dist/esm/Primitive/number/Registry.js +59 -0
- package/dist/esm/Primitive/number/Schema.js +18 -0
- package/dist/esm/Primitive/number/Types.js +1 -0
- package/dist/esm/Primitive/number/defaults.js +21 -0
- package/dist/esm/Primitive/number/index.js +5 -0
- package/dist/esm/Primitive/object/Fabricator.js +77 -0
- package/dist/esm/Primitive/object/Registry.js +146 -0
- package/dist/esm/Primitive/object/Schema.js +18 -0
- package/dist/esm/Primitive/object/Types.js +1 -0
- package/dist/esm/Primitive/object/compute/Fabricator.js +24 -0
- package/dist/esm/Primitive/object/compute/Registry.js +15 -0
- package/dist/esm/Primitive/object/compute/Schema.js +13 -0
- package/dist/esm/Primitive/object/compute/Types.js +1 -0
- package/dist/esm/Primitive/object/compute/index.js +5 -0
- package/dist/esm/Primitive/object/index.js +9 -0
- package/dist/esm/Primitive/object/omittable/Fabricator.js +57 -0
- package/dist/esm/Primitive/object/omittable/Outcomes.js +5 -0
- package/dist/esm/Primitive/object/omittable/Registry.js +13 -0
- package/dist/esm/Primitive/object/omittable/Schema.js +36 -0
- package/dist/esm/Primitive/object/omittable/Types.js +1 -0
- package/dist/esm/Primitive/object/omittable/index.js +6 -0
- package/dist/esm/Primitive/object/optional/Fabricator.js +55 -0
- package/dist/esm/Primitive/object/optional/Outcomes.js +6 -0
- package/dist/esm/Primitive/object/optional/Registry.js +13 -0
- package/dist/esm/Primitive/object/optional/Schema.js +36 -0
- package/dist/esm/Primitive/object/optional/Types.js +1 -0
- package/dist/esm/Primitive/object/optional/index.js +6 -0
- package/dist/esm/Primitive/opaque/Fabricator.js +19 -0
- package/dist/esm/Primitive/opaque/Registry.js +11 -0
- package/dist/esm/Primitive/opaque/Schema.js +10 -0
- package/dist/esm/Primitive/opaque/Types.js +1 -0
- package/dist/esm/Primitive/opaque/index.js +5 -0
- package/dist/esm/Primitive/record/Fabricator.js +55 -0
- package/dist/esm/Primitive/record/Registry.js +26 -0
- package/dist/esm/Primitive/record/Schema.js +17 -0
- package/dist/esm/Primitive/record/Types.js +1 -0
- package/dist/esm/Primitive/record/index.js +5 -0
- package/dist/esm/Primitive/recursive/Fabricator.js +33 -0
- package/dist/esm/Primitive/recursive/Registry.js +20 -0
- package/dist/esm/Primitive/recursive/Schema.js +10 -0
- package/dist/esm/Primitive/recursive/Terminate.js +236 -0
- package/dist/esm/Primitive/recursive/Types.js +1 -0
- package/dist/esm/Primitive/recursive/index.js +7 -0
- package/dist/esm/Primitive/recursive/self/Fabricator.js +15 -0
- package/dist/esm/Primitive/recursive/self/Registry.js +9 -0
- package/dist/esm/Primitive/recursive/self/Schema.js +10 -0
- package/dist/esm/Primitive/recursive/self/Types.js +1 -0
- package/dist/esm/Primitive/recursive/self/index.js +5 -0
- package/dist/esm/Primitive/string/Constants.js +73 -0
- package/dist/esm/Primitive/string/Fabricator.js +109 -0
- package/dist/esm/Primitive/string/Registry.js +25 -0
- package/dist/esm/Primitive/string/Schema.js +18 -0
- package/dist/esm/Primitive/string/Types.js +1 -0
- package/dist/esm/Primitive/string/index.js +6 -0
- package/dist/esm/Primitive/symbol/Fabricator.js +33 -0
- package/dist/esm/Primitive/symbol/Registry.js +17 -0
- package/dist/esm/Primitive/symbol/Schema.js +17 -0
- package/dist/esm/Primitive/symbol/Types.js +1 -0
- package/dist/esm/Primitive/symbol/index.js +5 -0
- package/dist/esm/Primitive/tuple/Fabricator.js +33 -0
- package/dist/esm/Primitive/tuple/Registry.js +13 -0
- package/dist/esm/Primitive/tuple/Schema.js +17 -0
- package/dist/esm/Primitive/tuple/Types.js +1 -0
- package/dist/esm/Primitive/tuple/index.js +5 -0
- package/dist/esm/Primitive/undefinable/Fabricator.js +58 -0
- package/dist/esm/Primitive/undefinable/Outcomes.js +5 -0
- package/dist/esm/Primitive/undefinable/Registry.js +13 -0
- package/dist/esm/Primitive/undefinable/Schema.js +36 -0
- package/dist/esm/Primitive/undefinable/Types.js +1 -0
- package/dist/esm/Primitive/undefinable/index.js +6 -0
- package/dist/esm/Primitive/undefined/Fabricator.js +16 -0
- package/dist/esm/Primitive/undefined/Registry.js +8 -0
- package/dist/esm/Primitive/undefined/Schema.js +10 -0
- package/dist/esm/Primitive/undefined/Types.js +1 -0
- package/dist/esm/Primitive/undefined/index.js +5 -0
- package/dist/esm/Random/CallSite.js +56 -0
- package/dist/esm/Random/Generator/sfc32.js +16 -0
- package/dist/esm/Random/Types.js +1 -0
- package/dist/esm/Random/index.js +151 -0
- package/dist/esm/Schema/Core.js +68 -0
- package/dist/esm/Schema/Registry.js +17 -0
- package/dist/esm/Schema/Types.js +1 -0
- package/dist/esm/Types.js +11 -0
- package/dist/esm/Utility/Core.js +36 -0
- package/dist/esm/Utility/DeepMerge.js +18 -0
- package/dist/esm/Utility/Digest.js +28 -0
- package/dist/esm/Utility/ShallowMerge.js +13 -0
- package/dist/esm/Utility/Types.js +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/internal.js +5 -0
- package/dist/types/Adapter/Core.d.ts +64 -0
- package/dist/types/Adapter/Types.d.ts +145 -0
- package/dist/types/Bound.d.ts +68 -0
- package/dist/types/Distribution/index.d.ts +157 -0
- package/dist/types/Enumeration/Enumerate.d.ts +35 -0
- package/dist/types/Enumeration/Plan.d.ts +44 -0
- package/dist/types/Enumeration/Types.d.ts +86 -0
- package/dist/types/Error/index.d.ts +541 -0
- package/dist/types/Fabricator/Constructor.d.ts +43 -0
- package/dist/types/Fabricator/Types.d.ts +150 -0
- package/dist/types/Instance/Core.d.ts +98 -0
- package/dist/types/Instance/Types.d.ts +167 -0
- package/dist/types/Primitive/always/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/always/Registry.d.ts +3 -0
- package/dist/types/Primitive/always/Schema.d.ts +19 -0
- package/dist/types/Primitive/always/Types.d.ts +23 -0
- package/dist/types/Primitive/always/index.d.ts +5 -0
- package/dist/types/Primitive/array/Fabricator.d.ts +22 -0
- package/dist/types/Primitive/array/Registry.d.ts +18 -0
- package/dist/types/Primitive/array/Schema.d.ts +23 -0
- package/dist/types/Primitive/array/Types.d.ts +44 -0
- package/dist/types/Primitive/array/index.d.ts +5 -0
- package/dist/types/Primitive/bigint/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/bigint/Registry.d.ts +19 -0
- package/dist/types/Primitive/bigint/Schema.d.ts +27 -0
- package/dist/types/Primitive/bigint/Types.d.ts +33 -0
- package/dist/types/Primitive/bigint/index.d.ts +5 -0
- package/dist/types/Primitive/boolean/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/boolean/Outcomes.d.ts +12 -0
- package/dist/types/Primitive/boolean/Registry.d.ts +14 -0
- package/dist/types/Primitive/boolean/Schema.d.ts +28 -0
- package/dist/types/Primitive/boolean/Types.d.ts +26 -0
- package/dist/types/Primitive/boolean/index.d.ts +6 -0
- package/dist/types/Primitive/choice/Fabricator.d.ts +32 -0
- package/dist/types/Primitive/choice/Registry.d.ts +38 -0
- package/dist/types/Primitive/choice/Schema.d.ts +24 -0
- package/dist/types/Primitive/choice/Types.d.ts +35 -0
- package/dist/types/Primitive/choice/index.d.ts +5 -0
- package/dist/types/Primitive/date/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/date/Registry.d.ts +82 -0
- package/dist/types/Primitive/date/Schema.d.ts +28 -0
- package/dist/types/Primitive/date/Types.d.ts +34 -0
- package/dist/types/Primitive/date/index.d.ts +5 -0
- package/dist/types/Primitive/enum/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/enum/Registry.d.ts +39 -0
- package/dist/types/Primitive/enum/Schema.d.ts +23 -0
- package/dist/types/Primitive/enum/Types.d.ts +44 -0
- package/dist/types/Primitive/enum/index.d.ts +5 -0
- package/dist/types/Primitive/index.d.ts +28 -0
- package/dist/types/Primitive/namespace.d.ts +38 -0
- package/dist/types/Primitive/null/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/null/Registry.d.ts +3 -0
- package/dist/types/Primitive/null/Schema.d.ts +16 -0
- package/dist/types/Primitive/null/Types.d.ts +15 -0
- package/dist/types/Primitive/null/index.d.ts +5 -0
- package/dist/types/Primitive/nullable/Fabricator.d.ts +31 -0
- package/dist/types/Primitive/nullable/Outcomes.d.ts +9 -0
- package/dist/types/Primitive/nullable/Registry.d.ts +3 -0
- package/dist/types/Primitive/nullable/Schema.d.ts +36 -0
- package/dist/types/Primitive/nullable/Types.d.ts +48 -0
- package/dist/types/Primitive/nullable/index.d.ts +6 -0
- package/dist/types/Primitive/nullish/Fabricator.d.ts +36 -0
- package/dist/types/Primitive/nullish/Outcomes.d.ts +9 -0
- package/dist/types/Primitive/nullish/Registry.d.ts +3 -0
- package/dist/types/Primitive/nullish/Schema.d.ts +36 -0
- package/dist/types/Primitive/nullish/Types.d.ts +58 -0
- package/dist/types/Primitive/nullish/index.d.ts +6 -0
- package/dist/types/Primitive/number/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/number/Registry.d.ts +52 -0
- package/dist/types/Primitive/number/Schema.d.ts +32 -0
- package/dist/types/Primitive/number/Types.d.ts +56 -0
- package/dist/types/Primitive/number/defaults.d.ts +18 -0
- package/dist/types/Primitive/number/index.d.ts +5 -0
- package/dist/types/Primitive/object/Fabricator.d.ts +56 -0
- package/dist/types/Primitive/object/Registry.d.ts +23 -0
- package/dist/types/Primitive/object/Schema.d.ts +41 -0
- package/dist/types/Primitive/object/Types.d.ts +85 -0
- package/dist/types/Primitive/object/compute/Fabricator.d.ts +31 -0
- package/dist/types/Primitive/object/compute/Registry.d.ts +4 -0
- package/dist/types/Primitive/object/compute/Schema.d.ts +21 -0
- package/dist/types/Primitive/object/compute/Types.d.ts +56 -0
- package/dist/types/Primitive/object/compute/index.d.ts +5 -0
- package/dist/types/Primitive/object/index.d.ts +8 -0
- package/dist/types/Primitive/object/omittable/Fabricator.d.ts +37 -0
- package/dist/types/Primitive/object/omittable/Outcomes.d.ts +9 -0
- package/dist/types/Primitive/object/omittable/Registry.d.ts +3 -0
- package/dist/types/Primitive/object/omittable/Schema.d.ts +32 -0
- package/dist/types/Primitive/object/omittable/Types.d.ts +57 -0
- package/dist/types/Primitive/object/omittable/index.d.ts +6 -0
- package/dist/types/Primitive/object/optional/Fabricator.d.ts +45 -0
- package/dist/types/Primitive/object/optional/Outcomes.d.ts +9 -0
- package/dist/types/Primitive/object/optional/Registry.d.ts +3 -0
- package/dist/types/Primitive/object/optional/Schema.d.ts +32 -0
- package/dist/types/Primitive/object/optional/Types.d.ts +72 -0
- package/dist/types/Primitive/object/optional/index.d.ts +6 -0
- package/dist/types/Primitive/opaque/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/opaque/Registry.d.ts +12 -0
- package/dist/types/Primitive/opaque/Schema.d.ts +22 -0
- package/dist/types/Primitive/opaque/Types.d.ts +18 -0
- package/dist/types/Primitive/opaque/index.d.ts +5 -0
- package/dist/types/Primitive/record/Fabricator.d.ts +25 -0
- package/dist/types/Primitive/record/Registry.d.ts +17 -0
- package/dist/types/Primitive/record/Schema.d.ts +27 -0
- package/dist/types/Primitive/record/Types.d.ts +85 -0
- package/dist/types/Primitive/record/index.d.ts +5 -0
- package/dist/types/Primitive/recursive/Fabricator.d.ts +47 -0
- package/dist/types/Primitive/recursive/Registry.d.ts +22 -0
- package/dist/types/Primitive/recursive/Schema.d.ts +21 -0
- package/dist/types/Primitive/recursive/Terminate.d.ts +20 -0
- package/dist/types/Primitive/recursive/Types.d.ts +82 -0
- package/dist/types/Primitive/recursive/index.d.ts +6 -0
- package/dist/types/Primitive/recursive/self/Fabricator.d.ts +29 -0
- package/dist/types/Primitive/recursive/self/Registry.d.ts +7 -0
- package/dist/types/Primitive/recursive/self/Schema.d.ts +20 -0
- package/dist/types/Primitive/recursive/self/Types.d.ts +28 -0
- package/dist/types/Primitive/recursive/self/index.d.ts +5 -0
- package/dist/types/Primitive/string/Constants.d.ts +58 -0
- package/dist/types/Primitive/string/Fabricator.d.ts +24 -0
- package/dist/types/Primitive/string/Registry.d.ts +44 -0
- package/dist/types/Primitive/string/Schema.d.ts +65 -0
- package/dist/types/Primitive/string/Types.d.ts +77 -0
- package/dist/types/Primitive/string/index.d.ts +6 -0
- package/dist/types/Primitive/symbol/Fabricator.d.ts +24 -0
- package/dist/types/Primitive/symbol/Registry.d.ts +16 -0
- package/dist/types/Primitive/symbol/Schema.d.ts +24 -0
- package/dist/types/Primitive/symbol/Types.d.ts +19 -0
- package/dist/types/Primitive/symbol/index.d.ts +5 -0
- package/dist/types/Primitive/tuple/Fabricator.d.ts +37 -0
- package/dist/types/Primitive/tuple/Registry.d.ts +3 -0
- package/dist/types/Primitive/tuple/Schema.d.ts +24 -0
- package/dist/types/Primitive/tuple/Types.d.ts +53 -0
- package/dist/types/Primitive/tuple/index.d.ts +5 -0
- package/dist/types/Primitive/undefinable/Fabricator.d.ts +31 -0
- package/dist/types/Primitive/undefinable/Outcomes.d.ts +9 -0
- package/dist/types/Primitive/undefinable/Registry.d.ts +3 -0
- package/dist/types/Primitive/undefinable/Schema.d.ts +36 -0
- package/dist/types/Primitive/undefinable/Types.d.ts +48 -0
- package/dist/types/Primitive/undefinable/index.d.ts +6 -0
- package/dist/types/Primitive/undefined/Fabricator.d.ts +19 -0
- package/dist/types/Primitive/undefined/Registry.d.ts +3 -0
- package/dist/types/Primitive/undefined/Schema.d.ts +16 -0
- package/dist/types/Primitive/undefined/Types.d.ts +15 -0
- package/dist/types/Primitive/undefined/index.d.ts +5 -0
- package/dist/types/Random/CallSite.d.ts +59 -0
- package/dist/types/Random/Generator/sfc32.d.ts +10 -0
- package/dist/types/Random/Types.d.ts +384 -0
- package/dist/types/Random/index.d.ts +107 -0
- package/dist/types/Schema/Core.d.ts +44 -0
- package/dist/types/Schema/Registry.d.ts +20 -0
- package/dist/types/Schema/Types.d.ts +70 -0
- package/dist/types/Types.d.ts +78 -0
- package/dist/types/Utility/Core.d.ts +35 -0
- package/dist/types/Utility/DeepMerge.d.ts +14 -0
- package/dist/types/Utility/Digest.d.ts +9 -0
- package/dist/types/Utility/ShallowMerge.d.ts +6 -0
- package/dist/types/Utility/Types.d.ts +4 -0
- package/dist/types/index.d.ts +186 -0
- package/dist/types/internal.d.ts +64 -0
- package/package.json +53 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { Adaptations, AdaptationsOf } from "../Adapter/Types";
|
|
2
|
+
import type { Primitive, Kind as SchemaKind } from "../Primitive";
|
|
3
|
+
import type { Algorithm, Trace } from "../Random/Types";
|
|
4
|
+
import type { ValueOf } from "../Schema/Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produces } from "../Types";
|
|
6
|
+
import type { PlainObject } from "../Utility/Types";
|
|
7
|
+
/**
|
|
8
|
+
* Threaded through `Constructor.ts`'s `make` for every dispatch of one
|
|
9
|
+
* `new Fabricator(...)` construction — every branch forwards it
|
|
10
|
+
* (extending `path`, never `algorithm`/`self`) into its own nested
|
|
11
|
+
* `make(...)` calls, so it reaches however deeply a leaf sits nested
|
|
12
|
+
* through `array`/`object`/`tuple`/etc.
|
|
13
|
+
*
|
|
14
|
+
* `toTrace` records this node's {@link Trace} — a plain object literal,
|
|
15
|
+
* no hashing. Hashing is paid only where a kind actually calls
|
|
16
|
+
* `toStreamFromTrace(algorithm, trace)`. Bound once in `construct()` to
|
|
17
|
+
* this one construction's already-resolved `RandomSource`/
|
|
18
|
+
* `ConstructionTrace` pair (see `Constructor.ts`'s `resolveScope`) —
|
|
19
|
+
* every leaf calls `toTrace` with only its own structural `path` and
|
|
20
|
+
* kind, never re-resolving the construction's root itself.
|
|
21
|
+
* `T.recursive` is the one kind that rebinds `toTrace`: each lazy
|
|
22
|
+
* expansion opens its own scope on the node's own private forked
|
|
23
|
+
* `RandomSource` (see `recursive/Fabricator.ts`), so a data-dependent
|
|
24
|
+
* expansion count can never perturb, or be perturbed by, anything else
|
|
25
|
+
* built from the same `initialize()` instance —
|
|
26
|
+
* `RandomSource.fork` (`Random/Types.ts`) is the isolation primitive.
|
|
27
|
+
*
|
|
28
|
+
* `algorithm` rather than the `RandomSource` itself: stream derivation
|
|
29
|
+
* depends on no per-source state, and a leaf has no business with
|
|
30
|
+
* `toRoot`/`fork`. `clock` is not a field of its own — it is always
|
|
31
|
+
* `trace.clock`.
|
|
32
|
+
*
|
|
33
|
+
* `self` is what makes `case "recursive.self"` resolve to "recurse one
|
|
34
|
+
* level deeper, right now" — absent outside any active recursion, which
|
|
35
|
+
* is how `case "recursive.self"` detects and rejects a `self` node used
|
|
36
|
+
* where none applies.
|
|
37
|
+
*/
|
|
38
|
+
export type ConstructionContext = {
|
|
39
|
+
toTrace: (path: ReadonlyArray<string>, kind: string) => Trace;
|
|
40
|
+
algorithm: Algorithm;
|
|
41
|
+
self?: (() => unknown) | undefined;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* What every kind's `Fabricator(...)` receives in place of a repeated
|
|
45
|
+
* `(schema, algorithm, trace)` positional list — `Constructor.ts`'s
|
|
46
|
+
* `make` builds one per dispatched node from its own
|
|
47
|
+
* `ConstructionContext`. `trace` is already path-bound and built
|
|
48
|
+
* eagerly, so a kind that never draws still records one without calling
|
|
49
|
+
* `toStreamFromTrace`. Laziness is load-bearing: `toTrace` is a plain
|
|
50
|
+
* object literal, and hashing is paid only where a kind actually calls
|
|
51
|
+
* `toStreamFromTrace(algorithm, trace)`. The guard is the call site's
|
|
52
|
+
* own `if (meta.produce)` branch (or the equivalent drawing path), not
|
|
53
|
+
* an unevaluated closure. `algorithm` rather than the `RandomSource`:
|
|
54
|
+
* derivation depends on no per-source state, and a leaf has no business
|
|
55
|
+
* with `toRoot`/`fork`. No `clock`: it is `trace.clock`, always. A
|
|
56
|
+
* kind-specific extra — an array's `element`, an object's `fields`, a
|
|
57
|
+
* choice's `weightings` — still follows as its own trailing parameter:
|
|
58
|
+
* those vary per kind and were never part of the shared prefix this
|
|
59
|
+
* replaces.
|
|
60
|
+
*/
|
|
61
|
+
export type FabricatorContext<$Schema> = {
|
|
62
|
+
schema: $Schema;
|
|
63
|
+
algorithm: Algorithm;
|
|
64
|
+
trace: Trace;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The most basic interface for a typed Fabricator.
|
|
68
|
+
* No type introspection is possible.
|
|
69
|
+
*/
|
|
70
|
+
export type NaiveFabricator<$T> = {
|
|
71
|
+
fabricate: () => $T;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* What every kind's `construct()` produces: a `NaiveFabricator` that
|
|
75
|
+
* also hands back the Schema it was built from, via the same
|
|
76
|
+
* `[Kind]`/`[Meta]` a Schema itself carries — so a built Fabricator
|
|
77
|
+
* can be passed back into `object`/`array`/a registry `.extend()`
|
|
78
|
+
* anywhere a Schema is expected (see `toSchema`).
|
|
79
|
+
*/
|
|
80
|
+
export type Fabricator<$T> = NaiveFabricator<$T> & {
|
|
81
|
+
[Kind]: SchemaKind;
|
|
82
|
+
[Meta]: PlainObject;
|
|
83
|
+
readonly trace: Trace;
|
|
84
|
+
/**
|
|
85
|
+
* 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
|
+
* built Fabricator to see what the Schema declared (see
|
|
88
|
+
* `Adapter/Types.ts`).
|
|
89
|
+
*/
|
|
90
|
+
readonly [Adaptation]?: Adaptations;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The value type a built Fabricator produces — read directly off its
|
|
94
|
+
* `fabricate` signature. Every kind's `construct()` output shares the
|
|
95
|
+
* exact same shape (`NaiveFabricator<$T>` plus `[Kind]`/`[Meta]`, see
|
|
96
|
+
* this file's `Fabricator<$T>`), so there's nothing to dispatch per
|
|
97
|
+
* kind here — unlike `ValueOf`, which reads a Schema's phantom
|
|
98
|
+
* `[Produces]` marker for the pre-`construct()` case, this only ever
|
|
99
|
+
* needs to unwrap an already-uniform `fabricate: () => $T`.
|
|
100
|
+
*/
|
|
101
|
+
export type Fabrication<$Fabricator extends NaiveFabricator<any>> = $Fabricator extends NaiveFabricator<infer $T> ? $T : never;
|
|
102
|
+
/**
|
|
103
|
+
* Maps a Schema (or an already-built Fabricator of the same kind — see
|
|
104
|
+
* the `object` branch, and every other branch below since each kind's
|
|
105
|
+
* `Schema` also carries a required `as` method a built Fabricator never
|
|
106
|
+
* has) to the precise, kind-specific `Fabricator<...>` type it builds
|
|
107
|
+
* into. Mirrors `Adapter/TypeBox/index.ts`'s `ToTypeBox` dispatch.
|
|
108
|
+
* Falls back to the loose base `Fabricator<ValueOf<$Schema>>` for
|
|
109
|
+
* anything unmatched.
|
|
110
|
+
*
|
|
111
|
+
* No branch here needs to do anything about `[Adaptation]`: each
|
|
112
|
+
* kind's own `Fabricator<$Schema>` reads it back off `$Schema` via
|
|
113
|
+
* `AdaptationsOf`, so an adapted Schema's Fabricator carries the map
|
|
114
|
+
* without this dispatch (or an intersection on top of it, which the
|
|
115
|
+
* warning below would otherwise apply to) having to mention it.
|
|
116
|
+
* `object.compute` is the one exception, taking its `$Adaptations`
|
|
117
|
+
* explicitly because its Fabricator is parameterized by the computed
|
|
118
|
+
* value and source rather than by the Schema.
|
|
119
|
+
*
|
|
120
|
+
* Every branch's own `Fabricator<$Schema>` type already carries a
|
|
121
|
+
* `.schema` field (see each kind's `Core.ts`) — *not* added here via an
|
|
122
|
+
* extra `& { schema: ... }` intersection: wrapping an already-named
|
|
123
|
+
* type in a fresh intersection defeats a later `infer` over it (e.g.
|
|
124
|
+
* each kind's own `Fabrication<$Fabricator>` helper, which narrows via
|
|
125
|
+
* `extends Fabricator<infer $Schema>`) — TypeScript can't always
|
|
126
|
+
* decompose the intersection back to recover `$Schema`, and silently
|
|
127
|
+
* widens to the generic's constraint instead.
|
|
128
|
+
*/
|
|
129
|
+
export type AsFabricator<$Schema> =
|
|
130
|
+
/**
|
|
131
|
+
* `<any>`, not bare `Primitive.object.Schema | Primitive.object.Fabricator`:
|
|
132
|
+
* `Primitive.object.Schema` is an interface whose `refine` method uses
|
|
133
|
+
* `$Definition` contravariantly (nested inside `Refiner`/`Computer`),
|
|
134
|
+
* so `Primitive.object.Schema<{ narrow definition }>` doesn't actually extend
|
|
135
|
+
* the *default*-parameterized bare `Primitive.object.Schema`
|
|
136
|
+
* (`Definition<AnySchema>`) — comparing against `<any>` sidesteps
|
|
137
|
+
* that variance check entirely, the same way `ToTypeBox`'s object
|
|
138
|
+
* branch sidesteps it by never referencing `refine`/`extend` at all
|
|
139
|
+
* (see its structural `[Meta].definition` check).
|
|
140
|
+
*/
|
|
141
|
+
$Schema extends Primitive.object.Core ? Primitive.object.Fabricator<$Schema> : $Schema extends Primitive.object.compute.Core<infer $Fabricated, infer $Source> ? Primitive.object.compute.Fabricator<$Fabricated, $Source, AdaptationsOf<$Schema>> : $Schema extends Primitive.object.omittable.Core ? Primitive.object.omittable.Fabricator<$Schema> : $Schema extends Primitive.object.optional.Core ? Primitive.object.optional.Fabricator<$Schema> : $Schema extends Primitive.array.Core ? Primitive.array.Fabricator<$Schema> : $Schema extends Primitive.opaque.Core ? Primitive.opaque.Fabricator<$Schema> : $Schema extends Primitive.record.Core ? Primitive.record.Fabricator<$Schema> : $Schema extends Primitive.recursive.Core ? Primitive.recursive.Fabricator<$Schema> :
|
|
142
|
+
/**
|
|
143
|
+
* `self` is never independently built in ordinary use — it only ever
|
|
144
|
+
* appears nested inside a `T.recursive` body, resolved by
|
|
145
|
+
* `Constructor.ts`'s `make` context, not through this boundary. `[]`
|
|
146
|
+
* (unbound) is the same default `self.Core` itself falls back to.
|
|
147
|
+
*/
|
|
148
|
+
$Schema extends Primitive.recursive.self.Core ? Primitive.recursive.self.Fabricator<[]> : $Schema extends Primitive.tuple.Core ? Primitive.tuple.Fabricator<$Schema> : $Schema extends Primitive.always.Core ? Primitive.always.Fabricator<$Schema> : $Schema extends Primitive.bigint.Core ? Primitive.bigint.Fabricator<$Schema> : $Schema extends Primitive.boolean.Core ? Primitive.boolean.Fabricator<$Schema> : $Schema extends Primitive.choice.Core ? Primitive.choice.Fabricator<$Schema> : $Schema extends Primitive.enum.Core ? Primitive.enum.Fabricator<$Schema> : $Schema extends Primitive.date.Core ? Primitive.date.Fabricator<$Schema> : $Schema extends Primitive.number.Core ? Primitive.number.Fabricator<$Schema> : $Schema extends Primitive.string.Core ? Primitive.string.Fabricator<$Schema> : $Schema extends Primitive.symbol.Core ? Primitive.symbol.Fabricator<$Schema> : $Schema extends Primitive.undefined.Core ? Primitive.undefined.Fabricator<$Schema> : $Schema extends Primitive.undefinable.Core ? Primitive.undefinable.Fabricator<$Schema> : $Schema extends Primitive.null.Core ? Primitive.null.Fabricator<$Schema> : $Schema extends Primitive.nullable.Core ? Primitive.nullable.Fabricator<$Schema> : $Schema extends Primitive.nullish.Core ? Primitive.nullish.Fabricator<$Schema> : $Schema extends {
|
|
149
|
+
readonly [Produces]?: unknown;
|
|
150
|
+
} ? Fabricator<ValueOf<$Schema>> : Fabricator<unknown>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { RandomSource } from "../Random/Types";
|
|
2
|
+
import type { PlainObject } from "../Utility/Types";
|
|
3
|
+
import type { Config, Instance, Overlay, Stack } from "./Types";
|
|
4
|
+
/**
|
|
5
|
+
* `combinatorial`'s default limit — `2**10`, so it admits ten
|
|
6
|
+
* independent binary axes before requiring the caller to raise it
|
|
7
|
+
* explicitly. Each enumerated instance costs a full build and
|
|
8
|
+
* fabricate, so this is as much a wall-clock guard as a combinatorial
|
|
9
|
+
* one.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_COMBINATORIAL_LIMIT = 1024;
|
|
12
|
+
/**
|
|
13
|
+
* The single place a `Config` inherits from a base — `initialize` lays
|
|
14
|
+
* its own config over an empty `{}` base (nothing to inherit, so every
|
|
15
|
+
* field falls through to a hardcoded default: an empty seed, wall-clock
|
|
16
|
+
* `clock`, the built-in algorithm, `resolveAttribution(undefined)`'s
|
|
17
|
+
* `"call site"` resolution, the default registry, the default
|
|
18
|
+
* combinatorial limit), and `fork` lays its overlay over the instance
|
|
19
|
+
* it was called on (a full, already-resolved `Config`, so every field
|
|
20
|
+
* has a real value to fall back to). `base` is typed
|
|
21
|
+
* `Partial<Config<PlainObject>>` rather than `Config` specifically so
|
|
22
|
+
* both calls go through the same function.
|
|
23
|
+
*
|
|
24
|
+
* `seed` composes onto the base rather than replacing it only when
|
|
25
|
+
* tagged with `layer(...)` (`{@link isLayered}`) — a bare `seed` (the
|
|
26
|
+
* ordinary meaning everywhere else in this library) replaces the
|
|
27
|
+
* base's outright, and an omitted `seed` inherits the base's unchanged
|
|
28
|
+
* (or, at the root, an empty mixer via `normalizeSeed(undefined)`,
|
|
29
|
+
* unless an env var supplies one). Wall-clock `clock` is the default
|
|
30
|
+
* entropy; `seed` is an optional mixer.
|
|
31
|
+
*
|
|
32
|
+
* `attribution` resolves through `resolveAttribution` at most once per
|
|
33
|
+
* call, and only when it's actually needed:
|
|
34
|
+
* - an explicit `over.attribution` always wins (resolved fresh, so
|
|
35
|
+
* `fork({ attribution: { kind: "call site" } })` roots at *that*
|
|
36
|
+
* call);
|
|
37
|
+
* - otherwise an already-resolved `base.attribution` is reused as-is
|
|
38
|
+
* — never re-resolved, which keeps a fork from silently re-rooting
|
|
39
|
+
* `"call site"` at wherever `fork()` itself happens to be called
|
|
40
|
+
* (`resolveCallerFile()` skips this library's own frames, so calling
|
|
41
|
+
* it from here still lands on the user's call site either way);
|
|
42
|
+
* - only when neither is available (the root case, `base.attribution`
|
|
43
|
+
* absent) does this fall back to resolving the `"call site"`
|
|
44
|
+
* default.
|
|
45
|
+
* That also keeps `initialize({ attribution: { kind: "none" } })` — or
|
|
46
|
+
* any other explicit override — from paying for a stack walk whose
|
|
47
|
+
* result would be immediately discarded.
|
|
48
|
+
*
|
|
49
|
+
* `algorithm`/`types`: wholesale replacement when given, matching how
|
|
50
|
+
* `initialize({ types })` already behaves — no deep merge;
|
|
51
|
+
* `registry.extend(...)` is the existing tool for that. `limits` is
|
|
52
|
+
* re-validated through `resolveCombinatorialLimit` whenever given (or
|
|
53
|
+
* inherited, or defaulted), so a bad limit fails at
|
|
54
|
+
* `fork()`/`initialize()` time rather than at first use. `clock`
|
|
55
|
+
* follows the given → inherited → default shape `algorithm` does, but
|
|
56
|
+
* stays *unresolved* only for the explicit `"seeded"` sentinel: an
|
|
57
|
+
* explicit `Date` and the unconfigured wall-clock default are stored
|
|
58
|
+
* as epoch milliseconds (a stated instant, inherited as-is from then
|
|
59
|
+
* on), while `"seeded"` is left as the sentinel rather than collapsed
|
|
60
|
+
* to a number, so `resolveClock` can re-derive it from whichever
|
|
61
|
+
* `seed` is actually in effect at read time. An omitted `clock` on a
|
|
62
|
+
* `fork`/`wrap` whose seed changed therefore keeps the parent's
|
|
63
|
+
* instant unless that parent was itself `"seeded"`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function overlay<$Registry extends PlainObject>(base: Partial<Config<PlainObject>>, over: Overlay<$Registry>): Config<$Registry>;
|
|
66
|
+
/**
|
|
67
|
+
* Builds a `Stack`: closes over a private `Frame[]`, pushing on `enter`
|
|
68
|
+
* and popping in a `finally` — correct even around a `throw` from
|
|
69
|
+
* `block`. One per root `initialize()`, threaded — never re-created —
|
|
70
|
+
* through every `fork`/`wrap` descended from it, so it stays
|
|
71
|
+
* per-lineage rather than module-level: two unrelated `initialize()`
|
|
72
|
+
* calls each get their own stack and can never perturb each other,
|
|
73
|
+
* while every instance sharing one stack (a fork included, no matter
|
|
74
|
+
* where in the lineage it was created) resolves against the same
|
|
75
|
+
* active frame.
|
|
76
|
+
*/
|
|
77
|
+
export declare function toStack(): Stack;
|
|
78
|
+
/**
|
|
79
|
+
* The shared body `initialize` and `fork` both reduce to: build a
|
|
80
|
+
* `RandomSource` from an already-resolved `Config`, then everything an
|
|
81
|
+
* `Instance` exposes off of it. Returns the `RandomSource` alongside
|
|
82
|
+
* the `Instance` — `initialize`/`fork` discard it, `wrap` keeps it to
|
|
83
|
+
* stash on the `Frame` it pushes, so implicit (ambient) and explicit
|
|
84
|
+
* (`scope.Fabricator`) construction inside one `wrap` resolve against
|
|
85
|
+
* the very same source rather than each independently re-deriving one
|
|
86
|
+
* from the same config (and so silently diverging/duplicating
|
|
87
|
+
* construction ordinals).
|
|
88
|
+
*
|
|
89
|
+
* `stack` is threaded straight through to `Constructor`/`enumerables`
|
|
90
|
+
* — this function never reads or writes it itself, only passes it
|
|
91
|
+
* along so every built `Fabricator`/`combinatorial`/`coverage` can
|
|
92
|
+
* consult whichever frame is active *at the moment each is called*,
|
|
93
|
+
* not at this moment.
|
|
94
|
+
*/
|
|
95
|
+
export declare function instantiate<$Registry extends PlainObject>(config: Config<$Registry>, stack: Stack): {
|
|
96
|
+
instance: Instance<$Registry>;
|
|
97
|
+
source: RandomSource;
|
|
98
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Enumerable, Limits } from "../Enumeration/Types";
|
|
2
|
+
import type { Constructor } from "../Fabricator/Constructor";
|
|
3
|
+
import type { Algorithm, Attribution, Layered, RandomSource, Seed } from "../Random/Types";
|
|
4
|
+
import type { PlainObject } from "../Utility/Types";
|
|
5
|
+
/**
|
|
6
|
+
* A fully resolved instance configuration — every field present, nothing
|
|
7
|
+
* left to default. `Overlay` is what `fork` accepts; `overlay()`
|
|
8
|
+
* (`Instance/Core.ts`) is the only thing producing a complete `Config`.
|
|
9
|
+
*
|
|
10
|
+
* Two fields are declared at their caller-facing type but always hold
|
|
11
|
+
* their resolved form once `overlay()` has run: `seed` is `Seed` because
|
|
12
|
+
* that is what a caller may supply, but always holds the normalized
|
|
13
|
+
* array (`Instance.seed` is the authoritative read); `attribution` is
|
|
14
|
+
* `Attribution` for the same reason but always holds a
|
|
15
|
+
* `ResolvedAttribution`, a subtype. `clock` is different from both:
|
|
16
|
+
* unlike `seed`/`attribution`, it holds *either* a resolved instant
|
|
17
|
+
* (epoch milliseconds) or the unresolved `"seeded"` policy — never
|
|
18
|
+
* collapsed to a number by `overlay()` when `"seeded"`, because that
|
|
19
|
+
* policy must re-derive whenever the seed it composes changes (a
|
|
20
|
+
* `fork({ seed: layer(...) })`). The unconfigured default is a wall-
|
|
21
|
+
* clock number, inherited as-is like an explicit `Date`. `resolveClock`
|
|
22
|
+
* (`Instance/Core.ts`) is the one place that resolves `"seeded"` to a
|
|
23
|
+
* number, called fresh wherever the clock actually matters
|
|
24
|
+
* (`instantiate`, the `context.clock` getter) rather than once here.
|
|
25
|
+
*/
|
|
26
|
+
export type Config<$Registry extends PlainObject> = {
|
|
27
|
+
readonly seed: Seed;
|
|
28
|
+
readonly algorithm: Algorithm;
|
|
29
|
+
readonly attribution: Attribution;
|
|
30
|
+
readonly types: $Registry;
|
|
31
|
+
readonly limits: Limits;
|
|
32
|
+
readonly clock: number | "seeded";
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* What `fork` accepts — a `Config` to lay over a base, every field
|
|
36
|
+
* optional. Identical to `Partial<Config>` but for `seed`, which
|
|
37
|
+
* additionally accepts a {@link Layered}: a bare `Seed` replaces the
|
|
38
|
+
* base's seed outright (what `seed` means everywhere else in this
|
|
39
|
+
* library), `layer(seed)` appends onto it (`[...base.seed, ...seed]`)
|
|
40
|
+
* — the shape a wrapping integration wants, and what
|
|
41
|
+
* `ConstructorOptions`' layered form is for a single construction.
|
|
42
|
+
* Omitting `seed` inherits the base's unchanged. `clock` similarly
|
|
43
|
+
* accepts the caller-facing `Date | "seeded"` rather than `Config`'s
|
|
44
|
+
* own resolved `number | "seeded"`, so a caller can hand in a literal
|
|
45
|
+
* instant without converting it to epoch milliseconds themselves.
|
|
46
|
+
* `"seeded"` is the explicit opt-in that derives "now" from the
|
|
47
|
+
* instance seed; omitting `clock` at the root captures wall-clock time
|
|
48
|
+
* instead.
|
|
49
|
+
*
|
|
50
|
+
* `initialize`'s own parameter keeps a plain `seed?: Seed`, so passing
|
|
51
|
+
* `layer(...)` there is a compile error: there is no base to layer onto
|
|
52
|
+
* at the root.
|
|
53
|
+
*/
|
|
54
|
+
export type Overlay<$Registry extends PlainObject> = Partial<Omit<Config<$Registry>, "seed" | "clock">> & {
|
|
55
|
+
readonly seed?: Seed | Layered;
|
|
56
|
+
readonly clock?: Date | "seeded" | undefined;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* One active `wrap` — its resolved config plus the single `RandomSource`
|
|
60
|
+
* every build reached inside that `wrap` shares, whether reached
|
|
61
|
+
* implicitly (any instance in the lineage consulting the active frame)
|
|
62
|
+
* or explicitly (`scope.Fabricator`, the `Instance` passed to the
|
|
63
|
+
* block). Storing the scope's own already-built `source` here, rather
|
|
64
|
+
* than each consumer re-deriving one from `config`, keeps the two
|
|
65
|
+
* routes resolving against the *same* source — sharing one set of
|
|
66
|
+
* construction-ordinal counters — instead of each silently starting
|
|
67
|
+
* its own.
|
|
68
|
+
*/
|
|
69
|
+
export type Frame = {
|
|
70
|
+
readonly config: Config<PlainObject>;
|
|
71
|
+
readonly source: RandomSource;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* The per-lineage ambient stack. Created once at a root `initialize()`
|
|
75
|
+
* and threaded — never re-created — through every `fork`/`wrap`
|
|
76
|
+
* descended from it (see `instantiate`, `Instance/Core.ts`). Two
|
|
77
|
+
* unrelated `initialize()` calls stay fully isolated; one lineage's
|
|
78
|
+
* `wrap` reaches every instance in that lineage — its `Fabricator`,
|
|
79
|
+
* `combinatorial`, and `coverage` alike — regardless of where in the
|
|
80
|
+
* lineage that instance was itself created.
|
|
81
|
+
*/
|
|
82
|
+
export type Stack = {
|
|
83
|
+
current(): Frame | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Push `frame`, run `block`, pop — in a `finally`, so a frame unwinds
|
|
86
|
+
* correctly even if `block` throws.
|
|
87
|
+
*/
|
|
88
|
+
enter<$Return>(frame: Frame, block: () => $Return): $Return;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The configuration in effect *right now* — the innermost active `wrap`
|
|
92
|
+
* frame, or this instance's own when there is none. Distinct from
|
|
93
|
+
* `ConstructionContext` (`Fabricator/Types.ts`), which is one
|
|
94
|
+
* construction's internal dispatch plumbing; this is the caller-facing
|
|
95
|
+
* "what configuration is in effect."
|
|
96
|
+
*/
|
|
97
|
+
export type Context = {
|
|
98
|
+
readonly seed: ReadonlyArray<string>;
|
|
99
|
+
readonly algorithm: Algorithm;
|
|
100
|
+
readonly attribution: Attribution;
|
|
101
|
+
readonly clock: number;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* A single initialized library instance: the registry it was given, and
|
|
105
|
+
* a `construct()` bound to its own isolated randomness — its own seed,
|
|
106
|
+
* builder, and per-file overrides/streams, held internally and never
|
|
107
|
+
* shared with any other `initialize()` call. Independently initialized
|
|
108
|
+
* instances (e.g. parallel tests) can never perturb each other.
|
|
109
|
+
*/
|
|
110
|
+
export interface Instance<$Registry extends PlainObject> extends Pick<RandomSource, "seed"> {
|
|
111
|
+
/** The registry of type definers this instance was initialized with. */
|
|
112
|
+
readonly T: $Registry;
|
|
113
|
+
/**
|
|
114
|
+
* Turn a Schema built from `T` into a live Fabricator, deriving fresh
|
|
115
|
+
* randomness from this instance's own seed for whichever leaves
|
|
116
|
+
* actually need it.
|
|
117
|
+
*/
|
|
118
|
+
Fabricator: Constructor;
|
|
119
|
+
/**
|
|
120
|
+
* Every combination of every enumerable node in `schema` — every enum
|
|
121
|
+
* member, both sides of an optional field, and so on — as a cartesian
|
|
122
|
+
* product, lazily. Throws eagerly, before producing anything, if the
|
|
123
|
+
* count exceeds `limits.combinatorial` (see `initialize`'s config).
|
|
124
|
+
*/
|
|
125
|
+
combinatorial: Enumerable;
|
|
126
|
+
/**
|
|
127
|
+
* The minimum set of instances such that every option of every
|
|
128
|
+
* enumerable node in `schema` appears at least once — count equal to
|
|
129
|
+
* the *widest* single axis, not the product, with narrower axes
|
|
130
|
+
* cycling to fill it. Unbounded: its count can never exceed the
|
|
131
|
+
* schema as written, so unlike `combinatorial` it carries no limit.
|
|
132
|
+
*/
|
|
133
|
+
coverage: Enumerable;
|
|
134
|
+
/**
|
|
135
|
+
* Derive a new instance laid over this one: anything the overlay names
|
|
136
|
+
* overrides, anything it omits inherits. A bare `seed` replaces this
|
|
137
|
+
* instance's seed; `seed: layer(...)` appends onto it. A peer of an
|
|
138
|
+
* `initialize()` return value in every respect, including its own
|
|
139
|
+
* `fork`.
|
|
140
|
+
*/
|
|
141
|
+
fork<const $ForkRegistry extends PlainObject = $Registry>(overlay?: Overlay<$ForkRegistry>): Instance<$ForkRegistry>;
|
|
142
|
+
/**
|
|
143
|
+
* `fork(overlay)`, made ambient for the synchronous extent of `block`:
|
|
144
|
+
* every `new Fabricator(...)`, `combinatorial(...)`, and
|
|
145
|
+
* `coverage(...)` reached inside — on this instance or any other in
|
|
146
|
+
* the same lineage — resolves against the fork instead, with nothing
|
|
147
|
+
* threaded through. The fork is also passed to `block`: use it
|
|
148
|
+
* explicitly where that reads better, and *necessarily* for any async
|
|
149
|
+
* work, which the ambient frame does not survive — a build reached
|
|
150
|
+
* after an `await` inside `block` sees this instance's own
|
|
151
|
+
* configuration again, not the wrap's.
|
|
152
|
+
*
|
|
153
|
+
* A nested `wrap` lays over whichever frame is currently active, not
|
|
154
|
+
* over the instance it was called on — so `overlay.seed: layer(...)`
|
|
155
|
+
* accumulates with nesting depth while a bare `seed` still replaces
|
|
156
|
+
* outright, discarding every enclosing layer.
|
|
157
|
+
*/
|
|
158
|
+
wrap<$Return, const $WrapRegistry extends PlainObject = $Registry>(overlay: Overlay<$WrapRegistry>, block: (scope: Instance<$WrapRegistry>) => $Return): $Return;
|
|
159
|
+
/**
|
|
160
|
+
* The configuration in effect right now: the innermost active `wrap`
|
|
161
|
+
* frame's, or this instance's own outside any `wrap`. A live view, not
|
|
162
|
+
* a snapshot — reflects whichever frame is active at the moment each
|
|
163
|
+
* property is read, since one `Instance` outlives any number of
|
|
164
|
+
* `wrap`s.
|
|
165
|
+
*/
|
|
166
|
+
readonly context: Context;
|
|
167
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
|
+
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../Random/Types";
|
|
4
|
+
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
5
|
+
import { Schema } from "./Schema";
|
|
6
|
+
import type { Fabricated, Meta as ThisMeta, Value } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema> ? Fabricated<$Schema[typeof Meta]["value"]> : never;
|
|
8
|
+
export type Fabricator<$Schema extends {
|
|
9
|
+
[Meta]: ThisMeta;
|
|
10
|
+
} = {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
}> = NaiveFabricator<Fabricated<$Schema[typeof Meta]["value"]>> & {
|
|
13
|
+
[Kind]: "always";
|
|
14
|
+
[Meta]: $Schema[typeof Meta];
|
|
15
|
+
readonly trace: Trace;
|
|
16
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
schema: Schema<$Schema[typeof Meta]["value"], AdaptationsOf<$Schema>>;
|
|
18
|
+
};
|
|
19
|
+
export declare function Fabricator<$Value extends Value>(context: FabricatorContext<Schema<$Value>>): Fabricator<Schema<$Value>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AdaptationEntry } from "../../Adapter/Core";
|
|
2
|
+
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
|
|
3
|
+
import type { Core, Value } from "./Types";
|
|
4
|
+
/**
|
|
5
|
+
* A fixed value, so unlike every other kind there is no `.as()` — nothing
|
|
6
|
+
* left to override about producing it. `adapt` still applies: what a value
|
|
7
|
+
* *means* to an external schema library is a separate question from what it
|
|
8
|
+
* fabricates to, and for a value TypeBox cannot pin exactly (a `symbol`, or
|
|
9
|
+
* any value's *static* type — see `Adapter/TypeBox`'s `toConst`) it is the
|
|
10
|
+
* only way to close the gap.
|
|
11
|
+
*/
|
|
12
|
+
export interface Schema<$Value extends Value = Value, $Adaptations extends Adaptations = {}> extends Core<$Value, $Adaptations> {
|
|
13
|
+
/**
|
|
14
|
+
* Override what this schema maps to in one or more external schema
|
|
15
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
16
|
+
*/
|
|
17
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Value, $Adaptations>>) => $Returnable) => Schema<$Value, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function Schema<$Value extends Value, $Adaptations extends Adaptations = {}>(schema: Core<$Value, $Adaptations>): Schema<$Value, $Adaptations>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
/**
|
|
4
|
+
* Any value at all. Deliberately unconstrained: fabricating a fixed value
|
|
5
|
+
* needs nothing of it. A `string | number | boolean` cap would be TypeBox's
|
|
6
|
+
* `TLiteralValue` leaking into the primitive. Narrowing back to what a
|
|
7
|
+
* given external schema library can express is that library's adapter's
|
|
8
|
+
* job — see `Adapter/TypeBox`'s `toConst`.
|
|
9
|
+
*
|
|
10
|
+
* Kept as a named alias: it is the public name for this kind's domain, and
|
|
11
|
+
* both `Registry.ts` and `Schema.ts` use it as a bound.
|
|
12
|
+
*/
|
|
13
|
+
export type Value = unknown;
|
|
14
|
+
export type Fabricated<$Value extends Value> = $Value;
|
|
15
|
+
export type Meta<$Value extends Value = Value> = {
|
|
16
|
+
value: $Value;
|
|
17
|
+
};
|
|
18
|
+
export type Core<$Value extends Value = Value, $Adaptations extends Adaptations = {}> = {
|
|
19
|
+
[Kind]: "always";
|
|
20
|
+
[Meta]: Meta<$Value>;
|
|
21
|
+
readonly [Produces]?: Fabricated<$Value>;
|
|
22
|
+
readonly [Adaptation]?: $Adaptations;
|
|
23
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
|
+
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../Random/Types";
|
|
4
|
+
import { Children, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
|
+
import { Schema } from "./Schema";
|
|
6
|
+
import type { Definition, Fabricated, Meta as ThisMeta } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema extends {
|
|
8
|
+
[Meta]: ThisMeta;
|
|
9
|
+
}> ? Fabricated<$Schema[typeof Meta]["definition"]> : never;
|
|
10
|
+
export type Fabricator<$Schema extends {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
} = {
|
|
13
|
+
[Meta]: ThisMeta;
|
|
14
|
+
}> = NaiveFabricator<Fabricated<$Schema[typeof Meta]["definition"]>> & {
|
|
15
|
+
[Kind]: "array";
|
|
16
|
+
[Meta]: $Schema[typeof Meta];
|
|
17
|
+
readonly trace: Trace;
|
|
18
|
+
[Children]: NaiveFabricator<any>;
|
|
19
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
20
|
+
schema: Schema<$Schema[typeof Meta]["definition"], AdaptationsOf<$Schema>>;
|
|
21
|
+
};
|
|
22
|
+
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, element: NaiveFabricator<any>): Fabricator<Schema<$Definition>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Produce } from "../../Random/Types";
|
|
2
|
+
import { Schema } from "./Schema";
|
|
3
|
+
import type { Definition, Fabricated, InputWhereby } from "./Types";
|
|
4
|
+
export default function <const $Definition extends Definition>(definition: $Definition): {
|
|
5
|
+
/**
|
|
6
|
+
* An array of `definition`, repeated `whereby.length` times — either a
|
|
7
|
+
* fixed count, or uniformly across `[length.min, length.max]` with
|
|
8
|
+
* `length.min` defaulting to inclusive 0, so an empty array is a
|
|
9
|
+
* legitimate outcome when no `min` is given. Exclusive ends use a Bound
|
|
10
|
+
* object; a bare `length: N` is stored as min = max = N inclusive.
|
|
11
|
+
*/
|
|
12
|
+
whereby: (whereby: InputWhereby) => Schema<$Definition>;
|
|
13
|
+
/**
|
|
14
|
+
* An array whose production is `produce`, in full, instead of drawn
|
|
15
|
+
* element by element.
|
|
16
|
+
*/
|
|
17
|
+
as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AdaptationEntry } from "../../Adapter/Core";
|
|
2
|
+
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
|
|
3
|
+
import type { Produce } from "../../Random/Types";
|
|
4
|
+
import type { Core, Definition, Fabricated } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* The buildable recipe for an `array`: a single element Schema, repeated
|
|
7
|
+
* `whereby.length` times.
|
|
8
|
+
*/
|
|
9
|
+
export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
|
|
10
|
+
/**
|
|
11
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
12
|
+
* `whereby`/`definition` forward, not discarding them, so a later
|
|
13
|
+
* `.as(...)` (or future validation of `produce`) still has them to check
|
|
14
|
+
* against.
|
|
15
|
+
*/
|
|
16
|
+
as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
|
|
17
|
+
/**
|
|
18
|
+
* Override what this schema maps to in one or more external schema
|
|
19
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
20
|
+
*/
|
|
21
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Definition, $Adaptations>>) => $Returnable) => Schema<$Definition, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
22
|
+
}
|
|
23
|
+
export declare function Schema<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: Core<$Definition, $Adaptations>): Schema<$Definition, $Adaptations>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Bound, InputBound } from "../../Bound";
|
|
3
|
+
import type { Produce } from "../../Random/Types";
|
|
4
|
+
import type { AnySchema, ValueOf } from "../../Schema/Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
6
|
+
export type Definition = AnySchema;
|
|
7
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Array<ValueOf<$Definition, $Bindings>>;
|
|
8
|
+
export type InputWhereby = {
|
|
9
|
+
length: number | {
|
|
10
|
+
max: InputBound<number>;
|
|
11
|
+
min?: InputBound<number> | undefined;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type Whereby = {
|
|
15
|
+
length: {
|
|
16
|
+
min: Bound<number>;
|
|
17
|
+
max: Bound<number>;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* `whereby` (a length spec — no natural bound to fuzz to, so unlike
|
|
22
|
+
* `number`/`date` there's no bare form), optionally overridden by an
|
|
23
|
+
* opaque `as` production, carried alongside `whereby` rather than replacing
|
|
24
|
+
* it (when `whereby` was already set) so a prior length spec survives `as`
|
|
25
|
+
* for future validation. `definition` stays required regardless — it's
|
|
26
|
+
* known at `T.array(...)` call time and describes the element shape TypeBox
|
|
27
|
+
* derives either way.
|
|
28
|
+
*/
|
|
29
|
+
export type Meta<$Definition extends Definition = Definition> = {
|
|
30
|
+
definition: $Definition;
|
|
31
|
+
whereby: Whereby;
|
|
32
|
+
produce?: never;
|
|
33
|
+
} | {
|
|
34
|
+
definition: $Definition;
|
|
35
|
+
whereby?: Whereby;
|
|
36
|
+
produce: Produce<Fabricated<$Definition>>;
|
|
37
|
+
};
|
|
38
|
+
export interface Core<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> {
|
|
39
|
+
[Kind]: "array";
|
|
40
|
+
[Meta]: Meta<$Definition>;
|
|
41
|
+
bindings?: unknown[];
|
|
42
|
+
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
|
|
43
|
+
readonly [Adaptation]?: $Adaptations;
|
|
44
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
|
+
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../Random/Types";
|
|
4
|
+
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
5
|
+
import { Schema } from "./Schema";
|
|
6
|
+
import type { Fabricated, Meta as ThisMeta } from "./Types";
|
|
7
|
+
export type Fabrication<_ extends Fabricator> = Fabricated;
|
|
8
|
+
export type Fabricator<$Schema extends {
|
|
9
|
+
[Meta]: ThisMeta;
|
|
10
|
+
} = {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
}> = NaiveFabricator<Fabricated> & {
|
|
13
|
+
[Kind]: "bigint";
|
|
14
|
+
[Meta]: $Schema[typeof Meta];
|
|
15
|
+
readonly trace: Trace;
|
|
16
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
schema: Schema<$Schema[typeof Meta], AdaptationsOf<$Schema>>;
|
|
18
|
+
};
|
|
19
|
+
export declare function Fabricator(context: FabricatorContext<Schema>): Fabricator;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Produce } from "../../Random/Types";
|
|
2
|
+
import { Kind } from "../../Types";
|
|
3
|
+
import { Schema } from "./Schema";
|
|
4
|
+
import type { Fabricated, InputWhereby, Whereby } from "./Types";
|
|
5
|
+
declare const _default: {
|
|
6
|
+
/**
|
|
7
|
+
* The builder carries the primitive's `[Kind]` so it can be named directly
|
|
8
|
+
* as a `compute` source — which derives its schema by kind — without
|
|
9
|
+
* first satisfying a `whereby`.
|
|
10
|
+
*/
|
|
11
|
+
[Kind]: "bigint";
|
|
12
|
+
whereby: (whereby: InputWhereby) => Schema<{
|
|
13
|
+
whereby: Whereby;
|
|
14
|
+
}, {}>;
|
|
15
|
+
as: (produce: Produce<Fabricated>) => Schema<{
|
|
16
|
+
produce: Produce<bigint>;
|
|
17
|
+
}, {}>;
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|