@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,27 @@
|
|
|
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, Fabricated, Meta as ThisMeta } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* Buildable `bigint` recipe: a range (`whereby` — required, like `string`;
|
|
7
|
+
* no natural bound to fuzz to), or opaque production via `as`.
|
|
8
|
+
*
|
|
9
|
+
* `$Meta` is generic (defaulting to the full `Meta` union) so builder
|
|
10
|
+
* return types stay narrow — see `number/Schema.ts`. `$Adaptations` is
|
|
11
|
+
* threaded through every builder method for the same reason — see
|
|
12
|
+
* `string/Schema.ts`'s `adapt`.
|
|
13
|
+
*/
|
|
14
|
+
export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends Adaptations = {}> extends Core<$Meta, $Adaptations> {
|
|
15
|
+
/**
|
|
16
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
17
|
+
* `whereby` forward, not discarding it, so a later `.as(...)` (or future
|
|
18
|
+
* validation of `produce`) still has it to check against.
|
|
19
|
+
*/
|
|
20
|
+
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
21
|
+
/**
|
|
22
|
+
* Override what this schema maps to in one or more external schema
|
|
23
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
24
|
+
*/
|
|
25
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Meta, $Adaptations>>) => $Returnable) => Schema<$Meta, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
26
|
+
}
|
|
27
|
+
export declare function Schema<$Meta extends ThisMeta, $Adaptations extends Adaptations = {}>(schema: Core<$Meta, $Adaptations>): Schema<$Meta, $Adaptations>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Bound, InputBound } from "../../Bound";
|
|
3
|
+
import type { Produce } from "../../Random/Types";
|
|
4
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
5
|
+
export type InputWhereby = {
|
|
6
|
+
min?: InputBound<bigint> | undefined;
|
|
7
|
+
max: InputBound<bigint>;
|
|
8
|
+
};
|
|
9
|
+
export type Whereby = {
|
|
10
|
+
min: Bound<bigint>;
|
|
11
|
+
max: Bound<bigint>;
|
|
12
|
+
};
|
|
13
|
+
export type Fabricated = bigint;
|
|
14
|
+
/**
|
|
15
|
+
* A ranged bigint, drawn via `whereby` — no natural bound to fuzz to, so
|
|
16
|
+
* unlike `number`/`date` there's no bare form — optionally overridden by
|
|
17
|
+
* an opaque `as` production, carried alongside `whereby` rather than
|
|
18
|
+
* replacing it (when `whereby` was already set) so a prior range survives
|
|
19
|
+
* `as` for future validation.
|
|
20
|
+
*/
|
|
21
|
+
export type Meta = {
|
|
22
|
+
whereby: Whereby;
|
|
23
|
+
produce?: never;
|
|
24
|
+
} | {
|
|
25
|
+
whereby?: Whereby;
|
|
26
|
+
produce: Produce<Fabricated>;
|
|
27
|
+
};
|
|
28
|
+
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
29
|
+
[Kind]: "bigint";
|
|
30
|
+
[Meta]: $Meta;
|
|
31
|
+
readonly [Produces]?: Fabricated;
|
|
32
|
+
readonly [Adaptation]?: $Adaptations;
|
|
33
|
+
};
|
|
@@ -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]: "boolean";
|
|
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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weight *keys* for `.weighted(...)`, not the boolean values themselves.
|
|
3
|
+
* Derived so `assertDrawableKeyedWeights` and `Enumeration/Plan.ts`
|
|
4
|
+
* cannot drift from the named outcome set.
|
|
5
|
+
*
|
|
6
|
+
* Lives here rather than `Types.ts` so that file stays type-only. A
|
|
7
|
+
* value export alongside `export type Fabricated = boolean` makes the
|
|
8
|
+
* module a value module, and `export * as boolean` in
|
|
9
|
+
* `Primitive/namespace.ts` then resolves `boolean` to the namespace —
|
|
10
|
+
* a cycle that drops `[Kind]`/`[Meta]` off `Core`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const outcomes: readonly ["true", "false"];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import { Schema } from "./Schema";
|
|
4
|
+
import type { Fabricated } from "./Types";
|
|
5
|
+
declare const _default: {
|
|
6
|
+
[Kind]: "boolean";
|
|
7
|
+
[Meta]: {};
|
|
8
|
+
[Produces]?: Fabricated;
|
|
9
|
+
[Adaptation]?: Adaptations;
|
|
10
|
+
as: (produce: import("../../Random/Types").Produce<Fabricated>) => Schema<{}, Adaptations>;
|
|
11
|
+
weighted: (weights: import("./Types").Weights) => Schema<{}, Adaptations>;
|
|
12
|
+
adapt: <const $Adapter extends import("../..").Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: import("../..").Adapting<Schema<{}, Adaptations>>) => $Returnable) => Schema<{}, import("../../Adapter/Types").WithAdaptations<Adaptations, import("../../Adapter/Core").AdaptationEntry<$Adapter, $Returnable>>>;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
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, Fabricated, Meta as ThisMeta, Weights } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* Buildable `boolean` recipe: an even coin flip, a weighted one
|
|
7
|
+
* (`weights`), or opaque production via `as`.
|
|
8
|
+
*
|
|
9
|
+
* `$Meta` is generic (defaulting to the full `Meta` union) so builder
|
|
10
|
+
* return types stay narrow — see `number/Schema.ts`. `$Adaptations` is
|
|
11
|
+
* threaded through every builder method for the same reason — see
|
|
12
|
+
* `string/Schema.ts`'s `adapt`.
|
|
13
|
+
*/
|
|
14
|
+
export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends Adaptations = {}> extends Core<$Meta, $Adaptations> {
|
|
15
|
+
/**
|
|
16
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
17
|
+
* `weights` forward, not discarding it, so a later `.as(...)` (or future
|
|
18
|
+
* validation of `produce`) still has it to check against.
|
|
19
|
+
*/
|
|
20
|
+
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
21
|
+
weighted: (weights: Weights) => Schema<$Meta, $Adaptations>;
|
|
22
|
+
/**
|
|
23
|
+
* Override what this schema maps to in one or more external schema
|
|
24
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
25
|
+
*/
|
|
26
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Meta, $Adaptations>>) => $Returnable) => Schema<$Meta, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
27
|
+
}
|
|
28
|
+
export declare function Schema<$Meta extends ThisMeta, $Adaptations extends Adaptations = {}>(schema: Core<$Meta, $Adaptations>): Schema<$Meta, $Adaptations>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Produce } from "../../Random/Types";
|
|
3
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
4
|
+
export type Fabricated = boolean;
|
|
5
|
+
export type Weights = {
|
|
6
|
+
true: number;
|
|
7
|
+
false?: number | undefined;
|
|
8
|
+
} | {
|
|
9
|
+
true?: number | undefined;
|
|
10
|
+
false: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* An even coin flip, or a weighted one via `weights`, optionally overridden
|
|
14
|
+
* by an opaque `as` production — carried alongside `weights` rather than
|
|
15
|
+
* replacing it, so a prior weighting survives `as` for future validation.
|
|
16
|
+
*/
|
|
17
|
+
export type Meta = {
|
|
18
|
+
produce?: Produce<Fabricated>;
|
|
19
|
+
weights?: Weights;
|
|
20
|
+
};
|
|
21
|
+
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
22
|
+
[Kind]: "boolean";
|
|
23
|
+
[Meta]: $Meta;
|
|
24
|
+
readonly [Produces]?: Fabricated;
|
|
25
|
+
readonly [Adaptation]?: $Adaptations;
|
|
26
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { Fabricated, Items, 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]["items"]> : never;
|
|
10
|
+
export type Fabricator<$Schema extends {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
} = {
|
|
13
|
+
[Meta]: ThisMeta;
|
|
14
|
+
}> = NaiveFabricator<Fabricated<$Schema[typeof Meta]["items"]>> & {
|
|
15
|
+
[Kind]: "choice";
|
|
16
|
+
[Meta]: $Schema[typeof Meta];
|
|
17
|
+
readonly trace: Trace;
|
|
18
|
+
[Children]: ReadonlyArray<NaiveFabricator<any>>;
|
|
19
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
20
|
+
schema: Schema<$Schema[typeof Meta]["items"], AdaptationsOf<$Schema>>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `weightings` are each option's *already-dispatched* Fabricator, one per
|
|
24
|
+
* `[Meta].items` entry, built by `Constructor.ts`'s `make` before this call —
|
|
25
|
+
* mirrors `array.Fabricator`'s `element`, just one per option instead of
|
|
26
|
+
* one shared across every element. The weighted pick happens on this
|
|
27
|
+
* field's private stream; only the chosen option's `fabricate()` is called,
|
|
28
|
+
* so an unpicked option never advances its stream (safe for the same reason
|
|
29
|
+
* skipping `object.omittable`'s inner draw is — see CLAUDE.md's
|
|
30
|
+
* "Randomness").
|
|
31
|
+
*/
|
|
32
|
+
export declare function Fabricator<$Items extends Items>(context: FabricatorContext<Schema<$Items>>, weightings: ReadonlyArray<readonly [number, NaiveFabricator<any>]>): Fabricator<Schema<$Items>>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Schema } from "./Schema";
|
|
2
|
+
import type { Item, Items } from "./Types";
|
|
3
|
+
/**
|
|
4
|
+
* Tuple-preserving: a mapped type over `$Items` keeps its exact length and
|
|
5
|
+
* per-position option types (`{ [K in keyof $Items]: ... }` walks a tuple
|
|
6
|
+
* position-by-position, unlike `ReadonlyArray<...>`'s `.map()`, which only
|
|
7
|
+
* remembers the union of every element it saw). This is what lets
|
|
8
|
+
* `Adapter/TypeBox` recover real arity later and mirror TypeBox's
|
|
9
|
+
* `Union<T>` collapse-for-a-single-option — see `Types.ts`'s `Items`.
|
|
10
|
+
*/
|
|
11
|
+
type Weighted<$Items extends ReadonlyArray<Item>> = {
|
|
12
|
+
[$K in keyof $Items]: readonly [number, $Items[$K]];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* At least one element — a `choice` with no option has nothing to draw,
|
|
16
|
+
* which would otherwise fail inside `weighted()` (`Distribution/index.ts`)
|
|
17
|
+
* with an opaque `TypeError` at fabricate time (weight sum is `0`, so
|
|
18
|
+
* `.find` returns `undefined` and `chosen![1]` throws). Rejecting emptiness
|
|
19
|
+
* here is a construction-time compile error; the runtime check below is the
|
|
20
|
+
* backstop for an `as any` call that bypasses it.
|
|
21
|
+
*/
|
|
22
|
+
type NonEmpty<$T> = readonly [$T, ...$T[]];
|
|
23
|
+
declare const _default: {
|
|
24
|
+
/**
|
|
25
|
+
* Equal probability across every option. Delegates to `weighted` with a
|
|
26
|
+
* uniform weight of `1` per item — a plain `weighted()` draw is already a
|
|
27
|
+
* uniform draw when every weight is equal, so there is no separate
|
|
28
|
+
* unweighted code path to keep in sync.
|
|
29
|
+
*/
|
|
30
|
+
uniform: <const $Items extends NonEmpty<Item>>(items: $Items) => Schema<Weighted<$Items>>;
|
|
31
|
+
/**
|
|
32
|
+
* Relative probability across options, given as `[weight, schema]` pairs
|
|
33
|
+
* — the same tuple shape `weighted()` (`Distribution/index.ts`) itself
|
|
34
|
+
* accepts, not an object keyed by option.
|
|
35
|
+
*/
|
|
36
|
+
weighted: <const $Items extends NonEmpty<Items[number]>>(items: $Items) => Schema<$Items>;
|
|
37
|
+
};
|
|
38
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
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, Fabricated, Items } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* Buildable `choice` recipe: a weighted set of option Schemas, one of which
|
|
7
|
+
* is drawn (and only then dispatched into a value) each fabrication. No
|
|
8
|
+
* bare form — see `Registry.ts`'s `uniform`/`weighted`, the only way to
|
|
9
|
+
* reach this Schema.
|
|
10
|
+
*/
|
|
11
|
+
export interface Schema<$Items extends Items = Items, $Adaptations extends Adaptations = {}> extends Core<$Items, $Adaptations> {
|
|
12
|
+
/**
|
|
13
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
14
|
+
* `items` forward, not discarding it, so a later `.as(...)` (or future
|
|
15
|
+
* validation of `produce`) still has it to check against.
|
|
16
|
+
*/
|
|
17
|
+
as: (produce: Produce<Fabricated<$Items>>) => Schema<$Items, $Adaptations>;
|
|
18
|
+
/**
|
|
19
|
+
* Override what this schema maps to in one or more external schema
|
|
20
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
21
|
+
*/
|
|
22
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Items, $Adaptations>>) => $Returnable) => Schema<$Items, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
23
|
+
}
|
|
24
|
+
export declare function Schema<$Items extends Items, $Adaptations extends Adaptations = {}>(schema: Core<$Items, $Adaptations>): Schema<$Items, $Adaptations>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Produce } from "../../Random/Types";
|
|
3
|
+
import type { AnySchema, ValueOf } from "../../Schema/Types";
|
|
4
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
5
|
+
/** The schemas a `choice` can draw from. */
|
|
6
|
+
export type Item = AnySchema;
|
|
7
|
+
/**
|
|
8
|
+
* A *tuple* of `[weight, option]` pairs, one per position — not a flattened
|
|
9
|
+
* `ReadonlyArray<[number, Item]>`, which would remember only the union of
|
|
10
|
+
* every option's type and lose how many options there were (two identical
|
|
11
|
+
* option types would collapse to one union member). The real tuple is what
|
|
12
|
+
* lets `Adapter/TypeBox` mirror TypeBox's `Union<T>` — which collapses to a
|
|
13
|
+
* bare schema for a single option and only wraps in `TUnion<T>` for two or
|
|
14
|
+
* more — instead of always wrapping regardless of count.
|
|
15
|
+
*/
|
|
16
|
+
export type Items = ReadonlyArray<readonly [number, Item]>;
|
|
17
|
+
export type Fabricated<$Items extends Items = Items, $Bindings extends unknown[] = []> = ValueOf<$Items[number][1], $Bindings>;
|
|
18
|
+
/**
|
|
19
|
+
* Always stored as weighted pairs — `.uniform(...)` (`Registry.ts`) is
|
|
20
|
+
* `.weighted(...)` with every item given weight `1`, so there is only one
|
|
21
|
+
* shape to fabricate from. `produce` layers an opaque production via
|
|
22
|
+
* `.as()`, carried alongside `items` rather than replacing it, so a prior
|
|
23
|
+
* option set survives `.as()` for future validation.
|
|
24
|
+
*/
|
|
25
|
+
export type Meta<$Items extends Items = Items> = {
|
|
26
|
+
items: $Items;
|
|
27
|
+
produce?: Produce<Fabricated<$Items>>;
|
|
28
|
+
};
|
|
29
|
+
export interface Core<$Items extends Items = Items, $Adaptations extends Adaptations = {}> {
|
|
30
|
+
[Kind]: "choice";
|
|
31
|
+
[Meta]: Meta<$Items>;
|
|
32
|
+
bindings?: unknown[];
|
|
33
|
+
readonly [Produces]?: Fabricated<$Items, NonNullable<this["bindings"]>>;
|
|
34
|
+
readonly [Adaptation]?: $Adaptations;
|
|
35
|
+
}
|
|
@@ -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]: "date";
|
|
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,82 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import { type InputBound } from "../../Bound";
|
|
3
|
+
import { type Distribution } from "../../Distribution";
|
|
4
|
+
import { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
5
|
+
import { Schema } from "./Schema";
|
|
6
|
+
import type { Fabricated, Whereby } from "./Types";
|
|
7
|
+
declare const _default: {
|
|
8
|
+
[Kind]: "date";
|
|
9
|
+
[Meta]: {};
|
|
10
|
+
[Produces]?: Fabricated;
|
|
11
|
+
[Adaptation]?: Adaptations;
|
|
12
|
+
as: (produce: import("../../Random/Types").Produce<Fabricated>) => Schema<{}, Adaptations>;
|
|
13
|
+
adapt: <const $Adapter extends import("../..").Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: import("../..").Adapting<Schema<{}, Adaptations>>) => $Returnable) => Schema<{}, import("../../Adapter/Types").WithAdaptations<Adaptations, import("../../Adapter/Core").AdaptationEntry<$Adapter, $Returnable>>>;
|
|
14
|
+
whereby: (whereby: {
|
|
15
|
+
min: InputBound<Date>;
|
|
16
|
+
max: InputBound<Date>;
|
|
17
|
+
distribution?: Distribution | undefined;
|
|
18
|
+
}) => Schema<{
|
|
19
|
+
whereby: Whereby;
|
|
20
|
+
}, {}>;
|
|
21
|
+
/** Any `Date` from the earliest representable instant up to the present moment. */
|
|
22
|
+
past: {
|
|
23
|
+
[Kind]: "date";
|
|
24
|
+
[Meta]: {
|
|
25
|
+
mode: "past";
|
|
26
|
+
};
|
|
27
|
+
[Produces]?: Fabricated;
|
|
28
|
+
[Adaptation]?: {};
|
|
29
|
+
as: (produce: import("../../Random/Types").Produce<Fabricated>) => Schema<{
|
|
30
|
+
mode: "past";
|
|
31
|
+
}, {}>;
|
|
32
|
+
adapt: <const $Adapter extends import("../..").Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: import("../..").Adapting<Schema<{
|
|
33
|
+
mode: "past";
|
|
34
|
+
}, {}>>) => $Returnable) => Schema<{
|
|
35
|
+
mode: "past";
|
|
36
|
+
}, import("../../Adapter/Types").WithAdaptations<{}, import("../../Adapter/Core").AdaptationEntry<$Adapter, $Returnable>>>;
|
|
37
|
+
/**
|
|
38
|
+
* A past `Date` drawn from `[min, now]`. `min` defaults to the earliest
|
|
39
|
+
* representable instant. The implicit `now` end stays inclusive. Pass a
|
|
40
|
+
* `distribution` to shape how values cluster within the range; without
|
|
41
|
+
* one, every instant is equally likely.
|
|
42
|
+
*/
|
|
43
|
+
whereby: (whereby: {
|
|
44
|
+
min?: InputBound<Date> | undefined;
|
|
45
|
+
distribution?: Distribution | undefined;
|
|
46
|
+
}) => Schema<{
|
|
47
|
+
mode: "past";
|
|
48
|
+
whereby: Whereby;
|
|
49
|
+
}, {}>;
|
|
50
|
+
};
|
|
51
|
+
/** Any `Date` from the present moment up to the latest representable instant. */
|
|
52
|
+
future: {
|
|
53
|
+
[Kind]: "date";
|
|
54
|
+
[Meta]: {
|
|
55
|
+
mode: "future";
|
|
56
|
+
};
|
|
57
|
+
[Produces]?: Fabricated;
|
|
58
|
+
[Adaptation]?: {};
|
|
59
|
+
as: (produce: import("../../Random/Types").Produce<Fabricated>) => Schema<{
|
|
60
|
+
mode: "future";
|
|
61
|
+
}, {}>;
|
|
62
|
+
adapt: <const $Adapter extends import("../..").Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: import("../..").Adapting<Schema<{
|
|
63
|
+
mode: "future";
|
|
64
|
+
}, {}>>) => $Returnable) => Schema<{
|
|
65
|
+
mode: "future";
|
|
66
|
+
}, import("../../Adapter/Types").WithAdaptations<{}, import("../../Adapter/Core").AdaptationEntry<$Adapter, $Returnable>>>;
|
|
67
|
+
/**
|
|
68
|
+
* A future `Date` drawn from `[now, max]`. `max` defaults to the latest
|
|
69
|
+
* representable instant. The implicit `now` end stays inclusive. Pass a
|
|
70
|
+
* `distribution` to shape how values cluster within the range; without
|
|
71
|
+
* one, every instant is equally likely.
|
|
72
|
+
*/
|
|
73
|
+
whereby: (whereby: {
|
|
74
|
+
max?: InputBound<Date> | undefined;
|
|
75
|
+
distribution?: Distribution | undefined;
|
|
76
|
+
}) => Schema<{
|
|
77
|
+
mode: "future";
|
|
78
|
+
whereby: Whereby;
|
|
79
|
+
}, {}>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
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, Fabricated, Meta as ThisMeta } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* Buildable `Date` recipe: a range/distribution (`whereby`, absent for the
|
|
7
|
+
* full-range bare form), optionally scoped by `mode` to `"past"` (up to now)
|
|
8
|
+
* or `"future"` (from now), or opaque production via `as`.
|
|
9
|
+
*
|
|
10
|
+
* `$Meta` is generic (defaulting to the full `Meta` union) so builder
|
|
11
|
+
* return types stay narrow — e.g. `T.date.past` types as
|
|
12
|
+
* `Schema<{ mode: "past" }>`, not the widened `Schema` — see
|
|
13
|
+
* `number/Schema.ts`.
|
|
14
|
+
*/
|
|
15
|
+
export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends Adaptations = {}> extends Core<$Meta, $Adaptations> {
|
|
16
|
+
/**
|
|
17
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
18
|
+
* `mode`/`whereby` forward, not discarding them, so a later `.as(...)`
|
|
19
|
+
* (or future validation of `produce`) still has them to check against.
|
|
20
|
+
*/
|
|
21
|
+
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
22
|
+
/**
|
|
23
|
+
* Override what this schema maps to in one or more external schema
|
|
24
|
+
* libraries — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
25
|
+
*/
|
|
26
|
+
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Meta, $Adaptations>>) => $Returnable) => Schema<$Meta, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
27
|
+
}
|
|
28
|
+
export declare function Schema<$Meta extends ThisMeta, $Adaptations extends Adaptations = {}>(schema: Core<$Meta, $Adaptations>): Schema<$Meta, $Adaptations>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Bound, InputBound } from "../../Bound";
|
|
3
|
+
import type { Distribution } from "../../Distribution";
|
|
4
|
+
import type { Produce } from "../../Random/Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
6
|
+
export type InputWhereby = {
|
|
7
|
+
min?: InputBound<Date> | undefined;
|
|
8
|
+
max?: InputBound<Date> | undefined;
|
|
9
|
+
distribution?: Distribution | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type Whereby = {
|
|
12
|
+
min?: Bound<Date> | undefined;
|
|
13
|
+
max?: Bound<Date> | undefined;
|
|
14
|
+
distribution?: Distribution | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type Fabricated = Date;
|
|
17
|
+
/**
|
|
18
|
+
* A range/distribution (`whereby`, absent for the full-range bare form),
|
|
19
|
+
* optionally scoped by `mode` to `"past"` (up to now) or `"future"` (from
|
|
20
|
+
* now), optionally overridden by an opaque `as` production — carried
|
|
21
|
+
* alongside the rest rather than replacing it, so a prior scoping survives
|
|
22
|
+
* `as` for future validation.
|
|
23
|
+
*/
|
|
24
|
+
export type Meta = {
|
|
25
|
+
mode?: "past" | "future";
|
|
26
|
+
whereby?: Whereby;
|
|
27
|
+
produce?: Produce<Fabricated>;
|
|
28
|
+
};
|
|
29
|
+
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
30
|
+
[Kind]: "date";
|
|
31
|
+
[Meta]: $Meta;
|
|
32
|
+
readonly [Produces]?: Fabricated;
|
|
33
|
+
readonly [Adaptation]?: $Adaptations;
|
|
34
|
+
};
|
|
@@ -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, Items, Meta as ThisMeta } from "./Types";
|
|
7
|
+
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema> ? Fabricated<$Schema[typeof Meta]["items"]> : never;
|
|
8
|
+
export type Fabricator<$Schema extends {
|
|
9
|
+
[Meta]: ThisMeta;
|
|
10
|
+
} = {
|
|
11
|
+
[Meta]: ThisMeta;
|
|
12
|
+
}> = NaiveFabricator<Fabricated<$Schema[typeof Meta]["items"]>> & {
|
|
13
|
+
[Kind]: "enum";
|
|
14
|
+
[Meta]: $Schema[typeof Meta];
|
|
15
|
+
readonly trace: Trace;
|
|
16
|
+
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
schema: Schema<$Schema[typeof Meta]["items"], AdaptationsOf<$Schema>>;
|
|
18
|
+
};
|
|
19
|
+
export declare function Fabricator<$Items extends Items>(context: FabricatorContext<Schema<$Items>>): Fabricator<Schema<$Items>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Schema } from "./Schema";
|
|
2
|
+
import type { Item, Items } from "./Types";
|
|
3
|
+
/**
|
|
4
|
+
* Tuple-preserving: a mapped type over `$Items` keeps its exact length and
|
|
5
|
+
* per-position member types (`{ [K in keyof $Items]: ... }` walks a tuple
|
|
6
|
+
* position-by-position, unlike `ReadonlyArray<...>`'s `.map()`, which only
|
|
7
|
+
* remembers the union of every element it saw). This is what lets
|
|
8
|
+
* `Adapter/TypeBox` recover real arity later and mirror TypeBox's
|
|
9
|
+
* `Union<T>` collapse-for-a-single-member — see `Types.ts`'s `Items`. The
|
|
10
|
+
* same helper `choice/Registry.ts` uses, for the same reason.
|
|
11
|
+
*/
|
|
12
|
+
type Weighted<$Items extends ReadonlyArray<Item>> = {
|
|
13
|
+
[$K in keyof $Items]: readonly [number, $Items[$K]];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* At least one element — an empty `enum` has no member to draw, which would
|
|
17
|
+
* otherwise fail inside `weighted()` (`Distribution/index.ts`) with an
|
|
18
|
+
* opaque `TypeError` at fabricate time (weight sum is `0`, so `.find`
|
|
19
|
+
* returns `undefined` and `chosen![1]` throws). Rejecting emptiness here is
|
|
20
|
+
* a construction-time compile error; the runtime check below is the
|
|
21
|
+
* backstop for an `as any` call that bypasses it.
|
|
22
|
+
*/
|
|
23
|
+
type NonEmpty<$T> = readonly [$T, ...$T[]];
|
|
24
|
+
declare const _default: {
|
|
25
|
+
/**
|
|
26
|
+
* Equal probability across every member. Delegates to `weighted` with a
|
|
27
|
+
* uniform weight of `1` per item — a plain `weighted()` draw is already a
|
|
28
|
+
* uniform draw when every weight is equal, so there is no separate
|
|
29
|
+
* unweighted code path to keep in sync.
|
|
30
|
+
*/
|
|
31
|
+
uniform: <const $Items extends NonEmpty<Item>>(items: $Items) => Schema<Weighted<$Items>>;
|
|
32
|
+
/**
|
|
33
|
+
* Relative probability across members, given as `[weight, item]` pairs —
|
|
34
|
+
* the same tuple shape `weighted()` (`Distribution/index.ts`) itself
|
|
35
|
+
* accepts, not an object keyed by member.
|
|
36
|
+
*/
|
|
37
|
+
weighted: <const $Items extends NonEmpty<Items[number]>>(items: $Items) => Schema<$Items>;
|
|
38
|
+
};
|
|
39
|
+
export default _default;
|
|
@@ -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, Fabricated, Items } from "./Types";
|
|
5
|
+
/**
|
|
6
|
+
* The buildable recipe for an `enum`: a weighted set of member values, one
|
|
7
|
+
* of which is drawn each fabrication. There is no bare form — see
|
|
8
|
+
* `Registry.ts`'s `uniform`/`weighted`, the only way to reach this Schema.
|
|
9
|
+
*/
|
|
10
|
+
export interface Schema<$Items extends Items = Items, $Adaptations extends Adaptations = {}> extends Core<$Items, $Adaptations> {
|
|
11
|
+
/**
|
|
12
|
+
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
13
|
+
* `items` forward, not discarding it, so a later `.as(...)` (or future
|
|
14
|
+
* validation of `produce`) still has it to check against.
|
|
15
|
+
*/
|
|
16
|
+
as: (produce: Produce<Fabricated<$Items>>) => Schema<$Items, $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<$Items, $Adaptations>>) => $Returnable) => Schema<$Items, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
22
|
+
}
|
|
23
|
+
export declare function Schema<$Items extends Items, $Adaptations extends Adaptations = {}>(schema: Core<$Items, $Adaptations>): Schema<$Items, $Adaptations>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
+
import type { Produce } from "../../Random/Types";
|
|
3
|
+
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
4
|
+
/**
|
|
5
|
+
* The values an `enum` can draw from — any value at all, for the same
|
|
6
|
+
* reason `always.Value` is unconstrained (see its doc).
|
|
7
|
+
*
|
|
8
|
+
* What still separates `enum` from `choice`: an `enum` draws one of these
|
|
9
|
+
* exact *values*; a `choice` draws one of these *schemas* and fabricates
|
|
10
|
+
* from it.
|
|
11
|
+
*/
|
|
12
|
+
export type Item = unknown;
|
|
13
|
+
/**
|
|
14
|
+
* A *tuple* of `[weight, item]` pairs, one per position — not a flattened
|
|
15
|
+
* `ReadonlyArray<[number, Item]>`, which would remember only the union of
|
|
16
|
+
* every member's type and lose how many members there were (two identical
|
|
17
|
+
* member types would collapse to one union member). The real tuple is what
|
|
18
|
+
* lets `Adapter/TypeBox` mirror TypeBox's `Union<T>` — which collapses to a
|
|
19
|
+
* bare schema for a single member and only wraps in `TUnion<T>` for two or
|
|
20
|
+
* more — instead of mapping each member independently and losing the union
|
|
21
|
+
* wrapper.
|
|
22
|
+
*
|
|
23
|
+
* Identical shape to `choice.Items`; the two kinds differ only in what sits
|
|
24
|
+
* on the right of each pair (a value here, a Schema there).
|
|
25
|
+
*/
|
|
26
|
+
export type Items = ReadonlyArray<readonly [number, Item]>;
|
|
27
|
+
export type Fabricated<$Items extends Items = Items> = $Items[number][1];
|
|
28
|
+
/**
|
|
29
|
+
* Always stored as weighted pairs — `.uniform(...)` (`Registry.ts`) is
|
|
30
|
+
* `.weighted(...)` with every item given weight `1`, so there is only one
|
|
31
|
+
* shape to fabricate from. `produce` layers an opaque production via
|
|
32
|
+
* `.as()`, carried alongside `items` rather than replacing it, so a prior
|
|
33
|
+
* member set survives `.as()` for future validation.
|
|
34
|
+
*/
|
|
35
|
+
export type Meta<$Items extends Items = Items> = {
|
|
36
|
+
items: $Items;
|
|
37
|
+
produce?: Produce<Fabricated<$Items>>;
|
|
38
|
+
};
|
|
39
|
+
export type Core<$Items extends Items = Items, $Adaptations extends Adaptations = {}> = {
|
|
40
|
+
[Kind]: "enum";
|
|
41
|
+
[Meta]: Meta<$Items>;
|
|
42
|
+
readonly [Produces]?: Fabricated<$Items>;
|
|
43
|
+
readonly [Adaptation]?: $Adaptations;
|
|
44
|
+
};
|