@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,9 +1,10 @@
|
|
|
1
1
|
import { weighted } from "../../Distribution/index.js";
|
|
2
2
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
3
|
-
import { Kind, Meta } from "../../Types.js";
|
|
3
|
+
import { Claim, Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { exactValues, toLifetimeScope } from "../../Unique/Strategy.js";
|
|
4
5
|
import { Schema } from "./Schema.js";
|
|
5
6
|
function Fabricator(context) {
|
|
6
|
-
const { schema, algorithm, trace } = context;
|
|
7
|
+
const { schema, algorithm, trace, exhaustion } = context;
|
|
7
8
|
const meta = schema[Meta];
|
|
8
9
|
const rehydrated = Schema(schema);
|
|
9
10
|
if (meta.produce) {
|
|
@@ -21,6 +22,17 @@ function Fabricator(context) {
|
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
const stream = toStreamFromTrace(algorithm, trace);
|
|
25
|
+
if (meta.unique) {
|
|
26
|
+
const scope = toLifetimeScope(exactValues("enum", meta.items, stream), exhaustion);
|
|
27
|
+
return {
|
|
28
|
+
[Kind]: "enum",
|
|
29
|
+
[Meta]: meta,
|
|
30
|
+
trace,
|
|
31
|
+
fabricate: ()=>scope.draw(),
|
|
32
|
+
[Claim]: scope.claim,
|
|
33
|
+
schema: rehydrated
|
|
34
|
+
};
|
|
35
|
+
}
|
|
24
36
|
const pick = weighted(meta.items, stream, "T.enum");
|
|
25
37
|
return {
|
|
26
38
|
[Kind]: "enum",
|
|
@@ -2,32 +2,45 @@ import { assertDrawableWeights } from "../../Distribution/index.js";
|
|
|
2
2
|
import { FabricatorError } from "../../Error/index.js";
|
|
3
3
|
import { Kind, Meta } from "../../Types.js";
|
|
4
4
|
import { Schema } from "./Schema.js";
|
|
5
|
-
function assertNonEmpty(items) {
|
|
6
|
-
if (0 === items.length) throw new FabricatorError.EmptyItemsError(
|
|
5
|
+
function assertNonEmpty(label, items) {
|
|
6
|
+
if (0 === items.length) throw new FabricatorError.EmptyItemsError(label, "member");
|
|
7
|
+
}
|
|
8
|
+
function uniform(label, flag, items) {
|
|
9
|
+
assertNonEmpty(label, items);
|
|
10
|
+
const weighted = items.map((x)=>[
|
|
11
|
+
1,
|
|
12
|
+
x
|
|
13
|
+
]);
|
|
14
|
+
return Schema({
|
|
15
|
+
[Kind]: "enum",
|
|
16
|
+
[Meta]: {
|
|
17
|
+
items: weighted,
|
|
18
|
+
...flag
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function Registry_weighted(label, flag, items) {
|
|
23
|
+
assertNonEmpty(label, items);
|
|
24
|
+
assertDrawableWeights(`${label}.weighted`, "member", items);
|
|
25
|
+
return Schema({
|
|
26
|
+
[Kind]: "enum",
|
|
27
|
+
[Meta]: {
|
|
28
|
+
items,
|
|
29
|
+
...flag
|
|
30
|
+
}
|
|
31
|
+
});
|
|
7
32
|
}
|
|
8
33
|
const Registry = {
|
|
9
|
-
uniform: (items)=>{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
weighted: (items)=>{
|
|
23
|
-
assertNonEmpty(items);
|
|
24
|
-
assertDrawableWeights("T.enum.weighted", "member", items);
|
|
25
|
-
return Schema({
|
|
26
|
-
[Kind]: "enum",
|
|
27
|
-
[Meta]: {
|
|
28
|
-
items
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
34
|
+
uniform: (items)=>uniform("T.enum", {}, items),
|
|
35
|
+
weighted: (items)=>Registry_weighted("T.enum", {}, items)
|
|
36
|
+
};
|
|
37
|
+
const unique = {
|
|
38
|
+
uniform: (items)=>uniform("T.unique.enum", {
|
|
39
|
+
unique: true
|
|
40
|
+
}, items),
|
|
41
|
+
weighted: (items)=>Registry_weighted("T.unique.enum", {
|
|
42
|
+
unique: true
|
|
43
|
+
}, items)
|
|
32
44
|
};
|
|
33
45
|
export default Registry;
|
|
46
|
+
export { unique };
|
|
@@ -23,5 +23,6 @@ export { default as string } from "./string/index.js";
|
|
|
23
23
|
export { default as symbol } from "./symbol/index.js";
|
|
24
24
|
export { default as tuple } from "./tuple/index.js";
|
|
25
25
|
export { default as undefinable } from "./undefinable/index.js";
|
|
26
|
+
export { default as unique } from "./unique/index.js";
|
|
26
27
|
export { default as undefined } from "./undefined/index.js";
|
|
27
28
|
export { __rspack_external__namespace_js_84cb9ec2 as Primitive };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Kind, Meta } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
function registry() {
|
|
4
|
+
return Schema({
|
|
5
|
+
[Kind]: "null",
|
|
6
|
+
[Meta]: {}
|
|
7
|
+
});
|
|
8
|
+
}
|
|
7
9
|
const Registry = registry;
|
|
8
10
|
export default Registry;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { continuousWithin, discreteWithin, toAdmittedEnds, toFiniteBound } from "../../Bound.js";
|
|
2
|
+
const label = ".admits on a number schema";
|
|
3
|
+
function toAdmits(meta, input) {
|
|
4
|
+
var _input_multipleOf, _meta_admits;
|
|
5
|
+
var _meta_whereby, _meta_whereby1, _meta_admits1;
|
|
6
|
+
const stated = {
|
|
7
|
+
min: null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.min,
|
|
8
|
+
max: null == (_meta_whereby1 = meta.whereby) ? void 0 : _meta_whereby1.max
|
|
9
|
+
};
|
|
10
|
+
const multipleOf = null != (_input_multipleOf = input.multipleOf) ? _input_multipleOf : null == (_meta_admits1 = meta.admits) ? void 0 : _meta_admits1.multipleOf;
|
|
11
|
+
const ends = toAdmittedEnds(label, void 0, null != (_meta_admits = meta.admits) ? _meta_admits : stated, toFabricable(meta, stated), input, (end, given)=>toFiniteBound(label, end, given), meta.integer ? discreteWithin : continuousWithin);
|
|
12
|
+
return void 0 === multipleOf ? ends : {
|
|
13
|
+
...ends,
|
|
14
|
+
multipleOf
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function toFabricable(meta, stated) {
|
|
18
|
+
if (meta.produce) return;
|
|
19
|
+
if (meta.sequence) return {
|
|
20
|
+
min: {
|
|
21
|
+
value: 1,
|
|
22
|
+
exclusive: false
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return stated;
|
|
26
|
+
}
|
|
27
|
+
export { toAdmits };
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { constrainContinuous, effectiveDiscrete } from "../../Bound.js";
|
|
2
2
|
import { Distribution, discreteSampler, sampler } from "../../Distribution/index.js";
|
|
3
3
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
4
|
-
import { Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { Claim, Kind, Meta } from "../../Types.js";
|
|
5
|
+
import { toNumberStrategy } from "../../Unique/Distinct.js";
|
|
6
|
+
import { toLifetimeScope } from "../../Unique/Strategy.js";
|
|
5
7
|
import { unboundedContinuous, unboundedDiscrete } from "./Defaults.js";
|
|
6
8
|
import { Schema } from "./Schema.js";
|
|
7
9
|
function Fabricator(context) {
|
|
8
10
|
var _ref, _ref1, _range_distribution;
|
|
9
11
|
var _meta_whereby, _meta_whereby1, _meta_whereby2;
|
|
10
|
-
const { schema, algorithm, trace } = context;
|
|
12
|
+
const { schema, algorithm, trace, exhaustion } = context;
|
|
11
13
|
const meta = schema[Meta];
|
|
12
14
|
const rehydrated = Schema({
|
|
13
15
|
...schema,
|
|
@@ -45,13 +47,23 @@ function Fabricator(context) {
|
|
|
45
47
|
distribution: null == (_meta_whereby2 = meta.whereby) ? void 0 : _meta_whereby2.distribution
|
|
46
48
|
};
|
|
47
49
|
const distribution = null != (_range_distribution = range.distribution) ? _range_distribution : Distribution.uniform();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const draw = meta.integer ? discreteSampler(distribution, effectiveDiscrete(range.min, range.max), stream) : constrainContinuous(sampler(distribution, {
|
|
51
|
+
min: range.min.value,
|
|
52
|
+
max: range.max.value
|
|
53
|
+
}, stream), range.min, range.max);
|
|
54
|
+
if (meta.unique) {
|
|
55
|
+
const scope = toLifetimeScope(toNumberStrategy({
|
|
56
|
+
label: "T.unique.number",
|
|
57
|
+
meta,
|
|
58
|
+
stream,
|
|
59
|
+
draw
|
|
60
|
+
}), exhaustion);
|
|
50
61
|
return {
|
|
51
62
|
[Kind]: "number",
|
|
52
63
|
[Meta]: meta,
|
|
53
64
|
trace,
|
|
54
|
-
fabricate: ()=>draw(),
|
|
65
|
+
fabricate: ()=>scope.draw(),
|
|
66
|
+
[Claim]: scope.claim,
|
|
55
67
|
schema: rehydrated
|
|
56
68
|
};
|
|
57
69
|
}
|
|
@@ -59,10 +71,7 @@ function Fabricator(context) {
|
|
|
59
71
|
[Kind]: "number",
|
|
60
72
|
[Meta]: meta,
|
|
61
73
|
trace,
|
|
62
|
-
fabricate:
|
|
63
|
-
min: range.min.value,
|
|
64
|
-
max: range.max.value
|
|
65
|
-
}, stream), range.min, range.max),
|
|
74
|
+
fabricate: draw,
|
|
66
75
|
schema: rehydrated
|
|
67
76
|
};
|
|
68
77
|
}
|
|
@@ -1,51 +1,107 @@
|
|
|
1
1
|
import { assertNonemptyContinuous, assertNonemptyDiscrete, toBound } from "../../Bound.js";
|
|
2
2
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
3
|
+
import { toRedraws } from "../../Unique/Strategy.js";
|
|
3
4
|
import bigint from "../bigint/index.js";
|
|
5
|
+
import { unique } from "../bigint/Registry.js";
|
|
4
6
|
import { unboundedContinuous, unboundedDiscrete } from "./Defaults.js";
|
|
5
7
|
import { Schema } from "./Schema.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[Kind]: "number",
|
|
9
|
-
[Meta]: {},
|
|
10
|
-
[Produces]: void 0,
|
|
11
|
-
[Adaptation]: void 0
|
|
12
|
-
}),
|
|
13
|
-
whereby: (whereby)=>Schema({
|
|
14
|
-
[Kind]: "number",
|
|
15
|
-
[Meta]: {
|
|
16
|
-
whereby: toWhereby(whereby, false)
|
|
17
|
-
}
|
|
18
|
-
}),
|
|
19
|
-
integer: {
|
|
8
|
+
function registry() {
|
|
9
|
+
return {
|
|
20
10
|
...Schema({
|
|
21
11
|
[Kind]: "number",
|
|
22
|
-
[Meta]: {
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
[Meta]: {},
|
|
13
|
+
[Produces]: void 0,
|
|
14
|
+
[Adaptation]: void 0
|
|
25
15
|
}),
|
|
26
16
|
whereby: (whereby)=>Schema({
|
|
27
17
|
[Kind]: "number",
|
|
28
18
|
[Meta]: {
|
|
29
|
-
|
|
30
|
-
whereby: toWhereby(whereby, true)
|
|
19
|
+
whereby: toWhereby("T.number", whereby, false)
|
|
31
20
|
}
|
|
32
21
|
}),
|
|
33
|
-
|
|
22
|
+
get integer () {
|
|
23
|
+
return {
|
|
24
|
+
...Schema({
|
|
25
|
+
[Kind]: "number",
|
|
26
|
+
[Meta]: {
|
|
27
|
+
integer: true
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
whereby: (whereby)=>Schema({
|
|
31
|
+
[Kind]: "number",
|
|
32
|
+
[Meta]: {
|
|
33
|
+
integer: true,
|
|
34
|
+
whereby: toWhereby("T.number", whereby, true)
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
get sequence () {
|
|
38
|
+
return Schema({
|
|
39
|
+
[Kind]: "number",
|
|
40
|
+
[Meta]: {
|
|
41
|
+
sequence: true,
|
|
42
|
+
integer: true
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
big: bigint
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const Registry = registry;
|
|
52
|
+
function Registry_unique() {
|
|
53
|
+
return {
|
|
54
|
+
...Schema({
|
|
34
55
|
[Kind]: "number",
|
|
35
56
|
[Meta]: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
57
|
+
unique: true
|
|
58
|
+
},
|
|
59
|
+
[Produces]: void 0,
|
|
60
|
+
[Adaptation]: void 0
|
|
39
61
|
}),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
whereby: (whereby)=>Schema({
|
|
63
|
+
[Kind]: "number",
|
|
64
|
+
[Meta]: {
|
|
65
|
+
unique: true,
|
|
66
|
+
whereby: toUniqueWhereby("T.unique.number", whereby, false)
|
|
67
|
+
}
|
|
68
|
+
}),
|
|
69
|
+
get integer () {
|
|
70
|
+
return {
|
|
71
|
+
...Schema({
|
|
72
|
+
[Kind]: "number",
|
|
73
|
+
[Meta]: {
|
|
74
|
+
integer: true,
|
|
75
|
+
unique: true
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
whereby: (whereby)=>Schema({
|
|
79
|
+
[Kind]: "number",
|
|
80
|
+
[Meta]: {
|
|
81
|
+
integer: true,
|
|
82
|
+
unique: true,
|
|
83
|
+
whereby: toUniqueWhereby("T.unique.number", whereby, true)
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
big: unique
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function toUniqueWhereby(prefix, input, integer) {
|
|
92
|
+
const label = integer ? `${prefix}.integer.whereby` : `${prefix}.whereby`;
|
|
93
|
+
const whereby = toWhereby(prefix, input, integer);
|
|
94
|
+
const redraws = toRedraws(label, input.redraws);
|
|
95
|
+
return void 0 === redraws ? whereby : {
|
|
96
|
+
...whereby,
|
|
97
|
+
redraws
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function toWhereby(prefix, input, integer) {
|
|
45
101
|
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
46
102
|
const max = void 0 === input.max ? void 0 : toBound(input.max);
|
|
47
103
|
const defaults = integer ? unboundedDiscrete : unboundedContinuous;
|
|
48
|
-
const label = integer ?
|
|
104
|
+
const label = integer ? `${prefix}.integer.whereby` : `${prefix}.whereby`;
|
|
49
105
|
if (integer) assertNonemptyDiscrete(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
|
|
50
106
|
else assertNonemptyContinuous(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
|
|
51
107
|
return void 0 === input.distribution ? {
|
|
@@ -58,3 +114,4 @@ function toWhereby(input, integer) {
|
|
|
58
114
|
};
|
|
59
115
|
}
|
|
60
116
|
export default Registry;
|
|
117
|
+
export { Registry_unique as unique };
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { withAdaptations } from "../../Adapter/Core.js";
|
|
2
2
|
import { schemaSatisfies } from "../../Schema/Satisfies.js";
|
|
3
3
|
import { Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { toAdmits } from "./Admits.js";
|
|
4
5
|
function Schema(schema) {
|
|
5
6
|
return {
|
|
6
7
|
...schema,
|
|
7
8
|
[Kind]: "number",
|
|
8
|
-
as: (produce
|
|
9
|
+
as: (produce)=>Schema({
|
|
9
10
|
...schema,
|
|
10
11
|
[Meta]: {
|
|
11
12
|
...schema[Meta],
|
|
12
|
-
produce
|
|
13
|
-
|
|
13
|
+
produce
|
|
14
|
+
}
|
|
15
|
+
}),
|
|
16
|
+
admits: (admitted)=>Schema({
|
|
17
|
+
...schema,
|
|
18
|
+
[Meta]: {
|
|
19
|
+
...schema[Meta],
|
|
20
|
+
admits: toAdmits(schema[Meta], admitted)
|
|
14
21
|
}
|
|
15
22
|
}),
|
|
16
23
|
satisfies: schemaSatisfies,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FabricatorError } from "../../Error/index.js";
|
|
2
2
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
3
3
|
import { Children, Kind, Meta, Omitted } from "../../Types.js";
|
|
4
|
+
import { recordOverride } from "../../Unique/Override.js";
|
|
4
5
|
import { isPollutionKey } from "../../Utility/Core.js";
|
|
5
6
|
import { isObjectComputeFabricator } from "./compute/Fabricator.js";
|
|
6
7
|
import { isObjectOmittableFabricator } from "./omittable/Fabricator.js";
|
|
@@ -57,6 +58,7 @@ function Fabricator(context, fields, hidden = {}) {
|
|
|
57
58
|
if (isPollutionKey(k)) throw new FabricatorError.PrototypePollutionError(k);
|
|
58
59
|
if (visible && overrides && k in overrides) {
|
|
59
60
|
const value = overrides[k];
|
|
61
|
+
recordOverride(v, value);
|
|
60
62
|
if (value === Omitted) continue;
|
|
61
63
|
fabricated[k] = isObjectFabricator(v) ? v.fabricate(value, {
|
|
62
64
|
validate: false
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { discreteWithin, toAdmittedEnds, toFiniteBound } from "../../Bound.js";
|
|
2
|
+
const label = ".admits on a record schema";
|
|
3
|
+
function toAdmits(meta, input) {
|
|
4
|
+
var _ref;
|
|
5
|
+
var _meta_admits;
|
|
6
|
+
return {
|
|
7
|
+
size: toAdmittedEnds(label, "size", null != (_ref = null == (_meta_admits = meta.admits) ? void 0 : _meta_admits.size) ? _ref : toStatedSize(meta), meta.produce ? void 0 : toFabricableSize(meta), input.size, (end, given)=>toFiniteBound(label, end, given), discreteWithin)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function toStatedSize(meta) {
|
|
11
|
+
if (meta.unique) {
|
|
12
|
+
const { size } = meta.whereby;
|
|
13
|
+
return {
|
|
14
|
+
min: size.min,
|
|
15
|
+
max: size.max
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (!meta.whereby) return {};
|
|
19
|
+
const { size } = meta.whereby;
|
|
20
|
+
return {
|
|
21
|
+
max: {
|
|
22
|
+
value: size.max,
|
|
23
|
+
exclusive: false
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function toFabricableSize(meta) {
|
|
28
|
+
var _size_minTried;
|
|
29
|
+
if (meta.unique || !meta.whereby) return toStatedSize(meta);
|
|
30
|
+
const { size } = meta.whereby;
|
|
31
|
+
return {
|
|
32
|
+
min: {
|
|
33
|
+
value: (null != (_size_minTried = size.minTried) ? _size_minTried : 0) >= 1 ? 1 : 0,
|
|
34
|
+
exclusive: false
|
|
35
|
+
},
|
|
36
|
+
max: {
|
|
37
|
+
value: size.max,
|
|
38
|
+
exclusive: false
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { toAdmits, toStatedSize };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { effectiveDiscrete } from "../../Bound.js";
|
|
1
2
|
import { discreteSampler } from "../../Distribution/index.js";
|
|
2
3
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
3
4
|
import { Children, Kind, Meta } from "../../Types.js";
|
|
5
|
+
import { assertCapacity, toDistinct } from "../../Unique/Distinct.js";
|
|
6
|
+
import { withinCollection } from "../../Unique/Strategy.js";
|
|
4
7
|
import { Schema } from "./Schema.js";
|
|
5
8
|
function Fabricator(context, key, value) {
|
|
6
9
|
const { schema, algorithm, trace } = context;
|
|
@@ -25,36 +28,63 @@ function Fabricator(context, key, value) {
|
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
const stream = toStreamFromTrace(algorithm, trace);
|
|
28
|
-
const
|
|
31
|
+
const fabricate = meta.unique ? distinctly(key, value, stream, meta.whereby) : collapsing(key, value, stream, meta.whereby);
|
|
32
|
+
return {
|
|
33
|
+
[Kind]: "record",
|
|
34
|
+
[Meta]: meta,
|
|
35
|
+
trace,
|
|
36
|
+
[Children]: {
|
|
37
|
+
key,
|
|
38
|
+
value
|
|
39
|
+
},
|
|
40
|
+
fabricate: fabricate,
|
|
41
|
+
schema: rehydrated
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function collapsing(key, value, stream, whereby) {
|
|
45
|
+
const { max, minTried = 0 } = whereby.size;
|
|
29
46
|
const drawSize = discreteSampler(void 0, {
|
|
30
47
|
min: minTried,
|
|
31
48
|
max
|
|
32
49
|
}, stream);
|
|
33
|
-
const
|
|
50
|
+
const drawKey = withinCollection("record", key);
|
|
51
|
+
return ()=>{
|
|
34
52
|
const size = drawSize();
|
|
35
53
|
const fabricated = {};
|
|
36
54
|
for(let i = 0; i < size; i++){
|
|
37
|
-
const k =
|
|
55
|
+
const k = drawKey();
|
|
38
56
|
const v = value.fabricate();
|
|
39
|
-
|
|
40
|
-
value: v,
|
|
41
|
-
enumerable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
configurable: true
|
|
44
|
-
});
|
|
57
|
+
Fabricator_define(fabricated, k, v);
|
|
45
58
|
}
|
|
46
59
|
return fabricated;
|
|
47
60
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
}
|
|
62
|
+
function distinctly(key, value, stream, whereby) {
|
|
63
|
+
const size = effectiveDiscrete(whereby.size.min, whereby.size.max);
|
|
64
|
+
const drawSize = discreteSampler(whereby.size.distribution, size, stream);
|
|
65
|
+
const distinct = toDistinct(key, stream, {
|
|
66
|
+
label: "T.unique.record",
|
|
67
|
+
redraws: whereby.redraws
|
|
68
|
+
});
|
|
69
|
+
assertCapacity("T.unique.record", distinct, size.max);
|
|
70
|
+
return ()=>{
|
|
71
|
+
const count = drawSize();
|
|
72
|
+
const scope = distinct.open();
|
|
73
|
+
const fabricated = {};
|
|
74
|
+
for(let i = 0; i < count; i++){
|
|
75
|
+
const k = scope.draw();
|
|
76
|
+
const v = value.fabricate();
|
|
77
|
+
Fabricator_define(fabricated, k, v);
|
|
78
|
+
}
|
|
79
|
+
return fabricated;
|
|
58
80
|
};
|
|
59
81
|
}
|
|
82
|
+
function Fabricator_define(fabricated, k, v) {
|
|
83
|
+
Object.defineProperty(fabricated, k, {
|
|
84
|
+
value: v,
|
|
85
|
+
enumerable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
60
90
|
export { Fabricator };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { toLengthRange } from "../../Bound.js";
|
|
1
2
|
import { toSchema } from "../../Schema/Core.js";
|
|
2
3
|
import { Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { toRedraws } from "../../Unique/Strategy.js";
|
|
3
5
|
import { Schema } from "./Schema.js";
|
|
4
6
|
function Registry(key, value) {
|
|
5
7
|
const normalizedKey = toSchema(key);
|
|
@@ -23,4 +25,31 @@ function Registry(key, value) {
|
|
|
23
25
|
})
|
|
24
26
|
};
|
|
25
27
|
}
|
|
28
|
+
function unique(key, value) {
|
|
29
|
+
const normalizedKey = toSchema(key);
|
|
30
|
+
const normalizedValue = toSchema(value);
|
|
31
|
+
return {
|
|
32
|
+
whereby: (whereby)=>Schema({
|
|
33
|
+
[Kind]: "record",
|
|
34
|
+
[Meta]: {
|
|
35
|
+
whereby: toUniqueWhereby(whereby),
|
|
36
|
+
unique: true,
|
|
37
|
+
key: normalizedKey,
|
|
38
|
+
value: normalizedValue
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function toUniqueWhereby(input) {
|
|
44
|
+
const label = "T.unique.record.whereby";
|
|
45
|
+
const size = toLengthRange(input.size, label);
|
|
46
|
+
const redraws = toRedraws(label, input.redraws);
|
|
47
|
+
return void 0 === redraws ? {
|
|
48
|
+
size
|
|
49
|
+
} : {
|
|
50
|
+
size,
|
|
51
|
+
redraws
|
|
52
|
+
};
|
|
53
|
+
}
|
|
26
54
|
export default Registry;
|
|
55
|
+
export { unique };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { withAdaptations } from "../../Adapter/Core.js";
|
|
2
2
|
import { schemaSatisfies } from "../../Schema/Satisfies.js";
|
|
3
3
|
import { Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { toAdmits } from "./Admits.js";
|
|
4
5
|
function Schema(schema) {
|
|
5
6
|
return {
|
|
6
7
|
...schema,
|
|
@@ -12,6 +13,13 @@ function Schema(schema) {
|
|
|
12
13
|
produce
|
|
13
14
|
}
|
|
14
15
|
}),
|
|
16
|
+
admits: (admitted)=>Schema({
|
|
17
|
+
...schema,
|
|
18
|
+
[Meta]: {
|
|
19
|
+
...schema[Meta],
|
|
20
|
+
admits: toAdmits(schema[Meta], admitted)
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
15
23
|
satisfies: schemaSatisfies,
|
|
16
24
|
adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
|
|
17
25
|
};
|
|
@@ -2,7 +2,7 @@ import { toStreamFromTrace } from "../../Random/index.js";
|
|
|
2
2
|
import { Kind, Meta } from "../../Types.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
function Fabricator(context, forkSource, make) {
|
|
5
|
-
const { schema, algorithm, trace } = context;
|
|
5
|
+
const { schema, algorithm, trace, exhaustion } = context;
|
|
6
6
|
const meta = schema[Meta];
|
|
7
7
|
const rehydrated = Schema(schema);
|
|
8
8
|
const stream = toStreamFromTrace(algorithm, trace);
|
|
@@ -19,7 +19,8 @@ function Fabricator(context, forkSource, make) {
|
|
|
19
19
|
}),
|
|
20
20
|
algorithm,
|
|
21
21
|
fork: privateSource.fork,
|
|
22
|
-
self: atMax ? void 0 : ()=>fabricateAt(depth + 1)
|
|
22
|
+
self: atMax ? void 0 : ()=>fabricateAt(depth + 1),
|
|
23
|
+
exhaustion
|
|
23
24
|
};
|
|
24
25
|
return make(target, [], context).fabricate();
|
|
25
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FabricatorError } from "../../Error/index.js";
|
|
2
2
|
import { Adaptation, Kind, Meta, Omitted } from "../../Types.js";
|
|
3
3
|
import { never } from "../../Utility/Core.js";
|
|
4
|
+
import { toStatedSize } from "../record/Admits.js";
|
|
4
5
|
function terminate(body) {
|
|
5
6
|
return terminateAt(body, []);
|
|
6
7
|
}
|
|
@@ -11,13 +12,20 @@ function terminateAt(schema, path) {
|
|
|
11
12
|
throw new FabricatorError.UnterminableRecursiveError(path);
|
|
12
13
|
case "array":
|
|
13
14
|
{
|
|
15
|
+
var _meta_whereby;
|
|
14
16
|
const s = schema;
|
|
15
|
-
|
|
17
|
+
if (!containsSelf(s[Meta].definition)) return schema;
|
|
18
|
+
const meta = s[Meta];
|
|
19
|
+
assertEmptiable(path, "length", meta.admits ? meta.admits.length : null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.length);
|
|
20
|
+
return emptyArray();
|
|
16
21
|
}
|
|
17
22
|
case "record":
|
|
18
23
|
{
|
|
19
24
|
const s = schema;
|
|
20
|
-
|
|
25
|
+
if (!containsSelf(s[Meta].key) && !containsSelf(s[Meta].value)) return schema;
|
|
26
|
+
const meta = s[Meta];
|
|
27
|
+
assertEmptiable(path, "size", meta.admits ? meta.admits.size : toStatedSize(meta));
|
|
28
|
+
return emptyRecord();
|
|
21
29
|
}
|
|
22
30
|
case "choice":
|
|
23
31
|
{
|
|
@@ -214,6 +222,12 @@ function containsSelf(schema) {
|
|
|
214
222
|
return never(kind);
|
|
215
223
|
}
|
|
216
224
|
}
|
|
225
|
+
function assertEmptiable(path, key, stated) {
|
|
226
|
+
const min = null == stated ? void 0 : stated.min;
|
|
227
|
+
if (!min) return;
|
|
228
|
+
const smallest = min.exclusive ? min.value + 1 : min.value;
|
|
229
|
+
if (smallest > 0) throw new FabricatorError.UnsatisfiableRecursiveBoundError(path, key, smallest);
|
|
230
|
+
}
|
|
217
231
|
function withMeta(schema, meta) {
|
|
218
232
|
const adaptations = schema[Adaptation];
|
|
219
233
|
return adaptations ? {
|