@venizia/ignis-helpers 0.4.6 → 0.4.7-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 (300) hide show
  1. package/LICENSE.md +1 -3
  2. package/README.md +4 -5
  3. package/dist/esm/common/redact.d.ts +25 -17
  4. package/dist/esm/common/redact.d.ts.map +1 -1
  5. package/dist/esm/common/redact.js +50 -46
  6. package/dist/esm/common/redact.js.map +1 -1
  7. package/dist/esm/common/resolvers.d.ts +7 -5
  8. package/dist/esm/common/resolvers.d.ts.map +1 -1
  9. package/dist/esm/common/resolvers.js +11 -9
  10. package/dist/esm/common/resolvers.js.map +1 -1
  11. package/dist/esm/core.d.ts +6 -3
  12. package/dist/esm/core.d.ts.map +1 -1
  13. package/dist/esm/core.js +6 -3
  14. package/dist/esm/core.js.map +1 -1
  15. package/dist/esm/modules/base.js +4 -4
  16. package/dist/esm/modules/base.js.map +1 -1
  17. package/dist/esm/modules/cron/helper.js +4 -4
  18. package/dist/esm/modules/cron/helper.js.map +1 -1
  19. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
  20. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
  21. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
  22. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  23. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
  24. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  25. package/dist/esm/modules/env/app-env.d.ts.map +1 -1
  26. package/dist/esm/modules/env/app-env.js +2 -2
  27. package/dist/esm/modules/env/app-env.js.map +1 -1
  28. package/dist/esm/modules/logger/common/constants.d.ts +23 -21
  29. package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
  30. package/dist/esm/modules/logger/common/constants.js +45 -42
  31. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  32. package/dist/esm/modules/logger/factory.d.ts +5 -3
  33. package/dist/esm/modules/logger/factory.d.ts.map +1 -1
  34. package/dist/esm/modules/logger/factory.js +5 -3
  35. package/dist/esm/modules/logger/factory.js.map +1 -1
  36. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
  37. package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
  38. package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
  39. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  40. package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
  41. package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
  42. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  43. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  44. package/dist/esm/modules/logger/hf/logger.js +2 -2
  45. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  46. package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
  47. package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
  48. package/dist/esm/modules/logger/pino/backing.js +3 -8
  49. package/dist/esm/modules/logger/pino/backing.js.map +1 -1
  50. package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
  51. package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
  52. package/dist/esm/modules/logger/pino/destination.js +12 -13
  53. package/dist/esm/modules/logger/pino/destination.js.map +1 -1
  54. package/dist/esm/modules/logger/pino/logger.js +2 -2
  55. package/dist/esm/modules/logger/pino/logger.js.map +1 -1
  56. package/dist/esm/modules/logger/resolver.js +2 -2
  57. package/dist/esm/modules/logger/resolver.js.map +1 -1
  58. package/dist/esm/modules/logger/slot.d.ts +39 -18
  59. package/dist/esm/modules/logger/slot.d.ts.map +1 -1
  60. package/dist/esm/modules/logger/slot.js +117 -110
  61. package/dist/esm/modules/logger/slot.js.map +1 -1
  62. package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
  63. package/dist/esm/modules/logger/winston/common/constants.js +7 -6
  64. package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
  65. package/dist/esm/modules/logger/winston/define.d.ts +0 -7
  66. package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
  67. package/dist/esm/modules/logger/winston/define.js +0 -5
  68. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  69. package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
  70. package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
  71. package/dist/esm/modules/logger/winston/formats.js +17 -4
  72. package/dist/esm/modules/logger/winston/formats.js.map +1 -1
  73. package/dist/esm/modules/logger/winston/index.d.ts +3 -2
  74. package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
  75. package/dist/esm/modules/logger/winston/index.js +3 -2
  76. package/dist/esm/modules/logger/winston/index.js.map +1 -1
  77. package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
  78. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  79. package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
  80. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  81. package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
  82. package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
  83. package/dist/esm/modules/network/http-request/common/index.js +0 -1
  84. package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
  85. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
  86. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
  87. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  88. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  89. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
  90. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  91. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
  92. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  93. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
  94. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  95. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
  96. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  97. package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
  98. package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
  99. package/dist/esm/modules/network/utilities/query-string.js +48 -46
  100. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  101. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
  102. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
  103. package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
  104. package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
  105. package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts.map +1 -1
  106. package/dist/esm/modules/network/utilities/url-safety/ingest.js +2 -1
  107. package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
  108. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
  109. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
  110. package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
  111. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  112. package/dist/esm/modules/pool/abstract.d.ts.map +1 -1
  113. package/dist/esm/modules/pool/abstract.js +4 -2
  114. package/dist/esm/modules/pool/abstract.js.map +1 -1
  115. package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
  116. package/dist/esm/modules/queue/bullmq/helper.js +6 -6
  117. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  118. package/dist/esm/modules/queue/common/hook.d.ts +14 -12
  119. package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
  120. package/dist/esm/modules/queue/common/hook.js +21 -19
  121. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  122. package/dist/esm/modules/queue/common/index.d.ts +0 -1
  123. package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
  124. package/dist/esm/modules/queue/common/index.js +0 -1
  125. package/dist/esm/modules/queue/common/index.js.map +1 -1
  126. package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
  127. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  128. package/dist/esm/modules/queue/kafka/base.js +3 -3
  129. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  130. package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
  131. package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
  132. package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
  133. package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
  134. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
  135. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
  136. package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
  137. package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
  138. package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
  139. package/dist/esm/modules/queue/kafka/consumer.js +26 -24
  140. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  141. package/dist/esm/modules/queue/mqtt/helper.js +10 -10
  142. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  143. package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
  144. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  145. package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
  146. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  147. package/dist/esm/modules/redis/factory.d.ts +13 -9
  148. package/dist/esm/modules/redis/factory.d.ts.map +1 -1
  149. package/dist/esm/modules/redis/factory.js +15 -13
  150. package/dist/esm/modules/redis/factory.js.map +1 -1
  151. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
  152. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  153. package/dist/esm/modules/redis/single/single.helper.js +2 -2
  154. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  155. package/dist/esm/modules/redis/utility.d.ts +13 -11
  156. package/dist/esm/modules/redis/utility.d.ts.map +1 -1
  157. package/dist/esm/modules/redis/utility.js +46 -44
  158. package/dist/esm/modules/redis/utility.js.map +1 -1
  159. package/dist/esm/modules/retry/helper.d.ts.map +1 -1
  160. package/dist/esm/modules/retry/helper.js +6 -4
  161. package/dist/esm/modules/retry/helper.js.map +1 -1
  162. package/dist/esm/modules/secrets/factory.d.ts +5 -3
  163. package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
  164. package/dist/esm/modules/secrets/factory.js +36 -34
  165. package/dist/esm/modules/secrets/factory.js.map +1 -1
  166. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts.map +1 -1
  167. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +4 -2
  168. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  169. package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
  170. package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
  171. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  172. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
  173. package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
  174. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  175. package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
  176. package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
  177. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  178. package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
  179. package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
  180. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  181. package/dist/esm/modules/storage/base.d.ts.map +1 -1
  182. package/dist/esm/modules/storage/base.js +9 -8
  183. package/dist/esm/modules/storage/base.js.map +1 -1
  184. package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
  185. package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
  186. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  187. package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
  188. package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
  189. package/dist/esm/modules/storage/bun-s3/utility.js +261 -244
  190. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  191. package/dist/esm/modules/storage/common/errors.d.ts +0 -4
  192. package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
  193. package/dist/esm/modules/storage/common/errors.js +0 -10
  194. package/dist/esm/modules/storage/common/errors.js.map +1 -1
  195. package/dist/esm/modules/storage/common/utility.d.ts +11 -5
  196. package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
  197. package/dist/esm/modules/storage/common/utility.js +30 -17
  198. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  199. package/dist/esm/modules/storage/disk/helper.d.ts.map +1 -1
  200. package/dist/esm/modules/storage/disk/helper.js +18 -9
  201. package/dist/esm/modules/storage/disk/helper.js.map +1 -1
  202. package/dist/esm/modules/tree/builder.d.ts.map +1 -1
  203. package/dist/esm/modules/tree/builder.js +2 -1
  204. package/dist/esm/modules/tree/builder.js.map +1 -1
  205. package/dist/esm/modules/uid/opaque.d.ts.map +1 -1
  206. package/dist/esm/modules/uid/opaque.js +4 -2
  207. package/dist/esm/modules/uid/opaque.js.map +1 -1
  208. package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
  209. package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
  210. package/dist/esm/modules/uid/uuid/helper.js +7 -7
  211. package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
  212. package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
  213. package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
  214. package/dist/esm/modules/uid/uuid/v4.js +51 -46
  215. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  216. package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
  217. package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
  218. package/dist/esm/modules/uid/uuid/v5.js +83 -78
  219. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  220. package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
  221. package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
  222. package/dist/esm/modules/uid/uuid/v7.js +88 -79
  223. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  224. package/dist/esm/modules/worker-thread/bus/base.js +2 -2
  225. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  226. package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
  227. package/dist/esm/modules/worker-thread/worker/base.js +4 -3
  228. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  229. package/dist/esm/utilities/error.utility.d.ts +7 -0
  230. package/dist/esm/utilities/error.utility.d.ts.map +1 -0
  231. package/dist/esm/utilities/error.utility.js +9 -0
  232. package/dist/esm/utilities/error.utility.js.map +1 -0
  233. package/dist/esm/utilities/form-body.utility.d.ts +12 -10
  234. package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
  235. package/dist/esm/utilities/form-body.utility.js +19 -16
  236. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  237. package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
  238. package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
  239. package/dist/esm/utilities/hr-time.utility.js +11 -9
  240. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  241. package/dist/esm/utilities/index.d.ts +2 -2
  242. package/dist/esm/utilities/index.d.ts.map +1 -1
  243. package/dist/esm/utilities/index.js +2 -2
  244. package/dist/esm/utilities/index.js.map +1 -1
  245. package/dist/esm/utilities/module.utility.d.ts.map +1 -1
  246. package/dist/esm/utilities/module.utility.js +4 -2
  247. package/dist/esm/utilities/module.utility.js.map +1 -1
  248. package/dist/esm/utilities/parse.utility.d.ts +89 -43
  249. package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
  250. package/dist/esm/utilities/parse.utility.js +173 -141
  251. package/dist/esm/utilities/parse.utility.js.map +1 -1
  252. package/dist/esm/utilities/performance.utility.d.ts +15 -13
  253. package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
  254. package/dist/esm/utilities/performance.utility.js +34 -29
  255. package/dist/esm/utilities/performance.utility.js.map +1 -1
  256. package/dist/esm/utilities/promise.utility.d.ts +20 -18
  257. package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
  258. package/dist/esm/utilities/promise.utility.js +41 -51
  259. package/dist/esm/utilities/promise.utility.js.map +1 -1
  260. package/dist/esm/utilities/request.utility.d.ts +35 -29
  261. package/dist/esm/utilities/request.utility.d.ts.map +1 -1
  262. package/dist/esm/utilities/request.utility.js +117 -115
  263. package/dist/esm/utilities/request.utility.js.map +1 -1
  264. package/package.json +4 -15
  265. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
  266. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
  267. package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
  268. package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
  269. package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
  270. package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
  271. package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
  272. package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
  273. package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
  274. package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
  275. package/dist/esm/modules/network/http-request/common/types.js +0 -2
  276. package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
  277. package/dist/esm/modules/queue/common/types.d.ts +0 -2
  278. package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
  279. package/dist/esm/modules/queue/common/types.js +0 -2
  280. package/dist/esm/modules/queue/common/types.js.map +0 -1
  281. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
  282. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
  283. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
  284. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
  285. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
  286. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
  287. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
  288. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
  289. package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
  290. package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
  291. package/dist/esm/modules/storage/minio/helper.js +0 -176
  292. package/dist/esm/modules/storage/minio/helper.js.map +0 -1
  293. package/dist/esm/modules/storage/minio/index.d.ts +0 -2
  294. package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
  295. package/dist/esm/modules/storage/minio/index.js +0 -2
  296. package/dist/esm/modules/storage/minio/index.js.map +0 -1
  297. package/dist/esm/utilities/sleep.utility.d.ts +0 -2
  298. package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
  299. package/dist/esm/utilities/sleep.utility.js +0 -4
  300. package/dist/esm/utilities/sleep.utility.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"opaque.js","sourceRoot":"","sources":["../../../../src/modules/uid/opaque.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,E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M,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACvF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,eAAe,CAAC,IAAI,6DAA6D,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,kEAAkE;aAChL,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport type { ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '../base';\nimport { getError } from '../error';\nimport {\n DEFAULT_UID_DELIMITER,\n DEFAULT_UID_LENGTH,\n DEFAULT_UID_MAX_ATTEMPTS,\n MIN_UID_ALPHABET_SIZE,\n UidAlphabets,\n UidCaseForms,\n} from './common/constants';\nimport type { TUidCaseForm } from './common/constants';\nimport type { INextOpaqueUidOptions, IOpaqueUidOptions, IUidSegment } from './common/types';\n\n/** How many random bytes to draw per refill, per remaining character. Rejection throws some away, so asking for exactly `length` would round-trip to the entropy source repeatedly. */\nconst SAMPLING_OVERDRAW = 2;\n\n/** Local, not `@/utilities/promise.utility`: that module imports the logger BARREL, which reaches `node:module` and would take this browser-pure module with it. */\nconst isPromiseLike = (value: unknown): value is PromiseLike<boolean> => {\n return typeof (value as PromiseLike<boolean> | null | undefined)?.then === 'function';\n};\n\n/**\n * Fixed-length opaque ids, optionally prefixed - the counterpart to `SnowflakeUidHelper`.\n *\n * OPAQUE is the difference that matters, not the randomness. A Snowflake id is TRANSPARENT: its own\n * `parseId()` reads back the exact millisecond it was minted and the worker that minted it. That is\n * what you want in a log and not what you want on an invoice. Nothing can be read out of an id from\n * here. The cost is the ordering, which a Snowflake gives an index for free.\n *\n * `length` counts the BODY only. A prefix and a delimiter sit in front of it, so the finished string\n * is `prefix + delimiter + length` characters.\n *\n * Read {@link DEFAULT_UID_LENGTH} before accepting the default: six characters is an airline record\n * locator, and it needs the same scoping and retry that airlines give one.\n */\nexport class OpaqueUidHelper extends BaseHelper {\n private readonly alphabet: string;\n private readonly length: number;\n private readonly prefix: string;\n private readonly delimiter: string;\n\n /** Rejection mask: the smallest `2^n - 1` that covers every alphabet index. A plain `byte % size` would favour the first `256 % size` characters, which is a bias a caller cannot see and cannot undo. */\n private readonly mask: number;\n\n constructor(opts?: IOpaqueUidOptions) {\n super({ scope: OpaqueUidHelper.name });\n\n const caseForm = opts?.caseForm ?? UidCaseForms.UPPER;\n OpaqueUidHelper.assertKnownCaseForm({ caseForm });\n\n this.alphabet = OpaqueUidHelper.resolveAlphabet({\n alphabet: opts?.alphabet ?? UidAlphabets.CROCKFORD,\n exclude: opts?.exclude ?? '',\n caseForm,\n });\n\n this.length = opts?.length ?? DEFAULT_UID_LENGTH;\n if (!Number.isInteger(this.length) || this.length < 1) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] length must be a positive integer | value: ${this.length}`,\n });\n }\n\n this.prefix = OpaqueUidHelper.resolvePrefix({ prefix: opts?.prefix, caseForm });\n this.delimiter = OpaqueUidHelper.resolveDelimiter({\n delimiter: opts?.delimiter,\n hasPrefix: this.prefix.length > 0,\n alphabet: this.alphabet,\n });\n\n this.mask = (1 << Math.ceil(Math.log2(this.alphabet.length))) - 1;\n }\n\n /**\n * `prefix` replaces the configured value for this call and turns the prefix on for it; the\n * delimiter follows its own switch.\n *\n * `isAvailable` redraws until it accepts an id, up to `maxAttempts`. It LOWERS the collision rate,\n * it does not remove it: against a database the check and the insert are two statements, and\n * another request can take the id in between. The column still needs a unique index, and the\n * insert still needs to regenerate on violation.\n */\n nextId(opts?: INextOpaqueUidOptions<boolean>): string;\n nextId(opts: INextOpaqueUidOptions<Promise<boolean>>): Promise<string>;\n nextId(opts: INextOpaqueUidOptions): ValueOrPromise<string>;\n nextId(opts?: INextOpaqueUidOptions): ValueOrPromise<string> {\n const head = this.resolveHead({ prefix: opts?.prefix });\n\n const isAvailable = opts?.isAvailable;\n if (!isAvailable) {\n // Refused rather than ignored: without a check there is exactly ONE draw, so a caller who set\n // `maxAttempts` has configured a retry that cannot happen and has no way to notice.\n if (opts?.maxAttempts !== undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] maxAttempts has no effect without \\`isAvailable\\` | Nothing rejects a draw, so there is only ever one`,\n });\n }\n\n return `${head}${this.randomBody()}`;\n }\n\n const maxAttempts = OpaqueUidHelper.resolveMaxAttempts({ maxAttempts: opts?.maxAttempts });\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n const id = `${head}${this.randomBody()}`;\n const verdict = isAvailable(id);\n\n // The first PENDING verdict decides the shape of the whole call. Everything before it already\n // resolved, so a synchronous check never allocates a promise and `nextId()` stays a string.\n if (isPromiseLike(verdict)) {\n return this.continueAsync({ head, isAvailable, maxAttempts, attempt, id, verdict });\n }\n\n if (verdict) {\n return id;\n }\n }\n\n throw this.buildExhaustedError({ maxAttempts });\n }\n\n /** Entered only once a verdict came back pending; every later draw is awaited from here. */\n private async continueAsync(opts: {\n head: string;\n isAvailable: (id: string) => ValueOrPromise<boolean>;\n maxAttempts: number;\n attempt: number;\n id: string;\n verdict: PromiseLike<boolean>;\n }): Promise<string> {\n const { head, isAvailable, maxAttempts, attempt, id, verdict } = opts;\n\n if (await verdict) {\n return id;\n }\n\n for (let next = attempt + 1; next <= maxAttempts; next++) {\n const candidate = `${head}${this.randomBody()}`;\n\n if (await isAvailable(candidate)) {\n return candidate;\n }\n }\n\n throw this.buildExhaustedError({ maxAttempts });\n }\n\n private resolveHead(opts: { prefix?: string }): string {\n const override = opts.prefix;\n\n if (override === '') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] An empty prefix is not how a prefix is turned off | Construct with \\`prefix: { enable: false }\\``,\n });\n }\n\n const prefix = override ?? this.prefix;\n return prefix.length > 0 ? `${prefix}${this.delimiter}` : '';\n }\n\n private static resolveMaxAttempts(opts: { maxAttempts?: number }): number {\n const maxAttempts = opts.maxAttempts ?? DEFAULT_UID_MAX_ATTEMPTS;\n\n if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] maxAttempts must be a positive integer | value: ${maxAttempts}`,\n });\n }\n\n return maxAttempts;\n }\n\n /** Bounded rather than endless: repeated rejection means the space is full, and a caller waiting forever learns that far later than a caller holding this error. */\n private buildExhaustedError(opts: { maxAttempts: number }) {\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] No available id after ${opts.maxAttempts} attempts | length: ${this.length} | alphabet: ${this.alphabet.length} | The space is crowded - raise \\`length\\``,\n });\n }\n\n /** The alphabet actually in use, after the case fold and every exclusion - what `length` is measured against. */\n getAlphabet(): string {\n return this.alphabet;\n }\n\n private randomBody(): string {\n const size = this.alphabet.length;\n let body = '';\n\n while (body.length < this.length) {\n const bytes = OpaqueUidHelper.randomBytes({\n count: (this.length - body.length) * SAMPLING_OVERDRAW,\n });\n\n for (const byte of bytes) {\n const index = byte & this.mask;\n\n // Rejection, not wrap-around: an index past the alphabet is discarded so every character\n // stays equally likely.\n if (index >= size) {\n continue;\n }\n\n body += this.alphabet[index];\n if (body.length === this.length) {\n break;\n }\n }\n }\n\n return body;\n }\n\n /**\n * `crypto.getRandomValues`, never `Math.random`. Unlike `crypto.randomUUID`, this one is NOT\n * restricted to a secure context, so it works on a plain-http origin and inside a browser Worker.\n */\n private static randomBytes(opts: { count: number }): Uint8Array {\n const source = globalThis.crypto;\n\n if (typeof source?.getRandomValues !== 'function') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] No Web Crypto available | \\`crypto.getRandomValues\\` is required and \\`Math.random\\` is not an acceptable substitute for an identifier`,\n });\n }\n\n return source.getRandomValues(new Uint8Array(opts.count));\n }\n\n private static hasBothCases(opts: { alphabet: string }): boolean {\n let hasUpper = false;\n let hasLower = false;\n\n for (const character of opts.alphabet) {\n hasUpper ||= character !== character.toLowerCase();\n hasLower ||= character !== character.toUpperCase();\n\n if (hasUpper && hasLower) {\n return true;\n }\n }\n\n return false;\n }\n\n private static assertKnownCaseForm(opts: { caseForm: TUidCaseForm }): void {\n if (UidCaseForms.isValid(opts.caseForm)) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] Unknown caseForm | value: ${opts.caseForm} | valid: ${[...UidCaseForms.SCHEME_SET].join(', ')}`,\n });\n }\n\n /**\n * Folds case FIRST, then excludes, then de-duplicates - folding after sampling would misreport the\n * entropy and undo the alphabet's own exclusions.\n *\n * Refuses to fold a two-case alphabet at all, because folding one puts back exactly what it took\n * out: uppercasing `BASE58` turns its lowercase letters into `I` and `O`, the two it drops to keep\n * `1` and `0` unambiguous, and lowercasing it brings back `l`. Measured - the result is 35\n * characters, not the 33 an entropy calculation would predict. A single-case alphabet folds\n * cleanly because there is nothing to collide with.\n */\n private static resolveAlphabet(opts: {\n alphabet: string;\n exclude: string;\n caseForm: TUidCaseForm;\n }): string {\n const { alphabet, exclude, caseForm } = opts;\n\n if (caseForm !== UidCaseForms.MIXED && OpaqueUidHelper.hasBothCases({ alphabet })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] caseForm '${caseForm}' cannot fold a two-case alphabet | Folding reintroduces the characters the alphabet excluded | Use \\`UidAlphabets.CROCKFORD\\` for a single-case alphabet, or \\`caseForm: '${UidCaseForms.MIXED}'\\``,\n });\n }\n\n const folded =\n caseForm === UidCaseForms.UPPER\n ? alphabet.toUpperCase()\n : caseForm === UidCaseForms.LOWER\n ? alphabet.toLowerCase()\n : alphabet;\n\n const removed = new Set(exclude);\n const resolved = [...new Set(folded)].filter((character) => !removed.has(character)).join('');\n\n if (resolved.length < MIN_UID_ALPHABET_SIZE) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] Alphabet too small | size: ${resolved.length} | minimum: ${MIN_UID_ALPHABET_SIZE} | Widen \\`alphabet\\` or shorten \\`exclude\\``,\n });\n }\n\n return resolved;\n }\n\n /** An enabled prefix in the wrong case defeats the reason for choosing one: an id meant to survive a case-insensitive column stops being one the moment its prefix disagrees. */\n private static resolvePrefix(opts: { prefix?: IUidSegment; caseForm: TUidCaseForm }): string {\n const { prefix, caseForm } = opts;\n\n if (!prefix?.enable) {\n return '';\n }\n\n const value = prefix.value ?? '';\n if (value.length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] prefix is enabled but carries no value`,\n });\n }\n\n const expected =\n caseForm === UidCaseForms.UPPER\n ? value.toUpperCase()\n : caseForm === UidCaseForms.LOWER\n ? value.toLowerCase()\n : value;\n\n if (value !== expected) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] prefix does not match caseForm | prefix: ${value} | caseForm: ${caseForm} | expected: ${expected}`,\n });\n }\n\n return value;\n }\n\n /**\n * Two refusals here, both because the alternative fails silently: a delimiter with no prefix is a\n * leading character that separates nothing, and a delimiter drawn from the alphabet makes the id\n * impossible to split back into prefix and body.\n */\n private static resolveDelimiter(opts: {\n delimiter?: IUidSegment;\n hasPrefix: boolean;\n alphabet: string;\n }): string {\n const { delimiter, hasPrefix, alphabet } = opts;\n\n if (!delimiter?.enable) {\n return '';\n }\n\n if (!hasPrefix) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] delimiter is enabled without a prefix | It would lead the id and separate nothing | Put the character in \\`prefix.value\\` if that is what you want`,\n });\n }\n\n const value = delimiter.value ?? DEFAULT_UID_DELIMITER;\n if (value.length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] delimiter is enabled but carries no value`,\n });\n }\n\n const shared = [...new Set(value)].filter((character) => alphabet.includes(character));\n if (shared.length > 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] delimiter shares characters with the alphabet | shared: ${shared.join('')} | An id built with it cannot be split back into prefix and body`,\n });\n }\n\n return value;\n }\n}\n"]}
1
+ {"version":3,"file":"opaque.js","sourceRoot":"","sources":["../../../../src/modules/uid/opaque.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,EACZ,YAAY,GACb,MAAM,oBAAoB,CAAC;AAI5B,uLAAuL;AACvL,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,oKAAoK;AACpK,MAAM,aAAa,GAAG,CAAC,KAAc,EAAiC,EAAE;IACtE,OAAO,OAAQ,KAAiD,EAAE,IAAI,KAAK,UAAU,CAAC;AACxF,CAAC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAS7C,YAAY,IAAwB;QAClC,KAAK,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;QAEvC,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,YAAY,CAAC,KAAK,CAAC;QACtD,e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I/B;QACC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEhD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,eAAe,CAAC,IAAI,sJAAsJ;aACxL,CAAC,CAAC;QACL,CAAC;QAED,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,IAAI,qBAAqB,CAAC;QACvD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,eAAe,CAAC,IAAI,6CAA6C;aAC/E,CAAC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACvF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,eAAe,CAAC,IAAI,6DAA6D,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,kEAAkE;aAChL,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport type { ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '../base';\nimport { getError } from '../error';\nimport {\n DEFAULT_UID_DELIMITER,\n DEFAULT_UID_LENGTH,\n DEFAULT_UID_MAX_ATTEMPTS,\n MIN_UID_ALPHABET_SIZE,\n UidAlphabets,\n UidCaseForms,\n} from './common/constants';\nimport type { TUidCaseForm } from './common/constants';\nimport type { INextOpaqueUidOptions, IOpaqueUidOptions, IUidSegment } from './common/types';\n\n/** How many random bytes to draw per refill, per remaining character. Rejection throws some away, so asking for exactly `length` would round-trip to the entropy source repeatedly. */\nconst SAMPLING_OVERDRAW = 2;\n\n/** Local, not `@/utilities/promise.utility`: that module imports the logger BARREL, which reaches `node:module` and would take this browser-pure module with it. */\nconst isPromiseLike = (value: unknown): value is PromiseLike<boolean> => {\n return typeof (value as PromiseLike<boolean> | null | undefined)?.then === 'function';\n};\n\n/**\n * Fixed-length opaque ids, optionally prefixed - the counterpart to `SnowflakeUidHelper`.\n *\n * OPAQUE is the difference that matters, not the randomness. A Snowflake id is TRANSPARENT: its own\n * `parseId()` reads back the exact millisecond it was minted and the worker that minted it. That is\n * what you want in a log and not what you want on an invoice. Nothing can be read out of an id from\n * here. The cost is the ordering, which a Snowflake gives an index for free.\n *\n * `length` counts the BODY only. A prefix and a delimiter sit in front of it, so the finished string\n * is `prefix + delimiter + length` characters.\n *\n * Read {@link DEFAULT_UID_LENGTH} before accepting the default: six characters is an airline record\n * locator, and it needs the same scoping and retry that airlines give one.\n */\nexport class OpaqueUidHelper extends BaseHelper {\n private readonly alphabet: string;\n private readonly length: number;\n private readonly prefix: string;\n private readonly delimiter: string;\n\n /** Rejection mask: the smallest `2^n - 1` that covers every alphabet index. A plain `byte % size` would favour the first `256 % size` characters, which is a bias a caller cannot see and cannot undo. */\n private readonly mask: number;\n\n constructor(opts?: IOpaqueUidOptions) {\n super({ scope: OpaqueUidHelper.name });\n\n const caseForm = opts?.caseForm ?? UidCaseForms.UPPER;\n OpaqueUidHelper.assertKnownCaseForm({ caseForm });\n\n this.alphabet = OpaqueUidHelper.resolveAlphabet({\n alphabet: opts?.alphabet ?? UidAlphabets.CROCKFORD,\n exclude: opts?.exclude ?? '',\n caseForm,\n });\n\n this.length = opts?.length ?? DEFAULT_UID_LENGTH;\n if (!Number.isInteger(this.length) || this.length < 1) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] length must be a positive integer | value: ${this.length}`,\n });\n }\n\n this.prefix = OpaqueUidHelper.resolvePrefix({ prefix: opts?.prefix, caseForm });\n this.delimiter = OpaqueUidHelper.resolveDelimiter({\n delimiter: opts?.delimiter,\n hasPrefix: this.prefix.length > 0,\n alphabet: this.alphabet,\n });\n\n this.mask = (1 << Math.ceil(Math.log2(this.alphabet.length))) - 1;\n }\n\n /**\n * `prefix` replaces the configured value for this call and turns the prefix on for it; the\n * delimiter follows its own switch.\n *\n * `isAvailable` redraws until it accepts an id, up to `maxAttempts`. It LOWERS the collision rate,\n * it does not remove it: against a database the check and the insert are two statements, and\n * another request can take the id in between. The column still needs a unique index, and the\n * insert still needs to regenerate on violation.\n */\n nextId(opts?: INextOpaqueUidOptions<boolean>): string;\n nextId(opts: INextOpaqueUidOptions<Promise<boolean>>): Promise<string>;\n nextId(opts: INextOpaqueUidOptions): ValueOrPromise<string>;\n nextId(opts?: INextOpaqueUidOptions): ValueOrPromise<string> {\n const head = this.resolveHead({ prefix: opts?.prefix });\n\n const isAvailable = opts?.isAvailable;\n if (!isAvailable) {\n // Refused rather than ignored: without a check there is exactly ONE draw, so a caller who set\n // `maxAttempts` has configured a retry that cannot happen and has no way to notice.\n if (opts?.maxAttempts !== undefined) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] maxAttempts has no effect without \\`isAvailable\\` | Nothing rejects a draw, so there is only ever one`,\n });\n }\n\n return `${head}${this.randomBody()}`;\n }\n\n const maxAttempts = OpaqueUidHelper.resolveMaxAttempts({ maxAttempts: opts?.maxAttempts });\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n const id = `${head}${this.randomBody()}`;\n const verdict = isAvailable(id);\n\n // The first PENDING verdict decides the shape of the whole call. Everything before it already\n // resolved, so a synchronous check never allocates a promise and `nextId()` stays a string.\n if (isPromiseLike(verdict)) {\n return this.continueAsync({ head, isAvailable, maxAttempts, attempt, id, verdict });\n }\n\n if (verdict) {\n return id;\n }\n }\n\n throw this.buildExhaustedError({ maxAttempts });\n }\n\n /** Entered only once a verdict came back pending; every later draw is awaited from here. */\n private async continueAsync(opts: {\n head: string;\n isAvailable: (id: string) => ValueOrPromise<boolean>;\n maxAttempts: number;\n attempt: number;\n id: string;\n verdict: PromiseLike<boolean>;\n }): Promise<string> {\n const { head, isAvailable, maxAttempts, attempt, id, verdict } = opts;\n\n const result = await verdict;\n if (result) {\n return id;\n }\n\n for (let next = attempt + 1; next <= maxAttempts; next++) {\n const candidate = `${head}${this.randomBody()}`;\n\n const result2 = await isAvailable(candidate);\n if (result2) {\n return candidate;\n }\n }\n\n throw this.buildExhaustedError({ maxAttempts });\n }\n\n private resolveHead(opts: { prefix?: string }): string {\n const override = opts.prefix;\n\n if (override === '') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] An empty prefix is not how a prefix is turned off | Construct with \\`prefix: { enable: false }\\``,\n });\n }\n\n const prefix = override ?? this.prefix;\n return prefix.length > 0 ? `${prefix}${this.delimiter}` : '';\n }\n\n private static resolveMaxAttempts(opts: { maxAttempts?: number }): number {\n const maxAttempts = opts.maxAttempts ?? DEFAULT_UID_MAX_ATTEMPTS;\n\n if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] maxAttempts must be a positive integer | value: ${maxAttempts}`,\n });\n }\n\n return maxAttempts;\n }\n\n /** Bounded rather than endless: repeated rejection means the space is full, and a caller waiting forever learns that far later than a caller holding this error. */\n private buildExhaustedError(opts: { maxAttempts: number }) {\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}][nextId] No available id after ${opts.maxAttempts} attempts | length: ${this.length} | alphabet: ${this.alphabet.length} | The space is crowded - raise \\`length\\``,\n });\n }\n\n /** The alphabet actually in use, after the case fold and every exclusion - what `length` is measured against. */\n getAlphabet(): string {\n return this.alphabet;\n }\n\n private randomBody(): string {\n const size = this.alphabet.length;\n let body = '';\n\n while (body.length < this.length) {\n const bytes = OpaqueUidHelper.randomBytes({\n count: (this.length - body.length) * SAMPLING_OVERDRAW,\n });\n\n for (const byte of bytes) {\n const index = byte & this.mask;\n\n // Rejection, not wrap-around: an index past the alphabet is discarded so every character\n // stays equally likely.\n if (index >= size) {\n continue;\n }\n\n body += this.alphabet[index];\n if (body.length === this.length) {\n break;\n }\n }\n }\n\n return body;\n }\n\n /**\n * `crypto.getRandomValues`, never `Math.random`. Unlike `crypto.randomUUID`, this one is NOT\n * restricted to a secure context, so it works on a plain-http origin and inside a browser Worker.\n */\n private static randomBytes(opts: { count: number }): Uint8Array {\n const source = globalThis.crypto;\n\n if (typeof source?.getRandomValues !== 'function') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] No Web Crypto available | \\`crypto.getRandomValues\\` is required and \\`Math.random\\` is not an acceptable substitute for an identifier`,\n });\n }\n\n return source.getRandomValues(new Uint8Array(opts.count));\n }\n\n private static hasBothCases(opts: { alphabet: string }): boolean {\n let hasUpper = false;\n let hasLower = false;\n\n for (const character of opts.alphabet) {\n hasUpper ||= character !== character.toLowerCase();\n hasLower ||= character !== character.toUpperCase();\n\n if (hasUpper && hasLower) {\n return true;\n }\n }\n\n return false;\n }\n\n private static assertKnownCaseForm(opts: { caseForm: TUidCaseForm }): void {\n if (UidCaseForms.isValid(opts.caseForm)) {\n return;\n }\n\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] Unknown caseForm | value: ${opts.caseForm} | valid: ${[...UidCaseForms.SCHEME_SET].join(', ')}`,\n });\n }\n\n /**\n * Folds case FIRST, then excludes, then de-duplicates - folding after sampling would misreport the\n * entropy and undo the alphabet's own exclusions.\n *\n * Refuses to fold a two-case alphabet at all, because folding one puts back exactly what it took\n * out: uppercasing `BASE58` turns its lowercase letters into `I` and `O`, the two it drops to keep\n * `1` and `0` unambiguous, and lowercasing it brings back `l`. Measured - the result is 35\n * characters, not the 33 an entropy calculation would predict. A single-case alphabet folds\n * cleanly because there is nothing to collide with.\n */\n private static resolveAlphabet(opts: {\n alphabet: string;\n exclude: string;\n caseForm: TUidCaseForm;\n }): string {\n const { alphabet, exclude, caseForm } = opts;\n\n if (caseForm !== UidCaseForms.MIXED && OpaqueUidHelper.hasBothCases({ alphabet })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] caseForm '${caseForm}' cannot fold a two-case alphabet | Folding reintroduces the characters the alphabet excluded | Use \\`UidAlphabets.CROCKFORD\\` for a single-case alphabet, or \\`caseForm: '${UidCaseForms.MIXED}'\\``,\n });\n }\n\n const folded =\n caseForm === UidCaseForms.UPPER\n ? alphabet.toUpperCase()\n : caseForm === UidCaseForms.LOWER\n ? alphabet.toLowerCase()\n : alphabet;\n\n const removed = new Set(exclude);\n const resolved = [...new Set(folded)].filter((character) => !removed.has(character)).join('');\n\n if (resolved.length < MIN_UID_ALPHABET_SIZE) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] Alphabet too small | size: ${resolved.length} | minimum: ${MIN_UID_ALPHABET_SIZE} | Widen \\`alphabet\\` or shorten \\`exclude\\``,\n });\n }\n\n return resolved;\n }\n\n /** An enabled prefix in the wrong case defeats the reason for choosing one: an id meant to survive a case-insensitive column stops being one the moment its prefix disagrees. */\n private static resolvePrefix(opts: { prefix?: IUidSegment; caseForm: TUidCaseForm }): string {\n const { prefix, caseForm } = opts;\n\n if (!prefix?.enable) {\n return '';\n }\n\n const value = prefix.value ?? '';\n if (value.length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] prefix is enabled but carries no value`,\n });\n }\n\n const expected =\n caseForm === UidCaseForms.UPPER\n ? value.toUpperCase()\n : caseForm === UidCaseForms.LOWER\n ? value.toLowerCase()\n : value;\n\n if (value !== expected) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] prefix does not match caseForm | prefix: ${value} | caseForm: ${caseForm} | expected: ${expected}`,\n });\n }\n\n return value;\n }\n\n /**\n * Two refusals here, both because the alternative fails silently: a delimiter with no prefix is a\n * leading character that separates nothing, and a delimiter drawn from the alphabet makes the id\n * impossible to split back into prefix and body.\n */\n private static resolveDelimiter(opts: {\n delimiter?: IUidSegment;\n hasPrefix: boolean;\n alphabet: string;\n }): string {\n const { delimiter, hasPrefix, alphabet } = opts;\n\n if (!delimiter?.enable) {\n return '';\n }\n\n if (!hasPrefix) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] delimiter is enabled without a prefix | It would lead the id and separate nothing | Put the character in \\`prefix.value\\` if that is what you want`,\n });\n }\n\n const value = delimiter.value ?? DEFAULT_UID_DELIMITER;\n if (value.length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] delimiter is enabled but carries no value`,\n });\n }\n\n const shared = [...new Set(value)].filter((character) => alphabet.includes(character));\n if (shared.length > 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${OpaqueUidHelper.name}] delimiter shares characters with the alphabet | shared: ${shared.join('')} | An id built with it cannot be split back into prefix and body`,\n });\n }\n\n return value;\n }\n}\n"]}
@@ -4,7 +4,7 @@ import type { IUuidInspection } from './common/types.js';
4
4
  * One door for every UUID IGNIS mints: `v7()` for a database key, `v5()` for a deterministic key,
5
5
  * `v4()` for a random token.
6
6
  *
7
- * A facade over {@link uuidV4}, {@link uuidV5} and {@link uuidV7} - importing one of those from
7
+ * A facade over {@link UuidV4Generator}, {@link UuidV5Generator} and {@link UuidV7Generator} - importing one of those from
8
8
  * `@venizia/ignis-helpers/uuid` leaves the other two out of a browser bundle.
9
9
  */
10
10
  export declare class UuidHelper extends BaseHelper {
@@ -1 +1 @@
1
- {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKtD;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACxC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAa;IAErC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,MAAM,CAAU;IAEnC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAU;IAE5E,uGAAuG;IACvG,QAAQ,CAAC,EAAE,EAAE,MAAM,MAAM,CAAU;gBAEvB,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAIrC,MAAM,CAAC,WAAW,IAAI,UAAU;IAKhC,sFAAsF;IACtF,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAItC,wFAAwF;IACxF,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe,GAAG,SAAS;CAe9D"}
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKtD;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACxC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAa;IAErC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,MAAM,CAA4B;IAErD,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAA4B;IAE9F,uGAAuG;IACvG,QAAQ,CAAC,EAAE,EAAE,MAAM,MAAM,CAA4B;gBAEzC,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAIrC,MAAM,CAAC,WAAW,IAAI,UAAU;IAKhC,sFAAsF;IACtF,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAItC,wFAAwF;IACxF,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe,GAAG,SAAS;CAe9D"}
@@ -1,24 +1,24 @@
1
1
  import { BaseHelper } from '../../base.js';
2
2
  import { UUID_PATTERN } from './common/constants.js';
3
- import { uuidV4 } from './v4.js';
4
- import { uuidV5 } from './v5.js';
5
- import { uuidV7 } from './v7.js';
3
+ import { UuidV4Generator } from './v4.js';
4
+ import { UuidV5Generator } from './v5.js';
5
+ import { UuidV7Generator } from './v7.js';
6
6
  /**
7
7
  * One door for every UUID IGNIS mints: `v7()` for a database key, `v5()` for a deterministic key,
8
8
  * `v4()` for a random token.
9
9
  *
10
- * A facade over {@link uuidV4}, {@link uuidV5} and {@link uuidV7} - importing one of those from
10
+ * A facade over {@link UuidV4Generator}, {@link UuidV5Generator} and {@link UuidV7Generator} - importing one of those from
11
11
  * `@venizia/ignis-helpers/uuid` leaves the other two out of a browser bundle.
12
12
  */
13
13
  export class UuidHelper extends BaseHelper {
14
14
  constructor(opts) {
15
15
  super({ scope: opts?.scope ?? UuidHelper.name });
16
16
  /** Random - a public identifier or a token. */
17
- this.v4 = uuidV4;
17
+ this.v4 = UuidV4Generator.generate;
18
18
  /** Deterministic - same inputs, same id. Reproducible therefore not secret. */
19
- this.v5 = uuidV5;
19
+ this.v5 = UuidV5Generator.generate;
20
20
  /** Time-ordered - a database key. A burst past about 2048 ids per millisecond leads the wall clock. */
21
- this.v7 = uuidV7;
21
+ this.v7 = UuidV7Generator.generate;
22
22
  }
23
23
  static getInstance() {
24
24
  UuidHelper.instance ??= new UuidHelper();
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAiBxC,YAAY,IAAyB;QACnC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAVnD,+CAA+C;QACtC,OAAE,GAAiB,MAAM,CAAC;QAEnC,+EAA+E;QACtE,OAAE,GAA0D,MAAM,CAAC;QAE5E,uGAAuG;QAC9F,OAAE,GAAiB,MAAM,CAAC;IAInC,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,UAAU,CAAC,QAAQ,KAAK,IAAI,UAAU,EAAE,CAAC;QACzC,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,wFAAwF;IACxF,OAAO,CAAC,IAAuB;QAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;YAClB,OAAO,EAAE,OAAO,EAAE,CAAC;QACrB,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACjF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;IACxD,CAAC;CACF","sourcesContent":["import { BaseHelper } from '../../base';\nimport { UUID_PATTERN } from './common/constants';\nimport type { IUuidInspection } from './common/types';\nimport { uuidV4 } from './v4';\nimport { uuidV5 } from './v5';\nimport { uuidV7 } from './v7';\n\n/**\n * One door for every UUID IGNIS mints: `v7()` for a database key, `v5()` for a deterministic key,\n * `v4()` for a random token.\n *\n * A facade over {@link uuidV4}, {@link uuidV5} and {@link uuidV7} - importing one of those from\n * `@venizia/ignis-helpers/uuid` leaves the other two out of a browser bundle.\n */\nexport class UuidHelper extends BaseHelper {\n /**\n * Per module copy, not realm-wide: the facade holds no state - ordering lives in the shared v7\n * sequence - and a realm-wide slot would hand an older version's instance, and its generators,\n * to every newer caller.\n */\n private static instance?: UuidHelper;\n\n /** Random - a public identifier or a token. */\n readonly v4: () => string = uuidV4;\n\n /** Deterministic - same inputs, same id. Reproducible therefore not secret. */\n readonly v5: (opts: { namespace: string; name: string }) => string = uuidV5;\n\n /** Time-ordered - a database key. A burst past about 2048 ids per millisecond leads the wall clock. */\n readonly v7: () => string = uuidV7;\n\n constructor(opts?: { scope?: string }) {\n super({ scope: opts?.scope ?? UuidHelper.name });\n }\n\n static getInstance(): UuidHelper {\n UuidHelper.instance ??= new UuidHelper();\n return UuidHelper.instance;\n }\n\n /** Lowercase, version 1-8, RFC variant - the nil and max placeholders are refused. */\n static isValid(value: string): boolean {\n return UUID_PATTERN.test(value);\n }\n\n /** Reads the version, and for v7 the creation time; undefined when it is not a UUID. */\n inspect(opts: { value: string }): IUuidInspection | undefined {\n const { value } = opts;\n\n if (!UUID_PATTERN.test(value)) {\n return undefined;\n }\n\n const version = Number.parseInt(value[14], 16);\n if (version !== 7) {\n return { version };\n }\n\n const milliseconds = Number.parseInt(value.slice(0, 8) + value.slice(9, 13), 16);\n return { version, createdAt: new Date(milliseconds) };\n }\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAiBxC,YAAY,IAAyB;QACnC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAVnD,+CAA+C;QACtC,OAAE,GAAiB,eAAe,CAAC,QAAQ,CAAC;QAErD,+EAA+E;QACtE,OAAE,GAA0D,eAAe,CAAC,QAAQ,CAAC;QAE9F,uGAAuG;QAC9F,OAAE,GAAiB,eAAe,CAAC,QAAQ,CAAC;IAIrD,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,UAAU,CAAC,QAAQ,KAAK,IAAI,UAAU,EAAE,CAAC;QACzC,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,wFAAwF;IACxF,OAAO,CAAC,IAAuB;QAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;YAClB,OAAO,EAAE,OAAO,EAAE,CAAC;QACrB,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACjF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;IACxD,CAAC;CACF","sourcesContent":["import { BaseHelper } from '../../base';\nimport { UUID_PATTERN } from './common/constants';\nimport type { IUuidInspection } from './common/types';\nimport { UuidV4Generator } from './v4';\nimport { UuidV5Generator } from './v5';\nimport { UuidV7Generator } from './v7';\n\n/**\n * One door for every UUID IGNIS mints: `v7()` for a database key, `v5()` for a deterministic key,\n * `v4()` for a random token.\n *\n * A facade over {@link UuidV4Generator}, {@link UuidV5Generator} and {@link UuidV7Generator} - importing one of those from\n * `@venizia/ignis-helpers/uuid` leaves the other two out of a browser bundle.\n */\nexport class UuidHelper extends BaseHelper {\n /**\n * Per module copy, not realm-wide: the facade holds no state - ordering lives in the shared v7\n * sequence - and a realm-wide slot would hand an older version's instance, and its generators,\n * to every newer caller.\n */\n private static instance?: UuidHelper;\n\n /** Random - a public identifier or a token. */\n readonly v4: () => string = UuidV4Generator.generate;\n\n /** Deterministic - same inputs, same id. Reproducible therefore not secret. */\n readonly v5: (opts: { namespace: string; name: string }) => string = UuidV5Generator.generate;\n\n /** Time-ordered - a database key. A burst past about 2048 ids per millisecond leads the wall clock. */\n readonly v7: () => string = UuidV7Generator.generate;\n\n constructor(opts?: { scope?: string }) {\n super({ scope: opts?.scope ?? UuidHelper.name });\n }\n\n static getInstance(): UuidHelper {\n UuidHelper.instance ??= new UuidHelper();\n return UuidHelper.instance;\n }\n\n /** Lowercase, version 1-8, RFC variant - the nil and max placeholders are refused. */\n static isValid(value: string): boolean {\n return UUID_PATTERN.test(value);\n }\n\n /** Reads the version, and for v7 the creation time; undefined when it is not a UUID. */\n inspect(opts: { value: string }): IUuidInspection | undefined {\n const { value } = opts;\n\n if (!UUID_PATTERN.test(value)) {\n return undefined;\n }\n\n const version = Number.parseInt(value[14], 16);\n if (version !== 7) {\n return { version };\n }\n\n const milliseconds = Number.parseInt(value.slice(0, 8) + value.slice(9, 13), 16);\n return { version, createdAt: new Date(milliseconds) };\n }\n}\n"]}
@@ -1,9 +1,12 @@
1
- /**
2
- * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context
3
- * never changes - and called with no argument, since Node validates it and `['a'].map(uuidV4)` would
4
- * throw.
5
- */
6
- export declare const createUuidV4: () => (() => string);
7
- /** Mints a random UUID v4 - a public identifier or a token. */
8
- export declare const uuidV4: () => string;
1
+ export declare class UuidV4Generator {
2
+ /**
3
+ * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context
4
+ * never changes - and called with no argument, since Node validates it and `['a'].map(...)` would
5
+ * throw.
6
+ */
7
+ static create(): () => string;
8
+ private static readonly shared;
9
+ /** Mints a random UUID v4 - a public identifier or a token. Reads no `this`, so `['a'].map(UuidV4Generator.generate)` is safe. */
10
+ static generate(): string;
11
+ }
9
12
  //# sourceMappingURL=v4.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"v4.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v4.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAAO,CAAC,MAAM,MAAM,CA8C5C,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,MAAM,EAAE,MAAM,MAAuB,CAAC"}
1
+ {"version":3,"file":"v4.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v4.ts"],"names":[],"mappings":"AAIA,qBAAa,eAAe;IAC1B;;;;OAIG;IACH,MAAM,CAAC,MAAM,IAAI,MAAM,MAAM;IAgD7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAA0C;IAExE,kIAAkI;IAClI,MAAM,CAAC,QAAQ,IAAI,MAAM;CAG1B"}
@@ -1,50 +1,55 @@
1
1
  import { UUID_HEX_OCTETS } from './common/constants.js';
2
2
  const POOL_SIZE = 16 * 256;
3
- /**
4
- * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context
5
- * never changes - and called with no argument, since Node validates it and `['a'].map(uuidV4)` would
6
- * throw.
7
- */
8
- export const createUuidV4 = () => {
9
- const randomUuid = globalThis.crypto?.randomUUID;
10
- if (typeof randomUuid === 'function') {
11
- const native = randomUuid.bind(globalThis.crypto);
12
- return () => native();
13
- }
14
- const pool = new Uint8Array(POOL_SIZE);
15
- let offset = POOL_SIZE;
16
- return () => {
17
- if (offset > POOL_SIZE - 16) {
18
- globalThis.crypto.getRandomValues(pool);
19
- offset = 0;
3
+ export class UuidV4Generator {
4
+ /**
5
+ * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context
6
+ * never changes - and called with no argument, since Node validates it and `['a'].map(...)` would
7
+ * throw.
8
+ */
9
+ static create() {
10
+ const randomUuid = globalThis.crypto?.randomUUID;
11
+ if (typeof randomUuid === 'function') {
12
+ const native = randomUuid.bind(globalThis.crypto);
13
+ return () => native();
20
14
  }
21
- const at = offset;
22
- offset = at + 16;
23
- const version = (pool[at + 6] & 0x0f) | 0x40;
24
- const variant = (pool[at + 8] & 0x3f) | 0x80;
25
- const hex = UUID_HEX_OCTETS;
26
- return (hex[pool[at]] +
27
- hex[pool[at + 1]] +
28
- hex[pool[at + 2]] +
29
- hex[pool[at + 3]] +
30
- '-' +
31
- hex[pool[at + 4]] +
32
- hex[pool[at + 5]] +
33
- '-' +
34
- hex[version] +
35
- hex[pool[at + 7]] +
36
- '-' +
37
- hex[variant] +
38
- hex[pool[at + 9]] +
39
- '-' +
40
- hex[pool[at + 10]] +
41
- hex[pool[at + 11]] +
42
- hex[pool[at + 12]] +
43
- hex[pool[at + 13]] +
44
- hex[pool[at + 14]] +
45
- hex[pool[at + 15]]);
46
- };
47
- };
48
- /** Mints a random UUID v4 - a public identifier or a token. */
49
- export const uuidV4 = createUuidV4();
15
+ const pool = new Uint8Array(POOL_SIZE);
16
+ let offset = POOL_SIZE;
17
+ return () => {
18
+ if (offset > POOL_SIZE - 16) {
19
+ globalThis.crypto.getRandomValues(pool);
20
+ offset = 0;
21
+ }
22
+ const at = offset;
23
+ offset = at + 16;
24
+ const version = (pool[at + 6] & 0x0f) | 0x40;
25
+ const variant = (pool[at + 8] & 0x3f) | 0x80;
26
+ const hex = UUID_HEX_OCTETS;
27
+ return (hex[pool[at]] +
28
+ hex[pool[at + 1]] +
29
+ hex[pool[at + 2]] +
30
+ hex[pool[at + 3]] +
31
+ '-' +
32
+ hex[pool[at + 4]] +
33
+ hex[pool[at + 5]] +
34
+ '-' +
35
+ hex[version] +
36
+ hex[pool[at + 7]] +
37
+ '-' +
38
+ hex[variant] +
39
+ hex[pool[at + 9]] +
40
+ '-' +
41
+ hex[pool[at + 10]] +
42
+ hex[pool[at + 11]] +
43
+ hex[pool[at + 12]] +
44
+ hex[pool[at + 13]] +
45
+ hex[pool[at + 14]] +
46
+ hex[pool[at + 15]]);
47
+ };
48
+ }
49
+ static { this.shared = UuidV4Generator.create(); }
50
+ /** Mints a random UUID v4 - a public identifier or a token. Reads no `this`, so `['a'].map(UuidV4Generator.generate)` is safe. */
51
+ static generate() {
52
+ return UuidV4Generator.shared();
53
+ }
54
+ }
50
55
  //# sourceMappingURL=v4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"v4.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAmB,EAAE;IAC/C,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC;IACjD,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;IACvC,IAAI,MAAM,GAAG,SAAS,CAAC;IAEvB,OAAO,GAAG,EAAE;QACV,IAAI,MAAM,GAAG,SAAS,GAAG,EAAE,EAAE,CAAC;YAC5B,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,C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,GAAG,EAAE,CAAC,CAAC;YAClB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,MAAM,GAAiB,YAAY,EAAE,CAAC","sourcesContent":["import { UUID_HEX_OCTETS } from './common/constants';\n\nconst POOL_SIZE = 16 * 256;\n\n/**\n * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context\n * never changes - and called with no argument, since Node validates it and `['a'].map(uuidV4)` would\n * throw.\n */\nexport const createUuidV4 = (): (() => string) => {\n const randomUuid = globalThis.crypto?.randomUUID;\n if (typeof randomUuid === 'function') {\n const native = randomUuid.bind(globalThis.crypto);\n return () => native();\n }\n\n const pool = new Uint8Array(POOL_SIZE);\n let offset = POOL_SIZE;\n\n return () => {\n if (offset > POOL_SIZE - 16) {\n globalThis.crypto.getRandomValues(pool);\n offset = 0;\n }\n\n const at = offset;\n offset = at + 16;\n\n const version = (pool[at + 6] & 0x0f) | 0x40;\n const variant = (pool[at + 8] & 0x3f) | 0x80;\n const hex = UUID_HEX_OCTETS;\n\n return (\n hex[pool[at]] +\n hex[pool[at + 1]] +\n hex[pool[at + 2]] +\n hex[pool[at + 3]] +\n '-' +\n hex[pool[at + 4]] +\n hex[pool[at + 5]] +\n '-' +\n hex[version] +\n hex[pool[at + 7]] +\n '-' +\n hex[variant] +\n hex[pool[at + 9]] +\n '-' +\n hex[pool[at + 10]] +\n hex[pool[at + 11]] +\n hex[pool[at + 12]] +\n hex[pool[at + 13]] +\n hex[pool[at + 14]] +\n hex[pool[at + 15]]\n );\n };\n};\n\n/** Mints a random UUID v4 - a public identifier or a token. */\nexport const uuidV4: () => string = createUuidV4();\n"]}
1
+ {"version":3,"file":"v4.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,o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,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG;gBACH,GAAG,CAAC,OAAO,CAAC;gBACZ,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG;gBACH,GAAG,CAAC,OAAO,CAAC;gBACZ,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG;gBACH,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;gBAClB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;gBAClB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;gBAClB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;gBAClB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;gBAClB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CACnB,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;aAEuB,WAAM,GAAiB,eAAe,CAAC,MAAM,EAAE,CAAC;IAExE,kIAAkI;IAClI,MAAM,CAAC,QAAQ;QACb,OAAO,eAAe,CAAC,MAAM,EAAE,CAAC;IAClC,CAAC","sourcesContent":["import { UUID_HEX_OCTETS } from './common/constants';\n\nconst POOL_SIZE = 16 * 256;\n\nexport class UuidV4Generator {\n /**\n * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context\n * never changes - and called with no argument, since Node validates it and `['a'].map(...)` would\n * throw.\n */\n static create(): () => string {\n const randomUuid = globalThis.crypto?.randomUUID;\n if (typeof randomUuid === 'function') {\n const native = randomUuid.bind(globalThis.crypto);\n return () => native();\n }\n\n const pool = new Uint8Array(POOL_SIZE);\n let offset = POOL_SIZE;\n\n return () => {\n if (offset > POOL_SIZE - 16) {\n globalThis.crypto.getRandomValues(pool);\n offset = 0;\n }\n\n const at = offset;\n offset = at + 16;\n\n const version = (pool[at + 6] & 0x0f) | 0x40;\n const variant = (pool[at + 8] & 0x3f) | 0x80;\n const hex = UUID_HEX_OCTETS;\n\n return (\n hex[pool[at]] +\n hex[pool[at + 1]] +\n hex[pool[at + 2]] +\n hex[pool[at + 3]] +\n '-' +\n hex[pool[at + 4]] +\n hex[pool[at + 5]] +\n '-' +\n hex[version] +\n hex[pool[at + 7]] +\n '-' +\n hex[variant] +\n hex[pool[at + 9]] +\n '-' +\n hex[pool[at + 10]] +\n hex[pool[at + 11]] +\n hex[pool[at + 12]] +\n hex[pool[at + 13]] +\n hex[pool[at + 14]] +\n hex[pool[at + 15]]\n );\n };\n }\n\n private static readonly shared: () => string = UuidV4Generator.create();\n\n /** Mints a random UUID v4 - a public identifier or a token. Reads no `this`, so `['a'].map(UuidV4Generator.generate)` is safe. */\n static generate(): string {\n return UuidV4Generator.shared();\n }\n}\n"]}
@@ -1,15 +1,18 @@
1
- /** Builds a v5 generator with its own namespace cache and buffer. */
2
- export declare const createUuidV5: () => ((opts: {
3
- namespace: string;
4
- name: string;
5
- }) => string);
6
- /**
7
- * Mints a deterministic UUID v5 from `namespace` and `name` - an idempotency key.
8
- *
9
- * Reproducible therefore NOT secret: never a share link, a reset token or an API key.
10
- */
11
- export declare const uuidV5: (opts: {
12
- namespace: string;
13
- name: string;
14
- }) => string;
1
+ export declare class UuidV5Generator {
2
+ /** Builds a v5 generator with its own namespace cache and buffer. */
3
+ static create(): (opts: {
4
+ namespace: string;
5
+ name: string;
6
+ }) => string;
7
+ private static readonly shared;
8
+ /**
9
+ * Mints a deterministic UUID v5 from `namespace` and `name` - an idempotency key.
10
+ *
11
+ * Reproducible therefore NOT secret: never a share link, a reset token or an API key.
12
+ */
13
+ static generate(opts: {
14
+ namespace: string;
15
+ name: string;
16
+ }): string;
17
+ }
15
18
  //# sourceMappingURL=v5.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"v5.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v5.ts"],"names":[],"mappings":"AASA,qEAAqE;AACrE,eAAO,MAAM,YAAY,QAAO,CAAC,CAAC,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,CAyFrF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,MAAuB,CAAC"}
1
+ {"version":3,"file":"v5.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v5.ts"],"names":[],"mappings":"AASA,qBAAa,eAAe;IAC1B,qEAAqE;IACrE,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM;IA2FtE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CACH;IAE3B;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;CAGnE"}
@@ -5,82 +5,87 @@ import { MAX_CACHED_NAMESPACES, UUID_HEX_OCTETS, UUID_NAMESPACE_PATTERN } from '
5
5
  import { Sha1Digest } from './sha1.js';
6
6
  /** Fits a namespace plus a ~160-character name; a longer one allocates for its own call. */
7
7
  const INPUT_SIZE = 512;
8
- /** Builds a v5 generator with its own namespace cache and buffer. */
9
- export const createUuidV5 = () => {
10
- const encoder = new TextEncoder();
11
- /** Parsed namespaces, capped so a caller-fed one cannot grow the map without bound. */
12
- const namespaces = new Map();
13
- const input = new Uint8Array(INPUT_SIZE);
14
- const nameView = input.subarray(16);
15
- const resolveNamespace = (opts) => {
16
- const { namespace } = opts;
17
- const cached = namespaces.get(namespace);
18
- if (cached) {
19
- return cached;
20
- }
21
- if (!UUID_NAMESPACE_PATTERN.test(namespace)) {
22
- throw getError({
23
- statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
24
- message: `[uuidV5] namespace must be a UUID - received: ${namespace}`,
25
- });
26
- }
27
- const bytes = new Uint8Array(16);
28
- const hex = namespace.replaceAll('-', '');
29
- for (let index = 0; index < 16; index++) {
30
- bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
31
- }
32
- if (namespaces.size < MAX_CACHED_NAMESPACES) {
33
- namespaces.set(namespace, bytes);
34
- }
35
- return bytes;
36
- };
37
- return (opts) => {
38
- const { namespace, name } = opts;
39
- const namespaceBytes = resolveNamespace({ namespace });
40
- // Encoding turns a lone surrogate into U+FFFD, so two different malformed names would share an id.
41
- if (typeof name.isWellFormed === 'function' && !name.isWellFormed()) {
42
- throw getError({
43
- statusCode: HTTP.ResultCodes.RS_4.BadRequest,
44
- message: '[uuidV5] name carries a lone surrogate - it is not well-formed UTF-16 and would collide with another name',
45
- });
46
- }
47
- // UTF-8 never exceeds 3 bytes per UTF-16 code unit. An oversized name gets a buffer of its own
48
- // for this call only, so one huge name does not pin its size for the life of the process.
49
- const required = 16 + name.length * 3;
50
- const target = required > input.length ? new Uint8Array(required) : input;
51
- const targetName = target === input ? nameView : target.subarray(16);
52
- target.set(namespaceBytes);
53
- const { written } = encoder.encodeInto(name, targetName);
54
- const digest = Sha1Digest.of({ bytes: target.subarray(0, 16 + written) });
55
- digest[6] = (digest[6] & 0x0f) | 0x50;
56
- digest[8] = (digest[8] & 0x3f) | 0x80;
57
- const hex = UUID_HEX_OCTETS;
58
- return (hex[digest[0]] +
59
- hex[digest[1]] +
60
- hex[digest[2]] +
61
- hex[digest[3]] +
62
- '-' +
63
- hex[digest[4]] +
64
- hex[digest[5]] +
65
- '-' +
66
- hex[digest[6]] +
67
- hex[digest[7]] +
68
- '-' +
69
- hex[digest[8]] +
70
- hex[digest[9]] +
71
- '-' +
72
- hex[digest[10]] +
73
- hex[digest[11]] +
74
- hex[digest[12]] +
75
- hex[digest[13]] +
76
- hex[digest[14]] +
77
- hex[digest[15]]);
78
- };
79
- };
80
- /**
81
- * Mints a deterministic UUID v5 from `namespace` and `name` - an idempotency key.
82
- *
83
- * Reproducible therefore NOT secret: never a share link, a reset token or an API key.
84
- */
85
- export const uuidV5 = createUuidV5();
8
+ export class UuidV5Generator {
9
+ /** Builds a v5 generator with its own namespace cache and buffer. */
10
+ static create() {
11
+ const encoder = new TextEncoder();
12
+ /** Parsed namespaces, capped so a caller-fed one cannot grow the map without bound. */
13
+ const namespaces = new Map();
14
+ const input = new Uint8Array(INPUT_SIZE);
15
+ const nameView = input.subarray(16);
16
+ const resolveNamespace = (opts) => {
17
+ const { namespace } = opts;
18
+ const cached = namespaces.get(namespace);
19
+ if (cached) {
20
+ return cached;
21
+ }
22
+ if (!UUID_NAMESPACE_PATTERN.test(namespace)) {
23
+ throw getError({
24
+ statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
25
+ message: `[uuidV5] namespace must be a UUID - received: ${namespace}`,
26
+ });
27
+ }
28
+ const bytes = new Uint8Array(16);
29
+ const hex = namespace.replaceAll('-', '');
30
+ for (let index = 0; index < 16; index++) {
31
+ bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
32
+ }
33
+ if (namespaces.size < MAX_CACHED_NAMESPACES) {
34
+ namespaces.set(namespace, bytes);
35
+ }
36
+ return bytes;
37
+ };
38
+ return (opts) => {
39
+ const { namespace, name } = opts;
40
+ const namespaceBytes = resolveNamespace({ namespace });
41
+ // Encoding turns a lone surrogate into U+FFFD, so two different malformed names would share an id.
42
+ if (typeof name.isWellFormed === 'function' && !name.isWellFormed()) {
43
+ throw getError({
44
+ statusCode: HTTP.ResultCodes.RS_4.BadRequest,
45
+ message: '[uuidV5] name carries a lone surrogate - it is not well-formed UTF-16 and would collide with another name',
46
+ });
47
+ }
48
+ // UTF-8 never exceeds 3 bytes per UTF-16 code unit. An oversized name gets a buffer of its own
49
+ // for this call only, so one huge name does not pin its size for the life of the process.
50
+ const required = 16 + name.length * 3;
51
+ const target = required > input.length ? new Uint8Array(required) : input;
52
+ const targetName = target === input ? nameView : target.subarray(16);
53
+ target.set(namespaceBytes);
54
+ const { written } = encoder.encodeInto(name, targetName);
55
+ const digest = Sha1Digest.of({ bytes: target.subarray(0, 16 + written) });
56
+ digest[6] = (digest[6] & 0x0f) | 0x50;
57
+ digest[8] = (digest[8] & 0x3f) | 0x80;
58
+ const hex = UUID_HEX_OCTETS;
59
+ return (hex[digest[0]] +
60
+ hex[digest[1]] +
61
+ hex[digest[2]] +
62
+ hex[digest[3]] +
63
+ '-' +
64
+ hex[digest[4]] +
65
+ hex[digest[5]] +
66
+ '-' +
67
+ hex[digest[6]] +
68
+ hex[digest[7]] +
69
+ '-' +
70
+ hex[digest[8]] +
71
+ hex[digest[9]] +
72
+ '-' +
73
+ hex[digest[10]] +
74
+ hex[digest[11]] +
75
+ hex[digest[12]] +
76
+ hex[digest[13]] +
77
+ hex[digest[14]] +
78
+ hex[digest[15]]);
79
+ };
80
+ }
81
+ static { this.shared = UuidV5Generator.create(); }
82
+ /**
83
+ * Mints a deterministic UUID v5 from `namespace` and `name` - an idempotency key.
84
+ *
85
+ * Reproducible therefore NOT secret: never a share link, a reset token or an API key.
86
+ */
87
+ static generate(opts) {
88
+ return UuidV5Generator.shared(opts);
89
+ }
90
+ }
86
91
  //# sourceMappingURL=v5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"v5.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v5.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE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AAC,MAAM,MAAM,GAA0D,YAAY,EAAE,CAAC","sourcesContent":["// Past the barrels: this module ships on the `./uuid` subpath and must not pull their surface.\nimport { getError } from '@venizia/ignis-inversion';\nimport { HTTP } from '@/common/constants/http';\nimport { MAX_CACHED_NAMESPACES, UUID_HEX_OCTETS, UUID_NAMESPACE_PATTERN } from './common/constants';\nimport { Sha1Digest } from './sha1';\n\n/** Fits a namespace plus a ~160-character name; a longer one allocates for its own call. */\nconst INPUT_SIZE = 512;\n\n/** Builds a v5 generator with its own namespace cache and buffer. */\nexport const createUuidV5 = (): ((opts: { namespace: string; name: string }) => string) => {\n const encoder = new TextEncoder();\n\n /** Parsed namespaces, capped so a caller-fed one cannot grow the map without bound. */\n const namespaces = new Map<string, Uint8Array>();\n\n const input = new Uint8Array(INPUT_SIZE);\n const nameView = input.subarray(16);\n\n const resolveNamespace = (opts: { namespace: string }): Uint8Array => {\n const { namespace } = opts;\n\n const cached = namespaces.get(namespace);\n if (cached) {\n return cached;\n }\n\n if (!UUID_NAMESPACE_PATTERN.test(namespace)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[uuidV5] namespace must be a UUID - received: ${namespace}`,\n });\n }\n\n const bytes = new Uint8Array(16);\n const hex = namespace.replaceAll('-', '');\n for (let index = 0; index < 16; index++) {\n bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);\n }\n\n if (namespaces.size < MAX_CACHED_NAMESPACES) {\n namespaces.set(namespace, bytes);\n }\n\n return bytes;\n };\n\n return (opts) => {\n const { namespace, name } = opts;\n\n const namespaceBytes = resolveNamespace({ namespace });\n\n // Encoding turns a lone surrogate into U+FFFD, so two different malformed names would share an id.\n if (typeof name.isWellFormed === 'function' && !name.isWellFormed()) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message:\n '[uuidV5] name carries a lone surrogate - it is not well-formed UTF-16 and would collide with another name',\n });\n }\n\n // UTF-8 never exceeds 3 bytes per UTF-16 code unit. An oversized name gets a buffer of its own\n // for this call only, so one huge name does not pin its size for the life of the process.\n const required = 16 + name.length * 3;\n const target = required > input.length ? new Uint8Array(required) : input;\n const targetName = target === input ? nameView : target.subarray(16);\n\n target.set(namespaceBytes);\n const { written } = encoder.encodeInto(name, targetName);\n\n const digest = Sha1Digest.of({ bytes: target.subarray(0, 16 + written) });\n digest[6] = (digest[6] & 0x0f) | 0x50;\n digest[8] = (digest[8] & 0x3f) | 0x80;\n\n const hex = UUID_HEX_OCTETS;\n\n return (\n hex[digest[0]] +\n hex[digest[1]] +\n hex[digest[2]] +\n hex[digest[3]] +\n '-' +\n hex[digest[4]] +\n hex[digest[5]] +\n '-' +\n hex[digest[6]] +\n hex[digest[7]] +\n '-' +\n hex[digest[8]] +\n hex[digest[9]] +\n '-' +\n hex[digest[10]] +\n hex[digest[11]] +\n hex[digest[12]] +\n hex[digest[13]] +\n hex[digest[14]] +\n hex[digest[15]]\n );\n };\n};\n\n/**\n * Mints a deterministic UUID v5 from `namespace` and `name` - an idempotency key.\n *\n * Reproducible therefore NOT secret: never a share link, a reset token or an API key.\n */\nexport const uuidV5: (opts: { namespace: string; name: string }) => string = createUuidV5();\n"]}
1
+ {"version":3,"file":"v5.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v5.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,4FAA4F;AAC5F,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,OAAO,eAAe;IAC1B,qEAAqE;IACrE,MAAM,CAAC,MAAM;QACX,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC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AM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;YAEtC,MAAM,GAAG,GAAG,eAAe,CAAC;YAE5B,OAAO,CACL,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG;gBACH,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG;gBACH,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG;gBACH,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,GAAG;gBACH,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAChB,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;aAEuB,WAAM,GAC5B,eAAe,CAAC,MAAM,EAAE,CAAC;IAE3B;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAyC;QACvD,OAAO,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC","sourcesContent":["// Past the barrels: this module ships on the `./uuid` subpath and must not pull their surface.\nimport { getError } from '@venizia/ignis-inversion';\nimport { HTTP } from '@/common/constants/http';\nimport { MAX_CACHED_NAMESPACES, UUID_HEX_OCTETS, UUID_NAMESPACE_PATTERN } from './common/constants';\nimport { Sha1Digest } from './sha1';\n\n/** Fits a namespace plus a ~160-character name; a longer one allocates for its own call. */\nconst INPUT_SIZE = 512;\n\nexport class UuidV5Generator {\n /** Builds a v5 generator with its own namespace cache and buffer. */\n static create(): (opts: { namespace: string; name: string }) => string {\n const encoder = new TextEncoder();\n\n /** Parsed namespaces, capped so a caller-fed one cannot grow the map without bound. */\n const namespaces = new Map<string, Uint8Array>();\n\n const input = new Uint8Array(INPUT_SIZE);\n const nameView = input.subarray(16);\n\n const resolveNamespace = (opts: { namespace: string }): Uint8Array => {\n const { namespace } = opts;\n\n const cached = namespaces.get(namespace);\n if (cached) {\n return cached;\n }\n\n if (!UUID_NAMESPACE_PATTERN.test(namespace)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[uuidV5] namespace must be a UUID - received: ${namespace}`,\n });\n }\n\n const bytes = new Uint8Array(16);\n const hex = namespace.replaceAll('-', '');\n for (let index = 0; index < 16; index++) {\n bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);\n }\n\n if (namespaces.size < MAX_CACHED_NAMESPACES) {\n namespaces.set(namespace, bytes);\n }\n\n return bytes;\n };\n\n return (opts) => {\n const { namespace, name } = opts;\n\n const namespaceBytes = resolveNamespace({ namespace });\n\n // Encoding turns a lone surrogate into U+FFFD, so two different malformed names would share an id.\n if (typeof name.isWellFormed === 'function' && !name.isWellFormed()) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message:\n '[uuidV5] name carries a lone surrogate - it is not well-formed UTF-16 and would collide with another name',\n });\n }\n\n // UTF-8 never exceeds 3 bytes per UTF-16 code unit. An oversized name gets a buffer of its own\n // for this call only, so one huge name does not pin its size for the life of the process.\n const required = 16 + name.length * 3;\n const target = required > input.length ? new Uint8Array(required) : input;\n const targetName = target === input ? nameView : target.subarray(16);\n\n target.set(namespaceBytes);\n const { written } = encoder.encodeInto(name, targetName);\n\n const digest = Sha1Digest.of({ bytes: target.subarray(0, 16 + written) });\n digest[6] = (digest[6] & 0x0f) | 0x50;\n digest[8] = (digest[8] & 0x3f) | 0x80;\n\n const hex = UUID_HEX_OCTETS;\n\n return (\n hex[digest[0]] +\n hex[digest[1]] +\n hex[digest[2]] +\n hex[digest[3]] +\n '-' +\n hex[digest[4]] +\n hex[digest[5]] +\n '-' +\n hex[digest[6]] +\n hex[digest[7]] +\n '-' +\n hex[digest[8]] +\n hex[digest[9]] +\n '-' +\n hex[digest[10]] +\n hex[digest[11]] +\n hex[digest[12]] +\n hex[digest[13]] +\n hex[digest[14]] +\n hex[digest[15]]\n );\n };\n }\n\n private static readonly shared: (opts: { namespace: string; name: string }) => string =\n UuidV5Generator.create();\n\n /**\n * Mints a deterministic UUID v5 from `namespace` and `name` - an idempotency key.\n *\n * Reproducible therefore NOT secret: never a share link, a reset token or an API key.\n */\n static generate(opts: { namespace: string; name: string }): string {\n return UuidV5Generator.shared(opts);\n }\n}\n"]}