@kronos-ts/axon-server 0.4.0 → 0.6.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/axon-server-event-store.d.ts +0 -16
- package/dist/axon-server-event-store.d.ts.map +1 -1
- package/dist/axon-server-event-store.js +73 -45
- package/dist/axon-server-event-store.js.map +1 -1
- package/dist/axon-server-snapshotting-event-store.d.ts +30 -0
- package/dist/axon-server-snapshotting-event-store.d.ts.map +1 -0
- package/dist/axon-server-snapshotting-event-store.js +154 -0
- package/dist/axon-server-snapshotting-event-store.js.map +1 -0
- package/dist/axon-server.d.ts +46 -65
- package/dist/axon-server.d.ts.map +1 -1
- package/dist/axon-server.js +490 -317
- package/dist/axon-server.js.map +1 -1
- package/dist/bounded-read.d.ts +19 -0
- package/dist/bounded-read.d.ts.map +1 -0
- package/dist/bounded-read.js +39 -0
- package/dist/bounded-read.js.map +1 -0
- package/dist/connection-manager.d.ts +2 -2
- package/dist/connection-manager.d.ts.map +1 -1
- package/dist/connection.d.ts +36 -21
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +84 -45
- package/dist/connection.js.map +1 -1
- package/dist/context-view.d.ts +2 -2
- package/dist/context-view.d.ts.map +1 -1
- package/dist/control-plane.d.ts +14 -24
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/control-plane.js +6 -37
- package/dist/control-plane.js.map +1 -1
- package/dist/event-processor-info.d.ts +7 -25
- package/dist/event-processor-info.d.ts.map +1 -1
- package/dist/event-processor-info.js +16 -20
- package/dist/event-processor-info.js.map +1 -1
- package/dist/flow-controlled-sender.d.ts +2 -2
- package/dist/flow-controlled-sender.d.ts.map +1 -1
- package/dist/flow-controlled-sender.js +37 -17
- package/dist/flow-controlled-sender.js.map +1 -1
- package/dist/generated/command.d.ts +20 -20
- package/dist/generated/command.d.ts.map +1 -1
- package/dist/generated/common.d.ts +20 -20
- package/dist/generated/common.d.ts.map +1 -1
- package/dist/generated/control.d.ts +36 -40
- package/dist/generated/control.d.ts.map +1 -1
- package/dist/generated/dcb.d.ts +88 -94
- package/dist/generated/dcb.d.ts.map +1 -1
- package/dist/generated/event.d.ts +81 -84
- package/dist/generated/event.d.ts.map +1 -1
- package/dist/generated/google/protobuf/empty.d.ts +3 -4
- package/dist/generated/google/protobuf/empty.d.ts.map +1 -1
- package/dist/generated/query.d.ts +40 -40
- package/dist/generated/query.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/message-size.d.ts +2 -2
- package/dist/message-size.d.ts.map +1 -1
- package/dist/outbound-stream.d.ts +7 -11
- package/dist/outbound-stream.d.ts.map +1 -1
- package/dist/outbound-stream.js +65 -16
- package/dist/outbound-stream.js.map +1 -1
- package/dist/platform-service.d.ts +14 -5
- package/dist/platform-service.d.ts.map +1 -1
- package/dist/platform-service.js +70 -10
- package/dist/platform-service.js.map +1 -1
- package/dist/resilience.d.ts +62 -0
- package/dist/resilience.d.ts.map +1 -0
- package/dist/resilience.js +103 -0
- package/dist/resilience.js.map +1 -0
- package/dist/shutdown-latch.d.ts +5 -4
- package/dist/shutdown-latch.d.ts.map +1 -1
- package/dist/shutdown-latch.js +20 -1
- package/dist/shutdown-latch.js.map +1 -1
- package/dist/stream-recovery.d.ts +9 -0
- package/dist/stream-recovery.d.ts.map +1 -0
- package/dist/stream-recovery.js +70 -0
- package/dist/stream-recovery.js.map +1 -0
- package/package.json +3 -3
- package/src/axon-server-event-store.ts +77 -47
- package/src/axon-server-snapshotting-event-store.ts +194 -0
- package/src/axon-server.ts +472 -374
- package/src/bounded-read.ts +43 -0
- package/src/connection-manager.ts +1 -1
- package/src/connection.ts +93 -59
- package/src/context-view.ts +1 -1
- package/src/control-plane.ts +22 -66
- package/src/event-processor-info.ts +23 -44
- package/src/flow-controlled-sender.ts +34 -15
- package/src/generated/command.ts +10 -10
- package/src/generated/common.ts +10 -10
- package/src/generated/control.ts +20 -20
- package/src/generated/dcb.ts +47 -47
- package/src/generated/event.ts +42 -42
- package/src/generated/google/protobuf/empty.ts +2 -2
- package/src/generated/query.ts +20 -20
- package/src/index.ts +1 -2
- package/src/message-size.ts +1 -1
- package/src/outbound-stream.ts +58 -28
- package/src/platform-service.ts +77 -13
- package/src/resilience.ts +149 -0
- package/src/shutdown-latch.ts +16 -3
- package/src/stream-recovery.ts +72 -0
- package/dist/axon-server-snapshot-store.d.ts +0 -12
- package/dist/axon-server-snapshot-store.d.ts.map +0 -1
- package/dist/axon-server-snapshot-store.js +0 -82
- package/dist/axon-server-snapshot-store.js.map +0 -1
- package/src/axon-server-snapshot-store.ts +0 -110
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
import type { EventStore } from "@kronos-ts/core";
|
|
2
2
|
import type { AxonServerStoreSource } from "./connection.js";
|
|
3
|
-
/**
|
|
4
|
-
* An EventStore over Axon Server's DCB event store, in one context.
|
|
5
|
-
*
|
|
6
|
-
* This bridges the framework's EventStore interface to the gRPC
|
|
7
|
-
* DcbEventStore service, handling conversion between framework types
|
|
8
|
-
* and proto messages.
|
|
9
|
-
*
|
|
10
|
-
* `context` is Axon Server's tenancy boundary and is a per-call header, so
|
|
11
|
-
* several contexts share the one channel `conn` holds — see `contextView`. The
|
|
12
|
-
* serializer is the connection's: one codec for everything this client puts on
|
|
13
|
-
* the wire.
|
|
14
|
-
*
|
|
15
|
-
* The {@link open} method returns a persistent {@link MessageStream} backed by
|
|
16
|
-
* a single gRPC Stream RPC call that stays open indefinitely, aligned with
|
|
17
|
-
* Java's infinite {@code ResultStream}.
|
|
18
|
-
*/
|
|
19
3
|
export declare function axonServerEventStore(conn: AxonServerStoreSource, context: string): EventStore;
|
|
20
4
|
//# sourceMappingURL=axon-server-event-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axon-server-event-store.d.ts","sourceRoot":"","sources":["../src/axon-server-event-store.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,UAAU,EAMX,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"axon-server-event-store.d.ts","sourceRoot":"","sources":["../src/axon-server-event-store.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,UAAU,EAMX,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAwJ5D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CA2N7F"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { qualifiedNameToString, qualifiedNameFromString, } from "@kronos-ts/core";
|
|
2
|
-
import {
|
|
2
|
+
import { compileQuery } from "@kronos-ts/core";
|
|
3
3
|
import { globalSequenceToken, FIRST_TOKEN } from "@kronos-ts/core";
|
|
4
4
|
import { markerAt, noMarker } from "@kronos-ts/core";
|
|
5
5
|
import { contextView } from "./context-view.js";
|
|
6
|
+
import { boundedRead } from "./bounded-read.js";
|
|
6
7
|
// ---------------------------------------------------------------------------
|
|
7
8
|
// Criteria conversion — framework EventCriteria → proto Criterion[]
|
|
8
9
|
// ---------------------------------------------------------------------------
|
|
@@ -114,33 +115,32 @@ function createEventConverters(serializer) {
|
|
|
114
115
|
* a single gRPC Stream RPC call that stays open indefinitely, aligned with
|
|
115
116
|
* Java's infinite {@code ResultStream}.
|
|
116
117
|
*/
|
|
118
|
+
/**
|
|
119
|
+
* Axon Server's way of saying "there is nothing at or after that position".
|
|
120
|
+
*
|
|
121
|
+
* Matched on the gRPC status code first — `OUT_OF_RANGE` is 11 — with the
|
|
122
|
+
* server's own message as a second, narrower gate, so an unrelated future
|
|
123
|
+
* OUT_OF_RANGE is not swallowed along with it.
|
|
124
|
+
*/
|
|
125
|
+
function isStartPastHead(err) {
|
|
126
|
+
const code = err.code;
|
|
127
|
+
const details = String(err.details ?? "");
|
|
128
|
+
return code === 11 && details.includes("Start sequence cannot be larger than end sequence");
|
|
129
|
+
}
|
|
117
130
|
export function axonServerEventStore(conn, context) {
|
|
118
131
|
const { connection, serializer, metadata: createAxonMetadata } = contextView(conn, context);
|
|
119
132
|
const { eventToProto, eventFromProto } = createEventConverters(serializer);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
async source(condition) {
|
|
136
|
-
const criterions = criteriaToCriterions(compileQuery(condition.query));
|
|
137
|
-
const request = {
|
|
138
|
-
fromSequence: condition.start ?? 0n,
|
|
139
|
-
criterion: criterions,
|
|
140
|
-
};
|
|
141
|
-
const events = [];
|
|
142
|
-
let marker = noMarker();
|
|
143
|
-
const stream = connection.eventStore.source(request, { metadata: createAxonMetadata() });
|
|
133
|
+
async function sourceOnce(condition, signal) {
|
|
134
|
+
const criterions = criteriaToCriterions(compileQuery(condition.query));
|
|
135
|
+
const start = condition.start ?? 0n;
|
|
136
|
+
const request = {
|
|
137
|
+
fromSequence: start,
|
|
138
|
+
criterion: criterions,
|
|
139
|
+
};
|
|
140
|
+
const events = [];
|
|
141
|
+
let marker = noMarker();
|
|
142
|
+
try {
|
|
143
|
+
const stream = connection.eventStore.source(request, { metadata: createAxonMetadata(), signal });
|
|
144
144
|
for await (const response of stream) {
|
|
145
145
|
if (response.event) {
|
|
146
146
|
const taggedEvent = response.event;
|
|
@@ -156,7 +156,30 @@ export function axonServerEventStore(conn, context) {
|
|
|
156
156
|
marker = markerAt(response.consistencyMarker);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
// READING PAST THE HEAD IS AN EMPTY ANSWER, NOT AN ERROR — and Axon
|
|
162
|
+
// Server disagrees, so this is where the two vocabularies are
|
|
163
|
+
// reconciled. `Source` fails OUT_OF_RANGE with "Start sequence cannot
|
|
164
|
+
// be larger than end sequence" whenever `fromSequence` is beyond the
|
|
165
|
+
// global head, which is the ORDINARY STEADY STATE of a snapshotted
|
|
166
|
+
// load: an entry written at the head means the very next read resumes
|
|
167
|
+
// at head + 1 and legitimately finds nothing.
|
|
168
|
+
//
|
|
169
|
+
// The marker is `start - 1`, and it is exact rather than conservative:
|
|
170
|
+
// the caller has already accounted for everything up to there (that is
|
|
171
|
+
// what asking to start later MEANS), and nothing can exist after it or
|
|
172
|
+
// the server would not have refused. So an append conditioned on this
|
|
173
|
+
// read is checked against precisely the range that was read.
|
|
174
|
+
if (!isStartPastHead(err))
|
|
175
|
+
throw err;
|
|
176
|
+
return { events: [], marker: start > 0n ? markerAt(start - 1n) : noMarker() };
|
|
177
|
+
}
|
|
178
|
+
return { events, marker };
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
source(condition) {
|
|
182
|
+
return boundedRead(connection.config.readTimeoutMs, (signal) => sourceOnce(condition, signal));
|
|
160
183
|
},
|
|
161
184
|
async appendEvents(newEvents, condition) {
|
|
162
185
|
const taggedEvents = newEvents.map(eventToProto);
|
|
@@ -181,7 +204,6 @@ export function axonServerEventStore(conn, context) {
|
|
|
181
204
|
metadata: createAxonMetadata(),
|
|
182
205
|
});
|
|
183
206
|
responseMarker = response.consistencyMarker;
|
|
184
|
-
await notifySubscribers(newEvents);
|
|
185
207
|
},
|
|
186
208
|
async afterCommit() {
|
|
187
209
|
return markerAt(responseMarker ?? 0n);
|
|
@@ -202,7 +224,20 @@ export function axonServerEventStore(conn, context) {
|
|
|
202
224
|
fromSequence: condition.position,
|
|
203
225
|
criterion: criterions,
|
|
204
226
|
};
|
|
205
|
-
|
|
227
|
+
// `close()` must reach the server. This is a server-streaming call: the
|
|
228
|
+
// client sends nothing after the request, so the only way to end it from
|
|
229
|
+
// this side is to cancel it. Abandoning the async iterator does not do
|
|
230
|
+
// that — the `for await` below stays parked on the call until the next
|
|
231
|
+
// event arrives, which at the head of a quiet stream is never, and every
|
|
232
|
+
// closed stream leaves a live call behind on the server. With enough of
|
|
233
|
+
// them open, Axon Server stops answering later `source` reads (a 2-CPU
|
|
234
|
+
// container gets there after a handful): handlers never reply, and
|
|
235
|
+
// commands die at the server's own timeout.
|
|
236
|
+
const cancel = new AbortController();
|
|
237
|
+
const grpcStream = connection.eventStore.stream(request, {
|
|
238
|
+
metadata: createAxonMetadata(),
|
|
239
|
+
signal: cancel.signal,
|
|
240
|
+
});
|
|
206
241
|
// Internal buffer for events pulled from the gRPC stream
|
|
207
242
|
const buffer = [];
|
|
208
243
|
let availableCallback = null;
|
|
@@ -232,13 +267,17 @@ export function axonServerEventStore(conn, context) {
|
|
|
232
267
|
availableCallback?.();
|
|
233
268
|
}
|
|
234
269
|
catch (err) {
|
|
235
|
-
|
|
270
|
+
// Our own cancellation surfaces here as an AbortError; that is the
|
|
271
|
+
// stream closing as asked, not a failure to report.
|
|
272
|
+
if (!completed) {
|
|
273
|
+
streamError = err instanceof Error ? err : new Error(String(err));
|
|
274
|
+
}
|
|
236
275
|
completed = true;
|
|
237
276
|
availableCallback?.();
|
|
238
277
|
}
|
|
239
278
|
}
|
|
240
279
|
startReading();
|
|
241
|
-
return
|
|
280
|
+
return {
|
|
242
281
|
next() {
|
|
243
282
|
return buffer.shift();
|
|
244
283
|
},
|
|
@@ -260,32 +299,21 @@ export function axonServerEventStore(conn, context) {
|
|
|
260
299
|
close() {
|
|
261
300
|
completed = true;
|
|
262
301
|
availableCallback = null;
|
|
263
|
-
|
|
302
|
+
cancel.abort();
|
|
264
303
|
},
|
|
265
|
-
}
|
|
304
|
+
};
|
|
266
305
|
},
|
|
267
306
|
async getHeadPosition() {
|
|
268
|
-
const response = await connection.eventStore.getHead({}, { metadata: createAxonMetadata() });
|
|
307
|
+
const response = await boundedRead(connection.config.readTimeoutMs, (signal) => connection.eventStore.getHead({}, { metadata: createAxonMetadata(), signal }));
|
|
269
308
|
return response.sequence;
|
|
270
309
|
},
|
|
271
310
|
async firstToken() {
|
|
272
311
|
return FIRST_TOKEN;
|
|
273
312
|
},
|
|
274
313
|
async latestToken() {
|
|
275
|
-
const response = await connection.eventStore.getHead({}, { metadata: createAxonMetadata() });
|
|
314
|
+
const response = await boundedRead(connection.config.readTimeoutMs, (signal) => connection.eventStore.getHead({}, { metadata: createAxonMetadata(), signal }));
|
|
276
315
|
return globalSequenceToken(response.sequence);
|
|
277
316
|
},
|
|
278
|
-
// EventBus contract — publish = append without condition, then notify
|
|
279
|
-
// in-process subscribers.
|
|
280
|
-
async publish(events) {
|
|
281
|
-
await this.append(events);
|
|
282
|
-
},
|
|
283
|
-
subscribe(handler) {
|
|
284
|
-
subscribers.add(handler);
|
|
285
|
-
return () => {
|
|
286
|
-
subscribers.delete(handler);
|
|
287
|
-
};
|
|
288
|
-
},
|
|
289
317
|
};
|
|
290
318
|
}
|
|
291
319
|
//# sourceMappingURL=axon-server-event-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axon-server-event-store.js","sourceRoot":"","sources":["../src/axon-server-event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GAGxB,MAAM,iBAAiB,CAAA;AAQxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"axon-server-event-store.js","sourceRoot":"","sources":["../src/axon-server-event-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GAGxB,MAAM,iBAAiB,CAAA;AAQxB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAU9C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,WAAW,E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import type { AxonServerStoreSource } from "./connection.js";
|
|
3
|
+
/**
|
|
4
|
+
* Add the snapshotting capability to an Axon Server-backed log.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const eventStore = axonServerSnapshottingEventStore(
|
|
8
|
+
* axonServerEventStore(axon, "default"),
|
|
9
|
+
* axon,
|
|
10
|
+
* "default",
|
|
11
|
+
* )
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* ADDITIVE, NOT COLLAPSING. It returns `E & SnapshotStoreCapability` — the store you
|
|
15
|
+
* passed in, plus the write — so capabilities stack in either order and nothing
|
|
16
|
+
* the inner store carried is laundered on the way through.
|
|
17
|
+
*
|
|
18
|
+
* `context` is a per-call header, so this shares the one channel `conn` holds
|
|
19
|
+
* with every other context — see `contextView`. Payloads go through the
|
|
20
|
+
* connection's serializer.
|
|
21
|
+
*
|
|
22
|
+
* LATEST-ONLY, over a service that is not. `DcbSnapshotStore` keeps a sequence
|
|
23
|
+
* of snapshots per key; the capability keeps one. `add` therefore sets
|
|
24
|
+
* `prune: true`, so writing an entry retires the ones before it, and `getLast`
|
|
25
|
+
* is the only read. That is the narrowing doing its job: the framework programs
|
|
26
|
+
* against the cache it needs, not against everything the backend happens to
|
|
27
|
+
* offer.
|
|
28
|
+
*/
|
|
29
|
+
export declare function axonServerSnapshottingEventStore<E extends EventStore>(next: E, conn: AxonServerStoreSource, context: string): E & SnapshotStoreCapability;
|
|
30
|
+
//# sourceMappingURL=axon-server-snapshotting-event-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axon-server-snapshotting-event-store.d.ts","sourceRoot":"","sources":["../src/axon-server-snapshotting-event-store.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EACV,UAAU,EAEV,uBAAuB,EAGxB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAmD5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,UAAU,EACnE,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,MAAM,GACd,CAAC,GAAG,uBAAuB,CA+E7B"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// AXON SERVER SNAPSHOTS — the capability tier, served by `DcbSnapshotStore`.
|
|
3
|
+
//
|
|
4
|
+
// THE PROBE, AND WHAT IT SETTLED. Axon Server's public API defines both a
|
|
5
|
+
// snapshot STORE service (`DcbSnapshotStore`: Add / Delete / List / GetLast)
|
|
6
|
+
// and, on newer API drops, a fused `SnapshottedDcbEventStore.Source` whose
|
|
7
|
+
// stream leads with the snapshot. Only the first of those is actually served:
|
|
8
|
+
//
|
|
9
|
+
// axoniq/axonserver:2025.2.5 DcbSnapshotStore/GetLast → answers
|
|
10
|
+
// SnapshottedDcbEventStore/Source → UNIMPLEMENTED
|
|
11
|
+
// axoniq/axonserver:2026.0.4 same, both ways
|
|
12
|
+
//
|
|
13
|
+
// So there is no server-side fusion to call here — there is nothing on the
|
|
14
|
+
// other end of the wire. The READ is therefore fused CLIENT-SIDE: `GetLast` for
|
|
15
|
+
// the entry, then a source after its position, assembled into the one
|
|
16
|
+
// `SourcingResult` a fold expects. Two round trips, the same answers, correct
|
|
17
|
+
// today.
|
|
18
|
+
//
|
|
19
|
+
// When a server version does serve `SnapshottedDcbEventStore.Source`, the fused
|
|
20
|
+
// call lands INSIDE this function — `source` stops making two calls and starts
|
|
21
|
+
// making one — and no host changes a line, because the capability was never a
|
|
22
|
+
// promise about round trips.
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
import { withoutSnapshotKey } from "@kronos-ts/core";
|
|
25
|
+
import { contextView } from "./context-view.js";
|
|
26
|
+
import { boundedRead } from "./bounded-read.js";
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Conversion — framework Snapshot ↔ proto Snapshot
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
const encoder = new TextEncoder();
|
|
31
|
+
/**
|
|
32
|
+
* The proto message carries `name`, `version`, `timestamp` and a metadata map
|
|
33
|
+
* the narrowed seam has no equivalent for. `name` carries the cache key,
|
|
34
|
+
* `timestamp` is filled at write time for operators, and `version` stays EMPTY
|
|
35
|
+
* — snapshots have no versions, and inventing one to fill a proto field would
|
|
36
|
+
* be exactly the bookkeeping this design removed. The metadata map stays empty
|
|
37
|
+
* too: a cache entry carries no cargo.
|
|
38
|
+
*/
|
|
39
|
+
function createSnapshotConverters(serializer) {
|
|
40
|
+
return {
|
|
41
|
+
snapshotToProto(name, snapshot) {
|
|
42
|
+
const serialized = serializer.serialize(snapshot.state, name, "");
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
version: "",
|
|
46
|
+
payload: serialized.data,
|
|
47
|
+
timestamp: BigInt(Date.now()),
|
|
48
|
+
metadata: {},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
snapshotFromProto(name, proto, position) {
|
|
52
|
+
const state = proto.payload.length > 0
|
|
53
|
+
? serializer.deserialize({ data: proto.payload, type: name, revision: "" })
|
|
54
|
+
: {};
|
|
55
|
+
return { state, position };
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function encodeKey(key) {
|
|
60
|
+
return encoder.encode(key);
|
|
61
|
+
}
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Axon Server snapshot store
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
/**
|
|
66
|
+
* Add the snapshotting capability to an Axon Server-backed log.
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* const eventStore = axonServerSnapshottingEventStore(
|
|
70
|
+
* axonServerEventStore(axon, "default"),
|
|
71
|
+
* axon,
|
|
72
|
+
* "default",
|
|
73
|
+
* )
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* ADDITIVE, NOT COLLAPSING. It returns `E & SnapshotStoreCapability` — the store you
|
|
77
|
+
* passed in, plus the write — so capabilities stack in either order and nothing
|
|
78
|
+
* the inner store carried is laundered on the way through.
|
|
79
|
+
*
|
|
80
|
+
* `context` is a per-call header, so this shares the one channel `conn` holds
|
|
81
|
+
* with every other context — see `contextView`. Payloads go through the
|
|
82
|
+
* connection's serializer.
|
|
83
|
+
*
|
|
84
|
+
* LATEST-ONLY, over a service that is not. `DcbSnapshotStore` keeps a sequence
|
|
85
|
+
* of snapshots per key; the capability keeps one. `add` therefore sets
|
|
86
|
+
* `prune: true`, so writing an entry retires the ones before it, and `getLast`
|
|
87
|
+
* is the only read. That is the narrowing doing its job: the framework programs
|
|
88
|
+
* against the cache it needs, not against everything the backend happens to
|
|
89
|
+
* offer.
|
|
90
|
+
*/
|
|
91
|
+
export function axonServerSnapshottingEventStore(next, conn, context) {
|
|
92
|
+
const { connection, serializer, metadata: createAxonMetadata } = contextView(conn, context);
|
|
93
|
+
const { snapshotToProto, snapshotFromProto } = createSnapshotConverters(serializer);
|
|
94
|
+
/** The cached fold filed under `key`, or nothing — the first of the two calls. */
|
|
95
|
+
async function loadSnapshot(key) {
|
|
96
|
+
try {
|
|
97
|
+
const response = await boundedRead(connection.config.readTimeoutMs, (signal) => connection.snapshotStore.getLast({ key: encodeKey(key) }, { metadata: createAxonMetadata(), signal }));
|
|
98
|
+
if (!response.snapshot) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return snapshotFromProto(key, response.snapshot, response.sequence);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
// Axon Server throws rather than answering empty when no snapshot
|
|
105
|
+
// exists — and a cache miss is not an error to anybody upstream.
|
|
106
|
+
if (String(err).includes("No snapshot found") ||
|
|
107
|
+
String(err).includes("not found")) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
...next,
|
|
115
|
+
async storeSnapshot(key, snapshot) {
|
|
116
|
+
await connection.snapshotStore.add({
|
|
117
|
+
key: encodeKey(key),
|
|
118
|
+
sequence: snapshot.position,
|
|
119
|
+
prune: true,
|
|
120
|
+
snapshot: snapshotToProto(key, snapshot),
|
|
121
|
+
}, { metadata: createAxonMetadata() });
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* THE CLIENT-SIDE FUSION. Two calls, assembled into the one result a fold
|
|
125
|
+
* expects — and the cache is NEVER LOAD-BEARING, so a miss or an outright
|
|
126
|
+
* throw from the snapshot service both fall through to a full read.
|
|
127
|
+
*/
|
|
128
|
+
async source(condition) {
|
|
129
|
+
const key = condition.snapshot;
|
|
130
|
+
if (key === undefined)
|
|
131
|
+
return next.source(condition);
|
|
132
|
+
// The strategy is CONSUMED here; the store below gets a plain condition.
|
|
133
|
+
const plain = withoutSnapshotKey(condition);
|
|
134
|
+
let snapshot;
|
|
135
|
+
try {
|
|
136
|
+
snapshot = await loadSnapshot(key.key);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// A cache you cannot reach is a cache miss. Loads stay correct; they
|
|
140
|
+
// just cost what they always cost.
|
|
141
|
+
return next.source(plain);
|
|
142
|
+
}
|
|
143
|
+
if (snapshot === undefined)
|
|
144
|
+
return next.source(plain);
|
|
145
|
+
// Resume AFTER the position the snapshot already folded; a condition that
|
|
146
|
+
// independently asked to start later keeps its own floor.
|
|
147
|
+
const resumeFrom = snapshot.position + 1n;
|
|
148
|
+
const start = plain.start !== undefined && plain.start > resumeFrom ? plain.start : resumeFrom;
|
|
149
|
+
const result = await next.source({ ...plain, start });
|
|
150
|
+
return { ...result, snapshot };
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=axon-server-snapshotting-event-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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