@jskit-ai/http-web 0.1.96 → 0.2.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/CHANGELOG.md +96 -0
- package/locales/en.json +112 -0
- package/package.json +8 -7
- package/src/client/components/CrudAddEditScreen.vue +10 -4
- package/src/client/components/CrudDeleteAction.vue +10 -7
- package/src/client/components/CrudListBulkActionSurface.vue +19 -7
- package/src/client/components/CrudListDateFilterControl.vue +10 -5
- package/src/client/components/CrudListFilterControls.vue +25 -17
- package/src/client/components/CrudListFilterSurface.vue +14 -7
- package/src/client/components/CrudListRecordActionMenu.vue +17 -5
- package/src/client/components/CrudListScreen.vue +31 -18
- package/src/client/components/CrudViewScreen.vue +17 -7
- package/src/client/composables/crud/crudLookupFieldRuntime.js +4 -1
- package/src/client/composables/internal/crudListFilterLookupSupport.js +7 -4
- package/src/client/composables/internal/crudListParentTitleSupport.js +6 -3
- package/src/client/composables/records/useAddEdit.js +13 -7
- package/src/client/composables/records/useList.js +6 -3
- package/src/client/composables/records/useView.js +7 -4
- package/src/client/composables/runtime/operationValidationHelpers.js +16 -11
- package/src/client/composables/runtime/useAddEditCore.js +9 -6
- package/src/client/composables/runtime/useCommandCore.js +8 -5
- package/src/client/composables/runtime/useEndpointResource.js +7 -5
- package/src/client/composables/runtime/useListCore.js +5 -2
- package/src/client/composables/runtime/useUiFeedback.js +1 -1
- package/src/client/composables/runtime/useViewCore.js +5 -2
- package/src/client/composables/support/errorMessageHelpers.js +24 -8
- package/src/client/composables/support/listSearchSupport.js +4 -1
- package/src/client/composables/useAccess.js +4 -1
- package/src/client/composables/useCommand.js +5 -4
- package/src/client/composables/useCrudAddEditScreen.js +5 -2
- package/src/client/composables/useCrudDeleteAction.js +6 -3
- package/src/client/composables/useCrudListFilterLookups.js +6 -3
- package/src/client/composables/useCrudListFilters.js +5 -1
- package/src/client/composables/useCrudListParentTitle.js +5 -2
- package/src/client/composables/useCrudListScreen.js +8 -5
- package/src/client/composables/useCrudViewScreen.js +7 -4
- package/src/client/composables/usePagedCollection.js +5 -2
- package/src/client/composables/useScopeRuntime.js +7 -1
- package/src/client/i18n.js +8 -0
- package/src/client/support/crudListDateFilterSupport.js +18 -9
- package/test/crudListBulkActionSurface.test.js +1 -1
- package/test/crudListFilterSurface.test.js +2 -2
- package/test/crudScreenComponents.test.js +1 -1
- package/test/exportsContract.test.js +3 -1
- package/test/i18nCatalog.test.js +16 -0
- package/test/translation.test.js +164 -0
|
@@ -71,8 +71,8 @@ test("CrudListDateFilterControl composes stable Vuetify picker components access
|
|
|
71
71
|
assert.match(source, /v-bind="\{ \.\.\.attrs, \.\.\.activatorProps \}"/);
|
|
72
72
|
assert.match(source, /\["Enter", " ", "ArrowDown"\]/);
|
|
73
73
|
assert.match(source, /role="dialog"/);
|
|
74
|
-
assert.match(source, />\s
|
|
75
|
-
assert.match(source, />\s
|
|
74
|
+
assert.match(source, />\s*\{\{ t\("jskit\.http\.actions\.clear"\) \}\}\s*</u);
|
|
75
|
+
assert.match(source, />\s*\{\{ t\("jskit\.http\.actions\.close"\) \}\}\s*</u);
|
|
76
76
|
assert.doesNotMatch(source, /VDateInput|vuetify\/labs|type="date"/);
|
|
77
77
|
|
|
78
78
|
const { descriptor, errors: parseErrors } = parse(source, { filename: componentPath });
|
|
@@ -95,7 +95,7 @@ test("CRUD screen components own list/view/form chrome centrally", async () => {
|
|
|
95
95
|
listSource,
|
|
96
96
|
/@media \(min-width: 960px\)[\s\S]*\.crud-list-cards\s*\{\s*display:\s*none;[\s\S]*\.crud-list-table\s*\{\s*display:\s*block;[\s\S]*\.crud-list-fab\s*\{\s*display:\s*none;/
|
|
97
97
|
);
|
|
98
|
-
assert.match(listSource,
|
|
98
|
+
assert.match(listSource, /:button-label="t\('jskit\.http\.actions\.more'\)"/);
|
|
99
99
|
assert.match(listSource, /selectableRows/);
|
|
100
100
|
assert.match(
|
|
101
101
|
listSource,
|
|
@@ -49,7 +49,9 @@ test("http-web exports are explicit and aligned with production and generated us
|
|
|
49
49
|
"./client/crudHttpClient",
|
|
50
50
|
"./client/lib/httpClient",
|
|
51
51
|
"./client/lib/permissions",
|
|
52
|
-
"./client/support/contractGuards"
|
|
52
|
+
"./client/support/contractGuards",
|
|
53
|
+
// The generated client bootstrap registers every package's English catalog.
|
|
54
|
+
"./locales/en.json"
|
|
53
55
|
]
|
|
54
56
|
});
|
|
55
57
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
|
|
6
|
+
|
|
7
|
+
const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
|
|
9
|
+
|
|
10
|
+
test("http-web English catalog matches its source", () => {
|
|
11
|
+
const { problems } = evaluateI18nCatalogContract({
|
|
12
|
+
repoRoot: REPO_ROOT,
|
|
13
|
+
packageDir: path.join(REPO_ROOT, "packages", "http-web")
|
|
14
|
+
});
|
|
15
|
+
assert.deepEqual(problems, []);
|
|
16
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { registerHooks } from "node:module";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { compileScript, parse } from "@vue/compiler-sfc";
|
|
6
|
+
import { createSSRApp, defineComponent, h } from "vue";
|
|
7
|
+
import { renderToString } from "vue/server-renderer";
|
|
8
|
+
import { createMemoryHistory, createRouter } from "vue-router";
|
|
9
|
+
import { createI18n } from "vue-i18n";
|
|
10
|
+
import { registerJskitMessages, setJskitI18n } from "@jskit-ai/kernel/client/i18n";
|
|
11
|
+
import { flattenCatalog } from "@jskit-ai/kernel/shared/i18n";
|
|
12
|
+
import en from "../locales/en.json" with { type: "json" };
|
|
13
|
+
import { toUiErrorMessage, toUiFieldErrors } from "../src/client/composables/support/errorMessageHelpers.js";
|
|
14
|
+
import {
|
|
15
|
+
formatCrudListDateFilterChipLabel,
|
|
16
|
+
formatDateOnlyDisplay
|
|
17
|
+
} from "../src/client/support/crudListDateFilterSupport.js";
|
|
18
|
+
|
|
19
|
+
// A server package's catalog, as the generated bootstrap registers it.
|
|
20
|
+
const SERVER_CATALOG = {
|
|
21
|
+
jskit: {
|
|
22
|
+
users: {
|
|
23
|
+
username: {
|
|
24
|
+
taken: "Username {username} is already taken."
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
registerJskitMessages(SERVER_CATALOG);
|
|
30
|
+
|
|
31
|
+
// A test language with every http-web key and the server codes above translated.
|
|
32
|
+
function testLanguageMessages() {
|
|
33
|
+
const messages = {};
|
|
34
|
+
const flat = {
|
|
35
|
+
...flattenCatalog(en),
|
|
36
|
+
...flattenCatalog(SERVER_CATALOG),
|
|
37
|
+
"jskit.errors.not_found": "Not found."
|
|
38
|
+
};
|
|
39
|
+
for (const [key, message] of Object.entries(flat)) {
|
|
40
|
+
let target = messages;
|
|
41
|
+
const segments = key.split(".");
|
|
42
|
+
for (const segment of segments.slice(0, -1)) {
|
|
43
|
+
target = target[segment] ||= {};
|
|
44
|
+
}
|
|
45
|
+
target[segments.at(-1)] = `[xx] ${message}`;
|
|
46
|
+
}
|
|
47
|
+
return messages;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function withTestLanguage(run, locale = "xx") {
|
|
51
|
+
setJskitI18n(createI18n({ legacy: false, locale, messages: { [locale]: testLanguageMessages() } }));
|
|
52
|
+
try {
|
|
53
|
+
return await run();
|
|
54
|
+
} finally {
|
|
55
|
+
setJskitI18n(null);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function importCrudListScreen() {
|
|
60
|
+
const componentUrl = new URL("../src/client/components/CrudListScreen.vue", import.meta.url).href;
|
|
61
|
+
const hooks = registerHooks({
|
|
62
|
+
load(url, context, nextLoad) {
|
|
63
|
+
if (!url.endsWith(".vue")) return nextLoad(url, context);
|
|
64
|
+
if (url !== componentUrl) {
|
|
65
|
+
return { format: "module", shortCircuit: true, source: "export default { render: () => null };" };
|
|
66
|
+
}
|
|
67
|
+
const { descriptor } = parse(readFileSync(new URL(url), "utf8"));
|
|
68
|
+
return {
|
|
69
|
+
format: "module", shortCircuit: true,
|
|
70
|
+
source: compileScript(descriptor, { id: "crud-list-translation", inlineTemplate: true }).content
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
return (await import(componentUrl)).default;
|
|
76
|
+
} finally {
|
|
77
|
+
hooks.deregister();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function renderCrudListScreen(props) {
|
|
82
|
+
const CrudListScreen = await importCrudListScreen();
|
|
83
|
+
const app = createSSRApp({ render: () => h(CrudListScreen, props) });
|
|
84
|
+
const router = createRouter({
|
|
85
|
+
history: createMemoryHistory(), routes: [{ path: "/books", component: { render: () => null } }]
|
|
86
|
+
});
|
|
87
|
+
await router.push("/books");
|
|
88
|
+
app.use(router);
|
|
89
|
+
for (const name of ["VBtn", "VSheet", "VTable", "VTextField", "VSkeletonLoader", "VCheckboxBtn"]) {
|
|
90
|
+
app.component(name, defineComponent({ setup: (_props, { slots }) => () => h("div", slots.default?.()) }));
|
|
91
|
+
}
|
|
92
|
+
return renderToString(app);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
test("API errors render through their code only when the server sent JSKIT's English", async () => {
|
|
96
|
+
const coded = { status: 409, message: "Username ada is already taken.", code: "users.username.taken", params: { username: "ada" } };
|
|
97
|
+
const appSentence = { status: 404, message: "Contact not found.", code: "not_found", params: {} };
|
|
98
|
+
const generic = { status: 404, message: "Not found.", code: "not_found", params: {} };
|
|
99
|
+
|
|
100
|
+
assert.equal(toUiErrorMessage(coded, "Unable to save."), "Username ada is already taken.");
|
|
101
|
+
await withTestLanguage(() => {
|
|
102
|
+
assert.equal(toUiErrorMessage(coded, "Unable to save."), "[xx] Username ada is already taken.");
|
|
103
|
+
assert.equal(toUiErrorMessage(appSentence, "Unable to load."), "Contact not found.");
|
|
104
|
+
assert.equal(toUiErrorMessage(generic), "[xx] Not found.");
|
|
105
|
+
// Specific fallback copy still wins over generic transport wording.
|
|
106
|
+
assert.equal(
|
|
107
|
+
toUiErrorMessage({ status: 500, message: "Request failed with status 500." }, "Unable to save."),
|
|
108
|
+
"Unable to save."
|
|
109
|
+
);
|
|
110
|
+
assert.equal(toUiErrorMessage({}), "[xx] Request failed.");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("field errors render through their codes field by field", async () => {
|
|
115
|
+
const error = {
|
|
116
|
+
fieldErrors: { username: "Username ada is already taken.", email: "Use your work email." },
|
|
117
|
+
fieldErrorCodes: {
|
|
118
|
+
username: { code: "users.username.taken", params: { username: "ada" } },
|
|
119
|
+
email: { code: "users.username.taken", params: { username: "ada" } }
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
assert.deepEqual(toUiFieldErrors(error), error.fieldErrors);
|
|
124
|
+
await withTestLanguage(() => {
|
|
125
|
+
assert.deepEqual(toUiFieldErrors(error), {
|
|
126
|
+
username: "[xx] Username ada is already taken.",
|
|
127
|
+
email: "Use your work email."
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("CRUD list chrome is English by default and follows the active language", async () => {
|
|
133
|
+
const screen = {
|
|
134
|
+
records: { hasMore: true, loadError: "" },
|
|
135
|
+
listPrimaryAction: "/books/new",
|
|
136
|
+
displayRows: [{ key: "1", recordKey: "1", record: { title: "Kindred" } }],
|
|
137
|
+
resolveRecordTitle: (record) => record.title
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const english = await renderCrudListScreen({ screen });
|
|
141
|
+
for (const text of ["Refresh", "New record", "Load more"]) {
|
|
142
|
+
assert.match(english, new RegExp(`>${text}<`, "u"));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await withTestLanguage(async () => {
|
|
146
|
+
const translated = await renderCrudListScreen({ screen });
|
|
147
|
+
for (const text of ["Refresh", "New record", "Load more"]) {
|
|
148
|
+
assert.match(translated, new RegExp(`>\\[xx\\] ${text}<`, "u"));
|
|
149
|
+
}
|
|
150
|
+
const appKeyed = await renderCrudListScreen({ screen, createLabel: "jskit.http.crud.record" });
|
|
151
|
+
assert.match(appKeyed, />\[xx\] Record</u);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("date filters format with the app's active language", async () => {
|
|
156
|
+
const filter = { type: "dateRange", label: "jskit.http.crud.records" };
|
|
157
|
+
await withTestLanguage(() => {
|
|
158
|
+
assert.equal(formatDateOnlyDisplay("2026-04-18"), "18 Apr 2026");
|
|
159
|
+
assert.equal(
|
|
160
|
+
formatCrudListDateFilterChipLabel(filter, { from: "2026-05-04", to: "2026-05-10" }),
|
|
161
|
+
"[xx] [xx] Records: 4 May 2026 to 10 May 2026"
|
|
162
|
+
);
|
|
163
|
+
}, "en-GB");
|
|
164
|
+
});
|