@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.
Files changed (139) hide show
  1. package/README.md +18 -12
  2. package/dist/esm/Adapter/Core.js +3 -3
  3. package/dist/esm/Enumeration/Enumerate.js +16 -13
  4. package/dist/esm/Error/index.js +16 -8
  5. package/dist/esm/Fabricator/Constructor.js +12 -14
  6. package/dist/esm/Harnessing/Core.js +30 -0
  7. package/dist/esm/Harnessing/Salt.js +12 -0
  8. package/dist/esm/Harnessing/Types.js +1 -0
  9. package/dist/esm/Instance/Core.js +25 -41
  10. package/dist/esm/Instance/Stack/Async.js +10 -0
  11. package/dist/esm/Instance/Stack/Sync.js +16 -0
  12. package/dist/esm/Primitive/bigint/Registry.js +12 -12
  13. package/dist/esm/Primitive/boolean/Registry.js +2 -1
  14. package/dist/esm/Primitive/date/Registry.js +15 -14
  15. package/dist/esm/Primitive/null/Registry.js +2 -1
  16. package/dist/esm/Primitive/number/Registry.js +18 -17
  17. package/dist/esm/Primitive/recursive/Fabricator.js +1 -1
  18. package/dist/esm/Primitive/symbol/Registry.js +2 -1
  19. package/dist/esm/Primitive/undefined/Registry.js +2 -1
  20. package/dist/esm/Random/index.js +24 -79
  21. package/dist/esm/Utility/Core.js +6 -1
  22. package/dist/esm/adapting.js +2 -0
  23. package/dist/esm/harnessing.js +1 -0
  24. package/dist/esm/index.js +5 -4
  25. package/dist/esm/internal.js +2 -2
  26. package/dist/types/Adapter/Core.d.ts +30 -33
  27. package/dist/types/Adapter/Types.d.ts +78 -88
  28. package/dist/types/Bound.d.ts +15 -15
  29. package/dist/types/Distribution/index.d.ts +54 -61
  30. package/dist/types/Enumeration/Enumerate.d.ts +24 -24
  31. package/dist/types/Enumeration/Plan.d.ts +22 -26
  32. package/dist/types/Enumeration/Types.d.ts +38 -43
  33. package/dist/types/Error/index.d.ts +103 -89
  34. package/dist/types/Fabricator/Constructor.d.ts +24 -26
  35. package/dist/types/Fabricator/Types.d.ts +73 -81
  36. package/dist/types/Harnessing/Core.d.ts +43 -0
  37. package/dist/types/Harnessing/Salt.d.ts +31 -0
  38. package/dist/types/Harnessing/Types.d.ts +79 -0
  39. package/dist/types/Instance/Core.d.ts +38 -74
  40. package/dist/types/Instance/Stack/Async.d.ts +14 -0
  41. package/dist/types/Instance/Stack/Sync.d.ts +14 -0
  42. package/dist/types/Instance/Types.d.ts +98 -102
  43. package/dist/types/Primitive/always/Schema.d.ts +8 -8
  44. package/dist/types/Primitive/always/Types.d.ts +7 -7
  45. package/dist/types/Primitive/array/Registry.d.ts +10 -8
  46. package/dist/types/Primitive/array/Schema.d.ts +4 -5
  47. package/dist/types/Primitive/array/Types.d.ts +6 -6
  48. package/dist/types/Primitive/bigint/Registry.d.ts +6 -6
  49. package/dist/types/Primitive/bigint/Schema.d.ts +8 -8
  50. package/dist/types/Primitive/bigint/Types.d.ts +5 -5
  51. package/dist/types/Primitive/boolean/Outcomes.d.ts +8 -8
  52. package/dist/types/Primitive/boolean/Registry.d.ts +2 -12
  53. package/dist/types/Primitive/boolean/Schema.d.ts +8 -8
  54. package/dist/types/Primitive/boolean/Types.d.ts +3 -3
  55. package/dist/types/Primitive/choice/Fabricator.d.ts +6 -7
  56. package/dist/types/Primitive/choice/Registry.d.ts +13 -13
  57. package/dist/types/Primitive/choice/Schema.d.ts +6 -6
  58. package/dist/types/Primitive/choice/Types.d.ts +11 -11
  59. package/dist/types/Primitive/date/Registry.d.ts +25 -48
  60. package/dist/types/Primitive/date/Schema.d.ts +9 -10
  61. package/dist/types/Primitive/date/Types.d.ts +4 -4
  62. package/dist/types/Primitive/enum/Registry.d.ts +13 -13
  63. package/dist/types/Primitive/enum/Schema.d.ts +5 -5
  64. package/dist/types/Primitive/enum/Types.d.ts +17 -19
  65. package/dist/types/Primitive/namespace.d.ts +10 -10
  66. package/dist/types/Primitive/null/Registry.d.ts +2 -2
  67. package/dist/types/Primitive/null/Schema.d.ts +2 -2
  68. package/dist/types/Primitive/null/Types.d.ts +3 -3
  69. package/dist/types/Primitive/nullable/Fabricator.d.ts +7 -7
  70. package/dist/types/Primitive/nullable/Schema.d.ts +13 -13
  71. package/dist/types/Primitive/nullable/Types.d.ts +9 -10
  72. package/dist/types/Primitive/nullish/Fabricator.d.ts +12 -13
  73. package/dist/types/Primitive/nullish/Schema.d.ts +8 -8
  74. package/dist/types/Primitive/nullish/Types.d.ts +12 -13
  75. package/dist/types/Primitive/number/Registry.d.ts +20 -38
  76. package/dist/types/Primitive/number/Schema.d.ts +11 -12
  77. package/dist/types/Primitive/number/Types.d.ts +13 -13
  78. package/dist/types/Primitive/number/defaults.d.ts +3 -3
  79. package/dist/types/Primitive/object/Fabricator.d.ts +15 -15
  80. package/dist/types/Primitive/object/Registry.d.ts +8 -8
  81. package/dist/types/Primitive/object/Schema.d.ts +10 -10
  82. package/dist/types/Primitive/object/Types.d.ts +20 -22
  83. package/dist/types/Primitive/object/compute/Fabricator.d.ts +4 -5
  84. package/dist/types/Primitive/object/compute/Schema.d.ts +4 -4
  85. package/dist/types/Primitive/object/compute/Types.d.ts +19 -20
  86. package/dist/types/Primitive/object/omittable/Fabricator.d.ts +10 -10
  87. package/dist/types/Primitive/object/omittable/Outcomes.d.ts +2 -2
  88. package/dist/types/Primitive/object/omittable/Schema.d.ts +11 -11
  89. package/dist/types/Primitive/object/omittable/Types.d.ts +14 -15
  90. package/dist/types/Primitive/object/optional/Fabricator.d.ts +16 -18
  91. package/dist/types/Primitive/object/optional/Outcomes.d.ts +2 -2
  92. package/dist/types/Primitive/object/optional/Schema.d.ts +4 -4
  93. package/dist/types/Primitive/object/optional/Types.d.ts +17 -17
  94. package/dist/types/Primitive/opaque/Registry.d.ts +3 -3
  95. package/dist/types/Primitive/opaque/Schema.d.ts +8 -9
  96. package/dist/types/Primitive/record/Registry.d.ts +8 -6
  97. package/dist/types/Primitive/record/Schema.d.ts +9 -11
  98. package/dist/types/Primitive/record/Types.d.ts +25 -25
  99. package/dist/types/Primitive/recursive/Fabricator.d.ts +20 -21
  100. package/dist/types/Primitive/recursive/Registry.d.ts +6 -7
  101. package/dist/types/Primitive/recursive/Schema.d.ts +8 -8
  102. package/dist/types/Primitive/recursive/Terminate.d.ts +13 -14
  103. package/dist/types/Primitive/recursive/Types.d.ts +31 -31
  104. package/dist/types/Primitive/recursive/self/Fabricator.d.ts +11 -12
  105. package/dist/types/Primitive/recursive/self/Schema.d.ts +10 -10
  106. package/dist/types/Primitive/recursive/self/Types.d.ts +7 -8
  107. package/dist/types/Primitive/string/Constants.d.ts +12 -13
  108. package/dist/types/Primitive/string/Fabricator.d.ts +2 -2
  109. package/dist/types/Primitive/string/Registry.d.ts +10 -16
  110. package/dist/types/Primitive/string/Schema.d.ts +5 -5
  111. package/dist/types/Primitive/string/Types.d.ts +17 -17
  112. package/dist/types/Primitive/symbol/Fabricator.d.ts +2 -2
  113. package/dist/types/Primitive/symbol/Registry.d.ts +4 -11
  114. package/dist/types/Primitive/symbol/Schema.d.ts +6 -6
  115. package/dist/types/Primitive/symbol/Types.d.ts +2 -2
  116. package/dist/types/Primitive/tuple/Fabricator.d.ts +7 -8
  117. package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
  118. package/dist/types/Primitive/tuple/Types.d.ts +24 -25
  119. package/dist/types/Primitive/undefinable/Fabricator.d.ts +7 -7
  120. package/dist/types/Primitive/undefinable/Schema.d.ts +13 -13
  121. package/dist/types/Primitive/undefinable/Types.d.ts +10 -10
  122. package/dist/types/Primitive/undefined/Registry.d.ts +2 -2
  123. package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
  124. package/dist/types/Primitive/undefined/Types.d.ts +3 -3
  125. package/dist/types/Random/Generator/sfc32.d.ts +4 -4
  126. package/dist/types/Random/Types.d.ts +151 -293
  127. package/dist/types/Random/index.d.ts +56 -81
  128. package/dist/types/Schema/Core.d.ts +19 -21
  129. package/dist/types/Schema/Registry.d.ts +3 -3
  130. package/dist/types/Schema/Types.d.ts +41 -48
  131. package/dist/types/Types.d.ts +39 -45
  132. package/dist/types/Utility/Core.d.ts +18 -9
  133. package/dist/types/adapting.d.ts +32 -0
  134. package/dist/types/harnessing.d.ts +30 -0
  135. package/dist/types/index.d.ts +95 -128
  136. package/dist/types/internal.d.ts +53 -40
  137. package/package.json +39 -7
  138. package/dist/esm/Random/CallSite.js +0 -56
  139. package/dist/types/Random/CallSite.d.ts +0 -59
package/README.md CHANGED
@@ -1,6 +1,20 @@
1
- # fabricator
1
+ <div align="center">
2
2
 
3
- Fabricate typed data from composable schemas.
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
+ [![npm](https://img.shields.io/badge/npm-ffffff.svg?style=for-the-badge&color=000000&logo=npm&logoColor=CB3837)](https://www.npmjs.com/package/@ghostry/fabricator)
10
+ [![npmx](https://img.shields.io/badge/npmx-ffffff.svg?style=for-the-badge&color=000000&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTMiIGhlaWdodD0iMTUzIiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAxNTMgMTUzIj4KICA8ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxNi43MDQgOS45ODI3KSI+CiAgICA8cGF0aCBkPSJtMC45MzQ3NiA5Ny4yMDVoMjQuMDgxdjIzLjY5M2gtMjQuMDgxeiIgZmlsbD0iI2ZmZiI+PC9wYXRoPgogICAgPHBhdGggZD0ibTEwMy4xMi05LjIzMDctMy42MjExIDEwLjI0Ni00Ni4zMDkgMTMxLTMuNjIxMSAxMC4yNDZoMTUuNTM3bDMuNjIxMS0xMC4yNDYgMTEuNzE3LTMzLjE0OCAzOC4yMTEtMTA4LjF6IiBmaWxsPSIjNTFjOGZjIj48L3BhdGg+CiAgPC9nPgo8L3N2Zz4K&logoColor=51C8FC)](https://npmx.dev/package/@ghostry/fabricator)
11
+ [![jsr](https://img.shields.io/badge/jsr-ffffff?style=for-the-badge&color=000000&logo=jsr&logoColor=F7DF1E)](https://jsr.io/@ghostry/fabricator)
12
+ [![github](https://img.shields.io/badge/github-ffffff?style=for-the-badge&color=000000&logo=github&logoColor=ffffff)](https://github.com/ghostry-dev/fabricator)
13
+ [![typescript](https://img.shields.io/badge/typescript-ffffff?style=for-the-badge&color=000000&logo=typescript&logoColor=3178C6)](#)
14
+ [![bun](https://img.shields.io/badge/bun-ffffff?style=for-the-badge&color=000000&logo=bun&logoColor=FBF0DF)](#)
15
+ [![node](https://img.shields.io/badge/node-ffffff?style=for-the-badge&color=000000&logo=nodedotjs&logoColor=5FA04E)](#)
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({ seed: "1234" });
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
- `seed: "1234"` is an optional mixer; `clock` (the wall-clock instant of this call, by default) is the run's entropy. Pass the same seed and clock to replay. See the [docs site](https://ghostry-dev.github.io/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).
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).
@@ -38,10 +38,10 @@ function Core_layer(key, adaptation, prior) {
38
38
  [key]: prior
39
39
  }));
40
40
  }
41
- function drive(adapter, schema, context) {
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)=>drive(adapter, child, childContext), context);
45
+ return adapter.convert(schema, (child, childContext)=>walk(adapter, child, childContext), context);
46
46
  }
47
- export { drive, mergeAdaptations, withAdaptations };
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 combinatorialSeed = [
38
- ...effectiveSource().seed,
37
+ const combinatorialSalt = [
38
+ ...effectiveSource().salt,
39
39
  "combinatorial"
40
40
  ];
41
41
  const probe = plan(new Fabricator(schema, {
42
- seed: combinatorialSeed
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
- seed: combinatorialSeed
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 coverageSeed = [
62
- ...base.seed,
63
+ const coverageSalt = [
64
+ ...base.salt,
63
65
  "coverage"
64
66
  ];
65
- const orderSeed = [
66
- ...base.seed,
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
- seed: coverageSeed
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, orderSeed)
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, seed) {
89
- const forked = source.fork(seed);
90
- const root = forked.toRoot("unattributed");
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: [],
@@ -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, normalizeSeed } from "../Random/index.js";
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: forked,
325
- root: forked.toRoot("unattributed", pins)
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,12 @@
1
+ function saltFor(identity) {
2
+ const salt = [
3
+ identity.kind,
4
+ ...identity.path,
5
+ identity.name
6
+ ];
7
+ return "number" == typeof identity.row ? [
8
+ ...salt,
9
+ String(identity.row)
10
+ ] : salt;
11
+ }
12
+ export { saltFor };
@@ -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, normalizeSeed, resolveAttribution, toRandomSource } from "../Random/index.js";
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, normalizeSeed(config.seed));
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, _base_attribution, _ref1, _over_types, _over_limits;
18
+ var _ref, _over_algorithm, _ref1, _over_types, _over_limits;
19
19
  var _this;
20
- const seed = inline(()=>{
21
- if (void 0 === over.seed) return normalizeSeed(base.seed);
22
- if (isLayered(over.seed)) return [
23
- ...normalizeSeed(base.seed),
24
- ...normalizeSeed(over.seed[Layer])
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 normalizeSeed(over.seed);
26
+ return normalizeSalt(over.salt);
27
27
  });
28
28
  const clock = inline(()=>{
29
29
  var _base_clock;
30
- if ("seeded" === over.clock) return "seeded";
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
- seed,
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
- seed: config.seed,
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
- return stack.enter({
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 seed () {
72
+ get salt () {
84
73
  var _ref;
85
74
  var _stack_current;
86
- return normalizeSeed((null != (_ref = null == (_stack_current = stack.current()) ? void 0 : _stack_current.config) ? _ref : config).seed);
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 attribution () {
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).attribution;
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
- seed: source.seed,
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, toStack };
103
+ export { DEFAULT_COMBINATORIAL_LIMIT, instantiate, overlay };
@@ -0,0 +1,10 @@
1
+ import { AsyncLocalStorage } from "async_hooks";
2
+ function toStack() {
3
+ const store = new AsyncLocalStorage();
4
+ return {
5
+ asynchronous: true,
6
+ current: ()=>store.getStore(),
7
+ enter: (frame, block)=>store.run(frame, block)
8
+ };
9
+ }
10
+ export { toStack };
@@ -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 Registry = {
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
- function toWhereby(input) {
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 Registry = Schema({
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
- function toWhereby(input, integer) {
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("counted");
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 Registry = {
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 Registry = Schema({
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;