@kronos-ts/messaging 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.
- package/dist/command-bus.d.ts +30 -0
- package/dist/command-bus.d.ts.map +1 -0
- package/dist/command-bus.js +2 -0
- package/dist/command-bus.js.map +1 -0
- package/dist/command-handler.d.ts +58 -0
- package/dist/command-handler.d.ts.map +1 -0
- package/dist/command-handler.js +12 -0
- package/dist/command-handler.js.map +1 -0
- package/dist/command-handling-module.d.ts +53 -0
- package/dist/command-handling-module.d.ts.map +1 -0
- package/dist/command-handling-module.js +130 -0
- package/dist/command-handling-module.js.map +1 -0
- package/dist/correlation-data.d.ts +79 -0
- package/dist/correlation-data.d.ts.map +1 -0
- package/dist/correlation-data.js +133 -0
- package/dist/correlation-data.js.map +1 -0
- package/dist/dead-letter-queue.d.ts +134 -0
- package/dist/dead-letter-queue.d.ts.map +1 -0
- package/dist/dead-letter-queue.js +176 -0
- package/dist/dead-letter-queue.js.map +1 -0
- package/dist/dead-lettering-handler.d.ts +42 -0
- package/dist/dead-lettering-handler.d.ts.map +1 -0
- package/dist/dead-lettering-handler.js +67 -0
- package/dist/dead-lettering-handler.js.map +1 -0
- package/dist/descriptor.d.ts +135 -0
- package/dist/descriptor.d.ts.map +1 -0
- package/dist/descriptor.js +36 -0
- package/dist/descriptor.js.map +1 -0
- package/dist/emit-update.d.ts +22 -0
- package/dist/emit-update.d.ts.map +1 -0
- package/dist/emit-update.js +23 -0
- package/dist/emit-update.js.map +1 -0
- package/dist/event-bus.d.ts +29 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +22 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/event-criteria.d.ts +87 -0
- package/dist/event-criteria.d.ts.map +1 -0
- package/dist/event-criteria.js +90 -0
- package/dist/event-criteria.js.map +1 -0
- package/dist/event-gateway.d.ts +19 -0
- package/dist/event-gateway.d.ts.map +1 -0
- package/dist/event-gateway.js +22 -0
- package/dist/event-gateway.js.map +1 -0
- package/dist/event-handler.d.ts +30 -0
- package/dist/event-handler.d.ts.map +1 -0
- package/dist/event-handler.js +18 -0
- package/dist/event-handler.js.map +1 -0
- package/dist/event-processor-builder.d.ts +148 -0
- package/dist/event-processor-builder.d.ts.map +1 -0
- package/dist/event-processor-builder.js +175 -0
- package/dist/event-processor-builder.js.map +1 -0
- package/dist/event-processor.d.ts +10 -0
- package/dist/event-processor.d.ts.map +1 -0
- package/dist/event-processor.js +2 -0
- package/dist/event-processor.js.map +1 -0
- package/dist/event-sink.d.ts +23 -0
- package/dist/event-sink.d.ts.map +1 -0
- package/dist/event-sink.js +2 -0
- package/dist/event-sink.js.map +1 -0
- package/dist/event-source.d.ts +98 -0
- package/dist/event-source.d.ts.map +1 -0
- package/dist/event-source.js +191 -0
- package/dist/event-source.js.map +1 -0
- package/dist/gateway.d.ts +68 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +62 -0
- package/dist/gateway.js.map +1 -0
- package/dist/handler-enhancer.d.ts +53 -0
- package/dist/handler-enhancer.d.ts.map +1 -0
- package/dist/handler-enhancer.js +17 -0
- package/dist/handler-enhancer.js.map +1 -0
- package/dist/handler.d.ts +51 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +26 -0
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +103 -0
- package/dist/index.js.map +1 -0
- package/dist/intercepting-command-bus.d.ts +17 -0
- package/dist/intercepting-command-bus.d.ts.map +1 -0
- package/dist/intercepting-command-bus.js +54 -0
- package/dist/intercepting-command-bus.js.map +1 -0
- package/dist/intercepting-event-bus.d.ts +8 -0
- package/dist/intercepting-event-bus.d.ts.map +1 -0
- package/dist/intercepting-event-bus.js +22 -0
- package/dist/intercepting-event-bus.js.map +1 -0
- package/dist/intercepting-query-bus.d.ts +17 -0
- package/dist/intercepting-query-bus.d.ts.map +1 -0
- package/dist/intercepting-query-bus.js +68 -0
- package/dist/intercepting-query-bus.js.map +1 -0
- package/dist/interceptor.d.ts +46 -0
- package/dist/interceptor.d.ts.map +1 -0
- package/dist/interceptor.js +2 -0
- package/dist/interceptor.js.map +1 -0
- package/dist/message-monitor-registry.d.ts +28 -0
- package/dist/message-monitor-registry.d.ts.map +1 -0
- package/dist/message-monitor-registry.js +37 -0
- package/dist/message-monitor-registry.js.map +1 -0
- package/dist/message-monitor.d.ts +36 -0
- package/dist/message-monitor.d.ts.map +1 -0
- package/dist/message-monitor.js +39 -0
- package/dist/message-monitor.js.map +1 -0
- package/dist/message.d.ts +42 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +2 -0
- package/dist/message.js.map +1 -0
- package/dist/processing-state.d.ts +115 -0
- package/dist/processing-state.d.ts.map +1 -0
- package/dist/processing-state.js +205 -0
- package/dist/processing-state.js.map +1 -0
- package/dist/processor-configuration.d.ts +51 -0
- package/dist/processor-configuration.d.ts.map +1 -0
- package/dist/processor-configuration.js +2 -0
- package/dist/processor-configuration.js.map +1 -0
- package/dist/query-bus.d.ts +51 -0
- package/dist/query-bus.d.ts.map +1 -0
- package/dist/query-bus.js +2 -0
- package/dist/query-bus.js.map +1 -0
- package/dist/query-handler.d.ts +35 -0
- package/dist/query-handler.d.ts.map +1 -0
- package/dist/query-handler.js +19 -0
- package/dist/query-handler.js.map +1 -0
- package/dist/query-handling-module.d.ts +24 -0
- package/dist/query-handling-module.d.ts.map +1 -0
- package/dist/query-handling-module.js +32 -0
- package/dist/query-handling-module.js.map +1 -0
- package/dist/replay-token.d.ts +31 -0
- package/dist/replay-token.d.ts.map +1 -0
- package/dist/replay-token.js +37 -0
- package/dist/replay-token.js.map +1 -0
- package/dist/retrying-command-bus.d.ts +32 -0
- package/dist/retrying-command-bus.d.ts.map +1 -0
- package/dist/retrying-command-bus.js +58 -0
- package/dist/retrying-command-bus.js.map +1 -0
- package/dist/routing-strategy.d.ts +30 -0
- package/dist/routing-strategy.d.ts.map +1 -0
- package/dist/routing-strategy.js +37 -0
- package/dist/routing-strategy.js.map +1 -0
- package/dist/segment.d.ts +72 -0
- package/dist/segment.d.ts.map +1 -0
- package/dist/segment.js +103 -0
- package/dist/segment.js.map +1 -0
- package/dist/send.d.ts +28 -0
- package/dist/send.d.ts.map +1 -0
- package/dist/send.js +36 -0
- package/dist/send.js.map +1 -0
- package/dist/serializer.d.ts +40 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +90 -0
- package/dist/serializer.js.map +1 -0
- package/dist/simple-command-bus.d.ts +23 -0
- package/dist/simple-command-bus.d.ts.map +1 -0
- package/dist/simple-command-bus.js +49 -0
- package/dist/simple-command-bus.js.map +1 -0
- package/dist/simple-query-bus.d.ts +16 -0
- package/dist/simple-query-bus.d.ts.map +1 -0
- package/dist/simple-query-bus.js +122 -0
- package/dist/simple-query-bus.js.map +1 -0
- package/dist/span-factory.d.ts +58 -0
- package/dist/span-factory.d.ts.map +1 -0
- package/dist/span-factory.js +19 -0
- package/dist/span-factory.js.map +1 -0
- package/dist/streaming-event-processor.d.ts +65 -0
- package/dist/streaming-event-processor.d.ts.map +1 -0
- package/dist/streaming-event-processor.js +239 -0
- package/dist/streaming-event-processor.js.map +1 -0
- package/dist/subscribing-event-processor.d.ts +57 -0
- package/dist/subscribing-event-processor.d.ts.map +1 -0
- package/dist/subscribing-event-processor.js +100 -0
- package/dist/subscribing-event-processor.js.map +1 -0
- package/dist/subscription-query.d.ts +63 -0
- package/dist/subscription-query.d.ts.map +1 -0
- package/dist/subscription-query.js +119 -0
- package/dist/subscription-query.js.map +1 -0
- package/dist/token-store.d.ts +83 -0
- package/dist/token-store.d.ts.map +1 -0
- package/dist/token-store.js +112 -0
- package/dist/token-store.js.map +1 -0
- package/dist/tracing-command-bus.d.ts +16 -0
- package/dist/tracing-command-bus.d.ts.map +1 -0
- package/dist/tracing-command-bus.js +44 -0
- package/dist/tracing-command-bus.js.map +1 -0
- package/dist/tracing-handler-enhancer.d.ts +11 -0
- package/dist/tracing-handler-enhancer.d.ts.map +1 -0
- package/dist/tracing-handler-enhancer.js +27 -0
- package/dist/tracing-handler-enhancer.js.map +1 -0
- package/dist/tracking-event-processor.d.ts +72 -0
- package/dist/tracking-event-processor.d.ts.map +1 -0
- package/dist/tracking-event-processor.js +223 -0
- package/dist/tracking-event-processor.js.map +1 -0
- package/dist/tracking-token.d.ts +120 -0
- package/dist/tracking-token.d.ts.map +1 -0
- package/dist/tracking-token.js +132 -0
- package/dist/tracking-token.js.map +1 -0
- package/dist/transaction.d.ts +60 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +74 -0
- package/dist/transaction.js.map +1 -0
- package/dist/unit-of-work.d.ts +41 -0
- package/dist/unit-of-work.d.ts.map +1 -0
- package/dist/unit-of-work.js +96 -0
- package/dist/unit-of-work.js.map +1 -0
- package/dist/upcaster.d.ts +91 -0
- package/dist/upcaster.d.ts.map +1 -0
- package/dist/upcaster.js +114 -0
- package/dist/upcaster.js.map +1 -0
- package/dist/with-namespace.d.ts +59 -0
- package/dist/with-namespace.d.ts.map +1 -0
- package/dist/with-namespace.js +42 -0
- package/dist/with-namespace.js.map +1 -0
- package/package.json +65 -0
- package/src/command-bus.ts +34 -0
- package/src/command-handler.ts +116 -0
- package/src/command-handling-module.ts +183 -0
- package/src/correlation-data.ts +169 -0
- package/src/dead-letter-queue.ts +330 -0
- package/src/dead-lettering-handler.ts +109 -0
- package/src/descriptor.ts +176 -0
- package/src/emit-update.ts +35 -0
- package/src/event-bus.ts +45 -0
- package/src/event-criteria.ts +141 -0
- package/src/event-gateway.ts +42 -0
- package/src/event-handler.ts +44 -0
- package/src/event-processor-builder.ts +246 -0
- package/src/event-processor.ts +9 -0
- package/src/event-sink.ts +23 -0
- package/src/event-source.ts +301 -0
- package/src/gateway.ts +144 -0
- package/src/handler-enhancer.ts +70 -0
- package/src/handler.ts +133 -0
- package/src/index.ts +356 -0
- package/src/intercepting-command-bus.ts +73 -0
- package/src/intercepting-event-bus.ts +29 -0
- package/src/intercepting-query-bus.ts +104 -0
- package/src/interceptor.ts +48 -0
- package/src/message-monitor-registry.ts +64 -0
- package/src/message-monitor.ts +68 -0
- package/src/message.ts +41 -0
- package/src/processing-state.ts +258 -0
- package/src/processor-configuration.ts +59 -0
- package/src/query-bus.ts +69 -0
- package/src/query-handler.ts +49 -0
- package/src/query-handling-module.ts +44 -0
- package/src/replay-token.ts +53 -0
- package/src/retrying-command-bus.ts +80 -0
- package/src/routing-strategy.ts +59 -0
- package/src/segment.ts +136 -0
- package/src/send.ts +44 -0
- package/src/serializer.ts +122 -0
- package/src/simple-command-bus.ts +59 -0
- package/src/simple-query-bus.ts +158 -0
- package/src/span-factory.ts +81 -0
- package/src/streaming-event-processor.ts +351 -0
- package/src/subscribing-event-processor.ts +169 -0
- package/src/subscription-query.ts +173 -0
- package/src/token-store.ts +211 -0
- package/src/tracing-command-bus.ts +52 -0
- package/src/tracing-handler-enhancer.ts +34 -0
- package/src/tracking-event-processor.ts +336 -0
- package/src/tracking-token.ts +231 -0
- package/src/transaction.ts +98 -0
- package/src/unit-of-work.ts +138 -0
- package/src/upcaster.ts +174 -0
- package/src/with-namespace.ts +75 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
/**
|
|
3
|
+
* Lifecycle phases for message processing, ordered by execution priority.
|
|
4
|
+
*
|
|
5
|
+
* Phases execute in ascending order. Actions within the same phase
|
|
6
|
+
* execute in registration order. Actions registered during execution
|
|
7
|
+
* (e.g., onPrepareCommit from a handler) are picked up when their
|
|
8
|
+
* phase comes.
|
|
9
|
+
*
|
|
10
|
+
* Plan 03-04 (CTX-04 / D-34): Phase enum relocated here from the
|
|
11
|
+
* deleted processing-context.ts. The numeric values are stable —
|
|
12
|
+
* external code (handler enhancers, processors) compares phase numbers.
|
|
13
|
+
*/
|
|
14
|
+
export const Phase = {
|
|
15
|
+
/** Setup before handler invocation (e.g., transaction start). */
|
|
16
|
+
PRE_INVOCATION: -10000,
|
|
17
|
+
/** Actual handler execution. */
|
|
18
|
+
INVOCATION: 0,
|
|
19
|
+
/** Cleanup after handler, before commit. */
|
|
20
|
+
POST_INVOCATION: 10000,
|
|
21
|
+
/** Prepare for commit (e.g., event store flush, token store). */
|
|
22
|
+
PREPARE_COMMIT: 20000,
|
|
23
|
+
/** Actual commit (e.g., database transaction commit). */
|
|
24
|
+
COMMIT: 30000,
|
|
25
|
+
/** Post-commit notifications (e.g., subscription query updates). */
|
|
26
|
+
AFTER_COMMIT: 40000,
|
|
27
|
+
};
|
|
28
|
+
// D-04: Framework-wide ALS instance. Exported (deep-path only per D-05).
|
|
29
|
+
export const processingStateStorage = new AsyncLocalStorage();
|
|
30
|
+
// D-10: stable error name.
|
|
31
|
+
export class NoActiveUnitOfWork extends Error {
|
|
32
|
+
constructor(message = "No active UnitOfWork: accessor called outside processingStateStorage.run()") {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "NoActiveUnitOfWork";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Plan 04-01 (HDL-02 / D-43): thrown by mutating helpers (append, send, emitUpdate)
|
|
39
|
+
* when called outside the INVOCATION phase. Distinct class (not a NoActiveUnitOfWork
|
|
40
|
+
* subclass) — a UoW IS active, but it's in the wrong phase. Catches the real bug
|
|
41
|
+
* pattern of mutations from lifecycle hooks (onCommit, onPrepareCommit, etc.).
|
|
42
|
+
*/
|
|
43
|
+
export class WrongUoWPhase extends Error {
|
|
44
|
+
currentPhase;
|
|
45
|
+
constructor(currentPhase) {
|
|
46
|
+
super(`Mutating helper called during phase ${currentPhase} — must be called during INVOCATION (${Phase.INVOCATION}) only. ` +
|
|
47
|
+
`Do not call append/send/emitUpdate from lifecycle hooks (onPrepareCommit, onCommit, onAfterCommit, onError, whenComplete).`);
|
|
48
|
+
this.name = "WrongUoWPhase";
|
|
49
|
+
this.currentPhase = currentPhase;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function requireState() {
|
|
53
|
+
const state = processingStateStorage.getStore();
|
|
54
|
+
if (state === undefined)
|
|
55
|
+
throw new NoActiveUnitOfWork();
|
|
56
|
+
return state;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Plan 04-01 (HDL-02 / D-43): mutator guard. Throws NoActiveUnitOfWork outside a UoW;
|
|
60
|
+
* throws WrongUoWPhase when active phase != INVOCATION; otherwise returns the state.
|
|
61
|
+
* Used by append (eventsourcing), send + emitUpdate (messaging).
|
|
62
|
+
* Internal — NOT exported from index.ts barrel. Consumed via deep-path import.
|
|
63
|
+
*/
|
|
64
|
+
export function requireInvocationPhase() {
|
|
65
|
+
const state = processingStateStorage.getStore();
|
|
66
|
+
if (state === undefined)
|
|
67
|
+
throw new NoActiveUnitOfWork();
|
|
68
|
+
if (state.currentPhase !== Phase.INVOCATION)
|
|
69
|
+
throw new WrongUoWPhase(state.currentPhase);
|
|
70
|
+
return state;
|
|
71
|
+
}
|
|
72
|
+
// ── Resource accessors ──────────────────────────────────────────────────
|
|
73
|
+
export function getResource(key) {
|
|
74
|
+
const state = requireState();
|
|
75
|
+
return state.resources.get(key.symbol);
|
|
76
|
+
}
|
|
77
|
+
export function setResource(key, value) {
|
|
78
|
+
const state = requireState();
|
|
79
|
+
const previous = state.resources.get(key.symbol);
|
|
80
|
+
state.resources.set(key.symbol, value);
|
|
81
|
+
return previous;
|
|
82
|
+
}
|
|
83
|
+
export function computeIfAbsent(key, supplier) {
|
|
84
|
+
const state = requireState();
|
|
85
|
+
const existing = state.resources.get(key.symbol);
|
|
86
|
+
if (existing !== undefined)
|
|
87
|
+
return existing;
|
|
88
|
+
const value = supplier();
|
|
89
|
+
state.resources.set(key.symbol, value);
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
export function removeResource(key) {
|
|
93
|
+
const state = requireState();
|
|
94
|
+
const previous = state.resources.get(key.symbol);
|
|
95
|
+
state.resources.delete(key.symbol);
|
|
96
|
+
return previous;
|
|
97
|
+
}
|
|
98
|
+
export function hasResource(key) {
|
|
99
|
+
const state = requireState();
|
|
100
|
+
return state.resources.has(key.symbol);
|
|
101
|
+
}
|
|
102
|
+
export function updateResource(key, updater) {
|
|
103
|
+
const state = requireState();
|
|
104
|
+
const current = state.resources.get(key.symbol);
|
|
105
|
+
const updated = updater(current);
|
|
106
|
+
state.resources.set(key.symbol, updated);
|
|
107
|
+
return updated;
|
|
108
|
+
}
|
|
109
|
+
// ── Lifecycle registration ──────────────────────────────────────────────
|
|
110
|
+
export function registerPhaseAction(phase, action) {
|
|
111
|
+
const state = requireState();
|
|
112
|
+
let bucket = state.phaseActions.get(phase);
|
|
113
|
+
if (!bucket) {
|
|
114
|
+
bucket = [];
|
|
115
|
+
state.phaseActions.set(phase, bucket);
|
|
116
|
+
}
|
|
117
|
+
bucket.push(action);
|
|
118
|
+
}
|
|
119
|
+
export function registerErrorHandler(handler) {
|
|
120
|
+
const state = requireState();
|
|
121
|
+
state.errorHandlers.push(handler);
|
|
122
|
+
}
|
|
123
|
+
export function registerCompleteHandler(handler) {
|
|
124
|
+
const state = requireState();
|
|
125
|
+
state.completeHandlers.push(handler);
|
|
126
|
+
}
|
|
127
|
+
// ── Lifecycle accessors (CTX-03, D-30) ──────────────────────────────────
|
|
128
|
+
//
|
|
129
|
+
// Module-level equivalents of ctx.on / ctx.onError / ctx.whenComplete /
|
|
130
|
+
// ctx.onPrepareCommit / ctx.onCommit / ctx.onAfterCommit. Thin wrappers
|
|
131
|
+
// over the Phase 1 accessors (registerPhaseAction / registerErrorHandler /
|
|
132
|
+
// registerCompleteHandler). Same fail-fast contract (D-31): throw
|
|
133
|
+
// NoActiveUnitOfWork outside an active processingStateStorage.run.
|
|
134
|
+
export function on(phase, action) {
|
|
135
|
+
registerPhaseAction(phase, action);
|
|
136
|
+
}
|
|
137
|
+
export function onPrepareCommit(action) {
|
|
138
|
+
registerPhaseAction(Phase.PREPARE_COMMIT, action);
|
|
139
|
+
}
|
|
140
|
+
export function onCommit(action) {
|
|
141
|
+
registerPhaseAction(Phase.COMMIT, action);
|
|
142
|
+
}
|
|
143
|
+
export function onAfterCommit(action) {
|
|
144
|
+
registerPhaseAction(Phase.AFTER_COMMIT, action);
|
|
145
|
+
}
|
|
146
|
+
export function onError(handler) {
|
|
147
|
+
registerErrorHandler(handler);
|
|
148
|
+
}
|
|
149
|
+
export function whenComplete(handler) {
|
|
150
|
+
registerCompleteHandler(handler);
|
|
151
|
+
}
|
|
152
|
+
// ── withOverride (D-07..D-09) ──────────────────────────────────────────
|
|
153
|
+
/**
|
|
154
|
+
* Run `fn` in a nested processingStateStorage context where `key` resolves to `value`.
|
|
155
|
+
*
|
|
156
|
+
* Only the `resources` Map is forked (D-08). All other fields — phaseActions,
|
|
157
|
+
* errorHandlers, completeHandlers, status, currentPhase, metadata — are SHARED
|
|
158
|
+
* references to the parent state. Registering a phase action or error handler
|
|
159
|
+
* inside `fn` targets the parent's lifecycle.
|
|
160
|
+
*
|
|
161
|
+
* After `fn` resolves, the parent's resources are unchanged (D-09) — nested
|
|
162
|
+
* `storage.run()` naturally pops the forked state.
|
|
163
|
+
*
|
|
164
|
+
* Throws NoActiveUnitOfWork if called outside an existing processingStateStorage.run().
|
|
165
|
+
*/
|
|
166
|
+
export function withOverride(key, value, fn) {
|
|
167
|
+
const parent = requireState();
|
|
168
|
+
const forkedResources = new Map(parent.resources);
|
|
169
|
+
forkedResources.set(key.symbol, value);
|
|
170
|
+
const forkedState = {
|
|
171
|
+
resources: forkedResources,
|
|
172
|
+
// SHARED references to parent (D-08):
|
|
173
|
+
phaseActions: parent.phaseActions,
|
|
174
|
+
errorHandlers: parent.errorHandlers,
|
|
175
|
+
completeHandlers: parent.completeHandlers,
|
|
176
|
+
status: parent.status,
|
|
177
|
+
currentPhase: parent.currentPhase,
|
|
178
|
+
metadata: parent.metadata,
|
|
179
|
+
};
|
|
180
|
+
return processingStateStorage.run(forkedState, fn);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* INTERNAL — used by UnitOfWork to construct the initial state passed to
|
|
184
|
+
* processingStateStorage.run(). The InternalProcessingState type is intentionally
|
|
185
|
+
* non-exported (D-13); this factory is the sanctioned construction point.
|
|
186
|
+
* Deep-path import only; NOT re-exported from the package barrel (D-05).
|
|
187
|
+
*
|
|
188
|
+
* Return type is intentionally INFERRED (no `: InternalProcessingState` annotation).
|
|
189
|
+
* Annotating the return type with a non-exported name produces TS4023 under
|
|
190
|
+
* `declaration: true` / `isolatedDeclarations`, breaking the package build.
|
|
191
|
+
* Inference preserves D-13 (the type remains non-exported) while allowing `.d.ts`
|
|
192
|
+
* emission.
|
|
193
|
+
*/
|
|
194
|
+
export function createInitialProcessingState(metadata) {
|
|
195
|
+
return {
|
|
196
|
+
resources: new Map(),
|
|
197
|
+
phaseActions: new Map(),
|
|
198
|
+
errorHandlers: [],
|
|
199
|
+
completeHandlers: [],
|
|
200
|
+
currentPhase: null,
|
|
201
|
+
status: "not_started",
|
|
202
|
+
metadata,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=processing-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processing-state.js","sourceRoot":"","sources":["../src/processing-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGpD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,iEAAiE;IACjE,cAAc,EAAE,CAAC,KAAK;IACtB,gCAAgC;IAChC,UAAU,EAAE,CAAC;IACb,4CAA4C;IAC5C,eAAe,EAAE,KAAK;IACtB,iEAAiE;IACjE,cAAc,EAAE,KAAK;IACrB,yDAAyD;IACzD,MAAM,EAAE,KAAK;IACb,oEAAoE;IACpE,YAAY,EAAE,KAAK;CACX,CAAA;AAqBV,yEAAyE;AACzE,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,iBAAiB,EA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AI,GAAG,EAA6B;QAClD,aAAa,EAAE,EAAoB;QACnC,gBAAgB,EAAE,EAAuB;QACzC,YAAY,EAAE,IAAyB;QACvC,MAAM,EAAE,aAAuB;QAC/B,QAAQ;KACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { TokenStore } from "./token-store.js";
|
|
2
|
+
import type { UoWRunner } from "./unit-of-work.js";
|
|
3
|
+
import type { EventProcessingErrorHandler } from "./tracking-event-processor.js";
|
|
4
|
+
import type { SequencedDeadLetterQueue } from "./dead-letter-queue.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for an individual event processor.
|
|
7
|
+
*
|
|
8
|
+
* All properties are optional — when not specified, the processor
|
|
9
|
+
* uses the global defaults from the messaging configurer.
|
|
10
|
+
*
|
|
11
|
+
* This enables per-processor tuning: different processors can have
|
|
12
|
+
* different batch sizes, token stores, error handlers, etc.
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* messagingConfigurer({
|
|
16
|
+
* eventHandlers: [courseProjection],
|
|
17
|
+
* processorConfiguration: {
|
|
18
|
+
* "course-projection": {
|
|
19
|
+
* batchSize: 50,
|
|
20
|
+
* initialSegmentCount: 4,
|
|
21
|
+
* errorHandler: propagatingErrorHandler(),
|
|
22
|
+
* },
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `trackingProcessor()` / `subscribingProcessor()` builders
|
|
29
|
+
* with `registerEventProcessor()` instead.
|
|
30
|
+
*/
|
|
31
|
+
export interface ProcessorConfiguration {
|
|
32
|
+
/** Events per transaction. Default: 100 */
|
|
33
|
+
batchSize?: number;
|
|
34
|
+
/** Number of segments to create on first startup. Default: 1 */
|
|
35
|
+
initialSegmentCount?: number;
|
|
36
|
+
/** Polling interval in ms (for TrackingEventProcessor). Default: 500 */
|
|
37
|
+
pollingIntervalMs?: number;
|
|
38
|
+
/** Override the token store for this processor. */
|
|
39
|
+
tokenStore?: TokenStore;
|
|
40
|
+
/** Override the UnitOfWork runner for this processor. */
|
|
41
|
+
unitOfWorkRunner?: UoWRunner;
|
|
42
|
+
/** Override the error handler for this processor. */
|
|
43
|
+
errorHandler?: EventProcessingErrorHandler;
|
|
44
|
+
/** Dead letter queue for this processor. */
|
|
45
|
+
deadLetterQueue?: SequencedDeadLetterQueue;
|
|
46
|
+
/** How often to extend claims in ms. Default: 5000 */
|
|
47
|
+
claimExtensionThresholdMs?: number;
|
|
48
|
+
/** How often to attempt claiming new segments in ms. Default: 5000 */
|
|
49
|
+
tokenClaimIntervalMs?: number;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=processor-configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor-configuration.d.ts","sourceRoot":"","sources":["../src/processor-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAChF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,gEAAgE;IAChE,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B,mDAAmD;IACnD,UAAU,CAAC,EAAE,UAAU,CAAA;IAEvB,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAE5B,qDAAqD;IACrD,YAAY,CAAC,EAAE,2BAA2B,CAAA;IAE1C,4CAA4C;IAC5C,eAAe,CAAC,EAAE,wBAAwB,CAAA;IAE1C,sDAAsD;IACtD,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAElC,sEAAsE;IACtE,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor-configuration.js","sourceRoot":"","sources":["../src/processor-configuration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { QueryMessage } from "./message.js";
|
|
2
|
+
import type { SubscriptionQueryResult } from "./subscription-query.js";
|
|
3
|
+
/**
|
|
4
|
+
* The query bus — low-level infrastructure for dispatching query messages.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export interface QueryBus {
|
|
8
|
+
/**
|
|
9
|
+
* Dispatch a query message to its handler(s).
|
|
10
|
+
*
|
|
11
|
+
* The bus auto-nests via ALS (CTX-02): when called outside a UnitOfWork,
|
|
12
|
+
* `runInUoW` creates one; when called inside an active UoW (handler-internal
|
|
13
|
+
* re-dispatch), the active UoW is reused.
|
|
14
|
+
*/
|
|
15
|
+
query(message: QueryMessage): Promise<unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe a handler for the given query name.
|
|
18
|
+
*
|
|
19
|
+
* Plan 03-04 (CTX-04 / D-34): handler signature dropped its `ctx`
|
|
20
|
+
* parameter. The ProcessingContext type is gone.
|
|
21
|
+
*/
|
|
22
|
+
subscribe(queryName: string, handler: (message: QueryMessage) => Promise<unknown>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Start a subscription query — returns the initial result plus a stream
|
|
25
|
+
* of incremental updates.
|
|
26
|
+
*/
|
|
27
|
+
subscriptionQuery(message: QueryMessage, bufferSize?: number): SubscriptionQueryResult;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to updates only (no initial result).
|
|
30
|
+
* Returns an async iterable of update payloads.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
subscribeToUpdates(message: QueryMessage, bufferSize?: number): AsyncIterable<unknown> & {
|
|
34
|
+
close(): void;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Emit an update to all active subscription queries matching the filter.
|
|
38
|
+
* When called within an active UnitOfWork (detected via ALS), the update is
|
|
39
|
+
* deferred to AFTER_COMMIT.
|
|
40
|
+
*/
|
|
41
|
+
emitUpdate(queryName: string, filter: (queryPayload: unknown) => boolean, update: unknown): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Complete all subscription queries matching the filter.
|
|
44
|
+
*/
|
|
45
|
+
completeSubscription(queryName: string, filter?: (queryPayload: unknown) => boolean): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Complete all subscription queries matching the filter with an error.
|
|
48
|
+
*/
|
|
49
|
+
completeSubscriptionExceptionally(queryName: string, error: Error, filter?: (queryPayload: unknown) => boolean): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=query-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-bus.d.ts","sourceRoot":"","sources":["../src/query-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAEtE;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAE9C;;;;;OAKG;IACH,SAAS,CACP,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,GACnD,IAAI,CAAA;IAEP;;;OAGG;IACH,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAA;IAEtF;;;;OAIG;IACH,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG;QAAE,KAAK,IAAI,IAAI,CAAA;KAAE,CAAA;IAE1G;;;;OAIG;IACH,UAAU,CACR,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,EAC1C,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhB;;OAEG;IACH,oBAAoB,CAClB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,GAC1C,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhB;;OAEG;IACH,iCAAiC,CAC/B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,KAAK,EACZ,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,GAC1C,OAAO,CAAC,IAAI,CAAC,CAAA;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-bus.js","sourceRoot":"","sources":["../src/query-bus.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { Metadata } from "@kronos-ts/common";
|
|
3
|
+
import type { QueryDescriptor } from "./descriptor.js";
|
|
4
|
+
/**
|
|
5
|
+
* A registered singular query handler — pairs a query descriptor with its handler
|
|
6
|
+
* function. Mirrors {@link import("./command-handler.js").CommandHandlerDefinition}
|
|
7
|
+
* structurally so all three handler shapes (command / event / query) share the same
|
|
8
|
+
* pattern.
|
|
9
|
+
*
|
|
10
|
+
* Note: queries do NOT carry a result schema on the descriptor (see `QueryDescriptor`
|
|
11
|
+
* in `./descriptor.ts` — no `result` field used here). The result type `R` is
|
|
12
|
+
* inferred from the handler's return type.
|
|
13
|
+
*/
|
|
14
|
+
export interface QueryHandlerDefinition<Q extends z.ZodType = z.ZodType, R = unknown> {
|
|
15
|
+
readonly kind: "query-handler";
|
|
16
|
+
readonly descriptor: QueryDescriptor<Q, z.ZodType | undefined>;
|
|
17
|
+
readonly handler: (query: z.infer<Q>, metadata: Metadata) => Promise<R> | R;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Defines a singular query handler.
|
|
21
|
+
*
|
|
22
|
+
* ```
|
|
23
|
+
* const getCourseView = queryHandler(GetCourseView, async (q, metadata) => {
|
|
24
|
+
* const view = courseViews.get(q.courseId)
|
|
25
|
+
* if (!view) throw new Error("not found")
|
|
26
|
+
* return view
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Use with `app.queries(getCourseView, getAllCourses)`. Symmetric to
|
|
31
|
+
* {@link import("./command-handler.js").commandHandler} and
|
|
32
|
+
* {@link import("./event-handler.js").eventHandler}.
|
|
33
|
+
*/
|
|
34
|
+
export declare function queryHandler<Q extends z.ZodType, R>(descriptor: QueryDescriptor<Q, z.ZodType | undefined>, handler: (query: z.infer<Q>, metadata: Metadata) => Promise<R> | R): QueryHandlerDefinition<Q, R>;
|
|
35
|
+
//# sourceMappingURL=query-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-handler.d.ts","sourceRoot":"","sources":["../src/query-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAOtD;;;;;;;;;GASG;AACH,MAAM,WAAW,sBAAsB,CACrC,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAC/B,CAAC,GAAG,OAAO;IAEX,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;IAC9D,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;CAC5E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,EACjD,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,EACrD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GACjE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,CAE9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a singular query handler.
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* const getCourseView = queryHandler(GetCourseView, async (q, metadata) => {
|
|
6
|
+
* const view = courseViews.get(q.courseId)
|
|
7
|
+
* if (!view) throw new Error("not found")
|
|
8
|
+
* return view
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Use with `app.queries(getCourseView, getAllCourses)`. Symmetric to
|
|
13
|
+
* {@link import("./command-handler.js").commandHandler} and
|
|
14
|
+
* {@link import("./event-handler.js").eventHandler}.
|
|
15
|
+
*/
|
|
16
|
+
export function queryHandler(descriptor, handler) {
|
|
17
|
+
return { kind: "query-handler", descriptor, handler };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=query-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-handler.js","sourceRoot":"","sources":["../src/query-handler.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAqD,EACrD,OAAkE;IAElE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA;AACvD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { QueryHandlerDefinition } from "./query-handler.js";
|
|
2
|
+
import type { QueryBus } from "./query-bus.js";
|
|
3
|
+
import type { HandlerEnhancerDefinition } from "./handler-enhancer.js";
|
|
4
|
+
/**
|
|
5
|
+
* Function-style helper called by AppImpl.start() to subscribe query handlers
|
|
6
|
+
* natively, without the configurer's Module shape.
|
|
7
|
+
*
|
|
8
|
+
* Accepts a flat ReadonlyArray<QueryHandlerDefinition> (singular handler shape).
|
|
9
|
+
*
|
|
10
|
+
* Symmetric to registerCommandHandlersNatively — accepts an optional
|
|
11
|
+
* handlerEnhancer that wraps each query invocation so query handlers receive
|
|
12
|
+
* the same tracing / timing / cross-cutting treatment as command and event
|
|
13
|
+
* handlers. moduleName defaults to "queries" for HandlerMetadata.handlerGroup.
|
|
14
|
+
*
|
|
15
|
+
* Query handlers do NOT need a Configuration shim — queries don't append
|
|
16
|
+
* events, so no per-invocation ALS resource setup is required at query
|
|
17
|
+
* subscription level.
|
|
18
|
+
*/
|
|
19
|
+
export declare function registerQueryHandlersNatively(handlers: ReadonlyArray<QueryHandlerDefinition>, deps: {
|
|
20
|
+
queryBus: QueryBus;
|
|
21
|
+
handlerEnhancer?: HandlerEnhancerDefinition;
|
|
22
|
+
moduleName?: string;
|
|
23
|
+
}): void;
|
|
24
|
+
//# sourceMappingURL=query-handling-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-handling-module.d.ts","sourceRoot":"","sources":["../src/query-handling-module.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAEtE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,aAAa,CAAC,sBAAsB,CAAC,EAC/C,IAAI,EAAE;IACJ,QAAQ,EAAE,QAAQ,CAAA;IAClB,eAAe,CAAC,EAAE,yBAAyB,CAAA;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GACA,IAAI,CAeN"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { qualifiedNameToString } from "@kronos-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* Function-style helper called by AppImpl.start() to subscribe query handlers
|
|
4
|
+
* natively, without the configurer's Module shape.
|
|
5
|
+
*
|
|
6
|
+
* Accepts a flat ReadonlyArray<QueryHandlerDefinition> (singular handler shape).
|
|
7
|
+
*
|
|
8
|
+
* Symmetric to registerCommandHandlersNatively — accepts an optional
|
|
9
|
+
* handlerEnhancer that wraps each query invocation so query handlers receive
|
|
10
|
+
* the same tracing / timing / cross-cutting treatment as command and event
|
|
11
|
+
* handlers. moduleName defaults to "queries" for HandlerMetadata.handlerGroup.
|
|
12
|
+
*
|
|
13
|
+
* Query handlers do NOT need a Configuration shim — queries don't append
|
|
14
|
+
* events, so no per-invocation ALS resource setup is required at query
|
|
15
|
+
* subscription level.
|
|
16
|
+
*/
|
|
17
|
+
export function registerQueryHandlersNatively(handlers, deps) {
|
|
18
|
+
const moduleName = deps.moduleName ?? "queries";
|
|
19
|
+
for (const reg of handlers) {
|
|
20
|
+
const queryName = qualifiedNameToString(reg.descriptor.name);
|
|
21
|
+
let invocation = async (message) => reg.handler(message.payload, message.metadata);
|
|
22
|
+
if (deps.handlerEnhancer) {
|
|
23
|
+
invocation = deps.handlerEnhancer.wrapHandler(invocation, {
|
|
24
|
+
messageType: "query",
|
|
25
|
+
messageName: queryName,
|
|
26
|
+
handlerGroup: moduleName,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
deps.queryBus.subscribe(queryName, invocation);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=query-handling-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-handling-module.js","sourceRoot":"","sources":["../src/query-handling-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAMzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAC3C,QAA+C,EAC/C,IAIC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,SAAS,CAAA;IAC/C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QAC5D,IAAI,UAAU,GAAG,KAAK,EAAE,OAAqB,EAAE,EAAE,CAC/C,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;QAChD,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,UAAU,EAAE;gBACxD,WAAW,EAAE,OAAO;gBACpB,WAAW,EAAE,SAAS;gBACtB,YAAY,EAAE,UAAU;aACzB,CAAC,CAAA;QACJ,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports from tracking-token.ts plus the isReplay() helper.
|
|
3
|
+
*
|
|
4
|
+
* Plan 03-04 (CTX-04 / D-29): `isReplay()` is a no-arg permissive ALS read.
|
|
5
|
+
* It returns `false` when called outside an active UnitOfWork (replay-state
|
|
6
|
+
* has only ever been set by the tracking processor; absence == not replaying).
|
|
7
|
+
*/
|
|
8
|
+
import { type ResourceKey } from "@kronos-ts/common";
|
|
9
|
+
export { type TrackingToken, type GlobalSequenceToken, type ReplayToken, globalSequenceToken, replayToken, isReplayToken, isGlobalSequenceToken, advanceToken, isReplaying, unwrapToken, wasProcessedBeforeReset, } from "./tracking-token.js";
|
|
10
|
+
/** Resource key for storing replay state in the active UnitOfWork. */
|
|
11
|
+
export declare const REPLAY_STATE_KEY: ResourceKey<{
|
|
12
|
+
replaying: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if the current processing is a replay.
|
|
16
|
+
* Use this in event handlers to skip side effects during replay.
|
|
17
|
+
*
|
|
18
|
+
* Plan 03-04 (D-29): no-arg permissive ALS read. Returns `false` when called
|
|
19
|
+
* outside an active UnitOfWork.
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* on(OrderPlaced, async (event) => {
|
|
23
|
+
* await db.orders.insert(event)
|
|
24
|
+
* if (!isReplay()) {
|
|
25
|
+
* await sendConfirmationEmail(event.email)
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function isReplay(): boolean;
|
|
31
|
+
//# sourceMappingURL=replay-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-token.d.ts","sourceRoot":"","sources":["../src/replay-token.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAIjE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,uBAAuB,GACxB,MAAM,qBAAqB,CAAA;AAE5B,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CACrC,CAAA;AAE5B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAOlC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports from tracking-token.ts plus the isReplay() helper.
|
|
3
|
+
*
|
|
4
|
+
* Plan 03-04 (CTX-04 / D-29): `isReplay()` is a no-arg permissive ALS read.
|
|
5
|
+
* It returns `false` when called outside an active UnitOfWork (replay-state
|
|
6
|
+
* has only ever been set by the tracking processor; absence == not replaying).
|
|
7
|
+
*/
|
|
8
|
+
import { resourceKey } from "@kronos-ts/common";
|
|
9
|
+
import { processingStateStorage } from "./processing-state.js";
|
|
10
|
+
// Re-export token types and operations
|
|
11
|
+
export { globalSequenceToken, replayToken, isReplayToken, isGlobalSequenceToken, advanceToken, isReplaying, unwrapToken, wasProcessedBeforeReset, } from "./tracking-token.js";
|
|
12
|
+
/** Resource key for storing replay state in the active UnitOfWork. */
|
|
13
|
+
export const REPLAY_STATE_KEY = resourceKey("replayState");
|
|
14
|
+
/**
|
|
15
|
+
* Check if the current processing is a replay.
|
|
16
|
+
* Use this in event handlers to skip side effects during replay.
|
|
17
|
+
*
|
|
18
|
+
* Plan 03-04 (D-29): no-arg permissive ALS read. Returns `false` when called
|
|
19
|
+
* outside an active UnitOfWork.
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* on(OrderPlaced, async (event) => {
|
|
23
|
+
* await db.orders.insert(event)
|
|
24
|
+
* if (!isReplay()) {
|
|
25
|
+
* await sendConfirmationEmail(event.email)
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function isReplay() {
|
|
31
|
+
const state = processingStateStorage.getStore();
|
|
32
|
+
if (!state)
|
|
33
|
+
return false;
|
|
34
|
+
const replayState = state.resources.get(REPLAY_STATE_KEY.symbol);
|
|
35
|
+
return replayState?.replaying === true;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=replay-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-token.js","sourceRoot":"","sources":["../src/replay-token.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAE9D,uCAAuC;AACvC,OAAO,EAIL,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,uBAAuB,GACxB,MAAM,qBAAqB,CAAA;AAE5B,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAC3B,WAAW,CAAC,aAAa,CAAC,CAAA;AAE5B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,GAAG,sBAAsB,CAAC,QAAQ,EAAE,CAAA;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAElD,CAAA;IACb,OAAO,WAAW,EAAE,SAAS,KAAK,IAAI,CAAA;AACxC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CommandBus } from "./command-bus.js";
|
|
2
|
+
/**
|
|
3
|
+
* Determines whether a failed command dispatch should be retried.
|
|
4
|
+
*/
|
|
5
|
+
export interface RetryPolicy {
|
|
6
|
+
/**
|
|
7
|
+
* Returns the delay in ms before the next retry, or undefined to stop retrying.
|
|
8
|
+
* @param error The error from the previous attempt
|
|
9
|
+
* @param attempt The attempt number (0-based, so 0 = first failure)
|
|
10
|
+
*/
|
|
11
|
+
shouldRetry(error: unknown, attempt: number): number | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Retries on transient errors (like AppendConditionError) with exponential backoff.
|
|
15
|
+
* Non-transient errors are rethrown immediately.
|
|
16
|
+
*/
|
|
17
|
+
export declare function exponentialBackoffRetryPolicy(options?: {
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
initialDelayMs?: number;
|
|
20
|
+
isTransient?: (error: unknown) => boolean;
|
|
21
|
+
}): RetryPolicy;
|
|
22
|
+
/**
|
|
23
|
+
* A command bus decorator that retries failed dispatches based on a retry policy.
|
|
24
|
+
*
|
|
25
|
+
* When a command fails with a transient error (e.g., AppendConditionError from
|
|
26
|
+
* an optimistic concurrency conflict), the entire dispatch is retried. This means
|
|
27
|
+
* the handler re-sources state and re-makes its decision based on fresh data.
|
|
28
|
+
*
|
|
29
|
+
* Non-transient errors propagate immediately to the caller.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createRetryingCommandBus(delegate: CommandBus, policy: RetryPolicy): CommandBus;
|
|
32
|
+
//# sourceMappingURL=retrying-command-bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrying-command-bus.d.ts","sourceRoot":"","sources":["../src/retrying-command-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGlD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACjE;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,CAAC,EAAE;IACtD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAC1C,GAAG,WAAW,CAYd;AASD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,WAAW,GAClB,UAAU,CAuBZ"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retries on transient errors (like AppendConditionError) with exponential backoff.
|
|
3
|
+
* Non-transient errors are rethrown immediately.
|
|
4
|
+
*/
|
|
5
|
+
export function exponentialBackoffRetryPolicy(options) {
|
|
6
|
+
const maxRetries = options?.maxRetries ?? 5;
|
|
7
|
+
const initialDelayMs = options?.initialDelayMs ?? 10;
|
|
8
|
+
const isTransient = options?.isTransient ?? defaultIsTransient;
|
|
9
|
+
return {
|
|
10
|
+
shouldRetry(error, attempt) {
|
|
11
|
+
if (attempt >= maxRetries)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (!isTransient(error))
|
|
14
|
+
return undefined;
|
|
15
|
+
return initialDelayMs * Math.pow(2, attempt);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function defaultIsTransient(error) {
|
|
20
|
+
if (error instanceof Error) {
|
|
21
|
+
return error.name === "AppendConditionError";
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A command bus decorator that retries failed dispatches based on a retry policy.
|
|
27
|
+
*
|
|
28
|
+
* When a command fails with a transient error (e.g., AppendConditionError from
|
|
29
|
+
* an optimistic concurrency conflict), the entire dispatch is retried. This means
|
|
30
|
+
* the handler re-sources state and re-makes its decision based on fresh data.
|
|
31
|
+
*
|
|
32
|
+
* Non-transient errors propagate immediately to the caller.
|
|
33
|
+
*/
|
|
34
|
+
export function createRetryingCommandBus(delegate, policy) {
|
|
35
|
+
return {
|
|
36
|
+
async dispatch(message) {
|
|
37
|
+
let attempt = 0;
|
|
38
|
+
while (true) {
|
|
39
|
+
try {
|
|
40
|
+
return await delegate.dispatch(message);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const delay = policy.shouldRetry(error, attempt);
|
|
44
|
+
if (delay === undefined)
|
|
45
|
+
throw error;
|
|
46
|
+
attempt++;
|
|
47
|
+
if (delay > 0) {
|
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
subscribe(commandName, handler) {
|
|
54
|
+
delegate.subscribe(commandName, handler);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=retrying-command-bus.js.map
|