@ghostry/fabricator 0.0.8 → 0.0.10

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 (77) hide show
  1. package/dist/esm/Bound.js +6 -1
  2. package/dist/esm/Distribution/index.js +51 -11
  3. package/dist/esm/Instance/Core.js +8 -8
  4. package/dist/esm/Primitive/always/Schema.js +2 -0
  5. package/dist/esm/Primitive/array/Fabricator.js +4 -9
  6. package/dist/esm/Primitive/array/Schema.js +2 -0
  7. package/dist/esm/Primitive/bigint/Schema.js +2 -0
  8. package/dist/esm/Primitive/boolean/Schema.js +2 -0
  9. package/dist/esm/Primitive/choice/Schema.js +2 -0
  10. package/dist/esm/Primitive/date/Schema.js +2 -0
  11. package/dist/esm/Primitive/derive/Schema.js +2 -0
  12. package/dist/esm/Primitive/enum/Schema.js +2 -0
  13. package/dist/esm/Primitive/null/Schema.js +2 -0
  14. package/dist/esm/Primitive/nullable/Schema.js +2 -0
  15. package/dist/esm/Primitive/nullish/Schema.js +2 -0
  16. package/dist/esm/Primitive/number/Fabricator.js +3 -7
  17. package/dist/esm/Primitive/number/Schema.js +2 -0
  18. package/dist/esm/Primitive/object/Schema.js +3 -1
  19. package/dist/esm/Primitive/object/compute/Schema.js +2 -0
  20. package/dist/esm/Primitive/object/omittable/Schema.js +2 -0
  21. package/dist/esm/Primitive/object/optional/Schema.js +2 -0
  22. package/dist/esm/Primitive/opaque/Schema.js +2 -0
  23. package/dist/esm/Primitive/record/Fabricator.js +6 -1
  24. package/dist/esm/Primitive/record/Schema.js +2 -0
  25. package/dist/esm/Primitive/recursive/Schema.js +2 -0
  26. package/dist/esm/Primitive/recursive/self/Schema.js +2 -0
  27. package/dist/esm/Primitive/string/Fabricator.js +6 -2
  28. package/dist/esm/Primitive/string/Schema.js +2 -0
  29. package/dist/esm/Primitive/symbol/Schema.js +2 -0
  30. package/dist/esm/Primitive/tuple/Schema.js +2 -0
  31. package/dist/esm/Primitive/undefinable/Schema.js +2 -0
  32. package/dist/esm/Primitive/undefined/Schema.js +2 -0
  33. package/dist/esm/Schema/Satisfies.js +5 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/internal.js +1 -0
  36. package/dist/types/Bound.d.ts +20 -4
  37. package/dist/types/Distribution/index.d.ts +36 -2
  38. package/dist/types/Error/index.d.ts +2 -4
  39. package/dist/types/Harnessing/Core.d.ts +4 -4
  40. package/dist/types/Primitive/always/Schema.d.ts +8 -1
  41. package/dist/types/Primitive/array/Registry.d.ts +7 -5
  42. package/dist/types/Primitive/array/Schema.d.ts +7 -0
  43. package/dist/types/Primitive/array/Types.d.ts +3 -9
  44. package/dist/types/Primitive/bigint/Schema.d.ts +7 -0
  45. package/dist/types/Primitive/boolean/Schema.d.ts +7 -0
  46. package/dist/types/Primitive/choice/Registry.d.ts +3 -3
  47. package/dist/types/Primitive/choice/Schema.d.ts +7 -0
  48. package/dist/types/Primitive/date/Schema.d.ts +7 -0
  49. package/dist/types/Primitive/derive/Schema.d.ts +8 -0
  50. package/dist/types/Primitive/derive/Types.d.ts +5 -6
  51. package/dist/types/Primitive/enum/Registry.d.ts +3 -3
  52. package/dist/types/Primitive/enum/Schema.d.ts +7 -0
  53. package/dist/types/Primitive/null/Schema.d.ts +9 -2
  54. package/dist/types/Primitive/nullable/Schema.d.ts +7 -0
  55. package/dist/types/Primitive/nullish/Schema.d.ts +7 -0
  56. package/dist/types/Primitive/number/Schema.d.ts +7 -0
  57. package/dist/types/Primitive/object/Schema.d.ts +12 -2
  58. package/dist/types/Primitive/object/compute/Schema.d.ts +8 -0
  59. package/dist/types/Primitive/object/omittable/Schema.d.ts +10 -1
  60. package/dist/types/Primitive/object/optional/Schema.d.ts +9 -1
  61. package/dist/types/Primitive/opaque/Schema.d.ts +8 -1
  62. package/dist/types/Primitive/record/Schema.d.ts +7 -0
  63. package/dist/types/Primitive/record/Types.d.ts +2 -2
  64. package/dist/types/Primitive/recursive/Schema.d.ts +8 -1
  65. package/dist/types/Primitive/recursive/self/Schema.d.ts +11 -1
  66. package/dist/types/Primitive/string/Registry.d.ts +13 -9
  67. package/dist/types/Primitive/string/Schema.d.ts +7 -0
  68. package/dist/types/Primitive/string/Types.d.ts +7 -11
  69. package/dist/types/Primitive/symbol/Schema.d.ts +7 -0
  70. package/dist/types/Primitive/tuple/Schema.d.ts +7 -0
  71. package/dist/types/Primitive/undefinable/Schema.d.ts +7 -0
  72. package/dist/types/Primitive/undefined/Schema.d.ts +9 -2
  73. package/dist/types/Schema/Satisfies.d.ts +84 -0
  74. package/dist/types/Schema/Types.d.ts +17 -1
  75. package/dist/types/index.d.ts +9 -0
  76. package/dist/types/internal.d.ts +7 -0
  77. package/package.json +1 -1
package/dist/esm/Bound.js CHANGED
@@ -76,6 +76,11 @@ function toLengthRange(length, label) {
76
76
  max: toBound(length.max)
77
77
  };
78
78
  assertNonemptyDiscrete(label, range.min, range.max);
79
- return range;
79
+ if ("number" == typeof length || void 0 === length.distribution) return range;
80
+ return {
81
+ min: range.min,
82
+ max: range.max,
83
+ distribution: length.distribution
84
+ };
80
85
  }
81
86
  export { assertNonemptyContinuous, assertNonemptyDiscrete, assertNonemptyDiscreteBigint, constrainContinuous, effectiveDiscrete, effectiveDiscreteBigint, epochBound, toBound, toLengthRange, towardInterior };
@@ -42,6 +42,14 @@ function unitPosition(x, min, max) {
42
42
  if (!Number.isFinite(ratio)) return 0;
43
43
  return 1 / (1 + ratio);
44
44
  }
45
+ function discreteSampler(distribution, range, stream) {
46
+ const { min, max } = range;
47
+ const draw = sampler(null != distribution ? distribution : Distribution_Distribution.uniform(), {
48
+ min,
49
+ max: max + 1
50
+ }, stream);
51
+ return ()=>Math.min(max, Math.floor(draw()));
52
+ }
45
53
  function sampler(distribution, range, stream) {
46
54
  const { min, max } = range;
47
55
  const span = max - min;
@@ -136,7 +144,10 @@ function normalInv(p) {
136
144
  }
137
145
  function sample(list, stream) {
138
146
  if (0 === list.length) throw new FabricatorError.EmptyItemsError("sample", "item");
139
- const index = Math.floor(stream.next() * list.length);
147
+ const index = discreteSampler(void 0, {
148
+ min: 0,
149
+ max: list.length - 1
150
+ }, stream)();
140
151
  const item = list[index];
141
152
  return item;
142
153
  }
@@ -185,17 +196,46 @@ function assertDrawableKeyedWeights(label, outcomes, weights) {
185
196
  if (0 === drawableOutcomes(outcomes, weights).length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
186
197
  }
187
198
  function weighted(weights, stream, label) {
188
- let sum = 0;
189
- const weightings = weights.filter(([weight])=>isDrawable(weight)).map(([weight, item])=>[
190
- sum += weight,
191
- item
192
- ]);
193
- if (0 === weightings.length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
199
+ const drawable = weights.filter(([weight])=>isDrawable(weight));
200
+ if (0 === drawable.length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
201
+ const items = drawable.map(([, item])=>item);
202
+ const column = discreteSampler(void 0, {
203
+ min: 0,
204
+ max: items.length - 1
205
+ }, stream);
206
+ const [first] = drawable[0];
207
+ if (drawable.every(([weight])=>weight === first)) return ()=>items[column()];
208
+ const table = toAliasTable(drawable.map(([weight])=>weight));
194
209
  return ()=>{
195
- const x = stream.next() * sum;
196
- const chosen = weightings.find(([weight])=>x < weight);
197
- return chosen[1];
210
+ const i = column();
211
+ const probability = table.probability[i];
212
+ if (1 === probability) return items[i];
213
+ return items[stream.next() < probability ? i : table.alias[i]];
214
+ };
215
+ }
216
+ function toAliasTable(weights) {
217
+ const n = weights.length;
218
+ const sum = weights.reduce((total, weight)=>total + weight, 0);
219
+ const scaled = weights.map((weight)=>weight * n / sum);
220
+ const probability = new Float64Array(n);
221
+ const aliases = new Uint32Array(n);
222
+ const small = [];
223
+ const large = [];
224
+ for(let i = 0; i < n; i++)(scaled[i] < 1 ? small : large).push(i);
225
+ while(small.length > 0 && large.length > 0){
226
+ const less = small.pop();
227
+ const more = large.pop();
228
+ probability[less] = scaled[less];
229
+ aliases[less] = more;
230
+ scaled[more] = scaled[more] + scaled[less] - 1;
231
+ (scaled[more] < 1 ? small : large).push(more);
232
+ }
233
+ for (const i of large)probability[i] = 1;
234
+ for (const i of small)probability[i] = 1;
235
+ return {
236
+ probability,
237
+ alias: aliases
198
238
  };
199
239
  }
200
240
  var Distribution_Distribution;
201
- export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, drawableOutcomes, isDrawable, isValidWeight, sample, sampler, shuffle, weighted };
241
+ export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, discreteSampler, drawableOutcomes, isDrawable, isValidWeight, sample, sampler, shuffle, weighted };
@@ -96,14 +96,14 @@ function instantiate(config, stack, parent) {
96
96
  return normalizeSalt((null != (_ref = null == (_visibleFrame = visibleFrame()) ? void 0 : _visibleFrame.config) ? _ref : config).salt);
97
97
  },
98
98
  get algorithm () {
99
- var _ref1;
100
- var _visibleFrame1;
101
- return (null != (_ref1 = null == (_visibleFrame1 = visibleFrame()) ? void 0 : _visibleFrame1.config) ? _ref1 : config).algorithm;
99
+ var _ref;
100
+ var _visibleFrame;
101
+ return (null != (_ref = null == (_visibleFrame = visibleFrame()) ? void 0 : _visibleFrame.config) ? _ref : config).algorithm;
102
102
  },
103
103
  get clock () {
104
- var _ref2;
105
- var _visibleFrame2;
106
- return resolveClock(null != (_ref2 = null == (_visibleFrame2 = visibleFrame()) ? void 0 : _visibleFrame2.config) ? _ref2 : config);
104
+ var _ref;
105
+ var _visibleFrame;
106
+ return resolveClock(null != (_ref = null == (_visibleFrame = visibleFrame()) ? void 0 : _visibleFrame.config) ? _ref : config);
107
107
  },
108
108
  scope: ()=>{
109
109
  var _ref;
@@ -118,8 +118,8 @@ function instantiate(config, stack, parent) {
118
118
  T: config.types,
119
119
  ancestry,
120
120
  get root () {
121
- var _ref3;
122
- return null != (_ref3 = null == parent ? void 0 : parent.root) ? _ref3 : instance;
121
+ var _ref;
122
+ return null != (_ref = null == parent ? void 0 : parent.root) ? _ref : instance;
123
123
  },
124
124
  Fabricator,
125
125
  combinatorial,
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "always",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,7 +1,7 @@
1
1
  import { effectiveDiscrete } from "../../Bound.js";
2
+ import { discreteSampler } from "../../Distribution/index.js";
2
3
  import { toStreamFromTrace } from "../../Random/index.js";
3
4
  import { Children, Kind, Meta } from "../../Types.js";
4
- import { inline } from "../../Utility/Core.js";
5
5
  import { Schema } from "./Schema.js";
6
6
  function Fabricator(context, element) {
7
7
  const { schema, algorithm, trace } = context;
@@ -24,15 +24,10 @@ function Fabricator(context, element) {
24
24
  }
25
25
  const stream = toStreamFromTrace(algorithm, trace);
26
26
  const whereby = meta.whereby;
27
- const fabricate = ()=>{
28
- const length = inline(()=>{
29
- const { min, max } = effectiveDiscrete(whereby.length.min, whereby.length.max);
30
- return min + Math.floor(stream.next() * (max - min + 1));
31
- });
32
- return Array.from({
33
- length
27
+ const drawLength = discreteSampler(whereby.length.distribution, effectiveDiscrete(whereby.length.min, whereby.length.max), stream);
28
+ const fabricate = ()=>Array.from({
29
+ length: drawLength()
34
30
  }, ()=>element.fabricate());
35
- };
36
31
  return {
37
32
  [Kind]: "array",
38
33
  [Meta]: meta,
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,5 +1,6 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
2
  import { assertDrawableKeyedWeights } from "../../Distribution/index.js";
3
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
3
4
  import { Kind, Meta } from "../../Types.js";
4
5
  import { outcomes } from "./Outcomes.js";
5
6
  function Schema(schema) {
@@ -13,6 +14,7 @@ function Schema(schema) {
13
14
  produce
14
15
  }
15
16
  }),
17
+ satisfies: schemaSatisfies,
16
18
  weighted: (weights)=>{
17
19
  const merged = {
18
20
  ...schema[Meta].weights,
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "derive",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "null",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,5 +1,6 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
2
  import { assertDrawableKeyedWeights } from "../../Distribution/index.js";
3
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
3
4
  import { Kind, Meta } from "../../Types.js";
4
5
  import { outcomes } from "./Outcomes.js";
5
6
  function Schema(schema) {
@@ -13,6 +14,7 @@ function Schema(schema) {
13
14
  produce
14
15
  }
15
16
  }),
17
+ satisfies: schemaSatisfies,
16
18
  weighted: (weights)=>{
17
19
  const merged = {
18
20
  ...schema[Meta].weights,
@@ -1,5 +1,6 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
2
  import { assertDrawableKeyedWeights } from "../../Distribution/index.js";
3
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
3
4
  import { Kind, Meta } from "../../Types.js";
4
5
  import { outcomes } from "./Outcomes.js";
5
6
  function Schema(schema) {
@@ -13,6 +14,7 @@ function Schema(schema) {
13
14
  produce
14
15
  }
15
16
  }),
17
+ satisfies: schemaSatisfies,
16
18
  weighted: (weights)=>{
17
19
  const merged = {
18
20
  ...schema[Meta].weights,
@@ -1,5 +1,5 @@
1
1
  import { constrainContinuous, effectiveDiscrete } from "../../Bound.js";
2
- import { Distribution, sampler } from "../../Distribution/index.js";
2
+ import { Distribution, discreteSampler, sampler } from "../../Distribution/index.js";
3
3
  import { toStreamFromTrace } from "../../Random/index.js";
4
4
  import { Kind, Meta } from "../../Types.js";
5
5
  import { unboundedContinuous, unboundedDiscrete } from "./defaults.js";
@@ -46,16 +46,12 @@ function Fabricator(context) {
46
46
  };
47
47
  const distribution = null != (_range_distribution = range.distribution) ? _range_distribution : Distribution.uniform();
48
48
  if (meta.integer) {
49
- const { min, max } = effectiveDiscrete(range.min, range.max);
50
- const draw = sampler(distribution, {
51
- min,
52
- max: max + 1
53
- }, stream);
49
+ const draw = discreteSampler(distribution, effectiveDiscrete(range.min, range.max), stream);
54
50
  return {
55
51
  [Kind]: "number",
56
52
  [Meta]: meta,
57
53
  trace,
58
- fabricate: ()=>Math.min(max, Math.floor(draw())),
54
+ fabricate: ()=>draw(),
59
55
  schema: rehydrated
60
56
  };
61
57
  }
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -12,6 +13,7 @@ function Schema(schema) {
12
13
  hints
13
14
  }
14
15
  }),
16
+ satisfies: schemaSatisfies,
15
17
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
16
18
  };
17
19
  }
@@ -1,3 +1,4 @@
1
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
1
2
  import { Kind, Meta } from "../../Types.js";
2
3
  function Schema(schema) {
3
4
  return {
@@ -9,7 +10,8 @@ function Schema(schema) {
9
10
  ...schema[Meta],
10
11
  produce
11
12
  }
12
- })
13
+ }),
14
+ satisfies: schemaSatisfies
13
15
  };
14
16
  }
15
17
  function isObjectSchema(candidate) {
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "object.compute",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,5 +1,6 @@
1
1
  import { withAdaptations } from "../../../Adapter/Core.js";
2
2
  import { assertDrawableKeyedWeights } from "../../../Distribution/index.js";
3
+ import { schemaSatisfies } from "../../../Schema/Satisfies.js";
3
4
  import { Kind, Meta } from "../../../Types.js";
4
5
  import { outcomes } from "./Outcomes.js";
5
6
  function Schema(schema) {
@@ -13,6 +14,7 @@ function Schema(schema) {
13
14
  produce
14
15
  }
15
16
  }),
17
+ satisfies: schemaSatisfies,
16
18
  weighted: (weights)=>{
17
19
  const merged = {
18
20
  ...schema[Meta].weights,
@@ -1,5 +1,6 @@
1
1
  import { withAdaptations } from "../../../Adapter/Core.js";
2
2
  import { assertDrawableKeyedWeights } from "../../../Distribution/index.js";
3
+ import { schemaSatisfies } from "../../../Schema/Satisfies.js";
3
4
  import { Kind, Meta } from "../../../Types.js";
4
5
  import { outcomes } from "./Outcomes.js";
5
6
  function Schema(schema) {
@@ -13,6 +14,7 @@ function Schema(schema) {
13
14
  produce
14
15
  }
15
16
  }),
17
+ satisfies: schemaSatisfies,
16
18
  weighted: (weights)=>{
17
19
  const merged = {
18
20
  ...schema[Meta].weights,
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "opaque",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,3 +1,4 @@
1
+ import { discreteSampler } from "../../Distribution/index.js";
1
2
  import { toStreamFromTrace } from "../../Random/index.js";
2
3
  import { Children, Kind, Meta } from "../../Types.js";
3
4
  import { Schema } from "./Schema.js";
@@ -25,8 +26,12 @@ function Fabricator(context, key, value) {
25
26
  }
26
27
  const stream = toStreamFromTrace(algorithm, trace);
27
28
  const { max, minTried = 0 } = meta.whereby.size;
29
+ const drawSize = discreteSampler(void 0, {
30
+ min: minTried,
31
+ max
32
+ }, stream);
28
33
  const fabricate = ()=>{
29
- const size = minTried + Math.floor(stream.next() * (max - minTried + 1));
34
+ const size = drawSize();
30
35
  const fabricated = {};
31
36
  for(let i = 0; i < size; i++){
32
37
  const k = key.fabricate();
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "recursive",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "recursive.self",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -1,5 +1,5 @@
1
1
  import { effectiveDiscrete } from "../../Bound.js";
2
- import { weighted } from "../../Distribution/index.js";
2
+ import { discreteSampler, weighted } from "../../Distribution/index.js";
3
3
  import { toStreamFromTrace } from "../../Random/index.js";
4
4
  import { Kind, Meta } from "../../Types.js";
5
5
  import { inline } from "../../Utility/Core.js";
@@ -26,6 +26,10 @@ function Fabricator(context) {
26
26
  const stream = toStreamFromTrace(algorithm, trace);
27
27
  const whereby = meta.whereby;
28
28
  const { min, max } = effectiveDiscrete(whereby.length.min, whereby.length.max);
29
+ const drawLength = discreteSampler(whereby.length.distribution, {
30
+ min,
31
+ max
32
+ }, stream);
29
33
  const sources = inline(()=>{
30
34
  const composition = whereby.composition;
31
35
  if (void 0 === composition) return [
@@ -46,7 +50,7 @@ function Fabricator(context) {
46
50
  ]), stream, "T.string.whereby.composition");
47
51
  const fill = compiler(bmpScalars, stream);
48
52
  const fabricate = ()=>{
49
- const length = min + Math.floor(stream.next() * (max - min + 1));
53
+ const length = drawLength();
50
54
  const pieces = [];
51
55
  let remaining = length;
52
56
  while(remaining > 0){
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -12,6 +13,7 @@ function Schema(schema) {
12
13
  hints
13
14
  }
14
15
  }),
16
+ satisfies: schemaSatisfies,
15
17
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
16
18
  };
17
19
  }
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,4 +1,5 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind, Meta } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
@@ -11,6 +12,7 @@ function Schema(schema) {
11
12
  produce
12
13
  }
13
14
  }),
15
+ satisfies: schemaSatisfies,
14
16
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
15
17
  };
16
18
  }
@@ -1,5 +1,6 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
2
  import { assertDrawableKeyedWeights } from "../../Distribution/index.js";
3
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
3
4
  import { Kind, Meta } from "../../Types.js";
4
5
  import { outcomes } from "./Outcomes.js";
5
6
  function Schema(schema) {
@@ -13,6 +14,7 @@ function Schema(schema) {
13
14
  produce
14
15
  }
15
16
  }),
17
+ satisfies: schemaSatisfies,
16
18
  weighted: (weights)=>{
17
19
  const merged = {
18
20
  ...schema[Meta].weights,
@@ -1,9 +1,11 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
+ import { schemaSatisfies } from "../../Schema/Satisfies.js";
2
3
  import { Kind } from "../../Types.js";
3
4
  function Schema(schema) {
4
5
  return {
5
6
  ...schema,
6
7
  [Kind]: "undefined",
8
+ satisfies: schemaSatisfies,
7
9
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
8
10
  };
9
11
  }
@@ -0,0 +1,5 @@
1
+ function schemaSatisfies() {
2
+ return this;
3
+ }
4
+ function satisfies(buildable) {}
5
+ export { satisfies, schemaSatisfies };
package/dist/esm/index.js CHANGED
@@ -10,4 +10,5 @@ export { FabricatorError } from "./Error/index.js";
10
10
  export { registry } from "./Schema/Registry.js";
11
11
  export { effectiveDiscrete, toBound } from "./Bound.js";
12
12
  export { sample, shuffle } from "./Distribution/index.js";
13
+ export { satisfies } from "./Schema/Satisfies.js";
13
14
  export { initialize };
@@ -2,4 +2,5 @@ export { Children, Kind, Meta, Produces } from "./Types.js";
2
2
  export { isPlainObject } from "./Utility/Core.js";
3
3
  export { plan, resolve } from "./Enumeration/Plan.js";
4
4
  export { defaultAlgorithm, encode, randomSalt, toRandomSource, toStream, toStreamFromTrace } from "./Random/index.js";
5
+ export { weighted } from "./Distribution/index.js";
5
6
  export { toStack as toSynchronousStack } from "./Instance/Stack/Sync.js";