@ddd-ts-kit/kafka 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 (214) hide show
  1. package/README.md +397 -2
  2. package/dist/codec/decode.d.ts +4 -0
  3. package/dist/codec/decode.d.ts.map +1 -0
  4. package/dist/codec/decode.js +39 -0
  5. package/dist/codec/decode.js.map +1 -0
  6. package/dist/codec/encode.d.ts +9 -0
  7. package/dist/codec/encode.d.ts.map +1 -0
  8. package/dist/codec/encode.js +22 -0
  9. package/dist/codec/encode.js.map +1 -0
  10. package/dist/codec/headers.d.ts +13 -0
  11. package/dist/codec/headers.d.ts.map +1 -0
  12. package/dist/codec/headers.js +13 -0
  13. package/dist/codec/headers.js.map +1 -0
  14. package/dist/codec/incoming-record.d.ts +8 -0
  15. package/dist/codec/incoming-record.d.ts.map +1 -0
  16. package/dist/codec/incoming-record.js +2 -0
  17. package/dist/codec/incoming-record.js.map +1 -0
  18. package/dist/codec/outgoing-record.d.ts +7 -0
  19. package/dist/codec/outgoing-record.d.ts.map +1 -0
  20. package/dist/codec/outgoing-record.js +2 -0
  21. package/dist/codec/outgoing-record.js.map +1 -0
  22. package/dist/codec/republication.d.ts +5 -0
  23. package/dist/codec/republication.d.ts.map +1 -0
  24. package/dist/codec/republication.js +8 -0
  25. package/dist/codec/republication.js.map +1 -0
  26. package/dist/codec/routing.d.ts +7 -0
  27. package/dist/codec/routing.d.ts.map +1 -0
  28. package/dist/codec/routing.js +2 -0
  29. package/dist/codec/routing.js.map +1 -0
  30. package/dist/codec/source-of.d.ts +4 -0
  31. package/dist/codec/source-of.d.ts.map +1 -0
  32. package/dist/codec/source-of.js +5 -0
  33. package/dist/codec/source-of.js.map +1 -0
  34. package/dist/codec/text-header.d.ts +4 -0
  35. package/dist/codec/text-header.d.ts.map +1 -0
  36. package/dist/codec/text-header.js +7 -0
  37. package/dist/codec/text-header.js.map +1 -0
  38. package/dist/connection/broker-link.d.ts +44 -0
  39. package/dist/connection/broker-link.d.ts.map +1 -0
  40. package/dist/connection/broker-link.js +145 -0
  41. package/dist/connection/broker-link.js.map +1 -0
  42. package/dist/connection/cluster-of.d.ts +8 -0
  43. package/dist/connection/cluster-of.d.ts.map +1 -0
  44. package/dist/connection/cluster-of.js +16 -0
  45. package/dist/connection/cluster-of.js.map +1 -0
  46. package/dist/connection/rebalance.d.ts +7 -0
  47. package/dist/connection/rebalance.d.ts.map +1 -0
  48. package/dist/connection/rebalance.js +2 -0
  49. package/dist/connection/rebalance.js.map +1 -0
  50. package/dist/consumption/attempts.d.ts +16 -0
  51. package/dist/consumption/attempts.d.ts.map +1 -0
  52. package/dist/consumption/attempts.js +23 -0
  53. package/dist/consumption/attempts.js.map +1 -0
  54. package/dist/consumption/backoff.d.ts +12 -0
  55. package/dist/consumption/backoff.d.ts.map +1 -0
  56. package/dist/consumption/backoff.js +20 -0
  57. package/dist/consumption/backoff.js.map +1 -0
  58. package/dist/consumption/consumption.d.ts +18 -0
  59. package/dist/consumption/consumption.d.ts.map +1 -0
  60. package/dist/consumption/consumption.js +33 -0
  61. package/dist/consumption/consumption.js.map +1 -0
  62. package/dist/consumption/delivery-postponed.d.ts +9 -0
  63. package/dist/consumption/delivery-postponed.d.ts.map +1 -0
  64. package/dist/consumption/delivery-postponed.js +12 -0
  65. package/dist/consumption/delivery-postponed.js.map +1 -0
  66. package/dist/consumption/failure-of.d.ts +7 -0
  67. package/dist/consumption/failure-of.d.ts.map +1 -0
  68. package/dist/consumption/failure-of.js +18 -0
  69. package/dist/consumption/failure-of.js.map +1 -0
  70. package/dist/consumption/group-consumer.d.ts +60 -0
  71. package/dist/consumption/group-consumer.d.ts.map +1 -0
  72. package/dist/consumption/group-consumer.js +145 -0
  73. package/dist/consumption/group-consumer.js.map +1 -0
  74. package/dist/consumption/poison-message.d.ts +3 -0
  75. package/dist/consumption/poison-message.d.ts.map +1 -0
  76. package/dist/consumption/poison-message.js +3 -0
  77. package/dist/consumption/poison-message.js.map +1 -0
  78. package/dist/consumption/postpone.d.ts +9 -0
  79. package/dist/consumption/postpone.d.ts.map +1 -0
  80. package/dist/consumption/postpone.js +30 -0
  81. package/dist/consumption/postpone.js.map +1 -0
  82. package/dist/consumption/record-handling.d.ts +58 -0
  83. package/dist/consumption/record-handling.d.ts.map +1 -0
  84. package/dist/consumption/record-handling.js +183 -0
  85. package/dist/consumption/record-handling.js.map +1 -0
  86. package/dist/consumption/timers.d.ts +7 -0
  87. package/dist/consumption/timers.d.ts.map +1 -0
  88. package/dist/consumption/timers.js +17 -0
  89. package/dist/consumption/timers.js.map +1 -0
  90. package/dist/errors/broker-unavailable-error.d.ts +8 -0
  91. package/dist/errors/broker-unavailable-error.d.ts.map +1 -0
  92. package/dist/errors/broker-unavailable-error.js +12 -0
  93. package/dist/errors/broker-unavailable-error.js.map +1 -0
  94. package/dist/errors/consumer-name-required-error.d.ts +5 -0
  95. package/dist/errors/consumer-name-required-error.d.ts.map +1 -0
  96. package/dist/errors/consumer-name-required-error.js +8 -0
  97. package/dist/errors/consumer-name-required-error.js.map +1 -0
  98. package/dist/errors/event-bus-closed-error.d.ts +5 -0
  99. package/dist/errors/event-bus-closed-error.d.ts.map +1 -0
  100. package/dist/errors/event-bus-closed-error.js +8 -0
  101. package/dist/errors/event-bus-closed-error.js.map +1 -0
  102. package/dist/errors/failure-code.d.ts +6 -0
  103. package/dist/errors/failure-code.d.ts.map +1 -0
  104. package/dist/errors/failure-code.js +15 -0
  105. package/dist/errors/failure-code.js.map +1 -0
  106. package/dist/errors/publish-not-acknowledged-error.d.ts +14 -0
  107. package/dist/errors/publish-not-acknowledged-error.d.ts.map +1 -0
  108. package/dist/errors/publish-not-acknowledged-error.js +18 -0
  109. package/dist/errors/publish-not-acknowledged-error.js.map +1 -0
  110. package/dist/errors/reason-of.d.ts +3 -0
  111. package/dist/errors/reason-of.d.ts.map +1 -0
  112. package/dist/errors/reason-of.js +11 -0
  113. package/dist/errors/reason-of.js.map +1 -0
  114. package/dist/errors/within.d.ts +3 -0
  115. package/dist/errors/within.d.ts.map +1 -0
  116. package/dist/errors/within.js +17 -0
  117. package/dist/errors/within.js.map +1 -0
  118. package/dist/ignore.d.ts +3 -0
  119. package/dist/ignore.d.ts.map +1 -0
  120. package/dist/ignore.js +5 -0
  121. package/dist/ignore.js.map +1 -0
  122. package/dist/index.d.ts +20 -0
  123. package/dist/index.d.ts.map +1 -0
  124. package/dist/index.js +10 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/kafka-event-bus.d.ts +58 -0
  127. package/dist/kafka-event-bus.d.ts.map +1 -0
  128. package/dist/kafka-event-bus.js +147 -0
  129. package/dist/kafka-event-bus.js.map +1 -0
  130. package/dist/messaging-system.d.ts +3 -0
  131. package/dist/messaging-system.d.ts.map +1 -0
  132. package/dist/messaging-system.js +3 -0
  133. package/dist/messaging-system.js.map +1 -0
  134. package/dist/options/kafka-delivery.d.ts +15 -0
  135. package/dist/options/kafka-delivery.d.ts.map +1 -0
  136. package/dist/options/kafka-delivery.js +2 -0
  137. package/dist/options/kafka-delivery.js.map +1 -0
  138. package/dist/options/kafka-event-bus-options.d.ts +42 -0
  139. package/dist/options/kafka-event-bus-options.d.ts.map +1 -0
  140. package/dist/options/kafka-event-bus-options.js +2 -0
  141. package/dist/options/kafka-event-bus-options.js.map +1 -0
  142. package/dist/options/kafka-failure.d.ts +19 -0
  143. package/dist/options/kafka-failure.d.ts.map +1 -0
  144. package/dist/options/kafka-failure.js +2 -0
  145. package/dist/options/kafka-failure.js.map +1 -0
  146. package/dist/options/reconnect-options.d.ts +9 -0
  147. package/dist/options/reconnect-options.d.ts.map +1 -0
  148. package/dist/options/reconnect-options.js +2 -0
  149. package/dist/options/reconnect-options.js.map +1 -0
  150. package/dist/options/retry-options.d.ts +7 -0
  151. package/dist/options/retry-options.d.ts.map +1 -0
  152. package/dist/options/retry-options.js +2 -0
  153. package/dist/options/retry-options.js.map +1 -0
  154. package/dist/options/settings-of.d.ts +4 -0
  155. package/dist/options/settings-of.d.ts.map +1 -0
  156. package/dist/options/settings-of.js +47 -0
  157. package/dist/options/settings-of.js.map +1 -0
  158. package/dist/options/settings.d.ts +27 -0
  159. package/dist/options/settings.d.ts.map +1 -0
  160. package/dist/options/settings.js +2 -0
  161. package/dist/options/settings.js.map +1 -0
  162. package/dist/options/topic-options.d.ts +9 -0
  163. package/dist/options/topic-options.d.ts.map +1 -0
  164. package/dist/options/topic-options.js +2 -0
  165. package/dist/options/topic-options.js.map +1 -0
  166. package/dist/publication/publications.d.ts +30 -0
  167. package/dist/publication/publications.d.ts.map +1 -0
  168. package/dist/publication/publications.js +83 -0
  169. package/dist/publication/publications.js.map +1 -0
  170. package/dist/replay/dead-letter-replay.d.ts +31 -0
  171. package/dist/replay/dead-letter-replay.d.ts.map +1 -0
  172. package/dist/replay/dead-letter-replay.js +97 -0
  173. package/dist/replay/dead-letter-replay.js.map +1 -0
  174. package/dist/secrecy/conceal.d.ts +8 -0
  175. package/dist/secrecy/conceal.d.ts.map +1 -0
  176. package/dist/secrecy/conceal.js +12 -0
  177. package/dist/secrecy/conceal.js.map +1 -0
  178. package/dist/topology/consumer-binding.d.ts +6 -0
  179. package/dist/topology/consumer-binding.d.ts.map +1 -0
  180. package/dist/topology/consumer-binding.js +2 -0
  181. package/dist/topology/consumer-binding.js.map +1 -0
  182. package/dist/topology/dead-topic-of.d.ts +3 -0
  183. package/dist/topology/dead-topic-of.d.ts.map +1 -0
  184. package/dist/topology/dead-topic-of.js +5 -0
  185. package/dist/topology/dead-topic-of.js.map +1 -0
  186. package/dist/topology/describe-topic.d.ts +5 -0
  187. package/dist/topology/describe-topic.d.ts.map +1 -0
  188. package/dist/topology/describe-topic.js +5 -0
  189. package/dist/topology/describe-topic.js.map +1 -0
  190. package/dist/topology/group-description.d.ts +5 -0
  191. package/dist/topology/group-description.d.ts.map +1 -0
  192. package/dist/topology/group-description.js +2 -0
  193. package/dist/topology/group-description.js.map +1 -0
  194. package/dist/topology/kafka-topology.d.ts +8 -0
  195. package/dist/topology/kafka-topology.d.ts.map +1 -0
  196. package/dist/topology/kafka-topology.js +2 -0
  197. package/dist/topology/kafka-topology.js.map +1 -0
  198. package/dist/topology/replay-group-of.d.ts +3 -0
  199. package/dist/topology/replay-group-of.d.ts.map +1 -0
  200. package/dist/topology/replay-group-of.js +5 -0
  201. package/dist/topology/replay-group-of.js.map +1 -0
  202. package/dist/topology/topic-description.d.ts +10 -0
  203. package/dist/topology/topic-description.d.ts.map +1 -0
  204. package/dist/topology/topic-description.js +2 -0
  205. package/dist/topology/topic-description.js.map +1 -0
  206. package/dist/topology/topology-of.d.ts +5 -0
  207. package/dist/topology/topology-of.d.ts.map +1 -0
  208. package/dist/topology/topology-of.js +25 -0
  209. package/dist/topology/topology-of.js.map +1 -0
  210. package/dist/topology/topology-settings.d.ts +7 -0
  211. package/dist/topology/topology-settings.d.ts.map +1 -0
  212. package/dist/topology/topology-settings.js +2 -0
  213. package/dist/topology/topology-settings.js.map +1 -0
  214. package/package.json +37 -4
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The in-sync replicas did not acknowledge the records in time: they may or may not be in
3
+ * the log. Publish again; consumers deduplicate on the event id.
4
+ */
5
+ export declare class PublishNotAcknowledgedError extends Error {
6
+ /** The events of the send that failed; some of them may have been written. */
7
+ readonly eventIds: readonly string[];
8
+ readonly reason: string;
9
+ readonly code = "PUBLISH_NOT_ACKNOWLEDGED";
10
+ constructor(
11
+ /** The events of the send that failed; some of them may have been written. */
12
+ eventIds: readonly string[], reason: string);
13
+ }
14
+ //# sourceMappingURL=publish-not-acknowledged-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-not-acknowledged-error.d.ts","sourceRoot":"","sources":["../../src/errors/publish-not-acknowledged-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAIlD,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM;IALzB,QAAQ,CAAC,IAAI,8BAA8B;IAE3C;IACE,8EAA8E;IACrE,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,EAAE,MAAM,EAIxB;CACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The in-sync replicas did not acknowledge the records in time: they may or may not be in
3
+ * the log. Publish again; consumers deduplicate on the event id.
4
+ */
5
+ export class PublishNotAcknowledgedError extends Error {
6
+ eventIds;
7
+ reason;
8
+ code = 'PUBLISH_NOT_ACKNOWLEDGED';
9
+ constructor(
10
+ /** The events of the send that failed; some of them may have been written. */
11
+ eventIds, reason) {
12
+ super(`The broker did not acknowledge ${String(eventIds.length)} event(s) (${reason})`);
13
+ this.eventIds = eventIds;
14
+ this.reason = reason;
15
+ this.name = 'PublishNotAcknowledgedError';
16
+ }
17
+ }
18
+ //# sourceMappingURL=publish-not-acknowledged-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-not-acknowledged-error.js","sourceRoot":"","sources":["../../src/errors/publish-not-acknowledged-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAKzC,QAAQ;IACR,MAAM;IALR,IAAI,GAAG,0BAA0B,CAAC;IAE3C;IACE,8EAA8E;IACrE,QAA2B,EAC3B,MAAc;QAEvB,KAAK,CAAC,kCAAkC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,MAAM,GAAG,CAAC,CAAC;wBAH/E,QAAQ;sBACR,MAAM;QAGf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ /** The code of a failure of the cluster, whether the bus already named it or the client raised it. */
2
+ export declare function reasonOf(error: unknown): string;
3
+ //# sourceMappingURL=reason-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reason-of.d.ts","sourceRoot":"","sources":["../../src/errors/reason-of.ts"],"names":[],"mappings":"AAIA,sGAAsG;AACtG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAM/C"}
@@ -0,0 +1,11 @@
1
+ import { BrokerUnavailableError } from './broker-unavailable-error.js';
2
+ import { failureCode } from './failure-code.js';
3
+ import { PublishNotAcknowledgedError } from './publish-not-acknowledged-error.js';
4
+ /** The code of a failure of the cluster, whether the bus already named it or the client raised it. */
5
+ export function reasonOf(error) {
6
+ if (error instanceof BrokerUnavailableError || error instanceof PublishNotAcknowledgedError) {
7
+ return error.reason;
8
+ }
9
+ return failureCode(error);
10
+ }
11
+ //# sourceMappingURL=reason-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reason-of.js","sourceRoot":"","sources":["../../src/errors/reason-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,sGAAsG;AACtG,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,IAAI,KAAK,YAAY,sBAAsB,IAAI,KAAK,YAAY,2BAA2B,EAAE,CAAC;QAC5F,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;IAED,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Rejects with `BROKER_UNAVAILABLE` when `work` has not settled after `timeoutMs`. */
2
+ export declare function within<T>(work: Promise<T>, timeoutMs: number, reason: string): Promise<T>;
3
+ //# sourceMappingURL=within.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"within.d.ts","sourceRoot":"","sources":["../../src/errors/within.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,wBAAsB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAc/F"}
@@ -0,0 +1,17 @@
1
+ import { BrokerUnavailableError } from './broker-unavailable-error.js';
2
+ /** Rejects with `BROKER_UNAVAILABLE` when `work` has not settled after `timeoutMs`. */
3
+ export async function within(work, timeoutMs, reason) {
4
+ let timer;
5
+ const expired = new Promise((_resolve, reject) => {
6
+ timer = setTimeout(() => {
7
+ reject(new BrokerUnavailableError(reason));
8
+ }, timeoutMs);
9
+ });
10
+ try {
11
+ return await Promise.race([work, expired]);
12
+ }
13
+ finally {
14
+ clearTimeout(timer);
15
+ }
16
+ }
17
+ //# sourceMappingURL=within.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"within.js","sourceRoot":"","sources":["../../src/errors/within.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,MAAM,CAAI,IAAgB,EAAE,SAAiB,EAAE,MAAc;IACjF,IAAI,KAAgD,CAAC;IAErD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;QACtD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,MAAM,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
@@ -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,20 @@
1
+ export { KafkaEventBus } from './kafka-event-bus.js';
2
+ export type { KafkaEventBusOptions } from './options/kafka-event-bus-options.js';
3
+ export type { KafkaDelivery } from './options/kafka-delivery.js';
4
+ export type { KafkaFailure } from './options/kafka-failure.js';
5
+ export type { ReconnectOptions } from './options/reconnect-options.js';
6
+ export type { RetryOptions } from './options/retry-options.js';
7
+ export type { TopicOptions } from './options/topic-options.js';
8
+ export { deadTopicOf } from './topology/dead-topic-of.js';
9
+ export { replayGroupOf } from './topology/replay-group-of.js';
10
+ export type { ConsumerBinding } from './topology/consumer-binding.js';
11
+ export type { GroupDescription } from './topology/group-description.js';
12
+ export type { KafkaTopology } from './topology/kafka-topology.js';
13
+ export type { TopicDescription } from './topology/topic-description.js';
14
+ export { ATTEMPT_HEADER, CORRELATION_HEADER, DEAD_REASON_HEADER, ERROR_CODE_HEADER, EVENT_ID_HEADER, EVENT_TYPE_HEADER, EVENT_VERSION_HEADER, REPLAY_FOR_HEADER, SOURCE_HEADER, TRACEPARENT_HEADER, } from './codec/headers.js';
15
+ export { POISON_MESSAGE } from './consumption/poison-message.js';
16
+ export { BrokerUnavailableError } from './errors/broker-unavailable-error.js';
17
+ export { ConsumerNameRequiredError } from './errors/consumer-name-required-error.js';
18
+ export { EventBusClosedError } from './errors/event-bus-closed-error.js';
19
+ export { PublishNotAcknowledgedError } from './errors/publish-not-acknowledged-error.js';
20
+ //# 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,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACjF,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,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,2BAA2B,EAAE,MAAM,4CAA4C,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { KafkaEventBus } from './kafka-event-bus.js';
2
+ export { deadTopicOf } from './topology/dead-topic-of.js';
3
+ export { replayGroupOf } from './topology/replay-group-of.js';
4
+ export { ATTEMPT_HEADER, CORRELATION_HEADER, DEAD_REASON_HEADER, ERROR_CODE_HEADER, EVENT_ID_HEADER, EVENT_TYPE_HEADER, EVENT_VERSION_HEADER, REPLAY_FOR_HEADER, SOURCE_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 { PublishNotAcknowledgedError } from './errors/publish-not-acknowledged-error.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAOrD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAK9D,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,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,2BAA2B,EAAE,MAAM,4CAA4C,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { inspect } from 'node:util';
2
+ import type { EventBus, IntegrationEvent, IntegrationEventCallback, IntegrationEventSubscriber, Subscription } from '@ddd-ts-kit/kernel';
3
+ import type { KafkaEventBusOptions } from './options/kafka-event-bus-options.js';
4
+ import type { ConsumerBinding } from './topology/consumer-binding.js';
5
+ import type { KafkaTopology } from './topology/kafka-topology.js';
6
+ /**
7
+ * The provider for Apache Kafka and other logs speaking its protocol.
8
+ *
9
+ * Publishing: one topic per event type unless `topicOf` says otherwise, record key =
10
+ * `keyOf(event)`, an idempotent producer with `acks=all`, and `publish` resolves only when
11
+ * every record is acknowledged, so it is a safe target for the outbox relay. Consuming: one
12
+ * consumer group per consuming context, the offset committed after the handlers resolved, a
13
+ * bounded number of delayed retries in place, then a dead-letter topic. Delivery is at least
14
+ * once, in order for the records of one key: consumers deduplicate.
15
+ */
16
+ export declare class KafkaEventBus implements EventBus {
17
+ /** Read by what observes the bus from outside: the name of the transport. */
18
+ readonly messagingSystem = "kafka";
19
+ private readonly settings;
20
+ private readonly link;
21
+ private readonly publications;
22
+ private readonly consumption;
23
+ private closed;
24
+ constructor(options: KafkaEventBusOptions);
25
+ /** Records delivered to this bus whose handlers have not finished yet. */
26
+ get deliveriesInFlight(): number;
27
+ /** Partitions the consumers of this bus own now: 0 means it consumes nothing. */
28
+ get partitionsAssigned(): number;
29
+ /**
30
+ * Resolves when every in-sync replica acknowledged every event, rejects otherwise: nothing
31
+ * is buffered for later, so the caller (the outbox relay) knows what to retry.
32
+ */
33
+ publish(events: readonly IntegrationEvent[]): Promise<void>;
34
+ /** Subscribes the consumer named by the `consumer` option. */
35
+ subscribe(type: string, handler: IntegrationEventCallback): Subscription;
36
+ /** A subscriber for one consuming context, on the clients of this bus. */
37
+ forConsumer(consumer: string): IntegrationEventSubscriber;
38
+ /**
39
+ * Creates the topics of the published types and of the subscriptions made so far, then
40
+ * resolves once those subscriptions have their partitions. Idempotent.
41
+ */
42
+ assertTopology(): Promise<void>;
43
+ describeTopology(): KafkaTopology;
44
+ /**
45
+ * Copies up to `limit` records from the dead-letter topic of a consumer back to the topic
46
+ * they came from, for that consumer only and with a fresh attempt budget. Returns how many.
47
+ */
48
+ replayDead({ consumer, type }: ConsumerBinding, limit?: number): Promise<number>;
49
+ /** Stops consuming, waits for the handlers and the acknowledgements in flight, disconnects. */
50
+ close(): Promise<void>;
51
+ /** What a serialisation shows of the bus: its name, never its clients or their properties. */
52
+ toJSON(): string;
53
+ /** What `console.log` and `util.inspect` show of the bus: the same. */
54
+ [inspect.custom](): string;
55
+ /** Adds a handler to the group of one consumer for one type; the group joins in the background. */
56
+ private consume;
57
+ }
58
+ //# sourceMappingURL=kafka-event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-event-bus.d.ts","sourceRoot":"","sources":["../src/kafka-event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EAChB,wBAAwB,EACxB,0BAA0B,EAC1B,YAAY,EACb,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAMjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAMlE;;;;;;;;;GASG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAC5C,6EAA6E;IAC7E,QAAQ,CAAC,eAAe,WAAoB;IAE5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAEpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAElC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAE5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAE1C,OAAO,CAAC,MAAM,CAAS;IAEvB,YAAY,OAAO,EAAE,oBAAoB,EAsBxC;IAED,0EAA0E;IAC1E,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,iFAAiF;IACjF,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED;;;OAGG;IACG,OAAO,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhE;IAED,8DAA8D;IAC9D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,wBAAwB,GAAG,YAAY,CAMvE;IAED,0EAA0E;IAC1E,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,0BAA0B,CAMxD;IAED;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAOpC;IAED,gBAAgB,IAAI,aAAa,CAEhC;IAED;;;OAGG;IACG,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,eAAe,EAAE,KAAK,SAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYlF;IAED,+FAA+F;IACzF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAS3B;IAED,8FAA8F;IAC9F,MAAM,IAAI,MAAM,CAEf;IAED,uEAAuE;IACvE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAEzB;IAED,mGAAmG;IACnG,OAAO,CAAC,OAAO;CAOhB"}
@@ -0,0 +1,147 @@
1
+ import { inspect } from 'node:util';
2
+ import { BrokerLink } from './connection/broker-link.js';
3
+ import { clusterOf } from './connection/cluster-of.js';
4
+ import { Consumption } from './consumption/consumption.js';
5
+ import { GroupConsumer } from './consumption/group-consumer.js';
6
+ import { ConsumerNameRequiredError } from './errors/consumer-name-required-error.js';
7
+ import { MESSAGING_SYSTEM } from './messaging-system.js';
8
+ import { EventBusClosedError } from './errors/event-bus-closed-error.js';
9
+ import { settingsOf } from './options/settings-of.js';
10
+ import { Publications } from './publication/publications.js';
11
+ import { DeadLetterReplay } from './replay/dead-letter-replay.js';
12
+ import { conceal } from './secrecy/conceal.js';
13
+ import { describeTopic } from './topology/describe-topic.js';
14
+ import { topologyOf } from './topology/topology-of.js';
15
+ const DESCRIPTION = 'KafkaEventBus [clients concealed]';
16
+ /**
17
+ * The provider for Apache Kafka and other logs speaking its protocol.
18
+ *
19
+ * Publishing: one topic per event type unless `topicOf` says otherwise, record key =
20
+ * `keyOf(event)`, an idempotent producer with `acks=all`, and `publish` resolves only when
21
+ * every record is acknowledged, so it is a safe target for the outbox relay. Consuming: one
22
+ * consumer group per consuming context, the offset committed after the handlers resolved, a
23
+ * bounded number of delayed retries in place, then a dead-letter topic. Delivery is at least
24
+ * once, in order for the records of one key: consumers deduplicate.
25
+ */
26
+ export class KafkaEventBus {
27
+ /** Read by what observes the bus from outside: the name of the transport. */
28
+ messagingSystem = MESSAGING_SYSTEM;
29
+ settings;
30
+ link;
31
+ publications;
32
+ consumption;
33
+ closed = false;
34
+ constructor(options) {
35
+ const settings = settingsOf(options);
36
+ const topology = topologySettingsOf(settings);
37
+ this.settings = settings;
38
+ this.link = new BrokerLink(clusterOf(options), { ...settings, createTopics: settings.topics.create });
39
+ this.publications = new Publications(this.link, {
40
+ routing: settings,
41
+ describe: (topic) => describeTopic(topology, topic, 'events'),
42
+ failed: (code) => {
43
+ settings.onFailure({ kind: 'connection', code });
44
+ },
45
+ });
46
+ const dependencies = { link: this.link, publications: this.publications };
47
+ this.consumption = new Consumption((consumer) => new GroupConsumer(consumer, { ...dependencies, settings: { ...settings, topology } }));
48
+ conceal(this);
49
+ }
50
+ /** Records delivered to this bus whose handlers have not finished yet. */
51
+ get deliveriesInFlight() {
52
+ return this.consumption.inFlight;
53
+ }
54
+ /** Partitions the consumers of this bus own now: 0 means it consumes nothing. */
55
+ get partitionsAssigned() {
56
+ return this.consumption.partitionsAssigned;
57
+ }
58
+ /**
59
+ * Resolves when every in-sync replica acknowledged every event, rejects otherwise: nothing
60
+ * is buffered for later, so the caller (the outbox relay) knows what to retry.
61
+ */
62
+ async publish(events) {
63
+ if (this.closed) {
64
+ throw new EventBusClosedError();
65
+ }
66
+ if (events.length === 0) {
67
+ return;
68
+ }
69
+ await this.publications.publish(events);
70
+ }
71
+ /** Subscribes the consumer named by the `consumer` option. */
72
+ subscribe(type, handler) {
73
+ if (this.settings.consumer === undefined) {
74
+ throw new ConsumerNameRequiredError();
75
+ }
76
+ return this.consume({ consumer: this.settings.consumer, type }, handler);
77
+ }
78
+ /** A subscriber for one consuming context, on the clients of this bus. */
79
+ forConsumer(consumer) {
80
+ if (consumer.length === 0) {
81
+ throw new ConsumerNameRequiredError();
82
+ }
83
+ return { subscribe: (type, handler) => this.consume({ consumer, type }, handler) };
84
+ }
85
+ /**
86
+ * Creates the topics of the published types and of the subscriptions made so far, then
87
+ * resolves once those subscriptions have their partitions. Idempotent.
88
+ */
89
+ async assertTopology() {
90
+ if (this.closed) {
91
+ throw new EventBusClosedError();
92
+ }
93
+ await this.link.declare(this.describeTopology().topics);
94
+ await this.consumption.started();
95
+ }
96
+ describeTopology() {
97
+ return topologyOf(topologySettingsOf(this.settings), this.consumption.bindings());
98
+ }
99
+ /**
100
+ * Copies up to `limit` records from the dead-letter topic of a consumer back to the topic
101
+ * they came from, for that consumer only and with a fresh attempt budget. Returns how many.
102
+ */
103
+ async replayDead({ consumer, type }, limit = 100) {
104
+ if (this.closed) {
105
+ throw new EventBusClosedError();
106
+ }
107
+ const topic = this.settings.topicOf(type);
108
+ const timeoutMs = this.settings.connectTimeoutMs * 3;
109
+ const plan = { consumer, topic, limit, timeoutMs };
110
+ await this.link.declare(topologyOf(topologySettingsOf(this.settings), [{ consumer, type }]).topics);
111
+ return new DeadLetterReplay(this.link, this.publications, plan).run();
112
+ }
113
+ /** Stops consuming, waits for the handlers and the acknowledgements in flight, disconnects. */
114
+ async close() {
115
+ if (this.closed) {
116
+ return;
117
+ }
118
+ this.closed = true;
119
+ await this.consumption.drain();
120
+ await this.publications.close();
121
+ await this.link.close();
122
+ }
123
+ /** What a serialisation shows of the bus: its name, never its clients or their properties. */
124
+ toJSON() {
125
+ return DESCRIPTION;
126
+ }
127
+ /** What `console.log` and `util.inspect` show of the bus: the same. */
128
+ [inspect.custom]() {
129
+ return DESCRIPTION;
130
+ }
131
+ /** Adds a handler to the group of one consumer for one type; the group joins in the background. */
132
+ consume(binding, handler) {
133
+ if (this.closed) {
134
+ throw new EventBusClosedError();
135
+ }
136
+ return this.consumption.add(binding, handler);
137
+ }
138
+ }
139
+ function topologySettingsOf(settings) {
140
+ return {
141
+ topicOf: settings.topicOf,
142
+ publishedTypes: settings.publishedTypes,
143
+ partitions: settings.topics.partitions,
144
+ replicationFactor: settings.topics.replicationFactor,
145
+ };
146
+ }
147
+ //# sourceMappingURL=kafka-event-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-event-bus.js","sourceRoot":"","sources":["../src/kafka-event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAGzE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C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xE,CAAC;IAED,+FAA+F;IAC/F,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,8FAA8F;IAC9F,MAAM;QACJ,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,uEAAuE;IACvE,CAAC,OAAO,CAAC,MAAM,CAAC;QACd,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,mGAAmG;IAC3F,OAAO,CAAC,OAAwB,EAAE,OAAiC;QACzE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;CACF;AAED,SAAS,kBAAkB,CAAC,QAAkB;IAC5C,OAAO;QACL,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,cAAc,EAAE,QAAQ,CAAC,cAAc;QACvC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU;QACtC,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB;KACrD,CAAC;AACJ,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 = "kafka";
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,UAAU,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 = 'kafka';
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,OAAO,CAAC"}
@@ -0,0 +1,15 @@
1
+ /** One record settled by a consumer of this bus. Counted by outcome, it is the metric to watch. */
2
+ export interface KafkaDelivery {
3
+ readonly consumer: string;
4
+ readonly topic: string;
5
+ readonly partition: number;
6
+ /** Which delivery of the record this was, starting at 1. */
7
+ readonly attempt: number;
8
+ /**
9
+ * `acknowledged`: every handler resolved, the offset is committed next. `retried`: the
10
+ * partition is paused for the delay, then the record is read again. `dead`: attempts spent,
11
+ * copied to the dead-letter topic. `poison`: not an envelope, copied there too.
12
+ */
13
+ readonly outcome: 'acknowledged' | 'retried' | 'dead' | 'poison';
14
+ }
15
+ //# sourceMappingURL=kafka-delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-delivery.d.ts","sourceRoot":"","sources":["../../src/options/kafka-delivery.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;CAClE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kafka-delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-delivery.js","sourceRoot":"","sources":["../../src/options/kafka-delivery.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import type { GlobalConfig } from '@confluentinc/kafka-javascript';
2
+ import type { IntegrationEvent } from '@ddd-ts-kit/kernel';
3
+ import type { KafkaDelivery } from './kafka-delivery.js';
4
+ import type { KafkaFailure } from './kafka-failure.js';
5
+ import type { ReconnectOptions } from './reconnect-options.js';
6
+ import type { RetryOptions } from './retry-options.js';
7
+ import type { TopicOptions } from './topic-options.js';
8
+ export interface KafkaEventBusOptions {
9
+ /** Bootstrap brokers as `host:port`, in a list or separated by commas. */
10
+ readonly brokers: string | readonly string[];
11
+ /** librdkafka properties given to every client of the bus: TLS, SASL, `client.id`. */
12
+ readonly client?: GlobalConfig;
13
+ /** The consuming context `subscribe` works for: its name is the consumer group id. */
14
+ readonly consumer?: string;
15
+ /** The topic of an event type. Default: the type itself, one topic per event type. */
16
+ readonly topicOf?: (type: string) => string;
17
+ /**
18
+ * The record key: events with the same key keep their order. Default: the event id, which
19
+ * orders nothing. Give the aggregate id for per-aggregate order.
20
+ */
21
+ readonly keyOf?: (event: IntegrationEvent) => string | undefined;
22
+ /** Event types this service publishes: `assertTopology` creates their topics at startup. */
23
+ readonly publishedTypes?: readonly string[];
24
+ readonly topics?: TopicOptions;
25
+ /** Where a consumer group that has no committed offset starts. Default `earliest`. */
26
+ readonly startFrom?: 'earliest' | 'latest';
27
+ /** Partitions a consumer handles at once; records of one partition are never concurrent. Default 1. */
28
+ readonly concurrency?: number;
29
+ /** Time the in-sync replicas have to acknowledge a record before `publish` rejects. Default 30000. */
30
+ readonly publishTimeoutMs?: number;
31
+ /** Time a connection or an administrative request may take. Default 10000. */
32
+ readonly connectTimeoutMs?: number;
33
+ /** `max.poll.interval.ms`: above it, the handlers of one record lose their partitions. Default 300000. */
34
+ readonly maxHandlingMs?: number;
35
+ readonly retry?: RetryOptions;
36
+ readonly reconnect?: ReconnectOptions;
37
+ /** Observability hook. It receives codes only, so it is safe to log as is. */
38
+ readonly onFailure?: (failure: KafkaFailure) => void;
39
+ /** Metrics hook, called once per record a consumer settles, before its offset is committed. */
40
+ readonly onDelivery?: (delivery: KafkaDelivery) => void;
41
+ }
42
+ //# sourceMappingURL=kafka-event-bus-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-event-bus-options.d.ts","sourceRoot":"","sources":["../../src/options/kafka-event-bus-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAC7C,sFAAsF;IACtF,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B,sFAAsF;IACtF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,sFAAsF;IACtF,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,MAAM,GAAG,SAAS,CAAC;IACjE,4FAA4F;IAC5F,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B,sFAAsF;IACtF,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC3C,uGAAuG;IACvG,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,sGAAsG;IACtG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,8EAA8E;IAC9E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,0GAA0G;IAC1G,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,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,YAAY,KAAK,IAAI,CAAC;IACrD,+FAA+F;IAC/F,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;CACzD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kafka-event-bus-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-event-bus-options.js","sourceRoot":"","sources":["../../src/options/kafka-event-bus-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ export type KafkaFailure = {
2
+ readonly kind: 'handler';
3
+ readonly consumer: string;
4
+ readonly topic: string;
5
+ readonly eventId: string;
6
+ readonly eventType: string;
7
+ readonly code: string;
8
+ readonly attempt: number;
9
+ readonly dead: boolean;
10
+ } | {
11
+ readonly kind: 'poison';
12
+ readonly consumer: string;
13
+ readonly topic: string;
14
+ readonly code: string;
15
+ } | {
16
+ readonly kind: 'connection';
17
+ readonly code: string;
18
+ };
19
+ //# sourceMappingURL=kafka-failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-failure.d.ts","sourceRoot":"","sources":["../../src/options/kafka-failure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACpB;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,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,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACrG;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kafka-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-failure.js","sourceRoot":"","sources":["../../src/options/kafka-failure.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export interface ReconnectOptions {
2
+ /** Delay before a consumer that could not start, commit or dead-letter tries again. 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,oGAAoG;IACpG,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 record goes to the dead-letter topic. Default 5. */
3
+ readonly maxAttempts?: number;
4
+ /** Time the partition of a failed record stays paused before it is read 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,gFAAgF;IAChF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,gGAAgG;IAChG,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,4 @@
1
+ import type { KafkaEventBusOptions } from './kafka-event-bus-options.js';
2
+ import type { Settings } from './settings.js';
3
+ export declare function settingsOf(options: KafkaEventBusOptions): Settings;
4
+ //# 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,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,wBAAgB,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,QAAQ,CAiBlE"}
@@ -0,0 +1,47 @@
1
+ export function settingsOf(options) {
2
+ return {
3
+ consumer: options.consumer,
4
+ topicOf: options.topicOf ?? ((type) => type),
5
+ keyOf: options.keyOf ?? ((event) => event.id),
6
+ publishedTypes: options.publishedTypes ?? [],
7
+ topics: topicsOf(options.topics),
8
+ startFromEarliest: options.startFrom !== 'latest',
9
+ concurrency: options.concurrency ?? 1,
10
+ publishTimeoutMs: options.publishTimeoutMs ?? 30_000,
11
+ connectTimeoutMs: options.connectTimeoutMs ?? 10_000,
12
+ maxHandlingMs: options.maxHandlingMs ?? 300_000,
13
+ retry: retryOf(options.retry),
14
+ reconnect: reconnectOf(options.reconnect),
15
+ onFailure: guarded(options.onFailure),
16
+ onDelivery: guarded(options.onDelivery),
17
+ };
18
+ }
19
+ function topicsOf(topics = {}) {
20
+ return {
21
+ partitions: topics.partitions ?? -1,
22
+ replicationFactor: topics.replicationFactor ?? -1,
23
+ create: topics.create ?? true,
24
+ };
25
+ }
26
+ function retryOf(retry = {}) {
27
+ return { maxAttempts: retry.maxAttempts ?? 5, delayMs: retry.delayMs ?? 5_000 };
28
+ }
29
+ function reconnectOf(reconnect = {}) {
30
+ return {
31
+ initialMs: reconnect.initialMs ?? 200,
32
+ factor: reconnect.factor ?? 2,
33
+ maxMs: reconnect.maxMs ?? 30_000,
34
+ };
35
+ }
36
+ // A hook that throws must not leave a record uncommitted or stop a consumer.
37
+ function guarded(hook) {
38
+ return (value) => {
39
+ try {
40
+ hook?.(value);
41
+ }
42
+ catch {
43
+ return;
44
+ }
45
+ };
46
+ }
47
+ //# sourceMappingURL=settings-of.js.map