zeed 1.3.0 → 1.4.0

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 (575) hide show
  1. package/AGENTS.md +50 -211
  2. package/README.md +16 -0
  3. package/dist/_experiments/bitcask.cjs +243 -1
  4. package/dist/_experiments/bitcask.cjs.map +1 -1
  5. package/dist/_experiments/bitcask.mjs +230 -1
  6. package/dist/_experiments/bitcask.mjs.map +1 -1
  7. package/dist/bin-BAoS4qtm.mjs +593 -0
  8. package/dist/{bin-SPdenYkw.mjs.map → bin-BAoS4qtm.mjs.map} +1 -1
  9. package/dist/bin-Ddaz2lxM.cjs +862 -0
  10. package/dist/{bin-Ce3i6ABn.cjs.map → bin-Ddaz2lxM.cjs.map} +1 -1
  11. package/dist/browser/base64.cjs +14 -1
  12. package/dist/browser/base64.cjs.map +1 -1
  13. package/dist/browser/base64.mjs +12 -1
  14. package/dist/browser/base64.mjs.map +1 -1
  15. package/dist/browser/gravatar.cjs +186 -1
  16. package/dist/browser/gravatar.cjs.map +1 -1
  17. package/dist/browser/gravatar.mjs +184 -1
  18. package/dist/browser/gravatar.mjs.map +1 -1
  19. package/dist/browser/index.cjs +14 -1
  20. package/dist/browser/index.mjs +8 -1
  21. package/dist/browser/localstorage.cjs +46 -1
  22. package/dist/browser/localstorage.cjs.map +1 -1
  23. package/dist/browser/localstorage.mjs +45 -1
  24. package/dist/browser/localstorage.mjs.map +1 -1
  25. package/dist/browser/log/index.cjs +8 -1
  26. package/dist/browser/log/index.mjs +5 -1
  27. package/dist/browser/log/log-browser-factory.cjs +65 -1
  28. package/dist/browser/log/log-browser-factory.cjs.map +1 -1
  29. package/dist/browser/log/log-browser-factory.mjs +64 -1
  30. package/dist/browser/log/log-browser-factory.mjs.map +1 -1
  31. package/dist/browser/log/log-browser.cjs +72 -1
  32. package/dist/browser/log/log-browser.cjs.map +1 -1
  33. package/dist/browser/log/log-browser.mjs +71 -1
  34. package/dist/browser/log/log-browser.mjs.map +1 -1
  35. package/dist/browser/log/log-colors.cjs +11 -1
  36. package/dist/browser/log/log-colors.cjs.map +1 -1
  37. package/dist/browser/log/log-colors.mjs +9 -1
  38. package/dist/browser/log/log-colors.mjs.map +1 -1
  39. package/dist/browser/log/log-context-browser.cjs +25 -1
  40. package/dist/browser/log/log-context-browser.cjs.map +1 -1
  41. package/dist/browser/log/log-context-browser.mjs +23 -1
  42. package/dist/browser/log/log-context-browser.mjs.map +1 -1
  43. package/dist/chunk-DQk6qfdC.mjs +18 -0
  44. package/dist/chunk-uaV2rQ02.cjs +53 -0
  45. package/dist/common/assert.cjs +22 -1
  46. package/dist/common/assert.cjs.map +1 -1
  47. package/dist/common/assert.mjs +19 -1
  48. package/dist/common/assert.mjs.map +1 -1
  49. package/dist/common/bin/index.cjs +106 -1
  50. package/dist/common/bin/index.cjs.map +1 -1
  51. package/dist/common/bin/index.mjs +98 -1
  52. package/dist/common/bin/index.mjs.map +1 -1
  53. package/dist/common/bin/lib0/binary.cjs +146 -1
  54. package/dist/common/bin/lib0/binary.cjs.map +1 -1
  55. package/dist/common/bin/lib0/binary.mjs +80 -1
  56. package/dist/common/bin/lib0/binary.mjs.map +1 -1
  57. package/dist/common/bin/lib0/buffer.cjs +42 -1
  58. package/dist/common/bin/lib0/buffer.cjs.map +1 -1
  59. package/dist/common/bin/lib0/buffer.mjs +38 -1
  60. package/dist/common/bin/lib0/buffer.mjs.map +1 -1
  61. package/dist/common/bin/lib0/create.cjs +24 -1
  62. package/dist/common/bin/lib0/create.cjs.map +1 -1
  63. package/dist/common/bin/lib0/create.mjs +21 -1
  64. package/dist/common/bin/lib0/create.mjs.map +1 -1
  65. package/dist/common/bin/lib0/decoding.cjs +325 -1
  66. package/dist/common/bin/lib0/decoding.cjs.map +1 -1
  67. package/dist/common/bin/lib0/decoding.mjs +298 -1
  68. package/dist/common/bin/lib0/decoding.mjs.map +1 -1
  69. package/dist/common/bin/lib0/encoding.cjs +404 -1
  70. package/dist/common/bin/lib0/encoding.cjs.map +1 -1
  71. package/dist/common/bin/lib0/encoding.mjs +377 -1
  72. package/dist/common/bin/lib0/encoding.mjs.map +1 -1
  73. package/dist/common/bin/lib0/string.cjs +81 -1
  74. package/dist/common/bin/lib0/string.cjs.map +1 -1
  75. package/dist/common/bin/lib0/string.mjs +71 -1
  76. package/dist/common/bin/lib0/string.mjs.map +1 -1
  77. package/dist/common/crypto/aes-sealed.cjs +34 -1
  78. package/dist/common/crypto/aes-sealed.cjs.map +1 -1
  79. package/dist/common/crypto/aes-sealed.mjs +32 -1
  80. package/dist/common/crypto/aes-sealed.mjs.map +1 -1
  81. package/dist/common/crypto/crypto.cjs +91 -1
  82. package/dist/common/crypto/crypto.cjs.map +1 -1
  83. package/dist/common/crypto/crypto.mjs +80 -1
  84. package/dist/common/crypto/crypto.mjs.map +1 -1
  85. package/dist/common/crypto/index.cjs +23 -1
  86. package/dist/common/crypto/index.mjs +5 -1
  87. package/dist/common/crypto/xaes.cjs +128 -1
  88. package/dist/common/crypto/xaes.cjs.map +1 -1
  89. package/dist/common/crypto/xaes.mjs +123 -1
  90. package/dist/common/crypto/xaes.mjs.map +1 -1
  91. package/dist/common/csv.cjs +49 -4
  92. package/dist/common/csv.cjs.map +1 -1
  93. package/dist/common/csv.mjs +46 -4
  94. package/dist/common/csv.mjs.map +1 -1
  95. package/dist/common/data/array.cjs +299 -1
  96. package/dist/common/data/array.cjs.map +1 -1
  97. package/dist/common/data/array.mjs +274 -1
  98. package/dist/common/data/array.mjs.map +1 -1
  99. package/dist/common/data/basex-secure.cjs +30 -1
  100. package/dist/common/data/basex-secure.mjs +3 -1
  101. package/dist/common/data/basex.cjs +163 -1
  102. package/dist/common/data/basex.cjs.map +1 -1
  103. package/dist/common/data/basex.mjs +152 -1
  104. package/dist/common/data/basex.mjs.map +1 -1
  105. package/dist/common/data/bin-types.mjs +1 -1
  106. package/dist/common/data/bin.cjs +21 -1
  107. package/dist/common/data/bin.mjs +3 -1
  108. package/dist/common/data/camelcase.cjs +27 -1
  109. package/dist/common/data/camelcase.cjs.map +1 -1
  110. package/dist/common/data/camelcase.mjs +22 -1
  111. package/dist/common/data/camelcase.mjs.map +1 -1
  112. package/dist/common/data/convert.cjs +104 -1
  113. package/dist/common/data/convert.cjs.map +1 -1
  114. package/dist/common/data/convert.mjs +88 -1
  115. package/dist/common/data/convert.mjs.map +1 -1
  116. package/dist/common/data/datauri.cjs +32 -1
  117. package/dist/common/data/datauri.cjs.map +1 -1
  118. package/dist/common/data/datauri.mjs +27 -1
  119. package/dist/common/data/datauri.mjs.map +1 -1
  120. package/dist/common/data/day-legacy.cjs +148 -1
  121. package/dist/common/data/day-legacy.cjs.map +1 -1
  122. package/dist/common/data/day-legacy.mjs +143 -1
  123. package/dist/common/data/day-legacy.mjs.map +1 -1
  124. package/dist/common/data/day.cjs +335 -1
  125. package/dist/common/data/day.cjs.map +1 -1
  126. package/dist/common/data/day.mjs +305 -1
  127. package/dist/common/data/day.mjs.map +1 -1
  128. package/dist/common/data/decimal.cjs +28 -1
  129. package/dist/common/data/decimal.cjs.map +1 -1
  130. package/dist/common/data/decimal.mjs +23 -1
  131. package/dist/common/data/decimal.mjs.map +1 -1
  132. package/dist/common/data/deep.cjs +57 -1
  133. package/dist/common/data/deep.cjs.map +1 -1
  134. package/dist/common/data/deep.mjs +54 -1
  135. package/dist/common/data/deep.mjs.map +1 -1
  136. package/dist/common/data/diff.cjs +62 -1
  137. package/dist/common/data/diff.cjs.map +1 -1
  138. package/dist/common/data/diff.mjs +60 -1
  139. package/dist/common/data/diff.mjs.map +1 -1
  140. package/dist/common/data/distributed.cjs +24 -1
  141. package/dist/common/data/distributed.cjs.map +1 -1
  142. package/dist/common/data/distributed.mjs +22 -1
  143. package/dist/common/data/distributed.mjs.map +1 -1
  144. package/dist/common/data/format.cjs +63 -1
  145. package/dist/common/data/format.cjs.map +1 -1
  146. package/dist/common/data/format.mjs +59 -1
  147. package/dist/common/data/format.mjs.map +1 -1
  148. package/dist/common/data/html.cjs +13 -1
  149. package/dist/common/data/html.cjs.map +1 -1
  150. package/dist/common/data/html.mjs +10 -1
  151. package/dist/common/data/html.mjs.map +1 -1
  152. package/dist/common/data/index.cjs +296 -1
  153. package/dist/common/data/index.mjs +37 -1
  154. package/dist/common/data/is.cjs +106 -1
  155. package/dist/common/data/is.cjs.map +1 -1
  156. package/dist/common/data/is.mjs +85 -1
  157. package/dist/common/data/is.mjs.map +1 -1
  158. package/dist/common/data/json.cjs +70 -1
  159. package/dist/common/data/json.cjs.map +1 -1
  160. package/dist/common/data/json.mjs +65 -1
  161. package/dist/common/data/json.mjs.map +1 -1
  162. package/dist/common/data/list.cjs +32 -1
  163. package/dist/common/data/list.cjs.map +1 -1
  164. package/dist/common/data/list.mjs +27 -1
  165. package/dist/common/data/list.mjs.map +1 -1
  166. package/dist/common/data/lru.mjs +1 -1
  167. package/dist/common/data/math.cjs +79 -1
  168. package/dist/common/data/math.cjs.map +1 -1
  169. package/dist/common/data/math.mjs +65 -1
  170. package/dist/common/data/math.mjs.map +1 -1
  171. package/dist/common/data/message.cjs +30 -1
  172. package/dist/common/data/message.cjs.map +1 -1
  173. package/dist/common/data/message.mjs +28 -1
  174. package/dist/common/data/message.mjs.map +1 -1
  175. package/dist/common/data/object-changes.cjs +66 -1
  176. package/dist/common/data/object-changes.cjs.map +1 -1
  177. package/dist/common/data/object-changes.mjs +63 -1
  178. package/dist/common/data/object-changes.mjs.map +1 -1
  179. package/dist/common/data/object.cjs +112 -1
  180. package/dist/common/data/object.cjs.map +1 -1
  181. package/dist/common/data/object.mjs +104 -1
  182. package/dist/common/data/object.mjs.map +1 -1
  183. package/dist/common/data/orderby.cjs +42 -1
  184. package/dist/common/data/orderby.cjs.map +1 -1
  185. package/dist/common/data/orderby.mjs +37 -1
  186. package/dist/common/data/orderby.mjs.map +1 -1
  187. package/dist/common/data/path.cjs +26 -1
  188. package/dist/common/data/path.cjs.map +1 -1
  189. package/dist/common/data/path.mjs +25 -1
  190. package/dist/common/data/path.mjs.map +1 -1
  191. package/dist/common/data/regexp.cjs +12 -1
  192. package/dist/common/data/regexp.cjs.map +1 -1
  193. package/dist/common/data/regexp.mjs +10 -1
  194. package/dist/common/data/regexp.mjs.map +1 -1
  195. package/dist/common/data/rounding.cjs +107 -1
  196. package/dist/common/data/rounding.cjs.map +1 -1
  197. package/dist/common/data/rounding.mjs +95 -1
  198. package/dist/common/data/rounding.mjs.map +1 -1
  199. package/dist/common/data/signal.cjs +39 -1
  200. package/dist/common/data/signal.cjs.map +1 -1
  201. package/dist/common/data/signal.mjs +38 -1
  202. package/dist/common/data/signal.mjs.map +1 -1
  203. package/dist/common/data/sortable.cjs +35 -1
  204. package/dist/common/data/sortable.cjs.map +1 -1
  205. package/dist/common/data/sortable.mjs +31 -1
  206. package/dist/common/data/sortable.mjs.map +1 -1
  207. package/dist/common/data/sorted.cjs +54 -1
  208. package/dist/common/data/sorted.cjs.map +1 -1
  209. package/dist/common/data/sorted.mjs +53 -1
  210. package/dist/common/data/sorted.mjs.map +1 -1
  211. package/dist/common/data/string-deburr.cjs +240 -1
  212. package/dist/common/data/string-deburr.cjs.map +1 -1
  213. package/dist/common/data/string-deburr.mjs +238 -1
  214. package/dist/common/data/string-deburr.mjs.map +1 -1
  215. package/dist/common/data/string-hash-fnv.cjs +69 -1
  216. package/dist/common/data/string-hash-fnv.cjs.map +1 -1
  217. package/dist/common/data/string-hash-fnv.mjs +67 -1
  218. package/dist/common/data/string-hash-fnv.mjs.map +1 -1
  219. package/dist/common/data/string-hash-pool.cjs +28 -1
  220. package/dist/common/data/string-hash-pool.cjs.map +1 -1
  221. package/dist/common/data/string-hash-pool.mjs +27 -1
  222. package/dist/common/data/string-hash-pool.mjs.map +1 -1
  223. package/dist/common/data/url.cjs +98 -2
  224. package/dist/common/data/url.cjs.map +1 -1
  225. package/dist/common/data/url.mjs +91 -2
  226. package/dist/common/data/url.mjs.map +1 -1
  227. package/dist/common/data/utils.cjs +118 -1
  228. package/dist/common/data/utils.cjs.map +1 -1
  229. package/dist/common/data/utils.mjs +107 -1
  230. package/dist/common/data/utils.mjs.map +1 -1
  231. package/dist/common/data/wordlist.cjs +531 -1
  232. package/dist/common/data/wordlist.cjs.map +1 -1
  233. package/dist/common/data/wordlist.mjs +529 -1
  234. package/dist/common/data/wordlist.mjs.map +1 -1
  235. package/dist/common/data/xrx.cjs +96 -1
  236. package/dist/common/data/xrx.cjs.map +1 -1
  237. package/dist/common/data/xrx.mjs +92 -1
  238. package/dist/common/data/xrx.mjs.map +1 -1
  239. package/dist/common/dispose-defer.cjs +133 -1
  240. package/dist/common/dispose-defer.cjs.map +1 -1
  241. package/dist/common/dispose-defer.mjs +130 -1
  242. package/dist/common/dispose-defer.mjs.map +1 -1
  243. package/dist/common/dispose-types.mjs +1 -1
  244. package/dist/common/dispose-utils.cjs +113 -1
  245. package/dist/common/dispose-utils.cjs.map +1 -1
  246. package/dist/common/dispose-utils.mjs +106 -1
  247. package/dist/common/dispose-utils.mjs.map +1 -1
  248. package/dist/common/exec/index.cjs +24 -1
  249. package/dist/common/exec/index.d.cts +1 -1
  250. package/dist/common/exec/index.d.mts +1 -1
  251. package/dist/common/exec/index.mjs +8 -1
  252. package/dist/common/exec/mutex.cjs +44 -1
  253. package/dist/common/exec/mutex.cjs.map +1 -1
  254. package/dist/common/exec/mutex.mjs +42 -1
  255. package/dist/common/exec/mutex.mjs.map +1 -1
  256. package/dist/common/exec/pool.cjs +181 -1
  257. package/dist/common/exec/pool.cjs.map +1 -1
  258. package/dist/common/exec/pool.d.cts +1 -1
  259. package/dist/common/exec/pool.d.mts +1 -1
  260. package/dist/common/exec/pool.mjs +180 -1
  261. package/dist/common/exec/pool.mjs.map +1 -1
  262. package/dist/common/exec/progress.cjs +149 -1
  263. package/dist/common/exec/progress.cjs.map +1 -1
  264. package/dist/common/exec/progress.d.cts +1 -1
  265. package/dist/common/exec/progress.d.mts +1 -1
  266. package/dist/common/exec/progress.mjs +148 -1
  267. package/dist/common/exec/progress.mjs.map +1 -1
  268. package/dist/common/exec/promise.cjs +113 -1
  269. package/dist/common/exec/promise.cjs.map +1 -1
  270. package/dist/common/exec/promise.mjs +103 -1
  271. package/dist/common/exec/promise.mjs.map +1 -1
  272. package/dist/common/exec/queue.cjs +125 -1
  273. package/dist/common/exec/queue.cjs.map +1 -1
  274. package/dist/common/exec/queue.d.cts +1 -1
  275. package/dist/common/exec/queue.d.mts +1 -1
  276. package/dist/common/exec/queue.mjs +124 -1
  277. package/dist/common/exec/queue.mjs.map +1 -1
  278. package/dist/common/exec/throttle-debounce.cjs +114 -1
  279. package/dist/common/exec/throttle-debounce.cjs.map +1 -1
  280. package/dist/common/exec/throttle-debounce.mjs +112 -1
  281. package/dist/common/exec/throttle-debounce.mjs.map +1 -1
  282. package/dist/common/global.cjs +22 -1
  283. package/dist/common/global.cjs.map +1 -1
  284. package/dist/common/global.mjs +19 -1
  285. package/dist/common/global.mjs.map +1 -1
  286. package/dist/common/index.cjs +559 -1
  287. package/dist/common/index.d.cts +1 -1
  288. package/dist/common/index.d.mts +1 -1
  289. package/dist/common/index.mjs +89 -1
  290. package/dist/common/localhost.cjs +16 -1
  291. package/dist/common/localhost.cjs.map +1 -1
  292. package/dist/common/localhost.mjs +14 -1
  293. package/dist/common/localhost.mjs.map +1 -1
  294. package/dist/common/log/index.cjs +34 -1
  295. package/dist/common/log/index.mjs +11 -1
  296. package/dist/common/log/log-base.cjs +40 -1
  297. package/dist/common/log/log-base.cjs.map +1 -1
  298. package/dist/common/log/log-base.mjs +31 -1
  299. package/dist/common/log/log-base.mjs.map +1 -1
  300. package/dist/common/log/log-colors.cjs +92 -1
  301. package/dist/common/log/log-colors.cjs.map +1 -1
  302. package/dist/common/log/log-colors.mjs +90 -1
  303. package/dist/common/log/log-colors.mjs.map +1 -1
  304. package/dist/common/log/log-config.cjs +15 -1
  305. package/dist/common/log/log-config.cjs.map +1 -1
  306. package/dist/common/log/log-config.mjs +14 -1
  307. package/dist/common/log/log-config.mjs.map +1 -1
  308. package/dist/common/log/log-console-capture.cjs +33 -1
  309. package/dist/common/log/log-console-capture.cjs.map +1 -1
  310. package/dist/common/log/log-console-capture.mjs +32 -1
  311. package/dist/common/log/log-console-capture.mjs.map +1 -1
  312. package/dist/common/log/log-console-original.cjs +27 -1
  313. package/dist/common/log/log-console-original.cjs.map +1 -1
  314. package/dist/common/log/log-console-original.mjs +26 -1
  315. package/dist/common/log/log-console-original.mjs.map +1 -1
  316. package/dist/common/log/log-console.cjs +39 -1
  317. package/dist/common/log/log-console.cjs.map +1 -1
  318. package/dist/common/log/log-console.mjs +38 -1
  319. package/dist/common/log/log-console.mjs.map +1 -1
  320. package/dist/common/log/log-context.cjs +109 -1
  321. package/dist/common/log/log-context.cjs.map +1 -1
  322. package/dist/common/log/log-context.mjs +108 -1
  323. package/dist/common/log/log-context.mjs.map +1 -1
  324. package/dist/common/log/log-filter.cjs +80 -1
  325. package/dist/common/log/log-filter.cjs.map +1 -1
  326. package/dist/common/log/log-filter.mjs +75 -1
  327. package/dist/common/log/log-filter.mjs.map +1 -1
  328. package/dist/common/log/log-memory.cjs +45 -1
  329. package/dist/common/log/log-memory.cjs.map +1 -1
  330. package/dist/common/log/log-memory.mjs +43 -1
  331. package/dist/common/log/log-memory.mjs.map +1 -1
  332. package/dist/common/log/log-noop.cjs +17 -1
  333. package/dist/common/log/log-noop.cjs.map +1 -1
  334. package/dist/common/log/log-noop.mjs +15 -1
  335. package/dist/common/log/log-noop.mjs.map +1 -1
  336. package/dist/common/log/log.cjs +46 -1
  337. package/dist/common/log/log.cjs.map +1 -1
  338. package/dist/common/log/log.mjs +43 -1
  339. package/dist/common/log/log.mjs.map +1 -1
  340. package/dist/common/msg/channel-debug.cjs +17 -1
  341. package/dist/common/msg/channel-debug.cjs.map +1 -1
  342. package/dist/common/msg/channel-debug.d.cts +1 -1
  343. package/dist/common/msg/channel-debug.d.mts +1 -1
  344. package/dist/common/msg/channel-debug.mjs +16 -1
  345. package/dist/common/msg/channel-debug.mjs.map +1 -1
  346. package/dist/common/msg/channel-local.cjs +28 -1
  347. package/dist/common/msg/channel-local.cjs.map +1 -1
  348. package/dist/common/msg/channel-local.d.cts +1 -1
  349. package/dist/common/msg/channel-local.d.mts +1 -1
  350. package/dist/common/msg/channel-local.mjs +26 -1
  351. package/dist/common/msg/channel-local.mjs.map +1 -1
  352. package/dist/common/msg/channel-resilient.cjs +63 -1
  353. package/dist/common/msg/channel-resilient.cjs.map +1 -1
  354. package/dist/common/msg/channel-resilient.d.cts +1 -1
  355. package/dist/common/msg/channel-resilient.d.mts +1 -1
  356. package/dist/common/msg/channel-resilient.mjs +62 -1
  357. package/dist/common/msg/channel-resilient.mjs.map +1 -1
  358. package/dist/common/msg/channel-wkwebview.cjs +35 -1
  359. package/dist/common/msg/channel-wkwebview.cjs.map +1 -1
  360. package/dist/common/msg/channel-wkwebview.d.cts +2 -1
  361. package/dist/common/msg/channel-wkwebview.d.mts +2 -1
  362. package/dist/common/msg/channel-wkwebview.mjs +34 -1
  363. package/dist/common/msg/channel-wkwebview.mjs.map +1 -1
  364. package/dist/common/msg/channel.cjs +23 -1
  365. package/dist/common/msg/channel.cjs.map +1 -1
  366. package/dist/common/msg/channel.d.cts +1 -1
  367. package/dist/common/msg/channel.d.mts +1 -1
  368. package/dist/common/msg/channel.mjs +22 -1
  369. package/dist/common/msg/channel.mjs.map +1 -1
  370. package/dist/common/msg/emitter.cjs +141 -1
  371. package/dist/common/msg/emitter.cjs.map +1 -1
  372. package/dist/common/msg/emitter.d.cts +1 -1
  373. package/dist/common/msg/emitter.d.mts +1 -1
  374. package/dist/common/msg/emitter.mjs +139 -1
  375. package/dist/common/msg/emitter.mjs.map +1 -1
  376. package/dist/common/msg/encoder.cjs +38 -1
  377. package/dist/common/msg/encoder.cjs.map +1 -1
  378. package/dist/common/msg/encoder.mjs +35 -1
  379. package/dist/common/msg/encoder.mjs.map +1 -1
  380. package/dist/common/msg/index.cjs +28 -1
  381. package/dist/common/msg/index.d.cts +1 -1
  382. package/dist/common/msg/index.d.mts +1 -1
  383. package/dist/common/msg/index.mjs +11 -1
  384. package/dist/common/msg/messages.cjs +135 -1
  385. package/dist/common/msg/messages.cjs.map +1 -1
  386. package/dist/common/msg/messages.d.cts +1 -1
  387. package/dist/common/msg/messages.d.mts +1 -1
  388. package/dist/common/msg/messages.mjs +133 -1
  389. package/dist/common/msg/messages.mjs.map +1 -1
  390. package/dist/common/msg/pipe.mjs +1 -1
  391. package/dist/common/msg/pubsub.cjs +78 -1
  392. package/dist/common/msg/pubsub.cjs.map +1 -1
  393. package/dist/common/msg/pubsub.d.cts +1 -1
  394. package/dist/common/msg/pubsub.d.mts +1 -1
  395. package/dist/common/msg/pubsub.mjs +76 -1
  396. package/dist/common/msg/pubsub.mjs.map +1 -1
  397. package/dist/common/msg/rpc.cjs +142 -1
  398. package/dist/common/msg/rpc.cjs.map +1 -1
  399. package/dist/common/msg/rpc.mjs +139 -1
  400. package/dist/common/msg/rpc.mjs.map +1 -1
  401. package/dist/common/network.cjs +129 -1
  402. package/dist/common/network.cjs.map +1 -1
  403. package/dist/common/network.mjs +122 -1
  404. package/dist/common/network.mjs.map +1 -1
  405. package/dist/common/platform.cjs +92 -1
  406. package/dist/common/platform.cjs.map +1 -1
  407. package/dist/common/platform.mjs +84 -1
  408. package/dist/common/platform.mjs.map +1 -1
  409. package/dist/common/schema/_sandbox/sandbox-inherit.mjs +1 -1
  410. package/dist/common/schema/_sandbox/sandbox.mjs +1 -1
  411. package/dist/common/schema/_sandbox/sandbox.xspec.mjs +1 -1
  412. package/dist/common/schema/export-json-schema.cjs +54 -1
  413. package/dist/common/schema/export-json-schema.cjs.map +1 -1
  414. package/dist/common/schema/export-json-schema.mjs +52 -1
  415. package/dist/common/schema/export-json-schema.mjs.map +1 -1
  416. package/dist/common/schema/export-swift.cjs +30 -2
  417. package/dist/common/schema/export-swift.cjs.map +1 -1
  418. package/dist/common/schema/export-swift.mjs +29 -2
  419. package/dist/common/schema/export-swift.mjs.map +1 -1
  420. package/dist/common/schema/export-typescript.cjs +20 -2
  421. package/dist/common/schema/export-typescript.cjs.map +1 -1
  422. package/dist/common/schema/export-typescript.mjs +19 -2
  423. package/dist/common/schema/export-typescript.mjs.map +1 -1
  424. package/dist/common/schema/index.cjs +55 -1
  425. package/dist/common/schema/index.mjs +12 -1
  426. package/dist/common/schema/parse-args.cjs +62 -2
  427. package/dist/common/schema/parse-args.cjs.map +1 -1
  428. package/dist/common/schema/parse-args.mjs +60 -2
  429. package/dist/common/schema/parse-args.mjs.map +1 -1
  430. package/dist/common/schema/parse-env.cjs +48 -3
  431. package/dist/common/schema/parse-env.cjs.map +1 -1
  432. package/dist/common/schema/parse-env.mjs +46 -3
  433. package/dist/common/schema/parse-env.mjs.map +1 -1
  434. package/dist/common/schema/parse-object.cjs +122 -1
  435. package/dist/common/schema/parse-object.cjs.map +1 -1
  436. package/dist/common/schema/parse-object.mjs +119 -1
  437. package/dist/common/schema/parse-object.mjs.map +1 -1
  438. package/dist/common/schema/schema-standard.mjs +1 -1
  439. package/dist/common/schema/schema.cjs +423 -1
  440. package/dist/common/schema/schema.cjs.map +1 -1
  441. package/dist/common/schema/schema.mjs +404 -1
  442. package/dist/common/schema/schema.mjs.map +1 -1
  443. package/dist/common/schema/serialize.cjs +109 -1
  444. package/dist/common/schema/serialize.cjs.map +1 -1
  445. package/dist/common/schema/serialize.mjs +107 -1
  446. package/dist/common/schema/serialize.mjs.map +1 -1
  447. package/dist/common/schema/type-test.mjs +1 -1
  448. package/dist/common/schema/utils.cjs +25 -1
  449. package/dist/common/schema/utils.cjs.map +1 -1
  450. package/dist/common/schema/utils.mjs +19 -1
  451. package/dist/common/schema/utils.mjs.map +1 -1
  452. package/dist/common/schema/z-collection.cjs +51 -1
  453. package/dist/common/schema/z-collection.mjs +27 -1
  454. package/dist/common/schema/z.cjs +9 -1
  455. package/dist/common/schema/z.mjs +3 -1
  456. package/dist/common/storage/index.cjs +4 -1
  457. package/dist/common/storage/index.mjs +3 -1
  458. package/dist/common/storage/memstorage.cjs +26 -1
  459. package/dist/common/storage/memstorage.cjs.map +1 -1
  460. package/dist/common/storage/memstorage.mjs +25 -1
  461. package/dist/common/storage/memstorage.mjs.map +1 -1
  462. package/dist/common/test.cjs +14 -1
  463. package/dist/common/test.cjs.map +1 -1
  464. package/dist/common/test.mjs +13 -1
  465. package/dist/common/test.mjs.map +1 -1
  466. package/dist/common/time.cjs +220 -1
  467. package/dist/common/time.cjs.map +1 -1
  468. package/dist/common/time.mjs +194 -1
  469. package/dist/common/time.mjs.map +1 -1
  470. package/dist/common/timeout.cjs +27 -1
  471. package/dist/common/timeout.cjs.map +1 -1
  472. package/dist/common/timeout.mjs +25 -1
  473. package/dist/common/timeout.mjs.map +1 -1
  474. package/dist/common/types.mjs +1 -1
  475. package/dist/common/utils.cjs +7 -1
  476. package/dist/common/utils.cjs.map +1 -1
  477. package/dist/common/utils.mjs +5 -1
  478. package/dist/common/utils.mjs.map +1 -1
  479. package/dist/common/uuid.cjs +307 -1
  480. package/dist/common/uuid.cjs.map +1 -1
  481. package/dist/common/uuid.mjs +284 -1
  482. package/dist/common/uuid.mjs.map +1 -1
  483. package/dist/{index-DHXVOH8h.d.cts → index-CFkMqHvX.d.cts} +1 -2
  484. package/dist/{index-DMaPyx9O.d.mts → index-C_3Y_s6f.d.mts} +1 -2
  485. package/dist/index.all.cjs +641 -1
  486. package/dist/index.all.d.cts +1 -1
  487. package/dist/index.all.d.mts +1 -1
  488. package/dist/index.all.mjs +113 -1
  489. package/dist/index.browser.cjs +576 -1
  490. package/dist/index.browser.d.cts +1 -1
  491. package/dist/index.browser.d.mts +1 -1
  492. package/dist/index.browser.mjs +98 -1
  493. package/dist/index.jsr.cjs +57 -1
  494. package/dist/index.jsr.mjs +6 -1
  495. package/dist/index.node.cjs +628 -1
  496. package/dist/index.node.d.cts +1 -1
  497. package/dist/index.node.d.mts +1 -1
  498. package/dist/index.node.mjs +106 -1
  499. package/dist/node/args.cjs +56 -1
  500. package/dist/node/args.cjs.map +1 -1
  501. package/dist/node/args.mjs +53 -1
  502. package/dist/node/args.mjs.map +1 -1
  503. package/dist/node/clipboard.cjs +18 -1
  504. package/dist/node/clipboard.cjs.map +1 -1
  505. package/dist/node/clipboard.mjs +16 -1
  506. package/dist/node/clipboard.mjs.map +1 -1
  507. package/dist/node/crypto.cjs +28 -1
  508. package/dist/node/crypto.cjs.map +1 -1
  509. package/dist/node/crypto.mjs +24 -1
  510. package/dist/node/crypto.mjs.map +1 -1
  511. package/dist/node/env.cjs +100 -4
  512. package/dist/node/env.cjs.map +1 -1
  513. package/dist/node/env.mjs +90 -4
  514. package/dist/node/env.mjs.map +1 -1
  515. package/dist/node/files-async.cjs +66 -1
  516. package/dist/node/files-async.cjs.map +1 -1
  517. package/dist/node/files-async.mjs +60 -1
  518. package/dist/node/files-async.mjs.map +1 -1
  519. package/dist/node/files.cjs +52 -1
  520. package/dist/node/files.cjs.map +1 -1
  521. package/dist/node/files.mjs +46 -1
  522. package/dist/node/files.mjs.map +1 -1
  523. package/dist/node/filestorage.cjs +100 -1
  524. package/dist/node/filestorage.cjs.map +1 -1
  525. package/dist/node/filestorage.mjs +97 -1
  526. package/dist/node/filestorage.mjs.map +1 -1
  527. package/dist/node/fs.cjs +119 -1
  528. package/dist/node/fs.cjs.map +1 -1
  529. package/dist/node/fs.mjs +101 -1
  530. package/dist/node/fs.mjs.map +1 -1
  531. package/dist/node/glob.cjs +75 -1
  532. package/dist/node/glob.cjs.map +1 -1
  533. package/dist/node/glob.mjs +73 -1
  534. package/dist/node/glob.mjs.map +1 -1
  535. package/dist/node/index.cjs +66 -1
  536. package/dist/node/index.mjs +16 -1
  537. package/dist/node/log/index.cjs +20 -1
  538. package/dist/node/log/index.mjs +7 -1
  539. package/dist/node/log/log-context-node.cjs +39 -1
  540. package/dist/node/log/log-context-node.cjs.map +1 -1
  541. package/dist/node/log/log-context-node.mjs +35 -1
  542. package/dist/node/log/log-context-node.mjs.map +1 -1
  543. package/dist/node/log/log-file-rotation.cjs +71 -1
  544. package/dist/node/log/log-file-rotation.cjs.map +1 -1
  545. package/dist/node/log/log-file-rotation.mjs +68 -1
  546. package/dist/node/log/log-file-rotation.mjs.map +1 -1
  547. package/dist/node/log/log-file.cjs +57 -1
  548. package/dist/node/log/log-file.cjs.map +1 -1
  549. package/dist/node/log/log-file.mjs +54 -1
  550. package/dist/node/log/log-file.mjs.map +1 -1
  551. package/dist/node/log/log-node.cjs +162 -1
  552. package/dist/node/log/log-node.cjs.map +1 -1
  553. package/dist/node/log/log-node.mjs +155 -1
  554. package/dist/node/log/log-node.mjs.map +1 -1
  555. package/dist/node/log/log-rotation.cjs +543 -3
  556. package/dist/node/log/log-rotation.cjs.map +1 -1
  557. package/dist/node/log/log-rotation.mjs +538 -3
  558. package/dist/node/log/log-rotation.mjs.map +1 -1
  559. package/dist/node/log/log-util.cjs +69 -3
  560. package/dist/node/log/log-util.cjs.map +1 -1
  561. package/dist/node/log/log-util.mjs +63 -3
  562. package/dist/node/log/log-util.mjs.map +1 -1
  563. package/dist/node/open-browser.cjs +20 -1
  564. package/dist/node/open-browser.cjs.map +1 -1
  565. package/dist/node/open-browser.mjs +18 -1
  566. package/dist/node/open-browser.mjs.map +1 -1
  567. package/package.json +15 -15
  568. package/src/common/schema/README.md +247 -66
  569. package/src/eslint-defaults.js +4 -0
  570. package/src/index.spec.ts +6 -6
  571. package/dist/bin-Ce3i6ABn.cjs +0 -3
  572. package/dist/bin-SPdenYkw.mjs +0 -3
  573. package/dist/chunk-0Lt9GpW0.mjs +0 -1
  574. package/dist/chunk-D-qHiVGv.cjs +0 -1
  575. package/src/common/schema/README-SCHEMA.md +0 -0
@@ -1,2 +1,308 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./time.cjs`),t=require(`../bin-Ce3i6ABn.cjs`),n=require(`./crypto/crypto.cjs`),r=require(`./data/basex.cjs`);function i(){return n.randomUint8Array(16)}function a(e=i()){return r.encodeBase62(e,22)}function o(e){return r.encodeBase62(e,22)}function s(e){return r.decodeBase62(e,16)}function c(e=i()){return r.encodeBase32(e,26)}function l(e){return r.encodeBase32(e,26)}function u(e){return r.decodeBase32(e,16)}function d(){if(typeof crypto<`u`&&crypto.randomUUID!=null)return crypto.randomUUID();let e=n.randomUint8Array(16);return e[6]=e[6]&15|64,e[8]=e[8]&63|128,f(e)}function f(e){let n=t._(e);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function p(e){return t.u(e.replace(/-/g,``))}const m=16e11;function h(e){let t=new Uint8Array(6);for(let n=5;n>=0;n--)t[n]=e&255,e=Math.floor(e/256);return t}function g(){let t=e.getTimestamp()-m,r=new Uint8Array(16);return r.set(h(t),0),r.set(n.randomUint8Array(10),6),r}function _(){return D(g())}function v(e){return y(E(e))}function y(e){return new Date(m+e.slice(0,6).reduce((e,t)=>e*256+t,0))}function b(){let e=n.randomUint8Array(4);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!1)}const x={base62:{uuid:a,uuidDecode:s,uuidEncode:o},base32:{uuid:c,uuidDecode:u,uuidEncode:l},uuidv4:{uuid:d,uuidDecode:p,uuidEncode:f},test:{uuid:()=>A(`test`),uuidDecode:e=>t.v(e),uuidEncode:e=>t.r(e)}};let S=`base62`,C=!1;function w(e,t=!1){e===`test`&&j(`test`),S=e??`base62`,C=t}function T(){return x[S].uuid(C?g():i())}function E(e){return x[S].uuidDecode(e)}function D(e){return x[S].uuidEncode(e)}function O(e){try{return E(e).length===16}catch{}return!1}const k={};function A(e=`id`){return k[e]??=0,`${e}-${k[e]++}`}function j(e=`id`){k[e]=0}let M=0;function N(){return`id-${M++}`}exports.qid=N,exports.setUuidDefaultEncoding=w,exports.suid=_,exports.suidBytes=g,exports.suidBytesDate=y,exports.suidDate=v,exports.uname=A,exports.unameReset=j,exports.uuid=T,exports.uuid32bit=b,exports.uuidB32=c,exports.uuidB62=a,exports.uuidBytes=i,exports.uuidDecode=E,exports.uuidDecodeB32=u,exports.uuidDecodeB62=s,exports.uuidDecodeV4=p,exports.uuidEncode=D,exports.uuidEncodeB32=l,exports.uuidEncodeB62=o,exports.uuidEncodeV4=f,exports.uuidIsValid=O,exports.uuidv4=d;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_common_time = require('./time.cjs');
3
+ const require_bin = require('../bin-Ddaz2lxM.cjs');
4
+ const require_common_crypto_crypto = require('./crypto/crypto.cjs');
5
+ const require_common_data_basex = require('./data/basex.cjs');
6
+
7
+ //#region src/common/uuid.ts
8
+ const uuidBytesLength = 16;
9
+ /**
10
+ * Generate raw UUID bytes (128 bits / 16 bytes).
11
+ *
12
+ * Uses a cryptographically secure random source provided by
13
+ * `randomUint8Array`.
14
+ *
15
+ * @returns Uint8Array of length 16 with random bytes
16
+ */
17
+ function uuidBytes() {
18
+ return require_common_crypto_crypto.randomUint8Array(uuidBytesLength);
19
+ }
20
+ /**
21
+ * Create a Base62-encoded UUID string from the provided bytes or a newly
22
+ * generated random UUID. The result is a compact, URL-safe identifier.
23
+ *
24
+ * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated
25
+ * @returns Base62 string representation (22 characters)
26
+ */
27
+ function uuidB62(bytes = uuidBytes()) {
28
+ return require_common_data_basex.encodeBase62(bytes, 22);
29
+ }
30
+ /**
31
+ * Encode raw UUID bytes to a Base62 string.
32
+ *
33
+ * @param bytes - 16-byte UUID as Uint8Array
34
+ * @returns Base62-encoded string
35
+ */
36
+ function uuidEncodeB62(bytes) {
37
+ return require_common_data_basex.encodeBase62(bytes, 22);
38
+ }
39
+ /**
40
+ * Decode a Base62-encoded UUID string into raw bytes.
41
+ *
42
+ * @param uuid - Base62 string
43
+ * @returns 16-byte Uint8Array
44
+ */
45
+ function uuidDecodeB62(uuid) {
46
+ return require_common_data_basex.decodeBase62(uuid, uuidBytesLength);
47
+ }
48
+ /**
49
+ * Create a Base32-encoded UUID string from bytes or a new random UUID.
50
+ *
51
+ * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated
52
+ * @returns Base32 string representation (26 characters)
53
+ */
54
+ function uuidB32(bytes = uuidBytes()) {
55
+ return require_common_data_basex.encodeBase32(bytes, 26);
56
+ }
57
+ /**
58
+ * Encode raw UUID bytes to a Base32 string.
59
+ *
60
+ * @param bytes - 16-byte UUID as Uint8Array
61
+ * @returns Base32-encoded string
62
+ */
63
+ function uuidEncodeB32(bytes) {
64
+ return require_common_data_basex.encodeBase32(bytes, 26);
65
+ }
66
+ /**
67
+ * Decode a Base32-encoded UUID string into raw bytes.
68
+ *
69
+ * @param uuid - Base32 string
70
+ * @returns 16-byte Uint8Array
71
+ */
72
+ function uuidDecodeB32(uuid) {
73
+ return require_common_data_basex.decodeBase32(uuid, uuidBytesLength);
74
+ }
75
+ /**
76
+ * Generate a UUID v4 string.
77
+ *
78
+ * Uses the native `crypto.randomUUID()` if available; otherwise falls back to
79
+ * a random-based implementation using `randomUint8Array`.
80
+ *
81
+ * @returns UUID v4 string in standard 8-4-4-4-12 hex format
82
+ */
83
+ function uuidv4() {
84
+ if (typeof crypto !== "undefined" && crypto.randomUUID != null) return crypto.randomUUID();
85
+ const bytes = require_common_crypto_crypto.randomUint8Array(16);
86
+ bytes[6] = bytes[6] & 15 | 64;
87
+ bytes[8] = bytes[8] & 63 | 128;
88
+ return uuidEncodeV4(bytes);
89
+ }
90
+ /**
91
+ * Encode 16 raw bytes as a UUID v4 formatted string (hex with dashes).
92
+ *
93
+ * @param bytes - 16-byte Uint8Array
94
+ * @returns UUID string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
95
+ */
96
+ function uuidEncodeV4(bytes) {
97
+ const id = require_bin.toHex(bytes);
98
+ return `${id.slice(0, 8)}-${id.slice(8, 12)}-${id.slice(12, 16)}-${id.slice(16, 20)}-${id.slice(20)}`;
99
+ }
100
+ /**
101
+ * Decode a UUID v4 string (hex with dashes) into raw bytes.
102
+ *
103
+ * @param uuid - UUID string
104
+ * @returns 16-byte Uint8Array
105
+ */
106
+ function uuidDecodeV4(uuid) {
107
+ return require_bin.fromHex(uuid.replace(/-/g, ""));
108
+ }
109
+ /**
110
+ * Sortable unique ID
111
+ * Inspired by https://github.com/rsms/go-uuid
112
+ *
113
+ * Bytes 0-5: Current time in miliseconds from 2021-06-01T00:00:00Z
114
+ * Bytes 6-15: Random
115
+ */
116
+ const ReferenceDateInMS = 16e11;
117
+ function longToByteArray(long) {
118
+ const byteArray = new Uint8Array(6);
119
+ for (let i = 5; i >= 0; i--) {
120
+ byteArray[i] = long & 255;
121
+ long = Math.floor(long / 256);
122
+ }
123
+ return byteArray;
124
+ }
125
+ /**
126
+ * Create a sortable unique identifier (SUID) as raw bytes.
127
+ *
128
+ * The first 6 bytes encode a millisecond timestamp offset from an internal
129
+ * reference date to allow lexicographic sorting by creation time. The
130
+ * remaining 10 bytes are random.
131
+ *
132
+ * @returns 16-byte Uint8Array where bytes 0-5 are timestamp and 6-15 are random
133
+ */
134
+ function suidBytes() {
135
+ const ms = require_common_time.getTimestamp() - ReferenceDateInMS;
136
+ const out = new Uint8Array(16);
137
+ out.set(longToByteArray(ms), 0);
138
+ out.set(require_common_crypto_crypto.randomUint8Array(10), 6);
139
+ return out;
140
+ }
141
+ /**
142
+ * Create a sortable unique identifier (SUID) and return it encoded using the
143
+ * currently configured UUID encoding.
144
+ *
145
+ * @returns encoded SUID string
146
+ */
147
+ function suid() {
148
+ return uuidEncode(suidBytes());
149
+ }
150
+ /**
151
+ * Extract the creation Date from an encoded SUID string.
152
+ *
153
+ * @param id - encoded SUID
154
+ * @returns Date corresponding to the timestamp component of the SUID
155
+ */
156
+ function suidDate(id) {
157
+ return suidBytesDate(uuidDecode(id));
158
+ }
159
+ /**
160
+ * Extract the creation Date from raw SUID bytes.
161
+ *
162
+ * @param id - 16-byte SUID as Uint8Array
163
+ * @returns Date corresponding to the timestamp encoded in bytes 0-5
164
+ */
165
+ function suidBytesDate(id) {
166
+ return new Date(ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => acc * 256 + byte, 0));
167
+ }
168
+ /**
169
+ * Generate a 32-bit unsigned integer from 4 random bytes.
170
+ *
171
+ * @returns a random 32-bit unsigned integer
172
+ */
173
+ function uuid32bit() {
174
+ const bytes = require_common_crypto_crypto.randomUint8Array(4);
175
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0, false);
176
+ }
177
+ const mapModes = {
178
+ base62: {
179
+ uuid: uuidB62,
180
+ uuidDecode: uuidDecodeB62,
181
+ uuidEncode: uuidEncodeB62
182
+ },
183
+ base32: {
184
+ uuid: uuidB32,
185
+ uuidDecode: uuidDecodeB32,
186
+ uuidEncode: uuidEncodeB32
187
+ },
188
+ uuidv4: {
189
+ uuid: uuidv4,
190
+ uuidDecode: uuidDecodeV4,
191
+ uuidEncode: uuidEncodeV4
192
+ },
193
+ test: {
194
+ uuid: () => uname("test"),
195
+ uuidDecode: (id) => require_bin.toUint8Array(id),
196
+ uuidEncode: (bin) => require_bin.Uint8ArrayToString(bin)
197
+ }
198
+ };
199
+ let _mode = "base62";
200
+ let _sorted = false;
201
+ /**
202
+ * Configure the default encoding and whether generated IDs should be
203
+ * lexicographically sortable.
204
+ *
205
+ * @param mode - encoding mode ('base62' | 'base32' | 'uuidv4' | 'test')
206
+ * @param sorted - when true, `uuid()` will prefer sortable SUIDs
207
+ */
208
+ function setUuidDefaultEncoding(mode, sorted = false) {
209
+ if (mode === "test") unameReset("test");
210
+ _mode = mode ?? "base62";
211
+ _sorted = sorted;
212
+ }
213
+ /**
214
+ * Generate an identifier using the current encoding mode.
215
+ *
216
+ * If the default encoding is configured with `sorted=true`, this returns a
217
+ * sortable SUID; otherwise a random UUID is returned.
218
+ *
219
+ * @returns encoded identifier string
220
+ */
221
+ function uuid() {
222
+ return mapModes[_mode].uuid(_sorted ? suidBytes() : uuidBytes());
223
+ }
224
+ /**
225
+ * Decode an encoded identifier according to the current encoding mode into
226
+ * raw bytes.
227
+ *
228
+ * @param uuid - encoded identifier string
229
+ * @returns raw 16-byte Uint8Array
230
+ */
231
+ function uuidDecode(uuid) {
232
+ return mapModes[_mode].uuidDecode(uuid);
233
+ }
234
+ /**
235
+ * Encode raw UUID bytes using the current encoding mode.
236
+ *
237
+ * @param bytes - 16-byte Uint8Array
238
+ * @returns encoded identifier string
239
+ */
240
+ function uuidEncode(bytes) {
241
+ return mapModes[_mode].uuidEncode(bytes);
242
+ }
243
+ /**
244
+ * Validate an encoded identifier by attempting to decode it and checking
245
+ * for the expected byte length.
246
+ *
247
+ * @param uuid - encoded identifier string
248
+ * @returns true when valid and decodes to 16 bytes
249
+ */
250
+ function uuidIsValid(uuid) {
251
+ try {
252
+ return uuidDecode(uuid).length === uuidBytesLength;
253
+ } catch (err) {}
254
+ return false;
255
+ }
256
+ const _unameCounters = {};
257
+ /**
258
+ * Simple counter-based unique name generator.
259
+ *
260
+ * Returns strings like 'name-0', 'name-1', ... and increments an internal
261
+ * counter per `name`.
262
+ *
263
+ * @param name - base name for the counter (default: 'id')
264
+ * @returns generated unique name
265
+ */
266
+ function uname(name = "id") {
267
+ _unameCounters[name] ??= 0;
268
+ return `${name}-${_unameCounters[name]++}`;
269
+ }
270
+ /** Reset the counter used by `uname` for the given name. */
271
+ function unameReset(name = "id") {
272
+ _unameCounters[name] = 0;
273
+ }
274
+ let _qid = 0;
275
+ /**
276
+ * Quick global incremental id generator.
277
+ *
278
+ * Returns strings like 'id-0', 'id-1', ... using a single global counter.
279
+ */
280
+ function qid() {
281
+ return `id-${_qid++}`;
282
+ }
283
+
284
+ //#endregion
285
+ exports.qid = qid;
286
+ exports.setUuidDefaultEncoding = setUuidDefaultEncoding;
287
+ exports.suid = suid;
288
+ exports.suidBytes = suidBytes;
289
+ exports.suidBytesDate = suidBytesDate;
290
+ exports.suidDate = suidDate;
291
+ exports.uname = uname;
292
+ exports.unameReset = unameReset;
293
+ exports.uuid = uuid;
294
+ exports.uuid32bit = uuid32bit;
295
+ exports.uuidB32 = uuidB32;
296
+ exports.uuidB62 = uuidB62;
297
+ exports.uuidBytes = uuidBytes;
298
+ exports.uuidDecode = uuidDecode;
299
+ exports.uuidDecodeB32 = uuidDecodeB32;
300
+ exports.uuidDecodeB62 = uuidDecodeB62;
301
+ exports.uuidDecodeV4 = uuidDecodeV4;
302
+ exports.uuidEncode = uuidEncode;
303
+ exports.uuidEncodeB32 = uuidEncodeB32;
304
+ exports.uuidEncodeB62 = uuidEncodeB62;
305
+ exports.uuidEncodeV4 = uuidEncodeV4;
306
+ exports.uuidIsValid = uuidIsValid;
307
+ exports.uuidv4 = uuidv4;
2
308
  //# sourceMappingURL=uuid.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.cjs","names":["randomUint8Array","encodeBase62","decodeBase62","encodeBase32","decodeBase32","toHex","fromHex","getTimestamp","toUint8Array","Uint8ArrayToString"],"sources":["../../src/common/uuid.ts"],"sourcesContent":["import { randomUint8Array } from './crypto'\nimport { decodeBase32, decodeBase62, encodeBase32, encodeBase62 } from './data/basex'\nimport { fromHex, toHex, toUint8Array, Uint8ArrayToString } from './data/bin'\nimport { getTimestamp } from './time'\n\n// 128 bit UUID\n\nconst uuidBytesLength = 16\n\n/**\n * Generate raw UUID bytes (128 bits / 16 bytes).\n *\n * Uses a cryptographically secure random source provided by\n * `randomUint8Array`.\n *\n * @returns Uint8Array of length 16 with random bytes\n */\nexport function uuidBytes(): Uint8Array {\n return randomUint8Array(uuidBytesLength)\n}\n\n// Base62\n\n/**\n * Create a Base62-encoded UUID string from the provided bytes or a newly\n * generated random UUID. The result is a compact, URL-safe identifier.\n *\n * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated\n * @returns Base62 string representation (22 characters)\n */\nexport function uuidB62(bytes: Uint8Array = uuidBytes()): string {\n return encodeBase62(bytes, 22)\n}\n\n/**\n * Encode raw UUID bytes to a Base62 string.\n *\n * @param bytes - 16-byte UUID as Uint8Array\n * @returns Base62-encoded string\n */\nexport function uuidEncodeB62(bytes: Uint8Array): string {\n return encodeBase62(bytes, 22)\n}\n\n/**\n * Decode a Base62-encoded UUID string into raw bytes.\n *\n * @param uuid - Base62 string\n * @returns 16-byte Uint8Array\n */\nexport function uuidDecodeB62(uuid: string): Uint8Array {\n return decodeBase62(uuid, uuidBytesLength)\n}\n\n// Base32\n\n/**\n * Create a Base32-encoded UUID string from bytes or a new random UUID.\n *\n * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated\n * @returns Base32 string representation (26 characters)\n */\nexport function uuidB32(bytes: Uint8Array = uuidBytes()): string {\n return encodeBase32(bytes, 26)\n}\n\n/**\n * Encode raw UUID bytes to a Base32 string.\n *\n * @param bytes - 16-byte UUID as Uint8Array\n * @returns Base32-encoded string\n */\nexport function uuidEncodeB32(bytes: Uint8Array): string {\n return encodeBase32(bytes, 26)\n}\n\n/**\n * Decode a Base32-encoded UUID string into raw bytes.\n *\n * @param uuid - Base32 string\n * @returns 16-byte Uint8Array\n */\nexport function uuidDecodeB32(uuid: string): Uint8Array {\n return decodeBase32(uuid, uuidBytesLength)\n}\n\n// UUIDv4\n\n// https://stackoverflow.com/a/2117523/140927\nconst pattern = '10000000-1000-4000-8000-100000000000' // String([1e7] + -1e3 + -4e3 + -8e3 + -1e11)\n\n/**\n * Generate a UUID v4 string.\n *\n * Uses the native `crypto.randomUUID()` if available; otherwise falls back to\n * a random-based implementation using `randomUint8Array`.\n *\n * @returns UUID v4 string in standard 8-4-4-4-12 hex format\n */\nexport function uuidv4(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID != null)\n return crypto.randomUUID() // native!\n\n // Fallback: generate 16 random bytes, set version and variant bits per RFC-4122\n const bytes = randomUint8Array(16)\n bytes[6] = (bytes[6] & 0x0F) | 0x40 // version 4\n bytes[8] = (bytes[8] & 0x3F) | 0x80 // variant\n return uuidEncodeV4(bytes)\n}\n\n/**\n * Encode 16 raw bytes as a UUID v4 formatted string (hex with dashes).\n *\n * @param bytes - 16-byte Uint8Array\n * @returns UUID string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)\n */\nexport function uuidEncodeV4(bytes: Uint8Array): string {\n const id = toHex(bytes)\n return `${id.slice(0, 8)}-${id.slice(8, 12)}-${id.slice(12, 16)}-${id.slice(16, 20)}-${id.slice(20)}` // 10000000 - 1000 - 4000 - 8000 - 100000000000\n}\n\n/**\n * Decode a UUID v4 string (hex with dashes) into raw bytes.\n *\n * @param uuid - UUID string\n * @returns 16-byte Uint8Array\n */\nexport function uuidDecodeV4(uuid: string): Uint8Array {\n return fromHex(uuid.replace(/-/g, ''))\n}\n\n// Sortable UID\n\n// https://github.com/segmentio/ksuid\n// https://pkg.go.dev/github.com/rsms/go-uuid\n\n/**\n * Sortable unique ID\n * Inspired by https://github.com/rsms/go-uuid\n *\n * Bytes 0-5: Current time in miliseconds from 2021-06-01T00:00:00Z\n * Bytes 6-15: Random\n */\n\n// 1622505600000 // new Date('2021-06-01T00:00:00Z').getTime()\nconst ReferenceDateInMS = 1600000000000\n\n// 6 bytes will stay valid until end of time: new Date(1622505600000 + 0xffffffffffff) === Date Sun Jan 01 10941 06:31:50 GMT+0100 (Central European Standard Time)\n\nfunction longToByteArray(long: number) {\n const byteArray = new Uint8Array(6)\n for (let i = 5; i >= 0; i--) {\n byteArray[i] = long & 0xFF\n long = Math.floor(long / 256)\n }\n return byteArray\n}\n\n// function byteArrayToLong(byteArray: number[]): number {\n// var value = 0\n// for (var i = byteArray.length - 1; i >= 0; i--) {\n// value = value * 256 + byteArray[i]\n// }\n// return value\n// }\n\n/**\n * Create a sortable unique identifier (SUID) as raw bytes.\n *\n * The first 6 bytes encode a millisecond timestamp offset from an internal\n * reference date to allow lexicographic sorting by creation time. The\n * remaining 10 bytes are random.\n *\n * @returns 16-byte Uint8Array where bytes 0-5 are timestamp and 6-15 are random\n */\nexport function suidBytes(): Uint8Array {\n const ms = getTimestamp() - ReferenceDateInMS\n const out = new Uint8Array(16)\n out.set(longToByteArray(ms), 0)\n out.set(randomUint8Array(10), 6)\n return out\n}\n\n/**\n * Create a sortable unique identifier (SUID) and return it encoded using the\n * currently configured UUID encoding.\n *\n * @returns encoded SUID string\n */\nexport function suid(): string {\n return uuidEncode(suidBytes())\n}\n\n/**\n * Extract the creation Date from an encoded SUID string.\n *\n * @param id - encoded SUID\n * @returns Date corresponding to the timestamp component of the SUID\n */\nexport function suidDate(id: string): Date {\n return suidBytesDate(uuidDecode(id))\n}\n\n/**\n * Extract the creation Date from raw SUID bytes.\n *\n * @param id - 16-byte SUID as Uint8Array\n * @returns Date corresponding to the timestamp encoded in bytes 0-5\n */\nexport function suidBytesDate(id: Uint8Array): Date {\n return new Date(\n ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => acc * 256 + byte, 0),\n )\n}\n\n// 32 bit UUID\n\n/**\n * Generate a 32-bit unsigned integer from 4 random bytes.\n *\n * @returns a random 32-bit unsigned integer\n */\nexport function uuid32bit(): number {\n const bytes = randomUint8Array(4)\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n return view.getUint32(0, false)\n}\n\n// Global Settings\n\nconst mapModes = {\n base62: {\n uuid: uuidB62,\n uuidDecode: uuidDecodeB62,\n uuidEncode: uuidEncodeB62,\n },\n base32: {\n uuid: uuidB32,\n uuidDecode: uuidDecodeB32,\n uuidEncode: uuidEncodeB32,\n },\n uuidv4: {\n uuid: uuidv4,\n uuidDecode: uuidDecodeV4,\n uuidEncode: uuidEncodeV4,\n },\n test: {\n uuid: (): string => uname('test'),\n uuidDecode: (id: string): Uint8Array => toUint8Array(id),\n uuidEncode: (bin: Uint8Array): string => Uint8ArrayToString(bin),\n },\n}\n\nlet _mode: keyof typeof mapModes = 'base62'\nlet _sorted = false\n\n/**\n * Configure the default encoding and whether generated IDs should be\n * lexicographically sortable.\n *\n * @param mode - encoding mode ('base62' | 'base32' | 'uuidv4' | 'test')\n * @param sorted - when true, `uuid()` will prefer sortable SUIDs\n */\nexport function setUuidDefaultEncoding(mode?: keyof typeof mapModes, sorted = false) {\n if (mode === 'test')\n unameReset('test')\n\n _mode = mode ?? 'base62'\n _sorted = sorted\n}\n\n/**\n * Generate an identifier using the current encoding mode.\n *\n * If the default encoding is configured with `sorted=true`, this returns a\n * sortable SUID; otherwise a random UUID is returned.\n *\n * @returns encoded identifier string\n */\nexport function uuid(): string {\n return mapModes[_mode].uuid(_sorted ? suidBytes() : uuidBytes())\n}\n\n/**\n * Decode an encoded identifier according to the current encoding mode into\n * raw bytes.\n *\n * @param uuid - encoded identifier string\n * @returns raw 16-byte Uint8Array\n */\nexport function uuidDecode(uuid: string): Uint8Array {\n return mapModes[_mode].uuidDecode(uuid)\n}\n\n/**\n * Encode raw UUID bytes using the current encoding mode.\n *\n * @param bytes - 16-byte Uint8Array\n * @returns encoded identifier string\n */\nexport function uuidEncode(bytes: Uint8Array): string {\n return mapModes[_mode].uuidEncode(bytes)\n}\n\n/**\n * Validate an encoded identifier by attempting to decode it and checking\n * for the expected byte length.\n *\n * @param uuid - encoded identifier string\n * @returns true when valid and decodes to 16 bytes\n */\nexport function uuidIsValid(uuid: string): boolean {\n try {\n const bin = uuidDecode(uuid)\n return bin.length === uuidBytesLength\n }\n catch (err) {\n // log.warn('Invalid ID:', uuid)\n }\n return false\n}\n\n// Simple Counters\n\nconst _unameCounters: Record<string, number> = {}\n\n/**\n * Simple counter-based unique name generator.\n *\n * Returns strings like 'name-0', 'name-1', ... and increments an internal\n * counter per `name`.\n *\n * @param name - base name for the counter (default: 'id')\n * @returns generated unique name\n */\nexport function uname(name = 'id'): string {\n _unameCounters[name] ??= 0\n\n return `${name}-${_unameCounters[name]++}`\n}\n\n/** Reset the counter used by `uname` for the given name. */\nexport function unameReset(name = 'id') {\n _unameCounters[name] = 0\n}\n\nlet _qid = 0\n\n/**\n * Quick global incremental id generator.\n *\n * Returns strings like 'id-0', 'id-1', ... using a single global counter.\n */\nexport function qid(): string {\n return `id-${_qid++}`\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"uuid.cjs","names":["randomUint8Array","encodeBase62","decodeBase62","encodeBase32","decodeBase32","toHex","fromHex","getTimestamp","toUint8Array","Uint8ArrayToString"],"sources":["../../src/common/uuid.ts"],"sourcesContent":["import { randomUint8Array } from './crypto'\nimport { decodeBase32, decodeBase62, encodeBase32, encodeBase62 } from './data/basex'\nimport { fromHex, toHex, toUint8Array, Uint8ArrayToString } from './data/bin'\nimport { getTimestamp } from './time'\n\n// 128 bit UUID\n\nconst uuidBytesLength = 16\n\n/**\n * Generate raw UUID bytes (128 bits / 16 bytes).\n *\n * Uses a cryptographically secure random source provided by\n * `randomUint8Array`.\n *\n * @returns Uint8Array of length 16 with random bytes\n */\nexport function uuidBytes(): Uint8Array {\n return randomUint8Array(uuidBytesLength)\n}\n\n// Base62\n\n/**\n * Create a Base62-encoded UUID string from the provided bytes or a newly\n * generated random UUID. The result is a compact, URL-safe identifier.\n *\n * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated\n * @returns Base62 string representation (22 characters)\n */\nexport function uuidB62(bytes: Uint8Array = uuidBytes()): string {\n return encodeBase62(bytes, 22)\n}\n\n/**\n * Encode raw UUID bytes to a Base62 string.\n *\n * @param bytes - 16-byte UUID as Uint8Array\n * @returns Base62-encoded string\n */\nexport function uuidEncodeB62(bytes: Uint8Array): string {\n return encodeBase62(bytes, 22)\n}\n\n/**\n * Decode a Base62-encoded UUID string into raw bytes.\n *\n * @param uuid - Base62 string\n * @returns 16-byte Uint8Array\n */\nexport function uuidDecodeB62(uuid: string): Uint8Array {\n return decodeBase62(uuid, uuidBytesLength)\n}\n\n// Base32\n\n/**\n * Create a Base32-encoded UUID string from bytes or a new random UUID.\n *\n * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated\n * @returns Base32 string representation (26 characters)\n */\nexport function uuidB32(bytes: Uint8Array = uuidBytes()): string {\n return encodeBase32(bytes, 26)\n}\n\n/**\n * Encode raw UUID bytes to a Base32 string.\n *\n * @param bytes - 16-byte UUID as Uint8Array\n * @returns Base32-encoded string\n */\nexport function uuidEncodeB32(bytes: Uint8Array): string {\n return encodeBase32(bytes, 26)\n}\n\n/**\n * Decode a Base32-encoded UUID string into raw bytes.\n *\n * @param uuid - Base32 string\n * @returns 16-byte Uint8Array\n */\nexport function uuidDecodeB32(uuid: string): Uint8Array {\n return decodeBase32(uuid, uuidBytesLength)\n}\n\n// UUIDv4\n\n// https://stackoverflow.com/a/2117523/140927\nconst pattern = '10000000-1000-4000-8000-100000000000' // String([1e7] + -1e3 + -4e3 + -8e3 + -1e11)\n\n/**\n * Generate a UUID v4 string.\n *\n * Uses the native `crypto.randomUUID()` if available; otherwise falls back to\n * a random-based implementation using `randomUint8Array`.\n *\n * @returns UUID v4 string in standard 8-4-4-4-12 hex format\n */\nexport function uuidv4(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID != null)\n return crypto.randomUUID() // native!\n\n // Fallback: generate 16 random bytes, set version and variant bits per RFC-4122\n const bytes = randomUint8Array(16)\n bytes[6] = (bytes[6] & 0x0F) | 0x40 // version 4\n bytes[8] = (bytes[8] & 0x3F) | 0x80 // variant\n return uuidEncodeV4(bytes)\n}\n\n/**\n * Encode 16 raw bytes as a UUID v4 formatted string (hex with dashes).\n *\n * @param bytes - 16-byte Uint8Array\n * @returns UUID string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)\n */\nexport function uuidEncodeV4(bytes: Uint8Array): string {\n const id = toHex(bytes)\n return `${id.slice(0, 8)}-${id.slice(8, 12)}-${id.slice(12, 16)}-${id.slice(16, 20)}-${id.slice(20)}` // 10000000 - 1000 - 4000 - 8000 - 100000000000\n}\n\n/**\n * Decode a UUID v4 string (hex with dashes) into raw bytes.\n *\n * @param uuid - UUID string\n * @returns 16-byte Uint8Array\n */\nexport function uuidDecodeV4(uuid: string): Uint8Array {\n return fromHex(uuid.replace(/-/g, ''))\n}\n\n// Sortable UID\n\n// https://github.com/segmentio/ksuid\n// https://pkg.go.dev/github.com/rsms/go-uuid\n\n/**\n * Sortable unique ID\n * Inspired by https://github.com/rsms/go-uuid\n *\n * Bytes 0-5: Current time in miliseconds from 2021-06-01T00:00:00Z\n * Bytes 6-15: Random\n */\n\n// 1622505600000 // new Date('2021-06-01T00:00:00Z').getTime()\nconst ReferenceDateInMS = 1600000000000\n\n// 6 bytes will stay valid until end of time: new Date(1622505600000 + 0xffffffffffff) === Date Sun Jan 01 10941 06:31:50 GMT+0100 (Central European Standard Time)\n\nfunction longToByteArray(long: number) {\n const byteArray = new Uint8Array(6)\n for (let i = 5; i >= 0; i--) {\n byteArray[i] = long & 0xFF\n long = Math.floor(long / 256)\n }\n return byteArray\n}\n\n// function byteArrayToLong(byteArray: number[]): number {\n// var value = 0\n// for (var i = byteArray.length - 1; i >= 0; i--) {\n// value = value * 256 + byteArray[i]\n// }\n// return value\n// }\n\n/**\n * Create a sortable unique identifier (SUID) as raw bytes.\n *\n * The first 6 bytes encode a millisecond timestamp offset from an internal\n * reference date to allow lexicographic sorting by creation time. The\n * remaining 10 bytes are random.\n *\n * @returns 16-byte Uint8Array where bytes 0-5 are timestamp and 6-15 are random\n */\nexport function suidBytes(): Uint8Array {\n const ms = getTimestamp() - ReferenceDateInMS\n const out = new Uint8Array(16)\n out.set(longToByteArray(ms), 0)\n out.set(randomUint8Array(10), 6)\n return out\n}\n\n/**\n * Create a sortable unique identifier (SUID) and return it encoded using the\n * currently configured UUID encoding.\n *\n * @returns encoded SUID string\n */\nexport function suid(): string {\n return uuidEncode(suidBytes())\n}\n\n/**\n * Extract the creation Date from an encoded SUID string.\n *\n * @param id - encoded SUID\n * @returns Date corresponding to the timestamp component of the SUID\n */\nexport function suidDate(id: string): Date {\n return suidBytesDate(uuidDecode(id))\n}\n\n/**\n * Extract the creation Date from raw SUID bytes.\n *\n * @param id - 16-byte SUID as Uint8Array\n * @returns Date corresponding to the timestamp encoded in bytes 0-5\n */\nexport function suidBytesDate(id: Uint8Array): Date {\n return new Date(\n ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => acc * 256 + byte, 0),\n )\n}\n\n// 32 bit UUID\n\n/**\n * Generate a 32-bit unsigned integer from 4 random bytes.\n *\n * @returns a random 32-bit unsigned integer\n */\nexport function uuid32bit(): number {\n const bytes = randomUint8Array(4)\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n return view.getUint32(0, false)\n}\n\n// Global Settings\n\nconst mapModes = {\n base62: {\n uuid: uuidB62,\n uuidDecode: uuidDecodeB62,\n uuidEncode: uuidEncodeB62,\n },\n base32: {\n uuid: uuidB32,\n uuidDecode: uuidDecodeB32,\n uuidEncode: uuidEncodeB32,\n },\n uuidv4: {\n uuid: uuidv4,\n uuidDecode: uuidDecodeV4,\n uuidEncode: uuidEncodeV4,\n },\n test: {\n uuid: (): string => uname('test'),\n uuidDecode: (id: string): Uint8Array => toUint8Array(id),\n uuidEncode: (bin: Uint8Array): string => Uint8ArrayToString(bin),\n },\n}\n\nlet _mode: keyof typeof mapModes = 'base62'\nlet _sorted = false\n\n/**\n * Configure the default encoding and whether generated IDs should be\n * lexicographically sortable.\n *\n * @param mode - encoding mode ('base62' | 'base32' | 'uuidv4' | 'test')\n * @param sorted - when true, `uuid()` will prefer sortable SUIDs\n */\nexport function setUuidDefaultEncoding(mode?: keyof typeof mapModes, sorted = false) {\n if (mode === 'test')\n unameReset('test')\n\n _mode = mode ?? 'base62'\n _sorted = sorted\n}\n\n/**\n * Generate an identifier using the current encoding mode.\n *\n * If the default encoding is configured with `sorted=true`, this returns a\n * sortable SUID; otherwise a random UUID is returned.\n *\n * @returns encoded identifier string\n */\nexport function uuid(): string {\n return mapModes[_mode].uuid(_sorted ? suidBytes() : uuidBytes())\n}\n\n/**\n * Decode an encoded identifier according to the current encoding mode into\n * raw bytes.\n *\n * @param uuid - encoded identifier string\n * @returns raw 16-byte Uint8Array\n */\nexport function uuidDecode(uuid: string): Uint8Array {\n return mapModes[_mode].uuidDecode(uuid)\n}\n\n/**\n * Encode raw UUID bytes using the current encoding mode.\n *\n * @param bytes - 16-byte Uint8Array\n * @returns encoded identifier string\n */\nexport function uuidEncode(bytes: Uint8Array): string {\n return mapModes[_mode].uuidEncode(bytes)\n}\n\n/**\n * Validate an encoded identifier by attempting to decode it and checking\n * for the expected byte length.\n *\n * @param uuid - encoded identifier string\n * @returns true when valid and decodes to 16 bytes\n */\nexport function uuidIsValid(uuid: string): boolean {\n try {\n const bin = uuidDecode(uuid)\n return bin.length === uuidBytesLength\n }\n catch (err) {\n // log.warn('Invalid ID:', uuid)\n }\n return false\n}\n\n// Simple Counters\n\nconst _unameCounters: Record<string, number> = {}\n\n/**\n * Simple counter-based unique name generator.\n *\n * Returns strings like 'name-0', 'name-1', ... and increments an internal\n * counter per `name`.\n *\n * @param name - base name for the counter (default: 'id')\n * @returns generated unique name\n */\nexport function uname(name = 'id'): string {\n _unameCounters[name] ??= 0\n\n return `${name}-${_unameCounters[name]++}`\n}\n\n/** Reset the counter used by `uname` for the given name. */\nexport function unameReset(name = 'id') {\n _unameCounters[name] = 0\n}\n\nlet _qid = 0\n\n/**\n * Quick global incremental id generator.\n *\n * Returns strings like 'id-0', 'id-1', ... using a single global counter.\n */\nexport function qid(): string {\n return `id-${_qid++}`\n}\n"],"mappings":"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"}
@@ -1,2 +1,285 @@
1
- import{getTimestamp as e}from"./time.mjs";import{_ as t,r as n,u as r,v as i}from"../bin-SPdenYkw.mjs";import{randomUint8Array as a}from"./crypto/crypto.mjs";import{decodeBase32 as o,decodeBase62 as s,encodeBase32 as c,encodeBase62 as l}from"./data/basex.mjs";function u(){return a(16)}function d(e=u()){return l(e,22)}function f(e){return l(e,22)}function p(e){return s(e,16)}function m(e=u()){return c(e,26)}function h(e){return c(e,26)}function g(e){return o(e,16)}function _(){if(typeof crypto<`u`&&crypto.randomUUID!=null)return crypto.randomUUID();let e=a(16);return e[6]=e[6]&15|64,e[8]=e[8]&63|128,v(e)}function v(e){let n=t(e);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function y(e){return r(e.replace(/-/g,``))}const b=16e11;function x(e){let t=new Uint8Array(6);for(let n=5;n>=0;n--)t[n]=e&255,e=Math.floor(e/256);return t}function S(){let t=e()-b,n=new Uint8Array(16);return n.set(x(t),0),n.set(a(10),6),n}function C(){return N(S())}function w(e){return T(M(e))}function T(e){return new Date(b+e.slice(0,6).reduce((e,t)=>e*256+t,0))}function E(){let e=a(4);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!1)}const D={base62:{uuid:d,uuidDecode:p,uuidEncode:f},base32:{uuid:m,uuidDecode:g,uuidEncode:h},uuidv4:{uuid:_,uuidDecode:y,uuidEncode:v},test:{uuid:()=>I(`test`),uuidDecode:e=>i(e),uuidEncode:e=>n(e)}};let O=`base62`,k=!1;function A(e,t=!1){e===`test`&&L(`test`),O=e??`base62`,k=t}function j(){return D[O].uuid(k?S():u())}function M(e){return D[O].uuidDecode(e)}function N(e){return D[O].uuidEncode(e)}function P(e){try{return M(e).length===16}catch{}return!1}const F={};function I(e=`id`){return F[e]??=0,`${e}-${F[e]++}`}function L(e=`id`){F[e]=0}let R=0;function z(){return`id-${R++}`}export{z as qid,A as setUuidDefaultEncoding,C as suid,S as suidBytes,T as suidBytesDate,w as suidDate,I as uname,L as unameReset,j as uuid,E as uuid32bit,m as uuidB32,d as uuidB62,u as uuidBytes,M as uuidDecode,g as uuidDecodeB32,p as uuidDecodeB62,y as uuidDecodeV4,N as uuidEncode,h as uuidEncodeB32,f as uuidEncodeB62,v as uuidEncodeV4,P as uuidIsValid,_ as uuidv4};
1
+ import { getTimestamp } from "./time.mjs";
2
+ import { _ as toHex, r as Uint8ArrayToString, u as fromHex, v as toUint8Array } from "../bin-BAoS4qtm.mjs";
3
+ import { randomUint8Array } from "./crypto/crypto.mjs";
4
+ import { decodeBase32, decodeBase62, encodeBase32, encodeBase62 } from "./data/basex.mjs";
5
+
6
+ //#region src/common/uuid.ts
7
+ const uuidBytesLength = 16;
8
+ /**
9
+ * Generate raw UUID bytes (128 bits / 16 bytes).
10
+ *
11
+ * Uses a cryptographically secure random source provided by
12
+ * `randomUint8Array`.
13
+ *
14
+ * @returns Uint8Array of length 16 with random bytes
15
+ */
16
+ function uuidBytes() {
17
+ return randomUint8Array(uuidBytesLength);
18
+ }
19
+ /**
20
+ * Create a Base62-encoded UUID string from the provided bytes or a newly
21
+ * generated random UUID. The result is a compact, URL-safe identifier.
22
+ *
23
+ * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated
24
+ * @returns Base62 string representation (22 characters)
25
+ */
26
+ function uuidB62(bytes = uuidBytes()) {
27
+ return encodeBase62(bytes, 22);
28
+ }
29
+ /**
30
+ * Encode raw UUID bytes to a Base62 string.
31
+ *
32
+ * @param bytes - 16-byte UUID as Uint8Array
33
+ * @returns Base62-encoded string
34
+ */
35
+ function uuidEncodeB62(bytes) {
36
+ return encodeBase62(bytes, 22);
37
+ }
38
+ /**
39
+ * Decode a Base62-encoded UUID string into raw bytes.
40
+ *
41
+ * @param uuid - Base62 string
42
+ * @returns 16-byte Uint8Array
43
+ */
44
+ function uuidDecodeB62(uuid) {
45
+ return decodeBase62(uuid, uuidBytesLength);
46
+ }
47
+ /**
48
+ * Create a Base32-encoded UUID string from bytes or a new random UUID.
49
+ *
50
+ * @param bytes - optional 16-byte Uint8Array; if omitted a new random UUID is generated
51
+ * @returns Base32 string representation (26 characters)
52
+ */
53
+ function uuidB32(bytes = uuidBytes()) {
54
+ return encodeBase32(bytes, 26);
55
+ }
56
+ /**
57
+ * Encode raw UUID bytes to a Base32 string.
58
+ *
59
+ * @param bytes - 16-byte UUID as Uint8Array
60
+ * @returns Base32-encoded string
61
+ */
62
+ function uuidEncodeB32(bytes) {
63
+ return encodeBase32(bytes, 26);
64
+ }
65
+ /**
66
+ * Decode a Base32-encoded UUID string into raw bytes.
67
+ *
68
+ * @param uuid - Base32 string
69
+ * @returns 16-byte Uint8Array
70
+ */
71
+ function uuidDecodeB32(uuid) {
72
+ return decodeBase32(uuid, uuidBytesLength);
73
+ }
74
+ /**
75
+ * Generate a UUID v4 string.
76
+ *
77
+ * Uses the native `crypto.randomUUID()` if available; otherwise falls back to
78
+ * a random-based implementation using `randomUint8Array`.
79
+ *
80
+ * @returns UUID v4 string in standard 8-4-4-4-12 hex format
81
+ */
82
+ function uuidv4() {
83
+ if (typeof crypto !== "undefined" && crypto.randomUUID != null) return crypto.randomUUID();
84
+ const bytes = randomUint8Array(16);
85
+ bytes[6] = bytes[6] & 15 | 64;
86
+ bytes[8] = bytes[8] & 63 | 128;
87
+ return uuidEncodeV4(bytes);
88
+ }
89
+ /**
90
+ * Encode 16 raw bytes as a UUID v4 formatted string (hex with dashes).
91
+ *
92
+ * @param bytes - 16-byte Uint8Array
93
+ * @returns UUID string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
94
+ */
95
+ function uuidEncodeV4(bytes) {
96
+ const id = toHex(bytes);
97
+ return `${id.slice(0, 8)}-${id.slice(8, 12)}-${id.slice(12, 16)}-${id.slice(16, 20)}-${id.slice(20)}`;
98
+ }
99
+ /**
100
+ * Decode a UUID v4 string (hex with dashes) into raw bytes.
101
+ *
102
+ * @param uuid - UUID string
103
+ * @returns 16-byte Uint8Array
104
+ */
105
+ function uuidDecodeV4(uuid) {
106
+ return fromHex(uuid.replace(/-/g, ""));
107
+ }
108
+ /**
109
+ * Sortable unique ID
110
+ * Inspired by https://github.com/rsms/go-uuid
111
+ *
112
+ * Bytes 0-5: Current time in miliseconds from 2021-06-01T00:00:00Z
113
+ * Bytes 6-15: Random
114
+ */
115
+ const ReferenceDateInMS = 16e11;
116
+ function longToByteArray(long) {
117
+ const byteArray = new Uint8Array(6);
118
+ for (let i = 5; i >= 0; i--) {
119
+ byteArray[i] = long & 255;
120
+ long = Math.floor(long / 256);
121
+ }
122
+ return byteArray;
123
+ }
124
+ /**
125
+ * Create a sortable unique identifier (SUID) as raw bytes.
126
+ *
127
+ * The first 6 bytes encode a millisecond timestamp offset from an internal
128
+ * reference date to allow lexicographic sorting by creation time. The
129
+ * remaining 10 bytes are random.
130
+ *
131
+ * @returns 16-byte Uint8Array where bytes 0-5 are timestamp and 6-15 are random
132
+ */
133
+ function suidBytes() {
134
+ const ms = getTimestamp() - ReferenceDateInMS;
135
+ const out = new Uint8Array(16);
136
+ out.set(longToByteArray(ms), 0);
137
+ out.set(randomUint8Array(10), 6);
138
+ return out;
139
+ }
140
+ /**
141
+ * Create a sortable unique identifier (SUID) and return it encoded using the
142
+ * currently configured UUID encoding.
143
+ *
144
+ * @returns encoded SUID string
145
+ */
146
+ function suid() {
147
+ return uuidEncode(suidBytes());
148
+ }
149
+ /**
150
+ * Extract the creation Date from an encoded SUID string.
151
+ *
152
+ * @param id - encoded SUID
153
+ * @returns Date corresponding to the timestamp component of the SUID
154
+ */
155
+ function suidDate(id) {
156
+ return suidBytesDate(uuidDecode(id));
157
+ }
158
+ /**
159
+ * Extract the creation Date from raw SUID bytes.
160
+ *
161
+ * @param id - 16-byte SUID as Uint8Array
162
+ * @returns Date corresponding to the timestamp encoded in bytes 0-5
163
+ */
164
+ function suidBytesDate(id) {
165
+ return new Date(ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => acc * 256 + byte, 0));
166
+ }
167
+ /**
168
+ * Generate a 32-bit unsigned integer from 4 random bytes.
169
+ *
170
+ * @returns a random 32-bit unsigned integer
171
+ */
172
+ function uuid32bit() {
173
+ const bytes = randomUint8Array(4);
174
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0, false);
175
+ }
176
+ const mapModes = {
177
+ base62: {
178
+ uuid: uuidB62,
179
+ uuidDecode: uuidDecodeB62,
180
+ uuidEncode: uuidEncodeB62
181
+ },
182
+ base32: {
183
+ uuid: uuidB32,
184
+ uuidDecode: uuidDecodeB32,
185
+ uuidEncode: uuidEncodeB32
186
+ },
187
+ uuidv4: {
188
+ uuid: uuidv4,
189
+ uuidDecode: uuidDecodeV4,
190
+ uuidEncode: uuidEncodeV4
191
+ },
192
+ test: {
193
+ uuid: () => uname("test"),
194
+ uuidDecode: (id) => toUint8Array(id),
195
+ uuidEncode: (bin) => Uint8ArrayToString(bin)
196
+ }
197
+ };
198
+ let _mode = "base62";
199
+ let _sorted = false;
200
+ /**
201
+ * Configure the default encoding and whether generated IDs should be
202
+ * lexicographically sortable.
203
+ *
204
+ * @param mode - encoding mode ('base62' | 'base32' | 'uuidv4' | 'test')
205
+ * @param sorted - when true, `uuid()` will prefer sortable SUIDs
206
+ */
207
+ function setUuidDefaultEncoding(mode, sorted = false) {
208
+ if (mode === "test") unameReset("test");
209
+ _mode = mode ?? "base62";
210
+ _sorted = sorted;
211
+ }
212
+ /**
213
+ * Generate an identifier using the current encoding mode.
214
+ *
215
+ * If the default encoding is configured with `sorted=true`, this returns a
216
+ * sortable SUID; otherwise a random UUID is returned.
217
+ *
218
+ * @returns encoded identifier string
219
+ */
220
+ function uuid() {
221
+ return mapModes[_mode].uuid(_sorted ? suidBytes() : uuidBytes());
222
+ }
223
+ /**
224
+ * Decode an encoded identifier according to the current encoding mode into
225
+ * raw bytes.
226
+ *
227
+ * @param uuid - encoded identifier string
228
+ * @returns raw 16-byte Uint8Array
229
+ */
230
+ function uuidDecode(uuid) {
231
+ return mapModes[_mode].uuidDecode(uuid);
232
+ }
233
+ /**
234
+ * Encode raw UUID bytes using the current encoding mode.
235
+ *
236
+ * @param bytes - 16-byte Uint8Array
237
+ * @returns encoded identifier string
238
+ */
239
+ function uuidEncode(bytes) {
240
+ return mapModes[_mode].uuidEncode(bytes);
241
+ }
242
+ /**
243
+ * Validate an encoded identifier by attempting to decode it and checking
244
+ * for the expected byte length.
245
+ *
246
+ * @param uuid - encoded identifier string
247
+ * @returns true when valid and decodes to 16 bytes
248
+ */
249
+ function uuidIsValid(uuid) {
250
+ try {
251
+ return uuidDecode(uuid).length === uuidBytesLength;
252
+ } catch (err) {}
253
+ return false;
254
+ }
255
+ const _unameCounters = {};
256
+ /**
257
+ * Simple counter-based unique name generator.
258
+ *
259
+ * Returns strings like 'name-0', 'name-1', ... and increments an internal
260
+ * counter per `name`.
261
+ *
262
+ * @param name - base name for the counter (default: 'id')
263
+ * @returns generated unique name
264
+ */
265
+ function uname(name = "id") {
266
+ _unameCounters[name] ??= 0;
267
+ return `${name}-${_unameCounters[name]++}`;
268
+ }
269
+ /** Reset the counter used by `uname` for the given name. */
270
+ function unameReset(name = "id") {
271
+ _unameCounters[name] = 0;
272
+ }
273
+ let _qid = 0;
274
+ /**
275
+ * Quick global incremental id generator.
276
+ *
277
+ * Returns strings like 'id-0', 'id-1', ... using a single global counter.
278
+ */
279
+ function qid() {
280
+ return `id-${_qid++}`;
281
+ }
282
+
283
+ //#endregion
284
+ export { qid, setUuidDefaultEncoding, suid, suidBytes, suidBytesDate, suidDate, uname, unameReset, uuid, uuid32bit, uuidB32, uuidB62, uuidBytes, uuidDecode, uuidDecodeB32, uuidDecodeB62, uuidDecodeV4, uuidEncode, uuidEncodeB32, uuidEncodeB62, uuidEncodeV4, uuidIsValid, uuidv4 };
2
285
  //# sourceMappingURL=uuid.mjs.map