@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,500 @@
1
+ import { computed, onScopeDispose, proxyRefs, ref, watch } from "vue";
2
+ import { useRouter } from "vue-router";
3
+ import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
4
+ import { ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/kernel/shared/support/visibility";
5
+ import { useListCore } from "../runtime/useListCore.js";
6
+ import { resolveOperationAdapter } from "../runtime/operationAdapters.js";
7
+ import { setupOperationErrorReporting } from "../runtime/operationUiHelpers.js";
8
+ import { createListUiRuntime } from "../runtime/listUiRuntime.js";
9
+ import { asPlainObject } from "../support/scopeHelpers.js";
10
+ import {
11
+ buildRequestQueryObject,
12
+ createRequestQueryRuntime
13
+ } from "../support/requestQueryRuntimeSupport.js";
14
+ import {
15
+ normalizeListSearchConfig,
16
+ matchesLocalSearch
17
+ } from "../support/listSearchSupport.js";
18
+ import {
19
+ normalizeListSyncToRouteConfig,
20
+ resolveQueryParamDescriptors,
21
+ resolveActiveQueryParamEntries,
22
+ resolveWritableQueryParamBindings,
23
+ buildQueryParamEntriesToken,
24
+ parseRouteBindingValue,
25
+ areQueryParamBindingValuesEqual,
26
+ buildRouteQueryCompareToken,
27
+ mergeManagedQueryParamKeyHistory,
28
+ resolveRouteSyncManagedKeys
29
+ } from "../support/listQueryParamSupport.js";
30
+ import {
31
+ resolveRouteParamNamesInOrder,
32
+ } from "../support/routeTemplateHelpers.js";
33
+
34
+ const EMPTY_ROUTE_SYNC_QUERY_PARAM_BLACKLIST = Object.freeze([]);
35
+
36
+ function useList({
37
+ ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
38
+ surfaceId = "",
39
+ access = "auto",
40
+ apiSuffix = "",
41
+ queryKeyFactory = null,
42
+ viewPermissions = [],
43
+ readEnabled = true,
44
+ placementSource = "http-web.list",
45
+ fallbackLoadError = "Unable to load list.",
46
+ initialPageParam = null,
47
+ getNextPageParam,
48
+ selectItems,
49
+ client = null,
50
+ transport = null,
51
+ requestOptions,
52
+ queryOptions,
53
+ requestRecovery,
54
+ requestRecoveryLabel = "List",
55
+ realtime = null,
56
+ adapter = null,
57
+ recordIdParam = "recordId",
58
+ recordIdSelector = null,
59
+ viewUrlTemplate = "",
60
+ editUrlTemplate = "",
61
+ search = null,
62
+ queryParams = null,
63
+ routeQueryValueResolvers = null,
64
+ requestQueryParams = null,
65
+ requestFieldsets = null,
66
+ syncToRoute = false
67
+ } = {}) {
68
+ const searchConfig = normalizeListSearchConfig(search);
69
+ const routeSyncConfig = normalizeListSyncToRouteConfig(syncToRoute, {
70
+ defaultSearchParam: searchConfig.queryParam
71
+ });
72
+ const routeSyncHydrated = ref(
73
+ routeSyncConfig.enabled !== true || routeSyncConfig.hydrateFromRoute !== true
74
+ );
75
+ const router = routeSyncConfig.enabled === true ? useRouter() : null;
76
+ const searchQuery = ref(searchConfig.initialQuery);
77
+ const debouncedSearchQuery = ref(searchConfig.initialQuery);
78
+ let searchDebounceTimer = null;
79
+ const isSearchDebouncing = ref(false);
80
+
81
+ watch(searchQuery, (value) => {
82
+ const normalizedValue = normalizeText(value);
83
+ if (searchDebounceTimer) {
84
+ clearTimeout(searchDebounceTimer);
85
+ }
86
+ if (searchConfig.enabled !== true) {
87
+ debouncedSearchQuery.value = normalizedValue;
88
+ isSearchDebouncing.value = false;
89
+ return;
90
+ }
91
+ isSearchDebouncing.value = true;
92
+ searchDebounceTimer = setTimeout(() => {
93
+ debouncedSearchQuery.value = normalizedValue;
94
+ isSearchDebouncing.value = false;
95
+ searchDebounceTimer = null;
96
+ }, searchConfig.debounceMs);
97
+ }, { immediate: true });
98
+
99
+ onScopeDispose(() => {
100
+ if (!searchDebounceTimer) {
101
+ return;
102
+ }
103
+ clearTimeout(searchDebounceTimer);
104
+ searchDebounceTimer = null;
105
+ });
106
+
107
+ const operationAdapter = resolveOperationAdapter(adapter, {
108
+ context: "useList adapter"
109
+ });
110
+ const operationScope = operationAdapter.useOperationScope({
111
+ ownershipFilter,
112
+ surfaceId,
113
+ access,
114
+ placementSource,
115
+ apiSuffix,
116
+ readEnabled,
117
+ queryKeyFactory,
118
+ permissionSets: {
119
+ view: viewPermissions
120
+ },
121
+ realtime
122
+ });
123
+ if (
124
+ routeSyncConfig.enabled === true &&
125
+ routeSyncConfig.hydrateFromRoute === true &&
126
+ routeSyncConfig.syncSearch === true &&
127
+ searchConfig.enabled === true
128
+ ) {
129
+ const routeQuerySource = asPlainObject(operationScope.routeContext.route?.query || {});
130
+ const routeSearchValue = routeQuerySource[routeSyncConfig.searchParam];
131
+ const hydratedSearch = normalizeText(Array.isArray(routeSearchValue) ? routeSearchValue[0] : routeSearchValue);
132
+
133
+ if (searchDebounceTimer) {
134
+ clearTimeout(searchDebounceTimer);
135
+ searchDebounceTimer = null;
136
+ }
137
+
138
+ searchQuery.value = hydratedSearch;
139
+ debouncedSearchQuery.value = hydratedSearch;
140
+ isSearchDebouncing.value = false;
141
+ }
142
+ const canView = operationScope.permissionGate("view");
143
+ const queryParamsContext = computed(() => {
144
+ return Object.freeze({
145
+ surfaceId: operationScope.routeContext.currentSurfaceId.value,
146
+ scopeParamValue: operationScope.scopeParamValue.value,
147
+ ownershipFilter: operationScope.normalizedOwnershipFilter
148
+ });
149
+ });
150
+ const queryParamDescriptors = computed(() => {
151
+ return resolveQueryParamDescriptors(queryParams, queryParamsContext.value, {
152
+ routeValueResolvers: routeQueryValueResolvers
153
+ });
154
+ });
155
+ const requestQueryRuntime = createRequestQueryRuntime({
156
+ requestQueryParams,
157
+ requestFieldsets,
158
+ context: queryParamsContext
159
+ });
160
+ const {
161
+ activeRequestQueryParamEntries,
162
+ activeRequestQueryParamsToken,
163
+ activeRequestFieldsets,
164
+ activeRequestFieldsetsToken,
165
+ queryKeyParts: requestQueryKeyParts
166
+ } = requestQueryRuntime;
167
+ const declaredQueryParamKeys = computed(() => {
168
+ return queryParamDescriptors.value.map((descriptor) => descriptor.key);
169
+ });
170
+ const activeQueryParamEntries = computed(() => {
171
+ return resolveActiveQueryParamEntries(queryParamDescriptors.value);
172
+ });
173
+ const activeQueryParamsToken = computed(() => buildQueryParamEntriesToken(activeQueryParamEntries.value));
174
+ const writableQueryParamBindings = computed(() => {
175
+ return resolveWritableQueryParamBindings(queryParamDescriptors.value);
176
+ });
177
+ const activeSearchQuery = computed(() => {
178
+ if (searchConfig.enabled !== true) {
179
+ return "";
180
+ }
181
+ const normalized = normalizeText(debouncedSearchQuery.value);
182
+ if (!normalized || normalized.length < searchConfig.minLength) {
183
+ return "";
184
+ }
185
+ return normalized;
186
+ });
187
+ const querySearchEnabled = computed(() => searchConfig.enabled === true && searchConfig.mode === "query");
188
+ const listPath = computed(() => {
189
+ return normalizeText(operationScope.apiPath.value);
190
+ });
191
+ const listRequestOptions = computed(() => {
192
+ const entries = [];
193
+
194
+ if (querySearchEnabled.value) {
195
+ const queryValue = activeSearchQuery.value;
196
+ if (queryValue) {
197
+ entries.push({
198
+ key: searchConfig.queryParam,
199
+ values: [queryValue]
200
+ });
201
+ }
202
+ }
203
+
204
+ entries.push(...activeRequestQueryParamEntries.value);
205
+ entries.push(...activeQueryParamEntries.value);
206
+
207
+ const query = buildRequestQueryObject(entries, {
208
+ fieldsets: activeRequestFieldsets.value
209
+ });
210
+ const baseOptions = asPlainObject(requestOptions);
211
+ if (Object.keys(query).length < 1) {
212
+ return baseOptions;
213
+ }
214
+
215
+ return {
216
+ ...baseOptions,
217
+ query
218
+ };
219
+ });
220
+ const listQueryKey = computed(() => {
221
+ const sourceQueryKey = operationScope.queryKey.value;
222
+ const baseQueryKey = Array.isArray(sourceQueryKey)
223
+ ? [...sourceQueryKey]
224
+ : sourceQueryKey == null
225
+ ? []
226
+ : [sourceQueryKey];
227
+ baseQueryKey.push(...requestQueryKeyParts.value);
228
+ if (querySearchEnabled.value) {
229
+ baseQueryKey.push("__search__", searchConfig.queryParam, activeSearchQuery.value);
230
+ }
231
+ if (activeQueryParamsToken.value) {
232
+ baseQueryKey.push("__query__", activeQueryParamsToken.value);
233
+ }
234
+ return baseQueryKey;
235
+ });
236
+
237
+ const listReadEnabled = computed(() => canView.value && routeSyncHydrated.value);
238
+ const list = useListCore({
239
+ queryKey: listQueryKey,
240
+ path: listPath,
241
+ enabled: operationScope.queryCanRun(listReadEnabled),
242
+ client,
243
+ transport,
244
+ initialPageParam,
245
+ getNextPageParam,
246
+ selectItems,
247
+ requestOptions: listRequestOptions,
248
+ queryOptions,
249
+ requestRecovery,
250
+ requestRecoveryLabel,
251
+ fallbackLoadError
252
+ });
253
+ const routeSyncApplying = ref(false);
254
+ const routeSyncManagedKeyHistory = ref([]);
255
+ const routeSyncQueryParamBlacklist = computed(() => {
256
+ if (routeSyncConfig.enabled !== true || routeSyncConfig.syncQueryParams !== true) {
257
+ return EMPTY_ROUTE_SYNC_QUERY_PARAM_BLACKLIST;
258
+ }
259
+ return routeSyncConfig.queryParamBlacklist;
260
+ });
261
+ const routeSyncQueryParamBlacklistSet = computed(() => {
262
+ return new Set(routeSyncQueryParamBlacklist.value);
263
+ });
264
+ if (routeSyncConfig.enabled === true && routeSyncConfig.syncQueryParams === true) {
265
+ watch(declaredQueryParamKeys, (nextKeys) => {
266
+ routeSyncManagedKeyHistory.value = mergeManagedQueryParamKeyHistory(
267
+ routeSyncManagedKeyHistory.value,
268
+ nextKeys
269
+ );
270
+ }, { immediate: true });
271
+ }
272
+ const routeSyncManagedKeys = computed(() => {
273
+ const managedKeys = resolveRouteSyncManagedKeys({
274
+ searchEnabled: searchConfig.enabled,
275
+ searchParam: routeSyncConfig.searchParam,
276
+ syncSearch: routeSyncConfig.enabled === true && routeSyncConfig.syncSearch === true,
277
+ syncQueryParams: routeSyncConfig.enabled === true && routeSyncConfig.syncQueryParams === true,
278
+ declaredKeys: declaredQueryParamKeys.value,
279
+ keyHistory: routeSyncManagedKeyHistory.value
280
+ });
281
+ if (routeSyncConfig.enabled !== true || routeSyncConfig.syncQueryParams !== true) {
282
+ return managedKeys;
283
+ }
284
+
285
+ const output = new Set(managedKeys);
286
+ for (const key of routeSyncQueryParamBlacklist.value) {
287
+ output.add(key);
288
+ }
289
+ return [...output].sort((left, right) => left.localeCompare(right));
290
+ });
291
+ const routeSyncDesiredQuery = computed(() => {
292
+ if (routeSyncConfig.enabled !== true) {
293
+ return {};
294
+ }
295
+
296
+ const desiredQuery = {};
297
+ if (routeSyncConfig.syncSearch === true && searchConfig.enabled === true) {
298
+ const normalizedSearch = normalizeText(searchQuery.value);
299
+ if (normalizedSearch) {
300
+ desiredQuery[routeSyncConfig.searchParam] = normalizedSearch;
301
+ }
302
+ }
303
+ if (routeSyncConfig.syncQueryParams === true) {
304
+ for (const entry of activeQueryParamEntries.value) {
305
+ if (routeSyncQueryParamBlacklistSet.value.has(entry.key)) {
306
+ continue;
307
+ }
308
+ if (entry.values.length === 1) {
309
+ desiredQuery[entry.key] = entry.values[0];
310
+ continue;
311
+ }
312
+ desiredQuery[entry.key] = [...entry.values];
313
+ }
314
+ }
315
+
316
+ return desiredQuery;
317
+ });
318
+ if (routeSyncConfig.enabled === true) {
319
+ watch(
320
+ () => operationScope.routeContext.route?.query || {},
321
+ (routeQuery) => {
322
+ const initialHydration = routeSyncHydrated.value !== true;
323
+ if (routeSyncConfig.hydrateFromRoute !== true || routeSyncApplying.value === true) {
324
+ routeSyncHydrated.value = true;
325
+ return;
326
+ }
327
+
328
+ const routeQuerySource = asPlainObject(routeQuery);
329
+ if (routeSyncConfig.syncSearch === true && searchConfig.enabled === true) {
330
+ const routeSearchValue = routeQuerySource[routeSyncConfig.searchParam];
331
+ const nextSearch = normalizeText(Array.isArray(routeSearchValue) ? routeSearchValue[0] : routeSearchValue);
332
+ if (nextSearch !== searchQuery.value) {
333
+ searchQuery.value = nextSearch;
334
+ }
335
+ }
336
+ if (routeSyncConfig.syncQueryParams === true) {
337
+ for (const binding of writableQueryParamBindings.value) {
338
+ if (routeSyncQueryParamBlacklistSet.value.has(binding.key)) {
339
+ continue;
340
+ }
341
+ const nextValue = parseRouteBindingValue(binding, routeQuerySource[binding.key], {
342
+ initial: initialHydration
343
+ });
344
+ const currentValue = typeof binding.get === "function" ? binding.get() : undefined;
345
+ if (areQueryParamBindingValuesEqual(currentValue, nextValue)) {
346
+ continue;
347
+ }
348
+ try {
349
+ binding.set(nextValue);
350
+ } catch {
351
+ // Ignore non-writable query param bindings.
352
+ }
353
+ }
354
+ }
355
+
356
+ routeSyncHydrated.value = true;
357
+ },
358
+ {
359
+ immediate: true
360
+ }
361
+ );
362
+
363
+ watch(
364
+ [routeSyncDesiredQuery, routeSyncManagedKeys],
365
+ async ([desiredQuery, managedKeys]) => {
366
+ if (routeSyncHydrated.value !== true || routeSyncApplying.value === true) {
367
+ return;
368
+ }
369
+
370
+ const managedKeySet = new Set(Array.isArray(managedKeys) ? managedKeys : []);
371
+ const currentQuery = asPlainObject(operationScope.routeContext.route?.query || {});
372
+ const nextQuery = {};
373
+
374
+ for (const [key, value] of Object.entries(currentQuery)) {
375
+ if (managedKeySet.has(key)) {
376
+ continue;
377
+ }
378
+ nextQuery[key] = value;
379
+ }
380
+ for (const [key, value] of Object.entries(asPlainObject(desiredQuery))) {
381
+ nextQuery[key] = value;
382
+ }
383
+
384
+ if (buildRouteQueryCompareToken(currentQuery) === buildRouteQueryCompareToken(nextQuery)) {
385
+ return;
386
+ }
387
+
388
+ routeSyncApplying.value = true;
389
+ try {
390
+ if (routeSyncConfig.mode === "push") {
391
+ await router.push({
392
+ query: nextQuery
393
+ });
394
+ } else {
395
+ await router.replace({
396
+ query: nextQuery
397
+ });
398
+ }
399
+ } finally {
400
+ routeSyncApplying.value = false;
401
+ }
402
+ }
403
+ );
404
+ }
405
+
406
+ watch(activeSearchQuery, (nextValue, previousValue) => {
407
+ if (!querySearchEnabled.value) {
408
+ return;
409
+ }
410
+ if (nextValue === previousValue) {
411
+ return;
412
+ }
413
+
414
+ list.trimToFirstPage();
415
+ });
416
+ watch(
417
+ [
418
+ activeQueryParamsToken,
419
+ activeRequestQueryParamsToken,
420
+ activeRequestFieldsetsToken
421
+ ],
422
+ () => {
423
+ list.trimToFirstPage();
424
+ }
425
+ );
426
+ const filteredItems = computed(() => {
427
+ const sourceItems = Array.isArray(list.items.value) ? list.items.value : [];
428
+ if (searchConfig.enabled !== true || searchConfig.mode !== "local") {
429
+ return sourceItems;
430
+ }
431
+
432
+ const queryValue = activeSearchQuery.value;
433
+ if (!queryValue) {
434
+ return sourceItems;
435
+ }
436
+
437
+ return sourceItems.filter((item) => matchesLocalSearch(item, queryValue, searchConfig.fields));
438
+ });
439
+
440
+ const isInitialLoading = operationScope.isLoading(list.isInitialLoading);
441
+ const isFetching = operationScope.isLoading(list.isFetching);
442
+ const isRefetching = computed(() => Boolean(isFetching.value && !isInitialLoading.value));
443
+ const loadError = operationScope.loadError(list.loadError);
444
+ const isLoading = operationScope.isLoading(list.isLoading);
445
+ const listUiRuntime = createListUiRuntime({
446
+ items: filteredItems,
447
+ isInitialLoading,
448
+ recordIdParam,
449
+ recordIdSelector,
450
+ routeParams: computed(() => operationScope.routeContext.route?.params || {}),
451
+ routeParamNames: computed(() => resolveRouteParamNamesInOrder(operationScope.routeContext.route)),
452
+ routePath: computed(() => operationScope.routeContext.route?.path || ""),
453
+ viewUrlTemplate,
454
+ editUrlTemplate
455
+ });
456
+ setupOperationErrorReporting({
457
+ source: `${placementSource}.load`,
458
+ loadError,
459
+ dedupeWindowMs: 0,
460
+ loadActionFactory: () => ({
461
+ label: "Retry",
462
+ dismissOnRun: true,
463
+ handler() {
464
+ void list.reload();
465
+ }
466
+ })
467
+ });
468
+
469
+ return proxyRefs({
470
+ canView,
471
+ isInitialLoading,
472
+ isFetching,
473
+ isRefetching,
474
+ isLoading,
475
+ isLoadingMore: list.isLoadingMore,
476
+ hasMore: list.hasMore,
477
+ loadError,
478
+ pages: list.pages,
479
+ items: filteredItems,
480
+ reload: list.reload,
481
+ loadMore: list.loadMore,
482
+ hasViewUrl: listUiRuntime.hasViewUrl,
483
+ hasEditUrl: listUiRuntime.hasEditUrl,
484
+ actionColumnCount: listUiRuntime.actionColumnCount,
485
+ showListSkeleton: listUiRuntime.showListSkeleton,
486
+ resolveRowKey: listUiRuntime.resolveRowKey,
487
+ resolveParams: listUiRuntime.resolveParams,
488
+ resolveViewUrl: listUiRuntime.resolveViewUrl,
489
+ resolveEditUrl: listUiRuntime.resolveEditUrl,
490
+ searchEnabled: searchConfig.enabled,
491
+ searchMode: searchConfig.mode,
492
+ searchQuery,
493
+ searchLabel: searchConfig.label,
494
+ searchPlaceholder: searchConfig.placeholder,
495
+ isSearchDebouncing,
496
+ activeQueryParamsToken
497
+ });
498
+ }
499
+
500
+ export { useList };
@@ -0,0 +1,164 @@
1
+ import { computed, proxyRefs } from "vue";
2
+ import { useRoute } from "vue-router";
3
+ import { ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/kernel/shared/support/visibility";
4
+ import { useViewCore } from "../runtime/useViewCore.js";
5
+ import { useEndpointResource } from "../runtime/useEndpointResource.js";
6
+ import { resolveOperationAdapter } from "../runtime/operationAdapters.js";
7
+ import { setupOperationErrorReporting } from "../runtime/operationUiHelpers.js";
8
+ import { createViewUiRuntime } from "../runtime/viewUiRuntime.js";
9
+ import { createRequestQueryRuntime } from "../support/requestQueryRuntimeSupport.js";
10
+ import { resolveRouteParamNamesInOrder } from "../support/routeTemplateHelpers.js";
11
+ import { resolveOperationRealtimeOptions } from "../useRealtimeQueryInvalidation.js";
12
+
13
+ function useView({
14
+ resource = null,
15
+ ownershipFilter = ROUTE_VISIBILITY_WORKSPACE,
16
+ surfaceId = "",
17
+ access = "auto",
18
+ apiSuffix = "",
19
+ queryKeyFactory = null,
20
+ viewPermissions = [],
21
+ readMethod = "GET",
22
+ readEnabled = true,
23
+ client = null,
24
+ transport = null,
25
+ requestRecovery = null,
26
+ requestRecoveryLabel = "Resource",
27
+ placementSource = "http-web.view",
28
+ fallbackLoadError = "Unable to load resource.",
29
+ notFoundStatuses = [404],
30
+ notFoundMessage = "Record not found.",
31
+ model,
32
+ mapLoadedToModel,
33
+ requestQueryParams = null,
34
+ requestFieldsets = null,
35
+ recordIdParam = "recordId",
36
+ routeParams = null,
37
+ routeRecordId = null,
38
+ apiUrlTemplate = "",
39
+ listUrlTemplate = "",
40
+ editUrlTemplate = "",
41
+ includeRecordIdInQueryKey = false,
42
+ realtime = undefined,
43
+ adapter = null
44
+ } = {}) {
45
+ const route = useRoute();
46
+ const viewUiRuntime = createViewUiRuntime({
47
+ recordIdParam,
48
+ routeParams: routeParams ?? computed(() => route?.params || {}),
49
+ routeParamNames: computed(() => resolveRouteParamNamesInOrder(route)),
50
+ routePath: computed(() => route?.path || ""),
51
+ routeRecordId,
52
+ apiUrlTemplate,
53
+ listUrlTemplate,
54
+ editUrlTemplate
55
+ });
56
+ const normalizedApiUrlTemplate = String(apiUrlTemplate || "").trim();
57
+ const effectiveApiSuffix = normalizedApiUrlTemplate ? viewUiRuntime.apiSuffix : apiSuffix;
58
+ const operationAdapter = resolveOperationAdapter(adapter, {
59
+ context: "useView adapter"
60
+ });
61
+ const operationScope = operationAdapter.useOperationScope({
62
+ ownershipFilter,
63
+ surfaceId,
64
+ access,
65
+ placementSource,
66
+ apiSuffix: effectiveApiSuffix,
67
+ readEnabled,
68
+ queryKeyFactory,
69
+ permissionSets: {
70
+ view: viewPermissions
71
+ },
72
+ realtime: resolveOperationRealtimeOptions({
73
+ realtime,
74
+ fallbackRealtime: resource?.operations?.view?.realtime ||
75
+ resource?.operations?.list?.realtime ||
76
+ null
77
+ })
78
+ });
79
+ const queryParamsContext = computed(() => {
80
+ return Object.freeze({
81
+ surfaceId: operationScope.routeContext.currentSurfaceId.value,
82
+ scopeParamValue: operationScope.scopeParamValue.value,
83
+ ownershipFilter: operationScope.normalizedOwnershipFilter,
84
+ recordId: viewUiRuntime.recordId.value
85
+ });
86
+ });
87
+ const baseQueryKey = computed(() => {
88
+ const source = Array.isArray(operationScope.queryKey.value) ? operationScope.queryKey.value : [];
89
+ const next = [...source];
90
+ if (!includeRecordIdInQueryKey) {
91
+ return next;
92
+ }
93
+
94
+ const recordIdToken = String(viewUiRuntime.recordId.value || "").trim();
95
+ return [...next, recordIdToken];
96
+ });
97
+ const requestQueryRuntime = createRequestQueryRuntime({
98
+ requestQueryParams,
99
+ requestFieldsets,
100
+ context: queryParamsContext,
101
+ sourceQueryKey: baseQueryKey
102
+ });
103
+ const canView = operationScope.permissionGate("view");
104
+
105
+ const endpointResource = useEndpointResource({
106
+ queryKey: requestQueryRuntime.queryKey,
107
+ path: operationScope.apiPath,
108
+ enabled: operationScope.queryCanRun(canView),
109
+ client,
110
+ readMethod,
111
+ readQuery: requestQueryRuntime.requestQuery,
112
+ transport,
113
+ requestRecovery,
114
+ requestRecoveryLabel,
115
+ refreshOnPull: true,
116
+ fallbackLoadError
117
+ });
118
+
119
+ const view = useViewCore({
120
+ resource: endpointResource,
121
+ model,
122
+ canView,
123
+ mapLoadedToModel,
124
+ notFoundStatuses,
125
+ notFoundMessage
126
+ });
127
+
128
+ const loadError = operationScope.loadError(view.loadError);
129
+ const isLoading = operationScope.isLoading(view.isLoading);
130
+ const isFetching = operationScope.isLoading(view.isFetching);
131
+ const isRefetching = computed(() => Boolean(isFetching.value && !isLoading.value));
132
+ setupOperationErrorReporting({
133
+ source: `${placementSource}.load`,
134
+ loadError,
135
+ notFoundError: view.notFoundError,
136
+ dedupeWindowMs: 0,
137
+ loadActionFactory: () => ({
138
+ label: "Retry",
139
+ dismissOnRun: true,
140
+ handler() {
141
+ void view.refresh();
142
+ }
143
+ })
144
+ });
145
+
146
+ return proxyRefs({
147
+ record: view.record,
148
+ recordId: viewUiRuntime.recordId,
149
+ listUrl: viewUiRuntime.listUrl,
150
+ editUrl: viewUiRuntime.editUrl,
151
+ resolveParams: viewUiRuntime.resolveParams,
152
+ canView,
153
+ isLoading,
154
+ isFetching,
155
+ isRefetching,
156
+ isNotFound: view.isNotFound,
157
+ notFoundError: view.notFoundError,
158
+ loadError,
159
+ refresh: view.refresh,
160
+ resource: endpointResource
161
+ });
162
+ }
163
+
164
+ export { useView };