@ghostry/fabricator 0.0.13 → 0.0.15

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 (234) hide show
  1. package/dist/esm/Bound.js +74 -1
  2. package/dist/esm/Distribution/index.js +103 -2
  3. package/dist/esm/Enumeration/Enumerate.js +10 -5
  4. package/dist/esm/Enumeration/Plan.js +2 -2
  5. package/dist/esm/Error/index.js +96 -27
  6. package/dist/esm/Fabricator/Constructor.js +7 -5
  7. package/dist/esm/Instance/Core.js +3 -0
  8. package/dist/esm/Primitive/array/Admits.js +18 -0
  9. package/dist/esm/Primitive/array/Fabricator.js +20 -2
  10. package/dist/esm/Primitive/array/Registry.js +32 -0
  11. package/dist/esm/Primitive/array/Schema.js +8 -0
  12. package/dist/esm/Primitive/bigint/Admits.js +11 -0
  13. package/dist/esm/Primitive/bigint/Fabricator.js +16 -23
  14. package/dist/esm/Primitive/bigint/Registry.js +17 -6
  15. package/dist/esm/Primitive/bigint/Schema.js +8 -0
  16. package/dist/esm/Primitive/date/Admits.js +22 -0
  17. package/dist/esm/Primitive/date/Defaults.js +27 -1
  18. package/dist/esm/Primitive/date/Fabricator.js +32 -34
  19. package/dist/esm/Primitive/date/Registry.js +80 -13
  20. package/dist/esm/Primitive/date/Schema.js +8 -0
  21. package/dist/esm/Primitive/enum/Fabricator.js +14 -2
  22. package/dist/esm/Primitive/enum/Registry.js +38 -25
  23. package/dist/esm/Primitive/index.js +1 -0
  24. package/dist/esm/Primitive/number/Admits.js +27 -0
  25. package/dist/esm/Primitive/number/Fabricator.js +18 -9
  26. package/dist/esm/Primitive/number/Registry.js +55 -4
  27. package/dist/esm/Primitive/number/Schema.js +10 -3
  28. package/dist/esm/Primitive/object/Fabricator.js +2 -0
  29. package/dist/esm/Primitive/record/Admits.js +42 -0
  30. package/dist/esm/Primitive/record/Fabricator.js +49 -19
  31. package/dist/esm/Primitive/record/Registry.js +29 -0
  32. package/dist/esm/Primitive/record/Schema.js +8 -0
  33. package/dist/esm/Primitive/recursive/Fabricator.js +3 -2
  34. package/dist/esm/Primitive/recursive/Terminate.js +16 -2
  35. package/dist/esm/Primitive/string/Admits.js +26 -0
  36. package/dist/esm/Primitive/string/Capacity.js +81 -0
  37. package/dist/esm/Primitive/string/Fabricator.js +23 -43
  38. package/dist/esm/Primitive/string/Registry.js +31 -9
  39. package/dist/esm/Primitive/string/Schema.js +10 -3
  40. package/dist/esm/Primitive/string/Sources.js +41 -0
  41. package/dist/esm/Primitive/unique/Registry.js +22 -0
  42. package/dist/esm/Primitive/unique/index.js +2 -0
  43. package/dist/esm/Types.js +2 -1
  44. package/dist/esm/Unique/Capacity.js +85 -0
  45. package/dist/esm/Unique/Distinct.js +187 -0
  46. package/dist/esm/Unique/Key.js +70 -0
  47. package/dist/esm/Unique/Override.js +23 -0
  48. package/dist/esm/Unique/Strategy.js +173 -0
  49. package/dist/esm/internal.js +1 -0
  50. package/dist/types/Adapter/Core.d.ts +2 -2
  51. package/dist/types/Adapter/Types.d.ts +1 -1
  52. package/dist/types/Bound.d.ts +67 -1
  53. package/dist/types/Distribution/index.d.ts +83 -1
  54. package/dist/types/Enumeration/Enumerate.d.ts +3 -3
  55. package/dist/types/Enumeration/Plan.d.ts +1 -1
  56. package/dist/types/Enumeration/Types.d.ts +14 -5
  57. package/dist/types/Error/index.d.ts +283 -0
  58. package/dist/types/Fabricator/Constructor.d.ts +9 -5
  59. package/dist/types/Fabricator/Fabricate.d.ts +5 -5
  60. package/dist/types/Fabricator/Types.d.ts +19 -6
  61. package/dist/types/Harnessing/Core.d.ts +3 -3
  62. package/dist/types/Harnessing/Salt.d.ts +1 -1
  63. package/dist/types/Harnessing/Types.d.ts +2 -2
  64. package/dist/types/Instance/Core.d.ts +4 -4
  65. package/dist/types/Instance/Stack/Async.d.ts +1 -1
  66. package/dist/types/Instance/Stack/Sync.d.ts +1 -1
  67. package/dist/types/Instance/Stack/Visible.d.ts +2 -2
  68. package/dist/types/Instance/Types.d.ts +19 -5
  69. package/dist/types/Primitive/always/Fabricator.d.ts +6 -6
  70. package/dist/types/Primitive/always/Registry.d.ts +2 -2
  71. package/dist/types/Primitive/always/Schema.d.ts +4 -4
  72. package/dist/types/Primitive/always/Types.d.ts +2 -2
  73. package/dist/types/Primitive/always/index.d.ts +5 -5
  74. package/dist/types/Primitive/array/Admits.d.ts +7 -0
  75. package/dist/types/Primitive/array/Fabricator.d.ts +7 -7
  76. package/dist/types/Primitive/array/Registry.d.ts +40 -3
  77. package/dist/types/Primitive/array/Schema.d.ts +10 -5
  78. package/dist/types/Primitive/array/Types.d.ts +37 -5
  79. package/dist/types/Primitive/array/index.d.ts +5 -5
  80. package/dist/types/Primitive/bigint/Admits.d.ts +7 -0
  81. package/dist/types/Primitive/bigint/Fabricator.d.ts +8 -6
  82. package/dist/types/Primitive/bigint/Registry.d.ts +24 -4
  83. package/dist/types/Primitive/bigint/Schema.d.ts +13 -5
  84. package/dist/types/Primitive/bigint/Types.d.ts +30 -6
  85. package/dist/types/Primitive/bigint/index.d.ts +5 -5
  86. package/dist/types/Primitive/boolean/Fabricator.d.ts +6 -6
  87. package/dist/types/Primitive/boolean/Registry.d.ts +2 -2
  88. package/dist/types/Primitive/boolean/Schema.d.ts +5 -5
  89. package/dist/types/Primitive/boolean/Types.d.ts +3 -3
  90. package/dist/types/Primitive/boolean/index.d.ts +6 -6
  91. package/dist/types/Primitive/choice/Fabricator.d.ts +6 -6
  92. package/dist/types/Primitive/choice/Registry.d.ts +2 -2
  93. package/dist/types/Primitive/choice/Schema.d.ts +5 -5
  94. package/dist/types/Primitive/choice/Types.d.ts +4 -4
  95. package/dist/types/Primitive/choice/index.d.ts +5 -5
  96. package/dist/types/Primitive/date/Admits.d.ts +7 -0
  97. package/dist/types/Primitive/date/Defaults.d.ts +22 -1
  98. package/dist/types/Primitive/date/Fabricator.d.ts +8 -6
  99. package/dist/types/Primitive/date/Registry.d.ts +49 -13
  100. package/dist/types/Primitive/date/Schema.d.ts +14 -5
  101. package/dist/types/Primitive/date/Types.d.ts +57 -8
  102. package/dist/types/Primitive/date/index.d.ts +5 -5
  103. package/dist/types/Primitive/derive/Fabricator.d.ts +7 -7
  104. package/dist/types/Primitive/derive/Registry.d.ts +2 -2
  105. package/dist/types/Primitive/derive/Schema.d.ts +6 -6
  106. package/dist/types/Primitive/derive/Types.d.ts +6 -6
  107. package/dist/types/Primitive/derive/index.d.ts +5 -5
  108. package/dist/types/Primitive/enum/Fabricator.d.ts +8 -6
  109. package/dist/types/Primitive/enum/Registry.d.ts +22 -2
  110. package/dist/types/Primitive/enum/Schema.d.ts +5 -5
  111. package/dist/types/Primitive/enum/Types.d.ts +8 -3
  112. package/dist/types/Primitive/enum/index.d.ts +5 -5
  113. package/dist/types/Primitive/index.d.ts +28 -27
  114. package/dist/types/Primitive/namespace.d.ts +21 -21
  115. package/dist/types/Primitive/null/Fabricator.d.ts +6 -6
  116. package/dist/types/Primitive/null/Registry.d.ts +1 -1
  117. package/dist/types/Primitive/null/Schema.d.ts +4 -4
  118. package/dist/types/Primitive/null/Types.d.ts +2 -2
  119. package/dist/types/Primitive/null/index.d.ts +5 -5
  120. package/dist/types/Primitive/nullable/Fabricator.d.ts +6 -6
  121. package/dist/types/Primitive/nullable/Registry.d.ts +2 -2
  122. package/dist/types/Primitive/nullable/Schema.d.ts +6 -6
  123. package/dist/types/Primitive/nullable/Types.d.ts +5 -5
  124. package/dist/types/Primitive/nullable/index.d.ts +6 -6
  125. package/dist/types/Primitive/nullish/Fabricator.d.ts +6 -6
  126. package/dist/types/Primitive/nullish/Registry.d.ts +2 -2
  127. package/dist/types/Primitive/nullish/Schema.d.ts +6 -6
  128. package/dist/types/Primitive/nullish/Types.d.ts +5 -5
  129. package/dist/types/Primitive/nullish/index.d.ts +6 -6
  130. package/dist/types/Primitive/number/Admits.d.ts +9 -0
  131. package/dist/types/Primitive/number/Defaults.d.ts +1 -1
  132. package/dist/types/Primitive/number/Fabricator.d.ts +8 -6
  133. package/dist/types/Primitive/number/Registry.d.ts +45 -4
  134. package/dist/types/Primitive/number/Schema.d.ts +14 -6
  135. package/dist/types/Primitive/number/Types.d.ts +36 -14
  136. package/dist/types/Primitive/number/index.d.ts +5 -5
  137. package/dist/types/Primitive/object/Fabricator.d.ts +6 -6
  138. package/dist/types/Primitive/object/Registry.d.ts +4 -4
  139. package/dist/types/Primitive/object/Schema.d.ts +8 -8
  140. package/dist/types/Primitive/object/Types.d.ts +6 -6
  141. package/dist/types/Primitive/object/compute/Fabricator.d.ts +7 -7
  142. package/dist/types/Primitive/object/compute/Registry.d.ts +2 -2
  143. package/dist/types/Primitive/object/compute/Schema.d.ts +7 -7
  144. package/dist/types/Primitive/object/compute/Types.d.ts +3 -3
  145. package/dist/types/Primitive/object/compute/index.d.ts +5 -5
  146. package/dist/types/Primitive/object/index.d.ts +8 -8
  147. package/dist/types/Primitive/object/omit/Registry.d.ts +2 -2
  148. package/dist/types/Primitive/object/omit/index.d.ts +2 -2
  149. package/dist/types/Primitive/object/omittable/Fabricator.d.ts +6 -6
  150. package/dist/types/Primitive/object/omittable/Registry.d.ts +2 -2
  151. package/dist/types/Primitive/object/omittable/Schema.d.ts +6 -6
  152. package/dist/types/Primitive/object/omittable/Types.d.ts +5 -5
  153. package/dist/types/Primitive/object/omittable/index.d.ts +6 -6
  154. package/dist/types/Primitive/object/optional/Fabricator.d.ts +6 -6
  155. package/dist/types/Primitive/object/optional/Registry.d.ts +2 -2
  156. package/dist/types/Primitive/object/optional/Schema.d.ts +6 -6
  157. package/dist/types/Primitive/object/optional/Types.d.ts +5 -5
  158. package/dist/types/Primitive/object/optional/index.d.ts +6 -6
  159. package/dist/types/Primitive/object/pick/Registry.d.ts +2 -2
  160. package/dist/types/Primitive/object/pick/index.d.ts +2 -2
  161. package/dist/types/Primitive/opaque/Fabricator.d.ts +6 -6
  162. package/dist/types/Primitive/opaque/Registry.d.ts +2 -2
  163. package/dist/types/Primitive/opaque/Schema.d.ts +4 -4
  164. package/dist/types/Primitive/opaque/Types.d.ts +3 -3
  165. package/dist/types/Primitive/opaque/index.d.ts +5 -5
  166. package/dist/types/Primitive/record/Admits.d.ts +18 -0
  167. package/dist/types/Primitive/record/Fabricator.d.ts +7 -7
  168. package/dist/types/Primitive/record/Registry.d.ts +20 -3
  169. package/dist/types/Primitive/record/Schema.d.ts +12 -5
  170. package/dist/types/Primitive/record/Types.d.ts +64 -10
  171. package/dist/types/Primitive/record/index.d.ts +5 -5
  172. package/dist/types/Primitive/recursive/Fabricator.d.ts +6 -6
  173. package/dist/types/Primitive/recursive/Registry.d.ts +4 -4
  174. package/dist/types/Primitive/recursive/Schema.d.ts +4 -4
  175. package/dist/types/Primitive/recursive/Terminate.d.ts +8 -1
  176. package/dist/types/Primitive/recursive/Types.d.ts +3 -3
  177. package/dist/types/Primitive/recursive/index.d.ts +6 -6
  178. package/dist/types/Primitive/recursive/self/Fabricator.d.ts +5 -5
  179. package/dist/types/Primitive/recursive/self/Registry.d.ts +1 -1
  180. package/dist/types/Primitive/recursive/self/Schema.d.ts +4 -4
  181. package/dist/types/Primitive/recursive/self/Types.d.ts +2 -2
  182. package/dist/types/Primitive/recursive/self/index.d.ts +5 -5
  183. package/dist/types/Primitive/string/Admits.d.ts +8 -0
  184. package/dist/types/Primitive/string/Capacity.d.ts +36 -0
  185. package/dist/types/Primitive/string/Constants.d.ts +1 -1
  186. package/dist/types/Primitive/string/Fabricator.d.ts +8 -6
  187. package/dist/types/Primitive/string/Registry.d.ts +29 -8
  188. package/dist/types/Primitive/string/Schema.d.ts +32 -6
  189. package/dist/types/Primitive/string/Sources.d.ts +16 -0
  190. package/dist/types/Primitive/string/Types.d.ts +39 -19
  191. package/dist/types/Primitive/string/index.d.ts +6 -6
  192. package/dist/types/Primitive/symbol/Fabricator.d.ts +6 -6
  193. package/dist/types/Primitive/symbol/Registry.d.ts +2 -2
  194. package/dist/types/Primitive/symbol/Schema.d.ts +5 -5
  195. package/dist/types/Primitive/symbol/Types.d.ts +3 -3
  196. package/dist/types/Primitive/symbol/index.d.ts +5 -5
  197. package/dist/types/Primitive/tuple/Fabricator.d.ts +6 -6
  198. package/dist/types/Primitive/tuple/Registry.d.ts +2 -2
  199. package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
  200. package/dist/types/Primitive/tuple/Types.d.ts +4 -4
  201. package/dist/types/Primitive/tuple/index.d.ts +5 -5
  202. package/dist/types/Primitive/undefinable/Fabricator.d.ts +6 -6
  203. package/dist/types/Primitive/undefinable/Registry.d.ts +2 -2
  204. package/dist/types/Primitive/undefinable/Schema.d.ts +6 -6
  205. package/dist/types/Primitive/undefinable/Types.d.ts +5 -5
  206. package/dist/types/Primitive/undefinable/index.d.ts +6 -6
  207. package/dist/types/Primitive/undefined/Fabricator.d.ts +6 -6
  208. package/dist/types/Primitive/undefined/Registry.d.ts +1 -1
  209. package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
  210. package/dist/types/Primitive/undefined/Types.d.ts +2 -2
  211. package/dist/types/Primitive/undefined/index.d.ts +5 -5
  212. package/dist/types/Primitive/unique/Registry.d.ts +39 -0
  213. package/dist/types/Primitive/unique/index.d.ts +2 -0
  214. package/dist/types/Random/Generator/sfc32.d.ts +1 -1
  215. package/dist/types/Random/Types.d.ts +1 -1
  216. package/dist/types/Random/index.d.ts +1 -1
  217. package/dist/types/Schema/Core.d.ts +5 -5
  218. package/dist/types/Schema/Registry.d.ts +3 -3
  219. package/dist/types/Schema/Satisfies.d.ts +3 -3
  220. package/dist/types/Schema/Types.d.ts +5 -5
  221. package/dist/types/Types.d.ts +11 -2
  222. package/dist/types/Unique/Capacity.d.ts +29 -0
  223. package/dist/types/Unique/Distinct.d.ts +95 -0
  224. package/dist/types/Unique/Key.d.ts +29 -0
  225. package/dist/types/Unique/Override.d.ts +16 -0
  226. package/dist/types/Unique/Strategy.d.ts +135 -0
  227. package/dist/types/Utility/Core.d.ts +2 -2
  228. package/dist/types/Utility/DeepMerge.d.ts +2 -2
  229. package/dist/types/Utility/ShallowMerge.d.ts +2 -2
  230. package/dist/types/adapting.d.ts +3 -3
  231. package/dist/types/harnessing.d.ts +2 -2
  232. package/dist/types/index.d.ts +40 -27
  233. package/dist/types/internal.d.ts +16 -15
  234. package/package.json +2 -2
@@ -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 fabricate = ()=>Array.from({
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
- }, ()=>element.fabricate());
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
- const { min, max } = effectiveDiscreteBigint(meta.whereby.min, meta.whereby.max);
25
- const range = max - min + BigInt(1);
26
- const byteBits = 8;
27
- const bitWidth = range.toString(2).length;
28
- const byteWidth = Math.ceil(bitWidth / byteBits);
29
- const bitMask = (BigInt(1) << BigInt(bitWidth)) - BigInt(1);
30
- const fabricate = ()=>{
31
- const buffer = new Uint8Array(byteWidth);
32
- const readBufferAsBigInt = ()=>{
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
- while(true){
42
- const candidate = sample();
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, toBound } from "../../Bound.js";
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
- function toWhereby(input) {
20
- const max = toBound(input.max);
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
- } : toBound(input.min);
25
- assertNonemptyDiscreteBigint("T.bigint.whereby", min, max);
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
  };
@@ -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
- export { unboundedEpoch };
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, epochBound } from "../../Bound.js";
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 { unboundedEpoch } from "./Defaults.js";
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
- const whereby = meta.whereby;
28
- if ("past" === meta.mode) {
29
- const fabricate = whereby ? drawPastOrFuture({
30
- min: whereby.min ? epochBound(whereby.min) : unboundedEpoch.min,
31
- max: {
32
- value: clock,
33
- exclusive: false
34
- }
35
- }, "T.date.past", whereby.distribution, stream) : ()=>new Date(clock - stream.next() * (clock + MAX_TIME));
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 = whereby ? draw({
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,5 +1,6 @@
1
- import { assertNonemptyDiscrete, epochBound, toBound } from "../../Bound.js";
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
  function registry() {
@@ -10,16 +11,12 @@ function registry() {
10
11
  [Produces]: void 0,
11
12
  [Adaptation]: void 0
12
13
  }),
13
- whereby: (whereby)=>{
14
- const converted = toWhereby(whereby);
15
- assertNonemptyDiscrete("T.date.whereby", converted.min ? epochBound(converted.min) : unboundedEpoch.min, converted.max ? epochBound(converted.max) : unboundedEpoch.max);
16
- return Schema({
14
+ whereby: (whereby)=>Schema({
17
15
  [Kind]: "date",
18
16
  [Meta]: {
19
- whereby: converted
17
+ whereby: toCheckedWhereby("T.date.whereby", whereby)
20
18
  }
21
- });
22
- },
19
+ }),
23
20
  get past () {
24
21
  return {
25
22
  ...Schema({
@@ -32,7 +29,7 @@ function registry() {
32
29
  [Kind]: "date",
33
30
  [Meta]: {
34
31
  mode: "past",
35
- whereby: toWhereby(whereby)
32
+ whereby: toWhereby("T.date.past.whereby", whereby)
36
33
  }
37
34
  })
38
35
  };
@@ -49,7 +46,7 @@ function registry() {
49
46
  [Kind]: "date",
50
47
  [Meta]: {
51
48
  mode: "future",
52
- whereby: toWhereby(whereby)
49
+ whereby: toWhereby("T.date.future.whereby", whereby)
53
50
  }
54
51
  })
55
52
  };
@@ -57,9 +54,78 @@ function registry() {
57
54
  };
58
55
  }
59
56
  const Registry = registry;
60
- function toWhereby(input) {
61
- const min = void 0 === input.min ? void 0 : toBound(input.min);
62
- const max = void 0 === input.max ? void 0 : toBound(input.max);
57
+ function unique() {
58
+ return {
59
+ ...Schema({
60
+ [Kind]: "date",
61
+ [Meta]: {
62
+ unique: true
63
+ },
64
+ [Produces]: void 0,
65
+ [Adaptation]: void 0
66
+ }),
67
+ whereby: (whereby)=>Schema({
68
+ [Kind]: "date",
69
+ [Meta]: {
70
+ unique: true,
71
+ whereby: withRedraws("T.unique.date.whereby", toCheckedWhereby("T.unique.date.whereby", whereby), whereby)
72
+ }
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);
63
129
  return void 0 === input.distribution ? {
64
130
  min,
65
131
  max
@@ -70,3 +136,4 @@ function toWhereby(input) {
70
136
  };
71
137
  }
72
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
  };
@@ -1,9 +1,10 @@
1
1
  import { weighted } from "../../Distribution/index.js";
2
2
  import { toStreamFromTrace } from "../../Random/index.js";
3
- import { Kind, Meta } from "../../Types.js";
3
+ import { Claim, Kind, Meta } from "../../Types.js";
4
+ import { exactValues, toLifetimeScope } from "../../Unique/Strategy.js";
4
5
  import { Schema } from "./Schema.js";
5
6
  function Fabricator(context) {
6
- const { schema, algorithm, trace } = context;
7
+ const { schema, algorithm, trace, exhaustion } = context;
7
8
  const meta = schema[Meta];
8
9
  const rehydrated = Schema(schema);
9
10
  if (meta.produce) {
@@ -21,6 +22,17 @@ function Fabricator(context) {
21
22
  };
22
23
  }
23
24
  const stream = toStreamFromTrace(algorithm, trace);
25
+ if (meta.unique) {
26
+ const scope = toLifetimeScope(exactValues("enum", meta.items, stream), exhaustion);
27
+ return {
28
+ [Kind]: "enum",
29
+ [Meta]: meta,
30
+ trace,
31
+ fabricate: ()=>scope.draw(),
32
+ [Claim]: scope.claim,
33
+ schema: rehydrated
34
+ };
35
+ }
24
36
  const pick = weighted(meta.items, stream, "T.enum");
25
37
  return {
26
38
  [Kind]: "enum",
@@ -2,32 +2,45 @@ import { assertDrawableWeights } from "../../Distribution/index.js";
2
2
  import { FabricatorError } from "../../Error/index.js";
3
3
  import { Kind, Meta } from "../../Types.js";
4
4
  import { Schema } from "./Schema.js";
5
- function assertNonEmpty(items) {
6
- if (0 === items.length) throw new FabricatorError.EmptyItemsError("T.enum", "member");
5
+ function assertNonEmpty(label, items) {
6
+ if (0 === items.length) throw new FabricatorError.EmptyItemsError(label, "member");
7
+ }
8
+ function uniform(label, flag, items) {
9
+ assertNonEmpty(label, items);
10
+ const weighted = items.map((x)=>[
11
+ 1,
12
+ x
13
+ ]);
14
+ return Schema({
15
+ [Kind]: "enum",
16
+ [Meta]: {
17
+ items: weighted,
18
+ ...flag
19
+ }
20
+ });
21
+ }
22
+ function Registry_weighted(label, flag, items) {
23
+ assertNonEmpty(label, items);
24
+ assertDrawableWeights(`${label}.weighted`, "member", items);
25
+ return Schema({
26
+ [Kind]: "enum",
27
+ [Meta]: {
28
+ items,
29
+ ...flag
30
+ }
31
+ });
7
32
  }
8
33
  const Registry = {
9
- uniform: (items)=>{
10
- assertNonEmpty(items);
11
- const weighted = items.map((x)=>[
12
- 1,
13
- x
14
- ]);
15
- return Schema({
16
- [Kind]: "enum",
17
- [Meta]: {
18
- items: weighted
19
- }
20
- });
21
- },
22
- weighted: (items)=>{
23
- assertNonEmpty(items);
24
- assertDrawableWeights("T.enum.weighted", "member", items);
25
- return Schema({
26
- [Kind]: "enum",
27
- [Meta]: {
28
- items
29
- }
30
- });
31
- }
34
+ uniform: (items)=>uniform("T.enum", {}, items),
35
+ weighted: (items)=>Registry_weighted("T.enum", {}, items)
36
+ };
37
+ const unique = {
38
+ uniform: (items)=>uniform("T.unique.enum", {
39
+ unique: true
40
+ }, items),
41
+ weighted: (items)=>Registry_weighted("T.unique.enum", {
42
+ unique: true
43
+ }, items)
32
44
  };
33
45
  export default Registry;
46
+ export { unique };