@ghostry/fabricator 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/dist/esm/Error/index.js +8 -0
- package/dist/esm/Instance/Core.js +8 -17
- package/dist/esm/Instance/Stack/Async.js +10 -0
- package/dist/esm/Instance/Stack/Sync.js +16 -0
- package/dist/esm/Primitive/bigint/Registry.js +12 -12
- package/dist/esm/Primitive/boolean/Registry.js +2 -1
- package/dist/esm/Primitive/date/Registry.js +15 -14
- package/dist/esm/Primitive/null/Registry.js +2 -1
- package/dist/esm/Primitive/number/Registry.js +18 -17
- package/dist/esm/Primitive/symbol/Registry.js +2 -1
- package/dist/esm/Primitive/undefined/Registry.js +2 -1
- package/dist/esm/Random/CallSite.js +27 -13
- package/dist/esm/Utility/Core.js +6 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/internal.js +2 -1
- package/dist/types/Adapter/Core.d.ts +29 -32
- package/dist/types/Adapter/Types.d.ts +78 -88
- package/dist/types/Bound.d.ts +15 -15
- package/dist/types/Distribution/index.d.ts +54 -61
- package/dist/types/Enumeration/Enumerate.d.ts +21 -23
- package/dist/types/Enumeration/Plan.d.ts +22 -26
- package/dist/types/Enumeration/Types.d.ts +38 -43
- package/dist/types/Error/index.d.ts +94 -76
- package/dist/types/Fabricator/Constructor.d.ts +23 -25
- package/dist/types/Fabricator/Types.d.ts +73 -81
- package/dist/types/Instance/Core.d.ts +54 -73
- package/dist/types/Instance/Stack/Async.d.ts +14 -0
- package/dist/types/Instance/Stack/Sync.d.ts +14 -0
- package/dist/types/Instance/Types.d.ts +91 -89
- package/dist/types/Primitive/always/Schema.d.ts +8 -8
- package/dist/types/Primitive/always/Types.d.ts +7 -7
- package/dist/types/Primitive/array/Registry.d.ts +10 -8
- package/dist/types/Primitive/array/Schema.d.ts +4 -5
- package/dist/types/Primitive/array/Types.d.ts +6 -6
- package/dist/types/Primitive/bigint/Registry.d.ts +6 -6
- package/dist/types/Primitive/bigint/Schema.d.ts +8 -8
- package/dist/types/Primitive/bigint/Types.d.ts +5 -5
- package/dist/types/Primitive/boolean/Outcomes.d.ts +8 -8
- package/dist/types/Primitive/boolean/Registry.d.ts +2 -12
- package/dist/types/Primitive/boolean/Schema.d.ts +8 -8
- package/dist/types/Primitive/boolean/Types.d.ts +3 -3
- package/dist/types/Primitive/choice/Fabricator.d.ts +6 -7
- package/dist/types/Primitive/choice/Registry.d.ts +13 -13
- package/dist/types/Primitive/choice/Schema.d.ts +6 -6
- package/dist/types/Primitive/choice/Types.d.ts +11 -11
- package/dist/types/Primitive/date/Registry.d.ts +25 -48
- package/dist/types/Primitive/date/Schema.d.ts +9 -10
- package/dist/types/Primitive/date/Types.d.ts +4 -4
- package/dist/types/Primitive/enum/Registry.d.ts +13 -13
- package/dist/types/Primitive/enum/Schema.d.ts +5 -5
- package/dist/types/Primitive/enum/Types.d.ts +17 -19
- package/dist/types/Primitive/namespace.d.ts +10 -10
- package/dist/types/Primitive/null/Registry.d.ts +2 -2
- package/dist/types/Primitive/null/Schema.d.ts +2 -2
- package/dist/types/Primitive/null/Types.d.ts +3 -3
- package/dist/types/Primitive/nullable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/nullable/Schema.d.ts +13 -13
- package/dist/types/Primitive/nullable/Types.d.ts +9 -10
- package/dist/types/Primitive/nullish/Fabricator.d.ts +12 -13
- package/dist/types/Primitive/nullish/Schema.d.ts +8 -8
- package/dist/types/Primitive/nullish/Types.d.ts +12 -13
- package/dist/types/Primitive/number/Registry.d.ts +20 -38
- package/dist/types/Primitive/number/Schema.d.ts +11 -12
- package/dist/types/Primitive/number/Types.d.ts +13 -13
- package/dist/types/Primitive/number/defaults.d.ts +3 -3
- package/dist/types/Primitive/object/Fabricator.d.ts +15 -15
- package/dist/types/Primitive/object/Registry.d.ts +8 -8
- package/dist/types/Primitive/object/Schema.d.ts +10 -10
- package/dist/types/Primitive/object/Types.d.ts +20 -22
- package/dist/types/Primitive/object/compute/Fabricator.d.ts +4 -5
- package/dist/types/Primitive/object/compute/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/compute/Types.d.ts +19 -20
- package/dist/types/Primitive/object/omittable/Fabricator.d.ts +10 -10
- package/dist/types/Primitive/object/omittable/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/omittable/Schema.d.ts +11 -11
- package/dist/types/Primitive/object/omittable/Types.d.ts +14 -15
- package/dist/types/Primitive/object/optional/Fabricator.d.ts +16 -18
- package/dist/types/Primitive/object/optional/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/optional/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/optional/Types.d.ts +17 -17
- package/dist/types/Primitive/opaque/Registry.d.ts +3 -3
- package/dist/types/Primitive/opaque/Schema.d.ts +8 -9
- package/dist/types/Primitive/record/Registry.d.ts +8 -6
- package/dist/types/Primitive/record/Schema.d.ts +9 -11
- package/dist/types/Primitive/record/Types.d.ts +25 -25
- package/dist/types/Primitive/recursive/Fabricator.d.ts +16 -17
- package/dist/types/Primitive/recursive/Registry.d.ts +6 -7
- package/dist/types/Primitive/recursive/Schema.d.ts +8 -8
- package/dist/types/Primitive/recursive/Terminate.d.ts +13 -14
- package/dist/types/Primitive/recursive/Types.d.ts +31 -31
- package/dist/types/Primitive/recursive/self/Fabricator.d.ts +11 -12
- package/dist/types/Primitive/recursive/self/Schema.d.ts +10 -10
- package/dist/types/Primitive/recursive/self/Types.d.ts +7 -8
- package/dist/types/Primitive/string/Constants.d.ts +12 -13
- package/dist/types/Primitive/string/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/string/Registry.d.ts +10 -16
- package/dist/types/Primitive/string/Schema.d.ts +5 -5
- package/dist/types/Primitive/string/Types.d.ts +17 -17
- package/dist/types/Primitive/symbol/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/symbol/Registry.d.ts +4 -11
- package/dist/types/Primitive/symbol/Schema.d.ts +6 -6
- package/dist/types/Primitive/symbol/Types.d.ts +2 -2
- package/dist/types/Primitive/tuple/Fabricator.d.ts +7 -8
- package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
- package/dist/types/Primitive/tuple/Types.d.ts +24 -25
- package/dist/types/Primitive/undefinable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/undefinable/Schema.d.ts +13 -13
- package/dist/types/Primitive/undefinable/Types.d.ts +10 -10
- package/dist/types/Primitive/undefined/Registry.d.ts +2 -2
- package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
- package/dist/types/Primitive/undefined/Types.d.ts +3 -3
- package/dist/types/Random/CallSite.d.ts +63 -44
- package/dist/types/Random/Generator/sfc32.d.ts +4 -4
- package/dist/types/Random/Types.d.ts +214 -236
- package/dist/types/Random/index.d.ts +63 -70
- package/dist/types/Schema/Core.d.ts +19 -21
- package/dist/types/Schema/Registry.d.ts +3 -3
- package/dist/types/Schema/Types.d.ts +41 -48
- package/dist/types/Types.d.ts +39 -45
- package/dist/types/Utility/Core.d.ts +18 -9
- package/dist/types/index.d.ts +110 -108
- package/dist/types/internal.d.ts +68 -37
- package/package.json +17 -5
|
@@ -1,107 +1,100 @@
|
|
|
1
1
|
import type { Algorithm, Attribution, Layered, NumberGenerator, Options, RandomSource, ResolvedAttribution, Seed, Stream, Trace } from "./Types";
|
|
2
2
|
/**
|
|
3
|
-
* Build the library's built-in PRNG from a seed. The same seed always
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Build the library's built-in PRNG from a seed. The same seed always yields
|
|
4
|
+
* the same stream. Seeds may be numbers or strings; both are stringified and
|
|
5
|
+
* hashed to fully seed sfc32's state.
|
|
6
6
|
*/
|
|
7
7
|
export declare function defaultAlgorithm(seed: string): NumberGenerator;
|
|
8
8
|
/**
|
|
9
|
-
* Mint a fresh seed value — a uint32 label. Not used as
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Mint a fresh seed value — a uint32 label. Not used as `initialize()`'s
|
|
10
|
+
* default (an omitted seed is empty; wall-clock `clock` is the default
|
|
11
|
+
* entropy); kept for callers that want a generated mixer, and for tests that
|
|
12
|
+
* need one.
|
|
13
13
|
*/
|
|
14
14
|
export declare function randomSeed(): string;
|
|
15
15
|
/**
|
|
16
|
-
* Derive the explicit `"seeded"` clock — an epoch-millisecond instant,
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* (`Instance/Core.ts`'s `overlay`); this is the opt-in that makes
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* `Math.trunc`ed because a `Date`'s precision is whole milliseconds.
|
|
16
|
+
* Derive the explicit `"seeded"` clock — an epoch-millisecond instant, drawn
|
|
17
|
+
* across the full representable `Date` span — from an instance's own
|
|
18
|
+
* `algorithm`/`seed`. The unconfigured default is wall-clock time
|
|
19
|
+
* (`Instance/Core.ts`'s `overlay`); this is the opt-in that makes `seed` alone
|
|
20
|
+
* the reproducibility unit, at the cost of an implausible "now". A throwaway
|
|
21
|
+
* two-element encoding (`JSON.stringify([seed, "clock"])`), _not_ routed
|
|
22
|
+
* through `RandomSource`/`Trace`: after the clock is folded into stream
|
|
23
|
+
* derivation, a forked source's own stream derivation requires a clock, so
|
|
24
|
+
* deriving the clock from a fork would be circular. Kept below that layer,
|
|
25
|
+
* which also keeps this collision-free with every leaf's `encode(trace)` — that
|
|
26
|
+
* encoding is always seven elements, this is always two, and the two can never
|
|
27
|
+
* produce the same JSON array. `Math.trunc`ed because a `Date`'s precision is
|
|
28
|
+
* whole milliseconds.
|
|
30
29
|
*/
|
|
31
30
|
export declare function deriveClock(algorithm: Algorithm, seed: ReadonlyArray<string>): number;
|
|
32
31
|
/**
|
|
33
32
|
* Collapse a {@link Trace} into one string to hash — and, since
|
|
34
|
-
* `toStreamFromTrace` hashes exactly this output, the
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* of colliding with a real file path or index.
|
|
33
|
+
* `toStreamFromTrace` hashes exactly this output, the _definition_ of that
|
|
34
|
+
* leaf's stream seed. Concatenating fields with a delimiter would collide when
|
|
35
|
+
* a path/kind/seed part contains that delimiter (`file="a b", kind="c"` vs
|
|
36
|
+
* `file="a", kind="b c"`) — silently: two leaves that should draw independently
|
|
37
|
+
* would share one stream. `JSON.stringify` as an array makes every field's and
|
|
38
|
+
* slot's boundaries unambiguous regardless of content or nesting depth.
|
|
39
|
+
* `undefined` (`file`, `ordinal`) is the right "this slot doesn't apply" rather
|
|
40
|
+
* than a sentinel string: `JSON.stringify` writes it as `null` in an array
|
|
41
|
+
* position, one unambiguous value, with no chance of colliding with a real file
|
|
42
|
+
* path or index.
|
|
45
43
|
*/
|
|
46
44
|
export declare function encode(trace: Trace): string;
|
|
47
45
|
/**
|
|
48
|
-
* Normalize a caller-supplied {@link Seed} to its parts: a single string
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* entropy beside the instance clock.
|
|
46
|
+
* Normalize a caller-supplied {@link Seed} to its parts: a single string becomes
|
|
47
|
+
* a one-element array, an array passes through unchanged, and a missing seed is
|
|
48
|
+
* empty — unless {@link envSeed} supplies one. No generated fallback: an omitted
|
|
49
|
+
* seed is not a second source of entropy beside the instance clock.
|
|
53
50
|
*/
|
|
54
51
|
export declare function normalizeSeed(seed: Seed | undefined): ReadonlyArray<string>;
|
|
55
52
|
/**
|
|
56
53
|
* Tag a seed as composing onto whatever base is in effect, rather than
|
|
57
|
-
* replacing it — the reading a bare `seed` has everywhere else in this
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* the symbol.
|
|
54
|
+
* replacing it — the reading a bare `seed` has everywhere else in this library.
|
|
55
|
+
* Mirrors `replace()`'s `[Replace]` tagging: the `[Layer]` directive is read
|
|
56
|
+
* (and, at every level that accepts one, consumed) by whoever resolves the seed
|
|
57
|
+
* against its base, so a caller never names the symbol.
|
|
62
58
|
*/
|
|
63
59
|
export declare function layer(seed: Seed): Layered;
|
|
64
60
|
export declare function isLayered(value: unknown): value is Layered;
|
|
65
61
|
/**
|
|
66
62
|
* Collapse a caller-facing {@link Attribution} to the
|
|
67
|
-
* {@link ResolvedAttribution} the stream machinery uses. `"call site"`
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* whichever
|
|
74
|
-
* internal mechanism happened to trigger a fork.
|
|
63
|
+
* {@link ResolvedAttribution} the stream machinery uses. `"call site"` must
|
|
64
|
+
* resolve _here_, and only here: `resolveCallerFile()` reads the live stack,
|
|
65
|
+
* and `toRandomSource` runs synchronously inside `initialize()`, so this is the
|
|
66
|
+
* one moment the first external frame genuinely is the file that called
|
|
67
|
+
* `initialize()`. Resolving lazily — on first construction, or again inside
|
|
68
|
+
* `fork` — would capture whichever file happened to call `new Fabricator(...)`,
|
|
69
|
+
* or whichever internal mechanism happened to trigger a fork.
|
|
75
70
|
*
|
|
76
|
-
* A directory, not the file itself, becomes the root: rooting at the
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
71
|
+
* A directory, not the file itself, becomes the root: rooting at the file would
|
|
72
|
+
* relativize that one file to `""` while every sibling still carried a full
|
|
73
|
+
* relative path from a directory one level up, an arbitrary asymmetry with no
|
|
74
|
+
* reason to prefer it.
|
|
80
75
|
*/
|
|
81
76
|
export declare function resolveAttribution(attribution: Attribution | undefined): ResolvedAttribution;
|
|
82
77
|
export declare function toStream(algorithm: Algorithm, seed: string): Stream;
|
|
83
78
|
/**
|
|
84
79
|
* A leaf's stream: `toStream(algorithm, encode(trace))`. This is the
|
|
85
|
-
* composition that
|
|
80
|
+
* composition that _defines_ a leaf's stream seed — the invariant
|
|
86
81
|
* `toStream(algorithm, encode(trace)).seed === stream.seed`. Not a
|
|
87
|
-
* {@link RandomSource} member: derivation depends on no per-source
|
|
88
|
-
*
|
|
89
|
-
*
|
|
82
|
+
* {@link RandomSource} member: derivation depends on no per-source state (a
|
|
83
|
+
* fork shares only the algorithm), so it is a free function of `(algorithm,
|
|
84
|
+
* trace)`. `toRoot` is the only stateful member.
|
|
90
85
|
*
|
|
91
|
-
* {@link deriveClock} cannot route through this: a {@link Trace}
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* never collide with `encode`'s seven.
|
|
86
|
+
* {@link deriveClock} cannot route through this: a {@link Trace} carries
|
|
87
|
+
* `clock`, and `deriveClock` is what produces it. That circularity is why
|
|
88
|
+
* `deriveClock` stays below the `RandomSource`/`Trace` layer, with a
|
|
89
|
+
* two-element encoding that can never collide with `encode`'s seven.
|
|
96
90
|
*/
|
|
97
91
|
export declare function toStreamFromTrace(algorithm: Algorithm, trace: Trace): Stream;
|
|
98
92
|
/**
|
|
99
|
-
* Create a fresh, self-contained {@link RandomSource} — the randomness
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* `fork` threads it forward unchanged.
|
|
93
|
+
* Create a fresh, self-contained {@link RandomSource} — the randomness state a
|
|
94
|
+
* single `initialize()` instance owns for its lifetime. `options.clock` is
|
|
95
|
+
* baked in here, once, as a plain number — the `"seeded"` policy is already
|
|
96
|
+
* resolved by the caller (`Instance/Core.ts`'s `resolveClock`) before a source
|
|
97
|
+
* is ever built, so every root this source resolves carries the identical
|
|
98
|
+
* instant, and `fork` threads it forward unchanged.
|
|
106
99
|
*/
|
|
107
100
|
export declare function toRandomSource(options: Options): RandomSource;
|
|
@@ -3,25 +3,23 @@ import type { Kind as SchemaKind } from "../Primitive";
|
|
|
3
3
|
import { Adaptation, Kind, Meta, type Produces } from "../Types";
|
|
4
4
|
import { type PlainObject } from "../Utility/Types";
|
|
5
5
|
/**
|
|
6
|
-
* Normalize a Schema, a builder namespace, or an already-built
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* interchangeably while only ever storing inert data: a built
|
|
6
|
+
* Normalize a Schema, a builder namespace, or an already-built Fabricator into
|
|
7
|
+
* a clean, storable Schema — keeping only `[Kind]`/ `[Meta]`/`[Adaptation]` and
|
|
8
|
+
* discarding `fabricate` and any builder-method properties. This is what lets
|
|
9
|
+
* `object`/`array` fields, and registry `.extend()` registrations, accept any
|
|
10
|
+
* of the three interchangeably while only ever storing inert data: a built
|
|
12
11
|
* Fabricator's `[Meta]` is exactly the Schema it came from.
|
|
13
12
|
*
|
|
14
|
-
* `[Adaptation]` is carried rather than dropped because it is a
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* `Adapter/TypeBox`'s `build`, which walks `[Meta].definition`).
|
|
13
|
+
* `[Adaptation]` is carried rather than dropped because it is a property of the
|
|
14
|
+
* schema itself, not of the builder that produced it: a field adapted with
|
|
15
|
+
* `.adapt(adapter, produce)` has to still be adapted once normalized into its
|
|
16
|
+
* enclosing `object`/`array`, which is where every adapter actually reads it
|
|
17
|
+
* from (see `Adapter/TypeBox`'s `build`, which walks `[Meta].definition`).
|
|
20
18
|
*
|
|
21
|
-
* `$SchemaProduces` is threaded through in the type only (never read
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* `$SchemaProduces` is threaded through in the type only (never read or written
|
|
20
|
+
* at runtime) so `ValueOf` stays precise across a `toSchema` call — dropping it
|
|
21
|
+
* would make every normalized field (e.g. every `object`/`array` element) fall
|
|
22
|
+
* back to `unknown`.
|
|
25
23
|
*/
|
|
26
24
|
export declare function toSchema<$Kind extends string, $Meta extends PlainObject, $Produces = unknown, $Adaptations extends Adaptations = Adaptations>(value: {
|
|
27
25
|
[Kind]: $Kind;
|
|
@@ -35,10 +33,10 @@ export declare function toSchema<$Kind extends string, $Meta extends PlainObject
|
|
|
35
33
|
readonly [Adaptation]?: $Adaptations;
|
|
36
34
|
};
|
|
37
35
|
/**
|
|
38
|
-
* Whether `value`'s basic JS shape is compatible with `kind` (one of
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
36
|
+
* Whether `value`'s basic JS shape is compatible with `kind` (one of this
|
|
37
|
+
* library's `[Kind]` literals, e.g. `"string"`, `"object"`, `"date"`). Stops at
|
|
38
|
+
* "is this the right _kind of value_" (right JS type/shape), not deeper schema
|
|
39
|
+
* constraints like a number's `whereby` range, a string's length, or a
|
|
40
|
+
* weighted-enum's member set.
|
|
43
41
|
*/
|
|
44
42
|
export declare function violatesKind(kind: SchemaKind, value: unknown): boolean;
|
|
@@ -2,9 +2,9 @@ import * as primitives from "../Primitive";
|
|
|
2
2
|
import { deepMerge, type DeepMerge } from "../Utility/DeepMerge";
|
|
3
3
|
import { type PlainObject } from "../Utility/Types";
|
|
4
4
|
/**
|
|
5
|
-
* `Primitive/index.ts` also exports the kind-module namespace as
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* `Primitive/index.ts` also exports the kind-module namespace as `Primitive`
|
|
6
|
+
* (`Primitive.boolean.Schema`, …). That is not a builder — omitting it here is
|
|
7
|
+
* what keeps `T.Primitive` from existing.
|
|
8
8
|
*/
|
|
9
9
|
type Builders = Omit<typeof primitives, "Primitive">;
|
|
10
10
|
type RegistryInterface<$Registry> = {
|
|
@@ -3,13 +3,12 @@ import type { Kind as SchemaKind } from "../Primitive";
|
|
|
3
3
|
import type { Adaptation, Kind, Meta, Produces } from "../Types";
|
|
4
4
|
import type { PlainObject } from "../Utility/Types";
|
|
5
5
|
/**
|
|
6
|
-
* The broadest Schema constraint: some kind, some config. Used by
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
-
* for the same reason.
|
|
6
|
+
* The broadest Schema constraint: some kind, some config. Used by compound
|
|
7
|
+
* kinds (`object`/`array`) for their nested fields instead of the library-wide
|
|
8
|
+
* Schema union `Primitive/index.ts` assembles — that union imports every kind's
|
|
9
|
+
* `Core.ts`, so importing it back from within a kind's own `Core.ts` would
|
|
10
|
+
* cycle. Mirrors how `array.Definition` uses the equally generic
|
|
11
|
+
* `NaiveFabricator<any>` for the same reason.
|
|
13
12
|
*/
|
|
14
13
|
export type AnySchema = {
|
|
15
14
|
[Kind]: SchemaKind;
|
|
@@ -17,51 +16,45 @@ export type AnySchema = {
|
|
|
17
16
|
[Adaptation]?: Adaptations;
|
|
18
17
|
};
|
|
19
18
|
/**
|
|
20
|
-
* Extract the value a Schema fabricates to, via the phantom,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* keys for why that matters).
|
|
19
|
+
* Extract the value a Schema fabricates to, via the phantom, runtime-absent
|
|
20
|
+
* `[Produces]` marker every kind's `Schema` carries. This is what lets
|
|
21
|
+
* `object`/`array`'s per-field type extraction work uniformly across every kind
|
|
22
|
+
* without importing and enumerating them (which would cycle, since
|
|
23
|
+
* `object`/`array` can nest any kind, including each other) — the same role
|
|
24
|
+
* `fabricate: () => $T` already plays for `NaiveFabricator<infer $T>`, one step
|
|
25
|
+
* earlier, before a Schema has been built. `[Produces]` is always optional
|
|
26
|
+
* (never assigned at runtime — see `DeepMerge`'s handling of optional-only keys
|
|
27
|
+
* for why that matters).
|
|
30
28
|
*
|
|
31
|
-
* `$Bindings` is threaded down into every composite kind's children
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* later without restructuring, though nothing today defines what that
|
|
46
|
-
* would mean. `test/ValueOfBindings.types.test.ts` is the only thing
|
|
47
|
-
* asserting any of it.
|
|
29
|
+
* `$Bindings` is threaded down into every composite kind's children (each
|
|
30
|
+
* `Core` is an `interface` carrying an optional `bindings`, and forwards
|
|
31
|
+
* `NonNullable<this["bindings"]>` into its own `[Produces]`). It is a
|
|
32
|
+
* substitution slot for a self-reference, not a parameter of the schema the way
|
|
33
|
+
* `$Definition`/`$Value` are — every composite forwards it unread, so whatever
|
|
34
|
+
* `self` node is buried arbitrarily deep still receives it. A node whose
|
|
35
|
+
* `[Produces]` reads `bindings[0]` (`recursive.self.Core`) can then close a
|
|
36
|
+
* type-level fixed point, which is what makes a self-referential schema resolve
|
|
37
|
+
* rather than collapse to `unknown`. Mirrors TypeBox's `Static<T, P> = (T & {
|
|
38
|
+
* params: P })['static']`, renamed because "params" reads as configuration and
|
|
39
|
+
* this is closer to a de-Bruijn-style resolution environment — kept as a tuple,
|
|
40
|
+
* as TypeBox's is, so a second bound self-reference could occupy index 1 later
|
|
41
|
+
* without restructuring, though nothing today defines what that would mean.
|
|
42
|
+
* `test/ValueOfBindings.types.test.ts` is the only thing asserting any of it.
|
|
48
43
|
*
|
|
49
44
|
* Three details here are load-bearing, and each looks simplifiable:
|
|
50
45
|
*
|
|
51
|
-
* - **Indexed access, not a conditional `infer`.** Writing this as
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* - **`Required<>`, never `Exclude<..., undefined>`.** Both strip the
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* `nullish`/`undefinable`/`object.optional`/`undefined`'s own value
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* variance enough to break `.as`'s contravariant parameter check in
|
|
64
|
-
* `Fabrication.types.test.ts`.
|
|
46
|
+
* - **Indexed access, not a conditional `infer`.** Writing this as `($Schema & {
|
|
47
|
+
* bindings: $Bindings }) extends { [Produces]?: infer $T } ? ...` fails with
|
|
48
|
+
* `TS2615` — the bindings do not collapse, and the error surfaces as
|
|
49
|
+
* `unknown[] & [...]`.
|
|
50
|
+
* - **`Required<>`, never `Exclude<..., undefined>`.** Both strip the `|
|
|
51
|
+
* undefined` that indexing an optional property adds, but `Exclude` also
|
|
52
|
+
* strips the _legitimate_ `undefined` out of
|
|
53
|
+
* `nullish`/`undefinable`/`object.optional`/`undefined`'s own value types.
|
|
54
|
+
* - **The `extends` guard belongs inside, not on the parameter.** Constraining
|
|
55
|
+
* `$Schema` instead would force `[Produces]` onto `AnySchema` (which
|
|
56
|
+
* deliberately omits it), and that shifts variance enough to break `.as`'s
|
|
57
|
+
* contravariant parameter check in `Fabrication.types.test.ts`.
|
|
65
58
|
*/
|
|
66
59
|
export type ValueOf<$Schema, $Bindings extends unknown[] = []> = $Schema extends {
|
|
67
60
|
readonly [Produces]?: unknown;
|
package/dist/types/Types.d.ts
CHANGED
|
@@ -6,60 +6,55 @@ export declare const Produces: unique symbol;
|
|
|
6
6
|
export declare const Replace: unique symbol;
|
|
7
7
|
export declare const Fixed: unique symbol;
|
|
8
8
|
/**
|
|
9
|
-
* Tags a `Seed` as composing onto whatever base is in effect, rather
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* Tags a `Seed` as composing onto whatever base is in effect, rather than
|
|
10
|
+
* replacing it — the reading a bare `seed` has everywhere else in this library.
|
|
11
|
+
* `layer()` (`Random/index.ts`) is the only producer; a caller never names this
|
|
12
|
+
* symbol, mirroring `[Replace]`. Unlike every other symbol in this file, it
|
|
13
|
+
* tags a config value (a `Seed`), not a Schema or Fabricator — see
|
|
14
|
+
* `Random/Types.ts`'s `Layered`.
|
|
15
15
|
*/
|
|
16
16
|
export declare const Layer: unique symbol;
|
|
17
17
|
/**
|
|
18
|
-
* The Fabricators that exist at build time — whatever
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `[Meta].items` order — weights stay in `[Meta]`), `array` (the single
|
|
18
|
+
* The Fabricators that exist at build time — whatever `Constructor.ts`'s `make`
|
|
19
|
+
* already constructed for this node's nested schemas before handing them to the
|
|
20
|
+
* kind's own `Fabricator()` factory. Every composite kind whose construction
|
|
21
|
+
* receives already-dispatched Fabricators carries this: `object` (its `Fields`
|
|
22
|
+
* map), `tuple` (`elements`, in slot order), `choice` (the dispatched options,
|
|
23
|
+
* in `[Meta].items` order — weights stay in `[Meta]`), `array` (the single
|
|
25
24
|
* shared `element`), `record` (`{ key, value }`), and each of
|
|
26
|
-
* `nullable`/`nullish`/`undefinable`/`object.omittable`/`object.optional`
|
|
27
|
-
*
|
|
25
|
+
* `nullable`/`nullish`/`undefinable`/`object.omittable`/`object.optional` (the
|
|
26
|
+
* single wrapped `source`).
|
|
28
27
|
*
|
|
29
|
-
* The payload shape is kind-private, exactly as `[Meta]` is — nothing
|
|
30
|
-
*
|
|
31
|
-
* shape.
|
|
28
|
+
* The payload shape is kind-private, exactly as `[Meta]` is — nothing outside a
|
|
29
|
+
* kind's own files interprets another kind's `[Children]` shape.
|
|
32
30
|
*
|
|
33
|
-
* `recursive` carries none: its expansions are a function of draws
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* introspect them.
|
|
31
|
+
* `recursive` carries none: its expansions are a function of draws made
|
|
32
|
+
* _during_ `fabricate()` (`recursive/Fabricator.ts`), one throwaway Fabricator
|
|
33
|
+
* per `self` occurrence, so there is no stable child at build time to point at.
|
|
34
|
+
* `body`/`terminal` are already on `[Meta]` as ordinary sub-Schemas for
|
|
35
|
+
* anything that needs to introspect them.
|
|
39
36
|
*/
|
|
40
37
|
export declare const Children: unique symbol;
|
|
41
38
|
/**
|
|
42
|
-
* A per-library map of external-schema overrides
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* for the registry of supported libraries, and `Adapter/TypeBox`'s
|
|
39
|
+
* A per-library map of external-schema overrides (`{ typebox: (schema) =>
|
|
40
|
+
* TSchema }`), written by every kind's `.adapt(adapter, produce)` builder
|
|
41
|
+
* method and read only by `src/Adapter/*` — completely inert for fabrication,
|
|
42
|
+
* which never looks at it. A map rather than a single function so one schema
|
|
43
|
+
* can map to several external libraries at once; see `Adapter/Types.ts` for the
|
|
44
|
+
* registry of supported libraries, and `Adapter/TypeBox`'s
|
|
49
45
|
* `ToTypeBox`/`convert` for the reading end.
|
|
50
46
|
*/
|
|
51
47
|
export declare const Adaptation: unique symbol;
|
|
52
48
|
/**
|
|
53
|
-
* A public sentinel with two uses that share one meaning — "this key
|
|
54
|
-
*
|
|
55
|
-
* `object.optional`'s Fabricators return it internally when their roll
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* `Primitive/undefined`, and `Primitive/object/optional`, which
|
|
49
|
+
* A public sentinel with two uses that share one meaning — "this key does not
|
|
50
|
+
* appear in the fabricated object": `object.omittable`'s and
|
|
51
|
+
* `object.optional`'s Fabricators return it internally when their roll lands on
|
|
52
|
+
* absence (read by `object/Fabricator.ts`'s fabricate loop, never surfaced to a
|
|
53
|
+
* caller fabricating normally), and it is also the value a caller passes in
|
|
54
|
+
* `.override(...)`/`.fabricate(overrides)` to force an omittable or optional
|
|
55
|
+
* field off — `{ a: undefined }` present-as-`undefined` is not expressible this
|
|
56
|
+
* way, since that would conflate with a genuinely present-but-`undefined` value
|
|
57
|
+
* (see `Primitive/undefined`, and `Primitive/object/optional`, which
|
|
63
58
|
* distinguishes the two outcomes).
|
|
64
59
|
*/
|
|
65
60
|
export declare const Omitted: unique symbol;
|
|
@@ -70,9 +65,8 @@ export declare const Omitted: unique symbol;
|
|
|
70
65
|
export type Buildable = AnySchema | Fabricator<any>;
|
|
71
66
|
/**
|
|
72
67
|
* The span of valid `Date` time values: ±8.64e15 ms from the epoch. An
|
|
73
|
-
* ECMAScript spec fact (`Date`'s own representable range), not a
|
|
74
|
-
*
|
|
75
|
-
* `
|
|
76
|
-
* `Primitive/`.
|
|
68
|
+
* ECMAScript spec fact (`Date`'s own representable range), not a `date`-kind
|
|
69
|
+
* detail — lives here rather than in `Primitive/date/` so `Random/index.ts`'s
|
|
70
|
+
* `deriveClock` can use it without importing from `Primitive/`.
|
|
77
71
|
*/
|
|
78
72
|
export declare const MAX_TIME = 8640000000000000;
|
|
@@ -5,30 +5,39 @@ import { type PlainObject } from "./Types";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function inline<$T>(fn: () => $T): $T;
|
|
7
7
|
export declare function never(_: never): never;
|
|
8
|
+
/**
|
|
9
|
+
* Does nothing, deliberately. For attaching a settled handler to a promise
|
|
10
|
+
* being abandoned, so it cannot surface as an unhandled rejection.
|
|
11
|
+
*/
|
|
12
|
+
export declare function noop(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a value is thenable — the structural test, not `instanceof Promise`,
|
|
15
|
+
* since an `async` function's return may be any conforming implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
|
|
8
18
|
/**
|
|
9
19
|
* @see https://github.com/microsoft/TypeScript/issues/17002
|
|
10
20
|
*/
|
|
11
21
|
export declare function isArray(candidate: unknown): candidate is Array<unknown> | ReadonlyArray<unknown>;
|
|
12
22
|
export declare function isPollutionKey(key: string): boolean;
|
|
13
23
|
/**
|
|
14
|
-
* A plain `{}`/`Object.create(null)` object — not an array, `Date`,
|
|
15
|
-
*
|
|
24
|
+
* A plain `{}`/`Object.create(null)` object — not an array, `Date`, class
|
|
25
|
+
* instance, etc.
|
|
16
26
|
*/
|
|
17
27
|
export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
18
28
|
/**
|
|
19
29
|
* Keys worth carrying across a merge. String keys are subject to the
|
|
20
30
|
* prototype-pollution guard; symbol keys (e.g. a fabricator's
|
|
21
31
|
* `[Kind]`/`[Meta]`) are carried through — dropping them would strip a
|
|
22
|
-
* primitive's identity when it is extended — except `Replace`, which is
|
|
23
|
-
*
|
|
32
|
+
* primitive's identity when it is extended — except `Replace`, which is a
|
|
33
|
+
* directive consumed here rather than data to propagate.
|
|
24
34
|
*/
|
|
25
35
|
export declare function mergeableKeys(source: PlainObject): Array<string | symbol>;
|
|
26
36
|
/**
|
|
27
|
-
* Tag an object so a subsequent deep or shallow merge replaces the
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* naming the symbol.
|
|
37
|
+
* Tag an object so a subsequent deep or shallow merge replaces the left-hand
|
|
38
|
+
* operand wholesale instead of merging into it. The `[Replace]` directive is
|
|
39
|
+
* consumed by the merge and does not appear on the result, so callers can wrap
|
|
40
|
+
* a replacement value without ever naming the symbol.
|
|
32
41
|
*/
|
|
33
42
|
export declare function replace<$T extends PlainObject>(value: $T): $T & {
|
|
34
43
|
[Replace]: true;
|