@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
|
@@ -17,29 +17,27 @@ export type Fabricator<$Schema extends {
|
|
|
17
17
|
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
18
18
|
/**
|
|
19
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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* verbatim.
|
|
20
|
+
* — read only by `object/Fabricator.ts`'s fabricate loop, which omits the key
|
|
21
|
+
* entirely rather than writing `undefined`. A "present as `undefined`" roll
|
|
22
|
+
* returns `undefined` directly, which the loop assigns like any ordinary
|
|
23
|
+
* value — the difference from `object.omittable`. Fabricating this outside a
|
|
24
|
+
* parent `object` hands whichever of the three results back verbatim.
|
|
26
25
|
*/
|
|
27
26
|
fabricate: () => Resolved<$Schema[typeof Meta]["definition"]>;
|
|
28
27
|
};
|
|
29
28
|
export declare function isObjectOptionalFabricator(candidate: BaseFabricator<unknown>): candidate is Fabricator;
|
|
30
29
|
/**
|
|
31
|
-
* Three-way roll: omitted, present-as-`undefined`, or the wrapped value —
|
|
32
|
-
*
|
|
30
|
+
* Three-way roll: omitted, present-as-`undefined`, or the wrapped value — on
|
|
31
|
+
* this field's private stream; `source` is drawn only when "value" wins.
|
|
33
32
|
* Uniform (1/3 each) by default; not achievable by composing
|
|
34
|
-
* `object.omittable(T.undefinable(inner))`'s two independent 50/50 rolls
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* CLAUDE.md's "Randomness").
|
|
33
|
+
* `object.omittable(T.undefinable(inner))`'s two independent 50/50 rolls (that
|
|
34
|
+
* is 50/25/25, not 33/33/33), hence the dedicated three-way `weighted()` here —
|
|
35
|
+
* see CLAUDE.md's "Why `T.optional` isn't `omittable(undefinable(inner))`"
|
|
36
|
+
* under "Compound / field-only kinds". `.weighted(...)` (`Schema.ts`) reweights
|
|
37
|
+
* individual outcomes relative to that same default of `1`; an unspecified
|
|
38
|
+
* outcome keeps it. Skipping `source`'s draw on the two non-"value" outcomes is
|
|
39
|
+
* safe for the same reason as `object/omittable/Fabricator.ts`: `source`
|
|
40
|
+
* already has its own independent stream, minted at build time regardless of
|
|
41
|
+
* this roll (see CLAUDE.md's "Randomness").
|
|
44
42
|
*/
|
|
45
43
|
export declare function Fabricator<$Definition extends Definition>(context: FabricatorContext<Schema<$Definition>>, source: BaseFabricator<any>): Fabricator<Schema<$Definition>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The three outcomes an optional field's roll can land on. Also the key
|
|
3
|
-
*
|
|
2
|
+
* The three outcomes an optional field's roll can land on. Also the key space
|
|
3
|
+
* `.weighted(...)` weighs — see `Types.ts`'s `Weights`.
|
|
4
4
|
*
|
|
5
5
|
* Lives here rather than `Types.ts` so that file stays type-only (see
|
|
6
6
|
* `boolean/Outcomes.ts`).
|
|
@@ -8,8 +8,8 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
|
|
|
8
8
|
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
9
9
|
* `definition` forward, not discarding it, so a later `.as(...)` (or future
|
|
10
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
|
-
*
|
|
11
|
+
* return `undefined` or `Omitted`, so custom logic composes the same way the
|
|
12
|
+
* built-in three-way roll does.
|
|
13
13
|
*/
|
|
14
14
|
as: (produce: Produce<Resolved<$Definition>>) => Schema<$Definition, $Adaptations>;
|
|
15
15
|
/**
|
|
@@ -23,8 +23,8 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
|
|
|
23
23
|
*/
|
|
24
24
|
weighted: (weights: Weights) => Schema<$Definition, $Adaptations>;
|
|
25
25
|
/**
|
|
26
|
-
* Override what this schema maps to in one or more external schema
|
|
27
|
-
*
|
|
26
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
27
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
28
28
|
*/
|
|
29
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
30
|
}
|
|
@@ -11,33 +11,33 @@ export type Definition = AnySchema;
|
|
|
11
11
|
* The value an optional field's key holds when present at all — the wrapped
|
|
12
12
|
* value, or `undefined` (present-as-`undefined` is one of three outcomes,
|
|
13
13
|
* distinct from the key not appearing). Flows through `[Produces]` into
|
|
14
|
-
* `object/Types.ts`'s per-field type, so a `T.optional`-wrapped field types
|
|
15
|
-
*
|
|
16
|
-
* covers this kind)
|
|
14
|
+
* `object/Types.ts`'s per-field type, so a `T.optional`-wrapped field types as
|
|
15
|
+
* `{ a?: T | undefined }` — a real `?:` (from `OmittableKeys`, which also
|
|
16
|
+
* covers this kind) _and_ a real `| undefined`.
|
|
17
17
|
*/
|
|
18
18
|
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = ValueOf<$Definition, $Bindings> | undefined;
|
|
19
19
|
/**
|
|
20
|
-
* What an optional field's Fabricator returns: the wrapped value,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* What an optional field's Fabricator returns: the wrapped value, `undefined`,
|
|
21
|
+
* or `Omitted` when the key should not appear — whether from the built-in
|
|
22
|
+
* three-way roll or, via `.as(...)`, an opaque producer.
|
|
23
23
|
*/
|
|
24
24
|
export type Resolved<$Definition extends Definition> = Fabricated<$Definition> | typeof Omitted;
|
|
25
25
|
export type { Outcome } from "./Outcomes";
|
|
26
26
|
/**
|
|
27
|
-
* Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional —
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional — an
|
|
28
|
+
* omitted key falls back to baseline `1`, the same weight the uniform 1/3 split
|
|
29
|
+
* already uses. Values are relative, exactly like `weighted()`
|
|
30
30
|
* (`Distribution/index.ts`) — they need not sum to one, and are fed to
|
|
31
31
|
* `weighted()` unchanged alongside each unspecified key's baseline `1`.
|
|
32
32
|
*
|
|
33
|
-
* Specifying one outcome's weight shifts
|
|
34
|
-
* probability, not just the named one — unspecified ones stay at weight `1`
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
33
|
+
* Specifying one outcome's weight shifts _every_ outcome's resulting
|
|
34
|
+
* probability, not just the named one — unspecified ones stay at weight `1` but
|
|
35
|
+
* their share of the total still moves, since the total changed. `.weighted({
|
|
36
|
+
* omitted: 0.1 })` on `T.optional` is not "10% omitted, other two still 33%" —
|
|
37
|
+
* with `undefined`/`value` at default `1`, the split is `0.1 / 2.1 ≈ 4.8%`
|
|
38
|
+
* omitted and `≈47.6%` each for the other two. No independent "absolute
|
|
39
|
+
* probability" mode; weights are only meaningful relative to the full set in
|
|
40
|
+
* play.
|
|
41
41
|
*/
|
|
42
42
|
export type Weights = {
|
|
43
43
|
omitted: number;
|
|
@@ -5,8 +5,8 @@ import { Schema } from "./Schema";
|
|
|
5
5
|
* instance — produced by `produce` and typed as whatever it returns, so
|
|
6
6
|
* `T.opaque((random) => new Map<string, number>())` needs no annotation.
|
|
7
7
|
*
|
|
8
|
-
* `produce` receives this schema's own seeded stream, so an opaque value
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* `produce` receives this schema's own seeded stream, so an opaque value still
|
|
9
|
+
* replays from a seed; see `Types.ts`'s `Produce`. No bare form and no `.as()`
|
|
10
|
+
* — `produce` is the whole schema.
|
|
11
11
|
*/
|
|
12
12
|
export default function <$T>(produce: Produce<$T>): Schema<$T>;
|
|
@@ -2,20 +2,19 @@ import { type AdaptationEntry } from "../../Adapter/Core";
|
|
|
2
2
|
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
|
|
3
3
|
import type { Core } from "./Types";
|
|
4
4
|
/**
|
|
5
|
-
* Escape hatch for values no kind models — a `Map`, a `Set`, a `URL`, a
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Escape hatch for values no kind models — a `Map`, a `Set`, a `URL`, a class
|
|
6
|
+
* instance, a branded type. `produce` is supplied at construction and receives
|
|
7
|
+
* the schema's own seeded stream (`Types.ts`'s `Produce`).
|
|
8
8
|
*
|
|
9
9
|
* No `.as()`, for `always`'s reason: the constructor argument already fully
|
|
10
|
-
* determines production. `adapt` matters more here than for any other kind
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* more.
|
|
10
|
+
* determines production. `adapt` matters more here than for any other kind — an
|
|
11
|
+
* opaque value maps to TypeBox's `Unknown`, which is honest but maximally
|
|
12
|
+
* imprecise, and `.adapt(typebox, ...)` is the only way to say more.
|
|
14
13
|
*/
|
|
15
14
|
export interface Schema<$T = unknown, $Adaptations extends Adaptations = {}> extends Core<$T, $Adaptations> {
|
|
16
15
|
/**
|
|
17
|
-
* Override what this schema maps to in one or more external schema
|
|
18
|
-
*
|
|
16
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
17
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
19
18
|
*/
|
|
20
19
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$T, $Adaptations>>) => $Returnable) => Schema<$T, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
21
20
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import type { Produce } from "../../Random/Types";
|
|
2
2
|
import { Schema } from "./Schema";
|
|
3
3
|
import type { Fabricated, Key, Value, Whereby } from "./Types";
|
|
4
|
-
|
|
4
|
+
type ThisRegistry<$Key extends Key, $Value extends Value> = {
|
|
5
5
|
/**
|
|
6
6
|
* A record of `value` keyed by `key`, attempted `whereby.size` times —
|
|
7
|
-
* uniformly across `[size.minTried, size.max]` (with `minTried`
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* uniformly across `[size.minTried, size.max]` (with `minTried` defaulting to
|
|
8
|
+
* 0). Colliding keys collapse, so the result holds _at most_ that many
|
|
9
|
+
* entries; see `Types.ts`'s `Whereby`.
|
|
10
10
|
*/
|
|
11
11
|
whereby: (whereby: Whereby) => Schema<$Key, $Value>;
|
|
12
12
|
/**
|
|
13
|
-
* A record whose production is `produce`, in full, instead of drawn
|
|
14
|
-
* entry
|
|
13
|
+
* A record whose production is `produce`, in full, instead of drawn entry by
|
|
14
|
+
* entry.
|
|
15
15
|
*/
|
|
16
16
|
as: (produce: Produce<Fabricated<$Key, $Value>>) => Schema<$Key, $Value>;
|
|
17
17
|
};
|
|
18
|
+
export default function <const $Key extends Key, const $Value extends Value>(key: $Key, value: $Value): ThisRegistry<$Key, $Value>;
|
|
19
|
+
export {};
|
|
@@ -3,24 +3,22 @@ import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adap
|
|
|
3
3
|
import type { Produce } from "../../Random/Types";
|
|
4
4
|
import type { Core, Fabricated, Key, Value } from "./Types";
|
|
5
5
|
/**
|
|
6
|
-
* The buildable recipe for a `record`: a key Schema and a value Schema,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The buildable recipe for a `record`: a key Schema and a value Schema, drawn
|
|
7
|
+
* `whereby.size` times. `array`'s sibling — one repeated value shape and a
|
|
8
|
+
* fuzzed count — but keyed rather than indexed.
|
|
9
9
|
*/
|
|
10
10
|
export interface Schema<$Key extends Key = Key, $Value extends Value = Value, $Adaptations extends Adaptations = {}> extends Core<$Key, $Value, $Adaptations> {
|
|
11
11
|
/**
|
|
12
12
|
* Layer an opaque production on this schema's existing `[Meta]` — carrying
|
|
13
|
-
* `whereby`/`key`/`value` forward, not discarding them, so a later
|
|
14
|
-
*
|
|
15
|
-
* against.
|
|
13
|
+
* `whereby`/`key`/`value` forward, not discarding them, so a later `.as(...)`
|
|
14
|
+
* (or future validation of `produce`) still has them to check against.
|
|
16
15
|
*/
|
|
17
16
|
as: (produce: Produce<Fabricated<$Key, $Value>>) => Schema<$Key, $Value, $Adaptations>;
|
|
18
17
|
/**
|
|
19
|
-
* Override what this schema maps to in one or more external schema
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* one a mapping.
|
|
18
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
19
|
+
* — see `string/Schema.ts`'s `adapt`. Particularly relevant here: a
|
|
20
|
+
* symbol-keyed record has no TypeBox counterpart (`Adapter/TypeBox`'s
|
|
21
|
+
* `record` case), so this is the only way to give one a mapping.
|
|
24
22
|
*/
|
|
25
23
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Key, $Value, $Adaptations>>) => $Returnable) => Schema<$Key, $Value, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
26
24
|
}
|
|
@@ -5,37 +5,37 @@ import { Produces, type Adaptation, type Kind, type Meta } from "../../Types";
|
|
|
5
5
|
/**
|
|
6
6
|
* A Schema usable as a record's keys: any Schema whose fabricated value is a
|
|
7
7
|
* legal JS property key. Constrained through the phantom `[Produces]` marker
|
|
8
|
-
* rather than by enumerating kinds, so any current or future key-producing
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* rather than by enumerating kinds, so any current or future key-producing kind
|
|
9
|
+
* qualifies — `T.string.whereby(...)`, `T.symbol`, `T.enum.uniform([...])` of
|
|
10
|
+
* strings, `T.always("k")`, a string `T.choice` — while `T.number`/`T.date` are
|
|
11
|
+
* rejected at the call site.
|
|
12
12
|
*
|
|
13
|
-
* `symbol` is included deliberately: symbols are legal property keys.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* `symbol` is included deliberately: symbols are legal property keys. Excluding
|
|
14
|
+
* them would arbitrarily narrow what a record can describe. They do not survive
|
|
15
|
+
* `Adapter/TypeBox` — see its `record` case.
|
|
16
16
|
*/
|
|
17
17
|
export type Key = AnySchema & {
|
|
18
18
|
readonly [Produces]?: string | symbol;
|
|
19
19
|
};
|
|
20
20
|
export type Value = AnySchema;
|
|
21
21
|
/**
|
|
22
|
-
* Whether a key type spans a whole primitive key type rather than a finite
|
|
23
|
-
*
|
|
22
|
+
* Whether a key type spans a whole primitive key type rather than a finite set
|
|
23
|
+
* of literals — i.e. whether the record's keyspace is open-ended.
|
|
24
24
|
*/
|
|
25
25
|
type IsKeyspaceOpen<$Key> = string extends $Key ? true : symbol extends $Key ? true : false;
|
|
26
26
|
/**
|
|
27
|
-
* Split is
|
|
27
|
+
* Split is _open keyspace vs. finite_, not string vs. symbol.
|
|
28
28
|
*
|
|
29
29
|
* An open key (`string`, `symbol`, or both) is a plain index signature: no
|
|
30
30
|
* `Partial` — an index signature never guarantees a key is present, and
|
|
31
31
|
* wrapping one would only add a spurious `| undefined`. Carrying
|
|
32
|
-
* `ValueOf<$Key>` rather than hardcoding `string` keeps a mixed
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* `ValueOf<$Key>` rather than hardcoding `string` keeps a mixed `string |
|
|
33
|
+
* symbol` key as `Record<string | symbol, ...>` instead of silently dropping
|
|
34
|
+
* the symbol half.
|
|
35
35
|
*
|
|
36
36
|
* A finite literal key set (`enum`/`always`/`choice`) is `Partial`: size is
|
|
37
|
-
* drawn from `whereby.size`, and colliding keys collapse (`Fabricator.ts`),
|
|
38
|
-
*
|
|
37
|
+
* drawn from `whereby.size`, and colliding keys collapse (`Fabricator.ts`), so
|
|
38
|
+
* a two-member key schema may produce only one. Every key present wants
|
|
39
39
|
* `T.object({ ... })` — what a record over a finite key set degenerates to.
|
|
40
40
|
*/
|
|
41
41
|
export type Fabricated<$Key extends Key = Key, $Value extends Value = Value, $Bindings extends unknown[] = []> = IsKeyspaceOpen<ValueOf<$Key, $Bindings>> extends true ? Record<ValueOf<$Key, $Bindings> & PropertyKey, ValueOf<$Value, $Bindings>> : Partial<Record<ValueOf<$Key, $Bindings> & PropertyKey, ValueOf<$Value, $Bindings>>>;
|
|
@@ -43,13 +43,13 @@ export type Fabricated<$Key extends Key = Key, $Value extends Value = Value, $Bi
|
|
|
43
43
|
* How many entries to attempt, uniformly across `[minTried, max]`.
|
|
44
44
|
*
|
|
45
45
|
* Asymmetric naming is the point. Colliding keys collapse rather than being
|
|
46
|
-
* redrawn, so surviving count is only ever
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* `
|
|
46
|
+
* redrawn, so surviving count is only ever _at most_ what was attempted: `max`
|
|
47
|
+
* is a real upper bound; the lower bound is not guaranteed and the field says
|
|
48
|
+
* so. `minTried` is optional, default `0`, matching `string`'s
|
|
49
|
+
* `whereby.length.min`.
|
|
50
50
|
*
|
|
51
|
-
* No bare-number form (unlike `array`'s `length`): "exactly N" is a promise
|
|
52
|
-
*
|
|
51
|
+
* No bare-number form (unlike `array`'s `length`): "exactly N" is a promise a
|
|
52
|
+
* collapsing key set cannot keep.
|
|
53
53
|
*/
|
|
54
54
|
export type Whereby = {
|
|
55
55
|
size: {
|
|
@@ -59,10 +59,10 @@ export type Whereby = {
|
|
|
59
59
|
};
|
|
60
60
|
/**
|
|
61
61
|
* `key`/`value` stay required regardless of `produce` — both are known at
|
|
62
|
-
* `T.record(...)` call time and describe the shape TypeBox derives either
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* `
|
|
62
|
+
* `T.record(...)` call time and describe the shape TypeBox derives either way.
|
|
63
|
+
* `produce` is carried _alongside_ `whereby` rather than replacing it, so a
|
|
64
|
+
* prior size spec survives `as` for future validation — same as `array`'s
|
|
65
|
+
* `Meta`.
|
|
66
66
|
*/
|
|
67
67
|
export type Meta<$Key extends Key = Key, $Value extends Value = Value> = {
|
|
68
68
|
key: $Key;
|
|
@@ -21,27 +21,26 @@ export type Fabricator<$Schema extends {
|
|
|
21
21
|
/**
|
|
22
22
|
* Expansion is lazy — one dispatch per `self` at fabricate time, not unrolled
|
|
23
23
|
* to `depth.max` at build. This is the only place dispatch (assigning a node
|
|
24
|
-
* its private stream) happens
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* private source's construction counter orders expansions; nothing to
|
|
24
|
+
* its private stream) happens _inside_ `fabricate()`, not at `new
|
|
25
|
+
* Fabricator(...)`. Safe because of isolation, not memoization: every other
|
|
26
|
+
* kind's dispatch count is a function of schema shape, so structural path
|
|
27
|
+
* keying already identifies it. A recursive node's count is data-dependent —
|
|
28
|
+
* how deep this `fabricate()` goes — so no structural path distinguishes
|
|
29
|
+
* sibling expansions at the same depth (an `array` of three `self` children
|
|
30
|
+
* calls `fabricateAt` three times on one shared element Fabricator; the schema
|
|
31
|
+
* does not tell them apart). Each expansion gets its own _root_: `forkSource`
|
|
32
|
+
* mints an isolated `RandomSource` seeded from this node's draw, and each
|
|
33
|
+
* `fabricateAt` opens a `"counted"` scope on it (`Random/Types.ts`'s `RootKind`
|
|
34
|
+
* — recorded on each expansion's `trace`, not chosen at `ConstructorOptions`).
|
|
35
|
+
* The private source's construction counter orders expansions; nothing to
|
|
37
36
|
* increment here. Isolation also keeps this node's data-dependent draws from
|
|
38
37
|
* perturbing (or being perturbed by) an unrelated Fabricator from the same
|
|
39
38
|
* `initialize()` instance.
|
|
40
39
|
*
|
|
41
40
|
* Each `self` gets its own independently-dispatched expansion — calling
|
|
42
|
-
* `context.self` twice (two array slots) is two `fabricateAt` calls, each
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* `context.self` twice (two array slots) is two `fabricateAt` calls, each with
|
|
42
|
+
* its own scope and stream space — `tuple`'s per-slot convention, not `array`'s
|
|
43
|
+
* shared-element one. Sibling tree branches therefore draw independently, not a
|
|
44
|
+
* correlated shared sequence.
|
|
46
45
|
*/
|
|
47
46
|
export declare function Fabricator<$Body>(context: FabricatorContext<Schema<$Body>>, forkSource: (seed: string) => RandomSource, make: (schema: unknown, path: ReadonlyArray<string>, context: ConstructionContext) => NaiveFabricator<unknown>): Fabricator<Schema<$Body>>;
|
|
@@ -9,13 +9,12 @@ import type { Whereby } from "./Types";
|
|
|
9
9
|
*
|
|
10
10
|
* `body` is called exactly once, here, with a single freshly-minted `self`
|
|
11
11
|
* placeholder — eagerly, the same timing `array`/`record` normalize their
|
|
12
|
-
* nested definitions at call time, not deferred to `.whereby()`. Every
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* wrong schema object elsewhere isn't.
|
|
12
|
+
* nested definitions at call time, not deferred to `.whereby()`. Every `self`
|
|
13
|
+
* in the returned schema is this same placeholder; `Constructor.ts`'s `make`
|
|
14
|
+
* matches it only by `[Kind]`, never by identity, so a `self` captured out of
|
|
15
|
+
* its callback and reused elsewhere silently resolves against whichever
|
|
16
|
+
* recursion is currently active rather than erroring — a misuse this library
|
|
17
|
+
* doesn't guard, the same way passing the wrong schema object elsewhere isn't.
|
|
19
18
|
*/
|
|
20
19
|
export default function <const $Body extends AnySchema>(body: (self: SelfSchema) => $Body): {
|
|
21
20
|
whereby(config: Whereby<$Body>): Schema<$Body>;
|
|
@@ -2,19 +2,19 @@ import { type AdaptationEntry } from "../../Adapter/Core";
|
|
|
2
2
|
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
|
|
3
3
|
import type { Core } from "./Types";
|
|
4
4
|
/**
|
|
5
|
-
* A recursive schema, produced by `.whereby({ depth })` — see
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* A recursive schema, produced by `.whereby({ depth })` — see `Registry.ts` for
|
|
6
|
+
* the builder `T.recursive(body)` itself returns. `terminal` is optional there;
|
|
7
|
+
* omitted, it is derived from `body`.
|
|
8
8
|
*
|
|
9
9
|
* No `.as()`, unlike `array`/`record`: a fully custom whole-value producer
|
|
10
|
-
* would need to be reproducible per depth on its own terms, which is
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* would need to be reproducible per depth on its own terms, which is exactly
|
|
11
|
+
* the problem `depth`/`terminal` already solve — deferred rather than ruled
|
|
12
|
+
* out, since adding it later is non-breaking.
|
|
13
13
|
*/
|
|
14
14
|
export interface Schema<$Body = unknown, $Adaptations extends Adaptations = {}> extends Core<$Body, $Adaptations> {
|
|
15
15
|
/**
|
|
16
|
-
* Override what this schema maps to in one or more external schema
|
|
17
|
-
*
|
|
16
|
+
* Override what this schema maps to in one or more external schema libraries
|
|
17
|
+
* — see `string/Schema.ts`'s `adapt` for the full contract.
|
|
18
18
|
*/
|
|
19
19
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Body, $Adaptations>>) => $Returnable) => Schema<$Body, WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|
|
20
20
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import type { AnySchema } from "../../Schema/Types";
|
|
2
2
|
/**
|
|
3
|
-
* Derive the schema that `fabricateAt` swaps in at `depth.max` when the
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3
|
+
* Derive the schema that `fabricateAt` swaps in at `depth.max` when the caller
|
|
4
|
+
* omits `terminal`. Walks `body` and rewrites every `self` site into a
|
|
5
|
+
* declining state so the result contains _no_ `recursive.self` nodes —
|
|
6
|
+
* `Constructor.ts`'s `make` still dispatches nested schemas eagerly, and
|
|
7
|
+
* `recursive.self` throws when `context.self` is missing (which it is, at the
|
|
8
|
+
* ceiling).
|
|
9
9
|
*
|
|
10
|
-
* Empty collections are `opaque(() => [])` / `opaque(() => ({}))`,
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* would still construct that inner node.
|
|
10
|
+
* Empty collections are `opaque(() => [])` / `opaque(() => ({}))`, never
|
|
11
|
+
* `always([])`: each leaf must get its own reference (see `Recursive.test.ts`).
|
|
12
|
+
* Presence wrappers become a self-free schema that always declines (`null` /
|
|
13
|
+
* `undefined` / `Omitted`), rather than keeping the inner `self` behind a
|
|
14
|
+
* produce short-circuit — `make` would still construct that inner node.
|
|
16
15
|
*
|
|
17
|
-
* Nested `T.recursive` is its own fixed point and is treated as a
|
|
18
|
-
*
|
|
16
|
+
* Nested `T.recursive` is its own fixed point and is treated as a leaf; its
|
|
17
|
+
* inner `self` is not this walk's `self`.
|
|
19
18
|
*/
|
|
20
19
|
export declare function terminate(body: AnySchema): AnySchema;
|
|
@@ -3,11 +3,11 @@ import type { AnySchema, ValueOf } from "../../Schema/Types";
|
|
|
3
3
|
import { Produces, type Adaptation, type Kind, type Meta } from "../../Types";
|
|
4
4
|
/**
|
|
5
5
|
* Fixed point of a recursive schema. A self-referential alias, normally
|
|
6
|
-
* `TS2456` ("`RecursiveValue` circularly references itself") — legal
|
|
6
|
+
* `TS2456` ("`RecursiveValue` circularly references itself") — legal _only_
|
|
7
7
|
* because `ValueOf`'s second argument is read through an interface member
|
|
8
|
-
* (`this["bindings"]` on every composite `Core`), which TypeScript defers.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* (`this["bindings"]` on every composite `Core`), which TypeScript defers. Do
|
|
9
|
+
* not rewrite as a conditional; that reintroduces the error. See `CLAUDE.md`'s
|
|
10
|
+
* "`ValueOf`'s `$Bindings`".
|
|
11
11
|
*
|
|
12
12
|
* Wherever `self` sits in `$Body` (nested through `array`/`object`/`tuple`/
|
|
13
13
|
* etc., each forwarding `this["bindings"]`), it reads `bindings[0]` —
|
|
@@ -19,33 +19,33 @@ export type Fabricated<$Body> = RecursiveValue<$Body>;
|
|
|
19
19
|
* `terminal` is what `self` expands into at `depth.max`, in place of `body`.
|
|
20
20
|
* Expansion is lazy (per `self`, at fabricate time) — see `Fabricator.ts`.
|
|
21
21
|
*
|
|
22
|
-
* Constraining `terminal` against `RecursiveValue<$Body>` as a plain field
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* Constraining `terminal` against `RecursiveValue<$Body>` as a plain field type
|
|
23
|
+
* (not `terminal`'s own type parameter) is enough: structural assignability
|
|
24
|
+
* already rejects a wrong terminal (e.g. missing a required field `body` has),
|
|
25
|
+
* and nothing downstream needs `terminal`'s precise type (`Core`'s `[Produces]`
|
|
26
|
+
* depends only on `$Body`). A bare-vs-generic comparison rejects the same wrong
|
|
27
|
+
* terminal either way.
|
|
28
28
|
*
|
|
29
29
|
* Omitted, `terminal` is derived from `body` (`Terminate.ts`): every `self`
|
|
30
30
|
* behind a declining kind is rewritten into a stop (empty array/record,
|
|
31
|
-
* remaining non-`self` choice arms, `null`/`undefined`/`Omitted`). A
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* leaf
|
|
31
|
+
* remaining non-`self` choice arms, `null`/`undefined`/`Omitted`). A required
|
|
32
|
+
* `self` cannot be derived — `.whereby()` throws `UnterminableRecursiveError`,
|
|
33
|
+
* and an explicit `terminal` is the way out. A provided `terminal` is a
|
|
34
|
+
* wholesale override of that derivation (custom leaf values, a narrower JSON
|
|
35
|
+
* leaf), not a patch of `self` sites.
|
|
36
36
|
*
|
|
37
|
-
* `depth.max` is a ceiling, not a target: `fabricateAt` (`Fabricator.ts`)
|
|
38
|
-
*
|
|
39
|
-
* `array`/`record`/`string`'s `{min, max}`, there is no drawn count for a
|
|
40
|
-
*
|
|
41
|
-
*
|
|
37
|
+
* `depth.max` is a ceiling, not a target: `fabricateAt` (`Fabricator.ts`) only
|
|
38
|
+
* _compares_ a counter against it, never draws one — unlike
|
|
39
|
+
* `array`/`record`/`string`'s `{min, max}`, there is no drawn count for a `min`
|
|
40
|
+
* to constrain. Realized depth is emergent: intervening kinds decline to
|
|
41
|
+
* recurse (an `array`/`record` rolling 0, a `choice` picking a non-`self`
|
|
42
42
|
* option, an `omittable`/`optional`/`undefinable` resolving absent). The
|
|
43
|
-
* recursive node has no say. "Force `body` while `depth` is below some
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* `
|
|
48
|
-
*
|
|
43
|
+
* recursive node has no say. "Force `body` while `depth` is below some `min`"
|
|
44
|
+
* is a no-op: that already happens below `depth.max`. A genuine floor would
|
|
45
|
+
* coerce those intervening kinds' draws — a different feature than a second
|
|
46
|
+
* number here. The derived terminal may empty a collection whose `body` said
|
|
47
|
+
* `length.min > 0`: the ceiling has to stop somehow, and an explicit `terminal`
|
|
48
|
+
* already did the same with `T.opaque(() => [])`.
|
|
49
49
|
*/
|
|
50
50
|
export type Whereby<$Body> = {
|
|
51
51
|
depth: {
|
|
@@ -68,11 +68,11 @@ export type Meta<$Body = unknown> = {
|
|
|
68
68
|
terminal: AnySchema;
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
|
-
* A `type` alias, not an `interface` — unlike every composite that
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
71
|
+
* A `type` alias, not an `interface` — unlike every composite that _contains_ a
|
|
72
|
+
* `self`, `recursive` is where the fixed point _closes_, so `[Produces]` never
|
|
73
|
+
* needs `this["bindings"]`: `RecursiveValue` is already concrete once `$Body`
|
|
74
|
+
* is, regardless of bindings this schema sits inside (a nested `T.recursive` is
|
|
75
|
+
* its own independent fixed point).
|
|
76
76
|
*/
|
|
77
77
|
export type Core<$Body = unknown, $Adaptations extends Adaptations = {}> = {
|
|
78
78
|
[Kind]: "recursive";
|
|
@@ -6,9 +6,8 @@ import type { Fabricated, Meta as ThisMeta } from "./Types";
|
|
|
6
6
|
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Bindings> ? $Bindings[0] : never;
|
|
7
7
|
/**
|
|
8
8
|
* Deliberately not parameterized by a Schema the way every other kind's
|
|
9
|
-
* Fabricator type is — `self` carries no config to read a shape from
|
|
10
|
-
*
|
|
11
|
-
* against.
|
|
9
|
+
* Fabricator type is — `self` carries no config to read a shape from (`[Meta]`
|
|
10
|
+
* is always `{}`), only whatever `$Bindings` its position resolves against.
|
|
12
11
|
*/
|
|
13
12
|
export type Fabricator<$Bindings extends unknown[] = []> = NaiveFabricator<Fabricated<$Bindings>> & {
|
|
14
13
|
[Kind]: "recursive.self";
|
|
@@ -16,14 +15,14 @@ export type Fabricator<$Bindings extends unknown[] = []> = NaiveFabricator<Fabri
|
|
|
16
15
|
readonly trace: Trace;
|
|
17
16
|
};
|
|
18
17
|
/**
|
|
19
|
-
* A transient passthrough, unlike every other kind's Fabricator — it draws
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
18
|
+
* A transient passthrough, unlike every other kind's Fabricator — it draws no
|
|
19
|
+
* randomness of its own: a `self` node stands for wherever `T.recursive`'s
|
|
20
|
+
* current expansion is, and `resolve` _is_ that expansion, one level deeper —
|
|
21
|
+
* the same closure `recursive/Fabricator.ts` hands to every `self` in its body
|
|
22
|
+
* via `Constructor.ts`'s `make` context (`case "recursive.self"`). Calling
|
|
23
|
+
* `resolve` is what actually recurses; this function only wraps it in the shape
|
|
24
|
+
* `make` expects back. Absent `resolve` (a `self` rebuilt from its schema plus
|
|
25
|
+
* trace, without the enclosing recursive parent), `.fabricate()` throws
|
|
26
|
+
* `DetachedSelfError`.
|
|
28
27
|
*/
|
|
29
28
|
export declare function Fabricator<$Bindings extends unknown[]>(context: FabricatorContext<Schema>, resolve?: (() => Fabricated<$Bindings>) | undefined): Fabricator<$Bindings>;
|
|
@@ -2,17 +2,17 @@ import { type AdaptationEntry } from "../../../Adapter/Core";
|
|
|
2
2
|
import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
|
|
3
3
|
import type { Core } from "./Types";
|
|
4
4
|
/**
|
|
5
|
-
* The placeholder `T.recursive`'s body callback receives in place of the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The placeholder `T.recursive`'s body callback receives in place of the schema
|
|
6
|
+
* being defined — everywhere `self` appears, it stands for "recurse one level
|
|
7
|
+
* deeper here." Never constructed directly: `T.recursive` is the only thing
|
|
8
|
+
* that mints one, and only ever hands it to its own callback, so there is no
|
|
9
|
+
* bare `T.self`.
|
|
10
10
|
*
|
|
11
|
-
* No `.as()` — unlike `always`, not because there's nothing left to
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* No `.as()` — unlike `always`, not because there's nothing left to override,
|
|
12
|
+
* but because there is nothing here _to_ produce: a `self` node carries no
|
|
13
|
+
* value of its own, only a reference to whatever the enclosing recursion
|
|
14
|
+
* currently binds it to. `adapt` still applies, on the same footing as every
|
|
15
|
+
* other kind.
|
|
16
16
|
*/
|
|
17
17
|
export interface Schema<$Adaptations extends Adaptations = {}> extends Core<$Adaptations> {
|
|
18
18
|
adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Adaptations>>) => $Returnable) => Schema<WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
|