@venizia/ignis-helpers 0.4.7 → 0.4.8-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 (678) hide show
  1. package/README.md +2 -2
  2. package/dist/esm/common/constants/app.d.ts +15 -0
  3. package/dist/esm/common/constants/app.js +14 -0
  4. package/dist/esm/common/constants/app.js.map +1 -1
  5. package/dist/esm/common/constants/duration.d.ts +2 -0
  6. package/dist/esm/common/constants/duration.js.map +1 -1
  7. package/dist/esm/common/constants/grpc.d.ts +3 -0
  8. package/dist/esm/common/constants/grpc.js +1 -0
  9. package/dist/esm/common/constants/grpc.js.map +1 -1
  10. package/dist/esm/common/constants/http.d.ts +4 -0
  11. package/dist/esm/common/constants/http.js +1 -0
  12. package/dist/esm/common/constants/http.js.map +1 -1
  13. package/dist/esm/common/constants/mime.d.ts +4 -0
  14. package/dist/esm/common/constants/mime.js +1 -0
  15. package/dist/esm/common/constants/mime.js.map +1 -1
  16. package/dist/esm/common/redact.d.ts +2 -0
  17. package/dist/esm/common/redact.js +2 -0
  18. package/dist/esm/common/redact.js.map +1 -1
  19. package/dist/esm/common/resolvers.d.ts +1 -0
  20. package/dist/esm/common/resolvers.js +1 -0
  21. package/dist/esm/common/resolvers.js.map +1 -1
  22. package/dist/esm/common/types/class.d.ts +6 -0
  23. package/dist/esm/common/types/class.js.map +1 -1
  24. package/dist/esm/common/types/const-value.d.ts +3 -0
  25. package/dist/esm/common/types/const-value.js.map +1 -1
  26. package/dist/esm/common/types/field-mapping.d.ts +3 -0
  27. package/dist/esm/common/types/field-mapping.js.map +1 -1
  28. package/dist/esm/common/types/injection.d.ts +2 -0
  29. package/dist/esm/common/types/injection.js.map +1 -1
  30. package/dist/esm/common/types/utility.d.ts +9 -0
  31. package/dist/esm/common/types/utility.js.map +1 -1
  32. package/dist/esm/modules/base.d.ts +1 -0
  33. package/dist/esm/modules/base.js +1 -0
  34. package/dist/esm/modules/base.js.map +1 -1
  35. package/dist/esm/modules/cron/helper.d.ts +7 -0
  36. package/dist/esm/modules/cron/helper.js +1 -0
  37. package/dist/esm/modules/cron/helper.js.map +1 -1
  38. package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts +2 -0
  39. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  40. package/dist/esm/modules/crypto/algorithms/aes.engine.js.map +1 -1
  41. package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts +1 -0
  42. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +1 -0
  43. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  44. package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts +12 -4
  45. package/dist/esm/modules/crypto/algorithms/credential.algorithm.js +4 -4
  46. package/dist/esm/modules/crypto/algorithms/credential.algorithm.js.map +1 -1
  47. package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts +3 -0
  48. package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js.map +1 -1
  49. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
  50. package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts +1 -0
  51. package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js.map +1 -1
  52. package/dist/esm/modules/crypto/common/constants.d.ts +12 -1
  53. package/dist/esm/modules/crypto/common/constants.js +9 -1
  54. package/dist/esm/modules/crypto/common/constants.js.map +1 -1
  55. package/dist/esm/modules/crypto/common/types.d.ts +1 -0
  56. package/dist/esm/modules/crypto/common/types.js.map +1 -1
  57. package/dist/esm/modules/env/app-env.d.ts +3 -0
  58. package/dist/esm/modules/env/app-env.js +3 -0
  59. package/dist/esm/modules/env/app-env.js.map +1 -1
  60. package/dist/esm/modules/env/common/types.d.ts +1 -0
  61. package/dist/esm/modules/env/common/types.js.map +1 -1
  62. package/dist/esm/modules/logger/base/base.js.map +1 -1
  63. package/dist/esm/modules/logger/base/console.js.map +1 -1
  64. package/dist/esm/modules/logger/common/constants.d.ts +3 -0
  65. package/dist/esm/modules/logger/common/constants.js +2 -0
  66. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  67. package/dist/esm/modules/logger/common/debug-gate.js.map +1 -1
  68. package/dist/esm/modules/logger/common/types.d.ts +2 -0
  69. package/dist/esm/modules/logger/common/types.js +1 -0
  70. package/dist/esm/modules/logger/common/types.js.map +1 -1
  71. package/dist/esm/modules/logger/factory.js.map +1 -1
  72. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +1 -0
  73. package/dist/esm/modules/logger/formatting/deep-splat.js +1 -0
  74. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  75. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  76. package/dist/esm/modules/logger/hf/common/types.d.ts +7 -2
  77. package/dist/esm/modules/logger/hf/common/types.js.map +1 -1
  78. package/dist/esm/modules/logger/hf/flusher.js.map +1 -1
  79. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  80. package/dist/esm/modules/logger/hf/ring.js.map +1 -1
  81. package/dist/esm/modules/logger/pino/backing.js.map +1 -1
  82. package/dist/esm/modules/logger/pino/destination.js.map +1 -1
  83. package/dist/esm/modules/logger/pino/logger.js.map +1 -1
  84. package/dist/esm/modules/logger/winston/common/types.d.ts +31 -3
  85. package/dist/esm/modules/logger/winston/common/types.js.map +1 -1
  86. package/dist/esm/modules/logger/winston/define.d.ts +1 -0
  87. package/dist/esm/modules/logger/winston/define.js +1 -0
  88. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  89. package/dist/esm/modules/logger/winston/formats.js.map +1 -1
  90. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  91. package/dist/esm/modules/logger/winston/logger.d.ts +1 -0
  92. package/dist/esm/modules/logger/winston/logger.js +1 -0
  93. package/dist/esm/modules/logger/winston/logger.js.map +1 -1
  94. package/dist/esm/modules/logger/winston/transports/dgram.transport.d.ts +1 -0
  95. package/dist/esm/modules/logger/winston/transports/dgram.transport.js +1 -0
  96. package/dist/esm/modules/logger/winston/transports/dgram.transport.js.map +1 -1
  97. package/dist/esm/modules/network/http-request/base-network-request.helper.d.ts +1 -0
  98. package/dist/esm/modules/network/http-request/base-network-request.helper.js +1 -0
  99. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  100. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts +8 -8
  101. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +2 -0
  102. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  103. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +2 -0
  104. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
  105. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +5 -1
  106. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +2 -0
  107. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  108. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.d.ts +11 -0
  109. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +1 -0
  110. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  111. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts +3 -0
  112. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +1 -0
  113. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  114. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.d.ts +1 -0
  115. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.js +1 -0
  116. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.js.map +1 -1
  117. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.d.ts +1 -0
  118. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.js +1 -0
  119. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.js.map +1 -1
  120. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.d.ts +1 -0
  121. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.js +1 -0
  122. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.js.map +1 -1
  123. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.d.ts +1 -0
  124. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.js +1 -0
  125. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.js.map +1 -1
  126. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.d.ts +4 -0
  127. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +4 -0
  128. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  129. package/dist/esm/modules/network/utilities/query-string.d.ts +13 -2
  130. package/dist/esm/modules/network/utilities/query-string.js +2 -1
  131. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  132. package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +2 -1
  133. package/dist/esm/modules/network/utilities/url-safety/common/constants.js +1 -1
  134. package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
  135. package/dist/esm/modules/network/utilities/url-safety/common/types.d.ts +18 -5
  136. package/dist/esm/modules/network/utilities/url-safety/common/types.js.map +1 -1
  137. package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
  138. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  139. package/dist/esm/modules/pool/abstract.js.map +1 -1
  140. package/dist/esm/modules/pool/common/types.d.ts +5 -1
  141. package/dist/esm/modules/pool/common/types.js.map +1 -1
  142. package/dist/esm/modules/queue/bullmq/helper.d.ts +13 -0
  143. package/dist/esm/modules/queue/bullmq/helper.js +4 -0
  144. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  145. package/dist/esm/modules/queue/common/hook.d.ts +1 -0
  146. package/dist/esm/modules/queue/common/hook.js +1 -0
  147. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  148. package/dist/esm/modules/queue/internal/hf/helper.js.map +1 -1
  149. package/dist/esm/modules/queue/internal/sequential/common/types.d.ts +8 -0
  150. package/dist/esm/modules/queue/internal/sequential/common/types.js +1 -0
  151. package/dist/esm/modules/queue/internal/sequential/common/types.js.map +1 -1
  152. package/dist/esm/modules/queue/internal/sequential/helper.d.ts +4 -0
  153. package/dist/esm/modules/queue/internal/sequential/helper.js +4 -0
  154. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  155. package/dist/esm/modules/queue/kafka/base.d.ts +5 -0
  156. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  157. package/dist/esm/modules/queue/kafka/bundler/common/constants.d.ts +3 -0
  158. package/dist/esm/modules/queue/kafka/bundler/common/constants.js +3 -0
  159. package/dist/esm/modules/queue/kafka/bundler/common/constants.js.map +1 -1
  160. package/dist/esm/modules/queue/kafka/common/constants.d.ts +8 -0
  161. package/dist/esm/modules/queue/kafka/common/constants.js +5 -0
  162. package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
  163. package/dist/esm/modules/queue/kafka/common/types/admin.d.ts +1 -0
  164. package/dist/esm/modules/queue/kafka/common/types/admin.js.map +1 -1
  165. package/dist/esm/modules/queue/kafka/common/types/callbacks.d.ts +12 -0
  166. package/dist/esm/modules/queue/kafka/common/types/callbacks.js.map +1 -1
  167. package/dist/esm/modules/queue/kafka/common/types/connection.d.ts +2 -0
  168. package/dist/esm/modules/queue/kafka/common/types/connection.js.map +1 -1
  169. package/dist/esm/modules/queue/kafka/common/types/consumer.d.ts +62 -0
  170. package/dist/esm/modules/queue/kafka/common/types/consumer.js.map +1 -1
  171. package/dist/esm/modules/queue/kafka/common/types/producer.d.ts +1 -0
  172. package/dist/esm/modules/queue/kafka/common/types/producer.js.map +1 -1
  173. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  174. package/dist/esm/modules/queue/mqtt/helper.d.ts +2 -0
  175. package/dist/esm/modules/queue/mqtt/helper.js +1 -0
  176. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  177. package/dist/esm/modules/redis/base/abstract.helper.d.ts +2 -0
  178. package/dist/esm/modules/redis/base/abstract.helper.js +2 -0
  179. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  180. package/dist/esm/modules/redis/cluster/cluster.helper.d.ts +1 -0
  181. package/dist/esm/modules/redis/cluster/cluster.helper.js +1 -0
  182. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  183. package/dist/esm/modules/redis/common/constants.d.ts +4 -0
  184. package/dist/esm/modules/redis/common/constants.js +2 -0
  185. package/dist/esm/modules/redis/common/constants.js.map +1 -1
  186. package/dist/esm/modules/redis/common/interfaces.d.ts +12 -0
  187. package/dist/esm/modules/redis/common/interfaces.js.map +1 -1
  188. package/dist/esm/modules/redis/common/types.d.ts +21 -1
  189. package/dist/esm/modules/redis/common/types.js.map +1 -1
  190. package/dist/esm/modules/redis/factory.d.ts +2 -0
  191. package/dist/esm/modules/redis/factory.js +1 -0
  192. package/dist/esm/modules/redis/factory.js.map +1 -1
  193. package/dist/esm/modules/redis/sentinel/sentinel.helper.d.ts +1 -0
  194. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +1 -0
  195. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  196. package/dist/esm/modules/redis/single/single.helper.d.ts +1 -0
  197. package/dist/esm/modules/redis/single/single.helper.js +1 -0
  198. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  199. package/dist/esm/modules/redis/utility.d.ts +1 -0
  200. package/dist/esm/modules/redis/utility.js +1 -0
  201. package/dist/esm/modules/redis/utility.js.map +1 -1
  202. package/dist/esm/modules/retry/common/constants.d.ts +4 -0
  203. package/dist/esm/modules/retry/common/constants.js +2 -0
  204. package/dist/esm/modules/retry/common/constants.js.map +1 -1
  205. package/dist/esm/modules/retry/common/types.d.ts +19 -5
  206. package/dist/esm/modules/retry/common/types.js.map +1 -1
  207. package/dist/esm/modules/retry/helper.d.ts +4 -4
  208. package/dist/esm/modules/retry/helper.js.map +1 -1
  209. package/dist/esm/modules/secrets/base/abstract.helper.d.ts +1 -0
  210. package/dist/esm/modules/secrets/base/abstract.helper.js +1 -0
  211. package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
  212. package/dist/esm/modules/secrets/common/constants.d.ts +4 -0
  213. package/dist/esm/modules/secrets/common/constants.js +2 -0
  214. package/dist/esm/modules/secrets/common/constants.js.map +1 -1
  215. package/dist/esm/modules/secrets/common/types/helper.d.ts +13 -0
  216. package/dist/esm/modules/secrets/common/types/helper.js.map +1 -1
  217. package/dist/esm/modules/secrets/common/types/lease.d.ts +2 -0
  218. package/dist/esm/modules/secrets/common/types/lease.js.map +1 -1
  219. package/dist/esm/modules/secrets/common/types/registration.d.ts +13 -2
  220. package/dist/esm/modules/secrets/common/types/registration.js.map +1 -1
  221. package/dist/esm/modules/secrets/common/types/timer.d.ts +1 -0
  222. package/dist/esm/modules/secrets/common/types/timer.js.map +1 -1
  223. package/dist/esm/modules/secrets/dotenv/dotenv.helper.d.ts +8 -0
  224. package/dist/esm/modules/secrets/dotenv/dotenv.helper.js +1 -0
  225. package/dist/esm/modules/secrets/dotenv/dotenv.helper.js.map +1 -1
  226. package/dist/esm/modules/secrets/factory.d.ts +1 -0
  227. package/dist/esm/modules/secrets/factory.js +1 -0
  228. package/dist/esm/modules/secrets/factory.js.map +1 -1
  229. package/dist/esm/modules/secrets/hashicorp/auth.d.ts +2 -0
  230. package/dist/esm/modules/secrets/hashicorp/auth.js +1 -0
  231. package/dist/esm/modules/secrets/hashicorp/auth.js.map +1 -1
  232. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts +2 -0
  233. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +1 -0
  234. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  235. package/dist/esm/modules/secrets/system-envs/system-envs.helper.d.ts +1 -0
  236. package/dist/esm/modules/secrets/system-envs/system-envs.helper.js +1 -0
  237. package/dist/esm/modules/secrets/system-envs/system-envs.helper.js.map +1 -1
  238. package/dist/esm/modules/slug/common/constants.d.ts +1 -0
  239. package/dist/esm/modules/slug/common/constants.js +1 -0
  240. package/dist/esm/modules/slug/common/constants.js.map +1 -1
  241. package/dist/esm/modules/socket/socket-io/client/browser-helper.js.map +1 -1
  242. package/dist/esm/modules/socket/socket-io/common/constants.d.ts +2 -0
  243. package/dist/esm/modules/socket/socket-io/common/constants.js +2 -0
  244. package/dist/esm/modules/socket/socket-io/common/constants.js.map +1 -1
  245. package/dist/esm/modules/socket/socket-io/common/types/client.d.ts +5 -0
  246. package/dist/esm/modules/socket/socket-io/common/types/client.js.map +1 -1
  247. package/dist/esm/modules/socket/socket-io/common/types/hooks.d.ts +4 -0
  248. package/dist/esm/modules/socket/socket-io/common/types/hooks.js.map +1 -1
  249. package/dist/esm/modules/socket/socket-io/common/types/server.d.ts +6 -0
  250. package/dist/esm/modules/socket/socket-io/common/types/server.js.map +1 -1
  251. package/dist/esm/modules/socket/socket-io/server/helper.d.ts +1 -0
  252. package/dist/esm/modules/socket/socket-io/server/helper.js +1 -0
  253. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  254. package/dist/esm/modules/socket/websocket/common/constants.d.ts +7 -0
  255. package/dist/esm/modules/socket/websocket/common/constants.js +5 -0
  256. package/dist/esm/modules/socket/websocket/common/constants.js.map +1 -1
  257. package/dist/esm/modules/socket/websocket/common/types/client.d.ts +4 -0
  258. package/dist/esm/modules/socket/websocket/common/types/client.js.map +1 -1
  259. package/dist/esm/modules/socket/websocket/common/types/hooks.d.ts +7 -0
  260. package/dist/esm/modules/socket/websocket/common/types/hooks.js.map +1 -1
  261. package/dist/esm/modules/socket/websocket/common/types/server.d.ts +30 -0
  262. package/dist/esm/modules/socket/websocket/common/types/server.js.map +1 -1
  263. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts +1 -0
  264. package/dist/esm/modules/socket/websocket/emitter/helper.js +1 -0
  265. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  266. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  267. package/dist/esm/modules/socket/websocket/server/helper.d.ts +1 -0
  268. package/dist/esm/modules/socket/websocket/server/helper.js +1 -0
  269. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  270. package/dist/esm/modules/storage/base.d.ts +6 -1
  271. package/dist/esm/modules/storage/base.js +1 -0
  272. package/dist/esm/modules/storage/base.js.map +1 -1
  273. package/dist/esm/modules/storage/bun-s3/helper.d.ts +9 -1
  274. package/dist/esm/modules/storage/bun-s3/helper.js +2 -1
  275. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  276. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  277. package/dist/esm/modules/storage/common/constants.d.ts +1 -0
  278. package/dist/esm/modules/storage/common/constants.js.map +1 -1
  279. package/dist/esm/modules/storage/common/types.d.ts +17 -1
  280. package/dist/esm/modules/storage/common/types.js.map +1 -1
  281. package/dist/esm/modules/storage/common/utility.d.ts +1 -0
  282. package/dist/esm/modules/storage/common/utility.js +1 -0
  283. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  284. package/dist/esm/modules/storage/disk/helper.d.ts +2 -0
  285. package/dist/esm/modules/storage/disk/helper.js +1 -0
  286. package/dist/esm/modules/storage/disk/helper.js.map +1 -1
  287. package/dist/esm/modules/temporal/abstract.d.ts +5 -0
  288. package/dist/esm/modules/temporal/abstract.js +2 -1
  289. package/dist/esm/modules/temporal/abstract.js.map +1 -1
  290. package/dist/esm/modules/temporal/adapters/dayjs.js.map +1 -1
  291. package/dist/esm/modules/temporal/adapters/intl.js.map +1 -1
  292. package/dist/esm/modules/temporal/adapters/luxon.js.map +1 -1
  293. package/dist/esm/modules/temporal/adapters/native.js.map +1 -1
  294. package/dist/esm/modules/temporal/calendar/calendar.js.map +1 -1
  295. package/dist/esm/modules/temporal/common/constants.d.ts +3 -0
  296. package/dist/esm/modules/temporal/common/constants.js.map +1 -1
  297. package/dist/esm/modules/temporal/common/types.js.map +1 -1
  298. package/dist/esm/modules/temporal/duration/duration.js.map +1 -1
  299. package/dist/esm/modules/temporal/helper.js.map +1 -1
  300. package/dist/esm/modules/temporal/locale/locale.js.map +1 -1
  301. package/dist/esm/modules/temporal/pattern/pattern.js.map +1 -1
  302. package/dist/esm/modules/temporal/pattern/tokens.js.map +1 -1
  303. package/dist/esm/modules/tree/builder.js.map +1 -1
  304. package/dist/esm/modules/tree/common/types.d.ts +6 -0
  305. package/dist/esm/modules/tree/common/types.js.map +1 -1
  306. package/dist/esm/modules/uid/common/constants.d.ts +1 -0
  307. package/dist/esm/modules/uid/common/constants.js.map +1 -1
  308. package/dist/esm/modules/uid/common/types.d.ts +28 -7
  309. package/dist/esm/modules/uid/common/types.js.map +1 -1
  310. package/dist/esm/modules/uid/helper.d.ts +12 -0
  311. package/dist/esm/modules/uid/helper.js.map +1 -1
  312. package/dist/esm/modules/uid/opaque.js.map +1 -1
  313. package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
  314. package/dist/esm/modules/uid/uuid/sha1.js.map +1 -1
  315. package/dist/esm/modules/uid/uuid/v4.d.ts +1 -0
  316. package/dist/esm/modules/uid/uuid/v4.js +1 -0
  317. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  318. package/dist/esm/modules/uid/uuid/v5.d.ts +1 -0
  319. package/dist/esm/modules/uid/uuid/v5.js +1 -0
  320. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  321. package/dist/esm/modules/uid/uuid/v7.d.ts +1 -0
  322. package/dist/esm/modules/uid/uuid/v7.js +1 -0
  323. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  324. package/dist/esm/modules/worker-thread/bus/abstract.d.ts +1 -0
  325. package/dist/esm/modules/worker-thread/bus/abstract.js +1 -0
  326. package/dist/esm/modules/worker-thread/bus/abstract.js.map +1 -1
  327. package/dist/esm/modules/worker-thread/bus/base.d.ts +1 -0
  328. package/dist/esm/modules/worker-thread/bus/base.js +1 -0
  329. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  330. package/dist/esm/modules/worker-thread/bus/handler/abstract.d.ts +1 -0
  331. package/dist/esm/modules/worker-thread/bus/handler/abstract.js +1 -0
  332. package/dist/esm/modules/worker-thread/bus/handler/abstract.js.map +1 -1
  333. package/dist/esm/modules/worker-thread/bus/handler/base.d.ts +1 -0
  334. package/dist/esm/modules/worker-thread/bus/handler/base.js +1 -0
  335. package/dist/esm/modules/worker-thread/bus/handler/base.js.map +1 -1
  336. package/dist/esm/modules/worker-thread/common/types.d.ts +4 -0
  337. package/dist/esm/modules/worker-thread/common/types.js.map +1 -1
  338. package/dist/esm/modules/worker-thread/thread/abstract.d.ts +1 -0
  339. package/dist/esm/modules/worker-thread/thread/abstract.js +1 -0
  340. package/dist/esm/modules/worker-thread/thread/abstract.js.map +1 -1
  341. package/dist/esm/modules/worker-thread/thread/base.d.ts +1 -0
  342. package/dist/esm/modules/worker-thread/thread/base.js +1 -0
  343. package/dist/esm/modules/worker-thread/thread/base.js.map +1 -1
  344. package/dist/esm/modules/worker-thread/worker/abstract.d.ts +1 -0
  345. package/dist/esm/modules/worker-thread/worker/abstract.js +1 -0
  346. package/dist/esm/modules/worker-thread/worker/abstract.js.map +1 -1
  347. package/dist/esm/modules/worker-thread/worker/base.d.ts +1 -0
  348. package/dist/esm/modules/worker-thread/worker/base.js +1 -0
  349. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  350. package/dist/esm/modules/worker-thread/worker-pool.d.ts +1 -0
  351. package/dist/esm/modules/worker-thread/worker-pool.js +1 -0
  352. package/dist/esm/modules/worker-thread/worker-pool.js.map +1 -1
  353. package/dist/esm/utilities/error.utility.d.ts +1 -0
  354. package/dist/esm/utilities/error.utility.js +1 -0
  355. package/dist/esm/utilities/error.utility.js.map +1 -1
  356. package/dist/esm/utilities/form-body.utility.d.ts +1 -0
  357. package/dist/esm/utilities/form-body.utility.js +1 -0
  358. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  359. package/dist/esm/utilities/hr-time.utility.d.ts +1 -0
  360. package/dist/esm/utilities/hr-time.utility.js +1 -0
  361. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  362. package/dist/esm/utilities/module.utility.js.map +1 -1
  363. package/dist/esm/utilities/parse.utility.js.map +1 -1
  364. package/dist/esm/utilities/performance.utility.d.ts +1 -0
  365. package/dist/esm/utilities/performance.utility.js +1 -0
  366. package/dist/esm/utilities/performance.utility.js.map +1 -1
  367. package/dist/esm/utilities/promise.utility.d.ts +1 -0
  368. package/dist/esm/utilities/promise.utility.js.map +1 -1
  369. package/dist/esm/utilities/request.utility.d.ts +2 -0
  370. package/dist/esm/utilities/request.utility.js +1 -0
  371. package/dist/esm/utilities/request.utility.js.map +1 -1
  372. package/package.json +4 -4
  373. package/dist/esm/common/constants/app.d.ts.map +0 -1
  374. package/dist/esm/common/constants/duration.d.ts.map +0 -1
  375. package/dist/esm/common/constants/grpc.d.ts.map +0 -1
  376. package/dist/esm/common/constants/http.d.ts.map +0 -1
  377. package/dist/esm/common/constants/index.d.ts.map +0 -1
  378. package/dist/esm/common/constants/mime.d.ts.map +0 -1
  379. package/dist/esm/common/index.d.ts.map +0 -1
  380. package/dist/esm/common/jsx.d.ts.map +0 -1
  381. package/dist/esm/common/redact.d.ts.map +0 -1
  382. package/dist/esm/common/resolvers.d.ts.map +0 -1
  383. package/dist/esm/common/types/class.d.ts.map +0 -1
  384. package/dist/esm/common/types/const-value.d.ts.map +0 -1
  385. package/dist/esm/common/types/field-mapping.d.ts.map +0 -1
  386. package/dist/esm/common/types/index.d.ts.map +0 -1
  387. package/dist/esm/common/types/injection.d.ts.map +0 -1
  388. package/dist/esm/common/types/resolver.d.ts.map +0 -1
  389. package/dist/esm/common/types/utility.d.ts.map +0 -1
  390. package/dist/esm/core.d.ts.map +0 -1
  391. package/dist/esm/index.d.ts.map +0 -1
  392. package/dist/esm/modules/base.d.ts.map +0 -1
  393. package/dist/esm/modules/cron/helper.d.ts.map +0 -1
  394. package/dist/esm/modules/cron/index.d.ts.map +0 -1
  395. package/dist/esm/modules/crypto/algorithms/abstract.algorithm.d.ts.map +0 -1
  396. package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts.map +0 -1
  397. package/dist/esm/modules/crypto/algorithms/aes.constants.d.ts.map +0 -1
  398. package/dist/esm/modules/crypto/algorithms/aes.engine.d.ts.map +0 -1
  399. package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts.map +0 -1
  400. package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts.map +0 -1
  401. package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts.map +0 -1
  402. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +0 -1
  403. package/dist/esm/modules/crypto/algorithms/index.d.ts.map +0 -1
  404. package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts.map +0 -1
  405. package/dist/esm/modules/crypto/common/constants.d.ts.map +0 -1
  406. package/dist/esm/modules/crypto/common/index.d.ts.map +0 -1
  407. package/dist/esm/modules/crypto/common/types.d.ts.map +0 -1
  408. package/dist/esm/modules/crypto/index.d.ts.map +0 -1
  409. package/dist/esm/modules/env/app-env.d.ts.map +0 -1
  410. package/dist/esm/modules/env/common/index.d.ts.map +0 -1
  411. package/dist/esm/modules/env/common/types.d.ts.map +0 -1
  412. package/dist/esm/modules/env/index.d.ts.map +0 -1
  413. package/dist/esm/modules/env/names.d.ts.map +0 -1
  414. package/dist/esm/modules/error/index.d.ts.map +0 -1
  415. package/dist/esm/modules/index.d.ts.map +0 -1
  416. package/dist/esm/modules/logger/base/abstract.d.ts.map +0 -1
  417. package/dist/esm/modules/logger/base/base.d.ts.map +0 -1
  418. package/dist/esm/modules/logger/base/console.d.ts.map +0 -1
  419. package/dist/esm/modules/logger/base/index.d.ts.map +0 -1
  420. package/dist/esm/modules/logger/common/constants.d.ts.map +0 -1
  421. package/dist/esm/modules/logger/common/debug-gate.d.ts.map +0 -1
  422. package/dist/esm/modules/logger/common/index.d.ts.map +0 -1
  423. package/dist/esm/modules/logger/common/types.d.ts.map +0 -1
  424. package/dist/esm/modules/logger/factory.d.ts.map +0 -1
  425. package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +0 -1
  426. package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +0 -1
  427. package/dist/esm/modules/logger/formatting/index.d.ts.map +0 -1
  428. package/dist/esm/modules/logger/hf/common/constants.d.ts.map +0 -1
  429. package/dist/esm/modules/logger/hf/common/index.d.ts.map +0 -1
  430. package/dist/esm/modules/logger/hf/common/types.d.ts.map +0 -1
  431. package/dist/esm/modules/logger/hf/flusher.d.ts.map +0 -1
  432. package/dist/esm/modules/logger/hf/index.d.ts.map +0 -1
  433. package/dist/esm/modules/logger/hf/logger.d.ts.map +0 -1
  434. package/dist/esm/modules/logger/hf/ring.d.ts.map +0 -1
  435. package/dist/esm/modules/logger/index.d.ts.map +0 -1
  436. package/dist/esm/modules/logger/pino/backing.d.ts.map +0 -1
  437. package/dist/esm/modules/logger/pino/common/constants.d.ts.map +0 -1
  438. package/dist/esm/modules/logger/pino/common/index.d.ts.map +0 -1
  439. package/dist/esm/modules/logger/pino/common/types.d.ts.map +0 -1
  440. package/dist/esm/modules/logger/pino/destination.d.ts.map +0 -1
  441. package/dist/esm/modules/logger/pino/index.d.ts.map +0 -1
  442. package/dist/esm/modules/logger/pino/logger.d.ts.map +0 -1
  443. package/dist/esm/modules/logger/winston/common/constants.d.ts.map +0 -1
  444. package/dist/esm/modules/logger/winston/common/index.d.ts.map +0 -1
  445. package/dist/esm/modules/logger/winston/common/types.d.ts.map +0 -1
  446. package/dist/esm/modules/logger/winston/define.d.ts.map +0 -1
  447. package/dist/esm/modules/logger/winston/formats.d.ts.map +0 -1
  448. package/dist/esm/modules/logger/winston/index.d.ts.map +0 -1
  449. package/dist/esm/modules/logger/winston/logger-factory.d.ts.map +0 -1
  450. package/dist/esm/modules/logger/winston/logger.d.ts.map +0 -1
  451. package/dist/esm/modules/logger/winston/transports/dgram.transport.d.ts.map +0 -1
  452. package/dist/esm/modules/logger/winston/transports/index.d.ts.map +0 -1
  453. package/dist/esm/modules/network/http-request/base-network-request.helper.d.ts.map +0 -1
  454. package/dist/esm/modules/network/http-request/common/constants.d.ts.map +0 -1
  455. package/dist/esm/modules/network/http-request/common/index.d.ts.map +0 -1
  456. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +0 -1
  457. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts.map +0 -1
  458. package/dist/esm/modules/network/http-request/fetcher/common/index.d.ts.map +0 -1
  459. package/dist/esm/modules/network/http-request/fetcher/common/types.d.ts.map +0 -1
  460. package/dist/esm/modules/network/http-request/fetcher/index.d.ts.map +0 -1
  461. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +0 -1
  462. package/dist/esm/modules/network/http-request/index.d.ts.map +0 -1
  463. package/dist/esm/modules/network/index.d.ts.map +0 -1
  464. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.d.ts.map +0 -1
  465. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +0 -1
  466. package/dist/esm/modules/network/tcp-socket/index.d.ts.map +0 -1
  467. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.d.ts.map +0 -1
  468. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.d.ts.map +0 -1
  469. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.d.ts.map +0 -1
  470. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.d.ts.map +0 -1
  471. package/dist/esm/modules/network/udp-socket/index.d.ts.map +0 -1
  472. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.d.ts.map +0 -1
  473. package/dist/esm/modules/network/utilities/index.d.ts.map +0 -1
  474. package/dist/esm/modules/network/utilities/query-string.d.ts.map +0 -1
  475. package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts.map +0 -1
  476. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +0 -1
  477. package/dist/esm/modules/network/utilities/url-safety/common/index.d.ts.map +0 -1
  478. package/dist/esm/modules/network/utilities/url-safety/common/types.d.ts.map +0 -1
  479. package/dist/esm/modules/network/utilities/url-safety/index.d.ts.map +0 -1
  480. package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts.map +0 -1
  481. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +0 -1
  482. package/dist/esm/modules/pool/abstract.d.ts.map +0 -1
  483. package/dist/esm/modules/pool/base.d.ts.map +0 -1
  484. package/dist/esm/modules/pool/common/index.d.ts.map +0 -1
  485. package/dist/esm/modules/pool/common/types.d.ts.map +0 -1
  486. package/dist/esm/modules/pool/index.d.ts.map +0 -1
  487. package/dist/esm/modules/queue/bullmq/helper.d.ts.map +0 -1
  488. package/dist/esm/modules/queue/bullmq/index.d.ts.map +0 -1
  489. package/dist/esm/modules/queue/common/constants.d.ts.map +0 -1
  490. package/dist/esm/modules/queue/common/hook.d.ts.map +0 -1
  491. package/dist/esm/modules/queue/common/index.d.ts.map +0 -1
  492. package/dist/esm/modules/queue/index.d.ts.map +0 -1
  493. package/dist/esm/modules/queue/internal/hf/common/index.d.ts.map +0 -1
  494. package/dist/esm/modules/queue/internal/hf/common/types.d.ts.map +0 -1
  495. package/dist/esm/modules/queue/internal/hf/helper.d.ts.map +0 -1
  496. package/dist/esm/modules/queue/internal/hf/index.d.ts.map +0 -1
  497. package/dist/esm/modules/queue/internal/index.d.ts.map +0 -1
  498. package/dist/esm/modules/queue/internal/sequential/common/index.d.ts.map +0 -1
  499. package/dist/esm/modules/queue/internal/sequential/common/types.d.ts.map +0 -1
  500. package/dist/esm/modules/queue/internal/sequential/helper.d.ts.map +0 -1
  501. package/dist/esm/modules/queue/internal/sequential/index.d.ts.map +0 -1
  502. package/dist/esm/modules/queue/kafka/admin.d.ts.map +0 -1
  503. package/dist/esm/modules/queue/kafka/base.d.ts.map +0 -1
  504. package/dist/esm/modules/queue/kafka/bundler/common/constants.d.ts.map +0 -1
  505. package/dist/esm/modules/queue/kafka/bundler/common/index.d.ts.map +0 -1
  506. package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +0 -1
  507. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +0 -1
  508. package/dist/esm/modules/queue/kafka/common/constants.d.ts.map +0 -1
  509. package/dist/esm/modules/queue/kafka/common/index.d.ts.map +0 -1
  510. package/dist/esm/modules/queue/kafka/common/types/admin.d.ts.map +0 -1
  511. package/dist/esm/modules/queue/kafka/common/types/callbacks.d.ts.map +0 -1
  512. package/dist/esm/modules/queue/kafka/common/types/connection.d.ts.map +0 -1
  513. package/dist/esm/modules/queue/kafka/common/types/consumer.d.ts.map +0 -1
  514. package/dist/esm/modules/queue/kafka/common/types/index.d.ts.map +0 -1
  515. package/dist/esm/modules/queue/kafka/common/types/producer.d.ts.map +0 -1
  516. package/dist/esm/modules/queue/kafka/consumer.d.ts.map +0 -1
  517. package/dist/esm/modules/queue/kafka/index.d.ts.map +0 -1
  518. package/dist/esm/modules/queue/kafka/producer.d.ts.map +0 -1
  519. package/dist/esm/modules/queue/kafka/schema/index.d.ts.map +0 -1
  520. package/dist/esm/modules/queue/kafka/schema/registry.d.ts.map +0 -1
  521. package/dist/esm/modules/queue/mqtt/helper.d.ts.map +0 -1
  522. package/dist/esm/modules/queue/mqtt/index.d.ts.map +0 -1
  523. package/dist/esm/modules/redis/base/abstract.helper.d.ts.map +0 -1
  524. package/dist/esm/modules/redis/base/index.d.ts.map +0 -1
  525. package/dist/esm/modules/redis/cluster/cluster.helper.d.ts.map +0 -1
  526. package/dist/esm/modules/redis/cluster/index.d.ts.map +0 -1
  527. package/dist/esm/modules/redis/common/constants.d.ts.map +0 -1
  528. package/dist/esm/modules/redis/common/index.d.ts.map +0 -1
  529. package/dist/esm/modules/redis/common/interfaces.d.ts.map +0 -1
  530. package/dist/esm/modules/redis/common/types.d.ts.map +0 -1
  531. package/dist/esm/modules/redis/factory.d.ts.map +0 -1
  532. package/dist/esm/modules/redis/index.d.ts.map +0 -1
  533. package/dist/esm/modules/redis/sentinel/index.d.ts.map +0 -1
  534. package/dist/esm/modules/redis/sentinel/sentinel.helper.d.ts.map +0 -1
  535. package/dist/esm/modules/redis/single/index.d.ts.map +0 -1
  536. package/dist/esm/modules/redis/single/single.helper.d.ts.map +0 -1
  537. package/dist/esm/modules/redis/utility.d.ts.map +0 -1
  538. package/dist/esm/modules/retry/common/constants.d.ts.map +0 -1
  539. package/dist/esm/modules/retry/common/index.d.ts.map +0 -1
  540. package/dist/esm/modules/retry/common/types.d.ts.map +0 -1
  541. package/dist/esm/modules/retry/helper.d.ts.map +0 -1
  542. package/dist/esm/modules/retry/index.d.ts.map +0 -1
  543. package/dist/esm/modules/secrets/base/abstract.helper.d.ts.map +0 -1
  544. package/dist/esm/modules/secrets/base/index.d.ts.map +0 -1
  545. package/dist/esm/modules/secrets/common/constants.d.ts.map +0 -1
  546. package/dist/esm/modules/secrets/common/index.d.ts.map +0 -1
  547. package/dist/esm/modules/secrets/common/types/helper.d.ts.map +0 -1
  548. package/dist/esm/modules/secrets/common/types/index.d.ts.map +0 -1
  549. package/dist/esm/modules/secrets/common/types/lease.d.ts.map +0 -1
  550. package/dist/esm/modules/secrets/common/types/registration.d.ts.map +0 -1
  551. package/dist/esm/modules/secrets/common/types/timer.d.ts.map +0 -1
  552. package/dist/esm/modules/secrets/dotenv/dotenv.helper.d.ts.map +0 -1
  553. package/dist/esm/modules/secrets/dotenv/index.d.ts.map +0 -1
  554. package/dist/esm/modules/secrets/factory.d.ts.map +0 -1
  555. package/dist/esm/modules/secrets/hashicorp/auth.d.ts.map +0 -1
  556. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts.map +0 -1
  557. package/dist/esm/modules/secrets/hashicorp/index.d.ts.map +0 -1
  558. package/dist/esm/modules/secrets/index.d.ts.map +0 -1
  559. package/dist/esm/modules/secrets/system-envs/index.d.ts.map +0 -1
  560. package/dist/esm/modules/secrets/system-envs/system-envs.helper.d.ts.map +0 -1
  561. package/dist/esm/modules/slug/common/constants.d.ts.map +0 -1
  562. package/dist/esm/modules/slug/common/index.d.ts.map +0 -1
  563. package/dist/esm/modules/slug/helper.d.ts.map +0 -1
  564. package/dist/esm/modules/slug/index.d.ts.map +0 -1
  565. package/dist/esm/modules/socket/index.d.ts.map +0 -1
  566. package/dist/esm/modules/socket/socket-io/browser.d.ts.map +0 -1
  567. package/dist/esm/modules/socket/socket-io/client/browser-helper.d.ts.map +0 -1
  568. package/dist/esm/modules/socket/socket-io/client/helper.d.ts.map +0 -1
  569. package/dist/esm/modules/socket/socket-io/client/index.d.ts.map +0 -1
  570. package/dist/esm/modules/socket/socket-io/common/constants.d.ts.map +0 -1
  571. package/dist/esm/modules/socket/socket-io/common/index.d.ts.map +0 -1
  572. package/dist/esm/modules/socket/socket-io/common/types/client.d.ts.map +0 -1
  573. package/dist/esm/modules/socket/socket-io/common/types/hooks.d.ts.map +0 -1
  574. package/dist/esm/modules/socket/socket-io/common/types/index.d.ts.map +0 -1
  575. package/dist/esm/modules/socket/socket-io/common/types/server.d.ts.map +0 -1
  576. package/dist/esm/modules/socket/socket-io/index.d.ts.map +0 -1
  577. package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +0 -1
  578. package/dist/esm/modules/socket/socket-io/server/index.d.ts.map +0 -1
  579. package/dist/esm/modules/socket/websocket/common/constants.d.ts.map +0 -1
  580. package/dist/esm/modules/socket/websocket/common/index.d.ts.map +0 -1
  581. package/dist/esm/modules/socket/websocket/common/types/client.d.ts.map +0 -1
  582. package/dist/esm/modules/socket/websocket/common/types/hooks.d.ts.map +0 -1
  583. package/dist/esm/modules/socket/websocket/common/types/index.d.ts.map +0 -1
  584. package/dist/esm/modules/socket/websocket/common/types/message.d.ts.map +0 -1
  585. package/dist/esm/modules/socket/websocket/common/types/server.d.ts.map +0 -1
  586. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +0 -1
  587. package/dist/esm/modules/socket/websocket/emitter/index.d.ts.map +0 -1
  588. package/dist/esm/modules/socket/websocket/index.d.ts.map +0 -1
  589. package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +0 -1
  590. package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +0 -1
  591. package/dist/esm/modules/socket/websocket/server/index.d.ts.map +0 -1
  592. package/dist/esm/modules/storage/base.d.ts.map +0 -1
  593. package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +0 -1
  594. package/dist/esm/modules/storage/bun-s3/index.d.ts.map +0 -1
  595. package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +0 -1
  596. package/dist/esm/modules/storage/common/constants.d.ts.map +0 -1
  597. package/dist/esm/modules/storage/common/errors.d.ts.map +0 -1
  598. package/dist/esm/modules/storage/common/index.d.ts.map +0 -1
  599. package/dist/esm/modules/storage/common/types.d.ts.map +0 -1
  600. package/dist/esm/modules/storage/common/utility.d.ts.map +0 -1
  601. package/dist/esm/modules/storage/disk/helper.d.ts.map +0 -1
  602. package/dist/esm/modules/storage/disk/index.d.ts.map +0 -1
  603. package/dist/esm/modules/storage/in-memory/helper.d.ts.map +0 -1
  604. package/dist/esm/modules/storage/in-memory/index.d.ts.map +0 -1
  605. package/dist/esm/modules/storage/index.d.ts.map +0 -1
  606. package/dist/esm/modules/temporal/abstract.d.ts.map +0 -1
  607. package/dist/esm/modules/temporal/adapters/dayjs.d.ts.map +0 -1
  608. package/dist/esm/modules/temporal/adapters/index.d.ts.map +0 -1
  609. package/dist/esm/modules/temporal/adapters/intl.d.ts.map +0 -1
  610. package/dist/esm/modules/temporal/adapters/luxon.d.ts.map +0 -1
  611. package/dist/esm/modules/temporal/adapters/native.d.ts.map +0 -1
  612. package/dist/esm/modules/temporal/calendar/calendar.d.ts.map +0 -1
  613. package/dist/esm/modules/temporal/calendar/index.d.ts.map +0 -1
  614. package/dist/esm/modules/temporal/common/constants.d.ts.map +0 -1
  615. package/dist/esm/modules/temporal/common/index.d.ts.map +0 -1
  616. package/dist/esm/modules/temporal/common/types.d.ts.map +0 -1
  617. package/dist/esm/modules/temporal/duration/duration.d.ts.map +0 -1
  618. package/dist/esm/modules/temporal/duration/index.d.ts.map +0 -1
  619. package/dist/esm/modules/temporal/helper.d.ts.map +0 -1
  620. package/dist/esm/modules/temporal/index.d.ts.map +0 -1
  621. package/dist/esm/modules/temporal/locale/index.d.ts.map +0 -1
  622. package/dist/esm/modules/temporal/locale/locale.d.ts.map +0 -1
  623. package/dist/esm/modules/temporal/pattern/common/constants.d.ts.map +0 -1
  624. package/dist/esm/modules/temporal/pattern/common/index.d.ts.map +0 -1
  625. package/dist/esm/modules/temporal/pattern/common/types.d.ts.map +0 -1
  626. package/dist/esm/modules/temporal/pattern/index.d.ts.map +0 -1
  627. package/dist/esm/modules/temporal/pattern/pattern.d.ts.map +0 -1
  628. package/dist/esm/modules/temporal/pattern/tokens.d.ts.map +0 -1
  629. package/dist/esm/modules/tree/builder.d.ts.map +0 -1
  630. package/dist/esm/modules/tree/common/index.d.ts.map +0 -1
  631. package/dist/esm/modules/tree/common/types.d.ts.map +0 -1
  632. package/dist/esm/modules/tree/index.d.ts.map +0 -1
  633. package/dist/esm/modules/tree/walk.d.ts.map +0 -1
  634. package/dist/esm/modules/uid/common/constants.d.ts.map +0 -1
  635. package/dist/esm/modules/uid/common/index.d.ts.map +0 -1
  636. package/dist/esm/modules/uid/common/types.d.ts.map +0 -1
  637. package/dist/esm/modules/uid/helper.d.ts.map +0 -1
  638. package/dist/esm/modules/uid/index.d.ts.map +0 -1
  639. package/dist/esm/modules/uid/opaque.d.ts.map +0 -1
  640. package/dist/esm/modules/uid/request-id.d.ts.map +0 -1
  641. package/dist/esm/modules/uid/uuid/common/constants.d.ts.map +0 -1
  642. package/dist/esm/modules/uid/uuid/common/index.d.ts.map +0 -1
  643. package/dist/esm/modules/uid/uuid/common/types.d.ts.map +0 -1
  644. package/dist/esm/modules/uid/uuid/helper.d.ts.map +0 -1
  645. package/dist/esm/modules/uid/uuid/index.d.ts.map +0 -1
  646. package/dist/esm/modules/uid/uuid/sha1.d.ts.map +0 -1
  647. package/dist/esm/modules/uid/uuid/v4.d.ts.map +0 -1
  648. package/dist/esm/modules/uid/uuid/v5.d.ts.map +0 -1
  649. package/dist/esm/modules/uid/uuid/v7.d.ts.map +0 -1
  650. package/dist/esm/modules/worker-thread/bus/abstract.d.ts.map +0 -1
  651. package/dist/esm/modules/worker-thread/bus/base.d.ts.map +0 -1
  652. package/dist/esm/modules/worker-thread/bus/handler/abstract.d.ts.map +0 -1
  653. package/dist/esm/modules/worker-thread/bus/handler/base.d.ts.map +0 -1
  654. package/dist/esm/modules/worker-thread/bus/handler/index.d.ts.map +0 -1
  655. package/dist/esm/modules/worker-thread/bus/index.d.ts.map +0 -1
  656. package/dist/esm/modules/worker-thread/common/index.d.ts.map +0 -1
  657. package/dist/esm/modules/worker-thread/common/types.d.ts.map +0 -1
  658. package/dist/esm/modules/worker-thread/index.d.ts.map +0 -1
  659. package/dist/esm/modules/worker-thread/thread/abstract.d.ts.map +0 -1
  660. package/dist/esm/modules/worker-thread/thread/base.d.ts.map +0 -1
  661. package/dist/esm/modules/worker-thread/thread/index.d.ts.map +0 -1
  662. package/dist/esm/modules/worker-thread/worker/abstract.d.ts.map +0 -1
  663. package/dist/esm/modules/worker-thread/worker/base.d.ts.map +0 -1
  664. package/dist/esm/modules/worker-thread/worker/index.d.ts.map +0 -1
  665. package/dist/esm/modules/worker-thread/worker-pool.d.ts.map +0 -1
  666. package/dist/esm/temporal.d.ts.map +0 -1
  667. package/dist/esm/utilities/build-info.utility.d.ts.map +0 -1
  668. package/dist/esm/utilities/error.utility.d.ts.map +0 -1
  669. package/dist/esm/utilities/form-body.utility.d.ts.map +0 -1
  670. package/dist/esm/utilities/hr-time.utility.d.ts.map +0 -1
  671. package/dist/esm/utilities/index.d.ts.map +0 -1
  672. package/dist/esm/utilities/module.utility.d.ts.map +0 -1
  673. package/dist/esm/utilities/parse.utility.d.ts.map +0 -1
  674. package/dist/esm/utilities/performance.utility.d.ts.map +0 -1
  675. package/dist/esm/utilities/project-root.utility.d.ts.map +0 -1
  676. package/dist/esm/utilities/promise.utility.d.ts.map +0 -1
  677. package/dist/esm/utilities/request.utility.d.ts.map +0 -1
  678. package/dist/esm/uuid.d.ts.map +0 -1
@@ -11,18 +11,35 @@ export interface IUidSegment {
11
11
  enable: boolean;
12
12
  value?: string;
13
13
  }
14
+ /** Options for generating an opaque id. Every field is optional. */
14
15
  export interface IOpaqueUidOptions {
15
- /** Defaults to disabled. */
16
+ /** @default { enable: false } */
16
17
  prefix?: IUidSegment;
17
- /** Defaults to disabled, with `_` ready. Meaningless without a prefix, and refused there. */
18
+ /**
19
+ * Meaningless without a prefix, and refused there. Enabled without a `value`, it is {@link DEFAULT_UID_DELIMITER}.
20
+ *
21
+ * @default { enable: false }
22
+ */
18
23
  delimiter?: IUidSegment;
19
- /** Characters in the BODY. The prefix and the delimiter are not counted. */
24
+ /**
25
+ * Characters in the BODY. The prefix and the delimiter are not counted.
26
+ *
27
+ * @default DEFAULT_UID_LENGTH
28
+ */
20
29
  length?: number;
21
- /** Defaults to `upper` - the alphabet default is uppercase-only, so anything else would widen it. */
30
+ /**
31
+ * Upper is the default because the default alphabet is uppercase-only, so anything else would widen it.
32
+ *
33
+ * @default UidCaseForms.UPPER
34
+ */
22
35
  caseForm?: TUidCaseForm;
23
- /** Defaults to `UidAlphabets.CROCKFORD`. */
36
+ /** @default UidAlphabets.CROCKFORD */
24
37
  alphabet?: string;
25
- /** Removed from `alphabet` on top of whatever the set already drops. */
38
+ /**
39
+ * Removed from `alphabet` on top of whatever the set already drops.
40
+ *
41
+ * @default ''
42
+ */
26
43
  exclude?: string;
27
44
  }
28
45
  /**
@@ -45,7 +62,11 @@ export interface INextOpaqueUidOptions<TVerdict extends ValueOrPromise<boolean>
45
62
  * collision rate; the unique index and the regenerate-on-violation insert are what remove it.
46
63
  */
47
64
  isAvailable?: (id: string) => TVerdict;
48
- /** Draws before giving up, when `isAvailable` is supplied. Defaults to {@link DEFAULT_UID_MAX_ATTEMPTS}. */
65
+ /**
66
+ * Draws before giving up, when `isAvailable` is supplied.
67
+ *
68
+ * @default DEFAULT_UID_MAX_ATTEMPTS
69
+ */
49
70
  maxAttempts?: number;
50
71
  }
51
72
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/uid/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@/common/types';\nimport type { TUidCaseForm } from './constants';\n\n/**\n * A segment an id may or may not carry. `enable` decides; `value` survives being turned off, so a\n * caller can flip a configured delimiter back on without having to remember what it was.\n *\n * An empty string is NOT the off switch. That conflates \"no prefix\" with \"a prefix I have not filled\n * in yet\", and the second one is a bug worth reporting rather than silently accepting.\n */\nexport interface IUidSegment {\n enable: boolean;\n value?: string;\n}\n\nexport interface IOpaqueUidOptions {\n /** Defaults to disabled. */\n prefix?: IUidSegment;\n\n /** Defaults to disabled, with `_` ready. Meaningless without a prefix, and refused there. */\n delimiter?: IUidSegment;\n\n /** Characters in the BODY. The prefix and the delimiter are not counted. */\n length?: number;\n\n /** Defaults to `upper` - the alphabet default is uppercase-only, so anything else would widen it. */\n caseForm?: TUidCaseForm;\n\n /** Defaults to `UidAlphabets.CROCKFORD`. */\n alphabet?: string;\n\n /** Removed from `alphabet` on top of whatever the set already drops. */\n exclude?: string;\n}\n\n/**\n * `TVerdict` is what `isAvailable` returns, and it decides what `nextId` returns: a synchronous\n * check keeps the call synchronous, an asynchronous one makes it a promise. See the overloads on\n * `OpaqueUidHelper.nextId`.\n */\nexport interface INextOpaqueUidOptions<\n TVerdict extends ValueOrPromise<boolean> = ValueOrPromise<boolean>,\n> {\n /** Replaces the configured prefix for this call and turns it on. An empty string is refused - that is what the toggle is for. */\n prefix?: string;\n\n /**\n * Whether the drawn id may be used. `true` accepts it, `false` means taken and draws another.\n *\n * Named for what it RETURNS, not for the question it answers: an `exists` callback returning\n * `true` for a usable id is the sort of inverted polarity a reader gets wrong once and debugs for\n * an hour.\n *\n * An ASYNCHRONOUS check does not make an id safe. Against a database it is a read and then a\n * write with a gap in between, and another request can take the id inside that gap. It lowers the\n * collision rate; the unique index and the regenerate-on-violation insert are what remove it.\n */\n isAvailable?: (id: string) => TVerdict;\n\n /** Draws before giving up, when `isAvailable` is supplied. Defaults to {@link DEFAULT_UID_MAX_ATTEMPTS}. */\n maxAttempts?: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/uid/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@/common/types';\nimport type { TUidCaseForm } from './constants';\n\n/**\n * A segment an id may or may not carry. `enable` decides; `value` survives being turned off, so a\n * caller can flip a configured delimiter back on without having to remember what it was.\n *\n * An empty string is NOT the off switch. That conflates \"no prefix\" with \"a prefix I have not filled\n * in yet\", and the second one is a bug worth reporting rather than silently accepting.\n */\nexport interface IUidSegment {\n enable: boolean;\n value?: string;\n}\n\n/** Options for generating an opaque id. Every field is optional. */\nexport interface IOpaqueUidOptions {\n /** @default { enable: false } */\n prefix?: IUidSegment;\n\n /**\n * Meaningless without a prefix, and refused there. Enabled without a `value`, it is {@link DEFAULT_UID_DELIMITER}.\n *\n * @default { enable: false }\n */\n delimiter?: IUidSegment;\n\n /**\n * Characters in the BODY. The prefix and the delimiter are not counted.\n *\n * @default DEFAULT_UID_LENGTH\n */\n length?: number;\n\n /**\n * Upper is the default because the default alphabet is uppercase-only, so anything else would widen it.\n *\n * @default UidCaseForms.UPPER\n */\n caseForm?: TUidCaseForm;\n\n /** @default UidAlphabets.CROCKFORD */\n alphabet?: string;\n\n /**\n * Removed from `alphabet` on top of whatever the set already drops.\n *\n * @default ''\n */\n exclude?: string;\n}\n\n/**\n * `TVerdict` is what `isAvailable` returns, and it decides what `nextId` returns: a synchronous\n * check keeps the call synchronous, an asynchronous one makes it a promise. See the overloads on\n * `OpaqueUidHelper.nextId`.\n */\nexport interface INextOpaqueUidOptions<\n TVerdict extends ValueOrPromise<boolean> = ValueOrPromise<boolean>,\n> {\n /** Replaces the configured prefix for this call and turns it on. An empty string is refused - that is what the toggle is for. */\n prefix?: string;\n\n /**\n * Whether the drawn id may be used. `true` accepts it, `false` means taken and draws another.\n *\n * Named for what it RETURNS, not for the question it answers: an `exists` callback returning\n * `true` for a usable id is the sort of inverted polarity a reader gets wrong once and debugs for\n * an hour.\n *\n * An ASYNCHRONOUS check does not make an id safe. Against a database it is a read and then a\n * write with a gap in between, and another request can take the id inside that gap. It lowers the\n * collision rate; the unique index and the regenerate-on-violation insert are what remove it.\n */\n isAvailable?: (id: string) => TVerdict;\n\n /**\n * Draws before giving up, when `isAvailable` is supplied.\n *\n * @default DEFAULT_UID_MAX_ATTEMPTS\n */\n maxAttempts?: number;\n}\n"]}
@@ -13,10 +13,22 @@ export declare class SnowflakeConfig {
13
13
  static readonly MAX_TIMESTAMP_MS: bigint;
14
14
  static readonly WARNING_THRESHOLD_MS: bigint;
15
15
  }
16
+ /** Options for `SnowflakeUidHelper`. */
16
17
  export interface IIdGeneratorOptions {
18
+ /**
19
+ * Integer from 0 to 1023.
20
+ *
21
+ * @default 199
22
+ */
17
23
  workerId?: number;
24
+ /**
25
+ * Milliseconds since the Unix epoch.
26
+ *
27
+ * @default SnowflakeConfig.DEFAULT_EPOCH
28
+ */
18
29
  epoch?: bigint;
19
30
  }
31
+ /** The fields of a Snowflake id, as decoded from its raw `bigint`. */
20
32
  export interface ISnowflakeParsedId {
21
33
  raw: bigint;
22
34
  timestamp: Date;
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/modules/uid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE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,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEnF,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC;aACjC,IAAI,CACH,wHAAwH,EACxH,cAAc,EACd,UAAU,CAAC,WAAW,EAAE,CACzB,CAAC;IACN,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport { BaseHelper } from '../base';\nimport { getError } from '../error';\n\nconst BASE62_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n\n/** Snowflake bit layout: 48-bit timestamp (~8,919 years), 10-bit worker ID (max 1024 workers), 12-bit sequence (4096/ms/worker). */\nexport class SnowflakeConfig {\n static readonly DEFAULT_EPOCH = BigInt(1735689600000); // 2025-01-01 00:00:00 UTC\n static readonly TIMESTAMP_BITS = BigInt(48);\n static readonly WORKER_ID_BITS = BigInt(10);\n static readonly SEQUENCE_BITS = BigInt(12);\n static readonly MAX_WORKER_ID = (BigInt(1) << BigInt(10)) - BigInt(1); // 1023\n static readonly MAX_SEQUENCE = (BigInt(1) << BigInt(12)) - BigInt(1); // 4095\n static readonly WORKER_ID_SHIFT = BigInt(12);\n static readonly TIMESTAMP_SHIFT = BigInt(22); // 10 + 12\n static readonly MAX_CLOCK_BACKWARD_MS = BigInt(100);\n\n // 48 bits max = ~8,919 years, warn 10 years before expiry (~8,909 years)\n static readonly MAX_TIMESTAMP_MS = (BigInt(1) << BigInt(48)) - BigInt(1);\n static readonly WARNING_THRESHOLD_MS = BigInt(Math.floor(8909 * 365.25 * 24 * 60 * 60 * 1000)); // ~8,909 years\n}\n\nexport interface IIdGeneratorOptions {\n workerId?: number;\n epoch?: bigint;\n}\n\nexport interface ISnowflakeParsedId {\n raw: bigint;\n timestamp: Date;\n workerId: number;\n sequence: number;\n}\n\n/** Snowflake ID generator with Base62 encoding for distributed, time-sortable unique IDs. */\nexport class SnowflakeUidHelper extends BaseHelper {\n private readonly workerId: bigint;\n private readonly epoch: bigint;\n private sequence: bigint = BigInt(0);\n private lastTimestamp: bigint = BigInt(-1);\n\n constructor(opts?: IIdGeneratorOptions) {\n super({ scope: SnowflakeUidHelper.name });\n\n const workerId = opts?.workerId ?? 199;\n const epoch = opts?.epoch ?? SnowflakeConfig.DEFAULT_EPOCH;\n\n this.validateWorkerId(workerId);\n this.workerId = BigInt(workerId);\n\n this.validateEpoch(epoch);\n this.epoch = epoch;\n\n this.logger\n .for(this.constructor.name)\n .info(\n 'Initialized | workerId: %d | epoch: %s | epochDate: %s',\n workerId,\n epoch.toString(),\n new Date(Number(epoch)).toISOString(),\n );\n }\n\n /** Generate next unique ID as Base62 string. */\n nextId(): string {\n const snowflake = this.nextSnowflake();\n return this.encodeBase62(snowflake);\n }\n\n /** Generate next unique ID as raw Snowflake bigint. */\n nextSnowflake(): bigint {\n let timestamp = this.currentTimestamp();\n\n if (timestamp < this.lastTimestamp) {\n const diff = this.lastTimestamp - timestamp;\n this.logger\n .for(this.nextSnowflake.name)\n .warn('Clock moved backward | diff: %d ms', Number(diff));\n\n if (diff <= SnowflakeConfig.MAX_CLOCK_BACKWARD_MS) {\n timestamp = this.waitForNextMs(this.lastTimestamp);\n } else {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][nextSnowflake] Clock moved backward by ${diff}ms. Refusing to generate ID.`,\n });\n }\n }\n\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & SnowflakeConfig.MAX_SEQUENCE;\n\n if (this.sequence === BigInt(0)) {\n timestamp = this.waitForNextMs(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n\n this.lastTimestamp = timestamp;\n\n this.checkExpiryWarning(timestamp);\n\n const id =\n ((timestamp - this.epoch) << SnowflakeConfig.TIMESTAMP_SHIFT) |\n (this.workerId << SnowflakeConfig.WORKER_ID_SHIFT) |\n this.sequence;\n\n return id;\n }\n\n /** Encode a bigint to Base62 string. */\n encodeBase62(num: bigint): string {\n if (num === BigInt(0)) {\n return BASE62_CHARS[0];\n }\n\n let result = '';\n let value = num;\n const base = BigInt(BASE62_CHARS.length);\n\n while (value > BigInt(0)) {\n const remainder = value % base;\n result = BASE62_CHARS[Number(remainder)] + result;\n value = value / base;\n }\n\n return result;\n }\n\n /** Decode a Base62 string to bigint. */\n decodeBase62(str: string): bigint {\n if (!str) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: '[IdGenerator][decodeBase62] Base62 input must not be empty',\n });\n }\n\n let result = BigInt(0);\n const base = BigInt(BASE62_CHARS.length);\n\n for (const char of str) {\n const index = BASE62_CHARS.indexOf(char);\n if (index === -1) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[IdGenerator][decodeBase62] Invalid Base62 character: ${char}`,\n });\n }\n result = result * base + BigInt(index);\n }\n\n return result;\n }\n\n /** Extract timestamp from a Snowflake ID. */\n extractTimestamp(id: bigint): Date {\n const timestamp = (id >> SnowflakeConfig.TIMESTAMP_SHIFT) + this.epoch;\n return new Date(Number(timestamp));\n }\n\n /** Extract worker ID from a Snowflake ID. */\n extractWorkerId(id: bigint): number {\n const extractedWorkerId =\n (id >> SnowflakeConfig.WORKER_ID_SHIFT) & SnowflakeConfig.MAX_WORKER_ID;\n return Number(extractedWorkerId);\n }\n\n /** Extract sequence from a Snowflake ID. */\n extractSequence(id: bigint): number {\n return Number(id & SnowflakeConfig.MAX_SEQUENCE);\n }\n\n /** Parse a Base62 ID and extract its components. */\n parseId(base62Id: string): ISnowflakeParsedId {\n const raw = this.decodeBase62(base62Id);\n return {\n raw,\n timestamp: this.extractTimestamp(raw),\n workerId: this.extractWorkerId(raw),\n sequence: this.extractSequence(raw),\n };\n }\n\n /** Get current worker ID. */\n getWorkerId(): number {\n return Number(this.workerId);\n }\n\n private currentTimestamp(): bigint {\n return BigInt(Date.now());\n }\n\n private waitForNextMs(lastTimestamp: bigint): bigint {\n let timestamp = this.currentTimestamp();\n while (timestamp <= lastTimestamp) {\n timestamp = this.currentTimestamp();\n }\n return timestamp;\n }\n\n private validateWorkerId(workerId: number): void {\n if (\n !Number.isInteger(workerId) ||\n workerId < 0 ||\n workerId > Number(SnowflakeConfig.MAX_WORKER_ID)\n ) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][validateWorkerId] Worker ID must be an integer between 0 and ${SnowflakeConfig.MAX_WORKER_ID} | received: ${workerId}`,\n });\n }\n }\n\n private validateEpoch(epoch: bigint): void {\n const now = BigInt(Date.now());\n\n if (epoch <= BigInt(0)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][validateEpoch] Epoch must be a positive number | received: ${epoch}`,\n });\n }\n\n if (epoch > now) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][validateEpoch] Epoch cannot be in the future | received: ${epoch} (${new Date(Number(epoch)).toISOString()}) | now: ${now}`,\n });\n }\n }\n\n private checkExpiryWarning(timestamp: bigint): void {\n const elapsedMs = timestamp - this.epoch;\n\n if (elapsedMs < SnowflakeConfig.WARNING_THRESHOLD_MS) {\n return;\n }\n\n const remainingMs = SnowflakeConfig.MAX_TIMESTAMP_MS - elapsedMs;\n const remainingYears = Number(remainingMs) / (365.25 * 24 * 60 * 60 * 1000);\n const expiryDate = new Date(Number(this.epoch + SnowflakeConfig.MAX_TIMESTAMP_MS));\n\n this.logger\n .for(this.checkExpiryWarning.name)\n .warn(\n 'Snowflake ID sequence approaching expiry | remainingYears: %.2f | expiryDate: %s | action: Plan migration to new epoch',\n remainingYears,\n expiryDate.toISOString(),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/modules/uid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,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G,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEnF,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC;aACjC,IAAI,CACH,wHAAwH,EACxH,cAAc,EACd,UAAU,CAAC,WAAW,EAAE,CACzB,CAAC;IACN,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport { BaseHelper } from '../base';\nimport { getError } from '../error';\n\nconst BASE62_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n\n/** Snowflake bit layout: 48-bit timestamp (~8,919 years), 10-bit worker ID (max 1024 workers), 12-bit sequence (4096/ms/worker). */\nexport class SnowflakeConfig {\n static readonly DEFAULT_EPOCH = BigInt(1735689600000); // 2025-01-01 00:00:00 UTC\n static readonly TIMESTAMP_BITS = BigInt(48);\n static readonly WORKER_ID_BITS = BigInt(10);\n static readonly SEQUENCE_BITS = BigInt(12);\n static readonly MAX_WORKER_ID = (BigInt(1) << BigInt(10)) - BigInt(1); // 1023\n static readonly MAX_SEQUENCE = (BigInt(1) << BigInt(12)) - BigInt(1); // 4095\n static readonly WORKER_ID_SHIFT = BigInt(12);\n static readonly TIMESTAMP_SHIFT = BigInt(22); // 10 + 12\n static readonly MAX_CLOCK_BACKWARD_MS = BigInt(100);\n\n // 48 bits max = ~8,919 years, warn 10 years before expiry (~8,909 years)\n static readonly MAX_TIMESTAMP_MS = (BigInt(1) << BigInt(48)) - BigInt(1);\n static readonly WARNING_THRESHOLD_MS = BigInt(Math.floor(8909 * 365.25 * 24 * 60 * 60 * 1000)); // ~8,909 years\n}\n\n/** Options for `SnowflakeUidHelper`. */\nexport interface IIdGeneratorOptions {\n /**\n * Integer from 0 to 1023.\n *\n * @default 199\n */\n workerId?: number;\n /**\n * Milliseconds since the Unix epoch.\n *\n * @default SnowflakeConfig.DEFAULT_EPOCH\n */\n epoch?: bigint;\n}\n\n/** The fields of a Snowflake id, as decoded from its raw `bigint`. */\nexport interface ISnowflakeParsedId {\n raw: bigint;\n timestamp: Date;\n workerId: number;\n sequence: number;\n}\n\n/** Snowflake ID generator with Base62 encoding for distributed, time-sortable unique IDs. */\nexport class SnowflakeUidHelper extends BaseHelper {\n private readonly workerId: bigint;\n private readonly epoch: bigint;\n private sequence: bigint = BigInt(0);\n private lastTimestamp: bigint = BigInt(-1);\n\n constructor(opts?: IIdGeneratorOptions) {\n super({ scope: SnowflakeUidHelper.name });\n\n const workerId = opts?.workerId ?? 199;\n const epoch = opts?.epoch ?? SnowflakeConfig.DEFAULT_EPOCH;\n\n this.validateWorkerId(workerId);\n this.workerId = BigInt(workerId);\n\n this.validateEpoch(epoch);\n this.epoch = epoch;\n\n this.logger\n .for(this.constructor.name)\n .info(\n 'Initialized | workerId: %d | epoch: %s | epochDate: %s',\n workerId,\n epoch.toString(),\n new Date(Number(epoch)).toISOString(),\n );\n }\n\n /** Generate next unique ID as Base62 string. */\n nextId(): string {\n const snowflake = this.nextSnowflake();\n\n return this.encodeBase62(snowflake);\n }\n\n /** Generate next unique ID as raw Snowflake bigint. */\n nextSnowflake(): bigint {\n let timestamp = this.currentTimestamp();\n\n if (timestamp < this.lastTimestamp) {\n const diff = this.lastTimestamp - timestamp;\n this.logger\n .for(this.nextSnowflake.name)\n .warn('Clock moved backward | diff: %d ms', Number(diff));\n\n if (diff <= SnowflakeConfig.MAX_CLOCK_BACKWARD_MS) {\n timestamp = this.waitForNextMs(this.lastTimestamp);\n } else {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][nextSnowflake] Clock moved backward by ${diff}ms. Refusing to generate ID.`,\n });\n }\n }\n\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & SnowflakeConfig.MAX_SEQUENCE;\n\n if (this.sequence === BigInt(0)) {\n timestamp = this.waitForNextMs(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n\n this.lastTimestamp = timestamp;\n\n this.checkExpiryWarning(timestamp);\n\n const id =\n ((timestamp - this.epoch) << SnowflakeConfig.TIMESTAMP_SHIFT) |\n (this.workerId << SnowflakeConfig.WORKER_ID_SHIFT) |\n this.sequence;\n\n return id;\n }\n\n /** Encode a bigint to Base62 string. */\n encodeBase62(num: bigint): string {\n if (num === BigInt(0)) {\n return BASE62_CHARS[0];\n }\n\n let result = '';\n let value = num;\n const base = BigInt(BASE62_CHARS.length);\n\n while (value > BigInt(0)) {\n const remainder = value % base;\n result = BASE62_CHARS[Number(remainder)] + result;\n value = value / base;\n }\n\n return result;\n }\n\n /** Decode a Base62 string to bigint. */\n decodeBase62(str: string): bigint {\n if (!str) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: '[IdGenerator][decodeBase62] Base62 input must not be empty',\n });\n }\n\n let result = BigInt(0);\n const base = BigInt(BASE62_CHARS.length);\n\n for (const char of str) {\n const index = BASE62_CHARS.indexOf(char);\n\n if (index === -1) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[IdGenerator][decodeBase62] Invalid Base62 character: ${char}`,\n });\n }\n\n result = result * base + BigInt(index);\n }\n\n return result;\n }\n\n /** Extract timestamp from a Snowflake ID. */\n extractTimestamp(id: bigint): Date {\n const timestamp = (id >> SnowflakeConfig.TIMESTAMP_SHIFT) + this.epoch;\n\n return new Date(Number(timestamp));\n }\n\n /** Extract worker ID from a Snowflake ID. */\n extractWorkerId(id: bigint): number {\n const extractedWorkerId =\n (id >> SnowflakeConfig.WORKER_ID_SHIFT) & SnowflakeConfig.MAX_WORKER_ID;\n\n return Number(extractedWorkerId);\n }\n\n /** Extract sequence from a Snowflake ID. */\n extractSequence(id: bigint): number {\n return Number(id & SnowflakeConfig.MAX_SEQUENCE);\n }\n\n /** Parse a Base62 ID and extract its components. */\n parseId(base62Id: string): ISnowflakeParsedId {\n const raw = this.decodeBase62(base62Id);\n\n return {\n raw,\n timestamp: this.extractTimestamp(raw),\n workerId: this.extractWorkerId(raw),\n sequence: this.extractSequence(raw),\n };\n }\n\n /** Get current worker ID. */\n getWorkerId(): number {\n return Number(this.workerId);\n }\n\n private currentTimestamp(): bigint {\n return BigInt(Date.now());\n }\n\n private waitForNextMs(lastTimestamp: bigint): bigint {\n let timestamp = this.currentTimestamp();\n\n while (timestamp <= lastTimestamp) {\n timestamp = this.currentTimestamp();\n }\n\n return timestamp;\n }\n\n private validateWorkerId(workerId: number): void {\n if (\n !Number.isInteger(workerId) ||\n workerId < 0 ||\n workerId > Number(SnowflakeConfig.MAX_WORKER_ID)\n ) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][validateWorkerId] Worker ID must be an integer between 0 and ${SnowflakeConfig.MAX_WORKER_ID} | received: ${workerId}`,\n });\n }\n }\n\n private validateEpoch(epoch: bigint): void {\n const now = BigInt(Date.now());\n\n if (epoch <= BigInt(0)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][validateEpoch] Epoch must be a positive number | received: ${epoch}`,\n });\n }\n\n if (epoch > now) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[IdGenerator][validateEpoch] Epoch cannot be in the future | received: ${epoch} (${new Date(Number(epoch)).toISOString()}) | now: ${now}`,\n });\n }\n }\n\n private checkExpiryWarning(timestamp: bigint): void {\n const elapsedMs = timestamp - this.epoch;\n\n if (elapsedMs < SnowflakeConfig.WARNING_THRESHOLD_MS) {\n return;\n }\n\n const remainingMs = SnowflakeConfig.MAX_TIMESTAMP_MS - elapsedMs;\n const remainingYears = Number(remainingMs) / (365.25 * 24 * 60 * 60 * 1000);\n const expiryDate = new Date(Number(this.epoch + SnowflakeConfig.MAX_TIMESTAMP_MS));\n\n this.logger\n .for(this.checkExpiryWarning.name)\n .warn(\n 'Snowflake ID sequence approaching expiry | remainingYears: %.2f | expiryDate: %s | action: Plan migration to new epoch',\n remainingYears,\n expiryDate.toISOString(),\n );\n }\n}\n"]}
@@ -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,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,eAAe,CAAC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAElD,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,eAAe,CAAC;YAC9C,QAAQ,EAAE,IAAI,EAAE,QAAQ,IAAI,YAAY,CAAC,SAAS;YAClD,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE;YAC5B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AU,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"]}
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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AAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QAEvF,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\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\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\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\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\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\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\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\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\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 +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,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
+ {"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,YAA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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\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\n if (version !== 7) {\n return { version };\n }\n\n const milliseconds = Number.parseInt(value.slice(0, 8) + value.slice(9, 13), 16);\n\n return { version, createdAt: new Date(milliseconds) };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sha1.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/sha1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AK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;YACrB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YAClC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YACtC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;YACrC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["/**\n * SHA-1 over bytes, synchronous, no host API - a host module would fail the purity gate and\n * `crypto.subtle` is async and secure-context only.\n *\n * Only UUID v5 uses it. SHA-1 is broken against a chosen-prefix collision: never sign, authenticate\n * or store a password with it.\n */\nexport class Sha1Digest {\n /** Reused: `of()` never yields, so no second call can observe it mid-flight. */\n private static readonly SCHEDULE = new Uint32Array(80);\n\n /** Padding buffer sized for a namespace plus a name; a longer input allocates. */\n private static readonly SCRATCH = new Uint8Array(512);\n\n private static readonly K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];\n\n /** Digests `bytes` into 20 big-endian bytes. */\n static of(opts: { bytes: Uint8Array }): Uint8Array {\n const { bytes } = opts;\n const length = bytes.length;\n\n // Padding: a `0x80` byte, zeroes, then the bit length in the last 8 bytes of the last block.\n const blockCount = Math.floor((length + 8) / 64) + 1;\n const paddedLength = blockCount * 64;\n\n const reusable = paddedLength <= Sha1Digest.SCRATCH.length;\n const padded = reusable ? Sha1Digest.SCRATCH : new Uint8Array(paddedLength);\n\n padded.set(bytes);\n padded[length] = 0x80;\n if (reusable) {\n // The scratch still holds the previous input past this one: zero the gap, not the whole buffer.\n padded.fill(0, length + 1, paddedLength);\n }\n\n // The bit length is 3 bits wider than 32 for inputs over 512 MB: split it arithmetically.\n const bitsHigh = Math.floor(length / 0x20000000);\n const bitsLow = (length << 3) >>> 0;\n padded[paddedLength - 8] = (bitsHigh >>> 24) & 0xff;\n padded[paddedLength - 7] = (bitsHigh >>> 16) & 0xff;\n padded[paddedLength - 6] = (bitsHigh >>> 8) & 0xff;\n padded[paddedLength - 5] = bitsHigh & 0xff;\n padded[paddedLength - 4] = (bitsLow >>> 24) & 0xff;\n padded[paddedLength - 3] = (bitsLow >>> 16) & 0xff;\n padded[paddedLength - 2] = (bitsLow >>> 8) & 0xff;\n padded[paddedLength - 1] = bitsLow & 0xff;\n\n let h0 = 0x67452301;\n let h1 = 0xefcdab89;\n let h2 = 0x98badcfe;\n let h3 = 0x10325476;\n let h4 = 0xc3d2e1f0;\n\n const schedule = Sha1Digest.SCHEDULE;\n const constants = Sha1Digest.K;\n\n for (let block = 0; block < paddedLength; block += 64) {\n for (let index = 0; index < 16; index++) {\n const at = block + index * 4;\n schedule[index] =\n ((padded[at] << 24) | (padded[at + 1] << 16) | (padded[at + 2] << 8) | padded[at + 3]) >>>\n 0;\n }\n\n for (let index = 16; index < 80; index++) {\n const mixed =\n schedule[index - 3] ^ schedule[index - 8] ^ schedule[index - 14] ^ schedule[index - 16];\n schedule[index] = (mixed << 1) | (mixed >>> 31);\n }\n\n let a = h0;\n let b = h1;\n let c = h2;\n let d = h3;\n let e = h4;\n\n for (let index = 0; index < 80; index++) {\n const round = (index / 20) | 0;\n\n let mixed: number;\n if (round === 0) {\n mixed = (b & c) | (~b & d);\n } else if (round === 2) {\n mixed = (b & c) | (b & d) | (c & d);\n } else {\n mixed = b ^ c ^ d;\n }\n\n const next =\n (((a << 5) | (a >>> 27)) + mixed + e + constants[round] + schedule[index]) >>> 0;\n\n e = d;\n d = c;\n c = (b << 30) | (b >>> 2);\n b = a;\n a = next;\n }\n\n h0 = (h0 + a) >>> 0;\n h1 = (h1 + b) >>> 0;\n h2 = (h2 + c) >>> 0;\n h3 = (h3 + d) >>> 0;\n h4 = (h4 + e) >>> 0;\n }\n\n const digest = new Uint8Array(20);\n const words = [h0, h1, h2, h3, h4];\n for (let index = 0; index < 5; index++) {\n const word = words[index];\n const at = index * 4;\n digest[at] = (word >>> 24) & 0xff;\n digest[at + 1] = (word >>> 16) & 0xff;\n digest[at + 2] = (word >>> 8) & 0xff;\n digest[at + 3] = word & 0xff;\n }\n\n return digest;\n }\n}\n"]}
1
+ {"version":3,"file":"sha1.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/sha1.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IACrB,gFAAgF;aACxD,aAAQ,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IAEvD,kFAAkF;aAC1D,YAAO,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;aAE9B,MAAC,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE7E,gDAAgD;IAChD,MAAM,CAAC,EAAE,CAAC,IAA2B;QACnC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAE5B,6FAA6F;QAC7F,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACrD,MAAM,YAAY,GAAG,UAAU,GAAG,EAAE,CAAC;QAErC,MAAM,QAAQ,GAAG,YAAY,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,UAAU,CA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pB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAEnC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;YACrB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YAClC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YACtC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;YACrC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["/**\n * SHA-1 over bytes, synchronous, no host API - a host module would fail the purity gate and\n * `crypto.subtle` is async and secure-context only.\n *\n * Only UUID v5 uses it. SHA-1 is broken against a chosen-prefix collision: never sign, authenticate\n * or store a password with it.\n */\nexport class Sha1Digest {\n /** Reused: `of()` never yields, so no second call can observe it mid-flight. */\n private static readonly SCHEDULE = new Uint32Array(80);\n\n /** Padding buffer sized for a namespace plus a name; a longer input allocates. */\n private static readonly SCRATCH = new Uint8Array(512);\n\n private static readonly K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];\n\n /** Digests `bytes` into 20 big-endian bytes. */\n static of(opts: { bytes: Uint8Array }): Uint8Array {\n const { bytes } = opts;\n const length = bytes.length;\n\n // Padding: a `0x80` byte, zeroes, then the bit length in the last 8 bytes of the last block.\n const blockCount = Math.floor((length + 8) / 64) + 1;\n const paddedLength = blockCount * 64;\n\n const reusable = paddedLength <= Sha1Digest.SCRATCH.length;\n const padded = reusable ? Sha1Digest.SCRATCH : new Uint8Array(paddedLength);\n\n padded.set(bytes);\n padded[length] = 0x80;\n\n if (reusable) {\n // The scratch still holds the previous input past this one: zero the gap, not the whole buffer.\n padded.fill(0, length + 1, paddedLength);\n }\n\n // The bit length is 3 bits wider than 32 for inputs over 512 MB: split it arithmetically.\n const bitsHigh = Math.floor(length / 0x20000000);\n const bitsLow = (length << 3) >>> 0;\n padded[paddedLength - 8] = (bitsHigh >>> 24) & 0xff;\n padded[paddedLength - 7] = (bitsHigh >>> 16) & 0xff;\n padded[paddedLength - 6] = (bitsHigh >>> 8) & 0xff;\n padded[paddedLength - 5] = bitsHigh & 0xff;\n padded[paddedLength - 4] = (bitsLow >>> 24) & 0xff;\n padded[paddedLength - 3] = (bitsLow >>> 16) & 0xff;\n padded[paddedLength - 2] = (bitsLow >>> 8) & 0xff;\n padded[paddedLength - 1] = bitsLow & 0xff;\n\n let h0 = 0x67452301;\n let h1 = 0xefcdab89;\n let h2 = 0x98badcfe;\n let h3 = 0x10325476;\n let h4 = 0xc3d2e1f0;\n\n const schedule = Sha1Digest.SCHEDULE;\n const constants = Sha1Digest.K;\n\n for (let block = 0; block < paddedLength; block += 64) {\n for (let index = 0; index < 16; index++) {\n const at = block + index * 4;\n schedule[index] =\n ((padded[at] << 24) | (padded[at + 1] << 16) | (padded[at + 2] << 8) | padded[at + 3]) >>>\n 0;\n }\n\n for (let index = 16; index < 80; index++) {\n const mixed =\n schedule[index - 3] ^ schedule[index - 8] ^ schedule[index - 14] ^ schedule[index - 16];\n schedule[index] = (mixed << 1) | (mixed >>> 31);\n }\n\n let a = h0;\n let b = h1;\n let c = h2;\n let d = h3;\n let e = h4;\n\n for (let index = 0; index < 80; index++) {\n const round = (index / 20) | 0;\n\n let mixed: number;\n\n if (round === 0) {\n mixed = (b & c) | (~b & d);\n } else if (round === 2) {\n mixed = (b & c) | (b & d) | (c & d);\n } else {\n mixed = b ^ c ^ d;\n }\n\n const next =\n (((a << 5) | (a >>> 27)) + mixed + e + constants[round] + schedule[index]) >>> 0;\n\n e = d;\n d = c;\n c = (b << 30) | (b >>> 2);\n b = a;\n a = next;\n }\n\n h0 = (h0 + a) >>> 0;\n h1 = (h1 + b) >>> 0;\n h2 = (h2 + c) >>> 0;\n h3 = (h3 + d) >>> 0;\n h4 = (h4 + e) >>> 0;\n }\n\n const digest = new Uint8Array(20);\n const words = [h0, h1, h2, h3, h4];\n\n for (let index = 0; index < 5; index++) {\n const word = words[index];\n const at = index * 4;\n digest[at] = (word >>> 24) & 0xff;\n digest[at + 1] = (word >>> 16) & 0xff;\n digest[at + 2] = (word >>> 8) & 0xff;\n digest[at + 3] = word & 0xff;\n }\n\n return digest;\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /** Random UUID v4 generator. Use `generate()` for the shared instance or `create()` for one of your own. */
1
2
  export declare class UuidV4Generator {
2
3
  /**
3
4
  * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context
@@ -1,5 +1,6 @@
1
1
  import { UUID_HEX_OCTETS } from './common/constants.js';
2
2
  const POOL_SIZE = 16 * 256;
3
+ /** Random UUID v4 generator. Use `generate()` for the shared instance or `create()` for one of your own. */
3
4
  export class UuidV4Generator {
4
5
  /**
5
6
  * Builds a v4 generator. `crypto.randomUUID` is captured once - whether a realm is a secure context
@@ -1 +1 @@
1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CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG;gBACH,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
+ {"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,4GAA4G;AAC5G,MAAM,OAAO,eAAe;IAC1B;;;;OAIG;IACH,MAAM,CAAC,MAAM;QACX,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC;QAEjD,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;YACrC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAElD,OAAO,GAAG,EAA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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\n/** Random UUID v4 generator. Use `generate()` for the shared instance or `create()` for one of your own. */\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\n if (typeof randomUuid === 'function') {\n const native = randomUuid.bind(globalThis.crypto);\n\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,3 +1,4 @@
1
+ /** Deterministic UUID v5 generator: the same `namespace` and `name` always give the same id. Use `generate()` for the shared instance or `create()` for one with its own cache. */
1
2
  export declare class UuidV5Generator {
2
3
  /** Builds a v5 generator with its own namespace cache and buffer. */
3
4
  static create(): (opts: {
@@ -5,6 +5,7 @@ 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
+ /** Deterministic UUID v5 generator: the same `namespace` and `name` always give the same id. Use `generate()` for the shared instance or `create()` for one with its own cache. */
8
9
  export class UuidV5Generator {
9
10
  /** Builds a v5 generator with its own namespace cache and buffer. */
10
11
  static create() {
@@ -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,eAAe,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,4FAA4F;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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"]}
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,mLAAmL;AACnL,MAAM,OAA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","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/** Deterministic UUID v5 generator: the same `namespace` and `name` always give the same id. Use `generate()` for the shared instance or `create()` for one with its own cache. */\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\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\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"]}
@@ -1,3 +1,4 @@
1
+ /** Time-ordered UUID v7 generator. Use `generate()` for the shared instance or `create()` for one with its own clock state and counter. */
1
2
  export declare class UuidV7Generator {
2
3
  /**
3
4
  * Builds a v7 generator with its own clock state and counter. Never `Bun.randomUUIDv7`: it is
@@ -6,6 +6,7 @@ import { UUID_HEX_OCTETS } from './common/constants.js';
6
6
  const SHARED_SLOT = Symbol.for('@venizia/ignis-helpers:uuid-v7');
7
7
  const POOL_SIZE = 8 * 256;
8
8
  const MAX_COUNTER = 0xfff;
9
+ /** Time-ordered UUID v7 generator. Use `generate()` for the shared instance or `create()` for one with its own clock state and counter. */
9
10
  export class UuidV7Generator {
10
11
  /**
11
12
  * Builds a v7 generator with its own clock state and counter. Never `Bun.randomUUIDv7`: it is
@@ -1 +1 @@
1
- {"version":3,"file":"v7.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAEjE,MAAM,SAAS,GAAG,CAAC,GAAG,GAAG,CAAC;AAC1B,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,OAAO,eAAe;IAC1B;;;OAGG;IACH,MAAM,CAAC,MAAM;QACX,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;QACvC,IAAI,MAAM,GAAG,SAAS,CAAC;QACvB,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;QAChB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,sFAAsF;QACtF,MAAM,eAAe,GAAG,GAAW,EAAE;YACnC,IAAI,MAAM,GAAG,SAAS,GAAG,CAAC,EAAE,CAAC;gBAC3B,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;gBACxC,MAAM,GAAG,CAAC,CAAC;YACb,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;YAC9D,MAAM,IAAI,CAAC,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;QAEF,mDAAmD;QACnD,MAAM,YAAY,GAAG,CAAC,IAAoB,EAAU,EAAE;YACpD,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;YACpB,MAAM,GAAG,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E;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACb,OAAO,eAAe,CAAC,MAAM,EAAE,CAAC;IAClC,CAAC","sourcesContent":["import { UUID_HEX_OCTETS } from './common/constants';\n\n/**\n * One sequence per realm, so the CJS and ESM copies - and two helpers versions - never interleave two\n * counters. The slot holds a `() => string`; that key and shape are a contract across versions.\n */\nconst SHARED_SLOT = Symbol.for('@venizia/ignis-helpers:uuid-v7');\n\nconst POOL_SIZE = 8 * 256;\nconst MAX_COUNTER = 0xfff;\n\nexport class UuidV7Generator {\n /**\n * Builds a v7 generator with its own clock state and counter. Never `Bun.randomUUIDv7`: it is\n * slower, and it reads `(encoding, timestamp)` from whatever it is called with.\n */\n static create(): () => string {\n const pool = new Uint8Array(POOL_SIZE);\n let offset = POOL_SIZE;\n let lastMs = -1;\n let counter = 0;\n let prefix = '';\n\n /** Draws a counter seed below 0x800, leaving room to climb inside the millisecond. */\n const drawCounterSeed = (): number => {\n if (offset > POOL_SIZE - 2) {\n globalThis.crypto.getRandomValues(pool);\n offset = 0;\n }\n\n const seed = ((pool[offset] << 8) | pool[offset + 1]) & 0x7ff;\n offset += 2;\n return seed;\n };\n\n /** Renders the 48-bit timestamp half of the id. */\n const renderPrefix = (opts: { ms: number }): string => {\n const { ms } = opts;\n const hex = UUID_HEX_OCTETS;\n // 48 bits exceed the 32-bit bitwise range: split at 24 bits with arithmetic first.\n const high = Math.floor(ms / 0x1000000);\n const low = ms % 0x1000000;\n\n return (\n hex[(high >>> 16) & 0xff] +\n hex[(high >>> 8) & 0xff] +\n hex[high & 0xff] +\n hex[(low >>> 16) & 0xff] +\n '-' +\n hex[(low >>> 8) & 0xff] +\n hex[low & 0xff] +\n '-'\n );\n };\n\n return () => {\n const now = Date.now();\n\n if (now > lastMs) {\n lastMs = now;\n counter = drawCounterSeed();\n prefix = renderPrefix({ ms: now });\n } else if (++counter > MAX_COUNTER) {\n // Counter spent, or the clock stepped back: borrow the next millisecond rather than repeat.\n lastMs += 1;\n counter = drawCounterSeed();\n prefix = renderPrefix({ ms: lastMs });\n }\n\n if (offset > POOL_SIZE - 8) {\n globalThis.crypto.getRandomValues(pool);\n offset = 0;\n }\n\n const at = offset;\n offset = at + 8;\n\n const hex = UUID_HEX_OCTETS;\n\n return (\n prefix +\n hex[0x70 | (counter >>> 8)] +\n hex[counter & 0xff] +\n '-' +\n hex[(pool[at] & 0x3f) | 0x80] +\n hex[pool[at + 1]] +\n '-' +\n hex[pool[at + 2]] +\n hex[pool[at + 3]] +\n hex[pool[at + 4]] +\n hex[pool[at + 5]] +\n hex[pool[at + 6]] +\n hex[pool[at + 7]]\n );\n };\n }\n\n /** The realm's one generator: the one in the shared slot when another copy of this module put it there, else a new one that fills the slot. */\n private static resolveShared(): () => string {\n const shared: (() => string) | undefined = Reflect.get(globalThis, SHARED_SLOT);\n const resolved = shared ?? UuidV7Generator.create();\n if (!shared) {\n Reflect.set(globalThis, SHARED_SLOT, resolved);\n }\n\n return resolved;\n }\n\n private static readonly shared: () => string = UuidV7Generator.resolveShared();\n\n /**\n * Mints a time-ordered UUID v7 - the default for a string primary key. Forwards no argument: the\n * shared slot may hold another helpers version's generator.\n */\n static generate(): string {\n return UuidV7Generator.shared();\n }\n}\n"]}
1
+ {"version":3,"file":"v7.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/v7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAEjE,MAAM,SAAS,GAAG,CAAC,GAAG,GAAG,CAAC;AAC1B,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,2IAA2I;AAC3I,MAAM,OAAO,eAAe;IAC1B;;;OAGG;IACH,MAAM,CAAC,MAAM;QACX,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;QACvC,IAAI,MAAM,GAAG,SAAS,CAAC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CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAClB,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,+IAA+I;IACvI,MAAM,CAAC,aAAa;QAC1B,MAAM,MAAM,GAA+B,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAChF,MAAM,QAAQ,GAAG,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAEpD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;aAEuB,WAAM,GAAiB,eAAe,CAAC,aAAa,EAAE,CAAC;IAE/E;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACb,OAAO,eAAe,CAAC,MAAM,EAAE,CAAC;IAClC,CAAC","sourcesContent":["import { UUID_HEX_OCTETS } from './common/constants';\n\n/**\n * One sequence per realm, so the CJS and ESM copies - and two helpers versions - never interleave two\n * counters. The slot holds a `() => string`; that key and shape are a contract across versions.\n */\nconst SHARED_SLOT = Symbol.for('@venizia/ignis-helpers:uuid-v7');\n\nconst POOL_SIZE = 8 * 256;\nconst MAX_COUNTER = 0xfff;\n\n/** Time-ordered UUID v7 generator. Use `generate()` for the shared instance or `create()` for one with its own clock state and counter. */\nexport class UuidV7Generator {\n /**\n * Builds a v7 generator with its own clock state and counter. Never `Bun.randomUUIDv7`: it is\n * slower, and it reads `(encoding, timestamp)` from whatever it is called with.\n */\n static create(): () => string {\n const pool = new Uint8Array(POOL_SIZE);\n let offset = POOL_SIZE;\n let lastMs = -1;\n let counter = 0;\n let prefix = '';\n\n /** Draws a counter seed below 0x800, leaving room to climb inside the millisecond. */\n const drawCounterSeed = (): number => {\n if (offset > POOL_SIZE - 2) {\n globalThis.crypto.getRandomValues(pool);\n offset = 0;\n }\n\n const seed = ((pool[offset] << 8) | pool[offset + 1]) & 0x7ff;\n offset += 2;\n\n return seed;\n };\n\n /** Renders the 48-bit timestamp half of the id. */\n const renderPrefix = (opts: { ms: number }): string => {\n const { ms } = opts;\n const hex = UUID_HEX_OCTETS;\n // 48 bits exceed the 32-bit bitwise range: split at 24 bits with arithmetic first.\n const high = Math.floor(ms / 0x1000000);\n const low = ms % 0x1000000;\n\n return (\n hex[(high >>> 16) & 0xff] +\n hex[(high >>> 8) & 0xff] +\n hex[high & 0xff] +\n hex[(low >>> 16) & 0xff] +\n '-' +\n hex[(low >>> 8) & 0xff] +\n hex[low & 0xff] +\n '-'\n );\n };\n\n return () => {\n const now = Date.now();\n\n if (now > lastMs) {\n lastMs = now;\n counter = drawCounterSeed();\n prefix = renderPrefix({ ms: now });\n } else if (++counter > MAX_COUNTER) {\n // Counter spent, or the clock stepped back: borrow the next millisecond rather than repeat.\n lastMs += 1;\n counter = drawCounterSeed();\n prefix = renderPrefix({ ms: lastMs });\n }\n\n if (offset > POOL_SIZE - 8) {\n globalThis.crypto.getRandomValues(pool);\n offset = 0;\n }\n\n const at = offset;\n offset = at + 8;\n\n const hex = UUID_HEX_OCTETS;\n\n return (\n prefix +\n hex[0x70 | (counter >>> 8)] +\n hex[counter & 0xff] +\n '-' +\n hex[(pool[at] & 0x3f) | 0x80] +\n hex[pool[at + 1]] +\n '-' +\n hex[pool[at + 2]] +\n hex[pool[at + 3]] +\n hex[pool[at + 4]] +\n hex[pool[at + 5]] +\n hex[pool[at + 6]] +\n hex[pool[at + 7]]\n );\n };\n }\n\n /** The realm's one generator: the one in the shared slot when another copy of this module put it there, else a new one that fills the slot. */\n private static resolveShared(): () => string {\n const shared: (() => string) | undefined = Reflect.get(globalThis, SHARED_SLOT);\n const resolved = shared ?? UuidV7Generator.create();\n\n if (!shared) {\n Reflect.set(globalThis, SHARED_SLOT, resolved);\n }\n\n return resolved;\n }\n\n private static readonly shared: () => string = UuidV7Generator.resolveShared();\n\n /**\n * Mints a time-ordered UUID v7 - the default for a string primary key. Forwards no argument: the\n * shared slot may hold another helpers version's generator.\n */\n static generate(): string {\n return UuidV7Generator.shared();\n }\n}\n"]}
@@ -2,6 +2,7 @@ import { type ValueOrPromise } from '../../../common/types/index.js';
2
2
  import { BaseHelper } from '../../base.js';
3
3
  import { type MessagePort, type Transferable } from 'node:worker_threads';
4
4
  import { type IWorkerBus, type IWorkerMessageBusHandler } from '../common/index.js';
5
+ /** Base for a bus over a `MessagePort`: incoming messages go to `handler`, outgoing ones through `postMessage`. */
5
6
  export declare abstract class AbstractWorkerBusHelper<IConsumePayload, IPublishPayload> extends BaseHelper implements IWorkerBus<IConsumePayload, IPublishPayload> {
6
7
  port: MessagePort;
7
8
  handler: IWorkerMessageBusHandler<IConsumePayload>;
@@ -1,4 +1,5 @@
1
1
  import { BaseHelper } from '../../base.js';
2
+ /** Base for a bus over a `MessagePort`: incoming messages go to `handler`, outgoing ones through `postMessage`. */
2
3
  export class AbstractWorkerBusHelper extends BaseHelper {
3
4
  }
4
5
  //# sourceMappingURL=abstract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/modules/worker-thread/bus/abstract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,OAAgB,uBACpB,SAAQ,UAAU;CAYnB","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { type MessagePort, type Transferable } from 'node:worker_threads';\nimport { type IWorkerBus, type IWorkerMessageBusHandler } from '../common';\n\nexport abstract class AbstractWorkerBusHelper<IConsumePayload, IPublishPayload>\n extends BaseHelper\n implements IWorkerBus<IConsumePayload, IPublishPayload>\n{\n port: MessagePort;\n handler: IWorkerMessageBusHandler<IConsumePayload>;\n\n abstract onBeforePostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n abstract onAfterPostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n abstract postMessage(opts: {\n message: IPublishPayload;\n transferList: readonly Transferable[] | undefined;\n }): ValueOrPromise<void>;\n}\n"]}
1
+ {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../src/modules/worker-thread/bus/abstract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,mHAAmH;AACnH,MAAM,OAAgB,uBACpB,SAAQ,UAAU;CAYnB","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { type MessagePort, type Transferable } from 'node:worker_threads';\nimport { type IWorkerBus, type IWorkerMessageBusHandler } from '../common';\n\n/** Base for a bus over a `MessagePort`: incoming messages go to `handler`, outgoing ones through `postMessage`. */\nexport abstract class AbstractWorkerBusHelper<IConsumePayload, IPublishPayload>\n extends BaseHelper\n implements IWorkerBus<IConsumePayload, IPublishPayload>\n{\n port: MessagePort;\n handler: IWorkerMessageBusHandler<IConsumePayload>;\n\n abstract onBeforePostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n abstract onAfterPostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n abstract postMessage(opts: {\n message: IPublishPayload;\n transferList: readonly Transferable[] | undefined;\n }): ValueOrPromise<void>;\n}\n"]}
@@ -2,6 +2,7 @@ import { type ValueOrPromise } from '../../../common/types/index.js';
2
2
  import { type MessagePort, type Transferable } from 'node:worker_threads';
3
3
  import { type IWorkerMessageBusHandler } from '../common/index.js';
4
4
  import { AbstractWorkerBusHelper } from './abstract.js';
5
+ /** A `MessagePort` bus that forwards the port's message, error, exit and close events to a handler. A throwing hook is logged, not rethrown. */
5
6
  export declare class BaseWorkerBusHelper<IConsumePayload, IPublishPayload> extends AbstractWorkerBusHelper<IConsumePayload, IPublishPayload> {
6
7
  constructor(opts: {
7
8
  scope: string;
@@ -1,5 +1,6 @@
1
1
  import { PromiseUtility } from '../../../utilities/promise.utility.js';
2
2
  import { AbstractWorkerBusHelper } from './abstract.js';
3
+ /** A `MessagePort` bus that forwards the port's message, error, exit and close events to a handler. A throwing hook is logged, not rethrown. */
3
4
  export class BaseWorkerBusHelper extends AbstractWorkerBusHelper {
4
5
  constructor(opts) {
5
6
  super({ scope: opts.scope, identifier: opts.scope });
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/modules/worker-thread/bus/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,OAAO,mBAAsD,SAAQ,uBAG1E;IACC,YAAY,IAIX;QACC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAErD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC;QAE/B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;YAClC,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QAChG,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9B,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAA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AAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAKD,WAAW,CAAC,IAGX;QACC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;iBAC1B,KAAK,CAAC,sDAAsD,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,UAAU,CAAC;YACd,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC5B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,IAAI,CAAC;SAClD,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,CAAC,UAAU,CAAC;YACd,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC5B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { type MessagePort, type Transferable } from 'node:worker_threads';\nimport { type IWorkerMessageBusHandler } from '../common';\nimport { AbstractWorkerBusHelper } from './abstract';\n\nexport class BaseWorkerBusHelper<IConsumePayload, IPublishPayload> extends AbstractWorkerBusHelper<\n IConsumePayload,\n IPublishPayload\n> {\n constructor(opts: {\n scope: string;\n port: MessagePort;\n busHandler: IWorkerMessageBusHandler<IConsumePayload>;\n }) {\n super({ scope: opts.scope, identifier: opts.scope });\n\n this.port = opts.port;\n this.handler = opts.busHandler;\n\n this.port.on('message', (message) => {\n this.invokeHook({ scope: 'onMessage', execution: () => this.handler.onMessage({ message }) });\n });\n\n this.port.on('error', (error) => {\n this.invokeHook({ scope: 'onError', execution: () => this.handler.onError({ error }) });\n });\n\n this.port.on('messageerror', (error) => {\n this.invokeHook({ scope: 'onError', execution: () => this.handler.onError({ error }) });\n });\n\n this.port.on('exit', (exitCode) => {\n this.invokeHook({ scope: 'onExit', execution: () => this.handler.onExit({ exitCode }) });\n });\n\n this.port.on('close', () => {\n this.invokeHook({ scope: 'onClose', execution: () => this.handler.onClose() });\n });\n }\n\n /** Bus handlers run inside MessagePort listeners; a sync throw there is uncaught and kills the worker thread, so wrap it - voidExecution alone can't catch a throw evaluated before it's called. */\n protected invokeHook(opts: { scope: string; execution: () => ValueOrPromise<void> }) {\n const { scope, execution } = opts;\n\n try {\n PromiseUtility.voidExecution({ logger: this.logger, scope, execution: execution() });\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n onBeforePostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n onAfterPostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n\n postMessage(opts: {\n message: IPublishPayload;\n transferList: readonly Transferable[] | undefined;\n }): ValueOrPromise<void> {\n if (!this.port) {\n this.logger\n .for(this.postMessage.name)\n .error('Failed to post message to main | Invalid parentPort!');\n return;\n }\n\n this.invokeHook({\n scope: this.postMessage.name,\n execution: () => this.onBeforePostMessage?.(opts),\n });\n\n if (opts.transferList) {\n this.port.postMessage(opts.message, [...opts.transferList]);\n } else {\n this.port.postMessage(opts.message);\n }\n\n this.invokeHook({\n scope: this.postMessage.name,\n execution: () => this.onAfterPostMessage?.(opts),\n });\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/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I;YAC5B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,IAAI,CAAC;SAClD,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,CAAC,UAAU,CAAC;YACd,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC5B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { type MessagePort, type Transferable } from 'node:worker_threads';\nimport { type IWorkerMessageBusHandler } from '../common';\nimport { AbstractWorkerBusHelper } from './abstract';\n\n/** A `MessagePort` bus that forwards the port's message, error, exit and close events to a handler. A throwing hook is logged, not rethrown. */\nexport class BaseWorkerBusHelper<IConsumePayload, IPublishPayload> extends AbstractWorkerBusHelper<\n IConsumePayload,\n IPublishPayload\n> {\n constructor(opts: {\n scope: string;\n port: MessagePort;\n busHandler: IWorkerMessageBusHandler<IConsumePayload>;\n }) {\n super({ scope: opts.scope, identifier: opts.scope });\n\n this.port = opts.port;\n this.handler = opts.busHandler;\n\n this.port.on('message', (message) => {\n this.invokeHook({ scope: 'onMessage', execution: () => this.handler.onMessage({ message }) });\n });\n\n this.port.on('error', (error) => {\n this.invokeHook({ scope: 'onError', execution: () => this.handler.onError({ error }) });\n });\n\n this.port.on('messageerror', (error) => {\n this.invokeHook({ scope: 'onError', execution: () => this.handler.onError({ error }) });\n });\n\n this.port.on('exit', (exitCode) => {\n this.invokeHook({ scope: 'onExit', execution: () => this.handler.onExit({ exitCode }) });\n });\n\n this.port.on('close', () => {\n this.invokeHook({ scope: 'onClose', execution: () => this.handler.onClose() });\n });\n }\n\n /** Bus handlers run inside MessagePort listeners; a sync throw there is uncaught and kills the worker thread, so wrap it - voidExecution alone can't catch a throw evaluated before it's called. */\n protected invokeHook(opts: { scope: string; execution: () => ValueOrPromise<void> }) {\n const { scope, execution } = opts;\n\n try {\n PromiseUtility.voidExecution({ logger: this.logger, scope, execution: execution() });\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n onBeforePostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n onAfterPostMessage?(opts: { message: IPublishPayload }): ValueOrPromise<void>;\n\n postMessage(opts: {\n message: IPublishPayload;\n transferList: readonly Transferable[] | undefined;\n }): ValueOrPromise<void> {\n if (!this.port) {\n this.logger\n .for(this.postMessage.name)\n .error('Failed to post message to main | Invalid parentPort!');\n\n return;\n }\n\n this.invokeHook({\n scope: this.postMessage.name,\n execution: () => this.onBeforePostMessage?.(opts),\n });\n\n if (opts.transferList) {\n this.port.postMessage(opts.message, [...opts.transferList]);\n } else {\n this.port.postMessage(opts.message);\n }\n\n this.invokeHook({\n scope: this.postMessage.name,\n execution: () => this.onAfterPostMessage?.(opts),\n });\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { type ValueOrPromise } from '../../../../common/types/index.js';
2
2
  import { BaseHelper } from '../../../base.js';
3
3
  import { type IWorkerMessageBusHandler } from '../../common/index.js';
4
+ /** Base for the callbacks a worker bus invokes: `onMessage`, `onClose`, `onError` and `onExit`. */
4
5
  export declare abstract class AbstractWorkerMessageBusHandlerHelper<IConsumePayload> extends BaseHelper implements IWorkerMessageBusHandler<IConsumePayload> {
5
6
  onMessage: (opts: {
6
7
  message: IConsumePayload;
@@ -1,4 +1,5 @@
1
1
  import { BaseHelper } from '../../../base.js';
2
+ /** Base for the callbacks a worker bus invokes: `onMessage`, `onClose`, `onError` and `onExit`. */
2
3
  export class AbstractWorkerMessageBusHandlerHelper extends BaseHelper {
3
4
  }
4
5
  //# sourceMappingURL=abstract.js.map