@cosmicdrift/kumiko-framework 0.247.0 → 0.249.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.247.0",
3
+ "version": "0.249.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.247.0",
201
+ "@cosmicdrift/kumiko-types": "0.249.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.247.0",
217
+ "@cosmicdrift/kumiko-dispatcher-live": "0.249.0",
218
218
  "bun-types": "^1.3.13",
219
219
  "pino-pretty": "^13.1.3"
220
220
  },
@@ -359,6 +359,91 @@ describe("validateBoot — nav validation", () => {
359
359
  });
360
360
  });
361
361
 
362
+ // fw#2750: createAction + actions[] entries carry the same screen-XOR-target
363
+ // polymorphism as the node itself — the validator must reject the same
364
+ // classes of mistake for actions that it already rejects for nodes.
365
+ describe("validateBoot — nav action validation (fw#2750)", () => {
366
+ test("createAction with neither screen nor target fails boot", () => {
367
+ const feature = defineFeature("shop", (r) => {
368
+ r.nav({
369
+ id: "catalog",
370
+ label: "x",
371
+ createAction: { icon: "plus", label: "New" },
372
+ });
373
+ });
374
+ expect(() => validateBoot([feature])).toThrow(/createAction.*must set exactly one/);
375
+ });
376
+
377
+ test("createAction with both screen and target fails boot", () => {
378
+ const feature = defineFeature("shop", (r) => {
379
+ r.entity("product", productEntity());
380
+ r.screen({
381
+ id: "products",
382
+ type: "entityList",
383
+ entity: "product",
384
+ columns: ["name"],
385
+ });
386
+ r.nav({
387
+ id: "catalog",
388
+ label: "x",
389
+ createAction: {
390
+ icon: "plus",
391
+ label: "New",
392
+ screen: "shop:screen:products",
393
+ target: { featureId: "shop", action: "create" },
394
+ },
395
+ });
396
+ });
397
+ expect(() => validateBoot([feature])).toThrow(/createAction.*must set exactly one/);
398
+ });
399
+
400
+ test("actions[] entry referencing an unregistered screen fails boot", () => {
401
+ const feature = defineFeature("shop", (r) => {
402
+ r.nav({
403
+ id: "catalog",
404
+ label: "x",
405
+ actions: [{ icon: "edit", label: "Edit", screen: "shop:screen:does-not-exist" }],
406
+ });
407
+ });
408
+ expect(() => validateBoot([feature])).toThrow(
409
+ /actions\[0\] references screen "shop:screen:does-not-exist"/,
410
+ );
411
+ });
412
+
413
+ test("createAction with a target-only action still passes boot (regression)", () => {
414
+ const feature = defineFeature("shop", (r) => {
415
+ r.nav({
416
+ id: "catalog",
417
+ label: "x",
418
+ createAction: {
419
+ icon: "plus",
420
+ label: "New",
421
+ target: { featureId: "shop", action: "create" },
422
+ },
423
+ });
424
+ });
425
+ expect(() => validateBoot([feature])).not.toThrow();
426
+ });
427
+
428
+ test("createAction with a screen-only action referencing a registered screen passes boot", () => {
429
+ const feature = defineFeature("shop", (r) => {
430
+ r.entity("product", productEntity());
431
+ r.screen({
432
+ id: "products",
433
+ type: "entityList",
434
+ entity: "product",
435
+ columns: ["name"],
436
+ });
437
+ r.nav({
438
+ id: "catalog",
439
+ label: "x",
440
+ createAction: { icon: "plus", label: "New", screen: "shop:screen:products" },
441
+ });
442
+ });
443
+ expect(() => validateBoot([feature])).not.toThrow();
444
+ });
445
+ });
446
+
362
447
  describe("nav access inversion warning (fw#2640)", () => {
363
448
  test("leaf role-gate disjoint from its parent section's → warns but boot still succeeds", () => {
364
449
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
@@ -0,0 +1,52 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { evalFieldCondition } from "../screen-helpers";
3
+ import type { FieldCondition } from "../types/screen";
4
+
5
+ describe("evalFieldCondition()", () => {
6
+ test("boolean forms pass through unchanged", () => {
7
+ expect(evalFieldCondition(true, {})).toBe(true);
8
+ expect(evalFieldCondition(false, {})).toBe(false);
9
+ });
10
+
11
+ test("eq matches when the field equals the given value", () => {
12
+ const cond: FieldCondition = { field: "status", eq: "active" };
13
+ expect(evalFieldCondition(cond, { status: "active" })).toBe(true);
14
+ expect(evalFieldCondition(cond, { status: "archived" })).toBe(false);
15
+ });
16
+
17
+ test("ne matches when the field differs from the given value", () => {
18
+ const cond: FieldCondition = { field: "status", ne: "archived" };
19
+ expect(evalFieldCondition(cond, { status: "active" })).toBe(true);
20
+ expect(evalFieldCondition(cond, { status: "archived" })).toBe(false);
21
+ });
22
+
23
+ test("in matches when the field is one of the given values", () => {
24
+ const cond: FieldCondition = { field: "status", in: ["draft", "active"] };
25
+ expect(evalFieldCondition(cond, { status: "active" })).toBe(true);
26
+ expect(evalFieldCondition(cond, { status: "archived" })).toBe(false);
27
+ });
28
+
29
+ test("notIn matches when the field is none of the given values", () => {
30
+ const cond: FieldCondition = { field: "status", notIn: ["draft", "archived"] };
31
+ expect(evalFieldCondition(cond, { status: "active" })).toBe(true);
32
+ expect(evalFieldCondition(cond, { status: "draft" })).toBe(false);
33
+ });
34
+
35
+ test("empty in is always false", () => {
36
+ const cond: FieldCondition = { field: "status", in: [] };
37
+ expect(evalFieldCondition(cond, { status: "active" })).toBe(false);
38
+ expect(evalFieldCondition(cond, {})).toBe(false);
39
+ });
40
+
41
+ test("empty notIn is always true", () => {
42
+ const cond: FieldCondition = { field: "status", notIn: [] };
43
+ expect(evalFieldCondition(cond, { status: "active" })).toBe(true);
44
+ expect(evalFieldCondition(cond, {})).toBe(true);
45
+ });
46
+
47
+ test("a missing field is undefined — in false, notIn true", () => {
48
+ const values: Record<string, unknown> = {};
49
+ expect(evalFieldCondition({ field: "status", in: ["active"] }, values)).toBe(false);
50
+ expect(evalFieldCondition({ field: "status", notIn: ["active"] }, values)).toBe(true);
51
+ });
52
+ });
@@ -21,9 +21,10 @@ function throwIfFunction(value: unknown, message: string): void {
21
21
  // rowActions/toolbarActions carry row-context extractors (payload/params),
22
22
  // static visibility conditions and navigate entityId — all declarative-DSL-
23
23
  // only fields (RowFieldExtractor's `{ pick }`/`{ map }`, FieldCondition's
24
- // `{ field, eq }`/`{ field, ne }`, plain strings). A function literal here
25
- // does not type-check against these structural DSL types — it only reaches
26
- // here via a leaked `any`/`as any`, which this runtime check backstops.
24
+ // `{ field, eq }`/`{ field, ne }`/`{ field, in }`/`{ field, notIn }`, plain
25
+ // strings). A function literal here does not type-check against these
26
+ // structural DSL types — it only reaches here via a leaked `any`/`as any`,
27
+ // which this runtime check backstops.
27
28
  const ACTION_FUNCTION_FIELDS = ["payload", "params", "entityId", "visible"] as const;
28
29
 
29
30
  function validateActionNoFunctions(
@@ -38,7 +39,7 @@ function validateActionNoFunctions(
38
39
  record[field],
39
40
  `[Feature ${featureName}] Screen "${screenId}" ${actionKind} "${action.id}" ${field} ` +
40
41
  `is a function — ${FUNCTION_DROPPED_HINT} Use the declarative DSL ({ pick }, { map }, ` +
41
- `"fieldName", { field, eq }) instead.`,
42
+ `"fieldName", { field, eq }/{ field, in }) instead.`,
42
43
  );
43
44
  }
44
45
  }
@@ -78,7 +79,7 @@ function validateEditFieldNoFunctions(
78
79
  record[key],
79
80
  `[Feature ${featureName}] Screen "${screenId}" (${screenType}) field "${normalized.field}" ` +
80
81
  `${key} is a function — ${FUNCTION_DROPPED_HINT} Use a FieldCondition ` +
81
- `(boolean or { field, eq }/{ field, ne }) instead.`,
82
+ `(boolean or { field, eq }/{ field, ne }/{ field, in }/{ field, notIn }) instead.`,
82
83
  );
83
84
  }
84
85
  throwIfFunction(
@@ -63,6 +63,42 @@ export function validateNavs(
63
63
  }
64
64
  }
65
65
  }
66
+ if (navDef.createAction !== undefined) {
67
+ validateTreeAction(feature.name, navId, "createAction", navDef.createAction, allScreenQns);
68
+ }
69
+ for (const [i, action] of (navDef.actions ?? []).entries()) {
70
+ validateTreeAction(feature.name, navId, `actions[${i}]`, action, allScreenQns);
71
+ }
72
+ }
73
+ }
74
+
75
+ // A TreeAction (createAction or an actions[] entry) navigates via `screen`
76
+ // XOR dispatches via `target` — same polymorphism as the node's own
77
+ // `screen`/`target`. Without this check an action with neither is a
78
+ // Hover-Icon that does nothing; one with both is ambiguous about which
79
+ // click-mode wins.
80
+ function validateTreeAction(
81
+ featureName: string,
82
+ navId: string,
83
+ actionPath: string,
84
+ action: { readonly screen?: string; readonly target?: unknown },
85
+ allScreenQns: ReadonlySet<string>,
86
+ ): void {
87
+ const { screen, target } = action;
88
+ const hasScreen = screen !== undefined;
89
+ const hasTarget = target !== undefined;
90
+ if (hasScreen === hasTarget) {
91
+ throw new Error(
92
+ `[Feature ${featureName}] Nav entry "${navId}" ${actionPath} must set exactly one of ` +
93
+ `"screen"/"target" (${hasScreen ? "both are set" : "neither is set"}).`,
94
+ );
95
+ }
96
+ if (screen !== undefined && !allScreenQns.has(screen)) {
97
+ throw new Error(
98
+ `[Feature ${featureName}] Nav entry "${navId}" ${actionPath} references screen ` +
99
+ `"${screen}" which is not registered. Expected a qualified name of the form ` +
100
+ `"<feature>:screen:<id>" pointing at an r.screen() declaration.`,
101
+ );
66
102
  }
67
103
  }
68
104
 
@@ -56,6 +56,8 @@ export function evalFieldCondition(cond: FieldCondition, values: Record<string,
56
56
  if (typeof cond === "boolean") return cond;
57
57
  const val = values[cond.field];
58
58
  if ("eq" in cond) return val === cond.eq;
59
+ if ("in" in cond) return cond.in.includes(val);
60
+ if ("notIn" in cond) return !cond.notIn.includes(val);
59
61
  return val !== cond.ne;
60
62
  }
61
63