@ghostry/fabricator 0.0.1

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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/esm/Adapter/Core.js +47 -0
  4. package/dist/esm/Adapter/Types.js +1 -0
  5. package/dist/esm/Bound.js +81 -0
  6. package/dist/esm/Distribution/index.js +200 -0
  7. package/dist/esm/Enumeration/Enumerate.js +103 -0
  8. package/dist/esm/Enumeration/Plan.js +286 -0
  9. package/dist/esm/Enumeration/Types.js +1 -0
  10. package/dist/esm/Error/index.js +201 -0
  11. package/dist/esm/Fabricator/Constructor.js +328 -0
  12. package/dist/esm/Fabricator/Types.js +1 -0
  13. package/dist/esm/Instance/Core.js +119 -0
  14. package/dist/esm/Instance/Types.js +1 -0
  15. package/dist/esm/Primitive/always/Fabricator.js +13 -0
  16. package/dist/esm/Primitive/always/Registry.js +11 -0
  17. package/dist/esm/Primitive/always/Schema.js +10 -0
  18. package/dist/esm/Primitive/always/Types.js +1 -0
  19. package/dist/esm/Primitive/always/index.js +5 -0
  20. package/dist/esm/Primitive/array/Fabricator.js +45 -0
  21. package/dist/esm/Primitive/array/Registry.js +26 -0
  22. package/dist/esm/Primitive/array/Schema.js +17 -0
  23. package/dist/esm/Primitive/array/Types.js +1 -0
  24. package/dist/esm/Primitive/array/index.js +5 -0
  25. package/dist/esm/Primitive/bigint/Fabricator.js +54 -0
  26. package/dist/esm/Primitive/bigint/Registry.js +31 -0
  27. package/dist/esm/Primitive/bigint/Schema.js +17 -0
  28. package/dist/esm/Primitive/bigint/Types.js +1 -0
  29. package/dist/esm/Primitive/bigint/index.js +5 -0
  30. package/dist/esm/Primitive/boolean/Fabricator.js +44 -0
  31. package/dist/esm/Primitive/boolean/Outcomes.js +5 -0
  32. package/dist/esm/Primitive/boolean/Registry.js +11 -0
  33. package/dist/esm/Primitive/boolean/Schema.js +33 -0
  34. package/dist/esm/Primitive/boolean/Types.js +1 -0
  35. package/dist/esm/Primitive/boolean/index.js +6 -0
  36. package/dist/esm/Primitive/choice/Fabricator.js +37 -0
  37. package/dist/esm/Primitive/choice/Registry.js +38 -0
  38. package/dist/esm/Primitive/choice/Schema.js +17 -0
  39. package/dist/esm/Primitive/choice/Types.js +1 -0
  40. package/dist/esm/Primitive/choice/index.js +5 -0
  41. package/dist/esm/Primitive/date/Fabricator.js +86 -0
  42. package/dist/esm/Primitive/date/Registry.js +61 -0
  43. package/dist/esm/Primitive/date/Schema.js +17 -0
  44. package/dist/esm/Primitive/date/Types.js +1 -0
  45. package/dist/esm/Primitive/date/index.js +5 -0
  46. package/dist/esm/Primitive/enum/Fabricator.js +33 -0
  47. package/dist/esm/Primitive/enum/Registry.js +33 -0
  48. package/dist/esm/Primitive/enum/Schema.js +17 -0
  49. package/dist/esm/Primitive/enum/Types.js +1 -0
  50. package/dist/esm/Primitive/enum/index.js +5 -0
  51. package/dist/esm/Primitive/index.js +24 -0
  52. package/dist/esm/Primitive/namespace.js +21 -0
  53. package/dist/esm/Primitive/null/Fabricator.js +14 -0
  54. package/dist/esm/Primitive/null/Registry.js +8 -0
  55. package/dist/esm/Primitive/null/Schema.js +10 -0
  56. package/dist/esm/Primitive/null/Types.js +1 -0
  57. package/dist/esm/Primitive/null/index.js +5 -0
  58. package/dist/esm/Primitive/nullable/Fabricator.js +58 -0
  59. package/dist/esm/Primitive/nullable/Outcomes.js +5 -0
  60. package/dist/esm/Primitive/nullable/Registry.js +13 -0
  61. package/dist/esm/Primitive/nullable/Schema.js +36 -0
  62. package/dist/esm/Primitive/nullable/Types.js +1 -0
  63. package/dist/esm/Primitive/nullable/index.js +6 -0
  64. package/dist/esm/Primitive/nullish/Fabricator.js +64 -0
  65. package/dist/esm/Primitive/nullish/Outcomes.js +6 -0
  66. package/dist/esm/Primitive/nullish/Registry.js +13 -0
  67. package/dist/esm/Primitive/nullish/Schema.js +36 -0
  68. package/dist/esm/Primitive/nullish/Types.js +1 -0
  69. package/dist/esm/Primitive/nullish/index.js +6 -0
  70. package/dist/esm/Primitive/number/Fabricator.js +73 -0
  71. package/dist/esm/Primitive/number/Registry.js +59 -0
  72. package/dist/esm/Primitive/number/Schema.js +18 -0
  73. package/dist/esm/Primitive/number/Types.js +1 -0
  74. package/dist/esm/Primitive/number/defaults.js +21 -0
  75. package/dist/esm/Primitive/number/index.js +5 -0
  76. package/dist/esm/Primitive/object/Fabricator.js +77 -0
  77. package/dist/esm/Primitive/object/Registry.js +146 -0
  78. package/dist/esm/Primitive/object/Schema.js +18 -0
  79. package/dist/esm/Primitive/object/Types.js +1 -0
  80. package/dist/esm/Primitive/object/compute/Fabricator.js +24 -0
  81. package/dist/esm/Primitive/object/compute/Registry.js +15 -0
  82. package/dist/esm/Primitive/object/compute/Schema.js +13 -0
  83. package/dist/esm/Primitive/object/compute/Types.js +1 -0
  84. package/dist/esm/Primitive/object/compute/index.js +5 -0
  85. package/dist/esm/Primitive/object/index.js +9 -0
  86. package/dist/esm/Primitive/object/omittable/Fabricator.js +57 -0
  87. package/dist/esm/Primitive/object/omittable/Outcomes.js +5 -0
  88. package/dist/esm/Primitive/object/omittable/Registry.js +13 -0
  89. package/dist/esm/Primitive/object/omittable/Schema.js +36 -0
  90. package/dist/esm/Primitive/object/omittable/Types.js +1 -0
  91. package/dist/esm/Primitive/object/omittable/index.js +6 -0
  92. package/dist/esm/Primitive/object/optional/Fabricator.js +55 -0
  93. package/dist/esm/Primitive/object/optional/Outcomes.js +6 -0
  94. package/dist/esm/Primitive/object/optional/Registry.js +13 -0
  95. package/dist/esm/Primitive/object/optional/Schema.js +36 -0
  96. package/dist/esm/Primitive/object/optional/Types.js +1 -0
  97. package/dist/esm/Primitive/object/optional/index.js +6 -0
  98. package/dist/esm/Primitive/opaque/Fabricator.js +19 -0
  99. package/dist/esm/Primitive/opaque/Registry.js +11 -0
  100. package/dist/esm/Primitive/opaque/Schema.js +10 -0
  101. package/dist/esm/Primitive/opaque/Types.js +1 -0
  102. package/dist/esm/Primitive/opaque/index.js +5 -0
  103. package/dist/esm/Primitive/record/Fabricator.js +55 -0
  104. package/dist/esm/Primitive/record/Registry.js +26 -0
  105. package/dist/esm/Primitive/record/Schema.js +17 -0
  106. package/dist/esm/Primitive/record/Types.js +1 -0
  107. package/dist/esm/Primitive/record/index.js +5 -0
  108. package/dist/esm/Primitive/recursive/Fabricator.js +33 -0
  109. package/dist/esm/Primitive/recursive/Registry.js +20 -0
  110. package/dist/esm/Primitive/recursive/Schema.js +10 -0
  111. package/dist/esm/Primitive/recursive/Terminate.js +236 -0
  112. package/dist/esm/Primitive/recursive/Types.js +1 -0
  113. package/dist/esm/Primitive/recursive/index.js +7 -0
  114. package/dist/esm/Primitive/recursive/self/Fabricator.js +15 -0
  115. package/dist/esm/Primitive/recursive/self/Registry.js +9 -0
  116. package/dist/esm/Primitive/recursive/self/Schema.js +10 -0
  117. package/dist/esm/Primitive/recursive/self/Types.js +1 -0
  118. package/dist/esm/Primitive/recursive/self/index.js +5 -0
  119. package/dist/esm/Primitive/string/Constants.js +73 -0
  120. package/dist/esm/Primitive/string/Fabricator.js +109 -0
  121. package/dist/esm/Primitive/string/Registry.js +25 -0
  122. package/dist/esm/Primitive/string/Schema.js +18 -0
  123. package/dist/esm/Primitive/string/Types.js +1 -0
  124. package/dist/esm/Primitive/string/index.js +6 -0
  125. package/dist/esm/Primitive/symbol/Fabricator.js +33 -0
  126. package/dist/esm/Primitive/symbol/Registry.js +17 -0
  127. package/dist/esm/Primitive/symbol/Schema.js +17 -0
  128. package/dist/esm/Primitive/symbol/Types.js +1 -0
  129. package/dist/esm/Primitive/symbol/index.js +5 -0
  130. package/dist/esm/Primitive/tuple/Fabricator.js +33 -0
  131. package/dist/esm/Primitive/tuple/Registry.js +13 -0
  132. package/dist/esm/Primitive/tuple/Schema.js +17 -0
  133. package/dist/esm/Primitive/tuple/Types.js +1 -0
  134. package/dist/esm/Primitive/tuple/index.js +5 -0
  135. package/dist/esm/Primitive/undefinable/Fabricator.js +58 -0
  136. package/dist/esm/Primitive/undefinable/Outcomes.js +5 -0
  137. package/dist/esm/Primitive/undefinable/Registry.js +13 -0
  138. package/dist/esm/Primitive/undefinable/Schema.js +36 -0
  139. package/dist/esm/Primitive/undefinable/Types.js +1 -0
  140. package/dist/esm/Primitive/undefinable/index.js +6 -0
  141. package/dist/esm/Primitive/undefined/Fabricator.js +16 -0
  142. package/dist/esm/Primitive/undefined/Registry.js +8 -0
  143. package/dist/esm/Primitive/undefined/Schema.js +10 -0
  144. package/dist/esm/Primitive/undefined/Types.js +1 -0
  145. package/dist/esm/Primitive/undefined/index.js +5 -0
  146. package/dist/esm/Random/CallSite.js +56 -0
  147. package/dist/esm/Random/Generator/sfc32.js +16 -0
  148. package/dist/esm/Random/Types.js +1 -0
  149. package/dist/esm/Random/index.js +151 -0
  150. package/dist/esm/Schema/Core.js +68 -0
  151. package/dist/esm/Schema/Registry.js +17 -0
  152. package/dist/esm/Schema/Types.js +1 -0
  153. package/dist/esm/Types.js +11 -0
  154. package/dist/esm/Utility/Core.js +36 -0
  155. package/dist/esm/Utility/DeepMerge.js +18 -0
  156. package/dist/esm/Utility/Digest.js +28 -0
  157. package/dist/esm/Utility/ShallowMerge.js +13 -0
  158. package/dist/esm/Utility/Types.js +1 -0
  159. package/dist/esm/index.js +11 -0
  160. package/dist/esm/internal.js +5 -0
  161. package/dist/types/Adapter/Core.d.ts +64 -0
  162. package/dist/types/Adapter/Types.d.ts +145 -0
  163. package/dist/types/Bound.d.ts +68 -0
  164. package/dist/types/Distribution/index.d.ts +157 -0
  165. package/dist/types/Enumeration/Enumerate.d.ts +35 -0
  166. package/dist/types/Enumeration/Plan.d.ts +44 -0
  167. package/dist/types/Enumeration/Types.d.ts +86 -0
  168. package/dist/types/Error/index.d.ts +541 -0
  169. package/dist/types/Fabricator/Constructor.d.ts +43 -0
  170. package/dist/types/Fabricator/Types.d.ts +150 -0
  171. package/dist/types/Instance/Core.d.ts +98 -0
  172. package/dist/types/Instance/Types.d.ts +167 -0
  173. package/dist/types/Primitive/always/Fabricator.d.ts +19 -0
  174. package/dist/types/Primitive/always/Registry.d.ts +3 -0
  175. package/dist/types/Primitive/always/Schema.d.ts +19 -0
  176. package/dist/types/Primitive/always/Types.d.ts +23 -0
  177. package/dist/types/Primitive/always/index.d.ts +5 -0
  178. package/dist/types/Primitive/array/Fabricator.d.ts +22 -0
  179. package/dist/types/Primitive/array/Registry.d.ts +18 -0
  180. package/dist/types/Primitive/array/Schema.d.ts +23 -0
  181. package/dist/types/Primitive/array/Types.d.ts +44 -0
  182. package/dist/types/Primitive/array/index.d.ts +5 -0
  183. package/dist/types/Primitive/bigint/Fabricator.d.ts +19 -0
  184. package/dist/types/Primitive/bigint/Registry.d.ts +19 -0
  185. package/dist/types/Primitive/bigint/Schema.d.ts +27 -0
  186. package/dist/types/Primitive/bigint/Types.d.ts +33 -0
  187. package/dist/types/Primitive/bigint/index.d.ts +5 -0
  188. package/dist/types/Primitive/boolean/Fabricator.d.ts +19 -0
  189. package/dist/types/Primitive/boolean/Outcomes.d.ts +12 -0
  190. package/dist/types/Primitive/boolean/Registry.d.ts +14 -0
  191. package/dist/types/Primitive/boolean/Schema.d.ts +28 -0
  192. package/dist/types/Primitive/boolean/Types.d.ts +26 -0
  193. package/dist/types/Primitive/boolean/index.d.ts +6 -0
  194. package/dist/types/Primitive/choice/Fabricator.d.ts +32 -0
  195. package/dist/types/Primitive/choice/Registry.d.ts +38 -0
  196. package/dist/types/Primitive/choice/Schema.d.ts +24 -0
  197. package/dist/types/Primitive/choice/Types.d.ts +35 -0
  198. package/dist/types/Primitive/choice/index.d.ts +5 -0
  199. package/dist/types/Primitive/date/Fabricator.d.ts +19 -0
  200. package/dist/types/Primitive/date/Registry.d.ts +82 -0
  201. package/dist/types/Primitive/date/Schema.d.ts +28 -0
  202. package/dist/types/Primitive/date/Types.d.ts +34 -0
  203. package/dist/types/Primitive/date/index.d.ts +5 -0
  204. package/dist/types/Primitive/enum/Fabricator.d.ts +19 -0
  205. package/dist/types/Primitive/enum/Registry.d.ts +39 -0
  206. package/dist/types/Primitive/enum/Schema.d.ts +23 -0
  207. package/dist/types/Primitive/enum/Types.d.ts +44 -0
  208. package/dist/types/Primitive/enum/index.d.ts +5 -0
  209. package/dist/types/Primitive/index.d.ts +28 -0
  210. package/dist/types/Primitive/namespace.d.ts +38 -0
  211. package/dist/types/Primitive/null/Fabricator.d.ts +19 -0
  212. package/dist/types/Primitive/null/Registry.d.ts +3 -0
  213. package/dist/types/Primitive/null/Schema.d.ts +16 -0
  214. package/dist/types/Primitive/null/Types.d.ts +15 -0
  215. package/dist/types/Primitive/null/index.d.ts +5 -0
  216. package/dist/types/Primitive/nullable/Fabricator.d.ts +31 -0
  217. package/dist/types/Primitive/nullable/Outcomes.d.ts +9 -0
  218. package/dist/types/Primitive/nullable/Registry.d.ts +3 -0
  219. package/dist/types/Primitive/nullable/Schema.d.ts +36 -0
  220. package/dist/types/Primitive/nullable/Types.d.ts +48 -0
  221. package/dist/types/Primitive/nullable/index.d.ts +6 -0
  222. package/dist/types/Primitive/nullish/Fabricator.d.ts +36 -0
  223. package/dist/types/Primitive/nullish/Outcomes.d.ts +9 -0
  224. package/dist/types/Primitive/nullish/Registry.d.ts +3 -0
  225. package/dist/types/Primitive/nullish/Schema.d.ts +36 -0
  226. package/dist/types/Primitive/nullish/Types.d.ts +58 -0
  227. package/dist/types/Primitive/nullish/index.d.ts +6 -0
  228. package/dist/types/Primitive/number/Fabricator.d.ts +19 -0
  229. package/dist/types/Primitive/number/Registry.d.ts +52 -0
  230. package/dist/types/Primitive/number/Schema.d.ts +32 -0
  231. package/dist/types/Primitive/number/Types.d.ts +56 -0
  232. package/dist/types/Primitive/number/defaults.d.ts +18 -0
  233. package/dist/types/Primitive/number/index.d.ts +5 -0
  234. package/dist/types/Primitive/object/Fabricator.d.ts +56 -0
  235. package/dist/types/Primitive/object/Registry.d.ts +23 -0
  236. package/dist/types/Primitive/object/Schema.d.ts +41 -0
  237. package/dist/types/Primitive/object/Types.d.ts +85 -0
  238. package/dist/types/Primitive/object/compute/Fabricator.d.ts +31 -0
  239. package/dist/types/Primitive/object/compute/Registry.d.ts +4 -0
  240. package/dist/types/Primitive/object/compute/Schema.d.ts +21 -0
  241. package/dist/types/Primitive/object/compute/Types.d.ts +56 -0
  242. package/dist/types/Primitive/object/compute/index.d.ts +5 -0
  243. package/dist/types/Primitive/object/index.d.ts +8 -0
  244. package/dist/types/Primitive/object/omittable/Fabricator.d.ts +37 -0
  245. package/dist/types/Primitive/object/omittable/Outcomes.d.ts +9 -0
  246. package/dist/types/Primitive/object/omittable/Registry.d.ts +3 -0
  247. package/dist/types/Primitive/object/omittable/Schema.d.ts +32 -0
  248. package/dist/types/Primitive/object/omittable/Types.d.ts +57 -0
  249. package/dist/types/Primitive/object/omittable/index.d.ts +6 -0
  250. package/dist/types/Primitive/object/optional/Fabricator.d.ts +45 -0
  251. package/dist/types/Primitive/object/optional/Outcomes.d.ts +9 -0
  252. package/dist/types/Primitive/object/optional/Registry.d.ts +3 -0
  253. package/dist/types/Primitive/object/optional/Schema.d.ts +32 -0
  254. package/dist/types/Primitive/object/optional/Types.d.ts +72 -0
  255. package/dist/types/Primitive/object/optional/index.d.ts +6 -0
  256. package/dist/types/Primitive/opaque/Fabricator.d.ts +19 -0
  257. package/dist/types/Primitive/opaque/Registry.d.ts +12 -0
  258. package/dist/types/Primitive/opaque/Schema.d.ts +22 -0
  259. package/dist/types/Primitive/opaque/Types.d.ts +18 -0
  260. package/dist/types/Primitive/opaque/index.d.ts +5 -0
  261. package/dist/types/Primitive/record/Fabricator.d.ts +25 -0
  262. package/dist/types/Primitive/record/Registry.d.ts +17 -0
  263. package/dist/types/Primitive/record/Schema.d.ts +27 -0
  264. package/dist/types/Primitive/record/Types.d.ts +85 -0
  265. package/dist/types/Primitive/record/index.d.ts +5 -0
  266. package/dist/types/Primitive/recursive/Fabricator.d.ts +47 -0
  267. package/dist/types/Primitive/recursive/Registry.d.ts +22 -0
  268. package/dist/types/Primitive/recursive/Schema.d.ts +21 -0
  269. package/dist/types/Primitive/recursive/Terminate.d.ts +20 -0
  270. package/dist/types/Primitive/recursive/Types.d.ts +82 -0
  271. package/dist/types/Primitive/recursive/index.d.ts +6 -0
  272. package/dist/types/Primitive/recursive/self/Fabricator.d.ts +29 -0
  273. package/dist/types/Primitive/recursive/self/Registry.d.ts +7 -0
  274. package/dist/types/Primitive/recursive/self/Schema.d.ts +20 -0
  275. package/dist/types/Primitive/recursive/self/Types.d.ts +28 -0
  276. package/dist/types/Primitive/recursive/self/index.d.ts +5 -0
  277. package/dist/types/Primitive/string/Constants.d.ts +58 -0
  278. package/dist/types/Primitive/string/Fabricator.d.ts +24 -0
  279. package/dist/types/Primitive/string/Registry.d.ts +44 -0
  280. package/dist/types/Primitive/string/Schema.d.ts +65 -0
  281. package/dist/types/Primitive/string/Types.d.ts +77 -0
  282. package/dist/types/Primitive/string/index.d.ts +6 -0
  283. package/dist/types/Primitive/symbol/Fabricator.d.ts +24 -0
  284. package/dist/types/Primitive/symbol/Registry.d.ts +16 -0
  285. package/dist/types/Primitive/symbol/Schema.d.ts +24 -0
  286. package/dist/types/Primitive/symbol/Types.d.ts +19 -0
  287. package/dist/types/Primitive/symbol/index.d.ts +5 -0
  288. package/dist/types/Primitive/tuple/Fabricator.d.ts +37 -0
  289. package/dist/types/Primitive/tuple/Registry.d.ts +3 -0
  290. package/dist/types/Primitive/tuple/Schema.d.ts +24 -0
  291. package/dist/types/Primitive/tuple/Types.d.ts +53 -0
  292. package/dist/types/Primitive/tuple/index.d.ts +5 -0
  293. package/dist/types/Primitive/undefinable/Fabricator.d.ts +31 -0
  294. package/dist/types/Primitive/undefinable/Outcomes.d.ts +9 -0
  295. package/dist/types/Primitive/undefinable/Registry.d.ts +3 -0
  296. package/dist/types/Primitive/undefinable/Schema.d.ts +36 -0
  297. package/dist/types/Primitive/undefinable/Types.d.ts +48 -0
  298. package/dist/types/Primitive/undefinable/index.d.ts +6 -0
  299. package/dist/types/Primitive/undefined/Fabricator.d.ts +19 -0
  300. package/dist/types/Primitive/undefined/Registry.d.ts +3 -0
  301. package/dist/types/Primitive/undefined/Schema.d.ts +16 -0
  302. package/dist/types/Primitive/undefined/Types.d.ts +15 -0
  303. package/dist/types/Primitive/undefined/index.d.ts +5 -0
  304. package/dist/types/Random/CallSite.d.ts +59 -0
  305. package/dist/types/Random/Generator/sfc32.d.ts +10 -0
  306. package/dist/types/Random/Types.d.ts +384 -0
  307. package/dist/types/Random/index.d.ts +107 -0
  308. package/dist/types/Schema/Core.d.ts +44 -0
  309. package/dist/types/Schema/Registry.d.ts +20 -0
  310. package/dist/types/Schema/Types.d.ts +70 -0
  311. package/dist/types/Types.d.ts +78 -0
  312. package/dist/types/Utility/Core.d.ts +35 -0
  313. package/dist/types/Utility/DeepMerge.d.ts +14 -0
  314. package/dist/types/Utility/Digest.d.ts +9 -0
  315. package/dist/types/Utility/ShallowMerge.d.ts +6 -0
  316. package/dist/types/Utility/Types.d.ts +4 -0
  317. package/dist/types/index.d.ts +186 -0
  318. package/dist/types/internal.d.ts +64 -0
  319. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Rebsch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # fabricator
2
+
3
+ Fabricate typed data from composable schemas.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @ghostry/fabricator
9
+ ```
10
+
11
+ Also available via `bun add @ghostry/fabricator` or `bunx jsr add @ghostry/fabricator`.
12
+
13
+ ## Example
14
+
15
+ ```ts
16
+ import { initialize } from "@ghostry/fabricator";
17
+
18
+ const { T, Fabricator } = initialize({ seed: "1234" });
19
+
20
+ const ProductSchema = T.object({
21
+ name: T.string.whereby({ length: { min: 1, max: 25 } }),
22
+ price: T.number.whereby({ min: 1, max: 500 }),
23
+ inStock: T.boolean,
24
+ createdAt: T.date.past,
25
+ tags: T.array(T.string.whereby({ length: { max: 15 } })).whereby({
26
+ length: { max: 5 },
27
+ }),
28
+ });
29
+
30
+ const Product = new Fabricator(ProductSchema);
31
+
32
+ const item = Product.fabricate();
33
+ // { name: "...", price: ..., inStock: ..., createdAt: ..., tags: [...] }
34
+
35
+ /**
36
+ * Fabricate with everything random except a few fields you care about.
37
+ */
38
+ const widget = Product.fabricate({ name: "Widget", inStock: true });
39
+ ```
40
+
41
+ `seed: "1234"` is an optional mixer; `clock` (the wall-clock instant of this call, by default) is the run's entropy. Pass the same seed and clock to replay. See the [docs site](https://ghostry-dev.github.io/fabricator/) for the full guide: the mental model behind Schemas and Fabricators, composing and overriding schemas, custom types, distributions, and the [TypeBox adapter](https://www.npmjs.com/package/@ghostry/fabricator-adapter-typebox-v0).
42
+
43
+ ## Similar
44
+
45
+ https://www.npmjs.com/package/@anatine/zod-mock
46
+
47
+ https://www.npmjs.com/package/@travelperksl/fabricator
@@ -0,0 +1,47 @@
1
+ import { Adaptation, Meta } from "../Types.js";
2
+ function withAdaptations(schema, adapter, produce) {
3
+ return patched(schema, {
4
+ [adapter.key]: toSchemaAdaptation(produce)
5
+ });
6
+ }
7
+ function mergeAdaptations(prior, adapter, produce) {
8
+ return patched({
9
+ [Adaptation]: prior
10
+ }, {
11
+ [adapter.key]: toSchemaAdaptation(produce)
12
+ })[Adaptation];
13
+ }
14
+ function toSchemaAdaptation(produce) {
15
+ return (schema)=>produce({
16
+ schema,
17
+ meta: schema[Meta]
18
+ });
19
+ }
20
+ function patched(schema, patch) {
21
+ const prior = schema[Adaptation];
22
+ const merged = {
23
+ ...prior
24
+ };
25
+ for (const [key, adaptation] of Object.entries(patch))if (void 0 === adaptation) delete merged[key];
26
+ else merged[key] = Core_layer(key, adaptation, merged[key]);
27
+ if (0 === Object.keys(merged).length) {
28
+ const { [Adaptation]: _, ...rest } = schema;
29
+ return rest;
30
+ }
31
+ return {
32
+ ...schema,
33
+ [Adaptation]: merged
34
+ };
35
+ }
36
+ function Core_layer(key, adaptation, prior) {
37
+ return (schema)=>adaptation(patched(schema, {
38
+ [key]: prior
39
+ }));
40
+ }
41
+ function drive(adapter, schema, context) {
42
+ var _schema_Adaptation;
43
+ const adaptation = null == (_schema_Adaptation = schema[Adaptation]) ? void 0 : _schema_Adaptation[adapter.key];
44
+ if (adaptation) return adaptation(schema);
45
+ return adapter.convert(schema, (child, childContext)=>drive(adapter, child, childContext), context);
46
+ }
47
+ export { drive, mergeAdaptations, withAdaptations };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,81 @@
1
+ import { FabricatorError } from "./Error/index.js";
2
+ import { isPlainObject } from "./Utility/Core.js";
3
+ function toBound(input) {
4
+ if (isCanonicalBound(input)) return {
5
+ value: input.value,
6
+ exclusive: input.exclusive
7
+ };
8
+ return {
9
+ value: input,
10
+ exclusive: false
11
+ };
12
+ }
13
+ function isCanonicalBound(input) {
14
+ return isPlainObject(input) && "value" in input && "boolean" == typeof input.exclusive;
15
+ }
16
+ function effectiveDiscrete(min, max) {
17
+ return {
18
+ min: min.exclusive ? min.value + 1 : min.value,
19
+ max: max.exclusive ? max.value - 1 : max.value
20
+ };
21
+ }
22
+ function effectiveDiscreteBigint(min, max) {
23
+ return {
24
+ min: min.exclusive ? min.value + BigInt(1) : min.value,
25
+ max: max.exclusive ? max.value - BigInt(1) : max.value
26
+ };
27
+ }
28
+ function assertNonemptyDiscrete(label, min, max) {
29
+ const range = effectiveDiscrete(min, max);
30
+ if (range.min > range.max) throw new FabricatorError.EmptyRangeError(label, min, max);
31
+ }
32
+ function assertNonemptyDiscreteBigint(label, min, max) {
33
+ const range = effectiveDiscreteBigint(min, max);
34
+ if (range.min > range.max) throw new FabricatorError.EmptyRangeError(label, min, max);
35
+ }
36
+ function assertNonemptyContinuous(label, min, max) {
37
+ if (isEmptyContinuous(min, max)) throw new FabricatorError.EmptyRangeError(label, min, max);
38
+ }
39
+ function isEmptyContinuous(min, max) {
40
+ if (min.value > max.value) return true;
41
+ if (min.value === max.value) return min.exclusive || max.exclusive;
42
+ if (min.exclusive && max.exclusive) return towardInterior(min.value, max.value) >= max.value;
43
+ return false;
44
+ }
45
+ function towardInterior(value, toward) {
46
+ if (value === toward) return value;
47
+ const direction = toward > value ? 1 : -1;
48
+ if (0 === value) return 5e-324 * direction;
49
+ const scaled = value + direction * Number.EPSILON * Math.abs(value);
50
+ if (scaled !== value) return scaled;
51
+ return value + 5e-324 * direction;
52
+ }
53
+ function constrainContinuous(next, min, max) {
54
+ return ()=>{
55
+ let value = next();
56
+ if (min.exclusive && value === min.value) value = towardInterior(value, max.value);
57
+ if (max.exclusive && value === max.value) value = towardInterior(value, min.value);
58
+ return value;
59
+ };
60
+ }
61
+ function epochBound(bound) {
62
+ return {
63
+ value: bound.value.getTime(),
64
+ exclusive: bound.exclusive
65
+ };
66
+ }
67
+ function toLengthRange(length, label) {
68
+ const range = "number" == typeof length ? {
69
+ min: toBound(length),
70
+ max: toBound(length)
71
+ } : {
72
+ min: void 0 === length.min ? {
73
+ value: 0,
74
+ exclusive: false
75
+ } : toBound(length.min),
76
+ max: toBound(length.max)
77
+ };
78
+ assertNonemptyDiscrete(label, range.min, range.max);
79
+ return range;
80
+ }
81
+ export { assertNonemptyContinuous, assertNonemptyDiscrete, assertNonemptyDiscreteBigint, constrainContinuous, effectiveDiscrete, effectiveDiscreteBigint, epochBound, toBound, toLengthRange, towardInterior };
@@ -0,0 +1,200 @@
1
+ import { FabricatorError } from "../Error/index.js";
2
+ (function(Distribution) {
3
+ Distribution.uniform = ()=>({
4
+ kind: "uniform"
5
+ });
6
+ Distribution.normal = (params)=>({
7
+ kind: "normal",
8
+ mean: null == params ? void 0 : params.mean,
9
+ spread: null == params ? void 0 : params.spread
10
+ });
11
+ Distribution.skew = (exponent)=>({
12
+ kind: "skew",
13
+ exponent
14
+ });
15
+ Distribution.triangular = (params)=>({
16
+ kind: "triangular",
17
+ mode: null == params ? void 0 : params.mode
18
+ });
19
+ Distribution.logarithmic = ()=>({
20
+ kind: "logarithmic"
21
+ });
22
+ Distribution.multi = (components)=>({
23
+ kind: "multi",
24
+ components
25
+ });
26
+ Distribution.custom = (shape)=>({
27
+ kind: "custom",
28
+ shape
29
+ });
30
+ })(Distribution_Distribution || (Distribution_Distribution = {}));
31
+ function at(u, min, max) {
32
+ return (1 - u) * min + u * max;
33
+ }
34
+ function unitPosition(x, min, max) {
35
+ if (x === min) return 0;
36
+ if (x === max) return 1;
37
+ const span = max - min;
38
+ if (Number.isFinite(span)) return 0 === span ? 0 : (x - min) / span;
39
+ const left = x - min;
40
+ if (0 === left) return 0;
41
+ const ratio = (max - x) / left;
42
+ if (!Number.isFinite(ratio)) return 0;
43
+ return 1 / (1 + ratio);
44
+ }
45
+ function sampler(distribution, range, stream) {
46
+ const { min, max } = range;
47
+ const span = max - min;
48
+ switch(distribution.kind){
49
+ case "uniform":
50
+ return ()=>at(stream.next(), min, max);
51
+ case "skew":
52
+ {
53
+ const exponent = distribution.exponent;
54
+ return ()=>at(stream.next() ** exponent, min, max);
55
+ }
56
+ case "triangular":
57
+ {
58
+ var _distribution_mode;
59
+ const mode = null != (_distribution_mode = distribution.mode) ? _distribution_mode : at(0.5, min, max);
60
+ const split = unitPosition(mode, min, max);
61
+ return ()=>{
62
+ const u = stream.next();
63
+ const t = u < split ? Math.sqrt(u * split) : 1 - Math.sqrt((1 - u) * (1 - split));
64
+ return at(t, min, max);
65
+ };
66
+ }
67
+ case "normal":
68
+ {
69
+ var _distribution_mean, _distribution_spread;
70
+ const mean = null != (_distribution_mean = distribution.mean) ? _distribution_mean : at(0.5, min, max);
71
+ const spread = null != (_distribution_spread = distribution.spread) ? _distribution_spread : Number.isFinite(span) && 0 !== span ? span / 6 : Math.max(Math.abs(min), Math.abs(max)) / 6 || 1;
72
+ const lower = normalCdf((min - mean) / spread);
73
+ const upper = normalCdf((max - mean) / spread);
74
+ return ()=>{
75
+ const p = lower + stream.next() * (upper - lower);
76
+ const value = mean + spread * normalInv(p);
77
+ return clamp(value, min, max);
78
+ };
79
+ }
80
+ case "logarithmic":
81
+ {
82
+ if (min <= 0) throw new FabricatorError.InvalidDistributionBoundError("logarithmic", min, max);
83
+ const ratio = max / min;
84
+ return ()=>min * ratio ** stream.next();
85
+ }
86
+ case "multi":
87
+ {
88
+ const pick = weighted(distribution.components.map((component)=>[
89
+ component.weight,
90
+ sampler(component.distribution, range, stream)
91
+ ]), stream, "Distribution.multi");
92
+ return ()=>{
93
+ const distribution = pick();
94
+ const value = distribution();
95
+ return value;
96
+ };
97
+ }
98
+ case "custom":
99
+ {
100
+ const shape = distribution.shape;
101
+ return ()=>at(clamp(shape(stream.next()), 0, 1), min, max);
102
+ }
103
+ }
104
+ }
105
+ function clamp(value, min, max) {
106
+ if (value < min) return min;
107
+ if (value > max) return max;
108
+ return value;
109
+ }
110
+ function normalCdf(x) {
111
+ return 0.5 * (1 + erf(x / Math.SQRT2));
112
+ }
113
+ function erf(x) {
114
+ const sign = x < 0 ? -1 : 1;
115
+ const z = Math.abs(x);
116
+ const t = 1 / (1 + 0.3275911 * z);
117
+ const poly = ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t;
118
+ return sign * (1 - poly * Math.exp(-z * z));
119
+ }
120
+ function normalInv(p) {
121
+ if (p <= 0) return -1 / 0;
122
+ if (p >= 1) return 1 / 0;
123
+ const low = 0.02425;
124
+ const high = 1 - low;
125
+ if (p < low) {
126
+ const q = Math.sqrt(-2 * Math.log(p));
127
+ return (((((-0.007784894002430293 * q - 3.223964580411365e-1) * q - 2.400758277161838) * q - 2.549732539343734) * q + 4.374664141464968) * q + 2.938163982698783) / ((((7.784695709041462e-3 * q + 3.224671290700398e-1) * q + 2.445134137142996) * q + 3.754408661907416) * q + 1);
128
+ }
129
+ if (p <= high) {
130
+ const q = p - 0.5;
131
+ const r = q * q;
132
+ return (((((-39.69683028665376 * r + 2.209460984245205e2) * r - 2.759285104469687e2) * r + 1.38357751867269e2) * r - 3.066479806614716e1) * r + 2.506628277459239) * q / (((((-54.47609879822406 * r + 1.615858368580409e2) * r - 1.556989798598866e2) * r + 6.680131188771972e1) * r - 1.328068155288572e1) * r + 1);
133
+ }
134
+ const q = Math.sqrt(-2 * Math.log(1 - p));
135
+ return -(((((-0.007784894002430293 * q - 3.223964580411365e-1) * q - 2.400758277161838) * q - 2.549732539343734) * q + 4.374664141464968) * q + 2.938163982698783) / ((((7.784695709041462e-3 * q + 3.224671290700398e-1) * q + 2.445134137142996) * q + 3.754408661907416) * q + 1);
136
+ }
137
+ function sample(list, stream) {
138
+ const index = Math.floor(stream.next() * list.length);
139
+ const item = list[index];
140
+ return item;
141
+ }
142
+ function shuffle(items, stream) {
143
+ const shuffled = [
144
+ ...items
145
+ ];
146
+ for(let i = 1; i < shuffled.length; i++){
147
+ const j = Math.floor(stream.next() * (i + 1));
148
+ const swap = shuffled[i];
149
+ shuffled[i] = shuffled[j];
150
+ shuffled[j] = swap;
151
+ }
152
+ return shuffled;
153
+ }
154
+ function isDrawable(weight) {
155
+ return weight > 0;
156
+ }
157
+ function isValidWeight(weight) {
158
+ return weight >= 0 && Number.isFinite(weight);
159
+ }
160
+ function drawableOutcomes(outcomes, weights) {
161
+ return outcomes.filter((outcome)=>{
162
+ var _ref;
163
+ return isDrawable(null != (_ref = null == weights ? void 0 : weights[outcome]) ? _ref : 1);
164
+ });
165
+ }
166
+ function assertDrawableWeights(label, noun, items) {
167
+ for(let i = 0; i < items.length; i++){
168
+ const weight = items[i][0];
169
+ if (!isValidWeight(weight)) throw new FabricatorError.InvalidWeightError(label, weight, {
170
+ kind: "index",
171
+ index: i,
172
+ noun
173
+ });
174
+ }
175
+ if (!items.some(([weight])=>isDrawable(weight))) throw new FabricatorError.NoDrawableOutcomesError(label, noun);
176
+ }
177
+ function assertDrawableKeyedWeights(label, outcomes, weights) {
178
+ for (const [key, weight] of Object.entries(weights))if (void 0 !== weight) {
179
+ if (!isValidWeight(weight)) throw new FabricatorError.InvalidWeightError(label, weight, {
180
+ kind: "name",
181
+ name: key
182
+ });
183
+ }
184
+ if (0 === drawableOutcomes(outcomes, weights).length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
185
+ }
186
+ function weighted(weights, stream, label) {
187
+ let sum = 0;
188
+ const weightings = weights.filter(([weight])=>isDrawable(weight)).map(([weight, item])=>[
189
+ sum += weight,
190
+ item
191
+ ]);
192
+ if (0 === weightings.length) throw new FabricatorError.NoDrawableOutcomesError(label, "outcome");
193
+ return ()=>{
194
+ const x = stream.next() * sum;
195
+ const chosen = weightings.find(([weight])=>x < weight);
196
+ return chosen[1];
197
+ };
198
+ }
199
+ var Distribution_Distribution;
200
+ export { Distribution_Distribution as Distribution, assertDrawableKeyedWeights, assertDrawableWeights, drawableOutcomes, isDrawable, isValidWeight, sample, sampler, shuffle, weighted };
@@ -0,0 +1,103 @@
1
+ import { shuffle } from "../Distribution/index.js";
2
+ import { FabricatorError } from "../Error/index.js";
3
+ import { Constructor } from "../Fabricator/Constructor.js";
4
+ import { toStreamFromTrace } from "../Random/index.js";
5
+ import { plan, resolve } from "./Plan.js";
6
+ function enumerables(source, limits, stack) {
7
+ const Fabricator = Constructor(source, stack);
8
+ function effectiveSource() {
9
+ var _ref;
10
+ var _stack_current;
11
+ return null != (_ref = null == (_stack_current = stack.current()) ? void 0 : _stack_current.source) ? _ref : source;
12
+ }
13
+ function iterable(rebuild) {
14
+ return {
15
+ [Symbol.iterator] () {
16
+ const { built, axis } = rebuild();
17
+ const width = Number(axis.width);
18
+ let index = 0;
19
+ return {
20
+ next: ()=>{
21
+ if (index >= width) return {
22
+ done: true,
23
+ value: void 0
24
+ };
25
+ const value = resolve(built, axis.at(BigInt(index)));
26
+ index++;
27
+ return {
28
+ done: false,
29
+ value
30
+ };
31
+ }
32
+ };
33
+ }
34
+ };
35
+ }
36
+ function combinatorial(schema) {
37
+ const combinatorialSeed = [
38
+ ...effectiveSource().seed,
39
+ "combinatorial"
40
+ ];
41
+ const probe = plan(new Fabricator(schema, {
42
+ seed: combinatorialSeed
43
+ }), {
44
+ strategy: "product"
45
+ });
46
+ if (probe.width > BigInt(limits.combinatorial)) throw new FabricatorError.CombinatorialLimitExceededError(probe.width, limits.combinatorial);
47
+ return iterable(()=>{
48
+ const built = new Fabricator(schema, {
49
+ seed: combinatorialSeed
50
+ });
51
+ return {
52
+ built,
53
+ axis: plan(built, {
54
+ strategy: "product"
55
+ })
56
+ };
57
+ });
58
+ }
59
+ function coverage(schema) {
60
+ const base = effectiveSource();
61
+ const coverageSeed = [
62
+ ...base.seed,
63
+ "coverage"
64
+ ];
65
+ const orderSeed = [
66
+ ...base.seed,
67
+ "coverage",
68
+ "order"
69
+ ];
70
+ return iterable(()=>{
71
+ const built = new Fabricator(schema, {
72
+ seed: coverageSeed
73
+ });
74
+ return {
75
+ built,
76
+ axis: plan(built, {
77
+ strategy: "cycle",
78
+ orderer: orderer(base, orderSeed)
79
+ })
80
+ };
81
+ });
82
+ }
83
+ return {
84
+ combinatorial,
85
+ coverage
86
+ };
87
+ }
88
+ function orderer(source, seed) {
89
+ const forked = source.fork(seed);
90
+ const root = forked.toRoot("unattributed");
91
+ const stream = toStreamFromTrace(forked.algorithm, {
92
+ ...root,
93
+ path: [],
94
+ kind: "order"
95
+ });
96
+ return (width)=>{
97
+ const identity = Array.from({
98
+ length: Number(width)
99
+ }, (_, i)=>BigInt(i));
100
+ return shuffle(identity, stream);
101
+ };
102
+ }
103
+ export { enumerables };