@cosmicdrift/kumiko-framework 0.207.0 → 0.208.1
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/db/__tests__/event-store-executor-list.integration.test.ts +75 -0
- package/src/db/event-store-executor-read.ts +2 -2
- package/src/engine/__tests__/boot-validator-i18n-keys.test.ts +3 -3
- package/src/engine/boot-validator/i18n-keys.ts +0 -7
- package/src/i18n/__tests__/mail-registry.test.ts +23 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/mail-registry.ts +26 -0
- package/src/i18n/required-surface-keys.ts +3 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.208.1",
|
|
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>",
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
"./package.json": "./package.json"
|
|
191
191
|
},
|
|
192
192
|
"dependencies": {
|
|
193
|
-
"@cosmicdrift/kumiko-types": "0.
|
|
193
|
+
"@cosmicdrift/kumiko-types": "0.208.1",
|
|
194
194
|
"bullmq": "^5.76.7",
|
|
195
195
|
"bun-types": "^1.3.13",
|
|
196
196
|
"hono": "^4.13.1",
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
"zod": "^4.4.3"
|
|
207
207
|
},
|
|
208
208
|
"devDependencies": {
|
|
209
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
209
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.208.1",
|
|
210
210
|
"bun-types": "^1.3.13",
|
|
211
211
|
"pino-pretty": "^13.1.3"
|
|
212
212
|
},
|
|
@@ -126,6 +126,81 @@ describe("event-store-executor.list — offset + totalCount (Tier 2.6d)", () =>
|
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
describe("event-store-executor.list — stable order (#2198)", () => {
|
|
130
|
+
const exec = createEventStoreExecutor(table, entity, { entityName: "pagerItem" });
|
|
131
|
+
|
|
132
|
+
test("offset paging mit identischem sort-Wert: keine Row auf beiden Seiten, Union = alle Rows", async () => {
|
|
133
|
+
// All rows share the same rank value. Postgres picks a Top-N heapsort
|
|
134
|
+
// for LIMIT queries, which is not stable across ties — and different
|
|
135
|
+
// offsets sort differently-sized heaps (LIMIT 3 OFFSET 0 sorts the
|
|
136
|
+
// top 3, LIMIT 3 OFFSET 3 sorts the top 6), so without an id
|
|
137
|
+
// tie-breaker the same row can surface on multiple pages while
|
|
138
|
+
// another is skipped entirely. Needs enough rows + small enough
|
|
139
|
+
// pages to make the heap sizes diverge; 10 rows / page 5 (the
|
|
140
|
+
// previous setup) was too forgiving and stayed green without the fix.
|
|
141
|
+
const total = 25;
|
|
142
|
+
const pageSize = 3;
|
|
143
|
+
for (let i = 0; i < total; i++) {
|
|
144
|
+
await exec.create({ title: `item-${String(i).padStart(3, "0")}`, rank: 1 }, admin, tdb);
|
|
145
|
+
}
|
|
146
|
+
const page1 = await exec.list(
|
|
147
|
+
{ limit: pageSize, offset: 0, sort: "rank", sortDirection: "asc" },
|
|
148
|
+
admin,
|
|
149
|
+
tdb,
|
|
150
|
+
);
|
|
151
|
+
const page2 = await exec.list(
|
|
152
|
+
{ limit: pageSize, offset: pageSize, sort: "rank", sortDirection: "asc" },
|
|
153
|
+
admin,
|
|
154
|
+
tdb,
|
|
155
|
+
);
|
|
156
|
+
const ids1 = page1.rows.map((r) => r["id"]);
|
|
157
|
+
const ids2 = page2.rows.map((r) => r["id"]);
|
|
158
|
+
expect(ids1.filter((id) => ids2.includes(id))).toHaveLength(0);
|
|
159
|
+
|
|
160
|
+
const allIds = new Set<unknown>();
|
|
161
|
+
for (let offset = 0; offset < total; offset += pageSize) {
|
|
162
|
+
const page = await exec.list(
|
|
163
|
+
{ limit: pageSize, offset, sort: "rank", sortDirection: "asc" },
|
|
164
|
+
admin,
|
|
165
|
+
tdb,
|
|
166
|
+
);
|
|
167
|
+
for (const id of page.rows.map((r) => r["id"])) allIds.add(id);
|
|
168
|
+
}
|
|
169
|
+
expect(allIds.size).toBe(total);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("cursor paging ohne sort: jede Row genau einmal", async () => {
|
|
173
|
+
// Plain sequential inserts keep heap physical order == uuidv7 id order,
|
|
174
|
+
// so a Seq Scan without ORDER BY happens to come out sorted anyway and
|
|
175
|
+
// the missing-ORDER-BY bug stays invisible. Delete half the rows and
|
|
176
|
+
// VACUUM to free their heap space, then insert more rows so their
|
|
177
|
+
// (higher) uuidv7 ids get placed into the reused (earlier) pages —
|
|
178
|
+
// now physical scan order diverges from id order.
|
|
179
|
+
const client = asRawClient(testDb.db);
|
|
180
|
+
for (let i = 0; i < 100; i++) {
|
|
181
|
+
await exec.create({ title: `item-${String(i).padStart(3, "0")}`, rank: i }, admin, tdb);
|
|
182
|
+
}
|
|
183
|
+
await client.unsafe(`DELETE FROM read_pager_items WHERE rank::int % 2 = 1`);
|
|
184
|
+
await client.unsafe(`VACUUM read_pager_items`);
|
|
185
|
+
for (let i = 100; i < 150; i++) {
|
|
186
|
+
await exec.create({ title: `item-${String(i).padStart(3, "0")}`, rank: i }, admin, tdb);
|
|
187
|
+
}
|
|
188
|
+
const countRow = await client.unsafe(`SELECT count(*)::int AS c FROM read_pager_items`);
|
|
189
|
+
const total = (countRow as unknown as Array<{ c: number }>)[0]?.c ?? 0;
|
|
190
|
+
|
|
191
|
+
const seenIds: string[] = [];
|
|
192
|
+
let cursor: string | undefined;
|
|
193
|
+
for (let page = 0; page < total + 5; page++) {
|
|
194
|
+
const res = await exec.list({ limit: 3, cursor }, admin, tdb);
|
|
195
|
+
seenIds.push(...res.rows.map((r) => r["id"] as string));
|
|
196
|
+
if (res.nextCursor === null) break;
|
|
197
|
+
cursor = res.nextCursor;
|
|
198
|
+
}
|
|
199
|
+
expect(seenIds).toHaveLength(total);
|
|
200
|
+
expect(new Set(seenIds).size).toBe(total);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
129
204
|
describe("event-store-executor.list — filter (Tier 2.7c)", () => {
|
|
130
205
|
const exec = createEventStoreExecutor(table, entity, { entityName: "pagerItem" });
|
|
131
206
|
|
|
@@ -200,8 +200,8 @@ export function createReadVerbs(ctx: ExecutorContext): Pick<EventStoreExecutor,
|
|
|
200
200
|
|
|
201
201
|
const orderByClause =
|
|
202
202
|
payload.sort && table[payload.sort]
|
|
203
|
-
? ` ORDER BY ${colSql(payload.sort)} ${payload.sortDirection === "desc" ? "DESC" : "ASC"}`
|
|
204
|
-
: ""
|
|
203
|
+
? ` ORDER BY ${colSql(payload.sort)} ${payload.sortDirection === "desc" ? "DESC" : "ASC"}, ${colSql("id")} ASC`
|
|
204
|
+
: ` ORDER BY ${colSql("id")} ASC`;
|
|
205
205
|
const useOffset = !payload.cursor && offset > 0;
|
|
206
206
|
const offsetClause = useOffset ? ` OFFSET ${offset}` : "";
|
|
207
207
|
|
|
@@ -77,15 +77,15 @@ describe("validateBoot — i18n surface keys", () => {
|
|
|
77
77
|
expect(() => validateBoot([feature])).toThrow(/required translation key missing/);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
test("
|
|
80
|
+
test("does not require every locale on every key", () => {
|
|
81
81
|
const feature = defineFeature("demo", (r) => {
|
|
82
82
|
r.nav({ id: "home", label: "demo:nav.home" });
|
|
83
83
|
r.translations({
|
|
84
84
|
keys: {
|
|
85
|
-
"demo:nav.home": { de: "Start"
|
|
85
|
+
"demo:nav.home": { de: "Start" },
|
|
86
86
|
},
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
|
-
expect(() => validateBoot([feature])).toThrow(
|
|
89
|
+
expect(() => validateBoot([feature])).not.toThrow();
|
|
90
90
|
});
|
|
91
91
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildEffectiveTranslationKeys,
|
|
3
3
|
featureHasI18nSurface,
|
|
4
|
-
findTranslationLocaleGaps,
|
|
5
4
|
requiredKeysFromFeature,
|
|
6
5
|
requiredKeysFromNav,
|
|
7
6
|
requiredKeysFromScreen,
|
|
@@ -75,10 +74,4 @@ export function validateI18nSurfaceKeys(features: readonly FeatureDefinition[]):
|
|
|
75
74
|
throw new Error(`[i18n] Settings-Hub: required translation key missing: "${key}"`);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
|
|
79
|
-
for (const gap of findTranslationLocaleGaps(features)) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
`[i18n] Feature "${gap.featureName}": key "${gap.key}" missing locale(s): ${gap.missingLocales.join(", ")}`,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
77
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { hasMailTranslations, mailT, registerMailTranslations } from "../mail-registry";
|
|
3
|
+
|
|
4
|
+
describe("mail-registry", () => {
|
|
5
|
+
registerMailTranslations("en", { "test.hi": "Hello {name}" });
|
|
6
|
+
|
|
7
|
+
test("falls back to English when locale is missing", () => {
|
|
8
|
+
expect(mailT("fr", "test.hi", { name: "Ada" })).toBe("Hello Ada");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("registered locale wins", () => {
|
|
12
|
+
registerMailTranslations("de", { "test.hi": "Hallo {name}" });
|
|
13
|
+
expect(mailT("de", "test.hi", { name: "Ada" })).toBe("Hallo Ada");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("hasMailTranslations is true only for registered locales", () => {
|
|
18
|
+
expect(hasMailTranslations("en")).toBe(true);
|
|
19
|
+
expect(hasMailTranslations("fr")).toBe(false);
|
|
20
|
+
registerMailTranslations("de", { "test.hi": "Hallo {name}" });
|
|
21
|
+
expect(hasMailTranslations("de")).toBe(true);
|
|
22
|
+
expect(hasMailTranslations("de-AT")).toBe(true);
|
|
23
|
+
});
|
package/src/i18n/index.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const tables = new Map<string, Readonly<Record<string, string>>>();
|
|
2
|
+
|
|
3
|
+
export function registerMailTranslations(
|
|
4
|
+
locale: string,
|
|
5
|
+
bundle: Readonly<Record<string, string>>,
|
|
6
|
+
): void {
|
|
7
|
+
const prev = tables.get(locale) ?? {};
|
|
8
|
+
tables.set(locale, { ...prev, ...bundle });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function hasMailTranslations(locale: string): boolean {
|
|
12
|
+
const root = locale.split("-")[0] ?? locale;
|
|
13
|
+
return tables.has(locale) || tables.has(root);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function mailT(
|
|
17
|
+
locale: string,
|
|
18
|
+
key: string,
|
|
19
|
+
params?: Readonly<Record<string, string>>,
|
|
20
|
+
): string {
|
|
21
|
+
const root = locale.split("-")[0] ?? locale;
|
|
22
|
+
const raw =
|
|
23
|
+
tables.get(locale)?.[key] ?? tables.get(root)?.[key] ?? tables.get("en")?.[key] ?? key;
|
|
24
|
+
if (params === undefined) return raw;
|
|
25
|
+
return raw.replace(/\{(\w+)\}/g, (_, name: string) => params[name] ?? `{${name}}`);
|
|
26
|
+
}
|
|
@@ -322,23 +322,9 @@ export type TranslationLocaleGap = {
|
|
|
322
322
|
readonly missingLocales: readonly string[];
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
/** Locale completeness is opt-in via @cosmicdrift/kumiko-locale-* packages. */
|
|
327
326
|
export function findTranslationLocaleGaps(
|
|
328
|
-
|
|
327
|
+
_features: readonly FeatureDefinition[],
|
|
329
328
|
): readonly TranslationLocaleGap[] {
|
|
330
|
-
|
|
331
|
-
for (const feature of features) {
|
|
332
|
-
for (const [localKey, entry] of Object.entries(feature.translations ?? {})) {
|
|
333
|
-
const missing = REQUIRED_LOCALES.filter((locale) => (entry[locale] ?? "").length === 0);
|
|
334
|
-
if (missing.length > 0) {
|
|
335
|
-
gaps.push({
|
|
336
|
-
featureName: feature.name,
|
|
337
|
-
key: localKey,
|
|
338
|
-
missingLocales: missing,
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return gaps;
|
|
329
|
+
return [];
|
|
344
330
|
}
|