@jskit-ai/users-web 0.1.173 → 0.1.175

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 (113) hide show
  1. package/package.json +18 -149
  2. package/src/client/composables/account-settings/accountSettingsAvatarUploadRuntime.js +2 -2
  3. package/src/client/composables/useAccountSettingsRuntime.js +3 -3
  4. package/src/client/index.js +0 -11
  5. package/src/client/providers/UsersWebClientProvider.js +0 -2
  6. package/test/exportsContract.test.js +3 -29
  7. package/test/settingsPlacementContract.test.js +10 -0
  8. package/fixtures/crud-list-date-filters/App.vue +0 -107
  9. package/fixtures/crud-list-date-filters/index.html +0 -12
  10. package/fixtures/crud-list-date-filters/main.js +0 -24
  11. package/fixtures/crud-list-date-filters/vite.config.mjs +0 -18
  12. package/src/client/bulkActions.js +0 -47
  13. package/src/client/components/CrudAddEditScreen.vue +0 -186
  14. package/src/client/components/CrudDeleteAction.vue +0 -93
  15. package/src/client/components/CrudListBulkActionSurface.vue +0 -126
  16. package/src/client/components/CrudListDateFilterControl.vue +0 -188
  17. package/src/client/components/CrudListFilterSurface.vue +0 -388
  18. package/src/client/components/CrudListRecordActionMenu.vue +0 -120
  19. package/src/client/components/CrudListScreen.vue +0 -501
  20. package/src/client/components/CrudViewScreen.vue +0 -197
  21. package/src/client/composables/crud/crudBindingSupport.js +0 -75
  22. package/src/client/composables/crud/crudHttpClientSupport.js +0 -57
  23. package/src/client/composables/crud/crudJsonApiTransportSupport.js +0 -145
  24. package/src/client/composables/crud/crudLookupFieldLabelSupport.js +0 -151
  25. package/src/client/composables/crud/crudLookupFieldRuntime.js +0 -251
  26. package/src/client/composables/crud/crudSchemaFormHelpers.js +0 -464
  27. package/src/client/composables/internal/crudListFilterLookupSupport.js +0 -161
  28. package/src/client/composables/internal/crudListParentTitleSupport.js +0 -171
  29. package/src/client/composables/internal/useOperationScope.js +0 -144
  30. package/src/client/composables/records/useAddEdit.js +0 -224
  31. package/src/client/composables/records/useCrudAddEdit.js +0 -227
  32. package/src/client/composables/records/useCrudList.js +0 -101
  33. package/src/client/composables/records/useCrudView.js +0 -47
  34. package/src/client/composables/records/useList.js +0 -500
  35. package/src/client/composables/records/useView.js +0 -164
  36. package/src/client/composables/runtime/addEditUiRuntime.js +0 -130
  37. package/src/client/composables/runtime/listUiRuntime.js +0 -123
  38. package/src/client/composables/runtime/modelStateHelpers.js +0 -90
  39. package/src/client/composables/runtime/operationAdapters.js +0 -34
  40. package/src/client/composables/runtime/operationUiHelpers.js +0 -125
  41. package/src/client/composables/runtime/operationValidationHelpers.js +0 -51
  42. package/src/client/composables/runtime/useAddEditCore.js +0 -112
  43. package/src/client/composables/runtime/useCommandCore.js +0 -123
  44. package/src/client/composables/runtime/useEndpointResource.js +0 -199
  45. package/src/client/composables/runtime/useFieldErrorBag.js +0 -61
  46. package/src/client/composables/runtime/useListCore.js +0 -112
  47. package/src/client/composables/runtime/useUiFeedback.js +0 -98
  48. package/src/client/composables/runtime/useViewCore.js +0 -93
  49. package/src/client/composables/runtime/viewUiRuntime.js +0 -96
  50. package/src/client/composables/support/errorMessageHelpers.js +0 -66
  51. package/src/client/composables/support/listQueryParamSupport.js +0 -473
  52. package/src/client/composables/support/listSearchSupport.js +0 -70
  53. package/src/client/composables/support/refValueHelpers.js +0 -19
  54. package/src/client/composables/support/requestQueryRuntimeSupport.js +0 -141
  55. package/src/client/composables/support/resourceLoadStateHelpers.js +0 -208
  56. package/src/client/composables/support/routeTemplateHelpers.js +0 -285
  57. package/src/client/composables/support/scopeHelpers.js +0 -145
  58. package/src/client/composables/useAccess.js +0 -109
  59. package/src/client/composables/useCommand.js +0 -118
  60. package/src/client/composables/useCrudAddEditScreen.js +0 -88
  61. package/src/client/composables/useCrudDeleteAction.js +0 -160
  62. package/src/client/composables/useCrudListBulkActions.js +0 -147
  63. package/src/client/composables/useCrudListFilterLookups.js +0 -146
  64. package/src/client/composables/useCrudListFilters.js +0 -339
  65. package/src/client/composables/useCrudListParentTitle.js +0 -151
  66. package/src/client/composables/useCrudListRowActions.js +0 -144
  67. package/src/client/composables/useCrudListScreen.js +0 -237
  68. package/src/client/composables/useCrudViewScreen.js +0 -77
  69. package/src/client/composables/usePagedCollection.js +0 -181
  70. package/src/client/composables/useRealtimeQueryInvalidation.js +0 -156
  71. package/src/client/composables/useScopeRuntime.js +0 -135
  72. package/src/client/filters.js +0 -15
  73. package/src/client/lib/httpClient.js +0 -47
  74. package/src/client/lib/permissions.js +0 -34
  75. package/src/client/rowActions.js +0 -47
  76. package/src/client/support/contractGuards.js +0 -34
  77. package/src/client/support/crudListDateFilterSupport.js +0 -91
  78. package/test/addEditUiRuntime.test.js +0 -110
  79. package/test/crudBindingSupport.test.js +0 -110
  80. package/test/crudHttpClientSupport.test.js +0 -77
  81. package/test/crudJsonApiTransportSupport.test.js +0 -179
  82. package/test/crudListBulkActionSurface.test.js +0 -27
  83. package/test/crudListDateFilterSupport.test.js +0 -92
  84. package/test/crudListDateFilterSurface.browser.test.js +0 -182
  85. package/test/crudListFilterSurface.test.js +0 -90
  86. package/test/crudLookupFieldRuntime.test.js +0 -264
  87. package/test/crudScreenComponents.test.js +0 -117
  88. package/test/errorIntentContract.test.js +0 -31
  89. package/test/errorMessageHelpers.test.js +0 -28
  90. package/test/listQueryParamSupport.test.js +0 -223
  91. package/test/listUiRuntime.test.js +0 -102
  92. package/test/operationValidationHelpers.test.js +0 -64
  93. package/test/permissions.test.js +0 -35
  94. package/test/refValueHelpers.test.js +0 -14
  95. package/test/requestTransportOptions.test.js +0 -457
  96. package/test/resourceLoadStateHelpers.test.js +0 -189
  97. package/test/routeTemplateHelpers.test.js +0 -85
  98. package/test/scopeHelpers.test.js +0 -57
  99. package/test/useAddEditCore.test.js +0 -124
  100. package/test/useAddEditRequestQueryParams.test.js +0 -190
  101. package/test/useCrudAddEdit.test.js +0 -415
  102. package/test/useCrudDeleteAction.test.js +0 -139
  103. package/test/useCrudListBulkActions.test.js +0 -65
  104. package/test/useCrudListFilterLookups.test.js +0 -114
  105. package/test/useCrudListFilters.test.js +0 -293
  106. package/test/useCrudListParentTitle.test.js +0 -262
  107. package/test/useCrudListRowActions.test.js +0 -77
  108. package/test/useListRouteInitialization.test.js +0 -337
  109. package/test/useListSearchSupport.test.js +0 -61
  110. package/test/usePagedCollection.test.js +0 -53
  111. package/test/useViewRequestQueryParams.test.js +0 -20
  112. package/test/viewCoreLoading.test.js +0 -44
  113. package/test/viewUiRuntime.test.js +0 -95
@@ -1,130 +0,0 @@
1
- import { computed, unref } from "vue";
2
- import { asPlainObject } from "../support/scopeHelpers.js";
3
- import {
4
- normalizeRouteParamName,
5
- resolveRouteParamsSource,
6
- resolveScopedRoutePathname,
7
- resolveRouteTemplateLocation,
8
- toRouteParamValue
9
- } from "../support/routeTemplateHelpers.js";
10
-
11
- function toResolvedRecordId({ routeParams, recordIdParam, routeRecordId }) {
12
- const explicitRecordId = toRouteParamValue(
13
- typeof routeRecordId === "function" ? routeRecordId() : unref(routeRecordId)
14
- );
15
- if (explicitRecordId) {
16
- return explicitRecordId;
17
- }
18
-
19
- return toRouteParamValue(routeParams[recordIdParam]);
20
- }
21
-
22
- function resolveSavedRecordId(payload, saveRecordIdSelector) {
23
- const sourcePayload = asPlainObject(payload);
24
- if (typeof saveRecordIdSelector === "function") {
25
- return toRouteParamValue(saveRecordIdSelector(sourcePayload));
26
- }
27
-
28
- return toRouteParamValue(sourcePayload.id);
29
- }
30
-
31
- function createAddEditUiRuntime({
32
- recordIdParam = "recordId",
33
- routeParams = null,
34
- routeParamNames = null,
35
- routePath = "",
36
- routeRecordId = null,
37
- apiUrlTemplate = "",
38
- viewUrlTemplate = "",
39
- listUrlTemplate = "",
40
- saveRecordIdSelector = null
41
- } = {}) {
42
- const normalizedRecordIdParam = normalizeRouteParamName(recordIdParam, {
43
- context: "useAddEdit recordIdParam"
44
- });
45
- const normalizedApiUrlTemplate = String(apiUrlTemplate || "").trim();
46
- const normalizedViewUrlTemplate = String(viewUrlTemplate || "").trim();
47
- const normalizedListUrlTemplate = String(listUrlTemplate || "").trim();
48
-
49
- function resolveTemplatePath(urlTemplate = "", extraParams = {}) {
50
- const normalizedTemplate = String(urlTemplate || "").trim();
51
- if (!normalizedTemplate) {
52
- return "";
53
- }
54
-
55
- const currentRouteParams = resolveRouteParamsSource(routeParams);
56
- const sourceParams = {
57
- ...currentRouteParams,
58
- ...asPlainObject(extraParams)
59
- };
60
- const currentRouteRecordId = toResolvedRecordId({
61
- routeParams: currentRouteParams,
62
- recordIdParam: normalizedRecordIdParam,
63
- routeRecordId
64
- });
65
- const resolvedRecordId = toRouteParamValue(sourceParams[normalizedRecordIdParam]) ||
66
- currentRouteRecordId;
67
- sourceParams[normalizedRecordIdParam] = resolvedRecordId;
68
- const currentPathname = resolveScopedRoutePathname({
69
- currentPathname: routePath,
70
- params: currentRouteParams,
71
- orderedParamNames: routeParamNames,
72
- anchorParamName: normalizedRecordIdParam,
73
- anchorParamValue: currentRouteRecordId,
74
- anchorMode: "after"
75
- });
76
-
77
- return resolveRouteTemplateLocation(normalizedTemplate, {
78
- params: sourceParams,
79
- currentPathname
80
- });
81
- }
82
-
83
- const recordId = computed(() =>
84
- toResolvedRecordId({
85
- routeParams: resolveRouteParamsSource(routeParams),
86
- recordIdParam: normalizedRecordIdParam,
87
- routeRecordId
88
- })
89
- );
90
-
91
- const apiSuffix = computed(() => resolveTemplatePath(normalizedApiUrlTemplate));
92
- const listUrl = computed(() => resolveTemplatePath(normalizedListUrlTemplate));
93
- const cancelUrl = computed(() => resolveTemplatePath(normalizedViewUrlTemplate) || listUrl.value);
94
-
95
- function resolveParams(urlTemplate = "", extraParams = {}) {
96
- return resolveTemplatePath(urlTemplate, extraParams);
97
- }
98
-
99
- function resolveViewUrl(recordIdLike = "") {
100
- const targetRecordId = toRouteParamValue(recordIdLike);
101
- if (!targetRecordId) {
102
- return "";
103
- }
104
-
105
- return resolveTemplatePath(normalizedViewUrlTemplate, {
106
- [normalizedRecordIdParam]: targetRecordId
107
- });
108
- }
109
-
110
- function resolveSavedViewUrl(payload = {}) {
111
- const targetRecordId = resolveSavedRecordId(payload, saveRecordIdSelector);
112
- if (!targetRecordId) {
113
- return "";
114
- }
115
-
116
- return resolveViewUrl(targetRecordId);
117
- }
118
-
119
- return Object.freeze({
120
- recordId,
121
- apiSuffix,
122
- listUrl,
123
- cancelUrl,
124
- resolveParams,
125
- resolveViewUrl,
126
- resolveSavedViewUrl
127
- });
128
- }
129
-
130
- export { createAddEditUiRuntime };
@@ -1,123 +0,0 @@
1
- import { computed } from "vue";
2
- import { asPlainObject } from "../support/scopeHelpers.js";
3
- import {
4
- normalizeRouteParamName,
5
- toRouteParamValue,
6
- resolveRouteParamsSource,
7
- resolveScopedRoutePathname,
8
- resolveRouteTemplateLocation
9
- } from "../support/routeTemplateHelpers.js";
10
-
11
- function resolveRecordId(record, recordIdSelector) {
12
- const item = asPlainObject(record);
13
- if (typeof recordIdSelector === "function") {
14
- return toRouteParamValue(recordIdSelector(item));
15
- }
16
-
17
- return toRouteParamValue(item.id);
18
- }
19
-
20
- function createListUiRuntime({
21
- items,
22
- isInitialLoading,
23
- recordIdParam = "recordId",
24
- recordIdSelector = null,
25
- routeParams = null,
26
- routeParamNames = null,
27
- routePath = "",
28
- viewUrlTemplate = "",
29
- editUrlTemplate = ""
30
- } = {}) {
31
- const normalizedRecordIdParam = normalizeRouteParamName(recordIdParam, {
32
- context: "useList recordIdParam"
33
- });
34
- const normalizedViewUrlTemplate = String(viewUrlTemplate || "").trim();
35
- const normalizedEditUrlTemplate = String(editUrlTemplate || "").trim();
36
- const hasViewUrl = Boolean(normalizedViewUrlTemplate);
37
- const hasEditUrl = Boolean(normalizedEditUrlTemplate);
38
- const actionColumnCount = (hasViewUrl ? 1 : 0) + (hasEditUrl ? 1 : 0);
39
- const normalizedItems = computed(() => (Array.isArray(items?.value) ? items.value : []));
40
- const showListSkeleton = computed(() => Boolean(isInitialLoading?.value && normalizedItems.value.length < 1));
41
-
42
- function resolveTemplatePath(urlTemplate = "", extraParams = {}) {
43
- const normalizedTemplate = String(urlTemplate || "").trim();
44
- if (!normalizedTemplate) {
45
- return "";
46
- }
47
-
48
- const currentRouteParams = resolveRouteParamsSource(routeParams);
49
- const sourceParams = {
50
- ...currentRouteParams,
51
- ...asPlainObject(extraParams)
52
- };
53
- const currentPathname = resolveScopedRoutePathname({
54
- currentPathname: routePath,
55
- params: currentRouteParams,
56
- orderedParamNames: routeParamNames,
57
- anchorParamName: normalizedRecordIdParam,
58
- anchorParamValue: currentRouteParams[normalizedRecordIdParam],
59
- anchorMode: "before"
60
- });
61
-
62
- return resolveRouteTemplateLocation(normalizedTemplate, {
63
- params: sourceParams,
64
- currentPathname
65
- });
66
- }
67
-
68
- function resolveParams(urlTemplate = "", extraParams = {}) {
69
- return resolveTemplatePath(urlTemplate, extraParams);
70
- }
71
-
72
- function resolveRowKey(record, index) {
73
- const recordId = resolveRecordId(record, recordIdSelector);
74
- if (recordId) {
75
- return recordId;
76
- }
77
-
78
- return `row-${index}`;
79
- }
80
-
81
- function resolveViewUrl(record) {
82
- if (!hasViewUrl) {
83
- return "";
84
- }
85
-
86
- const recordId = resolveRecordId(record, recordIdSelector);
87
- if (!recordId) {
88
- return "";
89
- }
90
-
91
- return resolveTemplatePath(normalizedViewUrlTemplate, {
92
- [normalizedRecordIdParam]: recordId
93
- });
94
- }
95
-
96
- function resolveEditUrl(record) {
97
- if (!hasEditUrl) {
98
- return "";
99
- }
100
-
101
- const recordId = resolveRecordId(record, recordIdSelector);
102
- if (!recordId) {
103
- return "";
104
- }
105
-
106
- return resolveTemplatePath(normalizedEditUrlTemplate, {
107
- [normalizedRecordIdParam]: recordId
108
- });
109
- }
110
-
111
- return Object.freeze({
112
- hasViewUrl,
113
- hasEditUrl,
114
- actionColumnCount,
115
- showListSkeleton,
116
- resolveParams,
117
- resolveRowKey,
118
- resolveViewUrl,
119
- resolveEditUrl
120
- });
121
- }
122
-
123
- export { createListUiRuntime };
@@ -1,90 +0,0 @@
1
- import { watch } from "vue";
2
-
3
- function isObjectLike(value) {
4
- return value !== null && typeof value === "object";
5
- }
6
-
7
- function deepClone(value) {
8
- try {
9
- return JSON.parse(JSON.stringify(value));
10
- } catch {
11
- return null;
12
- }
13
- }
14
-
15
- function captureModelSnapshot(model) {
16
- if (!isObjectLike(model)) {
17
- return null;
18
- }
19
-
20
- return deepClone(model);
21
- }
22
-
23
- function restoreModelSnapshot(model, snapshot) {
24
- if (!isObjectLike(model) || !isObjectLike(snapshot)) {
25
- return;
26
- }
27
-
28
- if (Array.isArray(model) && Array.isArray(snapshot)) {
29
- model.splice(0, model.length, ...snapshot);
30
- return;
31
- }
32
-
33
- if (Array.isArray(model) || Array.isArray(snapshot)) {
34
- return;
35
- }
36
-
37
- for (const key of Object.keys(model)) {
38
- if (!Object.prototype.hasOwnProperty.call(snapshot, key)) {
39
- delete model[key];
40
- }
41
- }
42
-
43
- for (const [key, value] of Object.entries(snapshot)) {
44
- model[key] = value;
45
- }
46
- }
47
-
48
- function watchResourceModelState({
49
- resource,
50
- model,
51
- mapLoadedToModel,
52
- resolveMapContext = null
53
- } = {}) {
54
- const modelSnapshot = captureModelSnapshot(model);
55
-
56
- watch(
57
- () => resource?.query?.isPending?.value,
58
- (isPending) => {
59
- if (!isPending || !modelSnapshot) {
60
- return;
61
- }
62
-
63
- restoreModelSnapshot(model, modelSnapshot);
64
- },
65
- {
66
- immediate: true
67
- }
68
- );
69
-
70
- watch(
71
- () => resource?.data?.value,
72
- (payload) => {
73
- if (!payload || typeof mapLoadedToModel !== "function") {
74
- return;
75
- }
76
-
77
- const context = typeof resolveMapContext === "function" ? resolveMapContext() : {};
78
- mapLoadedToModel(model, payload, context);
79
- },
80
- {
81
- immediate: true
82
- }
83
- );
84
- }
85
-
86
- export {
87
- captureModelSnapshot,
88
- restoreModelSnapshot,
89
- watchResourceModelState
90
- };
@@ -1,34 +0,0 @@
1
- import { useOperationScope } from "../internal/useOperationScope.js";
2
-
3
- const USERS_OPERATION_ADAPTER_ID = "users-default";
4
-
5
- function createUsersOperationAdapter() {
6
- return Object.freeze({
7
- id: USERS_OPERATION_ADAPTER_ID,
8
- useOperationScope(options = {}) {
9
- return useOperationScope(options);
10
- }
11
- });
12
- }
13
-
14
- const defaultUsersOperationAdapter = createUsersOperationAdapter();
15
-
16
- function resolveOperationAdapter(adapter, { context = "users-web operation adapter" } = {}) {
17
- if (adapter == null) {
18
- return defaultUsersOperationAdapter;
19
- }
20
-
21
- if (!adapter || typeof adapter !== "object" || Array.isArray(adapter)) {
22
- throw new TypeError(`${context} must be an object when provided.`);
23
- }
24
- if (typeof adapter.useOperationScope !== "function") {
25
- throw new TypeError(`${context} must expose useOperationScope(options).`);
26
- }
27
-
28
- return adapter;
29
- }
30
-
31
- export {
32
- createUsersOperationAdapter,
33
- resolveOperationAdapter
34
- };
@@ -1,125 +0,0 @@
1
- import { watch } from "vue";
2
- import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
3
-
4
- function normalizeMessage(value) {
5
- return String(value || "").trim();
6
- }
7
-
8
- function setupOperationErrorReporting({
9
- enabled = true,
10
- source = "users-web.operation",
11
- loadError = null,
12
- notFoundError = null,
13
- loadActionFactory = null,
14
- notFoundActionFactory = null,
15
- loadChannel = "",
16
- notFoundChannel = "",
17
- loadSeverity = "error",
18
- notFoundSeverity = "warning",
19
- dedupeWindowMs = 2000
20
- } = {}) {
21
- if (!enabled) {
22
- return;
23
- }
24
-
25
- const runtime = useShellWebErrorRuntime();
26
- const normalizedSource = normalizeMessage(source) || "users-web.operation";
27
-
28
- function watchMessage(value, {
29
- kind = "load",
30
- channel = "",
31
- intent = "resource-load",
32
- severity = "error",
33
- actionFactory = null
34
- } = {}) {
35
- let lastMessage = "";
36
- let lastPresentationId = "";
37
-
38
- watch(
39
- () => normalizeMessage(value?.value),
40
- (nextMessage) => {
41
- if (!nextMessage) {
42
- lastMessage = "";
43
- if (lastPresentationId) {
44
- runtime.dismiss(lastPresentationId);
45
- lastPresentationId = "";
46
- }
47
- return;
48
- }
49
-
50
- if (nextMessage === lastMessage) {
51
- return;
52
- }
53
-
54
- lastMessage = nextMessage;
55
- const action = typeof actionFactory === "function"
56
- ? actionFactory({
57
- message: nextMessage,
58
- kind
59
- })
60
- : null;
61
- const reportResult = runtime.report({
62
- source: normalizedSource,
63
- message: nextMessage,
64
- intent,
65
- severity,
66
- channel,
67
- action,
68
- dedupeKey: `${normalizedSource}:${kind}:${nextMessage}`,
69
- dedupeWindowMs
70
- });
71
-
72
- const nextPresentationId = String(reportResult?.presentationId || "").trim();
73
- if (nextPresentationId) {
74
- if (lastPresentationId && lastPresentationId !== nextPresentationId) {
75
- runtime.dismiss(lastPresentationId);
76
- }
77
- lastPresentationId = nextPresentationId;
78
- }
79
- },
80
- { immediate: true }
81
- );
82
- }
83
-
84
- if (loadError) {
85
- watchMessage(loadError, {
86
- kind: "load",
87
- channel: loadChannel,
88
- intent: "resource-load",
89
- severity: loadSeverity,
90
- actionFactory: loadActionFactory
91
- });
92
- }
93
-
94
- if (notFoundError) {
95
- watchMessage(notFoundError, {
96
- kind: "not-found",
97
- channel: notFoundChannel,
98
- intent: "resource-load",
99
- severity: notFoundSeverity,
100
- actionFactory: notFoundActionFactory
101
- });
102
- }
103
- }
104
-
105
- function setupRouteChangeCleanup({
106
- enabled = true,
107
- route = null,
108
- feedback = null,
109
- fieldBag = null
110
- } = {}) {
111
- if (!enabled) {
112
- return;
113
- }
114
-
115
- watch(
116
- () => route?.fullPath,
117
- () => {
118
- feedback?.clear?.();
119
- fieldBag?.clear?.();
120
- }
121
- );
122
- }
123
-
124
- export { setupRouteChangeCleanup };
125
- export { setupOperationErrorReporting };
@@ -1,51 +0,0 @@
1
- import {
2
- createValidationFailure,
3
- resolveFieldErrors
4
- } from "@jskit-ai/http-runtime/client";
5
- import { validateSchemaPayload } from "@jskit-ai/kernel/shared/validators";
6
-
7
- function validateOperationInput({
8
- input,
9
- rawPayload = {},
10
- fieldBag = null,
11
- feedback = null,
12
- validationMessage = "Validation failed."
13
- } = {}) {
14
- if (!input) {
15
- return {
16
- ok: true,
17
- parsedInput: rawPayload
18
- };
19
- }
20
-
21
- try {
22
- const parsedInput = validateSchemaPayload(input, rawPayload, {
23
- phase: "input",
24
- context: "operation input"
25
- });
26
-
27
- return {
28
- ok: true,
29
- parsedInput
30
- };
31
- } catch (error) {
32
- if (!error?.fieldErrors || typeof error.fieldErrors !== "object") {
33
- throw error;
34
- }
35
-
36
- const failure = createValidationFailure({
37
- error: String(validationMessage || "Validation failed."),
38
- code: "validation_failed",
39
- fieldErrors: error?.fieldErrors
40
- });
41
- fieldBag?.apply?.(resolveFieldErrors(failure));
42
- feedback?.error?.(failure, failure.error);
43
- return {
44
- ok: false,
45
- failure,
46
- parsedInput: null
47
- };
48
- }
49
- }
50
-
51
- export { validateOperationInput };
@@ -1,112 +0,0 @@
1
- import { useQueryClient } from "@tanstack/vue-query";
2
- import { resolveFieldErrors } from "@jskit-ai/http-runtime/client";
3
- import { validateOperationInput } from "./operationValidationHelpers.js";
4
- import { watchResourceModelState } from "./modelStateHelpers.js";
5
-
6
- function useAddEditCore({
7
- model,
8
- resource,
9
- queryKey,
10
- canSave,
11
- fieldBag,
12
- feedback,
13
- input,
14
- mapLoadedToModel,
15
- buildRawPayload,
16
- buildSavePayload,
17
- onSaveSuccess,
18
- messages = {}
19
- } = {}) {
20
- const queryClient = useQueryClient();
21
- watchResourceModelState({
22
- resource,
23
- model,
24
- mapLoadedToModel,
25
- resolveMapContext() {
26
- return {
27
- queryClient,
28
- resource
29
- };
30
- }
31
- });
32
-
33
- const saving = resource?.isSaving;
34
- const fieldErrors = fieldBag?.errors;
35
- const message = feedback?.message;
36
- const messageType = feedback?.messageType;
37
-
38
- async function submit() {
39
- if (!canSave?.value || saving?.value) {
40
- return;
41
- }
42
-
43
- feedback?.clear?.();
44
- fieldBag?.clear?.();
45
-
46
- const rawPayload = typeof buildRawPayload === "function" ? buildRawPayload(model, {
47
- queryClient,
48
- resource
49
- }) : {};
50
-
51
- const validationResult = validateOperationInput({
52
- input,
53
- rawPayload,
54
- fieldBag,
55
- feedback,
56
- validationMessage: String(messages.validation || "Validation failed.")
57
- });
58
- if (!validationResult.ok) {
59
- return;
60
- }
61
-
62
- const { parsedInput } = validationResult;
63
- const savePayload = typeof buildSavePayload === "function"
64
- ? buildSavePayload(parsedInput, {
65
- rawPayload,
66
- queryClient,
67
- resource
68
- })
69
- : parsedInput;
70
-
71
- try {
72
- const queryKeySnapshot = queryKey?.value;
73
- const payload = await resource.save(savePayload);
74
-
75
- if (typeof mapLoadedToModel === "function") {
76
- mapLoadedToModel(model, payload, {
77
- queryClient,
78
- resource
79
- });
80
- }
81
-
82
- if (queryKeySnapshot !== undefined) {
83
- queryClient.setQueryData(queryKeySnapshot, payload);
84
- }
85
-
86
- if (typeof onSaveSuccess === "function") {
87
- await onSaveSuccess(payload, {
88
- queryClient,
89
- parsed: parsedInput,
90
- rawPayload,
91
- savePayload,
92
- resource
93
- });
94
- }
95
-
96
- feedback?.success?.(String(messages.saveSuccess || "Saved."));
97
- } catch (error) {
98
- fieldBag?.apply?.(resolveFieldErrors(error));
99
- feedback?.error?.(error, String(messages.saveError || "Unable to save."));
100
- }
101
- }
102
-
103
- return Object.freeze({
104
- saving,
105
- fieldErrors,
106
- message,
107
- messageType,
108
- submit
109
- });
110
- }
111
-
112
- export { useAddEditCore };