@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,56 @@
|
|
|
1
|
+
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
|
+
import type { Fabricator as BaseFabricator, FabricatorContext } from "../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../Random/Types";
|
|
4
|
+
import { Children, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
|
+
import type { Schema } from "./Schema";
|
|
6
|
+
import type { Definition, Fabricated, Override, Meta as ThisMeta } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema> ? Fabricated<$Schema[typeof Meta]["definition"]> : never;
|
|
8
|
+
export type Fabricator<$Schema extends {
|
|
9
|
+
[Meta]: ThisMeta;
|
|
10
|
+
} = {
|
|
11
|
+
[Meta]: ThisMeta<any>;
|
|
12
|
+
}> = {
|
|
13
|
+
[Kind]: "object";
|
|
14
|
+
[Meta]: $Schema[typeof Meta];
|
|
15
|
+
readonly trace: Trace;
|
|
16
|
+
[Children]: Fields;
|
|
17
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
18
|
+
schema: Schema<$Schema[typeof Meta]["definition"], AdaptationsOf<$Schema>>;
|
|
19
|
+
/**
|
|
20
|
+
* `overrides`, if given, skips generation for exactly the fields it names —
|
|
21
|
+
* using this Fabricator's already-derived randomness for everything else,
|
|
22
|
+
* never drawing fresh (see `Fabricator()` below). `config.validate` defaults
|
|
23
|
+
* to `true`, delegated to `schema.override(overrides)`'s existing recursive
|
|
24
|
+
* checks (result unused); `{ validate: false }` skips that — used internally
|
|
25
|
+
* when recursing into an already-validated nested override, also available
|
|
26
|
+
* to a caller who already knows their overrides are valid.
|
|
27
|
+
*/
|
|
28
|
+
fabricate: (overrides?: Override<$Schema[typeof Meta]["definition"]>, config?: {
|
|
29
|
+
validate?: boolean;
|
|
30
|
+
}) => Fabricated<$Schema[typeof Meta]["definition"]>;
|
|
31
|
+
};
|
|
32
|
+
export declare function isObjectFabricator(candidate: BaseFabricator<unknown>): candidate is Fabricator;
|
|
33
|
+
export type Fields = Record<string, BaseFabricator<unknown>>;
|
|
34
|
+
/**
|
|
35
|
+
* Turn an `object` Schema into a live Fabricator, given every field already
|
|
36
|
+
* built by `Constructor.ts` — which owns recursion into nested Schemas, so
|
|
37
|
+
* `object` never calls `construct()` and there's no import cycle with
|
|
38
|
+
* `Constructor.ts`. Schema-baked `.override()`-marked fields (`[Fixed]` in
|
|
39
|
+
* `Types.ts`) are already resolved into literal-valued `fields` entries
|
|
40
|
+
* before they reach here. `fabricate`'s `overrides` (below) is a separate
|
|
41
|
+
* per-call mechanism; the two compose.
|
|
42
|
+
*
|
|
43
|
+
* `schema` is echoed as `.schema` unchanged — callers wanting a
|
|
44
|
+
* `toSchema`-normalized Fabricator (no `extend`/`refine`/`override`) pass
|
|
45
|
+
* that; `Constructor.ts`'s `make` passes `object.rehydrate(...)` so a
|
|
46
|
+
* top-level built Fabricator's `.schema` still composes.
|
|
47
|
+
*
|
|
48
|
+
* A compute-kind field (from `.refine()`) needs the rest of the object
|
|
49
|
+
* already fabricated (`object/compute/Fabricator.ts`), which isn't available
|
|
50
|
+
* until every ordinary field has resolved. Two phases: ordinary fields
|
|
51
|
+
* first, then compute fields against the accumulated result, in definition
|
|
52
|
+
* order (a compute field can see an earlier compute field's value, not a
|
|
53
|
+
* later one) — unless covered by `overrides`, in which case it resolves in
|
|
54
|
+
* phase 1 like any other overridden field.
|
|
55
|
+
*/
|
|
56
|
+
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, fields: Fields): Fabricator<Schema<$Definition>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import { Adaptation, Meta } from "../../Types";
|
|
3
|
+
import { Schema } from "./Schema";
|
|
4
|
+
import type { Definition, Meta as ThisMeta } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* Rebuild a full `object` Schema — with `extend`/`refine` restored — from
|
|
7
|
+
* anything already reduced to this kind's `[Meta]` (a bare Schema, or a
|
|
8
|
+
* built Fabricator normalized via `toSchema`). `toSchema` alone only keeps
|
|
9
|
+
* `[Kind]`/`[Meta]`, enough to fabricate from but not to derive a subtype —
|
|
10
|
+
* this is what lets a built Fabricator's `.schema` still compose via
|
|
11
|
+
* `extend`/`refine` (`Constructor.ts`'s `make`). Reattaches `produce` via
|
|
12
|
+
* `.as(...)` when present, so a `toSchema`-stripped, `.as(...)`-produced
|
|
13
|
+
* schema doesn't lose its custom producer — and carries `[Adaptation]` for
|
|
14
|
+
* the same reason: without it, `.override(...)` on a nested adapted
|
|
15
|
+
* `object` field (which round-trips through here) and a built Fabricator's
|
|
16
|
+
* `.schema` would both silently come back unadapted.
|
|
17
|
+
*/
|
|
18
|
+
export declare function rehydrate<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: {
|
|
19
|
+
[Meta]: ThisMeta<$Definition>;
|
|
20
|
+
readonly [Adaptation]?: $Adaptations;
|
|
21
|
+
}): Schema<$Definition, $Adaptations>;
|
|
22
|
+
export default _default;
|
|
23
|
+
declare function _default<const $Definition extends Definition>(definition: $Definition): Schema<$Definition>;
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { AnySchema } from "../../Schema/Types";
|
|
5
|
+
import type { ShallowMerge } from "../../Utility/ShallowMerge";
|
|
6
|
+
import type { Computer } from "./compute/Schema";
|
|
7
|
+
import type { Core, Definition, Extender, Fabricated, Override, Refinement } from "./Types";
|
|
8
|
+
export type Refiner<$Definition extends Definition, $Refinement extends Refinement<$Definition>> = (params: {
|
|
9
|
+
base: Schema<$Definition>;
|
|
10
|
+
compute: Computer<$Definition>;
|
|
11
|
+
}) => $Refinement;
|
|
12
|
+
export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
|
|
13
|
+
extend: <const $Extension extends Definition>(extender: Extender<$Definition, $Extension>) => Schema<ShallowMerge<$Definition, $Extension>, $Adaptations>;
|
|
14
|
+
refine: <const $Refinement extends Refinement<$Definition>>(refiner: Refiner<$Definition, $Refinement>) => Schema<ShallowMerge<$Definition, $Refinement>, $Adaptations>;
|
|
15
|
+
override: (override: Override<$Definition>) => Schema<$Definition, $Adaptations>;
|
|
16
|
+
/**
|
|
17
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
18
|
+
* `definition`/`refinements` forward, not discarding them, so
|
|
19
|
+
* `extend`/`refine`/`override` keep working (they drop the custom producer
|
|
20
|
+
* again, falling back to definition-based fabrication) and a later
|
|
21
|
+
* `.as(...)` (or future validation of `produce`) still has the definition
|
|
22
|
+
* to check against.
|
|
23
|
+
*/
|
|
24
|
+
as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
|
|
25
|
+
/**
|
|
26
|
+
* Override what this schema maps to in one or more external schema
|
|
27
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
28
|
+
* Carried through `extend`/`refine`/`override`, which all reduce to a
|
|
29
|
+
* fresh `make(...)` (`Registry.ts`) over this same schema.
|
|
30
|
+
*/
|
|
31
|
+
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>>>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Unlike every other kind, `adapt` is *not* added here but by `Registry.ts`'s
|
|
35
|
+
* `make` alongside `extend`/`refine`/`override`: those three rebuild from
|
|
36
|
+
* `definition`/`refinements` rather than deriving from this object, so the
|
|
37
|
+
* adaptation map has to be threaded through `make` itself or chaining one
|
|
38
|
+
* of them would drop it (see `make`'s `adapt`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function Schema<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: Omit<Schema<$Definition, $Adaptations>, "as">): Schema<$Definition, $Adaptations>;
|
|
41
|
+
export declare function isObjectSchema(candidate: AnySchema): candidate is Schema;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Produce } from "../../Random/Types";
|
|
3
|
+
import type { AnySchema, ValueOf } from "../../Schema/Types";
|
|
4
|
+
import { Kind, Meta, type Adaptation, type Omitted, type Produces } from "../../Types";
|
|
5
|
+
import { type Pretty } from "../../Utility/Types";
|
|
6
|
+
import type { Schema as ComputeSchema } from "./compute/Schema";
|
|
7
|
+
export type Definition<$Schema = AnySchema> = {
|
|
8
|
+
[_ in string]: $Schema;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Constraint for a refinement's values. The source schema differs per
|
|
12
|
+
* property, so it must be `any` (not `AnySchema`) to stay assignable across
|
|
13
|
+
* every property's own `$Source`. Constraint only: precise types still flow
|
|
14
|
+
* via `$Refinement`.
|
|
15
|
+
*/
|
|
16
|
+
export type Refinement<$Definition extends Definition> = Definition<ComputeSchema<Fabricated<$Definition>, any>>;
|
|
17
|
+
export type Extender<$Definition extends Definition, $Extension extends Definition> = (params: {
|
|
18
|
+
base: $Definition;
|
|
19
|
+
}) => $Extension;
|
|
20
|
+
export type Refinements = ReadonlyArray<Definition>;
|
|
21
|
+
/**
|
|
22
|
+
* Every `object.omittable`- or `object.optional`-kind field's key, so
|
|
23
|
+
* `Fabricated` can mark exactly those `?:` instead of required — matching
|
|
24
|
+
* runtime, where a field whose roll lands on omission never has its key
|
|
25
|
+
* appear (`object/omittable/Fabricator.ts`, `object/optional/Fabricator.ts`).
|
|
26
|
+
* `object.optional`'s `ValueOf` already carries `| undefined` (its
|
|
27
|
+
* `Fabricated`), so combined with the `?:` here a field lands on
|
|
28
|
+
* `{ a?: T | undefined }` — omitted, present-as-`undefined`, or
|
|
29
|
+
* present-with-a-value.
|
|
30
|
+
*/
|
|
31
|
+
type OmittableKeys<$Definition extends Definition> = {
|
|
32
|
+
[$K in keyof $Definition]: $Definition[$K] extends {
|
|
33
|
+
[Kind]: "object.omittable" | "object.optional";
|
|
34
|
+
} ? $K : never;
|
|
35
|
+
}[keyof $Definition];
|
|
36
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Pretty<{
|
|
37
|
+
[$K in Exclude<keyof $Definition, OmittableKeys<$Definition>>]: ValueOf<$Definition[$K], $Bindings>;
|
|
38
|
+
} & {
|
|
39
|
+
[$K in OmittableKeys<$Definition>]?: ValueOf<$Definition[$K], $Bindings>;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* The shape `.override()` accepts: every field optional, so a present key
|
|
43
|
+
* skips generation for that field. A nested `object`-kind field recurses
|
|
44
|
+
* into its own `Override` (deep-merge); an `object.omittable` or
|
|
45
|
+
* `object.optional` field additionally accepts `Omitted`, to force that
|
|
46
|
+
* field off rather than only forcing a value on (`object.optional` already
|
|
47
|
+
* accepts `undefined` via `ValueOf`); every other field — including
|
|
48
|
+
* `object.compute` — is a full-replacement leaf, typed as whatever it
|
|
49
|
+
* fabricates to (`ValueOf`).
|
|
50
|
+
*
|
|
51
|
+
* Checked via a bare structural `[Kind]`/`[Meta]` shape, never `Schema`/
|
|
52
|
+
* `Fabricator` — either carries `refine`'s contravariant use of
|
|
53
|
+
* `$Definition`, and referencing it here would leak that contravariance
|
|
54
|
+
* into every recursive `Override` instantiation.
|
|
55
|
+
*/
|
|
56
|
+
export type Override<$Definition extends Definition> = Pretty<{
|
|
57
|
+
[$K in keyof $Definition]?: $Definition[$K] extends {
|
|
58
|
+
[Kind]: "object";
|
|
59
|
+
[Meta]: {
|
|
60
|
+
definition: infer $Nested extends Definition;
|
|
61
|
+
};
|
|
62
|
+
} ? Override<$Nested> : $Definition[$K] extends {
|
|
63
|
+
[Kind]: "object.omittable" | "object.optional";
|
|
64
|
+
} ? ValueOf<$Definition[$K]> | typeof Omitted : ValueOf<$Definition[$K]>;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* `definition`/`refinements` stay required regardless of `produce` — an
|
|
68
|
+
* opaque `as` production layers on top rather than replacing them, so
|
|
69
|
+
* `extend`/`refine`/`override` and `ToTypeBox`'s structural derivation keep
|
|
70
|
+
* working, and a prior definition survives `as` for future validation of
|
|
71
|
+
* `produce`.
|
|
72
|
+
*/
|
|
73
|
+
export type Meta<$Definition extends Definition = Definition> = {
|
|
74
|
+
definition: $Definition;
|
|
75
|
+
refinements: Refinements;
|
|
76
|
+
produce?: Produce<Fabricated<$Definition>>;
|
|
77
|
+
};
|
|
78
|
+
export interface Core<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> {
|
|
79
|
+
[Kind]: "object";
|
|
80
|
+
[Meta]: Meta<$Definition>;
|
|
81
|
+
bindings?: unknown[];
|
|
82
|
+
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
|
|
83
|
+
readonly [Adaptation]?: $Adaptations;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Adaptations } from "../../../Adapter/Types";
|
|
2
|
+
import type { Fabricator as BaseFabricator, FabricatorContext } from "../../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../../Random/Types";
|
|
4
|
+
import { Kind, Meta, type Adaptation } from "../../../Types";
|
|
5
|
+
import type { Schema } from "./Schema";
|
|
6
|
+
import type { Resolved, Source } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator<any, Source>> = $Fabricator extends Fabricator<any, infer $Source> ? Resolved<$Source> : never;
|
|
8
|
+
export type Fabricator<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}> = {
|
|
9
|
+
[Kind]: "object.compute";
|
|
10
|
+
[Meta]: {
|
|
11
|
+
source: $Source;
|
|
12
|
+
resolve: (params: {
|
|
13
|
+
fabricated: $Fabricated;
|
|
14
|
+
}) => Resolved<$Source>;
|
|
15
|
+
};
|
|
16
|
+
readonly trace: Trace;
|
|
17
|
+
readonly [Adaptation]?: $Adaptations;
|
|
18
|
+
fabricate: (params?: {
|
|
19
|
+
fabricated: $Fabricated;
|
|
20
|
+
}) => Resolved<$Source>;
|
|
21
|
+
};
|
|
22
|
+
export declare function isObjectComputeFabricator(candidate: BaseFabricator<unknown>): candidate is Fabricator<unknown, Source>;
|
|
23
|
+
/**
|
|
24
|
+
* Turn an `object.compute` Schema into a live Fabricator. Unlike every other
|
|
25
|
+
* kind, there's nothing of `source` to build here — a computed field's
|
|
26
|
+
* value comes entirely from `resolve`, given the rest of the object. The
|
|
27
|
+
* node still records `trace` so it can be rebuilt from a parent field's
|
|
28
|
+
* captured trace; `.fabricate()` without the parent object throws
|
|
29
|
+
* `DetachedComputeError`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function Fabricator<$Fabricated, $Source extends Source>(context: FabricatorContext<Schema<$Fabricated, $Source>>): Fabricator<$Fabricated, $Source>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type AdaptationEntry } from "../../../Adapter/Core";
|
|
2
|
+
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
|
|
3
|
+
import type { AnySchema } from "../../../Schema/Types";
|
|
4
|
+
import type * as object from "../Types";
|
|
5
|
+
import type { Core, Resolved, Source } from "./Types";
|
|
6
|
+
export type Computer<$Definition extends object.Definition> = <const $Source extends Source>(source: $Source) => {
|
|
7
|
+
as: (resolve: (params: {
|
|
8
|
+
fabricated: object.Fabricated<$Definition>;
|
|
9
|
+
}) => NoInfer<Resolved<$Source>>) => Schema<object.Fabricated<$Definition>, $Source>;
|
|
10
|
+
};
|
|
11
|
+
export interface Schema<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}> extends Core<$Fabricated, $Source, $Adaptations> {
|
|
12
|
+
/**
|
|
13
|
+
* Override what this schema maps to in one or more external schema
|
|
14
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
15
|
+
* Adapting the computed field itself, rather than the `source` it derives
|
|
16
|
+
* its shape from, is the way to say the two differ.
|
|
17
|
+
*/
|
|
18
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Fabricated, $Source, $Adaptations>>) => $Returnable) => Schema<$Fabricated, $Source, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
19
|
+
}
|
|
20
|
+
export declare function Schema<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}>(schema: Core<$Fabricated, $Source, $Adaptations>): Schema<$Fabricated, $Source, $Adaptations>;
|
|
21
|
+
export declare function isObjectComputeSchema(candidate: AnySchema): candidate is Schema<unknown, Source>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Adaptations } from "../../../Adapter/Types";
|
|
2
|
+
import type { AnySchema, ValueOf } from "../../../Schema/Types";
|
|
3
|
+
import { Kind, type Adaptation, type Meta, type Produces } from "../../../Types";
|
|
4
|
+
/**
|
|
5
|
+
* A builder that can mint a Schema via `as` — e.g. `T.string`, `T.bigint`.
|
|
6
|
+
* `compute` accepts one alongside a plain Schema so a caller needn't
|
|
7
|
+
* satisfy a `whereby` just to name a computed field's type: the resolver
|
|
8
|
+
* supplies the value, so the field's length/range is irrelevant.
|
|
9
|
+
*/
|
|
10
|
+
export type Builder<$Schema extends AnySchema = AnySchema> = {
|
|
11
|
+
[Kind]: $Schema[typeof Kind];
|
|
12
|
+
as: (produce: () => any) => $Schema;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A `compute` source: the Schema whose value and shape a computed field
|
|
16
|
+
* adopts, or a builder that denotes one.
|
|
17
|
+
*/
|
|
18
|
+
export type Source = AnySchema | Builder;
|
|
19
|
+
/**
|
|
20
|
+
* The Schema a source denotes: a plain Schema is itself; a builder is
|
|
21
|
+
* the Schema its `as` mints.
|
|
22
|
+
*/
|
|
23
|
+
export type Denoted<$Source> = $Source extends AnySchema ? $Source : $Source extends Builder<infer $Schema> ? $Schema : never;
|
|
24
|
+
/**
|
|
25
|
+
* The value a source resolves to: what the Schema it denotes fabricates to.
|
|
26
|
+
*/
|
|
27
|
+
export type Resolved<$Source, $Bindings extends unknown[] = []> = ValueOf<Denoted<$Source>, $Bindings>;
|
|
28
|
+
/**
|
|
29
|
+
* Source and resolver are stored raw — the source whether a Schema or a
|
|
30
|
+
* builder (both carry a `[Kind]`, which is all schema derivation needs),
|
|
31
|
+
* and the resolver as plain data from the moment
|
|
32
|
+
* `compute(source).as(resolve)` is called: `compute` never builds anything,
|
|
33
|
+
* so unlike a Fabricator's closure there's nothing lossy about storing it.
|
|
34
|
+
* `source` is only used for its shape/type (`Adapter/TypeBox` reflects a
|
|
35
|
+
* computed field as its source's shape, unless the field itself is
|
|
36
|
+
* adapted) — the resolver draws entirely from `fabricated`, never from
|
|
37
|
+
* `source`, which may not even have a buildable recipe (a bare
|
|
38
|
+
* `T.string`/`T.bigint`).
|
|
39
|
+
*
|
|
40
|
+
* Unlike every other kind's `Meta`, this one is generic over the *enclosing
|
|
41
|
+
* object's* fabricated type as well as the source — that is what the
|
|
42
|
+
* resolver is handed.
|
|
43
|
+
*/
|
|
44
|
+
export type Meta<$Fabricated, $Source extends Source> = {
|
|
45
|
+
source: $Source;
|
|
46
|
+
resolve: (params: {
|
|
47
|
+
fabricated: $Fabricated;
|
|
48
|
+
}) => Resolved<$Source>;
|
|
49
|
+
};
|
|
50
|
+
export interface Core<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}> {
|
|
51
|
+
[Kind]: "object.compute";
|
|
52
|
+
[Meta]: Meta<$Fabricated, $Source>;
|
|
53
|
+
bindings?: unknown[];
|
|
54
|
+
readonly [Produces]?: Resolved<$Source, NonNullable<this["bindings"]>>;
|
|
55
|
+
readonly [Adaptation]?: $Adaptations;
|
|
56
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./Types";
|
|
2
|
+
export * from "./Schema";
|
|
3
|
+
export * from "./Fabricator";
|
|
4
|
+
export * from "./Registry";
|
|
5
|
+
export { default } from "./Registry";
|
|
6
|
+
export * as compute from "./compute";
|
|
7
|
+
export * as omittable from "./omittable";
|
|
8
|
+
export * as optional from "./optional";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AdaptationsOf } from "../../../Adapter/Types";
|
|
2
|
+
import type { Fabricator as BaseFabricator, FabricatorContext } from "../../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../../Random/Types";
|
|
4
|
+
import { Children, Kind, Meta, type Adaptation } from "../../../Types";
|
|
5
|
+
import type { Schema } from "./Schema";
|
|
6
|
+
import type { Definition, Resolved, Meta as ThisMeta } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator<any>> = $Fabricator extends Fabricator<infer $Schema> ? Resolved<$Schema[typeof Meta]["definition"]> : never;
|
|
8
|
+
export type Fabricator<$Schema extends {
|
|
9
|
+
[Meta]: ThisMeta;
|
|
10
|
+
} = {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
}> = {
|
|
13
|
+
[Kind]: "object.omittable";
|
|
14
|
+
[Meta]: $Schema[typeof Meta];
|
|
15
|
+
readonly trace: Trace;
|
|
16
|
+
[Children]: BaseFabricator<any>;
|
|
17
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
18
|
+
/**
|
|
19
|
+
* `Omitted` on the empty roll (or when an `.as(...)` producer returns it)
|
|
20
|
+
* — read only by `object/Fabricator.ts`'s fabricate loop, which omits the
|
|
21
|
+
* key entirely rather than writing `undefined`. Fabricating this outside
|
|
22
|
+
* a parent `object` hands the sentinel straight back.
|
|
23
|
+
*/
|
|
24
|
+
fabricate: () => Resolved<$Schema[typeof Meta]["definition"]>;
|
|
25
|
+
};
|
|
26
|
+
export declare function isObjectOmittableFabricator(candidate: BaseFabricator<unknown>): candidate is Fabricator;
|
|
27
|
+
/**
|
|
28
|
+
* A presence roll on this field's private stream, drawn only when present
|
|
29
|
+
* is decided — an omission roll never advances `source`'s stream, and since
|
|
30
|
+
* `source` is already dispatched into its own independent stream by
|
|
31
|
+
* `Constructor.ts` regardless of this roll, skipping its draw here can
|
|
32
|
+
* never perturb any other field's reproducibility (`Random/index.ts`'s
|
|
33
|
+
* `toStreamFromTrace`: every field's stream is private from the moment it's
|
|
34
|
+
* minted). 50/50 by default; `.weighted(...)` (`Schema.ts`) reweights
|
|
35
|
+
* either outcome relative to that same default of `1`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, source: BaseFabricator<any>): Fabricator<Schema<$Definition>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two outcomes an omittable field's presence roll can land on. Also
|
|
3
|
+
* the key space `.weighted(...)` weighs — see `Types.ts`'s `Weights`.
|
|
4
|
+
*
|
|
5
|
+
* Lives here rather than `Types.ts` so that file stays type-only (see
|
|
6
|
+
* `boolean/Outcomes.ts`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const outcomes: readonly ["omitted", "value"];
|
|
9
|
+
export type Outcome = (typeof outcomes)[number];
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { AnySchema } from "../../../Schema/Types";
|
|
5
|
+
import type { Core, Definition, Resolved, Weights } from "./Types";
|
|
6
|
+
export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
|
|
7
|
+
/**
|
|
8
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
9
|
+
* `definition` forward, not discarding it, so a later `.as(...)` (or
|
|
10
|
+
* future validation of `produce`) still has it to check against.
|
|
11
|
+
* `produce` may return `Omitted`, so custom presence logic composes the
|
|
12
|
+
* same way the built-in roll does.
|
|
13
|
+
*/
|
|
14
|
+
as: (produce: Produce<Resolved<$Definition>>) => Schema<$Definition, $Adaptations>;
|
|
15
|
+
/**
|
|
16
|
+
* Reweight the built-in presence roll. Keys are optional — an omitted key
|
|
17
|
+
* keeps baseline weight `1`, the same weight the 50/50 split already uses
|
|
18
|
+
* — but that baseline is still relative to whatever else is specified, so
|
|
19
|
+
* `.weighted({ omitted: 0.1 })` shifts both outcomes' shares, not just
|
|
20
|
+
* `omitted`'s (see `Types.ts`'s `Weights`). Chaining `.weighted(...)`
|
|
21
|
+
* merges into previous weights rather than replacing them, the same
|
|
22
|
+
* layering `.as(...)` uses for `produce`.
|
|
23
|
+
*/
|
|
24
|
+
weighted: (weights: Weights) => Schema<$Definition, $Adaptations>;
|
|
25
|
+
/**
|
|
26
|
+
* Override what this schema maps to in one or more external schema
|
|
27
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
28
|
+
*/
|
|
29
|
+
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>>>;
|
|
30
|
+
}
|
|
31
|
+
export declare function Schema<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: Core<$Definition, $Adaptations>): Schema<$Definition, $Adaptations>;
|
|
32
|
+
export declare function isObjectOmittableSchema(candidate: AnySchema): candidate is Schema;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Adaptations } from "../../../Adapter/Types";
|
|
2
|
+
import type { Produce } from "../../../Random/Types";
|
|
3
|
+
import type { AnySchema, ValueOf } from "../../../Schema/Types";
|
|
4
|
+
import { Kind, Meta, Omitted, type Adaptation, type Produces } from "../../../Types";
|
|
5
|
+
/**
|
|
6
|
+
* The wrapped field's own Schema — the value type an omittable field
|
|
7
|
+
* produces when its presence roll comes up present.
|
|
8
|
+
*/
|
|
9
|
+
export type Definition = AnySchema;
|
|
10
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = ValueOf<$Definition, $Bindings>;
|
|
11
|
+
/**
|
|
12
|
+
* What an omittable field's Fabricator returns: the wrapped value, or
|
|
13
|
+
* `Omitted` when it should not appear — whether from the built-in presence
|
|
14
|
+
* roll or, via `.as(...)`, an opaque producer.
|
|
15
|
+
*/
|
|
16
|
+
export type Resolved<$Definition extends Definition> = Fabricated<$Definition> | typeof Omitted;
|
|
17
|
+
export type { Outcome } from "./Outcomes";
|
|
18
|
+
/**
|
|
19
|
+
* Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional —
|
|
20
|
+
* an omitted key falls back to baseline `1`, the same weight the 50/50
|
|
21
|
+
* split already uses. Values are relative, exactly like `weighted()`
|
|
22
|
+
* (`Distribution/index.ts`) — they need not sum to one, and are fed to
|
|
23
|
+
* `weighted()` unchanged alongside each unspecified key's baseline `1`.
|
|
24
|
+
*
|
|
25
|
+
* Specifying one outcome's weight shifts the *other* outcome's resulting
|
|
26
|
+
* probability too, even though its weight stays at `1` — its share of the
|
|
27
|
+
* total still moves, since the total changed. `.weighted({ omitted: 0.1 })`
|
|
28
|
+
* is not "10% omitted, 90% present" — with `value` at default `1`, the
|
|
29
|
+
* split is `0.1 / 1.1 ≈ 9.1%` omitted, `≈90.9%` present. No independent
|
|
30
|
+
* "absolute probability" mode; weights are only meaningful relative to the
|
|
31
|
+
* full set in play.
|
|
32
|
+
*/
|
|
33
|
+
export type Weights = {
|
|
34
|
+
omitted: number;
|
|
35
|
+
value?: number | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
omitted?: number | undefined;
|
|
38
|
+
value: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* `definition` stays required regardless of `produce` — an opaque `as`
|
|
42
|
+
* production layers on top rather than replacing it, so a prior definition
|
|
43
|
+
* survives `as` for future validation of `produce` (and so `ToTypeBox`'s
|
|
44
|
+
* structural derivation of the wrapped shape keeps working either way).
|
|
45
|
+
*/
|
|
46
|
+
export type Meta<$Definition extends Definition = Definition> = {
|
|
47
|
+
definition: $Definition;
|
|
48
|
+
produce?: Produce<Resolved<$Definition>>;
|
|
49
|
+
weights?: Weights;
|
|
50
|
+
};
|
|
51
|
+
export interface Core<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> {
|
|
52
|
+
[Kind]: "object.omittable";
|
|
53
|
+
[Meta]: Meta<$Definition>;
|
|
54
|
+
bindings?: unknown[];
|
|
55
|
+
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]>>;
|
|
56
|
+
readonly [Adaptation]?: $Adaptations;
|
|
57
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AdaptationsOf } from "../../../Adapter/Types";
|
|
2
|
+
import type { Fabricator as BaseFabricator, FabricatorContext } from "../../../Fabricator/Types";
|
|
3
|
+
import type { Trace } from "../../../Random/Types";
|
|
4
|
+
import { Children, Kind, Meta, type Adaptation } from "../../../Types";
|
|
5
|
+
import type { Schema } from "./Schema";
|
|
6
|
+
import type { Definition, Resolved, Meta as ThisMeta } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator<any>> = $Fabricator extends Fabricator<infer $Schema> ? Resolved<$Schema[typeof Meta]["definition"]> : never;
|
|
8
|
+
export type Fabricator<$Schema extends {
|
|
9
|
+
[Meta]: ThisMeta;
|
|
10
|
+
} = {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
}> = {
|
|
13
|
+
[Kind]: "object.optional";
|
|
14
|
+
[Meta]: $Schema[typeof Meta];
|
|
15
|
+
readonly trace: Trace;
|
|
16
|
+
[Children]: BaseFabricator<any>;
|
|
17
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
18
|
+
/**
|
|
19
|
+
* `Omitted` on the omission roll (or when an `.as(...)` producer returns it)
|
|
20
|
+
* — read only by `object/Fabricator.ts`'s fabricate loop, which omits the
|
|
21
|
+
* key entirely rather than writing `undefined`. A "present as `undefined`"
|
|
22
|
+
* roll returns `undefined` directly, which the loop assigns like any
|
|
23
|
+
* ordinary value — the difference from `object.omittable`. Fabricating this
|
|
24
|
+
* outside a parent `object` hands whichever of the three results back
|
|
25
|
+
* verbatim.
|
|
26
|
+
*/
|
|
27
|
+
fabricate: () => Resolved<$Schema[typeof Meta]["definition"]>;
|
|
28
|
+
};
|
|
29
|
+
export declare function isObjectOptionalFabricator(candidate: BaseFabricator<unknown>): candidate is Fabricator;
|
|
30
|
+
/**
|
|
31
|
+
* Three-way roll: omitted, present-as-`undefined`, or the wrapped value —
|
|
32
|
+
* on this field's private stream; `source` is drawn only when "value" wins.
|
|
33
|
+
* Uniform (1/3 each) by default; not achievable by composing
|
|
34
|
+
* `object.omittable(T.undefinable(inner))`'s two independent 50/50 rolls
|
|
35
|
+
* (that is 50/25/25, not 33/33/33), hence the dedicated three-way
|
|
36
|
+
* `weighted()` here — see CLAUDE.md's "Why `T.optional` isn't
|
|
37
|
+
* `omittable(undefinable(inner))`" under "Compound / field-only kinds".
|
|
38
|
+
* `.weighted(...)` (`Schema.ts`) reweights individual outcomes relative to
|
|
39
|
+
* that same default of `1`; an unspecified outcome keeps it. Skipping
|
|
40
|
+
* `source`'s draw on the two non-"value" outcomes is safe for the same
|
|
41
|
+
* reason as `object/omittable/Fabricator.ts`: `source` already has its own
|
|
42
|
+
* independent stream, minted at build time regardless of this roll (see
|
|
43
|
+
* CLAUDE.md's "Randomness").
|
|
44
|
+
*/
|
|
45
|
+
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, source: BaseFabricator<any>): Fabricator<Schema<$Definition>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three outcomes an optional field's roll can land on. Also the key
|
|
3
|
+
* space `.weighted(...)` weighs — see `Types.ts`'s `Weights`.
|
|
4
|
+
*
|
|
5
|
+
* Lives here rather than `Types.ts` so that file stays type-only (see
|
|
6
|
+
* `boolean/Outcomes.ts`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const outcomes: readonly ["omitted", "undefined", "value"];
|
|
9
|
+
export type Outcome = (typeof outcomes)[number];
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { AnySchema } from "../../../Schema/Types";
|
|
5
|
+
import type { Core, Definition, Resolved, Weights } from "./Types";
|
|
6
|
+
export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
|
|
7
|
+
/**
|
|
8
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
9
|
+
* `definition` forward, not discarding it, so a later `.as(...)` (or future
|
|
10
|
+
* validation of `produce`) still has it to check against. `produce` may
|
|
11
|
+
* return `undefined` or `Omitted`, so custom logic composes the same way
|
|
12
|
+
* the built-in three-way roll does.
|
|
13
|
+
*/
|
|
14
|
+
as: (produce: Produce<Resolved<$Definition>>) => Schema<$Definition, $Adaptations>;
|
|
15
|
+
/**
|
|
16
|
+
* Reweight the built-in three-way roll. Keys are optional — an omitted key
|
|
17
|
+
* keeps baseline weight `1`, the same weight the uniform 1/3 split already
|
|
18
|
+
* uses — but that baseline is still relative to whatever else is specified,
|
|
19
|
+
* so `.weighted({ omitted: 0.1 })` shifts every outcome's share, not just
|
|
20
|
+
* `omitted`'s (see `Types.ts`'s `Weights`). Chaining `.weighted(...)` merges
|
|
21
|
+
* into previous weights rather than replacing them, the same layering
|
|
22
|
+
* `.as(...)` uses for `produce`.
|
|
23
|
+
*/
|
|
24
|
+
weighted: (weights: Weights) => Schema<$Definition, $Adaptations>;
|
|
25
|
+
/**
|
|
26
|
+
* Override what this schema maps to in one or more external schema
|
|
27
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
28
|
+
*/
|
|
29
|
+
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>>>;
|
|
30
|
+
}
|
|
31
|
+
export declare function Schema<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: Core<$Definition, $Adaptations>): Schema<$Definition, $Adaptations>;
|
|
32
|
+
export declare function isObjectOptionalSchema(candidate: AnySchema): candidate is Schema;
|