@zdavison/matador 2.0.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 (256) hide show
  1. package/cli.ts +453 -0
  2. package/dist/checkpoint/context.d.ts +59 -0
  3. package/dist/checkpoint/context.d.ts.map +1 -0
  4. package/dist/checkpoint/context.js +140 -0
  5. package/dist/checkpoint/context.test.d.ts +2 -0
  6. package/dist/checkpoint/context.test.d.ts.map +1 -0
  7. package/dist/checkpoint/context.test.js +424 -0
  8. package/dist/checkpoint/index.d.ts +7 -0
  9. package/dist/checkpoint/index.d.ts.map +1 -0
  10. package/dist/checkpoint/index.js +6 -0
  11. package/dist/checkpoint/stores/memory.d.ts +29 -0
  12. package/dist/checkpoint/stores/memory.d.ts.map +1 -0
  13. package/dist/checkpoint/stores/memory.js +39 -0
  14. package/dist/checkpoint/stores/noop.d.ts +14 -0
  15. package/dist/checkpoint/stores/noop.d.ts.map +1 -0
  16. package/dist/checkpoint/stores/noop.js +18 -0
  17. package/dist/checkpoint/stores/stores.test.d.ts +2 -0
  18. package/dist/checkpoint/stores/stores.test.d.ts.map +1 -0
  19. package/dist/checkpoint/stores/stores.test.js +146 -0
  20. package/dist/checkpoint/types.d.ts +119 -0
  21. package/dist/checkpoint/types.d.ts.map +1 -0
  22. package/dist/checkpoint/types.js +1 -0
  23. package/dist/codec/codec.d.ts +29 -0
  24. package/dist/codec/codec.d.ts.map +1 -0
  25. package/dist/codec/codec.js +15 -0
  26. package/dist/codec/header-aware-codec.d.ts +36 -0
  27. package/dist/codec/header-aware-codec.d.ts.map +1 -0
  28. package/dist/codec/header-aware-codec.js +1 -0
  29. package/dist/codec/index.d.ts +6 -0
  30. package/dist/codec/index.d.ts.map +1 -0
  31. package/dist/codec/index.js +3 -0
  32. package/dist/codec/json-codec.d.ts +13 -0
  33. package/dist/codec/json-codec.d.ts.map +1 -0
  34. package/dist/codec/json-codec.js +64 -0
  35. package/dist/codec/rabbitmq-codec.d.ts +28 -0
  36. package/dist/codec/rabbitmq-codec.d.ts.map +1 -0
  37. package/dist/codec/rabbitmq-codec.js +242 -0
  38. package/dist/codec/rabbitmq-codec.test.d.ts +2 -0
  39. package/dist/codec/rabbitmq-codec.test.d.ts.map +1 -0
  40. package/dist/codec/rabbitmq-codec.test.js +433 -0
  41. package/dist/core/fanout.d.ts +59 -0
  42. package/dist/core/fanout.d.ts.map +1 -0
  43. package/dist/core/fanout.js +121 -0
  44. package/dist/core/fanout.test.d.ts +2 -0
  45. package/dist/core/fanout.test.d.ts.map +1 -0
  46. package/dist/core/fanout.test.js +1055 -0
  47. package/dist/core/index.d.ts +7 -0
  48. package/dist/core/index.d.ts.map +1 -0
  49. package/dist/core/index.js +3 -0
  50. package/dist/core/matador.d.ts +133 -0
  51. package/dist/core/matador.d.ts.map +1 -0
  52. package/dist/core/matador.js +222 -0
  53. package/dist/core/matador.test.d.ts +2 -0
  54. package/dist/core/matador.test.d.ts.map +1 -0
  55. package/dist/core/matador.test.js +446 -0
  56. package/dist/core/shutdown.d.ts +78 -0
  57. package/dist/core/shutdown.d.ts.map +1 -0
  58. package/dist/core/shutdown.js +111 -0
  59. package/dist/core/shutdown.test.d.ts +2 -0
  60. package/dist/core/shutdown.test.d.ts.map +1 -0
  61. package/dist/core/shutdown.test.js +524 -0
  62. package/dist/errors/checkpoint-errors.d.ts +30 -0
  63. package/dist/errors/checkpoint-errors.d.ts.map +1 -0
  64. package/dist/errors/checkpoint-errors.js +49 -0
  65. package/dist/errors/has-description.d.ts +18 -0
  66. package/dist/errors/has-description.d.ts.map +1 -0
  67. package/dist/errors/has-description.js +9 -0
  68. package/dist/errors/index.d.ts +6 -0
  69. package/dist/errors/index.d.ts.map +1 -0
  70. package/dist/errors/index.js +22 -0
  71. package/dist/errors/matador-errors.d.ts +183 -0
  72. package/dist/errors/matador-errors.d.ts.map +1 -0
  73. package/dist/errors/matador-errors.js +376 -0
  74. package/dist/errors/retry-errors.d.ts +67 -0
  75. package/dist/errors/retry-errors.d.ts.map +1 -0
  76. package/dist/errors/retry-errors.js +108 -0
  77. package/dist/hooks/index.d.ts +4 -0
  78. package/dist/hooks/index.d.ts.map +1 -0
  79. package/dist/hooks/index.js +2 -0
  80. package/dist/hooks/safe-hooks.d.ts +34 -0
  81. package/dist/hooks/safe-hooks.d.ts.map +1 -0
  82. package/dist/hooks/safe-hooks.js +135 -0
  83. package/dist/hooks/types.d.ts +189 -0
  84. package/dist/hooks/types.d.ts.map +1 -0
  85. package/dist/hooks/types.js +9 -0
  86. package/dist/index.cjs +3156 -0
  87. package/dist/index.cjs.map +1 -0
  88. package/dist/index.d.cts +23 -0
  89. package/dist/index.d.ts +23 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +31 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/pipeline/index.d.ts +3 -0
  94. package/dist/pipeline/index.d.ts.map +1 -0
  95. package/dist/pipeline/index.js +1 -0
  96. package/dist/pipeline/pipeline.d.ts +60 -0
  97. package/dist/pipeline/pipeline.d.ts.map +1 -0
  98. package/dist/pipeline/pipeline.js +261 -0
  99. package/dist/pipeline/pipeline.test.d.ts +2 -0
  100. package/dist/pipeline/pipeline.test.d.ts.map +1 -0
  101. package/dist/pipeline/pipeline.test.js +1065 -0
  102. package/dist/retry/index.d.ts +4 -0
  103. package/dist/retry/index.d.ts.map +1 -0
  104. package/dist/retry/index.js +1 -0
  105. package/dist/retry/policy.d.ts +43 -0
  106. package/dist/retry/policy.d.ts.map +1 -0
  107. package/dist/retry/policy.js +1 -0
  108. package/dist/retry/standard-policy.d.ts +44 -0
  109. package/dist/retry/standard-policy.d.ts.map +1 -0
  110. package/dist/retry/standard-policy.js +102 -0
  111. package/dist/retry/standard-policy.test.d.ts +2 -0
  112. package/dist/retry/standard-policy.test.d.ts.map +1 -0
  113. package/dist/retry/standard-policy.test.js +190 -0
  114. package/dist/schema/index.d.ts +4 -0
  115. package/dist/schema/index.d.ts.map +1 -0
  116. package/dist/schema/index.js +2 -0
  117. package/dist/schema/registry.d.ts +63 -0
  118. package/dist/schema/registry.d.ts.map +1 -0
  119. package/dist/schema/registry.js +171 -0
  120. package/dist/schema/registry.test.d.ts +2 -0
  121. package/dist/schema/registry.test.d.ts.map +1 -0
  122. package/dist/schema/registry.test.js +278 -0
  123. package/dist/schema/types.d.ts +158 -0
  124. package/dist/schema/types.d.ts.map +1 -0
  125. package/dist/schema/types.js +74 -0
  126. package/dist/schema/types.test.d.ts +2 -0
  127. package/dist/schema/types.test.d.ts.map +1 -0
  128. package/dist/schema/types.test.js +243 -0
  129. package/dist/topology/builder.d.ts +66 -0
  130. package/dist/topology/builder.d.ts.map +1 -0
  131. package/dist/topology/builder.js +156 -0
  132. package/dist/topology/builder.test.d.ts +2 -0
  133. package/dist/topology/builder.test.d.ts.map +1 -0
  134. package/dist/topology/builder.test.js +222 -0
  135. package/dist/topology/index.d.ts +5 -0
  136. package/dist/topology/index.d.ts.map +1 -0
  137. package/dist/topology/index.js +2 -0
  138. package/dist/topology/types.d.ts +76 -0
  139. package/dist/topology/types.d.ts.map +1 -0
  140. package/dist/topology/types.js +18 -0
  141. package/dist/transport/capabilities.d.ts +66 -0
  142. package/dist/transport/capabilities.d.ts.map +1 -0
  143. package/dist/transport/capabilities.js +18 -0
  144. package/dist/transport/connection-manager.d.ts +95 -0
  145. package/dist/transport/connection-manager.d.ts.map +1 -0
  146. package/dist/transport/connection-manager.js +144 -0
  147. package/dist/transport/index.d.ts +11 -0
  148. package/dist/transport/index.d.ts.map +1 -0
  149. package/dist/transport/index.js +5 -0
  150. package/dist/transport/local/local-transport.d.ts +62 -0
  151. package/dist/transport/local/local-transport.d.ts.map +1 -0
  152. package/dist/transport/local/local-transport.js +241 -0
  153. package/dist/transport/local/local-transport.test.d.ts +2 -0
  154. package/dist/transport/local/local-transport.test.d.ts.map +1 -0
  155. package/dist/transport/local/local-transport.test.js +192 -0
  156. package/dist/transport/multi/multi-transport.d.ts +94 -0
  157. package/dist/transport/multi/multi-transport.d.ts.map +1 -0
  158. package/dist/transport/multi/multi-transport.js +184 -0
  159. package/dist/transport/multi/multi-transport.test.d.ts +2 -0
  160. package/dist/transport/multi/multi-transport.test.d.ts.map +1 -0
  161. package/dist/transport/multi/multi-transport.test.js +236 -0
  162. package/dist/transport/rabbitmq/rabbitmq-transport.d.ts +73 -0
  163. package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +1 -0
  164. package/dist/transport/rabbitmq/rabbitmq-transport.js +518 -0
  165. package/dist/transport/transport.d.ts +152 -0
  166. package/dist/transport/transport.d.ts.map +1 -0
  167. package/dist/transport/transport.js +1 -0
  168. package/dist/types/common.d.ts +41 -0
  169. package/dist/types/common.d.ts.map +1 -0
  170. package/dist/types/common.js +12 -0
  171. package/dist/types/envelope.d.ts +82 -0
  172. package/dist/types/envelope.d.ts.map +1 -0
  173. package/dist/types/envelope.js +36 -0
  174. package/dist/types/event.d.ts +96 -0
  175. package/dist/types/event.d.ts.map +1 -0
  176. package/dist/types/event.js +26 -0
  177. package/dist/types/event.test.d.ts +2 -0
  178. package/dist/types/event.test.d.ts.map +1 -0
  179. package/dist/types/event.test.js +130 -0
  180. package/dist/types/index.d.ts +9 -0
  181. package/dist/types/index.d.ts.map +1 -0
  182. package/dist/types/index.js +4 -0
  183. package/dist/types/subscriber.d.ts +207 -0
  184. package/dist/types/subscriber.d.ts.map +1 -0
  185. package/dist/types/subscriber.js +99 -0
  186. package/examples/config.ts +126 -0
  187. package/examples/event.ts +26 -0
  188. package/examples/order-event.json +19 -0
  189. package/package.json +66 -0
  190. package/src/checkpoint/context.test.ts +510 -0
  191. package/src/checkpoint/context.ts +213 -0
  192. package/src/checkpoint/index.ts +30 -0
  193. package/src/checkpoint/stores/memory.ts +47 -0
  194. package/src/checkpoint/stores/noop.ts +22 -0
  195. package/src/checkpoint/stores/stores.test.ts +177 -0
  196. package/src/checkpoint/types.ts +147 -0
  197. package/src/codec/codec.ts +42 -0
  198. package/src/codec/header-aware-codec.ts +41 -0
  199. package/src/codec/index.ts +11 -0
  200. package/src/codec/json-codec.ts +69 -0
  201. package/src/codec/rabbitmq-codec.test.ts +516 -0
  202. package/src/codec/rabbitmq-codec.ts +336 -0
  203. package/src/core/fanout.test.ts +1351 -0
  204. package/src/core/fanout.ts +184 -0
  205. package/src/core/index.ts +12 -0
  206. package/src/core/matador.test.ts +575 -0
  207. package/src/core/matador.ts +344 -0
  208. package/src/core/shutdown.test.ts +853 -0
  209. package/src/core/shutdown.ts +165 -0
  210. package/src/errors/checkpoint-errors.ts +62 -0
  211. package/src/errors/has-description.ts +25 -0
  212. package/src/errors/index.ts +57 -0
  213. package/src/errors/matador-errors.ts +477 -0
  214. package/src/errors/retry-errors.ts +134 -0
  215. package/src/hooks/index.ts +15 -0
  216. package/src/hooks/safe-hooks.ts +223 -0
  217. package/src/hooks/types.ts +248 -0
  218. package/src/index.ts +231 -0
  219. package/src/pipeline/index.ts +2 -0
  220. package/src/pipeline/pipeline.test.ts +1317 -0
  221. package/src/pipeline/pipeline.ts +371 -0
  222. package/src/retry/index.ts +4 -0
  223. package/src/retry/policy.ts +46 -0
  224. package/src/retry/standard-policy.test.ts +282 -0
  225. package/src/retry/standard-policy.ts +156 -0
  226. package/src/schema/index.ts +16 -0
  227. package/src/schema/registry.test.ts +339 -0
  228. package/src/schema/registry.ts +226 -0
  229. package/src/schema/types.test.ts +281 -0
  230. package/src/schema/types.ts +217 -0
  231. package/src/topology/builder.test.ts +275 -0
  232. package/src/topology/builder.ts +199 -0
  233. package/src/topology/index.ts +15 -0
  234. package/src/topology/types.ts +109 -0
  235. package/src/transport/capabilities.ts +88 -0
  236. package/src/transport/connection-manager.ts +218 -0
  237. package/src/transport/index.ts +42 -0
  238. package/src/transport/local/local-transport.test.ts +262 -0
  239. package/src/transport/local/local-transport.ts +327 -0
  240. package/src/transport/multi/multi-transport.test.ts +320 -0
  241. package/src/transport/multi/multi-transport.ts +294 -0
  242. package/src/transport/rabbitmq/rabbitmq-transport.ts +753 -0
  243. package/src/transport/transport.ts +200 -0
  244. package/src/types/common.ts +53 -0
  245. package/src/types/envelope.ts +152 -0
  246. package/src/types/event.test.ts +157 -0
  247. package/src/types/event.ts +118 -0
  248. package/src/types/index.ts +52 -0
  249. package/src/types/subscriber.ts +310 -0
  250. package/test/e2e/multi-transport.e2e.test.ts +236 -0
  251. package/test/e2e/rabbitmq-transport.e2e.test.ts +327 -0
  252. package/test/e2e/transport-compliance.e2e.test.ts +505 -0
  253. package/test/integration/matador.integration.test.ts +634 -0
  254. package/tsconfig.json +29 -0
  255. package/tsconfig.tsbuildinfo +1 -0
  256. package/tsup.config.ts +13 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors/has-description.ts","../src/errors/retry-errors.ts","../src/errors/matador-errors.ts","../src/errors/checkpoint-errors.ts","../src/topology/types.ts","../src/topology/builder.ts","../src/types/common.ts","../src/types/envelope.ts","../src/types/event.ts","../src/types/subscriber.ts","../src/core/fanout.ts","../src/hooks/types.ts","../src/hooks/safe-hooks.ts","../src/core/shutdown.ts","../src/codec/codec.ts","../src/codec/json-codec.ts","../src/codec/rabbitmq-codec.ts","../src/checkpoint/context.ts","../src/checkpoint/stores/memory.ts","../src/checkpoint/stores/noop.ts","../src/pipeline/pipeline.ts","../src/retry/standard-policy.ts","../src/schema/types.ts","../src/schema/registry.ts","../src/core/matador.ts","../src/transport/capabilities.ts","../src/transport/connection-manager.ts","../src/transport/local/local-transport.ts","../src/transport/multi/multi-transport.ts","../src/transport/rabbitmq/rabbitmq-transport.ts"],"names":["error","decision","amqplib"],"mappings":";;;;;;;;;AAiBO,SAAS,eAAe,KAAA,EAAyC;AACtE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,aAAA,IAAiB,KAAA,IACjB,OAAQ,KAAA,CAAyB,WAAA,KAAgB,QAAA;AAErD;;;ACpBO,IAAe,iBAAA,GAAf,cAAyC,KAAA,CAAM;AAAA,EAWpD,YAAY,OAAA,EAAiB;AAC3B,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A,MAAM,aAAa,MAAA,CAAO,MAAA;AAAA,QACxB,CAAC,GAAA,EAAa,KAAA,KAA8B,GAAA,IAAO,MAAM,KAAA,IAAS,CAAA,CAAA;AAAA,QAClE;AAAA,OACF;AACA,MAAA,OAAO,UAAA,GAAa,CAAA;AAAA,IACtB;AACA,IAAA,OAAO,CAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,gBAAA,CAAiB,KAAqB,aAAA,EAA+B;AAE3E,IAAA,MAAM,aAAA,GAAgB,GAAA,CAAI,UAAA,CAAW,OAAA,GAAU,kBAAkB,CAAA;AACjE,IAAA,IAAI,OAAO,kBAAkB,QAAA,EAAU;AACrC,MAAA,OAAO,aAAA;AAAA,IACT;AAGA,IAAA,MAAM,MAAA,GAAS,GAAA,CAAI,UAAA,CAAW,OAAA,GAAU,SAAS,CAAA;AACjD,IAAA,IAAI,MAAM,OAAA,CAAQ,MAAM,CAAA,IAAK,MAAA,CAAO,SAAS,CAAA,EAAG;AAC9C,MAAA,MAAM,aAAa,MAAA,CAAO,MAAA;AAAA,QACxB,CAAC,GAAA,EAAa,KAAA,KAA8B,GAAA,IAAO,MAAM,KAAA,IAAS,CAAA,CAAA;AAAA,QAClE;AAAA,OACF;AAEA,MAAA,OAAO,UAAA,GAAa,CAAA;AAAA,IACtB;AAGA,IAAA,IAAI,GAAA,CAAI,OAAO,WAAA,EAAa;AAC1B,MAAA,OAAO,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,aAAa,CAAA;AAAA,IAClC;AAGA,IAAA,OAAO,aAAA;AAAA,EACT;AACF","file":"index.cjs","sourcesContent":["/**\n * Interface for errors that provide a human-readable description.\n * The description explains what the error means and what actions\n * users should take when encountering it in logs/observability.\n */\nexport interface HasDescription {\n /**\n * Human-readable description of the error type.\n * Intended for logging and observability to help users understand\n * the error and determine appropriate remediation steps.\n */\n readonly description: string;\n}\n\n/**\n * Type guard to check if an error implements HasDescription.\n */\nexport function hasDescription(error: unknown): error is HasDescription {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'description' in error &&\n typeof (error as HasDescription).description === 'string'\n );\n}\n","/**\n * Base class for retry control errors.\n * These errors control the retry behavior of message processing.\n */\nexport abstract class RetryControlError extends Error {\n /**\n * Error class name for monitoring tools.\n */\n declare readonly name: string;\n\n /**\n * Human-readable description of the error and recommended actions.\n */\n abstract readonly description: string;\n\n constructor(message: string) {\n super(message);\n this.name = this.constructor.name;\n // Ensure name is preserved when serialized\n Object.defineProperty(this, 'name', {\n value: this.constructor.name,\n enumerable: true,\n configurable: false,\n writable: false,\n });\n }\n\n /**\n * Returns a serializable representation for logging/monitoring.\n */\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n description: this.description,\n stack: this.stack,\n };\n }\n}\n\n/**\n * Forces retry regardless of subscriber idempotency setting.\n * Use when you know the operation is safe to retry.\n *\n * ACTION: Check subscriber code to understand why retry was forced.\n * This overrides default retry behavior based on idempotency settings.\n */\nexport class DoRetry extends RetryControlError {\n readonly description =\n 'A subscriber explicitly requested retry by throwing DoRetry. ' +\n 'ACTION: Check the subscriber code to understand why retry was forced. ' +\n 'This overrides the default retry behavior based on idempotency settings.';\n\n constructor(message = 'Forced retry requested') {\n super(message);\n }\n}\n\n/**\n * Prevents retry regardless of subscriber idempotency setting.\n * Use for permanent failures that should not be retried.\n *\n * ACTION: Check subscriber code to understand why retry was disabled.\n * Typically used for permanent failures like invalid data or business rule violations.\n */\nexport class DontRetry extends RetryControlError {\n readonly description =\n 'A subscriber explicitly prevented retry by throwing DontRetry. ' +\n 'ACTION: Check the subscriber code to understand why retry was disabled. ' +\n 'Typically used for permanent failures like invalid data or business rule violations. ' +\n 'The message will be sent to the dead-letter queue for manual review.';\n\n constructor(message = 'Retry explicitly disabled') {\n super(message);\n }\n}\n\n/**\n * Assertion error that should never be retried.\n * Use for programming errors and invariant violations.\n *\n * ACTION: Review the assertion failure message to identify the bug\n * in the event payload or subscriber logic.\n */\nexport class EventAssertionError extends Error {\n declare readonly name: string;\n\n readonly description =\n 'An event assertion failed, indicating a programming error or invariant violation. ' +\n 'ACTION: Review the assertion failure message to identify the bug in the ' +\n 'event payload or subscriber logic. These errors are never retried and go ' +\n 'directly to the dead-letter queue.';\n\n constructor(message: string) {\n super(message);\n this.name = 'EventAssertionError';\n Object.defineProperty(this, 'name', {\n value: 'EventAssertionError',\n enumerable: true,\n configurable: false,\n writable: false,\n });\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n description: this.description,\n stack: this.stack,\n };\n }\n}\n\n/**\n * Checks if an error forces a retry.\n */\nexport function isDoRetry(error: unknown): error is DoRetry {\n return error instanceof DoRetry;\n}\n\n/**\n * Checks if an error prevents retry.\n */\nexport function isDontRetry(error: unknown): error is DontRetry {\n return error instanceof DontRetry;\n}\n\n/**\n * Checks if an error is an assertion error (never retry).\n */\nexport function isAssertionError(error: unknown): error is EventAssertionError {\n return error instanceof EventAssertionError;\n}\n","/**\n * Base class for all Matador errors.\n * All errors have a unique name that appears in monitoring tools (e.g., DataDog)\n * and a description explaining the error and actions to resolve it.\n *\n * The `name` property is automatically set to the class name for proper\n * identification in error monitoring and logging systems.\n */\nexport abstract class MatadorError extends Error {\n /**\n * Error class name (e.g., \"NotStartedError\", \"TransportNotConnectedError\").\n * This is preserved during serialization for error monitoring tools.\n */\n declare readonly name: string;\n\n /**\n * Human-readable description explaining what went wrong and\n * what ACTION the user should take to resolve the issue.\n */\n abstract readonly description: string;\n\n constructor(message: string) {\n super(message);\n this.name = this.constructor.name;\n // Ensure name is preserved when serialized\n Object.defineProperty(this, 'name', {\n value: this.constructor.name,\n enumerable: true,\n configurable: false,\n writable: false,\n });\n }\n\n /**\n * Returns a serializable representation for logging/monitoring.\n */\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n description: this.description,\n stack: this.stack,\n };\n }\n}\n\n// ============================================================================\n// Lifecycle Errors\n// ============================================================================\n\n/**\n * Thrown when attempting to use Matador before calling start().\n */\nexport class NotStartedError extends MatadorError {\n readonly description =\n 'Matador has not been started. ' +\n 'ACTION: Call matador.start() before dispatching events or performing other operations. ' +\n 'Ensure start() completes successfully before using other methods.';\n\n constructor(operation = 'operation') {\n super(\n `Cannot perform ${operation}: Matador has not been started. Call start() first.`,\n );\n }\n}\n\n/**\n * Thrown when attempting to dispatch events during shutdown.\n */\nexport class ShutdownInProgressError extends MatadorError {\n readonly description =\n 'Matador is shutting down and will not accept new events. ' +\n 'ACTION: Do not dispatch events after calling shutdown(). ' +\n 'If you need to send events, do so before initiating shutdown. ' +\n 'Consider implementing a pre-shutdown event flush if needed.';\n\n constructor() {\n super('Cannot dispatch events: Matador is shutting down.');\n }\n}\n\n// ============================================================================\n// Transport Errors\n// ============================================================================\n\n/**\n * Thrown when a transport operation is attempted but the transport is not connected.\n */\nexport class TransportNotConnectedError extends MatadorError {\n readonly description =\n 'The transport is not connected to the message broker. ' +\n 'ACTION: Ensure the transport is connected by calling transport.connect() or matador.start(). ' +\n 'Check that the broker (e.g., RabbitMQ) is running and accessible. ' +\n 'Verify connection settings (URL, credentials, network access).';\n\n constructor(\n public readonly transportName: string,\n operation = 'operation',\n ) {\n super(\n `Cannot perform ${operation}: Transport \"${transportName}\" is not connected. ` +\n `Ensure connect() was called and the broker is accessible.`,\n );\n }\n}\n\n/**\n * Thrown when the transport has been closed (during shutdown).\n */\nexport class TransportClosedError extends MatadorError {\n readonly description =\n 'The transport has been closed and will not accept new operations. ' +\n 'ACTION: This typically occurs during application shutdown. ' +\n 'If unexpected, check for early shutdown triggers. ' +\n 'Events sent after transport closure will be lost.';\n\n constructor(public readonly transportName: string) {\n super(\n `Transport \"${transportName}\" has been closed and will not accept new operations.`,\n );\n }\n}\n\n/**\n * Thrown when all transports in a fallback chain fail.\n */\nexport class AllTransportsFailedError extends MatadorError {\n readonly description =\n 'All transports failed to send the message. ' +\n 'ACTION: Check the health of all configured transports (primary and fallbacks). ' +\n 'Review the errors array for specific failure reasons. ' +\n 'Ensure at least one transport is properly configured and reachable. ' +\n 'Consider adding a LocalTransport as a last-resort fallback.';\n\n constructor(\n public readonly queue: string,\n public readonly errors: readonly Error[],\n ) {\n super(\n `All transports failed to send message to queue \"${queue}\". ` +\n `Errors: ${errors.map((e) => e.message).join('; ')}`,\n );\n }\n}\n\n/**\n * Thrown when sending a message to the transport fails.\n */\nexport class TransportSendError extends MatadorError {\n readonly description =\n 'Failed to send a message through the transport. ' +\n 'ACTION: Check the underlying error for details. Common causes: ' +\n '(1) Transport disconnected during send, ' +\n '(2) Network issues between application and broker, ' +\n '(3) Broker rejected the message (size, permissions, queue limits). ' +\n 'The message was NOT delivered and should be retried or logged.';\n\n constructor(\n public readonly queue: string,\n public readonly cause: Error,\n ) {\n super(`Failed to send message to queue \"${queue}\": ${cause.message}`);\n }\n\n override toJSON(): Record<string, unknown> {\n return {\n ...super.toJSON(),\n queue: this.queue,\n cause: {\n name: this.cause.name,\n message: this.cause.message,\n },\n };\n }\n}\n\n/**\n * Thrown when delayed messages are requested but the plugin is not available.\n */\nexport class DelayedMessagesNotSupportedError extends MatadorError {\n readonly description =\n 'Delayed messages were requested but the transport does not support them. ' +\n 'ACTION: For RabbitMQ, install the rabbitmq_delayed_message_exchange plugin. ' +\n 'Run: rabbitmq-plugins enable rabbitmq_delayed_message_exchange ' +\n 'Then restart RabbitMQ and reconnect. ' +\n 'Alternatively, remove delayMs from your event options if delays are not required.';\n\n constructor(public readonly transportName: string) {\n super(\n `Delayed messages require the RabbitMQ delayed message exchange plugin. ` +\n `Install rabbitmq_delayed_message_exchange or remove delayMs from event options.`,\n );\n }\n}\n\n// ============================================================================\n// Schema & Configuration Errors\n// ============================================================================\n\n/**\n * Thrown when an event is not registered in the schema.\n */\nexport class EventNotRegisteredError extends MatadorError {\n readonly description =\n 'The event type is not registered in the schema. ' +\n 'ACTION: Register the event using matador.register(EventClass, subscribers) before dispatching. ' +\n 'If this occurs during message consumption, it may indicate schema drift between services. ' +\n 'Ensure all services have matching schema registrations for shared events.';\n\n constructor(public readonly eventKey: string) {\n super(\n `Event \"${eventKey}\" is not registered in schema. ` +\n `Register it using matador.register(EventClass, subscribers).`,\n );\n }\n}\n\n/**\n * Thrown when a subscriber is not found for an event.\n */\nexport class SubscriberNotRegisteredError extends MatadorError {\n readonly description =\n 'The subscriber is not registered for this event in the schema. ' +\n 'ACTION: Ensure the subscriber is included in the registration for this event. ' +\n 'This may occur if: (1) The subscriber was removed from the schema but messages still exist, ' +\n '(2) Schema drift between producer and consumer services, ' +\n '(3) A deployment is in progress with different schema versions. ' +\n 'Check the dead-letter queue for affected messages.';\n\n constructor(\n public readonly subscriberName: string,\n public readonly eventKey?: string,\n ) {\n super(\n `Subscriber \"${subscriberName}\" is not registered` +\n (eventKey ? ` for event \"${eventKey}\"` : '') +\n '. Check schema registration.',\n );\n }\n}\n\n/**\n * Thrown when no subscribers exist for an event during fanout.\n */\nexport class NoSubscribersExistError extends MatadorError {\n readonly description =\n 'The event has no subscribers registered. ' +\n 'ACTION: Register at least one subscriber for this event type. ' +\n 'If subscribers were intentionally removed, consider also removing the event dispatch. ' +\n 'Events without subscribers are not useful and may indicate configuration issues.';\n\n constructor(public readonly eventKey: string) {\n super(\n `No subscribers registered for event \"${eventKey}\". ` +\n `Add subscribers using matador.register(EventClass, [subscriber1, subscriber2]).`,\n );\n }\n}\n\n/**\n * Thrown when the schema configuration is invalid.\n */\nexport class InvalidSchemaError extends MatadorError {\n readonly description =\n 'The schema configuration is invalid. ' +\n 'ACTION: Review the schema registration for issues. Common problems: ' +\n '(1) Duplicate subscriber names for the same event, ' +\n '(2) Missing required fields on event class (key, description), ' +\n '(3) Invalid alias configuration. ' +\n 'Check the cause property for specific details.';\n\n constructor(\n message: string,\n public readonly cause?: string,\n ) {\n super(`Invalid schema: ${message}` + (cause ? `. Cause: ${cause}` : ''));\n }\n}\n\n/**\n * Thrown when a subscriber is a stub but is being processed locally.\n */\nexport class SubscriberIsStubError extends MatadorError {\n readonly description =\n 'A SubscriberStub was registered in a consuming schema. ' +\n 'ACTION: SubscriberStubs should only be used in producer schemas to declare ' +\n 'that a subscriber exists in another service. ' +\n 'In the consumer service, provide a full Subscriber with a callback function. ' +\n 'Remove the stub from the consumer schema and add the actual implementation.';\n\n constructor(public readonly subscriberName: string) {\n super(\n `Subscriber \"${subscriberName}\" is a stub and cannot be processed locally. ` +\n `Replace with a full Subscriber implementation in the consumer schema.`,\n );\n }\n}\n\n/**\n * Thrown when a LocalTransport tries to process a stub subscriber.\n */\nexport class LocalTransportCannotProcessStubError extends MatadorError {\n readonly description =\n 'The LocalTransport cannot process events for SubscriberStubs. ' +\n 'ACTION: SubscriberStubs represent remote implementations that only RabbitMQ can route. ' +\n 'If using LocalTransport for testing, provide mock implementations instead of stubs. ' +\n 'For production fallback scenarios, be aware that stub-targeted events will be dropped.';\n\n constructor(public readonly subscriberName: string) {\n super(\n `LocalTransport cannot process stub subscriber \"${subscriberName}\". ` +\n `Stub subscribers require a distributed transport like RabbitMQ.`,\n );\n }\n}\n\n// ============================================================================\n// Queue Errors\n// ============================================================================\n\n/**\n * Thrown when a queue is not found or not created.\n */\nexport class QueueNotFoundError extends MatadorError {\n readonly description =\n 'The specified queue does not exist or has not been created. ' +\n 'ACTION: Ensure the queue is defined in the topology configuration. ' +\n 'Call transport.applyTopology() or matador.start() to create queues. ' +\n 'Check that the queue name matches the topology definition.';\n\n constructor(public readonly queueName: string) {\n super(\n `Queue \"${queueName}\" not found. ` +\n `Ensure it is defined in topology and applyTopology() was called.`,\n );\n }\n}\n\n// ============================================================================\n// Event Validation Errors\n// ============================================================================\n\n/**\n * Thrown when an event is invalid or malformed.\n */\nexport class InvalidEventError extends MatadorError {\n readonly description =\n 'The event is invalid or missing required fields. ' +\n 'ACTION: Ensure the event has all required properties. ' +\n 'Common issues: missing targetSubscriber during processing, ' +\n 'null/undefined data when the event type requires data, ' +\n 'malformed event structure from codec decode failure.';\n\n constructor(\n message: string,\n public readonly cause?: string,\n ) {\n super(`Invalid event: ${message}` + (cause ? `. Cause: ${cause}` : ''));\n }\n}\n\n// ============================================================================\n// Message Processing Errors\n// ============================================================================\n\n/**\n * Thrown when a message has been redelivered too many times (poison message).\n */\nexport class MessageMaybePoisonedError extends MatadorError {\n readonly description =\n 'A message was redelivered multiple times without successful processing. ' +\n 'This usually indicates the message causes a crash or timeout during processing. ' +\n 'ACTION: (1) Check application logs for errors/crashes during message processing, ' +\n '(2) Inspect the message in the dead-letter queue for malformed data, ' +\n '(3) Review the subscriber code for bugs that cause crashes, ' +\n '(4) Consider increasing processing timeout if the operation is legitimately slow. ' +\n 'This message will NOT be retried to prevent crash loops.';\n\n constructor(\n public readonly eventId: string,\n public readonly deliveryCount: number,\n public readonly maxDeliveries: number,\n ) {\n super(\n `Message \"${eventId}\" delivered ${deliveryCount} times (max: ${maxDeliveries}). ` +\n `Possible poison message - will not be retried.`,\n );\n }\n}\n\n/**\n * Thrown when a non-idempotent message cannot be retried after redelivery.\n */\nexport class IdempotentMessageCannotRetryError extends MatadorError {\n readonly description =\n 'A non-idempotent subscriber received a redelivered message. ' +\n 'Retrying would risk duplicate side effects (e.g., double payments, duplicate emails). ' +\n 'ACTION: (1) Mark the subscriber as idempotent if it safely handles duplicates, ' +\n '(2) Implement idempotency keys in the subscriber logic, ' +\n '(3) Manually inspect and replay the message from the dead-letter queue after verification. ' +\n 'The message will be sent to the dead-letter queue for manual review.';\n\n constructor(\n public readonly eventId: string,\n public readonly subscriberName: string,\n ) {\n super(\n `Non-idempotent subscriber \"${subscriberName}\" cannot retry redelivered message \"${eventId}\". ` +\n `Mark subscriber as idempotent='yes' or implement idempotency handling.`,\n );\n }\n}\n\n// ============================================================================\n// Timeout Errors\n// ============================================================================\n\n/**\n * Thrown when an operation times out.\n */\nexport class TimeoutError extends MatadorError {\n readonly description =\n 'An operation timed out before completing. ' +\n 'ACTION: (1) Increase the timeout if the operation legitimately needs more time, ' +\n '(2) Optimize the operation to complete faster, ' +\n '(3) Check for deadlocks or blocking operations, ' +\n '(4) Verify external service dependencies are responsive.';\n\n constructor(\n public readonly operation: string,\n public readonly timeoutMs: number,\n ) {\n super(`Operation \"${operation}\" timed out after ${timeoutMs}ms.`);\n }\n}\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\nexport function isMatadorError(error: unknown): error is MatadorError {\n return error instanceof MatadorError;\n}\n\nexport function isNotStartedError(error: unknown): error is NotStartedError {\n return error instanceof NotStartedError;\n}\n\nexport function isTransportNotConnectedError(\n error: unknown,\n): error is TransportNotConnectedError {\n return error instanceof TransportNotConnectedError;\n}\n\nexport function isEventNotRegisteredError(\n error: unknown,\n): error is EventNotRegisteredError {\n return error instanceof EventNotRegisteredError;\n}\n\nexport function isSubscriberNotRegisteredError(\n error: unknown,\n): error is SubscriberNotRegisteredError {\n return error instanceof SubscriberNotRegisteredError;\n}\n\nexport function isMessageMaybePoisonedError(\n error: unknown,\n): error is MessageMaybePoisonedError {\n return error instanceof MessageMaybePoisonedError;\n}\n\nexport function isIdempotentMessageCannotRetryError(\n error: unknown,\n): error is IdempotentMessageCannotRetryError {\n return error instanceof IdempotentMessageCannotRetryError;\n}\n","import { MatadorError } from './matador-errors.js';\n\n/**\n * Thrown when a duplicate io() key is used within a single subscriber execution.\n * Each io() call must have a unique key to prevent cache collisions.\n */\nexport class DuplicateIoKeyError extends MatadorError {\n readonly description =\n 'The same io() key was used multiple times in a single subscriber execution. ' +\n 'Each io() call must have a unique key to ensure correct checkpoint behavior. ' +\n 'ACTION: Ensure all io() keys are unique within the subscriber. ' +\n 'For dynamic operations (e.g., loops), include a unique identifier in the key ' +\n '(e.g., `process-item-${item.id}`).';\n\n constructor(\n public readonly key: string,\n public readonly subscriberName: string,\n ) {\n super(\n `Duplicate io key \"${key}\" in subscriber \"${subscriberName}\". ` +\n `Each io() call must have a unique key.`,\n );\n }\n}\n\n/**\n * Thrown when checkpoint store operations fail.\n */\nexport class CheckpointStoreError extends MatadorError {\n readonly description =\n 'A checkpoint store operation failed. This may cause issues with resumable subscribers. ' +\n 'ACTION: Check the underlying storage system (Redis, etc.) for connectivity issues. ' +\n 'The subscriber may re-execute operations that were already completed.';\n\n constructor(\n public readonly operation: 'get' | 'set' | 'delete',\n public readonly envelopeId: string,\n public readonly cause: Error,\n ) {\n super(\n `Checkpoint store ${operation} failed for envelope \"${envelopeId}\": ${cause.message}`,\n );\n }\n}\n\n/**\n * Type guard for DuplicateIoKeyError.\n */\nexport function isDuplicateIoKeyError(\n error: unknown,\n): error is DuplicateIoKeyError {\n return error instanceof DuplicateIoKeyError;\n}\n\n/**\n * Type guard for CheckpointStoreError.\n */\nexport function isCheckpointStoreError(\n error: unknown,\n): error is CheckpointStoreError {\n return error instanceof CheckpointStoreError;\n}\n","/**\n * Transport-agnostic topology definition.\n * Matador owns the topology; transports translate and apply it.\n */\nexport interface Topology {\n /** Namespace prefix for all queues */\n readonly namespace: string;\n\n /** Work queues for processing events */\n readonly queues: readonly QueueDefinition[];\n\n /** Dead-letter queue configuration */\n readonly deadLetter: DeadLetterConfig;\n\n /** Retry queue configuration */\n readonly retry: RetryConfig;\n}\n\n/**\n * Individual queue definition.\n */\nexport interface QueueDefinition {\n /** Queue name (will be prefixed with namespace) */\n readonly name: string;\n\n /** Concurrency for this queue */\n readonly concurrency?: number | undefined;\n\n /** Consumer timeout in milliseconds */\n readonly consumerTimeout?: number | undefined;\n\n /** Enable priority support if transport allows */\n readonly priorities?: boolean | undefined;\n\n /**\n * When true, the queue name is used exactly as provided without any\n * modification. The namespace prefix will NOT be added, and no other\n * transformations will be applied. Use this for referencing external\n * queues that are not managed by Matador.\n */\n readonly exact?: boolean | undefined;\n}\n\n/**\n * Dead-letter queue configuration.\n */\nexport interface DeadLetterConfig {\n /** Unhandled events (schema mismatch) queue */\n readonly unhandled: DeadLetterQueueConfig;\n\n /** Undeliverable events (permanent failures) queue */\n readonly undeliverable: DeadLetterQueueConfig;\n}\n\n/**\n * Configuration for a specific dead-letter queue.\n */\nexport interface DeadLetterQueueConfig {\n /** Whether this DLQ is enabled */\n readonly enabled: boolean;\n\n /** Maximum number of messages in the DLQ */\n readonly maxLength?: number | undefined;\n}\n\n/**\n * Retry queue configuration.\n */\nexport interface RetryConfig {\n /** Enable retry queue with delay */\n readonly enabled: boolean;\n\n /** Default retry delay in milliseconds */\n readonly defaultDelayMs: number;\n\n /** Maximum retry delay in milliseconds */\n readonly maxDelayMs: number;\n}\n\n/**\n * Gets the fully qualified queue name with namespace prefix.\n */\nexport function getQualifiedQueueName(\n namespace: string,\n queueName: string,\n): string {\n return `${namespace}.${queueName}`;\n}\n\n/**\n * Gets the dead-letter queue name for a given queue.\n */\nexport function getDeadLetterQueueName(\n namespace: string,\n queueName: string,\n dlqType: 'unhandled' | 'undeliverable',\n): string {\n return `${namespace}.${queueName}.${dlqType}`;\n}\n\n/**\n * Gets the retry queue name for a given queue.\n */\nexport function getRetryQueueName(\n namespace: string,\n queueName: string,\n): string {\n return `${namespace}.${queueName}.retry`;\n}\n","import type { HasDescription } from '../errors/index.js';\nimport type {\n DeadLetterConfig,\n QueueDefinition,\n RetryConfig,\n Topology,\n} from './types.js';\n\n/**\n * Options for adding a queue.\n * Excludes 'name' as that is provided as the first argument to addQueue.\n */\nexport type QueueOptions = Omit<QueueDefinition, 'name'>;\n\n/**\n * Error thrown when topology validation fails.\n */\nexport class TopologyValidationError extends Error implements HasDescription {\n readonly description =\n 'The topology configuration is invalid. Check the issues array for ' +\n 'specific validation failures such as missing namespace, invalid queue ' +\n 'names, or conflicting settings. This error occurs during Matador ' +\n 'initialization and must be fixed in the configuration.';\n\n constructor(\n message: string,\n public readonly issues: readonly string[],\n ) {\n super(message);\n this.name = 'TopologyValidationError';\n }\n}\n\n/**\n * Fluent builder for creating Topology configurations.\n */\nexport class TopologyBuilder {\n /**\n * Creates a new TopologyBuilder instance.\n */\n static create(): TopologyBuilder {\n return new TopologyBuilder();\n }\n\n private namespace = '';\n private queues: QueueDefinition[] = [];\n private deadLetter: DeadLetterConfig = {\n unhandled: { enabled: true },\n undeliverable: { enabled: true },\n };\n private retry: RetryConfig = {\n enabled: true,\n defaultDelayMs: 1000,\n maxDelayMs: 300000, // 5 minutes\n };\n\n /**\n * Sets the namespace prefix for all queues.\n */\n withNamespace(namespace: string): this {\n this.namespace = namespace;\n return this;\n }\n\n /**\n * Adds a queue to the topology.\n */\n addQueue(name: string, options: QueueOptions = {}): this {\n this.queues.push({ name, ...options });\n return this;\n }\n\n /**\n * Alias for addQueue().\n */\n queue(name: string, options: QueueOptions = {}): this {\n return this.addQueue(name, options);\n }\n\n /**\n * Configures dead-letter queue settings.\n */\n withDeadLetter(config: Partial<DeadLetterConfig>): this {\n this.deadLetter = {\n unhandled: config.unhandled ?? this.deadLetter.unhandled,\n undeliverable: config.undeliverable ?? this.deadLetter.undeliverable,\n };\n return this;\n }\n\n /**\n * Configures retry settings.\n */\n withRetry(config: Partial<RetryConfig>): this {\n this.retry = {\n enabled: config.enabled ?? this.retry.enabled,\n defaultDelayMs: config.defaultDelayMs ?? this.retry.defaultDelayMs,\n maxDelayMs: config.maxDelayMs ?? this.retry.maxDelayMs,\n };\n return this;\n }\n\n /**\n * Disables retry functionality.\n */\n withoutRetry(): this {\n this.retry = { ...this.retry, enabled: false };\n return this;\n }\n\n /**\n * Disables dead-letter queues.\n */\n withoutDeadLetter(): this {\n this.deadLetter = {\n unhandled: { enabled: false },\n undeliverable: { enabled: false },\n };\n return this;\n }\n\n /**\n * Validates the topology configuration.\n */\n validate(): readonly string[] {\n const issues: string[] = [];\n\n if (!this.namespace || this.namespace.trim() === '') {\n issues.push('Namespace is required');\n } else if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(this.namespace)) {\n issues.push(\n 'Namespace must start with a letter and contain only alphanumeric characters, underscores, and hyphens',\n );\n }\n\n if (this.queues.length === 0) {\n issues.push('At least one queue is required');\n }\n\n const queueNames = new Set<string>();\n for (const queue of this.queues) {\n if (!queue.name || queue.name.trim() === '') {\n issues.push('Queue name cannot be empty');\n } else if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(queue.name)) {\n issues.push(\n `Queue name \"${queue.name}\" must start with a letter and contain only alphanumeric characters, underscores, and hyphens`,\n );\n } else if (queueNames.has(queue.name)) {\n issues.push(`Duplicate queue name: \"${queue.name}\"`);\n } else {\n queueNames.add(queue.name);\n }\n\n if (queue.concurrency !== undefined && queue.concurrency < 1) {\n issues.push(`Queue \"${queue.name}\" concurrency must be at least 1`);\n }\n\n if (queue.consumerTimeout !== undefined && queue.consumerTimeout < 0) {\n issues.push(\n `Queue \"${queue.name}\" consumer timeout must be non-negative`,\n );\n }\n }\n\n if (this.retry.enabled) {\n if (this.retry.defaultDelayMs < 0) {\n issues.push('Default retry delay must be non-negative');\n }\n if (this.retry.maxDelayMs < this.retry.defaultDelayMs) {\n issues.push(\n 'Max retry delay must be greater than or equal to default delay',\n );\n }\n }\n\n return issues;\n }\n\n /**\n * Builds the topology configuration.\n * @throws TopologyValidationError if validation fails\n */\n build(): Topology {\n const issues = this.validate();\n if (issues.length > 0) {\n throw new TopologyValidationError(\n `Invalid topology: ${issues.join('; ')}`,\n issues,\n );\n }\n\n return {\n namespace: this.namespace,\n queues: [...this.queues],\n deadLetter: this.deadLetter,\n retry: this.retry,\n };\n }\n}\n","/**\n * Delivery semantics for message processing.\n * - 'at-least-once': Acknowledge after processing (may redeliver on failure)\n * - 'at-most-once': Acknowledge before processing (no redelivery, may lose messages)\n */\nexport type DeliveryMode = 'at-least-once' | 'at-most-once';\n\n/**\n * Importance level for subscribers, used for monitoring and alerting prioritization.\n */\nexport type Importance =\n | 'can-ignore'\n | 'should-investigate'\n | 'must-investigate';\n\n/**\n * Idempotency declaration for subscribers.\n * - 'yes': Safe to retry on failure (subscriber handles duplicates)\n * - 'no': Not safe to retry, may cause duplicate side effects\n * - 'unknown': Idempotency not determined (default)\n * - 'resumable': Uses checkpoint-based idempotency via io() calls\n */\nexport type Idempotency = 'yes' | 'no' | 'unknown' | 'resumable';\n\n/**\n * Result of a validation operation.\n */\nexport interface ValidationResult {\n readonly valid: boolean;\n readonly errors: readonly ValidationError[];\n}\n\n/**\n * Individual validation error.\n */\nexport interface ValidationError {\n readonly path: string;\n readonly message: string;\n}\n\n/**\n * Creates a successful validation result.\n */\nexport function validResult(): ValidationResult {\n return { valid: true, errors: [] };\n}\n\n/**\n * Creates a failed validation result.\n */\nexport function invalidResult(errors: ValidationError[]): ValidationResult {\n return { valid: false, errors };\n}\n","import type { Importance } from './common.js';\n\n/**\n * Message envelope containing the event data and routing/observability metadata.\n * This is the transport-agnostic message format used throughout Matador.\n */\nexport interface Envelope<T = unknown> {\n /** Unique message ID (UUID v4) */\n readonly id: string;\n\n /** The event data */\n readonly data: T;\n\n /** Routing, processing state, and observability metadata */\n readonly docket: Docket;\n}\n\n/**\n * Metadata associated with an envelope for routing, processing state, and observability.\n */\nexport interface Docket {\n // === Routing ===\n\n /** Event key for routing */\n readonly eventKey: string;\n\n /** Human-readable description of the event (for observability/logging) */\n readonly eventDescription?: string | undefined;\n\n /** Target subscriber name for 1:1 routing */\n readonly targetSubscriber: string;\n\n /** Original queue before any dead-letter routing */\n originalQueue?: string | undefined;\n\n /** Scheduled processing time for delayed messages (ISO 8601 string) */\n scheduledFor?: string | undefined;\n\n // === Processing State ===\n\n /**\n * Attempt counter managed by Matador (1-based).\n * Incremented on each retry. Used when transport doesn't track attempts.\n */\n attempts: number;\n\n /** When the envelope was first created (ISO 8601 string) */\n readonly createdAt: string;\n\n /** Error message from first failure (for debugging) */\n firstError?: string | undefined;\n\n /** Error message from most recent failure */\n lastError?: string | undefined;\n\n // === Observability ===\n\n /** Importance level for monitoring */\n readonly importance: Importance;\n\n /** Correlation ID for request tracing */\n readonly correlationId?: string | undefined;\n\n /**\n * Custom metadata provided by the application.\n * This is the merged result of universal metadata (from loadUniversalMetadata hook)\n * and event-specific metadata (from dispatch options). Event-specific metadata\n * overrides universal metadata when keys conflict.\n */\n readonly metadata?: Record<string, unknown> | undefined;\n}\n\n/**\n * Fields from Docket that can be specified when creating an envelope.\n */\ntype DocketCreateFields = Pick<\n Docket,\n | 'eventKey'\n | 'eventDescription'\n | 'targetSubscriber'\n | 'importance'\n | 'correlationId'\n>;\n\n/**\n * Options for creating an envelope.\n */\nexport interface CreateEnvelopeOptions<T> extends DocketCreateFields {\n /** Optional custom ID (defaults to UUID v4) */\n readonly id?: string | undefined;\n\n /** The event data */\n readonly data: T;\n\n /**\n * Event-specific metadata to include in the docket.\n * Will be merged with universal metadata, with these values taking precedence.\n */\n readonly metadata?: Record<string, unknown> | undefined;\n\n /**\n * Universal metadata loaded from the loadUniversalMetadata hook.\n * This is provided by the fanout engine, not by the caller.\n * @internal\n */\n readonly universalMetadata?: Record<string, unknown> | undefined;\n\n /** Delay processing by this many milliseconds */\n readonly delayMs?: number | undefined;\n}\n\n/**\n * Creates a new envelope with the provided options.\n */\nexport function createEnvelope<T>(\n options: CreateEnvelopeOptions<T>,\n): Envelope<T> {\n const now = new Date().toISOString();\n\n // Merge universal metadata with event-specific metadata\n // Event-specific metadata takes precedence\n const mergedMetadata =\n options.universalMetadata || options.metadata\n ? { ...options.universalMetadata, ...options.metadata }\n : undefined;\n\n return {\n id: options.id ?? crypto.randomUUID(),\n data: options.data,\n docket: {\n // Routing\n eventKey: options.eventKey,\n ...(options.eventDescription !== undefined && {\n eventDescription: options.eventDescription,\n }),\n targetSubscriber: options.targetSubscriber,\n ...(options.delayMs !== undefined &&\n options.delayMs > 0 && {\n scheduledFor: new Date(Date.now() + options.delayMs).toISOString(),\n }),\n // Processing state\n attempts: 1,\n createdAt: now,\n // Observability\n importance: options.importance,\n ...(options.correlationId !== undefined && {\n correlationId: options.correlationId,\n }),\n ...(mergedMetadata !== undefined && { metadata: mergedMetadata }),\n },\n };\n}\n","/**\n * Unique event routing key type alias.\n */\nexport type EventKey = string;\n\n/**\n * JSON-serializable primitive types.\n */\nexport type JsonPrimitive = string | number | boolean | null;\n\n/**\n * JSON-serializable value (recursive type for objects and arrays).\n */\nexport type JsonValue =\n | JsonPrimitive\n | JsonValue[]\n | { [key: string]: JsonValue };\n\n/**\n * JSON-serializable record type for metadata.\n */\nexport type JsonRecord = Record<string, JsonValue>;\n\n/**\n * Static properties required on Event classes for schema registration.\n */\nexport interface EventStatic<T = unknown> {\n /** Unique routing key for the event */\n readonly key: string;\n\n /** Human-readable description of the event */\n readonly description?: string;\n\n /** Alternative names/keys for backwards compatibility */\n readonly aliases?: readonly string[];\n\n /** Create an instance from data (for deserialization) */\n new (data: T): Event<T>;\n}\n\n/**\n * Base interface for all events.\n * Events represent something that happened in the system.\n */\nexport interface Event<T = unknown> {\n /** The event data/payload */\n readonly data: T;\n\n /** Event-specific metadata (merged with EventOptions metadata on dispatch) */\n readonly metadata?: JsonRecord | undefined;\n}\n\n/**\n * Options for dispatching an event.\n */\nexport interface EventOptions {\n /** Delay processing by this many milliseconds */\n readonly delayMs?: number | undefined;\n\n /** Correlation ID for request tracing */\n readonly correlationId?: string | undefined;\n\n /**\n * Event-specific metadata to include in the docket.\n * This metadata will be merged with:\n * 1. Event instance metadata (if defined on the event)\n * 2. Universal metadata from the loadUniversalMetadata hook\n * With EventOptions metadata taking precedence over event metadata,\n * and both taking precedence over universal metadata.\n */\n readonly metadata?: JsonRecord | undefined;\n}\n\n/**\n * Abstract base class for creating Matador events.\n * Extend this class to define custom events.\n *\n * @example\n * ```typescript\n * class UserCreatedEvent extends MatadorEvent {\n * static readonly key = 'user.created'\n * static readonly description = 'Fired when a new user is created'\n *\n * constructor(\n * public data: { userId: string; email: string },\n * public metadata?: JsonRecord,\n * ) {\n * super()\n * }\n * }\n * ```\n */\nexport abstract class MatadorEvent<T = unknown> implements Event<T> {\n static readonly key: string;\n static readonly description?: string;\n static readonly aliases?: readonly string[];\n\n /** The event data/payload - must be defined by subclass */\n abstract readonly data: T;\n\n /** Event-specific metadata */\n readonly metadata?: JsonRecord | undefined;\n}\n\n/**\n * Type helper to extract the data type from an event class.\n */\nexport type EventData<E extends Event<unknown>> = E extends Event<infer T>\n ? T\n : never;\n\n/**\n * Type helper to get the event class type.\n */\nexport type EventClass<T = unknown> = EventStatic<T> &\n (new (\n data: T,\n ) => Event<T>);\n","import type { SubscriberContext } from '../checkpoint/index.js';\nimport type { Idempotency, Importance } from './common.js';\nimport type { Envelope } from './envelope.js';\nimport type { MatadorEvent } from './event.js';\n\n/**\n * Helper type to get the envelope type for a subscriber callback.\n * Extracts the data type from a MatadorEvent and wraps it in an Envelope.\n *\n * @example\n * async callback(envelope: EnvelopeOf<MyEvent>) {\n * console.log(envelope.data.someField); // Type-safe access\n * }\n */\nexport type EnvelopeOf<T extends MatadorEvent> = Envelope<T['data']>;\n\n/**\n * Callback function executed when an event is received (standard subscribers).\n * Receives the full envelope containing id, data, and docket.\n */\nexport type StandardCallback<T = unknown> = (\n envelope: Envelope<T>,\n) => Promise<void> | void;\n\n/**\n * Callback function for resumable subscribers.\n * Receives the envelope and a SubscriberContext with io() for checkpointed operations.\n */\nexport type ResumableCallback<T = unknown> = (\n envelope: Envelope<T>,\n context: SubscriberContext,\n) => Promise<void> | void;\n\n/**\n * Callback function executed when an event is received.\n * @deprecated Use StandardCallback or ResumableCallback instead.\n */\nexport type SubscriberCallback<T = unknown> = StandardCallback<T>;\n\n/**\n * Base configuration options shared by all subscriber types.\n */\nexport interface BaseSubscriberOptions {\n /** Human-readable description of what this subscriber does */\n readonly description: string;\n\n /** Route this subscriber's events to a specific queue */\n readonly targetQueue?: string | undefined;\n\n /** Importance level for monitoring and alerting */\n readonly importance?: Importance | undefined;\n\n /** Feature flag function to conditionally enable/disable the subscriber */\n readonly enabled?: (() => boolean | Promise<boolean>) | undefined;\n}\n\n/**\n * Options for standard (non-resumable) subscribers.\n */\nexport interface StandardSubscriberOptions extends BaseSubscriberOptions {\n /** Idempotency declaration for retry handling (non-resumable) */\n readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;\n}\n\n/**\n * Options for resumable subscribers that use io() for checkpointed operations.\n */\nexport interface ResumableSubscriberOptions extends BaseSubscriberOptions {\n /** Must be 'resumable' to enable checkpoint-based idempotency */\n readonly idempotent: 'resumable';\n}\n\n/**\n * Configuration options for a subscriber.\n * Discriminated union based on idempotent value.\n */\nexport type SubscriberOptions =\n | StandardSubscriberOptions\n | ResumableSubscriberOptions;\n\n/**\n * Standard subscriber definition with standard callback.\n */\nexport interface StandardSubscriber<T extends MatadorEvent>\n extends StandardSubscriberOptions {\n /** Human-readable name for the subscriber */\n readonly name: string;\n\n /** Callback function to execute when event is received */\n readonly callback: StandardCallback<T['data']>;\n}\n\n/**\n * Resumable subscriber definition with resumable callback.\n */\nexport interface ResumableSubscriber<T extends MatadorEvent>\n extends ResumableSubscriberOptions {\n /** Human-readable name for the subscriber */\n readonly name: string;\n\n /** Callback function with SubscriberContext for checkpointed operations */\n readonly callback: ResumableCallback<T['data']>;\n}\n\n/**\n * Full subscriber definition with callback (either standard or resumable).\n */\nexport type Subscriber<T extends MatadorEvent> =\n | StandardSubscriber<T>\n | ResumableSubscriber<T>;\n\n/**\n * Subscriber stub for multi-codebase scenarios where subscriber implementation\n * is in a remote service. Declares the subscriber contract without providing\n * the callback.\n */\nexport interface SubscriberStub extends StandardSubscriberOptions {\n /** Human-readable name for the subscriber */\n readonly name: string;\n\n /** Indicates this is a stub without implementation */\n readonly isStub: true;\n}\n\n/**\n * Union type for any subscriber definition (full or stub).\n * This is the type-erased version for use in collections and schema.\n * Uses `any` because Subscriber<T> is contravariant in T (callback parameter),\n * making it impossible to assign Subscriber<SpecificEvent> to Subscriber<MatadorEvent<unknown>>.\n */\n// biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility in heterogeneous collections\nexport type AnySubscriber = Subscriber<MatadorEvent<any>> | SubscriberStub;\n\n/**\n * Type guard to check if a subscriber is a stub.\n */\nexport function isSubscriberStub(\n subscriber: AnySubscriber,\n): subscriber is SubscriberStub {\n return 'isStub' in subscriber && subscriber.isStub === true;\n}\n\n/**\n * Type guard to check if a subscriber has a callback implementation.\n */\nexport function isSubscriber(\n subscriber: AnySubscriber,\n // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility\n): subscriber is Subscriber<MatadorEvent<any>> {\n return 'callback' in subscriber && typeof subscriber.callback === 'function';\n}\n\n/**\n * Type guard to check if a subscriber is resumable.\n */\nexport function isResumableSubscriber(\n subscriber: AnySubscriber,\n // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility\n): subscriber is ResumableSubscriber<MatadorEvent<any>> {\n return isSubscriber(subscriber) && subscriber.idempotent === 'resumable';\n}\n\n/**\n * Type guard to check if a subscriber is a standard (non-resumable) subscriber.\n */\nexport function isStandardSubscriber(\n subscriber: AnySubscriber,\n // biome-ignore lint/suspicious/noExplicitAny: Required for variance compatibility\n): subscriber is StandardSubscriber<MatadorEvent<any>> {\n return isSubscriber(subscriber) && subscriber.idempotent !== 'resumable';\n}\n\n/**\n * Input options for createSubscriber with standard callback.\n */\nexport interface CreateStandardSubscriberInput<T extends MatadorEvent> {\n readonly name: string;\n readonly description: string;\n readonly callback: StandardCallback<T['data']>;\n readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;\n readonly importance?: Importance | undefined;\n readonly targetQueue?: string | undefined;\n readonly enabled?: (() => boolean | Promise<boolean>) | undefined;\n}\n\n/**\n * Input options for createSubscriber with resumable callback.\n */\nexport interface CreateResumableSubscriberInput<T extends MatadorEvent> {\n readonly name: string;\n readonly description: string;\n readonly callback: ResumableCallback<T['data']>;\n readonly idempotent: 'resumable';\n readonly importance?: Importance | undefined;\n readonly targetQueue?: string | undefined;\n readonly enabled?: (() => boolean | Promise<boolean>) | undefined;\n}\n\n/**\n * Input options for createSubscriber (discriminated union).\n */\nexport type CreateSubscriberInput<T extends MatadorEvent> =\n | CreateStandardSubscriberInput<T>\n | CreateResumableSubscriberInput<T>;\n\n/**\n * Creates a subscriber definition.\n *\n * @example Standard subscriber\n * ```typescript\n * const subscriber = createSubscriber<MyEvent>({\n * name: 'my-subscriber',\n * description: 'Handles MyEvent by logging the data',\n * callback: async (envelope) => {\n * console.log(envelope.data);\n * },\n * });\n * ```\n *\n * @example Resumable subscriber with io()\n * ```typescript\n * const subscriber = createSubscriber<MyEvent>({\n * name: 'my-resumable-subscriber',\n * description: 'Processes MyEvent with checkpoint-based idempotency',\n * idempotent: 'resumable',\n * callback: async (envelope, { io }) => {\n * await io('step-1', () => doSomething());\n * },\n * });\n * ```\n */\nexport function createSubscriber<T extends MatadorEvent>(\n input: CreateSubscriberInput<T>,\n): Subscriber<T> {\n const base = {\n name: input.name,\n description: input.description,\n callback: input.callback,\n importance: input.importance ?? 'should-investigate',\n ...(input.targetQueue !== undefined && {\n targetQueue: input.targetQueue,\n }),\n ...(input.enabled !== undefined && { enabled: input.enabled }),\n };\n\n if (input.idempotent === 'resumable') {\n return {\n ...base,\n idempotent: 'resumable',\n callback: input.callback,\n } as ResumableSubscriber<T>;\n }\n\n return {\n ...base,\n idempotent: input.idempotent ?? 'unknown',\n callback: input.callback,\n } as StandardSubscriber<T>;\n}\n\n/**\n * Input options for createSubscriberStub.\n */\nexport interface CreateSubscriberStubInput {\n readonly name: string;\n readonly description: string;\n readonly idempotent?: 'yes' | 'no' | 'unknown' | undefined;\n readonly importance?: Importance | undefined;\n readonly targetQueue?: string | undefined;\n readonly enabled?: (() => boolean | Promise<boolean>) | undefined;\n}\n\n/**\n * Creates a subscriber stub for remote implementations.\n *\n * @example\n * ```typescript\n * const stub = createSubscriberStub({\n * name: 'remote-analytics',\n * description: 'Sends events to remote analytics service',\n * targetQueue: 'analytics-worker',\n * });\n * ```\n */\nexport function createSubscriberStub(\n input: CreateSubscriberStubInput,\n): SubscriberStub {\n return {\n name: input.name,\n description: input.description,\n isStub: true,\n idempotent: input.idempotent ?? 'unknown',\n importance: input.importance ?? 'should-investigate',\n ...(input.targetQueue !== undefined && {\n targetQueue: input.targetQueue,\n }),\n ...(input.enabled !== undefined && { enabled: input.enabled }),\n };\n}\n\n/**\n * Definition interface used by the pipeline (excludes event class reference).\n */\nexport interface SubscriberDefinition {\n readonly name: string;\n readonly description: string;\n readonly idempotent: Idempotency;\n readonly importance: Importance;\n readonly targetQueue?: string | undefined;\n}\n","import { TransportSendError } from '../errors/index.js';\nimport type { SafeHooks } from '../hooks/index.js';\nimport type { SchemaRegistry } from '../schema/index.js';\nimport { getQualifiedQueueName } from '../topology/index.js';\nimport type { Transport } from '../transport/index.js';\nimport type {\n AnySubscriber,\n Event,\n EventClass,\n EventOptions,\n} from '../types/index.js';\nimport { createEnvelope } from '../types/index.js';\n\n/**\n * Configuration for the fanout engine.\n */\nexport interface FanoutConfig {\n readonly transport: Transport;\n readonly schema: SchemaRegistry;\n readonly hooks: SafeHooks;\n readonly namespace: string;\n readonly defaultQueue: string;\n}\n\n/**\n * Result of sending an event.\n */\nexport interface SendResult {\n readonly eventKey: string;\n readonly subscribersSent: number;\n readonly subscribersSkipped: number;\n readonly errors: readonly SendError[];\n}\n\n/**\n * Error during send.\n */\nexport interface SendError {\n readonly subscriberName: string;\n readonly queue: string;\n readonly error: Error;\n}\n\n/**\n * Engine for fanning out events to subscribers.\n *\n * Handles:\n * 1. Getting subscribers from schema\n * 2. Filtering by enabled() hook\n * 3. Creating envelopes for each subscriber\n * 4. Sending to appropriate queues via transport\n */\nexport class FanoutEngine {\n private readonly transport: Transport;\n private readonly schema: SchemaRegistry;\n private readonly hooks: SafeHooks;\n private readonly namespace: string;\n private readonly defaultQueue: string;\n private enqueuingCount = 0;\n\n constructor(config: FanoutConfig) {\n this.transport = config.transport;\n this.schema = config.schema;\n this.hooks = config.hooks;\n this.namespace = config.namespace;\n this.defaultQueue = config.defaultQueue;\n }\n\n /**\n * Current count of events being enqueued.\n */\n get eventsBeingEnqueuedCount(): number {\n return this.enqueuingCount;\n }\n\n /**\n * Sends an event to all registered subscribers.\n */\n async send<T>(\n eventClass: EventClass<T>,\n event: Event<T>,\n options: EventOptions = {},\n ): Promise<SendResult> {\n const eventKey = eventClass.key;\n const subscribers = this.schema.getSubscribers(eventKey);\n\n const errors: SendError[] = [];\n let sent = 0;\n let skipped = 0;\n\n // Load universal metadata\n const universalMetadata = await this.hooks.loadUniversalMetadata();\n\n // Merge event.metadata with options.metadata (options takes precedence)\n const mergedMetadata =\n event.metadata || options.metadata\n ? { ...event.metadata, ...options.metadata }\n : undefined;\n\n for (const subscriber of subscribers) {\n // Check if subscriber is enabled\n const enabled = await this.isSubscriberEnabled(subscriber);\n if (!enabled) {\n skipped++;\n continue;\n }\n\n // Determine target queue\n const targetQueue = subscriber.targetQueue ?? this.defaultQueue;\n const qualifiedQueue = getQualifiedQueueName(this.namespace, targetQueue);\n\n // Create envelope\n const envelope = createEnvelope({\n eventKey,\n eventDescription: eventClass.description,\n targetSubscriber: subscriber.name,\n data: event.data,\n importance: subscriber.importance ?? 'should-investigate',\n correlationId: options.correlationId,\n metadata: mergedMetadata,\n universalMetadata,\n delayMs: options.delayMs,\n });\n\n // Send to transport\n this.enqueuingCount++;\n try {\n const usedTransport = await this.transport.send(\n qualifiedQueue,\n envelope,\n options.delayMs !== undefined\n ? { delay: options.delayMs }\n : undefined,\n );\n sent++;\n\n await this.hooks.onEnqueueSuccess({\n envelope,\n queue: qualifiedQueue,\n transport: usedTransport,\n });\n } catch (error) {\n const cause = error instanceof Error ? error : new Error(String(error));\n const err = new TransportSendError(qualifiedQueue, cause);\n errors.push({\n subscriberName: subscriber.name,\n queue: qualifiedQueue,\n error: err,\n });\n\n await this.hooks.onEnqueueError({\n envelope,\n error: err,\n transport: this.transport.name,\n });\n } finally {\n this.enqueuingCount--;\n }\n }\n\n return {\n eventKey,\n subscribersSent: sent,\n subscribersSkipped: skipped,\n errors,\n };\n }\n\n private async isSubscriberEnabled(\n subscriber: AnySubscriber,\n ): Promise<boolean> {\n if (!subscriber.enabled) {\n return true;\n }\n\n try {\n const result = await subscriber.enabled();\n return result;\n } catch {\n // If enabled check fails, consider it enabled\n return true;\n }\n }\n}\n","import type {\n CheckpointClearedContext,\n CheckpointHitContext,\n CheckpointLoadedContext,\n CheckpointMissContext,\n} from '../checkpoint/index.js';\nimport type { RetryDecision } from '../retry/index.js';\nimport type { ConnectionState, Transport } from '../transport/index.js';\nimport type { Envelope, SubscriberDefinition } from '../types/index.js';\n\n/**\n * Logger interface for Matador internal logging.\n */\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n}\n\n/**\n * Default logger that uses console.\n */\nexport const consoleLogger: Logger = {\n debug: (message, ...args) => console.debug(message, ...args),\n info: (message, ...args) => console.info(message, ...args),\n warn: (message, ...args) => console.warn(message, ...args),\n error: (message, ...args) => console.error(message, ...args),\n};\n\n/**\n * Context for enqueue success hook.\n */\nexport interface EnqueueSuccessContext {\n readonly envelope: Envelope;\n readonly queue: string;\n /** The transport that was used (e.g., 'local', 'rabbitmq') */\n readonly transport: string;\n}\n\n/**\n * Context for enqueue warning hook (fallback used).\n */\nexport interface EnqueueWarningContext {\n readonly envelope: Envelope;\n readonly originalQueue: string;\n readonly fallbackQueue: string;\n readonly error: Error;\n}\n\n/**\n * Context for transport fallback hook.\n */\nexport interface TransportFallbackContext {\n /** The envelope that was being sent */\n readonly envelope: Envelope;\n /** The queue the message was being sent to */\n readonly queue: string;\n /** The transport that failed */\n readonly failedTransport: Transport['name'];\n /** The transport that will be tried next */\n readonly nextTransport: Transport['name'];\n /** The error from the failed transport */\n readonly error: Error;\n}\n\n/**\n * Context for enqueue error hook.\n */\nexport interface EnqueueErrorContext {\n readonly envelope: Envelope;\n readonly error: Error;\n /** The transport that failed (e.g., 'local', 'rabbitmq') */\n readonly transport: string;\n}\n\n/**\n * Context for decode error hook.\n */\nexport interface DecodeErrorContext {\n readonly error: Error;\n readonly rawMessage: Uint8Array;\n readonly sourceQueue: string;\n /** The transport that received the message (e.g., 'local', 'rabbitmq') */\n readonly transport: string;\n}\n\n/**\n * Context for worker success hook.\n */\nexport interface WorkerSuccessContext {\n readonly envelope: Envelope;\n readonly subscriber: SubscriberDefinition;\n readonly result: unknown;\n readonly durationMs: number;\n /** The transport that received the message (e.g., 'local', 'rabbitmq') */\n readonly transport: string;\n}\n\n/**\n * Context for worker error hook.\n */\nexport interface WorkerErrorContext {\n readonly envelope: Envelope;\n readonly subscriber: SubscriberDefinition;\n readonly error: Error;\n readonly durationMs: number;\n readonly decision: RetryDecision;\n /** The transport that received the message (e.g., 'local', 'rabbitmq') */\n readonly transport: string;\n}\n\n/**\n * Execution function passed to onWorkerWrap for APM wrapping.\n */\nexport type WorkerExecuteFn = () => Promise<void>;\n\n/**\n * All available hooks for Matador.\n */\nexport interface MatadorHooks {\n /**\n * Logger for internal Matador logging.\n * Defaults to console logger if not provided.\n */\n logger?: Logger;\n\n /**\n * Called when an event is successfully enqueued.\n */\n onEnqueueSuccess?(context: EnqueueSuccessContext): void | Promise<void>;\n\n /**\n * Called when enqueue falls back to a secondary queue.\n */\n onEnqueueWarning?(context: EnqueueWarningContext): void | Promise<void>;\n\n /**\n * Called when transport fallback occurs during send.\n * Only fires when using MultiTransport with fallbackEnabled=true.\n */\n onTransportFallback?(context: TransportFallbackContext): void | Promise<void>;\n\n /**\n * Called when enqueue fails completely.\n */\n onEnqueueError?(context: EnqueueErrorContext): void | Promise<void>;\n\n /**\n * Wraps entire worker processing (for APM context).\n * Must call execute() to run the actual processing.\n */\n onWorkerWrap?(\n envelope: Envelope,\n subscriber: SubscriberDefinition,\n execute: WorkerExecuteFn,\n ): Promise<void>;\n\n /**\n * Called before processing begins.\n */\n onWorkerBeforeProcess?(\n envelope: Envelope,\n subscriber: SubscriberDefinition,\n ): void | Promise<void>;\n\n /**\n * Called after successful processing.\n */\n onWorkerSuccess?(context: WorkerSuccessContext): void | Promise<void>;\n\n /**\n * Called after processing error.\n */\n onWorkerError?(context: WorkerErrorContext): void | Promise<void>;\n\n /**\n * Called when message decoding fails.\n */\n onDecodeError?(context: DecodeErrorContext): void | Promise<void>;\n\n /**\n * Called when transport connection state changes.\n */\n onConnectionStateChange?(state: ConnectionState): void | Promise<void>;\n\n /**\n * Loads universal metadata to add to all envelopes.\n */\n loadUniversalMetadata?():\n | Record<string, unknown>\n | Promise<Record<string, unknown>>;\n\n /**\n * Dynamic queue concurrency lookup.\n */\n getQueueConcurrency?(\n queueName: string,\n ): number | undefined | Promise<number | undefined>;\n\n /**\n * Dynamic retry delay lookup.\n */\n getRetryDelay?(\n envelope: Envelope,\n attemptNumber: number,\n ): number | undefined | Promise<number | undefined>;\n\n /**\n * Dynamic max attempts lookup.\n */\n getAttempts?(\n envelope: Envelope,\n ): number | undefined | Promise<number | undefined>;\n\n /**\n * Dynamic max deliveries (poison threshold) lookup.\n */\n getMaxDeliveries?(\n envelope: Envelope,\n ): number | undefined | Promise<number | undefined>;\n\n // === Checkpoint Hooks (Resumable Subscribers) ===\n\n /**\n * Called when a checkpoint is loaded for a retry.\n * Only fires for resumable subscribers on retry attempts.\n */\n onCheckpointLoaded?(context: CheckpointLoadedContext): void | Promise<void>;\n\n /**\n * Called when an io() operation uses a cached value (checkpoint hit).\n * Useful for observability and metrics.\n */\n onCheckpointHit?(context: CheckpointHitContext): void | Promise<void>;\n\n /**\n * Called when an io() operation executes (cache miss).\n * Useful for observability and metrics.\n */\n onCheckpointMiss?(context: CheckpointMissContext): void | Promise<void>;\n\n /**\n * Called when a checkpoint is cleared.\n * Fires on successful completion or when moving to dead-letter queue.\n */\n onCheckpointCleared?(context: CheckpointClearedContext): void | Promise<void>;\n}\n","import type {\n CheckpointClearedContext,\n CheckpointHitContext,\n CheckpointLoadedContext,\n CheckpointMissContext,\n} from '../checkpoint/index.js';\nimport type { ConnectionState } from '../transport/index.js';\nimport type { Envelope, SubscriberDefinition } from '../types/index.js';\nimport {\n type DecodeErrorContext,\n type EnqueueErrorContext,\n type EnqueueSuccessContext,\n type EnqueueWarningContext,\n type Logger,\n type MatadorHooks,\n type WorkerErrorContext,\n type WorkerExecuteFn,\n type WorkerSuccessContext,\n consoleLogger,\n} from './types.js';\n\n/**\n * Wraps hooks with error handling to prevent hook errors from breaking processing.\n * All hooks become safe to call and will catch any errors internally.\n */\nexport class SafeHooks {\n private readonly hooks: MatadorHooks;\n\n /** The logger instance used by Matador. */\n readonly logger: Logger;\n\n constructor(hooks: MatadorHooks = {}) {\n this.hooks = hooks;\n this.logger = hooks.logger ?? consoleLogger;\n }\n\n async onEnqueueSuccess(context: EnqueueSuccessContext): Promise<void> {\n await this.safeCall('onEnqueueSuccess', () =>\n this.hooks.onEnqueueSuccess?.(context),\n );\n }\n\n async onEnqueueWarning(context: EnqueueWarningContext): Promise<void> {\n await this.safeCall('onEnqueueWarning', () =>\n this.hooks.onEnqueueWarning?.(context),\n );\n }\n\n async onEnqueueError(context: EnqueueErrorContext): Promise<void> {\n await this.safeCall('onEnqueueError', () =>\n this.hooks.onEnqueueError?.(context),\n );\n }\n\n async onWorkerWrap(\n envelope: Envelope,\n subscriber: SubscriberDefinition,\n execute: WorkerExecuteFn,\n ): Promise<void> {\n if (this.hooks.onWorkerWrap) {\n try {\n await this.hooks.onWorkerWrap(envelope, subscriber, execute);\n } catch (error) {\n this.logger.warn(\n '[Matador] 🟡 Hook onWorkerWrap threw an error',\n error,\n );\n // Still try to execute if wrap failed\n await execute();\n }\n } else {\n await execute();\n }\n }\n\n async onWorkerBeforeProcess(\n envelope: Envelope,\n subscriber: SubscriberDefinition,\n ): Promise<void> {\n await this.safeCall('onWorkerBeforeProcess', () =>\n this.hooks.onWorkerBeforeProcess?.(envelope, subscriber),\n );\n }\n\n async onWorkerSuccess(context: WorkerSuccessContext): Promise<void> {\n await this.safeCall('onWorkerSuccess', () =>\n this.hooks.onWorkerSuccess?.(context),\n );\n }\n\n async onWorkerError(context: WorkerErrorContext): Promise<void> {\n await this.safeCall('onWorkerError', () =>\n this.hooks.onWorkerError?.(context),\n );\n }\n\n async onDecodeError(context: DecodeErrorContext): Promise<void> {\n await this.safeCall('onDecodeError', () =>\n this.hooks.onDecodeError?.(context),\n );\n }\n\n async onConnectionStateChange(state: ConnectionState): Promise<void> {\n await this.safeCall('onConnectionStateChange', () =>\n this.hooks.onConnectionStateChange?.(state),\n );\n }\n\n async loadUniversalMetadata(): Promise<Record<string, unknown>> {\n if (!this.hooks.loadUniversalMetadata) {\n return {};\n }\n\n try {\n const result = await this.hooks.loadUniversalMetadata();\n return result ?? {};\n } catch (error) {\n this.logger.warn(\n '[Matador] 🟡 Hook loadUniversalMetadata threw an error',\n error,\n );\n return {};\n }\n }\n\n async getQueueConcurrency(queueName: string): Promise<number | undefined> {\n if (!this.hooks.getQueueConcurrency) {\n return undefined;\n }\n\n try {\n return await this.hooks.getQueueConcurrency(queueName);\n } catch (error) {\n this.logger.warn(\n '[Matador] 🟡 Hook getQueueConcurrency threw an error',\n error,\n );\n return undefined;\n }\n }\n\n async getRetryDelay(\n envelope: Envelope,\n attemptNumber: number,\n ): Promise<number | undefined> {\n if (!this.hooks.getRetryDelay) {\n return undefined;\n }\n\n try {\n return await this.hooks.getRetryDelay(envelope, attemptNumber);\n } catch (error) {\n this.logger.warn('[Matador] 🟡 Hook getRetryDelay threw an error', error);\n return undefined;\n }\n }\n\n async getAttempts(envelope: Envelope): Promise<number | undefined> {\n if (!this.hooks.getAttempts) {\n return undefined;\n }\n\n try {\n return await this.hooks.getAttempts(envelope);\n } catch (error) {\n this.logger.warn('[Matador] 🟡 Hook getAttempts threw an error', error);\n return undefined;\n }\n }\n\n async getMaxDeliveries(envelope: Envelope): Promise<number | undefined> {\n if (!this.hooks.getMaxDeliveries) {\n return undefined;\n }\n\n try {\n return await this.hooks.getMaxDeliveries(envelope);\n } catch (error) {\n this.logger.warn(\n '[Matador] 🟡 Hook getMaxDeliveries threw an error',\n error,\n );\n return undefined;\n }\n }\n\n // === Checkpoint Hooks ===\n\n async onCheckpointLoaded(context: CheckpointLoadedContext): Promise<void> {\n await this.safeCall('onCheckpointLoaded', () =>\n this.hooks.onCheckpointLoaded?.(context),\n );\n }\n\n async onCheckpointHit(context: CheckpointHitContext): Promise<void> {\n await this.safeCall('onCheckpointHit', () =>\n this.hooks.onCheckpointHit?.(context),\n );\n }\n\n async onCheckpointMiss(context: CheckpointMissContext): Promise<void> {\n await this.safeCall('onCheckpointMiss', () =>\n this.hooks.onCheckpointMiss?.(context),\n );\n }\n\n async onCheckpointCleared(context: CheckpointClearedContext): Promise<void> {\n await this.safeCall('onCheckpointCleared', () =>\n this.hooks.onCheckpointCleared?.(context),\n );\n }\n\n private async safeCall(\n hookName: string,\n fn: () => void | Promise<void> | undefined,\n ): Promise<void> {\n try {\n await fn();\n } catch (error) {\n this.logger.warn(`[Matador] 🟡 Hook ${hookName} threw an error`, error);\n }\n }\n}\n","import { type Logger, consoleLogger } from '../hooks/index.js';\n\n/**\n * Shutdown state.\n */\nexport type ShutdownState =\n | 'running'\n | 'stopping-receive'\n | 'waiting-handlers'\n | 'stopping-enqueue'\n | 'disconnecting'\n | 'stopped';\n\n/**\n * Configuration for shutdown manager.\n */\nexport interface ShutdownConfig {\n /** Timeout for graceful shutdown in milliseconds */\n readonly gracefulShutdownTimeout: number;\n\n /** Polling interval when waiting for handlers to idle */\n readonly idlePollingInterval: number;\n\n /** Logger for shutdown events (defaults to console) */\n readonly logger: Logger;\n}\n\n/**\n * Default shutdown configuration.\n */\nexport const defaultShutdownConfig: ShutdownConfig = {\n gracefulShutdownTimeout: 30000,\n idlePollingInterval: 1000,\n logger: consoleLogger,\n};\n\n/**\n * Handler state tracking.\n */\nexport interface HandlersState {\n readonly eventsBeingProcessed: number;\n readonly eventsBeingEnqueued: number;\n readonly isIdle: boolean;\n}\n\n/**\n * Manages graceful shutdown of Matador.\n *\n * Shutdown sequence:\n * 1. Stop receiving new messages\n * 2. Wait for in-flight processing to complete\n * 3. Stop accepting new enqueue requests\n * 4. Disconnect transport\n */\nexport class ShutdownManager {\n private _state: ShutdownState = 'running';\n private readonly config: ShutdownConfig;\n private eventsBeingProcessed = 0;\n private acceptingEnqueue = true;\n\n constructor(\n private readonly getEnqueueCount: () => number,\n private readonly stopReceiving: () => Promise<void>,\n private readonly disconnectTransport: () => Promise<void>,\n config: Partial<ShutdownConfig> = {},\n ) {\n this.config = { ...defaultShutdownConfig, ...config };\n }\n\n /**\n * Current shutdown state.\n */\n get state(): ShutdownState {\n return this._state;\n }\n\n /**\n * Whether enqueue is currently allowed.\n */\n get isEnqueueAllowed(): boolean {\n return this.acceptingEnqueue;\n }\n\n /**\n * Gets current handler state.\n */\n getHandlersState(): HandlersState {\n const eventsBeingEnqueued = this.getEnqueueCount();\n return {\n eventsBeingProcessed: this.eventsBeingProcessed,\n eventsBeingEnqueued,\n isIdle: this.eventsBeingProcessed === 0 && eventsBeingEnqueued === 0,\n };\n }\n\n /**\n * Increment processing counter.\n */\n incrementProcessing(): void {\n this.eventsBeingProcessed++;\n }\n\n /**\n * Decrement processing counter.\n */\n decrementProcessing(): void {\n this.eventsBeingProcessed--;\n }\n\n /**\n * Performs graceful shutdown.\n */\n async shutdown(): Promise<void> {\n if (this._state !== 'running') {\n return;\n }\n\n // 1. Stop receiving new messages\n this._state = 'stopping-receive';\n await this.stopReceiving();\n\n // 2. Wait for handlers to idle\n this._state = 'waiting-handlers';\n await this.waitForIdle();\n\n // 3. Stop accepting new enqueue requests\n this._state = 'stopping-enqueue';\n this.acceptingEnqueue = false;\n\n // 4. Disconnect transport\n this._state = 'disconnecting';\n await this.disconnectTransport();\n\n this._state = 'stopped';\n }\n\n /**\n * Forcefully stops without waiting.\n */\n async forceStop(): Promise<void> {\n this.acceptingEnqueue = false;\n await this.stopReceiving();\n await this.disconnectTransport();\n this._state = 'stopped';\n }\n\n private async waitForIdle(): Promise<void> {\n const deadline = Date.now() + this.config.gracefulShutdownTimeout;\n\n while (!this.getHandlersState().isIdle) {\n if (Date.now() > deadline) {\n this.config.logger.warn(\n `[Matador] ⚠️ Shutdown timeout reached with ${this.eventsBeingProcessed} events still processing`,\n );\n break;\n }\n\n await this.sleep(this.config.idlePollingInterval);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","import type { HasDescription } from '../errors/index.js';\nimport type { Envelope } from '../types/index.js';\n\n/**\n * Codec interface for serializing/deserializing envelopes.\n */\nexport interface Codec {\n /**\n * Encodes an envelope to a buffer for transport.\n */\n encode(envelope: Envelope): Uint8Array;\n\n /**\n * Decodes a buffer back to an envelope.\n * @throws Error if the buffer is invalid or cannot be decoded\n */\n decode(buffer: Uint8Array): Envelope;\n\n /**\n * MIME content type for this codec.\n */\n readonly contentType: string;\n}\n\n/**\n * Error thrown when decoding fails.\n */\nexport class CodecDecodeError extends Error implements HasDescription {\n readonly description =\n 'Failed to decode a message from the transport. This typically indicates ' +\n 'corrupted data, incompatible codec versions, or messages from a different ' +\n 'system. Check the cause property for the underlying parsing error. ' +\n 'The message will be sent to the dead-letter queue for investigation.';\n\n constructor(\n message: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = 'CodecDecodeError';\n }\n}\n","import type { Envelope } from '../types/index.js';\nimport type { Codec } from './codec.js';\nimport { CodecDecodeError } from './codec.js';\n\n/**\n * JSON codec for envelope serialization.\n * Uses standard JSON.stringify/parse with Date handling.\n */\nexport class JsonCodec implements Codec {\n readonly contentType = 'application/json';\n\n encode(envelope: Envelope): Uint8Array {\n const json = JSON.stringify(envelope);\n return new TextEncoder().encode(json);\n }\n\n decode(buffer: Uint8Array): Envelope {\n if (buffer.length === 0) {\n throw new CodecDecodeError('Cannot decode empty buffer');\n }\n\n let json: string;\n try {\n json = new TextDecoder('utf-8').decode(buffer);\n } catch (error) {\n throw new CodecDecodeError('Invalid UTF-8 encoding', error);\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(json);\n } catch (error) {\n throw new CodecDecodeError('Invalid JSON', error);\n }\n\n if (!this.isValidEnvelope(parsed)) {\n throw new CodecDecodeError('Invalid envelope structure');\n }\n\n return parsed;\n }\n\n private isValidEnvelope(value: unknown): value is Envelope {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n\n // Required top-level fields\n if (typeof envelope['id'] !== 'string') return false;\n if (!('data' in envelope)) return false;\n if (typeof envelope['docket'] !== 'object' || envelope['docket'] === null)\n return false;\n\n // Validate docket (routing, processing state, observability)\n const docket = envelope['docket'] as Record<string, unknown>;\n // Routing\n if (typeof docket['eventKey'] !== 'string') return false;\n if (typeof docket['targetSubscriber'] !== 'string') return false;\n // Processing state\n if (typeof docket['attempts'] !== 'number') return false;\n if (typeof docket['createdAt'] !== 'string') return false;\n // Observability\n if (typeof docket['importance'] !== 'string') return false;\n\n return true;\n }\n}\n","import type { Docket, Envelope } from '../types/index.js';\nimport { CodecDecodeError } from './codec.js';\nimport type { EncodedMessage, HeaderAwareCodec } from './header-aware-codec.js';\n\n/**\n * Header names used by Matador in RabbitMQ messages.\n */\nconst HEADERS = {\n // Routing\n EVENT_KEY: 'x-matador-event-key',\n TARGET_SUBSCRIBER: 'x-matador-subscriber',\n SCHEDULED_FOR: 'x-matador-scheduled-for',\n ORIGINAL_QUEUE: 'x-matador-original-queue',\n\n // Processing state\n ATTEMPTS: 'x-matador-attempts',\n CREATED_AT: 'x-matador-created-at',\n FIRST_ERROR: 'x-matador-first-error',\n LAST_ERROR: 'x-matador-last-error',\n\n // Observability\n IMPORTANCE: 'x-matador-importance',\n CORRELATION_ID: 'x-matador-correlation-id',\n\n // v1 compatibility headers\n V1_EVENT_ID: 'x-event-id',\n V1_CORRELATION_ID: 'x-correlation-id',\n V1_USER_ID: 'x-user-id',\n} as const;\n\n/**\n * Body structure for v2 messages.\n * Only contains id, data, and optionally metadata (since it can be large).\n */\ninterface V2Body {\n readonly id: string;\n readonly data: unknown;\n readonly metadata?: Record<string, unknown>;\n}\n\n/**\n * v1 message format (for backwards compatibility).\n */\ninterface V1Body {\n key: string;\n data: unknown;\n metadata: unknown;\n universal?: {\n event_id?: string | null;\n user_id?: string | null;\n correlation_id?: string | null;\n [key: string]: unknown;\n };\n before?: unknown;\n options?: { delayMs?: number };\n targetSubscriber: string;\n}\n\n/**\n * RabbitMQ-specific codec that stores routing/metadata in headers.\n *\n * Benefits:\n * - No duplication between body and headers\n * - RabbitMQ can route/filter based on headers\n * - Smaller message body\n * - v1 message format compatibility built-in\n */\nexport class RabbitMQCodec implements HeaderAwareCodec {\n readonly contentType = 'application/json';\n\n encode(envelope: Envelope): EncodedMessage {\n const { docket } = envelope;\n\n // Body only contains id, data, and metadata (since metadata can be large)\n const body: V2Body = {\n id: envelope.id,\n data: envelope.data,\n ...(docket.metadata !== undefined && { metadata: docket.metadata }),\n };\n\n // All docket fields go in headers\n const headers: Record<string, unknown> = {\n // Routing\n [HEADERS.EVENT_KEY]: docket.eventKey,\n [HEADERS.TARGET_SUBSCRIBER]: docket.targetSubscriber,\n\n // Processing state\n [HEADERS.ATTEMPTS]: docket.attempts,\n [HEADERS.CREATED_AT]: docket.createdAt,\n\n // Observability\n [HEADERS.IMPORTANCE]: docket.importance,\n };\n\n // Optional fields\n if (docket.scheduledFor !== undefined) {\n headers[HEADERS.SCHEDULED_FOR] = docket.scheduledFor;\n }\n if (docket.originalQueue !== undefined) {\n headers[HEADERS.ORIGINAL_QUEUE] = docket.originalQueue;\n }\n if (docket.firstError !== undefined) {\n headers[HEADERS.FIRST_ERROR] = docket.firstError;\n }\n if (docket.lastError !== undefined) {\n headers[HEADERS.LAST_ERROR] = docket.lastError;\n }\n if (docket.correlationId !== undefined) {\n headers[HEADERS.CORRELATION_ID] = docket.correlationId;\n }\n\n return {\n body: new TextEncoder().encode(JSON.stringify(body)),\n headers,\n contentType: this.contentType,\n };\n }\n\n decode(body: Uint8Array, headers: Record<string, unknown>): Envelope {\n if (body.length === 0) {\n throw new CodecDecodeError('Cannot decode empty buffer');\n }\n\n let json: string;\n try {\n json = new TextDecoder('utf-8').decode(body);\n } catch (error) {\n throw new CodecDecodeError('Invalid UTF-8 encoding', error);\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(json);\n } catch (error) {\n throw new CodecDecodeError('Invalid JSON', error);\n }\n\n // Detect format: v1 has 'key' and 'targetSubscriber' at top level\n if (this.isV1Body(parsed)) {\n return this.decodeV1(parsed, headers);\n }\n\n // v2 format\n if (!this.isV2Body(parsed)) {\n throw new CodecDecodeError('Invalid message body structure');\n }\n\n return this.decodeV2(parsed, headers);\n }\n\n private isV1Body(value: unknown): value is V1Body {\n if (typeof value !== 'object' || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n typeof obj['key'] === 'string' &&\n typeof obj['targetSubscriber'] === 'string' &&\n 'data' in obj &&\n !('payload' in obj)\n );\n }\n\n private isV2Body(value: unknown): value is V2Body {\n if (typeof value !== 'object' || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n typeof obj['id'] === 'string' && 'data' in obj && !('key' in obj) // Distinguish from v1 which also has 'data'\n );\n }\n\n private decodeV2(body: V2Body, headers: Record<string, unknown>): Envelope {\n // Required headers\n const eventKey = this.requireStringHeader(headers, HEADERS.EVENT_KEY);\n const targetSubscriber = this.requireStringHeader(\n headers,\n HEADERS.TARGET_SUBSCRIBER,\n );\n const attempts = this.requireNumberHeader(headers, HEADERS.ATTEMPTS);\n const createdAt = this.requireStringHeader(headers, HEADERS.CREATED_AT);\n const importance = this.requireStringHeader(headers, HEADERS.IMPORTANCE);\n\n // Optional headers\n const scheduledFor = this.optionalStringHeader(\n headers,\n HEADERS.SCHEDULED_FOR,\n );\n const originalQueue = this.optionalStringHeader(\n headers,\n HEADERS.ORIGINAL_QUEUE,\n );\n const firstError = this.optionalStringHeader(headers, HEADERS.FIRST_ERROR);\n const lastError = this.optionalStringHeader(headers, HEADERS.LAST_ERROR);\n const correlationId = this.optionalStringHeader(\n headers,\n HEADERS.CORRELATION_ID,\n );\n\n const docket: Docket = {\n // Routing\n eventKey,\n targetSubscriber,\n ...(scheduledFor !== undefined && { scheduledFor }),\n ...(originalQueue !== undefined && { originalQueue }),\n // Processing state\n attempts,\n createdAt,\n ...(firstError !== undefined && { firstError }),\n ...(lastError !== undefined && { lastError }),\n // Observability\n importance: importance as Docket['importance'],\n ...(correlationId !== undefined && { correlationId }),\n ...(body.metadata !== undefined && { metadata: body.metadata }),\n };\n\n return {\n id: body.id,\n data: body.data,\n docket,\n };\n }\n\n /**\n * Decodes a v1 format message for backwards compatibility.\n * v1 format: { key, data, metadata, universal, targetSubscriber, ... }\n */\n private decodeV1(body: V1Body, headers: Record<string, unknown>): Envelope {\n const { event_id, user_id, correlation_id, ...otherUniversal } =\n body.universal ?? {};\n\n // Merge metadata: event metadata + remaining universal fields\n const mergedMetadata: Record<string, unknown> = {};\n if (body.metadata && typeof body.metadata === 'object') {\n Object.assign(mergedMetadata, body.metadata);\n }\n if (user_id !== undefined && user_id !== null) {\n mergedMetadata['user_id'] = user_id;\n }\n Object.assign(mergedMetadata, otherUniversal);\n\n // Try to get attempts from header (v1 also uses x-matador-attempts)\n const attempts =\n typeof headers[HEADERS.ATTEMPTS] === 'number'\n ? (headers[HEADERS.ATTEMPTS] as number)\n : 1;\n\n // Try to get importance from header\n const importance =\n typeof headers[HEADERS.IMPORTANCE] === 'string'\n ? (headers[HEADERS.IMPORTANCE] as string)\n : 'should-investigate';\n\n // Get correlation ID from either v1 or v2 header\n const correlationId =\n (headers[HEADERS.CORRELATION_ID] as string | undefined) ??\n (headers[HEADERS.V1_CORRELATION_ID] as string | undefined) ??\n correlation_id ??\n undefined;\n\n // Get event ID from v1 header or body\n const eventId =\n (headers[HEADERS.V1_EVENT_ID] as string | undefined) ??\n event_id ??\n crypto.randomUUID();\n\n const now = new Date().toISOString();\n\n // Calculate scheduledFor if delayMs was specified (though it's likely already passed)\n let scheduledFor: string | undefined;\n if (body.options?.delayMs) {\n scheduledFor = new Date(Date.now() + body.options.delayMs).toISOString();\n }\n\n const docket: Docket = {\n // Routing\n eventKey: body.key,\n targetSubscriber: body.targetSubscriber,\n ...(scheduledFor !== undefined && { scheduledFor }),\n // Processing state\n attempts,\n createdAt: now,\n // Observability\n importance: importance as Docket['importance'],\n ...(correlationId !== undefined && { correlationId }),\n ...(Object.keys(mergedMetadata).length > 0 && {\n metadata: mergedMetadata,\n }),\n };\n\n return {\n id: eventId,\n data: body.data,\n docket,\n };\n }\n\n private requireStringHeader(\n headers: Record<string, unknown>,\n name: string,\n ): string {\n const value = headers[name];\n if (value === undefined) {\n throw new CodecDecodeError(`Missing required header: ${name}`);\n }\n if (typeof value !== 'string') {\n throw new CodecDecodeError(\n `Header ${name} must be string, got ${typeof value}`,\n );\n }\n return value;\n }\n\n private requireNumberHeader(\n headers: Record<string, unknown>,\n name: string,\n ): number {\n const value = headers[name];\n if (value === undefined) {\n throw new CodecDecodeError(`Missing required header: ${name}`);\n }\n if (typeof value !== 'number') {\n throw new CodecDecodeError(\n `Header ${name} must be number, got ${typeof value}`,\n );\n }\n return value;\n }\n\n private optionalStringHeader(\n headers: Record<string, unknown>,\n name: string,\n ): string | undefined {\n const value = headers[name];\n if (value === undefined) return undefined;\n if (typeof value !== 'string') return undefined;\n return value;\n }\n}\n","import { DuplicateIoKeyError } from '../errors/index.js';\nimport type { Envelope, SubscriberDefinition } from '../types/index.js';\nimport type {\n Checkpoint,\n CheckpointHitContext,\n CheckpointMissContext,\n CheckpointStore,\n JsonSerializable,\n SubscriberContext,\n} from './types.js';\n\n/**\n * Hooks for observability during context operations.\n */\nexport interface ResumableContextHooks {\n onCheckpointHit?(context: CheckpointHitContext): void | Promise<void>;\n onCheckpointMiss?(context: CheckpointMissContext): void | Promise<void>;\n}\n\n/**\n * Configuration for creating a ResumableContext.\n */\nexport interface ResumableContextConfig {\n readonly store: CheckpointStore;\n readonly envelope: Envelope;\n readonly subscriber: SubscriberDefinition;\n readonly existingCheckpoint?: Checkpoint | undefined;\n readonly hooks?: ResumableContextHooks | undefined;\n}\n\n/**\n * Implementation of SubscriberContext that provides io() caching.\n *\n * On first execution, io() calls execute their lambdas and cache results.\n * On retry (when existingCheckpoint is provided), cached results are returned\n * without re-executing the lambda.\n */\nexport class ResumableContext implements SubscriberContext {\n private checkpoint: Checkpoint;\n private readonly usedKeys = new Set<string>();\n private readonly store: CheckpointStore;\n private readonly envelope: Envelope;\n private readonly subscriber: SubscriberDefinition;\n private readonly hooks: ResumableContextHooks | undefined;\n\n constructor(config: ResumableContextConfig) {\n this.store = config.store;\n this.envelope = config.envelope;\n this.subscriber = config.subscriber;\n this.hooks = config.hooks;\n\n this.checkpoint = config.existingCheckpoint ?? {\n envelopeId: config.envelope.id,\n subscriberName: config.subscriber.name,\n completedSteps: {},\n };\n }\n\n get attempt(): number {\n return this.envelope.docket.attempts;\n }\n\n get isRetry(): boolean {\n return this.attempt > 1;\n }\n\n async io<T extends JsonSerializable>(\n key: string,\n fn: () => Promise<T> | T,\n ): Promise<T> {\n // Validate key uniqueness within this execution\n if (this.usedKeys.has(key)) {\n throw new DuplicateIoKeyError(key, this.subscriber.name);\n }\n this.usedKeys.add(key);\n\n // Check cache first\n if (key in this.checkpoint.completedSteps) {\n await this.hooks?.onCheckpointHit?.({\n envelope: this.envelope,\n subscriber: this.subscriber,\n stepKey: key,\n });\n return this.checkpoint.completedSteps[key] as T;\n }\n\n // Notify cache miss\n await this.hooks?.onCheckpointMiss?.({\n envelope: this.envelope,\n subscriber: this.subscriber,\n stepKey: key,\n });\n\n // Execute the function - errors propagate, no caching on failure\n const result = await fn();\n\n // Cache the result\n this.checkpoint = {\n ...this.checkpoint,\n completedSteps: {\n ...this.checkpoint.completedSteps,\n [key]: result,\n },\n };\n\n // Persist checkpoint immediately (incremental persistence)\n await this.store.set(this.envelope.id, this.checkpoint);\n\n return result;\n }\n\n async all<\n T extends readonly [\n string,\n () => Promise<JsonSerializable> | JsonSerializable,\n ][],\n >(\n ops: T,\n ): Promise<{\n [K in keyof T]: T[K] extends [string, () => Promise<infer R> | infer R]\n ? R\n : never;\n }> {\n // First, check for duplicates within this all() call\n const keysInThisCall = new Set<string>();\n for (const [key] of ops) {\n if (keysInThisCall.has(key)) {\n throw new DuplicateIoKeyError(key, this.subscriber.name);\n }\n keysInThisCall.add(key);\n }\n\n // Then validate against previously used keys\n for (const [key] of ops) {\n if (this.usedKeys.has(key)) {\n throw new DuplicateIoKeyError(key, this.subscriber.name);\n }\n }\n\n // Mark all keys as used\n for (const [key] of ops) {\n this.usedKeys.add(key);\n }\n\n // Execute all operations in parallel\n const results = await Promise.all(\n ops.map(async ([key, fn]) => {\n // Check cache first\n if (key in this.checkpoint.completedSteps) {\n await this.hooks?.onCheckpointHit?.({\n envelope: this.envelope,\n subscriber: this.subscriber,\n stepKey: key,\n });\n return this.checkpoint.completedSteps[key];\n }\n\n // Notify cache miss\n await this.hooks?.onCheckpointMiss?.({\n envelope: this.envelope,\n subscriber: this.subscriber,\n stepKey: key,\n });\n\n // Execute - errors propagate\n const result = await fn();\n\n // Cache individually (in local state, will persist after Promise.all)\n this.checkpoint = {\n ...this.checkpoint,\n completedSteps: {\n ...this.checkpoint.completedSteps,\n [key]: result,\n },\n };\n\n return result;\n }),\n );\n\n // Persist after all parallel operations complete\n await this.store.set(this.envelope.id, this.checkpoint);\n\n return results as {\n [K in keyof T]: T[K] extends [string, () => Promise<infer R> | infer R]\n ? R\n : never;\n };\n }\n\n /**\n * Clears the checkpoint from storage.\n * Called after successful completion or dead-letter.\n */\n async clear(): Promise<void> {\n await this.store.delete(this.envelope.id);\n }\n\n /**\n * Gets the current checkpoint state.\n * Useful for debugging and testing.\n */\n getCheckpoint(): Checkpoint {\n return this.checkpoint;\n }\n\n /**\n * Gets the number of cached steps.\n */\n get cachedStepCount(): number {\n return Object.keys(this.checkpoint.completedSteps).length;\n }\n}\n","import type { Checkpoint, CheckpointStore } from '../types.js';\n\n/**\n * In-memory checkpoint store for testing and development.\n * Checkpoints are lost when the process restarts.\n *\n * For production use, implement a persistent store (e.g., RedisCheckpointStore).\n */\nexport class MemoryCheckpointStore implements CheckpointStore {\n private readonly checkpoints = new Map<string, Checkpoint>();\n\n async get(envelopeId: string): Promise<Checkpoint | undefined> {\n return this.checkpoints.get(envelopeId);\n }\n\n async set(envelopeId: string, checkpoint: Checkpoint): Promise<void> {\n this.checkpoints.set(envelopeId, checkpoint);\n }\n\n async delete(envelopeId: string): Promise<void> {\n this.checkpoints.delete(envelopeId);\n }\n\n /**\n * Gets the number of stored checkpoints.\n * Useful for testing.\n */\n get size(): number {\n return this.checkpoints.size;\n }\n\n /**\n * Clears all stored checkpoints.\n * Useful for testing.\n */\n clear(): void {\n this.checkpoints.clear();\n }\n\n /**\n * Gets all stored checkpoint IDs.\n * Useful for testing.\n */\n keys(): string[] {\n return [...this.checkpoints.keys()];\n }\n}\n","import type { Checkpoint, CheckpointStore } from '../types.js';\n\n/**\n * No-operation checkpoint store that doesn't persist anything.\n * Used when no checkpoint store is configured.\n *\n * With this store, resumable subscribers will work but checkpoints\n * won't persist across retries - all io() operations will re-execute.\n */\nexport class NoOpCheckpointStore implements CheckpointStore {\n async get(_envelopeId: string): Promise<Checkpoint | undefined> {\n return undefined;\n }\n\n async set(_envelopeId: string, _checkpoint: Checkpoint): Promise<void> {\n // No-op\n }\n\n async delete(_envelopeId: string): Promise<void> {\n // No-op\n }\n}\n","import type { Checkpoint, CheckpointStore } from '../checkpoint/index.js';\nimport { NoOpCheckpointStore, ResumableContext } from '../checkpoint/index.js';\nimport type { Codec } from '../codec/index.js';\nimport { CodecDecodeError } from '../codec/index.js';\nimport {\n SubscriberIsStubError,\n SubscriberNotRegisteredError,\n} from '../errors/index.js';\nimport type { SafeHooks } from '../hooks/index.js';\nimport type { RetryDecision, RetryPolicy } from '../retry/index.js';\nimport type { SchemaRegistry } from '../schema/index.js';\nimport type { MessageReceipt, Transport } from '../transport/index.js';\nimport type { Envelope, SubscriberDefinition } from '../types/index.js';\nimport { isResumableSubscriber } from '../types/index.js';\n\n/**\n * Configuration for the processing pipeline.\n */\nexport interface PipelineConfig {\n readonly transport: Transport;\n readonly schema: SchemaRegistry;\n readonly codec: Codec;\n readonly retryPolicy: RetryPolicy;\n readonly hooks: SafeHooks;\n /** Optional checkpoint store for resumable subscribers */\n readonly checkpointStore?: CheckpointStore | undefined;\n}\n\n/**\n * Result of pipeline processing.\n */\nexport interface ProcessResult {\n readonly success: boolean;\n readonly envelope?: Envelope | undefined;\n readonly subscriber?: SubscriberDefinition | undefined;\n readonly error?: Error | undefined;\n readonly decision?: RetryDecision | undefined;\n readonly durationMs: number;\n}\n\n/**\n * Processing pipeline for incoming messages.\n *\n * Handles the complete message lifecycle:\n * 1. Decode envelope from raw bytes\n * 2. Lookup subscriber from schema\n * 3. Execute subscriber callback with hooks\n * 4. Handle success/failure with retry policy\n */\nexport class ProcessingPipeline {\n private readonly transport: Transport;\n private readonly schema: SchemaRegistry;\n private readonly codec: Codec;\n private readonly retryPolicy: RetryPolicy;\n private readonly hooks: SafeHooks;\n private readonly checkpointStore: CheckpointStore;\n\n constructor(config: PipelineConfig) {\n this.transport = config.transport;\n this.schema = config.schema;\n this.codec = config.codec;\n this.retryPolicy = config.retryPolicy;\n this.hooks = config.hooks;\n this.checkpointStore = config.checkpointStore ?? new NoOpCheckpointStore();\n }\n\n /**\n * Processes a raw message from the transport.\n */\n async process(\n rawMessage: Uint8Array,\n receipt: MessageReceipt,\n ): Promise<ProcessResult> {\n const startTime = performance.now();\n\n // 1. Decode envelope\n let envelope: Envelope;\n try {\n envelope = this.codec.decode(rawMessage);\n } catch (error) {\n const decodeError =\n error instanceof CodecDecodeError\n ? error\n : new CodecDecodeError('Unknown decode error', error);\n\n await this.transport.complete(receipt);\n await this.hooks.onDecodeError({\n error: decodeError,\n rawMessage,\n sourceQueue: receipt.sourceQueue,\n transport: receipt.sourceTransport,\n });\n\n return {\n success: false,\n error: decodeError,\n durationMs: performance.now() - startTime,\n };\n }\n\n // 2. Lookup subscriber from schema\n const subscriberDef = this.schema.getSubscriberDefinition(\n envelope.docket.eventKey,\n envelope.docket.targetSubscriber,\n );\n\n if (!subscriberDef) {\n const error = new SubscriberNotRegisteredError(\n envelope.docket.targetSubscriber,\n envelope.docket.eventKey,\n );\n\n // Retry unhandled messages (likely deployment timing issue)\n const decision = this.getUnhandledRetryDecision(envelope, receipt, error);\n await this.handleRetryDecision(receipt, envelope, decision);\n\n return {\n success: false,\n envelope,\n error,\n decision,\n durationMs: performance.now() - startTime,\n };\n }\n\n // Get executable subscriber\n const subscriber = this.schema.getExecutableSubscriber(\n envelope.docket.eventKey,\n envelope.docket.targetSubscriber,\n );\n\n if (!subscriber) {\n // Subscriber is a stub (remote implementation)\n const error = new SubscriberIsStubError(envelope.docket.targetSubscriber);\n\n // Retry stub messages (likely deployment timing issue)\n const decision = this.getUnhandledRetryDecision(envelope, receipt, error);\n await this.handleRetryDecision(receipt, envelope, decision);\n\n return {\n success: false,\n envelope,\n subscriber: subscriberDef,\n error,\n decision,\n durationMs: performance.now() - startTime,\n };\n }\n\n // 3. Execute subscriber callback with hooks\n let result: unknown;\n let error: Error | undefined;\n let context: ResumableContext | undefined;\n\n // For resumable subscribers, load existing checkpoint and create context\n const isResumable = isResumableSubscriber(subscriber);\n let existingCheckpoint: Checkpoint | undefined;\n\n if (isResumable) {\n existingCheckpoint = await this.checkpointStore.get(envelope.id);\n\n if (existingCheckpoint) {\n await this.hooks.onCheckpointLoaded?.({\n envelope,\n subscriber: subscriberDef,\n checkpoint: existingCheckpoint,\n cachedSteps: Object.keys(existingCheckpoint.completedSteps).length,\n });\n }\n\n context = new ResumableContext({\n store: this.checkpointStore,\n envelope,\n subscriber: subscriberDef,\n existingCheckpoint,\n hooks: {\n onCheckpointHit: (ctx) => this.hooks.onCheckpointHit?.(ctx),\n onCheckpointMiss: (ctx) => this.hooks.onCheckpointMiss?.(ctx),\n },\n });\n }\n\n await this.hooks.onWorkerWrap(envelope, subscriberDef, async () => {\n await this.hooks.onWorkerBeforeProcess(envelope, subscriberDef);\n\n try {\n if (isResumable && context) {\n // Resumable subscriber: pass context as second argument\n // Cast needed because TypeScript can't narrow the union type based on isResumable\n const resumableCallback = subscriber.callback as (\n envelope: Envelope,\n context: ResumableContext,\n ) => Promise<void> | void;\n result = await resumableCallback(envelope, context);\n } else {\n // Standard subscriber: just pass envelope\n const standardCallback = subscriber.callback as (\n envelope: Envelope,\n ) => Promise<void> | void;\n result = await standardCallback(envelope);\n }\n } catch (e) {\n error = e instanceof Error ? e : new Error(String(e));\n }\n });\n\n const durationMs = performance.now() - startTime;\n\n // 4. Handle success\n if (!error) {\n // Clear checkpoint on success for resumable subscribers\n if (context) {\n await context.clear();\n await this.hooks.onCheckpointCleared?.({\n envelope,\n subscriber: subscriberDef,\n reason: 'success',\n });\n }\n\n await this.transport.complete(receipt);\n await this.hooks.onWorkerSuccess({\n envelope,\n subscriber: subscriberDef,\n result,\n durationMs,\n transport: receipt.sourceTransport,\n });\n\n return {\n success: true,\n envelope,\n subscriber: subscriberDef,\n durationMs,\n };\n }\n\n // 5. Handle failure - consult retry policy\n const decision = this.retryPolicy.shouldRetry({\n envelope,\n error,\n subscriber: subscriberDef,\n receipt,\n });\n\n // Update envelope with error info\n envelope.docket.lastError = error.message;\n envelope.docket.firstError ??= error.message;\n\n // Clear checkpoint on dead-letter (terminal state)\n if (decision.action === 'dead-letter' && context) {\n await context.clear();\n await this.hooks.onCheckpointCleared?.({\n envelope,\n subscriber: subscriberDef,\n reason: 'dead-letter',\n });\n }\n\n await this.handleRetryDecision(receipt, envelope, decision);\n\n await this.hooks.onWorkerError({\n envelope,\n subscriber: subscriberDef,\n error,\n durationMs,\n decision,\n transport: receipt.sourceTransport,\n });\n\n return {\n success: false,\n envelope,\n subscriber: subscriberDef,\n error,\n decision,\n durationMs,\n };\n }\n\n private async handleRetryDecision(\n receipt: MessageReceipt,\n envelope: Envelope,\n decision: RetryDecision,\n ): Promise<void> {\n switch (decision.action) {\n case 'retry': {\n // Increment attempts and schedule retry\n envelope.docket.attempts++;\n envelope.docket.scheduledFor = new Date(\n Date.now() + decision.delay,\n ).toISOString();\n\n await this.transport.send(receipt.sourceQueue, envelope, {\n delay: decision.delay,\n });\n await this.transport.complete(receipt);\n break;\n }\n\n case 'dead-letter': {\n await this.sendToDeadLetter(\n receipt,\n envelope,\n decision.queue,\n decision.reason,\n );\n break;\n }\n\n case 'discard': {\n await this.transport.complete(receipt);\n break;\n }\n }\n }\n\n private async sendToDeadLetter(\n receipt: MessageReceipt,\n envelope: Envelope,\n dlqName: string,\n reason: string,\n ): Promise<void> {\n envelope.docket.originalQueue ??= receipt.sourceQueue;\n\n if (this.transport.sendToDeadLetter) {\n await this.transport.sendToDeadLetter(receipt, dlqName, envelope, reason);\n } else {\n // Manual: send to DLQ then complete original\n const fullDlqName = `${receipt.sourceQueue}.${dlqName}`;\n await this.transport.send(fullDlqName, envelope);\n await this.transport.complete(receipt);\n }\n }\n\n /**\n * Gets retry decision for unhandled messages (subscriber not found).\n * Uses same retry policy logic but sends to 'unhandled' DLQ after max attempts.\n */\n private getUnhandledRetryDecision(\n envelope: Envelope,\n receipt: MessageReceipt,\n error: Error,\n ): RetryDecision {\n // Create a synthetic subscriber definition for retry policy\n const syntheticSubscriber: SubscriberDefinition = {\n name: envelope.docket.targetSubscriber,\n description: 'Synthetic subscriber for unhandled message retry',\n idempotent: 'yes', // Safe to retry unhandled messages\n importance: envelope.docket.importance ?? 'should-investigate',\n };\n\n const decision = this.retryPolicy.shouldRetry({\n envelope,\n error,\n subscriber: syntheticSubscriber,\n receipt,\n });\n\n // Override dead-letter queue to 'unhandled' instead of 'undeliverable'\n if (decision.action === 'dead-letter') {\n return {\n action: 'dead-letter',\n queue: 'unhandled',\n reason: decision.reason,\n };\n }\n\n return decision;\n }\n}\n","import {\n IdempotentMessageCannotRetryError,\n MessageMaybePoisonedError,\n isAssertionError,\n isDoRetry,\n isDontRetry,\n} from '../errors/index.js';\nimport type { RetryContext, RetryDecision, RetryPolicy } from './policy.js';\n\n/**\n * Configuration for the standard retry policy.\n */\nexport interface StandardRetryPolicyConfig {\n /** Maximum number of attempts before dead-lettering */\n readonly maxAttempts: number;\n\n /** Base delay between retries in milliseconds */\n readonly baseDelay: number;\n\n /** Maximum delay between retries in milliseconds */\n readonly maxDelay: number;\n\n /** Multiplier for exponential backoff */\n readonly backoffMultiplier: number;\n\n /**\n * Maximum native delivery count before considering message poisoned.\n * This prevents crash loops from messages that crash the worker.\n * Poison messages are sent directly to the dead-letter queue.\n * Default: 5\n */\n readonly maxDeliveries: number;\n}\n\n/**\n * Default configuration values.\n */\nexport const defaultRetryConfig: StandardRetryPolicyConfig = {\n maxAttempts: 3,\n baseDelay: 1000,\n maxDelay: 300000, // 5 minutes\n backoffMultiplier: 2,\n maxDeliveries: 5,\n};\n\n/**\n * Standard retry policy implementing Matador v1 behavior.\n *\n * Decision logic (in priority order):\n * 1. Poison message → dead-letter (prevent crash loops)\n * 2. EventAssertionError → dead-letter (never retry)\n * 3. DontRetry → dead-letter (explicit no-retry)\n * 4. DoRetry → retry if under max attempts\n * 5. Max attempts exceeded → dead-letter\n * 6. Non-idempotent subscriber on redelivery → dead-letter\n * 7. Default → retry with exponential backoff\n */\nexport class StandardRetryPolicy implements RetryPolicy {\n private readonly config: StandardRetryPolicyConfig;\n\n constructor(config: Partial<StandardRetryPolicyConfig> = {}) {\n this.config = { ...defaultRetryConfig, ...config };\n }\n\n shouldRetry(context: RetryContext): RetryDecision {\n const { envelope, error, subscriber, receipt } = context;\n const errorMessage = error.message;\n\n // 1. Poison message detection - prevent crash loops\n if (receipt.deliveryCount >= this.config.maxDeliveries) {\n const poisonError = new MessageMaybePoisonedError(\n envelope.id,\n receipt.deliveryCount,\n this.config.maxDeliveries,\n );\n return {\n action: 'dead-letter',\n queue: 'undeliverable',\n reason: poisonError.message,\n };\n }\n\n // 2. Assertion errors never retry\n if (isAssertionError(error)) {\n return {\n action: 'dead-letter',\n queue: 'undeliverable',\n reason: `assertion error: ${errorMessage}`,\n };\n }\n\n // 3. Explicit no-retry\n if (isDontRetry(error)) {\n return {\n action: 'dead-letter',\n queue: 'undeliverable',\n reason: errorMessage,\n };\n }\n\n // 4. Explicit retry request\n if (isDoRetry(error)) {\n if (receipt.attemptNumber >= this.config.maxAttempts) {\n return {\n action: 'dead-letter',\n queue: 'undeliverable',\n reason: `max attempts exceeded (${this.config.maxAttempts}) with forced retry`,\n };\n }\n return {\n action: 'retry',\n delay: this.getDelay(context),\n };\n }\n\n // 5. Max attempts exceeded\n if (receipt.attemptNumber >= this.config.maxAttempts) {\n return {\n action: 'dead-letter',\n queue: 'undeliverable',\n reason: `max attempts exceeded (${this.config.maxAttempts})`,\n };\n }\n\n // 6. Non-idempotent subscriber on redelivery\n // 'no' and 'unknown' are treated the same (safer default)\n if (\n receipt.redelivered &&\n (subscriber.idempotent === 'no' || subscriber.idempotent === 'unknown')\n ) {\n const idempotentError = new IdempotentMessageCannotRetryError(\n envelope.id,\n subscriber.name,\n );\n return {\n action: 'dead-letter',\n queue: 'undeliverable',\n reason: idempotentError.message,\n };\n }\n\n // 7. Default: retry with backoff\n return {\n action: 'retry',\n delay: this.getDelay(context),\n };\n }\n\n getDelay(context: RetryContext): number {\n const attempt = context.receipt.attemptNumber;\n const delay =\n this.config.baseDelay *\n Math.pow(this.config.backoffMultiplier, attempt - 1);\n return Math.min(delay, this.config.maxDelay);\n }\n}\n","import type {\n AnySubscriber,\n EventClass,\n MatadorEvent,\n Subscriber,\n SubscriberStub,\n} from '../types/index.js';\n\n/**\n * Type-safe schema entry for a single event type (object format).\n * The type parameter enforces that subscribers match the event type.\n */\nexport interface SchemaEntry<T extends MatadorEvent = MatadorEvent> {\n /** The event class */\n readonly eventClass: EventClass<T['data']>;\n\n /** Subscribers for this event */\n readonly subscribers: readonly (Subscriber<T> | SubscriberStub)[];\n}\n\n/**\n * Type-safe schema entry as a tuple: [EventClass, Subscribers[]]\n * The type parameter enforces that subscribers match the event type.\n *\n * @example\n * ```typescript\n * const entry: SchemaEntryTuple<UserCreatedEvent> = [\n * UserCreatedEvent,\n * [createSubscriber<UserCreatedEvent>('handler', async (env) => {})]\n * ];\n * ```\n */\nexport type SchemaEntryTuple<T extends MatadorEvent = MatadorEvent> = readonly [\n eventClass: EventClass<T['data']>,\n subscribers: readonly (Subscriber<T> | SubscriberStub)[],\n];\n\n/**\n * Creates a type-safe schema entry tuple.\n * Ensures that subscribers are compatible with the event class at compile time.\n *\n * @example\n * ```typescript\n * const schema = {\n * [UserCreatedEvent.key]: bind(UserCreatedEvent, [\n * createSubscriber<UserCreatedEvent>('send-email', async (env) => {\n * console.log(env.data.email); // Type-safe access\n * }),\n * ]),\n * } satisfies MatadorSchema;\n * ```\n */\nexport function bind<T extends MatadorEvent>(\n eventClass: EventClass<T['data']>,\n subscribers: readonly (Subscriber<T> | SubscriberStub)[],\n): SchemaEntryTuple<T> {\n return [eventClass, subscribers] as const;\n}\n\n/**\n * Minimal type for event class in schema storage.\n * Only requires the static `key` property for routing.\n * Constructor constraint is omitted to allow heterogeneous event types.\n */\n// biome-ignore lint/suspicious/noExplicitAny: Constructor accepts any data type for variance compatibility\nexport type AnyEventClass = {\n readonly key: string;\n new (data: any): MatadorEvent;\n};\n\n/**\n * Runtime schema entry stored in MatadorSchema (object format).\n * Uses AnySubscriber and AnyEventClass to allow heterogeneous event types.\n * Type safety is enforced at definition time via `schemaEntry()` helper.\n */\nexport interface RuntimeSchemaEntry {\n readonly eventClass: AnyEventClass;\n readonly subscribers: readonly AnySubscriber[];\n}\n\n/**\n * Runtime schema tuple stored in MatadorSchema.\n * Uses AnySubscriber and AnyEventClass to allow heterogeneous event types.\n * Type safety is enforced at definition time via `schemaEntry()` helper.\n */\nexport type RuntimeSchemaEntryTuple = readonly [\n eventClass: AnyEventClass,\n subscribers: readonly AnySubscriber[],\n];\n\n/**\n * Matador schema mapping event keys to their definitions.\n * Supports both object format (SchemaEntry) and tuple format (SchemaEntryTuple).\n *\n * For type-safe schema definitions, use the `bind` helper function\n * which ensures subscribers are compatible with their event class.\n *\n * @example\n * ```typescript\n * // Type-safe with bind helper:\n * const schema = {\n * [UserCreatedEvent.key]: bind(UserCreatedEvent, [emailSubscriber]),\n * } satisfies MatadorSchema;\n *\n * // Or inline (less type-safe):\n * const schema: MatadorSchema = {\n * [UserCreatedEvent.key]: [UserCreatedEvent, [emailSubscriber]],\n * };\n * ```\n */\nexport type MatadorSchema = {\n readonly [eventKey: string]: RuntimeSchemaEntry | RuntimeSchemaEntryTuple;\n};\n\n/**\n * Type guard to check if a schema entry is in tuple format.\n */\nexport function isSchemaEntryTuple(\n entry: RuntimeSchemaEntry | RuntimeSchemaEntryTuple,\n): entry is RuntimeSchemaEntryTuple {\n return Array.isArray(entry);\n}\n\n/**\n * Options for schema registration.\n */\nexport interface RegisterOptions {\n /** Override existing registration if present */\n readonly override?: boolean;\n}\n\n/**\n * Result of schema validation.\n */\nexport interface SchemaValidationResult {\n readonly valid: boolean;\n readonly issues: readonly SchemaIssue[];\n}\n\n/**\n * Individual schema issue.\n */\nexport interface SchemaIssue {\n readonly severity: 'error' | 'warning';\n readonly eventKey: string;\n readonly message: string;\n}\n\n/**\n * Plugin definition for adding subscribers to multiple events.\n */\nexport interface SchemaPlugin {\n /** The subscriber to add to events */\n readonly subscriber: AnySubscriber;\n\n /** Event keys to exclude from this plugin */\n readonly exclusions?: readonly string[];\n}\n\n/**\n * Installs plugins (global subscribers) into a schema.\n * Each plugin subscriber is added to all events except those in its exclusions list.\n *\n * @param schema - The base schema to extend\n * @param plugins - Array of plugins to install\n * @returns A new schema with plugin subscribers added\n *\n * @example\n * ```typescript\n * const baseSchema: MatadorSchema = {\n * [UserCreatedEvent.key]: [UserCreatedEvent, [sendWelcomeEmail]],\n * [OrderPlacedEvent.key]: [OrderPlacedEvent, [processOrder]],\n * [ChatMessageSent.key]: [ChatMessageSent, [notifyRecipient]],\n * };\n *\n * const schema = installPlugins(baseSchema, [\n * {\n * subscriber: logToBigQuery,\n * exclusions: [ChatMessageSent.key], // Don't log chat messages\n * },\n * {\n * subscriber: trackAnalytics,\n * // No exclusions - added to all events\n * },\n * ]);\n * ```\n */\nexport function installPlugins(\n schema: MatadorSchema,\n plugins: readonly SchemaPlugin[],\n): MatadorSchema {\n const result: Record<string, RuntimeSchemaEntry | RuntimeSchemaEntryTuple> =\n {};\n\n for (const [eventKey, entry] of Object.entries(schema)) {\n // Get existing event class and subscribers\n const [eventClass, existingSubscribers] = isSchemaEntryTuple(entry)\n ? [entry[0], entry[1]]\n : [entry.eventClass, entry.subscribers];\n\n // Collect subscribers to add from plugins\n const pluginSubscribers: AnySubscriber[] = [];\n for (const plugin of plugins) {\n if (!plugin.exclusions?.includes(eventKey)) {\n pluginSubscribers.push(plugin.subscriber);\n }\n }\n\n // Create new entry with combined subscribers\n result[eventKey] = [\n eventClass,\n [...existingSubscribers, ...pluginSubscribers],\n ];\n }\n\n return result;\n}\n","import type { HasDescription } from '../errors/index.js';\nimport type {\n AnySubscriber,\n EventClass,\n MatadorEvent,\n Subscriber,\n SubscriberDefinition,\n} from '../types/index.js';\nimport { isSubscriber } from '../types/index.js';\nimport type {\n RegisterOptions,\n SchemaEntry,\n SchemaIssue,\n SchemaValidationResult,\n} from './types.js';\n\n/**\n * Error thrown when schema operations fail.\n */\nexport class SchemaError extends Error implements HasDescription {\n readonly description =\n 'A schema operation failed, such as registering a duplicate event or ' +\n 'conflicting alias. This is a configuration error that should be fixed ' +\n 'during development. Review the event and subscriber registrations to ' +\n 'resolve the conflict.';\n\n constructor(message: string) {\n super(message);\n this.name = 'SchemaError';\n }\n}\n\n/**\n * Registry for managing event-subscriber relationships.\n */\nexport class SchemaRegistry {\n private readonly entries = new Map<string, SchemaEntry>();\n private readonly aliases = new Map<string, string>();\n\n /**\n * Registers an event class with its subscribers.\n */\n register<T>(\n eventClass: EventClass<T>,\n subscribers: readonly AnySubscriber[],\n options: RegisterOptions = {},\n ): void {\n const key = eventClass.key;\n\n if (this.entries.has(key) && !options.override) {\n throw new SchemaError(`Event \"${key}\" is already registered`);\n }\n\n this.entries.set(key, {\n eventClass,\n subscribers,\n } as SchemaEntry);\n\n // Register aliases\n if (eventClass.aliases) {\n for (const alias of eventClass.aliases) {\n if (\n this.aliases.has(alias) &&\n this.aliases.get(alias) !== key &&\n !options.override\n ) {\n throw new SchemaError(\n `Alias \"${alias}\" is already registered for event \"${this.aliases.get(alias)}\"`,\n );\n }\n this.aliases.set(alias, key);\n }\n }\n }\n\n /**\n * Gets the event class for a given key.\n */\n getEventClass(key: string): EventClass | undefined {\n const entry = this.entries.get(key);\n if (entry) return entry.eventClass;\n\n // Check aliases\n const aliasKey = this.aliases.get(key);\n if (aliasKey) {\n return this.entries.get(aliasKey)?.eventClass;\n }\n\n return undefined;\n }\n\n /**\n * Gets all subscribers for an event key.\n */\n getSubscribers(eventKey: string): readonly AnySubscriber[] {\n const entry = this.getEntry(eventKey);\n return entry?.subscribers ?? [];\n }\n\n /**\n * Gets a specific subscriber by event key and subscriber name.\n */\n getSubscriber(\n eventKey: string,\n subscriberName: string,\n ): AnySubscriber | undefined {\n const subscribers = this.getSubscribers(eventKey);\n return subscribers.find((s) => s.name === subscriberName);\n }\n\n /**\n * Gets a subscriber definition for the pipeline.\n */\n getSubscriberDefinition(\n eventKey: string,\n subscriberName: string,\n ): SubscriberDefinition | undefined {\n const subscriber = this.getSubscriber(eventKey, subscriberName);\n if (!subscriber) return undefined;\n\n const def: SubscriberDefinition = {\n name: subscriber.name,\n description: subscriber.description,\n idempotent: subscriber.idempotent ?? 'unknown',\n importance: subscriber.importance ?? 'should-investigate',\n };\n\n if (subscriber.targetQueue !== undefined) {\n (def as { targetQueue?: string }).targetQueue = subscriber.targetQueue;\n }\n\n return def;\n }\n\n /**\n * Gets a subscriber with callback for execution.\n */\n getExecutableSubscriber(\n eventKey: string,\n subscriberName: string,\n ): Subscriber<MatadorEvent<unknown>> | undefined {\n const subscriber = this.getSubscriber(eventKey, subscriberName);\n if (!subscriber || !isSubscriber(subscriber)) return undefined;\n return subscriber;\n }\n\n /**\n * Gets the event class by alias.\n */\n getEventByAlias(alias: string): EventClass | undefined {\n const key = this.aliases.get(alias);\n if (!key) return undefined;\n return this.entries.get(key)?.eventClass;\n }\n\n /**\n * Checks if an event key is registered.\n */\n hasEvent(key: string): boolean {\n return this.entries.has(key) || this.aliases.has(key);\n }\n\n /**\n * Gets all registered event keys.\n */\n getEventKeys(): readonly string[] {\n return [...this.entries.keys()];\n }\n\n /**\n * Validates the schema for issues.\n */\n validate(): SchemaValidationResult {\n const issues: SchemaIssue[] = [];\n\n for (const [key, entry] of this.entries) {\n // Check for duplicate subscriber names\n const names = new Set<string>();\n for (const subscriber of entry.subscribers) {\n if (names.has(subscriber.name)) {\n issues.push({\n severity: 'error',\n eventKey: key,\n message: `Duplicate subscriber name: \"${subscriber.name}\"`,\n });\n }\n names.add(subscriber.name);\n }\n\n // Check for subscribers without callbacks (stubs in consuming instance)\n const stubs = entry.subscribers.filter((s) => !isSubscriber(s));\n if (stubs.length === entry.subscribers.length && stubs.length > 0) {\n issues.push({\n severity: 'warning',\n eventKey: key,\n message: 'All subscribers are stubs, no local handlers',\n });\n }\n }\n\n return {\n valid: issues.filter((i) => i.severity === 'error').length === 0,\n issues,\n };\n }\n\n /**\n * Clears all registered entries.\n */\n clear(): void {\n this.entries.clear();\n this.aliases.clear();\n }\n\n private getEntry(eventKey: string): SchemaEntry | undefined {\n const entry = this.entries.get(eventKey);\n if (entry) return entry;\n\n const aliasKey = this.aliases.get(eventKey);\n if (aliasKey) {\n return this.entries.get(aliasKey);\n }\n\n return undefined;\n }\n}\n","import type { CheckpointStore } from '../checkpoint/index.js';\nimport type { Codec } from '../codec/index.js';\nimport { JsonCodec } from '../codec/index.js';\nimport {\n InvalidSchemaError,\n NotStartedError,\n ShutdownInProgressError,\n} from '../errors/index.js';\nimport type { MatadorHooks } from '../hooks/index.js';\nimport { SafeHooks } from '../hooks/index.js';\nimport { ProcessingPipeline } from '../pipeline/index.js';\nimport type { RetryPolicy } from '../retry/index.js';\nimport { StandardRetryPolicy } from '../retry/index.js';\nimport type { MatadorSchema } from '../schema/index.js';\nimport { SchemaRegistry, isSchemaEntryTuple } from '../schema/index.js';\nimport type { Topology } from '../topology/index.js';\nimport { getQualifiedQueueName } from '../topology/index.js';\nimport type { Subscription, Transport } from '../transport/index.js';\nimport type {\n AnySubscriber,\n Event,\n EventClass,\n EventOptions,\n} from '../types/index.js';\nimport type { SendResult } from './fanout.js';\nimport { FanoutEngine } from './fanout.js';\nimport type { HandlersState, ShutdownConfig } from './shutdown.js';\nimport { ShutdownManager } from './shutdown.js';\n\n/**\n * Configuration for Matador.\n */\nexport interface MatadorConfig {\n /** Transport for message delivery */\n readonly transport: Transport;\n\n /** Topology configuration */\n readonly topology: Topology;\n\n /** Event schema mapping event keys to event classes and subscribers */\n readonly schema: MatadorSchema;\n\n /** Queues to consume from (empty = no consumption) */\n readonly consumeFrom?: readonly string[] | undefined;\n\n /** Custom codec (defaults to JSON) */\n readonly codec?: Codec | undefined;\n\n /** Custom retry policy */\n readonly retryPolicy?: RetryPolicy | undefined;\n\n /** Shutdown configuration */\n readonly shutdownConfig?: Partial<ShutdownConfig> | undefined;\n\n /**\n * Checkpoint store for resumable subscribers.\n * Required for persisting io() results across retries.\n * If not provided, resumable subscribers will work but checkpoints\n * won't persist across retries.\n */\n readonly checkpointStore?: CheckpointStore | undefined;\n}\n\n/**\n * Matador - Transport-agnostic event processing library.\n *\n * Main orchestrator that wires together:\n * - Transport: Message delivery\n * - Schema: Event-subscriber registry\n * - Pipeline: Message processing\n * - Fanout: Event sending\n * - Shutdown: Graceful termination\n */\nexport class Matador {\n private readonly transport: Transport;\n private readonly topology: Topology;\n private readonly schema;\n private readonly codec: Codec;\n private readonly retryPolicy: RetryPolicy;\n private readonly hooks;\n private readonly pipeline;\n private readonly fanout;\n private readonly shutdownManager;\n private readonly consumeFrom: readonly string[];\n private readonly subscriptions: Subscription[] = [];\n private started = false;\n\n /**\n * Creates a new Matador instance.\n *\n * @param config - Static configuration (transport, topology, schema, etc.)\n * @param hooks - Lifecycle hooks for logging, monitoring, and dynamic configuration.\n * Passed separately to support NestJS dependency injection.\n */\n constructor(config: MatadorConfig, hooks?: MatadorHooks) {\n this.transport = config.transport;\n this.topology = config.topology;\n this.consumeFrom = config.consumeFrom ?? [];\n\n // Initialize components\n this.schema = new SchemaRegistry();\n this.codec = config.codec ?? new JsonCodec();\n this.retryPolicy = config.retryPolicy ?? new StandardRetryPolicy();\n this.hooks = new SafeHooks(hooks);\n\n // Register schema from config\n this.registerSchema(config.schema);\n\n // Create pipeline\n this.pipeline = new ProcessingPipeline({\n transport: this.transport,\n schema: this.schema,\n codec: this.codec,\n retryPolicy: this.retryPolicy,\n hooks: this.hooks,\n checkpointStore: config.checkpointStore,\n });\n\n // Create fanout engine\n const defaultQueue = this.topology.queues[0]?.name ?? 'default';\n this.fanout = new FanoutEngine({\n transport: this.transport,\n schema: this.schema,\n hooks: this.hooks,\n namespace: this.topology.namespace,\n defaultQueue,\n });\n\n // Create shutdown manager\n this.shutdownManager = new ShutdownManager(\n () => this.fanout.eventsBeingEnqueuedCount,\n () => this.stopReceiving(),\n () => this.transport.disconnect(),\n config.shutdownConfig,\n );\n }\n\n /**\n * Registers an event class with its subscribers.\n */\n register<T>(\n eventClass: EventClass<T>,\n subscribers: readonly AnySubscriber[],\n ): this {\n this.schema.register(eventClass, subscribers);\n return this;\n }\n\n /**\n * Registers events from a schema object.\n * Supports both object format and tuple format entries.\n *\n * @example\n * ```typescript\n * // Tuple format\n * matador.registerSchema({\n * [UserCreatedEvent.key]: [UserCreatedEvent, [emailSubscriber]],\n * [OrderPlacedEvent.key]: [OrderPlacedEvent, [invoiceSubscriber]],\n * });\n *\n * // Object format\n * matador.registerSchema({\n * [UserCreatedEvent.key]: { eventClass: UserCreatedEvent, subscribers: [emailSubscriber] },\n * });\n * ```\n */\n registerSchema(schema: MatadorSchema): this {\n for (const entry of Object.values(schema)) {\n if (isSchemaEntryTuple(entry)) {\n // Tuple format: [EventClass, Subscriber[]]\n const [eventClass, subscribers] = entry;\n this.schema.register(eventClass, subscribers);\n } else {\n // Object format: { eventClass, subscribers }\n this.schema.register(entry.eventClass, entry.subscribers);\n }\n }\n return this;\n }\n\n /**\n * Starts Matador - connects transport and begins consuming.\n * This method is idempotent - calling it multiple times is safe.\n */\n async start(): Promise<void> {\n // Idempotent: if already started, just return\n if (this.started) {\n return;\n }\n\n // Validate schema\n const validation = this.schema.validate();\n if (!validation.valid) {\n const errors = validation.issues.filter((i) => i.severity === 'error');\n throw new InvalidSchemaError(\n 'Schema validation failed',\n errors.map((e) => e.message).join(', '),\n );\n }\n\n // Connect transport\n await this.transport.connect();\n\n // Apply topology\n await this.transport.applyTopology(this.topology);\n\n // Subscribe to queues\n for (const queueName of this.consumeFrom) {\n const qualifiedName = getQualifiedQueueName(\n this.topology.namespace,\n queueName,\n );\n const queueDef = this.topology.queues.find((q) => q.name === queueName);\n\n const subscription = await this.transport.subscribe(\n qualifiedName,\n async (envelope, receipt) => {\n this.shutdownManager.incrementProcessing();\n try {\n const rawMessage = this.codec.encode(envelope);\n await this.pipeline.process(rawMessage, receipt);\n } finally {\n this.shutdownManager.decrementProcessing();\n }\n },\n queueDef?.concurrency !== undefined\n ? { concurrency: queueDef.concurrency }\n : undefined,\n );\n\n this.subscriptions.push(subscription);\n }\n\n this.started = true;\n }\n\n /**\n * Sends an event to all registered subscribers.\n *\n * @example\n * ```typescript\n * // Pass the event class and data directly\n * await matador.send(UserCreatedEvent, { userId: '123' });\n *\n * // Or pass an event instance\n * const event = new UserCreatedEvent({ userId: '123' });\n * await matador.send(event);\n * ```\n */\n async send<T>(\n eventClass: EventClass<T>,\n data: T,\n options?: EventOptions,\n ): Promise<SendResult>;\n async send<T>(event: Event<T>, options?: EventOptions): Promise<SendResult>;\n async send<T>(\n eventOrClass: Event<T> | EventClass<T>,\n dataOrOptions?: T | EventOptions,\n maybeOptions?: EventOptions,\n ): Promise<SendResult> {\n if (!this.started) {\n throw new NotStartedError('send');\n }\n\n if (!this.shutdownManager.isEnqueueAllowed) {\n throw new ShutdownInProgressError();\n }\n\n // Determine if first arg is an event instance or event class\n const isEventClass =\n typeof eventOrClass === 'function' && 'key' in eventOrClass;\n\n if (isEventClass) {\n // Called as: send(EventClass, data, options?)\n const eventClass = eventOrClass as EventClass<T>;\n const data = dataOrOptions as T;\n const options = maybeOptions;\n const event = new eventClass(data);\n return this.fanout.send(eventClass, event, options);\n } else {\n // Called as: send(event, options?)\n const event = eventOrClass as Event<T>;\n const options = dataOrOptions as EventOptions | undefined;\n const eventClass = event.constructor as EventClass<T>;\n return this.fanout.send(eventClass, event, options);\n }\n }\n\n /**\n * Gets current handler state.\n */\n getHandlersState(): HandlersState {\n return this.shutdownManager.getHandlersState();\n }\n\n /**\n * Checks if Matador is idle (no processing or enqueuing).\n */\n isIdle(): boolean {\n return this.shutdownManager.getHandlersState().isIdle;\n }\n\n /**\n * Waits for all handlers to become idle.\n */\n async waitForIdle(timeoutMs = 30000): Promise<boolean> {\n const deadline = Date.now() + timeoutMs;\n\n while (!this.isIdle()) {\n if (Date.now() > deadline) {\n return false;\n }\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n return true;\n }\n\n /**\n * Gracefully shuts down Matador.\n */\n async shutdown(): Promise<void> {\n if (!this.started) {\n return;\n }\n\n await this.shutdownManager.shutdown();\n this.started = false;\n }\n\n /**\n * Checks if transport is connected.\n */\n isConnected(): boolean {\n return this.transport.isConnected();\n }\n\n private async stopReceiving(): Promise<void> {\n for (const subscription of this.subscriptions) {\n await subscription.unsubscribe();\n }\n this.subscriptions.length = 0;\n }\n}\n","import type { DeliveryMode } from '../types/index.js';\n\n/**\n * Describes the native capabilities of a transport.\n * Matador adapts its behavior based on these capabilities.\n */\nexport interface TransportCapabilities {\n /**\n * Delivery semantics the transport supports.\n * - 'at-least-once': Ack after processing (may redeliver on failure)\n * - 'at-most-once': Ack before processing (no redelivery, may lose messages)\n */\n readonly deliveryModes: readonly DeliveryMode[];\n\n /**\n * Transport can delay message delivery natively.\n * - true: Use transport's native delay (BullMQ, RabbitMQ with plugin)\n * - false: Matador handles via retry queue with TTL or external scheduler\n */\n readonly delayedMessages: boolean;\n\n /**\n * Transport can route failed messages to dead-letter queue natively.\n * - 'native': Transport handles DL routing (RabbitMQ DLX)\n * - 'manual': Matador must send() to DLQ then complete() original\n * - 'none': No DL support, Matador logs and discards\n */\n readonly deadLetterRouting: 'native' | 'manual' | 'none';\n\n /**\n * Transport tracks delivery/attempt count natively.\n * - true: Receipt includes accurate attemptNumber from transport\n * - false: Matador tracks attempts in envelope.docket.attempts field\n */\n readonly attemptTracking: boolean;\n\n /**\n * How transport handles concurrency.\n * - 'prefetch': Channel-based prefetch (RabbitMQ)\n * - 'worker': Worker concurrency setting (BullMQ)\n * - 'partition': Partition-based parallelism (Kafka)\n * - 'none': No concurrency control (Memory)\n */\n readonly concurrencyModel: 'prefetch' | 'worker' | 'partition' | 'none';\n\n /**\n * Message ordering guarantees.\n * - 'none': No ordering guarantee (most transports with multiple consumers)\n * - 'queue': Ordered within queue (single consumer scenarios)\n * - 'partition': Ordered within partition/key (Kafka)\n */\n readonly ordering: 'none' | 'queue' | 'partition';\n\n /**\n * Transport supports message priority.\n * - true: Higher priority messages processed first\n * - false: FIFO only\n */\n readonly priorities: boolean;\n}\n\n/**\n * Checks if the transport supports a specific delivery mode.\n */\nexport function supportsDeliveryMode(\n capabilities: TransportCapabilities,\n mode: DeliveryMode,\n): boolean {\n return capabilities.deliveryModes.includes(mode);\n}\n\n/**\n * Checks if the transport supports native delayed messages.\n */\nexport function supportsDelayedMessages(\n capabilities: TransportCapabilities,\n): boolean {\n return capabilities.delayedMessages;\n}\n\n/**\n * Checks if the transport has native dead-letter routing.\n */\nexport function hasNativeDeadLetter(\n capabilities: TransportCapabilities,\n): boolean {\n return capabilities.deadLetterRouting === 'native';\n}\n","/**\n * Connection state machine states.\n */\nexport type ConnectionState =\n | { readonly status: 'disconnected' }\n | { readonly status: 'connecting'; readonly attempt: number }\n | { readonly status: 'connected' }\n | {\n readonly status: 'reconnecting';\n readonly attempt: number;\n readonly lastError: Error;\n }\n | { readonly status: 'failed'; readonly error: Error };\n\n/**\n * Configuration for the connection manager.\n */\nexport interface ConnectionManagerConfig {\n /** Maximum reconnection attempts before giving up (0 = infinite) */\n readonly maxReconnectAttempts: number;\n\n /** Initial delay between reconnection attempts (ms) */\n readonly initialReconnectDelay: number;\n\n /** Maximum delay between reconnection attempts (ms) */\n readonly maxReconnectDelay: number;\n\n /** Backoff multiplier for reconnection delay */\n readonly backoffMultiplier: number;\n\n /** Heartbeat interval for connection health (ms), optional */\n readonly heartbeatInterval?: number;\n}\n\n/**\n * Default configuration values.\n */\nexport const defaultConnectionConfig: ConnectionManagerConfig = {\n maxReconnectAttempts: 0, // Infinite\n initialReconnectDelay: 1000,\n maxReconnectDelay: 30000,\n backoffMultiplier: 2,\n};\n\n/**\n * Callback for state change notifications.\n */\nexport type StateChangeCallback = (state: ConnectionState) => void;\n\n/**\n * Function that performs the actual connection.\n */\nexport type ConnectFn = () => Promise<void>;\n\n/**\n * Function that performs disconnection.\n */\nexport type DisconnectFn = () => Promise<void>;\n\n/**\n * Manages connection lifecycle with automatic reconnection.\n */\nexport class ConnectionManager {\n private _state: ConnectionState = { status: 'disconnected' };\n private readonly listeners: Set<StateChangeCallback> = new Set();\n private reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n private readonly config: ConnectionManagerConfig;\n\n constructor(\n private readonly connectFn: ConnectFn,\n private readonly disconnectFn: DisconnectFn,\n config: Partial<ConnectionManagerConfig> = {},\n ) {\n this.config = { ...defaultConnectionConfig, ...config };\n }\n\n /**\n * Current connection state.\n */\n get state(): ConnectionState {\n return this._state;\n }\n\n /**\n * Whether currently connected.\n */\n isConnected(): boolean {\n return this._state.status === 'connected';\n }\n\n /**\n * Register a callback for connection state changes.\n */\n onStateChange(callback: StateChangeCallback): () => void {\n this.listeners.add(callback);\n return () => this.listeners.delete(callback);\n }\n\n /**\n * Attempt to establish connection.\n */\n async connect(): Promise<void> {\n if (this._state.status === 'connected') {\n return;\n }\n\n this.setState({ status: 'connecting', attempt: 1 });\n\n try {\n await this.connectFn();\n this.setState({ status: 'connected' });\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n await this.handleConnectionFailure(err, 1);\n }\n }\n\n /**\n * Gracefully disconnect.\n */\n async disconnect(): Promise<void> {\n this.clearReconnectTimer();\n\n if (this._state.status === 'disconnected') {\n return;\n }\n\n try {\n await this.disconnectFn();\n } finally {\n this.setState({ status: 'disconnected' });\n }\n }\n\n /**\n * Called by transport when connection is lost unexpectedly.\n */\n async handleConnectionLost(error: Error): Promise<void> {\n if (this._state.status === 'disconnected') {\n return;\n }\n\n this.setState({ status: 'reconnecting', attempt: 1, lastError: error });\n await this.attemptReconnect(1);\n }\n\n /**\n * Calculate delay for a given attempt using exponential backoff.\n */\n calculateDelay(attempt: number): number {\n const delay =\n this.config.initialReconnectDelay *\n Math.pow(this.config.backoffMultiplier, attempt - 1);\n return Math.min(delay, this.config.maxReconnectDelay);\n }\n\n private setState(state: ConnectionState): void {\n this._state = state;\n for (const listener of this.listeners) {\n try {\n listener(state);\n } catch {\n // Ignore listener errors\n }\n }\n }\n\n private async handleConnectionFailure(\n error: Error,\n attempt: number,\n ): Promise<void> {\n if (this.shouldGiveUp(attempt)) {\n this.setState({ status: 'failed', error });\n throw error;\n }\n\n this.setState({\n status: 'reconnecting',\n attempt: attempt + 1,\n lastError: error,\n });\n await this.attemptReconnect(attempt + 1);\n }\n\n private shouldGiveUp(attempt: number): boolean {\n return (\n this.config.maxReconnectAttempts > 0 &&\n attempt >= this.config.maxReconnectAttempts\n );\n }\n\n private async attemptReconnect(attempt: number): Promise<void> {\n const delay = this.calculateDelay(attempt);\n\n await new Promise<void>((resolve) => {\n this.reconnectTimer = setTimeout(resolve, delay);\n });\n\n if (this._state.status === 'disconnected') {\n return;\n }\n\n try {\n await this.connectFn();\n this.setState({ status: 'connected' });\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n await this.handleConnectionFailure(err, attempt);\n }\n }\n\n private clearReconnectTimer(): void {\n if (this.reconnectTimer !== null) {\n clearTimeout(this.reconnectTimer);\n this.reconnectTimer = null;\n }\n }\n}\n","import { TransportNotConnectedError } from '../../errors/index.js';\nimport { type Logger, consoleLogger } from '../../hooks/index.js';\nimport type { Topology } from '../../topology/types.js';\nimport type { Envelope } from '../../types/index.js';\nimport type { TransportCapabilities } from '../capabilities.js';\nimport type {\n MessageHandler,\n MessageReceipt,\n SendOptions,\n SubscribeOptions,\n Subscription,\n Transport,\n} from '../transport.js';\n\n/**\n * Capabilities of the LocalTransport.\n */\nconst localCapabilities: TransportCapabilities = {\n deliveryModes: ['at-least-once', 'at-most-once'],\n delayedMessages: true, // Implemented with setTimeout\n deadLetterRouting: 'manual',\n attemptTracking: false,\n concurrencyModel: 'none',\n ordering: 'queue',\n priorities: false,\n};\n\n/**\n * Internal message structure for the local queue.\n */\ninterface QueuedMessage {\n readonly envelope: Envelope;\n readonly id: string;\n completed: boolean;\n}\n\n/**\n * Internal subscription structure.\n */\ninterface ActiveSubscription {\n readonly handler: MessageHandler;\n readonly options: SubscribeOptions;\n active: boolean;\n}\n\n/**\n * Local in-memory transport for testing and fallback.\n * Messages are stored in memory and delivered synchronously.\n */\nexport class LocalTransport implements Transport {\n readonly name = 'local';\n readonly capabilities = localCapabilities;\n\n private connected = false;\n private readonly queues = new Map<string, QueuedMessage[]>();\n private readonly subscriptions = new Map<string, ActiveSubscription[]>();\n private readonly completedMessages: MessageReceipt[] = [];\n private readonly delayedTimers = new Set<ReturnType<typeof setTimeout>>();\n private messageIdCounter = 0;\n private readonly logger: Logger;\n\n constructor(logger?: Logger) {\n this.logger = logger ?? consoleLogger;\n }\n\n async connect(): Promise<void> {\n this.connected = true;\n }\n\n async disconnect(): Promise<void> {\n // Cancel all delayed message timers\n for (const timer of this.delayedTimers) {\n clearTimeout(timer);\n }\n this.delayedTimers.clear();\n\n // Deactivate all subscriptions\n for (const subs of this.subscriptions.values()) {\n for (const sub of subs) {\n sub.active = false;\n }\n }\n\n this.connected = false;\n }\n\n isConnected(): boolean {\n return this.connected;\n }\n\n async applyTopology(topology: Topology): Promise<void> {\n if (!this.connected) {\n throw new TransportNotConnectedError(this.name, 'applyTopology');\n }\n\n // Initialize queues for the topology.\n // Note: Retry queues are not pre-created here because LocalTransport handles\n // retries by re-enqueueing messages with a delay to the original queue, matching\n // how the pipeline schedules retries via transport.send() with a delay option.\n for (const queueDef of topology.queues) {\n const queueName = `${topology.namespace}.${queueDef.name}`;\n if (!this.queues.has(queueName)) {\n this.queues.set(queueName, []);\n }\n }\n }\n\n async send(\n queue: string,\n envelope: Envelope,\n options?: SendOptions,\n ): Promise<Transport['name']> {\n if (!this.connected) {\n throw new TransportNotConnectedError(this.name, 'send');\n }\n\n // Handle delayed messages (non-blocking, like real transports)\n if (options?.delay !== undefined && options.delay > 0) {\n this.scheduleDelayedMessage(queue, envelope, options.delay);\n return this.name;\n }\n\n await this.enqueue(queue, envelope);\n return this.name;\n }\n\n /**\n * Schedules a message for delayed delivery.\n * Returns immediately (non-blocking) to match real transport behavior.\n */\n private scheduleDelayedMessage(\n queue: string,\n envelope: Envelope,\n delayMs: number,\n ): void {\n const timer = setTimeout(() => {\n this.delayedTimers.delete(timer);\n // Fire and forget - errors are logged in enqueue/deliverToSubscribers\n this.enqueue(queue, envelope).catch((error) => {\n this.logger.error(\n '[Matador] 🔴 Failed to enqueue delayed message',\n error,\n );\n });\n }, delayMs);\n this.delayedTimers.add(timer);\n }\n\n private async enqueue(queue: string, envelope: Envelope): Promise<void> {\n const messages = this.getOrCreateQueue(queue);\n const messageId = `${++this.messageIdCounter}`;\n\n const queuedMessage: QueuedMessage = {\n envelope,\n id: messageId,\n completed: false,\n };\n\n messages.push(queuedMessage);\n\n // Deliver to any active subscriptions\n await this.deliverToSubscribers(queue, queuedMessage);\n }\n\n private async deliverToSubscribers(\n queue: string,\n message: QueuedMessage,\n ): Promise<void> {\n const subs = this.subscriptions.get(queue);\n if (!subs) return;\n\n for (const sub of subs) {\n if (!sub.active || message.completed) continue;\n\n const receipt: MessageReceipt = {\n handle: message,\n redelivered: false,\n attemptNumber: message.envelope.docket.attempts,\n deliveryCount: message.envelope.docket.attempts,\n sourceQueue: queue,\n sourceTransport: this.name,\n };\n\n try {\n await sub.handler(message.envelope, receipt);\n } catch (error) {\n // Handler errors should be caught in the pipeline\n this.logger.error('🔴 Handler error in message processing', error);\n }\n }\n }\n\n async subscribe(\n queue: string,\n handler: MessageHandler,\n options: SubscribeOptions = {},\n ): Promise<Subscription> {\n if (!this.connected) {\n throw new TransportNotConnectedError(this.name, 'subscribe');\n }\n\n const subscription: ActiveSubscription = {\n handler,\n options,\n active: true,\n };\n\n const subs = this.subscriptions.get(queue) ?? [];\n subs.push(subscription);\n this.subscriptions.set(queue, subs);\n\n // Deliver any pending messages\n const messages = this.queues.get(queue) ?? [];\n for (const message of messages) {\n if (message.completed) continue;\n await this.deliverToSubscribers(queue, message);\n }\n\n return {\n unsubscribe: async () => {\n subscription.active = false;\n const remaining = subs.filter((s) => s !== subscription);\n if (remaining.length > 0) {\n this.subscriptions.set(queue, remaining);\n } else {\n this.subscriptions.delete(queue);\n }\n },\n get isActive() {\n return subscription.active;\n },\n };\n }\n\n async complete(receipt: MessageReceipt): Promise<void> {\n const message = receipt.handle as QueuedMessage;\n message.completed = true;\n this.completedMessages.push(receipt);\n }\n\n async sendToDeadLetter(\n receipt: MessageReceipt,\n dlqName: string,\n envelope: Envelope,\n _reason: string,\n ): Promise<void> {\n const dlqQueueName = `${receipt.sourceQueue}.${dlqName}`;\n await this.enqueue(dlqQueueName, envelope);\n await this.complete(receipt);\n }\n\n // Test helpers\n\n /**\n * Gets the current size of a queue.\n */\n getQueueSize(queue: string): number {\n const messages = this.queues.get(queue);\n if (!messages) return 0;\n return messages.filter((m) => !m.completed).length;\n }\n\n /**\n * Gets all completed message receipts.\n */\n getCompleted(): readonly MessageReceipt[] {\n return this.completedMessages;\n }\n\n /**\n * Gets pending (uncompleted) messages from a queue.\n */\n getPendingMessages(queue: string): readonly Envelope[] {\n const messages = this.queues.get(queue);\n if (!messages) return [];\n return messages.filter((m) => !m.completed).map((m) => m.envelope);\n }\n\n /**\n * Clears all state (for test isolation).\n */\n clear(): void {\n this.queues.clear();\n this.subscriptions.clear();\n this.completedMessages.length = 0;\n this.messageIdCounter = 0;\n\n for (const timer of this.delayedTimers) {\n clearTimeout(timer);\n }\n this.delayedTimers.clear();\n }\n\n /**\n * Receives one message from the queue without a subscription.\n * Useful for testing.\n */\n async receiveOne(\n queue: string,\n ): Promise<{ envelope: Envelope; receipt: MessageReceipt } | null> {\n const messages = this.queues.get(queue);\n if (!messages) return null;\n\n const pending = messages.find((m) => !m.completed);\n if (!pending) return null;\n\n const receipt: MessageReceipt = {\n handle: pending,\n redelivered: false,\n attemptNumber: pending.envelope.docket.attempts,\n deliveryCount: pending.envelope.docket.attempts,\n sourceQueue: queue,\n sourceTransport: this.name,\n };\n\n return { envelope: pending.envelope, receipt };\n }\n\n private getOrCreateQueue(queue: string): QueuedMessage[] {\n let messages = this.queues.get(queue);\n if (!messages) {\n messages = [];\n this.queues.set(queue, messages);\n }\n return messages;\n }\n}\n","import { AllTransportsFailedError } from '../../errors/index.js';\nimport type { TransportFallbackContext } from '../../hooks/index.js';\nimport type { Topology } from '../../topology/types.js';\nimport type { Envelope } from '../../types/index.js';\nimport type { TransportCapabilities } from '../capabilities.js';\nimport type {\n MessageHandler,\n MessageReceipt,\n SendOptions,\n SubscribeOptions,\n Subscription,\n Transport,\n} from '../transport.js';\n\n/**\n * Symbol key used to store the source transport on wrapped receipts.\n */\nconst SOURCE_TRANSPORT = Symbol('sourceTransport');\n\n/**\n * Extracts the source transport from a tagged receipt.\n */\nfunction getSourceTransport(receipt: MessageReceipt): Transport | undefined {\n return (receipt as unknown as Record<symbol, Transport | undefined>)[\n SOURCE_TRANSPORT\n ];\n}\n\n/**\n * Configuration for MultiTransport.\n */\nexport interface MultiTransportConfig {\n /**\n * Ordered list of transports.\n * First transport is primary, rest are used as fallbacks when primary fails\n * (if fallback is enabled), or can be explicitly selected via the getDesiredBackend hook.\n */\n readonly transports: readonly Transport[];\n\n /**\n * Whether to automatically try fallback transports when the primary/selected fails.\n * When true (default), send() will try each transport in order until one succeeds.\n * When false, send() will only use the selected transport and throw immediately on failure.\n *\n * @default true\n */\n readonly fallbackEnabled?: boolean;\n}\n\n/**\n * Hooks for MultiTransport.\n */\nexport interface MultiTransportHooks {\n /**\n * Hook to dynamically select which backend to use.\n * Return the transport name (e.g., 'local', 'rabbitmq') or undefined to use primary.\n *\n * @example\n * ```typescript\n * getDesiredBackend: async () => {\n * if (process.env.SANDBOX === 'true') return 'local';\n * const backend = await runtimeConfig.get('events.backend');\n * return backend || 'rabbitmq';\n * }\n * ```\n */\n readonly getDesiredBackend?: () =>\n | string\n | undefined\n | Promise<string | undefined>;\n\n /**\n * Called when a fallback transport is used successfully after the selected one fails.\n * Only called when fallbackEnabled is true.\n */\n readonly onEnqueueFallback?: (context: TransportFallbackContext) => void;\n}\n\n/**\n * Computes merged capabilities from multiple transports.\n * Uses the most restrictive/conservative interpretation.\n */\nfunction mergeCapabilities(\n transports: readonly Transport[],\n): TransportCapabilities {\n const primary = transports[0];\n if (!primary) {\n throw new Error('At least one transport is required');\n }\n\n // For multi-transport scenarios, we use primary's capabilities since that's\n // what we'll use for subscriptions and most operations\n return primary.capabilities;\n}\n\n/**\n * A transport wrapper that manages multiple transports.\n *\n * Features:\n * - All transports are connected upfront\n * - send() tries transports in order until one succeeds (fallback behavior)\n * - Specific transport can be selected via getDesiredBackend hook\n * - Subscriptions are created on ALL transports\n *\n * @example\n * ```typescript\n * const transport = new MultiTransport(\n * { transports: [rabbitMQTransport, localTransport] },\n * { onEnqueueFallback: (ctx) => console.warn(`Fallback to ${ctx.nextTransport}`) },\n * );\n * ```\n */\nexport class MultiTransport implements Transport {\n readonly name: string;\n readonly capabilities: TransportCapabilities;\n readonly primary: Transport;\n\n /** All available transports, in order of preference (primary first). */\n readonly transports: readonly Transport[];\n\n /** Whether fallback to secondary transports is enabled. */\n readonly fallbackEnabled: boolean;\n\n private readonly hooks: MultiTransportHooks;\n private connected = false;\n\n constructor(config: MultiTransportConfig, hooks: MultiTransportHooks = {}) {\n const primary = config.transports[0];\n if (!primary) {\n throw new Error('At least one transport is required');\n }\n\n this.primary = primary;\n this.transports = config.transports;\n this.fallbackEnabled = config.fallbackEnabled ?? true;\n this.hooks = hooks;\n this.name = `multi(${this.transports.map((t) => t.name).join(',')})`;\n this.capabilities = mergeCapabilities(this.transports);\n }\n\n async connect(): Promise<void> {\n // Connect all transports in parallel\n await Promise.all(this.transports.map((t) => t.connect()));\n this.connected = true;\n }\n\n async disconnect(): Promise<void> {\n // Disconnect all transports in parallel\n await Promise.all(this.transports.map((t) => t.disconnect()));\n this.connected = false;\n }\n\n isConnected(): boolean {\n // Consider connected if primary is connected\n return this.connected && this.primary.isConnected();\n }\n\n async applyTopology(topology: Topology): Promise<void> {\n // Apply topology to all transports so they're all ready\n await Promise.all(this.transports.map((t) => t.applyTopology(topology)));\n }\n\n async send(\n queue: string,\n envelope: Envelope,\n options?: SendOptions,\n ): Promise<Transport['name']> {\n // Determine which transport to use\n const selectedTransport = await this.selectTransport();\n\n // If fallback is disabled, only use selected transport\n if (!this.fallbackEnabled) {\n return selectedTransport.send(queue, envelope, options);\n }\n\n // Build transport order: selected first, then others\n const transportOrder = this.getTransportOrder(selectedTransport);\n\n const errors: Error[] = [];\n\n for (let i = 0; i < transportOrder.length; i++) {\n const transport = transportOrder[i]!;\n try {\n return await transport.send(queue, envelope, options);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n errors.push(err);\n\n // Notify about fallback before trying next transport\n const nextTransport = transportOrder[i + 1];\n if (nextTransport && this.hooks.onEnqueueFallback) {\n this.hooks.onEnqueueFallback({\n envelope,\n queue,\n failedTransport: transport.name,\n nextTransport: nextTransport.name,\n error: err,\n });\n }\n // Continue to next transport\n }\n }\n\n // All transports failed\n throw new AllTransportsFailedError(queue, errors);\n }\n\n /**\n * Selects the transport to use based on the getDesiredBackend hook.\n */\n private async selectTransport(): Promise<Transport> {\n if (!this.hooks.getDesiredBackend) {\n return this.primary;\n }\n\n try {\n const desiredBackend = await this.hooks.getDesiredBackend();\n if (!desiredBackend) {\n return this.primary;\n }\n\n const selected = this.transports.find((t) => t.name === desiredBackend);\n if (selected) {\n return selected;\n }\n\n // Desired backend not found, use primary\n return this.primary;\n } catch {\n // Hook threw, use primary\n return this.primary;\n }\n }\n\n /**\n * Returns transports in order, with the selected transport first.\n */\n private getTransportOrder(selected: Transport): readonly Transport[] {\n if (selected === this.primary) {\n return this.transports;\n }\n\n // Put selected first, then the rest (excluding selected)\n return [selected, ...this.transports.filter((t) => t !== selected)];\n }\n\n async subscribe(\n queue: string,\n handler: MessageHandler,\n options?: SubscribeOptions,\n ): Promise<Subscription> {\n // Subscribe on ALL transports so messages are processed regardless of\n // which transport they were enqueued to\n const subscriptions = await Promise.all(\n this.transports.map((transport) => {\n // Wrap handler to tag receipts with source transport\n const wrappedHandler: MessageHandler = (envelope, receipt) => {\n const taggedReceipt = Object.assign(receipt, {\n [SOURCE_TRANSPORT]: transport,\n });\n return handler(envelope, taggedReceipt);\n };\n return transport.subscribe(queue, wrappedHandler, options);\n }),\n );\n\n return {\n unsubscribe: async () => {\n await Promise.all(subscriptions.map((s) => s.unsubscribe()));\n },\n get isActive() {\n return subscriptions.some((s) => s.isActive);\n },\n };\n }\n\n async complete(receipt: MessageReceipt): Promise<void> {\n const transport = getSourceTransport(receipt) ?? this.primary;\n return transport.complete(receipt);\n }\n\n async sendToDeadLetter(\n receipt: MessageReceipt,\n dlqName: string,\n envelope: Envelope,\n reason: string,\n ): Promise<void> {\n const transport = getSourceTransport(receipt) ?? this.primary;\n if (transport.sendToDeadLetter) {\n return transport.sendToDeadLetter(receipt, dlqName, envelope, reason);\n }\n throw new Error('Transport does not support dead letter routing');\n }\n}\n","import type { Channel, ChannelModel, ConsumeMessage, Options } from 'amqplib';\nimport amqplib from 'amqplib';\nimport { RabbitMQCodec } from '../../codec/rabbitmq-codec.js';\nimport {\n DelayedMessagesNotSupportedError,\n TransportNotConnectedError,\n} from '../../errors/index.js';\nimport { type Logger, consoleLogger } from '../../hooks/index.js';\nimport type { QueueDefinition, Topology } from '../../topology/types.js';\nimport type { Envelope } from '../../types/index.js';\nimport type { TransportCapabilities } from '../capabilities.js';\nimport {\n ConnectionManager,\n type ConnectionManagerConfig,\n} from '../connection-manager.js';\nimport type {\n MessageHandler,\n MessageReceipt,\n SendOptions,\n SubscribeOptions,\n Subscription,\n Transport,\n} from '../transport.js';\n\n/**\n * Configuration options for the RabbitMQ transport.\n */\nexport interface RabbitMQTransportConfig {\n /** RabbitMQ connection URL */\n readonly url: string;\n\n /** Connection manager configuration */\n readonly connection?: Partial<ConnectionManagerConfig> | undefined;\n\n /** Use quorum queues for durability (default: true) */\n readonly quorumQueues?: boolean | undefined;\n\n /** Default prefetch count per consumer (default: 10) */\n readonly defaultPrefetch?: number | undefined;\n\n /** Enable the delayed message exchange plugin if available (default: true) */\n readonly enableDelayedMessages?: boolean | undefined;\n\n /** Logger for transport events (defaults to console) */\n readonly logger?: Logger | undefined;\n}\n\n/**\n * Internal structure for tracking a queue's dedicated channel.\n */\ninterface QueueChannel {\n readonly channel: Channel;\n readonly consumers: ActiveConsumer[];\n}\n\n/**\n * Internal structure for tracking active consumers.\n */\ninterface ActiveConsumer {\n readonly consumerTag: string;\n readonly queue: string;\n active: boolean;\n}\n\n/**\n * RabbitMQ transport implementation using amqplib.\n */\nexport class RabbitMQTransport implements Transport {\n readonly name = 'rabbitmq';\n\n private _capabilities: TransportCapabilities = {\n deliveryModes: ['at-least-once'],\n delayedMessages: false,\n deadLetterRouting: 'native',\n attemptTracking: true,\n concurrencyModel: 'prefetch',\n ordering: 'none',\n priorities: true,\n };\n\n get capabilities(): TransportCapabilities {\n return this._capabilities;\n }\n\n private connection: ChannelModel | null = null;\n private publishChannel: Channel | null = null;\n private readonly connectionManager: ConnectionManager;\n private readonly queueChannels = new Map<string, QueueChannel>();\n private topology: Topology | null = null;\n private readonly codec = new RabbitMQCodec();\n\n private readonly config: Required<\n Omit<RabbitMQTransportConfig, 'connection' | 'logger'>\n > & {\n connection: Partial<ConnectionManagerConfig>;\n };\n\n private readonly logger: Logger;\n private delayedExchangeAvailable = false;\n\n constructor(config: RabbitMQTransportConfig) {\n this.logger = config.logger ?? consoleLogger;\n this.config = {\n url: config.url,\n connection: config.connection ?? {},\n quorumQueues: config.quorumQueues ?? true,\n defaultPrefetch: config.defaultPrefetch ?? 10,\n enableDelayedMessages: config.enableDelayedMessages ?? true,\n };\n\n this.connectionManager = new ConnectionManager(\n () => this.doConnect(),\n () => this.doDisconnect(),\n this.config.connection,\n );\n }\n\n async connect(): Promise<void> {\n await this.connectionManager.connect();\n }\n\n async disconnect(): Promise<void> {\n await this.connectionManager.disconnect();\n }\n\n isConnected(): boolean {\n return this.connectionManager.isConnected();\n }\n\n async applyTopology(topology: Topology): Promise<void> {\n this.topology = topology;\n\n if (!this.publishChannel) {\n throw new TransportNotConnectedError(this.name, 'applyTopology');\n }\n\n const channel = this.publishChannel;\n\n // Create the main exchange for routing messages to queues\n const mainExchange = this.getMainExchangeName(topology.namespace);\n await channel.assertExchange(mainExchange, 'direct', { durable: true });\n\n // Create dead-letter exchange if DLQ is enabled\n const dlxExchange = this.getDLXExchangeName(topology.namespace);\n if (\n topology.deadLetter.unhandled.enabled ||\n topology.deadLetter.undeliverable.enabled\n ) {\n await channel.assertExchange(dlxExchange, 'direct', { durable: true });\n }\n\n // Check for delayed message exchange plugin\n if (this.config.enableDelayedMessages) {\n await this.setupDelayedExchange(topology.namespace);\n }\n\n // Create work queues\n for (const queueDef of topology.queues) {\n await this.assertWorkQueue(channel, topology, queueDef);\n }\n\n // Create DLQs\n if (topology.deadLetter.unhandled.enabled) {\n await this.assertDeadLetterQueues(channel, topology, 'unhandled');\n }\n\n if (topology.deadLetter.undeliverable.enabled) {\n await this.assertDeadLetterQueues(channel, topology, 'undeliverable');\n }\n }\n\n async send(\n queue: string,\n envelope: Envelope,\n options?: SendOptions,\n ): Promise<Transport['name']> {\n if (!this.publishChannel || !this.topology) {\n throw new TransportNotConnectedError(this.name, 'send');\n }\n\n const encoded = this.codec.encode(envelope);\n const buffer = Buffer.from(encoded.body);\n\n const publishOptions: Options.Publish = {\n persistent: true,\n contentType: encoded.contentType,\n messageId: envelope.id,\n timestamp: Date.now(),\n headers: encoded.headers,\n };\n\n if (options?.priority !== undefined) {\n publishOptions.priority = options.priority;\n }\n\n // Handle delayed messages\n if (options?.delay !== undefined && options.delay > 0) {\n if (!this.delayedExchangeAvailable) {\n throw new DelayedMessagesNotSupportedError(this.name);\n }\n\n const delayedExchange = this.getDelayedExchangeName(\n this.topology.namespace,\n );\n publishOptions.headers = {\n ...publishOptions.headers,\n 'x-delay': options.delay,\n };\n this.publishChannel.publish(\n delayedExchange,\n queue,\n buffer,\n publishOptions,\n );\n return this.name;\n }\n\n // Transport-specific options\n if (options?.transport?.rabbitmq?.expiration !== undefined) {\n publishOptions.expiration = String(options.transport.rabbitmq.expiration);\n }\n\n if (options?.transport?.rabbitmq?.persistent !== undefined) {\n publishOptions.persistent = options.transport.rabbitmq.persistent;\n }\n\n const routingKey = options?.transport?.rabbitmq?.routingKey ?? queue;\n const exchange = this.getMainExchangeName(this.topology.namespace);\n\n this.publishChannel.publish(exchange, routingKey, buffer, publishOptions);\n return this.name;\n }\n\n async subscribe(\n queue: string,\n handler: MessageHandler,\n options: SubscribeOptions = {},\n ): Promise<Subscription> {\n if (!this.connection || !this.topology) {\n throw new TransportNotConnectedError(this.name, 'subscribe');\n }\n\n // Get or create a dedicated channel for this queue\n const queueChannel = await this.getOrCreateQueueChannel(queue, options);\n const { channel } = queueChannel;\n\n const consumer: ActiveConsumer = {\n consumerTag: '',\n queue,\n active: true,\n };\n\n const { consumerTag } = await channel.consume(\n queue,\n async (msg: ConsumeMessage | null) => {\n if (!msg || !consumer.active) return;\n\n const attemptNumber = this.getAttemptNumber(msg);\n const receipt: MessageReceipt = {\n handle: { channel, msg },\n redelivered: msg.fields.redelivered,\n attemptNumber,\n deliveryCount: this.getDeliveryCount(msg, attemptNumber),\n sourceQueue: queue,\n sourceTransport: this.name,\n };\n\n try {\n const headers = (msg.properties.headers ?? {}) as Record<\n string,\n unknown\n >;\n const envelope = this.codec.decode(\n new Uint8Array(msg.content),\n headers,\n );\n await handler(envelope, receipt);\n } catch (error) {\n // Handler errors should be caught in the pipeline\n this.logger.error(\n '[Matador] 🔴 Handler error in message processing',\n error,\n );\n }\n },\n { noAck: false }, // Always manually ack\n );\n\n // Update the consumer tag\n (consumer as { consumerTag: string }).consumerTag = consumerTag;\n\n // Track the consumer\n queueChannel.consumers.push(consumer);\n\n return {\n unsubscribe: async () => {\n consumer.active = false;\n try {\n await channel.cancel(consumerTag);\n } catch {\n // Channel may already be closed\n }\n\n // Remove consumer from tracking\n const idx = queueChannel.consumers.indexOf(consumer);\n if (idx !== -1) {\n queueChannel.consumers.splice(idx, 1);\n }\n\n // Close channel if no more consumers on this queue\n if (queueChannel.consumers.length === 0) {\n try {\n await channel.close();\n } catch {\n // Ignore\n }\n this.queueChannels.delete(queue);\n }\n },\n get isActive() {\n return consumer.active;\n },\n };\n }\n\n async complete(receipt: MessageReceipt): Promise<void> {\n const { channel, msg } = receipt.handle as {\n channel: Channel;\n msg: ConsumeMessage;\n };\n\n try {\n channel.ack(msg);\n } catch {\n // Channel may be closed, ignore\n }\n }\n\n async sendToDeadLetter(\n receipt: MessageReceipt,\n dlqName: string,\n envelope: Envelope,\n reason: string,\n ): Promise<void> {\n if (!this.publishChannel || !this.topology) {\n throw new TransportNotConnectedError(this.name, 'sendToDeadLetter');\n }\n\n // Add error info to envelope\n const dlqEnvelope: Envelope = {\n ...envelope,\n docket: {\n ...envelope.docket,\n lastError: reason,\n firstError: envelope.docket.firstError ?? reason,\n originalQueue: receipt.sourceQueue,\n },\n };\n\n const encoded = this.codec.encode(dlqEnvelope);\n const buffer = Buffer.from(encoded.body);\n const dlxExchange = this.getDLXExchangeName(this.topology.namespace);\n const dlqQueueName = `${receipt.sourceQueue}.${dlqName}`;\n\n const publishOptions: Options.Publish = {\n persistent: true,\n contentType: encoded.contentType,\n messageId: envelope.id,\n timestamp: Date.now(),\n headers: {\n ...encoded.headers,\n 'x-matador-dead-letter-reason': reason,\n },\n };\n\n this.publishChannel.publish(\n dlxExchange,\n dlqQueueName,\n buffer,\n publishOptions,\n );\n\n // Complete the original message\n await this.complete(receipt);\n }\n\n // Private methods\n\n /**\n * Gets or creates a dedicated channel for a queue subscription.\n *\n * We create separate channels per subscribed queue to enable independent\n * prefetch/concurrency control.\n */\n private async getOrCreateQueueChannel(\n queue: string,\n options: SubscribeOptions,\n ): Promise<QueueChannel> {\n const existing = this.queueChannels.get(queue);\n if (existing) {\n return existing;\n }\n\n if (!this.connection) {\n throw new TransportNotConnectedError(\n this.name,\n 'getOrCreateQueueChannel',\n );\n }\n\n // Create a dedicated channel for this queue to control prefetch independently\n const channel = await this.connection.createChannel();\n\n const prefetch =\n options.transport?.rabbitmq?.prefetch ??\n options.concurrency ??\n this.config.defaultPrefetch ??\n 10;\n\n await channel.prefetch(prefetch);\n\n const queueChannel: QueueChannel = {\n channel,\n consumers: [],\n };\n\n this.queueChannels.set(queue, queueChannel);\n\n return queueChannel;\n }\n\n private async doConnect(): Promise<void> {\n const connection = await amqplib.connect(this.config.url);\n this.connection = connection;\n\n // Handle connection errors - let ConnectionManager handle reconnection\n connection.on('error', (err: Error) => {\n this.logger.error('[Matador] 🔴 RabbitMQ connection error', err);\n });\n\n connection.on('close', () => {\n if (this.connectionManager.isConnected()) {\n // Unexpected close, trigger reconnection\n this.connectionManager.handleConnectionLost(\n new Error('Connection closed unexpectedly'),\n );\n }\n });\n\n // Create the publish channel\n this.publishChannel = await connection.createChannel();\n\n // Handle publish channel errors to prevent unhandled error events\n this.publishChannel.on('error', (err: Error) => {\n this.logger.error('[Matador] 🔴 RabbitMQ publish channel error', err);\n });\n\n // Re-apply topology if we have one (reconnection scenario)\n if (this.topology) {\n await this.applyTopology(this.topology);\n }\n }\n\n private async doDisconnect(): Promise<void> {\n // Cancel all consumers and close queue channels\n for (const queueChannel of this.queueChannels.values()) {\n for (const consumer of queueChannel.consumers) {\n consumer.active = false;\n try {\n await queueChannel.channel.cancel(consumer.consumerTag);\n } catch {\n // Ignore errors during cleanup\n }\n }\n try {\n await queueChannel.channel.close();\n } catch {\n // Ignore\n }\n }\n this.queueChannels.clear();\n\n // Close publish channel\n if (this.publishChannel) {\n try {\n await this.publishChannel.close();\n } catch {\n // Ignore\n }\n this.publishChannel = null;\n }\n\n // Close connection\n if (this.connection) {\n try {\n await this.connection.close();\n } catch {\n // Ignore\n }\n this.connection = null;\n }\n\n // Reset capabilities\n this.delayedExchangeAvailable = false;\n this._capabilities = {\n ...this._capabilities,\n delayedMessages: false,\n };\n }\n\n private async setupDelayedExchange(namespace: string): Promise<void> {\n if (!this.connection) {\n return;\n }\n\n // Default to disabled\n this.delayedExchangeAvailable = false;\n\n const delayedExchange = this.getDelayedExchangeName(namespace);\n const connection = this.connection;\n\n // Use a promise-based approach to ensure all error paths resolve cleanly\n // This prevents any error from propagating and affecting other channels\n return new Promise<void>((resolve) => {\n let resolved = false;\n const safeResolve = () => {\n if (!resolved) {\n resolved = true;\n resolve();\n }\n };\n\n connection\n .createChannel()\n .then((probeChannel) => {\n // Handle channel errors - this fires when RabbitMQ closes the channel\n probeChannel.on('error', () => {\n safeResolve();\n });\n\n // Handle channel close\n probeChannel.on('close', () => {\n safeResolve();\n });\n\n // Try to declare a delayed exchange\n // This will fail if the plugin is not installed\n probeChannel\n .assertExchange(delayedExchange, 'x-delayed-message', {\n durable: true,\n arguments: { 'x-delayed-type': 'direct' },\n })\n .then(() => {\n this.delayedExchangeAvailable = true;\n this._capabilities = {\n ...this._capabilities,\n delayedMessages: true,\n };\n this.logger.debug(\n '[Matador] 🔌 Delayed message exchange plugin detected',\n );\n // Close the probe channel gracefully\n probeChannel.close().catch(() => {});\n safeResolve();\n })\n .catch(() => {\n // assertExchange failed - plugin not available\n // Channel is already closed by RabbitMQ, no need to close\n this.logger.warn(\n '[Matador] 🟡 RabbitMQ delayed message exchange plugin not available. ' +\n 'Delayed messages will not be supported.',\n );\n safeResolve();\n });\n })\n .catch(() => {\n // Failed to create channel - shouldn't happen but handle it\n safeResolve();\n });\n });\n }\n\n private async assertWorkQueue(\n channel: Channel,\n topology: Topology,\n queueDef: QueueDefinition,\n ): Promise<void> {\n const queueName = queueDef.exact\n ? queueDef.name\n : `${topology.namespace}.${queueDef.name}`;\n\n const queueOptions: Options.AssertQueue = {\n durable: true,\n arguments: {} as Record<string, unknown>,\n };\n\n // Use quorum queues for durability\n if (this.config.quorumQueues && !queueDef.exact) {\n queueOptions.arguments['x-queue-type'] = 'quorum';\n }\n\n // Set up dead-letter exchange routing\n const dlxExchange = this.getDLXExchangeName(topology.namespace);\n if (\n topology.deadLetter.unhandled.enabled ||\n topology.deadLetter.undeliverable.enabled\n ) {\n queueOptions.arguments['x-dead-letter-exchange'] = dlxExchange;\n }\n\n // Enable priority if requested\n if (queueDef.priorities) {\n queueOptions.arguments['x-max-priority'] = 10;\n }\n\n // Set consumer timeout if specified\n if (queueDef.consumerTimeout) {\n queueOptions.arguments['x-consumer-timeout'] = queueDef.consumerTimeout;\n }\n\n await channel.assertQueue(queueName, queueOptions);\n\n // Bind queue to main exchange\n const mainExchange = this.getMainExchangeName(topology.namespace);\n await channel.bindQueue(queueName, mainExchange, queueName);\n\n // Bind to delayed exchange if available\n if (this.delayedExchangeAvailable) {\n const delayedExchange = this.getDelayedExchangeName(topology.namespace);\n await channel.bindQueue(queueName, delayedExchange, queueName);\n }\n\n // Create retry queue if retry is enabled\n if (topology.retry.enabled) {\n await this.assertRetryQueue(channel, topology, queueName);\n }\n }\n\n private async assertRetryQueue(\n channel: Channel,\n topology: Topology,\n workQueueName: string,\n ): Promise<void> {\n const retryQueueName = `${workQueueName}.retry`;\n const mainExchange = this.getMainExchangeName(topology.namespace);\n\n const retryQueueOptions: Options.AssertQueue = {\n durable: true,\n arguments: {\n 'x-dead-letter-exchange': mainExchange,\n 'x-dead-letter-routing-key': workQueueName,\n 'x-message-ttl': topology.retry.defaultDelayMs,\n } as Record<string, unknown>,\n };\n\n if (this.config.quorumQueues) {\n retryQueueOptions.arguments['x-queue-type'] = 'quorum';\n }\n\n await channel.assertQueue(retryQueueName, retryQueueOptions);\n await channel.bindQueue(retryQueueName, mainExchange, retryQueueName);\n }\n\n private async assertDeadLetterQueues(\n channel: Channel,\n topology: Topology,\n dlqType: 'unhandled' | 'undeliverable',\n ): Promise<void> {\n const dlxExchange = this.getDLXExchangeName(topology.namespace);\n const dlConfig = topology.deadLetter[dlqType];\n\n for (const queueDef of topology.queues) {\n if (queueDef.exact) continue;\n\n const workQueueName = `${topology.namespace}.${queueDef.name}`;\n const dlqName = `${workQueueName}.${dlqType}`;\n\n const dlqOptions: Options.AssertQueue = {\n durable: true,\n arguments: {} as Record<string, unknown>,\n };\n\n if (dlConfig.maxLength) {\n dlqOptions.arguments['x-max-length'] = dlConfig.maxLength;\n }\n\n // DLQs use classic queues (not quorum) for simplicity\n await channel.assertQueue(dlqName, dlqOptions);\n await channel.bindQueue(dlqName, dlxExchange, dlqName);\n }\n }\n\n private getMainExchangeName(namespace: string): string {\n return `${namespace}.exchange`;\n }\n\n private getDLXExchangeName(namespace: string): string {\n return `${namespace}.dlx`;\n }\n\n private getDelayedExchangeName(namespace: string): string {\n return `${namespace}.delayed`;\n }\n\n private getAttemptNumber(msg: ConsumeMessage): number {\n const headerValue = msg.properties.headers?.['x-matador-attempts'];\n if (typeof headerValue === 'number') {\n return headerValue;\n }\n // Check for x-death header (native DLX redelivery count)\n const xDeath = msg.properties.headers?.['x-death'];\n if (Array.isArray(xDeath) && xDeath.length > 0) {\n const deathCount = xDeath.reduce(\n (sum: number, death: { count?: number }) => sum + (death.count ?? 0),\n 0,\n );\n return deathCount + 1;\n }\n return 1;\n }\n\n /**\n * Gets the native delivery count for poison message detection.\n * This tracks how many times the message was delivered without acknowledgment,\n * which helps detect crash loops.\n */\n private getDeliveryCount(msg: ConsumeMessage, attemptNumber: number): number {\n // Check for explicit delivery count header (some RabbitMQ setups track this)\n const deliveryCount = msg.properties.headers?.['x-delivery-count'];\n if (typeof deliveryCount === 'number') {\n return deliveryCount;\n }\n\n // Check x-death header for dead-letter redelivery count\n const xDeath = msg.properties.headers?.['x-death'];\n if (Array.isArray(xDeath) && xDeath.length > 0) {\n const deathCount = xDeath.reduce(\n (sum: number, death: { count?: number }) => sum + (death.count ?? 0),\n 0,\n );\n // Add 1 because we're currently being delivered again\n return deathCount + 1;\n }\n\n // If redelivered flag is set but no other tracking, count as 2 (first + this delivery)\n if (msg.fields.redelivered) {\n return Math.max(2, attemptNumber);\n }\n\n // Default to attempt number\n return attemptNumber;\n }\n}\n"]}