@cosmicdrift/kumiko-framework 0.277.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.
|
|
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.
|
|
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.
|
|
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,17 @@
|
|
|
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
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"version": "0.277.0",
|
|
4
17
|
"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
|
+
});
|
package/src/db/tenant-db.ts
CHANGED
|
@@ -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: {
|
|
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
|
});
|
|
@@ -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
|
? []
|