@kronos-ts/axon-server 0.3.2 → 0.5.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 +3 -15
- package/dist/axon-server-event-store.d.ts.map +1 -1
- package/dist/axon-server-event-store.js +85 -44
- 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 +153 -0
- package/dist/axon-server-snapshotting-event-store.js.map +1 -0
- package/dist/axon-server.d.ts +92 -208
- package/dist/axon-server.d.ts.map +1 -1
- package/dist/axon-server.js +221 -323
- package/dist/axon-server.js.map +1 -1
- package/dist/connection-manager.d.ts +2 -2
- package/dist/connection-manager.d.ts.map +1 -1
- package/dist/connection.d.ts +134 -4
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +135 -10
- package/dist/connection.js.map +1 -1
- package/dist/context-view.d.ts +30 -0
- package/dist/context-view.d.ts.map +1 -0
- package/dist/context-view.js +19 -0
- package/dist/context-view.js.map +1 -0
- package/dist/control-plane.d.ts +18 -17
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/control-plane.js +8 -6
- package/dist/control-plane.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/event-processor-info.d.ts +4 -4
- package/dist/event-processor-info.d.ts.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.map +1 -1
- package/dist/generated/command.d.ts +20 -20
- package/dist/generated/command.d.ts.map +1 -1
- package/dist/generated/command.js.map +1 -1
- package/dist/generated/common.d.ts +20 -20
- package/dist/generated/common.d.ts.map +1 -1
- package/dist/generated/common.js.map +1 -1
- package/dist/generated/control.d.ts +36 -40
- package/dist/generated/control.d.ts.map +1 -1
- package/dist/generated/control.js.map +1 -1
- package/dist/generated/dcb.d.ts +88 -94
- package/dist/generated/dcb.d.ts.map +1 -1
- package/dist/generated/dcb.js.map +1 -1
- package/dist/generated/event.d.ts +81 -84
- package/dist/generated/event.d.ts.map +1 -1
- package/dist/generated/event.js.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/google/protobuf/empty.js.map +1 -1
- package/dist/generated/query.d.ts +40 -40
- package/dist/generated/query.d.ts.map +1 -1
- package/dist/generated/query.js.map +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -5
- 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/metadata-conversion.d.ts +1 -1
- package/dist/metadata-conversion.d.ts.map +1 -1
- package/dist/outbound-stream.d.ts +2 -2
- package/dist/outbound-stream.d.ts.map +1 -1
- package/dist/platform-service.d.ts +4 -4
- package/dist/platform-service.d.ts.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 +4 -4
- package/dist/shutdown-latch.d.ts.map +1 -1
- package/dist/shutdown-latch.js.map +1 -1
- package/package.json +5 -9
- package/src/axon-server-event-store.ts +97 -57
- package/src/axon-server-snapshotting-event-store.ts +191 -0
- package/src/axon-server.ts +365 -524
- package/src/connection-manager.ts +1 -1
- package/src/connection.ts +274 -20
- package/src/context-view.ts +46 -0
- package/src/control-plane.ts +19 -19
- package/src/event-processor-info.ts +2 -2
- package/src/flow-controlled-sender.ts +1 -1
- 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 +12 -18
- package/src/message-size.ts +1 -1
- package/src/metadata-conversion.ts +1 -1
- package/src/outbound-stream.ts +1 -1
- package/src/platform-service.ts +2 -2
- package/src/resilience.ts +149 -0
- package/src/shutdown-latch.ts +2 -2
- 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 -88
- package/dist/axon-server-snapshot-store.js.map +0 -1
- package/src/axon-server-snapshot-store.ts +0 -118
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates an EventStore implementation backed by Axon Server's DCB event store.
|
|
6
|
-
*
|
|
7
|
-
* This bridges the framework's EventStore interface to the gRPC
|
|
8
|
-
* DcbEventStore service, handling conversion between framework types
|
|
9
|
-
* and proto messages.
|
|
10
|
-
*
|
|
11
|
-
* The {@link open} method returns a persistent {@link MessageStream} backed by
|
|
12
|
-
* a single gRPC Stream RPC call that stays open indefinitely, aligned with
|
|
13
|
-
* Java's infinite {@code ResultStream}.
|
|
14
|
-
*/
|
|
15
|
-
export declare function axonServerEventStore(connection: AxonServerConnection, serializer: Serializer): EventStore;
|
|
1
|
+
import type { EventStore } from "@kronos-ts/core";
|
|
2
|
+
import type { AxonServerStoreSource } from "./connection.js";
|
|
3
|
+
export declare function axonServerEventStore(conn: AxonServerStoreSource, context: string): EventStore;
|
|
16
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":"
|
|
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;AAuJ5D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CA8N7F"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { qualifiedNameToString, qualifiedNameFromString, } from "@kronos-ts/
|
|
2
|
-
import { messageStream } from "@kronos-ts/
|
|
3
|
-
import { globalSequenceToken, FIRST_TOKEN } from "@kronos-ts/
|
|
4
|
-
import { markerAt, noMarker } from "@kronos-ts/
|
|
5
|
-
import {
|
|
1
|
+
import { qualifiedNameToString, qualifiedNameFromString, } from "@kronos-ts/core";
|
|
2
|
+
import { messageStream, compileQuery } from "@kronos-ts/core";
|
|
3
|
+
import { globalSequenceToken, FIRST_TOKEN } from "@kronos-ts/core";
|
|
4
|
+
import { markerAt, noMarker } from "@kronos-ts/core";
|
|
5
|
+
import { contextView } from "./context-view.js";
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
// Criteria conversion — framework EventCriteria → proto Criterion[]
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
@@ -23,23 +23,25 @@ function tagFromProto(tag) {
|
|
|
23
23
|
function criteriaToCriterions(criteria) {
|
|
24
24
|
switch (criteria.kind) {
|
|
25
25
|
case "tags":
|
|
26
|
-
return [
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
27
28
|
tagsAndNames: {
|
|
28
29
|
name: [],
|
|
29
30
|
tag: criteria.tags.map(tagToProto),
|
|
30
31
|
},
|
|
31
|
-
}
|
|
32
|
+
},
|
|
33
|
+
];
|
|
32
34
|
case "type-restricted":
|
|
33
35
|
// Inner must be tags or any-tag
|
|
34
|
-
const innerTags = criteria.inner.kind === "tags"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return [{
|
|
36
|
+
const innerTags = criteria.inner.kind === "tags" ? criteria.inner.tags.map(tagToProto) : [];
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
38
39
|
tagsAndNames: {
|
|
39
40
|
name: [...criteria.types],
|
|
40
41
|
tag: innerTags,
|
|
41
42
|
},
|
|
42
|
-
}
|
|
43
|
+
},
|
|
44
|
+
];
|
|
43
45
|
case "either":
|
|
44
46
|
// Flatten all sub-criteria into a list of criterions (OR semantics)
|
|
45
47
|
return criteria.criteria.flatMap(criteriaToCriterions);
|
|
@@ -70,7 +72,11 @@ function createEventConverters(serializer) {
|
|
|
70
72
|
},
|
|
71
73
|
eventFromProto(protoEvent, tags) {
|
|
72
74
|
const payload = protoEvent.payload.length > 0
|
|
73
|
-
? serializer.deserialize({
|
|
75
|
+
? serializer.deserialize({
|
|
76
|
+
data: protoEvent.payload,
|
|
77
|
+
type: protoEvent.name,
|
|
78
|
+
revision: protoEvent.version,
|
|
79
|
+
})
|
|
74
80
|
: {};
|
|
75
81
|
const metadata = {};
|
|
76
82
|
for (const [k, v] of Object.entries(protoEvent.metadata)) {
|
|
@@ -93,26 +99,36 @@ function createEventConverters(serializer) {
|
|
|
93
99
|
// AxonServerDcbEventStore — implements our EventStore interface via gRPC
|
|
94
100
|
// ---------------------------------------------------------------------------
|
|
95
101
|
/**
|
|
96
|
-
*
|
|
102
|
+
* An EventStore over Axon Server's DCB event store, in one context.
|
|
97
103
|
*
|
|
98
104
|
* This bridges the framework's EventStore interface to the gRPC
|
|
99
105
|
* DcbEventStore service, handling conversion between framework types
|
|
100
106
|
* and proto messages.
|
|
101
107
|
*
|
|
108
|
+
* `context` is Axon Server's tenancy boundary and is a per-call header, so
|
|
109
|
+
* several contexts share the one channel `conn` holds — see `contextView`. The
|
|
110
|
+
* serializer is the connection's: one codec for everything this client puts on
|
|
111
|
+
* the wire.
|
|
112
|
+
*
|
|
102
113
|
* The {@link open} method returns a persistent {@link MessageStream} backed by
|
|
103
114
|
* a single gRPC Stream RPC call that stays open indefinitely, aligned with
|
|
104
115
|
* Java's infinite {@code ResultStream}.
|
|
105
116
|
*/
|
|
106
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Axon Server's way of saying "there is nothing at or after that position".
|
|
119
|
+
*
|
|
120
|
+
* Matched on the gRPC status code first — `OUT_OF_RANGE` is 11 — with the
|
|
121
|
+
* server's own message as a second, narrower gate, so an unrelated future
|
|
122
|
+
* OUT_OF_RANGE is not swallowed along with it.
|
|
123
|
+
*/
|
|
124
|
+
function isStartPastHead(err) {
|
|
125
|
+
const code = err.code;
|
|
126
|
+
const details = String(err.details ?? "");
|
|
127
|
+
return code === 11 && details.includes("Start sequence cannot be larger than end sequence");
|
|
128
|
+
}
|
|
129
|
+
export function axonServerEventStore(conn, context) {
|
|
130
|
+
const { connection, serializer, metadata: createAxonMetadata } = contextView(conn, context);
|
|
107
131
|
const { eventToProto, eventFromProto } = createEventConverters(serializer);
|
|
108
|
-
function createAxonMetadata() {
|
|
109
|
-
const axonMetadata = new Metadata();
|
|
110
|
-
axonMetadata.set("AxonIQ-Context", connection.config.context);
|
|
111
|
-
if (connection.config.token) {
|
|
112
|
-
axonMetadata.set("AxonIQ-Access-Token", connection.config.token);
|
|
113
|
-
}
|
|
114
|
-
return axonMetadata;
|
|
115
|
-
}
|
|
116
132
|
// Push-based subscriber registry (EventBus.subscribe contract). Axon Server's
|
|
117
133
|
// own distribution is the server-side Stream RPC (see open()); these in-process
|
|
118
134
|
// subscribers are notified best-effort on every successful local append.
|
|
@@ -129,38 +145,61 @@ export function axonServerEventStore(connection, serializer) {
|
|
|
129
145
|
}
|
|
130
146
|
return {
|
|
131
147
|
async source(condition) {
|
|
132
|
-
const criterions = criteriaToCriterions(condition.
|
|
148
|
+
const criterions = criteriaToCriterions(compileQuery(condition.query));
|
|
149
|
+
const start = condition.start ?? 0n;
|
|
133
150
|
const request = {
|
|
134
|
-
fromSequence:
|
|
151
|
+
fromSequence: start,
|
|
135
152
|
criterion: criterions,
|
|
136
153
|
};
|
|
137
154
|
const events = [];
|
|
138
155
|
let marker = noMarker();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
try {
|
|
157
|
+
const stream = connection.eventStore.source(request, { metadata: createAxonMetadata() });
|
|
158
|
+
for await (const response of stream) {
|
|
159
|
+
if (response.event) {
|
|
160
|
+
const taggedEvent = response.event;
|
|
161
|
+
const protoEvent = taggedEvent.event;
|
|
162
|
+
if (protoEvent) {
|
|
163
|
+
// DCB source/stream responses carry no tags — the server indexes
|
|
164
|
+
// them write-side but does not echo them back (SequencedEvent has
|
|
165
|
+
// only sequence + event). Reconstructed events get empty tags.
|
|
166
|
+
events.push(eventFromProto(protoEvent, []));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (response.consistencyMarker !== undefined) {
|
|
170
|
+
marker = markerAt(response.consistencyMarker);
|
|
149
171
|
}
|
|
150
|
-
}
|
|
151
|
-
if (response.consistencyMarker !== undefined) {
|
|
152
|
-
marker = markerAt(response.consistencyMarker);
|
|
153
172
|
}
|
|
154
173
|
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
// READING PAST THE HEAD IS AN EMPTY ANSWER, NOT AN ERROR — and Axon
|
|
176
|
+
// Server disagrees, so this is where the two vocabularies are
|
|
177
|
+
// reconciled. `Source` fails OUT_OF_RANGE with "Start sequence cannot
|
|
178
|
+
// be larger than end sequence" whenever `fromSequence` is beyond the
|
|
179
|
+
// global head, which is the ORDINARY STEADY STATE of a snapshotted
|
|
180
|
+
// load: an entry written at the head means the very next read resumes
|
|
181
|
+
// at head + 1 and legitimately finds nothing.
|
|
182
|
+
//
|
|
183
|
+
// The marker is `start - 1`, and it is exact rather than conservative:
|
|
184
|
+
// the caller has already accounted for everything up to there (that is
|
|
185
|
+
// what asking to start later MEANS), and nothing can exist after it or
|
|
186
|
+
// the server would not have refused. So an append conditioned on this
|
|
187
|
+
// read is checked against precisely the range that was read.
|
|
188
|
+
if (!isStartPastHead(err))
|
|
189
|
+
throw err;
|
|
190
|
+
return { events: [], marker: start > 0n ? markerAt(start - 1n) : noMarker() };
|
|
191
|
+
}
|
|
155
192
|
return { events, marker };
|
|
156
193
|
},
|
|
157
194
|
async appendEvents(newEvents, condition) {
|
|
158
195
|
const taggedEvents = newEvents.map(eventToProto);
|
|
159
196
|
const request = {
|
|
160
|
-
condition: condition
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
197
|
+
condition: condition
|
|
198
|
+
? {
|
|
199
|
+
consistencyMarker: condition.marker.position,
|
|
200
|
+
criterion: criteriaToCriterions(compileQuery(condition.query)),
|
|
201
|
+
}
|
|
202
|
+
: undefined,
|
|
164
203
|
event: taggedEvents,
|
|
165
204
|
};
|
|
166
205
|
// Axon Server's Append RPC is atomic — commit happens on the server
|
|
@@ -171,7 +210,9 @@ export function axonServerEventStore(connection, serializer) {
|
|
|
171
210
|
async function* requestStream() {
|
|
172
211
|
yield request;
|
|
173
212
|
}
|
|
174
|
-
const response = await connection.eventStore.append(requestStream(), {
|
|
213
|
+
const response = await connection.eventStore.append(requestStream(), {
|
|
214
|
+
metadata: createAxonMetadata(),
|
|
215
|
+
});
|
|
175
216
|
responseMarker = response.consistencyMarker;
|
|
176
217
|
await notifySubscribers(newEvents);
|
|
177
218
|
},
|
|
@@ -189,7 +230,7 @@ export function axonServerEventStore(connection, serializer) {
|
|
|
189
230
|
return tx.afterCommit();
|
|
190
231
|
},
|
|
191
232
|
open(condition) {
|
|
192
|
-
const criterions = condition.
|
|
233
|
+
const criterions = condition.query ? criteriaToCriterions(compileQuery(condition.query)) : [];
|
|
193
234
|
const request = {
|
|
194
235
|
fromSequence: condition.position,
|
|
195
236
|
criterion: criterions,
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"axon-server-event-store.js","sourceR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;QAED,SAAS,CAAC,OAA+D;YACvE,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YACxB,OAAO,GAAG,EAAE;gBACV,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;YAC7B,CAAC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { EventStore, SnapshotCapability } from "@kronos-ts/core";
|
|
2
|
+
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 & SnapshotCapability` — 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 & SnapshotCapability;
|
|
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,kBAAkB,EAGnB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAkD5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,UAAU,EACnE,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,MAAM,GACd,CAAC,GAAG,kBAAkB,CA6ExB"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Conversion — framework Snapshot ↔ proto Snapshot
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
/**
|
|
31
|
+
* The proto message carries `name`, `version`, `timestamp` and a metadata map
|
|
32
|
+
* the narrowed seam has no equivalent for. `name` carries the cache key,
|
|
33
|
+
* `timestamp` is filled at write time for operators, and `version` stays EMPTY
|
|
34
|
+
* — snapshots have no versions, and inventing one to fill a proto field would
|
|
35
|
+
* be exactly the bookkeeping this design removed. The metadata map stays empty
|
|
36
|
+
* too: a cache entry carries no cargo.
|
|
37
|
+
*/
|
|
38
|
+
function createSnapshotConverters(serializer) {
|
|
39
|
+
return {
|
|
40
|
+
snapshotToProto(name, snapshot) {
|
|
41
|
+
const serialized = serializer.serialize(snapshot.state, name, "");
|
|
42
|
+
return {
|
|
43
|
+
name,
|
|
44
|
+
version: "",
|
|
45
|
+
payload: serialized.data,
|
|
46
|
+
timestamp: BigInt(Date.now()),
|
|
47
|
+
metadata: {},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
snapshotFromProto(name, proto, position) {
|
|
51
|
+
const state = proto.payload.length > 0
|
|
52
|
+
? serializer.deserialize({ data: proto.payload, type: name, revision: "" })
|
|
53
|
+
: {};
|
|
54
|
+
return { state, position };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function encodeKey(key) {
|
|
59
|
+
return encoder.encode(key);
|
|
60
|
+
}
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// Axon Server snapshot store
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
/**
|
|
65
|
+
* Add the snapshotting capability to an Axon Server-backed log.
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const eventStore = axonServerSnapshottingEventStore(
|
|
69
|
+
* axonServerEventStore(axon, "default"),
|
|
70
|
+
* axon,
|
|
71
|
+
* "default",
|
|
72
|
+
* )
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ADDITIVE, NOT COLLAPSING. It returns `E & SnapshotCapability` — the store you
|
|
76
|
+
* passed in, plus the write — so capabilities stack in either order and nothing
|
|
77
|
+
* the inner store carried is laundered on the way through.
|
|
78
|
+
*
|
|
79
|
+
* `context` is a per-call header, so this shares the one channel `conn` holds
|
|
80
|
+
* with every other context — see `contextView`. Payloads go through the
|
|
81
|
+
* connection's serializer.
|
|
82
|
+
*
|
|
83
|
+
* LATEST-ONLY, over a service that is not. `DcbSnapshotStore` keeps a sequence
|
|
84
|
+
* of snapshots per key; the capability keeps one. `add` therefore sets
|
|
85
|
+
* `prune: true`, so writing an entry retires the ones before it, and `getLast`
|
|
86
|
+
* is the only read. That is the narrowing doing its job: the framework programs
|
|
87
|
+
* against the cache it needs, not against everything the backend happens to
|
|
88
|
+
* offer.
|
|
89
|
+
*/
|
|
90
|
+
export function axonServerSnapshottingEventStore(next, conn, context) {
|
|
91
|
+
const { connection, serializer, metadata: createAxonMetadata } = contextView(conn, context);
|
|
92
|
+
const { snapshotToProto, snapshotFromProto } = createSnapshotConverters(serializer);
|
|
93
|
+
/** The cached fold filed under `key`, or nothing — the first of the two calls. */
|
|
94
|
+
async function loadSnapshot(key) {
|
|
95
|
+
try {
|
|
96
|
+
const response = await connection.snapshotStore.getLast({ key: encodeKey(key) }, { metadata: createAxonMetadata() });
|
|
97
|
+
if (!response.snapshot) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
return snapshotFromProto(key, response.snapshot, response.sequence);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
// Axon Server throws rather than answering empty when no snapshot
|
|
104
|
+
// exists — and a cache miss is not an error to anybody upstream.
|
|
105
|
+
if (String(err).includes("No snapshot found") ||
|
|
106
|
+
String(err).includes("not found")) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
...next,
|
|
114
|
+
async storeSnapshot(key, snapshot) {
|
|
115
|
+
await connection.snapshotStore.add({
|
|
116
|
+
key: encodeKey(key),
|
|
117
|
+
sequence: snapshot.position,
|
|
118
|
+
prune: true,
|
|
119
|
+
snapshot: snapshotToProto(key, snapshot),
|
|
120
|
+
}, { metadata: createAxonMetadata() });
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* THE CLIENT-SIDE FUSION. Two calls, assembled into the one result a fold
|
|
124
|
+
* expects — and the cache is NEVER LOAD-BEARING, so a miss or an outright
|
|
125
|
+
* throw from the snapshot service both fall through to a full read.
|
|
126
|
+
*/
|
|
127
|
+
async source(condition) {
|
|
128
|
+
const key = condition.snapshot;
|
|
129
|
+
if (key === undefined)
|
|
130
|
+
return next.source(condition);
|
|
131
|
+
// The strategy is CONSUMED here; the store below gets a plain condition.
|
|
132
|
+
const plain = withoutSnapshotKey(condition);
|
|
133
|
+
let snapshot;
|
|
134
|
+
try {
|
|
135
|
+
snapshot = await loadSnapshot(key.key);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// A cache you cannot reach is a cache miss. Loads stay correct; they
|
|
139
|
+
// just cost what they always cost.
|
|
140
|
+
return next.source(plain);
|
|
141
|
+
}
|
|
142
|
+
if (snapshot === undefined)
|
|
143
|
+
return next.source(plain);
|
|
144
|
+
// Resume AFTER the position the snapshot already folded; a condition that
|
|
145
|
+
// independently asked to start later keeps its own floor.
|
|
146
|
+
const resumeFrom = snapshot.position + 1n;
|
|
147
|
+
const start = plain.start !== undefined && plain.start > resumeFrom ? plain.start : resumeFrom;
|
|
148
|
+
const result = await next.source({ ...plain, start });
|
|
149
|
+
return { ...result, snapshot };
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=axon-server-snapshotting-event-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axon-server-snapshotting-event-store.js","sourceRoot":"","sources":["../src/axon-server-snapshotting-event-store.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,EAAE;AACF,sEAAsE;AACtE,iFAAiF;AACjF,iDAAiD;AACjD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;AAChF,sEAAsE;AACtE,8EAA8E;AAC9E,SAAS;AACT,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,8EAA8E;AAC9E,6BAA6B;AAC7B,8EAA8E;AAU9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,8EAA8E;AAC9E,mDAAmD;AACnD,8EAA8E;AAE9E,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AAEjC;;;;;;;GAOG;AACH,SAAS,wBAAwB,CAAC,UAAsB;IACtD,OAAO;QACL,eAAe,CAAC,IAAY,EAAE,QAAkB;YAC9C,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;YACjE,OAAO;gBACL,IAAI;gBACJ,OAAO,EAAE,EAAE;gBACX,OAAO,EAAE,UAAU,CAAC,IAAI;gBACxB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC7B,QAAQ,EAAE,EAAE;aACb,CAAA;QACH,CAAC;QAED,iBAAiB,CAAC,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