@ddd-ts-kit/nats 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 (158) hide show
  1. package/README.md +344 -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 +8 -0
  7. package/dist/codec/encode.d.ts.map +1 -0
  8. package/dist/codec/encode.js +19 -0
  9. package/dist/codec/encode.js.map +1 -0
  10. package/dist/codec/headers.d.ts +14 -0
  11. package/dist/codec/headers.d.ts.map +1 -0
  12. package/dist/codec/headers.js +14 -0
  13. package/dist/codec/headers.js.map +1 -0
  14. package/dist/codec/publication.d.ts +7 -0
  15. package/dist/codec/publication.d.ts.map +1 -0
  16. package/dist/codec/publication.js +2 -0
  17. package/dist/codec/publication.js.map +1 -0
  18. package/dist/codec/republication.d.ts +11 -0
  19. package/dist/codec/republication.d.ts.map +1 -0
  20. package/dist/codec/republication.js +16 -0
  21. package/dist/codec/republication.js.map +1 -0
  22. package/dist/connection/broker-link.d.ts +49 -0
  23. package/dist/connection/broker-link.d.ts.map +1 -0
  24. package/dist/connection/broker-link.js +160 -0
  25. package/dist/connection/broker-link.js.map +1 -0
  26. package/dist/consumption/consumption.d.ts +56 -0
  27. package/dist/consumption/consumption.d.ts.map +1 -0
  28. package/dist/consumption/consumption.js +223 -0
  29. package/dist/consumption/consumption.js.map +1 -0
  30. package/dist/consumption/failure-of.d.ts +7 -0
  31. package/dist/consumption/failure-of.d.ts.map +1 -0
  32. package/dist/consumption/failure-of.js +18 -0
  33. package/dist/consumption/failure-of.js.map +1 -0
  34. package/dist/consumption/poison-message.d.ts +3 -0
  35. package/dist/consumption/poison-message.d.ts.map +1 -0
  36. package/dist/consumption/poison-message.js +3 -0
  37. package/dist/consumption/poison-message.js.map +1 -0
  38. package/dist/consumption/track.d.ts +3 -0
  39. package/dist/consumption/track.d.ts.map +1 -0
  40. package/dist/consumption/track.js +9 -0
  41. package/dist/consumption/track.js.map +1 -0
  42. package/dist/errors/broker-unavailable-error.d.ts +8 -0
  43. package/dist/errors/broker-unavailable-error.d.ts.map +1 -0
  44. package/dist/errors/broker-unavailable-error.js +12 -0
  45. package/dist/errors/broker-unavailable-error.js.map +1 -0
  46. package/dist/errors/consumer-name-required-error.d.ts +5 -0
  47. package/dist/errors/consumer-name-required-error.d.ts.map +1 -0
  48. package/dist/errors/consumer-name-required-error.js +8 -0
  49. package/dist/errors/consumer-name-required-error.js.map +1 -0
  50. package/dist/errors/event-bus-closed-error.d.ts +5 -0
  51. package/dist/errors/event-bus-closed-error.d.ts.map +1 -0
  52. package/dist/errors/event-bus-closed-error.js +8 -0
  53. package/dist/errors/event-bus-closed-error.js.map +1 -0
  54. package/dist/errors/failure-code.d.ts +8 -0
  55. package/dist/errors/failure-code.d.ts.map +1 -0
  56. package/dist/errors/failure-code.js +19 -0
  57. package/dist/errors/failure-code.js.map +1 -0
  58. package/dist/errors/publish-not-acknowledged-error.d.ts +11 -0
  59. package/dist/errors/publish-not-acknowledged-error.d.ts.map +1 -0
  60. package/dist/errors/publish-not-acknowledged-error.js +16 -0
  61. package/dist/errors/publish-not-acknowledged-error.js.map +1 -0
  62. package/dist/ignore.d.ts +3 -0
  63. package/dist/ignore.d.ts.map +1 -0
  64. package/dist/ignore.js +5 -0
  65. package/dist/ignore.js.map +1 -0
  66. package/dist/index.d.ts +22 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +11 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/messaging-system.d.ts +3 -0
  71. package/dist/messaging-system.d.ts.map +1 -0
  72. package/dist/messaging-system.js +3 -0
  73. package/dist/messaging-system.js.map +1 -0
  74. package/dist/nats-event-bus.d.ts +57 -0
  75. package/dist/nats-event-bus.d.ts.map +1 -0
  76. package/dist/nats-event-bus.js +168 -0
  77. package/dist/nats-event-bus.js.map +1 -0
  78. package/dist/options/nats-delivery.d.ts +14 -0
  79. package/dist/options/nats-delivery.d.ts.map +1 -0
  80. package/dist/options/nats-delivery.js +2 -0
  81. package/dist/options/nats-delivery.js.map +1 -0
  82. package/dist/options/nats-event-bus-options.d.ts +40 -0
  83. package/dist/options/nats-event-bus-options.d.ts.map +1 -0
  84. package/dist/options/nats-event-bus-options.js +3 -0
  85. package/dist/options/nats-event-bus-options.js.map +1 -0
  86. package/dist/options/nats-failure.d.ts +17 -0
  87. package/dist/options/nats-failure.d.ts.map +1 -0
  88. package/dist/options/nats-failure.js +2 -0
  89. package/dist/options/nats-failure.js.map +1 -0
  90. package/dist/options/reconnect-options.d.ts +9 -0
  91. package/dist/options/reconnect-options.d.ts.map +1 -0
  92. package/dist/options/reconnect-options.js +2 -0
  93. package/dist/options/reconnect-options.js.map +1 -0
  94. package/dist/options/retry-options.d.ts +7 -0
  95. package/dist/options/retry-options.d.ts.map +1 -0
  96. package/dist/options/retry-options.js +2 -0
  97. package/dist/options/retry-options.js.map +1 -0
  98. package/dist/options/settings-of.d.ts +5 -0
  99. package/dist/options/settings-of.d.ts.map +1 -0
  100. package/dist/options/settings-of.js +55 -0
  101. package/dist/options/settings-of.js.map +1 -0
  102. package/dist/options/settings.d.ts +23 -0
  103. package/dist/options/settings.d.ts.map +1 -0
  104. package/dist/options/settings.js +2 -0
  105. package/dist/options/settings.js.map +1 -0
  106. package/dist/options/stream-storage.d.ts +2 -0
  107. package/dist/options/stream-storage.d.ts.map +1 -0
  108. package/dist/options/stream-storage.js +2 -0
  109. package/dist/options/stream-storage.js.map +1 -0
  110. package/dist/publication/publications.d.ts +25 -0
  111. package/dist/publication/publications.d.ts.map +1 -0
  112. package/dist/publication/publications.js +47 -0
  113. package/dist/publication/publications.js.map +1 -0
  114. package/dist/secrecy/conceal.d.ts +8 -0
  115. package/dist/secrecy/conceal.d.ts.map +1 -0
  116. package/dist/secrecy/conceal.js +12 -0
  117. package/dist/secrecy/conceal.js.map +1 -0
  118. package/dist/topology/binding-names-of.d.ts +5 -0
  119. package/dist/topology/binding-names-of.d.ts.map +1 -0
  120. package/dist/topology/binding-names-of.js +13 -0
  121. package/dist/topology/binding-names-of.js.map +1 -0
  122. package/dist/topology/binding-names.d.ts +10 -0
  123. package/dist/topology/binding-names.d.ts.map +1 -0
  124. package/dist/topology/binding-names.js +2 -0
  125. package/dist/topology/binding-names.js.map +1 -0
  126. package/dist/topology/consumer-binding.d.ts +6 -0
  127. package/dist/topology/consumer-binding.d.ts.map +1 -0
  128. package/dist/topology/consumer-binding.js +2 -0
  129. package/dist/topology/consumer-binding.js.map +1 -0
  130. package/dist/topology/consumer-description.d.ts +9 -0
  131. package/dist/topology/consumer-description.d.ts.map +1 -0
  132. package/dist/topology/consumer-description.js +2 -0
  133. package/dist/topology/consumer-description.js.map +1 -0
  134. package/dist/topology/dead-stream-of.d.ts +2 -0
  135. package/dist/topology/dead-stream-of.d.ts.map +1 -0
  136. package/dist/topology/dead-stream-of.js +4 -0
  137. package/dist/topology/dead-stream-of.js.map +1 -0
  138. package/dist/topology/declare-topology.d.ts +8 -0
  139. package/dist/topology/declare-topology.d.ts.map +1 -0
  140. package/dist/topology/declare-topology.js +58 -0
  141. package/dist/topology/declare-topology.js.map +1 -0
  142. package/dist/topology/nats-topology.d.ts +8 -0
  143. package/dist/topology/nats-topology.d.ts.map +1 -0
  144. package/dist/topology/nats-topology.js +2 -0
  145. package/dist/topology/nats-topology.js.map +1 -0
  146. package/dist/topology/stream-description.d.ts +11 -0
  147. package/dist/topology/stream-description.d.ts.map +1 -0
  148. package/dist/topology/stream-description.js +2 -0
  149. package/dist/topology/stream-description.js.map +1 -0
  150. package/dist/topology/topology-of.d.ts +5 -0
  151. package/dist/topology/topology-of.d.ts.map +1 -0
  152. package/dist/topology/topology-of.js +29 -0
  153. package/dist/topology/topology-of.js.map +1 -0
  154. package/dist/topology/topology-settings.d.ts +11 -0
  155. package/dist/topology/topology-settings.d.ts.map +1 -0
  156. package/dist/topology/topology-settings.js +2 -0
  157. package/dist/topology/topology-settings.js.map +1 -0
  158. package/package.json +39 -4
@@ -0,0 +1,160 @@
1
+ import { inspect } from 'node:util';
2
+ import { BrokerUnavailableError } from '../errors/broker-unavailable-error.js';
3
+ import { EventBusClosedError } from '../errors/event-bus-closed-error.js';
4
+ import { failureCode } from '../errors/failure-code.js';
5
+ import { ignore } from '../ignore.js';
6
+ import { conceal } from '../secrecy/conceal.js';
7
+ const DESCRIPTION = 'BrokerLink [connection concealed]';
8
+ /**
9
+ * The one connection of a bus. The client reconnects by itself and resumes its consumers;
10
+ * the link opens the first connection, with a delay that grows with each failed attempt,
11
+ * knows when the server is away, and opens another connection if the client ever gives up.
12
+ */
13
+ export class BrokerLink {
14
+ settings;
15
+ hooks;
16
+ connection;
17
+ opening;
18
+ retry;
19
+ failures = 0;
20
+ away = false;
21
+ closed = false;
22
+ constructor(settings, hooks) {
23
+ this.settings = settings;
24
+ this.hooks = hooks;
25
+ conceal(this);
26
+ }
27
+ /**
28
+ * The live connection. Opens the first one, joins an attempt in progress, and fails at
29
+ * once while the server is away so that a publisher never hangs on it.
30
+ */
31
+ async opened() {
32
+ if (this.closed) {
33
+ throw new EventBusClosedError();
34
+ }
35
+ if (this.connection !== undefined) {
36
+ return this.present(this.connection);
37
+ }
38
+ if (this.opening === undefined && this.retry === undefined) {
39
+ this.open();
40
+ }
41
+ if (this.opening === undefined) {
42
+ throw new BrokerUnavailableError('RECONNECTING');
43
+ }
44
+ return this.opening;
45
+ }
46
+ /** Drops the connection so that everything is rebuilt, after a consumer died on its own. */
47
+ restart() {
48
+ const connection = this.connection;
49
+ if (connection !== undefined) {
50
+ this.lost(connection);
51
+ void connection.close().catch(ignore);
52
+ }
53
+ }
54
+ /** Sends what is buffered, acknowledgements included, unless the server is away; disconnects. */
55
+ async close() {
56
+ this.closed = true;
57
+ clearTimeout(this.retry);
58
+ this.retry = undefined;
59
+ const connection = this.connection ?? (await this.opening?.catch(ignore));
60
+ this.connection = undefined;
61
+ if (!this.away) {
62
+ await connection?.flush().catch(ignore);
63
+ }
64
+ await connection?.close().catch(ignore);
65
+ }
66
+ toJSON() {
67
+ return DESCRIPTION;
68
+ }
69
+ [inspect.custom]() {
70
+ return DESCRIPTION;
71
+ }
72
+ present(connection) {
73
+ if (this.away) {
74
+ throw new BrokerUnavailableError('RECONNECTING');
75
+ }
76
+ return connection;
77
+ }
78
+ open() {
79
+ const opening = this.establish();
80
+ this.opening = opening;
81
+ void opening
82
+ .then(() => {
83
+ this.failures = 0;
84
+ }, (error) => {
85
+ this.failed(error instanceof BrokerUnavailableError ? error.reason : failureCode(error));
86
+ })
87
+ .finally(() => {
88
+ this.opening = undefined;
89
+ });
90
+ }
91
+ async establish() {
92
+ const connection = await this.connect();
93
+ try {
94
+ await this.hooks.opened(connection);
95
+ }
96
+ catch (error) {
97
+ this.hooks.lost();
98
+ await connection.close().catch(ignore);
99
+ throw new BrokerUnavailableError(failureCode(error));
100
+ }
101
+ if (this.closed) {
102
+ await connection.close().catch(ignore);
103
+ throw new EventBusClosedError();
104
+ }
105
+ this.away = false;
106
+ this.connection = connection;
107
+ void this.watch(connection);
108
+ return connection;
109
+ }
110
+ async connect() {
111
+ try {
112
+ return await this.settings.open();
113
+ }
114
+ catch (error) {
115
+ // Rethrown without its message or cause: a connection error may quote the URL.
116
+ throw new BrokerUnavailableError(failureCode(error));
117
+ }
118
+ }
119
+ async watch(connection) {
120
+ void connection.closed().then(() => {
121
+ this.lost(connection);
122
+ });
123
+ for await (const status of connection.status()) {
124
+ if (this.connection !== connection) {
125
+ return;
126
+ }
127
+ if (status.type === 'disconnect') {
128
+ this.away = true;
129
+ this.hooks.failed('CONNECTION_LOST');
130
+ }
131
+ else if (status.type === 'reconnect') {
132
+ this.away = false;
133
+ }
134
+ }
135
+ }
136
+ lost(connection) {
137
+ if (this.connection !== connection) {
138
+ return;
139
+ }
140
+ this.connection = undefined;
141
+ this.hooks.lost();
142
+ if (!this.closed) {
143
+ this.failed('CONNECTION_CLOSED');
144
+ }
145
+ }
146
+ failed(code) {
147
+ if (this.closed) {
148
+ return;
149
+ }
150
+ this.hooks.failed(code);
151
+ const { initialMs, factor, maxMs } = this.settings.reconnect;
152
+ const delay = Math.min(maxMs, initialMs * factor ** this.failures);
153
+ this.failures += 1;
154
+ this.retry = setTimeout(() => {
155
+ this.retry = undefined;
156
+ this.open();
157
+ }, delay);
158
+ }
159
+ }
160
+ //# 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;AAEpC,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,cAAc,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAehD,MAAM,WAAW,GAAG,mCAAmC,CAAC;AAExD;;;;GAIG;AACH,MAAM,OAAO,UAAU;IAcF,QAAQ;IACR,KAAK;IAdhB,UAAU,CAA6B;IAEvC,OAAO,CAAsC;IAE7C,KAAK,CAA4C;IAEjD,QAAQ,GAAG,CAAC,CAAC;IAEb,IAAI,GAAG,KAAK,CAAC;IAEb,MAAM,GAAG,KAAK,CAAC;IAEvB,YACmB,QAAsB,EACtB,KAAgB;wBADhB,QAAQ;qBACR,KAAK;QAEtB,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM;QACV,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,SA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AAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAElB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,IAAY;QACzB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnE,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;QAEnB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACvB,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,56 @@
1
+ import type { NatsConnection } from '@nats-io/transport-node';
2
+ import type { IntegrationEventCallback, Subscription } from '@ddd-ts-kit/kernel';
3
+ import type { NatsDelivery } from '../options/nats-delivery.js';
4
+ import type { NatsFailure } from '../options/nats-failure.js';
5
+ import type { RetryOptions } from '../options/retry-options.js';
6
+ import type { Publications } from '../publication/publications.js';
7
+ import type { ConsumerBinding } from '../topology/consumer-binding.js';
8
+ import type { TopologySettings } from '../topology/topology-settings.js';
9
+ export interface ConsumptionSettings {
10
+ readonly topology: TopologySettings;
11
+ readonly prefetch: number;
12
+ readonly retry: Required<RetryOptions>;
13
+ readonly onFailure: (failure: NatsFailure) => void;
14
+ readonly onDelivery: (delivery: NatsDelivery) => void;
15
+ /** Called when a consumer dies while the connection lives. */
16
+ readonly consumerLost: () => void;
17
+ }
18
+ /**
19
+ * The consuming side: one durable pull consumer per consumer and event type, an explicit
20
+ * acknowledgement once every handler resolved, and for a failure a refusal with a delay,
21
+ * then a copy to the dead-letter stream when the attempts are spent. A message is never
22
+ * delivered again at once: no hot loop.
23
+ */
24
+ export declare class Consumption {
25
+ private readonly publications;
26
+ private readonly settings;
27
+ private readonly subscriptions;
28
+ private readonly starting;
29
+ private readonly handling;
30
+ private session;
31
+ constructor(publications: Publications, settings: ConsumptionSettings);
32
+ get inFlight(): number;
33
+ bindings(): ConsumerBinding[];
34
+ add(binding: ConsumerBinding, handler: IntegrationEventCallback): Subscription;
35
+ attach(connection: NatsConnection): Promise<void>;
36
+ detach(): void;
37
+ /** Resolves once the subscriptions made so far are consuming, or have failed to. */
38
+ started(): Promise<void>;
39
+ /** Stops taking messages, lets the handlers in progress finish and acknowledge. */
40
+ drain(): Promise<void>;
41
+ private subscriptionOf;
42
+ private startOrGiveUp;
43
+ private start;
44
+ /** Hands each message to the handlers, `prefetch` of them at once at most. */
45
+ private pump;
46
+ private process;
47
+ private handle;
48
+ private deliveryOf;
49
+ private buryPoison;
50
+ private retryOrBury;
51
+ /** Acknowledged copy to the dead-letter stream first, termination second: never lost in between. */
52
+ private bury;
53
+ private settled;
54
+ private remove;
55
+ }
56
+ //# sourceMappingURL=consumption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumption.d.ts","sourceRoot":"","sources":["../../src/consumption/consumption.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAmC,wBAAwB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAalH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,O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AAO,CAAC,IAAI,CAAC,CAWtD;IAED,MAAM,IAAI,IAAI,CAMb;IAED,oFAAoF;IAC9E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAI7B;IAED,mFAAmF;IAC7E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAS3B;IAED,OAAO,CAAC,cAAc;YAmBR,aAAa;YASb,KAAK;IAenB,8EAA8E;YAChE,IAAI;YAwBJ,OAAO;YAqBP,MAAM;IAapB,OAAO,CAAC,UAAU;YAUJ,UAAU;YAQV,WAAW;IAmBzB,oGAAoG;YACtF,IAAI;IAkBlB,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,MAAM;CAWf"}
@@ -0,0 +1,223 @@
1
+ import { jetstream, jetstreamManager, } from '@nats-io/jetstream';
2
+ import { decode } from '../codec/decode.js';
3
+ import { ATTEMPT_HEADER, DEAD_REASON_HEADER, ERROR_CODE_HEADER, REPLAY_FOR_HEADER, SOURCE_HEADER, } from '../codec/headers.js';
4
+ import { republication } from '../codec/republication.js';
5
+ import { failureCode } from '../errors/failure-code.js';
6
+ import { ignore } from '../ignore.js';
7
+ import { MESSAGING_SYSTEM } from '../messaging-system.js';
8
+ import { bindingNamesOf } from '../topology/binding-names-of.js';
9
+ import { declareTopology } from '../topology/declare-topology.js';
10
+ import { topologyOf } from '../topology/topology-of.js';
11
+ import { failureOf } from './failure-of.js';
12
+ import { POISON_MESSAGE } from './poison-message.js';
13
+ import { track } from './track.js';
14
+ /**
15
+ * The consuming side: one durable pull consumer per consumer and event type, an explicit
16
+ * acknowledgement once every handler resolved, and for a failure a refusal with a delay,
17
+ * then a copy to the dead-letter stream when the attempts are spent. A message is never
18
+ * delivered again at once: no hot loop.
19
+ */
20
+ export class Consumption {
21
+ publications;
22
+ settings;
23
+ subscriptions = new Map();
24
+ starting = new Set();
25
+ handling = new Set();
26
+ session;
27
+ constructor(publications, settings) {
28
+ this.publications = publications;
29
+ this.settings = settings;
30
+ }
31
+ get inFlight() {
32
+ return this.handling.size;
33
+ }
34
+ bindings() {
35
+ return [...this.subscriptions.values()].map((subscription) => subscription.binding);
36
+ }
37
+ add(binding, handler) {
38
+ const subscription = this.subscriptionOf(binding);
39
+ subscription.handlers.add(handler);
40
+ return {
41
+ unsubscribe: () => {
42
+ this.remove(subscription, handler);
43
+ },
44
+ };
45
+ }
46
+ async attach(connection) {
47
+ const session = { client: jetstream(connection), manager: await jetstreamManager(connection) };
48
+ await declareTopology(session.manager, topologyOf(this.settings.topology, []));
49
+ // The map is iterated live: a subscription added meanwhile is started by this loop.
50
+ for (const subscription of this.subscriptions.values()) {
51
+ await this.start(session, subscription);
52
+ }
53
+ this.session = session;
54
+ }
55
+ detach() {
56
+ this.session = undefined;
57
+ for (const subscription of this.subscriptions.values()) {
58
+ subscription.messages = undefined;
59
+ }
60
+ }
61
+ /** Resolves once the subscriptions made so far are consuming, or have failed to. */
62
+ async started() {
63
+ while (this.starting.size > 0) {
64
+ await Promise.allSettled([...this.starting]);
65
+ }
66
+ }
67
+ /** Stops taking messages, lets the handlers in progress finish and acknowledge. */
68
+ async drain() {
69
+ this.session = undefined;
70
+ const pulls = [...this.subscriptions.values()].map((subscription) => stop(subscription));
71
+ await Promise.allSettled(pulls);
72
+ while (this.handling.size > 0) {
73
+ await Promise.allSettled([...this.handling]);
74
+ }
75
+ }
76
+ subscriptionOf(binding) {
77
+ const names = bindingNamesOf(binding, this.settings.topology.subjectPrefix);
78
+ const existing = this.subscriptions.get(names.durable);
79
+ if (existing !== undefined) {
80
+ return existing;
81
+ }
82
+ const subscription = { binding, names, handlers: new Set(), messages: undefined };
83
+ this.subscriptions.set(names.durable, subscription);
84
+ if (this.session !== undefined) {
85
+ track(this.starting, this.startOrGiveUp(this.session, subscription));
86
+ }
87
+ return subscription;
88
+ }
89
+ async startOrGiveUp(session, subscription) {
90
+ try {
91
+ await this.start(session, subscription);
92
+ }
93
+ catch (error) {
94
+ this.settings.onFailure({ kind: 'connection', code: failureCode(error) });
95
+ this.settings.consumerLost();
96
+ }
97
+ }
98
+ async start(session, subscription) {
99
+ const { topology, prefetch } = this.settings;
100
+ await declareTopology(session.manager, {
101
+ streams: [],
102
+ consumers: topologyOf(topology, [subscription.binding]).consumers,
103
+ });
104
+ const consumer = await session.client.consumers.get(topology.stream, subscription.names.durable);
105
+ const messages = await consumer.consume({ max_messages: prefetch });
106
+ subscription.messages = messages;
107
+ void this.pump(subscription, messages);
108
+ }
109
+ /** Hands each message to the handlers, `prefetch` of them at once at most. */
110
+ async pump(subscription, messages) {
111
+ const running = new Set();
112
+ try {
113
+ for await (const message of messages) {
114
+ const work = this.process({ subscription, message });
115
+ track(running, work);
116
+ track(this.handling, work);
117
+ if (running.size >= this.settings.prefetch) {
118
+ await Promise.race(running);
119
+ }
120
+ }
121
+ }
122
+ catch (error) {
123
+ this.settings.onFailure({ kind: 'connection', code: failureCode(error) });
124
+ }
125
+ if (subscription.messages === messages) {
126
+ // The pull ended by itself (consumer deleted, stream gone): rebuild everything.
127
+ this.settings.consumerLost();
128
+ }
129
+ }
130
+ async process(delivery) {
131
+ const { subscription, message } = delivery;
132
+ const target = message.headers?.get(REPLAY_FOR_HEADER) ?? '';
133
+ if (target !== '' && target !== subscription.names.durable) {
134
+ message.ack();
135
+ return;
136
+ }
137
+ const event = decode(message.data);
138
+ if (event === undefined) {
139
+ await this.buryPoison(delivery);
140
+ }
141
+ else if (subscription.handlers.size === 0) {
142
+ message.nak();
143
+ }
144
+ else {
145
+ await this.handle(delivery, event);
146
+ }
147
+ }
148
+ async handle(delivery, event) {
149
+ const code = await failureOf(delivery.subscription.handlers, event, this.deliveryOf(delivery));
150
+ if (code === undefined) {
151
+ this.settled(delivery, 'acknowledged');
152
+ delivery.message.ack();
153
+ return;
154
+ }
155
+ await this.retryOrBury(delivery, event, code);
156
+ }
157
+ deliveryOf({ subscription, message }) {
158
+ return {
159
+ attempt: message.info.deliveryCount,
160
+ maxAttempts: this.settings.retry.maxAttempts,
161
+ system: MESSAGING_SYSTEM,
162
+ destination: message.subject,
163
+ consumer: subscription.names.durable,
164
+ };
165
+ }
166
+ async buryPoison(delivery) {
167
+ const consumer = delivery.subscription.names.durable;
168
+ this.settings.onFailure({ kind: 'poison', consumer, code: POISON_MESSAGE });
169
+ this.settled(delivery, 'poison');
170
+ await this.bury(delivery, { [ERROR_CODE_HEADER]: POISON_MESSAGE, [DEAD_REASON_HEADER]: 'poison' });
171
+ }
172
+ async retryOrBury(delivery, event, code) {
173
+ const { retry, onFailure } = this.settings;
174
+ const consumer = delivery.subscription.names.durable;
175
+ const attempt = delivery.message.info.deliveryCount;
176
+ const dead = attempt >= retry.maxAttempts;
177
+ const { id: eventId, type: eventType } = event;
178
+ onFailure({ kind: 'handler', consumer, eventId, eventType, code, attempt, dead });
179
+ this.settled(delivery, dead ? 'dead' : 'retried');
180
+ if (dead) {
181
+ const headers = { [ERROR_CODE_HEADER]: code, [DEAD_REASON_HEADER]: 'max-attempts' };
182
+ await this.bury(delivery, { ...headers, [ATTEMPT_HEADER]: String(attempt) });
183
+ }
184
+ else {
185
+ delivery.message.nak(retry.delayMs);
186
+ }
187
+ }
188
+ /** Acknowledged copy to the dead-letter stream first, termination second: never lost in between. */
189
+ async bury({ subscription, message }, headers) {
190
+ const { stream } = this.settings.topology;
191
+ const { durable, deadSubject } = subscription.names;
192
+ const source = { [SOURCE_HEADER]: `${stream}/${String(message.seq)}` };
193
+ // A redelivery of the same message is the same dead letter: the stream keeps one.
194
+ const copy = { data: message.data, headers: message.headers, messageId: `${durable}.${String(message.seq)}` };
195
+ try {
196
+ await this.publications.send(deadSubject, republication(copy, { ...headers, ...source }));
197
+ }
198
+ catch {
199
+ message.nak(this.settings.retry.delayMs);
200
+ return;
201
+ }
202
+ message.term();
203
+ }
204
+ settled({ subscription, message }, outcome) {
205
+ const consumer = subscription.names.durable;
206
+ this.settings.onDelivery({ consumer, attempt: message.info.deliveryCount, outcome });
207
+ }
208
+ remove(subscription, handler) {
209
+ subscription.handlers.delete(handler);
210
+ if (subscription.handlers.size > 0) {
211
+ return;
212
+ }
213
+ // The durable consumer stays: it keeps its place in the stream, it only stopped reading.
214
+ this.subscriptions.delete(subscription.names.durable);
215
+ void stop(subscription);
216
+ }
217
+ }
218
+ async function stop(subscription) {
219
+ const { messages } = subscription;
220
+ subscription.messages = undefined;
221
+ await messages?.close().catch(ignore);
222
+ }
223
+ //# sourceMappingURL=consumption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumption.js","sourceRoot":"","sources":["../../src/consumption/consumption.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,gBAAgB,GAKjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA6BnC;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAUH,YAAY;IACZ,QAAQ;IAVV,aAAa,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEvD,QAAQ,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEpC,QAAQ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,OAAO,CAAC,CAAC;YAEzC,OAAO;QACT,CAAC;QAED,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;IAEO,OAAO,CAAC,EAAE,YAAY,EAAE,OAAO,EAAY,EAAE,OAAgC;QACnF,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;QAE5C,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;IAEO,MAAM,CAAC,YAAiC,EAAE,OAAiC;QACjF,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEtC,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,yFAAyF;QACzF,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtD,KAAK,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;CACF;AAED,KAAK,UAAU,IAAI,CAAC,YAAiC;IACnD,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;IAElC,YAAY,CAAC,QAAQ,GAAG,SAAS,CAAC;IAClC,MAAM,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC"}
@@ -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,3 @@
1
+ /** The error code reported for a message whose body is not an envelope. */
2
+ export declare const POISON_MESSAGE = "POISON_MESSAGE";
3
+ //# sourceMappingURL=poison-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poison-message.d.ts","sourceRoot":"","sources":["../../src/consumption/poison-message.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The error code reported for a message whose body is not an envelope. */
2
+ export const POISON_MESSAGE = 'POISON_MESSAGE';
3
+ //# sourceMappingURL=poison-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poison-message.js","sourceRoot":"","sources":["../../src/consumption/poison-message.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Keeps `work` in `set` for as long as it is pending. */
2
+ export declare function track(set: Set<Promise<void>>, work: Promise<void>): void;
3
+ //# sourceMappingURL=track.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../src/consumption/track.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAQxE"}
@@ -0,0 +1,9 @@
1
+ /** Keeps `work` in `set` for as long as it is pending. */
2
+ export function track(set, work) {
3
+ set.add(work);
4
+ const done = () => {
5
+ set.delete(work);
6
+ };
7
+ void work.then(done, done);
8
+ }
9
+ //# sourceMappingURL=track.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"track.js","sourceRoot":"","sources":["../../src/consumption/track.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,UAAU,KAAK,CAAC,GAAuB,EAAE,IAAmB;IAChE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,IAAI,GAAG,GAAS,EAAE;QACtB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** No live connection: the first one failed, or a reconnection is pending. */
2
+ export declare class BrokerUnavailableError extends Error {
3
+ readonly reason: string;
4
+ readonly code = "BROKER_UNAVAILABLE";
5
+ /** `reason` is the code of what made the server unreachable, never a message. */
6
+ constructor(reason: string);
7
+ }
8
+ //# sourceMappingURL=broker-unavailable-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-unavailable-error.d.ts","sourceRoot":"","sources":["../../src/errors/broker-unavailable-error.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,qBAAa,sBAAuB,SAAQ,KAAK;IAInC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAHnC,QAAQ,CAAC,IAAI,wBAAwB;IAErC,iFAAiF;IACjF,YAAqB,MAAM,EAAE,MAAM,EAGlC;CACF"}
@@ -0,0 +1,12 @@
1
+ /** No live connection: the first one failed, or a reconnection is pending. */
2
+ export class BrokerUnavailableError extends Error {
3
+ reason;
4
+ code = 'BROKER_UNAVAILABLE';
5
+ /** `reason` is the code of what made the server unreachable, never a message. */
6
+ constructor(reason) {
7
+ super(`The broker is unavailable (${reason})`);
8
+ this.reason = reason;
9
+ this.name = 'BrokerUnavailableError';
10
+ }
11
+ }
12
+ //# sourceMappingURL=broker-unavailable-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-unavailable-error.js","sourceRoot":"","sources":["../../src/errors/broker-unavailable-error.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAI1B,MAAM;IAHlB,IAAI,GAAG,oBAAoB,CAAC;IAErC,iFAAiF;IACjF,YAAqB,MAAc;QACjC,KAAK,CAAC,8BAA8B,MAAM,GAAG,CAAC,CAAC;sBAD5B,MAAM;QAEzB,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class ConsumerNameRequiredError extends Error {
2
+ readonly code = "CONSUMER_NAME_REQUIRED";
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=consumer-name-required-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer-name-required-error.d.ts","sourceRoot":"","sources":["../../src/errors/consumer-name-required-error.ts"],"names":[],"mappings":"AAAA,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,IAAI,4BAA4B;IAEzC,cAIC;CACF"}
@@ -0,0 +1,8 @@
1
+ export class ConsumerNameRequiredError extends Error {
2
+ code = 'CONSUMER_NAME_REQUIRED';
3
+ constructor() {
4
+ super('Subscribing needs a consumer name: build the bus with `consumer`, or use `forConsumer(name)`');
5
+ this.name = 'ConsumerNameRequiredError';
6
+ }
7
+ }
8
+ //# sourceMappingURL=consumer-name-required-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer-name-required-error.js","sourceRoot":"","sources":["../../src/errors/consumer-name-required-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACzC,IAAI,GAAG,wBAAwB,CAAC;IAEzC;QACE,KAAK,CAAC,8FAA8F,CAAC,CAAC;QAEtG,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class EventBusClosedError extends Error {
2
+ readonly code = "EVENT_BUS_CLOSED";
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=event-bus-closed-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus-closed-error.d.ts","sourceRoot":"","sources":["../../src/errors/event-bus-closed-error.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,sBAAsB;IAEnC,cAGC;CACF"}
@@ -0,0 +1,8 @@
1
+ export class EventBusClosedError extends Error {
2
+ code = 'EVENT_BUS_CLOSED';
3
+ constructor() {
4
+ super('The event bus is closed');
5
+ this.name = 'EventBusClosedError';
6
+ }
7
+ }
8
+ //# sourceMappingURL=event-bus-closed-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus-closed-error.js","sourceRoot":"","sources":["../../src/errors/event-bus-closed-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,GAAG,kBAAkB,CAAC;IAEnC;QACE,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * What may be reported about a caught error. JetStream answers a refused request with a
3
+ * numeric error code (`10058` for a stream that exists with another configuration): it
4
+ * becomes `JETSTREAM_10058`. A connection error wraps the system error: its code
5
+ * (`ECONNREFUSED`) is the one reported. Never the message.
6
+ */
7
+ export declare function failureCode(error: unknown): string;
8
+ //# sourceMappingURL=failure-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-code.d.ts","sourceRoot":"","sources":["../../src/errors/failure-code.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAalD"}