@cosmicdrift/kumiko-framework 0.275.0 → 0.277.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 +3 -3
- package/src/changes.json +20 -0
- package/src/engine/__tests__/build-app-schema.test.ts +22 -0
- package/src/engine/__tests__/changeset-changes.test.ts +55 -0
- package/src/engine/build-app-schema.ts +5 -0
- package/src/engine/changeset-changes.ts +104 -0
- package/src/engine/constants.ts +9 -0
- package/src/engine/index.ts +2 -0
- package/src/engine/types/index.ts +1 -0
- package/src/event-store/__tests__/unscoped-stream-primitives.guard.test.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.277.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.277.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.277.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.277.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Changesets are the single source for upgrade changelog entries",
|
|
6
|
+
"detail": "The release step folds structured Changeset metadata into changes.json with the actual published version."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.276.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "entityEdit and actionForm screens accept `slots.titleAction`, rendered on the right of the form title.",
|
|
12
|
+
"detail": "`ScreenSlots.titleAction` mounts an `extensionSectionComponents` entry in the form title row (same props as `slots.header`: screenId, entityName, entityId, values). `FormProps.titleAction` carries it to the primitives; the web `DefaultForm` renders it right-aligned next to title and subtitle in `<testId>-title-action`, in both the card and the chromeless layout. Native primitives may ignore it.",
|
|
13
|
+
"migration": "No action required — purely additive."
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"version": "0.275.0",
|
|
4
17
|
"type": "breaking",
|
|
@@ -6,6 +19,13 @@
|
|
|
6
19
|
"detail": "Job handlers no longer receive the unfiltered boot `DbConnection` as `ctx.db`. `JobContext.db` is now a `TenantDb` in \"tenant\" mode, bound to the job's resolved tenant (`_tenantId`, `payload.tenantId`, or `SYSTEM_TENANT_ID` for tenant-less cron jobs). Reads see that tenant plus `SYSTEM_TENANT_ID` reference rows, and writes are scoped to it. `JobDefinition` gains `escapeHatch?: { reason }`: it grants `ctx.db.unsafeRaw(reason)` for that job and reports an `\"unsafe-raw\"` escape-hatch audit event through `_escapeHatchAuditSink` (deduplicated like handler grants). Without it, `ctx.db.unsafeRaw` throws `AccessDeniedError`. `r.systemScope()` features keep `ctx.systemDb` unchanged. `r.job` throws at registration for an `escapeHatch` with an empty reason. Framework `soft-delete` cleanup jobs run on the tenant-filtered `TenantDb` without a grant. Bundled cross-tenant jobs now declare `escapeHatch`: auth-mfa reencrypt, sessions cleanup, form-draft cleanup, secrets rotate, files-tenant-data sweep-orphaned-derivatives, data-retention retention-cleanup, inbound-mail-retention, tenant-lifecycle run-tenant-destruction, and user-data-rights run-export-jobs/run-forget-cleanup. The systemScope features config, jobs and workflow-runner use `ctx.systemDb.unsafeRaw`. The exported `rotateJob` (secrets) and `sweepOrphanedDerivativesJob` (files-tenant-data) take the raw `DbConnection` as a third argument.",
|
|
7
20
|
"migration": "Jobs that only read and write their own tenant through `ctx.db` method calls or `selectMany/fetchOne/insertOne/updateMany/deleteMany(ctx.db, ...)` need no change. A job that treated `ctx.db` as a `DbConnection` (casts, `asRawClient`, `countWhere`, `upsert*`, `incrementCounter`, `createTenantDb(ctx.db, ...)`, `runProjectionsForEvent(..., ctx.db)`, or `\"raw\" in db ? db.raw : db`) must declare the grant and fetch the runner explicitly. Use `r.job({ name, trigger, escapeHatch: { reason: \"<why>\" }, handler: async (payload, ctx) => work(ctx.db.unsafeRaw(\"<why>\")) })`; keep the `unsafeRaw` call inside the inline `handler` next to `escapeHatch` so `guard-escape-hatch-declared` recognizes the declaration. `r.systemScope()` features use `ctx.systemDb.unsafeRaw(reason)` instead. WARNING: a job that is not migrated but passes a foreign `where.tenantId` through `ctx.db` does not fail; the filter silently narrows it to the job's own tenant (`SYSTEM_TENANT_ID` for tenant-less cron jobs), so cross-tenant sweeps silently read nothing. Audit every cross-tenant job. Hand-built `JobContext` objects in tests need `db: createTenantDb(conn, tenantId)` (plus `systemDb` for systemScope jobs). Direct callers of `rotateJob`/`sweepOrphanedDerivativesJob` pass the raw connection as the third argument."
|
|
8
21
|
},
|
|
22
|
+
{
|
|
23
|
+
"version": "0.274.0",
|
|
24
|
+
"type": "improvement",
|
|
25
|
+
"title": "A money field can declare `currency: { kind: \"tenant\" }` to source its currency from the tenant-settings config key.",
|
|
26
|
+
"detail": "`createMoneyField` accepts an optional `currency: MoneyCurrencySource` — a discriminated union (exported from `@cosmicdrift/kumiko-framework/engine/types`), currently only `{ kind: \"tenant\" }`, left room for #2839's later `literal`/`field` variants. The declaration reaches the client app schema (`buildAppSchema`'s field projection). In an entityEdit form (create and update), a rendered money field that declares `{ kind: \"tenant\" }` reads the tenant's currency via the existing `config:query:values` query (key `tenant-settings:config:currency`) instead of `entity.defaultCurrency ?? \"EUR\"`: an empty value's initial amount and currency come from the tenant's setting, and the form waits for that query rather than momentarily showing/submitting `EUR` while it is in flight. A field's already-stored value always keeps its own currency, unaffected by the declaration. A field without the declaration is unchanged.",
|
|
27
|
+
"migration": "No action required — purely additive; a money field without `currency` declared keeps today's `entity.defaultCurrency ?? \"EUR\"` behavior."
|
|
28
|
+
},
|
|
9
29
|
{
|
|
10
30
|
"version": "0.274.0",
|
|
11
31
|
"type": "breaking",
|
|
@@ -622,6 +622,28 @@ describe("buildAppSchema", () => {
|
|
|
622
622
|
expect("defaultCurrency" in app.features[0]!.entities["thing"]!).toBe(false);
|
|
623
623
|
});
|
|
624
624
|
|
|
625
|
+
test("money field's `currency: { kind: 'tenant' }` declaration survives the projection (fw#2933)", () => {
|
|
626
|
+
const entity = {
|
|
627
|
+
defaultCurrency: "USD",
|
|
628
|
+
fields: {
|
|
629
|
+
price: { type: "money", currency: { kind: "tenant" } },
|
|
630
|
+
cost: { type: "money" },
|
|
631
|
+
},
|
|
632
|
+
} as unknown as EntityDefinition;
|
|
633
|
+
|
|
634
|
+
const f = defineFeature("ent", (r) => {
|
|
635
|
+
r.entity("thing", entity);
|
|
636
|
+
});
|
|
637
|
+
const app = buildAppSchema(createRegistry([f]));
|
|
638
|
+
const projected = app.features[0]!.entities["thing"] as unknown as {
|
|
639
|
+
fields: Record<string, Record<string, unknown>>;
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
expect(projected.fields["price"]?.["currency"]).toEqual({ kind: "tenant" });
|
|
643
|
+
expect(projected.fields["cost"]?.["currency"]).toBeUndefined();
|
|
644
|
+
expect(JSON.parse(JSON.stringify(projected))).toEqual(projected);
|
|
645
|
+
});
|
|
646
|
+
|
|
625
647
|
test("text format, timestamp locatedBy, file accept/maxSize, image variants and decimal scale survive the projection", () => {
|
|
626
648
|
// Regression: all of these are read by the edit view-model (password
|
|
627
649
|
// masking, wall-clock input, upload constraints, preview variant, derived
|
|
@@ -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
|
+
});
|
|
@@ -497,6 +497,11 @@ function projectField(fieldDef: FieldDefinition): FieldDefinition {
|
|
|
497
497
|
out["variants"] = def["variants"];
|
|
498
498
|
// decimal, incl. embedded sub-fields: rounding of derived embedded-list cells.
|
|
499
499
|
if (typeof def["scale"] === "number") out["scale"] = def["scale"];
|
|
500
|
+
// money: declared currency source (MoneyCurrencySource, fw#2933) — without
|
|
501
|
+
// it the renderer can't tell a "currency: { kind: 'tenant' }" field apart
|
|
502
|
+
// from an undeclared one and always falls back to entity.defaultCurrency.
|
|
503
|
+
if (isPlainObject(def["currency"]) && isJsonSafeValue(def["currency"]))
|
|
504
|
+
out["currency"] = def["currency"];
|
|
500
505
|
// embedded lists: row-count bounds, computed cells, totals row, and the
|
|
501
506
|
// sibling-money-field totals check (fw#2497).
|
|
502
507
|
if (typeof def["minItems"] === "number") out["minItems"] = def["minItems"];
|
|
@@ -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
|
+
}
|
package/src/engine/constants.ts
CHANGED
|
@@ -97,6 +97,15 @@ export type { ConcurrencyMode };
|
|
|
97
97
|
const _concurrencyModeExhaustive: Record<ConcurrencyMode, unknown> = ConcurrencyModes;
|
|
98
98
|
void _concurrencyModeExhaustive;
|
|
99
99
|
|
|
100
|
+
// --- Money Currency Sources ---
|
|
101
|
+
// Canonical definition lives in kumiko-types/fields (client-safe, next to
|
|
102
|
+
// MoneyCurrencySource) so renderer code can import it without pulling in
|
|
103
|
+
// runtime-only engine code (fw#2937). Re-exported here for server callers
|
|
104
|
+
// already importing framework/engine (bundled-features/src/tenant-settings/
|
|
105
|
+
// constants.ts TenantSettingsConfig.currency reuses this same constant, so
|
|
106
|
+
// the two stay in sync by construction).
|
|
107
|
+
export { TENANT_CURRENCY_CONFIG_KEY } from "@cosmicdrift/kumiko-types/fields";
|
|
108
|
+
|
|
100
109
|
// --- SSE Channels ---
|
|
101
110
|
|
|
102
111
|
export function tenantChannel(tenantId: TenantId): string {
|
package/src/engine/index.ts
CHANGED
|
@@ -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,
|
|
@@ -44,6 +45,7 @@ export {
|
|
|
44
45
|
OnDeleteStrategies,
|
|
45
46
|
SystemHookNames,
|
|
46
47
|
SystemHookPriorities,
|
|
48
|
+
TENANT_CURRENCY_CONFIG_KEY,
|
|
47
49
|
tenantChannel,
|
|
48
50
|
} from "./constants";
|
|
49
51
|
export type { App, AppConfig } from "./create-app";
|
|
@@ -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}/../../../../..`;
|