@jsudc/react 0.3.1 → 0.5.0
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 +1137 -22
- 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 +5 -4
- package/dist/calendar/CalendarRenderer.js.map +1 -1
- package/dist/calendar/EventDetail.js +1 -1
- package/dist/calendar.js +1 -1
- package/dist/cards/CardRenderer.d.ts +8 -1
- package/dist/cards/CardRenderer.js +179 -110
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/cells/registry.d.ts +60 -0
- package/dist/cells/registry.js +47 -0
- package/dist/cells/registry.js.map +1 -0
- package/dist/chart/ChartRenderer.js +6 -4
- package/dist/chart/ChartRenderer.js.map +1 -1
- package/dist/chart/ChartWindowControl.js +2 -2
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/dialog.js +4 -3
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/dropdown-menu.js +2 -1
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/popover.js +2 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/select.js +2 -1
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/toast.js +3 -2
- package/dist/components/ui/toast.js.map +1 -1
- package/dist/components/ui/tooltip.js +2 -1
- package/dist/components/ui/tooltip.js.map +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 +2 -2
- package/dist/data-view/FilterChips.js +2 -2
- package/dist/data-view/Freshness.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/SearchBox.js +1 -1
- package/dist/data-view/UdcDataView.d.ts +110 -1
- package/dist/data-view/UdcDataView.js +237 -90
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/data-view/useDataViewState.d.ts +8 -0
- package/dist/data-view/useDataViewState.js +2 -1
- package/dist/data-view/useDataViewState.js.map +1 -1
- package/dist/headless.d.ts +9 -0
- package/dist/headless.js +12 -2
- package/dist/i18n/translations.js +136 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.js +17 -4
- package/dist/kanban/KanbanCard.js +1 -1
- package/dist/kanban/KanbanColumn.js +1 -1
- package/dist/kanban/KanbanRenderer.js +6 -5
- package/dist/kanban/KanbanRenderer.js.map +1 -1
- package/dist/lib/scope.d.ts +8 -0
- package/dist/lib/scope.js +12 -0
- package/dist/lib/scope.js.map +1 -0
- package/dist/lookup/LookupCombobox.js +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 +4 -3
- package/dist/map/MapRenderer.js.map +1 -1
- package/dist/renderers/types.d.ts +44 -1
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +91 -0
- package/dist/rows/useRowActivation.js +257 -0
- package/dist/rows/useRowActivation.js.map +1 -0
- 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 +2 -2
- package/dist/schema-editor/FieldFormDialog.js +2 -2
- package/dist/schema-editor/TagInput.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +2 -0
- package/dist/table/CellEditor.js +2 -1
- package/dist/table/CellEditor.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 +15 -1
- package/dist/table/TableRenderer.js +305 -114
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.d.ts +13 -2
- package/dist/table/cells.js +15 -2
- package/dist/table/cells.js.map +1 -1
- package/dist/table/index.d.ts +1 -0
- package/dist/table/states.d.ts +6 -0
- package/dist/table/states.js +14 -1
- package/dist/table/states.js.map +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/TreeNode.js +1 -1
- package/dist/tree/TreeRenderer.d.ts +2 -0
- package/dist/tree/TreeRenderer.js +16 -10
- package/dist/tree/TreeRenderer.js.map +1 -1
- package/dist/udc/changeFeed.d.ts +94 -0
- package/dist/udc/changeFeed.js +250 -0
- package/dist/udc/changeFeed.js.map +1 -0
- package/dist/udc/changes.d.ts +34 -0
- package/dist/udc/changes.js +79 -0
- package/dist/udc/changes.js.map +1 -0
- package/dist/udc/client.d.ts +15 -1
- package/dist/udc/client.js +34 -10
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +94 -16
- package/dist/udc/hooks.js +113 -10
- 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 +21 -3
- package/dist/udc/provider.js +23 -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/dist/ui-kit/ui.d.ts +1 -0
- package/dist/ui.js +2 -1
- package/dist/url-state/adapters.d.ts +23 -0
- package/dist/url-state/adapters.js +57 -0
- package/dist/url-state/adapters.js.map +1 -0
- package/dist/url-state/index.d.ts +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { udcKeys } from "./keys.js";
|
|
2
|
+
import { applyToListRows } from "./listCache.js";
|
|
3
|
+
import { notifyUnauthenticated } from "./unauthenticated.js";
|
|
4
|
+
import { isUnauthenticated } from "@jsudc/core";
|
|
5
|
+
// src/udc/changeFeed.ts
|
|
6
|
+
var keyOf = (collections) => [...collections].sort().join("\n");
|
|
7
|
+
/**
|
|
8
|
+
* The change feed of one `UdcProvider`: one stream for every collection a
|
|
9
|
+
* mounted view (or hook) shows. Collections are reference-counted; when the
|
|
10
|
+
* set changes the new stream is opened first and the old one closed only once
|
|
11
|
+
* the new one is subscribed, so the collections that stay miss nothing. An
|
|
12
|
+
* event marks its collection dirty and, after `debounceMs`, its lists, lookup
|
|
13
|
+
* batches and lookup options are invalidated; "reconnected" invalidates every
|
|
14
|
+
* collection of the stream. Framework-free apart from TanStack's QueryClient;
|
|
15
|
+
* `useUdcChanges` is the React side.
|
|
16
|
+
*/
|
|
17
|
+
var UdcChangeFeed = class {
|
|
18
|
+
client;
|
|
19
|
+
opts;
|
|
20
|
+
subs = /* @__PURE__ */ new Map();
|
|
21
|
+
current = null;
|
|
22
|
+
pending = null;
|
|
23
|
+
reconcileTimer = null;
|
|
24
|
+
flushTimer = null;
|
|
25
|
+
dirty = /* @__PURE__ */ new Map();
|
|
26
|
+
listeners = /* @__PURE__ */ new Set();
|
|
27
|
+
constructor(client, options = {}) {
|
|
28
|
+
this.client = client;
|
|
29
|
+
this.opts = {
|
|
30
|
+
debounceMs: options.debounceMs ?? 200,
|
|
31
|
+
batchMs: options.batchMs ?? 50,
|
|
32
|
+
removeDeleted: options.removeDeleted ?? true,
|
|
33
|
+
...options.minDelayMs === void 0 ? {} : { minDelayMs: options.minDelayMs },
|
|
34
|
+
...options.maxDelayMs === void 0 ? {} : { maxDelayMs: options.maxDelayMs },
|
|
35
|
+
...options.idleTimeoutMs === void 0 ? {} : { idleTimeoutMs: options.idleTimeoutMs }
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Count one more user of `collection` (whose queries live in `qc`); the
|
|
40
|
+
* returned function counts it out. `onEvent` hears every event of the
|
|
41
|
+
* collection as it arrives, before the debounced invalidation.
|
|
42
|
+
*/
|
|
43
|
+
subscribe(collection, qc, onEvent) {
|
|
44
|
+
const sub = {
|
|
45
|
+
qc,
|
|
46
|
+
onEvent
|
|
47
|
+
};
|
|
48
|
+
let set = this.subs.get(collection);
|
|
49
|
+
if (!set) {
|
|
50
|
+
set = /* @__PURE__ */ new Set();
|
|
51
|
+
this.subs.set(collection, set);
|
|
52
|
+
}
|
|
53
|
+
set.add(sub);
|
|
54
|
+
this.scheduleReconcile();
|
|
55
|
+
this.emit();
|
|
56
|
+
let done = false;
|
|
57
|
+
return () => {
|
|
58
|
+
if (done) return;
|
|
59
|
+
done = true;
|
|
60
|
+
const s = this.subs.get(collection);
|
|
61
|
+
s?.delete(sub);
|
|
62
|
+
if (s?.size === 0) this.subs.delete(collection);
|
|
63
|
+
this.scheduleReconcile();
|
|
64
|
+
this.emit();
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The collections the stream is (or is about to be) asked for. */
|
|
68
|
+
collections() {
|
|
69
|
+
return [...this.subs.keys()].sort();
|
|
70
|
+
}
|
|
71
|
+
/** Where the feed stands for `collection`. */
|
|
72
|
+
status(collection) {
|
|
73
|
+
if (!this.subs.has(collection)) return "off";
|
|
74
|
+
const cur = this.current;
|
|
75
|
+
if (cur?.collections.has(collection) && !(cur.state === "down" && this.pending)) return cur.state;
|
|
76
|
+
const pen = this.pending;
|
|
77
|
+
if (pen?.collections.has(collection)) return pen.state === "live" ? "live" : pen.state === "down" ? "down" : "connecting";
|
|
78
|
+
return "connecting";
|
|
79
|
+
}
|
|
80
|
+
/** Called whenever a status may have changed (for `useSyncExternalStore`). */
|
|
81
|
+
onStatus(listener) {
|
|
82
|
+
this.listeners.add(listener);
|
|
83
|
+
return () => {
|
|
84
|
+
this.listeners.delete(listener);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Close the stream and drop every timer; the feed opens again when somebody subscribes. */
|
|
88
|
+
close() {
|
|
89
|
+
if (this.reconcileTimer) clearTimeout(this.reconcileTimer);
|
|
90
|
+
if (this.flushTimer) clearTimeout(this.flushTimer);
|
|
91
|
+
this.reconcileTimer = this.flushTimer = null;
|
|
92
|
+
this.dirty.clear();
|
|
93
|
+
this.pending?.ctl.abort();
|
|
94
|
+
this.current?.ctl.abort();
|
|
95
|
+
this.pending = this.current = null;
|
|
96
|
+
this.emit();
|
|
97
|
+
}
|
|
98
|
+
emit() {
|
|
99
|
+
for (const l of this.listeners) l();
|
|
100
|
+
}
|
|
101
|
+
scheduleReconcile() {
|
|
102
|
+
if (this.reconcileTimer) clearTimeout(this.reconcileTimer);
|
|
103
|
+
this.reconcileTimer = setTimeout(() => {
|
|
104
|
+
this.reconcileTimer = null;
|
|
105
|
+
this.reconcile();
|
|
106
|
+
}, this.opts.batchMs);
|
|
107
|
+
}
|
|
108
|
+
reconcile() {
|
|
109
|
+
const wanted = this.collections();
|
|
110
|
+
const key = keyOf(wanted);
|
|
111
|
+
if (wanted.length === 0) {
|
|
112
|
+
this.close();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const cur = this.current;
|
|
116
|
+
if (cur && cur.key === key) {
|
|
117
|
+
if (this.pending) {
|
|
118
|
+
this.pending.ctl.abort();
|
|
119
|
+
this.pending = null;
|
|
120
|
+
this.emit();
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (this.pending?.key === key) return;
|
|
125
|
+
this.pending?.ctl.abort();
|
|
126
|
+
this.pending = this.open(wanted, key);
|
|
127
|
+
this.emit();
|
|
128
|
+
}
|
|
129
|
+
open(collections, key) {
|
|
130
|
+
const conn = {
|
|
131
|
+
key,
|
|
132
|
+
collections: new Set(collections),
|
|
133
|
+
ctl: new AbortController(),
|
|
134
|
+
state: "connecting",
|
|
135
|
+
startedAt: Date.now()
|
|
136
|
+
};
|
|
137
|
+
const { minDelayMs, maxDelayMs, idleTimeoutMs } = this.opts;
|
|
138
|
+
const options = {
|
|
139
|
+
collections,
|
|
140
|
+
signal: conn.ctl.signal,
|
|
141
|
+
onChange: (event) => this.deliver(conn, event),
|
|
142
|
+
onOpen: ({ reconnected }) => this.opened(conn, reconnected),
|
|
143
|
+
onError: () => this.dropped(conn),
|
|
144
|
+
...minDelayMs === void 0 ? {} : { minDelayMs },
|
|
145
|
+
...maxDelayMs === void 0 ? {} : { maxDelayMs },
|
|
146
|
+
...idleTimeoutMs === void 0 ? {} : { idleTimeoutMs }
|
|
147
|
+
};
|
|
148
|
+
this.client.changes(options).then(() => {}, (err) => this.refused(conn, err));
|
|
149
|
+
return conn;
|
|
150
|
+
}
|
|
151
|
+
live(conn) {
|
|
152
|
+
return conn === this.current || conn === this.pending;
|
|
153
|
+
}
|
|
154
|
+
opened(conn, reconnected) {
|
|
155
|
+
if (!this.live(conn) || conn.ctl.signal.aborted) return;
|
|
156
|
+
const prev = this.current;
|
|
157
|
+
if (conn === this.pending) {
|
|
158
|
+
this.current = conn;
|
|
159
|
+
this.pending = null;
|
|
160
|
+
if (prev && prev !== conn) prev.ctl.abort();
|
|
161
|
+
}
|
|
162
|
+
conn.state = "live";
|
|
163
|
+
if (reconnected) for (const c of conn.collections) this.markDirty(c);
|
|
164
|
+
else {
|
|
165
|
+
const carried = prev && prev !== conn && prev.state === "live" ? prev.collections : /* @__PURE__ */ new Set();
|
|
166
|
+
for (const c of conn.collections) if (!carried.has(c)) this.markDirty(c, conn.startedAt);
|
|
167
|
+
}
|
|
168
|
+
this.emit();
|
|
169
|
+
}
|
|
170
|
+
dropped(conn) {
|
|
171
|
+
if (!this.live(conn) || conn.ctl.signal.aborted) return;
|
|
172
|
+
conn.state = "reconnecting";
|
|
173
|
+
this.emit();
|
|
174
|
+
}
|
|
175
|
+
/** `changes()` rejected: the server refused (401, 403, 404, 400). No reconnecting. */
|
|
176
|
+
refused(conn, err) {
|
|
177
|
+
if (!this.live(conn) || conn.ctl.signal.aborted) return;
|
|
178
|
+
conn.state = "down";
|
|
179
|
+
if (isUnauthenticated(err)) for (const qc of this.queryClients()) notifyUnauthenticated(qc, err);
|
|
180
|
+
this.emit();
|
|
181
|
+
}
|
|
182
|
+
deliver(conn, event) {
|
|
183
|
+
if (!this.live(conn) || conn.ctl.signal.aborted) return;
|
|
184
|
+
const subs = this.subs.get(event.collection);
|
|
185
|
+
if (!subs) return;
|
|
186
|
+
for (const s of [...subs]) try {
|
|
187
|
+
s.onEvent?.(event);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
console.error("useUdcChanges: onEvent threw", err);
|
|
190
|
+
}
|
|
191
|
+
if (event.op === "delete" && event.ids?.length && this.opts.removeDeleted) {
|
|
192
|
+
const gone = new Set(event.ids);
|
|
193
|
+
for (const qc of this.queryClients(event.collection)) qc.setQueriesData({ queryKey: udcKeys.lists(event.collection) }, (data) => applyToListRows(data, (r) => gone.has(r.__meta.id)));
|
|
194
|
+
}
|
|
195
|
+
this.markDirty(event.collection);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Refetch `collection` after the debounce; `before` limits it to queries
|
|
199
|
+
* whose data is older than that time (a later plain mark lifts the limit).
|
|
200
|
+
*/
|
|
201
|
+
markDirty(collection, before) {
|
|
202
|
+
const had = this.dirty.has(collection);
|
|
203
|
+
const prev = this.dirty.get(collection);
|
|
204
|
+
const next = before === void 0 || had && prev === void 0 ? void 0 : Math.max(prev ?? 0, before);
|
|
205
|
+
this.dirty.set(collection, next);
|
|
206
|
+
this.scheduleFlush();
|
|
207
|
+
}
|
|
208
|
+
scheduleFlush() {
|
|
209
|
+
if (this.flushTimer) clearTimeout(this.flushTimer);
|
|
210
|
+
this.flushTimer = setTimeout(() => this.flush(), this.opts.debounceMs);
|
|
211
|
+
}
|
|
212
|
+
flush() {
|
|
213
|
+
this.flushTimer = null;
|
|
214
|
+
if ([...this.queryClients()].some((qc) => qc.isMutating() > 0)) {
|
|
215
|
+
this.scheduleFlush();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const batch = [...this.dirty];
|
|
219
|
+
this.dirty.clear();
|
|
220
|
+
for (const [collection, before] of batch) {
|
|
221
|
+
const predicate = before === void 0 ? void 0 : (q) => q.state.dataUpdatedAt > 0 && q.state.dataUpdatedAt < before;
|
|
222
|
+
for (const qc of this.queryClients(collection)) for (const queryKey of invalidatedKeys(collection)) qc.invalidateQueries(predicate ? {
|
|
223
|
+
queryKey,
|
|
224
|
+
predicate
|
|
225
|
+
} : { queryKey });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** The query clients of `collection`'s subscribers, or of everybody's. */
|
|
229
|
+
queryClients(collection) {
|
|
230
|
+
const out = /* @__PURE__ */ new Set();
|
|
231
|
+
const sets = collection === void 0 ? [...this.subs.values()] : [this.subs.get(collection)];
|
|
232
|
+
for (const set of sets) for (const s of set ?? []) out.add(s.qc);
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
/** What a change of `collection` makes stale: its lists, the lookups into it, its picker options. */
|
|
237
|
+
function invalidatedKeys(collection) {
|
|
238
|
+
return [
|
|
239
|
+
udcKeys.lists(collection),
|
|
240
|
+
udcKeys.lookups(collection),
|
|
241
|
+
[
|
|
242
|
+
"udc",
|
|
243
|
+
"lookup-options",
|
|
244
|
+
collection
|
|
245
|
+
]
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
export { UdcChangeFeed, invalidatedKeys };
|
|
249
|
+
|
|
250
|
+
//# sourceMappingURL=changeFeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changeFeed.js","names":[],"sources":["../../src/udc/changeFeed.ts"],"sourcesContent":["import { type ChangeEvent, isUnauthenticated } from \"@jsudc/core\";\nimport type { ChangesOptions, UdcClient } from \"@jsudc/core/client\";\nimport type { Query, QueryClient } from \"@tanstack/react-query\";\nimport { udcKeys } from \"./keys.js\";\nimport { applyToListRows, type ListCache } from \"./listCache.js\";\nimport { notifyUnauthenticated } from \"./unauthenticated.js\";\n\n/**\n * Where the change feed stands for one collection, as `useUdcChanges` reports\n * it:\n * - `off`: no feed (the provider has none, or the collection does not offer\n * `capabilities.changes`); the view polls as it always did.\n * - `connecting`: subscribed, the stream that carries it is not open yet.\n * - `live`: the stream is open; timer polling is suspended.\n * - `reconnecting`: the stream dropped and is being reopened; polling resumes.\n * - `down`: the server refused the stream (signed out, forbidden, unknown\n * collection); no reconnecting, polling only.\n */\nexport type UdcChangeFeedStatus = \"off\" | \"connecting\" | \"live\" | \"reconnecting\" | \"down\";\n\n/** `UdcProvider changes={…}`: `true` takes every default. */\nexport interface UdcChangeFeedOptions {\n /** A burst of events for one collection within this many ms makes one invalidation. Default 200. */\n debounceMs?: number;\n /**\n * How long to wait after a view mounts or unmounts before the stream is\n * reopened with the new list of collections, so a page that mounts several\n * views opens one stream. Default 50.\n */\n batchMs?: number;\n /**\n * A `delete` event that names its ids removes those rows from the cached\n * lists at once, before the refetch. Default `true`.\n */\n removeDeleted?: boolean;\n /** Passed to `UdcClient.changes`: the first reconnect delay. */\n minDelayMs?: number;\n /** Passed to `UdcClient.changes`: the longest reconnect delay. */\n maxDelayMs?: number;\n /** Passed to `UdcClient.changes`: a silent stream is reopened after this long. */\n idleTimeoutMs?: number;\n}\n\ninterface Subscriber {\n qc: QueryClient;\n onEvent: ((event: ChangeEvent) => void) | undefined;\n}\n\ntype ConnState = \"connecting\" | \"live\" | \"reconnecting\" | \"down\";\n\ninterface Conn {\n key: string;\n collections: ReadonlySet<string>;\n ctl: AbortController;\n state: ConnState;\n /** When the stream was asked for: data fetched before it may have missed an event. */\n startedAt: number;\n}\n\nconst keyOf = (collections: Iterable<string>) => [...collections].sort().join(\"\\n\");\n\n/**\n * The change feed of one `UdcProvider`: one stream for every collection a\n * mounted view (or hook) shows. Collections are reference-counted; when the\n * set changes the new stream is opened first and the old one closed only once\n * the new one is subscribed, so the collections that stay miss nothing. An\n * event marks its collection dirty and, after `debounceMs`, its lists, lookup\n * batches and lookup options are invalidated; \"reconnected\" invalidates every\n * collection of the stream. Framework-free apart from TanStack's QueryClient;\n * `useUdcChanges` is the React side.\n */\nexport class UdcChangeFeed {\n readonly client: UdcClient;\n private readonly opts: Required<\n Omit<UdcChangeFeedOptions, \"minDelayMs\" | \"maxDelayMs\" | \"idleTimeoutMs\">\n > &\n Pick<UdcChangeFeedOptions, \"minDelayMs\" | \"maxDelayMs\" | \"idleTimeoutMs\">;\n private readonly subs = new Map<string, Set<Subscriber>>();\n private current: Conn | null = null;\n private pending: Conn | null = null;\n private reconcileTimer: ReturnType<typeof setTimeout> | null = null;\n private flushTimer: ReturnType<typeof setTimeout> | null = null;\n private readonly dirty = new Map<string, number | undefined>();\n private readonly listeners = new Set<() => void>();\n\n constructor(client: UdcClient, options: UdcChangeFeedOptions = {}) {\n this.client = client;\n this.opts = {\n debounceMs: options.debounceMs ?? 200,\n batchMs: options.batchMs ?? 50,\n removeDeleted: options.removeDeleted ?? true,\n ...(options.minDelayMs === undefined ? {} : { minDelayMs: options.minDelayMs }),\n ...(options.maxDelayMs === undefined ? {} : { maxDelayMs: options.maxDelayMs }),\n ...(options.idleTimeoutMs === undefined ? {} : { idleTimeoutMs: options.idleTimeoutMs }),\n };\n }\n\n /**\n * Count one more user of `collection` (whose queries live in `qc`); the\n * returned function counts it out. `onEvent` hears every event of the\n * collection as it arrives, before the debounced invalidation.\n */\n subscribe(collection: string, qc: QueryClient, onEvent?: (event: ChangeEvent) => void) {\n const sub: Subscriber = { qc, onEvent };\n let set = this.subs.get(collection);\n if (!set) {\n set = new Set();\n this.subs.set(collection, set);\n }\n set.add(sub);\n this.scheduleReconcile();\n this.emit();\n let done = false;\n return () => {\n if (done) return;\n done = true;\n const s = this.subs.get(collection);\n s?.delete(sub);\n if (s?.size === 0) this.subs.delete(collection);\n this.scheduleReconcile();\n this.emit();\n };\n }\n\n /** The collections the stream is (or is about to be) asked for. */\n collections(): string[] {\n return [...this.subs.keys()].sort();\n }\n\n /** Where the feed stands for `collection`. */\n status(collection: string): UdcChangeFeedStatus {\n if (!this.subs.has(collection)) return \"off\";\n const cur = this.current;\n if (cur?.collections.has(collection) && !(cur.state === \"down\" && this.pending)) {\n return cur.state;\n }\n const pen = this.pending;\n if (pen?.collections.has(collection)) {\n return pen.state === \"live\" ? \"live\" : pen.state === \"down\" ? \"down\" : \"connecting\";\n }\n return \"connecting\";\n }\n\n /** Called whenever a status may have changed (for `useSyncExternalStore`). */\n onStatus(listener: () => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /** Close the stream and drop every timer; the feed opens again when somebody subscribes. */\n close(): void {\n if (this.reconcileTimer) clearTimeout(this.reconcileTimer);\n if (this.flushTimer) clearTimeout(this.flushTimer);\n this.reconcileTimer = this.flushTimer = null;\n this.dirty.clear();\n this.pending?.ctl.abort();\n this.current?.ctl.abort();\n this.pending = this.current = null;\n this.emit();\n }\n\n // The stream ---------------------------------------------------------------\n\n private emit() {\n for (const l of this.listeners) l();\n }\n\n private scheduleReconcile() {\n if (this.reconcileTimer) clearTimeout(this.reconcileTimer);\n this.reconcileTimer = setTimeout(() => {\n this.reconcileTimer = null;\n this.reconcile();\n }, this.opts.batchMs);\n }\n\n private reconcile() {\n const wanted = this.collections();\n const key = keyOf(wanted);\n if (wanted.length === 0) {\n this.close();\n return;\n }\n const cur = this.current;\n if (cur && cur.key === key) {\n // The set went back to what is open: a reopen in flight is not needed. A stream the\n // server refused for this very set stays refused until the set changes.\n if (this.pending) {\n this.pending.ctl.abort();\n this.pending = null;\n this.emit();\n }\n return;\n }\n if (this.pending?.key === key) return;\n this.pending?.ctl.abort();\n this.pending = this.open(wanted, key);\n this.emit();\n }\n\n private open(collections: string[], key: string): Conn {\n const conn: Conn = {\n key,\n collections: new Set(collections),\n ctl: new AbortController(),\n state: \"connecting\",\n startedAt: Date.now(),\n };\n const { minDelayMs, maxDelayMs, idleTimeoutMs } = this.opts;\n const options: ChangesOptions = {\n collections,\n signal: conn.ctl.signal,\n onChange: (event) => this.deliver(conn, event),\n onOpen: ({ reconnected }) => this.opened(conn, reconnected),\n onError: () => this.dropped(conn),\n ...(minDelayMs === undefined ? {} : { minDelayMs }),\n ...(maxDelayMs === undefined ? {} : { maxDelayMs }),\n ...(idleTimeoutMs === undefined ? {} : { idleTimeoutMs }),\n };\n this.client.changes(options).then(\n () => {},\n (err: unknown) => this.refused(conn, err),\n );\n return conn;\n }\n\n private live(conn: Conn) {\n return conn === this.current || conn === this.pending;\n }\n\n private opened(conn: Conn, reconnected: boolean) {\n if (!this.live(conn) || conn.ctl.signal.aborted) return;\n const prev = this.current;\n if (conn === this.pending) {\n // The new stream is subscribed: it takes over, the old one closes.\n this.current = conn;\n this.pending = null;\n if (prev && prev !== conn) prev.ctl.abort();\n }\n conn.state = \"live\";\n if (reconnected) {\n // Changes made while the stream was down were not sent: refetch everything it carries.\n for (const c of conn.collections) this.markDirty(c);\n } else {\n // A collection that was not carried by an open stream until now may have changed between\n // its last fetch and this subscription: refetch what was fetched before the stream was asked for.\n const carried = prev && prev !== conn && prev.state === \"live\" ? prev.collections : new Set();\n for (const c of conn.collections) if (!carried.has(c)) this.markDirty(c, conn.startedAt);\n }\n this.emit();\n }\n\n private dropped(conn: Conn) {\n if (!this.live(conn) || conn.ctl.signal.aborted) return;\n conn.state = \"reconnecting\";\n this.emit();\n }\n\n /** `changes()` rejected: the server refused (401, 403, 404, 400). No reconnecting. */\n private refused(conn: Conn, err: unknown) {\n if (!this.live(conn) || conn.ctl.signal.aborted) return;\n conn.state = \"down\";\n if (isUnauthenticated(err))\n for (const qc of this.queryClients()) notifyUnauthenticated(qc, err);\n // A refused reopen stays as `pending` in state `down`: the old stream (if open) still carries\n // what it carried, and the same set is not asked for again until it changes.\n this.emit();\n }\n\n private deliver(conn: Conn, event: ChangeEvent) {\n if (!this.live(conn) || conn.ctl.signal.aborted) return;\n const subs = this.subs.get(event.collection);\n if (!subs) return; // Not a collection on screen.\n for (const s of [...subs]) {\n try {\n s.onEvent?.(event);\n } catch (err) {\n console.error(\"useUdcChanges: onEvent threw\", err);\n }\n }\n if (event.op === \"delete\" && event.ids?.length && this.opts.removeDeleted) {\n const gone = new Set(event.ids);\n for (const qc of this.queryClients(event.collection)) {\n qc.setQueriesData<ListCache>({ queryKey: udcKeys.lists(event.collection) }, (data) =>\n applyToListRows(data, (r) => gone.has(r.__meta.id)),\n );\n }\n }\n this.markDirty(event.collection);\n }\n\n // Invalidation -------------------------------------------------------------\n\n /**\n * Refetch `collection` after the debounce; `before` limits it to queries\n * whose data is older than that time (a later plain mark lifts the limit).\n */\n private markDirty(collection: string, before?: number) {\n const had = this.dirty.has(collection);\n const prev = this.dirty.get(collection);\n const next =\n before === undefined || (had && prev === undefined) ? undefined : Math.max(prev ?? 0, before);\n this.dirty.set(collection, next);\n this.scheduleFlush();\n }\n\n private scheduleFlush() {\n if (this.flushTimer) clearTimeout(this.flushTimer);\n this.flushTimer = setTimeout(() => this.flush(), this.opts.debounceMs);\n }\n\n private flush() {\n this.flushTimer = null;\n const clients = this.queryClients();\n // A mutation in flight invalidates when it settles; refetching under it would show the\n // row as it was before the optimistic patch. Wait for it.\n if ([...clients].some((qc) => qc.isMutating() > 0)) {\n this.scheduleFlush();\n return;\n }\n const batch = [...this.dirty];\n this.dirty.clear();\n for (const [collection, before] of batch) {\n const predicate =\n before === undefined\n ? undefined\n : (q: Query) => q.state.dataUpdatedAt > 0 && q.state.dataUpdatedAt < before;\n for (const qc of this.queryClients(collection)) {\n for (const queryKey of invalidatedKeys(collection)) {\n void qc.invalidateQueries(predicate ? { queryKey, predicate } : { queryKey });\n }\n }\n }\n }\n\n /** The query clients of `collection`'s subscribers, or of everybody's. */\n private queryClients(collection?: string): Set<QueryClient> {\n const out = new Set<QueryClient>();\n const sets = collection === undefined ? [...this.subs.values()] : [this.subs.get(collection)];\n for (const set of sets) for (const s of set ?? []) out.add(s.qc);\n return out;\n }\n}\n\n/** What a change of `collection` makes stale: its lists, the lookups into it, its picker options. */\nexport function invalidatedKeys(collection: string): (readonly unknown[])[] {\n return [\n udcKeys.lists(collection),\n udcKeys.lookups(collection),\n [\"udc\", \"lookup-options\", collection],\n ];\n}\n"],"mappings":";;;;;AA2DA,IAAM,SAAS,gBAAkC,CAAC,GAAG,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;;AAYlF,IAAa,gBAAb,MAA2B;CACzB;CACA;CAIA,uBAAwB,IAAI,IAA6B;CACzD,UAA+B;CAC/B,UAA+B;CAC/B,iBAA+D;CAC/D,aAA2D;CAC3D,wBAAyB,IAAI,IAAgC;CAC7D,4BAA6B,IAAI,IAAgB;CAEjD,YAAY,QAAmB,UAAgC,CAAC,GAAG;EACjE,KAAK,SAAS;EACd,KAAK,OAAO;GACV,YAAY,QAAQ,cAAc;GAClC,SAAS,QAAQ,WAAW;GAC5B,eAAe,QAAQ,iBAAiB;GACxC,GAAI,QAAQ,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,WAAW;GAC7E,GAAI,QAAQ,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,WAAW;GAC7E,GAAI,QAAQ,kBAAkB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe,QAAQ,cAA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ACC,MAAa,EAAE,MAAM,gBAAgB,KAAK,EAAE,MAAM,gBAAgB;GACzE,KAAK,MAAM,MAAM,KAAK,aAAa,UAAU,GAC3C,KAAK,MAAM,YAAY,gBAAgB,UAAU,GAC/C,GAAQ,kBAAkB,YAAY;IAAE;IAAU;GAAU,IAAI,EAAE,SAAS,CAAC;EAGlF;CACF;;CAGA,aAAqB,YAAuC;EAC1D,MAAM,sBAAM,IAAI,IAAiB;EACjC,MAAM,OAAO,eAAe,KAAA,IAAY,CAAC,GAAG,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,UAAU,CAAC;EAC5F,KAAK,MAAM,OAAO,MAAM,KAAK,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,EAAE;EAC/D,OAAO;CACT;AACF;;AAGA,SAAgB,gBAAgB,YAA4C;CAC1E,OAAO;EACL,QAAQ,MAAM,UAAU;EACxB,QAAQ,QAAQ,UAAU;EAC1B;GAAC;GAAO;GAAkB;EAAU;CACtC;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Capabilities, type ChangeEvent } from "@jsudc/core";
|
|
2
|
+
import type { UdcChangeFeed, UdcChangeFeedStatus } from "./changeFeed.js";
|
|
3
|
+
/** The provider's change feed; `null` when `UdcProvider changes` is off (the default). */
|
|
4
|
+
export declare const UdcChangeFeedContext: import("react").Context<UdcChangeFeed | null>;
|
|
5
|
+
/** The provider's change feed, or `null` without one. */
|
|
6
|
+
export declare function useUdcChangeFeed(): UdcChangeFeed | null;
|
|
7
|
+
export interface UseUdcChangesOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The collection's capabilities when the caller has them (`describe`): with
|
|
10
|
+
* `changes` set, no `describe` is asked; without it the hook reads the
|
|
11
|
+
* cached `describe` of the collection (only when the provider has a feed).
|
|
12
|
+
*/
|
|
13
|
+
capabilities?: Pick<Capabilities, "changes"> | undefined;
|
|
14
|
+
/** `false`: no subscription (a hidden or disabled view). Default `true`. */
|
|
15
|
+
enabled?: boolean | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface UdcChangesResult {
|
|
18
|
+
/** Where the feed stands for this collection (see `UdcChangeFeedStatus`). */
|
|
19
|
+
status: UdcChangeFeedStatus;
|
|
20
|
+
/** `status === "live"`: the stream carries the collection, timer polling is suspended. */
|
|
21
|
+
live: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Follow the change feed of `collection`: while it is mounted the provider's
|
|
25
|
+
* stream carries the collection (`UdcProvider changes`), its lists and lookups
|
|
26
|
+
* are refetched when the server says its rows changed, and `onEvent` (if
|
|
27
|
+
* given) hears each `ChangeEvent` as it arrives (e.g. a badge counter).
|
|
28
|
+
* Answers where the feed stands; `live` is when the views of the collection
|
|
29
|
+
* stop polling. Without a feed in the provider, or for a collection that does
|
|
30
|
+
* not offer `capabilities.changes`, it does nothing and answers `off`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useUdcChanges(collection: string, onEvent?: (event: ChangeEvent) => void, opts?: UseUdcChangesOptions): UdcChangesResult;
|
|
33
|
+
/** `useUdcChanges` for several collections at once, without a status (the lookup hooks). */
|
|
34
|
+
export declare function useUdcChangesMany(collections: readonly string[], opts?: Omit<UseUdcChangesOptions, "capabilities">): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { UdcClientContext } from "./client.js";
|
|
2
|
+
import { udcKeys } from "./keys.js";
|
|
3
|
+
import { sourcePushesChanges } from "@jsudc/core";
|
|
4
|
+
import { createContext, useContext, useEffect, useRef, useSyncExternalStore } from "react";
|
|
5
|
+
import { QueryClientContext, useQueries } from "@tanstack/react-query";
|
|
6
|
+
// src/udc/changes.ts
|
|
7
|
+
/** The provider's change feed; `null` when `UdcProvider changes` is off (the default). */
|
|
8
|
+
var UdcChangeFeedContext = createContext(null);
|
|
9
|
+
/** The provider's change feed, or `null` without one. */
|
|
10
|
+
function useUdcChangeFeed() {
|
|
11
|
+
return useContext(UdcChangeFeedContext);
|
|
12
|
+
}
|
|
13
|
+
var noSubscribe = () => () => {};
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe `collections` to the provider's feed, each one that offers
|
|
16
|
+
* `capabilities.changes`. Nothing at all (no `describe`, no connection) when
|
|
17
|
+
* the provider has no feed. Answers the collections that are subscribed.
|
|
18
|
+
*/
|
|
19
|
+
function useFeedSubscriptions(collections, onEvent, opts) {
|
|
20
|
+
const feed = useContext(UdcChangeFeedContext);
|
|
21
|
+
const client = useContext(UdcClientContext);
|
|
22
|
+
const qc = useContext(QueryClientContext);
|
|
23
|
+
const wanted = feed !== null && client !== null && qc !== void 0 && (opts.enabled ?? true) ? [...new Set(collections.filter((c) => c !== ""))] : [];
|
|
24
|
+
const known = opts.capabilities?.changes;
|
|
25
|
+
const described = useQueries({ queries: known === void 0 && client ? wanted.map((c) => ({
|
|
26
|
+
queryKey: udcKeys.describe(c),
|
|
27
|
+
queryFn: () => client.describe(c),
|
|
28
|
+
staleTime: 3e5
|
|
29
|
+
})) : [] });
|
|
30
|
+
const offered = known === void 0 ? wanted.filter((_, i) => sourcePushesChanges(described[i]?.data?.capabilities)) : known ? wanted : [];
|
|
31
|
+
const onEventRef = useRef(onEvent);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
onEventRef.current = onEvent;
|
|
34
|
+
});
|
|
35
|
+
const hasOnEvent = onEvent !== void 0;
|
|
36
|
+
const key = offered.join("\n");
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!feed || !qc || key === "") return;
|
|
39
|
+
const listener = hasOnEvent ? (e) => onEventRef.current?.(e) : void 0;
|
|
40
|
+
const offs = key.split("\n").map((c) => feed.subscribe(c, qc, listener));
|
|
41
|
+
return () => {
|
|
42
|
+
for (const off of offs) off();
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
feed,
|
|
46
|
+
qc,
|
|
47
|
+
key,
|
|
48
|
+
hasOnEvent
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
feed,
|
|
52
|
+
offered
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Follow the change feed of `collection`: while it is mounted the provider's
|
|
57
|
+
* stream carries the collection (`UdcProvider changes`), its lists and lookups
|
|
58
|
+
* are refetched when the server says its rows changed, and `onEvent` (if
|
|
59
|
+
* given) hears each `ChangeEvent` as it arrives (e.g. a badge counter).
|
|
60
|
+
* Answers where the feed stands; `live` is when the views of the collection
|
|
61
|
+
* stop polling. Without a feed in the provider, or for a collection that does
|
|
62
|
+
* not offer `capabilities.changes`, it does nothing and answers `off`.
|
|
63
|
+
*/
|
|
64
|
+
function useUdcChanges(collection, onEvent, opts = {}) {
|
|
65
|
+
const { feed, offered } = useFeedSubscriptions([collection], onEvent, opts);
|
|
66
|
+
const subscribed = offered.length > 0;
|
|
67
|
+
const status = useSyncExternalStore(feed ? (l) => feed.onStatus(l) : noSubscribe, () => feed && subscribed ? feed.status(collection) : "off", () => "off");
|
|
68
|
+
return {
|
|
69
|
+
status,
|
|
70
|
+
live: status === "live"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** `useUdcChanges` for several collections at once, without a status (the lookup hooks). */
|
|
74
|
+
function useUdcChangesMany(collections, opts = {}) {
|
|
75
|
+
useFeedSubscriptions(collections, void 0, opts);
|
|
76
|
+
}
|
|
77
|
+
export { UdcChangeFeedContext, useUdcChangeFeed, useUdcChanges, useUdcChangesMany };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changes.js","names":[],"sources":["../../src/udc/changes.ts"],"sourcesContent":["import { type Capabilities, type ChangeEvent, sourcePushesChanges } from \"@jsudc/core\";\nimport { QueryClientContext, useQueries } from \"@tanstack/react-query\";\nimport { createContext, useContext, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { UdcChangeFeed, UdcChangeFeedStatus } from \"./changeFeed.js\";\nimport { UdcClientContext } from \"./client.js\";\nimport { udcKeys } from \"./keys.js\";\n\n/** The provider's change feed; `null` when `UdcProvider changes` is off (the default). */\nexport const UdcChangeFeedContext = createContext<UdcChangeFeed | null>(null);\n\n/** The provider's change feed, or `null` without one. */\nexport function useUdcChangeFeed(): UdcChangeFeed | null {\n return useContext(UdcChangeFeedContext);\n}\n\nexport interface UseUdcChangesOptions {\n /**\n * The collection's capabilities when the caller has them (`describe`): with\n * `changes` set, no `describe` is asked; without it the hook reads the\n * cached `describe` of the collection (only when the provider has a feed).\n */\n capabilities?: Pick<Capabilities, \"changes\"> | undefined;\n /** `false`: no subscription (a hidden or disabled view). Default `true`. */\n enabled?: boolean | undefined;\n}\n\nexport interface UdcChangesResult {\n /** Where the feed stands for this collection (see `UdcChangeFeedStatus`). */\n status: UdcChangeFeedStatus;\n /** `status === \"live\"`: the stream carries the collection, timer polling is suspended. */\n live: boolean;\n}\n\nconst noSubscribe = () => () => {};\n\n/**\n * Subscribe `collections` to the provider's feed, each one that offers\n * `capabilities.changes`. Nothing at all (no `describe`, no connection) when\n * the provider has no feed. Answers the collections that are subscribed.\n */\nfunction useFeedSubscriptions(\n collections: readonly string[],\n onEvent: ((event: ChangeEvent) => void) | undefined,\n opts: UseUdcChangesOptions,\n): { feed: UdcChangeFeed | null; offered: string[] } {\n const feed = useContext(UdcChangeFeedContext);\n const client = useContext(UdcClientContext);\n const qc = useContext(QueryClientContext);\n const on = feed !== null && client !== null && qc !== undefined && (opts.enabled ?? true);\n const wanted = on ? [...new Set(collections.filter((c) => c !== \"\"))] : [];\n const known = opts.capabilities?.changes;\n // The capability, from `describe` (cached for minutes, shared with the view that shows it).\n const described = useQueries({\n queries:\n known === undefined && client\n ? wanted.map((c) => ({\n queryKey: udcKeys.describe(c),\n queryFn: () => client.describe(c),\n staleTime: 5 * 60_000,\n }))\n : [],\n });\n const offered =\n known === undefined\n ? wanted.filter((_, i) => sourcePushesChanges(described[i]?.data?.capabilities))\n : known\n ? wanted\n : [];\n\n const onEventRef = useRef(onEvent);\n useEffect(() => {\n onEventRef.current = onEvent;\n });\n const hasOnEvent = onEvent !== undefined;\n const key = offered.join(\"\\n\");\n useEffect(() => {\n if (!feed || !qc || key === \"\") return;\n const listener = hasOnEvent ? (e: ChangeEvent) => onEventRef.current?.(e) : undefined;\n const offs = key.split(\"\\n\").map((c) => feed.subscribe(c, qc, listener));\n return () => {\n for (const off of offs) off();\n };\n }, [feed, qc, key, hasOnEvent]);\n return { feed, offered };\n}\n\n/**\n * Follow the change feed of `collection`: while it is mounted the provider's\n * stream carries the collection (`UdcProvider changes`), its lists and lookups\n * are refetched when the server says its rows changed, and `onEvent` (if\n * given) hears each `ChangeEvent` as it arrives (e.g. a badge counter).\n * Answers where the feed stands; `live` is when the views of the collection\n * stop polling. Without a feed in the provider, or for a collection that does\n * not offer `capabilities.changes`, it does nothing and answers `off`.\n */\nexport function useUdcChanges(\n collection: string,\n onEvent?: (event: ChangeEvent) => void,\n opts: UseUdcChangesOptions = {},\n): UdcChangesResult {\n const { feed, offered } = useFeedSubscriptions([collection], onEvent, opts);\n const subscribed = offered.length > 0;\n const status = useSyncExternalStore(\n feed ? (l: () => void) => feed.onStatus(l) : noSubscribe,\n () => (feed && subscribed ? feed.status(collection) : \"off\"),\n () => \"off\" as const,\n );\n return { status, live: status === \"live\" };\n}\n\n/** `useUdcChanges` for several collections at once, without a status (the lookup hooks). */\nexport function useUdcChangesMany(\n collections: readonly string[],\n opts: Omit<UseUdcChangesOptions, \"capabilities\"> = {},\n): void {\n useFeedSubscriptions(collections, undefined, opts);\n}\n"],"mappings":";;;;;;;AAQA,IAAa,uBAAuB,cAAoC,IAAI;;AAG5E,SAAgB,mBAAyC;CACvD,OAAO,WAAW,oBAAoB;AACxC;AAoBA,IAAM,0BAA0B,CAAC;;;;;;AAOjC,SAAS,qBACP,aACA,SACA,MACmD;CACnD,MAAM,OAAO,WAAW,oBAAoB;CAC5C,MAAM,SAAS,WAAW,gBAAgB;CAC1C,MAAM,KAAK,WAAW,k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AI,mBACtC,QAAQ,aAAa,KAAK,OAAO,UAAU,IAAI,aAChD,KACR;CACA,OAAO;EAAE;EAAQ,MAAM,WAAW;CAAO;AAC3C;;AAGA,SAAgB,kBACd,aACA,OAAmD,CAAC,GAC9C;CACN,qBAAqB,aAAa,KAAA,GAAW,IAAI;AACnD"}
|
package/dist/udc/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type UdcError } from "@jsudc/core";
|
|
1
2
|
import type { UdcClient } from "@jsudc/core/client";
|
|
2
3
|
import { QueryClient } from "@tanstack/react-query";
|
|
3
4
|
/** The client every hook talks to; `UdcProvider` sets it. */
|
|
@@ -8,4 +9,17 @@ export declare function useUdcClient(): UdcClient;
|
|
|
8
9
|
* the same answer. Only transport failures are retried, twice.
|
|
9
10
|
*/
|
|
10
11
|
export declare function shouldRetry(failureCount: number, error: unknown): boolean;
|
|
11
|
-
export
|
|
12
|
+
export interface UdcQueryClientOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Called when a query or a mutation fails because the user is not signed in
|
|
15
|
+
* (`isUnauthenticated`: an HTTP 401 in front of `/udc`, or the server's
|
|
16
|
+
* in-protocol refusal) — the place to send the user to the host's login.
|
|
17
|
+
* Once per burst: the failures that arrive together (every query of a page,
|
|
18
|
+
* say) make one call; it fires again only after `unauthenticatedQuietMs`
|
|
19
|
+
* without such a failure.
|
|
20
|
+
*/
|
|
21
|
+
onUnauthenticated?: (error: UdcError) => void;
|
|
22
|
+
/** The quiet time, in ms, that ends a burst of unauthenticated failures. Default 2000. */
|
|
23
|
+
unauthenticatedQuietMs?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function createUdcQueryClient(options?: UdcQueryClientOptions): QueryClient;
|
package/dist/udc/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { registerUnauthenticated } from "./unauthenticated.js";
|
|
2
|
+
import { isUdcError, isUnauthenticated } from "@jsudc/core";
|
|
1
3
|
import { createContext, useContext } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query";
|
|
4
5
|
// src/udc/client.ts
|
|
5
6
|
/** The client every hook talks to; `UdcProvider` sets it. */
|
|
6
7
|
var UdcClientContext = createContext(null);
|
|
@@ -16,14 +17,37 @@ function useUdcClient() {
|
|
|
16
17
|
function shouldRetry(failureCount, error) {
|
|
17
18
|
return !isUdcError(error) && failureCount < 2;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Calls `fn` on the first unauthenticated error and swallows the rest until
|
|
22
|
+
* `quietMs` pass without one (each further error restarts that wait).
|
|
23
|
+
*/
|
|
24
|
+
function unauthenticatedNotifier(fn, quietMs) {
|
|
25
|
+
let lastAt = null;
|
|
26
|
+
return (error) => {
|
|
27
|
+
if (!isUnauthenticated(error)) return;
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const inBurst = lastAt !== null && now - lastAt < quietMs;
|
|
30
|
+
lastAt = now;
|
|
31
|
+
if (!inBurst) fn(error);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createUdcQueryClient(options = {}) {
|
|
35
|
+
const notify = options.onUnauthenticated ? unauthenticatedNotifier(options.onUnauthenticated, options.unauthenticatedQuietMs ?? 2e3) : void 0;
|
|
36
|
+
const qc = new QueryClient({
|
|
37
|
+
...notify ? {
|
|
38
|
+
queryCache: new QueryCache({ onError: notify }),
|
|
39
|
+
mutationCache: new MutationCache({ onError: notify })
|
|
40
|
+
} : {},
|
|
41
|
+
defaultOptions: {
|
|
42
|
+
queries: {
|
|
43
|
+
retry: shouldRetry,
|
|
44
|
+
refetchOnWindowFocus: false
|
|
45
|
+
},
|
|
46
|
+
mutations: { retry: false }
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (notify) registerUnauthenticated(qc, notify);
|
|
50
|
+
return qc;
|
|
27
51
|
}
|
|
28
52
|
export { UdcClientContext, createUdcQueryClient, shouldRetry, useUdcClient };
|
|
29
53
|
|
package/dist/udc/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isUdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport function createUdcQueryClient(): QueryClient {\n
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isUdcError, isUnauthenticated, type UdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { MutationCache, QueryCache, QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\nimport { registerUnauthenticated } from \"./unauthenticated.js\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport interface UdcQueryClientOptions {\n /**\n * Called when a query or a mutation fails because the user is not signed in\n * (`isUnauthenticated`: an HTTP 401 in front of `/udc`, or the server's\n * in-protocol refusal) — the place to send the user to the host's login.\n * Once per burst: the failures that arrive together (every query of a page,\n * say) make one call; it fires again only after `unauthenticatedQuietMs`\n * without such a failure.\n */\n onUnauthenticated?: (error: UdcError) => void;\n /** The quiet time, in ms, that ends a burst of unauthenticated failures. Default 2000. */\n unauthenticatedQuietMs?: number;\n}\n\n/**\n * Calls `fn` on the first unauthenticated error and swallows the rest until\n * `quietMs` pass without one (each further error restarts that wait).\n */\nfunction unauthenticatedNotifier(\n fn: (error: UdcError) => void,\n quietMs: number,\n): (error: unknown) => void {\n let lastAt: number | null = null;\n return (error) => {\n if (!isUnauthenticated(error)) return;\n const now = Date.now();\n const inBurst = lastAt !== null && now - lastAt < quietMs;\n lastAt = now;\n if (!inBurst) fn(error as UdcError);\n };\n}\n\nexport function createUdcQueryClient(options: UdcQueryClientOptions = {}): QueryClient {\n const notify = options.onUnauthenticated\n ? unauthenticatedNotifier(options.onUnauthenticated, options.unauthenticatedQuietMs ?? 2000)\n : undefined;\n const qc = new QueryClient({\n ...(notify\n ? {\n queryCache: new QueryCache({ onError: notify }),\n mutationCache: new MutationCache({ onError: notify }),\n }\n : {}),\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n // The change feed's unauthenticated error takes the same path (and the same burst).\n if (notify) registerUnauthenticated(qc, notify);\n return qc;\n}\n"],"mappings":";;;;;;AAOA,IAAa,mBAAmB,cAAgC,IAAI;AAEpE,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,OAAO,CAAC,WAAW,KAAK,KAAK,eAAe;AAC9C;;;;;AAoBA,SAAS,wBACP,IACA,SAC0B;CAC1B,IAAI,SAAwB;CAC5B,QAAQ,UAAU;EAChB,IAAI,CAAC,kBAAkB,KAAK,GAAG;EAC/B,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,UAAU,WAAW,QAAQ,MAAM,SAAS;EAClD,SAAS;EACT,IAAI,CAAC,SAAS,GAAG,KAAiB;CACpC;AACF;AAEA,SAAgB,qBAAqB,UAAiC,CAAC,GAAgB;CACrF,MAAM,SAAS,QAAQ,oBACnB,wBAAwB,QAAQ,mBAAmB,QAAQ,0BAA0B,GAAI,IACzF,KAAA;CACJ,MAAM,KAAK,IAAI,YAAY;EACzB,GAAI,SACA;GACE,YAAY,IAAI,WAAW,EAAE,SAAS,OAAO,CAAC;GAC9C,eAAe,IAAI,cAAc,EAAE,SAAS,OAAO,CAAC;EACtD,IACA,CAAC;EACL,gBAAgB;GACd,SAAS;IAAE,OAAO;IAAa,sBAAsB;GAAM;GAC3D,WAAW,EAAE,OAAO,MAAM;EAC5B;CACF,CAAC;CAED,IAAI,QAAQ,wBAAwB,IAAI,MAAM;CAC9C,OAAO;AACT"}
|