@ddd-ts-kit/kafka 0.0.0-stage → 0.1.0

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,5 @@
1
+ /** Where a record sits in the log: `<topic>/<partition>/<offset>`. */
2
+ export function sourceOf({ topic, partition, message }) {
3
+ return `${topic}/${String(partition)}/${message.offset}`;
4
+ }
5
+ //# sourceMappingURL=source-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-of.js","sourceRoot":"","sources":["../../src/codec/source-of.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,MAAM,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAkB;IACpE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { IncomingRecord } from './incoming-record.js';
2
+ /** The first value of a header of a record, as text. */
3
+ export declare function textHeader({ message }: IncomingRecord, name: string): string | undefined;
4
+ //# sourceMappingURL=text-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-header.d.ts","sourceRoot":"","sources":["../../src/codec/text-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKxF"}
@@ -0,0 +1,7 @@
1
+ /** The first value of a header of a record, as text. */
2
+ export function textHeader({ message }, name) {
3
+ const value = message.headers?.[name];
4
+ const first = Array.isArray(value) ? value[0] : value;
5
+ return first === undefined ? undefined : first.toString();
6
+ }
7
+ //# sourceMappingURL=text-header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-header.js","sourceRoot":"","sources":["../../src/codec/text-header.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,EAAE,OAAO,EAAkB,EAAE,IAAY;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEtD,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { inspect } from 'node:util';
2
+ import { KafkaJS } from '@confluentinc/kafka-javascript';
3
+ import type { TopicDescription } from '../topology/topic-description.js';
4
+ import type { Rebalance } from './rebalance.js';
5
+ export interface LinkSettings {
6
+ readonly createTopics: boolean;
7
+ readonly startFromEarliest: boolean;
8
+ readonly publishTimeoutMs: number;
9
+ readonly connectTimeoutMs: number;
10
+ readonly maxHandlingMs: number;
11
+ }
12
+ interface Connectable {
13
+ connect(): Promise<void>;
14
+ disconnect(): Promise<void>;
15
+ }
16
+ /**
17
+ * The cluster as the bus sees it: it builds the clients with the settings every one of them
18
+ * shares, and creates topics. Each client keeps its own connections alive: librdkafka
19
+ * reconnects by itself, so there is no connection for the bus to watch.
20
+ */
21
+ export declare class BrokerLink {
22
+ private readonly kafka;
23
+ private readonly settings;
24
+ private readonly known;
25
+ private adminClient;
26
+ private closed;
27
+ constructor(kafka: KafkaJS.Kafka, settings: LinkSettings);
28
+ /** Idempotent and acknowledged by every in-sync replica: what an outbox relay needs. */
29
+ producer(): KafkaJS.Producer;
30
+ /** A member of `groupId` that commits nothing by itself. */
31
+ consumer(groupId: string, rebalanced: (rebalance: Rebalance) => void): KafkaJS.Consumer;
32
+ /** Connects a client, or disconnects it and fails with a code when the cluster is silent. */
33
+ connected<Client extends Connectable>(client: Client): Promise<Client>;
34
+ /** Creates the topics that do not exist yet. An existing topic is never altered. */
35
+ declare(topics: readonly TopicDescription[]): Promise<void>;
36
+ admin(): Promise<KafkaJS.Admin>;
37
+ /** The answer of an administrative request, or `BROKER_UNAVAILABLE` with the code of its failure. */
38
+ answered<T>(request: Promise<T>): Promise<T>;
39
+ close(): Promise<void>;
40
+ toJSON(): string;
41
+ [inspect.custom](): string;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=broker-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-link.d.ts","sourceRoot":"","sources":["../../src/connection/broker-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAOzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAA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3B;IAED,MAAM,IAAI,MAAM,CAEf;IAED,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAEzB;CACF"}
@@ -0,0 +1,145 @@
1
+ import { inspect } from 'node:util';
2
+ import { KafkaJS } from '@confluentinc/kafka-javascript';
3
+ import { BrokerUnavailableError } from '../errors/broker-unavailable-error.js';
4
+ import { EventBusClosedError } from '../errors/event-bus-closed-error.js';
5
+ import { failureCode } from '../errors/failure-code.js';
6
+ import { within } from '../errors/within.js';
7
+ import { ignore } from '../ignore.js';
8
+ import { conceal } from '../secrecy/conceal.js';
9
+ const UNKNOWN_TOPIC = 'ERR_UNKNOWN_TOPIC_OR_PART';
10
+ const ASSIGNED = KafkaJS.ErrorCodes.ERR__ASSIGN_PARTITIONS;
11
+ const DESCRIPTION = 'BrokerLink [clients concealed]';
12
+ /**
13
+ * The cluster as the bus sees it: it builds the clients with the settings every one of them
14
+ * shares, and creates topics. Each client keeps its own connections alive: librdkafka
15
+ * reconnects by itself, so there is no connection for the bus to watch.
16
+ */
17
+ export class BrokerLink {
18
+ kafka;
19
+ settings;
20
+ known = new Set();
21
+ adminClient;
22
+ closed = false;
23
+ constructor(kafka, settings) {
24
+ this.kafka = kafka;
25
+ this.settings = settings;
26
+ conceal(this);
27
+ }
28
+ /** Idempotent and acknowledged by every in-sync replica: what an outbox relay needs. */
29
+ producer() {
30
+ return this.kafka.producer({
31
+ kafkaJS: { idempotent: true, acks: -1, allowAutoTopicCreation: false },
32
+ // `publish` awaits every acknowledgement: lingering would only delay it.
33
+ 'linger.ms': 0,
34
+ 'message.timeout.ms': this.settings.publishTimeoutMs,
35
+ });
36
+ }
37
+ /** A member of `groupId` that commits nothing by itself. */
38
+ consumer(groupId, rebalanced) {
39
+ return this.kafka.consumer({
40
+ kafkaJS: {
41
+ groupId,
42
+ fromBeginning: this.settings.startFromEarliest,
43
+ autoCommit: false,
44
+ allowAutoTopicCreation: false,
45
+ },
46
+ 'max.poll.interval.ms': this.settings.maxHandlingMs,
47
+ rebalance_cb: (error, partitions) => {
48
+ rebalanced({ assigned: numericCodeOf(error) === ASSIGNED, partitions });
49
+ },
50
+ });
51
+ }
52
+ /** Connects a client, or disconnects it and fails with a code when the cluster is silent. */
53
+ async connected(client) {
54
+ if (this.closed) {
55
+ throw new EventBusClosedError();
56
+ }
57
+ try {
58
+ await within(client.connect(), this.settings.connectTimeoutMs, 'CONNECT_TIMEOUT');
59
+ }
60
+ catch (error) {
61
+ void client.disconnect().catch(ignore);
62
+ throw unavailable(error);
63
+ }
64
+ return client;
65
+ }
66
+ /** Creates the topics that do not exist yet. An existing topic is never altered. */
67
+ async declare(topics) {
68
+ const missing = topics.filter((topic) => !this.known.has(topic.name));
69
+ if (missing.length === 0 || !this.settings.createTopics) {
70
+ return;
71
+ }
72
+ const admin = await this.admin();
73
+ const timeout = this.settings.connectTimeoutMs;
74
+ await this.answered(admin.createTopics({ topics: missing.map(configOf), timeout }));
75
+ await this.answered(visible(admin, missing.map((topic) => topic.name)));
76
+ for (const topic of missing) {
77
+ this.known.add(topic.name);
78
+ }
79
+ }
80
+ async admin() {
81
+ this.adminClient ??= this.connected(this.kafka.admin());
82
+ try {
83
+ return await this.adminClient;
84
+ }
85
+ catch (error) {
86
+ this.adminClient = undefined;
87
+ throw error;
88
+ }
89
+ }
90
+ /** The answer of an administrative request, or `BROKER_UNAVAILABLE` with the code of its failure. */
91
+ async answered(request) {
92
+ try {
93
+ return await within(request, this.settings.connectTimeoutMs, 'REQUEST_TIMEOUT');
94
+ }
95
+ catch (error) {
96
+ throw unavailable(error);
97
+ }
98
+ }
99
+ async close() {
100
+ this.closed = true;
101
+ const admin = await this.adminClient?.catch(ignore);
102
+ this.adminClient = undefined;
103
+ await admin?.disconnect().catch(ignore);
104
+ }
105
+ toJSON() {
106
+ return DESCRIPTION;
107
+ }
108
+ [inspect.custom]() {
109
+ return DESCRIPTION;
110
+ }
111
+ }
112
+ function numericCodeOf(error) {
113
+ return typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
114
+ }
115
+ // Rethrown without its message or cause: an error of the client may quote the brokers.
116
+ function unavailable(error) {
117
+ if (error instanceof BrokerUnavailableError || error instanceof EventBusClosedError) {
118
+ return error;
119
+ }
120
+ return new BrokerUnavailableError(failureCode(error));
121
+ }
122
+ function configOf(topic) {
123
+ return {
124
+ topic: topic.name,
125
+ ...(topic.partitions > 0 ? { numPartitions: topic.partitions } : {}),
126
+ ...(topic.replicationFactor > 0 ? { replicationFactor: topic.replicationFactor } : {}),
127
+ };
128
+ }
129
+ // A topic is created asynchronously: a client that subscribes before the broker lists it
130
+ // waits for its next metadata refresh, minutes later.
131
+ async function visible(admin, topics) {
132
+ for (;;) {
133
+ try {
134
+ await admin.fetchTopicMetadata({ topics });
135
+ return;
136
+ }
137
+ catch (error) {
138
+ if (failureCode(error) !== UNKNOWN_TOPIC) {
139
+ throw error;
140
+ }
141
+ await new Promise((resolve) => setTimeout(resolve, 50));
142
+ }
143
+ }
144
+ }
145
+ //# sourceMappingURL=broker-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-link.js","sourceRoot":"","sources":["../../src/connection/broker-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAiBhD,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,sBAAsB,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afka-event-bus-options.js';
3
+ /**
4
+ * The factory of the clients of a bus. The librdkafka properties carry the SASL password and
5
+ * the TLS keys: they go to the client library here, and the bus keeps them nowhere.
6
+ */
7
+ export declare function clusterOf({ brokers, client }: Pick<KafkaEventBusOptions, 'brokers' | 'client'>): KafkaJS.Kafka;
8
+ //# sourceMappingURL=cluster-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster-of.d.ts","sourceRoot":"","sources":["../../src/connection/cluster-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAElF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,KAAK,CAM9G"}
@@ -0,0 +1,16 @@
1
+ import { KafkaJS } from '@confluentinc/kafka-javascript';
2
+ /**
3
+ * The factory of the clients of a bus. The librdkafka properties carry the SASL password and
4
+ * the TLS keys: they go to the client library here, and the bus keeps them nowhere.
5
+ */
6
+ export function clusterOf({ brokers, client }) {
7
+ // The client logs the message and the stack of what it catches: its logs stay off, and
8
+ // failures are reported through `onFailure`, by code.
9
+ const quiet = { brokers: brokersOf(brokers), logLevel: KafkaJS.logLevel.NOTHING };
10
+ return new KafkaJS.Kafka({ ...client, kafkaJS: quiet });
11
+ }
12
+ function brokersOf(brokers) {
13
+ const listed = typeof brokers === 'string' ? brokers.split(',') : [...brokers];
14
+ return listed.map((broker) => broker.trim()).filter((broker) => broker.length > 0);
15
+ }
16
+ //# sourceMappingURL=cluster-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster-of.js","sourceRoot":"","sources":["../../src/connection/cluster-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAGzD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAoD;IAC7F,uFAAuF;IACvF,sDAAsD;IACtD,MAAM,KAAK,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAElF,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS,CAAC,OAAmC;IACpD,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;IAE/E,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { KafkaJS } from '@confluentinc/kafka-javascript';
2
+ /** Partitions a consumer group gave to a member, or took back from it. */
3
+ export interface Rebalance {
4
+ readonly assigned: boolean;
5
+ readonly partitions: readonly KafkaJS.TopicPartition[];
6
+ }
7
+ //# sourceMappingURL=rebalance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rebalance.d.ts","sourceRoot":"","sources":["../../src/connection/rebalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE9D,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,SAAS,OAAO,CAAC,cAAc,EAAE,CAAC;CACxD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rebalance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rebalance.js","sourceRoot":"","sources":["../../src/connection/rebalance.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import type { IncomingRecord } from '../codec/incoming-record.js';
2
+ /**
3
+ * How many times the record at the head of each partition has failed. Kept in memory: a
4
+ * consumer that restarts, or takes a partition over, starts the count again.
5
+ */
6
+ export declare class Attempts {
7
+ private readonly failedHeads;
8
+ /** Which delivery of the record this is, starting at 1. */
9
+ of(record: IncomingRecord): number;
10
+ failed(record: IncomingRecord): void;
11
+ forget(partition: {
12
+ readonly topic: string;
13
+ readonly partition: number;
14
+ }): void;
15
+ }
16
+ //# sourceMappingURL=attempts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempts.d.ts","sourceRoot":"","sources":["../../src/consumption/attempts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAOlE;;;GAGG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAE/D,2DAA2D;IAC3D,EAAE,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAIjC;IAED,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAInC;IAED,MAAM,CAAC,SAAS,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAE9E;CACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * How many times the record at the head of each partition has failed. Kept in memory: a
3
+ * consumer that restarts, or takes a partition over, starts the count again.
4
+ */
5
+ export class Attempts {
6
+ failedHeads = new Map();
7
+ /** Which delivery of the record this is, starting at 1. */
8
+ of(record) {
9
+ const failed = this.failedHeads.get(partitionKey(record));
10
+ return failed?.offset === record.message.offset ? failed.failures + 1 : 1;
11
+ }
12
+ failed(record) {
13
+ const failures = this.of(record);
14
+ this.failedHeads.set(partitionKey(record), { offset: record.message.offset, failures });
15
+ }
16
+ forget(partition) {
17
+ this.failedHeads.delete(partitionKey(partition));
18
+ }
19
+ }
20
+ function partitionKey({ topic, partition }) {
21
+ return `${topic}/${String(partition)}`;
22
+ }
23
+ //# sourceMappingURL=attempts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempts.js","sourceRoot":"","sources":["../../src/consumption/attempts.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACF,WAAW,GAAG,IAAI,GAAG,EAAwB,CAAC;IAE/D,2DAA2D;IAC3D,EAAE,CAAC,MAAsB;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QAE1D,OAAO,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,CAAC,MAAsB;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QAEjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM,CAAC,SAAiE;QACtE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AAED,SAAS,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAA0D;IAChG,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ReconnectOptions } from '../options/reconnect-options.js';
2
+ /** The wait before the next attempt of something that keeps failing: longer after each failure. */
3
+ export declare class Backoff {
4
+ private readonly reconnect;
5
+ private failures;
6
+ constructor(reconnect: Required<ReconnectOptions>);
7
+ /** The delay before the attempt that follows the failures counted so far. */
8
+ get delayMs(): number;
9
+ failed(): void;
10
+ reset(): void;
11
+ }
12
+ //# sourceMappingURL=backoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/consumption/backoff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,mGAAmG;AACnG,qBAAa,OAAO;IAGN,OAAO,CAAC,QAAQ,CAAC,SAAS;IAFtC,OAAO,CAAC,QAAQ,CAAK;IAErB,YAA6B,SAAS,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAI;IAEtE,6EAA6E;IAC7E,IAAI,OAAO,IAAI,MAAM,CAIpB;IAED,MAAM,IAAI,IAAI,CAEb;IAED,KAAK,IAAI,IAAI,CAEZ;CACF"}
@@ -0,0 +1,20 @@
1
+ /** The wait before the next attempt of something that keeps failing: longer after each failure. */
2
+ export class Backoff {
3
+ reconnect;
4
+ failures = 0;
5
+ constructor(reconnect) {
6
+ this.reconnect = reconnect;
7
+ }
8
+ /** The delay before the attempt that follows the failures counted so far. */
9
+ get delayMs() {
10
+ const { initialMs, factor, maxMs } = this.reconnect;
11
+ return Math.min(maxMs, initialMs * factor ** this.failures);
12
+ }
13
+ failed() {
14
+ this.failures += 1;
15
+ }
16
+ reset() {
17
+ this.failures = 0;
18
+ }
19
+ }
20
+ //# sourceMappingURL=backoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../src/consumption/backoff.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,MAAM,OAAO,OAAO;IAGW,SAAS;IAF9B,QAAQ,GAAG,CAAC,CAAC;IAErB,YAA6B,SAAqC;yBAArC,SAAS;IAA+B,CAAC;IAEtE,6EAA6E;IAC7E,IAAI,OAAO;QACT,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAEpD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import type { IntegrationEventCallback, Subscription } from '@ddd-ts-kit/kernel';
2
+ import type { ConsumerBinding } from '../topology/consumer-binding.js';
3
+ import type { GroupConsumer } from './group-consumer.js';
4
+ /** The consuming side of a bus: one group consumer per consuming context, opened on demand. */
5
+ export declare class Consumption {
6
+ private readonly open;
7
+ private readonly groups;
8
+ constructor(open: (consumer: string) => GroupConsumer);
9
+ get inFlight(): number;
10
+ get partitionsAssigned(): number;
11
+ bindings(): ConsumerBinding[];
12
+ add({ consumer, type }: ConsumerBinding, handler: IntegrationEventCallback): Subscription;
13
+ /** Resolves once the subscriptions made so far are consuming, or have failed to. */
14
+ started(): Promise<void>;
15
+ drain(): Promise<void>;
16
+ private sum;
17
+ }
18
+ //# sourceMappingURL=consumption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumption.d.ts","sourceRoot":"","sources":["../../src/consumption/consumption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,+FAA+F;AAC/F,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAE3D,YAA6B,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,aAAa,EAAI;IAE1E,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,QAAQ,IAAI,eAAe,EAAE,CAE5B;IAED,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,wBAAwB,GAAG,YAAY,CAMxF;IAED,oFAAoF;IAC9E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,OAAO,CAAC,GAAG;CAGZ"}
@@ -0,0 +1,33 @@
1
+ /** The consuming side of a bus: one group consumer per consuming context, opened on demand. */
2
+ export class Consumption {
3
+ open;
4
+ groups = new Map();
5
+ constructor(open) {
6
+ this.open = open;
7
+ }
8
+ get inFlight() {
9
+ return this.sum((group) => group.inFlight);
10
+ }
11
+ get partitionsAssigned() {
12
+ return this.sum((group) => group.partitionsAssigned);
13
+ }
14
+ bindings() {
15
+ return [...this.groups.values()].flatMap((group) => group.types().map((type) => ({ consumer: group.name, type })));
16
+ }
17
+ add({ consumer, type }, handler) {
18
+ const group = this.groups.get(consumer) ?? this.open(consumer);
19
+ this.groups.set(consumer, group);
20
+ return group.add(type, handler);
21
+ }
22
+ /** Resolves once the subscriptions made so far are consuming, or have failed to. */
23
+ async started() {
24
+ await Promise.all([...this.groups.values()].map((group) => group.started()));
25
+ }
26
+ async drain() {
27
+ await Promise.all([...this.groups.values()].map((group) => group.drain()));
28
+ }
29
+ sum(count) {
30
+ return [...this.groups.values()].reduce((total, group) => total + count(group), 0);
31
+ }
32
+ }
33
+ //# sourceMappingURL=cons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,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAEO,GAAG,CAAC,KAAuC;QACjD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Tells the client that a record was not handled: it reads the record again once the
3
+ * partition, paused beforehand, is resumed. Its message says nothing about the event.
4
+ */
5
+ export declare class DeliveryPostponed extends Error {
6
+ readonly code = "DELIVERY_POSTPONED";
7
+ constructor();
8
+ }
9
+ //# sourceMappingURL=delivery-postponed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery-postponed.d.ts","sourceRoot":"","sources":["../../src/consumption/delivery-postponed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,wBAAwB;IAErC,cAGC;CACF"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Tells the client that a record was not handled: it reads the record again once the
3
+ * partition, paused beforehand, is resumed. Its message says nothing about the event.
4
+ */
5
+ export class DeliveryPostponed extends Error {
6
+ code = 'DELIVERY_POSTPONED';
7
+ constructor() {
8
+ super('The delivery is postponed');
9
+ this.name = 'DeliveryPostponed';
10
+ }
11
+ }
12
+ //# sourceMappingURL=delivery-postponed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery-postponed.js","sourceRoot":"","sources":["../../src/consumption/delivery-postponed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,GAAG,oBAAoB,CAAC;IAErC;QACE,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { EventDelivery, IntegrationEvent, IntegrationEventCallback } from '@ddd-ts-kit/kernel';
2
+ /**
3
+ * Runs every handler, so one that fails does not starve the others; gives the first code. Each
4
+ * handler is told which delivery this is, for what observes it from outside.
5
+ */
6
+ export declare function failureOf(handlers: ReadonlySet<IntegrationEventCallback>, event: IntegrationEvent, delivery: EventDelivery): Promise<string | undefined>;
7
+ //# sourceMappingURL=failure-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-of.d.ts","sourceRoot":"","sources":["../../src/consumption/failure-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAGpG;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,WAAW,CAAC,wBAAwB,CAAC,EAC/C,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAY7B"}
@@ -0,0 +1,18 @@
1
+ import { failureCode } from '../errors/failure-code.js';
2
+ /**
3
+ * Runs every handler, so one that fails does not starve the others; gives the first code. Each
4
+ * handler is told which delivery this is, for what observes it from outside.
5
+ */
6
+ export async function failureOf(handlers, event, delivery) {
7
+ let code;
8
+ for (const handler of [...handlers]) {
9
+ try {
10
+ await handler(event, delivery);
11
+ }
12
+ catch (error) {
13
+ code ??= failureCode(error);
14
+ }
15
+ }
16
+ return code;
17
+ }
18
+ //# sourceMappingURL=failure-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-of.js","sourceRoot":"","sources":["../../src/consumption/failure-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAA+C,EAC/C,KAAuB,EACvB,QAAuB;IAEvB,IAAI,IAAwB,CAAC;IAE7B,KAAK,MAAM,OAAO,IAAI,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;QACpC,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { IntegrationEventCallback, Subscription } from '@ddd-ts-kit/kernel';
2
+ import type { BrokerLink } from '../connection/broker-link.js';
3
+ import type { KafkaDelivery } from '../options/kafka-delivery.js';
4
+ import type { KafkaFailure } from '../options/kafka-failure.js';
5
+ import type { ReconnectOptions } from '../options/reconnect-options.js';
6
+ import type { RetryOptions } from '../options/retry-options.js';
7
+ import type { Publications } from '../publication/publications.js';
8
+ import type { TopologySettings } from '../topology/topology-settings.js';
9
+ interface GroupSettings {
10
+ readonly topology: TopologySettings;
11
+ readonly concurrency: number;
12
+ readonly retry: Required<RetryOptions>;
13
+ readonly reconnect: Required<ReconnectOptions>;
14
+ readonly onFailure: (failure: KafkaFailure) => void;
15
+ readonly onDelivery: (delivery: KafkaDelivery) => void;
16
+ }
17
+ export interface GroupDependencies {
18
+ readonly link: BrokerLink;
19
+ readonly publications: Publications;
20
+ readonly settings: GroupSettings;
21
+ }
22
+ /**
23
+ * One consuming context: a member of the consumer group named after it. It joins the group,
24
+ * subscribes to the topics of its event types as they are added, starts again after a delay
25
+ * when the cluster fails it, and hands each record it reads to its `RecordHandling`.
26
+ */
27
+ export declare class GroupConsumer {
28
+ readonly name: string;
29
+ private readonly dependencies;
30
+ private readonly topics;
31
+ private readonly subscribed;
32
+ private readonly timers;
33
+ private readonly backoff;
34
+ private readonly records;
35
+ private client;
36
+ private running;
37
+ private work;
38
+ private joined;
39
+ private join;
40
+ private draining;
41
+ constructor(name: string, dependencies: GroupDependencies);
42
+ get inFlight(): number;
43
+ get partitionsAssigned(): number;
44
+ types(): string[];
45
+ add(type: string, handler: IntegrationEventCallback): Subscription;
46
+ /** Resolves once the group has its partitions for the subscriptions made so far, or failed to. */
47
+ started(): Promise<void>;
48
+ /** Stops reading, lets the handlers in progress finish and commit, leaves the group. */
49
+ drain(): Promise<void>;
50
+ private synchronize;
51
+ private subscribePending;
52
+ private topology;
53
+ private connected;
54
+ private rebalanced;
55
+ private run;
56
+ private deliver;
57
+ private restartLater;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=group-consumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-consumer.d.ts","sourceRoot":"","sources":["../../src/consumption/group-consumer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAI/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,M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