@jsudc/react 0.4.0 → 0.5.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.
- package/README.md +615 -11
- package/dist/actions/RowActionsMenu.d.ts +45 -0
- package/dist/actions/RowActionsMenu.js +161 -0
- package/dist/actions/RowActionsMenu.js.map +1 -0
- package/dist/actions/bulk.d.ts +81 -0
- package/dist/actions/bulk.js +54 -0
- package/dist/actions/bulk.js.map +1 -0
- package/dist/actions/row.d.ts +50 -0
- package/dist/actions/row.js +34 -0
- package/dist/actions/row.js.map +1 -0
- package/dist/actions/useRowActionRunner.d.ts +26 -0
- package/dist/actions/useRowActionRunner.js +198 -0
- package/dist/actions/useRowActionRunner.js.map +1 -0
- package/dist/calendar/CalendarRenderer.js +4 -3
- package/dist/calendar/CalendarRenderer.js.map +1 -1
- package/dist/cards/CardRenderer.d.ts +6 -0
- package/dist/cards/CardRenderer.js +45 -9
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/chart/ChartRenderer.js +6 -4
- package/dist/chart/ChartRenderer.js.map +1 -1
- package/dist/chart/ChartWindowControl.js +1 -1
- package/dist/data-view/BulkBar.d.ts +36 -0
- package/dist/data-view/BulkBar.js +239 -0
- package/dist/data-view/BulkBar.js.map +1 -0
- package/dist/data-view/FilePreview.js +1 -1
- package/dist/data-view/FilterBuilder.js +1 -1
- package/dist/data-view/FilterChips.js +1 -1
- package/dist/data-view/LiveIndicator.d.ts +10 -0
- package/dist/data-view/LiveIndicator.js +33 -0
- package/dist/data-view/LiveIndicator.js.map +1 -0
- package/dist/data-view/UdcDataView.d.ts +28 -1
- package/dist/data-view/UdcDataView.js +76 -9
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -2
- package/dist/i18n/translations.js +144 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +13 -4
- package/dist/kanban/KanbanCard.js +1 -1
- package/dist/kanban/KanbanRenderer.js +5 -4
- package/dist/kanban/KanbanRenderer.js.map +1 -1
- package/dist/lookup/batch.js +1 -1
- package/dist/lookup/options.js +4 -1
- package/dist/lookup/options.js.map +1 -1
- package/dist/lookup/useUdcLookup.js +9 -3
- package/dist/lookup/useUdcLookup.js.map +1 -1
- package/dist/map/MapRenderer.js +3 -2
- package/dist/map/MapRenderer.js.map +1 -1
- package/dist/renderers/types.d.ts +32 -1
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +17 -0
- package/dist/rows/useRowActivation.js +37 -5
- package/dist/rows/useRowActivation.js.map +1 -1
- package/dist/rows/useRowSelection.d.ts +92 -0
- package/dist/rows/useRowSelection.js +156 -0
- package/dist/rows/useRowSelection.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.js +1 -1
- package/dist/schema-editor/FieldFormDialog.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/dist/table/CellEditor.js +1 -1
- package/dist/table/Pager.d.ts +10 -2
- package/dist/table/Pager.js +26 -20
- package/dist/table/Pager.js.map +1 -1
- package/dist/table/SelectCheckbox.d.ts +15 -0
- package/dist/table/SelectCheckbox.js +37 -0
- package/dist/table/SelectCheckbox.js.map +1 -0
- package/dist/table/TableRenderer.d.ts +13 -0
- package/dist/table/TableRenderer.js +284 -125
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.js +1 -1
- package/dist/table/index.d.ts +1 -0
- package/dist/table/states.js +1 -1
- package/dist/table/useRowWindow.d.ts +82 -0
- package/dist/table/useRowWindow.js +182 -0
- package/dist/table/useRowWindow.js.map +1 -0
- package/dist/table.js.map +1 -1
- package/dist/tree/TreeRenderer.d.ts +2 -0
- package/dist/tree/TreeRenderer.js +15 -9
- package/dist/tree/TreeRenderer.js.map +1 -1
- package/dist/udc/changeFeed.d.ts +107 -0
- package/dist/udc/changeFeed.js +281 -0
- package/dist/udc/changeFeed.js.map +1 -0
- package/dist/udc/changes.d.ts +40 -0
- package/dist/udc/changes.js +85 -0
- package/dist/udc/changes.js.map +1 -0
- package/dist/udc/client.js +5 -2
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +93 -20
- package/dist/udc/hooks.js +115 -11
- package/dist/udc/hooks.js.map +1 -1
- package/dist/udc/keys.d.ts +2 -0
- package/dist/udc/keys.js.map +1 -1
- package/dist/udc/listCache.d.ts +11 -0
- package/dist/udc/listCache.js +38 -0
- package/dist/udc/listCache.js.map +1 -0
- package/dist/udc/provider.d.ts +34 -2
- package/dist/udc/provider.js +28 -2
- package/dist/udc/provider.js.map +1 -1
- package/dist/udc/unauthenticated.d.ts +4 -0
- package/dist/udc/unauthenticated.js +17 -0
- package/dist/udc/unauthenticated.js.map +1 -0
- package/dist/ui-kit/types.d.ts +14 -0
- package/package.json +3 -3
package/dist/udc/hooks.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { useUdcChanges } from "./changes.js";
|
|
1
2
|
import { useUdcClient } from "./client.js";
|
|
2
3
|
import { udcKeys } from "./keys.js";
|
|
4
|
+
import { applyToListRows, isInfinite } from "./listCache.js";
|
|
5
|
+
import { evaluateFilter, isVersionConflict } from "@jsudc/core";
|
|
3
6
|
import { useState } from "react";
|
|
4
|
-
import { isVersionConflict } from "@jsudc/core";
|
|
5
7
|
import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
6
8
|
// src/udc/hooks.ts
|
|
7
9
|
function useUdcCollections() {
|
|
@@ -41,6 +43,11 @@ function freshnessOf(res) {
|
|
|
41
43
|
stale: res?.stale === true
|
|
42
44
|
};
|
|
43
45
|
}
|
|
46
|
+
/** `{ search }` for a non-blank text, else nothing: spread into a list request and its query key. */
|
|
47
|
+
function searchPart(search) {
|
|
48
|
+
const text = search?.trim();
|
|
49
|
+
return text ? { search: text } : {};
|
|
50
|
+
}
|
|
44
51
|
/** The `offset` a 1-based page asks for. */
|
|
45
52
|
function pageOffset(page, limit) {
|
|
46
53
|
return Math.max(0, Math.floor(page) - 1) * limit;
|
|
@@ -60,12 +67,17 @@ function useUdcCollection(args) {
|
|
|
60
67
|
const page = Math.max(1, args.page ?? 1);
|
|
61
68
|
const enabled = args.enabled ?? true;
|
|
62
69
|
const byCursor = args.capabilities?.paging?.includes("cursor") ?? true;
|
|
63
|
-
const refetchInterval =
|
|
70
|
+
const refetchInterval = useUdcChanges(collection, void 0, {
|
|
71
|
+
capabilities: args.capabilities,
|
|
72
|
+
enabled
|
|
73
|
+
}).live ? false : pollInterval(args.refetchInterval);
|
|
74
|
+
const searched = searchPart(args.search);
|
|
64
75
|
const infiniteParams = {
|
|
65
76
|
filter,
|
|
66
77
|
sort,
|
|
67
78
|
limit,
|
|
68
|
-
mode: "infinite"
|
|
79
|
+
mode: "infinite",
|
|
80
|
+
...searched
|
|
69
81
|
};
|
|
70
82
|
const infinite = useInfiniteQuery({
|
|
71
83
|
queryKey: udcKeys.list(collection, infiniteParams),
|
|
@@ -73,6 +85,7 @@ function useUdcCollection(args) {
|
|
|
73
85
|
collection,
|
|
74
86
|
...filter ? { filter } : {},
|
|
75
87
|
sort,
|
|
88
|
+
...searched,
|
|
76
89
|
page: typeof pageParam === "number" ? {
|
|
77
90
|
limit,
|
|
78
91
|
offset: pageParam
|
|
@@ -85,7 +98,8 @@ function useUdcCollection(args) {
|
|
|
85
98
|
getNextPageParam: (last, all) => {
|
|
86
99
|
if (byCursor) return last.next_cursor ?? void 0;
|
|
87
100
|
const loaded = all.reduce((n, p) => n + p.rows.length, 0);
|
|
88
|
-
|
|
101
|
+
const more = last.total !== null ? loaded < last.total : last.rows.length >= limit;
|
|
102
|
+
return last.rows.length > 0 && more ? loaded : void 0;
|
|
89
103
|
},
|
|
90
104
|
placeholderData: keepPreviousData,
|
|
91
105
|
enabled: enabled && mode === "infinite",
|
|
@@ -96,7 +110,8 @@ function useUdcCollection(args) {
|
|
|
96
110
|
sort,
|
|
97
111
|
limit,
|
|
98
112
|
mode: "pages",
|
|
99
|
-
page
|
|
113
|
+
page,
|
|
114
|
+
...searched
|
|
100
115
|
};
|
|
101
116
|
const paged = useQuery({
|
|
102
117
|
queryKey: udcKeys.list(collection, pagesParams),
|
|
@@ -104,6 +119,7 @@ function useUdcCollection(args) {
|
|
|
104
119
|
collection,
|
|
105
120
|
...filter ? { filter } : {},
|
|
106
121
|
sort,
|
|
122
|
+
...searched,
|
|
107
123
|
page: {
|
|
108
124
|
limit,
|
|
109
125
|
offset: pageOffset(page, limit)
|
|
@@ -172,6 +188,7 @@ async function fetchAllRows(client, args) {
|
|
|
172
188
|
collection,
|
|
173
189
|
...filter ? { filter } : {},
|
|
174
190
|
sort,
|
|
191
|
+
...searchPart(args.search),
|
|
175
192
|
page
|
|
176
193
|
}, args.signal ? { signal: args.signal } : void 0);
|
|
177
194
|
if (rows.length === 0) freshness = {
|
|
@@ -208,11 +225,17 @@ function useUdcAllRows(args) {
|
|
|
208
225
|
const max = args.max ?? 2e3;
|
|
209
226
|
const cursor = args.capabilities?.paging?.includes("cursor") ?? true;
|
|
210
227
|
const [progress, setProgress] = useState(null);
|
|
228
|
+
const feed = useUdcChanges(collection, void 0, {
|
|
229
|
+
capabilities: args.capabilities,
|
|
230
|
+
enabled: args.enabled ?? true
|
|
231
|
+
});
|
|
232
|
+
const searched = searchPart(args.search);
|
|
211
233
|
const key = {
|
|
212
234
|
filter,
|
|
213
235
|
sort,
|
|
214
236
|
limit: max,
|
|
215
|
-
mode: "all"
|
|
237
|
+
mode: "all",
|
|
238
|
+
...searched
|
|
216
239
|
};
|
|
217
240
|
const query = useQuery({
|
|
218
241
|
queryKey: udcKeys.list(collection, key),
|
|
@@ -228,6 +251,7 @@ function useUdcAllRows(args) {
|
|
|
228
251
|
sort,
|
|
229
252
|
max,
|
|
230
253
|
cursor,
|
|
254
|
+
...searched,
|
|
231
255
|
signal,
|
|
232
256
|
onProgress: (loaded, total) => setProgress({
|
|
233
257
|
loaded,
|
|
@@ -240,7 +264,7 @@ function useUdcAllRows(args) {
|
|
|
240
264
|
},
|
|
241
265
|
placeholderData: keepPreviousData,
|
|
242
266
|
enabled: args.enabled ?? true,
|
|
243
|
-
refetchInterval: pollInterval(args.refetchInterval)
|
|
267
|
+
refetchInterval: feed.live ? false : pollInterval(args.refetchInterval)
|
|
244
268
|
});
|
|
245
269
|
const rows = query.data?.rows ?? [];
|
|
246
270
|
const total = query.data?.total ?? null;
|
|
@@ -256,9 +280,6 @@ function useUdcAllRows(args) {
|
|
|
256
280
|
...freshnessOf(query.data)
|
|
257
281
|
};
|
|
258
282
|
}
|
|
259
|
-
function isInfinite(data) {
|
|
260
|
-
return "pages" in data;
|
|
261
|
-
}
|
|
262
283
|
/** `data` with every row whose id is `id` passed through `patch`. */
|
|
263
284
|
function patchRowInList(data, id, patch) {
|
|
264
285
|
if (!data) return data;
|
|
@@ -356,6 +377,89 @@ function useUdcSchema(collection) {
|
|
|
356
377
|
})
|
|
357
378
|
};
|
|
358
379
|
}
|
|
359
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Which cached row a `mutate_many` request touches: one of its `ids`, or a row
|
|
382
|
+
* its `filter` matches (evaluated in the browser, `evaluateFilter`) that is
|
|
383
|
+
* not among `except_ids`. A filter the browser cannot evaluate touches no
|
|
384
|
+
* cached row: the invalidation after the call brings the server's answer.
|
|
385
|
+
*/
|
|
386
|
+
function mutateManyTouches(vars) {
|
|
387
|
+
if (vars.ids) {
|
|
388
|
+
const ids = new Set(vars.ids);
|
|
389
|
+
return (row) => ids.has(row.__meta.id);
|
|
390
|
+
}
|
|
391
|
+
const except = new Set(vars.except_ids ?? []);
|
|
392
|
+
const filter = vars.filter;
|
|
393
|
+
return (row) => {
|
|
394
|
+
if (except.has(row.__meta.id)) return false;
|
|
395
|
+
try {
|
|
396
|
+
return evaluateFilter(filter, row);
|
|
397
|
+
} catch {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Change (`update`, the patch in `row`) or delete many rows of a collection in
|
|
404
|
+
* one `mutate_many` request: by `ids`, or by `filter` with `except_ids` ("all
|
|
405
|
+
* that match, except these"). Like `useUdcMutate` for one row, the loaded
|
|
406
|
+
* rows are patched (or removed) in every cached list at once, put back if the
|
|
407
|
+
* call fails, and the collection's lists and lookups are invalidated once it
|
|
408
|
+
* settles. Resolves to the server's `{ updated, failed }`: `failed` names the
|
|
409
|
+
* ids that were not changed, and why.
|
|
410
|
+
*/
|
|
411
|
+
function useUdcMutateMany(collection) {
|
|
412
|
+
const client = useUdcClient();
|
|
413
|
+
const qc = useQueryClient();
|
|
414
|
+
return useMutation({
|
|
415
|
+
mutationFn: (vars) => client.mutateMany({
|
|
416
|
+
collection,
|
|
417
|
+
...vars
|
|
418
|
+
}),
|
|
419
|
+
onMutate: async (vars) => {
|
|
420
|
+
await qc.cancelQueries({ queryKey: udcKeys.lists(collection) });
|
|
421
|
+
const snapshot = qc.getQueriesData({ queryKey: udcKeys.lists(collection) });
|
|
422
|
+
const touches = mutateManyTouches(vars);
|
|
423
|
+
const set = vars.row;
|
|
424
|
+
const patch = vars.op === "update" && set ? (r) => ({
|
|
425
|
+
...r,
|
|
426
|
+
...set,
|
|
427
|
+
__meta: r.__meta
|
|
428
|
+
}) : void 0;
|
|
429
|
+
if (vars.op === "delete" || patch) qc.setQueriesData({ queryKey: udcKeys.lists(collection) }, (data) => applyToListRows(data, touches, patch));
|
|
430
|
+
return { snapshot };
|
|
431
|
+
},
|
|
432
|
+
onError: (_err, _vars, ctx) => {
|
|
433
|
+
for (const [key, data] of ctx?.snapshot ?? []) qc.setQueryData(key, data);
|
|
434
|
+
},
|
|
435
|
+
onSettled: () => Promise.all([
|
|
436
|
+
qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),
|
|
437
|
+
qc.invalidateQueries({ queryKey: udcKeys.lookups(collection) }),
|
|
438
|
+
qc.invalidateQueries({ queryKey: [
|
|
439
|
+
"udc",
|
|
440
|
+
"lookup-options",
|
|
441
|
+
collection
|
|
442
|
+
] })
|
|
443
|
+
])
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
function useUdcAction(action, options = {}) {
|
|
447
|
+
const client = useUdcClient();
|
|
448
|
+
const qc = useQueryClient();
|
|
449
|
+
const { invalidates, onSettled, ...rest } = options;
|
|
450
|
+
return useMutation({
|
|
451
|
+
...rest,
|
|
452
|
+
mutationFn: (payload) => callAction(client, action, payload),
|
|
453
|
+
onSettled: async (...args) => {
|
|
454
|
+
await Promise.all((invalidates ?? []).flatMap((c) => [qc.invalidateQueries({ queryKey: udcKeys.lists(c) }), qc.invalidateQueries({ queryKey: udcKeys.lookups(c) })]));
|
|
455
|
+
return onSettled?.(...args);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/** `client.call` for a host action given by definition or by name (the answer unchecked by name). */
|
|
460
|
+
function callAction(client, action, payload) {
|
|
461
|
+
return client.call.bind(client)(action, payload);
|
|
462
|
+
}
|
|
463
|
+
export { ALL_ROWS_MAX, applyToListRows, callAction, fetchAllRows, freshnessOf, mutateManyTouches, pageOffset, patchRowInList, pollInterval, searchPart, useUdcAction, useUdcAllRows, useUdcCollection, useUdcCollections, useUdcDescribe, useUdcMutate, useUdcMutateMany, useUdcSchema, useUdcSource };
|
|
360
464
|
|
|
361
465
|
//# sourceMappingURL=hooks.js.map
|
package/dist/udc/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":[],"sources":["../../src/udc/hooks.ts"],"sourcesContent":["import {\n type ActionRequest,\n type Capabilities,\n type FilterNode,\n isVersionConflict,\n type ListResponse,\n type Row,\n type SortKey,\n} from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport {\n type InfiniteData,\n keepPreviousData,\n type QueryClient,\n useInfiniteQuery,\n useMutation,\n useQuery,\n useQueryClient,\n} from \"@tanstack/react-query\";\nimport { useState } from \"react\";\nimport { useUdcClient } from \"./client.js\";\nimport { type ListKeyParams, type PagingMode, udcKeys } from \"./keys.js\";\n\nexport function useUdcCollections() {\n const client = useUdcClient();\n return useQuery({ queryKey: udcKeys.collections(), queryFn: () => client.collections() });\n}\n\nexport function useUdcDescribe(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.describe(collection),\n queryFn: () => client.describe(collection),\n staleTime: 5 * 60_000,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\n/** The file a `source_yaml` collection is read from (`source.read`); fetched again on every mount. */\nexport function useUdcSource(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.source(collection),\n queryFn: () => client.sourceRead(collection),\n staleTime: 0,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\nexport interface UseUdcCollectionArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n mode: PagingMode;\n pageLimit: number;\n /** 1-based; pages mode only. */\n page?: number;\n enabled?: boolean;\n /** From `describe`: a source without `cursor` paging is walked by offset in infinite mode too. */\n capabilities?: Pick<Capabilities, \"paging\"> | undefined;\n /** Poll: refetch the loaded rows this often (the view's `refresh_interval_ms`). */\n refetchInterval?: number | undefined;\n}\n\nexport interface UdcCollectionResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => void;\n /** Infinite mode only; always false in pages mode. */\n hasNextPage: boolean;\n isFetchingNextPage: boolean;\n fetchNextPage: () => void;\n /** A source serving a fetched copy: when it was fetched, and whether the last refresh failed. */\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/** `refetchInterval` for TanStack: a positive number of ms, else off. */\nexport function pollInterval(ms: number | undefined): number | false {\n return typeof ms === \"number\" && ms > 0 ? ms : false;\n}\n\n/** The freshness of a list answer: `fetched_at` and `stale` when the source sent them. */\nexport function freshnessOf(res: Pick<ListResponse, \"fetched_at\" | \"stale\"> | undefined): {\n fetchedAt: string | null;\n stale: boolean;\n} {\n return { fetchedAt: res?.fetched_at ?? null, stale: res?.stale === true };\n}\n\n/** The `offset` a 1-based page asks for. */\nexport function pageOffset(page: number, limit: number): number {\n return Math.max(0, Math.floor(page) - 1) * limit;\n}\n\n/**\n * Rows of one collection. Infinite mode follows `next_cursor` page by page\n * (`useInfiniteQuery`), or the next `offset` while rows remain when the\n * source pages by offset only; pages mode asks for one `offset` page\n * (`useQuery`). Both hooks are always mounted and the inactive one is\n * disabled, so switching modes keeps each cache warm. `refetchInterval`\n * polls the active one.\n */\nexport function useUdcCollection(args: UseUdcCollectionArgs): UdcCollectionResult {\n const client = useUdcClient();\n const { collection, filter, mode, pageLimit: limit } = args;\n const sort = args.sort ?? [];\n const page = Math.max(1, args.page ?? 1);\n const enabled = args.enabled ?? true;\n const byCursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const refetchInterval = pollInterval(args.refetchInterval);\n\n const infiniteParams: ListKeyParams = { filter, sort, limit, mode: \"infinite\" };\n const infinite = useInfiniteQuery({\n queryKey: udcKeys.list(collection, infiniteParams),\n queryFn: ({ pageParam, signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n page:\n typeof pageParam === \"number\"\n ? { limit, offset: pageParam }\n : pageParam\n ? { limit, cursor: pageParam }\n : { limit },\n },\n { signal },\n ),\n initialPageParam: null as string | number | null,\n getNextPageParam: (last, all) => {\n if (byCursor) return last.next_cursor ?? undefined;\n const loaded = all.reduce((n, p) => n + p.rows.length, 0);\n return last.rows.length > 0 && last.total !== null && loaded < last.total\n ? loaded\n : undefined;\n },\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"infinite\",\n refetchInterval,\n });\n\n const pagesParams: ListKeyParams = { filter, sort, limit, mode: \"pages\", page };\n const paged = useQuery({\n queryKey: udcKeys.list(collection, pagesParams),\n queryFn: ({ signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n page: { limit, offset: pageOffset(page, limit) },\n },\n { signal },\n ),\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"pages\",\n refetchInterval,\n });\n\n if (mode === \"infinite\") {\n const pages = infinite.data?.pages ?? [];\n return {\n rows: pages.flatMap((p) => p.rows),\n total: pages[0]?.total ?? null,\n isLoading: infinite.isLoading,\n isFetching: infinite.isFetching,\n error: infinite.error,\n refetch: () => void infinite.refetch(),\n hasNextPage: infinite.hasNextPage,\n isFetchingNextPage: infinite.isFetchingNextPage,\n fetchNextPage: () => void infinite.fetchNextPage(),\n ...freshnessOf(pages[0]),\n };\n }\n return {\n rows: paged.data?.rows ?? [],\n total: paged.data?.total ?? null,\n isLoading: paged.isLoading,\n isFetching: paged.isFetching,\n error: paged.error,\n refetch: () => void paged.refetch(),\n hasNextPage: false,\n isFetchingNextPage: false,\n fetchNextPage: () => {},\n ...freshnessOf(paged.data),\n };\n}\n\nexport const ALL_ROWS_MAX = 2000;\nconst ALL_ROWS_PAGE = 500;\n\nexport interface FetchAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Stop after this many rows. */\n max: number;\n /** Rows per `list` call. */\n pageLimit?: number;\n /** Keyset paging unless the source pages by offset only. */\n cursor: boolean;\n signal?: AbortSignal;\n onProgress?: (loaded: number, total: number | null) => void;\n}\n\n/**\n * Every row of a filter, `list` page after page, until `total` or `max`.\n * Follows `next_cursor` when keyset paging is on; a source that answers no\n * cursor while rows remain is walked on by offset. Answers one list whose\n * `total` is the server's (so `rows.length < total` means capped), with the\n * first page's `fetched_at` and `stale`.\n */\nexport async function fetchAllRows(\n client: UdcClient,\n args: FetchAllRowsArgs,\n): Promise<ListResponse> {\n const { collection, filter, max } = args;\n const sort = args.sort ?? [];\n const pageLimit = args.pageLimit ?? ALL_ROWS_PAGE;\n const rows: Row[] = [];\n let total: number | null = null;\n let freshness: Pick<ListResponse, \"fetched_at\" | \"stale\"> = {};\n let cursor: string | null = null;\n let byCursor = args.cursor;\n while (rows.length < max) {\n const limit = Math.min(pageLimit, max - rows.length);\n const page = byCursor\n ? cursor\n ? { limit, cursor }\n : { limit }\n : { limit, offset: rows.length };\n const res = await client.list(\n { collection, ...(filter ? { filter } : {}), sort, page },\n args.signal ? { signal: args.signal } : undefined,\n );\n if (rows.length === 0) {\n freshness = {\n ...(res.fetched_at === undefined ? {} : { fetched_at: res.fetched_at }),\n ...(res.stale === undefined ? {} : { stale: res.stale }),\n };\n }\n rows.push(...res.rows);\n total = res.total;\n args.onProgress?.(rows.length, total);\n if (res.rows.length === 0 || (total !== null && rows.length >= total)) break;\n if (byCursor) {\n if (res.next_cursor) cursor = res.next_cursor;\n else if (total === null) break;\n else byCursor = false;\n } else if (total === null && res.rows.length < limit) {\n break;\n }\n }\n return { ...freshness, rows, next_cursor: null, total: total ?? rows.length };\n}\n\nexport interface UseUdcAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Default 2,000. */\n max?: number;\n /** From `describe`: whether the source pages by cursor. */\n capabilities?: Pick<Capabilities, \"paging\"> | undefined;\n enabled?: boolean;\n /** Poll: refetch every row this often (the view's `refresh_interval_ms`). */\n refetchInterval?: number | undefined;\n}\n\nexport interface UdcAllRowsResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => Promise<unknown>;\n /** More rows match than `max`: only the first `max` are here. */\n capped: boolean;\n /** Rows loaded so far by the fetch in flight, for a progress bar. */\n progress: { loaded: number; total: number | null } | null;\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/**\n * All rows of the current filter in one cached list: what the kanban (and\n * the calendar, tree, map and charts after it) draw from. The cache entry\n * sits under `udcKeys.lists(collection)`, so `useUdcMutate`'s optimistic\n * patches and invalidations reach it like every other list.\n */\nexport function useUdcAllRows(args: UseUdcAllRowsArgs): UdcAllRowsResult {\n const client = useUdcClient();\n const { collection, filter } = args;\n const sort = args.sort ?? [];\n const max = args.max ?? ALL_ROWS_MAX;\n const cursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const [progress, setProgress] = useState<UdcAllRowsResult[\"progress\"]>(null);\n\n const key: ListKeyParams = { filter, sort, limit: max, mode: \"all\" };\n const query = useQuery({\n queryKey: udcKeys.list(collection, key),\n queryFn: async ({ signal }) => {\n setProgress({ loaded: 0, total: null });\n try {\n return await fetchAllRows(client, {\n collection,\n filter,\n sort,\n max,\n cursor,\n signal,\n onProgress: (loaded, total) => setProgress({ loaded, total }),\n });\n } finally {\n setProgress(null);\n }\n },\n placeholderData: keepPreviousData,\n enabled: args.enabled ?? true,\n refetchInterval: pollInterval(args.refetchInterval),\n });\n\n const rows = query.data?.rows ?? [];\n const total = query.data?.total ?? null;\n return {\n rows,\n total,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: query.error,\n refetch: () => query.refetch(),\n capped: total !== null && rows.length < total,\n progress,\n ...freshnessOf(query.data),\n };\n}\n\ntype ListCache = ListResponse | InfiniteData<ListResponse, unknown>;\n\nfunction isInfinite(data: ListCache): data is InfiniteData<ListResponse, unknown> {\n return \"pages\" in data;\n}\n\n/** `data` with every row whose id is `id` passed through `patch`. */\nexport function patchRowInList(\n data: ListCache | undefined,\n id: string,\n patch: (row: Row) => Row,\n): ListCache | undefined {\n if (!data) return data;\n const patchPage = (page: ListResponse): ListResponse =>\n page.rows.some((r) => r.__meta.id === id)\n ? { ...page, rows: page.rows.map((r) => (r.__meta.id === id ? patch(r) : r)) }\n : page;\n return isInfinite(data) ? { ...data, pages: data.pages.map(patchPage) } : patchPage(data);\n}\n\nfunction patchRowEverywhere(\n qc: QueryClient,\n collection: string,\n id: string,\n patch: (row: Row) => Row,\n) {\n qc.setQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) }, (data) =>\n patchRowInList(data, id, patch),\n );\n}\n\nexport type UdcMutateVars = Omit<ActionRequest<\"mutate\">, \"collection\">;\n\n/**\n * Insert / update / delete one row. An update is applied optimistically to\n * the row in every cached list page and rolled back if the server says no.\n * A `version_conflict` additionally re-reads the row, so the cache holds the\n * value that won; the error still reaches the caller. Lists are invalidated\n * once the call settles.\n */\nexport function useUdcMutate(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: (vars: UdcMutateVars) => client.mutate({ collection, ...vars }),\n onMutate: async (vars) => {\n await qc.cancelQueries({ queryKey: udcKeys.lists(collection) });\n const snapshot = qc.getQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) });\n const { id, row } = vars;\n if (vars.op === \"update\" && id && row) {\n patchRowEverywhere(qc, collection, id, (r) => ({ ...r, ...row, __meta: r.__meta }));\n }\n return { snapshot };\n },\n onSuccess: (res) => {\n patchRowEverywhere(qc, collection, res.row.__meta.id, () => res.row);\n },\n onError: async (err, vars, ctx) => {\n for (const [key, data] of ctx?.snapshot ?? []) qc.setQueryData(key, data);\n if (isVersionConflict(err) && vars.id) {\n try {\n const fresh = await client.read(collection, vars.id);\n patchRowEverywhere(qc, collection, vars.id, () => fresh.row);\n } catch {\n // The invalidation below refetches the lists anyway.\n }\n }\n },\n // A row of this collection may be another collection's lookup label: those batches go stale too.\n onSettled: () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),\n qc.invalidateQueries({ queryKey: udcKeys.lookups(collection) }),\n qc.invalidateQueries({ queryKey: [\"udc\", \"lookup-options\", collection] }),\n ]),\n });\n}\n\n/**\n * The three schema edits. Each answers the new schema; `describe` (which\n * derives the columns) and the lists are refetched afterwards.\n */\nexport function useUdcSchema(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n const onSuccess = async () => {\n await qc.invalidateQueries({ queryKey: udcKeys.describe(collection) });\n await qc.invalidateQueries({ queryKey: udcKeys.lists(collection) });\n };\n\n const addField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.add_field\">, \"collection\">) =>\n client.schemaAddField({ collection, ...req }),\n onSuccess,\n });\n const updateField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.update_field\">, \"collection\">) =>\n client.schemaUpdateField({ collection, ...req }),\n onSuccess,\n });\n const softDeleteField = useMutation({\n mutationFn: (field: string) => client.schemaSoftDeleteField({ collection, field }),\n onSuccess,\n });\n return { addField, updateField, softDeleteField };\n}\n"],"mappings":";;;;;;AAuBA,SAAgB,oBAAoB;CAClC,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EAAE,UAAU,QAAQ,YAAY;EAAG,eAAe,OAAO,YAAY;CAAE,CAAC;AAC1F;AAEA,SAAgB,eAAe,YAAoB,OAA8B,CAAC,GAAG;CACnF,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EACd,UAAU,QAAQ,SAAS,UAAU;EACrC,eAAe,OAAO,SAAS,UAAU;EACzC,WAAW;EACX,UAAU,KAAK,WAAW,SAAS,eAAe;CACpD,CAAC;AACH;;AAGA,SAAgB,aAAa,YAAoB,OAA8B,CAAC,GAAG;CACjF,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EACd,UAAU,QAAQ,OAAO,UAAU;EACnC,eAAe,OAAO,WAAW,UAAU;EAC3C,WAAW;EACX,UAAU,KAAK,WAAW,SAAS,eAAe;CACpD,CAAC;AACH;;AAkCA,SAAgB,aAAa,IAAwC;CACnE,OAAO,OAAO,OAAO,YAAY,KAAK,IAAI,KAAK;AACjD;;AAGA,SAAgB,YAAY,KAG1B;CACA,OAAO;EAAE,WAAW,KAAK,cAAc;EAAM,OAAO,KAAK,UAAU;CAAK;AAC1E;;AAGA,SAAgB,WAAW,MAAc,OAAuB;CAC9D,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI;AAC7C;;;;;;;;;AAUA,SAAgB,iBAAiB,MAAiD;CAChF,MAAM,SAAS,aAAa;CAC5B,MAAM,EAAE,YAAY,QAAQ,MAAM,WAAW,UAAU;CACvD,MAAM,OAAO,KAAK,QAAQ,CAAC;CAC3B,MAAM,OAAO,K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AC;GACjD;EACF,CAKmB;EAAa,iBAJR,YAAY;GAClC,aAAa,UAAkB,OAAO,sBAAsB;IAAE;IAAY;GAAM,CAAC;GACjF;EACF,CACgC;CAAgB;AAClD"}
|
|
1
|
+
{"version":3,"file":"hooks.js","names":[],"sources":["../../src/udc/hooks.ts"],"sourcesContent":["import {\n type ActionRequest,\n type Capabilities,\n evaluateFilter,\n type FilterNode,\n type HostAction,\n type HostActionPayload,\n type HostActionResponse,\n isVersionConflict,\n type ListResponse,\n type Row,\n type SortKey,\n} from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport {\n keepPreviousData,\n type QueryClient,\n type UseMutationOptions,\n type UseMutationResult,\n useInfiniteQuery,\n useMutation,\n useQuery,\n useQueryClient,\n} from \"@tanstack/react-query\";\nimport { useState } from \"react\";\nimport { useUdcChanges } from \"./changes.js\";\nimport { useUdcClient } from \"./client.js\";\nimport { type ListKeyParams, type PagingMode, udcKeys } from \"./keys.js\";\nimport { applyToListRows, isInfinite, type ListCache } from \"./listCache.js\";\n\nexport { applyToListRows };\n\nexport function useUdcCollections() {\n const client = useUdcClient();\n return useQuery({ queryKey: udcKeys.collections(), queryFn: () => client.collections() });\n}\n\nexport function useUdcDescribe(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.describe(collection),\n queryFn: () => client.describe(collection),\n staleTime: 5 * 60_000,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\n/** The file a `source_yaml` collection is read from (`source.read`); fetched again on every mount. */\nexport function useUdcSource(collection: string, opts: { enabled?: boolean } = {}) {\n const client = useUdcClient();\n return useQuery({\n queryKey: udcKeys.source(collection),\n queryFn: () => client.sourceRead(collection),\n staleTime: 0,\n enabled: (opts.enabled ?? true) && collection !== \"\",\n });\n}\n\nexport interface UseUdcCollectionArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n mode: PagingMode;\n pageLimit: number;\n /** 1-based; pages mode only. */\n page?: number;\n enabled?: boolean;\n /**\n * From `describe`: a source without `cursor` paging is walked by offset in\n * infinite mode too; `changes` says whether it offers the change feed.\n */\n capabilities?: Pick<Capabilities, \"paging\" | \"changes\"> | undefined;\n /**\n * Poll: refetch the loaded rows this often (the view's `refresh_interval_ms`).\n * Suspended while the provider's change feed carries the collection.\n */\n refetchInterval?: number | undefined;\n /**\n * The search box's text, sent as `ListRequest.search` for a source that\n * answers search itself (`capabilities.search === \"source\"`); blank or\n * absent: no `search` in the request, nor in the query key.\n */\n search?: string | undefined;\n}\n\nexport interface UdcCollectionResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => void;\n /** Infinite mode only; always false in pages mode. */\n hasNextPage: boolean;\n isFetchingNextPage: boolean;\n fetchNextPage: () => void;\n /** A source serving a fetched copy: when it was fetched, and whether the last refresh failed. */\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/** `refetchInterval` for TanStack: a positive number of ms, else off. */\nexport function pollInterval(ms: number | undefined): number | false {\n return typeof ms === \"number\" && ms > 0 ? ms : false;\n}\n\n/** The freshness of a list answer: `fetched_at` and `stale` when the source sent them. */\nexport function freshnessOf(res: Pick<ListResponse, \"fetched_at\" | \"stale\"> | undefined): {\n fetchedAt: string | null;\n stale: boolean;\n} {\n return { fetchedAt: res?.fetched_at ?? null, stale: res?.stale === true };\n}\n\n/** `{ search }` for a non-blank text, else nothing: spread into a list request and its query key. */\nexport function searchPart(search: string | undefined): { search?: string } {\n const text = search?.trim();\n return text ? { search: text } : {};\n}\n\n/** The `offset` a 1-based page asks for. */\nexport function pageOffset(page: number, limit: number): number {\n return Math.max(0, Math.floor(page) - 1) * limit;\n}\n\n/**\n * Rows of one collection. Infinite mode follows `next_cursor` page by page\n * (`useInfiniteQuery`), or the next `offset` while rows remain when the\n * source pages by offset only; pages mode asks for one `offset` page\n * (`useQuery`). Both hooks are always mounted and the inactive one is\n * disabled, so switching modes keeps each cache warm. `refetchInterval`\n * polls the active one.\n */\nexport function useUdcCollection(args: UseUdcCollectionArgs): UdcCollectionResult {\n const client = useUdcClient();\n const { collection, filter, mode, pageLimit: limit } = args;\n const sort = args.sort ?? [];\n const page = Math.max(1, args.page ?? 1);\n const enabled = args.enabled ?? true;\n const byCursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n // The change feed (when the provider has one) refetches on events; the timer covers the rest.\n const feed = useUdcChanges(collection, undefined, {\n capabilities: args.capabilities,\n enabled,\n });\n const refetchInterval = feed.live ? false : pollInterval(args.refetchInterval);\n const searched = searchPart(args.search);\n\n const infiniteParams: ListKeyParams = { filter, sort, limit, mode: \"infinite\", ...searched };\n const infinite = useInfiniteQuery({\n queryKey: udcKeys.list(collection, infiniteParams),\n queryFn: ({ pageParam, signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n ...searched,\n page:\n typeof pageParam === \"number\"\n ? { limit, offset: pageParam }\n : pageParam\n ? { limit, cursor: pageParam }\n : { limit },\n },\n { signal },\n ),\n initialPageParam: null as string | number | null,\n getNextPageParam: (last, all) => {\n if (byCursor) return last.next_cursor ?? undefined;\n const loaded = all.reduce((n, p) => n + p.rows.length, 0);\n // No total (`total_count: false`): a full page means there may be more.\n const more = last.total !== null ? loaded < last.total : last.rows.length >= limit;\n return last.rows.length > 0 && more ? loaded : undefined;\n },\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"infinite\",\n refetchInterval,\n });\n\n const pagesParams: ListKeyParams = { filter, sort, limit, mode: \"pages\", page, ...searched };\n const paged = useQuery({\n queryKey: udcKeys.list(collection, pagesParams),\n queryFn: ({ signal }) =>\n client.list(\n {\n collection,\n ...(filter ? { filter } : {}),\n sort,\n ...searched,\n page: { limit, offset: pageOffset(page, limit) },\n },\n { signal },\n ),\n placeholderData: keepPreviousData,\n enabled: enabled && mode === \"pages\",\n refetchInterval,\n });\n\n if (mode === \"infinite\") {\n const pages = infinite.data?.pages ?? [];\n return {\n rows: pages.flatMap((p) => p.rows),\n total: pages[0]?.total ?? null,\n isLoading: infinite.isLoading,\n isFetching: infinite.isFetching,\n error: infinite.error,\n refetch: () => void infinite.refetch(),\n hasNextPage: infinite.hasNextPage,\n isFetchingNextPage: infinite.isFetchingNextPage,\n fetchNextPage: () => void infinite.fetchNextPage(),\n ...freshnessOf(pages[0]),\n };\n }\n return {\n rows: paged.data?.rows ?? [],\n total: paged.data?.total ?? null,\n isLoading: paged.isLoading,\n isFetching: paged.isFetching,\n error: paged.error,\n refetch: () => void paged.refetch(),\n hasNextPage: false,\n isFetchingNextPage: false,\n fetchNextPage: () => {},\n ...freshnessOf(paged.data),\n };\n}\n\nexport const ALL_ROWS_MAX = 2000;\nconst ALL_ROWS_PAGE = 500;\n\nexport interface FetchAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Stop after this many rows. */\n max: number;\n /** Rows per `list` call. */\n pageLimit?: number;\n /** Keyset paging unless the source pages by offset only. */\n cursor: boolean;\n /** Sent as `ListRequest.search` when not blank (a source that answers search). */\n search?: string | undefined;\n signal?: AbortSignal;\n onProgress?: (loaded: number, total: number | null) => void;\n}\n\n/**\n * Every row of a filter, `list` page after page, until `total` or `max`.\n * Follows `next_cursor` when keyset paging is on; a source that answers no\n * cursor while rows remain is walked on by offset. Answers one list whose\n * `total` is the server's (so `rows.length < total` means capped), with the\n * first page's `fetched_at` and `stale`.\n */\nexport async function fetchAllRows(\n client: UdcClient,\n args: FetchAllRowsArgs,\n): Promise<ListResponse> {\n const { collection, filter, max } = args;\n const sort = args.sort ?? [];\n const pageLimit = args.pageLimit ?? ALL_ROWS_PAGE;\n const rows: Row[] = [];\n let total: number | null = null;\n let freshness: Pick<ListResponse, \"fetched_at\" | \"stale\"> = {};\n let cursor: string | null = null;\n let byCursor = args.cursor;\n while (rows.length < max) {\n const limit = Math.min(pageLimit, max - rows.length);\n const page = byCursor\n ? cursor\n ? { limit, cursor }\n : { limit }\n : { limit, offset: rows.length };\n const res = await client.list(\n { collection, ...(filter ? { filter } : {}), sort, ...searchPart(args.search), page },\n args.signal ? { signal: args.signal } : undefined,\n );\n if (rows.length === 0) {\n freshness = {\n ...(res.fetched_at === undefined ? {} : { fetched_at: res.fetched_at }),\n ...(res.stale === undefined ? {} : { stale: res.stale }),\n };\n }\n rows.push(...res.rows);\n total = res.total;\n args.onProgress?.(rows.length, total);\n if (res.rows.length === 0 || (total !== null && rows.length >= total)) break;\n if (byCursor) {\n if (res.next_cursor) cursor = res.next_cursor;\n else if (total === null) break;\n else byCursor = false;\n } else if (total === null && res.rows.length < limit) {\n break;\n }\n }\n return { ...freshness, rows, next_cursor: null, total: total ?? rows.length };\n}\n\nexport interface UseUdcAllRowsArgs {\n collection: string;\n filter?: FilterNode | undefined;\n sort?: SortKey[];\n /** Default 2,000. */\n max?: number;\n /** From `describe`: whether the source pages by cursor, and offers the change feed. */\n capabilities?: Pick<Capabilities, \"paging\" | \"changes\"> | undefined;\n enabled?: boolean;\n /**\n * Poll: refetch every row this often (the view's `refresh_interval_ms`).\n * Suspended while the provider's change feed carries the collection.\n */\n refetchInterval?: number | undefined;\n /** Sent as `ListRequest.search` when not blank (`capabilities.search === \"source\"`). */\n search?: string | undefined;\n}\n\nexport interface UdcAllRowsResult {\n rows: Row[];\n total: number | null;\n isLoading: boolean;\n isFetching: boolean;\n error: Error | null;\n refetch: () => Promise<unknown>;\n /** More rows match than `max`: only the first `max` are here. */\n capped: boolean;\n /** Rows loaded so far by the fetch in flight, for a progress bar. */\n progress: { loaded: number; total: number | null } | null;\n fetchedAt: string | null;\n stale: boolean;\n}\n\n/**\n * All rows of the current filter in one cached list: what the kanban (and\n * the calendar, tree, map and charts after it) draw from. The cache entry\n * sits under `udcKeys.lists(collection)`, so `useUdcMutate`'s optimistic\n * patches and invalidations reach it like every other list.\n */\nexport function useUdcAllRows(args: UseUdcAllRowsArgs): UdcAllRowsResult {\n const client = useUdcClient();\n const { collection, filter } = args;\n const sort = args.sort ?? [];\n const max = args.max ?? ALL_ROWS_MAX;\n const cursor = args.capabilities?.paging?.includes(\"cursor\") ?? true;\n const [progress, setProgress] = useState<UdcAllRowsResult[\"progress\"]>(null);\n const feed = useUdcChanges(collection, undefined, {\n capabilities: args.capabilities,\n enabled: args.enabled ?? true,\n });\n\n const searched = searchPart(args.search);\n const key: ListKeyParams = { filter, sort, limit: max, mode: \"all\", ...searched };\n const query = useQuery({\n queryKey: udcKeys.list(collection, key),\n queryFn: async ({ signal }) => {\n setProgress({ loaded: 0, total: null });\n try {\n return await fetchAllRows(client, {\n collection,\n filter,\n sort,\n max,\n cursor,\n ...searched,\n signal,\n onProgress: (loaded, total) => setProgress({ loaded, total }),\n });\n } finally {\n setProgress(null);\n }\n },\n placeholderData: keepPreviousData,\n enabled: args.enabled ?? true,\n refetchInterval: feed.live ? false : pollInterval(args.refetchInterval),\n });\n\n const rows = query.data?.rows ?? [];\n const total = query.data?.total ?? null;\n return {\n rows,\n total,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: query.error,\n refetch: () => query.refetch(),\n capped: total !== null && rows.length < total,\n progress,\n ...freshnessOf(query.data),\n };\n}\n\n/** `data` with every row whose id is `id` passed through `patch`. */\nexport function patchRowInList(\n data: ListCache | undefined,\n id: string,\n patch: (row: Row) => Row,\n): ListCache | undefined {\n if (!data) return data;\n const patchPage = (page: ListResponse): ListResponse =>\n page.rows.some((r) => r.__meta.id === id)\n ? { ...page, rows: page.rows.map((r) => (r.__meta.id === id ? patch(r) : r)) }\n : page;\n return isInfinite(data) ? { ...data, pages: data.pages.map(patchPage) } : patchPage(data);\n}\n\nfunction patchRowEverywhere(\n qc: QueryClient,\n collection: string,\n id: string,\n patch: (row: Row) => Row,\n) {\n qc.setQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) }, (data) =>\n patchRowInList(data, id, patch),\n );\n}\n\nexport type UdcMutateVars = Omit<ActionRequest<\"mutate\">, \"collection\">;\n\n/**\n * Insert / update / delete one row. An update is applied optimistically to\n * the row in every cached list page and rolled back if the server says no.\n * A `version_conflict` additionally re-reads the row, so the cache holds the\n * value that won; the error still reaches the caller. Lists are invalidated\n * once the call settles.\n */\nexport function useUdcMutate(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: (vars: UdcMutateVars) => client.mutate({ collection, ...vars }),\n onMutate: async (vars) => {\n await qc.cancelQueries({ queryKey: udcKeys.lists(collection) });\n const snapshot = qc.getQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) });\n const { id, row } = vars;\n if (vars.op === \"update\" && id && row) {\n patchRowEverywhere(qc, collection, id, (r) => ({ ...r, ...row, __meta: r.__meta }));\n }\n return { snapshot };\n },\n onSuccess: (res) => {\n patchRowEverywhere(qc, collection, res.row.__meta.id, () => res.row);\n },\n onError: async (err, vars, ctx) => {\n for (const [key, data] of ctx?.snapshot ?? []) qc.setQueryData(key, data);\n if (isVersionConflict(err) && vars.id) {\n try {\n const fresh = await client.read(collection, vars.id);\n patchRowEverywhere(qc, collection, vars.id, () => fresh.row);\n } catch {\n // The invalidation below refetches the lists anyway.\n }\n }\n },\n // A row of this collection may be another collection's lookup label: those batches go stale too.\n onSettled: () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),\n qc.invalidateQueries({ queryKey: udcKeys.lookups(collection) }),\n qc.invalidateQueries({ queryKey: [\"udc\", \"lookup-options\", collection] }),\n ]),\n });\n}\n\n/**\n * The three schema edits. Each answers the new schema; `describe` (which\n * derives the columns) and the lists are refetched afterwards.\n */\nexport function useUdcSchema(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n const onSuccess = async () => {\n await qc.invalidateQueries({ queryKey: udcKeys.describe(collection) });\n await qc.invalidateQueries({ queryKey: udcKeys.lists(collection) });\n };\n\n const addField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.add_field\">, \"collection\">) =>\n client.schemaAddField({ collection, ...req }),\n onSuccess,\n });\n const updateField = useMutation({\n mutationFn: (req: Omit<ActionRequest<\"schema.update_field\">, \"collection\">) =>\n client.schemaUpdateField({ collection, ...req }),\n onSuccess,\n });\n const softDeleteField = useMutation({\n mutationFn: (field: string) => client.schemaSoftDeleteField({ collection, field }),\n onSuccess,\n });\n return { addField, updateField, softDeleteField };\n}\n\n// mutate_many and host actions (0.5.0) --------------------------------------\n\nexport type UdcMutateManyVars = Omit<ActionRequest<\"mutate_many\">, \"collection\">;\n\n/**\n * Which cached row a `mutate_many` request touches: one of its `ids`, or a row\n * its `filter` matches (evaluated in the browser, `evaluateFilter`) that is\n * not among `except_ids`. A filter the browser cannot evaluate touches no\n * cached row: the invalidation after the call brings the server's answer.\n */\nexport function mutateManyTouches(vars: UdcMutateManyVars): (row: Row) => boolean {\n if (vars.ids) {\n const ids = new Set(vars.ids);\n return (row) => ids.has(row.__meta.id);\n }\n const except = new Set(vars.except_ids ?? []);\n const filter = vars.filter;\n return (row) => {\n if (except.has(row.__meta.id)) return false;\n try {\n return evaluateFilter(filter, row);\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Change (`update`, the patch in `row`) or delete many rows of a collection in\n * one `mutate_many` request: by `ids`, or by `filter` with `except_ids` (\"all\n * that match, except these\"). Like `useUdcMutate` for one row, the loaded\n * rows are patched (or removed) in every cached list at once, put back if the\n * call fails, and the collection's lists and lookups are invalidated once it\n * settles. Resolves to the server's `{ updated, failed }`: `failed` names the\n * ids that were not changed, and why.\n */\nexport function useUdcMutateMany(collection: string) {\n const client = useUdcClient();\n const qc = useQueryClient();\n\n return useMutation({\n mutationFn: (vars: UdcMutateManyVars) => client.mutateMany({ collection, ...vars }),\n onMutate: async (vars) => {\n await qc.cancelQueries({ queryKey: udcKeys.lists(collection) });\n const snapshot = qc.getQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) });\n const touches = mutateManyTouches(vars);\n const set = vars.row;\n const patch =\n vars.op === \"update\" && set\n ? (r: Row): Row => ({ ...r, ...set, __meta: r.__meta })\n : undefined;\n if (vars.op === \"delete\" || patch) {\n qc.setQueriesData<ListCache>({ queryKey: udcKeys.lists(collection) }, (data) =>\n applyToListRows(data, touches, patch),\n );\n }\n return { snapshot };\n },\n onError: (_err, _vars, ctx) => {\n for (const [key, data] of ctx?.snapshot ?? []) qc.setQueryData(key, data);\n },\n onSettled: () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: udcKeys.lists(collection) }),\n qc.invalidateQueries({ queryKey: udcKeys.lookups(collection) }),\n qc.invalidateQueries({ queryKey: [\"udc\", \"lookup-options\", collection] }),\n ]),\n });\n}\n\n/** What `useUdcAction` takes besides TanStack's mutation options. */\nexport interface UseUdcActionOptions<Res, Req>\n extends Omit<UseMutationOptions<Res, Error, Req>, \"mutationFn\"> {\n /** Collections whose lists and lookups to invalidate once the call settles (the rows it changed). */\n invalidates?: readonly string[] | undefined;\n}\n\n/**\n * A mutation over the client's typed `call`, for any host action: pass the\n * action's definition (`defineHostAction`, shared with the server) and the\n * payload and the result are typed from its schemas; or pass a name and type\n * it yourself (`useUdcAction<Res, Req>(\"mail.snooze\")`). `invalidates` names\n * the collections whose lists to refetch afterwards.\n */\nexport function useUdcAction<H extends HostAction>(\n action: H,\n options?: UseUdcActionOptions<HostActionResponse<H>, HostActionPayload<H>>,\n): UseMutationResult<HostActionResponse<H>, Error, HostActionPayload<H>>;\nexport function useUdcAction<Res = unknown, Req = Record<string, unknown>>(\n action: string,\n options?: UseUdcActionOptions<Res, Req>,\n): UseMutationResult<Res, Error, Req>;\nexport function useUdcAction(\n action: string | HostAction,\n options: UseUdcActionOptions<unknown, unknown> = {},\n): UseMutationResult<unknown, Error, unknown> {\n const client = useUdcClient();\n const qc = useQueryClient();\n const { invalidates, onSettled, ...rest } = options;\n return useMutation<unknown, Error, unknown>({\n ...rest,\n mutationFn: (payload) => callAction(client, action, payload),\n onSettled: async (...args) => {\n await Promise.all(\n (invalidates ?? []).flatMap((c) => [\n qc.invalidateQueries({ queryKey: udcKeys.lists(c) }),\n qc.invalidateQueries({ queryKey: udcKeys.lookups(c) }),\n ]),\n );\n return onSettled?.(...args);\n },\n });\n}\n\n/** `client.call` for a host action given by definition or by name (the answer unchecked by name). */\nexport function callAction(\n client: UdcClient,\n action: string | HostAction,\n payload: unknown,\n): Promise<unknown> {\n const call = client.call.bind(client) as (a: string | HostAction, p: unknown) => Promise<unknown>;\n return call(action, payload);\n}\n"],"mappings":";;;;;;;;AAgCA,SAAgB,oBAAoB;CAClC,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EAAE,UAAU,QAAQ,YAAY;EAAG,eAAe,OAAO,YAAY;CAAE,CAAC;AAC1F;AAEA,SAAgB,eAAe,YAAoB,OAA8B,CAAC,GAAG;CACnF,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EACd,UAAU,QAAQ,SAAS,UAAU;EACrC,eAAe,OAAO,SAAS,UAAU;EACzC,WAAW;EACX,UAAU,KAAK,WAAW,SAAS,eAAe;CACpD,CAAC;AACH;;AAGA,SAAgB,aAAa,YAAoB,OAA8B,CAAC,GAAG;CACjF,MAAM,SAAS,aAAa;CAC5B,OAAO,SAAS;EACd,UAAU,QAAQ,OAAO,UAAU;EACnC,eAAe,OAAO,WAAW,UAAU;EAC3C,WAAW;EACX,UAAU,KAAK,WAAW,SAAS,eAAe;CACpD,CAAC;AACH;;AA8CA,SAAgB,aAAa,IAAwC;CACnE,OAAO,OAAO,OAAO,YAAY,KAAK,IAAI,KAAK;AACjD;;AAGA,SAAgB,YAAY,KAG1B;CACA,OAAO;EAAE,WAAW,KAAK,cAAc;EAAM,OAAO,KAAK,UAAU;CAAK;AAC1E;;AAGA,SAAgB,WAAW,QAAiD;CAC1E,MAAM,OAAO,QAAQ,KAAK;CAC1B,OAAO,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;AACpC;;AAGA,SAAgB,WAAW,MAAc,OAAuB;CAC9D,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI;AAC7C;;;;;;;;;A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,GAAG,kBAAkB,EAAE,UAAU,QAAQ,QAAQ,CAAC,EAAE,CAAC,CACvD,CAAC,CACH;GACA,OAAO,YAAY,GAAG,IAAI;EAC5B;CACF,CAAC;AACH;;AAGA,SAAgB,WACd,QACA,QACA,SACkB;CAElB,OADa,OAAO,KAAK,KAAK,MACvB,CAAA,CAAK,QAAQ,OAAO;AAC7B"}
|
package/dist/udc/keys.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface ListKeyParams {
|
|
|
7
7
|
/** `all`: every row up to `limit`, fetched page by page into one list (`useUdcAllRows`). */
|
|
8
8
|
mode: PagingMode | "all";
|
|
9
9
|
page?: number;
|
|
10
|
+
/** The text sent as `ListRequest.search` (a source that answers search); absent otherwise. */
|
|
11
|
+
search?: string;
|
|
10
12
|
}
|
|
11
13
|
/** Every query this app makes sits under `["udc", ...]`. */
|
|
12
14
|
export declare const udcKeys: {
|
package/dist/udc/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","names":[],"sources":["../../src/udc/keys.ts"],"sourcesContent":["import type { FilterNode, SortKey } from \"@jsudc/core\";\n\nexport type PagingMode = \"infinite\" | \"pages\";\n\nexport interface ListKeyParams {\n filter: FilterNode | undefined;\n sort: SortKey[];\n limit: number;\n /** `all`: every row up to `limit`, fetched page by page into one list (`useUdcAllRows`). */\n mode: PagingMode | \"all\";\n page?: number;\n}\n\n/** Every query this app makes sits under `[\"udc\", ...]`. */\nexport const udcKeys = {\n all: [\"udc\"] as const,\n collections: () => [\"udc\", \"collections\"] as const,\n describe: (collection: string) => [\"udc\", \"describe\", collection] as const,\n source: (collection: string) => [\"udc\", \"source\", collection] as const,\n lists: (collection: string) => [\"udc\", \"list\", collection] as const,\n list: (collection: string, params: ListKeyParams) => [\"udc\", \"list\", collection, params] as const,\n lookups: (collection: string) => [\"udc\", \"lookup\", collection] as const,\n /** One lookup batch: the target collection, its sorted keys, and the key field when not `id`. */\n lookup: (collection: string, sortedKeys: readonly string[], keyField = \"id\") =>\n keyField === \"id\"\n ? ([\"udc\", \"lookup\", collection, sortedKeys] as const)\n : ([\"udc\", \"lookup\", collection, sortedKeys, keyField] as const),\n /** The options of a lookup picker (a chip, the inline editor): target, label field, search. */\n lookupOptions: (collection: string, labelField: string, search: string) =>\n [\"udc\", \"lookup-options\", collection, labelField, search] as const,\n};\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"keys.js","names":[],"sources":["../../src/udc/keys.ts"],"sourcesContent":["import type { FilterNode, SortKey } from \"@jsudc/core\";\n\nexport type PagingMode = \"infinite\" | \"pages\";\n\nexport interface ListKeyParams {\n filter: FilterNode | undefined;\n sort: SortKey[];\n limit: number;\n /** `all`: every row up to `limit`, fetched page by page into one list (`useUdcAllRows`). */\n mode: PagingMode | \"all\";\n page?: number;\n /** The text sent as `ListRequest.search` (a source that answers search); absent otherwise. */\n search?: string;\n}\n\n/** Every query this app makes sits under `[\"udc\", ...]`. */\nexport const udcKeys = {\n all: [\"udc\"] as const,\n collections: () => [\"udc\", \"collections\"] as const,\n describe: (collection: string) => [\"udc\", \"describe\", collection] as const,\n source: (collection: string) => [\"udc\", \"source\", collection] as const,\n lists: (collection: string) => [\"udc\", \"list\", collection] as const,\n list: (collection: string, params: ListKeyParams) => [\"udc\", \"list\", collection, params] as const,\n lookups: (collection: string) => [\"udc\", \"lookup\", collection] as const,\n /** One lookup batch: the target collection, its sorted keys, and the key field when not `id`. */\n lookup: (collection: string, sortedKeys: readonly string[], keyField = \"id\") =>\n keyField === \"id\"\n ? ([\"udc\", \"lookup\", collection, sortedKeys] as const)\n : ([\"udc\", \"lookup\", collection, sortedKeys, keyField] as const),\n /** The options of a lookup picker (a chip, the inline editor): target, label field, search. */\n lookupOptions: (collection: string, labelField: string, search: string) =>\n [\"udc\", \"lookup-options\", collection, labelField, search] as const,\n};\n"],"mappings":";;AAgBA,IAAa,UAAU;CACrB,KAAK,CAAC,KAAK;CACX,mBAAmB,CAAC,OAAO,aAAa;CACxC,WAAW,eAAuB;EAAC;EAAO;EAAY;CAAU;CAChE,SAAS,eAAuB;EAAC;EAAO;EAAU;CAAU;CAC5D,QAAQ,eAAuB;EAAC;EAAO;EAAQ;CAAU;CACzD,OAAO,YAAoB,WAA0B;EAAC;EAAO;EAAQ;EAAY;CAAM;CACvF,UAAU,eAAuB;EAAC;EAAO;EAAU;CAAU;;CAE7D,SAAS,YAAoB,YAA+B,WAAW,SACrE,aAAa,OACR;EAAC;EAAO;EAAU;EAAY;CAAU,IACxC;EAAC;EAAO;EAAU;EAAY;EAAY;CAAQ;;CAEzD,gBAAgB,YAAoB,YAAoB,WACtD;EAAC;EAAO;EAAkB;EAAY;EAAY;CAAM;AAC5D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ListResponse, Row } from "@jsudc/core";
|
|
2
|
+
import type { InfiniteData } from "@tanstack/react-query";
|
|
3
|
+
/** What a list query caches: one page (`useQuery`) or the pages of an infinite list. */
|
|
4
|
+
export type ListCache = ListResponse | InfiniteData<ListResponse, unknown>;
|
|
5
|
+
export declare function isInfinite(data: ListCache): data is InfiniteData<ListResponse, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* `data` with every row `touches` picks patched (`patch` given) or removed
|
|
8
|
+
* (`patch` absent; each page's `total` goes down by the rows removed from the
|
|
9
|
+
* whole list).
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyToListRows(data: ListCache | undefined, touches: (row: Row) => boolean, patch?: (row: Row) => Row): ListCache | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/udc/listCache.ts
|
|
2
|
+
function isInfinite(data) {
|
|
3
|
+
return "pages" in data;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* `data` with every row `touches` picks patched (`patch` given) or removed
|
|
7
|
+
* (`patch` absent; each page's `total` goes down by the rows removed from the
|
|
8
|
+
* whole list).
|
|
9
|
+
*/
|
|
10
|
+
function applyToListRows(data, touches, patch) {
|
|
11
|
+
if (!data) return data;
|
|
12
|
+
const pages = isInfinite(data) ? data.pages : [data];
|
|
13
|
+
let removed = 0;
|
|
14
|
+
const next = pages.map((page) => {
|
|
15
|
+
if (!page.rows.some(touches)) return page;
|
|
16
|
+
if (patch) return {
|
|
17
|
+
...page,
|
|
18
|
+
rows: page.rows.map((r) => touches(r) ? patch(r) : r)
|
|
19
|
+
};
|
|
20
|
+
const rows = page.rows.filter((r) => !touches(r));
|
|
21
|
+
removed += page.rows.length - rows.length;
|
|
22
|
+
return {
|
|
23
|
+
...page,
|
|
24
|
+
rows
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const counted = removed === 0 ? next : next.map((p) => p.total === null ? p : {
|
|
28
|
+
...p,
|
|
29
|
+
total: Math.max(0, p.total - removed)
|
|
30
|
+
});
|
|
31
|
+
return isInfinite(data) ? {
|
|
32
|
+
...data,
|
|
33
|
+
pages: counted
|
|
34
|
+
} : counted[0];
|
|
35
|
+
}
|
|
36
|
+
export { applyToListRows, isInfinite };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=listCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listCache.js","names":[],"sources":["../../src/udc/listCache.ts"],"sourcesContent":["import type { ListResponse, Row } from \"@jsudc/core\";\nimport type { InfiniteData } from \"@tanstack/react-query\";\n\n/** What a list query caches: one page (`useQuery`) or the pages of an infinite list. */\nexport type ListCache = ListResponse | InfiniteData<ListResponse, unknown>;\n\nexport function isInfinite(data: ListCache): data is InfiniteData<ListResponse, unknown> {\n return \"pages\" in data;\n}\n\n/**\n * `data` with every row `touches` picks patched (`patch` given) or removed\n * (`patch` absent; each page's `total` goes down by the rows removed from the\n * whole list).\n */\nexport function applyToListRows(\n data: ListCache | undefined,\n touches: (row: Row) => boolean,\n patch?: (row: Row) => Row,\n): ListCache | undefined {\n if (!data) return data;\n const pages = isInfinite(data) ? data.pages : [data];\n let removed = 0;\n const next = pages.map((page) => {\n if (!page.rows.some(touches)) return page;\n if (patch) return { ...page, rows: page.rows.map((r) => (touches(r) ? patch(r) : r)) };\n const rows = page.rows.filter((r) => !touches(r));\n removed += page.rows.length - rows.length;\n return { ...page, rows };\n });\n const counted =\n removed === 0\n ? next\n : next.map((p) => (p.total === null ? p : { ...p, total: Math.max(0, p.total - removed) }));\n return isInfinite(data) ? { ...data, pages: counted } : (counted[0] as ListResponse);\n}\n"],"mappings":";AAMA,SAAgB,WAAW,MAA8D;CACvF,OAAO,WAAW;AACpB;;;;;;AAOA,SAAgB,gBACd,MACA,SACA,OACuB;CACvB,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,QAAQ,WAAW,IAAI,IAAI,KAAK,QAAQ,CAAC,IAAI;CACnD,IAAI,UAAU;CACd,MAAM,OAAO,MAAM,KAAK,SAAS;EAC/B,IAAI,CAAC,KAAK,KAAK,KAAK,OAAO,GAAG,OAAO;EACrC,IAAI,OAAO,OAAO;GAAE,GAAG;GAAM,MAAM,KAAK,KAAK,KAAK,MAAO,QAAQ,CAAC,IAAI,MAAM,CAAC,IAAI,CAAE;EAAE;EACrF,MAAM,OAAO,KAAK,KAAK,QAAQ,MAAM,CAAC,QAAQ,CAAC,CAAC;EAChD,WAAW,KAAK,KAAK,SAAS,KAAK;EACnC,OAAO;GAAE,GAAG;GAAM;EAAK;CACzB,CAAC;CACD,MAAM,UACJ,YAAY,IACR,OACA,KAAK,KAAK,MAAO,EAAE,UAAU,OAAO,IAAI;EAAE,GAAG;EAAG,OAAO,KAAK,IAAI,GAAG,EAAE,QAAQ,OAAO;CAAE,CAAE;CAC9F,OAAO,WAAW,IAAI,IAAI;EAAE,GAAG;EAAM,OAAO;CAAQ,IAAK,QAAQ;AACnE"}
|
package/dist/udc/provider.d.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import type { UdcClient } from "@jsudc/core/client";
|
|
2
|
-
import type
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { type BulkActionHandlers } from "../actions/bulk.js";
|
|
3
4
|
import { type CellRegistry } from "../cells/registry.js";
|
|
4
5
|
import { type UdcLinks } from "../lookup/links.js";
|
|
5
6
|
import type { RendererRegistry } from "../renderers/types.js";
|
|
6
7
|
import type { UiKit } from "../ui-kit/types.js";
|
|
8
|
+
import { type UdcChangeFeedOptions } from "./changeFeed.js";
|
|
9
|
+
/**
|
|
10
|
+
* `UdcProvider changes={…}` as an object: the feed's options and the
|
|
11
|
+
* `identity` the stream is scoped to.
|
|
12
|
+
*/
|
|
13
|
+
export interface UdcProviderChangesOptions extends UdcChangeFeedOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Who the stream is for, when `UdcClient`'s `headers` is a function whose
|
|
16
|
+
* answer changes (a demo user switcher, an account switcher, an
|
|
17
|
+
* impersonation switch). The server scopes a stream once, when it opens;
|
|
18
|
+
* when `identity` changes the provider calls `UdcChangeFeed.reconnect()`,
|
|
19
|
+
* so the stream follows the new user, without remounting anything below.
|
|
20
|
+
* Compared with `Object.is`: a user id, not a new object per render.
|
|
21
|
+
*/
|
|
22
|
+
identity?: string | number | boolean | null | undefined;
|
|
23
|
+
}
|
|
7
24
|
export { createUdcQueryClient, shouldRetry, type UdcQueryClientOptions, useUdcClient, } from "./client.js";
|
|
8
25
|
/**
|
|
9
26
|
* The root provider: the client, the renderers `UdcDataView` draws its tabs
|
|
@@ -12,7 +29,7 @@ export { createUdcQueryClient, shouldRetry, type UdcQueryClientOptions, useUdcCl
|
|
|
12
29
|
* `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
|
|
13
30
|
* every tab says no renderer is registered).
|
|
14
31
|
*/
|
|
15
|
-
export declare function UdcProvider({ client, kit, renderers, links, cells, children, }: {
|
|
32
|
+
export declare function UdcProvider({ client, kit, renderers, links, cells, actions, changes, children, }: {
|
|
16
33
|
client: UdcClient;
|
|
17
34
|
/**
|
|
18
35
|
* Where a lookup link and a `row_link` go: the address of a collection's
|
|
@@ -25,5 +42,20 @@ export declare function UdcProvider({ client, kit, renderers, links, cells, chil
|
|
|
25
42
|
renderers?: RendererRegistry;
|
|
26
43
|
/** `createCellRegistry(...)`: the cell components a column's `render` may name (README "Custom cells"). */
|
|
27
44
|
cells?: CellRegistry;
|
|
45
|
+
/**
|
|
46
|
+
* The default handlers of the bulk actions of every data view below, by
|
|
47
|
+
* `kind` (README "Selection and bulk actions"); a view's `actions` win.
|
|
48
|
+
*/
|
|
49
|
+
actions?: BulkActionHandlers;
|
|
50
|
+
/**
|
|
51
|
+
* The change feed (README "Live updates"): `true`, or options, opens one
|
|
52
|
+
* stream for the collections the views below show, and they refetch when
|
|
53
|
+
* the server says their rows changed instead of on their timer. Off by
|
|
54
|
+
* default: no connection. Left out under another `UdcProvider` with the
|
|
55
|
+
* same client, the outer feed is used. `identity` (see
|
|
56
|
+
* `UdcProviderChangesOptions`) reopens the stream when the user behind the
|
|
57
|
+
* client's `headers` changes.
|
|
58
|
+
*/
|
|
59
|
+
changes?: boolean | UdcProviderChangesOptions;
|
|
28
60
|
children: ReactNode;
|
|
29
61
|
}): import("react").JSX.Element;
|
package/dist/udc/provider.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { UdcActionsProvider } from "../actions/bulk.js";
|
|
1
2
|
import { UdcCellsProvider } from "../cells/registry.js";
|
|
2
3
|
import { UdcLinksProvider } from "../lookup/links.js";
|
|
3
4
|
import { UdcRenderersProvider } from "../renderers/context.js";
|
|
4
5
|
import { UdcUiProvider } from "../ui-kit/context.js";
|
|
6
|
+
import { UdcChangeFeed } from "./changeFeed.js";
|
|
7
|
+
import { UdcChangeFeedContext } from "./changes.js";
|
|
5
8
|
import { UdcClientContext, createUdcQueryClient, shouldRetry, useUdcClient } from "./client.js";
|
|
9
|
+
import { useContext, useEffect, useMemo, useRef } from "react";
|
|
6
10
|
import { jsx } from "react/jsx-runtime";
|
|
7
11
|
// src/udc/provider.tsx
|
|
8
12
|
/**
|
|
@@ -12,10 +16,28 @@ import { jsx } from "react/jsx-runtime";
|
|
|
12
16
|
* `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:
|
|
13
17
|
* every tab says no renderer is registered).
|
|
14
18
|
*/
|
|
15
|
-
function UdcProvider({ client, kit, renderers, links, cells, children }) {
|
|
19
|
+
function UdcProvider({ client, kit, renderers, links, cells, actions, changes, children }) {
|
|
20
|
+
const outer = useContext(UdcChangeFeedContext);
|
|
21
|
+
const { identity, ...feedOptions } = typeof changes === "object" ? changes : {};
|
|
22
|
+
const optionsKey = typeof changes === "object" ? JSON.stringify(feedOptions) : String(changes ?? false);
|
|
23
|
+
const own = useMemo(() => optionsKey === "false" ? null : new UdcChangeFeed(client, optionsKey === "true" ? {} : JSON.parse(optionsKey)), [client, optionsKey]);
|
|
24
|
+
useEffect(() => own ? () => own.close() : void 0, [own]);
|
|
25
|
+
const scoped = useRef(null);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const last = scoped.current;
|
|
28
|
+
scoped.current = {
|
|
29
|
+
feed: own,
|
|
30
|
+
identity
|
|
31
|
+
};
|
|
32
|
+
if (own && last?.feed === own && !Object.is(last.identity, identity)) own.reconnect();
|
|
33
|
+
}, [own, identity]);
|
|
34
|
+
const feed = changes === void 0 ? outer?.client === client ? outer : null : own;
|
|
16
35
|
let inner = /* @__PURE__ */ jsx(UdcClientContext.Provider, {
|
|
17
36
|
value: client,
|
|
18
|
-
children
|
|
37
|
+
children: /* @__PURE__ */ jsx(UdcChangeFeedContext.Provider, {
|
|
38
|
+
value: feed,
|
|
39
|
+
children
|
|
40
|
+
})
|
|
19
41
|
});
|
|
20
42
|
if (links) inner = /* @__PURE__ */ jsx(UdcLinksProvider, {
|
|
21
43
|
links,
|
|
@@ -25,6 +47,10 @@ function UdcProvider({ client, kit, renderers, links, cells, children }) {
|
|
|
25
47
|
cells,
|
|
26
48
|
children: inner
|
|
27
49
|
});
|
|
50
|
+
if (actions) inner = /* @__PURE__ */ jsx(UdcActionsProvider, {
|
|
51
|
+
actions,
|
|
52
|
+
children: inner
|
|
53
|
+
});
|
|
28
54
|
if (renderers) inner = /* @__PURE__ */ jsx(UdcRenderersProvider, {
|
|
29
55
|
renderers,
|
|
30
56
|
children: inner
|
package/dist/udc/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import type { UdcClient } from \"@jsudc/core/client\";\nimport type
|
|
1
|
+
{"version":3,"file":"provider.js","names":[],"sources":["../../src/udc/provider.tsx"],"sourcesContent":["import type { UdcClient } from \"@jsudc/core/client\";\nimport { type ReactNode, useContext, useEffect, useMemo, useRef } from \"react\";\nimport { type BulkActionHandlers, UdcActionsProvider } from \"../actions/bulk.js\";\nimport { type CellRegistry, UdcCellsProvider } from \"../cells/registry.js\";\nimport { type UdcLinks, UdcLinksProvider } from \"../lookup/links.js\";\nimport { UdcRenderersProvider } from \"../renderers/context.js\";\nimport type { RendererRegistry } from \"../renderers/types.js\";\nimport { UdcUiProvider } from \"../ui-kit/context.js\";\nimport type { UiKit } from \"../ui-kit/types.js\";\nimport { UdcChangeFeed, type UdcChangeFeedOptions } from \"./changeFeed.js\";\nimport { UdcChangeFeedContext } from \"./changes.js\";\nimport { UdcClientContext } from \"./client.js\";\n\n/**\n * `UdcProvider changes={…}` as an object: the feed's options and the\n * `identity` the stream is scoped to.\n */\nexport interface UdcProviderChangesOptions extends UdcChangeFeedOptions {\n /**\n * Who the stream is for, when `UdcClient`'s `headers` is a function whose\n * answer changes (a demo user switcher, an account switcher, an\n * impersonation switch). The server scopes a stream once, when it opens;\n * when `identity` changes the provider calls `UdcChangeFeed.reconnect()`,\n * so the stream follows the new user, without remounting anything below.\n * Compared with `Object.is`: a user id, not a new object per render.\n */\n identity?: string | number | boolean | null | undefined;\n}\n\nexport {\n createUdcQueryClient,\n shouldRetry,\n type UdcQueryClientOptions,\n useUdcClient,\n} from \"./client.js\";\n\n/**\n * The root provider: the client, the renderers `UdcDataView` draws its tabs\n * with, and optionally the UI kit they draw with. Without `kit` the kit in\n * effect is kept (an outer `UdcUiProvider`'s, else `defaultUiKit`); without\n * `renderers` the outer `UdcRenderersProvider`'s registry is kept (else none:\n * every tab says no renderer is registered).\n */\nexport function UdcProvider({\n client,\n kit,\n renderers,\n links,\n cells,\n actions,\n changes,\n children,\n}: {\n client: UdcClient;\n /**\n * Where a lookup link and a `row_link` go: the address of a collection's\n * view, and how to navigate there. Default `defaultUdcLinks` (`/c/<name>`);\n * `UdcReactRouterUrlState collectionPath` sets it for react-router.\n */\n links?: UdcLinks;\n kit?: UiKit;\n /** `createRendererRegistry(tableRenderer, …)`, or `RENDERERS` from `@jsudc/react/all`. */\n renderers?: RendererRegistry;\n /** `createCellRegistry(...)`: the cell components a column's `render` may name (README \"Custom cells\"). */\n cells?: CellRegistry;\n /**\n * The default handlers of the bulk actions of every data view below, by\n * `kind` (README \"Selection and bulk actions\"); a view's `actions` win.\n */\n actions?: BulkActionHandlers;\n /**\n * The change feed (README \"Live updates\"): `true`, or options, opens one\n * stream for the collections the views below show, and they refetch when\n * the server says their rows changed instead of on their timer. Off by\n * default: no connection. Left out under another `UdcProvider` with the\n * same client, the outer feed is used. `identity` (see\n * `UdcProviderChangesOptions`) reopens the stream when the user behind the\n * client's `headers` changes.\n */\n changes?: boolean | UdcProviderChangesOptions;\n children: ReactNode;\n}) {\n const outer = useContext(UdcChangeFeedContext);\n const { identity, ...feedOptions } = typeof changes === \"object\" ? changes : {};\n const optionsKey =\n typeof changes === \"object\" ? JSON.stringify(feedOptions) : String(changes ?? false);\n // `changes` is read through its key: a new but equal options object keeps the feed.\n const own = useMemo(\n () =>\n optionsKey === \"false\"\n ? null\n : new UdcChangeFeed(\n client,\n optionsKey === \"true\" ? {} : (JSON.parse(optionsKey) as UdcChangeFeedOptions),\n ),\n [client, optionsKey],\n );\n useEffect(() => (own ? () => own.close() : undefined), [own]);\n // A new identity behind the client's `headers`: the same feed, its stream reopened for it.\n const scoped = useRef<{ feed: UdcChangeFeed | null; identity: unknown } | null>(null);\n useEffect(() => {\n const last = scoped.current;\n scoped.current = { feed: own, identity };\n if (own && last?.feed === own && !Object.is(last.identity, identity)) own.reconnect();\n }, [own, identity]);\n const feed = changes === undefined ? (outer?.client === client ? outer : null) : own;\n\n let inner = (\n <UdcClientContext.Provider value={client}>\n <UdcChangeFeedContext.Provider value={feed}>{children}</UdcChangeFeedContext.Provider>\n </UdcClientContext.Provider>\n );\n if (links) inner = <UdcLinksProvider links={links}>{inner}</UdcLinksProvider>;\n if (cells) inner = <UdcCellsProvider cells={cells}>{inner}</UdcCellsProvider>;\n if (actions) inner = <UdcActionsProvider actions={actions}>{inner}</UdcActionsProvider>;\n if (renderers) inner = <UdcRenderersProvider renderers={renderers}>{inner}</UdcRenderersProvider>;\n return kit ? <UdcUiProvider kit={kit}>{inner}</UdcUiProvider> : inner;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2CA,SAAgB,YAAY,EAC1B,QACA,KACA,WACA,OACA,OACA,SACA,SACA,YA8BC;CACD,MAAM,QAAQ,WAAW,oBAAoB;CAC7C,MAAM,EAAE,UAAU,GAAG,gBAAgB,OAAO,YAAY,WAAW,UAAU,CAAC;CAC9E,MAAM,aACJ,OAAO,YAAY,WAAW,KAAK,UAAU,WAAW,IAAI,OAAO,WAAW,KAAK;CAErF,MAAM,MAAM,cAER,eAAe,UACX,OACA,IAAI,cACF,QACA,eAAe,SAAS,CAAC,IAAK,KAAK,MAAM,UAAU,CACrD,GACN,CAAC,QAAQ,UAAU,CACrB;CACA,gBAAiB,YAAY,IAAI,MAAM,IAAI,KAAA,GAAY,CAAC,GAAG,CAAC;CAE5D,MAAM,SAAS,OAAiE,IAAI;CACpF,gBAAgB;EACd,MAAM,OAAO,OAAO;EACpB,OAAO,UAAU;GAAE,MAAM;GAAK;EAAS;EACvC,IAAI,OAAO,MAAM,SAAS,OAAO,CAAC,OAAO,GAAG,KAAK,UAAU,QAAQ,GAAG,IAAI,UAAU;CACtF,GAAG,CAAC,KAAK,QAAQ,CAAC;CAClB,MAAM,OAAO,YAAY,KAAA,IAAa,OAAO,WAAW,SAAS,QAAQ,OAAQ;CAEjF,IAAI,QACF,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO;EAChC,UAAA,oBAAC,qBAAqB,UAAtB;GAA+B,OAAO;GAAO;EAAwC,CAAA;CAC5D,CAAA;CAE7B,IAAI,OAAO,QAAQ,oBAAC,kBAAD;EAAyB;EAAQ,UAAA;CAAwB,CAAA;CAC5E,IAAI,OAAO,QAAQ,oBAAC,kBAAD;EAAyB;EAAQ,UAAA;CAAwB,CAAA;CAC5E,IAAI,SAAS,QAAQ,oBAAC,oBAAD;EAA6B;EAAU,UAAA;CAA0B,CAAA;CACtF,IAAI,WAAW,QAAQ,oBAAC,sBAAD;EAAiC;EAAY,UAAA;CAA4B,CAAA;CAChG,OAAO,MAAM,oBAAC,eAAD;EAAoB;EAAM,UAAA;CAAqB,CAAA,IAAI;AAClE"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { QueryClient } from "@tanstack/react-query";
|
|
2
|
+
export declare function registerUnauthenticated(qc: QueryClient, notify: (error: unknown) => void): void;
|
|
3
|
+
/** Hand `error` to `qc`'s `onUnauthenticated` (it checks `isUnauthenticated` itself). */
|
|
4
|
+
export declare function notifyUnauthenticated(qc: QueryClient, error: unknown): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/udc/unauthenticated.ts
|
|
2
|
+
/**
|
|
3
|
+
* The `onUnauthenticated` notifier of each query client `createUdcQueryClient`
|
|
4
|
+
* made, so a failure outside TanStack (the change feed) takes the same path as
|
|
5
|
+
* a failed query, burst limiting included. Internal: not exported.
|
|
6
|
+
*/
|
|
7
|
+
var notifiers = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function registerUnauthenticated(qc, notify) {
|
|
9
|
+
notifiers.set(qc, notify);
|
|
10
|
+
}
|
|
11
|
+
/** Hand `error` to `qc`'s `onUnauthenticated` (it checks `isUnauthenticated` itself). */
|
|
12
|
+
function notifyUnauthenticated(qc, error) {
|
|
13
|
+
notifiers.get(qc)?.(error);
|
|
14
|
+
}
|
|
15
|
+
export { notifyUnauthenticated, registerUnauthenticated };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=unauthenticated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticated.js","names":[],"sources":["../../src/udc/unauthenticated.ts"],"sourcesContent":["import type { QueryClient } from \"@tanstack/react-query\";\n\n/**\n * The `onUnauthenticated` notifier of each query client `createUdcQueryClient`\n * made, so a failure outside TanStack (the change feed) takes the same path as\n * a failed query, burst limiting included. Internal: not exported.\n */\nconst notifiers = new WeakMap<QueryClient, (error: unknown) => void>();\n\nexport function registerUnauthenticated(qc: QueryClient, notify: (error: unknown) => void): void {\n notifiers.set(qc, notify);\n}\n\n/** Hand `error` to `qc`'s `onUnauthenticated` (it checks `isUnauthenticated` itself). */\nexport function notifyUnauthenticated(qc: QueryClient, error: unknown): void {\n notifiers.get(qc)?.(error);\n}\n"],"mappings":";;;;;;AAOA,IAAM,4BAAY,IAAI,QAA+C;AAErE,SAAgB,wBAAwB,IAAiB,QAAwC;CAC/F,UAAU,IAAI,IAAI,MAAM;AAC1B;;AAGA,SAAgB,sBAAsB,IAAiB,OAAsB;CAC3E,UAAU,IAAI,EAAE,CAAC,GAAG,KAAK;AAC3B"}
|
package/dist/ui-kit/types.d.ts
CHANGED
|
@@ -129,10 +129,24 @@ export interface UiTriggerProps extends Base {
|
|
|
129
129
|
export interface UiDropdownMenuProps {
|
|
130
130
|
/** `false`: the page behind stays interactive while the menu is open. */
|
|
131
131
|
modal?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Controlled (0.5.0, optional): the menu is open while `true`. A row's
|
|
134
|
+
* actions menu sets it to open from the keyboard and on right-click; a kit
|
|
135
|
+
* that ignores it still opens the menu from its trigger.
|
|
136
|
+
*/
|
|
137
|
+
open?: boolean;
|
|
138
|
+
/** The menu wants to open or close (its trigger, Escape, a click outside, an item chosen). */
|
|
139
|
+
onOpenChange?: (open: boolean) => void;
|
|
132
140
|
children?: ReactNode;
|
|
133
141
|
}
|
|
134
142
|
export interface UiDropdownMenuContentProps extends Base {
|
|
135
143
|
align?: "start" | "center" | "end";
|
|
144
|
+
/**
|
|
145
|
+
* The menu closed and is about to give the focus back to its trigger
|
|
146
|
+
* (0.5.0, optional): `preventDefault()` to put it elsewhere (a row's menu
|
|
147
|
+
* gives it back to the row).
|
|
148
|
+
*/
|
|
149
|
+
onCloseAutoFocus?: (e: PreventableEvent) => void;
|
|
136
150
|
children?: ReactNode;
|
|
137
151
|
}
|
|
138
152
|
export interface UiDropdownMenuItemProps extends Base {
|