@cosmicdrift/kumiko-framework 0.121.1 → 0.122.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.122.0",
|
|
4
4
|
"description": "Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -135,6 +135,10 @@
|
|
|
135
135
|
"types": "./src/crypto/index.ts",
|
|
136
136
|
"default": "./src/crypto/index.ts"
|
|
137
137
|
},
|
|
138
|
+
"./logging": {
|
|
139
|
+
"types": "./src/logging/index.ts",
|
|
140
|
+
"default": "./src/logging/index.ts"
|
|
141
|
+
},
|
|
138
142
|
"./schema-cli": {
|
|
139
143
|
"types": "./src/schema-cli.ts",
|
|
140
144
|
"default": "./src/schema-cli.ts"
|
|
@@ -185,7 +189,7 @@
|
|
|
185
189
|
"zod": "^4.4.3"
|
|
186
190
|
},
|
|
187
191
|
"devDependencies": {
|
|
188
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
192
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.122.0",
|
|
189
193
|
"bun-types": "^1.3.13",
|
|
190
194
|
"pino-pretty": "^13.1.3"
|
|
191
195
|
},
|
|
@@ -23,12 +23,19 @@ export async function selectEventsForProjectionRebuildBatch(
|
|
|
23
23
|
afterId: bigint,
|
|
24
24
|
limit: number,
|
|
25
25
|
): Promise<ReadonlyArray<Record<string, unknown>>> {
|
|
26
|
+
// Archived streams don't replay (Marten-aligned): their aggregates are
|
|
27
|
+
// frozen ops-tombstones — replaying them would resurrect rows (or, for
|
|
28
|
+
// stranded duplicate-aggregates like fw#832, collide on unique indexes).
|
|
26
29
|
return (await asRawClient(db).unsafe(
|
|
27
|
-
`SELECT * FROM "kumiko_events"
|
|
28
|
-
WHERE "aggregate_type" = ANY($1::text[])
|
|
29
|
-
AND "type" = ANY($2::text[])
|
|
30
|
-
AND "id" > $3
|
|
31
|
-
|
|
30
|
+
`SELECT * FROM "kumiko_events" e
|
|
31
|
+
WHERE e."aggregate_type" = ANY($1::text[])
|
|
32
|
+
AND e."type" = ANY($2::text[])
|
|
33
|
+
AND e."id" > $3
|
|
34
|
+
AND NOT EXISTS (
|
|
35
|
+
SELECT 1 FROM "kumiko_archived_streams" a
|
|
36
|
+
WHERE a."tenant_id" = e."tenant_id" AND a."aggregate_id" = e."aggregate_id"
|
|
37
|
+
)
|
|
38
|
+
ORDER BY e."id" ASC
|
|
32
39
|
LIMIT $4`,
|
|
33
40
|
[aggregateTypes, eventTypes, afterId, limit],
|
|
34
41
|
)) as ReadonlyArray<Record<string, unknown>>;
|
|
@@ -43,10 +50,17 @@ export async function countSubscribedEvents(
|
|
|
43
50
|
aggregateTypes: readonly string[],
|
|
44
51
|
eventTypes: readonly string[],
|
|
45
52
|
): Promise<bigint> {
|
|
53
|
+
// Same archived-streams exclusion as the batch query — the #443 recompute
|
|
54
|
+
// compares this count against applied events; a filter mismatch would make
|
|
55
|
+
// every rebuild with an archived stream loop the full-re-replay forever.
|
|
46
56
|
const rows = (await asRawClient(db).unsafe(
|
|
47
|
-
`SELECT count(*)::bigint AS n FROM "kumiko_events"
|
|
48
|
-
WHERE "aggregate_type" = ANY($1::text[])
|
|
49
|
-
AND "type" = ANY($2::text[])
|
|
57
|
+
`SELECT count(*)::bigint AS n FROM "kumiko_events" e
|
|
58
|
+
WHERE e."aggregate_type" = ANY($1::text[])
|
|
59
|
+
AND e."type" = ANY($2::text[])
|
|
60
|
+
AND NOT EXISTS (
|
|
61
|
+
SELECT 1 FROM "kumiko_archived_streams" a
|
|
62
|
+
WHERE a."tenant_id" = e."tenant_id" AND a."aggregate_id" = e."aggregate_id"
|
|
63
|
+
)`,
|
|
50
64
|
[aggregateTypes, eventTypes],
|
|
51
65
|
)) as ReadonlyArray<{ n: bigint | string | number | null }>;
|
|
52
66
|
const raw = rows[0]?.n;
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
defineFeature,
|
|
27
27
|
} from "../../engine";
|
|
28
28
|
import type { ProjectionDefinition } from "../../engine/types";
|
|
29
|
-
import { createEventsTable } from "../../event-store";
|
|
29
|
+
import { archiveStream, createEventsTable } from "../../event-store";
|
|
30
30
|
import {
|
|
31
31
|
createProjectionStateTable,
|
|
32
32
|
getAllProjectionProgress,
|
|
@@ -116,7 +116,7 @@ afterAll(async () => {
|
|
|
116
116
|
|
|
117
117
|
beforeEach(async () => {
|
|
118
118
|
await asRawClient(testDb.db).unsafe(
|
|
119
|
-
`TRUNCATE kumiko_events, read_rebuild_items, read_rebuild_items_per_group, kumiko_projections RESTART IDENTITY CASCADE`,
|
|
119
|
+
`TRUNCATE kumiko_events, read_rebuild_items, read_rebuild_items_per_group, kumiko_projections, kumiko_archived_streams RESTART IDENTITY CASCADE`,
|
|
120
120
|
);
|
|
121
121
|
});
|
|
122
122
|
|
|
@@ -210,6 +210,36 @@ describe("rebuildProjection — happy path", () => {
|
|
|
210
210
|
expect(result.eventsProcessed).toBe(0);
|
|
211
211
|
expect(result.lastProcessedEventId).toBe(0n);
|
|
212
212
|
});
|
|
213
|
+
|
|
214
|
+
test("archived streams don't replay (fw#832) — stranded aggregate heals via archiveStream", async () => {
|
|
215
|
+
// Heilungs-Muster fuer eventlose Read-Side-Deletes im Bestand: ein
|
|
216
|
+
// Aggregat, dessen Live-Row (vor dem fw#832-Fix) read-side entfernt
|
|
217
|
+
// wurde, hinterlaesst ein created-Event ohne deleted — jeder Rebuild
|
|
218
|
+
// wuerde die Row resurrecten (bzw. an unique-Indexen kollidieren).
|
|
219
|
+
// archiveStream friert den Stream ein UND nimmt ihn aus dem Replay.
|
|
220
|
+
const group = "00000000-0000-4000-8000-000000000020";
|
|
221
|
+
const stranded = await executor.create({ groupId: group, name: "stranded" }, admin, tdb);
|
|
222
|
+
if (!stranded.isSuccess) throw new Error("create failed");
|
|
223
|
+
await appendCreatedEvent(group, "survivor");
|
|
224
|
+
|
|
225
|
+
await archiveStream(testDb.db, {
|
|
226
|
+
tenantId: admin.tenantId,
|
|
227
|
+
aggregateId: String(stranded.data.id),
|
|
228
|
+
aggregateType: "rebuild-item",
|
|
229
|
+
archivedBy: "fw832-heal-test",
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const result = await rebuildProjection(qualifiedProjectionName, {
|
|
233
|
+
db: testDb.db,
|
|
234
|
+
registry,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Nur das survivor-Event replayed; das archivierte Aggregat traegt
|
|
238
|
+
// nicht mehr bei — auch nicht im #443-ground-truth-count (sonst
|
|
239
|
+
// wuerde der Recompute-Pfad endlos nachziehen).
|
|
240
|
+
expect(result.eventsProcessed).toBe(1);
|
|
241
|
+
expect(await getCount(group)).toBe(1);
|
|
242
|
+
});
|
|
213
243
|
});
|
|
214
244
|
|
|
215
245
|
describe("rebuildProjection — state table lifecycle", () => {
|