@cosmicdrift/kumiko-framework 0.276.0 → 0.278.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.276.0",
3
+ "version": "0.278.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>",
@@ -198,7 +198,7 @@
198
198
  "./package.json": "./package.json"
199
199
  },
200
200
  "dependencies": {
201
- "@cosmicdrift/kumiko-types": "0.276.0",
201
+ "@cosmicdrift/kumiko-types": "0.278.0",
202
202
  "bullmq": "^5.76.7",
203
203
  "bun-types": "^1.3.13",
204
204
  "hono": "^4.13.1",
@@ -214,7 +214,7 @@
214
214
  "zod": "^4.4.3"
215
215
  },
216
216
  "devDependencies": {
217
- "@cosmicdrift/kumiko-dispatcher-live": "0.276.0",
217
+ "@cosmicdrift/kumiko-dispatcher-live": "0.278.0",
218
218
  "bun-types": "^1.3.13",
219
219
  "pino-pretty": "^13.1.3"
220
220
  },
package/src/changes.json CHANGED
@@ -1,4 +1,23 @@
1
1
  [
2
+ {
3
+ "version": "0.278.0",
4
+ "type": "fix",
5
+ "title": "Fix urlPrefillFields allowlist missing relatedList toolbarActions",
6
+ "detail": "A screen reached only through a relatedList toolbar action never received its mapped id, so its hidden required field stayed empty and the declared redirect never ran."
7
+ },
8
+ {
9
+ "version": "0.278.0",
10
+ "type": "improvement",
11
+ "title": "TenantDb gains a count(table, where?) method for a tenant-scoped COUNT(*) (fw#2854).",
12
+ "detail": "`TenantDb.count(table, where?)` returns a tenant-scoped row count with the same tenant semantics as `selectMany`: \"tenant\" mode counts the caller's own tenant plus `SYSTEM_TENANT_ID` reference rows, a caller-supplied `where.tenantId` may only narrow that scope, and \"system\" mode counts unfiltered. Lets app/feature code compute stock-caps (`count(*) WHERE tenant_id = …`) without an `unsafeRaw`/`escapeHatch` detour. A hand-built `TenantDb` object literal (test fakes, mocks) must add a `count` method to keep satisfying the `TenantDb` type — `db.global()` is unaffected, `count` is only on the tenant-scoped surface.",
13
+ "migration": "No action required for existing `TenantDb` consumers — purely additive. Any hand-built object literal typed as `TenantDb` (not built via `createTenantDb`) needs a `count(table, where?)` method added; `bunCountWhere`/`countWhere` from `@cosmicdrift/kumiko-framework/db` implements the same query shape if you need equivalent logic outside a `TenantDb`."
14
+ },
15
+ {
16
+ "version": "0.277.0",
17
+ "type": "improvement",
18
+ "title": "Changesets are the single source for upgrade changelog entries",
19
+ "detail": "The release step folds structured Changeset metadata into changes.json with the actual published version."
20
+ },
2
21
  {
3
22
  "version": "0.276.0",
4
23
  "type": "improvement",
@@ -0,0 +1,92 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
+ import { seedRow } from "@cosmicdrift/kumiko-framework/testing";
3
+ import { createEntity, createTextField } from "../../engine";
4
+ import { createTestDb, type TestDb, TestUsers, unsafeCreateEntityTable } from "../../stack";
5
+ import type { TableColumns } from "../dialect";
6
+ import { buildEntityTable } from "../table-builder";
7
+ import { createTenantDb } from "../tenant-db";
8
+
9
+ const entity = createEntity({
10
+ table: "tenant_db_count_items",
11
+ fields: {
12
+ name: createTextField({ required: true, personal: false, reason: "test_fixture" }),
13
+ },
14
+ });
15
+
16
+ const table: TableColumns = buildEntityTable("tenantDbCountItem", entity);
17
+
18
+ let testDb: TestDb;
19
+ const tenantA = TestUsers.admin; // tenantId: 1
20
+ const tenantB = TestUsers.otherTenant; // tenantId: 2
21
+
22
+ beforeAll(async () => {
23
+ testDb = await createTestDb();
24
+ await unsafeCreateEntityTable(testDb.db, entity, "tenantDbCountItem");
25
+
26
+ const tdbA = createTenantDb(testDb.db, tenantA.tenantId);
27
+ const tdbB = createTenantDb(testDb.db, tenantB.tenantId);
28
+
29
+ await tdbA.insertOne(table, { name: "A1" });
30
+ await tdbA.insertOne(table, { name: "A2" });
31
+ await tdbA.insertOne(table, { name: "A3" });
32
+ await tdbB.insertOne(table, { name: "B1" });
33
+
34
+ await seedRow(testDb.db, table, {
35
+ name: "Reference",
36
+ tenantId: "00000000-0000-4000-8000-000000000000",
37
+ version: 1,
38
+ insertedAt: Temporal.Now.instant(),
39
+ });
40
+ });
41
+
42
+ afterAll(async () => {
43
+ await testDb.cleanup();
44
+ });
45
+
46
+ describe("TenantDb.count() — tenant mode", () => {
47
+ test("B's count returns only B's own rows plus the reference row, never A's rows", async () => {
48
+ const tdbB = createTenantDb(testDb.db, tenantB.tenantId);
49
+ const count = await tdbB.count(table);
50
+ expect(count).toBe(2); // B1 + Reference
51
+ });
52
+
53
+ test("A's count returns only A's own rows plus the reference row", async () => {
54
+ const tdbA = createTenantDb(testDb.db, tenantA.tenantId);
55
+ const count = await tdbA.count(table);
56
+ expect(count).toBe(4); // A1, A2, A3 + Reference
57
+ });
58
+
59
+ test("where filter narrows the count", async () => {
60
+ const tdbA = createTenantDb(testDb.db, tenantA.tenantId);
61
+ const count = await tdbA.count(table, { name: "A1" });
62
+ expect(count).toBe(1);
63
+ });
64
+
65
+ test("B's where: { tenantId: tenantA } cannot widen scope — falls back to B's own scope", async () => {
66
+ const tdbB = createTenantDb(testDb.db, tenantB.tenantId);
67
+ const count = await tdbB.count(table, { tenantId: tenantA.tenantId });
68
+ // The requested tenantId isn't in B's allowed set [B, SYSTEM], so it falls
69
+ // back to B's full enforced scope rather than widening to A.
70
+ expect(count).toBe(2); // B1 + Reference
71
+ });
72
+
73
+ test("where: { tenantId: B } excludes the reference row", async () => {
74
+ const tdbB = createTenantDb(testDb.db, tenantB.tenantId);
75
+ const count = await tdbB.count(table, { tenantId: tenantB.tenantId });
76
+ expect(count).toBe(1); // B1 only
77
+ });
78
+
79
+ test("count matches selectMany(...).length for the same scope", async () => {
80
+ const tdbA = createTenantDb(testDb.db, tenantA.tenantId);
81
+ const [count, rows] = await Promise.all([tdbA.count(table), tdbA.selectMany(table)]);
82
+ expect(count).toBe(rows.length);
83
+ });
84
+ });
85
+
86
+ describe("TenantDb.count() — system mode", () => {
87
+ test("counts all rows across every tenant, unfiltered", async () => {
88
+ const systemDb = createTenantDb(testDb.db, tenantA.tenantId, "system");
89
+ const count = await systemDb.count(table);
90
+ expect(count).toBe(5); // A1, A2, A3, B1, Reference
91
+ });
92
+ });
@@ -15,6 +15,7 @@ import {
15
15
  import {
16
16
  asEntityTableMeta,
17
17
  asRawClient,
18
+ countWhere as bunCountWhere,
18
19
  deleteMany as bunDeleteMany,
19
20
  fetchOne as bunFetchOne,
20
21
  insertOne as bunInsertOne,
@@ -453,6 +454,11 @@ export function createTenantDb(
453
454
  return withDbSpan("select", table, async () => bunFetchOne<T>(db, table, filter));
454
455
  },
455
456
 
457
+ count(table: Table | EntityTableMeta, where?: WhereObject): Promise<number> {
458
+ const filter = readWhere(table, where);
459
+ return withDbSpan("select", table, async () => bunCountWhere(db, table, filter));
460
+ },
461
+
456
462
  insertOne<T = Record<string, unknown>>(
457
463
  table: Table,
458
464
  values: Record<string, unknown>,
@@ -70,7 +70,31 @@ const leasesFeature = defineFeature("leases", (r) => {
70
70
  id: "lease-detail",
71
71
  type: "projectionDetail",
72
72
  query: "leases:query:lease:detail",
73
- layout: { sections: [] },
73
+ layout: {
74
+ sections: [
75
+ {
76
+ kind: "relatedList",
77
+ title: "Items",
78
+ query: "leases:query:lease:items",
79
+ columns: ["name"],
80
+ toolbarActions: [
81
+ {
82
+ kind: "navigate",
83
+ id: "quick-note",
84
+ label: "Quick note",
85
+ screen: "item-toolbar-note",
86
+ params: { map: { leaseId: "id" } },
87
+ },
88
+ {
89
+ kind: "navigate",
90
+ id: "silent-add",
91
+ label: "Silent add",
92
+ screen: "item-toolbar-silent",
93
+ },
94
+ ],
95
+ },
96
+ ],
97
+ },
74
98
  metrics: [
75
99
  {
76
100
  field: "openItems",
@@ -85,6 +109,18 @@ const leasesFeature = defineFeature("leases", (r) => {
85
109
  entity: "item",
86
110
  layout: { sections: [{ title: "x", fields: ["leaseId", "note"] }] },
87
111
  });
112
+ r.screen({
113
+ id: "item-toolbar-note",
114
+ type: "entityEdit",
115
+ entity: "item",
116
+ layout: { sections: [{ title: "x", fields: ["leaseId", "note"] }] },
117
+ });
118
+ r.screen({
119
+ id: "item-toolbar-silent",
120
+ type: "entityEdit",
121
+ entity: "item",
122
+ layout: { sections: [{ title: "x", fields: ["leaseId", "note"] }] },
123
+ });
88
124
  r.screen({
89
125
  id: "record-payment",
90
126
  type: "actionForm",
@@ -150,4 +186,12 @@ describe("buildAppSchema — urlPrefillFields derived from navigate params", ()
150
186
  test("non-form screens carry no urlPrefillFields", () => {
151
187
  expect(urlPrefillFieldsOf("leases", "lease-list")).toBeUndefined();
152
188
  });
189
+
190
+ test("a relatedList toolbarAction's params.map target gets the mapped field", () => {
191
+ expect(urlPrefillFieldsOf("leases", "item-toolbar-note")).toEqual(["leaseId"]);
192
+ });
193
+
194
+ test("a relatedList toolbarAction without params contributes no fields — the allowlist stays an allowlist", () => {
195
+ expect(urlPrefillFieldsOf("leases", "item-toolbar-silent")).toEqual([]);
196
+ });
153
197
  });
@@ -0,0 +1,55 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { parseChangesetChanges } from "../changeset-changes";
3
+
4
+ describe("parseChangesetChanges", () => {
5
+ test("parses a structured change and derives detail from the body", () => {
6
+ const changes = parseChangesetChanges(
7
+ `---\n"@cosmicdrift/kumiko-framework": minor\n---\n\nAdds the new upgrade flow.\n\nMore detail.\n\n<!-- kumiko-changes\nfeature: framework\ntype: improvement\ntitle: Adds the new upgrade flow\n-->`,
8
+ ".changeset/upgrade-flow.md",
9
+ );
10
+
11
+ expect(changes).toEqual([
12
+ {
13
+ feature: "framework",
14
+ type: "improvement",
15
+ title: "Adds the new upgrade flow",
16
+ detail: "More detail.",
17
+ source: ".changeset/upgrade-flow.md",
18
+ },
19
+ ]);
20
+ });
21
+
22
+ test("parses multiple blocks with multiline migration", () => {
23
+ const changes = parseChangesetChanges(
24
+ `---\n"@cosmicdrift/kumiko-framework": minor\n---\n\n<!-- kumiko-changes\nfeature: framework\ntype: breaking\ntitle: Removes the old flow\nmigration: |\n Replace the old call.\n Then run the migration.\n-->\n\n<!-- kumiko-changes\nfeature: sessions\ntype: fix\ntitle: Fixes session cleanup\n-->`,
25
+ ".changeset/two-features.md",
26
+ );
27
+
28
+ expect(changes.map(({ feature, type, migration }) => ({ feature, type, migration }))).toEqual([
29
+ {
30
+ feature: "framework",
31
+ type: "breaking",
32
+ migration: "Replace the old call.\nThen run the migration.",
33
+ },
34
+ { feature: "sessions", type: "fix", migration: undefined },
35
+ ]);
36
+ });
37
+
38
+ test("rejects a breaking change without migration", () => {
39
+ expect(() =>
40
+ parseChangesetChanges(
41
+ `---\n"@cosmicdrift/kumiko-framework": minor\n---\n\n<!-- kumiko-changes\nfeature: framework\ntype: breaking\ntitle: Removes the old flow\n-->`,
42
+ ".changeset/breaking.md",
43
+ ),
44
+ ).toThrow('breaking change "Removes the old flow" missing migration field');
45
+ });
46
+
47
+ test("rejects an unknown type", () => {
48
+ expect(() =>
49
+ parseChangesetChanges(
50
+ `---\n"@cosmicdrift/kumiko-framework": patch\n---\n\n<!-- kumiko-changes\nfeature: framework\ntype: feature\ntitle: Invalid\n-->`,
51
+ ".changeset/invalid.md",
52
+ ),
53
+ ).toThrow("type must be breaking, improvement, or fix");
54
+ });
55
+ });
@@ -52,6 +52,9 @@ function projectionDetailNavigateActions(
52
52
  ...screen.layout.sections.flatMap((section) =>
53
53
  section.kind === "relatedList" ? scopeActions(section.rowActions, undefined) : [],
54
54
  ),
55
+ ...screen.layout.sections.flatMap((section) =>
56
+ section.kind === "relatedList" ? scopeActions(section.toolbarActions, undefined) : [],
57
+ ),
55
58
  ...(screen.metrics ?? []).flatMap((metric) =>
56
59
  typeof metric === "string" || metric.navigate === undefined
57
60
  ? []
@@ -0,0 +1,104 @@
1
+ import { type ChangelogType, validateChangelog } from "./feature-changelog";
2
+
3
+ export type PendingChange = {
4
+ readonly feature: string;
5
+ readonly type: ChangelogType;
6
+ readonly title: string;
7
+ readonly detail?: string;
8
+ readonly migration?: string;
9
+ readonly codemod?: string;
10
+ readonly source: string;
11
+ };
12
+
13
+ const BLOCK_RE = /<!--\s*kumiko-changes\s*\n([\s\S]*?)\n\s*-->/g;
14
+ const TYPE_VALUES = new Set<ChangelogType>(["breaking", "improvement", "fix"]);
15
+ const KEY_RE = /^(feature|type|title|detail|migration|codemod):(?:\s(.*))?$/;
16
+
17
+ function requiredField(fields: ReadonlyMap<string, string>, field: string, source: string): string {
18
+ const value = fields.get(field)?.trim();
19
+ if (!value) throw new Error(`${source}: kumiko-changes ${field} is required`);
20
+ return value;
21
+ }
22
+
23
+ function parseBlock(raw: string, source: string): ReadonlyMap<string, string> {
24
+ const fields = new Map<string, string>();
25
+ const lines = raw.split("\n");
26
+
27
+ for (let index = 0; index < lines.length; index++) {
28
+ const line = lines[index] ?? "";
29
+ if (line.trim() === "") continue;
30
+ const match = KEY_RE.exec(line.trim());
31
+ if (!match) throw new Error(`${source}: invalid kumiko-changes line "${line.trim()}"`);
32
+
33
+ const key = match[1];
34
+ if (!key) throw new Error(`${source}: invalid kumiko-changes field`);
35
+ if (fields.has(key)) throw new Error(`${source}: duplicate kumiko-changes field "${key}"`);
36
+ const value = match[2];
37
+ if (value === "|") {
38
+ const continuation: string[] = [];
39
+ while (index + 1 < lines.length && (lines[index + 1]?.startsWith(" ") ?? false)) {
40
+ index++;
41
+ const continuationLine = lines[index];
42
+ if (continuationLine) continuation.push(continuationLine.slice(2));
43
+ }
44
+ fields.set(key, continuation.join("\n").trim());
45
+ continue;
46
+ }
47
+ fields.set(key, value ?? "");
48
+ }
49
+
50
+ return fields;
51
+ }
52
+
53
+ function proseWithoutMetadata(markdown: string): string[] {
54
+ const withoutFrontmatter = markdown.replace(/^\s*---\n[\s\S]*?\n---\s*/, "");
55
+ return withoutFrontmatter
56
+ .replace(BLOCK_RE, "")
57
+ .split("\n")
58
+ .map((line) => line.trim())
59
+ .filter((line) => line !== "");
60
+ }
61
+
62
+ /** Parse structured upgrade metadata embedded in a Changeset body. */
63
+ export function parseChangesetChanges(markdown: string, source: string): readonly PendingChange[] {
64
+ const changes: PendingChange[] = [];
65
+ const prose = proseWithoutMetadata(markdown);
66
+ BLOCK_RE.lastIndex = 0;
67
+ let match = BLOCK_RE.exec(markdown);
68
+ while (match !== null) {
69
+ const block = match[1];
70
+ if (!block) throw new Error(`${source}: empty kumiko-changes block`);
71
+ const fields = parseBlock(block, source);
72
+ const feature = requiredField(fields, "feature", source);
73
+ const rawType = requiredField(fields, "type", source);
74
+ if (!TYPE_VALUES.has(rawType as ChangelogType)) {
75
+ throw new Error(`${source}: kumiko-changes type must be breaking, improvement, or fix`);
76
+ }
77
+ const title = fields.get("title")?.trim() || prose[0];
78
+ if (!title) throw new Error(`${source}: kumiko-changes title is required`);
79
+
80
+ const detail =
81
+ fields.get("detail")?.trim() ||
82
+ prose
83
+ .slice(prose.length > 0 ? 1 : 0)
84
+ .join("\n")
85
+ .trim();
86
+ const migration = fields.get("migration")?.trim();
87
+ const codemod = fields.get("codemod")?.trim();
88
+ const change: PendingChange = {
89
+ feature,
90
+ type: rawType as ChangelogType,
91
+ title,
92
+ ...(detail ? { detail } : {}),
93
+ ...(migration ? { migration } : {}),
94
+ ...(codemod ? { codemod } : {}),
95
+ source,
96
+ };
97
+ const validation = validateChangelog({ version: "0.0.0", ...change });
98
+ if (validation.length > 0) throw new Error(`${source}: ${validation.join("; ")}`);
99
+ changes.push(change);
100
+ match = BLOCK_RE.exec(markdown);
101
+ }
102
+
103
+ return changes;
104
+ }
@@ -24,6 +24,7 @@ export {
24
24
  SETTINGS_HUB_WORKSPACE,
25
25
  } from "./build-config-feature-schema";
26
26
  export { buildTarget } from "./build-target";
27
+ export { type PendingChange, parseChangesetChanges } from "./changeset-changes";
27
28
  export {
28
29
  access,
29
30
  createSeed,
@@ -13,6 +13,9 @@ const ALLOWED_FILES = new Set([
13
13
  "packages/bundled-features/src/tenant/seeding.ts",
14
14
  "packages/bundled-features/src/tier-engine/feature.ts",
15
15
  "packages/framework/src/event-store/__tests__/unscoped-stream-primitives.guard.test.ts",
16
+ // Fixtures of the AST guard that enforces this same restriction.
17
+ "packages/guards/src/__tests__/guard-fires.test.ts",
18
+ "packages/guards/src/__tests__/guard-restricted-symbols.test.ts",
16
19
  ]);
17
20
 
18
21
  const REPO_ROOT = `${import.meta.dir}/../../../../..`;