@ghostry/fabricator 0.0.8 → 0.0.9

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.
Files changed (73) hide show
  1. package/dist/esm/Bound.js +6 -1
  2. package/dist/esm/Distribution/index.js +9 -1
  3. package/dist/esm/Instance/Core.js +8 -8
  4. package/dist/esm/Primitive/always/Schema.js +2 -0
  5. package/dist/esm/Primitive/array/Fabricator.js +4 -9
  6. package/dist/esm/Primitive/array/Schema.js +2 -0
  7. package/dist/esm/Primitive/bigint/Schema.js +2 -0
  8. package/dist/esm/Primitive/boolean/Schema.js +2 -0
  9. package/dist/esm/Primitive/choice/Schema.js +2 -0
  10. package/dist/esm/Primitive/date/Schema.js +2 -0
  11. package/dist/esm/Primitive/derive/Schema.js +2 -0
  12. package/dist/esm/Primitive/enum/Schema.js +2 -0
  13. package/dist/esm/Primitive/null/Schema.js +2 -0
  14. package/dist/esm/Primitive/nullable/Schema.js +2 -0
  15. package/dist/esm/Primitive/nullish/Schema.js +2 -0
  16. package/dist/esm/Primitive/number/Fabricator.js +3 -7
  17. package/dist/esm/Primitive/number/Schema.js +2 -0
  18. package/dist/esm/Primitive/object/Schema.js +3 -1
  19. package/dist/esm/Primitive/object/compute/Schema.js +2 -0
  20. package/dist/esm/Primitive/object/omittable/Schema.js +2 -0
  21. package/dist/esm/Primitive/object/optional/Schema.js +2 -0
  22. package/dist/esm/Primitive/opaque/Schema.js +2 -0
  23. package/dist/esm/Primitive/record/Fabricator.js +6 -1
  24. package/dist/esm/Primitive/record/Schema.js +2 -0
  25. package/dist/esm/Primitive/recursive/Schema.js +2 -0
  26. package/dist/esm/Primitive/recursive/self/Schema.js +2 -0
  27. package/dist/esm/Primitive/string/Fabricator.js +6 -2
  28. package/dist/esm/Primitive/string/Schema.js +2 -0
  29. package/dist/esm/Primitive/symbol/Schema.js +2 -0
  30. package/dist/esm/Primitive/tuple/Schema.js +2 -0
  31. package/dist/esm/Primitive/undefinable/Schema.js +2 -0
  32. package/dist/esm/Primitive/undefined/Schema.js +2 -0
  33. package/dist/esm/Schema/Satisfies.js +5 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/types/Bound.d.ts +20 -4
  36. package/dist/types/Distribution/index.d.ts +14 -0
  37. package/dist/types/Error/index.d.ts +2 -4
  38. package/dist/types/Harnessing/Core.d.ts +4 -4
  39. package/dist/types/Primitive/always/Schema.d.ts +8 -1
  40. package/dist/types/Primitive/array/Registry.d.ts +7 -5
  41. package/dist/types/Primitive/array/Schema.d.ts +7 -0
  42. package/dist/types/Primitive/array/Types.d.ts +3 -9
  43. package/dist/types/Primitive/bigint/Schema.d.ts +7 -0
  44. package/dist/types/Primitive/boolean/Schema.d.ts +7 -0
  45. package/dist/types/Primitive/choice/Schema.d.ts +7 -0
  46. package/dist/types/Primitive/date/Schema.d.ts +7 -0
  47. package/dist/types/Primitive/derive/Schema.d.ts +8 -0
  48. package/dist/types/Primitive/derive/Types.d.ts +5 -6
  49. package/dist/types/Primitive/enum/Schema.d.ts +7 -0
  50. package/dist/types/Primitive/null/Schema.d.ts +9 -2
  51. package/dist/types/Primitive/nullable/Schema.d.ts +7 -0
  52. package/dist/types/Primitive/nullish/Schema.d.ts +7 -0
  53. package/dist/types/Primitive/number/Schema.d.ts +7 -0
  54. package/dist/types/Primitive/object/Schema.d.ts +12 -2
  55. package/dist/types/Primitive/object/compute/Schema.d.ts +8 -0
  56. package/dist/types/Primitive/object/omittable/Schema.d.ts +10 -1
  57. package/dist/types/Primitive/object/optional/Schema.d.ts +9 -1
  58. package/dist/types/Primitive/opaque/Schema.d.ts +8 -1
  59. package/dist/types/Primitive/record/Schema.d.ts +7 -0
  60. package/dist/types/Primitive/record/Types.d.ts +2 -2
  61. package/dist/types/Primitive/recursive/Schema.d.ts +8 -1
  62. package/dist/types/Primitive/recursive/self/Schema.d.ts +11 -1
  63. package/dist/types/Primitive/string/Registry.d.ts +13 -9
  64. package/dist/types/Primitive/string/Schema.d.ts +7 -0
  65. package/dist/types/Primitive/string/Types.d.ts +7 -11
  66. package/dist/types/Primitive/symbol/Schema.d.ts +7 -0
  67. package/dist/types/Primitive/tuple/Schema.d.ts +7 -0
  68. package/dist/types/Primitive/undefinable/Schema.d.ts +7 -0
  69. package/dist/types/Primitive/undefined/Schema.d.ts +9 -2
  70. package/dist/types/Schema/Satisfies.d.ts +84 -0
  71. package/dist/types/Schema/Types.d.ts +17 -1
  72. package/dist/types/index.d.ts +9 -0
  73. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
- import type { Core, Value } from "./Types";
3
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
+ import type { Core, Fabricated, Value } from "./Types";
4
5
  /**
5
6
  * A fixed value, so unlike every other kind there is no `.as()` — nothing left
6
7
  * to override about producing it. `adapt` still applies: what a value _means_
@@ -10,6 +11,12 @@ import type { Core, Value } from "./Types";
10
11
  * close the gap.
11
12
  */
12
13
  export interface Schema<$Value extends Value = Value, $Adaptations extends Adaptations = {}> extends Core<$Value, $Adaptations> {
14
+ /**
15
+ * Check that this schema's fabricated value type is assignable to `$Target`.
16
+ * Identity at runtime; the target is not carried into later chained calls —
17
+ * see `object/Schema.ts`'s `satisfies`.
18
+ */
19
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Value>, $Target>): Schema<$Value, $Adaptations>;
13
20
  /**
14
21
  * Override what this schema maps to in one or more external schema libraries
15
22
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -3,11 +3,13 @@ import { Schema } from "./Schema";
3
3
  import type { Definition, Fabricated, InputWhereby } from "./Types";
4
4
  type ThisRegistry<$Definition extends Definition> = {
5
5
  /**
6
- * An array of `definition`, repeated `whereby.length` times — either a fixed
7
- * count, or uniformly across `[length.min, length.max]` with `length.min`
8
- * defaulting to inclusive 0, so an empty array is a legitimate outcome when
9
- * no `min` is given. Exclusive ends use a Bound object; a bare `length: N` is
10
- * stored as min = max = N inclusive.
6
+ * An array of `definition`, repeated `length` times. `length` is a bare `N`
7
+ * (exactly N) or `{ min?, max, distribution? }`. `min` defaults to inclusive
8
+ * 0, so an empty array is a legitimate outcome when no `min` is given.
9
+ * Exclusive ends use a Bound object. A bare `N` is stored as min = max = N
10
+ * inclusive and carries no distribution. Without `distribution`, the length
11
+ * is drawn uniformly across the inclusive interval; `distribution` shapes
12
+ * that draw the same way it does for `T.number.integer`.
11
13
  */
12
14
  whereby: (whereby: InputWhereby) => Schema<$Definition>;
13
15
  /**
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Definition, Fabricated } from "./Types";
5
6
  /**
6
7
  * The buildable recipe for an `array`: a single element Schema, repeated
@@ -13,6 +14,12 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
13
14
  * (or future validation of `produce`) still has them to check against.
14
15
  */
15
16
  as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
17
+ /**
18
+ * Check that this schema's fabricated value type is assignable to `$Target`.
19
+ * Identity at runtime; the target is not carried into later chained calls —
20
+ * see `object/Schema.ts`'s `satisfies`.
21
+ */
22
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Definition>, $Target>): Schema<$Definition, $Adaptations>;
16
23
  /**
17
24
  * Override what this schema maps to in one or more external schema libraries
18
25
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,21 +1,15 @@
1
1
  import type { Adaptations } from "../../Adapter/Types";
2
- import type { Bound, InputBound } from "../../Bound";
2
+ import type { InputLength, Length } from "../../Bound";
3
3
  import type { Produce } from "../../Random/Types";
4
4
  import type { AnySchema, ValueOf } from "../../Schema/Types";
5
5
  import type { Adaptation, Kind, Meta, Produces } from "../../Types";
6
6
  export type Definition = AnySchema;
7
7
  export type Fabricated<$Definition extends Definition, $Bindings extends unknown[] = []> = Array<ValueOf<$Definition, $Bindings>>;
8
8
  export type InputWhereby = {
9
- length: number | {
10
- max: InputBound<number>;
11
- min?: InputBound<number> | undefined;
12
- };
9
+ length: InputLength;
13
10
  };
14
11
  export type Whereby = {
15
- length: {
16
- min: Bound<number>;
17
- max: Bound<number>;
18
- };
12
+ length: Length;
19
13
  };
20
14
  /**
21
15
  * `whereby` (a length spec — no natural bound to fuzz to, so unlike
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, Meta as ThisMeta } from "./Types";
5
6
  /**
6
7
  * Buildable `bigint` recipe: a range (`whereby` — required, like `string`; no
@@ -18,6 +19,12 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
18
19
  * validation of `produce`) still has it to check against.
19
20
  */
20
21
  as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
22
+ /**
23
+ * Check that this schema's fabricated value type is assignable to `$Target`.
24
+ * Identity at runtime; the target is not carried into later chained calls —
25
+ * see `object/Schema.ts`'s `satisfies`.
26
+ */
27
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Meta, $Adaptations>;
21
28
  /**
22
29
  * Override what this schema maps to in one or more external schema libraries
23
30
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, Meta as ThisMeta, Weights } from "./Types";
5
6
  /**
6
7
  * Buildable `boolean` recipe: an even coin flip, a weighted one (`weights`), or
@@ -18,6 +19,12 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
18
19
  * validation of `produce`) still has it to check against.
19
20
  */
20
21
  as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
22
+ /**
23
+ * Check that this schema's fabricated value type is assignable to `$Target`.
24
+ * Identity at runtime; the target is not carried into later chained calls —
25
+ * see `object/Schema.ts`'s `satisfies`.
26
+ */
27
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Meta, $Adaptations>;
21
28
  weighted: (weights: Weights) => Schema<$Meta, $Adaptations>;
22
29
  /**
23
30
  * Override what this schema maps to in one or more external schema libraries
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, Items } from "./Types";
5
6
  /**
6
7
  * Buildable `choice` recipe: a weighted set of option Schemas, one of which is
@@ -15,6 +16,12 @@ export interface Schema<$Items extends Items = Items, $Adaptations extends Adapt
15
16
  * validation of `produce`) still has it to check against.
16
17
  */
17
18
  as: (produce: Produce<Fabricated<$Items>>) => Schema<$Items, $Adaptations>;
19
+ /**
20
+ * Check that this schema's fabricated value type is assignable to `$Target`.
21
+ * Identity at runtime; the target is not carried into later chained calls —
22
+ * see `object/Schema.ts`'s `satisfies`.
23
+ */
24
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Items>, $Target>): Schema<$Items, $Adaptations>;
18
25
  /**
19
26
  * Override what this schema maps to in one or more external schema libraries
20
27
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, Meta as ThisMeta } from "./Types";
5
6
  /**
6
7
  * Buildable `Date` recipe: a range/distribution (`whereby`, absent for the
@@ -18,6 +19,12 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
18
19
  * future validation of `produce`) still has them to check against.
19
20
  */
20
21
  as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
22
+ /**
23
+ * Check that this schema's fabricated value type is assignable to `$Target`.
24
+ * Identity at runtime; the target is not carried into later chained calls —
25
+ * see `object/Schema.ts`'s `satisfies`.
26
+ */
27
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Meta, $Adaptations>;
21
28
  /**
22
29
  * Override what this schema maps to in one or more external schema libraries
23
30
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { ProduceContext } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type * as tuple from "../tuple/Types";
5
6
  import type { Core, From, Resolved, Source } from "./Types";
6
7
  /**
@@ -24,6 +25,13 @@ export type Deriver<$From extends From, $To extends Source> = {
24
25
  * for the mismatch check against `to`.
25
26
  */
26
27
  export interface Schema<$From extends From = From, $To extends Source = Source, $Adaptations extends Adaptations = {}> extends Core<$From, $To, $Adaptations> {
28
+ /**
29
+ * Check that this schema's fabricated value type is assignable to `$Target`.
30
+ * Identity at runtime; the target is not carried into later chained calls —
31
+ * see `object/Schema.ts`'s `satisfies`. The produced type is `to`'s
32
+ * (`Resolved<$To>`), not `from`'s.
33
+ */
34
+ satisfies<$Target>(this: this & SatisfiesThis<Resolved<$To>, $Target>): Schema<$From, $To, $Adaptations>;
27
35
  /**
28
36
  * Override what this schema maps to in one or more external schema libraries
29
37
  * — see `string/Schema.ts`'s `adapt` for the full contract. An unadapted
@@ -18,12 +18,11 @@ export type { Denoted, Resolved, Source } from "../object/compute/Types";
18
18
  * `from` is stored after `toSchema` (inert per-slot schemas, same as `tuple`).
19
19
  * `to` is stored exactly as given, whether a Schema or a builder, so its
20
20
  * `[Meta]` and `[Adaptation]` survive: adapters convert it as a nested schema
21
- * (honoring its own adaptation unless the derive is adapted), and
22
- * `toValueKind` follows it to the kind a result or override is checked
23
- * against. `resolve` is plain data from the moment `.as(resolve)` is called.
24
- * `to` is only used for its shape/type — the value comes entirely from
25
- * `resolve`, which is why `to` may not even have a buildable recipe (a bare
26
- * `T.string`/`T.bigint`).
21
+ * (honoring its own adaptation unless the derive is adapted), and `toValueKind`
22
+ * follows it to the kind a result or override is checked against. `resolve` is
23
+ * plain data from the moment `.as(resolve)` is called. `to` is only used for
24
+ * its shape/type — the value comes entirely from `resolve`, which is why `to`
25
+ * may not even have a buildable recipe (a bare `T.string`/`T.bigint`).
27
26
  */
28
27
  export type Meta<$From extends From = From, $To extends Source = Source> = {
29
28
  from: $From;
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, Items } from "./Types";
5
6
  /**
6
7
  * The buildable recipe for an `enum`: a weighted set of member values, one of
@@ -14,6 +15,12 @@ export interface Schema<$Items extends Items = Items, $Adaptations extends Adapt
14
15
  * validation of `produce`) still has it to check against.
15
16
  */
16
17
  as: (produce: Produce<Fabricated<$Items>>) => Schema<$Items, $Adaptations>;
18
+ /**
19
+ * Check that this schema's fabricated value type is assignable to `$Target`.
20
+ * Identity at runtime; the target is not carried into later chained calls —
21
+ * see `object/Schema.ts`'s `satisfies`.
22
+ */
23
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Items>, $Target>): Schema<$Items, $Adaptations>;
17
24
  /**
18
25
  * Override what this schema maps to in one or more external schema libraries
19
26
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,12 +1,19 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
- import type { Core, Meta as ThisMeta } from "./Types";
3
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
+ import type { Core, Fabricated, Meta as ThisMeta } from "./Types";
4
5
  /**
5
6
  * Nothing to configure (see `Types.ts`'s `Meta`), so `adapt` is this kind's
6
- * only builder method — an external library that spells "null" differently
7
+ * only mapping method — an external library that spells "null" differently
7
8
  * still needs a way to say so.
8
9
  */
9
10
  export interface Schema<$Adaptations extends Adaptations = {}> extends Core<ThisMeta, $Adaptations> {
11
+ /**
12
+ * Check that this schema's fabricated value type is assignable to `$Target`.
13
+ * Identity at runtime; the target is not carried into later chained calls —
14
+ * see `object/Schema.ts`'s `satisfies`.
15
+ */
16
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Adaptations>;
10
17
  /**
11
18
  * Override what this schema maps to in one or more external schema libraries
12
19
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { AnySchema } from "../../Schema/Types";
5
6
  import type { Core, Definition, Fabricated, Weights } from "./Types";
6
7
  /**
@@ -16,6 +17,12 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
16
17
  * does.
17
18
  */
18
19
  as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
20
+ /**
21
+ * Check that this schema's fabricated value type is assignable to `$Target`.
22
+ * Identity at runtime; the target is not carried into later chained calls —
23
+ * see `object/Schema.ts`'s `satisfies`.
24
+ */
25
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Definition>, $Target>): Schema<$Definition, $Adaptations>;
19
26
  /**
20
27
  * Reweight the built-in 50/50 roll. Keys are optional — an omitted key keeps
21
28
  * baseline weight `1`, the same weight the 50/50 split already uses — but
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { AnySchema } from "../../Schema/Types";
5
6
  import type { Core, Definition, Fabricated, Weights } from "./Types";
6
7
  /**
@@ -16,6 +17,12 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
16
17
  * built-in three-way roll does.
17
18
  */
18
19
  as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
20
+ /**
21
+ * Check that this schema's fabricated value type is assignable to `$Target`.
22
+ * Identity at runtime; the target is not carried into later chained calls —
23
+ * see `object/Schema.ts`'s `satisfies`.
24
+ */
25
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Definition>, $Target>): Schema<$Definition, $Adaptations>;
19
26
  /**
20
27
  * Reweight the built-in three-way roll. Keys are optional — an omitted key
21
28
  * keeps baseline weight `1`, the same weight the uniform 1/3 split already
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, JsonSchema, Meta as ThisMeta } from "./Types";
5
6
  /**
6
7
  * Buildable `number` recipe: a range/distribution (`whereby`, absent for the
@@ -22,6 +23,12 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
22
23
  * against.
23
24
  */
24
25
  as: (produce: Produce<Fabricated>, hints?: JsonSchema) => Schema<$Meta, $Adaptations>;
26
+ /**
27
+ * Check that this schema's fabricated value type is assignable to `$Target`.
28
+ * Identity at runtime; the target is not carried into later chained calls —
29
+ * see `object/Schema.ts`'s `satisfies`.
30
+ */
31
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Meta, $Adaptations>;
25
32
  /**
26
33
  * Override what this schema maps to in one or more external schema libraries
27
34
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import type { AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { AnySchema } from "../../Schema/Types";
5
6
  import type { ShallowMerge } from "../../Utility/ShallowMerge";
6
7
  import type { Computer } from "./compute/Schema";
@@ -22,6 +23,14 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
22
23
  * against.
23
24
  */
24
25
  as: (produce: Produce<Fabricated<$Definition>>) => Schema<$Definition, $Adaptations>;
26
+ /**
27
+ * Check that this schema's fabricated value type is assignable to `$Target`.
28
+ * Identity at runtime; the target is not carried into later chained calls.
29
+ * Canonical `.satisfies`; every other kind's method is the same and points
30
+ * here. See `Schema/Satisfies.ts` for the `this`-param signature and why the
31
+ * alternatives fail.
32
+ */
33
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Definition>, $Target>): Schema<$Definition, $Adaptations>;
25
34
  /**
26
35
  * Override what this schema maps to in one or more external schema libraries
27
36
  * — see `string/Schema.ts`'s `adapt` for the full contract. Carried through
@@ -35,7 +44,8 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
35
44
  * `make` alongside `extend`/`refine`/`override`: those three rebuild from
36
45
  * `definition`/`refinements` rather than deriving from this object, so the
37
46
  * adaptation map has to be threaded through `make` itself or chaining one of
38
- * them would drop it (see `make`'s `adapt`).
47
+ * them would drop it (see `make`'s `adapt`). `as` and `satisfies` are the
48
+ * methods this factory attaches, so they are what the parameter omits.
39
49
  */
40
- export declare function Schema<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: Omit<Schema<$Definition, $Adaptations>, "as">): Schema<$Definition, $Adaptations>;
50
+ export declare function Schema<$Definition extends Definition, $Adaptations extends Adaptations = {}>(schema: Omit<Schema<$Definition, $Adaptations>, "as" | "satisfies">): Schema<$Definition, $Adaptations>;
41
51
  export declare function isObjectSchema(candidate: AnySchema): candidate is Schema;
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
3
3
  import type { AnySchema } from "../../../Schema/Types";
4
+ import { type SatisfiesThis } from "../../../Schema/Satisfies";
4
5
  import type * as object from "../Types";
5
6
  import type { Core, Resolved, Source } from "./Types";
6
7
  export type Computer<$Definition extends object.Definition> = <const $Source extends Source>(source: $Source) => {
@@ -9,6 +10,13 @@ export type Computer<$Definition extends object.Definition> = <const $Source ext
9
10
  }) => NoInfer<Resolved<$Source>>) => Schema<object.Fabricated<$Definition>, $Source>;
10
11
  };
11
12
  export interface Schema<$Fabricated, $Source extends Source, $Adaptations extends Adaptations = {}> extends Core<$Fabricated, $Source, $Adaptations> {
13
+ /**
14
+ * Check that this schema's fabricated value type is assignable to `$Target`.
15
+ * Identity at runtime; the target is not carried into later chained calls —
16
+ * see `object/Schema.ts`'s `satisfies`. The produced type is `source`'s
17
+ * (`Resolved<$Source>`), not the enclosing object's.
18
+ */
19
+ satisfies<$Target>(this: this & SatisfiesThis<Resolved<$Source>, $Target>): Schema<$Fabricated, $Source, $Adaptations>;
12
20
  /**
13
21
  * Override what this schema maps to in one or more external schema libraries
14
22
  * — see `string/Schema.ts`'s `adapt` for the full contract. Adapting the
@@ -1,8 +1,9 @@
1
1
  import { type AdaptationEntry } from "../../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
3
3
  import type { Produce } from "../../../Random/Types";
4
+ import { type SatisfiesThis } from "../../../Schema/Satisfies";
4
5
  import type { AnySchema } from "../../../Schema/Types";
5
- import type { Core, Definition, Resolved, Weights } from "./Types";
6
+ import type { Core, Definition, Fabricated, Resolved, Weights } from "./Types";
6
7
  export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
7
8
  /**
8
9
  * Layer an opaque production on this schema's existing `[Meta]` — carrying
@@ -12,6 +13,14 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
12
13
  * built-in roll does.
13
14
  */
14
15
  as: (produce: Produce<Resolved<$Definition>>) => Schema<$Definition, $Adaptations>;
16
+ /**
17
+ * Check that this schema's fabricated value type is assignable to `$Target`.
18
+ * Identity at runtime; the target is not carried into later chained calls —
19
+ * see `object/Schema.ts`'s `satisfies`. The produced type is the wrapped
20
+ * value (not `Omitted`); omission is a fact about the enclosing object's
21
+ * keys, which is why this check lives more usefully on the object.
22
+ */
23
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Definition>, $Target>): Schema<$Definition, $Adaptations>;
15
24
  /**
16
25
  * Reweight the built-in presence roll. Keys are optional — an omitted key
17
26
  * keeps baseline weight `1`, the same weight the 50/50 split already uses —
@@ -1,8 +1,9 @@
1
1
  import { type AdaptationEntry } from "../../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
3
3
  import type { Produce } from "../../../Random/Types";
4
+ import { type SatisfiesThis } from "../../../Schema/Satisfies";
4
5
  import type { AnySchema } from "../../../Schema/Types";
5
- import type { Core, Definition, Resolved, Weights } from "./Types";
6
+ import type { Core, Definition, Fabricated, Resolved, Weights } from "./Types";
6
7
  export interface Schema<$Definition extends Definition = Definition, $Adaptations extends Adaptations = {}> extends Core<$Definition, $Adaptations> {
7
8
  /**
8
9
  * Layer an opaque production on this schema's existing `[Meta]` — carrying
@@ -12,6 +13,13 @@ export interface Schema<$Definition extends Definition = Definition, $Adaptation
12
13
  * built-in three-way roll does.
13
14
  */
14
15
  as: (produce: Produce<Resolved<$Definition>>) => Schema<$Definition, $Adaptations>;
16
+ /**
17
+ * Check that this schema's fabricated value type is assignable to `$Target`.
18
+ * Identity at runtime; the target is not carried into later chained calls —
19
+ * see `object/Schema.ts`'s `satisfies`. The produced type includes `|
20
+ * undefined`; omission is a fact about the enclosing object's keys.
21
+ */
22
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Definition>, $Target>): Schema<$Definition, $Adaptations>;
15
23
  /**
16
24
  * Reweight the built-in three-way roll. Keys are optional — an omitted key
17
25
  * keeps baseline weight `1`, the same weight the uniform 1/3 split already
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
- import type { Core } from "./Types";
3
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
+ import type { Core, Fabricated } from "./Types";
4
5
  /**
5
6
  * Escape hatch for values no kind models — a `Map`, a `Set`, a `URL`, a class
6
7
  * instance, a branded type. `produce` is supplied at construction and receives
@@ -12,6 +13,12 @@ import type { Core } from "./Types";
12
13
  * imprecise, and `.adapt(typebox, ...)` is the only way to say more.
13
14
  */
14
15
  export interface Schema<$T = unknown, $Adaptations extends Adaptations = {}> extends Core<$T, $Adaptations> {
16
+ /**
17
+ * Check that this schema's fabricated value type is assignable to `$Target`.
18
+ * Identity at runtime; the target is not carried into later chained calls —
19
+ * see `object/Schema.ts`'s `satisfies`.
20
+ */
21
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$T>, $Target>): Schema<$T, $Adaptations>;
15
22
  /**
16
23
  * Override what this schema maps to in one or more external schema libraries
17
24
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, Key, Value } from "./Types";
5
6
  /**
6
7
  * The buildable recipe for a `record`: a key Schema and a value Schema, drawn
@@ -14,6 +15,12 @@ export interface Schema<$Key extends Key = Key, $Value extends Value = Value, $A
14
15
  * (or future validation of `produce`) still has them to check against.
15
16
  */
16
17
  as: (produce: Produce<Fabricated<$Key, $Value>>) => Schema<$Key, $Value, $Adaptations>;
18
+ /**
19
+ * Check that this schema's fabricated value type is assignable to `$Target`.
20
+ * Identity at runtime; the target is not carried into later chained calls —
21
+ * see `object/Schema.ts`'s `satisfies`.
22
+ */
23
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Key, $Value>, $Target>): Schema<$Key, $Value, $Adaptations>;
17
24
  /**
18
25
  * Override what this schema maps to in one or more external schema libraries
19
26
  * — see `string/Schema.ts`'s `adapt`. Particularly relevant here: a
@@ -48,8 +48,8 @@ export type Fabricated<$Key extends Key = Key, $Value extends Value = Value, $Bi
48
48
  * so. `minTried` is optional, default `0`, matching `string`'s
49
49
  * `whereby.length.min`.
50
50
  *
51
- * No bare-number form (unlike `array`'s `length`): "exactly N" is a promise a
52
- * collapsing key set cannot keep.
51
+ * No bare-number form (unlike `string`'s and `array`'s `length`): "exactly N"
52
+ * is a promise a collapsing key set cannot keep.
53
53
  */
54
54
  export type Whereby = {
55
55
  size: {
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
- import type { Core } from "./Types";
3
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
+ import type { Core, Fabricated } from "./Types";
4
5
  /**
5
6
  * A recursive schema, produced by `.whereby({ depth })` — see `Registry.ts` for
6
7
  * the builder `T.recursive(body)` itself returns. `terminal` is optional there;
@@ -12,6 +13,12 @@ import type { Core } from "./Types";
12
13
  * out, since adding it later is non-breaking.
13
14
  */
14
15
  export interface Schema<$Body = unknown, $Adaptations extends Adaptations = {}> extends Core<$Body, $Adaptations> {
16
+ /**
17
+ * Check that this schema's fabricated value type is assignable to `$Target`.
18
+ * Identity at runtime; the target is not carried into later chained calls —
19
+ * see `object/Schema.ts`'s `satisfies`.
20
+ */
21
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated<$Body>, $Target>): Schema<$Body, $Adaptations>;
15
22
  /**
16
23
  * Override what this schema maps to in one or more external schema libraries
17
24
  * — see `string/Schema.ts`'s `adapt` for the full contract.
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../../Adapter/Types";
3
- import type { Core } from "./Types";
3
+ import { type SatisfiesThis } from "../../../Schema/Satisfies";
4
+ import type { Core, Fabricated } from "./Types";
4
5
  /**
5
6
  * The placeholder `T.recursive`'s body callback receives in place of the schema
6
7
  * being defined — everywhere `self` appears, it stands for "recurse one level
@@ -15,6 +16,15 @@ import type { Core } from "./Types";
15
16
  * other kind.
16
17
  */
17
18
  export interface Schema<$Adaptations extends Adaptations = {}> extends Core<$Adaptations> {
19
+ /**
20
+ * Check that this schema's fabricated value type is assignable to `$Target`.
21
+ * Identity at runtime; the target is not carried into later chained calls —
22
+ * see `object/Schema.ts`'s `satisfies`. Outside `ValueOf`'s `$Bindings`,
23
+ * `Fabricated` is `unknown` — a `self` has no value of its own. Put
24
+ * `.satisfies` on the enclosing `T.recursive(...).whereby(...)` to check the
25
+ * tree.
26
+ */
27
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Adaptations>;
18
28
  adapt: <const $Adapter extends Adapter, $Returnable extends ReturnType<$Adapter["convert"]>>(adapter: $Adapter, produce: (adapting: Adapting<Schema<$Adaptations>>) => $Returnable) => Schema<WithAdaptations<$Adaptations, AdaptationEntry<$Adapter, $Returnable>>>;
19
29
  }
20
30
  export declare function Schema<$Adaptations extends Adaptations = {}>(schema: Core<$Adaptations>): Schema<$Adaptations>;
@@ -19,17 +19,21 @@ declare const _default: {
19
19
  hints: JsonSchema | undefined;
20
20
  }>;
21
21
  /**
22
- * A string whose length falls uniformly within `[length.min, length.max]`;
23
- * `length.min` defaults to inclusive 0. Exclusive ends use a Bound object.
22
+ * A string of `length` UTF-16 code units. `length` is a bare `N` (exactly N)
23
+ * or `{ min?, max, distribution? }`. `min` defaults to inclusive 0. Exclusive
24
+ * ends use a Bound object. A bare `N` is stored as min = max = N inclusive
25
+ * and carries no distribution. Without `distribution`, the length is drawn
26
+ * uniformly across the inclusive interval; `distribution` shapes that draw
27
+ * the same way it does for `T.number.integer`.
28
+ *
24
29
  * Pass `composition` to control which characters appear and in what
25
30
  * proportion; without one, characters span all Unicode scalar values (the
26
- * codespace minus surrogates, so always well-formed UTF-16).
27
- *
28
- * `length` counts UTF-16 code units, so the result's `.length` equals the
29
- * chosen length exactly. When the composition cannot fill the final code
30
- * units — e.g. only astral, two-unit characters remain for a one-unit gap —
31
- * the gap is topped up with a well-formed BMP character outside the requested
32
- * `composition`, inserted at a random character boundary.
31
+ * codespace minus surrogates, so always well-formed UTF-16). The result's
32
+ * `.length` equals the chosen length exactly. When the composition cannot
33
+ * fill the final code units — e.g. only astral, two-unit characters remain
34
+ * for a one-unit gap — the gap is topped up with a well-formed BMP character
35
+ * outside the requested `composition`, inserted at a random character
36
+ * boundary.
33
37
  */
34
38
  whereby: (whereby: InputWhereby) => Schema<{
35
39
  whereby: Whereby;
@@ -1,6 +1,7 @@
1
1
  import { type AdaptationEntry } from "../../Adapter/Core";
2
2
  import type { Adaptations, Adapter, Adapting, WithAdaptations } from "../../Adapter/Types";
3
3
  import type { Produce } from "../../Random/Types";
4
+ import { type SatisfiesThis } from "../../Schema/Satisfies";
4
5
  import type { Core, Fabricated, JsonSchema, Meta as ThisMeta } from "./Types";
5
6
  /**
6
7
  * Buildable `string` recipe: length/composition (`whereby` — required, unlike
@@ -19,6 +20,12 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
19
20
  * validation of `produce`) still has it to check against.
20
21
  */
21
22
  as: (produce: Produce<Fabricated>, hints?: JsonSchema) => Schema<$Meta, $Adaptations>;
23
+ /**
24
+ * Check that this schema's fabricated value type is assignable to `$Target`.
25
+ * Identity at runtime; the target is not carried into later chained calls —
26
+ * see `object/Schema.ts`'s `satisfies`.
27
+ */
28
+ satisfies<$Target>(this: this & SatisfiesThis<Fabricated, $Target>): Schema<$Meta, $Adaptations>;
22
29
  /**
23
30
  * Override what this schema maps to in one external schema library, for a
24
31
  * contract no native kind expresses — a `string` that is really an email, a