@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,123 +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
-
5
- function useCommandCore({
6
- model,
7
- resource,
8
- writeMethod = "POST",
9
- canRun,
10
- fieldBag,
11
- feedback,
12
- input,
13
- buildRawPayload,
14
- buildCommandPayload,
15
- buildCommandOptions,
16
- onRunSuccess,
17
- onRunError,
18
- suppressSuccessMessage = false,
19
- messages = {}
20
- } = {}) {
21
- const queryClient = useQueryClient();
22
- const normalizedWriteMethod = String(writeMethod || "POST").trim().toUpperCase();
23
-
24
- const running = resource?.isSaving;
25
- const fieldErrors = fieldBag?.errors;
26
- const message = feedback?.message;
27
- const messageType = feedback?.messageType;
28
-
29
- async function run(context = {}) {
30
- if (!canRun?.value || running?.value) {
31
- return null;
32
- }
33
-
34
- feedback?.clear?.();
35
- fieldBag?.clear?.();
36
-
37
- const rawPayload = typeof buildRawPayload === "function"
38
- ? buildRawPayload(model, {
39
- queryClient,
40
- resource,
41
- context
42
- })
43
- : {};
44
-
45
- const validationResult = validateOperationInput({
46
- input,
47
- rawPayload,
48
- fieldBag,
49
- feedback,
50
- validationMessage: String(messages.validation || "Validation failed.")
51
- });
52
- if (!validationResult.ok) {
53
- return null;
54
- }
55
-
56
- const { parsedInput } = validationResult;
57
- const payload = typeof buildCommandPayload === "function"
58
- ? buildCommandPayload(parsedInput, {
59
- rawPayload,
60
- queryClient,
61
- resource,
62
- context
63
- })
64
- : (normalizedWriteMethod === "DELETE" ? undefined : parsedInput);
65
-
66
- const options = typeof buildCommandOptions === "function"
67
- ? buildCommandOptions(parsedInput, {
68
- rawPayload,
69
- queryClient,
70
- resource,
71
- context
72
- })
73
- : {};
74
-
75
- try {
76
- const response = await resource.save(payload, options);
77
-
78
- if (typeof onRunSuccess === "function") {
79
- await onRunSuccess(response, {
80
- parsed: parsedInput,
81
- rawPayload,
82
- payload,
83
- options,
84
- queryClient,
85
- resource,
86
- context
87
- });
88
- }
89
-
90
- if (!suppressSuccessMessage) {
91
- feedback?.success?.(String(messages.success || "Completed."));
92
- }
93
- return response;
94
- } catch (error) {
95
- fieldBag?.apply?.(resolveFieldErrors(error));
96
-
97
- if (typeof onRunError === "function") {
98
- await onRunError(error, {
99
- parsed: parsedInput,
100
- rawPayload,
101
- payload,
102
- options,
103
- queryClient,
104
- resource,
105
- context
106
- });
107
- }
108
-
109
- feedback?.error?.(error, String(messages.error || "Unable to complete action."));
110
- throw error;
111
- }
112
- }
113
-
114
- return Object.freeze({
115
- running,
116
- fieldErrors,
117
- message,
118
- messageType,
119
- run
120
- });
121
- }
122
-
123
- export { useCommandCore };
@@ -1,199 +0,0 @@
1
- import { computed, unref } from "vue";
2
- import { useMutation, useQuery } from "@tanstack/vue-query";
3
- import { getUsersWebHttpClient } from "../../lib/httpClient.js";
4
- import { asPlainObject } from "../support/scopeHelpers.js";
5
- import { resolveEnabledRef, resolveTextRef } from "../support/refValueHelpers.js";
6
- import { toQueryErrorMessage } from "../support/errorMessageHelpers.js";
7
- import { useOperationRealtime } from "../useRealtimeQueryInvalidation.js";
8
- import {
9
- hasResolvedQueryData,
10
- mergeQueryMeta,
11
- mergeRequestRecoveryQueryMeta
12
- } from "../support/resourceLoadStateHelpers.js";
13
-
14
- function buildEndpointReadRequestOptions({
15
- method = "GET",
16
- query = null,
17
- transport = null
18
- } = {}) {
19
- const requestOptions = {
20
- method: String(method || "GET").toUpperCase()
21
- };
22
-
23
- const normalizedQuery = resolveRequestQuery(query);
24
- if (normalizedQuery) {
25
- requestOptions.query = normalizedQuery;
26
- }
27
-
28
- if (transport && typeof transport === "object") {
29
- requestOptions.transport = transport;
30
- }
31
-
32
- return requestOptions;
33
- }
34
-
35
- function resolveRequestQuery(value = null) {
36
- const source = unref(value);
37
- if (!source || typeof source !== "object" || Array.isArray(source)) {
38
- return null;
39
- }
40
-
41
- return source;
42
- }
43
-
44
- function buildEndpointWriteRequestOptions({
45
- method = "PATCH",
46
- body = undefined,
47
- options = null,
48
- transport = null
49
- } = {}) {
50
- const requestOptions = {
51
- method: String(method || "PATCH").toUpperCase(),
52
- ...(asPlainObject(options))
53
- };
54
-
55
- if (body !== undefined) {
56
- requestOptions.body = body;
57
- }
58
-
59
- if (transport && typeof transport === "object") {
60
- requestOptions.transport = transport;
61
- }
62
-
63
- return requestOptions;
64
- }
65
-
66
- function useEndpointResource({
67
- queryKey,
68
- path = "",
69
- enabled = true,
70
- client = null,
71
- readMethod = "GET",
72
- writeMethod = "PATCH",
73
- readQuery = null,
74
- transport = null,
75
- refreshOnPull = false,
76
- realtime = null,
77
- queryOptions = null,
78
- mutationOptions = null,
79
- requestRecovery = null,
80
- requestRecoveryLabel = "Request",
81
- fallbackLoadError = "Unable to load resource.",
82
- fallbackSaveError = "Unable to save resource."
83
- } = {}) {
84
- const activeClient = client || getUsersWebHttpClient();
85
- if (!activeClient || typeof activeClient.request !== "function") {
86
- throw new TypeError("useEndpointResource requires a client with request().");
87
- }
88
-
89
- const normalizedPath = computed(() => resolveTextRef(path));
90
- const queryEnabled = computed(() => resolveEnabledRef(enabled) && Boolean(normalizedPath.value));
91
-
92
- const query = useQuery({
93
- queryKey,
94
- queryFn: () => {
95
- const requestPath = normalizedPath.value;
96
- if (!requestPath) {
97
- throw new Error("Resource path is required.");
98
- }
99
-
100
- return activeClient.request(requestPath, {
101
- ...buildEndpointReadRequestOptions({
102
- method: readMethod,
103
- query: readQuery,
104
- transport
105
- })
106
- });
107
- },
108
- enabled: queryEnabled,
109
- ...mergeRequestRecoveryQueryMeta(
110
- refreshOnPull
111
- ? mergeQueryMeta(asPlainObject(queryOptions), {
112
- jskit: {
113
- refreshOnPull: true
114
- }
115
- })
116
- : asPlainObject(queryOptions),
117
- requestRecovery,
118
- {
119
- label: requestRecoveryLabel,
120
- method: readMethod
121
- }
122
- )
123
- });
124
- const realtimeBinding = useOperationRealtime({
125
- realtime,
126
- queryKey,
127
- enabled: queryEnabled
128
- });
129
-
130
- const mutation = useMutation({
131
- mutationFn: async (request = {}) => {
132
- const options = asPlainObject(request);
133
- const requestPath = resolveTextRef(options.path || normalizedPath.value);
134
- if (!requestPath) {
135
- throw new Error("Resource path is required.");
136
- }
137
-
138
- const method = String(options.method || writeMethod || "PATCH").toUpperCase();
139
- const hasBody = Object.hasOwn(options, "body");
140
- const body = hasBody ? options.body : options.payload;
141
- return activeClient.request(
142
- requestPath,
143
- buildEndpointWriteRequestOptions({
144
- method,
145
- body,
146
- options: options.options,
147
- transport
148
- })
149
- );
150
- },
151
- ...(asPlainObject(mutationOptions))
152
- });
153
-
154
- const data = computed(() => query.data.value);
155
- const hasResolvedData = computed(() => hasResolvedQueryData({
156
- query,
157
- data
158
- }));
159
- const isInitialLoading = computed(() => Boolean(queryEnabled.value && query.isPending.value && !hasResolvedData.value));
160
- const isFetching = computed(() => Boolean(queryEnabled.value && query.isFetching.value));
161
- const isRefetching = computed(() => Boolean(isFetching.value && !isInitialLoading.value));
162
- const isLoading = computed(() => Boolean(isInitialLoading.value || isFetching.value));
163
- const isSaving = computed(() => Boolean(mutation.isPending.value));
164
- const loadError = computed(() => toQueryErrorMessage(query.error.value, fallbackLoadError, "Request failed."));
165
- const saveError = computed(() => toQueryErrorMessage(mutation.error.value, fallbackSaveError, "Request failed."));
166
-
167
- async function reload() {
168
- return query.refetch();
169
- }
170
-
171
- async function save(payload, options = {}) {
172
- return mutation.mutateAsync({
173
- ...asPlainObject(options),
174
- payload
175
- });
176
- }
177
-
178
- return Object.freeze({
179
- query,
180
- mutation,
181
- data,
182
- isInitialLoading,
183
- isFetching,
184
- isRefetching,
185
- isLoading,
186
- isSaving,
187
- loadError,
188
- saveError,
189
- realtime: realtimeBinding,
190
- reload,
191
- save
192
- });
193
- }
194
-
195
- export {
196
- buildEndpointReadRequestOptions,
197
- buildEndpointWriteRequestOptions,
198
- useEndpointResource
199
- };
@@ -1,61 +0,0 @@
1
- import { reactive } from "vue";
2
-
3
- function normalizeKeys(keys) {
4
- return Array.isArray(keys)
5
- ? keys.map((entry) => String(entry || "").trim()).filter(Boolean)
6
- : [];
7
- }
8
-
9
- function useFieldErrorBag(keys = []) {
10
- const normalizedKeys = normalizeKeys(keys);
11
- const hasFixedKeys = normalizedKeys.length > 0;
12
- const errors = reactive(
13
- Object.fromEntries(normalizedKeys.map((key) => [key, ""]))
14
- );
15
-
16
- function clear() {
17
- const keysToClear = hasFixedKeys ? normalizedKeys : Object.keys(errors);
18
- for (const key of keysToClear) {
19
- errors[key] = "";
20
- }
21
- }
22
-
23
- function apply(source = {}) {
24
- const fieldErrorMap = source && typeof source === "object" ? source : {};
25
- if (hasFixedKeys) {
26
- for (const key of normalizedKeys) {
27
- errors[key] = String(fieldErrorMap[key] || "");
28
- }
29
- return;
30
- }
31
-
32
- clear();
33
- for (const [field, message] of Object.entries(fieldErrorMap)) {
34
- const key = String(field || "").trim();
35
- if (!key) {
36
- continue;
37
- }
38
- errors[key] = String(message || "");
39
- }
40
- }
41
-
42
- function set(field, message) {
43
- const key = String(field || "").trim();
44
- if (!key) {
45
- return;
46
- }
47
- if (hasFixedKeys && !(key in errors)) {
48
- return;
49
- }
50
- errors[key] = String(message || "");
51
- }
52
-
53
- return Object.freeze({
54
- errors,
55
- clear,
56
- apply,
57
- set
58
- });
59
- }
60
-
61
- export { useFieldErrorBag };
@@ -1,112 +0,0 @@
1
- import { computed, unref } from "vue";
2
- import { getUsersWebHttpClient } from "../../lib/httpClient.js";
3
- import { asPlainObject } from "../support/scopeHelpers.js";
4
- import { resolveEnabledRef, resolveTextRef } from "../support/refValueHelpers.js";
5
- import { usePagedCollection } from "../usePagedCollection.js";
6
- import { mergeRequestRecoveryQueryMeta } from "../support/resourceLoadStateHelpers.js";
7
-
8
- const DEFAULT_LIST_LIMIT = 20;
9
-
10
- function buildListRequestOptions({
11
- requestOptions = null,
12
- transport = null,
13
- pageParam = null
14
- } = {}) {
15
- const resolvedOptions = {
16
- method: "GET",
17
- ...(resolveRequestOptionsObject(requestOptions))
18
- };
19
-
20
- const sourceQuery =
21
- resolvedOptions.query && typeof resolvedOptions.query === "object" && !Array.isArray(resolvedOptions.query)
22
- ? { ...resolvedOptions.query }
23
- : {};
24
- if (
25
- !Object.hasOwn(sourceQuery, "limit") &&
26
- !Object.hasOwn(sourceQuery, "page[limit]")
27
- ) {
28
- sourceQuery.limit = DEFAULT_LIST_LIMIT;
29
- }
30
- if (pageParam !== null && pageParam !== undefined && pageParam !== "") {
31
- sourceQuery.cursor = String(pageParam);
32
- }
33
- if (Object.keys(sourceQuery).length > 0) {
34
- resolvedOptions.query = sourceQuery;
35
- } else {
36
- delete resolvedOptions.query;
37
- }
38
-
39
- if (transport && typeof transport === "object") {
40
- resolvedOptions.transport = transport;
41
- }
42
-
43
- return resolvedOptions;
44
- }
45
-
46
- function resolveRequestOptionsObject(value = null) {
47
- const source = unref(value);
48
- return asPlainObject(source);
49
- }
50
-
51
- function resolveListRequestMethod(requestOptions = null) {
52
- return String(resolveRequestOptionsObject(requestOptions).method || "GET").toUpperCase();
53
- }
54
-
55
- function useListCore({
56
- queryKey,
57
- path = "",
58
- enabled = true,
59
- client = null,
60
- transport = null,
61
- initialPageParam = null,
62
- getNextPageParam,
63
- selectItems,
64
- requestOptions = null,
65
- queryOptions = null,
66
- requestRecovery = null,
67
- requestRecoveryLabel = "List",
68
- fallbackLoadError = "Unable to load list."
69
- } = {}) {
70
- const activeClient = client || getUsersWebHttpClient();
71
- if (!activeClient || typeof activeClient.request !== "function") {
72
- throw new TypeError("useListCore requires a client with request().");
73
- }
74
-
75
- const normalizedPath = computed(() => resolveTextRef(path));
76
- const queryEnabled = computed(() => resolveEnabledRef(enabled) && Boolean(normalizedPath.value));
77
-
78
- const collection = usePagedCollection({
79
- queryKey,
80
- initialPageParam,
81
- enabled: queryEnabled,
82
- queryFn: async ({ pageParam }) => {
83
- const requestPath = normalizedPath.value;
84
- if (!requestPath) {
85
- throw new Error("List path is required.");
86
- }
87
-
88
- return activeClient.request(
89
- requestPath,
90
- buildListRequestOptions({
91
- requestOptions,
92
- transport,
93
- pageParam
94
- })
95
- );
96
- },
97
- getNextPageParam,
98
- selectItems,
99
- queryOptions: mergeRequestRecoveryQueryMeta(queryOptions, requestRecovery, {
100
- label: requestRecoveryLabel,
101
- method: resolveListRequestMethod(requestOptions)
102
- }),
103
- fallbackLoadError
104
- });
105
-
106
- return collection;
107
- }
108
-
109
- export {
110
- buildListRequestOptions,
111
- useListCore
112
- };
@@ -1,98 +0,0 @@
1
- import { ref } from "vue";
2
- import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
3
- import { toUiErrorMessage } from "../support/errorMessageHelpers.js";
4
-
5
- function useUiFeedback({
6
- initialType = "success",
7
- source = "users-web.ui-feedback",
8
- successChannel = "",
9
- errorChannel = "",
10
- dedupeWindowMs = 2000
11
- } = {}) {
12
- const message = ref("");
13
- const messageType = ref(String(initialType || "success"));
14
- const errorRuntime = useShellWebErrorRuntime();
15
- const normalizedSource = String(source || "").trim() || "users-web.ui-feedback";
16
- let lastErrorPresentation = null;
17
-
18
- function rememberErrorPresentation(reportResult = null) {
19
- const presentationId = String(reportResult?.presentationId || "").trim();
20
- const presenterId = String(reportResult?.decision?.presenterId || "").trim();
21
- if (!presentationId || !presenterId) {
22
- return;
23
- }
24
-
25
- lastErrorPresentation = Object.freeze({
26
- presentationId,
27
- presenterId
28
- });
29
- }
30
-
31
- function dismissLastErrorPresentation() {
32
- if (!lastErrorPresentation) {
33
- return;
34
- }
35
-
36
- errorRuntime.dismiss(lastErrorPresentation.presentationId, {
37
- presenterId: lastErrorPresentation.presenterId
38
- });
39
- lastErrorPresentation = null;
40
- }
41
-
42
- function clear() {
43
- message.value = "";
44
- }
45
-
46
- function success(nextMessage = "") {
47
- messageType.value = "success";
48
- const normalizedMessage = String(nextMessage || "").trim();
49
- message.value = normalizedMessage;
50
- dismissLastErrorPresentation();
51
- if (!normalizedMessage) {
52
- return;
53
- }
54
-
55
- errorRuntime.report({
56
- source: normalizedSource,
57
- message: normalizedMessage,
58
- intent: "action-feedback",
59
- severity: "success",
60
- channel: successChannel,
61
- dedupeKey: `${normalizedSource}:success:${normalizedMessage}`,
62
- dedupeWindowMs
63
- });
64
- }
65
-
66
- function error(errorValue, fallbackMessage = "") {
67
- messageType.value = "error";
68
- message.value = toUiErrorMessage(errorValue, fallbackMessage, "Request failed.");
69
- if (!message.value) {
70
- return;
71
- }
72
-
73
- const reportResult = errorRuntime.report({
74
- source: normalizedSource,
75
- message: message.value,
76
- cause: errorValue || null,
77
- intent: "action-feedback",
78
- severity: "error",
79
- channel: errorChannel,
80
- dedupeKey: `${normalizedSource}:error:${message.value}`,
81
- dedupeWindowMs
82
- });
83
-
84
- if (!reportResult?.skipped) {
85
- rememberErrorPresentation(reportResult);
86
- }
87
- }
88
-
89
- return Object.freeze({
90
- message,
91
- messageType,
92
- clear,
93
- success,
94
- error
95
- });
96
- }
97
-
98
- export { useUiFeedback };
@@ -1,93 +0,0 @@
1
- import { computed } from "vue";
2
- import { watchResourceModelState } from "./modelStateHelpers.js";
3
-
4
- function normalizeStatusList(value) {
5
- if (Array.isArray(value)) {
6
- return value.map((entry) => Number(entry)).filter((entry) => Number.isInteger(entry) && entry > 0);
7
- }
8
-
9
- return [404];
10
- }
11
-
12
- function useViewCore({
13
- resource,
14
- model,
15
- canView,
16
- mapLoadedToModel,
17
- notFoundStatuses = [404],
18
- notFoundMessage = "Record not found."
19
- } = {}) {
20
- const statusList = normalizeStatusList(notFoundStatuses);
21
- watchResourceModelState({
22
- resource,
23
- model,
24
- mapLoadedToModel,
25
- resolveMapContext() {
26
- return {
27
- resource
28
- };
29
- }
30
- });
31
-
32
- const data = resource?.data;
33
- const record = computed(() => (model !== undefined ? model : data?.value));
34
- const isLoading = computed(() => {
35
- if (resource?.isInitialLoading?.value !== undefined) {
36
- return Boolean(resource.isInitialLoading.value);
37
- }
38
- return Boolean(resource?.query?.isPending?.value);
39
- });
40
- const isFetching = computed(() => {
41
- if (resource?.isFetching?.value !== undefined) {
42
- return Boolean(resource.isFetching.value);
43
- }
44
- return Boolean(resource?.query?.isFetching?.value);
45
- });
46
- const error = computed(() => resource?.query?.error?.value || null);
47
-
48
- const isNotFound = computed(() => {
49
- const status = Number(error.value?.status || 0);
50
- return statusList.includes(status);
51
- });
52
-
53
- const notFoundError = computed(() => {
54
- if (!isNotFound.value) {
55
- return "";
56
- }
57
-
58
- return String(notFoundMessage || "Record not found.");
59
- });
60
-
61
- const loadError = computed(() => {
62
- if (isNotFound.value) {
63
- return "";
64
- }
65
-
66
- return String(resource?.loadError?.value || "").trim();
67
- });
68
-
69
- const resolvedCanView = computed(() => {
70
- if (canView === undefined) {
71
- return true;
72
- }
73
-
74
- return Boolean(canView?.value);
75
- });
76
-
77
- async function refresh() {
78
- return resource?.reload?.();
79
- }
80
-
81
- return Object.freeze({
82
- record,
83
- isLoading,
84
- isFetching,
85
- isNotFound,
86
- notFoundError,
87
- loadError,
88
- canView: resolvedCanView,
89
- refresh
90
- });
91
- }
92
-
93
- export { useViewCore };