@ddd-ts-kit/rabbitmq 0.0.0-stage → 0.1.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 (174) hide show
  1. package/README.md +277 -2
  2. package/dist/codec/attempt-of.d.ts +4 -0
  3. package/dist/codec/attempt-of.d.ts.map +1 -0
  4. package/dist/codec/attempt-of.js +8 -0
  5. package/dist/codec/attempt-of.js.map +1 -0
  6. package/dist/codec/decode.d.ts +5 -0
  7. package/dist/codec/decode.d.ts.map +1 -0
  8. package/dist/codec/decode.js +39 -0
  9. package/dist/codec/decode.js.map +1 -0
  10. package/dist/codec/encode.d.ts +8 -0
  11. package/dist/codec/encode.d.ts.map +1 -0
  12. package/dist/codec/encode.js +23 -0
  13. package/dist/codec/encode.js.map +1 -0
  14. package/dist/codec/headers-of.d.ts +4 -0
  15. package/dist/codec/headers-of.d.ts.map +1 -0
  16. package/dist/codec/headers-of.js +6 -0
  17. package/dist/codec/headers-of.js.map +1 -0
  18. package/dist/codec/headers.d.ts +7 -0
  19. package/dist/codec/headers.d.ts.map +1 -0
  20. package/dist/codec/headers.js +7 -0
  21. package/dist/codec/headers.js.map +1 -0
  22. package/dist/codec/publication.d.ts +7 -0
  23. package/dist/codec/publication.d.ts.map +1 -0
  24. package/dist/codec/publication.js +2 -0
  25. package/dist/codec/publication.js.map +1 -0
  26. package/dist/codec/republication.d.ts +5 -0
  27. package/dist/codec/republication.d.ts.map +1 -0
  28. package/dist/codec/republication.js +20 -0
  29. package/dist/codec/republication.js.map +1 -0
  30. package/dist/connection/broker-link.d.ts +44 -0
  31. package/dist/connection/broker-link.d.ts.map +1 -0
  32. package/dist/connection/broker-link.js +133 -0
  33. package/dist/connection/broker-link.js.map +1 -0
  34. package/dist/consumption/consumption.d.ts +50 -0
  35. package/dist/consumption/consumption.d.ts.map +1 -0
  36. package/dist/consumption/consumption.js +214 -0
  37. package/dist/consumption/consumption.js.map +1 -0
  38. package/dist/consumption/failure-of.d.ts +7 -0
  39. package/dist/consumption/failure-of.d.ts.map +1 -0
  40. package/dist/consumption/failure-of.js +18 -0
  41. package/dist/consumption/failure-of.js.map +1 -0
  42. package/dist/consumption/poison-message.d.ts +3 -0
  43. package/dist/consumption/poison-message.d.ts.map +1 -0
  44. package/dist/consumption/poison-message.js +3 -0
  45. package/dist/consumption/poison-message.js.map +1 -0
  46. package/dist/consumption/track.d.ts +3 -0
  47. package/dist/consumption/track.d.ts.map +1 -0
  48. package/dist/consumption/track.js +9 -0
  49. package/dist/consumption/track.js.map +1 -0
  50. package/dist/errors/broker-unavailable-error.d.ts +8 -0
  51. package/dist/errors/broker-unavailable-error.d.ts.map +1 -0
  52. package/dist/errors/broker-unavailable-error.js +12 -0
  53. package/dist/errors/broker-unavailable-error.js.map +1 -0
  54. package/dist/errors/consumer-name-required-error.d.ts +5 -0
  55. package/dist/errors/consumer-name-required-error.d.ts.map +1 -0
  56. package/dist/errors/consumer-name-required-error.js +8 -0
  57. package/dist/errors/consumer-name-required-error.js.map +1 -0
  58. package/dist/errors/event-bus-closed-error.d.ts +5 -0
  59. package/dist/errors/event-bus-closed-error.d.ts.map +1 -0
  60. package/dist/errors/event-bus-closed-error.js +8 -0
  61. package/dist/errors/event-bus-closed-error.js.map +1 -0
  62. package/dist/errors/failure-code.d.ts +6 -0
  63. package/dist/errors/failure-code.d.ts.map +1 -0
  64. package/dist/errors/failure-code.js +15 -0
  65. package/dist/errors/failure-code.js.map +1 -0
  66. package/dist/errors/publish-not-confirmed-error.d.ts +7 -0
  67. package/dist/errors/publish-not-confirmed-error.d.ts.map +1 -0
  68. package/dist/errors/publish-not-confirmed-error.js +11 -0
  69. package/dist/errors/publish-not-confirmed-error.js.map +1 -0
  70. package/dist/errors/unroutable-event-error.d.ts +8 -0
  71. package/dist/errors/unroutable-event-error.d.ts.map +1 -0
  72. package/dist/errors/unroutable-event-error.js +13 -0
  73. package/dist/errors/unroutable-event-error.js.map +1 -0
  74. package/dist/ignore.d.ts +3 -0
  75. package/dist/ignore.d.ts.map +1 -0
  76. package/dist/ignore.js +5 -0
  77. package/dist/ignore.js.map +1 -0
  78. package/dist/index.d.ts +23 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +11 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/messaging-system.d.ts +3 -0
  83. package/dist/messaging-system.d.ts.map +1 -0
  84. package/dist/messaging-system.js +3 -0
  85. package/dist/messaging-system.js.map +1 -0
  86. package/dist/options/queue-type.d.ts +2 -0
  87. package/dist/options/queue-type.d.ts.map +1 -0
  88. package/dist/options/queue-type.js +2 -0
  89. package/dist/options/queue-type.js.map +1 -0
  90. package/dist/options/rabbit-mq-delivery.d.ts +12 -0
  91. package/dist/options/rabbit-mq-delivery.d.ts.map +1 -0
  92. package/dist/options/rabbit-mq-delivery.js +2 -0
  93. package/dist/options/rabbit-mq-delivery.js.map +1 -0
  94. package/dist/options/rabbit-mq-event-bus-options.d.ts +31 -0
  95. package/dist/options/rabbit-mq-event-bus-options.d.ts.map +1 -0
  96. package/dist/options/rabbit-mq-event-bus-options.js +2 -0
  97. package/dist/options/rabbit-mq-event-bus-options.js.map +1 -0
  98. package/dist/options/rabbit-mq-failure.d.ts +17 -0
  99. package/dist/options/rabbit-mq-failure.d.ts.map +1 -0
  100. package/dist/options/rabbit-mq-failure.js +2 -0
  101. package/dist/options/rabbit-mq-failure.js.map +1 -0
  102. package/dist/options/reconnect-options.d.ts +9 -0
  103. package/dist/options/reconnect-options.d.ts.map +1 -0
  104. package/dist/options/reconnect-options.js +2 -0
  105. package/dist/options/reconnect-options.js.map +1 -0
  106. package/dist/options/retry-options.d.ts +7 -0
  107. package/dist/options/retry-options.d.ts.map +1 -0
  108. package/dist/options/retry-options.js +2 -0
  109. package/dist/options/retry-options.js.map +1 -0
  110. package/dist/options/settings-of.d.ts +5 -0
  111. package/dist/options/settings-of.d.ts.map +1 -0
  112. package/dist/options/settings-of.js +38 -0
  113. package/dist/options/settings-of.js.map +1 -0
  114. package/dist/options/settings.d.ts +20 -0
  115. package/dist/options/settings.d.ts.map +1 -0
  116. package/dist/options/settings.js +2 -0
  117. package/dist/options/settings.js.map +1 -0
  118. package/dist/publication/publications.d.ts +28 -0
  119. package/dist/publication/publications.d.ts.map +1 -0
  120. package/dist/publication/publications.js +87 -0
  121. package/dist/publication/publications.js.map +1 -0
  122. package/dist/publication/send-confirmed.d.ts +5 -0
  123. package/dist/publication/send-confirmed.d.ts.map +1 -0
  124. package/dist/publication/send-confirmed.js +21 -0
  125. package/dist/publication/send-confirmed.js.map +1 -0
  126. package/dist/rabbit-mq-event-bus.d.ts +55 -0
  127. package/dist/rabbit-mq-event-bus.d.ts.map +1 -0
  128. package/dist/rabbit-mq-event-bus.js +168 -0
  129. package/dist/rabbit-mq-event-bus.js.map +1 -0
  130. package/dist/secrecy/conceal.d.ts +8 -0
  131. package/dist/secrecy/conceal.d.ts.map +1 -0
  132. package/dist/secrecy/conceal.js +12 -0
  133. package/dist/secrecy/conceal.js.map +1 -0
  134. package/dist/topology/binding-description.d.ts +6 -0
  135. package/dist/topology/binding-description.d.ts.map +1 -0
  136. package/dist/topology/binding-description.js +2 -0
  137. package/dist/topology/binding-description.js.map +1 -0
  138. package/dist/topology/consumer-binding.d.ts +6 -0
  139. package/dist/topology/consumer-binding.d.ts.map +1 -0
  140. package/dist/topology/consumer-binding.js +2 -0
  141. package/dist/topology/consumer-binding.js.map +1 -0
  142. package/dist/topology/declare-topology.d.ts +5 -0
  143. package/dist/topology/declare-topology.d.ts.map +1 -0
  144. package/dist/topology/declare-topology.js +13 -0
  145. package/dist/topology/declare-topology.js.map +1 -0
  146. package/dist/topology/exchange-description.d.ts +6 -0
  147. package/dist/topology/exchange-description.d.ts.map +1 -0
  148. package/dist/topology/exchange-description.js +2 -0
  149. package/dist/topology/exchange-description.js.map +1 -0
  150. package/dist/topology/queue-description.d.ts +8 -0
  151. package/dist/topology/queue-description.d.ts.map +1 -0
  152. package/dist/topology/queue-description.js +2 -0
  153. package/dist/topology/queue-description.js.map +1 -0
  154. package/dist/topology/queue-names-of.d.ts +4 -0
  155. package/dist/topology/queue-names-of.d.ts.map +1 -0
  156. package/dist/topology/queue-names-of.js +5 -0
  157. package/dist/topology/queue-names-of.js.map +1 -0
  158. package/dist/topology/queue-names.d.ts +6 -0
  159. package/dist/topology/queue-names.d.ts.map +1 -0
  160. package/dist/topology/queue-names.js +2 -0
  161. package/dist/topology/queue-names.js.map +1 -0
  162. package/dist/topology/rabbit-mq-topology.d.ts +10 -0
  163. package/dist/topology/rabbit-mq-topology.d.ts.map +1 -0
  164. package/dist/topology/rabbit-mq-topology.js +2 -0
  165. package/dist/topology/rabbit-mq-topology.js.map +1 -0
  166. package/dist/topology/topology-of.d.ts +5 -0
  167. package/dist/topology/topology-of.d.ts.map +1 -0
  168. package/dist/topology/topology-of.js +50 -0
  169. package/dist/topology/topology-of.js.map +1 -0
  170. package/dist/topology/topology-settings.d.ts +7 -0
  171. package/dist/topology/topology-settings.d.ts.map +1 -0
  172. package/dist/topology/topology-settings.js +2 -0
  173. package/dist/topology/topology-settings.js.map +1 -0
  174. package/package.json +37 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-not-confirmed-error.js","sourceRoot":"","sources":["../../src/errors/publish-not-confirmed-error.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAG5B,OAAO;IAFnB,IAAI,GAAG,uBAAuB,CAAC;IAExC,YAAqB,OAAe;QAClC,KAAK,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;uBADlC,OAAO;QAE1B,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /** Raised under `onUnroutable: 'fail'` when no queue is bound for the type of the event. */
2
+ export declare class UnroutableEventError extends Error {
3
+ readonly eventId: string;
4
+ readonly eventType: string;
5
+ readonly code = "UNROUTABLE_EVENT";
6
+ constructor(eventId: string, eventType: string);
7
+ }
8
+ //# sourceMappingURL=unroutable-event-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unroutable-event-error.d.ts","sourceRoot":"","sources":["../../src/errors/unroutable-event-error.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,qBAAa,oBAAqB,SAAQ,KAAK;IAI3C,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAJ5B,QAAQ,CAAC,IAAI,sBAAsB;IAEnC,YACW,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EAI3B;CACF"}
@@ -0,0 +1,13 @@
1
+ /** Raised under `onUnroutable: 'fail'` when no queue is bound for the type of the event. */
2
+ export class UnroutableEventError extends Error {
3
+ eventId;
4
+ eventType;
5
+ code = 'UNROUTABLE_EVENT';
6
+ constructor(eventId, eventType) {
7
+ super(`No queue is bound for ${eventType}: event ${eventId} was returned by the broker`);
8
+ this.eventId = eventId;
9
+ this.eventType = eventType;
10
+ this.name = 'UnroutableEventError';
11
+ }
12
+ }
13
+ //# sourceMappingURL=unroutable-event-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unroutable-event-error.js","sourceRoot":"","sources":["../../src/errors/unroutable-event-error.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAIlC,OAAO;IACP,SAAS;IAJX,IAAI,GAAG,kBAAkB,CAAC;IAEnC,YACW,OAAe,EACf,SAAiB;QAE1B,KAAK,CAAC,yBAAyB,SAAS,WAAW,OAAO,6BAA6B,CAAC,CAAC;uBAHhF,OAAO;yBACP,SAAS;QAGlB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ /** For a rejection or an event that needs no answer: closing what is already closed. */
2
+ export declare function ignore(): undefined;
3
+ //# sourceMappingURL=ignore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ignore.d.ts","sourceRoot":"","sources":["../src/ignore.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,MAAM,IAAI,SAAS,CAElC"}
package/dist/ignore.js ADDED
@@ -0,0 +1,5 @@
1
+ /** For a rejection or an event that needs no answer: closing what is already closed. */
2
+ export function ignore() {
3
+ return undefined;
4
+ }
5
+ //# sourceMappingURL=ignore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ignore.js","sourceRoot":"","sources":["../src/ignore.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,UAAU,MAAM;IACpB,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,23 @@
1
+ export { RabbitMqEventBus } from './rabbit-mq-event-bus.js';
2
+ export { DEFAULT_EXCHANGE } from './options/rabbit-mq-event-bus-options.js';
3
+ export type { RabbitMqEventBusOptions } from './options/rabbit-mq-event-bus-options.js';
4
+ export type { QueueType } from './options/queue-type.js';
5
+ export type { RabbitMqDelivery } from './options/rabbit-mq-delivery.js';
6
+ export type { RabbitMqFailure } from './options/rabbit-mq-failure.js';
7
+ export type { ReconnectOptions } from './options/reconnect-options.js';
8
+ export type { RetryOptions } from './options/retry-options.js';
9
+ export { queueNamesOf } from './topology/queue-names-of.js';
10
+ export type { BindingDescription } from './topology/binding-description.js';
11
+ export type { ConsumerBinding } from './topology/consumer-binding.js';
12
+ export type { ExchangeDescription } from './topology/exchange-description.js';
13
+ export type { QueueDescription } from './topology/queue-description.js';
14
+ export type { QueueNames } from './topology/queue-names.js';
15
+ export type { RabbitMqTopology } from './topology/rabbit-mq-topology.js';
16
+ export { ATTEMPT_HEADER, CORRELATION_HEADER, DEAD_REASON_HEADER, ERROR_CODE_HEADER, EVENT_VERSION_HEADER, TRACEPARENT_HEADER, } from './codec/headers.js';
17
+ export { POISON_MESSAGE } from './consumption/poison-message.js';
18
+ export { BrokerUnavailableError } from './errors/broker-unavailable-error.js';
19
+ export { ConsumerNameRequiredError } from './errors/consumer-name-required-error.js';
20
+ export { EventBusClosedError } from './errors/event-bus-closed-error.js';
21
+ export { PublishNotConfirmedError } from './errors/publish-not-confirmed-error.js';
22
+ export { UnroutableEventError } from './errors/unroutable-event-error.js';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,YAAY,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACxF,YAAY,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,YAAY,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { RabbitMqEventBus } from './rabbit-mq-event-bus.js';
2
+ export { DEFAULT_EXCHANGE } from './options/rabbit-mq-event-bus-options.js';
3
+ export { queueNamesOf } from './topology/queue-names-of.js';
4
+ export { ATTEMPT_HEADER, CORRELATION_HEADER, DEAD_REASON_HEADER, ERROR_CODE_HEADER, EVENT_VERSION_HEADER, TRACEPARENT_HEADER, } from './codec/headers.js';
5
+ export { POISON_MESSAGE } from './consumption/poison-message.js';
6
+ export { BrokerUnavailableError } from './errors/broker-unavailable-error.js';
7
+ export { ConsumerNameRequiredError } from './errors/consumer-name-required-error.js';
8
+ export { EventBusClosedError } from './errors/event-bus-closed-error.js';
9
+ export { PublishNotConfirmedError } from './errors/publish-not-confirmed-error.js';
10
+ export { UnroutableEventError } from './errors/unroutable-event-error.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAO5E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAO5D,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The name of the transport in what the bus says of itself and of each delivery. */
2
+ export declare const MESSAGING_SYSTEM = "rabbitmq";
3
+ //# sourceMappingURL=messaging-system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messaging-system.d.ts","sourceRoot":"","sources":["../src/messaging-system.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The name of the transport in what the bus says of itself and of each delivery. */
2
+ export const MESSAGING_SYSTEM = 'rabbitmq';
3
+ //# sourceMappingURL=messaging-system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messaging-system.js","sourceRoot":"","sources":["../src/messaging-system.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type QueueType = 'quorum' | 'classic';
2
+ //# sourceMappingURL=queue-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-type.d.ts","sourceRoot":"","sources":["../../src/options/queue-type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queue-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-type.js","sourceRoot":"","sources":["../../src/options/queue-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ /** One message settled by a consumer of this bus. Counted by outcome, it is the metric to watch. */
2
+ export interface RabbitMqDelivery {
3
+ readonly queue: string;
4
+ /** Which delivery of the message this was, starting at 1. */
5
+ readonly attempt: number;
6
+ /**
7
+ * `acknowledged`: every handler resolved. `retried`: sent to wait for another delivery.
8
+ * `dead`: attempts spent, moved to the dead queue. `poison`: not an envelope, moved there too.
9
+ */
10
+ readonly outcome: 'acknowledged' | 'retried' | 'dead' | 'poison';
11
+ }
12
+ //# sourceMappingURL=rabbit-mq-delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbit-mq-delivery.d.ts","sourceRoot":"","sources":["../../src/options/rabbit-mq-delivery.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;CAClE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rabbit-mq-delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbit-mq-delivery.js","sourceRoot":"","sources":["../../src/options/rabbit-mq-delivery.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import type { ChannelModel, Options } from 'amqplib';
2
+ import type { QueueType } from './queue-type.js';
3
+ import type { RabbitMqDelivery } from './rabbit-mq-delivery.js';
4
+ import type { RabbitMqFailure } from './rabbit-mq-failure.js';
5
+ import type { ReconnectOptions } from './reconnect-options.js';
6
+ import type { RetryOptions } from './retry-options.js';
7
+ export declare const DEFAULT_EXCHANGE = "integration-events";
8
+ export interface RabbitMqEventBusOptions {
9
+ /**
10
+ * An AMQP URL, amqplib connection options, or a factory opening a NEW connection each time
11
+ * it is called (TLS, rotating credentials). The bus owns what it opens and closes it.
12
+ */
13
+ readonly connection: string | Options.Connect | (() => Promise<ChannelModel>);
14
+ /** The durable topic exchange events are published to. Default `integration-events`. */
15
+ readonly exchange?: string;
16
+ /** The consuming context `subscribe` declares its queues for. See also `forConsumer`. */
17
+ readonly consumer?: string;
18
+ /** Unacknowledged messages a queue hands to this bus at once. Default 10. */
19
+ readonly prefetch?: number;
20
+ /** Default `quorum`. */
21
+ readonly queueType?: QueueType;
22
+ /** What `publish` does with an event no queue is bound for. Default `ignore`. */
23
+ readonly onUnroutable?: 'ignore' | 'fail';
24
+ readonly retry?: RetryOptions;
25
+ readonly reconnect?: ReconnectOptions;
26
+ /** Observability hook. It receives codes only, so it is safe to log as is. */
27
+ readonly onFailure?: (failure: RabbitMqFailure) => void;
28
+ /** Metrics hook, called once per message a consumer settles, before it is acknowledged. */
29
+ readonly onDelivery?: (delivery: RabbitMqDelivery) => void;
30
+ }
31
+ //# sourceMappingURL=rabbit-mq-event-bus-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbit-mq-event-bus-options.d.ts","sourceRoot":"","sources":["../../src/options/rabbit-mq-event-bus-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAErD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IAC9E,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,wBAAwB;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;IACxD,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC5D"}
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_EXCHANGE = 'integration-events';
2
+ //# sourceMappingURL=rabbit-mq-event-bus-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbit-mq-event-bus-options.js","sourceRoot":"","sources":["../../src/options/rabbit-mq-event-bus-options.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,17 @@
1
+ export type RabbitMqFailure = {
2
+ readonly kind: 'handler';
3
+ readonly queue: string;
4
+ readonly eventId: string;
5
+ readonly eventType: string;
6
+ readonly code: string;
7
+ readonly attempt: number;
8
+ readonly dead: boolean;
9
+ } | {
10
+ readonly kind: 'poison';
11
+ readonly queue: string;
12
+ readonly code: string;
13
+ } | {
14
+ readonly kind: 'connection';
15
+ readonly code: string;
16
+ };
17
+ //# sourceMappingURL=rabbit-mq-failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbit-mq-failure.d.ts","sourceRoot":"","sources":["../../src/options/rabbit-mq-failure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC1E;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rabbit-mq-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbit-mq-failure.js","sourceRoot":"","sources":["../../src/options/rabbit-mq-failure.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export interface ReconnectOptions {
2
+ /** Delay before the first reconnection attempt. Default 200. */
3
+ readonly initialMs?: number;
4
+ /** Multiplier applied at each further attempt. Default 2. */
5
+ readonly factor?: number;
6
+ /** Upper bound of the delay. Default 30000. */
7
+ readonly maxMs?: number;
8
+ }
9
+ //# sourceMappingURL=reconnect-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconnect-options.d.ts","sourceRoot":"","sources":["../../src/options/reconnect-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=reconnect-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconnect-options.js","sourceRoot":"","sources":["../../src/options/reconnect-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export interface RetryOptions {
2
+ /** Deliveries after which a message goes to the dead queue. Default 5. */
3
+ readonly maxAttempts?: number;
4
+ /** Time a failed message waits before it is delivered again. Default 5000. */
5
+ readonly delayMs?: number;
6
+ }
7
+ //# sourceMappingURL=retry-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-options.d.ts","sourceRoot":"","sources":["../../src/options/retry-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=retry-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-options.js","sourceRoot":"","sources":["../../src/options/retry-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { ChannelModel, Options } from 'amqplib';
2
+ import { type RabbitMqEventBusOptions } from './rabbit-mq-event-bus-options.js';
3
+ import type { Settings } from './settings.js';
4
+ export declare function settingsOf(options: RabbitMqEventBusOptions, connect: (target: string | Options.Connect) => Promise<ChannelModel>): Settings;
5
+ //# sourceMappingURL=settings-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-of.d.ts","sourceRoot":"","sources":["../../src/options/settings-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAGlG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,wBAAgB,UAAU,CACxB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,GACnE,QAAQ,CAeV"}
@@ -0,0 +1,38 @@
1
+ import { DEFAULT_EXCHANGE } from './rabbit-mq-event-bus-options.js';
2
+ export function settingsOf(options, connect) {
3
+ const { connection } = options;
4
+ return {
5
+ open: typeof connection === 'function' ? connection : () => connect(connection),
6
+ exchange: options.exchange ?? DEFAULT_EXCHANGE,
7
+ consumer: options.consumer,
8
+ prefetch: options.prefetch ?? 10,
9
+ queueType: options.queueType ?? 'quorum',
10
+ failOnUnroutable: options.onUnroutable === 'fail',
11
+ retry: retryOf(options.retry),
12
+ reconnect: reconnectOf(options.reconnect),
13
+ onFailure: guarded(options.onFailure),
14
+ onDelivery: guarded(options.onDelivery),
15
+ };
16
+ }
17
+ function retryOf(retry = {}) {
18
+ return { maxAttempts: retry.maxAttempts ?? 5, delayMs: retry.delayMs ?? 5_000 };
19
+ }
20
+ function reconnectOf(reconnect = {}) {
21
+ return {
22
+ initialMs: reconnect.initialMs ?? 200,
23
+ factor: reconnect.factor ?? 2,
24
+ maxMs: reconnect.maxMs ?? 30_000,
25
+ };
26
+ }
27
+ // A hook that throws must not leave a message unacknowledged or stop a reconnection.
28
+ function guarded(hook) {
29
+ return (value) => {
30
+ try {
31
+ hook?.(value);
32
+ }
33
+ catch {
34
+ return;
35
+ }
36
+ };
37
+ }
38
+ //# sourceMappingURL=settings-of.js.map
@@ -0,0 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KACjC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,SAAS,OAAO,CAAI,IAAsC;IACxD,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,IAAI,CAAC;YACH,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ChannelModel } from 'amqplib';
2
+ import type { QueueType } from './queue-type.js';
3
+ import type { RabbitMqDelivery } from './rabbit-mq-delivery.js';
4
+ import type { RabbitMqFailure } from './rabbit-mq-failure.js';
5
+ import type { ReconnectOptions } from './reconnect-options.js';
6
+ import type { RetryOptions } from './retry-options.js';
7
+ /** The options of a bus with every default applied. */
8
+ export interface Settings {
9
+ readonly open: () => Promise<ChannelModel>;
10
+ readonly exchange: string;
11
+ readonly consumer: string | undefined;
12
+ readonly prefetch: number;
13
+ readonly queueType: QueueType;
14
+ readonly failOnUnroutable: boolean;
15
+ readonly retry: Required<RetryOptions>;
16
+ readonly reconnect: Required<ReconnectOptions>;
17
+ readonly onFailure: (failure: RabbitMqFailure) => void;
18
+ readonly onDelivery: (delivery: RabbitMqDelivery) => void;
19
+ }
20
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/options/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,uDAAuD;AACvD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC3D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/options/settings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import type { ChannelModel } from 'amqplib';
2
+ import type { IntegrationEvent } from '@ddd-ts-kit/kernel';
3
+ export interface PublicationSettings {
4
+ readonly exchange: string;
5
+ readonly failOnUnroutable: boolean;
6
+ /** Called when the channel dies while the connection lives. */
7
+ readonly channelLost: () => void;
8
+ }
9
+ /**
10
+ * Publishing with publisher confirms: a publication succeeds only once the broker has taken
11
+ * responsibility for the message, which is what lets an outbox relay mark it published.
12
+ */
13
+ export declare class Publications {
14
+ private readonly settings;
15
+ private readonly returned;
16
+ private readonly unconfirmed;
17
+ private channel;
18
+ constructor(settings: PublicationSettings);
19
+ attach(model: ChannelModel): Promise<void>;
20
+ /** The channel is gone: what it had not confirmed never will be. */
21
+ detach(): void;
22
+ /** Resolves when every event is confirmed; rejects with the first failure otherwise. */
23
+ publish(events: readonly IntegrationEvent[]): Promise<void>;
24
+ /** Lets the confirmations in flight arrive, then closes the channel. */
25
+ close(): Promise<void>;
26
+ private send;
27
+ }
28
+ //# sourceMappingURL=publications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publications.d.ts","sourceRoot":"","sources":["../../src/publication/publications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAO3D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,YAAY;IAOX,OAAO,CAAC,QAAQ,CAAC,QAAQ;IANrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAE9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;IAEnE,OAAO,CAAC,OAAO,CAA6B;IAE5C,YAA6B,QAAQ,EAAE,mBAAmB,EAAI;IAExD,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB/C;IAED,oEAAoE;IACpE,MAAM,IAAI,IAAI,CAOb;IAED,wFAAwF;IAClF,OAAO,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAchE;IAED,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3B;IAED,OAAO,CAAC,IAAI;CA2Bb"}
@@ -0,0 +1,87 @@
1
+ import { encode } from '../codec/encode.js';
2
+ import { BrokerUnavailableError } from '../errors/broker-unavailable-error.js';
3
+ import { PublishNotConfirmedError } from '../errors/publish-not-confirmed-error.js';
4
+ import { UnroutableEventError } from '../errors/unroutable-event-error.js';
5
+ import { ignore } from '../ignore.js';
6
+ /**
7
+ * Publishing with publisher confirms: a publication succeeds only once the broker has taken
8
+ * responsibility for the message, which is what lets an outbox relay mark it published.
9
+ */
10
+ export class Publications {
11
+ settings;
12
+ returned = new Set();
13
+ unconfirmed = new Set();
14
+ channel;
15
+ constructor(settings) {
16
+ this.settings = settings;
17
+ }
18
+ async attach(model) {
19
+ const channel = await model.createConfirmChannel();
20
+ channel.on('error', ignore);
21
+ channel.on('close', () => {
22
+ if (this.channel === channel) {
23
+ this.settings.channelLost();
24
+ }
25
+ });
26
+ channel.on('return', (message) => {
27
+ this.returned.add(String(message.properties.messageId));
28
+ });
29
+ await channel.assertExchange(this.settings.exchange, 'topic', { durable: true });
30
+ this.channel = channel;
31
+ }
32
+ /** The channel is gone: what it had not confirmed never will be. */
33
+ detach() {
34
+ this.channel = undefined;
35
+ this.returned.clear();
36
+ for (const confirmed of [...this.unconfirmed]) {
37
+ confirmed(new Error('channel lost'));
38
+ }
39
+ }
40
+ /** Resolves when every event is confirmed; rejects with the first failure otherwise. */
41
+ async publish(events) {
42
+ const channel = this.channel;
43
+ if (channel === undefined) {
44
+ throw new BrokerUnavailableError('RECONNECTING');
45
+ }
46
+ const outcomes = await Promise.allSettled(events.map((event) => this.send(channel, event)));
47
+ for (const outcome of outcomes) {
48
+ if (outcome.status === 'rejected') {
49
+ throw outcome.reason;
50
+ }
51
+ }
52
+ }
53
+ /** Lets the confirmations in flight arrive, then closes the channel. */
54
+ async close() {
55
+ const channel = this.channel;
56
+ this.channel = undefined;
57
+ await channel?.waitForConfirms().catch(ignore);
58
+ await channel?.close().catch(ignore);
59
+ }
60
+ send(channel, event) {
61
+ const { content, properties } = encode(event);
62
+ const options = { ...properties, mandatory: this.settings.failOnUnroutable };
63
+ return new Promise((resolve, reject) => {
64
+ const confirmed = (error) => {
65
+ this.unconfirmed.delete(confirmed);
66
+ // The broker sends the return of an unroutable message before its confirmation.
67
+ if (error !== null && error !== undefined) {
68
+ reject(new PublishNotConfirmedError(event.id));
69
+ }
70
+ else if (this.returned.delete(event.id)) {
71
+ reject(new UnroutableEventError(event.id, event.type));
72
+ }
73
+ else {
74
+ resolve();
75
+ }
76
+ };
77
+ this.unconfirmed.add(confirmed);
78
+ try {
79
+ channel.publish(this.settings.exchange, event.type, content, options, confirmed);
80
+ }
81
+ catch {
82
+ confirmed(new Error('channel closed'));
83
+ }
84
+ });
85
+ }
86
+ }
87
+ //# sourceMappingURL=publications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publications.js","sourceRoot":"","sources":["../../src/publication/publications.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAStC;;;GAGG;AACH,MAAM,OAAO,YAAY;IAOM,QAAQ;IANpB,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7B,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE3D,OAAO,CAA6B;IAE5C,YAA6B,QAA6B;wBAA7B,QAAQ;IAAwB,CAAC;IAE9D,KAAK,CAAC,MAAM,CAAC,KAAmB;QAC9B,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAEnD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAE5B,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACvB,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC,QAA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AC,CAAC;YAEhC,IAAI,CAAC;gBACH,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YACnF,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACzC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import type { ConfirmChannel } from 'amqplib';
2
+ import type { Publication } from '../codec/publication.js';
3
+ /** Sends a message to a queue through the default exchange and waits for its confirmation. */
4
+ export declare function sendConfirmed(channel: ConfirmChannel, queue: string, publication: Publication): Promise<void>;
5
+ //# sourceMappingURL=send-confirmed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-confirmed.d.ts","sourceRoot":"","sources":["../../src/publication/send-confirmed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB7G"}
@@ -0,0 +1,21 @@
1
+ import { PublishNotConfirmedError } from '../errors/publish-not-confirmed-error.js';
2
+ /** Sends a message to a queue through the default exchange and waits for its confirmation. */
3
+ export function sendConfirmed(channel, queue, publication) {
4
+ return new Promise((resolve, reject) => {
5
+ const confirmed = (error) => {
6
+ if (error === null || error === undefined) {
7
+ resolve();
8
+ }
9
+ else {
10
+ reject(new PublishNotConfirmedError(String(publication.properties.messageId)));
11
+ }
12
+ };
13
+ try {
14
+ channel.sendToQueue(queue, publication.content, publication.properties, confirmed);
15
+ }
16
+ catch {
17
+ confirmed(new Error('channel closed'));
18
+ }
19
+ });
20
+ }
21
+ //# sourceMappingURL=send-confirmed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-confirmed.js","sourceRoot":"","sources":["../../src/publication/send-confirmed.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AAEpF,8FAA8F;AAC9F,MAAM,UAAU,aAAa,CAAC,OAAuB,EAAE,KAAa,EAAE,WAAwB;IAC5F,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAQ,EAAE;YACzC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC1C,OAAO,EAAE,CAAC;YACZ,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,wBAAwB,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC;QACH,CAAC,CAAC;QAEF,IAAI,CAAC;YACH,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACrF,CAAC;QAAC,MAAM,CAAC;YACP,SAAS,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { inspect } from 'node:util';
2
+ import type { EventBus, IntegrationEvent, IntegrationEventCallback, IntegrationEventSubscriber, Subscription } from '@ddd-ts-kit/kernel';
3
+ import type { RabbitMqEventBusOptions } from './options/rabbit-mq-event-bus-options.js';
4
+ import type { ConsumerBinding } from './topology/consumer-binding.js';
5
+ import type { RabbitMqTopology } from './topology/rabbit-mq-topology.js';
6
+ /**
7
+ * The provider for RabbitMQ and other AMQP 0-9-1 brokers.
8
+ *
9
+ * Publishing: a durable topic exchange, routing key = event type, persistent messages, and
10
+ * `publish` resolves only when the broker confirmed every message, so it is a safe target for
11
+ * the outbox relay. Consuming: a durable queue per consumer and event type, acknowledged
12
+ * after the handlers resolved, a bounded number of delayed retries, then a dead queue.
13
+ * Delivery is at least once and unordered: consumers deduplicate.
14
+ */
15
+ export declare class RabbitMqEventBus implements EventBus {
16
+ /** Read by what observes the bus from outside: the name of the transport. */
17
+ readonly messagingSystem = "rabbitmq";
18
+ private readonly settings;
19
+ private readonly link;
20
+ private readonly publications;
21
+ private readonly consumption;
22
+ private closed;
23
+ constructor(options: RabbitMqEventBusOptions);
24
+ /** Messages delivered to this bus whose handlers have not finished yet. */
25
+ get deliveriesInFlight(): number;
26
+ /**
27
+ * Resolves when the broker confirmed every event, rejects otherwise: nothing is buffered
28
+ * for later, so the caller (the outbox relay) knows what to retry.
29
+ */
30
+ publish(events: readonly IntegrationEvent[]): Promise<void>;
31
+ /** Subscribes the consumer named by the `consumer` option. */
32
+ subscribe(type: string, handler: IntegrationEventCallback): Subscription;
33
+ /** A subscriber for one consuming context, on the connection of this bus. */
34
+ forConsumer(consumer: string): IntegrationEventSubscriber;
35
+ /**
36
+ * Connects if needed and declares the exchange, the queues and the bindings of the
37
+ * subscriptions made so far. Idempotent. Resolves once those subscriptions are consuming.
38
+ */
39
+ assertTopology(): Promise<void>;
40
+ describeTopology(): RabbitMqTopology;
41
+ /**
42
+ * Moves up to `limit` messages from the dead queue of a consumer back to its work queue,
43
+ * with a fresh attempt budget. Returns how many were moved.
44
+ */
45
+ replayDead(binding: ConsumerBinding, limit?: number): Promise<number>;
46
+ /** Stops consuming, waits for the handlers and the confirmations in flight, disconnects. */
47
+ close(): Promise<void>;
48
+ /** What a serialisation shows of the bus: its name, never its connection. */
49
+ toJSON(): string;
50
+ /** What `console.log` and `util.inspect` show of the bus: the same. */
51
+ [inspect.custom](): string;
52
+ /** Adds a handler to the queue of one consumer for one type, and connects if needed. */
53
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