@venizia/ignis-helpers 0.4.6 → 0.4.7-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/LICENSE.md +1 -3
  2. package/README.md +4 -5
  3. package/dist/esm/common/redact.d.ts +25 -17
  4. package/dist/esm/common/redact.d.ts.map +1 -1
  5. package/dist/esm/common/redact.js +50 -46
  6. package/dist/esm/common/redact.js.map +1 -1
  7. package/dist/esm/common/resolvers.d.ts +7 -5
  8. package/dist/esm/common/resolvers.d.ts.map +1 -1
  9. package/dist/esm/common/resolvers.js +11 -9
  10. package/dist/esm/common/resolvers.js.map +1 -1
  11. package/dist/esm/core.d.ts +6 -3
  12. package/dist/esm/core.d.ts.map +1 -1
  13. package/dist/esm/core.js +6 -3
  14. package/dist/esm/core.js.map +1 -1
  15. package/dist/esm/modules/base.js +4 -4
  16. package/dist/esm/modules/base.js.map +1 -1
  17. package/dist/esm/modules/cron/helper.js +4 -4
  18. package/dist/esm/modules/cron/helper.js.map +1 -1
  19. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
  20. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
  21. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
  22. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  23. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
  24. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  25. package/dist/esm/modules/env/app-env.d.ts.map +1 -1
  26. package/dist/esm/modules/env/app-env.js +2 -2
  27. package/dist/esm/modules/env/app-env.js.map +1 -1
  28. package/dist/esm/modules/logger/common/constants.d.ts +23 -21
  29. package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
  30. package/dist/esm/modules/logger/common/constants.js +45 -42
  31. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  32. package/dist/esm/modules/logger/factory.d.ts +5 -3
  33. package/dist/esm/modules/logger/factory.d.ts.map +1 -1
  34. package/dist/esm/modules/logger/factory.js +5 -3
  35. package/dist/esm/modules/logger/factory.js.map +1 -1
  36. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
  37. package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
  38. package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
  39. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  40. package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
  41. package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
  42. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  43. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  44. package/dist/esm/modules/logger/hf/logger.js +2 -2
  45. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  46. package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
  47. package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
  48. package/dist/esm/modules/logger/pino/backing.js +3 -8
  49. package/dist/esm/modules/logger/pino/backing.js.map +1 -1
  50. package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
  51. package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
  52. package/dist/esm/modules/logger/pino/destination.js +12 -13
  53. package/dist/esm/modules/logger/pino/destination.js.map +1 -1
  54. package/dist/esm/modules/logger/pino/logger.js +2 -2
  55. package/dist/esm/modules/logger/pino/logger.js.map +1 -1
  56. package/dist/esm/modules/logger/resolver.js +2 -2
  57. package/dist/esm/modules/logger/resolver.js.map +1 -1
  58. package/dist/esm/modules/logger/slot.d.ts +39 -18
  59. package/dist/esm/modules/logger/slot.d.ts.map +1 -1
  60. package/dist/esm/modules/logger/slot.js +117 -110
  61. package/dist/esm/modules/logger/slot.js.map +1 -1
  62. package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
  63. package/dist/esm/modules/logger/winston/common/constants.js +7 -6
  64. package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
  65. package/dist/esm/modules/logger/winston/define.d.ts +0 -7
  66. package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
  67. package/dist/esm/modules/logger/winston/define.js +0 -5
  68. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  69. package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
  70. package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
  71. package/dist/esm/modules/logger/winston/formats.js +17 -4
  72. package/dist/esm/modules/logger/winston/formats.js.map +1 -1
  73. package/dist/esm/modules/logger/winston/index.d.ts +3 -2
  74. package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
  75. package/dist/esm/modules/logger/winston/index.js +3 -2
  76. package/dist/esm/modules/logger/winston/index.js.map +1 -1
  77. package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
  78. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  79. package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
  80. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  81. package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
  82. package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
  83. package/dist/esm/modules/network/http-request/common/index.js +0 -1
  84. package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
  85. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
  86. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
  87. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  88. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  89. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
  90. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  91. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
  92. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  93. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
  94. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  95. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
  96. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  97. package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
  98. package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
  99. package/dist/esm/modules/network/utilities/query-string.js +48 -46
  100. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  101. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
  102. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
  103. package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
  104. package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
  105. package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts.map +1 -1
  106. package/dist/esm/modules/network/utilities/url-safety/ingest.js +2 -1
  107. package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
  108. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
  109. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
  110. package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
  111. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  112. package/dist/esm/modules/pool/abstract.d.ts.map +1 -1
  113. package/dist/esm/modules/pool/abstract.js +4 -2
  114. package/dist/esm/modules/pool/abstract.js.map +1 -1
  115. package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
  116. package/dist/esm/modules/queue/bullmq/helper.js +6 -6
  117. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  118. package/dist/esm/modules/queue/common/hook.d.ts +14 -12
  119. package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
  120. package/dist/esm/modules/queue/common/hook.js +21 -19
  121. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  122. package/dist/esm/modules/queue/common/index.d.ts +0 -1
  123. package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
  124. package/dist/esm/modules/queue/common/index.js +0 -1
  125. package/dist/esm/modules/queue/common/index.js.map +1 -1
  126. package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
  127. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  128. package/dist/esm/modules/queue/kafka/base.js +3 -3
  129. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  130. package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
  131. package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
  132. package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
  133. package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
  134. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
  135. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
  136. package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
  137. package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
  138. package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
  139. package/dist/esm/modules/queue/kafka/consumer.js +26 -24
  140. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  141. package/dist/esm/modules/queue/mqtt/helper.js +10 -10
  142. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  143. package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
  144. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  145. package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
  146. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  147. package/dist/esm/modules/redis/factory.d.ts +13 -9
  148. package/dist/esm/modules/redis/factory.d.ts.map +1 -1
  149. package/dist/esm/modules/redis/factory.js +15 -13
  150. package/dist/esm/modules/redis/factory.js.map +1 -1
  151. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
  152. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  153. package/dist/esm/modules/redis/single/single.helper.js +2 -2
  154. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  155. package/dist/esm/modules/redis/utility.d.ts +13 -11
  156. package/dist/esm/modules/redis/utility.d.ts.map +1 -1
  157. package/dist/esm/modules/redis/utility.js +46 -44
  158. package/dist/esm/modules/redis/utility.js.map +1 -1
  159. package/dist/esm/modules/retry/helper.d.ts.map +1 -1
  160. package/dist/esm/modules/retry/helper.js +6 -4
  161. package/dist/esm/modules/retry/helper.js.map +1 -1
  162. package/dist/esm/modules/secrets/factory.d.ts +5 -3
  163. package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
  164. package/dist/esm/modules/secrets/factory.js +36 -34
  165. package/dist/esm/modules/secrets/factory.js.map +1 -1
  166. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts.map +1 -1
  167. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +4 -2
  168. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  169. package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
  170. package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
  171. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  172. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
  173. package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
  174. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  175. package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
  176. package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
  177. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  178. package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
  179. package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
  180. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  181. package/dist/esm/modules/storage/base.d.ts.map +1 -1
  182. package/dist/esm/modules/storage/base.js +9 -8
  183. package/dist/esm/modules/storage/base.js.map +1 -1
  184. package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
  185. package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
  186. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  187. package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
  188. package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
  189. package/dist/esm/modules/storage/bun-s3/utility.js +261 -244
  190. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  191. package/dist/esm/modules/storage/common/errors.d.ts +0 -4
  192. package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
  193. package/dist/esm/modules/storage/common/errors.js +0 -10
  194. package/dist/esm/modules/storage/common/errors.js.map +1 -1
  195. package/dist/esm/modules/storage/common/utility.d.ts +11 -5
  196. package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
  197. package/dist/esm/modules/storage/common/utility.js +30 -17
  198. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  199. package/dist/esm/modules/storage/disk/helper.d.ts.map +1 -1
  200. package/dist/esm/modules/storage/disk/helper.js +18 -9
  201. package/dist/esm/modules/storage/disk/helper.js.map +1 -1
  202. package/dist/esm/modules/tree/builder.d.ts.map +1 -1
  203. package/dist/esm/modules/tree/builder.js +2 -1
  204. package/dist/esm/modules/tree/builder.js.map +1 -1
  205. package/dist/esm/modules/uid/opaque.d.ts.map +1 -1
  206. package/dist/esm/modules/uid/opaque.js +4 -2
  207. package/dist/esm/modules/uid/opaque.js.map +1 -1
  208. package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
  209. package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
  210. package/dist/esm/modules/uid/uuid/helper.js +7 -7
  211. package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
  212. package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
  213. package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
  214. package/dist/esm/modules/uid/uuid/v4.js +51 -46
  215. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  216. package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
  217. package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
  218. package/dist/esm/modules/uid/uuid/v5.js +83 -78
  219. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  220. package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
  221. package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
  222. package/dist/esm/modules/uid/uuid/v7.js +88 -79
  223. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  224. package/dist/esm/modules/worker-thread/bus/base.js +2 -2
  225. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  226. package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
  227. package/dist/esm/modules/worker-thread/worker/base.js +4 -3
  228. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  229. package/dist/esm/utilities/error.utility.d.ts +7 -0
  230. package/dist/esm/utilities/error.utility.d.ts.map +1 -0
  231. package/dist/esm/utilities/error.utility.js +9 -0
  232. package/dist/esm/utilities/error.utility.js.map +1 -0
  233. package/dist/esm/utilities/form-body.utility.d.ts +12 -10
  234. package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
  235. package/dist/esm/utilities/form-body.utility.js +19 -16
  236. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  237. package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
  238. package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
  239. package/dist/esm/utilities/hr-time.utility.js +11 -9
  240. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  241. package/dist/esm/utilities/index.d.ts +2 -2
  242. package/dist/esm/utilities/index.d.ts.map +1 -1
  243. package/dist/esm/utilities/index.js +2 -2
  244. package/dist/esm/utilities/index.js.map +1 -1
  245. package/dist/esm/utilities/module.utility.d.ts.map +1 -1
  246. package/dist/esm/utilities/module.utility.js +4 -2
  247. package/dist/esm/utilities/module.utility.js.map +1 -1
  248. package/dist/esm/utilities/parse.utility.d.ts +89 -43
  249. package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
  250. package/dist/esm/utilities/parse.utility.js +173 -141
  251. package/dist/esm/utilities/parse.utility.js.map +1 -1
  252. package/dist/esm/utilities/performance.utility.d.ts +15 -13
  253. package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
  254. package/dist/esm/utilities/performance.utility.js +34 -29
  255. package/dist/esm/utilities/performance.utility.js.map +1 -1
  256. package/dist/esm/utilities/promise.utility.d.ts +20 -18
  257. package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
  258. package/dist/esm/utilities/promise.utility.js +41 -51
  259. package/dist/esm/utilities/promise.utility.js.map +1 -1
  260. package/dist/esm/utilities/request.utility.d.ts +35 -29
  261. package/dist/esm/utilities/request.utility.d.ts.map +1 -1
  262. package/dist/esm/utilities/request.utility.js +117 -115
  263. package/dist/esm/utilities/request.utility.js.map +1 -1
  264. package/package.json +4 -15
  265. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
  266. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
  267. package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
  268. package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
  269. package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
  270. package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
  271. package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
  272. package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
  273. package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
  274. package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
  275. package/dist/esm/modules/network/http-request/common/types.js +0 -2
  276. package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
  277. package/dist/esm/modules/queue/common/types.d.ts +0 -2
  278. package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
  279. package/dist/esm/modules/queue/common/types.js +0 -2
  280. package/dist/esm/modules/queue/common/types.js.map +0 -1
  281. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
  282. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
  283. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
  284. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
  285. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
  286. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
  287. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
  288. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
  289. package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
  290. package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
  291. package/dist/esm/modules/storage/minio/helper.js +0 -176
  292. package/dist/esm/modules/storage/minio/helper.js.map +0 -1
  293. package/dist/esm/modules/storage/minio/index.d.ts +0 -2
  294. package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
  295. package/dist/esm/modules/storage/minio/index.js +0 -2
  296. package/dist/esm/modules/storage/minio/index.js.map +0 -1
  297. package/dist/esm/utilities/sleep.utility.d.ts +0 -2
  298. package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
  299. package/dist/esm/utilities/sleep.utility.js +0 -4
  300. package/dist/esm/utilities/sleep.utility.js.map +0 -1
@@ -1,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,YAAY,IAAI,IAAI,CAAC;QAC9C,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;QAE/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,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["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,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,CAA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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,OAAO,CAAC;QAEzE,qDAAqD;QAClC,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QAOtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,eAAe,GAAG,IAAI,CA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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,CAAC;QAOtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,aAAa,CAAC,gBAAgB,CAAC;QAC9E,IAAI,CAAC,e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1C,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
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/plugins.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,yKAAyK;AACzK,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAgB,EAAE,CAAC;IACzD,sBAAsB,EAAE;IACxB,yBAAyB,EAAE;CAC5B,CAAC","sourcesContent":["import type { BunPlugin } from 'bun';\nimport { platformaticRequirePlugin } from './platformatic-require.plugin';\nimport { platformaticWasmPlugin } from './platformatic-wasm.plugin';\n\n/** Every `@platformatic/kafka` fix needed by `bun build --compile`, as one list - a service compile script registers this instead of tracking the individual plugins. */\nexport const platformaticKafkaPlugins = (): BunPlugin[] => [\n platformaticWasmPlugin(),\n platformaticRequirePlugin(),\n];\n"]}
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAElB,gKAAgK;AAChK,MAAM,OAAO,wBAAwB;IACnC,waAAwa;IACxa,MAAM,CAAC,kBAAkB;QACvB,OAAO;YACL,IAAI,EAAE,uBAAuB,CAAC,oBAAoB;YAClD,KAAK,CAAC,KAAK;gBACT,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,6BAA6B,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;oBACnF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAA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C,WAAW,CACnB,0BAA0B,CAAC,kBAAkB,EAC7C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CACvB;yBACF,CAAC;oBACJ,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,MAAM,QAAQ,CAAC;4BACb,OAAO,EAAE;gCACP,8CAA8C,0BAA0B,CAAC,kBAAkB,EAAE;gCAC7F,QAAQ,IAAI,CAAC,QAAQ,EAAE;gCACvB,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;6BACrE,CAAC,IAAI,CAAC,GAAG,CAAC;yBACZ,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK;QACV,OAAO;YACL,wBAAwB,CAAC,eAAe,EAAE;YAC1C,wBAAwB,CAAC,kBAAkB,EAAE;SAC9C,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { getError } from '@/modules/error';\nimport type { BunPlugin } from 'bun';\nimport { dirname } from 'node:path';\nimport {\n KafkaBundlerPluginNames,\n PlatformaticRequireSpecifiers,\n PlatformaticWasmSpecifiers,\n} from './common';\n\n/** Every `@platformatic/kafka` fix needed by `bun build --compile`: a service compile script registers `build()` instead of tracking the individual plugins. */\nexport class PlatformaticKafkaPlugins {\n /** `@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. */\n static buildRequirePlugin(): BunPlugin {\n return {\n name: KafkaBundlerPluginNames.PLATFORMATIC_REQUIRE,\n setup(build) {\n build.onLoad({ filter: PlatformaticRequireSpecifiers.MODULE_FILTER }, async (args) => {\n const source = await Bun.file(args.path).text();\n const imports: string[] = [];\n\n const contents = source.replace(\n PlatformaticRequireSpecifiers.REQUIRE_PATTERN,\n (matched, binding: string, _quote: string, specifier: string) => {\n if (PlatformaticRequireSpecifiers.SKIPPED_SPECIFIERS.includes(specifier)) {\n return matched;\n }\n\n const alias = `${PlatformaticRequireSpecifiers.IMPORT_ALIAS_PREFIX}${imports.length}`;\n imports.push(`import ${alias} from ${JSON.stringify(specifier)};`);\n\n // No `?.default` unwrap: a default import already yields `module.exports` for CJS, and\n // unwrapping would break JSON payloads carrying their own top-level `default` key - the\n // draft-06 meta schema has one, so unwrapping silently replaces it with `{}`.\n return `const ${binding} = ${alias};`;\n },\n );\n\n // No match is not an error: upstream fixing this makes the plugin an inert no-op.\n if (!imports.length) {\n return undefined;\n }\n\n return { contents: `${imports.join('\\n')}\\n${contents}`, loader: 'js' };\n });\n },\n };\n }\n\n /** `@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). */\n static buildWasmPlugin(): BunPlugin {\n return {\n name: KafkaBundlerPluginNames.PLATFORMATIC_WASM,\n setup(build) {\n build.onResolve({ filter: PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, (args) => {\n try {\n return {\n path: Bun.resolveSync(\n PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT,\n dirname(args.importer),\n ),\n };\n } catch (error) {\n throw getError({\n message: [\n `[platformaticWasmPlugin] Failed to resolve ${PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT}`,\n `from ${args.importer}`,\n `| Error: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n });\n },\n };\n }\n\n static build(): BunPlugin[] {\n return [\n PlatformaticKafkaPlugins.buildWasmPlugin(),\n PlatformaticKafkaPlugins.buildRequirePlugin(),\n ];\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"consumer.d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E,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,CAAC,GACtE,OAAO,CAAC,IAAI,CAAC;IAwBhB,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAcrE,SAAS,CAAC,iBAAiB,IAAI,IAAI;cAKnB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;cAkBzB,uBAAuB,IAAI,IAAI;cAU/B,qBAAqB,IAAI,IAAI;CAoGjD"}
@@ -1,8 +1,8 @@
1
1
  import { getError } from '../../error/index.js';
2
- import { sleep } from '../../../utilities/sleep.utility.js';
3
- import { toError } from '../../../utilities/promise.utility.js';
2
+ import { ErrorUtility } from '../../../utilities/error.utility.js';
3
+ import { PromiseUtility } from '../../../utilities/promise.utility.js';
4
4
  import { Consumer } from '@platformatic/kafka';
5
- import { invokeHook } from '../common/index.js';
5
+ import { HookUtility } from '../common/index.js';
6
6
  import { BaseKafkaHelper } from './base.js';
7
7
  import { KafkaBrokersDownReasons, KafkaClientEvents, KafkaDefaults, KafkaHealthStatuses, } from './common/constants.js';
8
8
  /**
@@ -91,11 +91,12 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
91
91
  }
92
92
  this.logger.info('[start] Starting consumer | Topics: %j', opts.topics);
93
93
  this.consumeStartOptions = opts;
94
- this.stream = await this.client.consume({
94
+ const result = await this.client.consume({
95
95
  topics: opts.topics,
96
96
  mode: opts.mode ?? KafkaDefaults.CONSUME_MODE,
97
97
  fallbackMode: opts.fallbackMode ?? KafkaDefaults.CONSUME_FALLBACK_MODE,
98
98
  });
99
+ this.stream = result;
99
100
  // Successful consume() means we're freshly joined to the group; clear any stale-session flag set during initial broker negotiation (e.g. a transient BROKER_DISCONNECT during bootstrap).
100
101
  this.sessionLikelyStale = false;
101
102
  // Always attached, hook or not: a stream 'error' with ZERO listeners is rethrown by EventEmitter as an uncaught exception, so a pull-style consumer (start() + getStream(), no onMessage/onMessageError) would take the whole process down on the first broker drop.
@@ -176,9 +177,9 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
176
177
  await doneHandler?.({ message });
177
178
  }
178
179
  catch (error) {
179
- const normalizedError = toError(error);
180
+ const normalizedError = ErrorUtility.toError({ error });
180
181
  this.logger.error('[startConsumeLoop] Message processing error: %s', normalizedError.message);
181
- invokeHook({
182
+ HookUtility.invoke({
182
183
  logger: this.logger,
183
184
  scope: 'startConsumeLoop',
184
185
  execution: () => errorHandler?.({ error: normalizedError, message }),
@@ -222,7 +223,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
222
223
  if (this.consumeLoop && this.stream === opts.stream) {
223
224
  return;
224
225
  }
225
- invokeHook({
226
+ HookUtility.invoke({
226
227
  logger: this.logger,
227
228
  scope: opts.scope,
228
229
  execution: () => this.onStreamError
@@ -237,9 +238,9 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
237
238
  this.logger.warn('[drainStream] Stream ended normally | Topics: %j', this.consumeStartOptions?.topics);
238
239
  }
239
240
  catch (error) {
240
- const normalizedError = toError(error);
241
+ const normalizedError = ErrorUtility.toError({ error });
241
242
  this.logger.error('[drainStream] Stream error: %s | Topics: %j', normalizedError.message, this.consumeStartOptions?.topics);
242
- invokeHook({
243
+ HookUtility.invoke({
243
244
  logger: this.logger,
244
245
  scope: 'drainStream',
245
246
  execution: () => this.onStreamError
@@ -252,7 +253,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
252
253
  async attemptReconnect(opts) {
253
254
  const { attempt, maxAttempts, delayMs, errorHandler } = opts;
254
255
  this.logger.info('[attemptReconnect] Reconnecting %d/%d in %dms | Topics: %j | ConnectedBrokers: %d', attempt, maxAttempts, delayMs, this.consumeStartOptions?.topics, this.getConnectedBrokerCount());
255
- await sleep(delayMs);
256
+ await PromiseUtility.sleep({ ms: delayMs });
256
257
  if (!this.consumeStartOptions) {
257
258
  return;
258
259
  }
@@ -266,9 +267,9 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
266
267
  this.sessionLikelyStale = false;
267
268
  }
268
269
  catch (error) {
269
- const normalizedError = toError(error);
270
+ const normalizedError = ErrorUtility.toError({ error });
270
271
  this.logger.error('[attemptReconnect] Client rebuild failed (%d/%d): %s | Topics: %j', attempt, maxAttempts, normalizedError.message, this.consumeStartOptions?.topics);
271
- invokeHook({
272
+ HookUtility.invoke({
272
273
  logger: this.logger,
273
274
  scope: 'attemptReconnect',
274
275
  execution: () => this.onReconnectError
@@ -279,11 +280,12 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
279
280
  }
280
281
  }
281
282
  try {
282
- this.stream = await this.client.consume({
283
+ const result = await this.client.consume({
283
284
  topics: this.consumeStartOptions.topics,
284
285
  mode: this.consumeStartOptions.mode ?? KafkaDefaults.CONSUME_MODE,
285
286
  fallbackMode: this.consumeStartOptions.fallbackMode ?? KafkaDefaults.CONSUME_FALLBACK_MODE,
286
287
  });
288
+ this.stream = result;
287
289
  // Always attached, hook or not, like the listener in start(): a stream 'error' with ZERO listeners is rethrown by EventEmitter and takes the process down.
288
290
  const reconnectedStream = this.stream;
289
291
  reconnectedStream.on(KafkaClientEvents.STREAM_ERROR, (streamError) => {
@@ -298,9 +300,9 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
298
300
  this.logger.info('[attemptReconnect] Reconnected successfully | Topics: %j | Attempt: %d | Rebuilt: %s', this.consumeStartOptions.topics, attempt, shouldRebuildClient);
299
301
  }
300
302
  catch (error) {
301
- const normalizedError = toError(error);
303
+ const normalizedError = ErrorUtility.toError({ error });
302
304
  this.logger.error('[attemptReconnect] Failed (%d/%d): %s | Topics: %j | ConnectedBrokers: %d', attempt, maxAttempts, normalizedError.message, this.consumeStartOptions?.topics, this.getConnectedBrokerCount());
303
- invokeHook({
305
+ HookUtility.invoke({
304
306
  logger: this.logger,
305
307
  scope: 'attemptReconnect',
306
308
  execution: () => this.onReconnectError
@@ -323,11 +325,11 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
323
325
  this.logger.info('[rebuildClient] Lag monitoring re-armed on new client | Topics: %j', opts.topics);
324
326
  }
325
327
  catch (error) {
326
- this.logger.warn('[rebuildClient] Failed to restart lag monitoring on new client | Error: %s', toError(error).message);
328
+ this.logger.warn('[rebuildClient] Failed to restart lag monitoring on new client | Error: %s', ErrorUtility.toError({ error }).message);
327
329
  }
328
330
  }
329
331
  this.closeOldClient(oldClient).catch((error) => {
330
- this.logger.warn('[rebuildClient] background close of old client failed (ignored) | Error: %s', toError(error).message);
332
+ this.logger.warn('[rebuildClient] background close of old client failed (ignored) | Error: %s', ErrorUtility.toError({ error }).message);
331
333
  });
332
334
  }
333
335
  async closeOldClient(oldClient) {
@@ -377,7 +379,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
377
379
  await stream?.close();
378
380
  }
379
381
  catch (error) {
380
- this.logger.warn('[closeStream] Error closing stream: %s', toError(error).message);
382
+ this.logger.warn('[closeStream] Error closing stream: %s', ErrorUtility.toError({ error }).message);
381
383
  }
382
384
  await this.consumeLoop;
383
385
  this.consumeLoop = null;
@@ -401,7 +403,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
401
403
  });
402
404
  this.client.on(KafkaClientEvents.CONSUMER_GROUP_JOIN, (payload) => {
403
405
  this.logger.info('[configureConsumerEvents] Group JOINED | GroupId: %s | MemberId: %s | GenerationId: %d', payload.groupId, payload.memberId, payload.generationId);
404
- invokeHook({
406
+ HookUtility.invoke({
405
407
  logger: this.logger,
406
408
  scope: 'configureBrokerEvents',
407
409
  execution: () => this.onGroupJoin?.({
@@ -413,7 +415,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
413
415
  });
414
416
  this.client.on(KafkaClientEvents.CONSUMER_GROUP_LEAVE, (payload) => {
415
417
  this.logger.info('[configureConsumerEvents] Group LEFT | GroupId: %s | MemberId: %s', payload.groupId, payload.memberId);
416
- invokeHook({
418
+ HookUtility.invoke({
417
419
  logger: this.logger,
418
420
  scope: 'configureBrokerEvents',
419
421
  execution: () => this.onGroupLeave?.({
@@ -424,7 +426,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
424
426
  });
425
427
  this.client.on(KafkaClientEvents.CONSUMER_GROUP_REBALANCE, (payload) => {
426
428
  this.logger.info('[configureConsumerEvents] Group REBALANCE | GroupId: %s', payload.groupId);
427
- invokeHook({
429
+ HookUtility.invoke({
428
430
  logger: this.logger,
429
431
  scope: 'configureBrokerEvents',
430
432
  execution: () => this.onGroupRebalance?.({ groupId: payload.groupId }),
@@ -432,7 +434,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
432
434
  });
433
435
  this.client.on(KafkaClientEvents.CONSUMER_HEARTBEAT_ERROR, (payload) => {
434
436
  this.logger.error('[configureConsumerEvents] Heartbeat ERROR | GroupId: %s | MemberId: %s | Error: %s', payload.groupId, payload.memberId, payload.error);
435
- invokeHook({
437
+ HookUtility.invoke({
436
438
  logger: this.logger,
437
439
  scope: 'configureBrokerEvents',
438
440
  execution: () => this.onHeartbeatError?.({
@@ -443,7 +445,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
443
445
  });
444
446
  });
445
447
  this.client.on(KafkaClientEvents.CONSUMER_LAG, (lag) => {
446
- invokeHook({
448
+ HookUtility.invoke({
447
449
  logger: this.logger,
448
450
  scope: 'configureBrokerEvents',
449
451
  execution: () => this.onLag?.({ lag }),
@@ -451,7 +453,7 @@ export class KafkaConsumerHelper extends BaseKafkaHelper {
451
453
  });
452
454
  this.client.on(KafkaClientEvents.CONSUMER_LAG_ERROR, (error) => {
453
455
  this.logger.error('[configureConsumerEvents] Lag monitoring ERROR: %s', error);
454
- invokeHook({
456
+ HookUtility.invoke({
455
457
  logger: this.logger,
456
458
  scope: 'configureBrokerEvents',
457
459
  execution: () => this.onLagError?.({ error }),