@ghostry/fabricator 0.0.12 → 0.0.14
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 -1
- package/dist/esm/Bound.js +74 -1
- package/dist/esm/Distribution/index.js +103 -2
- package/dist/esm/Enumeration/Enumerate.js +10 -5
- package/dist/esm/Enumeration/Plan.js +2 -2
- package/dist/esm/Error/index.js +96 -27
- package/dist/esm/Fabricator/Constructor.js +7 -5
- package/dist/esm/Fabricator/Fabricate.js +1 -6
- package/dist/esm/Instance/Core.js +3 -0
- package/dist/esm/Primitive/array/Admits.js +18 -0
- package/dist/esm/Primitive/array/Fabricator.js +20 -2
- package/dist/esm/Primitive/array/Registry.js +32 -0
- package/dist/esm/Primitive/array/Schema.js +8 -0
- package/dist/esm/Primitive/bigint/Admits.js +11 -0
- package/dist/esm/Primitive/bigint/Fabricator.js +16 -23
- package/dist/esm/Primitive/bigint/Registry.js +17 -6
- package/dist/esm/Primitive/bigint/Schema.js +8 -0
- package/dist/esm/Primitive/boolean/Registry.js +10 -8
- package/dist/esm/Primitive/date/Admits.js +22 -0
- package/dist/esm/Primitive/date/Defaults.js +27 -1
- package/dist/esm/Primitive/date/Fabricator.js +32 -34
- package/dist/esm/Primitive/date/Registry.js +111 -38
- package/dist/esm/Primitive/date/Schema.js +8 -0
- package/dist/esm/Primitive/enum/Fabricator.js +14 -2
- package/dist/esm/Primitive/enum/Registry.js +38 -25
- package/dist/esm/Primitive/index.js +1 -0
- package/dist/esm/Primitive/null/Registry.js +6 -4
- package/dist/esm/Primitive/number/Admits.js +27 -0
- package/dist/esm/Primitive/number/Fabricator.js +18 -9
- package/dist/esm/Primitive/number/Registry.js +86 -29
- package/dist/esm/Primitive/number/Schema.js +10 -3
- package/dist/esm/Primitive/object/Fabricator.js +2 -0
- package/dist/esm/Primitive/record/Admits.js +42 -0
- package/dist/esm/Primitive/record/Fabricator.js +49 -19
- package/dist/esm/Primitive/record/Registry.js +29 -0
- package/dist/esm/Primitive/record/Schema.js +8 -0
- package/dist/esm/Primitive/recursive/Fabricator.js +3 -2
- package/dist/esm/Primitive/recursive/Terminate.js +16 -2
- package/dist/esm/Primitive/string/Admits.js +26 -0
- package/dist/esm/Primitive/string/Capacity.js +81 -0
- package/dist/esm/Primitive/string/Fabricator.js +23 -43
- package/dist/esm/Primitive/string/Registry.js +31 -9
- package/dist/esm/Primitive/string/Schema.js +10 -3
- package/dist/esm/Primitive/string/Sources.js +41 -0
- package/dist/esm/Primitive/symbol/Registry.js +15 -13
- package/dist/esm/Primitive/undefined/Registry.js +6 -4
- package/dist/esm/Primitive/unique/Registry.js +22 -0
- package/dist/esm/Primitive/unique/index.js +2 -0
- package/dist/esm/Schema/Core.js +9 -1
- package/dist/esm/Schema/Registry.js +27 -7
- package/dist/esm/Types.js +2 -1
- package/dist/esm/Unique/Capacity.js +85 -0
- package/dist/esm/Unique/Distinct.js +187 -0
- package/dist/esm/Unique/Key.js +70 -0
- package/dist/esm/Unique/Override.js +23 -0
- package/dist/esm/Unique/Strategy.js +173 -0
- package/dist/esm/Utility/DeepMerge.js +47 -6
- package/dist/esm/internal.js +2 -0
- package/dist/types/Bound.d.ts +66 -0
- package/dist/types/Distribution/index.d.ts +82 -0
- package/dist/types/Enumeration/Types.d.ts +10 -1
- package/dist/types/Error/index.d.ts +283 -0
- package/dist/types/Fabricator/Constructor.d.ts +6 -2
- package/dist/types/Fabricator/Fabricate.d.ts +4 -2
- package/dist/types/Fabricator/Types.d.ts +13 -0
- package/dist/types/Instance/Types.d.ts +14 -0
- package/dist/types/Primitive/array/Admits.d.ts +7 -0
- package/dist/types/Primitive/array/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/array/Registry.d.ts +38 -1
- package/dist/types/Primitive/array/Schema.d.ts +6 -1
- package/dist/types/Primitive/array/Types.d.ts +33 -1
- package/dist/types/Primitive/bigint/Admits.d.ts +7 -0
- package/dist/types/Primitive/bigint/Fabricator.d.ts +3 -1
- package/dist/types/Primitive/bigint/Registry.d.ts +20 -0
- package/dist/types/Primitive/bigint/Schema.d.ts +9 -1
- package/dist/types/Primitive/bigint/Types.d.ts +27 -3
- package/dist/types/Primitive/boolean/Registry.d.ts +6 -1
- package/dist/types/Primitive/date/Admits.d.ts +7 -0
- package/dist/types/Primitive/date/Defaults.d.ts +22 -1
- package/dist/types/Primitive/date/Fabricator.d.ts +3 -1
- package/dist/types/Primitive/date/Registry.d.ts +54 -12
- package/dist/types/Primitive/date/Schema.d.ts +10 -1
- package/dist/types/Primitive/date/Types.d.ts +53 -4
- package/dist/types/Primitive/enum/Fabricator.d.ts +3 -1
- package/dist/types/Primitive/enum/Registry.d.ts +20 -0
- package/dist/types/Primitive/enum/Types.d.ts +5 -0
- package/dist/types/Primitive/index.d.ts +1 -0
- package/dist/types/Primitive/null/Registry.d.ts +6 -1
- package/dist/types/Primitive/number/Admits.d.ts +9 -0
- package/dist/types/Primitive/number/Fabricator.d.ts +3 -1
- package/dist/types/Primitive/number/Registry.d.ts +50 -2
- package/dist/types/Primitive/number/Schema.d.ts +10 -2
- package/dist/types/Primitive/number/Types.d.ts +32 -10
- package/dist/types/Primitive/record/Admits.d.ts +18 -0
- package/dist/types/Primitive/record/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/record/Registry.d.ts +18 -1
- package/dist/types/Primitive/record/Schema.d.ts +8 -1
- package/dist/types/Primitive/record/Types.d.ts +60 -6
- package/dist/types/Primitive/recursive/Terminate.d.ts +7 -0
- package/dist/types/Primitive/string/Admits.d.ts +8 -0
- package/dist/types/Primitive/string/Capacity.d.ts +36 -0
- package/dist/types/Primitive/string/Fabricator.d.ts +3 -1
- package/dist/types/Primitive/string/Registry.d.ts +26 -5
- package/dist/types/Primitive/string/Schema.d.ts +28 -2
- package/dist/types/Primitive/string/Sources.d.ts +16 -0
- package/dist/types/Primitive/string/Types.d.ts +35 -15
- package/dist/types/Primitive/symbol/Registry.d.ts +6 -1
- package/dist/types/Primitive/undefined/Registry.d.ts +6 -1
- package/dist/types/Primitive/unique/Registry.d.ts +39 -0
- package/dist/types/Primitive/unique/index.d.ts +2 -0
- package/dist/types/Schema/Core.d.ts +16 -1
- package/dist/types/Schema/Registry.d.ts +7 -4
- package/dist/types/Types.d.ts +9 -0
- package/dist/types/Unique/Capacity.d.ts +29 -0
- package/dist/types/Unique/Distinct.d.ts +95 -0
- package/dist/types/Unique/Key.d.ts +29 -0
- package/dist/types/Unique/Override.d.ts +16 -0
- package/dist/types/Unique/Strategy.d.ts +135 -0
- package/dist/types/Utility/DeepMerge.d.ts +11 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/internal.d.ts +9 -0
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
2
|
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
3
|
import type { Trace } from "../../Random/Types";
|
|
4
|
-
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
4
|
+
import { Claim, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
5
|
import { Schema } from "./Schema";
|
|
6
6
|
import type { Fabricated, Meta as ThisMeta } from "./Types";
|
|
7
7
|
export type Fabrication<_ extends Fabricator> = Fabricated;
|
|
@@ -14,6 +14,8 @@ export type Fabricator<$Schema extends {
|
|
|
14
14
|
[Meta]: $Schema[typeof Meta];
|
|
15
15
|
readonly trace: Trace;
|
|
16
16
|
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
/** Present on a `T.unique.bigint` only — see `Types.ts`'s `Claim`. */
|
|
18
|
+
readonly [Claim]?: (value: unknown) => void;
|
|
17
19
|
schema: Schema<$Schema[typeof Meta], AdaptationsOf<$Schema>>;
|
|
18
20
|
};
|
|
19
21
|
export declare function Fabricator(context: FabricatorContext<Schema>): Fabricator;
|
|
@@ -17,3 +17,23 @@ declare const _default: {
|
|
|
17
17
|
}>;
|
|
18
18
|
};
|
|
19
19
|
export default _default;
|
|
20
|
+
type UniqueRegistry = {
|
|
21
|
+
/** See the default export's `[Kind]`. */
|
|
22
|
+
[Kind]: "bigint";
|
|
23
|
+
/**
|
|
24
|
+
* A bigint the built Fabricator never repeats, drawn from `[min, max]` like
|
|
25
|
+
* `T.bigint.whereby`. The range is yielded as a random permutation at any
|
|
26
|
+
* width, so it produces every value exactly once and the draw after the last
|
|
27
|
+
* throws `UniqueExhaustedError`.
|
|
28
|
+
*/
|
|
29
|
+
whereby: (whereby: InputWhereby) => Schema<{
|
|
30
|
+
whereby: Whereby;
|
|
31
|
+
unique: true;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* `T.unique.bigint` (and `T.unique.number.integer.big`), assembled into the
|
|
36
|
+
* namespace by `Primitive/unique`. No `as`: a producer replaces the draw, so it
|
|
37
|
+
* would discard the one thing this builder adds.
|
|
38
|
+
*/
|
|
39
|
+
export declare const unique: UniqueRegistry;
|
|
@@ -2,7 +2,7 @@ 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
4
|
import { type SatisfiesThis } from "../../Schema/Satisfies";
|
|
5
|
-
import type { Core, Fabricated, Meta as ThisMeta } from "./Types";
|
|
5
|
+
import type { Admits, Core, Fabricated, InputAdmits, Meta as ThisMeta } from "./Types";
|
|
6
6
|
/**
|
|
7
7
|
* Buildable `bigint` recipe: a range (`whereby` — required, like `string`; no
|
|
8
8
|
* natural bound to fuzz to), or opaque production via `as`.
|
|
@@ -19,6 +19,14 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
|
|
|
19
19
|
* validation of `produce`) still has it to check against.
|
|
20
20
|
*/
|
|
21
21
|
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
22
|
+
/**
|
|
23
|
+
* State what adapters admit for this schema, widening what `whereby` draws —
|
|
24
|
+
* see `string/Schema.ts`'s `admits` for the full contract. A safe-integer
|
|
25
|
+
* `number` converts as in `whereby`.
|
|
26
|
+
*/
|
|
27
|
+
admits: (admitted: InputAdmits) => Schema<$Meta & {
|
|
28
|
+
admits: Admits;
|
|
29
|
+
}, $Adaptations>;
|
|
22
30
|
/**
|
|
23
31
|
* Check that this schema's fabricated value type is assignable to `$Target`.
|
|
24
32
|
* Identity at runtime; the target is not carried into later chained calls —
|
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import type { Bound, InputBound } from "../../Bound";
|
|
2
|
+
import type { AdmittedEnds, Bound, InputAdmittedEnds, InputBound } from "../../Bound";
|
|
3
3
|
import type { Produce } from "../../Random/Types";
|
|
4
4
|
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
5
|
+
/**
|
|
6
|
+
* Call-site `{ min?, max }`. Either end may be a `number` that is a safe
|
|
7
|
+
* integer (`Bound.ts`'s `toBigintBound`), stored as a `bigint`.
|
|
8
|
+
*/
|
|
5
9
|
export type InputWhereby = {
|
|
6
|
-
min?: InputBound<bigint> | undefined;
|
|
7
|
-
max: InputBound<bigint>;
|
|
10
|
+
min?: InputBound<bigint | number> | undefined;
|
|
11
|
+
max: InputBound<bigint | number>;
|
|
8
12
|
};
|
|
9
13
|
export type Whereby = {
|
|
10
14
|
min: Bound<bigint>;
|
|
11
15
|
max: Bound<bigint>;
|
|
12
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* `.admits(...)`'s input: the ends an adapter states, widening what `whereby`
|
|
19
|
+
* draws. An end is replaced (a safe-integer `number` converts as in `whereby`),
|
|
20
|
+
* `Infinity` (or `-Infinity` for `min`) states no limit, and an omitted end
|
|
21
|
+
* keeps what is admitted already.
|
|
22
|
+
*/
|
|
23
|
+
export type InputAdmits = InputAdmittedEnds<bigint | number>;
|
|
24
|
+
/**
|
|
25
|
+
* `[Meta].admits`, set only by `.admits(...)` and complete once set: an absent
|
|
26
|
+
* end states no limit (`Admits.ts`'s `toAdmits`).
|
|
27
|
+
*/
|
|
28
|
+
export type Admits = AdmittedEnds<bigint>;
|
|
13
29
|
export type Fabricated = bigint;
|
|
14
30
|
/**
|
|
15
31
|
* A ranged bigint, drawn via `whereby` — no natural bound to fuzz to, so unlike
|
|
@@ -17,12 +33,20 @@ export type Fabricated = bigint;
|
|
|
17
33
|
* `as` production, carried alongside `whereby` rather than replacing it (when
|
|
18
34
|
* `whereby` was already set) so a prior range survives `as` for future
|
|
19
35
|
* validation.
|
|
36
|
+
*
|
|
37
|
+
* `unique` is set by `T.unique.bigint`: the built Fabricator yields its range
|
|
38
|
+
* as a random permutation, never repeating for its whole lifetime
|
|
39
|
+
* (`Unique/Distinct.ts`'s `toBigintStrategy`).
|
|
20
40
|
*/
|
|
21
41
|
export type Meta = {
|
|
22
42
|
whereby: Whereby;
|
|
43
|
+
unique?: true;
|
|
44
|
+
admits?: Admits | undefined;
|
|
23
45
|
produce?: never;
|
|
24
46
|
} | {
|
|
25
47
|
whereby?: Whereby;
|
|
48
|
+
unique?: true;
|
|
49
|
+
admits?: Admits | undefined;
|
|
26
50
|
produce: Produce<Fabricated>;
|
|
27
51
|
};
|
|
28
52
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import { Schema } from "./Schema";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
5
|
+
* `T.boolean` getter, so every read is a distinct Schema — see AGENTS.md's
|
|
6
|
+
* "Registry entries are getters."
|
|
7
|
+
*/
|
|
8
|
+
declare function registry(): Schema<{}, Adaptations>;
|
|
4
9
|
export default registry;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Admits, InputAdmits, Meta } from "./Types";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve `.admits(...)` against what is admitted already: `meta.admits`, or by
|
|
4
|
+
* default the `whereby` ends — what an adapter states without one. An omitted
|
|
5
|
+
* `whereby` end draws against `±MAX_TIME`, so only no limit admits it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toAdmits(meta: Meta, input: InputAdmits): Admits;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Bound } from "../../Bound";
|
|
2
|
+
import type { Meta } from "./Types";
|
|
2
3
|
/**
|
|
3
4
|
* Inclusive epoch-millisecond caps that a missing `whereby` end draws against —
|
|
4
5
|
* the whole representable `Date` range. Not stored on `[Meta]`: an omitted end
|
|
@@ -9,3 +10,23 @@ export declare const unboundedEpoch: {
|
|
|
9
10
|
min: Bound<number>;
|
|
10
11
|
max: Bound<number>;
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* The epoch-millisecond ends a `date` draws between, given the construction's
|
|
15
|
+
* `clock`: `whereby`'s named ends, the unbounded caps for the rest, and `clock`
|
|
16
|
+
* itself (inclusive) as `past`'s upper or `future`'s lower end. Here rather
|
|
17
|
+
* than in `Fabricator.ts` so `Unique/Distinct.ts` can read a collection
|
|
18
|
+
* member's range without importing a Fabricator.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toEpochBounds(meta: Meta, clock: number): {
|
|
21
|
+
min: Bound<number>;
|
|
22
|
+
max: Bound<number>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* {@link toEpochBounds} as the inclusive whole-millisecond interval a `Date` can
|
|
26
|
+
* actually take — `Date` is `TimeClip`ped to whole milliseconds, so this is
|
|
27
|
+
* every value a draw can produce.
|
|
28
|
+
*/
|
|
29
|
+
export declare function toEpochRange(meta: Meta, clock: number): {
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
2
|
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
3
|
import type { Trace } from "../../Random/Types";
|
|
4
|
-
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
4
|
+
import { Claim, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
5
|
import { Schema } from "./Schema";
|
|
6
6
|
import type { Fabricated, Meta as ThisMeta } from "./Types";
|
|
7
7
|
export type Fabrication<_ extends Fabricator> = Fabricated;
|
|
@@ -14,6 +14,8 @@ export type Fabricator<$Schema extends {
|
|
|
14
14
|
[Meta]: $Schema[typeof Meta];
|
|
15
15
|
readonly trace: Trace;
|
|
16
16
|
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
/** Present on a `T.unique.date` only — see `Types.ts`'s `Claim`. */
|
|
18
|
+
readonly [Claim]?: (value: unknown) => void;
|
|
17
19
|
schema: Schema<$Schema[typeof Meta], AdaptationsOf<$Schema>>;
|
|
18
20
|
};
|
|
19
21
|
export declare function Fabricator(context: FabricatorContext<Schema>): Fabricator;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import { type InputBound } from "../../Bound";
|
|
3
|
-
import { type Distribution } from "../../Distribution";
|
|
4
2
|
import { Schema } from "./Schema";
|
|
5
|
-
import type { InputWhereby, Whereby } from "./Types";
|
|
3
|
+
import type { InputFutureWhereby, InputPastWhereby, InputUniqueFutureWhereby, InputUniquePastWhereby, InputUniqueWhereby, InputWhereby, Whereby } from "./Types";
|
|
6
4
|
type ThisRegistry = Schema<{}, Adaptations> & {
|
|
7
5
|
/**
|
|
8
6
|
* A `Date` drawn from `[min, max]`. Either end may be omitted: `min` defaults
|
|
@@ -26,10 +24,7 @@ type ThisRegistry = Schema<{}, Adaptations> & {
|
|
|
26
24
|
* `distribution` to shape how values cluster within the range; without one,
|
|
27
25
|
* every instant is equally likely.
|
|
28
26
|
*/
|
|
29
|
-
whereby: (whereby: {
|
|
30
|
-
min?: InputBound<Date> | undefined;
|
|
31
|
-
distribution?: Distribution | undefined;
|
|
32
|
-
}) => Schema<{
|
|
27
|
+
whereby: (whereby: InputPastWhereby) => Schema<{
|
|
33
28
|
mode: "past";
|
|
34
29
|
whereby: Whereby;
|
|
35
30
|
}>;
|
|
@@ -44,14 +39,61 @@ type ThisRegistry = Schema<{}, Adaptations> & {
|
|
|
44
39
|
* `distribution` to shape how values cluster within the range; without one,
|
|
45
40
|
* every instant is equally likely.
|
|
46
41
|
*/
|
|
47
|
-
whereby: (whereby: {
|
|
48
|
-
max?: InputBound<Date> | undefined;
|
|
49
|
-
distribution?: Distribution | undefined;
|
|
50
|
-
}) => Schema<{
|
|
42
|
+
whereby: (whereby: InputFutureWhereby) => Schema<{
|
|
51
43
|
mode: "future";
|
|
52
44
|
whereby: Whereby;
|
|
53
45
|
}>;
|
|
54
46
|
};
|
|
55
47
|
};
|
|
56
|
-
|
|
48
|
+
/**
|
|
49
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
50
|
+
* `T.date` getter, so every read is a distinct Schema. `past` and `future` are
|
|
51
|
+
* getters for the same reason — see AGENTS.md's "Registry entries are
|
|
52
|
+
* getters."
|
|
53
|
+
*/
|
|
54
|
+
declare function registry(): ThisRegistry;
|
|
57
55
|
export default registry;
|
|
56
|
+
type UniqueRegistry = Schema<{
|
|
57
|
+
unique: true;
|
|
58
|
+
}, Adaptations> & {
|
|
59
|
+
/**
|
|
60
|
+
* A `Date` the built Fabricator never repeats, drawn from `[min, max]` like
|
|
61
|
+
* `T.date.whereby`. Instants are whole milliseconds, so a uniform range is
|
|
62
|
+
* drawn as a random permutation of them: every instant exactly once, then
|
|
63
|
+
* `UniqueExhaustedError`. A skewed range is tracked instead, still exhausting
|
|
64
|
+
* exactly; `redraws` raises the cap on consecutive repeats its rarest
|
|
65
|
+
* instants can need.
|
|
66
|
+
*/
|
|
67
|
+
whereby: (whereby: InputUniqueWhereby) => Schema<{
|
|
68
|
+
unique: true;
|
|
69
|
+
whereby: Whereby;
|
|
70
|
+
}>;
|
|
71
|
+
/** A past `Date` the built Fabricator never repeats. */
|
|
72
|
+
past: Schema<{
|
|
73
|
+
mode: "past";
|
|
74
|
+
unique: true;
|
|
75
|
+
}> & {
|
|
76
|
+
whereby: (whereby: InputUniquePastWhereby) => Schema<{
|
|
77
|
+
mode: "past";
|
|
78
|
+
unique: true;
|
|
79
|
+
whereby: Whereby;
|
|
80
|
+
}>;
|
|
81
|
+
};
|
|
82
|
+
/** A future `Date` the built Fabricator never repeats. */
|
|
83
|
+
future: Schema<{
|
|
84
|
+
mode: "future";
|
|
85
|
+
unique: true;
|
|
86
|
+
}> & {
|
|
87
|
+
whereby: (whereby: InputUniqueFutureWhereby) => Schema<{
|
|
88
|
+
mode: "future";
|
|
89
|
+
unique: true;
|
|
90
|
+
whereby: Whereby;
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* `T.unique.date`, assembled into the namespace by `Primitive/unique`, which
|
|
96
|
+
* installs it as a getter for the same reason `T.date` is one. `past` and
|
|
97
|
+
* `future` are getters here too.
|
|
98
|
+
*/
|
|
99
|
+
export declare function unique(): UniqueRegistry;
|
|
@@ -2,7 +2,7 @@ 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
4
|
import { type SatisfiesThis } from "../../Schema/Satisfies";
|
|
5
|
-
import type { Core, Fabricated, Meta as ThisMeta } from "./Types";
|
|
5
|
+
import type { Core, Fabricated, Meta as ThisMeta, Admits, InputAdmitsOf } from "./Types";
|
|
6
6
|
/**
|
|
7
7
|
* Buildable `Date` recipe: a range/distribution (`whereby`, absent for the
|
|
8
8
|
* full-range bare form), optionally scoped by `mode` to `"past"` (up to now) or
|
|
@@ -19,6 +19,15 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
|
|
|
19
19
|
* future validation of `produce`) still has them to check against.
|
|
20
20
|
*/
|
|
21
21
|
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
22
|
+
/**
|
|
23
|
+
* State what adapters admit for this schema, widening what `whereby` draws —
|
|
24
|
+
* see `string/Schema.ts`'s `admits` for the full contract. Epoch milliseconds
|
|
25
|
+
* convert as in `whereby`. `past` admits only a `min` and `future` only a
|
|
26
|
+
* `max`: their other end is the clock.
|
|
27
|
+
*/
|
|
28
|
+
admits: (admitted: InputAdmitsOf<$Meta>) => Schema<$Meta & {
|
|
29
|
+
admits: Admits;
|
|
30
|
+
}, $Adaptations>;
|
|
22
31
|
/**
|
|
23
32
|
* Check that this schema's fabricated value type is assignable to `$Target`.
|
|
24
33
|
* Identity at runtime; the target is not carried into later chained calls —
|
|
@@ -1,28 +1,74 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
|
-
import type { Bound, InputBound } from "../../Bound";
|
|
2
|
+
import type { AdmittedEnds, Bound, InputAdmittedEnds, InputBound } from "../../Bound";
|
|
3
3
|
import type { Distribution } from "../../Distribution";
|
|
4
4
|
import type { Produce } from "../../Random/Types";
|
|
5
5
|
import type { Adaptation, Kind, Meta, Produced, Produces } from "../../Types";
|
|
6
|
+
import type { Redraws } from "../../Unique/Strategy";
|
|
6
7
|
/**
|
|
7
8
|
* Call-site `{ min, max }` — scalars are inclusive. Either end may be omitted;
|
|
8
9
|
* a missing `min` is the earliest representable instant and a missing `max` the
|
|
9
|
-
* latest, the same span as a bare `T.date`.
|
|
10
|
+
* latest, the same span as a bare `T.date`. Either end may be epoch
|
|
11
|
+
* milliseconds (`Bound.ts`'s `toDateBound`), stored as a `Date`.
|
|
10
12
|
*/
|
|
11
13
|
export type InputWhereby = {
|
|
12
|
-
min?: InputBound<Date> | undefined;
|
|
13
|
-
max?: InputBound<Date> | undefined;
|
|
14
|
+
min?: InputBound<Date | number> | undefined;
|
|
15
|
+
max?: InputBound<Date | number> | undefined;
|
|
14
16
|
distribution?: Distribution | undefined;
|
|
15
17
|
};
|
|
18
|
+
/** `T.date.past.whereby`: `past` closes its upper end at the clock. */
|
|
19
|
+
export type InputPastWhereby = {
|
|
20
|
+
min?: InputBound<Date | number> | undefined;
|
|
21
|
+
distribution?: Distribution | undefined;
|
|
22
|
+
};
|
|
23
|
+
/** `T.date.future.whereby`: `future` closes its lower end at the clock. */
|
|
24
|
+
export type InputFutureWhereby = {
|
|
25
|
+
max?: InputBound<Date | number> | undefined;
|
|
26
|
+
distribution?: Distribution | undefined;
|
|
27
|
+
};
|
|
28
|
+
/** `T.unique.date`'s `.whereby` inputs: each plain one, plus {@link Redraws}. */
|
|
29
|
+
export type InputUniqueWhereby = InputWhereby & Redraws;
|
|
30
|
+
export type InputUniquePastWhereby = InputPastWhereby & Redraws;
|
|
31
|
+
export type InputUniqueFutureWhereby = InputFutureWhereby & Redraws;
|
|
16
32
|
/**
|
|
17
33
|
* Stored `{ min, max }` — each present end is a canonical {@link Bound}. An
|
|
18
34
|
* omitted end stays omitted (fabricate fills `Defaults.ts`'s `unboundedEpoch`;
|
|
19
35
|
* adapters forward only the ends that were named).
|
|
36
|
+
*
|
|
37
|
+
* `redraws` is set only through {@link InputUniqueWhereby} and its
|
|
38
|
+
* `past`/`future` forms.
|
|
20
39
|
*/
|
|
21
40
|
export type Whereby = {
|
|
22
41
|
min?: Bound<Date> | undefined;
|
|
23
42
|
max?: Bound<Date> | undefined;
|
|
24
43
|
distribution?: Distribution | undefined;
|
|
44
|
+
redraws?: number | undefined;
|
|
25
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* `.admits(...)`'s input: the ends an adapter states, widening what `whereby`
|
|
48
|
+
* draws. An end is replaced (epoch milliseconds convert as in `whereby`),
|
|
49
|
+
* `Infinity` (or `-Infinity` for `min`) states no limit, and an omitted end
|
|
50
|
+
* keeps what is admitted already.
|
|
51
|
+
*/
|
|
52
|
+
export type InputAdmits = InputAdmittedEnds<Date | number>;
|
|
53
|
+
/**
|
|
54
|
+
* `T.date.past`'s `.admits`: its upper end is the clock, unknown until a
|
|
55
|
+
* Fabricator is built, so only `min` can be widened.
|
|
56
|
+
*/
|
|
57
|
+
export type InputPastAdmits = Pick<InputAdmits, "min">;
|
|
58
|
+
/** `T.date.future`'s `.admits`: likewise, only `max`. */
|
|
59
|
+
export type InputFutureAdmits = Pick<InputAdmits, "max">;
|
|
60
|
+
/** The `.admits` input a date schema of `$Meta` takes, by its `mode`. */
|
|
61
|
+
export type InputAdmitsOf<$Meta extends Meta> = $Meta extends {
|
|
62
|
+
mode: "past";
|
|
63
|
+
} ? InputPastAdmits : InputAdmitsOfFuture<$Meta>;
|
|
64
|
+
type InputAdmitsOfFuture<$Meta extends Meta> = $Meta extends {
|
|
65
|
+
mode: "future";
|
|
66
|
+
} ? InputFutureAdmits : InputAdmits;
|
|
67
|
+
/**
|
|
68
|
+
* `[Meta].admits`, set only by `.admits(...)` and complete once set: an absent
|
|
69
|
+
* end states no limit (`Admits.ts`'s `toAdmits`).
|
|
70
|
+
*/
|
|
71
|
+
export type Admits = AdmittedEnds<Date>;
|
|
26
72
|
export type Fabricated = Date;
|
|
27
73
|
/**
|
|
28
74
|
* A range/distribution (`whereby`, absent for the full-range bare form),
|
|
@@ -34,6 +80,8 @@ export type Fabricated = Date;
|
|
|
34
80
|
export type Meta = {
|
|
35
81
|
mode?: "past" | "future";
|
|
36
82
|
whereby?: Whereby;
|
|
83
|
+
unique?: true;
|
|
84
|
+
admits?: Admits | undefined;
|
|
37
85
|
produce?: Produce<Fabricated>;
|
|
38
86
|
};
|
|
39
87
|
export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {}> = {
|
|
@@ -42,3 +90,4 @@ export type Core<$Meta extends Meta = Meta, $Adaptations extends Adaptations = {
|
|
|
42
90
|
readonly [Produces]?: Produced<Fabricated>;
|
|
43
91
|
readonly [Adaptation]?: $Adaptations;
|
|
44
92
|
};
|
|
93
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
2
|
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
3
|
import type { Trace } from "../../Random/Types";
|
|
4
|
-
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
4
|
+
import { Claim, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
5
|
import { Schema } from "./Schema";
|
|
6
6
|
import type { Fabricated, Items, Meta as ThisMeta } from "./Types";
|
|
7
7
|
export type Fabrication<$Fabricator extends Fabricator> = $Fabricator extends Fabricator<infer $Schema> ? Fabricated<$Schema[typeof Meta]["items"]> : never;
|
|
@@ -14,6 +14,8 @@ export type Fabricator<$Schema extends {
|
|
|
14
14
|
[Meta]: $Schema[typeof Meta];
|
|
15
15
|
readonly trace: Trace;
|
|
16
16
|
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
/** Present on a `T.unique.enum` only — see `Types.ts`'s `Claim`. */
|
|
18
|
+
readonly [Claim]?: (value: unknown) => void;
|
|
17
19
|
schema: Schema<$Schema[typeof Meta]["items"], AdaptationsOf<$Schema>>;
|
|
18
20
|
};
|
|
19
21
|
export declare function Fabricator<$Items extends Items>(context: FabricatorContext<Schema<$Items>>): Fabricator<Schema<$Items>>;
|
|
@@ -43,7 +43,27 @@ declare const _default: {
|
|
|
43
43
|
* Relative probability across members, given as `[weight, item]` pairs — the
|
|
44
44
|
* same tuple shape `weighted()` (`Distribution/index.ts`) itself accepts, not
|
|
45
45
|
* an object keyed by member.
|
|
46
|
+
*
|
|
47
|
+
* Widened back to `$Items`: the `NonEmpty<$Items>` intersection is only a
|
|
48
|
+
* call-site guard, and left in place it would leak into the Schema's type.
|
|
46
49
|
*/
|
|
47
50
|
weighted: <const $Items extends Items>(items: $Items & NonEmpty<$Items>) => Schema<$Items>;
|
|
48
51
|
};
|
|
49
52
|
export default _default;
|
|
53
|
+
/**
|
|
54
|
+
* `T.unique.enum`, assembled into the namespace by `Primitive/unique`.
|
|
55
|
+
*/
|
|
56
|
+
export declare const unique: {
|
|
57
|
+
/**
|
|
58
|
+
* Equal probability across the members the built Fabricator has not yet
|
|
59
|
+
* produced: it never repeats a member, and the draw after the last throws
|
|
60
|
+
* `UniqueExhaustedError`.
|
|
61
|
+
*/
|
|
62
|
+
uniform: <const $Items extends ReadonlyArray<Item>>(items: $Items & NonEmpty<$Items>) => Schema<Weighted<$Items>>;
|
|
63
|
+
/**
|
|
64
|
+
* Relative probability across the members the built Fabricator has not yet
|
|
65
|
+
* produced, given as `[weight, item]` pairs: it never repeats a member, and
|
|
66
|
+
* the draw after the last throws `UniqueExhaustedError`.
|
|
67
|
+
*/
|
|
68
|
+
weighted: <const $Items extends Items>(items: $Items & NonEmpty<$Items>) => Schema<$Items>;
|
|
69
|
+
};
|
|
@@ -29,10 +29,15 @@ export type Fabricated<$Items extends Items = Items> = $Items[number][1];
|
|
|
29
29
|
* to fabricate from. `produce` layers an opaque production via `.as()`, carried
|
|
30
30
|
* alongside `items` rather than replacing it, so a prior member set survives
|
|
31
31
|
* `.as()` for future validation.
|
|
32
|
+
*
|
|
33
|
+
* `unique` is set by `T.unique.enum`: the built Fabricator draws its members
|
|
34
|
+
* without replacement for its whole lifetime (`Unique/Strategy.ts`'s
|
|
35
|
+
* `exactValues`). `produce` still wins over it, as over everything else.
|
|
32
36
|
*/
|
|
33
37
|
export type Meta<$Items extends Items = Items> = {
|
|
34
38
|
items: $Items;
|
|
35
39
|
produce?: Produce<Fabricated<$Items>>;
|
|
40
|
+
unique?: true;
|
|
36
41
|
};
|
|
37
42
|
export type Core<$Items extends Items = Items, $Adaptations extends Adaptations = {}> = {
|
|
38
43
|
[Kind]: "enum";
|
|
@@ -24,6 +24,7 @@ export { default as string } from "./string";
|
|
|
24
24
|
export { default as symbol } from "./symbol";
|
|
25
25
|
export { default as tuple } from "./tuple";
|
|
26
26
|
export { default as undefinable } from "./undefinable";
|
|
27
|
+
export { default as unique } from "./unique";
|
|
27
28
|
export { default as undefined } from "./undefined";
|
|
28
29
|
export { Primitive };
|
|
29
30
|
export type Fabricator = Primitive.always.Fabricator<any> | Primitive.array.Fabricator<any> | Primitive.bigint.Fabricator | Primitive.boolean.Fabricator | Primitive.choice.Fabricator<any> | Primitive.date.Fabricator | Primitive.derive.Fabricator<any> | Primitive.enum.Fabricator<any> | Primitive.null.Fabricator | Primitive.nullable.Fabricator<any> | Primitive.nullish.Fabricator<any> | Primitive.number.Fabricator | Primitive.object.Fabricator<any> | Primitive.object.compute.Fabricator<any, any> | Primitive.object.omittable.Fabricator<any> | Primitive.object.optional.Fabricator<any> | Primitive.opaque.Fabricator<any> | Primitive.record.Fabricator<any> | Primitive.recursive.Fabricator<any> | Primitive.recursive.self.Fabricator<any> | Primitive.string.Fabricator | Primitive.symbol.Fabricator | Primitive.tuple.Fabricator<any> | Primitive.undefined.Fabricator | Primitive.undefinable.Fabricator<any>;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Schema } from "./Schema";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
4
|
+
* `T.null` getter, so every read is a distinct Schema — see AGENTS.md's
|
|
5
|
+
* "Registry entries are getters."
|
|
6
|
+
*/
|
|
7
|
+
declare function registry(): Schema;
|
|
3
8
|
export default registry;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Admits, InputAdmits, Meta } from "./Types";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve `.admits(...)` against what is admitted already: `meta.admits`, or by
|
|
4
|
+
* default the `whereby` ends — what an adapter states without one. An omitted
|
|
5
|
+
* `whereby` end draws against `±Number.MAX_VALUE` (`±MAX_SAFE_INTEGER` for an
|
|
6
|
+
* integer), so only no limit admits it. `multipleOf` is never checked
|
|
7
|
+
* (`Types.ts`'s `Keywords`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function toAdmits(meta: Meta, input: InputAdmits): Admits;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AdaptationsOf } from "../../Adapter/Types";
|
|
2
2
|
import type { FabricatorContext, NaiveFabricator } from "../../Fabricator/Types";
|
|
3
3
|
import type { Trace } from "../../Random/Types";
|
|
4
|
-
import { Kind, Meta, type Adaptation } from "../../Types";
|
|
4
|
+
import { Claim, Kind, Meta, type Adaptation } from "../../Types";
|
|
5
5
|
import { Schema } from "./Schema";
|
|
6
6
|
import type { Fabricated, Meta as ThisMeta } from "./Types";
|
|
7
7
|
export type Fabrication<_ extends Fabricator> = Fabricated;
|
|
@@ -14,6 +14,8 @@ export type Fabricator<$Schema extends {
|
|
|
14
14
|
[Meta]: $Schema[typeof Meta];
|
|
15
15
|
readonly trace: Trace;
|
|
16
16
|
readonly [Adaptation]?: AdaptationsOf<$Schema>;
|
|
17
|
+
/** Present on a `T.unique.number` only — see `Types.ts`'s `Claim`. */
|
|
18
|
+
readonly [Claim]?: (value: unknown) => void;
|
|
17
19
|
schema: Schema<$Schema[typeof Meta], AdaptationsOf<$Schema>>;
|
|
18
20
|
};
|
|
19
21
|
export declare function Fabricator(context: FabricatorContext<Schema>): Fabricator;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import { default as bigint } from "../bigint";
|
|
3
|
+
import { unique as uniqueBigint } from "../bigint/Registry";
|
|
3
4
|
import { Schema } from "./Schema";
|
|
4
|
-
import type { InputWhereby, Whereby } from "./Types";
|
|
5
|
+
import type { InputUniqueWhereby, InputWhereby, Whereby } from "./Types";
|
|
5
6
|
type ThisRegistry = Schema<{}, Adaptations> & {
|
|
6
7
|
/**
|
|
7
8
|
* A `number` drawn from `[min, max]`, either end optional. Pass a
|
|
@@ -30,5 +31,52 @@ type ThisRegistry = Schema<{}, Adaptations> & {
|
|
|
30
31
|
big: typeof bigint;
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
36
|
+
* `T.number` getter, so every read is a distinct Schema. `integer` and
|
|
37
|
+
* `integer.sequence` are getters for the same reason; `big` is a builder, not a
|
|
38
|
+
* Schema, so it stays a plain property — see AGENTS.md's "Registry entries are
|
|
39
|
+
* getters."
|
|
40
|
+
*/
|
|
41
|
+
declare function registry(): ThisRegistry;
|
|
34
42
|
export default registry;
|
|
43
|
+
type UniqueRegistry = Schema<{
|
|
44
|
+
unique: true;
|
|
45
|
+
}, Adaptations> & {
|
|
46
|
+
/**
|
|
47
|
+
* A `number` that the built Fabricator never repeats, drawn from `[min, max]`
|
|
48
|
+
* like `T.number.whereby`. Values are tracked as they are drawn, so memory
|
|
49
|
+
* grows with the values produced. A continuous range repeats only by chance,
|
|
50
|
+
* which makes this mostly a guard; a range whose ends meet holds one value,
|
|
51
|
+
* and the draw after it throws `UniqueExhaustedError`.
|
|
52
|
+
*/
|
|
53
|
+
whereby: (whereby: InputUniqueWhereby) => Schema<{
|
|
54
|
+
unique: true;
|
|
55
|
+
whereby: Whereby;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Integers the built Fabricator never repeats. A uniform range is drawn as a
|
|
59
|
+
* random permutation, so it yields every value exactly once and the draw
|
|
60
|
+
* after the last throws `UniqueExhaustedError`. A skewed or unbounded range
|
|
61
|
+
* is tracked instead, still exhausting exactly when bounded. A skewed range's
|
|
62
|
+
* rarest values can take many draws to find; `redraws` raises the cap on
|
|
63
|
+
* consecutive repeats for that.
|
|
64
|
+
*/
|
|
65
|
+
integer: Schema<{
|
|
66
|
+
integer: true;
|
|
67
|
+
unique: true;
|
|
68
|
+
}> & {
|
|
69
|
+
whereby: (whereby: InputUniqueWhereby) => Schema<{
|
|
70
|
+
integer: true;
|
|
71
|
+
unique: true;
|
|
72
|
+
whereby: Whereby;
|
|
73
|
+
}>;
|
|
74
|
+
big: typeof uniqueBigint;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* `T.unique.number`, assembled into the namespace by `Primitive/unique`, which
|
|
79
|
+
* installs it as a getter for the same reason `T.number` is one. Mirrors
|
|
80
|
+
* {@link registry} without `integer.sequence`, which already never repeats.
|
|
81
|
+
*/
|
|
82
|
+
export declare function unique(): UniqueRegistry;
|
|
@@ -2,7 +2,7 @@ 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
4
|
import { type SatisfiesThis } from "../../Schema/Satisfies";
|
|
5
|
-
import type { Core, Fabricated,
|
|
5
|
+
import type { Core, Fabricated, Meta as ThisMeta, Admits, InputAdmits } from "./Types";
|
|
6
6
|
/**
|
|
7
7
|
* Buildable `number` recipe: a range/distribution (`whereby`, absent for the
|
|
8
8
|
* full-range bare form), `integer` for whole-number semantics, a `sequence`
|
|
@@ -22,7 +22,15 @@ export interface Schema<$Meta extends ThisMeta = ThisMeta, $Adaptations extends
|
|
|
22
22
|
* `.as(...)` (or future validation of `produce`) still has them to check
|
|
23
23
|
* against.
|
|
24
24
|
*/
|
|
25
|
-
as: (produce: Produce<Fabricated
|
|
25
|
+
as: (produce: Produce<Fabricated>) => Schema<$Meta, $Adaptations>;
|
|
26
|
+
/**
|
|
27
|
+
* State what adapters admit for this schema, widening what `whereby` draws —
|
|
28
|
+
* see `string/Schema.ts`'s `admits` for the full contract. An omitted
|
|
29
|
+
* `whereby` end is unbounded, so only no limit admits it.
|
|
30
|
+
*/
|
|
31
|
+
admits: (admitted: InputAdmits) => Schema<$Meta & {
|
|
32
|
+
admits: Admits;
|
|
33
|
+
}, $Adaptations>;
|
|
26
34
|
/**
|
|
27
35
|
* Check that this schema's fabricated value type is assignable to `$Target`.
|
|
28
36
|
* Identity at runtime; the target is not carried into later chained calls —
|