@jskit-ai/http-web 0.1.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.
Files changed (110) hide show
  1. package/fixtures/crud-list-date-filters/App.vue +107 -0
  2. package/fixtures/crud-list-date-filters/index.html +12 -0
  3. package/fixtures/crud-list-date-filters/main.js +24 -0
  4. package/fixtures/crud-list-date-filters/vite.config.mjs +18 -0
  5. package/package.json +150 -0
  6. package/src/client/bulkActions.js +47 -0
  7. package/src/client/components/CrudAddEditScreen.vue +186 -0
  8. package/src/client/components/CrudDeleteAction.vue +93 -0
  9. package/src/client/components/CrudListBulkActionSurface.vue +126 -0
  10. package/src/client/components/CrudListDateFilterControl.vue +188 -0
  11. package/src/client/components/CrudListFilterSurface.vue +388 -0
  12. package/src/client/components/CrudListRecordActionMenu.vue +120 -0
  13. package/src/client/components/CrudListScreen.vue +501 -0
  14. package/src/client/components/CrudViewScreen.vue +197 -0
  15. package/src/client/composables/crud/crudBindingSupport.js +75 -0
  16. package/src/client/composables/crud/crudHttpClientSupport.js +57 -0
  17. package/src/client/composables/crud/crudJsonApiTransportSupport.js +145 -0
  18. package/src/client/composables/crud/crudLookupFieldLabelSupport.js +151 -0
  19. package/src/client/composables/crud/crudLookupFieldRuntime.js +251 -0
  20. package/src/client/composables/crud/crudSchemaFormHelpers.js +464 -0
  21. package/src/client/composables/internal/crudListFilterLookupSupport.js +161 -0
  22. package/src/client/composables/internal/crudListParentTitleSupport.js +171 -0
  23. package/src/client/composables/internal/useOperationScope.js +144 -0
  24. package/src/client/composables/records/useAddEdit.js +224 -0
  25. package/src/client/composables/records/useCrudAddEdit.js +227 -0
  26. package/src/client/composables/records/useCrudList.js +101 -0
  27. package/src/client/composables/records/useCrudView.js +47 -0
  28. package/src/client/composables/records/useList.js +500 -0
  29. package/src/client/composables/records/useView.js +164 -0
  30. package/src/client/composables/runtime/addEditUiRuntime.js +130 -0
  31. package/src/client/composables/runtime/listUiRuntime.js +123 -0
  32. package/src/client/composables/runtime/modelStateHelpers.js +90 -0
  33. package/src/client/composables/runtime/operationAdapters.js +34 -0
  34. package/src/client/composables/runtime/operationUiHelpers.js +125 -0
  35. package/src/client/composables/runtime/operationValidationHelpers.js +51 -0
  36. package/src/client/composables/runtime/useAddEditCore.js +112 -0
  37. package/src/client/composables/runtime/useCommandCore.js +123 -0
  38. package/src/client/composables/runtime/useEndpointResource.js +199 -0
  39. package/src/client/composables/runtime/useFieldErrorBag.js +61 -0
  40. package/src/client/composables/runtime/useListCore.js +112 -0
  41. package/src/client/composables/runtime/useUiFeedback.js +98 -0
  42. package/src/client/composables/runtime/useViewCore.js +93 -0
  43. package/src/client/composables/runtime/viewUiRuntime.js +96 -0
  44. package/src/client/composables/support/errorMessageHelpers.js +66 -0
  45. package/src/client/composables/support/listQueryParamSupport.js +473 -0
  46. package/src/client/composables/support/listSearchSupport.js +70 -0
  47. package/src/client/composables/support/refValueHelpers.js +19 -0
  48. package/src/client/composables/support/requestQueryRuntimeSupport.js +141 -0
  49. package/src/client/composables/support/resourceLoadStateHelpers.js +208 -0
  50. package/src/client/composables/support/routeTemplateHelpers.js +285 -0
  51. package/src/client/composables/support/scopeHelpers.js +145 -0
  52. package/src/client/composables/useAccess.js +109 -0
  53. package/src/client/composables/useCommand.js +118 -0
  54. package/src/client/composables/useCrudAddEditScreen.js +88 -0
  55. package/src/client/composables/useCrudDeleteAction.js +160 -0
  56. package/src/client/composables/useCrudListBulkActions.js +147 -0
  57. package/src/client/composables/useCrudListFilterLookups.js +146 -0
  58. package/src/client/composables/useCrudListFilters.js +339 -0
  59. package/src/client/composables/useCrudListParentTitle.js +151 -0
  60. package/src/client/composables/useCrudListRowActions.js +144 -0
  61. package/src/client/composables/useCrudListScreen.js +237 -0
  62. package/src/client/composables/useCrudViewScreen.js +77 -0
  63. package/src/client/composables/usePagedCollection.js +181 -0
  64. package/src/client/composables/useRealtimeQueryInvalidation.js +156 -0
  65. package/src/client/composables/useScopeRuntime.js +135 -0
  66. package/src/client/filters.js +15 -0
  67. package/src/client/index.js +24 -0
  68. package/src/client/lib/httpClient.js +47 -0
  69. package/src/client/lib/permissions.js +34 -0
  70. package/src/client/rowActions.js +47 -0
  71. package/src/client/support/contractGuards.js +34 -0
  72. package/src/client/support/crudListDateFilterSupport.js +91 -0
  73. package/test/addEditUiRuntime.test.js +110 -0
  74. package/test/crudBindingSupport.test.js +110 -0
  75. package/test/crudHttpClientSupport.test.js +77 -0
  76. package/test/crudJsonApiTransportSupport.test.js +179 -0
  77. package/test/crudListBulkActionSurface.test.js +27 -0
  78. package/test/crudListDateFilterSupport.test.js +92 -0
  79. package/test/crudListDateFilterSurface.browser.test.js +182 -0
  80. package/test/crudListFilterSurface.test.js +90 -0
  81. package/test/crudLookupFieldRuntime.test.js +264 -0
  82. package/test/crudScreenComponents.test.js +110 -0
  83. package/test/errorIntentContract.test.js +31 -0
  84. package/test/errorMessageHelpers.test.js +28 -0
  85. package/test/exportsContract.test.js +68 -0
  86. package/test/listQueryParamSupport.test.js +223 -0
  87. package/test/listUiRuntime.test.js +102 -0
  88. package/test/operationValidationHelpers.test.js +64 -0
  89. package/test/packageBoundary.test.js +31 -0
  90. package/test/permissions.test.js +35 -0
  91. package/test/refValueHelpers.test.js +14 -0
  92. package/test/requestTransportOptions.test.js +457 -0
  93. package/test/resourceLoadStateHelpers.test.js +189 -0
  94. package/test/routeTemplateHelpers.test.js +85 -0
  95. package/test/scopeHelpers.test.js +57 -0
  96. package/test/useAddEditCore.test.js +124 -0
  97. package/test/useAddEditRequestQueryParams.test.js +190 -0
  98. package/test/useCrudAddEdit.test.js +415 -0
  99. package/test/useCrudDeleteAction.test.js +139 -0
  100. package/test/useCrudListBulkActions.test.js +65 -0
  101. package/test/useCrudListFilterLookups.test.js +114 -0
  102. package/test/useCrudListFilters.test.js +293 -0
  103. package/test/useCrudListParentTitle.test.js +262 -0
  104. package/test/useCrudListRowActions.test.js +77 -0
  105. package/test/useListRouteInitialization.test.js +337 -0
  106. package/test/useListSearchSupport.test.js +61 -0
  107. package/test/usePagedCollection.test.js +53 -0
  108. package/test/useViewRequestQueryParams.test.js +20 -0
  109. package/test/viewCoreLoading.test.js +44 -0
  110. package/test/viewUiRuntime.test.js +95 -0
@@ -0,0 +1,91 @@
1
+ const DATE_ONLY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/u;
2
+
3
+ function parseDateOnlyValue(value = "") {
4
+ const match = DATE_ONLY_PATTERN.exec(String(value || "").trim());
5
+ if (!match) {
6
+ return null;
7
+ }
8
+
9
+ const year = Number(match[1]);
10
+ const month = Number(match[2]);
11
+ const day = Number(match[3]);
12
+ const date = new Date(0);
13
+ date.setHours(12, 0, 0, 0);
14
+ date.setFullYear(year, month - 1, day);
15
+
16
+ if (
17
+ date.getFullYear() !== year ||
18
+ date.getMonth() !== month - 1 ||
19
+ date.getDate() !== day
20
+ ) {
21
+ return null;
22
+ }
23
+
24
+ return date;
25
+ }
26
+
27
+ function formatDateOnlyValue(value = null) {
28
+ const source = Array.isArray(value) ? value[0] : value;
29
+ const date = source instanceof Date
30
+ ? source
31
+ : parseDateOnlyValue(source);
32
+ if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
33
+ return "";
34
+ }
35
+
36
+ const year = date.getFullYear();
37
+ if (year < 0 || year > 9999) {
38
+ return "";
39
+ }
40
+
41
+ return [
42
+ String(year).padStart(4, "0"),
43
+ String(date.getMonth() + 1).padStart(2, "0"),
44
+ String(date.getDate()).padStart(2, "0")
45
+ ].join("-");
46
+ }
47
+
48
+ function formatDateOnlyDisplay(value = "", { locale = undefined } = {}) {
49
+ const date = parseDateOnlyValue(value);
50
+ if (!date) {
51
+ return "";
52
+ }
53
+
54
+ try {
55
+ return new Intl.DateTimeFormat(locale || undefined, {
56
+ year: "numeric",
57
+ month: "short",
58
+ day: "numeric"
59
+ }).format(date);
60
+ } catch {
61
+ return formatDateOnlyValue(date);
62
+ }
63
+ }
64
+
65
+ function formatCrudListDateFilterChipLabel(filter = {}, rawValue, { locale = undefined } = {}) {
66
+ if (filter.type === "date") {
67
+ const dateLabel = formatDateOnlyDisplay(rawValue, { locale }) || String(rawValue || "");
68
+ return dateLabel ? `${filter.label}: ${dateLabel}` : "";
69
+ }
70
+
71
+ if (filter.type !== "dateRange") {
72
+ return "";
73
+ }
74
+
75
+ const from = formatDateOnlyDisplay(rawValue?.from, { locale }) || String(rawValue?.from || "");
76
+ const to = formatDateOnlyDisplay(rawValue?.to, { locale }) || String(rawValue?.to || "");
77
+ if (from && to) {
78
+ return `${filter.label}: ${from} to ${to}`;
79
+ }
80
+ if (from) {
81
+ return `${filter.label}: from ${from}`;
82
+ }
83
+ return to ? `${filter.label}: to ${to}` : "";
84
+ }
85
+
86
+ export {
87
+ parseDateOnlyValue,
88
+ formatDateOnlyValue,
89
+ formatDateOnlyDisplay,
90
+ formatCrudListDateFilterChipLabel
91
+ };
@@ -0,0 +1,110 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { ref } from "vue";
4
+ import { createAddEditUiRuntime } from "../src/client/composables/runtime/addEditUiRuntime.js";
5
+
6
+ test("createAddEditUiRuntime resolves api/list/cancel paths from route params", () => {
7
+ const runtime = createAddEditUiRuntime({
8
+ recordIdParam: "addressId",
9
+ routeParams: ref({
10
+ contactId: "7",
11
+ addressId: "42"
12
+ }),
13
+ routePath: ref("/contacts/7/addresses/new"),
14
+ apiUrlTemplate: "/crud/contacts/:contactId/addresses/:addressId",
15
+ viewUrlTemplate: "../:addressId",
16
+ listUrlTemplate: ".."
17
+ });
18
+
19
+ assert.equal(runtime.recordId.value, "42");
20
+ assert.equal(runtime.apiSuffix.value, "/crud/contacts/7/addresses/42");
21
+ assert.equal(runtime.listUrl.value, "/contacts/7/addresses");
22
+ assert.equal(runtime.cancelUrl.value, "/contacts/7/addresses/42");
23
+ assert.equal(runtime.resolveParams("../:addressId"), "/contacts/7/addresses/42");
24
+ });
25
+
26
+ test("createAddEditUiRuntime resolves view urls for saved payload ids with nested params", () => {
27
+ const runtime = createAddEditUiRuntime({
28
+ recordIdParam: "addressId",
29
+ routeParams: ref({
30
+ contactId: "7"
31
+ }),
32
+ viewUrlTemplate: "/contacts/:contactId/addresses/:addressId"
33
+ });
34
+
35
+ assert.equal(runtime.resolveSavedViewUrl({ id: 99 }), "/contacts/7/addresses/99");
36
+ });
37
+
38
+ test("createAddEditUiRuntime keeps nested child routes stable when the saved child id matches a parent id", () => {
39
+ const runtime = createAddEditUiRuntime({
40
+ recordIdParam: "addressId",
41
+ routeParams: ref({
42
+ workspaceSlug: "tonymobily",
43
+ contactId: "1"
44
+ }),
45
+ routeParamNames: ref(["workspaceSlug", "contactId"]),
46
+ routePath: ref("/w/tonymobily/admin/contacts/1/addresses/new"),
47
+ viewUrlTemplate: "../:addressId",
48
+ listUrlTemplate: ".."
49
+ });
50
+
51
+ assert.equal(runtime.listUrl.value, "/w/tonymobily/admin/contacts/1/addresses");
52
+ assert.equal(runtime.resolveSavedViewUrl({ id: 1 }), "/w/tonymobily/admin/contacts/1/addresses/1");
53
+ });
54
+
55
+ test("createAddEditUiRuntime resolves edit-page relative list and cancel links", () => {
56
+ const runtime = createAddEditUiRuntime({
57
+ recordIdParam: "addressId",
58
+ routeParams: ref({
59
+ contactId: "7",
60
+ addressId: "42"
61
+ }),
62
+ routePath: ref("/contacts/7/addresses/42/edit"),
63
+ viewUrlTemplate: "..",
64
+ listUrlTemplate: "../.."
65
+ });
66
+
67
+ assert.equal(runtime.listUrl.value, "/contacts/7/addresses");
68
+ assert.equal(runtime.cancelUrl.value, "/contacts/7/addresses/42");
69
+ });
70
+
71
+ test("createAddEditUiRuntime resolves nested edit links from the record scope", () => {
72
+ const runtime = createAddEditUiRuntime({
73
+ recordIdParam: "petId",
74
+ routeParams: ref({
75
+ workspaceSlug: "dogandgroom",
76
+ contactId: "541841",
77
+ petId: "715528"
78
+ }),
79
+ routeParamNames: ref(["workspaceSlug", "contactId", "petId"]),
80
+ routePath: ref("/w/dogandgroom/admin/contacts/541841/pets/715528/edit/advanced"),
81
+ viewUrlTemplate: "..",
82
+ listUrlTemplate: "../.."
83
+ });
84
+
85
+ assert.equal(runtime.cancelUrl.value, "/w/dogandgroom/admin/contacts/541841/pets/715528");
86
+ assert.equal(runtime.listUrl.value, "/w/dogandgroom/admin/contacts/541841/pets");
87
+ });
88
+
89
+ test("createAddEditUiRuntime supports custom saved-record selector", () => {
90
+ const runtime = createAddEditUiRuntime({
91
+ recordIdParam: "addressId",
92
+ routeParams: ref({
93
+ contactId: "7"
94
+ }),
95
+ viewUrlTemplate: "/contacts/:contactId/addresses/:addressId",
96
+ saveRecordIdSelector: (payload = {}) => payload.uuid
97
+ });
98
+
99
+ assert.equal(runtime.resolveSavedViewUrl({ uuid: "abc-123" }), "/contacts/7/addresses/abc-123");
100
+ });
101
+
102
+ test("createAddEditUiRuntime validates route parameter names", () => {
103
+ assert.throws(
104
+ () =>
105
+ createAddEditUiRuntime({
106
+ recordIdParam: "record-id"
107
+ }),
108
+ /recordIdParam "record-id" is invalid/
109
+ );
110
+ });
@@ -0,0 +1,110 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { ref } from "vue";
4
+ import {
5
+ CRUD_BINDING_MODE_ROUTE,
6
+ CRUD_BINDING_MODE_MERGE,
7
+ CRUD_BINDING_MODE_EXPLICIT,
8
+ CRUD_BINDING_MODE_NONE,
9
+ normalizeCrudBindingMode,
10
+ resolveCrudBoundValues
11
+ } from "../src/client/composables/crud/crudBindingSupport.js";
12
+
13
+ test("normalizeCrudBindingMode defaults invalid values to route", () => {
14
+ assert.equal(normalizeCrudBindingMode(""), CRUD_BINDING_MODE_ROUTE);
15
+ assert.equal(normalizeCrudBindingMode("unknown"), CRUD_BINDING_MODE_ROUTE);
16
+ assert.equal(normalizeCrudBindingMode("merge"), CRUD_BINDING_MODE_MERGE);
17
+ assert.equal(normalizeCrudBindingMode("explicit"), CRUD_BINDING_MODE_EXPLICIT);
18
+ assert.equal(normalizeCrudBindingMode("none"), CRUD_BINDING_MODE_NONE);
19
+ });
20
+
21
+ test("resolveCrudBoundValues returns route values in route mode", () => {
22
+ const values = resolveCrudBoundValues({
23
+ binding: {
24
+ mode: "route",
25
+ values: {
26
+ contactId: "22"
27
+ }
28
+ },
29
+ routeValues: {
30
+ contactId: "11"
31
+ }
32
+ });
33
+
34
+ assert.deepEqual(values, {
35
+ contactId: "11"
36
+ });
37
+ });
38
+
39
+ test("resolveCrudBoundValues merges explicit values over route values in merge mode", () => {
40
+ const values = resolveCrudBoundValues({
41
+ binding: {
42
+ mode: "merge",
43
+ values: {
44
+ contactId: "22",
45
+ serviceId: "4"
46
+ }
47
+ },
48
+ routeValues: {
49
+ contactId: "11"
50
+ }
51
+ });
52
+
53
+ assert.deepEqual(values, {
54
+ contactId: "22",
55
+ serviceId: "4"
56
+ });
57
+ });
58
+
59
+ test("resolveCrudBoundValues uses only explicit values in explicit mode", () => {
60
+ const values = resolveCrudBoundValues({
61
+ binding: {
62
+ mode: "explicit",
63
+ values: {
64
+ serviceId: "4"
65
+ }
66
+ },
67
+ routeValues: {
68
+ contactId: "11"
69
+ }
70
+ });
71
+
72
+ assert.deepEqual(values, {
73
+ serviceId: "4"
74
+ });
75
+ });
76
+
77
+ test("resolveCrudBoundValues disables automatic binding in none mode", () => {
78
+ const values = resolveCrudBoundValues({
79
+ binding: {
80
+ mode: "none",
81
+ values: {
82
+ serviceId: "4"
83
+ }
84
+ },
85
+ routeValues: {
86
+ contactId: "11"
87
+ }
88
+ });
89
+
90
+ assert.deepEqual(values, {});
91
+ });
92
+
93
+ test("resolveCrudBoundValues unwraps reactive binding config and values", () => {
94
+ const values = resolveCrudBoundValues({
95
+ binding: ref({
96
+ mode: "merge",
97
+ values: ref({
98
+ serviceId: "4"
99
+ })
100
+ }),
101
+ routeValues: {
102
+ contactId: "11"
103
+ }
104
+ });
105
+
106
+ assert.deepEqual(values, {
107
+ contactId: "11",
108
+ serviceId: "4"
109
+ });
110
+ });
@@ -0,0 +1,77 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import {
5
+ normalizeCrudApiAccess,
6
+ resolveCrudHttpClient
7
+ } from "../src/client/composables/crud/crudHttpClientSupport.js";
8
+ import {
9
+ __testables as crudListScreenTestables
10
+ } from "../src/client/composables/useCrudListScreen.js";
11
+
12
+ test("resolveCrudHttpClient injects per-request CSRF opt-out for public resources", async () => {
13
+ const calls = [];
14
+ const configuredClient = {
15
+ async request(url, options) {
16
+ calls.push([url, options]);
17
+ return { ok: true };
18
+ }
19
+ };
20
+ const client = resolveCrudHttpClient({ apiAccess: "public" }, {
21
+ client: configuredClient
22
+ });
23
+
24
+ for (const method of ["POST", "PATCH", "DELETE"]) {
25
+ await client.request("/api/books/1", {
26
+ method,
27
+ csrf: true
28
+ });
29
+ }
30
+
31
+ assert.deepEqual(
32
+ calls.map(([url, options]) => [url, options.method, options.csrf]),
33
+ [
34
+ ["/api/books/1", "POST", false],
35
+ ["/api/books/1", "PATCH", false],
36
+ ["/api/books/1", "DELETE", false]
37
+ ]
38
+ );
39
+ });
40
+
41
+ test("resolveCrudHttpClient preserves the configured client for authenticated resources", () => {
42
+ const configuredClient = {
43
+ request() {}
44
+ };
45
+
46
+ assert.equal(
47
+ resolveCrudHttpClient({ apiAccess: "authenticated" }, { client: configuredClient }),
48
+ configuredClient
49
+ );
50
+ assert.equal(
51
+ resolveCrudHttpClient({}, { client: configuredClient }),
52
+ configuredClient
53
+ );
54
+ assert.equal(normalizeCrudApiAccess(""), "authenticated");
55
+ assert.throws(
56
+ () => resolveCrudHttpClient({ apiAccess: "always" }, { client: configuredClient }),
57
+ /apiAccess must be one of: authenticated, public/
58
+ );
59
+ });
60
+
61
+ test("CRUD list row and bulk action context carries the resource-aware client", () => {
62
+ const records = {
63
+ reload() {}
64
+ };
65
+ const client = {
66
+ request() {}
67
+ };
68
+
69
+ assert.deepEqual(
70
+ crudListScreenTestables.buildCrudListActionContext(records, client),
71
+ {
72
+ records,
73
+ reload: records.reload,
74
+ client
75
+ }
76
+ );
77
+ });
@@ -0,0 +1,179 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createSchema } from "json-rest-schema";
4
+ import {
5
+ inferCrudJsonApiTransport,
6
+ inferCrudLookupJsonApiTransport,
7
+ resolveCrudJsonApiTransport,
8
+ resolveLookupFieldMap
9
+ } from "../src/client/composables/crud/crudJsonApiTransportSupport.js";
10
+
11
+ const resource = {
12
+ namespace: "pets",
13
+ contract: {
14
+ lookup: {
15
+ containerKey: "lookups"
16
+ }
17
+ },
18
+ operations: {
19
+ view: {
20
+ output: {
21
+ schema: createSchema({
22
+ id: {
23
+ type: "string",
24
+ required: true
25
+ },
26
+ contactId: {
27
+ type: "string",
28
+ required: true,
29
+ belongsTo: "contacts",
30
+ as: "contact"
31
+ },
32
+ breedId: {
33
+ type: "string",
34
+ nullable: true,
35
+ belongsTo: "breeds",
36
+ as: "breed"
37
+ }
38
+ })
39
+ }
40
+ }
41
+ }
42
+ };
43
+
44
+ test("inferCrudJsonApiTransport infers collection transport for CRUD lists", () => {
45
+ assert.deepEqual(
46
+ inferCrudJsonApiTransport(resource, {
47
+ mode: "list"
48
+ }),
49
+ {
50
+ kind: "jsonapi-resource",
51
+ responseType: "pets",
52
+ responseKind: "collection"
53
+ }
54
+ );
55
+ });
56
+
57
+ test("inferCrudJsonApiTransport infers record request/response transport for CRUD add/edit", () => {
58
+ assert.deepEqual(
59
+ inferCrudJsonApiTransport(resource, {
60
+ mode: "add-edit",
61
+ operationName: "patch"
62
+ }),
63
+ {
64
+ kind: "jsonapi-resource",
65
+ requestType: "pets",
66
+ responseType: "pets",
67
+ responseKind: "record"
68
+ }
69
+ );
70
+ });
71
+
72
+ test("inferCrudJsonApiTransport infers record response transport for CRUD delete", () => {
73
+ assert.deepEqual(
74
+ inferCrudJsonApiTransport(resource, {
75
+ mode: "delete"
76
+ }),
77
+ {
78
+ kind: "jsonapi-resource",
79
+ responseType: "pets",
80
+ responseKind: "record"
81
+ }
82
+ );
83
+ });
84
+
85
+ test("inferCrudLookupJsonApiTransport infers collection transport from lookup namespace", () => {
86
+ assert.deepEqual(
87
+ inferCrudLookupJsonApiTransport({
88
+ namespace: "services"
89
+ }),
90
+ {
91
+ kind: "jsonapi-resource",
92
+ responseType: "services",
93
+ responseKind: "collection"
94
+ }
95
+ );
96
+ });
97
+
98
+ test("inferCrudLookupJsonApiTransport infers collection transport from lookup apiPath", () => {
99
+ assert.deepEqual(
100
+ inferCrudLookupJsonApiTransport({
101
+ apiPath: "/contact-roles"
102
+ }),
103
+ {
104
+ kind: "jsonapi-resource",
105
+ responseType: "contact-roles",
106
+ responseKind: "collection"
107
+ }
108
+ );
109
+ });
110
+
111
+ test("inferCrudLookupJsonApiTransport returns null without a lookup namespace", () => {
112
+ assert.equal(
113
+ inferCrudLookupJsonApiTransport({}),
114
+ null
115
+ );
116
+ });
117
+
118
+ test("resolveLookupFieldMap derives lookup aliases from the shared CRUD resource", () => {
119
+ assert.deepEqual(resolveLookupFieldMap(resource), {
120
+ breed: "breedId",
121
+ contact: "contactId"
122
+ });
123
+ });
124
+
125
+ test("resolveCrudJsonApiTransport infers and enriches JSON:API transport from the resource", () => {
126
+ assert.deepEqual(
127
+ resolveCrudJsonApiTransport(undefined, resource, {
128
+ mode: "list"
129
+ }),
130
+ {
131
+ kind: "jsonapi-resource",
132
+ responseType: "pets",
133
+ responseKind: "collection",
134
+ lookupContainerKey: "lookups",
135
+ lookupFieldMap: {
136
+ breed: "breedId",
137
+ contact: "contactId"
138
+ }
139
+ }
140
+ );
141
+ });
142
+
143
+ test("resolveCrudJsonApiTransport infers record request/response transport for CRUD add/edit", () => {
144
+ assert.deepEqual(
145
+ resolveCrudJsonApiTransport(undefined, resource, {
146
+ mode: "add-edit",
147
+ operationName: "patch"
148
+ }),
149
+ {
150
+ kind: "jsonapi-resource",
151
+ requestType: "pets",
152
+ responseType: "pets",
153
+ responseKind: "record",
154
+ lookupContainerKey: "lookups",
155
+ lookupFieldMap: {
156
+ breed: "breedId",
157
+ contact: "contactId"
158
+ }
159
+ }
160
+ );
161
+ });
162
+
163
+ test("resolveCrudJsonApiTransport rejects explicit CRUD transport overrides", () => {
164
+ assert.throws(
165
+ () =>
166
+ resolveCrudJsonApiTransport(
167
+ {
168
+ kind: "jsonapi-resource",
169
+ responseType: "pets",
170
+ responseKind: "record"
171
+ },
172
+ resource,
173
+ {
174
+ mode: "view"
175
+ }
176
+ ),
177
+ /do not accept explicit transport/
178
+ );
179
+ });
@@ -0,0 +1,27 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import path from "node:path";
4
+ import { readFile } from "node:fs/promises";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
8
+ const PACKAGE_DIR = path.resolve(TEST_DIRECTORY, "..");
9
+
10
+ test("CrudListBulkActionSurface stays adaptive and runtime-owned", async () => {
11
+ const source = await readFile(
12
+ path.join(PACKAGE_DIR, "src", "client", "components", "CrudListBulkActionSurface.vue"),
13
+ "utf8"
14
+ );
15
+
16
+ assert.match(source, /defineProps/);
17
+ assert.match(source, /useDisplay/);
18
+ assert.match(source, /v-if="shouldRender"/);
19
+ assert.match(source, /selectedCount/);
20
+ assert.match(source, /hasActions/);
21
+ assert.match(source, /hasSelection/);
22
+ assert.match(source, /v-menu/);
23
+ assert.match(source, /Bulk actions/);
24
+ assert.match(source, /min-height:\s*48px/);
25
+ assert.doesNotMatch(source, /useCrudList\(/);
26
+ assert.doesNotMatch(source, /apiSuffix|repository|server/);
27
+ });
@@ -0,0 +1,92 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import test from "node:test";
4
+ import {
5
+ parseDateOnlyValue,
6
+ formatDateOnlyValue,
7
+ formatDateOnlyDisplay,
8
+ formatCrudListDateFilterChipLabel
9
+ } from "../src/client/support/crudListDateFilterSupport.js";
10
+
11
+ test("date filter picker values round-trip through the YYYY-MM-DD contract", () => {
12
+ const parsed = parseDateOnlyValue("2026-04-18");
13
+
14
+ assert.ok(parsed instanceof Date);
15
+ assert.equal(parsed.getFullYear(), 2026);
16
+ assert.equal(parsed.getMonth(), 3);
17
+ assert.equal(parsed.getDate(), 18);
18
+ assert.equal(formatDateOnlyValue(parsed), "2026-04-18");
19
+ assert.equal(formatDateOnlyValue([new Date(2026, 4, 9)]), "2026-05-09");
20
+ assert.equal(formatDateOnlyValue("2026-11-03"), "2026-11-03");
21
+ });
22
+
23
+ test("date filter parsing rejects impossible calendar dates", () => {
24
+ assert.equal(parseDateOnlyValue("2026-02-29"), null);
25
+ assert.ok(parseDateOnlyValue("2028-02-29") instanceof Date);
26
+ assert.equal(parseDateOnlyValue("04/18/2026"), null);
27
+ assert.equal(parseDateOnlyValue(""), null);
28
+ assert.equal(formatDateOnlyValue(new Date("invalid")), "");
29
+ });
30
+
31
+ test("date filter display and chip labels are locale-aware without exposing Date strings", () => {
32
+ assert.equal(formatDateOnlyDisplay("2026-04-18", { locale: "en-US" }), "Apr 18, 2026");
33
+ assert.equal(formatDateOnlyDisplay("2026-04-18", { locale: "en-GB" }), "18 Apr 2026");
34
+ assert.equal(
35
+ formatCrudListDateFilterChipLabel(
36
+ { type: "date", label: "Submitted" },
37
+ "2026-04-18",
38
+ { locale: "en-US" }
39
+ ),
40
+ "Submitted: Apr 18, 2026"
41
+ );
42
+ assert.equal(
43
+ formatCrudListDateFilterChipLabel(
44
+ { type: "dateRange", label: "Arrival" },
45
+ { from: "2026-05-04", to: "2026-05-10" },
46
+ { locale: "en-US" }
47
+ ),
48
+ "Arrival: May 4, 2026 to May 10, 2026"
49
+ );
50
+ assert.equal(
51
+ formatCrudListDateFilterChipLabel(
52
+ { type: "dateRange", label: "Arrival" },
53
+ { from: "", to: "2026-05-10" },
54
+ { locale: "en-US" }
55
+ ),
56
+ "Arrival: to May 10, 2026"
57
+ );
58
+ });
59
+
60
+ test("date-only conversion does not shift across time zones", () => {
61
+ const supportModuleUrl = new URL(
62
+ "../src/client/support/crudListDateFilterSupport.js",
63
+ import.meta.url
64
+ ).href;
65
+ const script = `
66
+ import { parseDateOnlyValue, formatDateOnlyValue } from ${JSON.stringify(supportModuleUrl)};
67
+ const parsed = parseDateOnlyValue("2026-01-01");
68
+ process.stdout.write(JSON.stringify({
69
+ value: formatDateOnlyValue(parsed),
70
+ year: parsed.getFullYear(),
71
+ month: parsed.getMonth(),
72
+ day: parsed.getDate()
73
+ }));
74
+ `;
75
+
76
+ for (const timezone of ["UTC", "America/Los_Angeles", "Pacific/Kiritimati"]) {
77
+ const result = spawnSync(process.execPath, ["--input-type=module", "--eval", script], {
78
+ encoding: "utf8",
79
+ env: {
80
+ ...process.env,
81
+ TZ: timezone
82
+ }
83
+ });
84
+ assert.equal(result.status, 0, result.stderr);
85
+ assert.deepEqual(JSON.parse(result.stdout), {
86
+ value: "2026-01-01",
87
+ year: 2026,
88
+ month: 0,
89
+ day: 1
90
+ }, timezone);
91
+ }
92
+ });