@venizia/ignis-helpers 0.4.7-0 → 0.4.7-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 (311) hide show
  1. package/LICENSE.md +1 -3
  2. package/README.md +7 -8
  3. package/dist/esm/common/redact.d.ts +25 -17
  4. package/dist/esm/common/redact.d.ts.map +1 -1
  5. package/dist/esm/common/redact.js +50 -46
  6. package/dist/esm/common/redact.js.map +1 -1
  7. package/dist/esm/common/resolvers.d.ts +7 -5
  8. package/dist/esm/common/resolvers.d.ts.map +1 -1
  9. package/dist/esm/common/resolvers.js +11 -9
  10. package/dist/esm/common/resolvers.js.map +1 -1
  11. package/dist/esm/core.d.ts +5 -3
  12. package/dist/esm/core.d.ts.map +1 -1
  13. package/dist/esm/core.js +7 -3
  14. package/dist/esm/core.js.map +1 -1
  15. package/dist/esm/modules/base.d.ts +1 -1
  16. package/dist/esm/modules/base.d.ts.map +1 -1
  17. package/dist/esm/modules/base.js +14 -5
  18. package/dist/esm/modules/base.js.map +1 -1
  19. package/dist/esm/modules/cron/helper.js +4 -4
  20. package/dist/esm/modules/cron/helper.js.map +1 -1
  21. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
  22. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
  23. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
  24. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  25. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
  26. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  27. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts +15 -5
  28. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +1 -1
  29. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js +16 -4
  30. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
  31. package/dist/esm/modules/env/app-env.d.ts.map +1 -1
  32. package/dist/esm/modules/env/app-env.js +2 -2
  33. package/dist/esm/modules/env/app-env.js.map +1 -1
  34. package/dist/esm/modules/logger/base/base.d.ts.map +1 -1
  35. package/dist/esm/modules/logger/base/base.js +3 -3
  36. package/dist/esm/modules/logger/base/base.js.map +1 -1
  37. package/dist/esm/modules/logger/base/console.d.ts +9 -4
  38. package/dist/esm/modules/logger/base/console.d.ts.map +1 -1
  39. package/dist/esm/modules/logger/base/console.js +15 -4
  40. package/dist/esm/modules/logger/base/console.js.map +1 -1
  41. package/dist/esm/modules/logger/common/constants.d.ts +23 -22
  42. package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
  43. package/dist/esm/modules/logger/common/constants.js +43 -46
  44. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  45. package/dist/esm/modules/logger/common/debug-gate.d.ts +33 -0
  46. package/dist/esm/modules/logger/common/debug-gate.d.ts.map +1 -0
  47. package/dist/esm/modules/logger/common/debug-gate.js +51 -0
  48. package/dist/esm/modules/logger/common/debug-gate.js.map +1 -0
  49. package/dist/esm/modules/logger/common/index.d.ts +1 -0
  50. package/dist/esm/modules/logger/common/index.d.ts.map +1 -1
  51. package/dist/esm/modules/logger/common/index.js +1 -0
  52. package/dist/esm/modules/logger/common/index.js.map +1 -1
  53. package/dist/esm/modules/logger/common/types.d.ts +7 -0
  54. package/dist/esm/modules/logger/common/types.d.ts.map +1 -1
  55. package/dist/esm/modules/logger/common/types.js +16 -0
  56. package/dist/esm/modules/logger/common/types.js.map +1 -1
  57. package/dist/esm/modules/logger/factory.d.ts +29 -10
  58. package/dist/esm/modules/logger/factory.d.ts.map +1 -1
  59. package/dist/esm/modules/logger/factory.js +108 -48
  60. package/dist/esm/modules/logger/factory.js.map +1 -1
  61. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
  62. package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
  63. package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
  64. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  65. package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
  66. package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
  67. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  68. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  69. package/dist/esm/modules/logger/hf/logger.js +5 -5
  70. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  71. package/dist/esm/modules/logger/index.d.ts +0 -1
  72. package/dist/esm/modules/logger/index.d.ts.map +1 -1
  73. package/dist/esm/modules/logger/index.js +0 -1
  74. package/dist/esm/modules/logger/index.js.map +1 -1
  75. package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
  76. package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
  77. package/dist/esm/modules/logger/pino/backing.js +3 -8
  78. package/dist/esm/modules/logger/pino/backing.js.map +1 -1
  79. package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
  80. package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
  81. package/dist/esm/modules/logger/pino/destination.js +12 -13
  82. package/dist/esm/modules/logger/pino/destination.js.map +1 -1
  83. package/dist/esm/modules/logger/pino/logger.js +2 -2
  84. package/dist/esm/modules/logger/pino/logger.js.map +1 -1
  85. package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
  86. package/dist/esm/modules/logger/winston/common/constants.js +7 -6
  87. package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
  88. package/dist/esm/modules/logger/winston/define.d.ts +0 -7
  89. package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
  90. package/dist/esm/modules/logger/winston/define.js +0 -5
  91. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  92. package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
  93. package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
  94. package/dist/esm/modules/logger/winston/formats.js +17 -4
  95. package/dist/esm/modules/logger/winston/formats.js.map +1 -1
  96. package/dist/esm/modules/logger/winston/index.d.ts +3 -2
  97. package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
  98. package/dist/esm/modules/logger/winston/index.js +3 -2
  99. package/dist/esm/modules/logger/winston/index.js.map +1 -1
  100. package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
  101. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  102. package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
  103. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  104. package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
  105. package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
  106. package/dist/esm/modules/network/http-request/common/index.js +0 -1
  107. package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
  108. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
  109. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
  110. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  111. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  112. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
  113. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  114. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
  115. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  116. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
  117. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  118. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
  119. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  120. package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
  121. package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
  122. package/dist/esm/modules/network/utilities/query-string.js +48 -46
  123. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  124. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
  125. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
  126. package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
  127. package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
  128. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
  129. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
  130. package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
  131. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  132. package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
  133. package/dist/esm/modules/queue/bullmq/helper.js +6 -6
  134. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  135. package/dist/esm/modules/queue/common/hook.d.ts +14 -12
  136. package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
  137. package/dist/esm/modules/queue/common/hook.js +21 -19
  138. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  139. package/dist/esm/modules/queue/common/index.d.ts +0 -1
  140. package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
  141. package/dist/esm/modules/queue/common/index.js +0 -1
  142. package/dist/esm/modules/queue/common/index.js.map +1 -1
  143. package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
  144. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  145. package/dist/esm/modules/queue/kafka/base.js +3 -3
  146. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  147. package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
  148. package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
  149. package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
  150. package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
  151. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
  152. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
  153. package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
  154. package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
  155. package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
  156. package/dist/esm/modules/queue/kafka/consumer.js +22 -22
  157. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  158. package/dist/esm/modules/queue/mqtt/helper.js +10 -10
  159. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  160. package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
  161. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  162. package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
  163. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  164. package/dist/esm/modules/redis/factory.d.ts +13 -9
  165. package/dist/esm/modules/redis/factory.d.ts.map +1 -1
  166. package/dist/esm/modules/redis/factory.js +15 -13
  167. package/dist/esm/modules/redis/factory.js.map +1 -1
  168. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
  169. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  170. package/dist/esm/modules/redis/single/single.helper.js +2 -2
  171. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  172. package/dist/esm/modules/redis/utility.d.ts +13 -11
  173. package/dist/esm/modules/redis/utility.d.ts.map +1 -1
  174. package/dist/esm/modules/redis/utility.js +46 -44
  175. package/dist/esm/modules/redis/utility.js.map +1 -1
  176. package/dist/esm/modules/retry/helper.js +2 -2
  177. package/dist/esm/modules/retry/helper.js.map +1 -1
  178. package/dist/esm/modules/secrets/factory.d.ts +5 -3
  179. package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
  180. package/dist/esm/modules/secrets/factory.js +36 -34
  181. package/dist/esm/modules/secrets/factory.js.map +1 -1
  182. package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
  183. package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
  184. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  185. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
  186. package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
  187. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  188. package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
  189. package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
  190. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  191. package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
  192. package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
  193. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  194. package/dist/esm/modules/storage/base.js +7 -7
  195. package/dist/esm/modules/storage/base.js.map +1 -1
  196. package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
  197. package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
  198. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  199. package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
  200. package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
  201. package/dist/esm/modules/storage/bun-s3/utility.js +261 -239
  202. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  203. package/dist/esm/modules/storage/common/errors.d.ts +0 -4
  204. package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
  205. package/dist/esm/modules/storage/common/errors.js +0 -10
  206. package/dist/esm/modules/storage/common/errors.js.map +1 -1
  207. package/dist/esm/modules/storage/common/utility.d.ts +11 -5
  208. package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
  209. package/dist/esm/modules/storage/common/utility.js +30 -17
  210. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  211. package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
  212. package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
  213. package/dist/esm/modules/uid/uuid/helper.js +7 -7
  214. package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
  215. package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
  216. package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
  217. package/dist/esm/modules/uid/uuid/v4.js +51 -46
  218. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  219. package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
  220. package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
  221. package/dist/esm/modules/uid/uuid/v5.js +83 -78
  222. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  223. package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
  224. package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
  225. package/dist/esm/modules/uid/uuid/v7.js +88 -79
  226. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  227. package/dist/esm/modules/worker-thread/bus/base.js +2 -2
  228. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  229. package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
  230. package/dist/esm/modules/worker-thread/worker/base.js +4 -3
  231. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  232. package/dist/esm/utilities/error.utility.d.ts +7 -0
  233. package/dist/esm/utilities/error.utility.d.ts.map +1 -0
  234. package/dist/esm/utilities/error.utility.js +9 -0
  235. package/dist/esm/utilities/error.utility.js.map +1 -0
  236. package/dist/esm/utilities/form-body.utility.d.ts +12 -10
  237. package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
  238. package/dist/esm/utilities/form-body.utility.js +19 -17
  239. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  240. package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
  241. package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
  242. package/dist/esm/utilities/hr-time.utility.js +11 -9
  243. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  244. package/dist/esm/utilities/index.d.ts +2 -2
  245. package/dist/esm/utilities/index.d.ts.map +1 -1
  246. package/dist/esm/utilities/index.js +2 -2
  247. package/dist/esm/utilities/index.js.map +1 -1
  248. package/dist/esm/utilities/module.utility.d.ts.map +1 -1
  249. package/dist/esm/utilities/module.utility.js +1 -0
  250. package/dist/esm/utilities/module.utility.js.map +1 -1
  251. package/dist/esm/utilities/parse.utility.d.ts +89 -43
  252. package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
  253. package/dist/esm/utilities/parse.utility.js +173 -141
  254. package/dist/esm/utilities/parse.utility.js.map +1 -1
  255. package/dist/esm/utilities/performance.utility.d.ts +15 -13
  256. package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
  257. package/dist/esm/utilities/performance.utility.js +34 -29
  258. package/dist/esm/utilities/performance.utility.js.map +1 -1
  259. package/dist/esm/utilities/promise.utility.d.ts +20 -18
  260. package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
  261. package/dist/esm/utilities/promise.utility.js +41 -51
  262. package/dist/esm/utilities/promise.utility.js.map +1 -1
  263. package/dist/esm/utilities/request.utility.d.ts +35 -29
  264. package/dist/esm/utilities/request.utility.d.ts.map +1 -1
  265. package/dist/esm/utilities/request.utility.js +118 -115
  266. package/dist/esm/utilities/request.utility.js.map +1 -1
  267. package/package.json +4 -15
  268. package/dist/esm/modules/logger/resolver.d.ts +0 -33
  269. package/dist/esm/modules/logger/resolver.d.ts.map +0 -1
  270. package/dist/esm/modules/logger/resolver.js +0 -95
  271. package/dist/esm/modules/logger/resolver.js.map +0 -1
  272. package/dist/esm/modules/logger/slot.d.ts +0 -23
  273. package/dist/esm/modules/logger/slot.d.ts.map +0 -1
  274. package/dist/esm/modules/logger/slot.js +0 -119
  275. package/dist/esm/modules/logger/slot.js.map +0 -1
  276. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
  277. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
  278. package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
  279. package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
  280. package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
  281. package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
  282. package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
  283. package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
  284. package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
  285. package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
  286. package/dist/esm/modules/network/http-request/common/types.js +0 -2
  287. package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
  288. package/dist/esm/modules/queue/common/types.d.ts +0 -2
  289. package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
  290. package/dist/esm/modules/queue/common/types.js +0 -2
  291. package/dist/esm/modules/queue/common/types.js.map +0 -1
  292. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
  293. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
  294. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
  295. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
  296. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
  297. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
  298. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
  299. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
  300. package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
  301. package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
  302. package/dist/esm/modules/storage/minio/helper.js +0 -177
  303. package/dist/esm/modules/storage/minio/helper.js.map +0 -1
  304. package/dist/esm/modules/storage/minio/index.d.ts +0 -2
  305. package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
  306. package/dist/esm/modules/storage/minio/index.js +0 -2
  307. package/dist/esm/modules/storage/minio/index.js.map +0 -1
  308. package/dist/esm/utilities/sleep.utility.d.ts +0 -2
  309. package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
  310. package/dist/esm/utilities/sleep.utility.js +0 -4
  311. package/dist/esm/utilities/sleep.utility.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { BaseHelper } from '../../base.js';
2
2
  import { getError } from '../../error/index.js';
3
- import { toError } from '../../../utilities/promise.utility.js';
3
+ import { ErrorUtility } from '../../../utilities/error.utility.js';
4
4
  import { ModuleUtility } from '../../../utilities/module.utility.js';
5
- import { invokeHook } from '../common/index.js';
5
+ import { HookUtility } from '../common/index.js';
6
6
  export class BullMQHelper extends BaseHelper {
7
7
  constructor(options) {
8
8
  super({ scope: BullMQHelper.name, identifier: options.identifier });
@@ -118,14 +118,14 @@ export class BullMQHelper extends BaseHelper {
118
118
  },
119
119
  });
120
120
  this.worker.on('completed', (job, result) => {
121
- invokeHook({
121
+ HookUtility.invoke({
122
122
  logger: this.logger,
123
123
  scope: 'worker-completed',
124
124
  execution: () => this.onWorkerDataCompleted?.(job, result),
125
125
  });
126
126
  });
127
127
  this.worker.on('failed', (job, reason) => {
128
- invokeHook({
128
+ HookUtility.invoke({
129
129
  logger: this.logger,
130
130
  scope: 'worker-failed',
131
131
  execution: () => this.onWorkerDataFail?.(job, reason),
@@ -166,7 +166,7 @@ export class BullMQHelper extends BaseHelper {
166
166
  this.logger
167
167
  .for(this.close.name)
168
168
  .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);
169
- failures.push(toError(error).message);
169
+ failures.push(ErrorUtility.toError({ error }).message);
170
170
  }
171
171
  try {
172
172
  await this.queue?.close();
@@ -175,7 +175,7 @@ export class BullMQHelper extends BaseHelper {
175
175
  this.logger
176
176
  .for(this.close.name)
177
177
  .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);
178
- failures.push(toError(error).message);
178
+ failures.push(ErrorUtility.toError({ error }).message);
179
179
  }
180
180
  if (failures.length) {
181
181
  throw get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AAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { toError } from '@/utilities/promise.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { invokeHook, type TBullQueueRole } from '../common';\n\nexport interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {\n queueName: string;\n identifier: string;\n role: TBullQueueRole;\n redisConnection: IRedisHelper;\n\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. Omitted, it is loaded when a queue or worker is built. */\n module?: typeof import('bullmq');\n\n numberOfWorker?: number;\n lockDuration?: number;\n\n /** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */\n queueOptions?: Omit<QueueOptions, 'connection'>;\n /** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */\n workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: any) => Promise<void>;\n onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n}\n\nexport class BullMQHelper<TQueueElement = any, TQueueResult = any> extends BaseHelper {\n protected queueName: string;\n protected role: TBullQueueRole;\n protected redisConnection: IRedisHelper;\n\n queue: Queue<TQueueElement, TQueueResult>;\n worker: Worker<TQueueElement, TQueueResult>;\n\n protected numberOfWorker = 1;\n protected lockDuration = 90 * 60 * 1000;\n\n protected queueOptions?: Omit<QueueOptions, 'connection'>;\n protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n protected onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: any,\n ) => Promise<void>;\n protected onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n\n private readonly bullmqModule?: typeof import('bullmq');\n\n constructor(options: IBullMQOptions<TQueueElement, TQueueResult>) {\n super({ scope: BullMQHelper.name, identifier: options.identifier });\n const {\n queueName,\n redisConnection,\n role,\n numberOfWorker = 1,\n lockDuration = 90 * 60 * 1000,\n queueOptions,\n workerOptions,\n onWorkerData,\n onWorkerDataCompleted,\n onWorkerDataFail,\n module,\n } = options;\n\n this.bullmqModule = module;\n\n this.queueName = queueName;\n this.role = role;\n this.redisConnection = redisConnection;\n\n this.numberOfWorker = numberOfWorker;\n this.lockDuration = lockDuration;\n\n this.queueOptions = queueOptions;\n this.workerOptions = workerOptions;\n\n this.onWorkerData = onWorkerData;\n this.onWorkerDataCompleted = onWorkerDataCompleted;\n this.onWorkerDataFail = onWorkerDataFail;\n\n this.configure();\n }\n\n static newInstance<T = any, R = any>(opts: IBullMQOptions<T, R>) {\n return new BullMQHelper<T, R>(opts);\n }\n\n /** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */\n protected isClusterClient(): boolean {\n const client = Object(this.redisConnection.getClient());\n\n if (Reflect.get(client, 'isCluster') === true) {\n return true;\n }\n\n return typeof Reflect.get(client, 'nodes') === 'function';\n }\n\n protected resolveQueueName(): string {\n if (this.isClusterClient() && !this.queueName.startsWith('{')) {\n return `{${this.queueName}}`;\n }\n\n return this.queueName;\n }\n\n configureQueue() {\n if (!this.queueName) {\n this.logger\n .for(this.configureQueue.name)\n .error('Invalid queue name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.queue = this.buildQueue({ queueName });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.queue.on('error', (error) => {\n this.logger\n .for('queue-error')\n .error(\n 'queue: %s | Queue error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n /** Full `Queue` options: framework defaults, then `this.queueOptions`, then the connection the helper owns - in that precedence order. */\n protected queueOptionsFor(opts: { queueName: string }): QueueOptions {\n this.logger\n .for(this.queueOptionsFor.name)\n .debug('Building queue options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n defaultJobOptions: {\n removeOnComplete: true,\n removeOnFail: true,\n },\n ...this.queueOptions,\n connection: this.redisConnection.duplicateClient(),\n };\n }\n\n /** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */\n protected workerOptionsFor(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): WorkerOptions {\n this.logger\n .for(this.workerOptionsFor.name)\n .debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n ...this.workerOptions,\n connection: this.redisConnection.duplicateClient(),\n concurrency: this.numberOfWorker,\n lockDuration: this.lockDuration,\n };\n }\n\n /** `bullmq` is an optional peer: loaded when a queue or worker is built, not when this module is. */\n private loadBullMQ(): typeof import('bullmq') {\n return (\n this.bullmqModule ?? ModuleUtility.loadSync<typeof import('bullmq')>({ module: 'bullmq' })\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildQueue(opts: { queueName: string }): Queue<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Queue<TQueueElement, TQueueResult>(\n opts.queueName,\n this.queueOptionsFor(opts),\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildWorker(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): Worker<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Worker<TQueueElement, TQueueResult>(\n opts.queueName,\n opts.processor,\n this.workerOptionsFor(opts),\n );\n }\n\n configureWorker() {\n if (!this.queueName) {\n this.logger\n .for(this.configureWorker.name)\n .error('Invalid worker name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.worker = this.buildWorker({\n queueName,\n processor: async (job) => {\n if (this.onWorkerData) {\n const result = await this.onWorkerData(job);\n return result;\n }\n\n const { id, name, data } = job;\n this.logger\n .for('onWorkerData')\n .info(\n 'queue: %s | id: %s | name: %s | data: %j | ID: %s',\n this.queueName,\n id,\n name,\n data,\n this.identifier,\n );\n\n return undefined as TQueueResult;\n },\n });\n\n this.worker.on('completed', (job, result) => {\n invokeHook({\n logger: this.logger,\n scope: 'worker-completed',\n execution: () => this.onWorkerDataCompleted?.(job, result),\n });\n });\n\n this.worker.on('failed', (job, reason) => {\n invokeHook({\n logger: this.logger,\n scope: 'worker-failed',\n execution: () => this.onWorkerDataFail?.(job, reason),\n });\n });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.worker.on('error', (error) => {\n this.logger\n .for('worker-error')\n .error(\n 'queue: %s | Worker error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n configure() {\n if (!this.role) {\n this.logger\n .for(this.configure.name)\n .error(\n 'Invalid client role to configure | Valid roles: [queue|worker] | ID: %s',\n this.identifier,\n );\n return;\n }\n\n switch (this.role) {\n case 'queue': {\n this.configureQueue();\n break;\n }\n case 'worker': {\n this.configureWorker();\n break;\n }\n }\n }\n\n async close() {\n const failures: string[] = [];\n\n // Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.\n try {\n await this.worker?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);\n failures.push(toError(error).message);\n }\n\n try {\n await this.queue?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);\n failures.push(toError(error).message);\n }\n\n if (failures.length) {\n throw getError({\n message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,\n });\n }\n\n this.logger\n .for(this.close.name)\n .info('BullMQ helper closed successfully | ID: %s', this.identifier);\n }\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAuB,MAAM,WAAW,CAAC;AA2B7D,MAAM,OAAO,YAAsD,SAAQ,UAAU;IA0BnF,YAAY,OAAoD;QAC9D,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAnB5D,mBAAc,GAAG,CAAC,CAAC;QACnB,iBAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAmBtC,MAAM,EACJ,SAAS,EACT,eAAe,EACf,IAAI,EACJ,cAAc,GAAG,CAAC,EAClB,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAC7B,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,MAAM,GACP,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;QAE3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;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6CAA6C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;aACvG,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;aACpB,IAAI,CAAC,4CAA4C,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { type IRedisHelper } from '@/modules/redis';\nimport { ErrorUtility } from '@/utilities/error.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';\nimport { HookUtility, type TBullQueueRole } from '../common';\n\nexport interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {\n queueName: string;\n identifier: string;\n role: TBullQueueRole;\n redisConnection: IRedisHelper;\n\n /** `bullmq` itself, for a `bun build --compile` binary that has no `node_modules` to load it from. Omitted, it is loaded when a queue or worker is built. */\n module?: typeof import('bullmq');\n\n numberOfWorker?: number;\n lockDuration?: number;\n\n /** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */\n queueOptions?: Omit<QueueOptions, 'connection'>;\n /** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */\n workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: any) => Promise<void>;\n onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n}\n\nexport class BullMQHelper<TQueueElement = any, TQueueResult = any> extends BaseHelper {\n protected queueName: string;\n protected role: TBullQueueRole;\n protected redisConnection: IRedisHelper;\n\n queue: Queue<TQueueElement, TQueueResult>;\n worker: Worker<TQueueElement, TQueueResult>;\n\n protected numberOfWorker = 1;\n protected lockDuration = 90 * 60 * 1000;\n\n protected queueOptions?: Omit<QueueOptions, 'connection'>;\n protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;\n\n protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<any>;\n protected onWorkerDataCompleted?: (\n job: Job<TQueueElement, TQueueResult>,\n result: any,\n ) => Promise<void>;\n protected onWorkerDataFail?: (\n job: Job<TQueueElement, TQueueResult> | undefined,\n error: Error,\n ) => Promise<void>;\n\n private readonly bullmqModule?: typeof import('bullmq');\n\n constructor(options: IBullMQOptions<TQueueElement, TQueueResult>) {\n super({ scope: BullMQHelper.name, identifier: options.identifier });\n const {\n queueName,\n redisConnection,\n role,\n numberOfWorker = 1,\n lockDuration = 90 * 60 * 1000,\n queueOptions,\n workerOptions,\n onWorkerData,\n onWorkerDataCompleted,\n onWorkerDataFail,\n module,\n } = options;\n\n this.bullmqModule = module;\n\n this.queueName = queueName;\n this.role = role;\n this.redisConnection = redisConnection;\n\n this.numberOfWorker = numberOfWorker;\n this.lockDuration = lockDuration;\n\n this.queueOptions = queueOptions;\n this.workerOptions = workerOptions;\n\n this.onWorkerData = onWorkerData;\n this.onWorkerDataCompleted = onWorkerDataCompleted;\n this.onWorkerDataFail = onWorkerDataFail;\n\n this.configure();\n }\n\n static newInstance<T = any, R = any>(opts: IBullMQOptions<T, R>) {\n return new BullMQHelper<T, R>(opts);\n }\n\n /** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */\n protected isClusterClient(): boolean {\n const client = Object(this.redisConnection.getClient());\n\n if (Reflect.get(client, 'isCluster') === true) {\n return true;\n }\n\n return typeof Reflect.get(client, 'nodes') === 'function';\n }\n\n protected resolveQueueName(): string {\n if (this.isClusterClient() && !this.queueName.startsWith('{')) {\n return `{${this.queueName}}`;\n }\n\n return this.queueName;\n }\n\n configureQueue() {\n if (!this.queueName) {\n this.logger\n .for(this.configureQueue.name)\n .error('Invalid queue name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.queue = this.buildQueue({ queueName });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.queue.on('error', (error) => {\n this.logger\n .for('queue-error')\n .error(\n 'queue: %s | Queue error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n /** Full `Queue` options: framework defaults, then `this.queueOptions`, then the connection the helper owns - in that precedence order. */\n protected queueOptionsFor(opts: { queueName: string }): QueueOptions {\n this.logger\n .for(this.queueOptionsFor.name)\n .debug('Building queue options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n defaultJobOptions: {\n removeOnComplete: true,\n removeOnFail: true,\n },\n ...this.queueOptions,\n connection: this.redisConnection.duplicateClient(),\n };\n }\n\n /** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */\n protected workerOptionsFor(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): WorkerOptions {\n this.logger\n .for(this.workerOptionsFor.name)\n .debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);\n\n return {\n ...this.workerOptions,\n connection: this.redisConnection.duplicateClient(),\n concurrency: this.numberOfWorker,\n lockDuration: this.lockDuration,\n };\n }\n\n /** `bullmq` is an optional peer: loaded when a queue or worker is built, not when this module is. */\n private loadBullMQ(): typeof import('bullmq') {\n return (\n this.bullmqModule ?? ModuleUtility.loadSync<typeof import('bullmq')>({ module: 'bullmq' })\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildQueue(opts: { queueName: string }): Queue<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Queue<TQueueElement, TQueueResult>(\n opts.queueName,\n this.queueOptionsFor(opts),\n );\n }\n\n /** Client factory seam - overridden in tests to run the helper without Redis. */\n protected buildWorker(opts: {\n queueName: string;\n processor: Processor<TQueueElement, TQueueResult>;\n }): Worker<TQueueElement, TQueueResult> {\n const bullmq = this.loadBullMQ();\n return new bullmq.Worker<TQueueElement, TQueueResult>(\n opts.queueName,\n opts.processor,\n this.workerOptionsFor(opts),\n );\n }\n\n configureWorker() {\n if (!this.queueName) {\n this.logger\n .for(this.configureWorker.name)\n .error('Invalid worker name | ID: %s', this.identifier);\n return;\n }\n\n const queueName = this.resolveQueueName();\n this.worker = this.buildWorker({\n queueName,\n processor: async (job) => {\n if (this.onWorkerData) {\n const result = await this.onWorkerData(job);\n return result;\n }\n\n const { id, name, data } = job;\n this.logger\n .for('onWorkerData')\n .info(\n 'queue: %s | id: %s | name: %s | data: %j | ID: %s',\n this.queueName,\n id,\n name,\n data,\n this.identifier,\n );\n\n return undefined as TQueueResult;\n },\n });\n\n this.worker.on('completed', (job, result) => {\n HookUtility.invoke({\n logger: this.logger,\n scope: 'worker-completed',\n execution: () => this.onWorkerDataCompleted?.(job, result),\n });\n });\n\n this.worker.on('failed', (job, reason) => {\n HookUtility.invoke({\n logger: this.logger,\n scope: 'worker-failed',\n execution: () => this.onWorkerDataFail?.(job, reason),\n });\n });\n\n // An 'error' event without a listener is re-thrown by EventEmitter - a Redis hiccup would take the whole process down.\n this.worker.on('error', (error) => {\n this.logger\n .for('worker-error')\n .error(\n 'queue: %s | Worker error! Error: %s | ID: %s',\n this.queueName,\n error,\n this.identifier,\n );\n });\n }\n\n configure() {\n if (!this.role) {\n this.logger\n .for(this.configure.name)\n .error(\n 'Invalid client role to configure | Valid roles: [queue|worker] | ID: %s',\n this.identifier,\n );\n return;\n }\n\n switch (this.role) {\n case 'queue': {\n this.configureQueue();\n break;\n }\n case 'worker': {\n this.configureWorker();\n break;\n }\n }\n }\n\n async close() {\n const failures: string[] = [];\n\n // Both connections must be released even when the first close fails - otherwise a failing worker close silently leaks the queue's Redis connection forever.\n try {\n await this.worker?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ worker: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n\n try {\n await this.queue?.close();\n } catch (error) {\n this.logger\n .for(this.close.name)\n .error('Error closing BullMQ queue: %s | ID: %s', error, this.identifier);\n failures.push(ErrorUtility.toError({ error }).message);\n }\n\n if (failures.length) {\n throw getError({\n message: `[close][${this.identifier}] Failed to close BullMQ helper | Errors: ${failures.join(' | ')}`,\n });\n }\n\n this.logger\n .for(this.close.name)\n .info('BullMQ helper closed successfully | ID: %s', this.identifier);\n }\n}\n"]}
@@ -1,15 +1,17 @@
1
1
  import { type ValueOrPromise } from '../../../common/types/index.js';
2
2
  import type { ILogger } from '../../logger/index.js';
3
- /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */
4
- export declare const invokeHook: (opts: {
5
- logger: ILogger;
6
- scope: string;
7
- execution: () => ValueOrPromise<unknown>;
8
- }) => void;
9
- /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */
10
- export declare const awaitHook: (opts: {
11
- logger: ILogger;
12
- scope: string;
13
- execution: () => ValueOrPromise<unknown>;
14
- }) => Promise<void>;
3
+ export declare class HookUtility {
4
+ /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */
5
+ static invoke(opts: {
6
+ logger: ILogger;
7
+ scope: string;
8
+ execution: () => ValueOrPromise<unknown>;
9
+ }): void;
10
+ /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */
11
+ static execute(opts: {
12
+ logger: ILogger;
13
+ scope: string;
14
+ execution: () => ValueOrPromise<unknown>;
15
+ }): Promise<void>;
16
+ }
15
17
  //# sourceMappingURL=hook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,2PAA2P;AAC3P,eAAO,MAAM,UAAU,GAAI,MAAM;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;CAC1C,KAAG,IAQH,CAAC;AAEF,oHAAoH;AACpH,eAAO,MAAM,SAAS,GAAU,MAAM;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;CAC1C,KAAG,OAAO,CAAC,IAAI,CAQf,CAAC"}
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,qBAAa,WAAW;IACtB,0QAA0Q;IAC1Q,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAClB,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;KAC1C,GAAG,IAAI;IAUR,oHAAoH;WACvG,OAAO,CAAC,IAAI,EAAE;QACzB,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;KAC1C,GAAG,OAAO,CAAC,IAAI,CAAC;CASlB"}
@@ -1,22 +1,24 @@
1
- import { voidExecution } from '../../../utilities/promise.utility.js';
2
- /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */
3
- export const invokeHook = (opts) => {
4
- const { logger, scope, execution } = opts;
5
- try {
6
- voidExecution({ logger, scope, execution: execution() });
1
+ import { PromiseUtility } from '../../../utilities/promise.utility.js';
2
+ export class HookUtility {
3
+ /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */
4
+ static invoke(opts) {
5
+ const { logger, scope, execution } = opts;
6
+ try {
7
+ PromiseUtility.voidExecution({ logger, scope, execution: execution() });
8
+ }
9
+ catch (error) {
10
+ logger.for(scope).error('Hook execution FAILED | Error: %s', error);
11
+ }
7
12
  }
8
- catch (error) {
9
- logger.for(scope).error('Hook execution FAILED | Error: %s', error);
13
+ /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */
14
+ static async execute(opts) {
15
+ const { logger, scope, execution } = opts;
16
+ try {
17
+ await execution();
18
+ }
19
+ catch (error) {
20
+ logger.for(scope).error('Hook execution FAILED | Error: %s', error);
21
+ }
10
22
  }
11
- };
12
- /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */
13
- export const awaitHook = async (opts) => {
14
- const { logger, scope, execution } = opts;
15
- try {
16
- await execution();
17
- }
18
- catch (error) {
19
- logger.for(scope).error('Hook execution FAILED | Error: %s', error);
20
- }
21
- };
23
+ }
22
24
  //# sourceMappingURL=hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/hook.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,2PAA2P;AAC3P,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAI1B,EAAQ,EAAE;IACT,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE1C,IAAI,CAAC;QACH,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;AACH,CAAC,CAAC;AAEF,oHAAoH;AACpH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,IAI/B,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE1C,IAAI,CAAC;QACH,MAAM,SAAS,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport type { ILogger } from '@/modules/logger';\nimport { voidExecution } from '@/utilities/promise.utility';\n\n/** Fire-and-forget a hook from inside an event listener. Takes a thunk because `voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */\nexport const invokeHook = (opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n}): void => {\n const { logger, scope, execution } = opts;\n\n try {\n voidExecution({ logger, scope, execution: execution() });\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n};\n\n/** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */\nexport const awaitHook = async (opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n}): Promise<void> => {\n const { logger, scope, execution } = opts;\n\n try {\n await execution();\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n};\n"]}
1
+ {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/hook.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,MAAM,OAAO,WAAW;IACtB,0QAA0Q;IAC1Q,MAAM,CAAC,MAAM,CAAC,IAIb;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,CAAC;YACH,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,oHAAoH;IACpH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAIpB;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,CAAC;YACH,MAAM,SAAS,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport type { ILogger } from '@/modules/logger';\nimport { PromiseUtility } from '@/utilities/promise.utility';\n\nexport class HookUtility {\n /** Fire-and-forget a hook from inside an event listener. Takes a thunk because `PromiseUtility.voidExecution` takes a VALUE - a synchronous throw would escape the guard and, inside an emitter callback, take the process down. Rejections still route to the logger. */\n static invoke(opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n }): void {\n const { logger, scope, execution } = opts;\n\n try {\n PromiseUtility.voidExecution({ logger, scope, execution: execution() });\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n /** Await a user-supplied hook, absorbing sync throws and rejections without breaking the caller's state machine. */\n static async execute(opts: {\n logger: ILogger;\n scope: string;\n execution: () => ValueOrPromise<unknown>;\n }): Promise<void> {\n const { logger, scope, execution } = opts;\n\n try {\n await execution();\n } catch (error) {\n logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
1
  export * from './constants.js';
2
2
  export * from './hook.js';
3
- export * from './types.js';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
@@ -1,4 +1,3 @@
1
1
  export * from './constants.js';
2
2
  export * from './hook.js';
3
- export * from './types.js';
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC","sourcesContent":["export * from './constants';\nexport * from './hook';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC","sourcesContent":["export * from './constants';\nexport * from './hook';\n"]}
@@ -1,6 +1,6 @@
1
- import { isEmpty } from '@venizia/ignis-inversion';
1
+ import { ObjectUtility } from '@venizia/ignis-inversion';
2
2
  import { BaseHelper } from '../../../base.js';
3
- import { awaitHook, invokeHook } from '../../common/index.js';
3
+ import { HookUtility } from '../../common/index.js';
4
4
  import { QueueStatuses, } from './common/index.js';
5
5
  export class SequentialQueueHelper extends BaseHelper {
6
6
  constructor(opts) {
@@ -26,7 +26,7 @@ export class SequentialQueueHelper extends BaseHelper {
26
26
  /** Announce a state transition, awaiting the hook but never letting it break the caller. */
27
27
  notifyStateChange(opts) {
28
28
  const { scope, from } = opts;
29
- return awaitHook({
29
+ return HookUtility.execute({
30
30
  logger: this.logger,
31
31
  scope,
32
32
  execution: () => this.onStateChange?.({ identifier: this.identifier, from, to: this.state }),
@@ -35,7 +35,7 @@ export class SequentialQueueHelper extends BaseHelper {
35
35
  /** Announce a state transition from a synchronous caller (lock/unlock/settle) - fire-and-forget. */
36
36
  notifyStateChangeAsync(opts) {
37
37
  const { scope, from } = opts;
38
- invokeHook({
38
+ HookUtility.invoke({
39
39
  logger: this.logger,
40
40
  scope,
41
41
  execution: () => this.onStateChange?.({ identifier: this.identifier, from, to: this.state }),
@@ -62,7 +62,7 @@ export class SequentialQueueHelper extends BaseHelper {
62
62
  this.getElementAt(0).isLocked = true;
63
63
  this.processingEvents.add(this.getElementAt(0));
64
64
  // A failing handler must never leave the queue PROCESSING forever: the element would stay LOCKED at the head, nextMessage() would refuse every dispatch and storage would grow without bound. The handler owns its retry policy - here the element is logged, dropped, and the queue moves on.
65
- await awaitHook({
65
+ await HookUtility.execute({
66
66
  logger: this.logger,
67
67
  scope: this.handleMessage.name,
68
68
  execution: () => this.onMessage?.({ identifier: this.identifier, queueElement: this.getElementAt(0) }),
@@ -122,7 +122,7 @@ export class SequentialQueueHelper extends BaseHelper {
122
122
  const queueElement = { isLocked: false, payload };
123
123
  this.storage.push(queueElement);
124
124
  this.totalEvent++;
125
- await awaitHook({
125
+ await HookUtility.execute({
126
126
  logger: this.logger,
127
127
  scope: this.enqueue.name,
128
128
  execution: () => this.onDataEnqueue?.({ identifier: this.identifier, queueElement }),
@@ -133,8 +133,8 @@ export class SequentialQueueHelper extends BaseHelper {
133
133
  }
134
134
  dequeue() {
135
135
  const value = this.storage.shift();
136
- if (value && !isEmpty({ value: value })) {
137
- invokeHook({
136
+ if (value && !ObjectUtility.isEmpty({ value: value })) {
137
+ HookUtility.invoke({
138
138
  logger: this.logger,
139
139
  scope: this.dequeue.name,
140
140
  execution: () => this.onDataDequeue?.({ identifier: this.identifier, queueElement: value }),
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/internal/sequential/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAEL,aAAa,GAGd,MAAM,UAAU,CAAC;AAElB,MAAM,OAAO,qBAAuC,SAAQ,UAAU;IA+BpE,YAAY,IAA8D;QACxE,KAAK,CAAC;YACJ,KAAK,EAAE,GAAG,qBAAqB,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YACzD,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QA7BK,iBAAY,GAAY,IAAI,CAAC;QAC7B,UAAK,GAAiB,aAAa,CAAC,OAAO,CAAC;QA8BpD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAEzC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YA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AAC,KAAK,CAAC;IACpB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import { isEmpty } from '@venizia/ignis-inversion';\nimport { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { awaitHook, invokeHook } from '../../common';\nimport {\n type IQueueCallback,\n QueueStatuses,\n type TQueueElement,\n type TQueueStatus,\n} from './common';\n\nexport class SequentialQueueHelper<TElementPayload> extends BaseHelper {\n public storage: Array<TQueueElement<TElementPayload>>;\n protected processingEvents: Set<TQueueElement<TElementPayload>>;\n protected generator: Generator;\n\n protected totalEvent: number;\n protected autoDispatch: boolean = true;\n protected state: TQueueStatus = QueueStatuses.WAITING;\n protected isSettleRequested: boolean;\n\n private onMessage?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n\n private onDataEnqueue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n\n private onDataDequeue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n\n private onStateChange?: (opts: {\n identifier: string;\n from: TQueueStatus;\n to: TQueueStatus;\n }) => ValueOrPromise<void>;\n\n constructor(opts: IQueueCallback<TElementPayload> & { identifier: string }) {\n super({\n scope: `${SequentialQueueHelper.name}_${opts.identifier}`,\n identifier: opts.identifier,\n });\n\n this.identifier = opts.identifier;\n this.storage = [];\n this.processingEvents = new Set([]);\n this.generator = this._messageListener();\n\n this.totalEvent = 0;\n this.autoDispatch = opts.autoDispatch ?? true;\n this.state = QueueStatuses.WAITING;\n this.isSettleRequested = false;\n\n this.onMessage = opts.onMessage;\n this.onDataEnqueue = opts.onDataEnqueue;\n this.onDataDequeue = opts.onDataDequeue;\n this.onStateChange = opts.onStateChange;\n }\n\n /** Announce a state transition, awaiting the hook but never letting it break the caller. */\n protected notifyStateChange(opts: { scope: string; from: TQueueStatus }): Promise<void> {\n const { scope, from } = opts;\n\n return awaitHook({\n logger: this.logger,\n scope,\n execution: () => this.onStateChange?.({ identifier: this.identifier, from, to: this.state }),\n });\n }\n\n /** Announce a state transition from a synchronous caller (lock/unlock/settle) - fire-and-forget. */\n protected notifyStateChangeAsync(opts: { scope: string; from: TQueueStatus }): void {\n const { scope, from } = opts;\n\n invokeHook({\n logger: this.logger,\n scope,\n execution: () => this.onStateChange?.({ identifier: this.identifier, from, to: this.state }),\n });\n }\n\n protected async handleMessage() {\n const current = this.getElementAt(0);\n if (!current) {\n this.logger\n .for(this.handleMessage.name)\n .warn('current: %j | Invalid current message to handle!', current);\n return;\n }\n\n const { isLocked, payload } = current;\n if (isLocked) {\n this.logger.for('handle').info('Skip LOCKED message | Payload: %j', payload);\n return;\n }\n\n if (this.state !== QueueStatuses.LOCKED && this.state !== QueueStatuses.SETTLED) {\n const snap = this.state;\n this.state = QueueStatuses.PROCESSING;\n await this.notifyStateChange({ scope: this.handleMessage.name, from: snap });\n }\n\n this.getElementAt(0).isLocked = true;\n\n this.processingEvents.add(this.getElementAt(0));\n\n // A failing handler must never leave the queue PROCESSING forever: the element would stay LOCKED at the head, nextMessage() would refuse every dispatch and storage would grow without bound. The handler owns its retry policy - here the element is logged, dropped, and the queue moves on.\n await awaitHook({\n logger: this.logger,\n scope: this.handleMessage.name,\n execution: () =>\n this.onMessage?.({ identifier: this.identifier, queueElement: this.getElementAt(0) }),\n });\n\n const doneElement = this.dequeue();\n if (doneElement) {\n this.processingEvents.delete(doneElement);\n }\n\n if (this.state !== QueueStatuses.LOCKED && this.state !== QueueStatuses.SETTLED) {\n const snap = this.state;\n this.state = QueueStatuses.WAITING;\n await this.notifyStateChange({ scope: this.handleMessage.name, from: snap });\n }\n\n if (!this.storage.length) {\n if (this.isSettleRequested) {\n const snap = this.state;\n this.state = QueueStatuses.SETTLED;\n await this.notifyStateChange({ scope: this.handleMessage.name, from: snap });\n }\n\n return;\n }\n\n this.nextMessage();\n }\n\n private *_messageListener() {\n if (!this.onMessage) {\n this.logger\n .for('_messageListener')\n .warn('Queue has no onMessage listener | Skip initializing message iterator!');\n return;\n }\n\n while (true) {\n yield this.handleMessage();\n }\n }\n\n nextMessage() {\n if (this.state !== QueueStatuses.WAITING) {\n this.logger\n .for(this.nextMessage.name)\n .warn(\n 'SKIP request next message | Invalid queue state to request next message | currentState: %s',\n this.state,\n );\n return;\n }\n\n this.generator.next();\n }\n\n async enqueue(payload: TElementPayload) {\n if (this.isSettleRequested || this.state === QueueStatuses.SETTLED) {\n this.logger\n .for(this.enqueue.name)\n .error(\n 'isSettled: %s | currentState: %s | Queue was SETTLED | No more element acceptable',\n this.isSettleRequested,\n this.state,\n );\n return;\n }\n\n if (!this.storage) {\n this.storage = [];\n }\n\n if (!payload) {\n return;\n }\n\n const queueElement: TQueueElement<TElementPayload> = { isLocked: false, payload };\n this.storage.push(queueElement);\n this.totalEvent++;\n await awaitHook({\n logger: this.logger,\n scope: this.enqueue.name,\n execution: () => this.onDataEnqueue?.({ identifier: this.identifier, queueElement }),\n });\n\n if (this.autoDispatch) {\n this.nextMessage();\n }\n }\n\n dequeue() {\n const value = this.storage.shift();\n\n if (value && !isEmpty({ value: value })) {\n invokeHook({\n logger: this.logger,\n scope: this.dequeue.name,\n execution: () => this.onDataDequeue?.({ identifier: this.identifier, queueElement: value }),\n });\n }\n\n return value;\n }\n\n lock() {\n if (this.state >= QueueStatuses.LOCKED) {\n this.logger\n .for(this.lock.name)\n .error(\n 'isSettled | currentState: %s | Invalid queue state to request lock queue!',\n this.isSettleRequested,\n this.state,\n );\n return;\n }\n\n const snap = this.state;\n this.state = QueueStatuses.LOCKED;\n this.notifyStateChangeAsync({ scope: this.lock.name, from: snap });\n }\n\n unlock(opts: { shouldProcessNextElement?: boolean }) {\n if (this.state > QueueStatuses.LOCKED) {\n this.logger\n .for(this.unlock.name)\n .error(\n 'isSettled | currentState: %s | Invalid queue state to request unlock queue!',\n this.isSettleRequested,\n this.state,\n );\n return;\n }\n\n const { shouldProcessNextElement = true } = opts;\n\n const snap = this.state;\n this.state = QueueStatuses.WAITING;\n this.notifyStateChangeAsync({ scope: this.unlock.name, from: snap });\n\n if (!shouldProcessNextElement) {\n return;\n }\n\n this.nextMessage();\n }\n\n settle() {\n this.isSettleRequested = true;\n\n if (this.state !== QueueStatuses.PROCESSING) {\n const snap = this.state;\n this.state = QueueStatuses.SETTLED;\n this.notifyStateChangeAsync({ scope: this.settle.name, from: snap });\n }\n }\n\n isSettled() {\n return this.state === QueueStatuses.SETTLED && !this.storage.length;\n }\n\n close() {\n this.settle();\n this.generator.return({\n state: this.state,\n totalEvent: this.totalEvent,\n });\n }\n\n getElementAt(position: number) {\n return this.storage[position];\n }\n\n getState() {\n return this.state;\n }\n\n getTotalEvent() {\n return this.totalEvent;\n }\n\n getProcessingEvents() {\n return this.processingEvents;\n }\n}\n"]}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/internal/sequential/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAEL,aAAa,GAGd,MAAM,UAAU,CAAC;AAElB,MAAM,OAAO,qBAAuC,SAAQ,UAAU;IA+BpE,YAAY,IAA8D;QACxE,KAAK,CAAC;YACJ,KAAK,EAAE,GAAG,qBAAqB,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YACzD,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QA7BK,iBAAY,GAAY,IAAI,CAAC;QAC7B,UAAK,GAAiB,aAAa,CAAC,OAAO,CAAC;QA8BpD,IAAI,CAAC,UAAU,GAAG,IAAI,CAA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CAAC,OAAO,CAAC,MAAM,CAAC;IACtE,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,QAAgB;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { HookUtility } from '../../common';\nimport {\n type IQueueCallback,\n QueueStatuses,\n type TQueueElement,\n type TQueueStatus,\n} from './common';\n\nexport class SequentialQueueHelper<TElementPayload> extends BaseHelper {\n public storage: Array<TQueueElement<TElementPayload>>;\n protected processingEvents: Set<TQueueElement<TElementPayload>>;\n protected generator: Generator;\n\n protected totalEvent: number;\n protected autoDispatch: boolean = true;\n protected state: TQueueStatus = QueueStatuses.WAITING;\n protected isSettleRequested: boolean;\n\n private onMessage?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n\n private onDataEnqueue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n\n private onDataDequeue?: (opts: {\n identifier: string;\n queueElement: TQueueElement<TElementPayload>;\n }) => ValueOrPromise<void>;\n\n private onStateChange?: (opts: {\n identifier: string;\n from: TQueueStatus;\n to: TQueueStatus;\n }) => ValueOrPromise<void>;\n\n constructor(opts: IQueueCallback<TElementPayload> & { identifier: string }) {\n super({\n scope: `${SequentialQueueHelper.name}_${opts.identifier}`,\n identifier: opts.identifier,\n });\n\n this.identifier = opts.identifier;\n this.storage = [];\n this.processingEvents = new Set([]);\n this.generator = this._messageListener();\n\n this.totalEvent = 0;\n this.autoDispatch = opts.autoDispatch ?? true;\n this.state = QueueStatuses.WAITING;\n this.isSettleRequested = false;\n\n this.onMessage = opts.onMessage;\n this.onDataEnqueue = opts.onDataEnqueue;\n this.onDataDequeue = opts.onDataDequeue;\n this.onStateChange = opts.onStateChange;\n }\n\n /** Announce a state transition, awaiting the hook but never letting it break the caller. */\n protected notifyStateChange(opts: { scope: string; from: TQueueStatus }): Promise<void> {\n const { scope, from } = opts;\n\n return HookUtility.execute({\n logger: this.logger,\n scope,\n execution: () => this.onStateChange?.({ identifier: this.identifier, from, to: this.state }),\n });\n }\n\n /** Announce a state transition from a synchronous caller (lock/unlock/settle) - fire-and-forget. */\n protected notifyStateChangeAsync(opts: { scope: string; from: TQueueStatus }): void {\n const { scope, from } = opts;\n\n HookUtility.invoke({\n logger: this.logger,\n scope,\n execution: () => this.onStateChange?.({ identifier: this.identifier, from, to: this.state }),\n });\n }\n\n protected async handleMessage() {\n const current = this.getElementAt(0);\n if (!current) {\n this.logger\n .for(this.handleMessage.name)\n .warn('current: %j | Invalid current message to handle!', current);\n return;\n }\n\n const { isLocked, payload } = current;\n if (isLocked) {\n this.logger.for('handle').info('Skip LOCKED message | Payload: %j', payload);\n return;\n }\n\n if (this.state !== QueueStatuses.LOCKED && this.state !== QueueStatuses.SETTLED) {\n const snap = this.state;\n this.state = QueueStatuses.PROCESSING;\n await this.notifyStateChange({ scope: this.handleMessage.name, from: snap });\n }\n\n this.getElementAt(0).isLocked = true;\n\n this.processingEvents.add(this.getElementAt(0));\n\n // A failing handler must never leave the queue PROCESSING forever: the element would stay LOCKED at the head, nextMessage() would refuse every dispatch and storage would grow without bound. The handler owns its retry policy - here the element is logged, dropped, and the queue moves on.\n await HookUtility.execute({\n logger: this.logger,\n scope: this.handleMessage.name,\n execution: () =>\n this.onMessage?.({ identifier: this.identifier, queueElement: this.getElementAt(0) }),\n });\n\n const doneElement = this.dequeue();\n if (doneElement) {\n this.processingEvents.delete(doneElement);\n }\n\n if (this.state !== QueueStatuses.LOCKED && this.state !== QueueStatuses.SETTLED) {\n const snap = this.state;\n this.state = QueueStatuses.WAITING;\n await this.notifyStateChange({ scope: this.handleMessage.name, from: snap });\n }\n\n if (!this.storage.length) {\n if (this.isSettleRequested) {\n const snap = this.state;\n this.state = QueueStatuses.SETTLED;\n await this.notifyStateChange({ scope: this.handleMessage.name, from: snap });\n }\n\n return;\n }\n\n this.nextMessage();\n }\n\n private *_messageListener() {\n if (!this.onMessage) {\n this.logger\n .for('_messageListener')\n .warn('Queue has no onMessage listener | Skip initializing message iterator!');\n return;\n }\n\n while (true) {\n yield this.handleMessage();\n }\n }\n\n nextMessage() {\n if (this.state !== QueueStatuses.WAITING) {\n this.logger\n .for(this.nextMessage.name)\n .warn(\n 'SKIP request next message | Invalid queue state to request next message | currentState: %s',\n this.state,\n );\n return;\n }\n\n this.generator.next();\n }\n\n async enqueue(payload: TElementPayload) {\n if (this.isSettleRequested || this.state === QueueStatuses.SETTLED) {\n this.logger\n .for(this.enqueue.name)\n .error(\n 'isSettled: %s | currentState: %s | Queue was SETTLED | No more element acceptable',\n this.isSettleRequested,\n this.state,\n );\n return;\n }\n\n if (!this.storage) {\n this.storage = [];\n }\n\n if (!payload) {\n return;\n }\n\n const queueElement: TQueueElement<TElementPayload> = { isLocked: false, payload };\n this.storage.push(queueElement);\n this.totalEvent++;\n await HookUtility.execute({\n logger: this.logger,\n scope: this.enqueue.name,\n execution: () => this.onDataEnqueue?.({ identifier: this.identifier, queueElement }),\n });\n\n if (this.autoDispatch) {\n this.nextMessage();\n }\n }\n\n dequeue() {\n const value = this.storage.shift();\n\n if (value && !ObjectUtility.isEmpty({ value: value })) {\n HookUtility.invoke({\n logger: this.logger,\n scope: this.dequeue.name,\n execution: () => this.onDataDequeue?.({ identifier: this.identifier, queueElement: value }),\n });\n }\n\n return value;\n }\n\n lock() {\n if (this.state >= QueueStatuses.LOCKED) {\n this.logger\n .for(this.lock.name)\n .error(\n 'isSettled | currentState: %s | Invalid queue state to request lock queue!',\n this.isSettleRequested,\n this.state,\n );\n return;\n }\n\n const snap = this.state;\n this.state = QueueStatuses.LOCKED;\n this.notifyStateChangeAsync({ scope: this.lock.name, from: snap });\n }\n\n unlock(opts: { shouldProcessNextElement?: boolean }) {\n if (this.state > QueueStatuses.LOCKED) {\n this.logger\n .for(this.unlock.name)\n .error(\n 'isSettled | currentState: %s | Invalid queue state to request unlock queue!',\n this.isSettleRequested,\n this.state,\n );\n return;\n }\n\n const { shouldProcessNextElement = true } = opts;\n\n const snap = this.state;\n this.state = QueueStatuses.WAITING;\n this.notifyStateChangeAsync({ scope: this.unlock.name, from: snap });\n\n if (!shouldProcessNextElement) {\n return;\n }\n\n this.nextMessage();\n }\n\n settle() {\n this.isSettleRequested = true;\n\n if (this.state !== QueueStatuses.PROCESSING) {\n const snap = this.state;\n this.state = QueueStatuses.SETTLED;\n this.notifyStateChangeAsync({ scope: this.settle.name, from: snap });\n }\n }\n\n isSettled() {\n return this.state === QueueStatuses.SETTLED && !this.storage.length;\n }\n\n close() {\n this.settle();\n this.generator.return({\n state: this.state,\n totalEvent: this.totalEvent,\n });\n }\n\n getElementAt(position: number) {\n return this.storage[position];\n }\n\n getState() {\n return this.state;\n }\n\n getTotalEvent() {\n return this.totalEvent;\n }\n\n getProcessingEvents() {\n return this.processingEvents;\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { getError } from '../../error/index.js';
2
2
  import { BaseHelper } from '../../base.js';
3
- import { invokeHook } from '../common/index.js';
3
+ import { HookUtility } from '../common/index.js';
4
4
  import { KafkaClientEvents, KafkaDefaults, KafkaHealthStatuses, } from './common/constants.js';
5
5
  /**
6
6
  * Shared health tracking and broker event wiring for all Kafka helpers (producer, consumer, admin); `TClient` is the platformatic client type, passed by subclasses via `super({ client })`.
@@ -36,7 +36,7 @@ export class BaseKafkaHelper extends BaseHelper {
36
36
  this.connectedBrokers.add(brokerKey);
37
37
  this.healthStatus = KafkaHealthStatuses.CONNECTED;
38
38
  this.logger.info('[configureBrokerConnect] Broker CONNECTED | Host: %s | Port: %d | Connected: %d', payload.broker.host, payload.broker.port, this.connectedBrokers.size);
39
- invokeHook({
39
+ HookUtility.invoke({
40
40
  logger: this.logger,
41
41
  scope: 'configureBrokerConnect',
42
42
  execution: () => this.onBrokerConnect?.({ broker: payload.broker }),
@@ -51,7 +51,7 @@ export class BaseKafkaHelper extends BaseHelper {
51
51
  this.healthStatus = KafkaHealthStatuses.DISCONNECTED;
52
52
  }
53
53
  this.logger.warn('[configureBrokerDisconnect] Broker DISCONNECTED | Host: %s | Port: %d | Remaining: %d', payload.broker.host, payload.broker.port, this.connectedBrokers.size);
54
- invokeHook({
54
+ HookUtility.invoke({
55
55
  logger: this.logger,
56
56
  scope: 'configureBrokerDisconnect',
57
57
  execution: () => this.onBrokerDisconnect?.({ broker: payload.broker }),
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/modules/queue/kafka/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAY5B;;;;GAIG;AACH,MAAM,OAAgB,eAAmD,SAAQ,UAAU;IAYzF,YAAY,IAAgC;QAC1C,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QATlD,iBAAY,GAAuB,mBAAmB,CAAC,OA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,uBAAuB;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAiB,CAAC;QAEtC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAoB,EAAE,EAAE;gBAC1C,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,CAAC,KAAK,CAAC,CAAC;oBACd,OAAO;gBACT,CAAC;gBAED,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAES,KAAK,CAAC,mBAAmB;QACjC,IAAI,aAAa,GAA0B,IAAI,CAAC;QAEhD,IAAI,CAAC;YACH,2KAA2K;YAC3K,MAAM,OAAO,CAAC,IAAI,CAAC;gBACjB,IAAI,CAAC,WAAW,EAAE;gBAClB,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;oBAC9B,aAAa,GAAG,UAAU,CACxB,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,0CAA0C,EAAE,CAAC,CAAC,EAC/E,IAAI,CAAC,eAAe,CACrB,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;gBAC3B,YAAY,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { AnyType } from '@/common';\nimport { getError } from '@/modules/error';\nimport { BaseHelper } from '@/modules/base';\nimport type { Base, BaseOptions, ConnectionPoolEventPayload } from '@platformatic/kafka';\nimport { invokeHook } from '../common';\nimport {\n KafkaClientEvents,\n KafkaDefaults,\n KafkaHealthStatuses,\n type TKafkaHealthStatus,\n} from './common/constants';\nimport type { TKafkaBrokerEventCallback } from './common/types';\n\nexport interface IKafkaBaseOptions<TClient extends Base<BaseOptions>> {\n scope: string;\n identifier: string;\n client: TClient;\n shutdownTimeout?: number;\n onBrokerConnect?: TKafkaBrokerEventCallback;\n onBrokerDisconnect?: TKafkaBrokerEventCallback;\n}\n\n/**\n * Shared health tracking and broker event wiring for all Kafka helpers (producer, consumer, admin); `TClient` is the platformatic client type, passed by subclasses via `super({ client })`.\n *\n * Every member below is `protected`, not `private`, so a producer, consumer, or admin helper can extend this class instead of forking it. That visibility is not a stable contract between minor versions.\n */\nexport abstract class BaseKafkaHelper<TClient extends Base<BaseOptions>> extends BaseHelper {\n protected client: TClient;\n protected readonly shutdownTimeout: number;\n\n protected healthStatus: TKafkaHealthStatus = KafkaHealthStatuses.UNKNOWN;\n\n /** Per-broker connection state. Key = \"host:port\" */\n protected readonly connectedBrokers = new Set<string>();\n\n protected readonly onBrokerConnect?: TKafkaBrokerEventCallback;\n protected readonly onBrokerDisconnect?: TKafkaBrokerEventCallback;\n\n constructor(opts: IKafkaBaseOptions<TClient>) {\n super({ scope: opts.scope, identifier: opts.identifier });\n this.client = opts.client;\n this.shutdownTimeout = opts.shutdownTimeout ?? KafkaDefaults.SHUTDOWN_TIMEOUT;\n this.onBrokerConnect = opts.onBrokerConnect;\n this.onBrokerDisconnect = opts.onBrokerDisconnect;\n }\n\n isHealthy(): boolean {\n return this.connectedBrokers.size > 0;\n }\n\n isReady(): boolean {\n return this.healthStatus === KafkaHealthStatuses.CONNECTED;\n }\n\n getHealthStatus(): TKafkaHealthStatus {\n return this.healthStatus;\n }\n\n getConnectedBrokerCount(): number {\n return this.connectedBrokers.size;\n }\n\n protected configureBrokerConnect() {\n this.client.on(KafkaClientEvents.BROKER_CONNECT, (payload: ConnectionPoolEventPayload) => {\n const brokerKey = `${payload.broker.host}:${payload.broker.port}`;\n this.connectedBrokers.add(brokerKey);\n this.healthStatus = KafkaHealthStatuses.CONNECTED;\n\n this.logger.info(\n '[configureBrokerConnect] Broker CONNECTED | Host: %s | Port: %d | Connected: %d',\n payload.broker.host,\n payload.broker.port,\n this.connectedBrokers.size,\n );\n\n invokeHook({\n logger: this.logger,\n scope: 'configureBrokerConnect',\n execution: () => this.onBrokerConnect?.({ broker: payload.broker }),\n });\n });\n }\n\n protected configureBrokerDisconnect() {\n this.client.on(KafkaClientEvents.BROKER_DISCONNECT, (payload: ConnectionPoolEventPayload) => {\n const brokerKey = `${payload.broker.host}:${payload.broker.port}`;\n this.connectedBrokers.delete(brokerKey);\n\n if (this.connectedBrokers.size === 0) {\n this.healthStatus = KafkaHealthStatuses.DISCONNECTED;\n }\n\n this.logger.warn(\n '[configureBrokerDisconnect] Broker DISCONNECTED | Host: %s | Port: %d | Remaining: %d',\n payload.broker.host,\n payload.broker.port,\n this.connectedBrokers.size,\n );\n\n invokeHook({\n logger: this.logger,\n scope: 'configureBrokerDisconnect',\n execution: () => this.onBrokerDisconnect?.({ broker: payload.broker }),\n });\n });\n }\n\n protected configureBrokerFailed() {\n this.client.on(KafkaClientEvents.BROKER_FAILED, (payload: ConnectionPoolEventPayload) => {\n const brokerKey = `${payload.broker.host}:${payload.broker.port}`;\n this.connectedBrokers.delete(brokerKey);\n\n if (this.connectedBrokers.size === 0) {\n this.healthStatus = KafkaHealthStatuses.DISCONNECTED;\n }\n\n this.logger.error(\n '[configureBrokerFailed] Broker connection FAILED | Host: %s | Port: %d | Remaining: %d',\n payload.broker.host,\n payload.broker.port,\n this.connectedBrokers.size,\n );\n });\n }\n\n protected configureBrokerEvents(): void {\n this.configureBrokerConnect();\n this.configureBrokerDisconnect();\n this.configureBrokerFailed();\n }\n\n protected unconfigureBrokerEvents(): void {\n this.client.removeAllListeners(KafkaClientEvents.BROKER_CONNECT);\n this.client.removeAllListeners(KafkaClientEvents.BROKER_DISCONNECT);\n this.client.removeAllListeners(KafkaClientEvents.BROKER_FAILED);\n }\n\n protected swapClient(newClient: TClient): void {\n this.unconfigureBrokerEvents();\n this.client = newClient;\n this.resetHealthState();\n this.configureBrokerEvents();\n }\n\n protected resetHealthState(): void {\n this.connectedBrokers.clear();\n this.healthStatus = KafkaHealthStatuses.DISCONNECTED;\n }\n\n protected closeClient(): Promise<void> {\n return this.client.close();\n }\n\n /** Force-close through the callback overload: only Producer and Consumer expose `close(force, cb)`, and the `Base` type this class is generic over declares no such overload - hence the cast. */\n protected closeClientWithCallback(): Promise<void> {\n const client = this.client as AnyType;\n\n return new Promise<void>((resolve, reject) => {\n client.close(true, (error?: Error | null) => {\n if (error) {\n reject(error);\n return;\n }\n\n resolve();\n });\n });\n }\n\n protected async gracefulCloseClient(): Promise<void> {\n let timeoutHandle: NodeJS.Timeout | null = null;\n\n try {\n // The timer MUST be cleared once close() wins: an armed shutdownTimeout timer keeps the event loop alive long after a successful shutdown, so the process refuses to exit.\n await Promise.race([\n this.closeClient(),\n new Promise<void>((_, reject) => {\n timeoutHandle = setTimeout(\n () => reject(getError({ message: '[gracefulCloseClient] Shutdown timed out' })),\n this.shutdownTimeout,\n );\n }),\n ]);\n } finally {\n if (timeoutHandle !== null) {\n clearTimeout(timeoutHandle);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/modules/queue/kafka/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAY5B;;;;GAIG;AACH,MAAM,OAAgB,eAAmD,SAAQ,UAAU;IAYzF,YAAY,IAAgC;QAC1C,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QATlD,iBAAY,GAAuB,mBAAmB,CAAC,OAAO,CAAC;QAEzE,qDAAqD;QAClC,qBAAgB,GAAG,IAAI,GAAG,EAAU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AAI,CAAC,MAAiB,CAAC;QAEtC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAoB,EAAE,EAAE;gBAC1C,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,CAAC,KAAK,CAAC,CAAC;oBACd,OAAO;gBACT,CAAC;gBAED,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAES,KAAK,CAAC,mBAAmB;QACjC,IAAI,aAAa,GAA0B,IAAI,CAAC;QAEhD,IAAI,CAAC;YACH,2KAA2K;YAC3K,MAAM,OAAO,CAAC,IAAI,CAAC;gBACjB,IAAI,CAAC,WAAW,EAAE;gBAClB,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;oBAC9B,aAAa,GAAG,UAAU,CACxB,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,0CAA0C,EAAE,CAAC,CAAC,EAC/E,IAAI,CAAC,eAAe,CACrB,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;gBAC3B,YAAY,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { AnyType } from '@/common';\nimport { getError } from '@/modules/error';\nimport { BaseHelper } from '@/modules/base';\nimport type { Base, BaseOptions, ConnectionPoolEventPayload } from '@platformatic/kafka';\nimport { HookUtility } from '../common';\nimport {\n KafkaClientEvents,\n KafkaDefaults,\n KafkaHealthStatuses,\n type TKafkaHealthStatus,\n} from './common/constants';\nimport type { TKafkaBrokerEventCallback } from './common/types';\n\nexport interface IKafkaBaseOptions<TClient extends Base<BaseOptions>> {\n scope: string;\n identifier: string;\n client: TClient;\n shutdownTimeout?: number;\n onBrokerConnect?: TKafkaBrokerEventCallback;\n onBrokerDisconnect?: TKafkaBrokerEventCallback;\n}\n\n/**\n * Shared health tracking and broker event wiring for all Kafka helpers (producer, consumer, admin); `TClient` is the platformatic client type, passed by subclasses via `super({ client })`.\n *\n * Every member below is `protected`, not `private`, so a producer, consumer, or admin helper can extend this class instead of forking it. That visibility is not a stable contract between minor versions.\n */\nexport abstract class BaseKafkaHelper<TClient extends Base<BaseOptions>> extends BaseHelper {\n protected client: TClient;\n protected readonly shutdownTimeout: number;\n\n protected healthStatus: TKafkaHealthStatus = KafkaHealthStatuses.UNKNOWN;\n\n /** Per-broker connection state. Key = \"host:port\" */\n protected readonly connectedBrokers = new Set<string>();\n\n protected readonly onBrokerConnect?: TKafkaBrokerEventCallback;\n protected readonly onBrokerDisconnect?: TKafkaBrokerEventCallback;\n\n constructor(opts: IKafkaBaseOptions<TClient>) {\n super({ scope: opts.scope, identifier: opts.identifier });\n this.client = opts.client;\n this.shutdownTimeout = opts.shutdownTimeout ?? KafkaDefaults.SHUTDOWN_TIMEOUT;\n this.onBrokerConnect = opts.onBrokerConnect;\n this.onBrokerDisconnect = opts.onBrokerDisconnect;\n }\n\n isHealthy(): boolean {\n return this.connectedBrokers.size > 0;\n }\n\n isReady(): boolean {\n return this.healthStatus === KafkaHealthStatuses.CONNECTED;\n }\n\n getHealthStatus(): TKafkaHealthStatus {\n return this.healthStatus;\n }\n\n getConnectedBrokerCount(): number {\n return this.connectedBrokers.size;\n }\n\n protected configureBrokerConnect() {\n this.client.on(KafkaClientEvents.BROKER_CONNECT, (payload: ConnectionPoolEventPayload) => {\n const brokerKey = `${payload.broker.host}:${payload.broker.port}`;\n this.connectedBrokers.add(brokerKey);\n this.healthStatus = KafkaHealthStatuses.CONNECTED;\n\n this.logger.info(\n '[configureBrokerConnect] Broker CONNECTED | Host: %s | Port: %d | Connected: %d',\n payload.broker.host,\n payload.broker.port,\n this.connectedBrokers.size,\n );\n\n HookUtility.invoke({\n logger: this.logger,\n scope: 'configureBrokerConnect',\n execution: () => this.onBrokerConnect?.({ broker: payload.broker }),\n });\n });\n }\n\n protected configureBrokerDisconnect() {\n this.client.on(KafkaClientEvents.BROKER_DISCONNECT, (payload: ConnectionPoolEventPayload) => {\n const brokerKey = `${payload.broker.host}:${payload.broker.port}`;\n this.connectedBrokers.delete(brokerKey);\n\n if (this.connectedBrokers.size === 0) {\n this.healthStatus = KafkaHealthStatuses.DISCONNECTED;\n }\n\n this.logger.warn(\n '[configureBrokerDisconnect] Broker DISCONNECTED | Host: %s | Port: %d | Remaining: %d',\n payload.broker.host,\n payload.broker.port,\n this.connectedBrokers.size,\n );\n\n HookUtility.invoke({\n logger: this.logger,\n scope: 'configureBrokerDisconnect',\n execution: () => this.onBrokerDisconnect?.({ broker: payload.broker }),\n });\n });\n }\n\n protected configureBrokerFailed() {\n this.client.on(KafkaClientEvents.BROKER_FAILED, (payload: ConnectionPoolEventPayload) => {\n const brokerKey = `${payload.broker.host}:${payload.broker.port}`;\n this.connectedBrokers.delete(brokerKey);\n\n if (this.connectedBrokers.size === 0) {\n this.healthStatus = KafkaHealthStatuses.DISCONNECTED;\n }\n\n this.logger.error(\n '[configureBrokerFailed] Broker connection FAILED | Host: %s | Port: %d | Remaining: %d',\n payload.broker.host,\n payload.broker.port,\n this.connectedBrokers.size,\n );\n });\n }\n\n protected configureBrokerEvents(): void {\n this.configureBrokerConnect();\n this.configureBrokerDisconnect();\n this.configureBrokerFailed();\n }\n\n protected unconfigureBrokerEvents(): void {\n this.client.removeAllListeners(KafkaClientEvents.BROKER_CONNECT);\n this.client.removeAllListeners(KafkaClientEvents.BROKER_DISCONNECT);\n this.client.removeAllListeners(KafkaClientEvents.BROKER_FAILED);\n }\n\n protected swapClient(newClient: TClient): void {\n this.unconfigureBrokerEvents();\n this.client = newClient;\n this.resetHealthState();\n this.configureBrokerEvents();\n }\n\n protected resetHealthState(): void {\n this.connectedBrokers.clear();\n this.healthStatus = KafkaHealthStatuses.DISCONNECTED;\n }\n\n protected closeClient(): Promise<void> {\n return this.client.close();\n }\n\n /** Force-close through the callback overload: only Producer and Consumer expose `close(force, cb)`, and the `Base` type this class is generic over declares no such overload - hence the cast. */\n protected closeClientWithCallback(): Promise<void> {\n const client = this.client as AnyType;\n\n return new Promise<void>((resolve, reject) => {\n client.close(true, (error?: Error | null) => {\n if (error) {\n reject(error);\n return;\n }\n\n resolve();\n });\n });\n }\n\n protected async gracefulCloseClient(): Promise<void> {\n let timeoutHandle: NodeJS.Timeout | null = null;\n\n try {\n // The timer MUST be cleared once close() wins: an armed shutdownTimeout timer keeps the event loop alive long after a successful shutdown, so the process refuses to exit.\n await Promise.race([\n this.closeClient(),\n new Promise<void>((_, reject) => {\n timeoutHandle = setTimeout(\n () => reject(getError({ message: '[gracefulCloseClient] Shutdown timed out' })),\n this.shutdownTimeout,\n );\n }),\n ]);\n } finally {\n if (timeoutHandle !== null) {\n clearTimeout(timeoutHandle);\n }\n }\n }\n}\n"]}
@@ -1,5 +1,3 @@
1
1
  export * from './common/index.js';
2
- export * from './platformatic-require.plugin.js';
3
- export * from './platformatic-wasm.plugin.js';
4
2
  export * from './plugins.js';
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
@@ -1,5 +1,3 @@
1
1
  export * from './common/index.js';
2
- export * from './platformatic-require.plugin.js';
3
- export * from './platformatic-wasm.plugin.js';
4
2
  export * from './plugins.js';
5
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC","sourcesContent":["export * from './common';\nexport * from './platformatic-require.plugin';\nexport * from './platformatic-wasm.plugin';\nexport * from './plugins';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC","sourcesContent":["export * from './common';\nexport * from './plugins';\n"]}
@@ -1,4 +1,10 @@
1
1
  import type { BunPlugin } from 'bun';
2
- /** Every `@platformatic/kafka` fix needed by `bun build --compile`, as one list - a service compile script registers this instead of tracking the individual plugins. */
3
- export declare const platformaticKafkaPlugins: () => BunPlugin[];
2
+ /** Every `@platformatic/kafka` fix needed by `bun build --compile`: a service compile script registers `build()` instead of tracking the individual plugins. */
3
+ export declare class PlatformaticKafkaPlugins {
4
+ /** `@platformatic/kafka` 2.8-2.9 resolves some dependencies through `createRequire(import.meta.url)` at module scope; `bun build --compile` cannot see through that, so the specifier stays unresolved and the binary dies with "Cannot find package" before boot - this plugin hoists those calls to static imports at bundle time. 2.10 removed the module-scope require(), so on >= 2.10 the plugin matches nothing and is inert. */
5
+ static buildRequirePlugin(): BunPlugin;
6
+ /** `@platformatic/wasm-utils`'s default entrypoint reads `native.wasm` from disk at module load and `bun build --compile` embeds JS only, so it resolves against `/$bunfs` and the binary dies with ENOENT - this plugin redirects the import to the `/bundled` entrypoint (wasm inlined). */
7
+ static buildWasmPlugin(): BunPlugin;
8
+ static build(): BunPlugin[];
9
+ }
4
10
  //# sourceMappingURL=plugins.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAIrC,yKAAyK;AACzK,eAAO,MAAM,wBAAwB,QAAO,SAAS,EAGpD,CAAC"}
1
+ {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/plugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAQrC,gKAAgK;AAChK,qBAAa,wBAAwB;IACnC,waAAwa;IACxa,MAAM,CAAC,kBAAkB,IAAI,SAAS;IAoCtC,8RAA8R;IAC9R,MAAM,CAAC,eAAe,IAAI,SAAS;IA0BnC,MAAM,CAAC,KAAK,IAAI,SAAS,EAAE;CAM5B"}
@@ -1,8 +1,65 @@
1
- import { platformaticRequirePlugin } from './platformatic-require.plugin.js';
2
- import { platformaticWasmPlugin } from './platformatic-wasm.plugin.js';
3
- /** Every `@platformatic/kafka` fix needed by `bun build --compile`, as one list - a service compile script registers this instead of tracking the individual plugins. */
4
- export const platformaticKafkaPlugins = () => [
5
- platformaticWasmPlugin(),
6
- platformaticRequirePlugin(),
7
- ];
1
+ import { getError } from '../../../error/index.js';
2
+ import { dirname } from 'node:path';
3
+ import { KafkaBundlerPluginNames, PlatformaticRequireSpecifiers, PlatformaticWasmSpecifiers, } from './common/index.js';
4
+ /** Every `@platformatic/kafka` fix needed by `bun build --compile`: a service compile script registers `build()` instead of tracking the individual plugins. */
5
+ export class PlatformaticKafkaPlugins {
6
+ /** `@platformatic/kafka` 2.8-2.9 resolves some dependencies through `createRequire(import.meta.url)` at module scope; `bun build --compile` cannot see through that, so the specifier stays unresolved and the binary dies with "Cannot find package" before boot - this plugin hoists those calls to static imports at bundle time. 2.10 removed the module-scope require(), so on >= 2.10 the plugin matches nothing and is inert. */
7
+ static buildRequirePlugin() {
8
+ return {
9
+ name: KafkaBundlerPluginNames.PLATFORMATIC_REQUIRE,
10
+ setup(build) {
11
+ build.onLoad({ filter: PlatformaticRequireSpecifiers.MODULE_FILTER }, async (args) => {
12
+ const source = await Bun.file(args.path).text();
13
+ const imports = [];
14
+ const contents = source.replace(PlatformaticRequireSpecifiers.REQUIRE_PATTERN, (matched, binding, _quote, specifier) => {
15
+ if (PlatformaticRequireSpecifiers.SKIPPED_SPECIFIERS.includes(specifier)) {
16
+ return matched;
17
+ }
18
+ const alias = `${PlatformaticRequireSpecifiers.IMPORT_ALIAS_PREFIX}${imports.length}`;
19
+ imports.push(`import ${alias} from ${JSON.stringify(specifier)};`);
20
+ // No `?.default` unwrap: a default import already yields `module.exports` for CJS, and
21
+ // unwrapping would break JSON payloads carrying their own top-level `default` key - the
22
+ // draft-06 meta schema has one, so unwrapping silently replaces it with `{}`.
23
+ return `const ${binding} = ${alias};`;
24
+ });
25
+ // No match is not an error: upstream fixing this makes the plugin an inert no-op.
26
+ if (!imports.length) {
27
+ return undefined;
28
+ }
29
+ return { contents: `${imports.join('\n')}\n${contents}`, loader: 'js' };
30
+ });
31
+ },
32
+ };
33
+ }
34
+ /** `@platformatic/wasm-utils`'s default entrypoint reads `native.wasm` from disk at module load and `bun build --compile` embeds JS only, so it resolves against `/$bunfs` and the binary dies with ENOENT - this plugin redirects the import to the `/bundled` entrypoint (wasm inlined). */
35
+ static buildWasmPlugin() {
36
+ return {
37
+ name: KafkaBundlerPluginNames.PLATFORMATIC_WASM,
38
+ setup(build) {
39
+ build.onResolve({ filter: PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, (args) => {
40
+ try {
41
+ return {
42
+ path: Bun.resolveSync(PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT, dirname(args.importer)),
43
+ };
44
+ }
45
+ catch (error) {
46
+ throw getError({
47
+ message: [
48
+ `[platformaticWasmPlugin] Failed to resolve ${PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT}`,
49
+ `from ${args.importer}`,
50
+ `| Error: ${error instanceof Error ? error.message : String(error)}`,
51
+ ].join(' '),
52
+ });
53
+ }
54
+ });
55
+ },
56
+ };
57
+ }
58
+ static build() {
59
+ return [
60
+ PlatformaticKafkaPlugins.buildWasmPlugin(),
61
+ PlatformaticKafkaPlugins.buildRequirePlugin(),
62
+ ];
63
+ }
64
+ }
8
65
  //# sourceMappingURL=plugins.js.map