@ghostry/fabricator 0.0.1 → 0.0.3
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 +18 -12
- package/dist/esm/Adapter/Core.js +3 -3
- package/dist/esm/Enumeration/Enumerate.js +16 -13
- package/dist/esm/Error/index.js +16 -8
- package/dist/esm/Fabricator/Constructor.js +12 -14
- package/dist/esm/Harnessing/Core.js +30 -0
- package/dist/esm/Harnessing/Salt.js +12 -0
- package/dist/esm/Harnessing/Types.js +1 -0
- package/dist/esm/Instance/Core.js +25 -41
- package/dist/esm/Instance/Stack/Async.js +10 -0
- package/dist/esm/Instance/Stack/Sync.js +16 -0
- package/dist/esm/Primitive/bigint/Registry.js +12 -12
- package/dist/esm/Primitive/boolean/Registry.js +2 -1
- package/dist/esm/Primitive/date/Registry.js +15 -14
- package/dist/esm/Primitive/null/Registry.js +2 -1
- package/dist/esm/Primitive/number/Registry.js +18 -17
- package/dist/esm/Primitive/recursive/Fabricator.js +1 -1
- package/dist/esm/Primitive/symbol/Registry.js +2 -1
- package/dist/esm/Primitive/undefined/Registry.js +2 -1
- package/dist/esm/Random/index.js +24 -79
- package/dist/esm/Utility/Core.js +6 -1
- package/dist/esm/adapting.js +2 -0
- package/dist/esm/harnessing.js +1 -0
- package/dist/esm/index.js +5 -4
- package/dist/esm/internal.js +2 -2
- package/dist/types/Adapter/Core.d.ts +30 -33
- package/dist/types/Adapter/Types.d.ts +78 -88
- package/dist/types/Bound.d.ts +15 -15
- package/dist/types/Distribution/index.d.ts +54 -61
- package/dist/types/Enumeration/Enumerate.d.ts +24 -24
- package/dist/types/Enumeration/Plan.d.ts +22 -26
- package/dist/types/Enumeration/Types.d.ts +38 -43
- package/dist/types/Error/index.d.ts +103 -89
- package/dist/types/Fabricator/Constructor.d.ts +24 -26
- package/dist/types/Fabricator/Types.d.ts +73 -81
- package/dist/types/Harnessing/Core.d.ts +43 -0
- package/dist/types/Harnessing/Salt.d.ts +31 -0
- package/dist/types/Harnessing/Types.d.ts +79 -0
- package/dist/types/Instance/Core.d.ts +38 -74
- package/dist/types/Instance/Stack/Async.d.ts +14 -0
- package/dist/types/Instance/Stack/Sync.d.ts +14 -0
- package/dist/types/Instance/Types.d.ts +98 -102
- package/dist/types/Primitive/always/Schema.d.ts +8 -8
- package/dist/types/Primitive/always/Types.d.ts +7 -7
- package/dist/types/Primitive/array/Registry.d.ts +10 -8
- package/dist/types/Primitive/array/Schema.d.ts +4 -5
- package/dist/types/Primitive/array/Types.d.ts +6 -6
- package/dist/types/Primitive/bigint/Registry.d.ts +6 -6
- package/dist/types/Primitive/bigint/Schema.d.ts +8 -8
- package/dist/types/Primitive/bigint/Types.d.ts +5 -5
- package/dist/types/Primitive/boolean/Outcomes.d.ts +8 -8
- package/dist/types/Primitive/boolean/Registry.d.ts +2 -12
- package/dist/types/Primitive/boolean/Schema.d.ts +8 -8
- package/dist/types/Primitive/boolean/Types.d.ts +3 -3
- package/dist/types/Primitive/choice/Fabricator.d.ts +6 -7
- package/dist/types/Primitive/choice/Registry.d.ts +13 -13
- package/dist/types/Primitive/choice/Schema.d.ts +6 -6
- package/dist/types/Primitive/choice/Types.d.ts +11 -11
- package/dist/types/Primitive/date/Registry.d.ts +25 -48
- package/dist/types/Primitive/date/Schema.d.ts +9 -10
- package/dist/types/Primitive/date/Types.d.ts +4 -4
- package/dist/types/Primitive/enum/Registry.d.ts +13 -13
- package/dist/types/Primitive/enum/Schema.d.ts +5 -5
- package/dist/types/Primitive/enum/Types.d.ts +17 -19
- package/dist/types/Primitive/namespace.d.ts +10 -10
- package/dist/types/Primitive/null/Registry.d.ts +2 -2
- package/dist/types/Primitive/null/Schema.d.ts +2 -2
- package/dist/types/Primitive/null/Types.d.ts +3 -3
- package/dist/types/Primitive/nullable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/nullable/Schema.d.ts +13 -13
- package/dist/types/Primitive/nullable/Types.d.ts +9 -10
- package/dist/types/Primitive/nullish/Fabricator.d.ts +12 -13
- package/dist/types/Primitive/nullish/Schema.d.ts +8 -8
- package/dist/types/Primitive/nullish/Types.d.ts +12 -13
- package/dist/types/Primitive/number/Registry.d.ts +20 -38
- package/dist/types/Primitive/number/Schema.d.ts +11 -12
- package/dist/types/Primitive/number/Types.d.ts +13 -13
- package/dist/types/Primitive/number/defaults.d.ts +3 -3
- package/dist/types/Primitive/object/Fabricator.d.ts +15 -15
- package/dist/types/Primitive/object/Registry.d.ts +8 -8
- package/dist/types/Primitive/object/Schema.d.ts +10 -10
- package/dist/types/Primitive/object/Types.d.ts +20 -22
- package/dist/types/Primitive/object/compute/Fabricator.d.ts +4 -5
- package/dist/types/Primitive/object/compute/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/compute/Types.d.ts +19 -20
- package/dist/types/Primitive/object/omittable/Fabricator.d.ts +10 -10
- package/dist/types/Primitive/object/omittable/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/omittable/Schema.d.ts +11 -11
- package/dist/types/Primitive/object/omittable/Types.d.ts +14 -15
- package/dist/types/Primitive/object/optional/Fabricator.d.ts +16 -18
- package/dist/types/Primitive/object/optional/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/optional/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/optional/Types.d.ts +17 -17
- package/dist/types/Primitive/opaque/Registry.d.ts +3 -3
- package/dist/types/Primitive/opaque/Schema.d.ts +8 -9
- package/dist/types/Primitive/record/Registry.d.ts +8 -6
- package/dist/types/Primitive/record/Schema.d.ts +9 -11
- package/dist/types/Primitive/record/Types.d.ts +25 -25
- package/dist/types/Primitive/recursive/Fabricator.d.ts +20 -21
- package/dist/types/Primitive/recursive/Registry.d.ts +6 -7
- package/dist/types/Primitive/recursive/Schema.d.ts +8 -8
- package/dist/types/Primitive/recursive/Terminate.d.ts +13 -14
- package/dist/types/Primitive/recursive/Types.d.ts +31 -31
- package/dist/types/Primitive/recursive/self/Fabricator.d.ts +11 -12
- package/dist/types/Primitive/recursive/self/Schema.d.ts +10 -10
- package/dist/types/Primitive/recursive/self/Types.d.ts +7 -8
- package/dist/types/Primitive/string/Constants.d.ts +12 -13
- package/dist/types/Primitive/string/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/string/Registry.d.ts +10 -16
- package/dist/types/Primitive/string/Schema.d.ts +5 -5
- package/dist/types/Primitive/string/Types.d.ts +17 -17
- package/dist/types/Primitive/symbol/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/symbol/Registry.d.ts +4 -11
- package/dist/types/Primitive/symbol/Schema.d.ts +6 -6
- package/dist/types/Primitive/symbol/Types.d.ts +2 -2
- package/dist/types/Primitive/tuple/Fabricator.d.ts +7 -8
- package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
- package/dist/types/Primitive/tuple/Types.d.ts +24 -25
- package/dist/types/Primitive/undefinable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/undefinable/Schema.d.ts +13 -13
- package/dist/types/Primitive/undefinable/Types.d.ts +10 -10
- package/dist/types/Primitive/undefined/Registry.d.ts +2 -2
- package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
- package/dist/types/Primitive/undefined/Types.d.ts +3 -3
- package/dist/types/Random/Generator/sfc32.d.ts +4 -4
- package/dist/types/Random/Types.d.ts +151 -293
- package/dist/types/Random/index.d.ts +56 -81
- package/dist/types/Schema/Core.d.ts +19 -21
- package/dist/types/Schema/Registry.d.ts +3 -3
- package/dist/types/Schema/Types.d.ts +41 -48
- package/dist/types/Types.d.ts +39 -45
- package/dist/types/Utility/Core.d.ts +18 -9
- package/dist/types/adapting.d.ts +32 -0
- package/dist/types/harnessing.d.ts +30 -0
- package/dist/types/index.d.ts +95 -128
- package/dist/types/internal.d.ts +53 -40
- package/package.json +39 -7
- package/dist/esm/Random/CallSite.js +0 -56
- package/dist/types/Random/CallSite.d.ts +0 -59
package/README.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="https://docs.ghostry.dev/fabricator/logo.png" alt="fabricator" width="96" height="96">
|
|
4
|
+
|
|
5
|
+
# @ghostry/fabricator
|
|
6
|
+
|
|
7
|
+
**Fabricate typed data from composable schemas.**
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@ghostry/fabricator)
|
|
10
|
+
[](https://npmx.dev/package/@ghostry/fabricator)
|
|
11
|
+
[](https://jsr.io/@ghostry/fabricator)
|
|
12
|
+
[](https://github.com/ghostry-dev/fabricator)
|
|
13
|
+
[](#)
|
|
14
|
+
[](#)
|
|
15
|
+
[](#)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
4
18
|
|
|
5
19
|
## Install
|
|
6
20
|
|
|
@@ -8,14 +22,12 @@ Fabricate typed data from composable schemas.
|
|
|
8
22
|
npm install @ghostry/fabricator
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
Also available via `bun add @ghostry/fabricator` or `bunx jsr add @ghostry/fabricator`.
|
|
12
|
-
|
|
13
25
|
## Example
|
|
14
26
|
|
|
15
27
|
```ts
|
|
16
28
|
import { initialize } from "@ghostry/fabricator";
|
|
17
29
|
|
|
18
|
-
const { T, Fabricator } = initialize(
|
|
30
|
+
const { T, Fabricator } = initialize();
|
|
19
31
|
|
|
20
32
|
const ProductSchema = T.object({
|
|
21
33
|
name: T.string.whereby({ length: { min: 1, max: 25 } }),
|
|
@@ -38,10 +50,4 @@ const item = Product.fabricate();
|
|
|
38
50
|
const widget = Product.fabricate({ name: "Widget", inStock: true });
|
|
39
51
|
```
|
|
40
52
|
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
## Similar
|
|
44
|
-
|
|
45
|
-
https://www.npmjs.com/package/@anatine/zod-mock
|
|
46
|
-
|
|
47
|
-
https://www.npmjs.com/package/@travelperksl/fabricator
|
|
53
|
+
`initialize()` takes no required configuration. Its `clock` (by default, the wall-clock instant of the call) is the run's entropy, so every run differs, and passing that one number back as `clock` replays the run exactly. See the [docs site](https://docs.ghostry.dev/fabricator/) for the full guide: the mental model behind Schemas and Fabricators, composing and overriding schemas, custom types, distributions, and the [TypeBox adapter](https://www.npmjs.com/package/@ghostry/fabricator-adapter-typebox-v0).
|
package/dist/esm/Adapter/Core.js
CHANGED
|
@@ -38,10 +38,10 @@ function Core_layer(key, adaptation, prior) {
|
|
|
38
38
|
[key]: prior
|
|
39
39
|
}));
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function walk(adapter, schema, context) {
|
|
42
42
|
var _schema_Adaptation;
|
|
43
43
|
const adaptation = null == (_schema_Adaptation = schema[Adaptation]) ? void 0 : _schema_Adaptation[adapter.key];
|
|
44
44
|
if (adaptation) return adaptation(schema);
|
|
45
|
-
return adapter.convert(schema, (child, childContext)=>
|
|
45
|
+
return adapter.convert(schema, (child, childContext)=>walk(adapter, child, childContext), context);
|
|
46
46
|
}
|
|
47
|
-
export {
|
|
47
|
+
export { mergeAdaptations, walk, withAdaptations };
|
|
@@ -34,19 +34,21 @@ function enumerables(source, limits, stack) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
function combinatorial(schema) {
|
|
37
|
-
const
|
|
38
|
-
...effectiveSource().
|
|
37
|
+
const combinatorialSalt = [
|
|
38
|
+
...effectiveSource().salt,
|
|
39
39
|
"combinatorial"
|
|
40
40
|
];
|
|
41
41
|
const probe = plan(new Fabricator(schema, {
|
|
42
|
-
|
|
42
|
+
salt: combinatorialSalt,
|
|
43
|
+
ordinal: null
|
|
43
44
|
}), {
|
|
44
45
|
strategy: "product"
|
|
45
46
|
});
|
|
46
47
|
if (probe.width > BigInt(limits.combinatorial)) throw new FabricatorError.CombinatorialLimitExceededError(probe.width, limits.combinatorial);
|
|
47
48
|
return iterable(()=>{
|
|
48
49
|
const built = new Fabricator(schema, {
|
|
49
|
-
|
|
50
|
+
salt: combinatorialSalt,
|
|
51
|
+
ordinal: null
|
|
50
52
|
});
|
|
51
53
|
return {
|
|
52
54
|
built,
|
|
@@ -58,24 +60,25 @@ function enumerables(source, limits, stack) {
|
|
|
58
60
|
}
|
|
59
61
|
function coverage(schema) {
|
|
60
62
|
const base = effectiveSource();
|
|
61
|
-
const
|
|
62
|
-
...base.
|
|
63
|
+
const coverageSalt = [
|
|
64
|
+
...base.salt,
|
|
63
65
|
"coverage"
|
|
64
66
|
];
|
|
65
|
-
const
|
|
66
|
-
...base.
|
|
67
|
+
const orderSalt = [
|
|
68
|
+
...base.salt,
|
|
67
69
|
"coverage",
|
|
68
70
|
"order"
|
|
69
71
|
];
|
|
70
72
|
return iterable(()=>{
|
|
71
73
|
const built = new Fabricator(schema, {
|
|
72
|
-
|
|
74
|
+
salt: coverageSalt,
|
|
75
|
+
ordinal: null
|
|
73
76
|
});
|
|
74
77
|
return {
|
|
75
78
|
built,
|
|
76
79
|
axis: plan(built, {
|
|
77
80
|
strategy: "cycle",
|
|
78
|
-
orderer: orderer(base,
|
|
81
|
+
orderer: orderer(base, orderSalt)
|
|
79
82
|
})
|
|
80
83
|
};
|
|
81
84
|
});
|
|
@@ -85,9 +88,9 @@ function enumerables(source, limits, stack) {
|
|
|
85
88
|
coverage
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
function orderer(source,
|
|
89
|
-
const forked = source.fork(
|
|
90
|
-
const root = forked.toRoot(
|
|
91
|
+
function orderer(source, salt) {
|
|
92
|
+
const forked = source.fork(salt);
|
|
93
|
+
const root = forked.toRoot();
|
|
91
94
|
const stream = toStreamFromTrace(forked.algorithm, {
|
|
92
95
|
...root,
|
|
93
96
|
path: [],
|
package/dist/esm/Error/index.js
CHANGED
|
@@ -31,14 +31,6 @@ class Error_FabricatorError extends Error {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
FabricatorError.InvalidCombinatorialLimitError = InvalidCombinatorialLimitError;
|
|
34
|
-
class InvalidAttributionRootError extends FabricatorError {
|
|
35
|
-
constructor(root){
|
|
36
|
-
super(), _define_property(this, "root", void 0), this.root = root;
|
|
37
|
-
this.name = "InvalidAttributionRootError";
|
|
38
|
-
this.message = `initialize({ attribution: { kind: "rooted", root } }) requires an absolute path or a "file://" URL; received "${root}".`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
FabricatorError.InvalidAttributionRootError = InvalidAttributionRootError;
|
|
42
34
|
class DetachedSelfError extends FabricatorError {
|
|
43
35
|
constructor(during){
|
|
44
36
|
super(), _define_property(this, "during", void 0), this.during = during;
|
|
@@ -197,5 +189,21 @@ class Error_FabricatorError extends Error {
|
|
|
197
189
|
}
|
|
198
190
|
}
|
|
199
191
|
FabricatorError.TraceKindMismatchError = TraceKindMismatchError;
|
|
192
|
+
class SynchronousStackError extends FabricatorError {
|
|
193
|
+
constructor(){
|
|
194
|
+
super();
|
|
195
|
+
this.name = "SynchronousStackError";
|
|
196
|
+
this.message = "`wrap` received an async block, but this instance's ambient stack cannot carry a frame across `await` — a build after the first `await` would silently resolve against the base instance. This runtime has no `node:async_hooks`, so `#stack` resolved to the synchronous carrier; either keep the block synchronous, or pass an async-capable carrier as `initialize({ stack })`.";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
FabricatorError.SynchronousStackError = SynchronousStackError;
|
|
200
|
+
class HarnessingProviderError extends FabricatorError {
|
|
201
|
+
constructor(){
|
|
202
|
+
super();
|
|
203
|
+
this.name = "HarnessingProviderError";
|
|
204
|
+
this.message = "The `fabricator` provider was called outside its integration's `around`, so there is no per-test scope to provide. A composer must run each integration's providers inside that integration's `around` frame, as `@ghostry/harness` does.";
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
FabricatorError.HarnessingProviderError = HarnessingProviderError;
|
|
200
208
|
})(Error_FabricatorError || (Error_FabricatorError = {}));
|
|
201
209
|
export { Error_FabricatorError as FabricatorError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FabricatorError } from "../Error/index.js";
|
|
2
2
|
import { Primitive } from "../Primitive/index.js";
|
|
3
|
-
import { isLayered,
|
|
3
|
+
import { isLayered, normalizeSalt } from "../Random/index.js";
|
|
4
4
|
import { toSchema } from "../Schema/Core.js";
|
|
5
5
|
import { Adaptation, Fixed, Kind, Layer, Meta } from "../Types.js";
|
|
6
6
|
import { inline } from "../Utility/Core.js";
|
|
@@ -305,24 +305,22 @@ function resolveScope(source, options, stack) {
|
|
|
305
305
|
var _ref;
|
|
306
306
|
const frame = stack.current();
|
|
307
307
|
const base = null != (_ref = null == frame ? void 0 : frame.source) ? _ref : source;
|
|
308
|
+
const salt = inline(()=>{
|
|
309
|
+
if (!options.salt) return;
|
|
310
|
+
if (isLayered(options.salt)) return [
|
|
311
|
+
...base.salt,
|
|
312
|
+
...normalizeSalt(options.salt[Layer])
|
|
313
|
+
];
|
|
314
|
+
return normalizeSalt(options.salt);
|
|
315
|
+
});
|
|
308
316
|
const pins = {
|
|
317
|
+
salt,
|
|
309
318
|
clock: options.clock,
|
|
310
|
-
root: options.root,
|
|
311
|
-
file: options.file,
|
|
312
319
|
ordinal: options.ordinal
|
|
313
320
|
};
|
|
314
|
-
if (!options.seed) return {
|
|
315
|
-
source: base,
|
|
316
|
-
root: base.toRoot("attributed", pins)
|
|
317
|
-
};
|
|
318
|
-
const seed = isLayered(options.seed) ? [
|
|
319
|
-
...base.seed,
|
|
320
|
-
...normalizeSeed(options.seed[Layer])
|
|
321
|
-
] : options.seed;
|
|
322
|
-
const forked = base.fork(seed);
|
|
323
321
|
return {
|
|
324
|
-
source:
|
|
325
|
-
root:
|
|
322
|
+
source: base,
|
|
323
|
+
root: base.toRoot(pins)
|
|
326
324
|
};
|
|
327
325
|
}
|
|
328
326
|
export { Constructor };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FabricatorError } from "../Error/index.js";
|
|
2
|
+
import { layer as index_js_layer } from "../Random/index.js";
|
|
3
|
+
import { saltFor } from "./Salt.js";
|
|
4
|
+
function integration(instance) {
|
|
5
|
+
let scope;
|
|
6
|
+
return {
|
|
7
|
+
name: "@ghostry/fabricator",
|
|
8
|
+
provides: {
|
|
9
|
+
fabricator: ()=>{
|
|
10
|
+
if (void 0 === scope) throw new FabricatorError.HarnessingProviderError();
|
|
11
|
+
return scope;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
around (identity, body) {
|
|
15
|
+
const salt = index_js_layer(saltFor(identity));
|
|
16
|
+
return instance.wrap({
|
|
17
|
+
salt
|
|
18
|
+
}, (entered)=>{
|
|
19
|
+
const previous = scope;
|
|
20
|
+
scope = entered;
|
|
21
|
+
try {
|
|
22
|
+
return body();
|
|
23
|
+
} finally{
|
|
24
|
+
scope = previous;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { integration };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { enumerables } from "../Enumeration/Enumerate.js";
|
|
2
2
|
import { FabricatorError } from "../Error/index.js";
|
|
3
3
|
import { Constructor } from "../Fabricator/Constructor.js";
|
|
4
|
-
import { defaultAlgorithm, deriveClock, isLayered,
|
|
4
|
+
import { defaultAlgorithm, deriveClock, isLayered, normalizeSalt, toRandomSource } from "../Random/index.js";
|
|
5
5
|
import { registry } from "../Schema/Registry.js";
|
|
6
6
|
import { Layer } from "../Types.js";
|
|
7
|
-
import { inline } from "../Utility/Core.js";
|
|
7
|
+
import { inline, isThenable, noop } from "../Utility/Core.js";
|
|
8
8
|
const DEFAULT_COMBINATORIAL_LIMIT = 1024;
|
|
9
9
|
function resolveCombinatorialLimit(limit) {
|
|
10
10
|
if (void 0 === limit) return DEFAULT_COMBINATORIAL_LIMIT;
|
|
@@ -12,55 +12,39 @@ function resolveCombinatorialLimit(limit) {
|
|
|
12
12
|
return limit;
|
|
13
13
|
}
|
|
14
14
|
function resolveClock(config) {
|
|
15
|
-
return "number" == typeof config.clock ? config.clock : deriveClock(config.algorithm,
|
|
15
|
+
return "number" == typeof config.clock ? config.clock : deriveClock(config.algorithm, normalizeSalt(config.salt));
|
|
16
16
|
}
|
|
17
17
|
function overlay(base, over) {
|
|
18
|
-
var _ref, _over_algorithm,
|
|
18
|
+
var _ref, _over_algorithm, _ref1, _over_types, _over_limits;
|
|
19
19
|
var _this;
|
|
20
|
-
const
|
|
21
|
-
if (void 0 === over.
|
|
22
|
-
if (isLayered(over.
|
|
23
|
-
...
|
|
24
|
-
...
|
|
20
|
+
const salt = inline(()=>{
|
|
21
|
+
if (void 0 === over.salt) return normalizeSalt(base.salt);
|
|
22
|
+
if (isLayered(over.salt)) return [
|
|
23
|
+
...normalizeSalt(base.salt),
|
|
24
|
+
...normalizeSalt(over.salt[Layer])
|
|
25
25
|
];
|
|
26
|
-
return
|
|
26
|
+
return normalizeSalt(over.salt);
|
|
27
27
|
});
|
|
28
28
|
const clock = inline(()=>{
|
|
29
29
|
var _base_clock;
|
|
30
|
-
if ("
|
|
30
|
+
if ("derived" === over.clock) return "derived";
|
|
31
31
|
if (void 0 !== over.clock) return over.clock.valueOf();
|
|
32
32
|
return null != (_base_clock = base.clock) ? _base_clock : Date.now();
|
|
33
33
|
});
|
|
34
34
|
return {
|
|
35
|
-
|
|
35
|
+
salt,
|
|
36
36
|
clock,
|
|
37
37
|
algorithm: null != (_ref = null != (_over_algorithm = over.algorithm) ? _over_algorithm : base.algorithm) ? _ref : defaultAlgorithm,
|
|
38
|
-
attribution: over.attribution ? resolveAttribution(over.attribution) : null != (_base_attribution = base.attribution) ? _base_attribution : resolveAttribution(void 0),
|
|
39
38
|
types: null != (_ref1 = null != (_over_types = over.types) ? _over_types : base.types) ? _ref1 : registry,
|
|
40
39
|
limits: {
|
|
41
40
|
combinatorial: resolveCombinatorialLimit(null == (_this = null != (_over_limits = over.limits) ? _over_limits : base.limits) ? void 0 : _this.combinatorial)
|
|
42
41
|
}
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
function toStack() {
|
|
46
|
-
const frames = [];
|
|
47
|
-
return {
|
|
48
|
-
current: ()=>frames[frames.length - 1],
|
|
49
|
-
enter: (frame, block)=>{
|
|
50
|
-
frames.push(frame);
|
|
51
|
-
try {
|
|
52
|
-
return block();
|
|
53
|
-
} finally{
|
|
54
|
-
frames.pop();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
44
|
function instantiate(config, stack) {
|
|
60
45
|
const source = toRandomSource({
|
|
61
|
-
|
|
46
|
+
salt: config.salt,
|
|
62
47
|
algorithm: config.algorithm,
|
|
63
|
-
attribution: config.attribution,
|
|
64
48
|
clock: resolveClock(config)
|
|
65
49
|
});
|
|
66
50
|
const Fabricator = Constructor(source, stack);
|
|
@@ -74,31 +58,31 @@ function instantiate(config, stack) {
|
|
|
74
58
|
const base = null != (_ref = null == (_stack_current = stack.current()) ? void 0 : _stack_current.config) ? _ref : config;
|
|
75
59
|
const scopedConfig = overlay(base, wrapOverlay);
|
|
76
60
|
const scoped = instantiate(scopedConfig, stack);
|
|
77
|
-
|
|
61
|
+
const result = stack.enter({
|
|
78
62
|
config: scopedConfig,
|
|
79
63
|
source: scoped.source
|
|
80
64
|
}, ()=>block(scoped.instance));
|
|
65
|
+
if (!stack.asynchronous && isThenable(result)) {
|
|
66
|
+
result.then(noop, noop);
|
|
67
|
+
throw new FabricatorError.SynchronousStackError();
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
81
70
|
}
|
|
82
71
|
const context = {
|
|
83
|
-
get
|
|
72
|
+
get salt () {
|
|
84
73
|
var _ref;
|
|
85
74
|
var _stack_current;
|
|
86
|
-
return
|
|
75
|
+
return normalizeSalt((null != (_ref = null == (_stack_current = stack.current()) ? void 0 : _stack_current.config) ? _ref : config).salt);
|
|
87
76
|
},
|
|
88
77
|
get algorithm () {
|
|
89
78
|
var _ref1;
|
|
90
79
|
var _stack_current1;
|
|
91
80
|
return (null != (_ref1 = null == (_stack_current1 = stack.current()) ? void 0 : _stack_current1.config) ? _ref1 : config).algorithm;
|
|
92
81
|
},
|
|
93
|
-
get
|
|
82
|
+
get clock () {
|
|
94
83
|
var _ref2;
|
|
95
84
|
var _stack_current2;
|
|
96
|
-
return (null != (_ref2 = null == (_stack_current2 = stack.current()) ? void 0 : _stack_current2.config) ? _ref2 : config)
|
|
97
|
-
},
|
|
98
|
-
get clock () {
|
|
99
|
-
var _ref3;
|
|
100
|
-
var _stack_current3;
|
|
101
|
-
return resolveClock(null != (_ref3 = null == (_stack_current3 = stack.current()) ? void 0 : _stack_current3.config) ? _ref3 : config);
|
|
85
|
+
return resolveClock(null != (_ref2 = null == (_stack_current2 = stack.current()) ? void 0 : _stack_current2.config) ? _ref2 : config);
|
|
102
86
|
}
|
|
103
87
|
};
|
|
104
88
|
const instance = {
|
|
@@ -106,7 +90,7 @@ function instantiate(config, stack) {
|
|
|
106
90
|
Fabricator,
|
|
107
91
|
combinatorial,
|
|
108
92
|
coverage,
|
|
109
|
-
|
|
93
|
+
salt: source.salt,
|
|
110
94
|
fork,
|
|
111
95
|
wrap,
|
|
112
96
|
context
|
|
@@ -116,4 +100,4 @@ function instantiate(config, stack) {
|
|
|
116
100
|
source
|
|
117
101
|
};
|
|
118
102
|
}
|
|
119
|
-
export { DEFAULT_COMBINATORIAL_LIMIT, instantiate, overlay
|
|
103
|
+
export { DEFAULT_COMBINATORIAL_LIMIT, instantiate, overlay };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function toStack() {
|
|
2
|
+
const frames = [];
|
|
3
|
+
return {
|
|
4
|
+
asynchronous: false,
|
|
5
|
+
current: ()=>frames[frames.length - 1],
|
|
6
|
+
enter: (frame, block)=>{
|
|
7
|
+
frames.push(frame);
|
|
8
|
+
try {
|
|
9
|
+
return block();
|
|
10
|
+
} finally{
|
|
11
|
+
frames.pop();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { toStack };
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import { assertNonemptyDiscreteBigint, toBound } from "../../Bound.js";
|
|
2
2
|
import { Kind, Meta } from "../../Types.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
|
-
function toWhereby(input) {
|
|
5
|
-
const max = toBound(input.max);
|
|
6
|
-
const min = void 0 === input.min ? {
|
|
7
|
-
value: -max.value,
|
|
8
|
-
exclusive: false
|
|
9
|
-
} : toBound(input.min);
|
|
10
|
-
assertNonemptyDiscreteBigint("T.bigint.whereby", min, max);
|
|
11
|
-
return {
|
|
12
|
-
min,
|
|
13
|
-
max
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
4
|
const Registry = {
|
|
17
5
|
[Kind]: "bigint",
|
|
18
6
|
whereby: (whereby)=>Schema({
|
|
@@ -28,4 +16,16 @@ const Registry = {
|
|
|
28
16
|
}
|
|
29
17
|
})
|
|
30
18
|
};
|
|
19
|
+
function toWhereby(input) {
|
|
20
|
+
const max = toBound(input.max);
|
|
21
|
+
const min = void 0 === input.min ? {
|
|
22
|
+
value: -max.value,
|
|
23
|
+
exclusive: false
|
|
24
|
+
} : toBound(input.min);
|
|
25
|
+
assertNonemptyDiscreteBigint("T.bigint.whereby", min, max);
|
|
26
|
+
return {
|
|
27
|
+
min,
|
|
28
|
+
max
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
31
|
export default Registry;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
const
|
|
3
|
+
const registry = {
|
|
4
4
|
...Schema({
|
|
5
5
|
[Kind]: "boolean",
|
|
6
6
|
[Meta]: {},
|
|
@@ -8,4 +8,5 @@ const Registry = {
|
|
|
8
8
|
[Adaptation]: void 0
|
|
9
9
|
})
|
|
10
10
|
};
|
|
11
|
+
const Registry = registry;
|
|
11
12
|
export default Registry;
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { assertNonemptyDiscrete, epochBound, toBound } from "../../Bound.js";
|
|
2
2
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
|
-
|
|
5
|
-
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
6
|
-
const max = void 0 === input.max ? void 0 : toBound(input.max);
|
|
7
|
-
if (void 0 !== min && void 0 !== max) assertNonemptyDiscrete("T.date.whereby", epochBound(min), epochBound(max));
|
|
8
|
-
return void 0 === input.distribution ? {
|
|
9
|
-
min,
|
|
10
|
-
max
|
|
11
|
-
} : {
|
|
12
|
-
min,
|
|
13
|
-
max,
|
|
14
|
-
distribution: input.distribution
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const Registry = {
|
|
4
|
+
const registry = {
|
|
18
5
|
...Schema({
|
|
19
6
|
[Kind]: "date",
|
|
20
7
|
[Meta]: {},
|
|
@@ -58,4 +45,18 @@ const Registry = {
|
|
|
58
45
|
})
|
|
59
46
|
}
|
|
60
47
|
};
|
|
48
|
+
const Registry = registry;
|
|
49
|
+
function toWhereby(input) {
|
|
50
|
+
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
51
|
+
const max = void 0 === input.max ? void 0 : toBound(input.max);
|
|
52
|
+
if (void 0 !== min && void 0 !== max) assertNonemptyDiscrete("T.date.whereby", epochBound(min), epochBound(max));
|
|
53
|
+
return void 0 === input.distribution ? {
|
|
54
|
+
min,
|
|
55
|
+
max
|
|
56
|
+
} : {
|
|
57
|
+
min,
|
|
58
|
+
max,
|
|
59
|
+
distribution: input.distribution
|
|
60
|
+
};
|
|
61
|
+
}
|
|
61
62
|
export default Registry;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
const
|
|
3
|
+
const registry = Schema({
|
|
4
4
|
[Kind]: "null",
|
|
5
5
|
[Meta]: {},
|
|
6
6
|
[Produces]: null
|
|
7
7
|
});
|
|
8
|
+
const Registry = registry;
|
|
8
9
|
export default Registry;
|
|
@@ -3,23 +3,7 @@ import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
|
3
3
|
import bigint from "../bigint/index.js";
|
|
4
4
|
import { unboundedContinuous, unboundedDiscrete } from "./defaults.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
6
|
-
|
|
7
|
-
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
8
|
-
const max = void 0 === input.max ? void 0 : toBound(input.max);
|
|
9
|
-
const defaults = integer ? unboundedDiscrete : unboundedContinuous;
|
|
10
|
-
const label = integer ? "T.number.integer.whereby" : "T.number.whereby";
|
|
11
|
-
if (integer) assertNonemptyDiscrete(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
|
|
12
|
-
else assertNonemptyContinuous(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
|
|
13
|
-
return void 0 === input.distribution ? {
|
|
14
|
-
min,
|
|
15
|
-
max
|
|
16
|
-
} : {
|
|
17
|
-
min,
|
|
18
|
-
max,
|
|
19
|
-
distribution: input.distribution
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const Registry = {
|
|
6
|
+
const registry = {
|
|
23
7
|
...Schema({
|
|
24
8
|
[Kind]: "number",
|
|
25
9
|
[Meta]: {},
|
|
@@ -56,4 +40,21 @@ const Registry = {
|
|
|
56
40
|
big: bigint
|
|
57
41
|
}
|
|
58
42
|
};
|
|
43
|
+
const Registry = registry;
|
|
44
|
+
function toWhereby(input, integer) {
|
|
45
|
+
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
46
|
+
const max = void 0 === input.max ? void 0 : toBound(input.max);
|
|
47
|
+
const defaults = integer ? unboundedDiscrete : unboundedContinuous;
|
|
48
|
+
const label = integer ? "T.number.integer.whereby" : "T.number.whereby";
|
|
49
|
+
if (integer) assertNonemptyDiscrete(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
|
|
50
|
+
else assertNonemptyContinuous(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
|
|
51
|
+
return void 0 === input.distribution ? {
|
|
52
|
+
min,
|
|
53
|
+
max
|
|
54
|
+
} : {
|
|
55
|
+
min,
|
|
56
|
+
max,
|
|
57
|
+
distribution: input.distribution
|
|
58
|
+
};
|
|
59
|
+
}
|
|
59
60
|
export default Registry;
|
|
@@ -10,7 +10,7 @@ function Fabricator(context, forkSource, make) {
|
|
|
10
10
|
function fabricateAt(depth) {
|
|
11
11
|
const atMax = depth >= meta.depth.max;
|
|
12
12
|
const target = atMax ? meta.terminal : meta.body;
|
|
13
|
-
const construction = privateSource.toRoot(
|
|
13
|
+
const construction = privateSource.toRoot();
|
|
14
14
|
const context = {
|
|
15
15
|
toTrace: (path, kind)=>({
|
|
16
16
|
...construction,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
const
|
|
3
|
+
const registry = {
|
|
4
4
|
...Schema({
|
|
5
5
|
[Kind]: "symbol",
|
|
6
6
|
[Meta]: {},
|
|
@@ -14,4 +14,5 @@ const Registry = {
|
|
|
14
14
|
}
|
|
15
15
|
})
|
|
16
16
|
};
|
|
17
|
+
const Registry = registry;
|
|
17
18
|
export default Registry;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
const
|
|
3
|
+
const registry = Schema({
|
|
4
4
|
[Kind]: "undefined",
|
|
5
5
|
[Meta]: {},
|
|
6
6
|
[Produces]: void 0
|
|
7
7
|
});
|
|
8
|
+
const Registry = registry;
|
|
8
9
|
export default Registry;
|