@venizia/ignis-helpers 0.4.8-0 → 0.4.8-2

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 (332) hide show
  1. package/README.md +1 -0
  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/base.algorithm.d.ts +1 -0
  41. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +1 -0
  42. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  43. package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts +12 -4
  44. package/dist/esm/modules/crypto/algorithms/credential.algorithm.js +4 -4
  45. package/dist/esm/modules/crypto/algorithms/credential.algorithm.js.map +1 -1
  46. package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts +3 -0
  47. package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js.map +1 -1
  48. package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts +1 -0
  49. package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js.map +1 -1
  50. package/dist/esm/modules/crypto/common/constants.d.ts +12 -1
  51. package/dist/esm/modules/crypto/common/constants.js +9 -1
  52. package/dist/esm/modules/crypto/common/constants.js.map +1 -1
  53. package/dist/esm/modules/crypto/common/types.d.ts +1 -0
  54. package/dist/esm/modules/crypto/common/types.js.map +1 -1
  55. package/dist/esm/modules/env/app-env.d.ts +3 -0
  56. package/dist/esm/modules/env/app-env.js +3 -0
  57. package/dist/esm/modules/env/app-env.js.map +1 -1
  58. package/dist/esm/modules/env/common/types.d.ts +1 -0
  59. package/dist/esm/modules/env/common/types.js.map +1 -1
  60. package/dist/esm/modules/logger/common/constants.d.ts +3 -0
  61. package/dist/esm/modules/logger/common/constants.js +2 -0
  62. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  63. package/dist/esm/modules/logger/common/types.d.ts +2 -0
  64. package/dist/esm/modules/logger/common/types.js +1 -0
  65. package/dist/esm/modules/logger/common/types.js.map +1 -1
  66. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +1 -0
  67. package/dist/esm/modules/logger/formatting/deep-splat.js +1 -0
  68. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  69. package/dist/esm/modules/logger/hf/common/types.d.ts +7 -2
  70. package/dist/esm/modules/logger/hf/common/types.js.map +1 -1
  71. package/dist/esm/modules/logger/winston/common/types.d.ts +31 -3
  72. package/dist/esm/modules/logger/winston/common/types.js.map +1 -1
  73. package/dist/esm/modules/logger/winston/define.d.ts +1 -0
  74. package/dist/esm/modules/logger/winston/define.js +1 -0
  75. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  76. package/dist/esm/modules/logger/winston/logger.d.ts +1 -0
  77. package/dist/esm/modules/logger/winston/logger.js +1 -0
  78. package/dist/esm/modules/logger/winston/logger.js.map +1 -1
  79. package/dist/esm/modules/logger/winston/transports/dgram.transport.d.ts +1 -0
  80. package/dist/esm/modules/logger/winston/transports/dgram.transport.js +1 -0
  81. package/dist/esm/modules/logger/winston/transports/dgram.transport.js.map +1 -1
  82. package/dist/esm/modules/network/http-request/base-network-request.helper.d.ts +1 -0
  83. package/dist/esm/modules/network/http-request/base-network-request.helper.js +1 -0
  84. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  85. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts +8 -8
  86. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +2 -0
  87. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  88. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.d.ts +2 -0
  89. package/dist/esm/modules/network/http-request/fetcher/base-fetcher.js.map +1 -1
  90. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts +5 -1
  91. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +2 -0
  92. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  93. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.d.ts +11 -0
  94. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +1 -0
  95. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  96. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts +3 -0
  97. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +1 -0
  98. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  99. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.d.ts +1 -0
  100. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.js +1 -0
  101. package/dist/esm/modules/network/tcp-socket/network-tcp-client.helper.js.map +1 -1
  102. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.d.ts +1 -0
  103. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.js +1 -0
  104. package/dist/esm/modules/network/tcp-socket/network-tcp-server.helper.js.map +1 -1
  105. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.d.ts +1 -0
  106. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.js +1 -0
  107. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-client.helper.js.map +1 -1
  108. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.d.ts +1 -0
  109. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.js +1 -0
  110. package/dist/esm/modules/network/tcp-socket/network-tls-tcp-server.helper.js.map +1 -1
  111. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.d.ts +4 -0
  112. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +4 -0
  113. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  114. package/dist/esm/modules/network/utilities/query-string.d.ts +13 -2
  115. package/dist/esm/modules/network/utilities/query-string.js +2 -1
  116. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  117. package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +2 -1
  118. package/dist/esm/modules/network/utilities/url-safety/common/constants.js +1 -1
  119. package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
  120. package/dist/esm/modules/network/utilities/url-safety/common/types.d.ts +18 -5
  121. package/dist/esm/modules/network/utilities/url-safety/common/types.js.map +1 -1
  122. package/dist/esm/modules/pool/common/types.d.ts +5 -1
  123. package/dist/esm/modules/pool/common/types.js.map +1 -1
  124. package/dist/esm/modules/queue/bullmq/helper.d.ts +13 -0
  125. package/dist/esm/modules/queue/bullmq/helper.js +4 -0
  126. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  127. package/dist/esm/modules/queue/common/hook.d.ts +1 -0
  128. package/dist/esm/modules/queue/common/hook.js +1 -0
  129. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  130. package/dist/esm/modules/queue/internal/sequential/common/types.d.ts +8 -0
  131. package/dist/esm/modules/queue/internal/sequential/common/types.js +1 -0
  132. package/dist/esm/modules/queue/internal/sequential/common/types.js.map +1 -1
  133. package/dist/esm/modules/queue/internal/sequential/helper.d.ts +4 -0
  134. package/dist/esm/modules/queue/internal/sequential/helper.js +4 -0
  135. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  136. package/dist/esm/modules/queue/kafka/base.d.ts +5 -0
  137. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  138. package/dist/esm/modules/queue/kafka/bundler/common/constants.d.ts +3 -0
  139. package/dist/esm/modules/queue/kafka/bundler/common/constants.js +3 -0
  140. package/dist/esm/modules/queue/kafka/bundler/common/constants.js.map +1 -1
  141. package/dist/esm/modules/queue/kafka/common/constants.d.ts +8 -0
  142. package/dist/esm/modules/queue/kafka/common/constants.js +5 -0
  143. package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
  144. package/dist/esm/modules/queue/kafka/common/types/admin.d.ts +1 -0
  145. package/dist/esm/modules/queue/kafka/common/types/admin.js.map +1 -1
  146. package/dist/esm/modules/queue/kafka/common/types/callbacks.d.ts +12 -0
  147. package/dist/esm/modules/queue/kafka/common/types/callbacks.js.map +1 -1
  148. package/dist/esm/modules/queue/kafka/common/types/connection.d.ts +2 -0
  149. package/dist/esm/modules/queue/kafka/common/types/connection.js.map +1 -1
  150. package/dist/esm/modules/queue/kafka/common/types/consumer.d.ts +62 -0
  151. package/dist/esm/modules/queue/kafka/common/types/consumer.js.map +1 -1
  152. package/dist/esm/modules/queue/kafka/common/types/producer.d.ts +1 -0
  153. package/dist/esm/modules/queue/kafka/common/types/producer.js.map +1 -1
  154. package/dist/esm/modules/queue/mqtt/helper.d.ts +2 -0
  155. package/dist/esm/modules/queue/mqtt/helper.js +1 -0
  156. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  157. package/dist/esm/modules/redis/base/abstract.helper.d.ts +2 -0
  158. package/dist/esm/modules/redis/base/abstract.helper.js +2 -0
  159. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  160. package/dist/esm/modules/redis/cluster/cluster.helper.d.ts +1 -0
  161. package/dist/esm/modules/redis/cluster/cluster.helper.js +1 -0
  162. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  163. package/dist/esm/modules/redis/common/constants.d.ts +4 -0
  164. package/dist/esm/modules/redis/common/constants.js +2 -0
  165. package/dist/esm/modules/redis/common/constants.js.map +1 -1
  166. package/dist/esm/modules/redis/common/interfaces.d.ts +12 -0
  167. package/dist/esm/modules/redis/common/interfaces.js.map +1 -1
  168. package/dist/esm/modules/redis/common/types.d.ts +21 -1
  169. package/dist/esm/modules/redis/common/types.js.map +1 -1
  170. package/dist/esm/modules/redis/factory.d.ts +2 -0
  171. package/dist/esm/modules/redis/factory.js +1 -0
  172. package/dist/esm/modules/redis/factory.js.map +1 -1
  173. package/dist/esm/modules/redis/sentinel/sentinel.helper.d.ts +1 -0
  174. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +1 -0
  175. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  176. package/dist/esm/modules/redis/single/single.helper.d.ts +1 -0
  177. package/dist/esm/modules/redis/single/single.helper.js +1 -0
  178. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  179. package/dist/esm/modules/redis/utility.d.ts +1 -0
  180. package/dist/esm/modules/redis/utility.js +1 -0
  181. package/dist/esm/modules/redis/utility.js.map +1 -1
  182. package/dist/esm/modules/retry/common/constants.d.ts +4 -0
  183. package/dist/esm/modules/retry/common/constants.js +2 -0
  184. package/dist/esm/modules/retry/common/constants.js.map +1 -1
  185. package/dist/esm/modules/retry/common/types.d.ts +19 -5
  186. package/dist/esm/modules/retry/common/types.js.map +1 -1
  187. package/dist/esm/modules/retry/helper.d.ts +4 -4
  188. package/dist/esm/modules/retry/helper.js.map +1 -1
  189. package/dist/esm/modules/secrets/base/abstract.helper.d.ts +1 -0
  190. package/dist/esm/modules/secrets/base/abstract.helper.js +1 -0
  191. package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
  192. package/dist/esm/modules/secrets/common/constants.d.ts +4 -0
  193. package/dist/esm/modules/secrets/common/constants.js +2 -0
  194. package/dist/esm/modules/secrets/common/constants.js.map +1 -1
  195. package/dist/esm/modules/secrets/common/types/helper.d.ts +13 -0
  196. package/dist/esm/modules/secrets/common/types/helper.js.map +1 -1
  197. package/dist/esm/modules/secrets/common/types/lease.d.ts +2 -0
  198. package/dist/esm/modules/secrets/common/types/lease.js.map +1 -1
  199. package/dist/esm/modules/secrets/common/types/registration.d.ts +13 -2
  200. package/dist/esm/modules/secrets/common/types/registration.js.map +1 -1
  201. package/dist/esm/modules/secrets/common/types/timer.d.ts +1 -0
  202. package/dist/esm/modules/secrets/common/types/timer.js.map +1 -1
  203. package/dist/esm/modules/secrets/dotenv/dotenv.helper.d.ts +8 -0
  204. package/dist/esm/modules/secrets/dotenv/dotenv.helper.js +1 -0
  205. package/dist/esm/modules/secrets/dotenv/dotenv.helper.js.map +1 -1
  206. package/dist/esm/modules/secrets/factory.d.ts +1 -0
  207. package/dist/esm/modules/secrets/factory.js +1 -0
  208. package/dist/esm/modules/secrets/factory.js.map +1 -1
  209. package/dist/esm/modules/secrets/hashicorp/auth.d.ts +2 -0
  210. package/dist/esm/modules/secrets/hashicorp/auth.js +1 -0
  211. package/dist/esm/modules/secrets/hashicorp/auth.js.map +1 -1
  212. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts +2 -0
  213. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +1 -0
  214. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  215. package/dist/esm/modules/secrets/system-envs/system-envs.helper.d.ts +1 -0
  216. package/dist/esm/modules/secrets/system-envs/system-envs.helper.js +1 -0
  217. package/dist/esm/modules/secrets/system-envs/system-envs.helper.js.map +1 -1
  218. package/dist/esm/modules/slug/common/constants.d.ts +1 -0
  219. package/dist/esm/modules/slug/common/constants.js +1 -0
  220. package/dist/esm/modules/slug/common/constants.js.map +1 -1
  221. package/dist/esm/modules/socket/socket-io/common/constants.d.ts +2 -0
  222. package/dist/esm/modules/socket/socket-io/common/constants.js +2 -0
  223. package/dist/esm/modules/socket/socket-io/common/constants.js.map +1 -1
  224. package/dist/esm/modules/socket/socket-io/common/types/client.d.ts +5 -0
  225. package/dist/esm/modules/socket/socket-io/common/types/client.js.map +1 -1
  226. package/dist/esm/modules/socket/socket-io/common/types/hooks.d.ts +4 -0
  227. package/dist/esm/modules/socket/socket-io/common/types/hooks.js.map +1 -1
  228. package/dist/esm/modules/socket/socket-io/common/types/server.d.ts +6 -0
  229. package/dist/esm/modules/socket/socket-io/common/types/server.js.map +1 -1
  230. package/dist/esm/modules/socket/socket-io/server/helper.d.ts +1 -0
  231. package/dist/esm/modules/socket/socket-io/server/helper.js +1 -0
  232. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  233. package/dist/esm/modules/socket/websocket/common/constants.d.ts +7 -0
  234. package/dist/esm/modules/socket/websocket/common/constants.js +5 -0
  235. package/dist/esm/modules/socket/websocket/common/constants.js.map +1 -1
  236. package/dist/esm/modules/socket/websocket/common/types/client.d.ts +4 -0
  237. package/dist/esm/modules/socket/websocket/common/types/client.js.map +1 -1
  238. package/dist/esm/modules/socket/websocket/common/types/hooks.d.ts +7 -0
  239. package/dist/esm/modules/socket/websocket/common/types/hooks.js.map +1 -1
  240. package/dist/esm/modules/socket/websocket/common/types/server.d.ts +30 -0
  241. package/dist/esm/modules/socket/websocket/common/types/server.js.map +1 -1
  242. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts +1 -0
  243. package/dist/esm/modules/socket/websocket/emitter/helper.js +1 -0
  244. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  245. package/dist/esm/modules/socket/websocket/server/helper.d.ts +1 -0
  246. package/dist/esm/modules/socket/websocket/server/helper.js +1 -0
  247. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  248. package/dist/esm/modules/storage/base.d.ts +6 -1
  249. package/dist/esm/modules/storage/base.js +1 -0
  250. package/dist/esm/modules/storage/base.js.map +1 -1
  251. package/dist/esm/modules/storage/bun-s3/helper.d.ts +9 -1
  252. package/dist/esm/modules/storage/bun-s3/helper.js +2 -1
  253. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  254. package/dist/esm/modules/storage/common/constants.d.ts +1 -0
  255. package/dist/esm/modules/storage/common/constants.js.map +1 -1
  256. package/dist/esm/modules/storage/common/types.d.ts +17 -1
  257. package/dist/esm/modules/storage/common/types.js.map +1 -1
  258. package/dist/esm/modules/storage/common/utility.d.ts +1 -0
  259. package/dist/esm/modules/storage/common/utility.js +1 -0
  260. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  261. package/dist/esm/modules/storage/disk/helper.d.ts +2 -0
  262. package/dist/esm/modules/storage/disk/helper.js +1 -0
  263. package/dist/esm/modules/storage/disk/helper.js.map +1 -1
  264. package/dist/esm/modules/temporal/abstract.d.ts +5 -0
  265. package/dist/esm/modules/temporal/abstract.js +2 -1
  266. package/dist/esm/modules/temporal/abstract.js.map +1 -1
  267. package/dist/esm/modules/temporal/common/constants.d.ts +3 -0
  268. package/dist/esm/modules/temporal/common/constants.js.map +1 -1
  269. package/dist/esm/modules/tree/common/types.d.ts +6 -0
  270. package/dist/esm/modules/tree/common/types.js.map +1 -1
  271. package/dist/esm/modules/uid/common/constants.d.ts +1 -0
  272. package/dist/esm/modules/uid/common/constants.js.map +1 -1
  273. package/dist/esm/modules/uid/common/types.d.ts +28 -7
  274. package/dist/esm/modules/uid/common/types.js.map +1 -1
  275. package/dist/esm/modules/uid/helper.d.ts +12 -0
  276. package/dist/esm/modules/uid/helper.js.map +1 -1
  277. package/dist/esm/modules/uid/uuid/v4.d.ts +1 -0
  278. package/dist/esm/modules/uid/uuid/v4.js +1 -0
  279. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  280. package/dist/esm/modules/uid/uuid/v5.d.ts +1 -0
  281. package/dist/esm/modules/uid/uuid/v5.js +1 -0
  282. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  283. package/dist/esm/modules/uid/uuid/v7.d.ts +1 -0
  284. package/dist/esm/modules/uid/uuid/v7.js +1 -0
  285. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  286. package/dist/esm/modules/worker-thread/bus/abstract.d.ts +1 -0
  287. package/dist/esm/modules/worker-thread/bus/abstract.js +1 -0
  288. package/dist/esm/modules/worker-thread/bus/abstract.js.map +1 -1
  289. package/dist/esm/modules/worker-thread/bus/base.d.ts +1 -0
  290. package/dist/esm/modules/worker-thread/bus/base.js +1 -0
  291. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  292. package/dist/esm/modules/worker-thread/bus/handler/abstract.d.ts +1 -0
  293. package/dist/esm/modules/worker-thread/bus/handler/abstract.js +1 -0
  294. package/dist/esm/modules/worker-thread/bus/handler/abstract.js.map +1 -1
  295. package/dist/esm/modules/worker-thread/bus/handler/base.d.ts +1 -0
  296. package/dist/esm/modules/worker-thread/bus/handler/base.js +1 -0
  297. package/dist/esm/modules/worker-thread/bus/handler/base.js.map +1 -1
  298. package/dist/esm/modules/worker-thread/common/types.d.ts +4 -0
  299. package/dist/esm/modules/worker-thread/common/types.js.map +1 -1
  300. package/dist/esm/modules/worker-thread/thread/abstract.d.ts +1 -0
  301. package/dist/esm/modules/worker-thread/thread/abstract.js +1 -0
  302. package/dist/esm/modules/worker-thread/thread/abstract.js.map +1 -1
  303. package/dist/esm/modules/worker-thread/thread/base.d.ts +1 -0
  304. package/dist/esm/modules/worker-thread/thread/base.js +1 -0
  305. package/dist/esm/modules/worker-thread/thread/base.js.map +1 -1
  306. package/dist/esm/modules/worker-thread/worker/abstract.d.ts +1 -0
  307. package/dist/esm/modules/worker-thread/worker/abstract.js +1 -0
  308. package/dist/esm/modules/worker-thread/worker/abstract.js.map +1 -1
  309. package/dist/esm/modules/worker-thread/worker/base.d.ts +1 -0
  310. package/dist/esm/modules/worker-thread/worker/base.js +1 -0
  311. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  312. package/dist/esm/modules/worker-thread/worker-pool.d.ts +1 -0
  313. package/dist/esm/modules/worker-thread/worker-pool.js +1 -0
  314. package/dist/esm/modules/worker-thread/worker-pool.js.map +1 -1
  315. package/dist/esm/utilities/error.utility.d.ts +1 -0
  316. package/dist/esm/utilities/error.utility.js +1 -0
  317. package/dist/esm/utilities/error.utility.js.map +1 -1
  318. package/dist/esm/utilities/form-body.utility.d.ts +1 -0
  319. package/dist/esm/utilities/form-body.utility.js +1 -0
  320. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  321. package/dist/esm/utilities/hr-time.utility.d.ts +1 -0
  322. package/dist/esm/utilities/hr-time.utility.js +1 -0
  323. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  324. package/dist/esm/utilities/performance.utility.d.ts +1 -0
  325. package/dist/esm/utilities/performance.utility.js +1 -0
  326. package/dist/esm/utilities/performance.utility.js.map +1 -1
  327. package/dist/esm/utilities/promise.utility.d.ts +1 -0
  328. package/dist/esm/utilities/promise.utility.js.map +1 -1
  329. package/dist/esm/utilities/request.utility.d.ts +2 -0
  330. package/dist/esm/utilities/request.utility.js +1 -0
  331. package/dist/esm/utilities/request.utility.js.map +1 -1
  332. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"sentinel.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/sentinel/sentinel.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAoC,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnF,MAAM,OAAO,mBAAoB,SAAQ,mBAA0B;IACjE,YAAY,IAAiC;QAC3C,MAAM,EACJ,IAAI,EACJ,SAAS,EACT,UAAU,EACV,IAAI,GAAG,kBAAkB,CAAC,MAAM,EAChC,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,EAAE,GAClB,GAAG,IAAI,CAAC;QAET,MAAM,mBAAmB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACvD,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC;SAC5D,CAAC,CAAC,CAAC;QAEJ,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,UAAU,EAAE,IAAI;YAChB,gPAAgP;YAChP,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC;gBACrD,GAAG,YAAY;gBACf,SAAS,EAAE,mBAAmB;gBAC9B,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;gBAC/C,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;gBAC/D,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;aAChE,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { type IRedisSentinelHelperOptions, RedisSentinelRoles } from './../common';\n\nexport class RedisSentinelHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSentinelHelperOptions) {\n const {\n name,\n sentinels,\n masterName,\n role = RedisSentinelRoles.MASTER,\n password,\n sentinelPassword,\n sentinelUsername,\n database = 0,\n autoConnect = true,\n maxRetry = 0,\n redisOptions = {},\n } = opts;\n\n const normalizedSentinels = sentinels.map((sentinel) => ({\n host: sentinel.host,\n port: ParseUtility.toInt({ input: sentinel.port ?? 26379 }),\n }));\n\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSentinelHelper.name,\n identifier: name,\n // Precedence (low -> high): framework defaults, the redisOptions escape hatch, then first-class fields. Optional auth fields are spread ONLY when provided, so a value set via redisOptions is not clobbered by an undefined first-class field.\n client: new ioredis.Redis({\n ...AbstractRedisHelper.buildDefaultOpts({ maxRetry }),\n ...redisOptions,\n sentinels: normalizedSentinels,\n name: masterName,\n role,\n db: database,\n lazyConnect: !autoConnect,\n ...(password === undefined ? {} : { password }),\n ...(sentinelPassword === undefined ? {} : { sentinelPassword }),\n ...(sentinelUsername === undefined ? {} : { sentinelUsername }),\n }),\n });\n }\n\n override getClient() {\n return this.client as Redis;\n }\n}\n"]}
1
+ {"version":3,"file":"sentinel.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/sentinel/sentinel.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAoC,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnF,4JAA4J;AAC5J,MAAM,OAAO,mBAAoB,SAAQ,mBAA0B;IACjE,YAAY,IAAiC;QAC3C,MAAM,EACJ,IAAI,EACJ,SAAS,EACT,UAAU,EACV,IAAI,GAAG,kBAAkB,CAAC,MAAM,EAChC,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,EAAE,GAClB,GAAG,IAAI,CAAC;QAET,MAAM,mBAAmB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACvD,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC;SAC5D,CAAC,CAAC,CAAC;QAEJ,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,mBAAmB,CAAC,IAAI;YAC/B,UAAU,EAAE,IAAI;YAChB,gPAAgP;YAChP,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC;gBACrD,GAAG,YAAY;gBACf,SAAS,EAAE,mBAAmB;gBAC9B,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;gBAC/C,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;gBAC/D,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;aAChE,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { type IRedisSentinelHelperOptions, RedisSentinelRoles } from './../common';\n\n/** Redis helper for a master and replicas behind Sentinel. `redisOptions` overrides the helper defaults; the first-class fields override `redisOptions`. */\nexport class RedisSentinelHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSentinelHelperOptions) {\n const {\n name,\n sentinels,\n masterName,\n role = RedisSentinelRoles.MASTER,\n password,\n sentinelPassword,\n sentinelUsername,\n database = 0,\n autoConnect = true,\n maxRetry = 0,\n redisOptions = {},\n } = opts;\n\n const normalizedSentinels = sentinels.map((sentinel) => ({\n host: sentinel.host,\n port: ParseUtility.toInt({ input: sentinel.port ?? 26379 }),\n }));\n\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSentinelHelper.name,\n identifier: name,\n // Precedence (low -> high): framework defaults, the redisOptions escape hatch, then first-class fields. Optional auth fields are spread ONLY when provided, so a value set via redisOptions is not clobbered by an undefined first-class field.\n client: new ioredis.Redis({\n ...AbstractRedisHelper.buildDefaultOpts({ maxRetry }),\n ...redisOptions,\n sentinels: normalizedSentinels,\n name: masterName,\n role,\n db: database,\n lazyConnect: !autoConnect,\n ...(password === undefined ? {} : { password }),\n ...(sentinelPassword === undefined ? {} : { sentinelPassword }),\n ...(sentinelUsername === undefined ? {} : { sentinelUsername }),\n }),\n });\n }\n\n override getClient() {\n return this.client as Redis;\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { Redis } from 'ioredis';
2
2
  import { AbstractRedisHelper } from './../base/index.js';
3
3
  import { type IRedisSingleHelperOptions } from './../common/index.js';
4
+ /** Redis helper over one ioredis `Redis` client connected to a single node. */
4
5
  export declare class RedisSingleHelper extends AbstractRedisHelper<Redis> {
5
6
  constructor(opts: IRedisSingleHelperOptions);
6
7
  getClient(): Redis;
@@ -1,6 +1,7 @@
1
1
  import { ModuleUtility } from '../../../utilities/module.utility.js';
2
2
  import { ParseUtility } from '../../../utilities/parse.utility.js';
3
3
  import { AbstractRedisHelper } from './../base/index.js';
4
+ /** Redis helper over one ioredis `Redis` client connected to a single node. */
4
5
  export class RedisSingleHelper extends AbstractRedisHelper {
5
6
  constructor(opts) {
6
7
  const { name, host, port, password, database = 0, autoConnect = true, maxRetry = 0 } = opts;
@@ -1 +1 @@
1
- {"version":3,"file":"single.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/single/single.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGhD,MAAM,OAAO,iBAAkB,SAAQ,mBAA0B;IAC/D,YAAY,IAA+B;QACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;QAE5F,0FAA0F;QAC1F,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,iBAAiB,CAAC,IAAI;YAC7B,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBACzC,QAAQ;gBACR,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC;aACtD,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { type IRedisSingleHelperOptions } from './../common';\n\nexport class RedisSingleHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSingleHelperOptions) {\n const { name, host, port, password, database = 0, autoConnect = true, maxRetry = 0 } = opts;\n\n // Optional peer, loaded when a client is built: an app with no Redis installs no ioredis.\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSingleHelper.name,\n identifier: name,\n client: new ioredis.Redis({\n name,\n host,\n port: ParseUtility.toInt({ input: port }),\n password,\n db: database,\n lazyConnect: !autoConnect,\n ...AbstractRedisHelper.buildDefaultOpts({ maxRetry }),\n }),\n });\n }\n\n override getClient() {\n return this.client as Redis;\n }\n}\n"]}
1
+ {"version":3,"file":"single.helper.js","sourceRoot":"","sources":["../../../../../src/modules/redis/single/single.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGhD,+EAA+E;AAC/E,MAAM,OAAO,iBAAkB,SAAQ,mBAA0B;IAC/D,YAAY,IAA+B;QACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;QAE5F,0FAA0F;QAC1F,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzF,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,iBAAiB,CAAC,IAAI;YAC7B,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,IAAI,OAAO,CAAC,KAAK,CAAC;gBACxB,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBACzC,QAAQ;gBACR,EAAE,EAAE,QAAQ;gBACZ,WAAW,EAAE,CAAC,WAAW;gBACzB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAC;aACtD,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ModuleUtility } from '@/utilities/module.utility';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport type { Redis } from 'ioredis';\nimport { AbstractRedisHelper } from './../base';\nimport { type IRedisSingleHelperOptions } from './../common';\n\n/** Redis helper over one ioredis `Redis` client connected to a single node. */\nexport class RedisSingleHelper extends AbstractRedisHelper<Redis> {\n constructor(opts: IRedisSingleHelperOptions) {\n const { name, host, port, password, database = 0, autoConnect = true, maxRetry = 0 } = opts;\n\n // Optional peer, loaded when a client is built: an app with no Redis installs no ioredis.\n const ioredis =\n opts.module ?? ModuleUtility.loadSync<typeof import('ioredis')>({ module: 'ioredis' });\n\n super({\n ...opts,\n scope: RedisSingleHelper.name,\n identifier: name,\n client: new ioredis.Redis({\n name,\n host,\n port: ParseUtility.toInt({ input: port }),\n password,\n db: database,\n lazyConnect: !autoConnect,\n ...AbstractRedisHelper.buildDefaultOpts({ maxRetry }),\n }),\n });\n }\n\n override getClient() {\n return this.client as Redis;\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { ILogger } from '../logger/index.js';
2
2
  import type { TRedisClient } from './common/index.js';
3
+ /** Static helpers for working with ioredis clients. */
3
4
  export declare class RedisUtility {
4
5
  /** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */
5
6
  static waitForReady(opts: {
@@ -2,6 +2,7 @@ import { HTTP } from '../../common/index.js';
2
2
  import { getError } from '../error/index.js';
3
3
  import { PromiseUtility } from '../../utilities/promise.utility.js';
4
4
  const REDIS_READY_TIMEOUT = 30_000;
5
+ /** Static helpers for working with ioredis clients. */
5
6
  export class RedisUtility {
6
7
  /** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */
7
8
  static waitForReady(opts) {
@@ -1 +1 @@
1
- {"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../src/modules/redis/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI7D,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEnC,MAAM,OAAO,YAAY;IACvB,+GAA+G;IAC/G,MAAM,CAAC,YAAY,CAAC,IAAkD;QACpE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,mBAAmB,EAAE,GAAG,IAAI,CAAC;QAEzD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;gBAC9B,OAAO,EAAE,CAAC;gBAEV,OAAO;YACT,CAAC;YAED,MAAM,OAAO,GAAG,MAAsB,CAAC;YAEvC,kLAAkL;YAClL,MAAM,QAAQ,GAAsB,EAAE,CAAC;YAEvC,MAAM,MAAM,GAAG,GAAG,EAAE;gBAClB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;oBAC/B,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC;YAEF,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,MAAM,EAAE,CAAC;gBACT,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC;YAEF,MAAM,OAAO,GAAG,CAAC,KAAY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'@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { type EventEmitter } from 'node:events';\nimport type { TRedisClient } from './common';\n\nconst REDIS_READY_TIMEOUT = 30_000;\n\nexport class RedisUtility {\n /** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */\n static waitForReady(opts: { client: TRedisClient; timeoutMs?: number }): Promise<void> {\n const { client, timeoutMs = REDIS_READY_TIMEOUT } = opts;\n\n return new Promise<void>((resolve, reject) => {\n if (client.status === 'ready') {\n resolve();\n\n return;\n }\n\n const emitter = client as EventEmitter;\n\n /** Run by every terminal branch: clients are long-lived and re-`configure()`d, so an unbound listener leaks (EventEmitter warns) and could fire on an already-settled promise. */\n const cleanups: Array<() => void> = [];\n\n const detach = () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n };\n\n const onReady = () => {\n detach();\n resolve();\n };\n\n const onError = (error: Error) => {\n detach();\n reject(error);\n };\n\n const timer = setTimeout(() => {\n detach();\n reject(\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `Redis client did not become ready within ${timeoutMs}ms (status: ${client.status})`,\n }),\n );\n }, timeoutMs);\n\n cleanups.push(\n () => clearTimeout(timer),\n () => emitter.removeListener('ready', onReady),\n () => emitter.removeListener('error', onError),\n );\n\n emitter.once('ready', onReady);\n emitter.once('error', onError);\n });\n }\n\n /** Kicks off connection for clients still parked in `wait` - duplicated clients inherit `lazyConnect` from their parent and never dial on their own. */\n static ensureConnecting(opts: {\n clients: TRedisClient[];\n logger?: ILogger;\n scope: string;\n }): void {\n const { clients, logger, scope } = opts;\n\n for (const client of clients) {\n if (client.status !== 'wait') {\n continue;\n }\n\n PromiseUtility.voidExecution({ logger, scope, execution: client.connect() });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"utility.js","sourceRoot":"","sources":["../../../../src/modules/redis/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAA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d,QAAQ,CAAC,IAAI,CACX,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,EACzB,GAAG,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,EAC9C,GAAG,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAC/C,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,wJAAwJ;IACxJ,MAAM,CAAC,gBAAgB,CAAC,IAIvB;QACC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAExC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBAC7B,SAAS;YACX,CAAC;YAED,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common';\nimport { getError } from '@/modules/error';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { type EventEmitter } from 'node:events';\nimport type { TRedisClient } from './common';\n\nconst REDIS_READY_TIMEOUT = 30_000;\n\n/** Static helpers for working with ioredis clients. */\nexport class RedisUtility {\n /** Resolves once the client reaches `ready`; rejects on the first client error or when `timeoutMs` elapses. */\n static waitForReady(opts: { client: TRedisClient; timeoutMs?: number }): Promise<void> {\n const { client, timeoutMs = REDIS_READY_TIMEOUT } = opts;\n\n return new Promise<void>((resolve, reject) => {\n if (client.status === 'ready') {\n resolve();\n\n return;\n }\n\n const emitter = client as EventEmitter;\n\n /** Run by every terminal branch: clients are long-lived and re-`configure()`d, so an unbound listener leaks (EventEmitter warns) and could fire on an already-settled promise. */\n const cleanups: Array<() => void> = [];\n\n const detach = () => {\n for (const cleanup of cleanups) {\n cleanup();\n }\n };\n\n const onReady = () => {\n detach();\n resolve();\n };\n\n const onError = (error: Error) => {\n detach();\n reject(error);\n };\n\n const timer = setTimeout(() => {\n detach();\n reject(\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `Redis client did not become ready within ${timeoutMs}ms (status: ${client.status})`,\n }),\n );\n }, timeoutMs);\n\n cleanups.push(\n () => clearTimeout(timer),\n () => emitter.removeListener('ready', onReady),\n () => emitter.removeListener('error', onError),\n );\n\n emitter.once('ready', onReady);\n emitter.once('error', onError);\n });\n }\n\n /** Kicks off connection for clients still parked in `wait` - duplicated clients inherit `lazyConnect` from their parent and never dial on their own. */\n static ensureConnecting(opts: {\n clients: TRedisClient[];\n logger?: ILogger;\n scope: string;\n }): void {\n const { clients, logger, scope } = opts;\n\n for (const client of clients) {\n if (client.status !== 'wait') {\n continue;\n }\n\n PromiseUtility.voidExecution({ logger, scope, execution: client.connect() });\n }\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { TConstValue } from '../../../common/index.js';
2
+ /** How the retry delay grows between attempts. */
2
3
  export declare class RetryBackoffStrategies {
3
4
  static readonly FIXED = "fixed";
4
5
  static readonly LINEAR = "linear";
@@ -8,7 +9,9 @@ export declare class RetryBackoffStrategies {
8
9
  static readonly SCHEME_SET: Set<string>;
9
10
  static isValid(value: string): value is TRetryBackoffStrategy;
10
11
  }
12
+ /** Union of the `RetryBackoffStrategies` values. */
11
13
  export type TRetryBackoffStrategy = TConstValue<typeof RetryBackoffStrategies>;
14
+ /** How randomness is applied to a computed retry delay. */
12
15
  export declare class RetryJitterModes {
13
16
  /** The computed delay is used as-is. */
14
17
  static readonly NONE = "none";
@@ -19,5 +22,6 @@ export declare class RetryJitterModes {
19
22
  static readonly SCHEME_SET: Set<string>;
20
23
  static isValid(value: string): value is TRetryJitterMode;
21
24
  }
25
+ /** Union of the `RetryJitterModes` values. */
22
26
  export type TRetryJitterMode = TConstValue<typeof RetryJitterModes>;
23
27
  //# sourceMappingURL=constants.d.ts.map
@@ -1,3 +1,4 @@
1
+ /** How the retry delay grows between attempts. */
1
2
  export class RetryBackoffStrategies {
2
3
  static { this.FIXED = 'fixed'; }
3
4
  static { this.LINEAR = 'linear'; }
@@ -14,6 +15,7 @@ export class RetryBackoffStrategies {
14
15
  return this.SCHEME_SET.has(value);
15
16
  }
16
17
  }
18
+ /** How randomness is applied to a computed retry delay. */
17
19
  export class RetryJitterModes {
18
20
  /** The computed delay is used as-is. */
19
21
  static { this.NONE = 'none'; }
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/retry/common/constants.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,sBAAsB;aACjB,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,gBAAW,GAAG,aAAa,CAAC;IAE5C,4FAA4F;aAC5E,aAAQ,GAAG,UAAU,CAAC;aAEtB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,QAAQ;KACd,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,gBAAgB;IAC3B,wCAAwC;aACxB,SAAI,GAAG,MAAM,CAAC;IAE9B,6EAA6E;aAC7D,SAAI,GAAG,MAAM,CAAC;IAE9B,8FAA8F;aAC9E,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEjF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@/common';\n\nexport class RetryBackoffStrategies {\n static readonly FIXED = 'fixed';\n static readonly LINEAR = 'linear';\n static readonly EXPONENTIAL = 'exponential';\n\n /** An explicit per-attempt cap schedule, e.g. [250, 1000, 4000]; the last entry repeats. */\n static readonly SCHEDULE = 'schedule';\n\n static readonly SCHEME_SET = new Set<string>([\n this.FIXED,\n this.LINEAR,\n this.EXPONENTIAL,\n this.SCHEDULE,\n ]);\n\n static isValid(value: string): value is TRetryBackoffStrategy {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type TRetryBackoffStrategy = TConstValue<typeof RetryBackoffStrategies>;\n\nexport class RetryJitterModes {\n /** The computed delay is used as-is. */\n static readonly NONE = 'none';\n\n /** Uniform random in [0, delay) - decorrelates a thundering herd hardest. */\n static readonly FULL = 'full';\n\n /** delay/2 + uniform random in [0, delay/2) - jittered but never less than half the delay. */\n static readonly EQUAL = 'equal';\n\n static readonly SCHEME_SET = new Set<string>([this.NONE, this.FULL, this.EQUAL]);\n\n static isValid(value: string): value is TRetryJitterMode {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type TRetryJitterMode = TConstValue<typeof RetryJitterModes>;\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/retry/common/constants.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,OAAO,sBAAsB;aACjB,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,gBAAW,GAAG,aAAa,CAAC;IAE5C,4FAA4F;aAC5E,aAAQ,GAAG,UAAU,CAAC;aAEtB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,QAAQ;KACd,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,2DAA2D;AAC3D,MAAM,OAAO,gBAAgB;IAC3B,wCAAwC;aACxB,SAAI,GAAG,MAAM,CAAC;IAE9B,6EAA6E;aAC7D,SAAI,GAAG,MAAM,CAAC;IAE9B,8FAA8F;aAC9E,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEjF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@/common';\n\n/** How the retry delay grows between attempts. */\nexport class RetryBackoffStrategies {\n static readonly FIXED = 'fixed';\n static readonly LINEAR = 'linear';\n static readonly EXPONENTIAL = 'exponential';\n\n /** An explicit per-attempt cap schedule, e.g. [250, 1000, 4000]; the last entry repeats. */\n static readonly SCHEDULE = 'schedule';\n\n static readonly SCHEME_SET = new Set<string>([\n this.FIXED,\n this.LINEAR,\n this.EXPONENTIAL,\n this.SCHEDULE,\n ]);\n\n static isValid(value: string): value is TRetryBackoffStrategy {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Union of the `RetryBackoffStrategies` values. */\nexport type TRetryBackoffStrategy = TConstValue<typeof RetryBackoffStrategies>;\n\n/** How randomness is applied to a computed retry delay. */\nexport class RetryJitterModes {\n /** The computed delay is used as-is. */\n static readonly NONE = 'none';\n\n /** Uniform random in [0, delay) - decorrelates a thundering herd hardest. */\n static readonly FULL = 'full';\n\n /** delay/2 + uniform random in [0, delay/2) - jittered but never less than half the delay. */\n static readonly EQUAL = 'equal';\n\n static readonly SCHEME_SET = new Set<string>([this.NONE, this.FULL, this.EQUAL]);\n\n static isValid(value: string): value is TRetryJitterMode {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Union of the `RetryJitterModes` values. */\nexport type TRetryJitterMode = TConstValue<typeof RetryJitterModes>;\n"]}
@@ -1,18 +1,32 @@
1
1
  import type { TRetryBackoffStrategy, TRetryJitterMode } from './constants.js';
2
+ /** Retry delay settings; every field is optional. */
2
3
  export interface IRetryBackoffOptions {
3
- /** Default EXPONENTIAL. */
4
+ /** @default RetryBackoffStrategies.EXPONENTIAL */
4
5
  strategy?: TRetryBackoffStrategy;
5
- /** First delay, default 250ms. LINEAR adds it per attempt; EXPONENTIAL multiplies from it. */
6
+ /**
7
+ * First delay in milliseconds. LINEAR adds it per attempt; EXPONENTIAL multiplies from it.
8
+ *
9
+ * @default 250
10
+ */
6
11
  initialDelayMs?: number;
7
- /** EXPONENTIAL growth factor, default 2. Ignored by other strategies. */
12
+ /**
13
+ * EXPONENTIAL growth factor. Ignored by other strategies.
14
+ *
15
+ * @default 2
16
+ */
8
17
  multiplier?: number;
9
- /** Upper cap applied BEFORE jitter, default 30000ms. */
18
+ /**
19
+ * Upper cap in milliseconds, applied BEFORE jitter.
20
+ *
21
+ * @default 30_000
22
+ */
10
23
  maxDelayMs?: number;
11
24
  /** Required when strategy is SCHEDULE; the last entry repeats for later attempts. */
12
25
  scheduleMs?: readonly number[];
13
- /** Default FULL. */
26
+ /** @default RetryJitterModes.FULL */
14
27
  jitter?: TRetryJitterMode;
15
28
  }
29
+ /** State passed to retry callbacks: the attempt number, the error that triggered the retry and the elapsed time in milliseconds. */
16
30
  export interface IRetryContext {
17
31
  attempt: number;
18
32
  error: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/retry/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TRetryBackoffStrategy, TRetryJitterMode } from './constants';\n\nexport interface IRetryBackoffOptions {\n /** Default EXPONENTIAL. */\n strategy?: TRetryBackoffStrategy;\n\n /** First delay, default 250ms. LINEAR adds it per attempt; EXPONENTIAL multiplies from it. */\n initialDelayMs?: number;\n\n /** EXPONENTIAL growth factor, default 2. Ignored by other strategies. */\n multiplier?: number;\n\n /** Upper cap applied BEFORE jitter, default 30000ms. */\n maxDelayMs?: number;\n\n /** Required when strategy is SCHEDULE; the last entry repeats for later attempts. */\n scheduleMs?: readonly number[];\n\n /** Default FULL. */\n jitter?: TRetryJitterMode;\n}\n\nexport interface IRetryContext {\n attempt: number;\n error: unknown;\n elapsedMs: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/retry/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TRetryBackoffStrategy, TRetryJitterMode } from './constants';\n\n/** Retry delay settings; every field is optional. */\nexport interface IRetryBackoffOptions {\n /** @default RetryBackoffStrategies.EXPONENTIAL */\n strategy?: TRetryBackoffStrategy;\n\n /**\n * First delay in milliseconds. LINEAR adds it per attempt; EXPONENTIAL multiplies from it.\n *\n * @default 250\n */\n initialDelayMs?: number;\n\n /**\n * EXPONENTIAL growth factor. Ignored by other strategies.\n *\n * @default 2\n */\n multiplier?: number;\n\n /**\n * Upper cap in milliseconds, applied BEFORE jitter.\n *\n * @default 30_000\n */\n maxDelayMs?: number;\n\n /** Required when strategy is SCHEDULE; the last entry repeats for later attempts. */\n scheduleMs?: readonly number[];\n\n /** @default RetryJitterModes.FULL */\n jitter?: TRetryJitterMode;\n}\n\n/** State passed to retry callbacks: the attempt number, the error that triggered the retry and the elapsed time in milliseconds. */\nexport interface IRetryContext {\n attempt: number;\n error: unknown;\n elapsedMs: number;\n}\n"]}
@@ -32,11 +32,11 @@ export declare class RetryHelper extends BaseHelper {
32
32
  signal?: AbortSignal;
33
33
  logger?: ILogger;
34
34
  operation: string;
35
- /** Default 3. */
35
+ /** @default 3 */
36
36
  maxAttempts?: number;
37
- /** Total budget across attempts AND sleeps. Default: unlimited. */
37
+ /** Total budget across attempts AND sleeps. Unlimited when omitted. */
38
38
  maxTotalMs?: number;
39
- /** Per-attempt race. Default: no per-attempt timeout. */
39
+ /** Per-attempt race. No per-attempt timeout when omitted. */
40
40
  perAttemptTimeoutMs?: number;
41
41
  backoff?: IRetryBackoffOptions;
42
42
  execution: (context: {
@@ -55,7 +55,7 @@ export declare class RetryHelper extends BaseHelper {
55
55
  signal?: AbortSignal;
56
56
  logger?: ILogger;
57
57
  operation: string;
58
- /** Default 3. */
58
+ /** @default 3 */
59
59
  maxAttempts?: number;
60
60
  /** Bounds when a NEW attempt may start; it never interrupts an attempt already in flight, so the first execution always runs to completion - a budget of 0 just means "no retries". */
61
61
  maxTotalMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/modules/retry/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM5C;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;aACjB,yBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAElG,gGAAgG;IAChG,MAAM,CAAC,mBAAmB,CAAC,KAAc;QACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,WAAW,CAAC,oBAAoB,IAAI,KAAK,CAAC;IAClG,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAAC,IAA8C;QAC7E,MAAM,KAAK,GAAG,QAAQ,CAAC;YACrB,OAAO,EAAE,oBAAoB,IAAI,CAAC,SAAS,qBAAq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import type { ValueOrPromise } from '@/common';\nimport { getError } from '@/modules/error';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { RetryBackoffStrategies, RetryJitterModes } from './common/constants';\nimport type { IRetryBackoffOptions, IRetryContext } from './common/types';\nimport { BaseHelper } from '@/modules/base';\n\ntype TRetryAttemptOutcome<T> =\n | { isResolved: true; value: T }\n | { isResolved: false; error: unknown; isRetryAllowed: boolean };\n\n/**\n * Static members call each other through the class name (`RetryHelper.xxx`), never `this` - a\n * detached static method loses its `this` binding.\n */\nexport class RetryHelper extends BaseHelper {\n private static readonly RETRY_TIMEOUT_MARKER = Symbol.for('@venizia/ignis-helpers:retry-timeout');\n\n /** True when `error` is a per-attempt timeout raised by `runWithTimeout`/`executeWithRetry`. */\n static isRetryTimeoutError(error: unknown): boolean {\n return typeof error === 'object' && error !== null && RetryHelper.RETRY_TIMEOUT_MARKER in error;\n }\n\n private static buildTimeoutError(opts: { operation: string; timeoutMs: number }) {\n const error = getError({\n message: `[runWithTimeout][${opts.operation}] Timed out after ${opts.timeoutMs}ms`,\n });\n Object.defineProperty(error, RetryHelper.RETRY_TIMEOUT_MARKER, { value: true });\n\n return error;\n }\n\n private static throwIfAborted(opts: { operation: string; signal?: AbortSignal }) {\n if (opts.signal?.aborted) {\n throw getError({\n message: `[executeWithRetry][${opts.operation}] Aborted | Reason: ${String(opts.signal.reason ?? 'unknown')}`,\n });\n }\n }\n\n /** `sleep` that wakes up early (and rejects) when `signal` aborts mid-wait. */\n private static async sleepWithSignal(opts: {\n ms: number;\n operation: string;\n signal?: AbortSignal;\n }) {\n const { ms, operation, signal } = opts;\n\n if (!signal) {\n await PromiseUtility.sleep({ ms });\n\n return;\n }\n\n RetryHelper.throwIfAborted({ operation, signal });\n\n // The listener is removed in `finally` rather than by the timer callback - the two would otherwise have to reference each other, and a leaked listener on a long-lived signal accumulates across retries.\n let removeAbortListener = () => {};\n\n try {\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, ms);\n\n const onAbort = () => {\n clearTimeout(timer);\n reject(\n getError({\n message: `[executeWithRetry][${operation}] Aborted during backoff | Reason: ${String(signal.reason ?? 'unknown')}`,\n }),\n );\n };\n\n removeAbortListener = () => signal.removeEventListener('abort', onAbort);\n signal.addEventListener('abort', onAbort, { once: true });\n });\n } finally {\n removeAbortListener();\n }\n }\n\n /** Races `execution` against `timeoutMs` (`<= 0`/omitted = no timeout). The losing execution keeps running - JS promises cannot be cancelled - so pass `signal` through for cooperative cancellation. */\n static async runWithTimeout<T>(opts: {\n operation: string;\n timeoutMs?: number;\n execution: () => ValueOrPromise<T>;\n }): Promise<T> {\n const { operation, timeoutMs, execution } = opts;\n\n if (!timeoutMs || timeoutMs <= 0) {\n return execution();\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n reject(RetryHelper.buildTimeoutError({ operation, timeoutMs }));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([Promise.resolve().then(execution), timeoutPromise]);\n\n return result;\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** The pre-jitter delay for `attempt` (1-based, i.e. the delay AFTER attempt N failed). */\n static computeBackoffDelayMs(opts: { attempt: number; backoff?: IRetryBackoffOptions }): number {\n const { attempt } = opts;\n const {\n strategy = RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs = 250,\n multiplier = 2,\n maxDelayMs = 30_000,\n scheduleMs,\n jitter = RetryJitterModes.FULL,\n } = opts.backoff ?? {};\n\n let delayMs: number;\n\n switch (strategy) {\n case RetryBackoffStrategies.FIXED: {\n delayMs = initialDelayMs;\n break;\n }\n case RetryBackoffStrategies.LINEAR: {\n delayMs = initialDelayMs * attempt;\n break;\n }\n case RetryBackoffStrategies.EXPONENTIAL: {\n delayMs = initialDelayMs * Math.pow(multiplier, attempt - 1);\n break;\n }\n case RetryBackoffStrategies.SCHEDULE: {\n if (!scheduleMs?.length) {\n throw getError({\n message:\n '[computeBackoffDelayMs] strategy SCHEDULE requires a non-empty backoff.scheduleMs',\n });\n }\n\n delayMs = scheduleMs[Math.min(attempt - 1, scheduleMs.length - 1)];\n break;\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown backoff strategy '${strategy}' | Expected one of: ${[...RetryBackoffStrategies.SCHEME_SET].join(', ')}`,\n });\n }\n }\n\n delayMs = Math.min(delayMs, maxDelayMs);\n\n if (delayMs <= 0) {\n return 0;\n }\n\n switch (jitter) {\n case RetryJitterModes.NONE: {\n return delayMs;\n }\n case RetryJitterModes.FULL: {\n return Math.floor(Math.random() * delayMs);\n }\n case RetryJitterModes.EQUAL: {\n const half = delayMs / 2;\n\n return Math.floor(half + Math.random() * half);\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown jitter mode '${jitter}' | Expected one of: ${[...RetryJitterModes.SCHEME_SET].join(', ')}`,\n });\n }\n }\n }\n\n /** One `executeWithRetry` attempt and everything that follows a failure: `shouldRetry` refusing rethrows, otherwise the bounds are checked and - when another attempt is allowed - the retry is logged, `onRetry` awaited and the backoff slept, all before returning. */\n private static async runRetryAttempt<T>(opts: {\n attempt: number;\n attemptTimeoutMs?: number;\n startedAt: number;\n deadline?: number;\n maxAttempts: number;\n operation: string;\n signal?: AbortSignal;\n logger?: ILogger;\n backoff?: IRetryBackoffOptions;\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n shouldRetry?: (context: IRetryContext) => boolean;\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<TRetryAttemptOutcome<T>> {\n const {\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n } = opts;\n\n try {\n const value = await RetryHelper.runWithTimeout({\n operation,\n timeoutMs: attemptTimeoutMs,\n execution: () => execution({ attempt, signal }),\n });\n\n return { isResolved: true, value };\n } catch (error) {\n const elapsedMs = Date.now() - startedAt;\n\n if (shouldRetry && !shouldRetry({ attempt, error, elapsedMs })) {\n throw error;\n }\n\n if (attempt >= maxAttempts) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n\n if (deadline && Date.now() + nextDelayMs >= deadline) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n logger\n ?.for('executeWithRetry')\n .debug(\n '[%s] Attempt %d/%d failed - retrying in %dms | Error: %s',\n operation,\n attempt,\n maxAttempts,\n nextDelayMs,\n error,\n );\n\n await onRetry?.({ attempt, error, elapsedMs, nextDelayMs });\n\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n\n return { isResolved: false, error, isRetryAllowed: true };\n }\n }\n\n /** Retries `execution` with backoff, bounded by `maxAttempts`/`maxTotalMs`. JS cannot cancel a running promise - `signal` only stops between attempts/sleeps, so a timed-out execution keeps running unless it honors the signal itself. */\n static async executeWithRetry<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** Default 3. */\n maxAttempts?: number;\n\n /** Total budget across attempts AND sleeps. Default: unlimited. */\n maxTotalMs?: number;\n\n /** Per-attempt race. Default: no per-attempt timeout. */\n perAttemptTimeoutMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Return `false` to stop retrying and rethrow `context.error` immediately. */\n shouldRetry?: (context: IRetryContext) => boolean;\n\n /** Observability hook, awaited before the backoff sleep. */\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<T> {\n const {\n operation,\n execution,\n maxAttempts = 3,\n maxTotalMs,\n perAttemptTimeoutMs,\n backoff,\n shouldRetry,\n onRetry,\n signal,\n logger,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetry][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n const startedAt = Date.now();\n // `!== undefined`, never truthiness: a budget of 0 - or a negative one, which is what `deadline - Date.now()` yields under load - means NO time left, not unlimited time.\n const deadline = maxTotalMs !== undefined ? startedAt + maxTotalMs : undefined;\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const remainingMs = deadline ? deadline - Date.now() : undefined;\n\n if (remainingMs !== undefined && remainingMs <= 0) {\n break;\n }\n\n let attemptTimeoutMs = perAttemptTimeoutMs;\n\n if (remainingMs !== undefined) {\n attemptTimeoutMs = attemptTimeoutMs ? Math.min(attemptTimeoutMs, remainingMs) : remainingMs;\n }\n\n const outcome = await RetryHelper.runRetryAttempt({\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n });\n\n if (outcome.isResolved) {\n return outcome.value;\n }\n\n lastError = outcome.error;\n\n if (!outcome.isRetryAllowed) {\n break;\n }\n }\n\n const elapsedMs = Date.now() - startedAt;\n\n // The budget can run out BEFORE the first attempt (an expired `maxTotalMs`), leaving no error to rethrow; `throw undefined` would detonate inside the caller's own handler on `error.message`.\n if (lastError === undefined) {\n throw getError({\n message: `[executeWithRetry][${operation}] Time budget exhausted before any attempt ran | maxTotalMs: ${maxTotalMs}`,\n });\n }\n\n logger\n ?.for('executeWithRetry')\n .warn('[%s] Exhausted retries | Elapsed: %dms | Error: %s', operation, elapsedMs, lastError);\n\n throw lastError;\n }\n\n /** Retries `execution` while `until(result)` returns false - for read-after-write staleness behind a replicated pool. Never worse than a single un-retried call: on exhaustion the LAST result is returned rather than an error, and a thrown error propagates immediately instead of being retried. Only wrap idempotent operations. */\n static async executeWithRetryUntil<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** Default 3. */\n maxAttempts?: number;\n\n /** Bounds when a NEW attempt may start; it never interrupts an attempt already in flight, so the first execution always runs to completion - a budget of 0 just means \"no retries\". */\n maxTotalMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Retry while this returns false. */\n until: (result: T) => boolean;\n }): Promise<T> {\n const {\n signal,\n logger,\n operation,\n maxAttempts = 3,\n maxTotalMs,\n backoff,\n execution,\n until,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetryUntil][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n // Surfaced before the first execution - a misconfigured backoff discovered mid-loop would discard an already-fetched result.\n RetryHelper.computeBackoffDelayMs({ attempt: 1, backoff });\n\n const startedAt = Date.now();\n let lastResult: T | undefined;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const result2 = await execution({ attempt, signal });\n lastResult = result2;\n\n if (until(lastResult)) {\n return lastResult;\n }\n\n const elapsedMs = Date.now() - startedAt;\n\n if (attempt >= maxAttempts || (maxTotalMs !== undefined && elapsedMs >= maxTotalMs)) {\n break;\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .debug('[%s] until condition not met | Attempt: %d', operation, attempt);\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .warn('[%s] Exhausted retries - returning last (stale) result', operation);\n\n return lastResult as T;\n }\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/modules/retry/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,sBA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J,EAAE,GAAG,CAAC,uBAAuB,CAAC;iBAC7B,KAAK,CAAC,4CAA4C,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAE3E,MAAM,WAAW,GAAG,WAAW,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;YAE5E,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;gBACpB,MAAM,WAAW,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;QAED,MAAM;YACJ,EAAE,GAAG,CAAC,uBAAuB,CAAC;aAC7B,IAAI,CAAC,wDAAwD,EAAE,SAAS,CAAC,CAAC;QAE7E,OAAO,UAAe,CAAC;IACzB,CAAC","sourcesContent":["import type { ValueOrPromise } from '@/common';\nimport { getError } from '@/modules/error';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { RetryBackoffStrategies, RetryJitterModes } from './common/constants';\nimport type { IRetryBackoffOptions, IRetryContext } from './common/types';\nimport { BaseHelper } from '@/modules/base';\n\ntype TRetryAttemptOutcome<T> =\n | { isResolved: true; value: T }\n | { isResolved: false; error: unknown; isRetryAllowed: boolean };\n\n/**\n * Static members call each other through the class name (`RetryHelper.xxx`), never `this` - a\n * detached static method loses its `this` binding.\n */\nexport class RetryHelper extends BaseHelper {\n private static readonly RETRY_TIMEOUT_MARKER = Symbol.for('@venizia/ignis-helpers:retry-timeout');\n\n /** True when `error` is a per-attempt timeout raised by `runWithTimeout`/`executeWithRetry`. */\n static isRetryTimeoutError(error: unknown): boolean {\n return typeof error === 'object' && error !== null && RetryHelper.RETRY_TIMEOUT_MARKER in error;\n }\n\n private static buildTimeoutError(opts: { operation: string; timeoutMs: number }) {\n const error = getError({\n message: `[runWithTimeout][${opts.operation}] Timed out after ${opts.timeoutMs}ms`,\n });\n Object.defineProperty(error, RetryHelper.RETRY_TIMEOUT_MARKER, { value: true });\n\n return error;\n }\n\n private static throwIfAborted(opts: { operation: string; signal?: AbortSignal }) {\n if (opts.signal?.aborted) {\n throw getError({\n message: `[executeWithRetry][${opts.operation}] Aborted | Reason: ${String(opts.signal.reason ?? 'unknown')}`,\n });\n }\n }\n\n /** `sleep` that wakes up early (and rejects) when `signal` aborts mid-wait. */\n private static async sleepWithSignal(opts: {\n ms: number;\n operation: string;\n signal?: AbortSignal;\n }) {\n const { ms, operation, signal } = opts;\n\n if (!signal) {\n await PromiseUtility.sleep({ ms });\n\n return;\n }\n\n RetryHelper.throwIfAborted({ operation, signal });\n\n // The listener is removed in `finally` rather than by the timer callback - the two would otherwise have to reference each other, and a leaked listener on a long-lived signal accumulates across retries.\n let removeAbortListener = () => {};\n\n try {\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, ms);\n\n const onAbort = () => {\n clearTimeout(timer);\n reject(\n getError({\n message: `[executeWithRetry][${operation}] Aborted during backoff | Reason: ${String(signal.reason ?? 'unknown')}`,\n }),\n );\n };\n\n removeAbortListener = () => signal.removeEventListener('abort', onAbort);\n signal.addEventListener('abort', onAbort, { once: true });\n });\n } finally {\n removeAbortListener();\n }\n }\n\n /** Races `execution` against `timeoutMs` (`<= 0`/omitted = no timeout). The losing execution keeps running - JS promises cannot be cancelled - so pass `signal` through for cooperative cancellation. */\n static async runWithTimeout<T>(opts: {\n operation: string;\n timeoutMs?: number;\n execution: () => ValueOrPromise<T>;\n }): Promise<T> {\n const { operation, timeoutMs, execution } = opts;\n\n if (!timeoutMs || timeoutMs <= 0) {\n return execution();\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n reject(RetryHelper.buildTimeoutError({ operation, timeoutMs }));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([Promise.resolve().then(execution), timeoutPromise]);\n\n return result;\n } finally {\n clearTimeout(timer);\n }\n }\n\n /** The pre-jitter delay for `attempt` (1-based, i.e. the delay AFTER attempt N failed). */\n static computeBackoffDelayMs(opts: { attempt: number; backoff?: IRetryBackoffOptions }): number {\n const { attempt } = opts;\n const {\n strategy = RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs = 250,\n multiplier = 2,\n maxDelayMs = 30_000,\n scheduleMs,\n jitter = RetryJitterModes.FULL,\n } = opts.backoff ?? {};\n\n let delayMs: number;\n\n switch (strategy) {\n case RetryBackoffStrategies.FIXED: {\n delayMs = initialDelayMs;\n break;\n }\n case RetryBackoffStrategies.LINEAR: {\n delayMs = initialDelayMs * attempt;\n break;\n }\n case RetryBackoffStrategies.EXPONENTIAL: {\n delayMs = initialDelayMs * Math.pow(multiplier, attempt - 1);\n break;\n }\n case RetryBackoffStrategies.SCHEDULE: {\n if (!scheduleMs?.length) {\n throw getError({\n message:\n '[computeBackoffDelayMs] strategy SCHEDULE requires a non-empty backoff.scheduleMs',\n });\n }\n\n delayMs = scheduleMs[Math.min(attempt - 1, scheduleMs.length - 1)];\n break;\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown backoff strategy '${strategy}' | Expected one of: ${[...RetryBackoffStrategies.SCHEME_SET].join(', ')}`,\n });\n }\n }\n\n delayMs = Math.min(delayMs, maxDelayMs);\n\n if (delayMs <= 0) {\n return 0;\n }\n\n switch (jitter) {\n case RetryJitterModes.NONE: {\n return delayMs;\n }\n case RetryJitterModes.FULL: {\n return Math.floor(Math.random() * delayMs);\n }\n case RetryJitterModes.EQUAL: {\n const half = delayMs / 2;\n\n return Math.floor(half + Math.random() * half);\n }\n default: {\n throw getError({\n message: `[computeBackoffDelayMs] Unknown jitter mode '${jitter}' | Expected one of: ${[...RetryJitterModes.SCHEME_SET].join(', ')}`,\n });\n }\n }\n }\n\n /** One `executeWithRetry` attempt and everything that follows a failure: `shouldRetry` refusing rethrows, otherwise the bounds are checked and - when another attempt is allowed - the retry is logged, `onRetry` awaited and the backoff slept, all before returning. */\n private static async runRetryAttempt<T>(opts: {\n attempt: number;\n attemptTimeoutMs?: number;\n startedAt: number;\n deadline?: number;\n maxAttempts: number;\n operation: string;\n signal?: AbortSignal;\n logger?: ILogger;\n backoff?: IRetryBackoffOptions;\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n shouldRetry?: (context: IRetryContext) => boolean;\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<TRetryAttemptOutcome<T>> {\n const {\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n } = opts;\n\n try {\n const value = await RetryHelper.runWithTimeout({\n operation,\n timeoutMs: attemptTimeoutMs,\n execution: () => execution({ attempt, signal }),\n });\n\n return { isResolved: true, value };\n } catch (error) {\n const elapsedMs = Date.now() - startedAt;\n\n if (shouldRetry && !shouldRetry({ attempt, error, elapsedMs })) {\n throw error;\n }\n\n if (attempt >= maxAttempts) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n\n if (deadline && Date.now() + nextDelayMs >= deadline) {\n return { isResolved: false, error, isRetryAllowed: false };\n }\n\n logger\n ?.for('executeWithRetry')\n .debug(\n '[%s] Attempt %d/%d failed - retrying in %dms | Error: %s',\n operation,\n attempt,\n maxAttempts,\n nextDelayMs,\n error,\n );\n\n await onRetry?.({ attempt, error, elapsedMs, nextDelayMs });\n\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n\n return { isResolved: false, error, isRetryAllowed: true };\n }\n }\n\n /** Retries `execution` with backoff, bounded by `maxAttempts`/`maxTotalMs`. JS cannot cancel a running promise - `signal` only stops between attempts/sleeps, so a timed-out execution keeps running unless it honors the signal itself. */\n static async executeWithRetry<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** @default 3 */\n maxAttempts?: number;\n\n /** Total budget across attempts AND sleeps. Unlimited when omitted. */\n maxTotalMs?: number;\n\n /** Per-attempt race. No per-attempt timeout when omitted. */\n perAttemptTimeoutMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Return `false` to stop retrying and rethrow `context.error` immediately. */\n shouldRetry?: (context: IRetryContext) => boolean;\n\n /** Observability hook, awaited before the backoff sleep. */\n onRetry?: (context: IRetryContext & { nextDelayMs: number }) => ValueOrPromise<void>;\n }): Promise<T> {\n const {\n operation,\n execution,\n maxAttempts = 3,\n maxTotalMs,\n perAttemptTimeoutMs,\n backoff,\n shouldRetry,\n onRetry,\n signal,\n logger,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetry][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n const startedAt = Date.now();\n // `!== undefined`, never truthiness: a budget of 0 - or a negative one, which is what `deadline - Date.now()` yields under load - means NO time left, not unlimited time.\n const deadline = maxTotalMs !== undefined ? startedAt + maxTotalMs : undefined;\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const remainingMs = deadline ? deadline - Date.now() : undefined;\n\n if (remainingMs !== undefined && remainingMs <= 0) {\n break;\n }\n\n let attemptTimeoutMs = perAttemptTimeoutMs;\n\n if (remainingMs !== undefined) {\n attemptTimeoutMs = attemptTimeoutMs ? Math.min(attemptTimeoutMs, remainingMs) : remainingMs;\n }\n\n const outcome = await RetryHelper.runRetryAttempt({\n attempt,\n attemptTimeoutMs,\n startedAt,\n deadline,\n maxAttempts,\n operation,\n signal,\n logger,\n backoff,\n execution,\n shouldRetry,\n onRetry,\n });\n\n if (outcome.isResolved) {\n return outcome.value;\n }\n\n lastError = outcome.error;\n\n if (!outcome.isRetryAllowed) {\n break;\n }\n }\n\n const elapsedMs = Date.now() - startedAt;\n\n // The budget can run out BEFORE the first attempt (an expired `maxTotalMs`), leaving no error to rethrow; `throw undefined` would detonate inside the caller's own handler on `error.message`.\n if (lastError === undefined) {\n throw getError({\n message: `[executeWithRetry][${operation}] Time budget exhausted before any attempt ran | maxTotalMs: ${maxTotalMs}`,\n });\n }\n\n logger\n ?.for('executeWithRetry')\n .warn('[%s] Exhausted retries | Elapsed: %dms | Error: %s', operation, elapsedMs, lastError);\n\n throw lastError;\n }\n\n /** Retries `execution` while `until(result)` returns false - for read-after-write staleness behind a replicated pool. Never worse than a single un-retried call: on exhaustion the LAST result is returned rather than an error, and a thrown error propagates immediately instead of being retried. Only wrap idempotent operations. */\n static async executeWithRetryUntil<T>(opts: {\n signal?: AbortSignal;\n logger?: ILogger;\n operation: string;\n\n /** @default 3 */\n maxAttempts?: number;\n\n /** Bounds when a NEW attempt may start; it never interrupts an attempt already in flight, so the first execution always runs to completion - a budget of 0 just means \"no retries\". */\n maxTotalMs?: number;\n\n backoff?: IRetryBackoffOptions;\n\n execution: (context: { attempt: number; signal?: AbortSignal }) => ValueOrPromise<T>;\n\n /** Retry while this returns false. */\n until: (result: T) => boolean;\n }): Promise<T> {\n const {\n signal,\n logger,\n operation,\n maxAttempts = 3,\n maxTotalMs,\n backoff,\n execution,\n until,\n } = opts;\n\n if (maxAttempts < 1) {\n throw getError({\n message: `[executeWithRetryUntil][${operation}] maxAttempts must be >= 1 | Got: ${maxAttempts}`,\n });\n }\n\n // Surfaced before the first execution - a misconfigured backoff discovered mid-loop would discard an already-fetched result.\n RetryHelper.computeBackoffDelayMs({ attempt: 1, backoff });\n\n const startedAt = Date.now();\n let lastResult: T | undefined;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n RetryHelper.throwIfAborted({ operation, signal });\n\n const result2 = await execution({ attempt, signal });\n lastResult = result2;\n\n if (until(lastResult)) {\n return lastResult;\n }\n\n const elapsedMs = Date.now() - startedAt;\n\n if (attempt >= maxAttempts || (maxTotalMs !== undefined && elapsedMs >= maxTotalMs)) {\n break;\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .debug('[%s] until condition not met | Attempt: %d', operation, attempt);\n\n const nextDelayMs = RetryHelper.computeBackoffDelayMs({ attempt, backoff });\n\n if (nextDelayMs > 0) {\n await RetryHelper.sleepWithSignal({ ms: nextDelayMs, operation, signal });\n }\n }\n\n logger\n ?.for('executeWithRetryUntil')\n .warn('[%s] Exhausted retries - returning last (stale) result', operation);\n\n return lastResult as T;\n }\n}\n"]}
@@ -8,6 +8,7 @@ interface IRawFetchResult {
8
8
  renewable: boolean;
9
9
  };
10
10
  }
11
+ /** Base for secrets providers: caches bundles for `cacheTtlSeconds`, tracks leases and renews them at `renewBeforeRatio` of their TTL, and notifies rotation handlers. Subclasses implement `fetchRaw`, `renewRaw` and `revokeRaw`. The constructor throws when `renewBeforeRatio` is outside (0, 1]. */
11
12
  export declare abstract class AbstractSecretsHelper extends BaseHelper implements ISecretsHelper {
12
13
  protected readonly clock: IClock;
13
14
  protected readonly timers: ITimerAdapter;
@@ -15,6 +15,7 @@ const MIN_RENEW_DELAY_MS = 1_000;
15
15
  const BACKOFF_BASE_MS = 1_000;
16
16
  // Capped at 31 to keep 2 ** (attempt - 1) inside double range: past ~1024 it overflows to Infinity and clampDelayMs's non-finite branch returns the FLOOR, collapsing a long backoff into a 1/sec retry storm.
17
17
  const MAX_BACKOFF_ATTEMPT_EXPONENT = 31;
18
+ /** Base for secrets providers: caches bundles for `cacheTtlSeconds`, tracks leases and renews them at `renewBeforeRatio` of their TTL, and notifies rotation handlers. Subclasses implement `fetchRaw`, `renewRaw` and `revokeRaw`. The constructor throws when `renewBeforeRatio` is outside (0, 1]. */
18
19
  export class AbstractSecretsHelper extends BaseHelper {
19
20
  constructor(opts) {
20
21
  super({ scope: opts.scope, identifier: opts.identifier });
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.helper.js","sourceRoot":"","sources":["../../../../../src/modules/secrets/base/abstract.helper.ts"],"names":[],"mapp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AM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAC9E,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { AnyType } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport type {\n IClock,\n IGetSecretOptions,\n ISecretLease,\n ISecretRotatable,\n ISecretRotationEvent,\n ISecretsHelper,\n ISecretsHelperOptions,\n ITimerAdapter,\n TSecretRotationHandler,\n TTimerHandle,\n} from '../common';\n\ninterface ICacheEntry {\n value: Record<string, string>;\n expiresAt: number;\n}\n\ninterface IRawFetchResult {\n value: Record<string, string>;\n lease?: { leaseId: string; ttlSeconds: number; renewable: boolean };\n}\n\nconst DEFAULT_CLOCK: IClock = { now: () => Date.now() };\nconst DEFAULT_TIMERS: ITimerAdapter = {\n set: (handler, ms) => setTimeout(handler, ms),\n clear: (handle) => clearTimeout(handle as AnyType),\n};\n\nconst DEFAULT_CACHE_TTL_SECONDS = 300;\nconst DEFAULT_RENEW_BEFORE_RATIO = 0.66;\n\n// setTimeout coerces any delay above this to 1ms, triggering an immediate renewal storm.\nconst TIMEOUT_MAX_MS = 2_147_483_647;\n// Floor so an invalid/tiny ttl never becomes a 0ms busy-loop.\nconst MIN_RENEW_DELAY_MS = 1_000;\n// Bounded exponential backoff for the renewal retry loop when Vault is unreachable.\nconst BACKOFF_BASE_MS = 1_000;\n// Capped at 31 to keep 2 ** (attempt - 1) inside double range: past ~1024 it overflows to Infinity and clampDelayMs's non-finite branch returns the FLOOR, collapsing a long backoff into a 1/sec retry storm.\nconst MAX_BACKOFF_ATTEMPT_EXPONENT = 31;\n\nexport abstract class AbstractSecretsHelper extends BaseHelper implements ISecretsHelper {\n protected readonly clock: IClock;\n protected readonly timers: ITimerAdapter;\n protected readonly cacheTtlSeconds: number;\n protected readonly renewBeforeRatio: number;\n\n private readonly cache = new Map<string, ICacheEntry>();\n private readonly leases = new Map<string, ISecretLease>();\n private readonly leasePaths = new Map<string, string>();\n private readonly timerHandles = new Map<string, TTimerHandle>();\n private readonly rotatables = new Map<string, ISecretRotatable[]>();\n private readonly rotateHandlers: TSecretRotationHandler[] = [];\n private readonly backoffAttempts = new Map<string, number>();\n private closed = false;\n\n constructor(opts: ISecretsHelperOptions) {\n super({ scope: opts.scope, identifier: opts.identifier });\n this.clock = opts.clock ?? DEFAULT_CLOCK;\n this.timers = opts.timers ?? DEFAULT_TIMERS;\n this.cacheTtlSeconds = opts.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS;\n\n const ratio = opts.renewBeforeRatio ?? DEFAULT_RENEW_BEFORE_RATIO;\n\n if (!Number.isFinite(ratio) || ratio <= 0 || ratio > 1) {\n throw getError({\n message: `[constructor] renewBeforeRatio must be within (0, 1] | received: ${ratio}`,\n });\n }\n\n this.renewBeforeRatio = ratio;\n }\n\n protected abstract fetchRaw(opts: { path: string }): Promise<IRawFetchResult>;\n protected abstract renewRaw(opts: {\n leaseId: string;\n ttlSeconds: number;\n }): Promise<{ ttlSeconds: number } | null>;\n protected abstract revokeRaw(opts: { leaseId: string }): Promise<void>;\n\n // Concrete providers override to authenticate; default is a no-op.\n async configure(): Promise<void> {\n return;\n }\n\n async getBundle(opts: { path: string }): Promise<Record<string, string>> {\n this.evictExpiredCache();\n const cached = this.cache.get(opts.path);\n\n if (cached && cached.expiresAt > this.clock.now()) {\n return cached.value;\n }\n\n const fresh = await this.fetchRaw({ path: opts.path });\n\n // A shutdown that ran while fetchRaw was in flight already cleared `cache` - honor that and hand back the fetched value uncached rather than resurrecting a map shutdown just emptied.\n if (this.closed) {\n return fresh.value;\n }\n\n this.writeCache({ path: opts.path, value: fresh.value });\n\n return fresh.value;\n }\n\n async get(opts: IGetSecretOptions<string>): Promise<string>;\n async get<TValue>(opts: IGetSecretOptions<TValue>): Promise<TValue>;\n async get<TValue = string>(opts: IGetSecretOptions<TValue>): Promise<TValue> {\n const bundle = await this.getBundle({ path: opts.path });\n const raw = opts.key\n ? Object.hasOwn(bundle, opts.key)\n ? bundle[opts.key]\n : undefined\n : (bundle as AnyType);\n\n return (raw ?? opts.defaultValue) as TValue;\n }\n\n async lease(opts: { path: string; key: string }): Promise<ISecretLease> {\n const fresh = await this.fetchRaw({ path: opts.path });\n\n // A shutdown that ran while fetchRaw was in flight already revoked/cleared every lease - committing this one now would resurrect leases/leasePaths with a lease no live provider will ever renew or revoke, so surface the shutdown instead of silently leaking it back in.\n if (this.closed) {\n throw getError({\n message: `[lease] Provider is shut down | path: ${opts.path} | key: ${opts.key}`,\n });\n }\n\n if (!fresh.lease) {\n throw getError({\n message: `[lease] Path returned no lease | path: ${opts.path} | key: ${opts.key}`,\n });\n }\n\n const lease: ISecretLease = { value: fresh.value, ...fresh.lease };\n this.leases.set(opts.key, lease);\n this.leasePaths.set(opts.key, opts.path);\n this.scheduleRenewal({ key: opts.key, lease });\n\n return lease;\n }\n\n onRotate(handler: TSecretRotationHandler): void {\n this.rotateHandlers.push(handler);\n }\n\n registerRotatable(opts: { key: string; target: ISecretRotatable }): void {\n const list = this.rotatables.get(opts.key) ?? [];\n list.push(opts.target);\n this.rotatables.set(opts.key, list);\n }\n\n async shutdown(): Promise<void> {\n const logger = this.logger.for(this.shutdown.name);\n this.closed = true;\n\n const timerHandlesValues = this.timerHandles.values();\n\n for (const handle of timerHandlesValues) {\n this.timers.clear(handle);\n }\n\n this.timerHandles.clear();\n this.backoffAttempts.clear();\n\n for (const [key, lease] of this.leases) {\n try {\n await this.revokeRaw({ leaseId: lease.leaseId });\n } catch (error) {\n logger.error(\n 'Revoke failed | key: %s | leaseId: %s | error: %s',\n key,\n lease.leaseId,\n error,\n );\n }\n }\n\n this.leases.clear();\n this.leasePaths.clear();\n this.cache.clear();\n }\n\n private writeCache(opts: { path: string; value: Record<string, string> }): void {\n this.cache.set(opts.path, {\n value: opts.value,\n expiresAt: this.clock.now() + this.cacheTtlSeconds * 1000,\n });\n }\n\n private evictExpiredCache(): void {\n const now = this.clock.now();\n\n for (const [path, entry] of this.cache) {\n if (entry.expiresAt <= now) {\n this.cache.delete(path);\n }\n }\n }\n\n private clampDelayMs(opts: { delayMs: number }): number {\n if (!Number.isFinite(opts.delayMs) || opts.delayMs <= 0) {\n return MIN_RENEW_DELAY_MS;\n }\n\n return Math.min(Math.max(opts.delayMs, MIN_RENEW_DELAY_MS), TIMEOUT_MAX_MS);\n }\n\n private armTimer(opts: { key: string; delayMs: number }): void {\n const existing = this.timerHandles.get(opts.key);\n\n if (existing) {\n this.timers.clear(existing);\n }\n\n const handle = this.timers.set(() => {\n this.handleRenewal({ key: opts.key }).catch((error) => {\n this.logger\n .for(this.armTimer.name)\n .error('Renewal handler crashed | key: %s | error: %s', opts.key, error);\n });\n }, opts.delayMs);\n this.timerHandles.set(opts.key, handle);\n }\n\n private scheduleRenewal(opts: { key: string; lease: ISecretLease }): void {\n if (this.closed) {\n return;\n }\n\n this.backoffAttempts.delete(opts.key);\n const delayMs = this.clampDelayMs({\n delayMs: opts.lease.ttlSeconds * this.renewBeforeRatio * 1000,\n });\n this.armTimer({ key: opts.key, delayMs });\n }\n\n // A transient Vault failure must not kill the loop; retry with bounded exponential backoff.\n private scheduleBackoffRetry(opts: { key: string }): void {\n if (this.closed) {\n return;\n }\n\n const attempt = (this.backoffAttempts.get(opts.key) ?? 0) + 1;\n this.backoffAttempts.set(opts.key, attempt);\n const cappedAttempt = Math.min(attempt, MAX_BACKOFF_ATTEMPT_EXPONENT);\n const delayMs = this.clampDelayMs({ delayMs: BACKOFF_BASE_MS * 2 ** (cappedAttempt - 1) });\n this.armTimer({ key: opts.key, delayMs });\n }\n\n private async handleRenewal(opts: { key: string }): Promise<void> {\n if (this.closed) {\n return;\n }\n\n const logger = this.logger.for(this.handleRenewal.name);\n const lease = this.leases.get(opts.key);\n\n if (!lease) {\n logger.debug('No lease to renew | key: %s', opts.key);\n\n return;\n }\n\n try {\n if (!lease.renewable) {\n await this.rotate({ key: opts.key });\n\n return;\n }\n\n const renewed = await this.renewRaw({\n leaseId: lease.leaseId,\n ttlSeconds: lease.ttlSeconds,\n });\n\n if (this.closed) {\n return;\n }\n\n if (!renewed) {\n await this.rotate({ key: opts.key });\n\n return;\n }\n\n const next: ISecretLease = { ...lease, ttlSeconds: renewed.ttlSeconds };\n this.leases.set(opts.key, next);\n this.scheduleRenewal({ key: opts.key, lease: next });\n } catch (error) {\n if (this.closed) {\n return;\n }\n\n logger.error(\n 'Renewal cycle failed; scheduling backoff retry | key: %s | error: %s',\n opts.key,\n error,\n );\n this.scheduleBackoffRetry({ key: opts.key });\n }\n }\n\n private async rotate(opts: { key: string }): Promise<void> {\n const path = this.leasePaths.get(opts.key);\n\n if (!path) {\n throw getError({ message: `[rotate] No lease path registered | key: ${opts.key}` });\n }\n\n const fresh = await this.fetchRaw({ path });\n\n if (this.closed) {\n return;\n }\n\n if (!fresh.lease) {\n throw getError({ message: `[rotate] Path returned no lease on rotation | key: ${opts.key}` });\n }\n\n const lease: ISecretLease = { value: fresh.value, ...fresh.lease };\n this.leases.set(opts.key, lease);\n this.writeCache({ path, value: fresh.value });\n // Arm the next renewal BEFORE dispatching: a wedged consumer must not stall the loop.\n this.scheduleRenewal({ key: opts.key, lease });\n await this.dispatchRotation({ key: opts.key, lease });\n }\n\n private async dispatchRotation(event: ISecretRotationEvent): Promise<void> {\n const logger = this.logger.for(this.dispatchRotation.name);\n\n for (const handler of this.rotateHandlers) {\n try {\n await handler(event);\n } catch (error) {\n logger.error('onRotate handler failed | key: %s | error: %s', event.key, error);\n }\n }\n\n const targets = this.rotatables.get(event.key) ?? [];\n\n for (const target of targets) {\n try {\n await target.onSecretRotated({ key: event.key, secret: event.lease.value });\n } catch (error) {\n logger.error('Rotatable failed | key: %s | error: %s', event.key, error);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"abstract.helper.js","sourceRoot":"","sources":["../../../../../src/modules/secrets/base/abstract.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAwB3C,MAAM,aAAa,GAAW,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AACxD,MAAM,cAAc,GAAkB;IACpC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;IAC7C,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAiB,CAAC;CACnD,CAAC;AAEF,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAExC,yFAAyF;AACzF,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,oFAAoF;AACpF,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,+MAA+M;AAC/M,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,ySAAyS;AACzS,MAAM,OAAgB,qBAAsB,SAAQ,UAAU;IAe5D,YAAY,IAA2B;QACrC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAV3C,UAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;QACvC,WAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;QACzC,eAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QACvC,iBAAY,GA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C,KAAK,CAAC,+CAA+C,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAErD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAC9E,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { AnyType } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport type {\n IClock,\n IGetSecretOptions,\n ISecretLease,\n ISecretRotatable,\n ISecretRotationEvent,\n ISecretsHelper,\n ISecretsHelperOptions,\n ITimerAdapter,\n TSecretRotationHandler,\n TTimerHandle,\n} from '../common';\n\ninterface ICacheEntry {\n value: Record<string, string>;\n expiresAt: number;\n}\n\ninterface IRawFetchResult {\n value: Record<string, string>;\n lease?: { leaseId: string; ttlSeconds: number; renewable: boolean };\n}\n\nconst DEFAULT_CLOCK: IClock = { now: () => Date.now() };\nconst DEFAULT_TIMERS: ITimerAdapter = {\n set: (handler, ms) => setTimeout(handler, ms),\n clear: (handle) => clearTimeout(handle as AnyType),\n};\n\nconst DEFAULT_CACHE_TTL_SECONDS = 300;\nconst DEFAULT_RENEW_BEFORE_RATIO = 0.66;\n\n// setTimeout coerces any delay above this to 1ms, triggering an immediate renewal storm.\nconst TIMEOUT_MAX_MS = 2_147_483_647;\n// Floor so an invalid/tiny ttl never becomes a 0ms busy-loop.\nconst MIN_RENEW_DELAY_MS = 1_000;\n// Bounded exponential backoff for the renewal retry loop when Vault is unreachable.\nconst BACKOFF_BASE_MS = 1_000;\n// Capped at 31 to keep 2 ** (attempt - 1) inside double range: past ~1024 it overflows to Infinity and clampDelayMs's non-finite branch returns the FLOOR, collapsing a long backoff into a 1/sec retry storm.\nconst MAX_BACKOFF_ATTEMPT_EXPONENT = 31;\n\n/** Base for secrets providers: caches bundles for `cacheTtlSeconds`, tracks leases and renews them at `renewBeforeRatio` of their TTL, and notifies rotation handlers. Subclasses implement `fetchRaw`, `renewRaw` and `revokeRaw`. The constructor throws when `renewBeforeRatio` is outside (0, 1]. */\nexport abstract class AbstractSecretsHelper extends BaseHelper implements ISecretsHelper {\n protected readonly clock: IClock;\n protected readonly timers: ITimerAdapter;\n protected readonly cacheTtlSeconds: number;\n protected readonly renewBeforeRatio: number;\n\n private readonly cache = new Map<string, ICacheEntry>();\n private readonly leases = new Map<string, ISecretLease>();\n private readonly leasePaths = new Map<string, string>();\n private readonly timerHandles = new Map<string, TTimerHandle>();\n private readonly rotatables = new Map<string, ISecretRotatable[]>();\n private readonly rotateHandlers: TSecretRotationHandler[] = [];\n private readonly backoffAttempts = new Map<string, number>();\n private closed = false;\n\n constructor(opts: ISecretsHelperOptions) {\n super({ scope: opts.scope, identifier: opts.identifier });\n this.clock = opts.clock ?? DEFAULT_CLOCK;\n this.timers = opts.timers ?? DEFAULT_TIMERS;\n this.cacheTtlSeconds = opts.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS;\n\n const ratio = opts.renewBeforeRatio ?? DEFAULT_RENEW_BEFORE_RATIO;\n\n if (!Number.isFinite(ratio) || ratio <= 0 || ratio > 1) {\n throw getError({\n message: `[constructor] renewBeforeRatio must be within (0, 1] | received: ${ratio}`,\n });\n }\n\n this.renewBeforeRatio = ratio;\n }\n\n protected abstract fetchRaw(opts: { path: string }): Promise<IRawFetchResult>;\n protected abstract renewRaw(opts: {\n leaseId: string;\n ttlSeconds: number;\n }): Promise<{ ttlSeconds: number } | null>;\n protected abstract revokeRaw(opts: { leaseId: string }): Promise<void>;\n\n // Concrete providers override to authenticate; default is a no-op.\n async configure(): Promise<void> {\n return;\n }\n\n async getBundle(opts: { path: string }): Promise<Record<string, string>> {\n this.evictExpiredCache();\n const cached = this.cache.get(opts.path);\n\n if (cached && cached.expiresAt > this.clock.now()) {\n return cached.value;\n }\n\n const fresh = await this.fetchRaw({ path: opts.path });\n\n // A shutdown that ran while fetchRaw was in flight already cleared `cache` - honor that and hand back the fetched value uncached rather than resurrecting a map shutdown just emptied.\n if (this.closed) {\n return fresh.value;\n }\n\n this.writeCache({ path: opts.path, value: fresh.value });\n\n return fresh.value;\n }\n\n async get(opts: IGetSecretOptions<string>): Promise<string>;\n async get<TValue>(opts: IGetSecretOptions<TValue>): Promise<TValue>;\n async get<TValue = string>(opts: IGetSecretOptions<TValue>): Promise<TValue> {\n const bundle = await this.getBundle({ path: opts.path });\n const raw = opts.key\n ? Object.hasOwn(bundle, opts.key)\n ? bundle[opts.key]\n : undefined\n : (bundle as AnyType);\n\n return (raw ?? opts.defaultValue) as TValue;\n }\n\n async lease(opts: { path: string; key: string }): Promise<ISecretLease> {\n const fresh = await this.fetchRaw({ path: opts.path });\n\n // A shutdown that ran while fetchRaw was in flight already revoked/cleared every lease - committing this one now would resurrect leases/leasePaths with a lease no live provider will ever renew or revoke, so surface the shutdown instead of silently leaking it back in.\n if (this.closed) {\n throw getError({\n message: `[lease] Provider is shut down | path: ${opts.path} | key: ${opts.key}`,\n });\n }\n\n if (!fresh.lease) {\n throw getError({\n message: `[lease] Path returned no lease | path: ${opts.path} | key: ${opts.key}`,\n });\n }\n\n const lease: ISecretLease = { value: fresh.value, ...fresh.lease };\n this.leases.set(opts.key, lease);\n this.leasePaths.set(opts.key, opts.path);\n this.scheduleRenewal({ key: opts.key, lease });\n\n return lease;\n }\n\n onRotate(handler: TSecretRotationHandler): void {\n this.rotateHandlers.push(handler);\n }\n\n registerRotatable(opts: { key: string; target: ISecretRotatable }): void {\n const list = this.rotatables.get(opts.key) ?? [];\n list.push(opts.target);\n this.rotatables.set(opts.key, list);\n }\n\n async shutdown(): Promise<void> {\n const logger = this.logger.for(this.shutdown.name);\n this.closed = true;\n\n const timerHandlesValues = this.timerHandles.values();\n\n for (const handle of timerHandlesValues) {\n this.timers.clear(handle);\n }\n\n this.timerHandles.clear();\n this.backoffAttempts.clear();\n\n for (const [key, lease] of this.leases) {\n try {\n await this.revokeRaw({ leaseId: lease.leaseId });\n } catch (error) {\n logger.error(\n 'Revoke failed | key: %s | leaseId: %s | error: %s',\n key,\n lease.leaseId,\n error,\n );\n }\n }\n\n this.leases.clear();\n this.leasePaths.clear();\n this.cache.clear();\n }\n\n private writeCache(opts: { path: string; value: Record<string, string> }): void {\n this.cache.set(opts.path, {\n value: opts.value,\n expiresAt: this.clock.now() + this.cacheTtlSeconds * 1000,\n });\n }\n\n private evictExpiredCache(): void {\n const now = this.clock.now();\n\n for (const [path, entry] of this.cache) {\n if (entry.expiresAt <= now) {\n this.cache.delete(path);\n }\n }\n }\n\n private clampDelayMs(opts: { delayMs: number }): number {\n if (!Number.isFinite(opts.delayMs) || opts.delayMs <= 0) {\n return MIN_RENEW_DELAY_MS;\n }\n\n return Math.min(Math.max(opts.delayMs, MIN_RENEW_DELAY_MS), TIMEOUT_MAX_MS);\n }\n\n private armTimer(opts: { key: string; delayMs: number }): void {\n const existing = this.timerHandles.get(opts.key);\n\n if (existing) {\n this.timers.clear(existing);\n }\n\n const handle = this.timers.set(() => {\n this.handleRenewal({ key: opts.key }).catch((error) => {\n this.logger\n .for(this.armTimer.name)\n .error('Renewal handler crashed | key: %s | error: %s', opts.key, error);\n });\n }, opts.delayMs);\n this.timerHandles.set(opts.key, handle);\n }\n\n private scheduleRenewal(opts: { key: string; lease: ISecretLease }): void {\n if (this.closed) {\n return;\n }\n\n this.backoffAttempts.delete(opts.key);\n const delayMs = this.clampDelayMs({\n delayMs: opts.lease.ttlSeconds * this.renewBeforeRatio * 1000,\n });\n this.armTimer({ key: opts.key, delayMs });\n }\n\n // A transient Vault failure must not kill the loop; retry with bounded exponential backoff.\n private scheduleBackoffRetry(opts: { key: string }): void {\n if (this.closed) {\n return;\n }\n\n const attempt = (this.backoffAttempts.get(opts.key) ?? 0) + 1;\n this.backoffAttempts.set(opts.key, attempt);\n const cappedAttempt = Math.min(attempt, MAX_BACKOFF_ATTEMPT_EXPONENT);\n const delayMs = this.clampDelayMs({ delayMs: BACKOFF_BASE_MS * 2 ** (cappedAttempt - 1) });\n this.armTimer({ key: opts.key, delayMs });\n }\n\n private async handleRenewal(opts: { key: string }): Promise<void> {\n if (this.closed) {\n return;\n }\n\n const logger = this.logger.for(this.handleRenewal.name);\n const lease = this.leases.get(opts.key);\n\n if (!lease) {\n logger.debug('No lease to renew | key: %s', opts.key);\n\n return;\n }\n\n try {\n if (!lease.renewable) {\n await this.rotate({ key: opts.key });\n\n return;\n }\n\n const renewed = await this.renewRaw({\n leaseId: lease.leaseId,\n ttlSeconds: lease.ttlSeconds,\n });\n\n if (this.closed) {\n return;\n }\n\n if (!renewed) {\n await this.rotate({ key: opts.key });\n\n return;\n }\n\n const next: ISecretLease = { ...lease, ttlSeconds: renewed.ttlSeconds };\n this.leases.set(opts.key, next);\n this.scheduleRenewal({ key: opts.key, lease: next });\n } catch (error) {\n if (this.closed) {\n return;\n }\n\n logger.error(\n 'Renewal cycle failed; scheduling backoff retry | key: %s | error: %s',\n opts.key,\n error,\n );\n this.scheduleBackoffRetry({ key: opts.key });\n }\n }\n\n private async rotate(opts: { key: string }): Promise<void> {\n const path = this.leasePaths.get(opts.key);\n\n if (!path) {\n throw getError({ message: `[rotate] No lease path registered | key: ${opts.key}` });\n }\n\n const fresh = await this.fetchRaw({ path });\n\n if (this.closed) {\n return;\n }\n\n if (!fresh.lease) {\n throw getError({ message: `[rotate] Path returned no lease on rotation | key: ${opts.key}` });\n }\n\n const lease: ISecretLease = { value: fresh.value, ...fresh.lease };\n this.leases.set(opts.key, lease);\n this.writeCache({ path, value: fresh.value });\n // Arm the next renewal BEFORE dispatching: a wedged consumer must not stall the loop.\n this.scheduleRenewal({ key: opts.key, lease });\n await this.dispatchRotation({ key: opts.key, lease });\n }\n\n private async dispatchRotation(event: ISecretRotationEvent): Promise<void> {\n const logger = this.logger.for(this.dispatchRotation.name);\n\n for (const handler of this.rotateHandlers) {\n try {\n await handler(event);\n } catch (error) {\n logger.error('onRotate handler failed | key: %s | error: %s', event.key, error);\n }\n }\n\n const targets = this.rotatables.get(event.key) ?? [];\n\n for (const target of targets) {\n try {\n await target.onSecretRotated({ key: event.key, secret: event.lease.value });\n } catch (error) {\n logger.error('Rotatable failed | key: %s | error: %s', event.key, error);\n }\n }\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { TConstValue } from '../../../common/types/index.js';
2
+ /** Secret backends a secrets registration can select. */
2
3
  export declare class SecretProviders {
3
4
  static readonly SYSTEM_ENVS = "system-envs";
4
5
  static readonly HASHICORP_VAULT = "hashicorp-vault";
@@ -6,7 +7,9 @@ export declare class SecretProviders {
6
7
  static readonly SCHEME_SET: Set<string>;
7
8
  static isValid(value: string): value is TSecretProvider;
8
9
  }
10
+ /** Union of the `SecretProviders` values. */
9
11
  export type TSecretProvider = TConstValue<typeof SecretProviders>;
12
+ /** Ways a Vault provider can authenticate. */
10
13
  export declare class VaultAuthMethods {
11
14
  static readonly TOKEN = "token";
12
15
  static readonly APP_ROLE = "app-role";
@@ -14,5 +17,6 @@ export declare class VaultAuthMethods {
14
17
  static readonly SCHEME_SET: Set<string>;
15
18
  static isValid(value: string): value is TVaultAuthMethod;
16
19
  }
20
+ /** Union of the `VaultAuthMethods` values. */
17
21
  export type TVaultAuthMethod = TConstValue<typeof VaultAuthMethods>;
18
22
  //# sourceMappingURL=constants.d.ts.map
@@ -1,3 +1,4 @@
1
+ /** Secret backends a secrets registration can select. */
1
2
  export class SecretProviders {
2
3
  static { this.SYSTEM_ENVS = 'system-envs'; }
3
4
  static { this.HASHICORP_VAULT = 'hashicorp-vault'; }
@@ -7,6 +8,7 @@ export class SecretProviders {
7
8
  return this.SCHEME_SET.has(value);
8
9
  }
9
10
  }
11
+ /** Ways a Vault provider can authenticate. */
10
12
  export class VaultAuthMethods {
11
13
  static { this.TOKEN = 'token'; }
12
14
  static { this.APP_ROLE = 'app-role'; }
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/secrets/common/constants.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;aACV,gBAAW,GAAG,aAAa,CAAC;aAC5B,oBAAe,GAAG,iBAAiB,CAAC;aACpC,iBAAY,GAAG,cAAc,CAAC;aAE9B,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAElG,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,gBAAgB;aACX,UAAK,GAAG,OAAO,CAAC;aAChB,aAAQ,GAAG,UAAU,CAAC;aACtB,eAAU,GAAG,YAAY,CAAC;aAE1B,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAEnF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\nexport class SecretProviders {\n static readonly SYSTEM_ENVS = 'system-envs';\n static readonly HASHICORP_VAULT = 'hashicorp-vault';\n static readonly DOTENV_VAULT = 'dotenv-vault';\n\n static readonly SCHEME_SET = new Set([this.SYSTEM_ENVS, this.HASHICORP_VAULT, this.DOTENV_VAULT]);\n\n static isValid(value: string): value is TSecretProvider {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type TSecretProvider = TConstValue<typeof SecretProviders>;\n\nexport class VaultAuthMethods {\n static readonly TOKEN = 'token';\n static readonly APP_ROLE = 'app-role';\n static readonly KUBERNETES = 'kubernetes';\n\n static readonly SCHEME_SET = new Set([this.TOKEN, this.APP_ROLE, this.KUBERNETES]);\n\n static isValid(value: string): value is TVaultAuthMethod {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type TVaultAuthMethod = TConstValue<typeof VaultAuthMethods>;\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/secrets/common/constants.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,MAAM,OAAO,eAAe;aACV,gBAAW,GAAG,aAAa,CAAC;aAC5B,oBAAe,GAAG,iBAAiB,CAAC;aACpC,iBAAY,GAAG,cAAc,CAAC;aAE9B,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAElG,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,8CAA8C;AAC9C,MAAM,OAAO,gBAAgB;aACX,UAAK,GAAG,OAAO,CAAC;aAChB,aAAQ,GAAG,UAAU,CAAC;aACtB,eAAU,GAAG,YAAY,CAAC;aAE1B,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAEnF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\n/** Secret backends a secrets registration can select. */\nexport class SecretProviders {\n static readonly SYSTEM_ENVS = 'system-envs';\n static readonly HASHICORP_VAULT = 'hashicorp-vault';\n static readonly DOTENV_VAULT = 'dotenv-vault';\n\n static readonly SCHEME_SET = new Set([this.SYSTEM_ENVS, this.HASHICORP_VAULT, this.DOTENV_VAULT]);\n\n static isValid(value: string): value is TSecretProvider {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Union of the `SecretProviders` values. */\nexport type TSecretProvider = TConstValue<typeof SecretProviders>;\n\n/** Ways a Vault provider can authenticate. */\nexport class VaultAuthMethods {\n static readonly TOKEN = 'token';\n static readonly APP_ROLE = 'app-role';\n static readonly KUBERNETES = 'kubernetes';\n\n static readonly SCHEME_SET = new Set([this.TOKEN, this.APP_ROLE, this.KUBERNETES]);\n\n static isValid(value: string): value is TVaultAuthMethod {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Union of the `VaultAuthMethods` values. */\nexport type TVaultAuthMethod = TConstValue<typeof VaultAuthMethods>;\n"]}
@@ -1,11 +1,13 @@
1
1
  import type { IConfigurable } from '../../../../common/types/index.js';
2
2
  import type { ISecretLease, ISecretRotatable, TSecretRotationHandler } from './lease.js';
3
3
  import type { IClock, ITimerAdapter } from './timer.js';
4
+ /** Selects a secret: the `path` of a bundle and optionally one `key` in it. `defaultValue` is returned when the key is absent. */
4
5
  export interface IGetSecretOptions<TValue = string> {
5
6
  path: string;
6
7
  key?: string;
7
8
  defaultValue?: TValue;
8
9
  }
10
+ /** Contract of a secrets provider: cached reads, dynamic leases with rotation handlers, and shutdown. */
9
11
  export interface ISecretsHelper extends IConfigurable {
10
12
  get<TValue = string>(opts: IGetSecretOptions<TValue>): Promise<TValue>;
11
13
  getBundle(opts: {
@@ -22,10 +24,21 @@ export interface ISecretsHelper extends IConfigurable {
22
24
  }): void;
23
25
  shutdown(): Promise<void>;
24
26
  }
27
+ /** Constructor options of a secrets provider. `clock` and `timers` can be replaced in tests. */
25
28
  export interface ISecretsHelperOptions {
26
29
  scope: string;
27
30
  identifier?: string;
31
+ /**
32
+ * TTL in seconds of the get/getBundle cache.
33
+ *
34
+ * @default 300
35
+ */
28
36
  cacheTtlSeconds?: number;
37
+ /**
38
+ * Renew a lease at ttl * ratio; must be within (0, 1].
39
+ *
40
+ * @default 0.66
41
+ */
29
42
  renewBeforeRatio?: number;
30
43
  clock?: IClock;
31
44
  timers?: ITimerAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../../src/modules/secrets/common/types/helper.ts"],"names":[],"mappings":"","sourcesContent":["import type { IConfigurable } from '@/common/types';\nimport type { ISecretLease, ISecretRotatable, TSecretRotationHandler } from './lease';\nimport type { IClock, ITimerAdapter } from './timer';\n\nexport interface IGetSecretOptions<TValue = string> {\n path: string;\n key?: string;\n defaultValue?: TValue;\n}\n\nexport interface ISecretsHelper extends IConfigurable {\n get<TValue = string>(opts: IGetSecretOptions<TValue>): Promise<TValue>;\n getBundle(opts: { path: string }): Promise<Record<string, string>>;\n lease(opts: { path: string; key: string }): Promise<ISecretLease>;\n onRotate(handler: TSecretRotationHandler): void;\n registerRotatable(opts: { key: string; target: ISecretRotatable }): void;\n shutdown(): Promise<void>;\n}\n\nexport interface ISecretsHelperOptions {\n scope: string;\n identifier?: string;\n cacheTtlSeconds?: number;\n renewBeforeRatio?: number;\n clock?: IClock;\n timers?: ITimerAdapter;\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../../src/modules/secrets/common/types/helper.ts"],"names":[],"mappings":"","sourcesContent":["import type { IConfigurable } from '@/common/types';\nimport type { ISecretLease, ISecretRotatable, TSecretRotationHandler } from './lease';\nimport type { IClock, ITimerAdapter } from './timer';\n\n/** Selects a secret: the `path` of a bundle and optionally one `key` in it. `defaultValue` is returned when the key is absent. */\nexport interface IGetSecretOptions<TValue = string> {\n path: string;\n key?: string;\n defaultValue?: TValue;\n}\n\n/** Contract of a secrets provider: cached reads, dynamic leases with rotation handlers, and shutdown. */\nexport interface ISecretsHelper extends IConfigurable {\n get<TValue = string>(opts: IGetSecretOptions<TValue>): Promise<TValue>;\n getBundle(opts: { path: string }): Promise<Record<string, string>>;\n lease(opts: { path: string; key: string }): Promise<ISecretLease>;\n onRotate(handler: TSecretRotationHandler): void;\n registerRotatable(opts: { key: string; target: ISecretRotatable }): void;\n shutdown(): Promise<void>;\n}\n\n/** Constructor options of a secrets provider. `clock` and `timers` can be replaced in tests. */\nexport interface ISecretsHelperOptions {\n scope: string;\n identifier?: string;\n /**\n * TTL in seconds of the get/getBundle cache.\n *\n * @default 300\n */\n cacheTtlSeconds?: number;\n /**\n * Renew a lease at ttl * ratio; must be within (0, 1].\n *\n * @default 0.66\n */\n renewBeforeRatio?: number;\n clock?: IClock;\n timers?: ITimerAdapter;\n}\n"]}
@@ -6,10 +6,12 @@ export interface ISecretLease {
6
6
  ttlSeconds: number;
7
7
  renewable: boolean;
8
8
  }
9
+ /** Passed to rotation handlers: the `key` that rotated and its new lease. */
9
10
  export interface ISecretRotationEvent {
10
11
  key: string;
11
12
  lease: ISecretLease;
12
13
  }
14
+ /** Callback run when a leased secret is renewed with new values; may be async. */
13
15
  export type TSecretRotationHandler = (event: ISecretRotationEvent) => ValueOrPromise<void>;
14
16
  /** A live consumer (pool holder) that rebuilds gracefully when its secret rotates. */
15
17
  export interface ISecretRotatable {
@@ -1 +1 @@
1
- {"version":3,"file":"lease.js","sourceRoot":"","sources":["../../../../../../src/modules/secrets/common/types/lease.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@/common/types';\n\n/** A dynamic, lease-bearing secret (e.g. Vault `database/creds/...`). */\nexport interface ISecretLease {\n value: Record<string, string>;\n leaseId: string;\n ttlSeconds: number;\n renewable: boolean;\n}\n\nexport interface ISecretRotationEvent {\n key: string;\n lease: ISecretLease;\n}\n\nexport type TSecretRotationHandler = (event: ISecretRotationEvent) => ValueOrPromise<void>;\n\n/** A live consumer (pool holder) that rebuilds gracefully when its secret rotates. */\nexport interface ISecretRotatable {\n onSecretRotated(opts: { key: string; secret: Record<string, string> }): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"lease.js","sourceRoot":"","sources":["../../../../../../src/modules/secrets/common/types/lease.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueOrPromise } from '@/common/types';\n\n/** A dynamic, lease-bearing secret (e.g. Vault `database/creds/...`). */\nexport interface ISecretLease {\n value: Record<string, string>;\n leaseId: string;\n ttlSeconds: number;\n renewable: boolean;\n}\n\n/** Passed to rotation handlers: the `key` that rotated and its new lease. */\nexport interface ISecretRotationEvent {\n key: string;\n lease: ISecretLease;\n}\n\n/** Callback run when a leased secret is renewed with new values; may be async. */\nexport type TSecretRotationHandler = (event: ISecretRotationEvent) => ValueOrPromise<void>;\n\n/** A live consumer (pool holder) that rebuilds gracefully when its secret rotates. */\nexport interface ISecretRotatable {\n onSecretRotated(opts: { key: string; secret: Record<string, string> }): Promise<void>;\n}\n"]}