@nimbus-cqrs/eventsourcingdb 2.5.0 → 3.0.0-beta.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 (87) hide show
  1. package/README.md +82 -46
  2. package/dist/index.d.ts +8 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +8 -0
  5. package/dist/index.js.map +1 -0
  6. package/{esm → dist}/lib/client.d.ts +28 -17
  7. package/{esm → dist}/lib/client.d.ts.map +1 -1
  8. package/{esm → dist}/lib/client.js +25 -19
  9. package/dist/lib/client.js.map +1 -0
  10. package/dist/lib/consumerRunner.d.ts +62 -0
  11. package/dist/lib/consumerRunner.d.ts.map +1 -0
  12. package/dist/lib/consumerRunner.js +386 -0
  13. package/dist/lib/consumerRunner.js.map +1 -0
  14. package/dist/lib/eventConsumer.d.ts +94 -0
  15. package/dist/lib/eventConsumer.d.ts.map +1 -0
  16. package/dist/lib/eventConsumer.js +2 -0
  17. package/dist/lib/eventConsumer.js.map +1 -0
  18. package/{esm → dist}/lib/eventMapping.d.ts +1 -1
  19. package/dist/lib/eventMapping.d.ts.map +1 -0
  20. package/{esm → dist}/lib/eventMapping.js +2 -1
  21. package/dist/lib/eventMapping.js.map +1 -0
  22. package/dist/lib/eventObserver.d.ts +158 -0
  23. package/dist/lib/eventObserver.d.ts.map +1 -0
  24. package/dist/lib/eventObserver.js +339 -0
  25. package/dist/lib/eventObserver.js.map +1 -0
  26. package/dist/lib/observerRegistry.d.ts +39 -0
  27. package/dist/lib/observerRegistry.d.ts.map +1 -0
  28. package/dist/lib/observerRegistry.js +56 -0
  29. package/dist/lib/observerRegistry.js.map +1 -0
  30. package/{esm → dist}/lib/readEvents.d.ts.map +1 -1
  31. package/{esm → dist}/lib/readEvents.js +3 -2
  32. package/dist/lib/readEvents.js.map +1 -0
  33. package/{esm → dist}/lib/tracing.d.ts.map +1 -1
  34. package/{esm → dist}/lib/tracing.js +2 -1
  35. package/dist/lib/tracing.js.map +1 -0
  36. package/dist/lib/writeEvents.d.ts +29 -0
  37. package/dist/lib/writeEvents.d.ts.map +1 -0
  38. package/dist/lib/writeEvents.js +47 -0
  39. package/dist/lib/writeEvents.js.map +1 -0
  40. package/package.json +32 -13
  41. package/src/index.ts +7 -0
  42. package/src/lib/client.ts +166 -0
  43. package/src/lib/consumerRunner.ts +592 -0
  44. package/src/lib/eventConsumer.ts +95 -0
  45. package/src/lib/eventMapping.ts +115 -0
  46. package/src/lib/eventObserver.ts +620 -0
  47. package/src/lib/observerRegistry.ts +69 -0
  48. package/src/lib/readEvents.ts +28 -0
  49. package/src/lib/tracing.ts +295 -0
  50. package/src/lib/writeEvents.ts +72 -0
  51. package/esm/_dnt.polyfills.d.ts +0 -7
  52. package/esm/_dnt.polyfills.d.ts.map +0 -1
  53. package/esm/_dnt.polyfills.js +0 -1
  54. package/esm/_dnt.shims.d.ts +0 -2
  55. package/esm/_dnt.shims.d.ts.map +0 -1
  56. package/esm/_dnt.shims.js +0 -57
  57. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts +0 -700
  58. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.d.ts.map +0 -1
  59. package/esm/deps/jsr.io/@std/fmt/1.0.10/colors.js +0 -903
  60. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +0 -14
  61. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +0 -1
  62. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.js +0 -65
  63. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +0 -20
  64. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +0 -1
  65. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +0 -43
  66. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +0 -44
  67. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +0 -1
  68. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.js +0 -47
  69. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +0 -44
  70. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +0 -1
  71. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +0 -51
  72. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +0 -31
  73. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +0 -1
  74. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.js +0 -37
  75. package/esm/index.d.ts +0 -7
  76. package/esm/index.d.ts.map +0 -1
  77. package/esm/index.js +0 -6
  78. package/esm/lib/eventMapping.d.ts.map +0 -1
  79. package/esm/lib/eventObserver.d.ts +0 -133
  80. package/esm/lib/eventObserver.d.ts.map +0 -1
  81. package/esm/lib/eventObserver.js +0 -299
  82. package/esm/lib/writeEvents.d.ts +0 -11
  83. package/esm/lib/writeEvents.d.ts.map +0 -1
  84. package/esm/lib/writeEvents.js +0 -28
  85. package/esm/package.json +0 -3
  86. /package/{esm → dist}/lib/readEvents.d.ts +0 -0
  87. /package/{esm → dist}/lib/tracing.d.ts +0 -0
@@ -0,0 +1,386 @@
1
+ import { GenericException, getLogger, } from '@nimbus-cqrs/core';
2
+ import { eventSourcingDBEventToNimbusEvent } from "./eventMapping.js";
3
+ /** How long the stream has to go quiet before a burst is considered over. */
4
+ const BURST_IDLE_MS = 2000;
5
+ const toError = (error) => {
6
+ return error instanceof Error ? error : new Error(String(error));
7
+ };
8
+ const describeError = (error) => {
9
+ return {
10
+ name: error.name,
11
+ message: error.message,
12
+ ...(error.stack !== undefined ? { stack: error.stack } : {}),
13
+ };
14
+ };
15
+ const describeFailures = (failures) => {
16
+ return Object.fromEntries([...failures.entries()].map(([name, error]) => {
17
+ return [name, describeError(error)];
18
+ }));
19
+ };
20
+ const failureSummary = (failures) => {
21
+ return [...failures.entries()]
22
+ .map(([name, error]) => {
23
+ return `${name}: ${error.name}: ${error.message}`;
24
+ })
25
+ .join('; ');
26
+ };
27
+ /**
28
+ * Times contiguous runs of events and logs one summary per run, so a replay
29
+ * reports as a single line instead of one per event. A run ends once the
30
+ * stream has been quiet for {@link BURST_IDLE_MS}; the reported duration
31
+ * covers only the events themselves, never the idle wait.
32
+ */
33
+ const createBurstTimer = (observer) => {
34
+ let burst = null;
35
+ let timer;
36
+ let inFlight = false;
37
+ const log = () => {
38
+ if (burst === null) {
39
+ return;
40
+ }
41
+ const durationMs = burst.finishedAt - burst.startedAt;
42
+ const durationSeconds = Math.floor((durationMs / 1000) * 1000) / 1000;
43
+ const { events, eventsHandled, firstEventId, lastEventId } = burst;
44
+ burst = null;
45
+ getLogger().debug({
46
+ category: 'Nimbus',
47
+ message: `Observer "${observer}" processed ${events} event(s) in ${durationSeconds}s`,
48
+ data: {
49
+ observer,
50
+ events,
51
+ eventsHandled,
52
+ durationMs,
53
+ eventsPerSecond: durationMs > 0
54
+ ? Math.round((events / durationMs) * 1000)
55
+ : events,
56
+ firstEventId,
57
+ lastEventId,
58
+ },
59
+ });
60
+ };
61
+ const schedule = () => {
62
+ if (timer !== undefined) {
63
+ clearTimeout(timer);
64
+ }
65
+ const scheduled = setTimeout(() => {
66
+ timer = undefined;
67
+ // A single event slower than the idle window must not split its
68
+ // own burst in two.
69
+ if (inFlight) {
70
+ schedule();
71
+ return;
72
+ }
73
+ log();
74
+ }, BURST_IDLE_MS);
75
+ timer = scheduled;
76
+ // Never hold the process open just to emit a timing line.
77
+ scheduled.unref();
78
+ };
79
+ return {
80
+ start: (eventId) => {
81
+ inFlight = true;
82
+ const now = Date.now();
83
+ burst ??= {
84
+ startedAt: now,
85
+ finishedAt: now,
86
+ events: 0,
87
+ eventsHandled: 0,
88
+ firstEventId: eventId,
89
+ lastEventId: eventId,
90
+ };
91
+ burst.events += 1;
92
+ burst.lastEventId = eventId;
93
+ },
94
+ finish: (handled) => {
95
+ inFlight = false;
96
+ if (burst !== null) {
97
+ burst.finishedAt = Date.now();
98
+ if (handled) {
99
+ burst.eventsHandled += 1;
100
+ }
101
+ }
102
+ schedule();
103
+ },
104
+ };
105
+ };
106
+ /**
107
+ * The lowest position of all consumers. Consumers ahead of it skip the
108
+ * replayed events in memory.
109
+ */
110
+ const lowerBoundFor = (states) => {
111
+ let lowest = null;
112
+ for (const state of states) {
113
+ if (state.position === null) {
114
+ return { id: '0', type: 'inclusive' };
115
+ }
116
+ if (lowest === null || state.position < lowest) {
117
+ lowest = state.position;
118
+ }
119
+ }
120
+ return lowest === null
121
+ ? { id: '0', type: 'inclusive' }
122
+ : { id: lowest.toString(), type: 'exclusive' };
123
+ };
124
+ const startsFromHead = (consumer) => {
125
+ return consumer.startFrom === 'head';
126
+ };
127
+ /**
128
+ * Every consumer name has to be unique and every dependency has to name a
129
+ * consumer declared earlier on the same observer. A consumer that resumes
130
+ * from its checkpoint must not depend on one that starts from the head,
131
+ * because that dependency never built state for older events.
132
+ */
133
+ const validateConsumers = (observer, consumers) => {
134
+ const declared = new Map();
135
+ for (const consumer of consumers) {
136
+ if (declared.has(consumer.name)) {
137
+ throw new GenericException(`Observer "${observer}" declares consumer "${consumer.name}" more than once`, { observer, consumer: consumer.name });
138
+ }
139
+ for (const dependency of consumer.dependsOn ?? []) {
140
+ const declaredDependency = declared.get(dependency);
141
+ if (declaredDependency === undefined) {
142
+ throw new GenericException(`Consumer "${consumer.name}" of observer "${observer}" depends on "${dependency}", which is not declared before it`, { observer, consumer: consumer.name, dependency });
143
+ }
144
+ if (!startsFromHead(consumer) &&
145
+ startsFromHead(declaredDependency)) {
146
+ throw new GenericException(`Consumer "${consumer.name}" of observer "${observer}" resumes from its checkpoint but depends on "${dependency}", which starts from the head and skips older events`, { observer, consumer: consumer.name, dependency });
147
+ }
148
+ }
149
+ declared.set(consumer.name, consumer);
150
+ }
151
+ };
152
+ /**
153
+ * Wires the consumers of one observer onto a shared stream.
154
+ *
155
+ * Consumers run sequentially in declaration order. Every non-halted
156
+ * consumer advances its position on every event — handled or not — which
157
+ * keeps the position contiguous and lets a restart resume exactly where it
158
+ * stopped.
159
+ *
160
+ * A consumer that throws holds its position while its siblings advance, as
161
+ * does every consumer that depends on it. The handler then rejects so the
162
+ * observer retries in place. On the next retry the advanced consumers skip
163
+ * themselves, so only the failing ones run again. Once retries are
164
+ * exhausted those consumers are halted. They are skipped for the rest of
165
+ * the process lifetime and their checkpoint stays at the last event they
166
+ * finished, so a restart resumes at the event they could not handle.
167
+ *
168
+ * Consumers with `startFrom: 'head'` ignore their stored position and
169
+ * start at the head of the subject on every start. Their checkpoint is
170
+ * still written like any other, so operators see where they are.
171
+ */
172
+ export const createConsumerRunner = async ({ observer, consumers, checkpointStore, head, }) => {
173
+ validateConsumers(observer, consumers);
174
+ const names = consumers.map((consumer) => {
175
+ return consumer.name;
176
+ });
177
+ const checkpoints = await checkpointStore.load(names);
178
+ const positionFor = (consumer) => {
179
+ if (startsFromHead(consumer)) {
180
+ return head === null ? null : BigInt(head);
181
+ }
182
+ const position = checkpoints.get(consumer.name)?.position;
183
+ return position === undefined ? null : BigInt(position);
184
+ };
185
+ const states = consumers.map((consumer) => {
186
+ const checkpoint = checkpoints.get(consumer.name);
187
+ return {
188
+ consumer,
189
+ position: positionFor(consumer),
190
+ pending: false,
191
+ halted: false,
192
+ ...(checkpoint?.failure !== undefined
193
+ ? { failure: checkpoint.failure }
194
+ : {}),
195
+ };
196
+ });
197
+ const statesByName = new Map(states.map((state) => {
198
+ return [state.consumer.name, state];
199
+ }));
200
+ // Failures from the most recent handler attempt, read by onExhausted
201
+ // to know which consumers to halt.
202
+ let lastFailures = new Map();
203
+ const burstTimer = createBurstTimer(observer);
204
+ const flush = async (failed) => {
205
+ const updates = [];
206
+ const now = new Date().toISOString();
207
+ for (const state of states) {
208
+ const error = failed?.errors.get(state.consumer.name);
209
+ if (failed !== undefined && error !== undefined) {
210
+ state.failure = {
211
+ position: failed.position,
212
+ error: `${error.name}: ${error.message}`,
213
+ at: now,
214
+ };
215
+ state.pending = true;
216
+ }
217
+ if (!state.pending) {
218
+ continue;
219
+ }
220
+ // A halted consumer carries its marker on every write until
221
+ // it is reset, so a marker whose first write failed is still
222
+ // persisted by the next successful flush. A running consumer
223
+ // only has a marker loaded from the store, which the save
224
+ // after its next success clears.
225
+ const failure = state.halted && state.failure !== undefined
226
+ ? {
227
+ position: state.failure.position,
228
+ error: state.failure.error,
229
+ }
230
+ : undefined;
231
+ updates.push({
232
+ consumer: state.consumer.name,
233
+ observer,
234
+ ...(state.position !== null
235
+ ? { position: state.position.toString() }
236
+ : {}),
237
+ ...(failure !== undefined ? { failure } : {}),
238
+ });
239
+ }
240
+ if (updates.length === 0) {
241
+ return;
242
+ }
243
+ await checkpointStore.save(updates);
244
+ for (const state of states) {
245
+ state.pending = false;
246
+ }
247
+ };
248
+ /**
249
+ * The error that blocks the consumer on this event because one of its
250
+ * dependencies failed on it or is halted, or `undefined`.
251
+ */
252
+ const dependencyFailure = (state, failures, eventId) => {
253
+ const failedDependency = (state.consumer.dependsOn ?? []).find((dependency) => {
254
+ return (failures.has(dependency) ||
255
+ statesByName.get(dependency)?.halted === true);
256
+ });
257
+ return failedDependency === undefined
258
+ ? undefined
259
+ : new GenericException(`Dependency "${failedDependency}" did not finish event ${eventId}`, { dependency: failedDependency });
260
+ };
261
+ /**
262
+ * Offers the event to one consumer. Both the predicate and the handler
263
+ * run inside the error boundary, so a throwing predicate is a failure
264
+ * of this consumer alone and its siblings still receive the event.
265
+ */
266
+ const runConsumer = async (state, event, raw) => {
267
+ try {
268
+ if (!state.consumer.handles(event)) {
269
+ return { handled: false };
270
+ }
271
+ await state.consumer.handle(event, raw);
272
+ return { handled: true };
273
+ }
274
+ catch (error) {
275
+ const failure = toError(error);
276
+ getLogger().error({
277
+ category: 'Nimbus',
278
+ message: `Consumer "${state.consumer.name}" failed to handle event ${raw.id} (${raw.type})`,
279
+ error: failure,
280
+ data: {
281
+ observer,
282
+ consumer: state.consumer.name,
283
+ eventId: raw.id,
284
+ eventType: raw.type,
285
+ },
286
+ correlationId: event.correlationid,
287
+ });
288
+ return { handled: true, error: failure };
289
+ }
290
+ };
291
+ const handle = async (raw) => {
292
+ const eventId = BigInt(raw.id);
293
+ const failures = new Map();
294
+ let handled = false;
295
+ // Before mapping: an event that cannot be mapped leaves an empty
296
+ // map behind, which tells onExhausted to halt every consumer.
297
+ lastFailures = failures;
298
+ const event = eventSourcingDBEventToNimbusEvent(raw);
299
+ burstTimer.start(raw.id);
300
+ try {
301
+ for (const state of states) {
302
+ if (state.halted ||
303
+ (state.position !== null && eventId <= state.position)) {
304
+ continue;
305
+ }
306
+ const blocked = dependencyFailure(state, failures, raw.id);
307
+ if (blocked !== undefined) {
308
+ failures.set(state.consumer.name, blocked);
309
+ continue;
310
+ }
311
+ // Declaration order: a later consumer reads the earlier projection.
312
+ const result = await runConsumer(state, event, raw); // NOSONAR
313
+ handled ||= result.handled;
314
+ if (result.error !== undefined) {
315
+ failures.set(state.consumer.name, result.error);
316
+ continue;
317
+ }
318
+ state.position = eventId;
319
+ state.pending = true;
320
+ state.failure = undefined;
321
+ }
322
+ await flush();
323
+ }
324
+ finally {
325
+ burstTimer.finish(handled);
326
+ }
327
+ if (failures.size > 0) {
328
+ const exception = new GenericException(`Observer "${observer}" could not handle event ${raw.id} for ${failureSummary(failures)}`, {
329
+ eventId: raw.id,
330
+ eventType: raw.type,
331
+ consumers: describeFailures(failures),
332
+ });
333
+ const cause = [...failures.values()][0];
334
+ if (cause !== undefined) {
335
+ exception.cause = cause;
336
+ }
337
+ throw exception;
338
+ }
339
+ };
340
+ const onExhausted = async (error, raw) => {
341
+ // An empty failure map means the handler broke outside a consumer
342
+ // (event mapping or the checkpoint flush), leaving the whole
343
+ // observer in an unknown state — halt all of it.
344
+ const errors = lastFailures.size > 0
345
+ ? lastFailures
346
+ : new Map(states
347
+ .filter((state) => {
348
+ return !state.halted;
349
+ })
350
+ .map((state) => {
351
+ return [state.consumer.name, error];
352
+ }));
353
+ for (const state of states) {
354
+ if (errors.has(state.consumer.name)) {
355
+ state.halted = true;
356
+ }
357
+ }
358
+ const cause = errors.size === 1 ? [...errors.values()][0] : error;
359
+ getLogger().critical({
360
+ category: 'Nimbus',
361
+ message: `Halted ${errors.size} consumer(s) of observer "${observer}" at event ${raw.id}. They stay at their checkpoint until the process restarts. ${failureSummary(errors)}`,
362
+ error: cause ?? error,
363
+ data: {
364
+ observer,
365
+ eventId: raw.id,
366
+ eventType: raw.type,
367
+ consumers: describeFailures(errors),
368
+ },
369
+ });
370
+ await flush({ position: raw.id, errors });
371
+ };
372
+ const status = () => {
373
+ return states.map((state) => {
374
+ return {
375
+ name: state.consumer.name,
376
+ position: state.position === null ? null : state.position.toString(),
377
+ halted: state.halted,
378
+ ...(state.failure !== undefined
379
+ ? { failure: { ...state.failure } }
380
+ : {}),
381
+ };
382
+ });
383
+ };
384
+ return { lowerBound: lowerBoundFor(states), handle, onExhausted, status };
385
+ };
386
+ //# sourceMappingURL=consumerRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumerRunner.js","sourceRoot":"","sources":["../../src/lib/consumerRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,gBAAgB,EAChB,SAAS,GACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,iCAAiC,EAAE,MAAM,mBAAmB,CAAC;AAuDtE,6EAA6E;AAC7E,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,MAAM,OAAO,GAAG,CAAC,KAAc,EAAS,EAAE;IACtC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,KAAY,EAA2B,EAAE;IAC5D,OAAO;QACH,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,CAAC,K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C,EAAE,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE;oBACnC,CAAC,CAAC,EAAE,CAAC;aACZ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAC9E,CAAC,CAAC"}
@@ -0,0 +1,94 @@
1
+ import type { CheckpointFailure, Event } from '@nimbus-cqrs/core';
2
+ import type { Event as EventSourcingDBEvent } from 'eventsourcingdb';
3
+ /**
4
+ * One stateful consumer of an observed event stream.
5
+ *
6
+ * A read-model projection, a policy, an event handler and a process manager
7
+ * all share this shape. Each consumer owns a checkpoint keyed by its
8
+ * {@link name}, so one of them can be rebuilt or halted without moving the
9
+ * others on the same observer.
10
+ *
11
+ * Consumers run sequentially in the order they are declared on the
12
+ * observer. A consumer that reads what another one writes should declare
13
+ * it in {@link dependsOn} instead of relying on the order alone.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import type { EventConsumer } from '@nimbus-cqrs/eventsourcingdb';
18
+ *
19
+ * export const ticketsProjection: EventConsumer = {
20
+ * name: 'ticketing.tickets',
21
+ * handles: (event) => event.type.startsWith('at.example.ticketing.ticket.'),
22
+ * handle: async (event) => {
23
+ * const ticket = ticketEventSchema.parse(event);
24
+ * await ticketsRepository.apply(ticket);
25
+ * },
26
+ * };
27
+ * ```
28
+ */
29
+ export type EventConsumer = {
30
+ /**
31
+ * The checkpoint key. It has to be unique across the whole application,
32
+ * not just within one observer, because checkpoint stores key on the
33
+ * consumer name alone. It also has to stay stable: renaming a consumer
34
+ * makes it replay the subject from the beginning.
35
+ */
36
+ readonly name: string;
37
+ /**
38
+ * Whether the consumer handles the given event. Events it does not
39
+ * handle still advance its checkpoint, so the position stays
40
+ * contiguous.
41
+ *
42
+ * @param event - The observed event, mapped to a Nimbus event.
43
+ */
44
+ readonly handles: (event: Event) => boolean;
45
+ /**
46
+ * Handles one event. A thrown error holds the consumer's checkpoint
47
+ * while its siblings advance; the observer retries in place and halts
48
+ * the consumer once the handler retries are exhausted.
49
+ *
50
+ * @param event - The observed event, mapped to a Nimbus event.
51
+ * @param raw - The original EventSourcingDB event.
52
+ */
53
+ readonly handle: (event: Event, raw: EventSourcingDBEvent) => Promise<void>;
54
+ /**
55
+ * Names of consumers on the same observer this one reads from. They
56
+ * have to be declared before this consumer. When a dependency fails on
57
+ * an event, this consumer holds its position as well, so it never
58
+ * checkpoints past data its dependency has not written yet. When a
59
+ * dependency is halted, this consumer is halted too.
60
+ *
61
+ * A consumer that starts from its checkpoint must not depend on one
62
+ * that starts from the head, since the latter never built state for
63
+ * older events.
64
+ */
65
+ readonly dependsOn?: readonly string[];
66
+ /**
67
+ * Where the consumer starts on every start of the observer.
68
+ *
69
+ * - `checkpoint` (default): resumes after its stored checkpoint, or
70
+ * from the beginning of the subject when it has none.
71
+ * - `head`: starts at the newest event of the subject, ignoring its
72
+ * stored checkpoint. Events written while the process was down are
73
+ * never delivered. Use this for live-only consumers such as pushing
74
+ * to connected clients or invalidating in-memory caches. The
75
+ * checkpoint is still persisted for visibility, but it has no effect
76
+ * on where the consumer resumes, so resetting it does nothing.
77
+ */
78
+ readonly startFrom?: 'checkpoint' | 'head';
79
+ };
80
+ /**
81
+ * The runtime state of one {@link EventConsumer}.
82
+ *
83
+ * @property {string} name - The consumer name.
84
+ * @property {string | null} position - The id of the last event the consumer finished, `null` before its first.
85
+ * @property {boolean} halted - Whether the consumer gave up for the rest of the process lifetime.
86
+ * @property {CheckpointFailure} [failure] - The most recent failure, from this run or loaded from the checkpoint store.
87
+ */
88
+ export type ConsumerStatus = {
89
+ name: string;
90
+ position: string | null;
91
+ halted: boolean;
92
+ failure?: CheckpointFailure;
93
+ };
94
+ //# sourceMappingURL=eventConsumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventConsumer.d.ts","sourceRoot":"","sources":["../../src/lib/eventConsumer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;IAC5C;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;CAC9C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC/B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=eventConsumer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventConsumer.js","sourceRoot":"","sources":["../../src/lib/eventConsumer.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import { type Event } from '@nimbus-cqrs/core';
2
- import type { Event as EventSourcingDBEvent, EventCandidate } from 'eventsourcingdb';
2
+ import type { EventCandidate, Event as EventSourcingDBEvent } from 'eventsourcingdb';
3
3
  /**
4
4
  * Metadata that Nimbus attaches to events stored in EventSourcingDB
5
5
  * to preserve correlation and schema information.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventMapping.d.ts","sourceRoot":"","sources":["../../src/lib/eventMapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,KAAK,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACR,cAAc,EACd,KAAK,IAAI,oBAAoB,EAChC,MAAM,iBAAiB,CAAC;AAGzB;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,mBAAmB,CAAC;CACnC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,OAAO,KAAG,IAAI,IAAI,SAOnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0CAA0C,GACnD,OAAO,KAAK,EACZ,cAAc,MAAM,EACpB,aAAa,MAAM,KACpB,cAeF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,SAAS,KAAK,EAClE,sBAAsB,oBAAoB,KAC3C,MAwBF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { createEvent, } from '@nimbus-cqrs/core';
2
- import { ulid } from '../deps/jsr.io/@std/ulid/1.0.0/mod.js';
2
+ import { ulid } from 'ulid';
3
3
  /**
4
4
  * Type guard that checks whether the given value conforms to the {@link EventData} structure
5
5
  * by verifying the presence of both `payload` and `nimbusMeta` properties.
@@ -69,3 +69,4 @@ export const eventSourcingDBEventToNimbusEvent = (eventSourcingDBEvent) => {
69
69
  ...(dataschema && { dataschema: dataschema }),
70
70
  });
71
71
  };
72
+ //# sourceMappingURL=eventMapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventMapping.js","sourceRoot":"","sources":["../../src/lib/eventMapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,WAAW,GAEd,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA0B5B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAa,EAAqB,EAAE;IAC5D,OAAO,CACH,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,SAAS,IAAI,IAAI;QACjB,YAAY,IAAI,IAAI,CACvB,CAAC;AACN,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAAG,CACtD,KAAY,EACZ,WAAoB,EACpB,UAAmB,EACL,EAAE;IAChB,OAAO;QACH,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE;YACF,OAAO,EAAE,KAAK,CAAC,IAAI;YACnB,UAAU,EAAE;gBACR,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;aAC5D;SACJ;QACD,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;QAChD,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;KAChD,CAAC;AACN,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC7C,oBAA0C,EACpC,EAAE;IACR,IAAI,IAA6B,CAAC;IAClC,IAAI,aAAqB,CAAC;IAC1B,IAAI,UAA8B,CAAC;IAEnC,IAAI,WAAW,CAAC,oBAAoB,CAA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