@ghostry/fabricator 0.0.10 → 0.0.11
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/dist/esm/Distribution/index.js +1 -1
- package/dist/esm/Primitive/null/Registry.js +2 -3
- package/dist/esm/Primitive/undefined/Registry.js +2 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/internal.js +2 -2
- package/dist/types/Adapter/Types.d.ts +3 -2
- package/dist/types/Distribution/index.d.ts +10 -0
- package/dist/types/Enumeration/Types.d.ts +3 -3
- package/dist/types/Fabricator/Types.d.ts +8 -8
- package/dist/types/Primitive/always/Types.d.ts +2 -2
- package/dist/types/Primitive/array/Types.d.ts +4 -4
- package/dist/types/Primitive/bigint/Types.d.ts +2 -2
- package/dist/types/Primitive/boolean/Types.d.ts +2 -2
- package/dist/types/Primitive/choice/Types.d.ts +4 -4
- package/dist/types/Primitive/date/Types.d.ts +2 -2
- package/dist/types/Primitive/derive/Types.d.ts +2 -2
- package/dist/types/Primitive/enum/Types.d.ts +2 -2
- package/dist/types/Primitive/null/Types.d.ts +2 -2
- package/dist/types/Primitive/nullable/Types.d.ts +4 -4
- package/dist/types/Primitive/nullish/Types.d.ts +4 -4
- package/dist/types/Primitive/number/Types.d.ts +2 -2
- package/dist/types/Primitive/object/Types.d.ts +9 -9
- package/dist/types/Primitive/object/compute/Types.d.ts +4 -4
- package/dist/types/Primitive/object/omittable/Types.d.ts +4 -4
- package/dist/types/Primitive/object/optional/Types.d.ts +4 -4
- package/dist/types/Primitive/opaque/Types.d.ts +2 -2
- package/dist/types/Primitive/record/Types.d.ts +11 -6
- package/dist/types/Primitive/recursive/Types.d.ts +12 -8
- package/dist/types/Primitive/recursive/self/Schema.d.ts +4 -4
- package/dist/types/Primitive/recursive/self/Types.d.ts +7 -5
- package/dist/types/Primitive/string/Constants.d.ts +7 -31
- package/dist/types/Primitive/string/Types.d.ts +2 -2
- package/dist/types/Primitive/symbol/Types.d.ts +2 -2
- package/dist/types/Primitive/tuple/Types.d.ts +7 -7
- package/dist/types/Primitive/undefinable/Types.d.ts +4 -4
- package/dist/types/Primitive/undefined/Types.d.ts +2 -2
- package/dist/types/Schema/Core.d.ts +10 -6
- package/dist/types/Schema/Satisfies.d.ts +31 -23
- package/dist/types/Schema/Types.d.ts +31 -18
- package/dist/types/Types.d.ts +24 -0
- package/dist/types/index.d.ts +24 -10
- package/dist/types/internal.d.ts +24 -4
- package/package.json +3 -3
|
@@ -238,4 +238,4 @@ function toAliasTable(weights) {
|
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
var Distribution_Distribution;
|
|
241
|
-
export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, discreteSampler, drawableOutcomes, isDrawable, isValidWeight, sample, sampler, shuffle, weighted };
|
|
241
|
+
export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, discreteSampler, drawableOutcomes, isDrawable, isValidWeight, normalCdf, normalInv, sample, sampler, shuffle, weighted };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Kind, Meta
|
|
1
|
+
import { Kind, Meta } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
3
|
const registry = Schema({
|
|
4
4
|
[Kind]: "null",
|
|
5
|
-
[Meta]: {}
|
|
6
|
-
[Produces]: null
|
|
5
|
+
[Meta]: {}
|
|
7
6
|
});
|
|
8
7
|
const Registry = registry;
|
|
9
8
|
export default Registry;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Kind, Meta
|
|
1
|
+
import { Kind, Meta } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
3
|
const registry = Schema({
|
|
4
4
|
[Kind]: "undefined",
|
|
5
|
-
[Meta]: {}
|
|
6
|
-
[Produces]: void 0
|
|
5
|
+
[Meta]: {}
|
|
7
6
|
});
|
|
8
7
|
const Registry = registry;
|
|
9
8
|
export default Registry;
|
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { layer } from "./Random/index.js";
|
|
|
9
9
|
export { FabricatorError } from "./Error/index.js";
|
|
10
10
|
export { registry } from "./Schema/Registry.js";
|
|
11
11
|
export { effectiveDiscrete, toBound } from "./Bound.js";
|
|
12
|
+
export { classes, unicode } from "./Primitive/string/Constants.js";
|
|
12
13
|
export { sample, shuffle } from "./Distribution/index.js";
|
|
13
14
|
export { satisfies } from "./Schema/Satisfies.js";
|
|
14
15
|
export { initialize };
|
package/dist/esm/internal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Children, Kind, Meta, Produces } from "./Types.js";
|
|
2
|
-
export { isPlainObject } from "./Utility/Core.js";
|
|
2
|
+
export { isArray, isPlainObject } from "./Utility/Core.js";
|
|
3
3
|
export { plan, resolve } from "./Enumeration/Plan.js";
|
|
4
4
|
export { defaultAlgorithm, encode, randomSalt, toRandomSource, toStream, toStreamFromTrace } from "./Random/index.js";
|
|
5
|
-
export { weighted } from "./Distribution/index.js";
|
|
5
|
+
export { normalCdf, normalInv, weighted } from "./Distribution/index.js";
|
|
6
6
|
export { toStack as toSynchronousStack } from "./Instance/Stack/Sync.js";
|
|
@@ -101,7 +101,8 @@ export type Recurse<$Context, $Returnable> = (schema: any, context: $Context) =>
|
|
|
101
101
|
* package declares its own conversion entry point with its own return type
|
|
102
102
|
* (`toTypeBox<$S>(schema: $S): ToTypeBox<$S>`), so nothing has to compute a
|
|
103
103
|
* type-level mapping out of a stored value — which would need the
|
|
104
|
-
* interface-member-lookup encoding `
|
|
104
|
+
* interface-member-lookup encoding `Fabricated`'s `$Bindings` uses, for no
|
|
105
|
+
* gain.
|
|
105
106
|
*/
|
|
106
107
|
export interface Adapter<$Key extends string = string, $Context = unknown, $Returnable = unknown> {
|
|
107
108
|
readonly key: $Key;
|
|
@@ -115,7 +116,7 @@ export interface Adapter<$Key extends string = string, $Context = unknown, $Retu
|
|
|
115
116
|
* and why no adapter matches `{ [Adaptation]?: Record<Key, ...> }` directly.
|
|
116
117
|
* Every kind's `Core` declares `[Adaptation]` as _optional_, and a conditional
|
|
117
118
|
* matching an optional property against a schema that lacks it entirely still
|
|
118
|
-
* _succeeds_, inferring `unknown` (the same behavior `
|
|
119
|
+
* _succeeds_, inferring `unknown` (the same behavior `Fabricated` relies on for
|
|
119
120
|
* `[Produces]`) — so a direct match would resolve every unadapted schema to
|
|
120
121
|
* whatever the adapter's adaptation branch produces. Constraining the `infer`
|
|
121
122
|
* sends that case here, to `{}`, which then fails each adapter's `Record<Key,
|
|
@@ -110,6 +110,16 @@ export declare function discreteSampler(distribution: Distribution | undefined,
|
|
|
110
110
|
* clamped.
|
|
111
111
|
*/
|
|
112
112
|
export declare function sampler(distribution: Distribution, range: Range, stream: Stream): () => number;
|
|
113
|
+
/**
|
|
114
|
+
* Standard normal CDF via the Abramowitz & Stegun 7.1.26 approximation of the
|
|
115
|
+
* error function (|error| < 1.5e-7).
|
|
116
|
+
*/
|
|
117
|
+
export declare function normalCdf(x: number): number;
|
|
118
|
+
/**
|
|
119
|
+
* Inverse of the standard normal CDF (quantile function) via Peter Acklam's
|
|
120
|
+
* rational approximation (relative error < 1.15e-9).
|
|
121
|
+
*/
|
|
122
|
+
export declare function normalInv(p: number): number;
|
|
113
123
|
/**
|
|
114
124
|
* A uniform pick from `list`. One `stream.next()` per call; `list` is not
|
|
115
125
|
* mutated. An empty list throws {@link FabricatorError.EmptyItemsError} — there
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kind as SchemaKind } from "../Primitive";
|
|
2
|
-
import type { AnySchema,
|
|
2
|
+
import type { AnySchema, Fabricated } from "../Schema/Types";
|
|
3
3
|
import type { Children, Kind, Meta } from "../Types";
|
|
4
4
|
import type { PlainObject } from "../Utility/Types";
|
|
5
5
|
/**
|
|
@@ -71,9 +71,9 @@ export type Limits = {
|
|
|
71
71
|
* The shape both `combinatorial` and `coverage` share — strategy and limit
|
|
72
72
|
* differ internally, neither visible here. Takes a Schema, not a built
|
|
73
73
|
* Fabricator: `AnySchema` excludes `Fabricator<any>` (which carries no
|
|
74
|
-
* `[Produces]`), so `
|
|
74
|
+
* `[Produces]`), so `Fabricated` can't silently degrade to `unknown`.
|
|
75
75
|
*/
|
|
76
|
-
export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Iterable<
|
|
76
|
+
export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Iterable<Fabricated<$Schema>>;
|
|
77
77
|
export type Resolvable = {
|
|
78
78
|
[Kind]: SchemaKind;
|
|
79
79
|
[Meta]: PlainObject<any>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Adaptations, AdaptationsOf } from "../Adapter/Types";
|
|
2
2
|
import type { Primitive, Kind as SchemaKind } from "../Primitive";
|
|
3
3
|
import type { Algorithm, Trace } from "../Random/Types";
|
|
4
|
-
import type {
|
|
5
|
-
import type { Adaptation, Kind, Meta, Produces } from "../Types";
|
|
4
|
+
import type { Fabricated } from "../Schema/Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../Types";
|
|
6
6
|
import type { PlainObject } from "../Utility/Types";
|
|
7
7
|
/**
|
|
8
8
|
* Threaded through `Constructor.ts`'s `make` for every dispatch of one `new
|
|
@@ -89,9 +89,9 @@ export type Fabricator<$T> = NaiveFabricator<$T> & {
|
|
|
89
89
|
* `fabricate` signature. Every kind's `construct()` output shares the exact
|
|
90
90
|
* same shape (`NaiveFabricator<$T>` plus `[Kind]`/`[Meta]`, see this file's
|
|
91
91
|
* `Fabricator<$T>`), so there's nothing to dispatch per kind here — unlike
|
|
92
|
-
* `
|
|
93
|
-
* pre-`construct()` case, this only ever needs to unwrap an
|
|
94
|
-
* `fabricate: () => $T`.
|
|
92
|
+
* `Schema/Types.ts`'s `Fabricated`, which reads a Schema's phantom `[Produces]`
|
|
93
|
+
* marker for the pre-`construct()` case, this only ever needs to unwrap an
|
|
94
|
+
* already-uniform `fabricate: () => $T`.
|
|
95
95
|
*/
|
|
96
96
|
export type Fabrication<$Fabricator extends NaiveFabricator<any>> = $Fabricator extends NaiveFabricator<infer $T> ? $T : never;
|
|
97
97
|
/**
|
|
@@ -100,7 +100,7 @@ export type Fabrication<$Fabricator extends NaiveFabricator<any>> = $Fabricator
|
|
|
100
100
|
* carries a required `as` method a built Fabricator never has) to the precise,
|
|
101
101
|
* kind-specific `Fabricator<...>` type it builds into. Mirrors
|
|
102
102
|
* `Adapter/TypeBox/index.ts`'s `ToTypeBox` dispatch. Falls back to the loose
|
|
103
|
-
* base `Fabricator<
|
|
103
|
+
* base `Fabricator<Fabricated<$Schema>>` for anything unmatched.
|
|
104
104
|
*
|
|
105
105
|
* No branch here needs to do anything about `[Adaptation]`: each kind's own
|
|
106
106
|
* `Fabricator<$Schema>` reads it back off `$Schema` via `AdaptationsOf`, so an
|
|
@@ -139,5 +139,5 @@ $Schema extends Primitive.object.Core ? Primitive.object.Fabricator<$Schema> : $
|
|
|
139
139
|
* (unbound) is the same default `self.Core` itself falls back to.
|
|
140
140
|
*/
|
|
141
141
|
$Schema extends Primitive.recursive.self.Core ? Primitive.recursive.self.Fabricator<[]> : $Schema extends Primitive.tuple.Core ? Primitive.tuple.Fabricator<$Schema> : $Schema extends Primitive.derive.Core ? Primitive.derive.Fabricator<$Schema> : $Schema extends Primitive.always.Core ? Primitive.always.Fabricator<$Schema> : $Schema extends Primitive.bigint.Core ? Primitive.bigint.Fabricator<$Schema> : $Schema extends Primitive.boolean.Core ? Primitive.boolean.Fabricator<$Schema> : $Schema extends Primitive.choice.Core ? Primitive.choice.Fabricator<$Schema> : $Schema extends Primitive.enum.Core ? Primitive.enum.Fabricator<$Schema> : $Schema extends Primitive.date.Core ? Primitive.date.Fabricator<$Schema> : $Schema extends Primitive.number.Core ? Primitive.number.Fabricator<$Schema> : $Schema extends Primitive.string.Core ? Primitive.string.Fabricator<$Schema> : $Schema extends Primitive.symbol.Core ? Primitive.symbol.Fabricator<$Schema> : $Schema extends Primitive.undefined.Core ? Primitive.undefined.Fabricator<$Schema> : $Schema extends Primitive.undefinable.Core ? Primitive.undefinable.Fabricator<$Schema> : $Schema extends Primitive.null.Core ? Primitive.null.Fabricator<$Schema> : $Schema extends Primitive.nullable.Core ? Primitive.nullable.Fabricator<$Schema> : $Schema extends Primitive.nullish.Core ? Primitive.nullish.Fabricator<$Schema> : $Schema extends {
|
|
142
|
-
readonly [Produces]?: unknown
|
|
143
|
-
} ? Fabricator<
|
|
142
|
+
readonly [Produces]?: Produced<unknown>;
|
|
143
|
+
} ? Fabricator<Fabricated<$Schema>> : Fabricator<unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
2
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
3
3
|
/**
|
|
4
4
|
* Any value at all. Deliberately unconstrained: fabricating a fixed value needs
|
|
5
5
|
* nothing of it. A `string | number | boolean` cap would be TypeBox's
|
|
@@ -18,6 +18,6 @@ export type Meta<$Value extends Value = Value> = {
|
|
|
18
18
|
export type Core<$Value extends Value = Value, $Adaptations extends Adaptations = {}> = {
|
|
19
19
|
[Kind]: "always";
|
|
20
20
|
[Meta]: Meta<$Value>;
|
|
21
|
-
readonly [Produces]?: Fabricated<$Value
|
|
21
|
+
readonly [Produces]?: Produced<Fabricated<$Value>>;
|
|
22
22
|
readonly [Adaptation]?: $Adaptations;
|
|
23
23
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { InputLength, Length } from "../../Bound";
|
|
3
3
|
import type { Produce } from "../../Random/Types";
|
|
4
|
-
import type { AnySchema,
|
|
5
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
4
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
6
6
|
export type Definition = AnySchema;
|
|
7
|
-
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Array<
|
|
7
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Array<FabricatedBy<$Definition, $Bindings>>;
|
|
8
8
|
export type InputWhereby = {
|
|
9
9
|
length: InputLength;
|
|
10
10
|
};
|
|
@@ -33,6 +33,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
|
|
|
33
33
|
[Kind]: "array";
|
|
34
34
|
[Meta]: Meta<$Definition>;
|
|
35
35
|
bindings?: unknown[];
|
|
36
|
-
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]
|
|
36
|
+
readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
|
|
37
37
|
readonly [Adaptation]?: $Adaptations;
|
|
38
38
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Bound, InputBound } from "../../Bound";
|
|
3
3
|
import type { Produce } from "../../Random/Types";
|
|
4
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
4
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
5
5
|
export type InputWhereby = {
|
|
6
6
|
min?: InputBound<bigint> | undefined;
|
|
7
7
|
max: InputBound<bigint>;
|
|
@@ -28,6 +28,6 @@ export type Meta = {
|
|
|
28
28
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
29
29
|
[Kind]: "bigint";
|
|
30
30
|
[Meta]: $Meta;
|
|
31
|
-
readonly [Produces]?: Fabricated
|
|
31
|
+
readonly [Produces]?: Produced<Fabricated>;
|
|
32
32
|
readonly [Adaptation]?: $Adaptations;
|
|
33
33
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
4
4
|
export type Fabricated = boolean;
|
|
5
5
|
export type Weights = {
|
|
6
6
|
true: number;
|
|
@@ -21,6 +21,6 @@ export type Meta = {
|
|
|
21
21
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
22
22
|
[Kind]: "boolean";
|
|
23
23
|
[Meta]: $Meta;
|
|
24
|
-
readonly [Produces]?: Fabricated
|
|
24
|
+
readonly [Produces]?: Produced<Fabricated>;
|
|
25
25
|
readonly [Adaptation]?: $Adaptations;
|
|
26
26
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
|
|
4
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
5
5
|
/** The schemas a `choice` can draw from. */
|
|
6
6
|
export type Item = AnySchema;
|
|
7
7
|
/**
|
|
@@ -14,7 +14,7 @@ export type Item = AnySchema;
|
|
|
14
14
|
* instead of always wrapping regardless of count.
|
|
15
15
|
*/
|
|
16
16
|
export type Items = ReadonlyArray<readonly [number, Item]>;
|
|
17
|
-
export type Fabricated<$Items extends Items = Items, $Bindings extends unknown[] = []> =
|
|
17
|
+
export type Fabricated<$Items extends Items = Items, $Bindings extends unknown[] = []> = FabricatedBy<$Items[number][1], $Bindings>;
|
|
18
18
|
/**
|
|
19
19
|
* Always stored as weighted pairs — `.uniform(...)` (`Registry.ts`) is
|
|
20
20
|
* `.weighted(...)` with every item given weight `1`, so there is only one shape
|
|
@@ -30,6 +30,6 @@ export interface Core<$Items extends Items = Items, $Adaptations extends Adaptat
|
|
|
30
30
|
[Kind]: "choice";
|
|
31
31
|
[Meta]: Meta<$Items>;
|
|
32
32
|
bindings?: unknown[];
|
|
33
|
-
readonly [Produces]?: Fabricated<$Items, NonNullable<this["bindings"]
|
|
33
|
+
readonly [Produces]?: Produced<Fabricated<$Items, NonNullable<this["bindings"]>>>;
|
|
34
34
|
readonly [Adaptation]?: $Adaptations;
|
|
35
35
|
}
|
|
@@ -2,7 +2,7 @@ import type { Adaptations } from "../../Adapter/Types";
|
|
|
2
2
|
import type { Bound, InputBound } from "../../Bound";
|
|
3
3
|
import type { Distribution } from "../../Distribution";
|
|
4
4
|
import type { Produce } from "../../Random/Types";
|
|
5
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
6
6
|
export type InputWhereby = {
|
|
7
7
|
min?: InputBound<Date> | undefined;
|
|
8
8
|
max?: InputBound<Date> | undefined;
|
|
@@ -29,6 +29,6 @@ export type Meta = {
|
|
|
29
29
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
30
30
|
[Kind]: "date";
|
|
31
31
|
[Meta]: $Meta;
|
|
32
|
-
readonly [Produces]?: Fabricated
|
|
32
|
+
readonly [Produces]?: Produced<Fabricated>;
|
|
33
33
|
readonly [Adaptation]?: $Adaptations;
|
|
34
34
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { ProduceContext } from "../../Random/Types";
|
|
3
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
4
4
|
import type { Resolved, Source } from "../object/compute/Types";
|
|
5
5
|
import type * as tuple from "../tuple/Types";
|
|
6
6
|
/**
|
|
@@ -33,6 +33,6 @@ export interface Core<$From extends From = From, $To extends Source = Source, $A
|
|
|
33
33
|
[Kind]: "derive";
|
|
34
34
|
[Meta]: Meta<$From, $To>;
|
|
35
35
|
bindings?: unknown[];
|
|
36
|
-
readonly [Produces]?: Resolved<$To, NonNullable<this["bindings"]
|
|
36
|
+
readonly [Produces]?: Produced<Resolved<$To, NonNullable<this["bindings"]>>>;
|
|
37
37
|
readonly [Adaptation]?: $Adaptations;
|
|
38
38
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
4
4
|
/**
|
|
5
5
|
* The values an `enum` can draw from — any value at all, for the same reason
|
|
6
6
|
* `always.Value` is unconstrained (see its doc).
|
|
@@ -37,6 +37,6 @@ export type Meta<$Items extends Items = Items> = {
|
|
|
37
37
|
export type Core<$Items extends Items = Items, $Adaptations extends Adaptations = {}> = {
|
|
38
38
|
[Kind]: "enum";
|
|
39
39
|
[Meta]: Meta<$Items>;
|
|
40
|
-
readonly [Produces]?: Fabricated<$Items
|
|
40
|
+
readonly [Produces]?: Produced<Fabricated<$Items>>;
|
|
41
41
|
readonly [Adaptation]?: $Adaptations;
|
|
42
42
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
2
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
3
3
|
export type Fabricated = null;
|
|
4
4
|
/**
|
|
5
5
|
* Nothing to configure: `null` has exactly one possible value, so there is no
|
|
@@ -10,6 +10,6 @@ export type Meta = Record<string, never>;
|
|
|
10
10
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
11
11
|
[Kind]: "null";
|
|
12
12
|
[Meta]: $Meta;
|
|
13
|
-
readonly [Produces]?: Fabricated
|
|
13
|
+
readonly [Produces]?: Produced<Fabricated>;
|
|
14
14
|
readonly [Adaptation]?: $Adaptations;
|
|
15
15
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
|
|
4
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
5
5
|
/** The wrapped schema — the value type produced when the roll isn't `null`. */
|
|
6
6
|
export type Definition = AnySchema;
|
|
7
|
-
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> =
|
|
7
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings> | null;
|
|
8
8
|
export type { Outcome } from "./Outcomes";
|
|
9
9
|
/**
|
|
10
10
|
* Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional — an
|
|
@@ -42,6 +42,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
|
|
|
42
42
|
[Kind]: "nullable";
|
|
43
43
|
[Meta]: Meta<$Definition>;
|
|
44
44
|
bindings?: unknown[];
|
|
45
|
-
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]
|
|
45
|
+
readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
|
|
46
46
|
readonly [Adaptation]?: $Adaptations;
|
|
47
47
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
|
|
4
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
5
5
|
/**
|
|
6
6
|
* The wrapped schema — the value type produced when the roll lands on neither
|
|
7
7
|
* `null` nor `undefined`.
|
|
8
8
|
*/
|
|
9
9
|
export type Definition = AnySchema;
|
|
10
|
-
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> =
|
|
10
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings> | null | undefined;
|
|
11
11
|
export type { Outcome } from "./Outcomes";
|
|
12
12
|
/**
|
|
13
13
|
* Relative weights for `.weighted(...)`, keyed by `Outcome`. Keys optional — an
|
|
@@ -52,6 +52,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
|
|
|
52
52
|
[Kind]: "nullish";
|
|
53
53
|
[Meta]: Meta<$Definition>;
|
|
54
54
|
bindings?: unknown[];
|
|
55
|
-
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]
|
|
55
|
+
readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
|
|
56
56
|
readonly [Adaptation]?: $Adaptations;
|
|
57
57
|
}
|
|
@@ -2,7 +2,7 @@ import type { Adaptations } from "../../Adapter/Types";
|
|
|
2
2
|
import type { Bound, InputBound } from "../../Bound";
|
|
3
3
|
import type { Distribution } from "../../Distribution";
|
|
4
4
|
import type { Produce } from "../../Random/Types";
|
|
5
|
-
import type { Adaptation, Kind, Meta, Produces } from "../../Types";
|
|
5
|
+
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
6
6
|
/**
|
|
7
7
|
* Call-site `{ min, max }` — scalars are inclusive. Either end may be omitted;
|
|
8
8
|
* a missing end is unbounded (the same policy as a bare `T.number`), not a
|
|
@@ -51,6 +51,6 @@ export type Meta = {
|
|
|
51
51
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
52
52
|
[Kind]: "number";
|
|
53
53
|
[Meta]: $Meta;
|
|
54
|
-
readonly [Produces]?: Fabricated
|
|
54
|
+
readonly [Produces]?: Produced<Fabricated>;
|
|
55
55
|
readonly [Adaptation]?: $Adaptations;
|
|
56
56
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import { Kind, Meta, type Adaptation, type Omitted, type Produces } from "../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
|
|
4
|
+
import { Kind, Meta, type Adaptation, type Omitted, type Produced, type Produces } from "../../Types";
|
|
5
5
|
import { type Pretty } from "../../Utility/Types";
|
|
6
6
|
import type { Schema as ComputeSchema } from "./compute/Schema";
|
|
7
7
|
export type Definition<$Schema = AnySchema> = {
|
|
@@ -23,7 +23,7 @@ export type Refinements = ReadonlyArray<Definition>;
|
|
|
23
23
|
* `Fabricated` can mark exactly those `?:` instead of required — matching
|
|
24
24
|
* runtime, where a field whose roll lands on omission never has its key appear
|
|
25
25
|
* (`object/omittable/Fabricator.ts`, `object/optional/Fabricator.ts`).
|
|
26
|
-
* `object.optional`'s `
|
|
26
|
+
* `object.optional`'s `FabricatedBy` already carries `| undefined` (its
|
|
27
27
|
* `Fabricated`), so combined with the `?:` here a field lands on `{ a?: T |
|
|
28
28
|
* undefined }` — omitted, present-as-`undefined`, or present-with-a-value.
|
|
29
29
|
*/
|
|
@@ -33,9 +33,9 @@ type OmittableKeys<$Definition extends Definition> = {
|
|
|
33
33
|
} ? $K : never;
|
|
34
34
|
}[keyof $Definition];
|
|
35
35
|
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Pretty<{
|
|
36
|
-
[$K in Exclude<keyof $Definition, OmittableKeys<$Definition>>]:
|
|
36
|
+
[$K in Exclude<keyof $Definition, OmittableKeys<$Definition>>]: FabricatedBy<$Definition[$K], $Bindings>;
|
|
37
37
|
} & {
|
|
38
|
-
[$K in OmittableKeys<$Definition>]?:
|
|
38
|
+
[$K in OmittableKeys<$Definition>]?: FabricatedBy<$Definition[$K], $Bindings>;
|
|
39
39
|
}>;
|
|
40
40
|
/**
|
|
41
41
|
* The shape `.override()` accepts: every field optional, so a present key skips
|
|
@@ -43,8 +43,8 @@ export type Fabricated<$Definition extends Definition, $Bindings extends unknown
|
|
|
43
43
|
* `Override` (deep-merge); an `object.omittable` or `object.optional` field
|
|
44
44
|
* additionally accepts `Omitted`, to force that field off rather than only
|
|
45
45
|
* forcing a value on (`object.optional` already accepts `undefined` via
|
|
46
|
-
* `
|
|
47
|
-
* full-replacement leaf, typed as whatever it fabricates to (`
|
|
46
|
+
* `FabricatedBy`); every other field — including `object.compute` — is a
|
|
47
|
+
* full-replacement leaf, typed as whatever it fabricates to (`FabricatedBy`).
|
|
48
48
|
*
|
|
49
49
|
* Checked via a bare structural `[Kind]`/`[Meta]` shape, never `Schema`/
|
|
50
50
|
* `Fabricator` — either carries `refine`'s contravariant use of `$Definition`,
|
|
@@ -59,7 +59,7 @@ export type Override<$Definition extends Definition> = Pretty<{
|
|
|
59
59
|
};
|
|
60
60
|
} ? Override<$Nested> : $Definition[$K] extends {
|
|
61
61
|
[Kind]: "object.omittable" | "object.optional";
|
|
62
|
-
} ?
|
|
62
|
+
} ? FabricatedBy<$Definition[$K]> | typeof Omitted : FabricatedBy<$Definition[$K]>;
|
|
63
63
|
}>;
|
|
64
64
|
/**
|
|
65
65
|
* `definition`/`refinements` stay required regardless of `produce` — an opaque
|
|
@@ -77,7 +77,7 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
|
|
|
77
77
|
[Kind]: "object";
|
|
78
78
|
[Meta]: Meta<$Definition>;
|
|
79
79
|
bindings?: unknown[];
|
|
80
|
-
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]
|
|
80
|
+
readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
|
|
81
81
|
readonly [Adaptation]?: $Adaptations;
|
|
82
82
|
}
|
|
83
83
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Adaptations } from "../../../Adapter/Types";
|
|
2
|
-
import type { AnySchema,
|
|
3
|
-
import { Kind, type Adaptation, type Meta, type Produces } from "../../../Types";
|
|
2
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../../Schema/Types";
|
|
3
|
+
import { Kind, type Adaptation, type Meta, type Produced, type Produces } from "../../../Types";
|
|
4
4
|
/**
|
|
5
5
|
* A builder that can mint a Schema via `as` — e.g. `T.string`, `T.bigint`.
|
|
6
6
|
* `compute` accepts one alongside a plain Schema so a caller needn't satisfy a
|
|
@@ -24,7 +24,7 @@ export type Denoted<$Source> = $Source extends AnySchema ? $Source : $Source ext
|
|
|
24
24
|
/**
|
|
25
25
|
* The value a source resolves to: what the Schema it denotes fabricates to.
|
|
26
26
|
*/
|
|
27
|
-
export type Resolved<$Source, $Bindings extends unknown[] = []> =
|
|
27
|
+
export type Resolved<$Source, $Bindings extends unknown[] = []> = FabricatedBy<Denoted<$Source>, $Bindings>;
|
|
28
28
|
/**
|
|
29
29
|
* Source and resolver are stored raw — the source whether a Schema or a builder
|
|
30
30
|
* (both carry a `[Kind]`, which is all schema derivation needs), and the
|
|
@@ -50,6 +50,6 @@ export interface Core<$Fabricated, $Source extends Source, $Adaptations extends
|
|
|
50
50
|
[Kind]: "object.compute";
|
|
51
51
|
[Meta]: Meta<$Fabricated, $Source>;
|
|
52
52
|
bindings?: unknown[];
|
|
53
|
-
readonly [Produces]?: Resolved<$Source, NonNullable<this["bindings"]
|
|
53
|
+
readonly [Produces]?: Produced<Resolved<$Source, NonNullable<this["bindings"]>>>;
|
|
54
54
|
readonly [Adaptation]?: $Adaptations;
|
|
55
55
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Adaptations } from "../../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import { Kind, Meta, Omitted, type Adaptation, type Produces } from "../../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../../Schema/Types";
|
|
4
|
+
import { Kind, Meta, Omitted, type Adaptation, type Produced, type Produces } from "../../../Types";
|
|
5
5
|
/**
|
|
6
6
|
* The wrapped field's own Schema — the value type an omittable field produces
|
|
7
7
|
* when its presence roll comes up present.
|
|
8
8
|
*/
|
|
9
9
|
export type Definition = AnySchema;
|
|
10
|
-
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> =
|
|
10
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings>;
|
|
11
11
|
/**
|
|
12
12
|
* What an omittable field's Fabricator returns: the wrapped value, or `Omitted`
|
|
13
13
|
* when it should not appear — whether from the built-in presence roll or, via
|
|
@@ -51,6 +51,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
|
|
|
51
51
|
[Kind]: "object.omittable";
|
|
52
52
|
[Meta]: Meta<$Definition>;
|
|
53
53
|
bindings?: unknown[];
|
|
54
|
-
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]
|
|
54
|
+
readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
|
|
55
55
|
readonly [Adaptation]?: $Adaptations;
|
|
56
56
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Adaptations } from "../../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import { Kind, Meta, Omitted, type Adaptation, type Produces } from "../../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../../Schema/Types";
|
|
4
|
+
import { Kind, Meta, Omitted, type Adaptation, type Produced, type Produces } from "../../../Types";
|
|
5
5
|
/**
|
|
6
6
|
* The wrapped field's Schema — the value type when the roll is
|
|
7
7
|
* present-with-a-value.
|
|
@@ -15,7 +15,7 @@ export type Definition = AnySchema;
|
|
|
15
15
|
* `{ a?: T | undefined }` — a real `?:` (from `OmittableKeys`, which also
|
|
16
16
|
* covers this kind) _and_ a real `| undefined`.
|
|
17
17
|
*/
|
|
18
|
-
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> =
|
|
18
|
+
export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = FabricatedBy<$Definition, $Bindings> | undefined;
|
|
19
19
|
/**
|
|
20
20
|
* What an optional field's Fabricator returns: the wrapped value, `undefined`,
|
|
21
21
|
* or `Omitted` when the key should not appear — whether from the built-in
|
|
@@ -67,6 +67,6 @@ export interface Core<$Definition extends Definition = Definition, $Adaptations
|
|
|
67
67
|
[Kind]: "object.optional";
|
|
68
68
|
[Meta]: Meta<$Definition>;
|
|
69
69
|
bindings?: unknown[];
|
|
70
|
-
readonly [Produces]?: Fabricated<$Definition, NonNullable<this["bindings"]
|
|
70
|
+
readonly [Produces]?: Produced<Fabricated<$Definition, NonNullable<this["bindings"]>>>;
|
|
71
71
|
readonly [Adaptation]?: $Adaptations;
|
|
72
72
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import { Produces, type Adaptation, type Kind, type Meta } from "../../Types";
|
|
3
|
+
import { Produces, type Adaptation, type Kind, type Meta, type Produced } from "../../Types";
|
|
4
4
|
export type Fabricated<$T> = $T;
|
|
5
5
|
/**
|
|
6
6
|
* A single required member, unlike the two-arm unions kinds with a `whereby`
|
|
@@ -13,6 +13,6 @@ export type Meta<$T = unknown> = {
|
|
|
13
13
|
export type Core<$T = unknown, $Adaptations extends Adaptations = {}> = {
|
|
14
14
|
[Kind]: "opaque";
|
|
15
15
|
[Meta]: Meta<$T>;
|
|
16
|
-
readonly [Produces]?: Fabricated<$T
|
|
16
|
+
readonly [Produces]?: Produced<Fabricated<$T>>;
|
|
17
17
|
readonly [Adaptation]?: $Adaptations;
|
|
18
18
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import type { Produce } from "../../Random/Types";
|
|
3
|
-
import type { AnySchema,
|
|
4
|
-
import { Produces, type Adaptation, type Kind, type Meta } from "../../Types";
|
|
3
|
+
import type { AnySchema, Fabricated as FabricatedBy } from "../../Schema/Types";
|
|
4
|
+
import { Produces, type Adaptation, type Kind, type Meta, type Produced } 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
|
|
@@ -13,9 +13,14 @@ import { Produces, type Adaptation, type Kind, type Meta } from "../../Types";
|
|
|
13
13
|
* `symbol` is included deliberately: symbols are legal property keys. Excluding
|
|
14
14
|
* them would arbitrarily narrow what a record can describe. They do not survive
|
|
15
15
|
* `Adapter/TypeBox` — see its `record` case.
|
|
16
|
+
*
|
|
17
|
+
* Matched through the box (`Produced<…>`, `Types.ts`) so that a key schema
|
|
18
|
+
* which may produce `undefined` is rejected whatever the caller's
|
|
19
|
+
* `exactOptionalPropertyTypes` — unboxed and with the flag off, the optional
|
|
20
|
+
* slot already admits `undefined`.
|
|
16
21
|
*/
|
|
17
22
|
export type Key = AnySchema & {
|
|
18
|
-
readonly [Produces]?: string | symbol
|
|
23
|
+
readonly [Produces]?: Produced<string | symbol>;
|
|
19
24
|
};
|
|
20
25
|
export type Value = AnySchema;
|
|
21
26
|
/**
|
|
@@ -29,7 +34,7 @@ type IsKeyspaceOpen<$Key> = string extends $Key ? true : symbol extends $Key ? t
|
|
|
29
34
|
* An open key (`string`, `symbol`, or both) is a plain index signature: no
|
|
30
35
|
* `Partial` — an index signature never guarantees a key is present, and
|
|
31
36
|
* wrapping one would only add a spurious `| undefined`. Carrying
|
|
32
|
-
* `
|
|
37
|
+
* `FabricatedBy<$Key>` rather than hardcoding `string` keeps a mixed `string |
|
|
33
38
|
* symbol` key as `Record<string | symbol, ...>` instead of silently dropping
|
|
34
39
|
* the symbol half.
|
|
35
40
|
*
|
|
@@ -38,7 +43,7 @@ type IsKeyspaceOpen<$Key> = string extends $Key ? true : symbol extends $Key ? t
|
|
|
38
43
|
* a two-member key schema may produce only one. Every key present wants
|
|
39
44
|
* `T.object({ ... })` — what a record over a finite key set degenerates to.
|
|
40
45
|
*/
|
|
41
|
-
export type Fabricated<$Key extends Key = Key, $Value extends Value = Value, $Bindings extends unknown[] = []> = IsKeyspaceOpen<
|
|
46
|
+
export type Fabricated<$Key extends Key = Key, $Value extends Value = Value, $Bindings extends unknown[] = []> = IsKeyspaceOpen<FabricatedBy<$Key, $Bindings>> extends true ? Record<FabricatedBy<$Key, $Bindings> & PropertyKey, FabricatedBy<$Value, $Bindings>> : Partial<Record<FabricatedBy<$Key, $Bindings> & PropertyKey, FabricatedBy<$Value, $Bindings>>>;
|
|
42
47
|
/**
|
|
43
48
|
* How many entries to attempt, uniformly across `[minTried, max]`.
|
|
44
49
|
*
|
|
@@ -79,7 +84,7 @@ export interface Core<$Key extends Key = Key, $Value extends Value = Value, $Ada
|
|
|
79
84
|
[Kind]: "record";
|
|
80
85
|
[Meta]: Meta<$Key, $Value>;
|
|
81
86
|
bindings?: unknown[];
|
|
82
|
-
readonly [Produces]?: Fabricated<$Key, $Value, NonNullable<this["bindings"]
|
|
87
|
+
readonly [Produces]?: Produced<Fabricated<$Key, $Value, NonNullable<this["bindings"]>>>;
|
|
83
88
|
readonly [Adaptation]?: $Adaptations;
|
|
84
89
|
}
|
|
85
90
|
export {};
|