@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,4 +1,5 @@
|
|
|
1
1
|
import { enumerables } from "../Enumeration/Enumerate.js";
|
|
2
|
+
import { toCapacity } from "../Unique/Capacity.js";
|
|
2
3
|
import { FabricatorError } from "../Error/index.js";
|
|
3
4
|
import { Constructor } from "../Fabricator/Constructor.js";
|
|
4
5
|
import { Fabricate } from "../Fabricator/Fabricate.js";
|
|
@@ -67,6 +68,7 @@ function instantiate(config, stack, parent) {
|
|
|
67
68
|
});
|
|
68
69
|
const Fabricator = Constructor(source, stack, ancestry);
|
|
69
70
|
const { combinatorial, coverage } = enumerables(source, config.limits, stack, ancestry);
|
|
71
|
+
const capacity = (schema)=>toCapacity(schema, "trace" in schema ? schema.trace.clock : context.clock);
|
|
70
72
|
const fabricatorCache = null != (_ref = null == parent ? void 0 : parent.fabricatorCache) ? _ref : new WeakMap();
|
|
71
73
|
const fabricate = Fabricate(Fabricator, source, stack, ancestry, fabricatorCache);
|
|
72
74
|
function derive(over) {
|
|
@@ -136,6 +138,7 @@ function instantiate(config, stack, parent) {
|
|
|
136
138
|
fabricate,
|
|
137
139
|
combinatorial,
|
|
138
140
|
coverage,
|
|
141
|
+
capacity,
|
|
139
142
|
salt: source.salt,
|
|
140
143
|
fork,
|
|
141
144
|
wrap,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { discreteWithin, toAdmittedEnds, toFiniteBound } from "../../Bound.js";
|
|
2
|
+
const label = ".admits on an array schema";
|
|
3
|
+
function toAdmits(meta, input) {
|
|
4
|
+
var _ref;
|
|
5
|
+
var _meta_whereby, _meta_admits;
|
|
6
|
+
const drawn = toEnds(null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.length);
|
|
7
|
+
return {
|
|
8
|
+
length: toAdmittedEnds(label, "length", null != (_ref = null == (_meta_admits = meta.admits) ? void 0 : _meta_admits.length) ? _ref : drawn, meta.produce ? void 0 : drawn, input.length, (end, given)=>toFiniteBound(label, end, given), discreteWithin)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function toEnds(length) {
|
|
12
|
+
if (!length) return {};
|
|
13
|
+
return {
|
|
14
|
+
min: length.min,
|
|
15
|
+
max: length.max
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export { toAdmits };
|
|
@@ -2,6 +2,8 @@ import { effectiveDiscrete } from "../../Bound.js";
|
|
|
2
2
|
import { discreteSampler } from "../../Distribution/index.js";
|
|
3
3
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
4
4
|
import { Children, Kind, Meta } from "../../Types.js";
|
|
5
|
+
import { assertCapacity, toDistinct } from "../../Unique/Distinct.js";
|
|
6
|
+
import { withinCollection } from "../../Unique/Strategy.js";
|
|
5
7
|
import { Schema } from "./Schema.js";
|
|
6
8
|
function Fabricator(context, element) {
|
|
7
9
|
const { schema, algorithm, trace } = context;
|
|
@@ -25,9 +27,10 @@ function Fabricator(context, element) {
|
|
|
25
27
|
const stream = toStreamFromTrace(algorithm, trace);
|
|
26
28
|
const whereby = meta.whereby;
|
|
27
29
|
const drawLength = discreteSampler(whereby.length.distribution, effectiveDiscrete(whereby.length.min, whereby.length.max), stream);
|
|
28
|
-
const
|
|
30
|
+
const draw = withinCollection("array", element);
|
|
31
|
+
const fabricate = meta.unique ? distinctly(element, stream, meta.unique, whereby, drawLength) : ()=>Array.from({
|
|
29
32
|
length: drawLength()
|
|
30
|
-
},
|
|
33
|
+
}, draw);
|
|
31
34
|
return {
|
|
32
35
|
[Kind]: "array",
|
|
33
36
|
[Meta]: meta,
|
|
@@ -37,4 +40,19 @@ function Fabricator(context, element) {
|
|
|
37
40
|
schema: rehydrated
|
|
38
41
|
};
|
|
39
42
|
}
|
|
43
|
+
function distinctly(element, stream, unique, whereby, drawLength) {
|
|
44
|
+
const distinct = toDistinct(element, stream, {
|
|
45
|
+
label: "T.unique.array",
|
|
46
|
+
by: unique.by,
|
|
47
|
+
redraws: whereby.redraws
|
|
48
|
+
});
|
|
49
|
+
assertCapacity("T.unique.array", distinct, effectiveDiscrete(whereby.length.min, whereby.length.max).max);
|
|
50
|
+
return ()=>{
|
|
51
|
+
const count = drawLength();
|
|
52
|
+
const scope = distinct.open();
|
|
53
|
+
return Array.from({
|
|
54
|
+
length: count
|
|
55
|
+
}, ()=>scope.draw());
|
|
56
|
+
};
|
|
57
|
+
}
|
|
40
58
|
export { Fabricator };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { toLengthRange } from "../../Bound.js";
|
|
2
2
|
import { toSchema } from "../../Schema/Core.js";
|
|
3
3
|
import { Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { toRedraws } from "../../Unique/Strategy.js";
|
|
4
5
|
import { Schema } from "./Schema.js";
|
|
5
6
|
function Registry(definition) {
|
|
6
7
|
const normalized = toSchema(definition);
|
|
@@ -23,4 +24,35 @@ function Registry(definition) {
|
|
|
23
24
|
})
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
function unique(definition) {
|
|
28
|
+
const normalized = toSchema(definition);
|
|
29
|
+
const whereby = (by)=>(input)=>Schema({
|
|
30
|
+
[Kind]: "array",
|
|
31
|
+
[Meta]: {
|
|
32
|
+
whereby: toUniqueWhereby(input),
|
|
33
|
+
definition: normalized,
|
|
34
|
+
unique: by ? {
|
|
35
|
+
by
|
|
36
|
+
} : {}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
whereby: whereby(void 0),
|
|
41
|
+
by: (key)=>({
|
|
42
|
+
whereby: whereby(key)
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function toUniqueWhereby(input) {
|
|
47
|
+
const label = "T.unique.array.whereby";
|
|
48
|
+
const length = toLengthRange(input.length, label);
|
|
49
|
+
const redraws = toRedraws(label, input.redraws);
|
|
50
|
+
return void 0 === redraws ? {
|
|
51
|
+
length
|
|
52
|
+
} : {
|
|
53
|
+
length,
|
|
54
|
+
redraws
|
|
55
|
+
};
|
|
56
|
+
}
|
|
26
57
|
export default Registry;
|
|
58
|
+
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
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { bigintWithin, toAdmittedEnds, toBigintBound } from "../../Bound.js";
|
|
2
|
+
const label = ".admits on a bigint schema";
|
|
3
|
+
function toAdmits(meta, input) {
|
|
4
|
+
var _meta_admits;
|
|
5
|
+
const drawn = meta.whereby ? {
|
|
6
|
+
min: meta.whereby.min,
|
|
7
|
+
max: meta.whereby.max
|
|
8
|
+
} : {};
|
|
9
|
+
return toAdmittedEnds(label, void 0, null != (_meta_admits = meta.admits) ? _meta_admits : drawn, meta.produce ? void 0 : drawn, input, (end, given)=>toBigintBound(label, end, given), bigintWithin);
|
|
10
|
+
}
|
|
11
|
+
export { toAdmits };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { effectiveDiscreteBigint } from "../../Bound.js";
|
|
2
|
+
import { bigintSampler } from "../../Distribution/index.js";
|
|
2
3
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
3
|
-
import { Kind, Meta } from "../../Types.js";
|
|
4
|
+
import { Claim, Kind, Meta } from "../../Types.js";
|
|
5
|
+
import { toBigintStrategy } from "../../Unique/Distinct.js";
|
|
6
|
+
import { toLifetimeScope } from "../../Unique/Strategy.js";
|
|
4
7
|
import { Schema } from "./Schema.js";
|
|
5
8
|
function Fabricator(context) {
|
|
6
|
-
const { schema, algorithm, trace } = context;
|
|
9
|
+
const { schema, algorithm, trace, exhaustion } = context;
|
|
7
10
|
const meta = schema[Meta];
|
|
8
11
|
const rehydrated = Schema(schema);
|
|
9
12
|
if (meta.produce) {
|
|
@@ -21,28 +24,18 @@ function Fabricator(context) {
|
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
const stream = toStreamFromTrace(algorithm, trace);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let value = BigInt(0);
|
|
34
|
-
for (const byte of buffer)value = value << BigInt(byteBits) | BigInt(byte);
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
|
-
const sample = ()=>{
|
|
38
|
-
for(let i = 0; i < buffer.length; i++)buffer[i] = Math.floor(256 * stream.next());
|
|
39
|
-
return readBufferAsBigInt() & bitMask;
|
|
27
|
+
if (meta.unique) {
|
|
28
|
+
const scope = toLifetimeScope(toBigintStrategy(meta.whereby, stream), exhaustion);
|
|
29
|
+
return {
|
|
30
|
+
[Kind]: "bigint",
|
|
31
|
+
[Meta]: meta,
|
|
32
|
+
trace,
|
|
33
|
+
fabricate: ()=>scope.draw(),
|
|
34
|
+
[Claim]: scope.claim,
|
|
35
|
+
schema: rehydrated
|
|
40
36
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (candidate < range) return min + candidate;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
37
|
+
}
|
|
38
|
+
const fabricate = bigintSampler(effectiveDiscreteBigint(meta.whereby.min, meta.whereby.max), stream);
|
|
46
39
|
return {
|
|
47
40
|
[Kind]: "bigint",
|
|
48
41
|
[Meta]: meta,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertNonemptyDiscreteBigint,
|
|
1
|
+
import { assertNonemptyDiscreteBigint, toBigintBound } from "../../Bound.js";
|
|
2
2
|
import { Kind, Meta } from "../../Types.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
const Registry = {
|
|
@@ -6,7 +6,7 @@ const Registry = {
|
|
|
6
6
|
whereby: (whereby)=>Schema({
|
|
7
7
|
[Kind]: "bigint",
|
|
8
8
|
[Meta]: {
|
|
9
|
-
whereby: toWhereby(whereby)
|
|
9
|
+
whereby: toWhereby("T.bigint.whereby", whereby)
|
|
10
10
|
}
|
|
11
11
|
}),
|
|
12
12
|
as: (produce)=>Schema({
|
|
@@ -16,16 +16,27 @@ const Registry = {
|
|
|
16
16
|
}
|
|
17
17
|
})
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const unique = {
|
|
20
|
+
[Kind]: "bigint",
|
|
21
|
+
whereby: (whereby)=>Schema({
|
|
22
|
+
[Kind]: "bigint",
|
|
23
|
+
[Meta]: {
|
|
24
|
+
whereby: toWhereby("T.unique.bigint.whereby", whereby),
|
|
25
|
+
unique: true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
function toWhereby(label, input) {
|
|
30
|
+
const max = toBigintBound(label, "max", input.max);
|
|
21
31
|
const min = void 0 === input.min ? {
|
|
22
32
|
value: -max.value,
|
|
23
33
|
exclusive: false
|
|
24
|
-
} :
|
|
25
|
-
assertNonemptyDiscreteBigint(
|
|
34
|
+
} : toBigintBound(label, "min", input.min);
|
|
35
|
+
assertNonemptyDiscreteBigint(label, min, max);
|
|
26
36
|
return {
|
|
27
37
|
min,
|
|
28
38
|
max
|
|
29
39
|
};
|
|
30
40
|
}
|
|
31
41
|
export default Registry;
|
|
42
|
+
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
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
3
|
+
function registry() {
|
|
4
|
+
return {
|
|
5
|
+
...Schema({
|
|
6
|
+
[Kind]: "boolean",
|
|
7
|
+
[Meta]: {},
|
|
8
|
+
[Produces]: void 0,
|
|
9
|
+
[Adaptation]: void 0
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
}
|
|
11
13
|
const Registry = registry;
|
|
12
14
|
export default Registry;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dateWithin, toAdmittedEnds, toDateBound } from "../../Bound.js";
|
|
2
|
+
const label = ".admits on a date schema";
|
|
3
|
+
function toAdmits(meta, input) {
|
|
4
|
+
var _meta_admits;
|
|
5
|
+
var _meta_whereby, _meta_whereby1;
|
|
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
|
+
return toAdmittedEnds(label, void 0, null != (_meta_admits = meta.admits) ? _meta_admits : stated, toFabricable(meta, stated), input, (end, given)=>toDateBound(label, end, given), dateWithin);
|
|
11
|
+
}
|
|
12
|
+
function toFabricable(meta, stated) {
|
|
13
|
+
if (meta.produce) return;
|
|
14
|
+
if ("past" === meta.mode) return {
|
|
15
|
+
min: stated.min
|
|
16
|
+
};
|
|
17
|
+
if ("future" === meta.mode) return {
|
|
18
|
+
max: stated.max
|
|
19
|
+
};
|
|
20
|
+
return stated;
|
|
21
|
+
}
|
|
22
|
+
export { toAdmits };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { effectiveDiscrete, epochBound } from "../../Bound.js";
|
|
1
2
|
import { MAX_TIME } from "../../Types.js";
|
|
2
3
|
const unboundedEpoch = {
|
|
3
4
|
min: {
|
|
@@ -9,4 +10,29 @@ const unboundedEpoch = {
|
|
|
9
10
|
exclusive: false
|
|
10
11
|
}
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
function toEpochBounds(meta, clock) {
|
|
14
|
+
const whereby = meta.whereby;
|
|
15
|
+
const min = (null == whereby ? void 0 : whereby.min) ? epochBound(whereby.min) : unboundedEpoch.min;
|
|
16
|
+
const max = (null == whereby ? void 0 : whereby.max) ? epochBound(whereby.max) : unboundedEpoch.max;
|
|
17
|
+
const now = {
|
|
18
|
+
value: clock,
|
|
19
|
+
exclusive: false
|
|
20
|
+
};
|
|
21
|
+
if ("past" === meta.mode) return {
|
|
22
|
+
min,
|
|
23
|
+
max: now
|
|
24
|
+
};
|
|
25
|
+
if ("future" === meta.mode) return {
|
|
26
|
+
min: now,
|
|
27
|
+
max
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
min,
|
|
31
|
+
max
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function toEpochRange(meta, clock) {
|
|
35
|
+
const { min, max } = toEpochBounds(meta, clock);
|
|
36
|
+
return effectiveDiscrete(min, max);
|
|
37
|
+
}
|
|
38
|
+
export { toEpochBounds, toEpochRange, unboundedEpoch };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { assertNonemptyDiscrete, effectiveDiscrete
|
|
1
|
+
import { assertNonemptyDiscrete, effectiveDiscrete } from "../../Bound.js";
|
|
2
2
|
import { Distribution, sampler } from "../../Distribution/index.js";
|
|
3
3
|
import { toStreamFromTrace } from "../../Random/index.js";
|
|
4
|
-
import { Kind, MAX_TIME, Meta } from "../../Types.js";
|
|
5
|
-
import {
|
|
4
|
+
import { Claim, Kind, MAX_TIME, Meta } from "../../Types.js";
|
|
5
|
+
import { toDateStrategy } from "../../Unique/Distinct.js";
|
|
6
|
+
import { toLifetimeScope } from "../../Unique/Strategy.js";
|
|
7
|
+
import { toEpochBounds, toEpochRange } from "./Defaults.js";
|
|
6
8
|
import { Schema } from "./Schema.js";
|
|
7
9
|
function Fabricator(context) {
|
|
8
|
-
const { schema, algorithm, trace } = context;
|
|
10
|
+
const { schema, algorithm, trace, exhaustion } = context;
|
|
9
11
|
const { clock } = trace;
|
|
10
12
|
const meta = schema[Meta];
|
|
11
13
|
const rehydrated = Schema(schema);
|
|
@@ -24,43 +26,25 @@ function Fabricator(context) {
|
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
const stream = toStreamFromTrace(algorithm, trace);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
return {
|
|
37
|
-
[Kind]: "date",
|
|
38
|
-
[Meta]: meta,
|
|
39
|
-
trace,
|
|
40
|
-
fabricate,
|
|
41
|
-
schema: rehydrated
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if ("future" === meta.mode) {
|
|
45
|
-
const fabricate = whereby ? drawPastOrFuture({
|
|
46
|
-
min: {
|
|
47
|
-
value: clock,
|
|
48
|
-
exclusive: false
|
|
49
|
-
},
|
|
50
|
-
max: whereby.max ? epochBound(whereby.max) : unboundedEpoch.max
|
|
51
|
-
}, "T.date.future", whereby.distribution, stream) : ()=>new Date(clock + stream.next() * (MAX_TIME - clock));
|
|
29
|
+
if (meta.unique) {
|
|
30
|
+
var _meta_whereby, _meta_whereby1;
|
|
31
|
+
const scope = toLifetimeScope(toDateStrategy({
|
|
32
|
+
label: "T.unique.date",
|
|
33
|
+
range: toEpochRange(meta, clock),
|
|
34
|
+
distribution: null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.distribution,
|
|
35
|
+
stream,
|
|
36
|
+
redraws: null == (_meta_whereby1 = meta.whereby) ? void 0 : _meta_whereby1.redraws
|
|
37
|
+
}), exhaustion);
|
|
52
38
|
return {
|
|
53
39
|
[Kind]: "date",
|
|
54
40
|
[Meta]: meta,
|
|
55
41
|
trace,
|
|
56
|
-
fabricate,
|
|
42
|
+
fabricate: ()=>scope.draw(),
|
|
43
|
+
[Claim]: scope.claim,
|
|
57
44
|
schema: rehydrated
|
|
58
45
|
};
|
|
59
46
|
}
|
|
60
|
-
const fabricate =
|
|
61
|
-
min: whereby.min ? epochBound(whereby.min) : unboundedEpoch.min,
|
|
62
|
-
max: whereby.max ? epochBound(whereby.max) : unboundedEpoch.max
|
|
63
|
-
}, whereby.distribution, stream) : ()=>new Date((2 * stream.next() - 1) * MAX_TIME);
|
|
47
|
+
const fabricate = toDraw(meta, clock, stream);
|
|
64
48
|
return {
|
|
65
49
|
[Kind]: "date",
|
|
66
50
|
[Meta]: meta,
|
|
@@ -69,6 +53,20 @@ function Fabricator(context) {
|
|
|
69
53
|
schema: rehydrated
|
|
70
54
|
};
|
|
71
55
|
}
|
|
56
|
+
function toDraw(meta, clock, stream) {
|
|
57
|
+
const whereby = meta.whereby;
|
|
58
|
+
const prefix = meta.unique ? "T.unique.date" : "T.date";
|
|
59
|
+
if ("past" === meta.mode) {
|
|
60
|
+
if (!whereby) return ()=>new Date(clock - stream.next() * (clock + MAX_TIME));
|
|
61
|
+
return drawPastOrFuture(toEpochBounds(meta, clock), `${prefix}.past`, whereby.distribution, stream);
|
|
62
|
+
}
|
|
63
|
+
if ("future" === meta.mode) {
|
|
64
|
+
if (!whereby) return ()=>new Date(clock + stream.next() * (MAX_TIME - clock));
|
|
65
|
+
return drawPastOrFuture(toEpochBounds(meta, clock), `${prefix}.future`, whereby.distribution, stream);
|
|
66
|
+
}
|
|
67
|
+
if (!whereby) return ()=>new Date((2 * stream.next() - 1) * MAX_TIME);
|
|
68
|
+
return draw(toEpochBounds(meta, clock), whereby.distribution, stream);
|
|
69
|
+
}
|
|
72
70
|
function drawPastOrFuture(range, label, distribution, stream) {
|
|
73
71
|
assertNonemptyDiscrete(label, range.min, range.max);
|
|
74
72
|
return draw(range, distribution, stream);
|
|
@@ -1,59 +1,131 @@
|
|
|
1
|
-
import { assertNonemptyDiscrete, epochBound,
|
|
1
|
+
import { assertNonemptyDiscrete, epochBound, toDateBound } from "../../Bound.js";
|
|
2
2
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
3
|
+
import { toRedraws } from "../../Unique/Strategy.js";
|
|
3
4
|
import { unboundedEpoch } from "./Defaults.js";
|
|
4
5
|
import { Schema } from "./Schema.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[Kind]: "date",
|
|
8
|
-
[Meta]: {},
|
|
9
|
-
[Produces]: void 0,
|
|
10
|
-
[Adaptation]: void 0
|
|
11
|
-
}),
|
|
12
|
-
whereby: (whereby)=>{
|
|
13
|
-
const converted = toWhereby(whereby);
|
|
14
|
-
assertNonemptyDiscrete("T.date.whereby", converted.min ? epochBound(converted.min) : unboundedEpoch.min, converted.max ? epochBound(converted.max) : unboundedEpoch.max);
|
|
15
|
-
return Schema({
|
|
16
|
-
[Kind]: "date",
|
|
17
|
-
[Meta]: {
|
|
18
|
-
whereby: converted
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
past: {
|
|
6
|
+
function registry() {
|
|
7
|
+
return {
|
|
23
8
|
...Schema({
|
|
24
9
|
[Kind]: "date",
|
|
25
|
-
[Meta]: {
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
[Meta]: {},
|
|
11
|
+
[Produces]: void 0,
|
|
12
|
+
[Adaptation]: void 0
|
|
28
13
|
}),
|
|
29
14
|
whereby: (whereby)=>Schema({
|
|
30
15
|
[Kind]: "date",
|
|
31
16
|
[Meta]: {
|
|
32
|
-
|
|
33
|
-
whereby: toWhereby(whereby)
|
|
17
|
+
whereby: toCheckedWhereby("T.date.whereby", whereby)
|
|
34
18
|
}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
}),
|
|
20
|
+
get past () {
|
|
21
|
+
return {
|
|
22
|
+
...Schema({
|
|
23
|
+
[Kind]: "date",
|
|
24
|
+
[Meta]: {
|
|
25
|
+
mode: "past"
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
whereby: (whereby)=>Schema({
|
|
29
|
+
[Kind]: "date",
|
|
30
|
+
[Meta]: {
|
|
31
|
+
mode: "past",
|
|
32
|
+
whereby: toWhereby("T.date.past.whereby", whereby)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
get future () {
|
|
38
|
+
return {
|
|
39
|
+
...Schema({
|
|
40
|
+
[Kind]: "date",
|
|
41
|
+
[Meta]: {
|
|
42
|
+
mode: "future"
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
whereby: (whereby)=>Schema({
|
|
46
|
+
[Kind]: "date",
|
|
47
|
+
[Meta]: {
|
|
48
|
+
mode: "future",
|
|
49
|
+
whereby: toWhereby("T.date.future.whereby", whereby)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const Registry = registry;
|
|
57
|
+
function unique() {
|
|
58
|
+
return {
|
|
38
59
|
...Schema({
|
|
39
60
|
[Kind]: "date",
|
|
40
61
|
[Meta]: {
|
|
41
|
-
|
|
42
|
-
}
|
|
62
|
+
unique: true
|
|
63
|
+
},
|
|
64
|
+
[Produces]: void 0,
|
|
65
|
+
[Adaptation]: void 0
|
|
43
66
|
}),
|
|
44
67
|
whereby: (whereby)=>Schema({
|
|
45
68
|
[Kind]: "date",
|
|
46
69
|
[Meta]: {
|
|
47
|
-
|
|
48
|
-
whereby:
|
|
70
|
+
unique: true,
|
|
71
|
+
whereby: withRedraws("T.unique.date.whereby", toCheckedWhereby("T.unique.date.whereby", whereby), whereby)
|
|
49
72
|
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
73
|
+
}),
|
|
74
|
+
get past () {
|
|
75
|
+
return {
|
|
76
|
+
...Schema({
|
|
77
|
+
[Kind]: "date",
|
|
78
|
+
[Meta]: {
|
|
79
|
+
mode: "past",
|
|
80
|
+
unique: true
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
whereby: (whereby)=>Schema({
|
|
84
|
+
[Kind]: "date",
|
|
85
|
+
[Meta]: {
|
|
86
|
+
mode: "past",
|
|
87
|
+
unique: true,
|
|
88
|
+
whereby: withRedraws("T.unique.date.past.whereby", toWhereby("T.unique.date.past.whereby", whereby), whereby)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
get future () {
|
|
94
|
+
return {
|
|
95
|
+
...Schema({
|
|
96
|
+
[Kind]: "date",
|
|
97
|
+
[Meta]: {
|
|
98
|
+
mode: "future",
|
|
99
|
+
unique: true
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
whereby: (whereby)=>Schema({
|
|
103
|
+
[Kind]: "date",
|
|
104
|
+
[Meta]: {
|
|
105
|
+
mode: "future",
|
|
106
|
+
unique: true,
|
|
107
|
+
whereby: withRedraws("T.unique.date.future.whereby", toWhereby("T.unique.date.future.whereby", whereby), whereby)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function toCheckedWhereby(label, input) {
|
|
115
|
+
const converted = toWhereby(label, input);
|
|
116
|
+
assertNonemptyDiscrete(label, converted.min ? epochBound(converted.min) : unboundedEpoch.min, converted.max ? epochBound(converted.max) : unboundedEpoch.max);
|
|
117
|
+
return converted;
|
|
118
|
+
}
|
|
119
|
+
function withRedraws(label, whereby, input) {
|
|
120
|
+
const redraws = toRedraws(label, input.redraws);
|
|
121
|
+
return void 0 === redraws ? whereby : {
|
|
122
|
+
...whereby,
|
|
123
|
+
redraws
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function toWhereby(label, input) {
|
|
127
|
+
const min = void 0 === input.min ? void 0 : toDateBound(label, "min", input.min);
|
|
128
|
+
const max = void 0 === input.max ? void 0 : toDateBound(label, "max", input.max);
|
|
57
129
|
return void 0 === input.distribution ? {
|
|
58
130
|
min,
|
|
59
131
|
max
|
|
@@ -64,3 +136,4 @@ function toWhereby(input) {
|
|
|
64
136
|
};
|
|
65
137
|
}
|
|
66
138
|
export default Registry;
|
|
139
|
+
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
|
};
|