@cosmicdrift/kumiko-framework 0.121.0 → 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.121.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.121.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
- ORDER BY "id" ASC
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;
@@ -111,6 +111,35 @@ describe("buildAppSchema", () => {
111
111
  expect(idField?.["type"]).toBe("text"); // type kommt durch
112
112
  });
113
113
 
114
+ test("Reference-Field: entity + labelField + multiple überleben die Projection", () => {
115
+ // Regression: ohne diese Properties im Client-Schema baut der ReferenceInput
116
+ // die Options-Query als `<feature>:query::list` (leeres refEntity) → 404 →
117
+ // Dropdown zeigt „Keine Treffer" obwohl die referenzierte Entity Rows hat.
118
+ const entity = {
119
+ fields: {
120
+ name: { type: "text" },
121
+ parentId: { type: "reference", entity: "component", labelField: "name" },
122
+ tags: { type: "reference", entity: "tag", labelField: "label", multiple: true },
123
+ },
124
+ } as unknown as EntityDefinition;
125
+
126
+ const f = defineFeature("ent", (r) => {
127
+ r.entity("thing", entity);
128
+ });
129
+ const app = buildAppSchema(createRegistry([f]));
130
+ const fields = (
131
+ app.features[0]?.entities["thing"] as unknown as {
132
+ fields: Record<string, Record<string, unknown>>;
133
+ }
134
+ ).fields;
135
+
136
+ expect(fields["parentId"]?.["type"]).toBe("reference");
137
+ expect(fields["parentId"]?.["entity"]).toBe("component");
138
+ expect(fields["parentId"]?.["labelField"]).toBe("name");
139
+ expect(fields["tags"]?.["entity"]).toBe("tag");
140
+ expect(fields["tags"]?.["multiple"]).toBe(true);
141
+ });
142
+
114
143
  test("JSON-Safety: literal Defaults bleiben erhalten", () => {
115
144
  const entity = {
116
145
  fields: {
@@ -343,6 +343,13 @@ function projectField(fieldDef: FieldDefinition): FieldDefinition {
343
343
  if (isLiteral(def["default"])) out["default"] = def["default"];
344
344
  // Select: options-Liste ist plain JSON, durchschicken.
345
345
  if (Array.isArray(def["options"])) out["options"] = def["options"];
346
+ // Reference: entity-Target + labelField + multiple müssen zum Renderer.
347
+ // Der ReferenceInput baut die Options-Query aus refEntity/refFeature und
348
+ // resolved das Label über labelField — ohne diese Properties fällt das
349
+ // Dropdown leer aus (QN wird `<feature>:query::list` → 404).
350
+ if (typeof def["entity"] === "string") out["entity"] = def["entity"];
351
+ if (typeof def["labelField"] === "string") out["labelField"] = def["labelField"];
352
+ if (typeof def["multiple"] === "boolean") out["multiple"] = def["multiple"];
346
353
  return out as FieldDefinition; // @cast-boundary schema-walk
347
354
  }
348
355
 
@@ -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", () => {