@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,173 @@
1
+ import { bigintPermutation, isDrawable, permutation, withoutReplacement } from "../Distribution/index.js";
2
+ import { FabricatorError } from "../Error/index.js";
3
+ import { Claim } from "../Types.js";
4
+ import { toKeyer } from "./Key.js";
5
+ const FLOOR = 100;
6
+ const FACTOR = 20;
7
+ function defaultRedraws(produced) {
8
+ return Math.max(FLOOR, FACTOR * produced);
9
+ }
10
+ function toRedraws(label, redraws) {
11
+ if (void 0 === redraws) return;
12
+ if (Number.isSafeInteger(redraws) && redraws >= 0) return redraws;
13
+ throw new FabricatorError.InvalidRedrawsError(label, redraws);
14
+ }
15
+ function exactValues(kind, entries, stream) {
16
+ const { keyer, values } = toDistinctValues(entries);
17
+ const capacity = BigInt(values.length);
18
+ return {
19
+ capacity,
20
+ open: ()=>{
21
+ const pool = withoutReplacement(values, stream);
22
+ return {
23
+ draw: ()=>{
24
+ if (0 === pool.remaining) throw new FabricatorError.UniqueExhaustedError(kind, capacity);
25
+ return pool.draw().value;
26
+ },
27
+ claim: (value)=>{
28
+ const key = keyer(value);
29
+ pool.discard((entry)=>entry.key === key);
30
+ }
31
+ };
32
+ }
33
+ };
34
+ }
35
+ function toDistinctValues(entries) {
36
+ const keyer = toKeyer();
37
+ const merged = new Map();
38
+ for (const [weight, value] of entries){
39
+ if (!isDrawable(weight)) continue;
40
+ const key = keyer(value);
41
+ const known = merged.get(key);
42
+ if (known) known[0] += weight;
43
+ else merged.set(key, [
44
+ weight,
45
+ {
46
+ key,
47
+ value
48
+ }
49
+ ]);
50
+ }
51
+ return {
52
+ keyer,
53
+ values: [
54
+ ...merged.values()
55
+ ]
56
+ };
57
+ }
58
+ function exactRange(kind, range, stream) {
59
+ const capacity = BigInt(range.max - range.min + 1);
60
+ return {
61
+ capacity,
62
+ open: ()=>{
63
+ const order = permutation(range, stream);
64
+ const claimed = new Set();
65
+ return {
66
+ draw: ()=>{
67
+ while(order.remaining > 0){
68
+ const value = order.next();
69
+ if (!claimed.delete(value)) return value;
70
+ }
71
+ throw new FabricatorError.UniqueExhaustedError(kind, capacity);
72
+ },
73
+ claim: (value)=>{
74
+ if ("number" == typeof value && Number.isInteger(value) && value >= range.min && value <= range.max) claimed.add(value);
75
+ }
76
+ };
77
+ }
78
+ };
79
+ }
80
+ function exactBigintRange(kind, range, stream) {
81
+ const capacity = range.max - range.min + BigInt(1);
82
+ return {
83
+ capacity,
84
+ open: ()=>{
85
+ const order = bigintPermutation(range, stream);
86
+ const claimed = new Set();
87
+ return {
88
+ draw: ()=>{
89
+ while(order.remaining > BigInt(0)){
90
+ const value = order.next();
91
+ if (!claimed.delete(value)) return value;
92
+ }
93
+ throw new FabricatorError.UniqueExhaustedError(kind, capacity);
94
+ },
95
+ claim: (value)=>{
96
+ if ("bigint" == typeof value && value >= range.min && value <= range.max) claimed.add(value);
97
+ }
98
+ };
99
+ }
100
+ };
101
+ }
102
+ function tracked(options) {
103
+ const { label, kind, draw, key, capacity, admits, redraws } = options;
104
+ return {
105
+ capacity,
106
+ open: ()=>{
107
+ const seen = new Set();
108
+ return {
109
+ draw: ()=>{
110
+ if (void 0 !== capacity && BigInt(seen.size) >= capacity) throw new FabricatorError.UniqueExhaustedError(kind, capacity);
111
+ const limit = null != redraws ? redraws : defaultRedraws(seen.size);
112
+ for(let redraw = 0; redraw <= limit; redraw++){
113
+ const value = draw();
114
+ const k = key(value);
115
+ if (!seen.has(k)) {
116
+ seen.add(k);
117
+ return value;
118
+ }
119
+ }
120
+ throw new FabricatorError.UniqueRedrawsError(label, limit, seen.size);
121
+ },
122
+ claim: (value)=>{
123
+ if (admits && !admits(value)) return;
124
+ seen.add(key(value));
125
+ }
126
+ };
127
+ }
128
+ };
129
+ }
130
+ function trackedByKey(options) {
131
+ const { by, ...rest } = options;
132
+ const keyer = toKeyer();
133
+ return tracked({
134
+ ...rest,
135
+ key: by ? (value)=>keyer(by(value)) : keyer
136
+ });
137
+ }
138
+ function withinCollection(collection, member) {
139
+ const fabricate = ()=>member.fabricate();
140
+ if (!(Claim in member)) return fabricate;
141
+ return ()=>{
142
+ try {
143
+ return fabricate();
144
+ } catch (error) {
145
+ throw toWithin(error, collection);
146
+ }
147
+ };
148
+ }
149
+ function toWithin(error, collection) {
150
+ if (error instanceof FabricatorError.UniqueExhaustedError) return new FabricatorError.UniqueExhaustedError(error.kind, error.capacity, collection);
151
+ if (error instanceof FabricatorError.UniqueRedrawsError) return new FabricatorError.UniqueRedrawsError(error.label, error.redraws, error.produced, collection);
152
+ return error;
153
+ }
154
+ function toLifetimeScope(strategy, exhaustion) {
155
+ if ("throw" === exhaustion) return strategy.open();
156
+ let scope = strategy.open();
157
+ return {
158
+ draw: ()=>{
159
+ try {
160
+ return scope.draw();
161
+ } catch (error) {
162
+ if (!isExhaustion(error)) throw error;
163
+ scope = strategy.open();
164
+ return scope.draw();
165
+ }
166
+ },
167
+ claim: (value)=>scope.claim(value)
168
+ };
169
+ }
170
+ function isExhaustion(error) {
171
+ return error instanceof FabricatorError.UniqueExhaustedError || error instanceof FabricatorError.UniqueRedrawsError;
172
+ }
173
+ export { defaultRedraws, exactBigintRange, exactRange, exactValues, toDistinctValues, toLifetimeScope, toRedraws, tracked, trackedByKey, withinCollection };
@@ -1,6 +1,7 @@
1
1
  export { Children, Kind, Meta, Produces } from "./Types.js";
2
2
  export { isArray, isPlainObject } from "./Utility/Core.js";
3
3
  export { isBuildable, isSchema } from "./Schema/Core.js";
4
+ export { toKeyer } from "./Unique/Key.js";
4
5
  export { plan, resolve } from "./Enumeration/Plan.js";
5
6
  export { defaultAlgorithm, encode, randomSalt, toRandomSource, toStream, toStreamFromTrace } from "./Random/index.js";
6
7
  export { normalCdf, normalInv, weighted } from "./Distribution/index.js";
@@ -1,5 +1,5 @@
1
- import { Adaptation } from "../Types";
2
- import type { Adaptations, AdaptationsOf, Adapter, Adapting, WithAdaptations } from "./Types";
1
+ import { Adaptation } from "../Types.ts";
2
+ import type { Adaptations, AdaptationsOf, Adapter, Adapting, WithAdaptations } from "./Types.ts";
3
3
  type OverrideSchemaAdaptation<$Schema extends object, $Map extends Adaptations> = Omit<$Schema, typeof Adaptation> & {
4
4
  readonly [Adaptation]?: WithAdaptations<AdaptationsOf<$Schema>, $Map>;
5
5
  };
@@ -1,4 +1,4 @@
1
- import type { Adaptation, Meta } from "../Types";
1
+ import type { Adaptation, Meta } from "../Types.ts";
2
2
  /**
3
3
  * One adapter's override for one schema, _as stored_ in `[Adaptation]` — the
4
4
  * loosest signature the mechanism needs. An adapter states its real return type
@@ -1,4 +1,4 @@
1
- import type { Distribution } from "./Distribution";
1
+ import type { Distribution } from "./Distribution/index.ts";
2
2
  /**
3
3
  * Canonical endpoint stored on `[Meta].whereby`. Call sites still accept a
4
4
  * scalar (inclusive) via {@link InputBound}; `.whereby()` runs {@link toBound} so
@@ -55,6 +55,21 @@ export declare function towardInterior(value: number, toward: number): number;
55
55
  * distribution's mass on the bound would otherwise loop.
56
56
  */
57
57
  export declare function constrainContinuous(next: () => number, min: Bound<number>, max: Bound<number>): () => number;
58
+ /**
59
+ * A `bigint` end that may be written as a `number`, so a call site needs no
60
+ * `BigInt(...)` where `5n` does not compile. A `number` must be a safe integer:
61
+ * beyond ±2^53 a literal has already rounded before it arrives, so the exact
62
+ * value is only expressible as a `bigint`.
63
+ */
64
+ export declare function toBigintBound(label: string, end: "min" | "max", input: InputBound<bigint | number>): Bound<bigint>;
65
+ /**
66
+ * A `Date` end that may be written as epoch milliseconds, as `initialize({
67
+ * clock })` accepts. A `number` must be one a `Date` holds unchanged — the test
68
+ * `Instance/Core.ts`'s `resolveInstant` applies — so a fractional, non-finite,
69
+ * or out-of-range number throws rather than being adjusted the way `Date`'s
70
+ * `TimeClip` would.
71
+ */
72
+ export declare function toDateBound(label: string, end: "min" | "max", input: InputBound<Date | number>): Bound<Date>;
58
73
  export declare function epochBound(bound: Bound<Date>): Bound<number>;
59
74
  /**
60
75
  * Call-site `length` for `string` and `array`: a bare number is an exact count,
@@ -82,3 +97,54 @@ export type Length = {
82
97
  * matching `date/Registry.ts`'s `toWhereby`, so stored meta stays minimal.
83
98
  */
84
99
  export declare function toLengthRange(length: InputLength, label: string): Length;
100
+ /**
101
+ * The ends an adapter states for a schema, as `.admits(...)` stores them. An
102
+ * absent end states no limit. Also the shape of a schema's fabricable range,
103
+ * where an absent end is one drawn against the kind's unbounded cap.
104
+ */
105
+ export type AdmittedEnds<$T> = {
106
+ min?: Bound<$T> | undefined;
107
+ max?: Bound<$T> | undefined;
108
+ };
109
+ /**
110
+ * What `.admits({ min, max })` accepts: an end as `whereby` takes it, or
111
+ * `-Infinity`/`Infinity` (bare, or as a `Bound`'s value) for no limit. An
112
+ * omitted end keeps what is admitted already.
113
+ */
114
+ export type InputAdmittedEnds<$T> = {
115
+ min?: InputBound<$T> | undefined;
116
+ max?: InputBound<$T> | undefined;
117
+ };
118
+ /**
119
+ * Whether every value `inner` admits at one end is one `outer` admits too. Each
120
+ * kind's notion of "admits" differs — a whole-number end excludes by `±1`, a
121
+ * continuous end by its endpoint alone — so each passes its own.
122
+ */
123
+ export type Within<$T> = (inner: Bound<$T>, outer: Bound<$T>, end: "min" | "max") => boolean;
124
+ /**
125
+ * Continuous ends: a farther value, or the same value with `inner` no less
126
+ * exclusive than `outer`.
127
+ */
128
+ export declare const continuousWithin: Within<number>;
129
+ /** Whole-number ends, compared as the inclusive integers they leave. */
130
+ export declare const discreteWithin: Within<number>;
131
+ export declare const bigintWithin: Within<bigint>;
132
+ /** `Date` holds whole milliseconds, so its ends compare as discrete epoch ms. */
133
+ export declare const dateWithin: Within<Date>;
134
+ /** A `number` end for `.admits`, where a finite value is required. */
135
+ export declare function toFiniteBound(label: string, end: "min" | "max", input: InputBound<number>): Bound<number>;
136
+ /**
137
+ * Resolve one `.admits(...)` group of ends — a length, a size, or a kind's own
138
+ * `min`/`max`. Each end the caller names replaces the current one, `±Infinity`
139
+ * dropping it; each end left out keeps `current`, which is what was admitted
140
+ * before, or the kind's default. Successive calls therefore merge per end.
141
+ *
142
+ * Admitting may only widen what is fabricated, or a fabricated value would fail
143
+ * the validation an adapter builds from these ends: each resolved end must
144
+ * admit every value of `fabricable` at that side, an absent fabricable end
145
+ * (drawn against the kind's unbounded cap) admitting only no limit. A
146
+ * `fabricable` of `undefined` skips the check — under `.as(produce)` there is
147
+ * nothing drawn to compare against. The result is complete and minimal: an end
148
+ * with no limit is left off.
149
+ */
150
+ export declare function toAdmittedEnds<$T, $Input>(label: string, path: string | undefined, current: AdmittedEnds<$T>, fabricable: AdmittedEnds<$T> | undefined, input: InputAdmittedEnds<$Input> | undefined, convert: (end: "min" | "max", input: InputBound<$Input>) => Bound<$T>, within: Within<$T>): AdmittedEnds<$T>;
@@ -1,4 +1,4 @@
1
- import type { Stream } from "../Random/Types";
1
+ import type { Stream } from "../Random/Types.ts";
2
2
  /**
3
3
  * How randomly generated values cluster within a `{ min, max }` range. Without
4
4
  * one, generation is uniform — every value in the range is equally likely.
@@ -132,6 +132,88 @@ export declare function sample<$T>(list: ReadonlyArray<$T>, stream: Stream): $T;
132
132
  * `items`, matching `sample`/`weighted`'s read-only convention.
133
133
  */
134
134
  export declare function shuffle<$T>(items: ReadonlyArray<$T>, stream: Stream): $T[];
135
+ /**
136
+ * A weighted draw that never returns the same entry twice — each pick leaves
137
+ * the pool. The first pick follows `entries`' weights exactly as `weighted()`
138
+ * would; every later one follows the weights of what remains, which is the same
139
+ * distribution conditioned on not repeating.
140
+ */
141
+ export type Pool<$Item> = {
142
+ /** How many entries are left to draw. */
143
+ readonly remaining: number;
144
+ /**
145
+ * Remove and return one entry. The caller checks `remaining` first: an empty
146
+ * pool has nothing to return.
147
+ */
148
+ draw: () => $Item;
149
+ /**
150
+ * Remove the first remaining entry `matches` accepts, without drawing — for
151
+ * an entry produced some other way. A no-op when none matches.
152
+ */
153
+ discard: (matches: (item: $Item) => boolean) => void;
154
+ };
155
+ /**
156
+ * A {@link Pool} over `entries`' drawable members (`isDrawable`; a zero weight
157
+ * stays out, as in `weighted()`). Linear in the pool's size per draw, which
158
+ * suits the small, caller-written member lists it is built from (`enum`'s
159
+ * members, `boolean`'s two outcomes).
160
+ *
161
+ * Equal weights stay equal as entries leave, so that case is fixed once: the
162
+ * pick is `discreteSampler`'s uniform index, one `stream.next()` per draw.
163
+ * Unequal weights take one `stream.next()` scaled over the remaining total,
164
+ * summed afresh each draw so removals never accumulate float drift. `splice`,
165
+ * not swap-remove, so the remaining order stays the caller's.
166
+ */
167
+ export declare function withoutReplacement<$Item>(entries: ReadonlyArray<readonly [number, $Item]>, stream: Stream): Pool<$Item>;
168
+ /**
169
+ * Every integer of an inclusive range, in a uniformly random order, one per
170
+ * `next()` — so no value repeats until all of them have been returned.
171
+ */
172
+ export type Permutation<$T extends number | bigint> = {
173
+ /** How many values are left before the range is used up. */
174
+ readonly remaining: $T;
175
+ /**
176
+ * The next value. The caller checks `remaining` first: a used-up range has
177
+ * nothing to return.
178
+ */
179
+ next: () => $T;
180
+ };
181
+ /**
182
+ * A sparse Fisher–Yates shuffle of `[min, max]`: step `i` swaps position `i`
183
+ * with a uniform position `j` in `[i, size)` and returns what was at `j`. Only
184
+ * positions a swap has touched live in `displaced`, so memory grows with the
185
+ * values drawn, never with the range — `[1, 2^53]` costs nothing up front.
186
+ * Position `i` is never read again after its step, so its entry is deleted.
187
+ *
188
+ * The index draw is `discreteSampler`'s, never an inlined `floor(next() * n)`
189
+ * (see AGENTS.md's "Traps in the length/size draw"). Precondition: `max - min +
190
+ * 1 <= Number.MAX_SAFE_INTEGER`, so every position is an exact integer.
191
+ */
192
+ export declare function permutation(range: Range, stream: Stream): Permutation<number>;
193
+ /**
194
+ * {@link permutation} over a bigint range, with {@link bigintSampler} drawing
195
+ * each step's position. No size precondition: bigint positions are exact at any
196
+ * width.
197
+ */
198
+ export declare function bigintPermutation(range: {
199
+ min: bigint;
200
+ max: bigint;
201
+ }, stream: Stream): Permutation<bigint>;
202
+ /**
203
+ * A uniform bigint draw over the inclusive `[min, max]`.
204
+ *
205
+ * Fills a buffer one byte at a time from the seeded stream — the top 8 bits of
206
+ * each draw — so bigint generation replays under a salt like every other
207
+ * primitive, rather than drawing unseedable bytes from
208
+ * `crypto.getRandomValues`. Then rejection: keep the low `bitWidth` bits and
209
+ * retry any candidate past the span, which avoids the modulo bias of `random %
210
+ * span`. The mask keeps every candidate within one bit of the span, so the loop
211
+ * expects fewer than two iterations.
212
+ */
213
+ export declare function bigintSampler(range: {
214
+ min: bigint;
215
+ max: bigint;
216
+ }, stream: Stream): () => bigint;
135
217
  /**
136
218
  * `weighted()`'s own inclusion rule: whether this entry stays in the draw
137
219
  * table. `0` is valid and disables the outcome; negative/`NaN` are rejected
@@ -1,6 +1,6 @@
1
- import type { Ancestry, Stack } from "../Instance/Types";
2
- import type { RandomSource } from "../Random/Types";
3
- import type { Enumerable, Limits } from "./Types";
1
+ import type { Ancestry, Stack } from "../Instance/Types.ts";
2
+ import type { RandomSource } from "../Random/Types.ts";
3
+ import type { Enumerable, Limits } from "./Types.ts";
4
4
  /**
5
5
  * Typed `combinatorial`/`coverage` boundary, closing over one instance's
6
6
  * `source` and its already-validated `limits` — same shape as
@@ -1,4 +1,4 @@
1
- import type { Axis, Orderer, Pin, Resolvable } from "./Types";
1
+ import type { Axis, Orderer, Pin, Resolvable } from "./Types.ts";
2
2
  type Planning = {
3
3
  strategy: "product";
4
4
  orderer?: Orderer | undefined;
@@ -1,7 +1,7 @@
1
- import type { Kind as SchemaKind } from "../Primitive";
2
- import type { AnySchema, Fabricated } from "../Schema/Types";
3
- import type { Children, Kind, Meta } from "../Types";
4
- import type { PlainObject } from "../Utility/Types";
1
+ import type { Kind as SchemaKind } from "../Primitive/index.ts";
2
+ import type { AnySchema, Fabricated } from "../Schema/Types.ts";
3
+ import type { Children, Kind, Meta } from "../Types.ts";
4
+ import type { PlainObject } from "../Utility/Types.ts";
5
5
  /**
6
6
  * How a composite with more than one child combines their widths. `"product"`
7
7
  * is the cartesian product — width is the product of every child's width;
@@ -73,7 +73,16 @@ export type Limits = {
73
73
  * Fabricator: `AnySchema` excludes `Fabricator<any>` (which carries no
74
74
  * `[Produces]`), so `Fabricated` can't silently degrade to `unknown`.
75
75
  */
76
- export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Iterable<Fabricated<$Schema>>;
76
+ export type Enumerable = <const $Schema extends AnySchema>(schema: $Schema) => Enumeration<Fabricated<$Schema>>;
77
+ /**
78
+ * What `combinatorial`/`coverage` return: the lazy instances, plus `size`, how
79
+ * many there are — known before any is produced. When compared against
80
+ * `capacity(schema)`, it says up front whether every instance can hold distinct
81
+ * unique values, or whether some leaf will start a fresh round.
82
+ */
83
+ export type Enumeration<$T> = Iterable<$T> & {
84
+ readonly size: bigint;
85
+ };
77
86
  export type Resolvable = {
78
87
  [Kind]: SchemaKind;
79
88
  [Meta]: PlainObject<any>;