tsdf 8.0.0-beta.1 → 8.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/main.cjs +1860 -0
  2. package/dist/main.d.ts +291 -0
  3. package/dist/main.js +1825 -0
  4. package/package.json +6 -2
  5. package/.eslintignore +0 -3
  6. package/.eslintrc.cjs +0 -119
  7. package/.gitattributes +0 -22
  8. package/.prettierrc +0 -6
  9. package/.vscode/settings.json +0 -3
  10. package/.vscode/tasks.json +0 -35
  11. package/fetch-orquestrator-scenarios.excalidraw +0 -10115
  12. package/scripts/check-if-is-sync.sh +0 -6
  13. package/src/collectionFetchOrquestrator.ts +0 -23
  14. package/src/collectionStore.ts +0 -608
  15. package/src/documentStore.ts +0 -272
  16. package/src/fetchOrquestrator.ts +0 -335
  17. package/src/listQueryStore.ts +0 -1190
  18. package/src/main.ts +0 -22
  19. package/src/storeShared.ts +0 -5
  20. package/src/useEnsureIsLoaded.ts +0 -50
  21. package/src/utils/filterAndMap.ts +0 -20
  22. package/src/utils/getCacheId.ts +0 -19
  23. package/src/utils/hooks.ts +0 -110
  24. package/src/utils/isObject.ts +0 -3
  25. package/src/utils/math.ts +0 -7
  26. package/src/utils/serializableClone.ts +0 -3
  27. package/src/utils/useLatestValue.ts +0 -16
  28. package/test/__snapshots__/listQueryStore.test.ts.snap +0 -146
  29. package/test/__snapshots__/listQueryStoreHooks.test.ts.snap +0 -9
  30. package/test/collectionStore.test.ts +0 -523
  31. package/test/collectionStoreHooks.test.tsx +0 -651
  32. package/test/documentStore.test.ts +0 -183
  33. package/test/documentStoreHooks.test.tsx +0 -857
  34. package/test/fetchOrquestrator.test.ts +0 -913
  35. package/test/listQueryStore.test.ts +0 -1158
  36. package/test/listQueryStoreHooks.test.tsx +0 -662
  37. package/test/listQueryStoreHooks2.test.tsx +0 -483
  38. package/test/listQueryStoreHooksMutations.test.tsx +0 -764
  39. package/test/mocks/fetchMock.ts +0 -296
  40. package/test/mocks/fetchOrquestratorEnv.ts +0 -370
  41. package/test/setup/setup.ts +0 -109
  42. package/test/testHelpers.test.ts +0 -88
  43. package/test/utils/RenderObjValues.tsx +0 -23
  44. package/test/utils/arrayUtils.ts +0 -13
  45. package/test/utils/createDefaultListQueryStore.ts +0 -275
  46. package/test/utils/createOrVariations.ts +0 -48
  47. package/test/utils/dedent.ts +0 -50
  48. package/test/utils/delayCall.ts +0 -25
  49. package/test/utils/math.ts +0 -3
  50. package/test/utils/objectUtils.ts +0 -18
  51. package/test/utils/range.ts +0 -19
  52. package/test/utils/sleep.ts +0 -3
  53. package/test/utils/storeUtils.ts +0 -460
  54. package/tsconfig.json +0 -24
  55. package/tsconfig.prod.json +0 -9
  56. package/tsup.config.ts +0 -12
  57. package/vitest.config.ts +0 -10
package/dist/main.cjs ADDED
@@ -0,0 +1,1860 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/main.ts
27
+ var main_exports = {};
28
+ __export(main_exports, {
29
+ newTSDFCollectionStore: () => newTSDFCollectionStore,
30
+ newTSDFDocumentStore: () => newTSDFDocumentStore,
31
+ newTSDFListQueryStore: () => newTSDFListQueryStore
32
+ });
33
+ module.exports = __toCommonJS(main_exports);
34
+
35
+ // src/documentStore.ts
36
+ var import_immer = require("immer");
37
+ var import_mitt2 = __toESM(require("mitt"), 1);
38
+ var import_react3 = require("react");
39
+ var import_t_state3 = require("t-state");
40
+
41
+ // src/fetchOrquestrator.ts
42
+ function createFetchOrquestrator({
43
+ fetchFn,
44
+ on,
45
+ mediumPriorityThrottleMs = 10,
46
+ lowPriorityThrottleMs = 200,
47
+ dynamicRealtimeThrottleMs
48
+ }) {
49
+ const fetchs = {
50
+ a: null,
51
+ c: null,
52
+ b: null
53
+ };
54
+ let lastMutationIdStarted = 0;
55
+ let lastFetchIdStarted = 0;
56
+ let mutationIsInProgress = false;
57
+ let lastFetchStartTime = 0;
58
+ let lastFetchDuration = 0;
59
+ let onMutationEnd = [];
60
+ let lastFetchWasAborted = false;
61
+ let abortFetchsBeforeOrEqual = 0;
62
+ function setLastFetchDurantion(duration) {
63
+ lastFetchDuration = duration;
64
+ }
65
+ function setLastFetchStartTime(startTime) {
66
+ lastFetchStartTime = startTime;
67
+ }
68
+ function flushScheduledFetch() {
69
+ if (fetchs.c) {
70
+ on?.("scheduled-fetch-started");
71
+ const params = fetchs.c.params;
72
+ fetchs.c = null;
73
+ startFetch(params, Date.now());
74
+ }
75
+ }
76
+ function startMutation() {
77
+ mutationIsInProgress = true;
78
+ abortFetchsBeforeOrEqual = lastFetchIdStarted;
79
+ fetchs.a = null;
80
+ const id = getAutoIncrementId();
81
+ lastMutationIdStarted = id;
82
+ return () => endMutation(id);
83
+ }
84
+ function endMutation(id) {
85
+ if (id === lastMutationIdStarted) {
86
+ mutationIsInProgress = false;
87
+ if (onMutationEnd.length > 0) {
88
+ onMutationEnd.forEach((cb) => cb());
89
+ onMutationEnd = [];
90
+ }
91
+ flushScheduledFetch();
92
+ return true;
93
+ }
94
+ return false;
95
+ }
96
+ function getFetchs() {
97
+ return fetchs;
98
+ }
99
+ async function startFetch(params, startTime) {
100
+ if (fetchs.a) {
101
+ throw new Error("[tsdf] Fetch already in progress");
102
+ }
103
+ const id = getAutoIncrementId();
104
+ lastFetchIdStarted = id;
105
+ lastFetchWasAborted = false;
106
+ fetchs.a = { startTime, onEnd: [] };
107
+ const prevFetchStartTime = lastFetchStartTime;
108
+ lastFetchStartTime = startTime;
109
+ function shouldAbort() {
110
+ const abort = id !== lastFetchIdStarted || mutationIsInProgress || id <= abortFetchsBeforeOrEqual;
111
+ lastFetchWasAborted = abort;
112
+ return abort;
113
+ }
114
+ const success = await fetchFn(
115
+ {
116
+ shouldAbort,
117
+ getStartTime: () => startTime
118
+ },
119
+ params
120
+ );
121
+ const currentFetchs = getFetchs();
122
+ if (!currentFetchs.a) {
123
+ lastFetchStartTime = prevFetchStartTime;
124
+ return false;
125
+ }
126
+ if (success) {
127
+ lastFetchDuration = Date.now() - startTime;
128
+ }
129
+ if (currentFetchs.b) {
130
+ clearTimeout(currentFetchs.b.timeoutId);
131
+ fetchs.b = null;
132
+ }
133
+ const onEnd = currentFetchs.a.onEnd;
134
+ currentFetchs.a = null;
135
+ if (onEnd.length > 0) {
136
+ onEnd.forEach((cb) => cb());
137
+ }
138
+ flushScheduledFetch();
139
+ return true;
140
+ }
141
+ function scheduleFetch(fetchType, params) {
142
+ const startTime = Date.now();
143
+ if (dynamicRealtimeThrottleMs && fetchType === "realtimeUpdate") {
144
+ if (scheduleRTU(startTime, params)) {
145
+ return "rt-scheduled";
146
+ }
147
+ }
148
+ if (shouldSkipFetch(fetchType, startTime)) {
149
+ return "skipped";
150
+ }
151
+ if (shouldScheduleFetch(fetchType, params)) {
152
+ return "scheduled";
153
+ }
154
+ startFetch(params, startTime);
155
+ return "started";
156
+ }
157
+ function shouldSkipFetch(fetchType, startTime) {
158
+ if (fetchType === "highPriority") {
159
+ if (fetchs.a) {
160
+ const timeSinceLastFetch = startTime - fetchs.a.startTime;
161
+ if (timeSinceLastFetch < mediumPriorityThrottleMs) {
162
+ return true;
163
+ }
164
+ }
165
+ }
166
+ if (fetchType === "lowPriority") {
167
+ if (fetchs.a || fetchs.c || mutationIsInProgress) {
168
+ return true;
169
+ }
170
+ if (lastFetchStartTime) {
171
+ const timeSinceLastFetch = startTime - lastFetchStartTime;
172
+ if (timeSinceLastFetch < lowPriorityThrottleMs) {
173
+ return true;
174
+ }
175
+ }
176
+ }
177
+ return false;
178
+ }
179
+ function shouldScheduleFetch(priority, params) {
180
+ const shouldSchedule = (() => {
181
+ if (priority === "lowPriority") {
182
+ return false;
183
+ }
184
+ return !!fetchs.a || !!mutationIsInProgress;
185
+ })();
186
+ if (shouldSchedule) {
187
+ fetchs.c = { params };
188
+ }
189
+ return shouldSchedule;
190
+ }
191
+ function addDelayedRTU(startTime, params) {
192
+ if (!dynamicRealtimeThrottleMs)
193
+ return false;
194
+ const timeSinceLastFetch = startTime - (lastFetchStartTime + lastFetchDuration);
195
+ const minimumRealtimeInterval = dynamicRealtimeThrottleMs(lastFetchDuration);
196
+ if (timeSinceLastFetch >= minimumRealtimeInterval)
197
+ return false;
198
+ const delay = minimumRealtimeInterval - timeSinceLastFetch;
199
+ fetchs.b = {
200
+ timeoutId: window.setTimeout(() => {
201
+ fetchs.b = null;
202
+ on?.("scheduled-rt-fetch-started");
203
+ startFetch(params, Date.now());
204
+ }, delay)
205
+ };
206
+ return true;
207
+ }
208
+ function scheduleRTU(startTime, params) {
209
+ if (!lastFetchDuration || !lastFetchStartTime || !dynamicRealtimeThrottleMs) {
210
+ return false;
211
+ }
212
+ if (fetchs.b) {
213
+ return true;
214
+ }
215
+ if (fetchs.a) {
216
+ fetchs.a.onEnd.push(() => {
217
+ addDelayedRTU(Date.now(), params);
218
+ });
219
+ return true;
220
+ } else if (mutationIsInProgress) {
221
+ onMutationEnd.push(() => {
222
+ const added = addDelayedRTU(Date.now(), params);
223
+ if (!added) {
224
+ on?.("scheduled-rt-fetch-started");
225
+ scheduleFetch("highPriority", params);
226
+ }
227
+ });
228
+ return true;
229
+ } else {
230
+ if (!addDelayedRTU(startTime, params)) {
231
+ return false;
232
+ }
233
+ }
234
+ return true;
235
+ }
236
+ function addOnFetchEnd(cb) {
237
+ if (fetchs.a) {
238
+ fetchs.a.onEnd.push(cb);
239
+ }
240
+ }
241
+ async function awaitFetch(params) {
242
+ scheduleFetch("highPriority", params);
243
+ if (fetchs.a) {
244
+ await new Promise((resolve) => {
245
+ addOnFetchEnd(() => resolve(true));
246
+ });
247
+ }
248
+ return lastFetchWasAborted;
249
+ }
250
+ return {
251
+ scheduleFetch,
252
+ awaitFetch,
253
+ startMutation,
254
+ get hasPendingFetch() {
255
+ return !!fetchs.a || !!fetchs.c || !!fetchs.b;
256
+ },
257
+ get fetchIsInProgress() {
258
+ return !!fetchs.a;
259
+ },
260
+ get mutationIsInProgress() {
261
+ return mutationIsInProgress;
262
+ },
263
+ setLastFetchDurantion,
264
+ setLastFetchStartTime
265
+ };
266
+ }
267
+ var autoIncrementId = 0;
268
+ function getAutoIncrementId() {
269
+ return ++autoIncrementId;
270
+ }
271
+
272
+ // src/useEnsureIsLoaded.ts
273
+ var import_mitt = __toESM(require("mitt"), 1);
274
+ var import_react2 = require("react");
275
+
276
+ // src/utils/hooks.ts
277
+ var import_react = require("react");
278
+ var import_t_state = require("t-state");
279
+ function useDeepCompareMemoize(value, equalityFn = import_t_state.deepEqual) {
280
+ const ref = (0, import_react.useRef)();
281
+ const signalRef = (0, import_react.useRef)(0);
282
+ if (!equalityFn(value, ref.current)) {
283
+ ref.current = value;
284
+ signalRef.current += 1;
285
+ }
286
+ return [signalRef.current];
287
+ }
288
+ function useDeepMemo(callback, deeps) {
289
+ return (0, import_react.useMemo)(callback, useDeepCompareMemoize(deeps));
290
+ }
291
+ function useLatestValue(value) {
292
+ const ref = (0, import_react.useRef)({ insideEffect: value, insideMemo: value });
293
+ ref.current.insideMemo = value;
294
+ (0, import_react.useLayoutEffect)(() => {
295
+ ref.current.insideEffect = value;
296
+ });
297
+ return ref.current;
298
+ }
299
+ function useOnMittEvent(mitt5, event, callback) {
300
+ const latestCallback = useLatestValue(callback);
301
+ (0, import_react.useLayoutEffect)(() => {
302
+ const cb = (payload) => {
303
+ latestCallback.insideEffect(payload);
304
+ };
305
+ mitt5.on(event, cb);
306
+ return () => {
307
+ mitt5.off(event, cb);
308
+ };
309
+ }, [mitt5, event, latestCallback]);
310
+ }
311
+ function usePrevious(value, initial) {
312
+ const ref = (0, import_react.useRef)(initial);
313
+ (0, import_react.useEffect)(() => {
314
+ ref.current = value;
315
+ });
316
+ return ref.current;
317
+ }
318
+ function useOnChange(value, callBack, {
319
+ equalityFn: areEqual = import_t_state.shallowEqual,
320
+ callOnMount,
321
+ layoutEffect
322
+ } = {}) {
323
+ const useEffectFn = layoutEffect ? import_react.useLayoutEffect : import_react.useEffect;
324
+ const prev = usePrevious(value, !callOnMount ? value : void 0);
325
+ useEffectFn(() => {
326
+ if (!areEqual(value, prev)) {
327
+ return callBack({ prev, current: value });
328
+ }
329
+ });
330
+ }
331
+ function useConst(getValue) {
332
+ const store = (0, import_react.useRef)();
333
+ if (store.current === void 0) {
334
+ store.current = getValue();
335
+ }
336
+ return store.current;
337
+ }
338
+
339
+ // src/useEnsureIsLoaded.ts
340
+ function useEnsureIsLoaded(ensureIsLoaded, enabled, forceFetch) {
341
+ const isLoadedEvtEmitter = useConst(() => (0, import_mitt.default)());
342
+ const [isForceLoading, setIsForceLoading] = (0, import_react2.useState)(true);
343
+ useOnChange(
344
+ ensureIsLoaded && isForceLoading && enabled,
345
+ ({ current }) => {
346
+ if (current) {
347
+ forceFetch();
348
+ }
349
+ },
350
+ { callOnMount: true }
351
+ );
352
+ useOnMittEvent(isLoadedEvtEmitter, "isLoaded", (isLoaded) => {
353
+ if (ensureIsLoaded && enabled && isLoaded) {
354
+ setIsForceLoading(false);
355
+ }
356
+ });
357
+ function useModifyResult(result) {
358
+ return (0, import_react2.useMemo)(() => {
359
+ if (ensureIsLoaded) {
360
+ const newStatus = enabled && isForceLoading ? "loading" : result.status;
361
+ return {
362
+ ...result,
363
+ isLoading: newStatus === "loading",
364
+ status: newStatus
365
+ };
366
+ }
367
+ return result;
368
+ }, [ensureIsLoaded, isForceLoading, result]);
369
+ }
370
+ return [useModifyResult, isLoadedEvtEmitter.emit];
371
+ }
372
+
373
+ // src/utils/reuseRefIfEqual.ts
374
+ var import_t_state2 = require("t-state");
375
+ function reusePrevIfEqual({
376
+ prev,
377
+ current,
378
+ d: equalityFn_ = import_t_state2.deepEqual
379
+ }) {
380
+ if (prev === void 0)
381
+ return current;
382
+ if (equalityFn_(prev, current)) {
383
+ return prev;
384
+ }
385
+ return current;
386
+ }
387
+
388
+ // src/documentStore.ts
389
+ function newTSDFDocumentStore({
390
+ debugName,
391
+ fetchFn,
392
+ initialData,
393
+ disableRefetchOnWindowFocus,
394
+ disableRefetchOnMount: globalDisableRefetchOnMount,
395
+ lowPriorityThrottleMs,
396
+ mediumPriorityThrottleMs,
397
+ dynamicRealtimeThrottleMs,
398
+ disableInitialDataInvalidation,
399
+ errorNormalizer
400
+ }) {
401
+ const store = new import_t_state3.Store({
402
+ debugName,
403
+ state: {
404
+ data: initialData ?? null,
405
+ error: null,
406
+ status: initialData ? "success" : "idle",
407
+ refetchOnMount: !!initialData && !disableInitialDataInvalidation ? "lowPriority" : false
408
+ }
409
+ });
410
+ async function fetch(fetchCtx, _) {
411
+ store.setPartialState(
412
+ {
413
+ status: store.state.status === "success" ? "refetching" : "loading",
414
+ error: null,
415
+ refetchOnMount: false
416
+ },
417
+ {
418
+ action: store.state.status === "success" ? "fetch-start-refetching" : "fetch-start-loading"
419
+ }
420
+ );
421
+ try {
422
+ const data = await fetchFn();
423
+ if (fetchCtx.shouldAbort())
424
+ return false;
425
+ store.setPartialState(
426
+ {
427
+ data: reusePrevIfEqual({ prev: store.state.data, current: data }),
428
+ status: "success"
429
+ },
430
+ { action: "fetch-success" }
431
+ );
432
+ return true;
433
+ } catch (exception) {
434
+ if (fetchCtx.shouldAbort())
435
+ return false;
436
+ store.setPartialState(
437
+ {
438
+ error: errorNormalizer(exception),
439
+ status: "error"
440
+ },
441
+ { action: "fetch-error" }
442
+ );
443
+ return false;
444
+ }
445
+ }
446
+ const fetchOrquestrator = createFetchOrquestrator({
447
+ fetchFn: fetch,
448
+ lowPriorityThrottleMs,
449
+ dynamicRealtimeThrottleMs,
450
+ mediumPriorityThrottleMs
451
+ });
452
+ function scheduleFetch(fetchType) {
453
+ return fetchOrquestrator.scheduleFetch(fetchType, null);
454
+ }
455
+ async function awaitFetch() {
456
+ const wasAborted = await fetchOrquestrator.awaitFetch(null);
457
+ if (wasAborted) {
458
+ return { data: null, error: errorNormalizer(new Error("Aborted")) };
459
+ }
460
+ if (!store.state.data) {
461
+ return { data: null, error: errorNormalizer(new Error("No data")) };
462
+ }
463
+ return store.state.error ? { data: null, error: store.state.error } : { data: store.state.data, error: null };
464
+ }
465
+ const storeEvents = (0, import_mitt2.default)();
466
+ let invalidationWasTriggered = false;
467
+ function invalidateData(priority = "highPriority") {
468
+ store.setKey("refetchOnMount", priority, { action: "invalidate-data" });
469
+ invalidationWasTriggered = false;
470
+ storeEvents.emit("invalidateData", priority);
471
+ }
472
+ function useDocument({
473
+ selector,
474
+ disabled,
475
+ returnRefetchingStatus,
476
+ disableRefetchOnMount = globalDisableRefetchOnMount,
477
+ returnIdleStatus = !!disabled,
478
+ ensureIsLoaded
479
+ } = {}) {
480
+ const storeStateSelector = (0, import_react3.useCallback)(
481
+ (state) => {
482
+ const { error } = state;
483
+ const data = selector ? selector(state.data) : state.data;
484
+ let status = state.status;
485
+ if (!returnIdleStatus && status === "idle") {
486
+ status = "loading";
487
+ }
488
+ if (!returnRefetchingStatus && status === "refetching") {
489
+ status = "success";
490
+ }
491
+ return {
492
+ data,
493
+ error,
494
+ status,
495
+ isLoading: status === "loading"
496
+ };
497
+ },
498
+ [returnRefetchingStatus, returnIdleStatus, selector]
499
+ );
500
+ const storeState = store.useSelector(storeStateSelector, {
501
+ useExternalDeps: true
502
+ });
503
+ useOnMittEvent(storeEvents, "invalidateData", (priority) => {
504
+ if (!invalidationWasTriggered) {
505
+ scheduleFetch(priority);
506
+ invalidationWasTriggered = true;
507
+ }
508
+ });
509
+ (0, import_react3.useEffect)(() => {
510
+ if (disabled)
511
+ return;
512
+ if (disableRefetchOnMount) {
513
+ const shouldFetch = store.state.refetchOnMount || store.state.status === "idle";
514
+ if (shouldFetch) {
515
+ scheduleFetch(store.state.refetchOnMount || "lowPriority");
516
+ }
517
+ } else {
518
+ scheduleFetch("lowPriority");
519
+ }
520
+ }, [disableRefetchOnMount, disabled]);
521
+ const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
522
+ ensureIsLoaded,
523
+ !disabled,
524
+ () => {
525
+ scheduleFetch("highPriority");
526
+ }
527
+ );
528
+ (0, import_t_state3.useSubscribeToStore)(store, ({ observe }) => {
529
+ observe.ifSelector((state) => state.status).change.then(({ current }) => {
530
+ if (current === "success" || current === "error") {
531
+ emitIsLoadedEvt("isLoaded", true);
532
+ }
533
+ });
534
+ });
535
+ return useModifyResult(storeState);
536
+ }
537
+ function updateState(produceNewData) {
538
+ store.setKey(
539
+ "data",
540
+ (current) => {
541
+ if (!current)
542
+ return current;
543
+ return (0, import_immer.produce)(current, produceNewData);
544
+ },
545
+ { action: "update-state" }
546
+ );
547
+ }
548
+ if (!disableRefetchOnWindowFocus) {
549
+ let handleFocus2 = function() {
550
+ invalidateData("lowPriority");
551
+ };
552
+ var handleFocus = handleFocus2;
553
+ window.addEventListener("focus", handleFocus2);
554
+ window.addEventListener("visibilitychange", handleFocus2);
555
+ }
556
+ return {
557
+ store,
558
+ awaitFetch,
559
+ scheduleFetch,
560
+ invalidateData,
561
+ useDocument,
562
+ updateState,
563
+ startMutation: fetchOrquestrator.startMutation
564
+ };
565
+ }
566
+
567
+ // src/collectionStore.ts
568
+ var import_mitt3 = __toESM(require("mitt"), 1);
569
+ var import_react4 = require("react");
570
+ var import_t_state4 = require("t-state");
571
+
572
+ // src/collectionFetchOrquestrator.ts
573
+ function createCollectionFetchOrquestrator(props) {
574
+ const fetchOrquestrators = /* @__PURE__ */ new Map();
575
+ function getFetchOrquestrator(key) {
576
+ if (!fetchOrquestrators.has(key)) {
577
+ fetchOrquestrators.set(key, createFetchOrquestrator(props));
578
+ }
579
+ return fetchOrquestrators.get(key);
580
+ }
581
+ return {
582
+ get: getFetchOrquestrator
583
+ };
584
+ }
585
+
586
+ // src/utils/filterAndMap.ts
587
+ var ignore = Symbol();
588
+ function filterAndMap(arr, fn) {
589
+ const result = [];
590
+ let i = 0;
591
+ for (const item of arr) {
592
+ const mappedItem = fn(item, ignore, i);
593
+ if (mappedItem !== ignore) {
594
+ result.push(mappedItem);
595
+ }
596
+ i++;
597
+ }
598
+ return result;
599
+ }
600
+
601
+ // src/utils/isObject.ts
602
+ function isObject(value) {
603
+ return typeof value === "object" && value !== null && !Array.isArray(value);
604
+ }
605
+
606
+ // src/utils/getCacheId.ts
607
+ function getCacheId(input) {
608
+ return typeof input === "string" || typeof input === "number" ? String(input) : JSON.stringify(input && isObject(input) ? orderedProps(input) : input);
609
+ }
610
+ function orderedProps(obj) {
611
+ return filterAndMap(Object.keys(obj).sort(), (k, ignore2) => {
612
+ const value = obj[k];
613
+ if (value === void 0)
614
+ return ignore2;
615
+ return { [k]: obj[k] };
616
+ });
617
+ }
618
+
619
+ // src/collectionStore.ts
620
+ var import_json = require("klona/json");
621
+ function newTSDFCollectionStore({
622
+ debugName,
623
+ fetchFn,
624
+ disableRefetchOnWindowFocus,
625
+ lowPriorityThrottleMs,
626
+ errorNormalizer,
627
+ disableInitialDataInvalidation,
628
+ mediumPriorityThrottleMs,
629
+ initialStateItems,
630
+ disableRefetchOnMount: globalDisableRefetchOnMount,
631
+ dynamicRealtimeThrottleMs,
632
+ getCollectionItemKey: filterCollectionItemObjKey
633
+ }) {
634
+ const initialState = {};
635
+ if (initialStateItems) {
636
+ for (const item of initialStateItems) {
637
+ const itemKey = getItemKey(item.payload);
638
+ initialState[itemKey] = {
639
+ data: item.data,
640
+ error: null,
641
+ status: "success",
642
+ payload: item.payload,
643
+ refetchOnMount: disableInitialDataInvalidation ? false : "lowPriority",
644
+ wasLoaded: true
645
+ };
646
+ }
647
+ }
648
+ const store = new import_t_state4.Store({
649
+ debugName,
650
+ state: initialState
651
+ });
652
+ function getItemKey(params) {
653
+ return getCacheId(
654
+ filterCollectionItemObjKey ? filterCollectionItemObjKey(params) : params
655
+ );
656
+ }
657
+ async function fetch(fetchCtx, itemPayload) {
658
+ const itemId = getItemKey(itemPayload);
659
+ const payload = (0, import_json.klona)(itemPayload);
660
+ const itemState = store.state[itemId];
661
+ store.produceState(
662
+ (draft) => {
663
+ const item = draft[itemId];
664
+ if (!item) {
665
+ draft[itemId] = {
666
+ data: null,
667
+ error: null,
668
+ status: "loading",
669
+ payload,
670
+ refetchOnMount: false,
671
+ wasLoaded: false
672
+ };
673
+ return;
674
+ }
675
+ item.status = item.data !== null ? "refetching" : "loading";
676
+ item.payload = payload;
677
+ item.error = null;
678
+ item.refetchOnMount = false;
679
+ },
680
+ {
681
+ equalityCheck: import_t_state4.deepEqual,
682
+ action: {
683
+ type: !itemState?.data ? "fetch-start-loading" : "fetch-start-refetching",
684
+ payload
685
+ }
686
+ }
687
+ );
688
+ try {
689
+ const data = await fetchFn(payload);
690
+ if (fetchCtx.shouldAbort())
691
+ return false;
692
+ store.produceState(
693
+ (draft) => {
694
+ const item = draft[itemId];
695
+ if (!item)
696
+ return;
697
+ item.data = reusePrevIfEqual({ current: data, prev: item.data });
698
+ item.status = "success";
699
+ item.wasLoaded = true;
700
+ },
701
+ { action: { type: "fetch-success", payload } }
702
+ );
703
+ return true;
704
+ } catch (exception) {
705
+ if (fetchCtx.shouldAbort())
706
+ return false;
707
+ const error = errorNormalizer(exception);
708
+ store.produceState(
709
+ (draft) => {
710
+ const item = draft[itemId];
711
+ if (!item)
712
+ return;
713
+ item.error = error;
714
+ item.status = "error";
715
+ },
716
+ { action: { type: "fetch-error", payload, error } }
717
+ );
718
+ return false;
719
+ }
720
+ }
721
+ const fetchOrquestrator = createCollectionFetchOrquestrator({
722
+ fetchFn: fetch,
723
+ lowPriorityThrottleMs,
724
+ dynamicRealtimeThrottleMs,
725
+ mediumPriorityThrottleMs
726
+ });
727
+ function scheduleFetch(fetchType, payload) {
728
+ const multiplePayloads = Array.isArray(payload);
729
+ const payloads = multiplePayloads ? payload : [payload];
730
+ const results = [];
731
+ for (const param of payloads) {
732
+ const itemKey = getItemKey(param);
733
+ results.push(
734
+ fetchOrquestrator.get(itemKey).scheduleFetch(fetchType, param)
735
+ );
736
+ }
737
+ return multiplePayloads ? results : results[0];
738
+ }
739
+ async function awaitFetch(params) {
740
+ const itemId = getItemKey(params);
741
+ const wasAborted = await fetchOrquestrator.get(itemId).awaitFetch(params);
742
+ if (wasAborted) {
743
+ return { data: null, error: errorNormalizer(new Error("Aborted")) };
744
+ }
745
+ const item = store.state[itemId];
746
+ if (!item?.data) {
747
+ return { data: null, error: errorNormalizer(new Error("Not found")) };
748
+ }
749
+ return item.error ? { data: null, error: item.error } : { data: item.data, error: null };
750
+ }
751
+ function getItemsKeyArray(params) {
752
+ const items = store.state;
753
+ if (Array.isArray(params)) {
754
+ return params.map(getItemKey);
755
+ } else if (typeof params === "function") {
756
+ return filterAndMap(Object.entries(items), ([itemKey, item], ignore2) => {
757
+ return item && params(item.payload, item.data) ? itemKey : ignore2;
758
+ });
759
+ } else {
760
+ return [getItemKey(params)];
761
+ }
762
+ }
763
+ const storeEvents = (0, import_mitt3.default)();
764
+ const invalidationWasTriggered = /* @__PURE__ */ new Set();
765
+ function invalidateItem(itemPayload, priority = "highPriority") {
766
+ const itemsKey = getItemsKeyArray(itemPayload);
767
+ for (const itemKey of itemsKey) {
768
+ store.produceState(
769
+ (draft) => {
770
+ const item = draft[itemKey];
771
+ if (!item)
772
+ return;
773
+ item.refetchOnMount = priority;
774
+ },
775
+ { action: { type: "invalidate-data", itemKey } }
776
+ );
777
+ invalidationWasTriggered.delete(itemKey);
778
+ storeEvents.emit("invalidateData", { priority, itemKey });
779
+ }
780
+ }
781
+ function getItemState(params) {
782
+ if (typeof params === "function" || Array.isArray(params)) {
783
+ const itemsId = getItemsKeyArray(params);
784
+ return filterAndMap(itemsId, (itemId, ignore2) => {
785
+ return store.state[itemId] || ignore2;
786
+ });
787
+ }
788
+ return store.state[getItemKey(params)];
789
+ }
790
+ function useMultipleItems(queries, {
791
+ selector,
792
+ omitPayload,
793
+ returnIdleStatus,
794
+ returnRefetchingStatus,
795
+ disableRefetchOnMount = globalDisableRefetchOnMount
796
+ } = {}) {
797
+ const queriesWithId = useDeepMemo(() => {
798
+ return queries.map((payload) => {
799
+ return { itemKey: getItemKey(payload), payload };
800
+ });
801
+ }, [queries]);
802
+ const dataSelector = (0, import_react4.useCallback)((itemState) => {
803
+ if (selector)
804
+ return selector(itemState);
805
+ return itemState;
806
+ }, []);
807
+ const resultSelector = (0, import_react4.useCallback)(
808
+ (state) => {
809
+ return queriesWithId.map(
810
+ ({
811
+ itemKey,
812
+ payload
813
+ }) => {
814
+ const item = state[itemKey];
815
+ if (item === null) {
816
+ return {
817
+ itemStateKey: itemKey,
818
+ status: "deleted",
819
+ data: dataSelector(null),
820
+ error: null,
821
+ payload: omitPayload ? void 0 : payload,
822
+ isLoading: false
823
+ };
824
+ }
825
+ if (!item) {
826
+ return {
827
+ itemStateKey: itemKey,
828
+ status: returnIdleStatus ? "idle" : "loading",
829
+ data: dataSelector(null),
830
+ error: null,
831
+ payload: omitPayload ? void 0 : payload,
832
+ isLoading: returnIdleStatus ? false : true
833
+ };
834
+ }
835
+ let status = item.status;
836
+ if (!returnRefetchingStatus && item.status === "refetching") {
837
+ status = "success";
838
+ }
839
+ return {
840
+ itemStateKey: itemKey,
841
+ status,
842
+ data: dataSelector(item.data),
843
+ error: item.error,
844
+ isLoading: status === "loading",
845
+ payload: omitPayload ? void 0 : item.payload
846
+ };
847
+ }
848
+ );
849
+ },
850
+ [
851
+ dataSelector,
852
+ omitPayload,
853
+ queriesWithId,
854
+ returnIdleStatus,
855
+ returnRefetchingStatus
856
+ ]
857
+ );
858
+ const storeState = store.useSelector(resultSelector, {
859
+ equalityFn: import_t_state4.deepEqual,
860
+ useExternalDeps: true
861
+ });
862
+ useOnMittEvent(storeEvents, "invalidateData", (event) => {
863
+ for (const { itemKey, payload } of queriesWithId) {
864
+ if (itemKey !== event.itemKey)
865
+ continue;
866
+ if (!invalidationWasTriggered.has(itemKey)) {
867
+ scheduleFetch(event.priority, payload);
868
+ invalidationWasTriggered.add(itemKey);
869
+ }
870
+ }
871
+ });
872
+ (0, import_react4.useEffect)(() => {
873
+ for (const { itemKey: itemId, payload } of queriesWithId) {
874
+ if (itemId) {
875
+ if (disableRefetchOnMount) {
876
+ const itemState = getItemState(payload);
877
+ const shouldFetch = !itemState?.wasLoaded || itemState.refetchOnMount;
878
+ if (shouldFetch) {
879
+ scheduleFetch(
880
+ itemState?.refetchOnMount || "lowPriority",
881
+ payload
882
+ );
883
+ return;
884
+ }
885
+ } else {
886
+ scheduleFetch("lowPriority", payload);
887
+ }
888
+ }
889
+ }
890
+ }, [disableRefetchOnMount, queriesWithId]);
891
+ return storeState;
892
+ }
893
+ function useItem(payload, options = {}) {
894
+ const { selector, ensureIsLoaded } = options;
895
+ const query = (0, import_react4.useMemo)(
896
+ () => payload === false || payload === null || payload === void 0 ? [] : [payload],
897
+ [payload]
898
+ );
899
+ const item = useMultipleItems(query, options);
900
+ const result = (0, import_react4.useMemo)(
901
+ () => item[0] ?? {
902
+ payload: void 0,
903
+ data: selector ? selector(null) : null,
904
+ error: null,
905
+ status: "idle",
906
+ itemStateKey: "",
907
+ isLoading: false
908
+ },
909
+ [item]
910
+ );
911
+ const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
912
+ ensureIsLoaded,
913
+ !!payload,
914
+ () => {
915
+ if (payload) {
916
+ scheduleFetch("highPriority", payload);
917
+ }
918
+ }
919
+ );
920
+ (0, import_t_state4.useSubscribeToStore)(store, ({ observe }) => {
921
+ if (!ensureIsLoaded)
922
+ return;
923
+ observe.ifSelector((state) => state[result.itemStateKey]?.status).change.then(({ current }) => {
924
+ if (current === "success" || current === "error") {
925
+ emitIsLoadedEvt("isLoaded", true);
926
+ }
927
+ });
928
+ });
929
+ return useModifyResult(result);
930
+ }
931
+ function startMutation(fetchParams) {
932
+ const itemKeys = getItemsKeyArray(fetchParams);
933
+ const endMutations = [];
934
+ for (const itemKey of itemKeys) {
935
+ endMutations.push(fetchOrquestrator.get(itemKey).startMutation());
936
+ }
937
+ return () => {
938
+ for (const endMutation of endMutations) {
939
+ endMutation();
940
+ }
941
+ };
942
+ }
943
+ function addItemToState(fetchParams, data) {
944
+ const itemKey = getItemKey(fetchParams);
945
+ store.produceState(
946
+ (draftState) => {
947
+ draftState[itemKey] = {
948
+ data,
949
+ status: "success",
950
+ wasLoaded: true,
951
+ refetchOnMount: false,
952
+ error: null,
953
+ payload: (0, import_json.klona)(fetchParams)
954
+ };
955
+ },
956
+ { action: { type: "create-item-state", payload: fetchParams } }
957
+ );
958
+ }
959
+ function deleteItemState(fetchParams) {
960
+ const itemKeys = getItemsKeyArray(fetchParams);
961
+ store.produceState(
962
+ (draftState) => {
963
+ for (const itemKey of itemKeys) {
964
+ draftState[itemKey] = null;
965
+ }
966
+ },
967
+ { action: { type: "delete-item-state", payload: fetchParams } }
968
+ );
969
+ }
970
+ function updateItemState(fetchParams, produceNewData, ifNothingWasUpdated) {
971
+ const itemKeys = getItemsKeyArray(fetchParams);
972
+ let someItemWasUpdated = false;
973
+ store.batch(
974
+ () => {
975
+ store.produceState((draftState) => {
976
+ for (const itemKey of itemKeys) {
977
+ const item = draftState[itemKey];
978
+ if (!item)
979
+ continue;
980
+ if (item.data) {
981
+ someItemWasUpdated = true;
982
+ const newData = produceNewData(item.data, item);
983
+ if (newData) {
984
+ item.data = newData;
985
+ }
986
+ }
987
+ }
988
+ });
989
+ if (ifNothingWasUpdated && !someItemWasUpdated) {
990
+ ifNothingWasUpdated();
991
+ }
992
+ },
993
+ { type: "update-item-state", item: itemKeys }
994
+ );
995
+ return someItemWasUpdated;
996
+ }
997
+ if (!disableRefetchOnWindowFocus) {
998
+ let handleFocus2 = function() {
999
+ invalidateItem(() => true, "lowPriority");
1000
+ };
1001
+ var handleFocus = handleFocus2;
1002
+ window.addEventListener("focus", handleFocus2);
1003
+ window.addEventListener("visibilitychange", handleFocus2);
1004
+ }
1005
+ return {
1006
+ store,
1007
+ scheduleFetch,
1008
+ awaitFetch,
1009
+ useMultipleItems,
1010
+ useItem,
1011
+ getItemKey,
1012
+ getItemState,
1013
+ startMutation,
1014
+ invalidateItem,
1015
+ updateItemState,
1016
+ addItemToState,
1017
+ deleteItemState
1018
+ };
1019
+ }
1020
+
1021
+ // src/listQueryStore.ts
1022
+ var import_mitt4 = __toESM(require("mitt"), 1);
1023
+ var import_react5 = require("react");
1024
+ var import_t_state5 = require("t-state");
1025
+ var import_json2 = require("klona/json");
1026
+ var noFetchFnError = "No fetchItemFn was provided";
1027
+ function newTSDFListQueryStore({
1028
+ debugName,
1029
+ fetchListFn,
1030
+ fetchItemFn,
1031
+ errorNormalizer,
1032
+ defaultQuerySize = 50,
1033
+ initialData,
1034
+ disableRefetchOnWindowFocus,
1035
+ disableRefetchOnMount: globalDisableRefetchOnMount,
1036
+ lowPriorityThrottleMs,
1037
+ disableInitialDataInvalidation,
1038
+ mediumPriorityThrottleMs,
1039
+ dynamicRealtimeThrottleMs,
1040
+ syncMutationsAndInvalidations
1041
+ }) {
1042
+ const initialState = { items: {}, queries: {}, itemQueries: {} };
1043
+ if (initialData) {
1044
+ for (const { payload, data } of initialData.items) {
1045
+ const itemKey = getItemKey(payload);
1046
+ initialState.items[itemKey] = data;
1047
+ initialState.itemQueries[itemKey] = {
1048
+ error: null,
1049
+ status: "success",
1050
+ refetchOnMount: disableInitialDataInvalidation ? false : "lowPriority",
1051
+ wasLoaded: true,
1052
+ payload
1053
+ };
1054
+ }
1055
+ for (const { payload, items, hasMore } of initialData.queries) {
1056
+ const queryKey = getQueryKey(payload);
1057
+ initialState.queries[queryKey] = {
1058
+ error: null,
1059
+ status: "success",
1060
+ refetchOnMount: disableInitialDataInvalidation ? false : "lowPriority",
1061
+ wasLoaded: true,
1062
+ payload,
1063
+ items: items.map(getItemKey),
1064
+ hasMore
1065
+ };
1066
+ }
1067
+ }
1068
+ const store = new import_t_state5.Store({
1069
+ debugName,
1070
+ state: initialState
1071
+ });
1072
+ function getQueryKey(params) {
1073
+ return getCacheId(params);
1074
+ }
1075
+ function getItemKey(params) {
1076
+ return getCacheId(params);
1077
+ }
1078
+ async function fetchQuery(fetchCtx, [fetchType, queryPayload, size = defaultQuerySize]) {
1079
+ const payload = (0, import_json2.klona)(queryPayload);
1080
+ const queryKey = getQueryKey(payload);
1081
+ const queryState = store.state.queries[queryKey];
1082
+ const isLoading = !queryState?.wasLoaded;
1083
+ store.produceState(
1084
+ (draft) => {
1085
+ const query = draft.queries[queryKey];
1086
+ if (!query) {
1087
+ draft.queries[queryKey] = {
1088
+ error: null,
1089
+ status: "loading",
1090
+ wasLoaded: false,
1091
+ payload,
1092
+ refetchOnMount: false,
1093
+ hasMore: false,
1094
+ items: []
1095
+ };
1096
+ return;
1097
+ }
1098
+ query.status = query.wasLoaded ? fetchType === "loadMore" ? "loadingMore" : "refetching" : "loading";
1099
+ query.error = null;
1100
+ query.refetchOnMount = false;
1101
+ },
1102
+ {
1103
+ equalityCheck: import_t_state5.deepEqual,
1104
+ action: {
1105
+ type: isLoading ? "fetch-query-start-loading" : fetchType === "loadMore" ? "fetch-query-loading-more" : "refetching-query-start",
1106
+ payload
1107
+ }
1108
+ }
1109
+ );
1110
+ const currentQuerySize = queryState?.items.length ?? 0;
1111
+ const querySize = (() => {
1112
+ if (fetchType === "loadMore") {
1113
+ return currentQuerySize + size;
1114
+ }
1115
+ if (isLoading)
1116
+ return size;
1117
+ return Math.max(currentQuerySize, size);
1118
+ })();
1119
+ try {
1120
+ const { items, hasMore } = await fetchListFn(payload, querySize);
1121
+ if (fetchCtx.shouldAbort())
1122
+ return false;
1123
+ store.produceState(
1124
+ (draft) => {
1125
+ const query = draft.queries[queryKey];
1126
+ if (!query)
1127
+ return;
1128
+ query.status = "success";
1129
+ query.wasLoaded = true;
1130
+ query.hasMore = hasMore;
1131
+ query.items = [];
1132
+ for (const { data, itemPayload } of items) {
1133
+ const itemKey = getItemKey(itemPayload);
1134
+ draft.items[itemKey] = reusePrevIfEqual({
1135
+ current: data,
1136
+ prev: draft.items[itemKey] ?? void 0
1137
+ });
1138
+ query.items.push(String(itemKey));
1139
+ const itemQuery = draft.itemQueries[itemKey];
1140
+ if (!itemQuery || itemQuery.status !== "loading" && itemQuery.status !== "refetching") {
1141
+ draft.itemQueries[itemKey] = {
1142
+ error: null,
1143
+ refetchOnMount: false,
1144
+ status: "success",
1145
+ wasLoaded: true,
1146
+ payload: itemPayload
1147
+ };
1148
+ }
1149
+ }
1150
+ },
1151
+ {
1152
+ action: { type: "fetch-query-success", payload }
1153
+ }
1154
+ );
1155
+ for (const { itemPayload: id } of items) {
1156
+ const itemFetchOrquestrator = fetchItemOrquestrator?.get(String(id));
1157
+ if (itemFetchOrquestrator) {
1158
+ itemFetchOrquestrator.setLastFetchStartTime(fetchCtx.getStartTime());
1159
+ }
1160
+ }
1161
+ return true;
1162
+ } catch (exception) {
1163
+ if (fetchCtx.shouldAbort())
1164
+ return false;
1165
+ const error = errorNormalizer(exception);
1166
+ store.produceState(
1167
+ (draft) => {
1168
+ const query = draft.queries[queryKey];
1169
+ if (!query)
1170
+ return;
1171
+ query.status = "error";
1172
+ query.error = error;
1173
+ },
1174
+ {
1175
+ action: { type: "fetch-query-error", payload, error }
1176
+ }
1177
+ );
1178
+ return false;
1179
+ }
1180
+ }
1181
+ function getQueryState(params) {
1182
+ return store.state.queries[getQueryKey(params)];
1183
+ }
1184
+ function getItemState(itemPayload) {
1185
+ if (typeof itemPayload === "function" || Array.isArray(itemPayload)) {
1186
+ const itemsId = getItemsKeyArray(itemPayload);
1187
+ return filterAndMap(itemsId, ({ itemKey }, ignore2) => {
1188
+ const item = store.state.items[itemKey];
1189
+ const payload = store.state.itemQueries[itemKey]?.payload;
1190
+ return !item || !payload ? ignore2 : { payload, data: item };
1191
+ });
1192
+ }
1193
+ return store.state.items[getItemKey(itemPayload)];
1194
+ }
1195
+ const fetchQueryOrquestrator = createCollectionFetchOrquestrator({
1196
+ fetchFn: fetchQuery,
1197
+ lowPriorityThrottleMs,
1198
+ dynamicRealtimeThrottleMs,
1199
+ mediumPriorityThrottleMs
1200
+ });
1201
+ function scheduleListQueryFetch(fetchType, payload, size) {
1202
+ const multiplePayloads = Array.isArray(payload);
1203
+ const payloads = multiplePayloads ? payload : [payload];
1204
+ const results = payloads.map((param) => {
1205
+ return fetchQueryOrquestrator.get(getQueryKey(param)).scheduleFetch(fetchType, ["load", param, size]);
1206
+ });
1207
+ return multiplePayloads ? results : results[0];
1208
+ }
1209
+ function loadMore(params, size) {
1210
+ const queryState = getQueryState(params);
1211
+ if (!queryState || !queryState.hasMore)
1212
+ return "skipped";
1213
+ return fetchQueryOrquestrator.get(getQueryKey(params)).scheduleFetch("highPriority", ["loadMore", params, size]);
1214
+ }
1215
+ function getQueryItems(query, itemDataSelector) {
1216
+ return filterAndMap(query.items, (itemKey, ignore2) => {
1217
+ const item = store.state.items[itemKey];
1218
+ return item ? itemDataSelector(item, itemKey) : ignore2;
1219
+ });
1220
+ }
1221
+ async function awaitListQueryFetch(params, size = defaultQuerySize) {
1222
+ const queryKey = getQueryKey(params);
1223
+ const wasAborted = await fetchQueryOrquestrator.get(queryKey).awaitFetch(["load", params, size]);
1224
+ if (wasAborted) {
1225
+ return {
1226
+ items: [],
1227
+ error: errorNormalizer(new Error("Aborted")),
1228
+ hasMore: false
1229
+ };
1230
+ }
1231
+ const query = store.state.queries[queryKey];
1232
+ if (!query) {
1233
+ return {
1234
+ items: [],
1235
+ error: errorNormalizer(new Error("Not found")),
1236
+ hasMore: false
1237
+ };
1238
+ }
1239
+ return query.error ? { items: [], error: query.error, hasMore: query.hasMore } : {
1240
+ items: getQueryItems(query, (data, itemKey) => ({ data, itemKey })),
1241
+ error: null,
1242
+ hasMore: query.hasMore
1243
+ };
1244
+ }
1245
+ async function awaitItemFetch(itemPayload) {
1246
+ if (!fetchItemOrquestrator)
1247
+ throw new Error(noFetchFnError);
1248
+ const itemKey = getItemKey(itemPayload);
1249
+ const wasAborted = await fetchItemOrquestrator.get(itemKey).awaitFetch(itemPayload);
1250
+ if (wasAborted) {
1251
+ return { data: null, error: errorNormalizer(new Error("Aborted")) };
1252
+ }
1253
+ const item = store.state.items[itemKey];
1254
+ const itemQuery = store.state.itemQueries[itemKey];
1255
+ if (!itemQuery || !item) {
1256
+ return { data: null, error: errorNormalizer(new Error("Not found")) };
1257
+ }
1258
+ return itemQuery.error ? { data: null, error: itemQuery.error } : { data: item, error: null };
1259
+ }
1260
+ function getQueriesKeyArray(payloads) {
1261
+ if (Array.isArray(payloads)) {
1262
+ return payloads.map((payload) => ({
1263
+ key: getQueryKey(payload),
1264
+ payload
1265
+ }));
1266
+ } else if (typeof payloads === "function") {
1267
+ return filterAndMap(
1268
+ Object.entries(store.state.queries),
1269
+ ([queryKey, query], ignore2) => {
1270
+ return payloads(query.payload, query, queryKey) ? {
1271
+ key: queryKey,
1272
+ payload: query.payload
1273
+ } : ignore2;
1274
+ }
1275
+ );
1276
+ } else {
1277
+ return [{ key: getQueryKey(payloads), payload: payloads }];
1278
+ }
1279
+ }
1280
+ const storeEvents = (0, import_mitt4.default)();
1281
+ const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
1282
+ function invalidateQuery(queryPayload, priority = "highPriority", ignoreInvalidationSync = false) {
1283
+ const queriesKey = getQueriesKeyArray(queryPayload);
1284
+ for (const { key } of queriesKey) {
1285
+ store.produceState(
1286
+ (draft) => {
1287
+ const query = draft.queries[key];
1288
+ if (!query)
1289
+ return;
1290
+ query.refetchOnMount = priority;
1291
+ },
1292
+ { action: { type: "invalidate-data", key } }
1293
+ );
1294
+ queryInvalidationWasTriggered.delete(key);
1295
+ storeEvents.emit("invalidateQuery", { priority, queryKey: key });
1296
+ }
1297
+ if (syncMutationsAndInvalidations && !ignoreInvalidationSync) {
1298
+ invalidateItem(
1299
+ (itemPayload) => queriesKey.some(({ payload }) => {
1300
+ return syncMutationsAndInvalidations.syncItemAndQuery(
1301
+ itemPayload,
1302
+ payload
1303
+ );
1304
+ }),
1305
+ priority,
1306
+ true
1307
+ );
1308
+ invalidateQuery(
1309
+ (queryToInvalidatePayload, _, queryToInvalidateKey) => queriesKey.some((alreadyInvalidatedQueryPayload) => {
1310
+ return queryToInvalidateKey !== alreadyInvalidatedQueryPayload.key && syncMutationsAndInvalidations.syncQueries(
1311
+ alreadyInvalidatedQueryPayload.payload,
1312
+ queryToInvalidatePayload
1313
+ );
1314
+ }),
1315
+ priority,
1316
+ true
1317
+ );
1318
+ }
1319
+ }
1320
+ function defaultItemSelector(data, id) {
1321
+ return { id, data };
1322
+ }
1323
+ function useMultipleListQueries(queries, {
1324
+ itemSelector = defaultItemSelector,
1325
+ omitPayload,
1326
+ returnIdleStatus,
1327
+ returnRefetchingStatus,
1328
+ loadSize,
1329
+ disableRefetchOnMount = globalDisableRefetchOnMount
1330
+ } = {}) {
1331
+ const queriesWithId = useDeepMemo(() => {
1332
+ return queries.map((payload) => {
1333
+ return {
1334
+ key: getQueryKey(payload),
1335
+ payload
1336
+ };
1337
+ });
1338
+ }, [queries]);
1339
+ const dataSelector = (0, import_react5.useCallback)(itemSelector, []);
1340
+ const resultSelector = (0, import_react5.useCallback)(
1341
+ (state) => {
1342
+ return queriesWithId.map(
1343
+ ({
1344
+ key: queryKey,
1345
+ payload
1346
+ }) => {
1347
+ const query = state.queries[queryKey];
1348
+ if (!query) {
1349
+ return {
1350
+ queryKey,
1351
+ status: returnIdleStatus ? "idle" : "loading",
1352
+ items: [],
1353
+ error: null,
1354
+ hasMore: false,
1355
+ payload: omitPayload ? void 0 : payload,
1356
+ isLoading: returnIdleStatus ? false : true
1357
+ };
1358
+ }
1359
+ let status = query.status;
1360
+ if (!returnRefetchingStatus && query.status === "refetching") {
1361
+ status = "success";
1362
+ }
1363
+ return {
1364
+ queryKey,
1365
+ status,
1366
+ items: getQueryItems(query, dataSelector),
1367
+ error: query.error,
1368
+ hasMore: query.hasMore,
1369
+ isLoading: status === "loading",
1370
+ payload: omitPayload ? void 0 : query.payload
1371
+ };
1372
+ }
1373
+ );
1374
+ },
1375
+ [
1376
+ dataSelector,
1377
+ omitPayload,
1378
+ queriesWithId,
1379
+ returnIdleStatus,
1380
+ returnRefetchingStatus
1381
+ ]
1382
+ );
1383
+ const storeState = store.useSelector(resultSelector, {
1384
+ equalityFn: import_t_state5.deepEqual,
1385
+ useExternalDeps: true
1386
+ });
1387
+ useOnMittEvent(storeEvents, "invalidateQuery", (event) => {
1388
+ for (const { key, payload } of queriesWithId) {
1389
+ if (key !== event.queryKey)
1390
+ continue;
1391
+ if (!queryInvalidationWasTriggered.has(key)) {
1392
+ scheduleListQueryFetch(event.priority, payload);
1393
+ queryInvalidationWasTriggered.add(key);
1394
+ }
1395
+ }
1396
+ });
1397
+ const loadSizeConst = useConst(() => loadSize);
1398
+ (0, import_react5.useEffect)(() => {
1399
+ for (const { key: itemId, payload: fetchParams } of queriesWithId) {
1400
+ if (itemId) {
1401
+ if (disableRefetchOnMount) {
1402
+ const itemState = getQueryState(fetchParams);
1403
+ const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
1404
+ if (shouldFetch) {
1405
+ scheduleListQueryFetch(
1406
+ itemState?.refetchOnMount || "lowPriority",
1407
+ fetchParams,
1408
+ loadSizeConst
1409
+ );
1410
+ return;
1411
+ }
1412
+ } else {
1413
+ scheduleListQueryFetch("lowPriority", fetchParams, loadSizeConst);
1414
+ }
1415
+ }
1416
+ }
1417
+ }, [disableRefetchOnMount, loadSizeConst, queriesWithId]);
1418
+ return storeState;
1419
+ }
1420
+ function useListQuery(payload, options = {}) {
1421
+ const { ensureIsLoaded } = options;
1422
+ const query = (0, import_react5.useMemo)(
1423
+ () => payload === false || payload === null || payload === void 0 ? [] : [payload],
1424
+ [payload]
1425
+ );
1426
+ const queryResult = useMultipleListQueries(query, options);
1427
+ const result = (0, import_react5.useMemo)(
1428
+ () => queryResult[0] ?? {
1429
+ payload: void 0,
1430
+ error: null,
1431
+ hasMore: false,
1432
+ isLoading: false,
1433
+ status: "idle",
1434
+ queryKey: "",
1435
+ items: []
1436
+ },
1437
+ [queryResult]
1438
+ );
1439
+ const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
1440
+ ensureIsLoaded,
1441
+ !!payload,
1442
+ () => {
1443
+ if (payload) {
1444
+ scheduleListQueryFetch("highPriority", payload);
1445
+ }
1446
+ }
1447
+ );
1448
+ (0, import_t_state5.useSubscribeToStore)(store, ({ observe }) => {
1449
+ if (!ensureIsLoaded)
1450
+ return;
1451
+ observe.ifSelector((state) => state.queries[result.queryKey]?.status).change.then(({ current }) => {
1452
+ if (current === "success" || current === "error") {
1453
+ emitIsLoadedEvt("isLoaded", true);
1454
+ }
1455
+ });
1456
+ });
1457
+ return useModifyResult(result);
1458
+ }
1459
+ async function fetchItem(fetchCtx, itemPayload) {
1460
+ if (!fetchItemOrquestrator) {
1461
+ throw new Error(noFetchFnError);
1462
+ }
1463
+ const itemKey = getCacheId(itemPayload);
1464
+ const isLoaded = !store.state.itemQueries[itemKey]?.wasLoaded;
1465
+ store.produceState(
1466
+ (draft) => {
1467
+ const itemQuery = draft.itemQueries[itemKey];
1468
+ if (!itemQuery) {
1469
+ draft.itemQueries[itemKey] = {
1470
+ status: "loading",
1471
+ error: null,
1472
+ wasLoaded: false,
1473
+ refetchOnMount: false,
1474
+ payload: (0, import_json2.klona)(itemPayload)
1475
+ };
1476
+ return;
1477
+ }
1478
+ itemQuery.status = itemQuery.wasLoaded ? "refetching" : "loading";
1479
+ itemQuery.error = null;
1480
+ itemQuery.refetchOnMount = false;
1481
+ },
1482
+ {
1483
+ action: {
1484
+ type: isLoaded ? "fetch-item-start" : "fetch-item-refetch-start",
1485
+ itemPayload
1486
+ }
1487
+ }
1488
+ );
1489
+ try {
1490
+ const item = await fetchItemFn(itemPayload);
1491
+ if (fetchCtx.shouldAbort())
1492
+ return false;
1493
+ store.produceState(
1494
+ (draft) => {
1495
+ const itemQuery = draft.itemQueries[itemKey];
1496
+ if (!itemQuery)
1497
+ return;
1498
+ itemQuery.status = "success";
1499
+ itemQuery.wasLoaded = true;
1500
+ draft.items[itemKey] = reusePrevIfEqual({
1501
+ current: item,
1502
+ prev: draft.items[itemKey] ?? void 0
1503
+ });
1504
+ },
1505
+ {
1506
+ action: { type: "fetch-item-success", itemPayload }
1507
+ }
1508
+ );
1509
+ return true;
1510
+ } catch (exception) {
1511
+ if (fetchCtx.shouldAbort())
1512
+ return false;
1513
+ const error = errorNormalizer(exception);
1514
+ store.produceState(
1515
+ (draft) => {
1516
+ const itemQuery = draft.itemQueries[itemKey];
1517
+ if (!itemQuery)
1518
+ return;
1519
+ itemQuery.status = "error";
1520
+ itemQuery.error = error;
1521
+ },
1522
+ {
1523
+ action: { type: "fetch-item-error", itemPayload }
1524
+ }
1525
+ );
1526
+ return false;
1527
+ }
1528
+ }
1529
+ const fetchItemOrquestrator = fetchItemFn && createCollectionFetchOrquestrator({
1530
+ fetchFn: fetchItem,
1531
+ lowPriorityThrottleMs,
1532
+ dynamicRealtimeThrottleMs,
1533
+ mediumPriorityThrottleMs
1534
+ });
1535
+ function scheduleItemFetch(fetchType, itemPayload) {
1536
+ if (!fetchItemOrquestrator) {
1537
+ throw new Error(noFetchFnError);
1538
+ }
1539
+ const fetchMultiple = Array.isArray(itemPayload);
1540
+ const itemsId = fetchMultiple ? itemPayload : [itemPayload];
1541
+ const results = itemsId.map((payload) => {
1542
+ const itemKey = getCacheId(payload);
1543
+ return fetchItemOrquestrator.get(itemKey).scheduleFetch(fetchType, payload);
1544
+ });
1545
+ return fetchMultiple ? results : results[0];
1546
+ }
1547
+ function getItemsKeyArray(itemsPayload) {
1548
+ if (Array.isArray(itemsPayload)) {
1549
+ return itemsPayload.map((payload) => ({
1550
+ itemKey: getItemKey(payload),
1551
+ payload
1552
+ }));
1553
+ }
1554
+ if (typeof itemsPayload === "function") {
1555
+ return filterAndMap(
1556
+ Object.entries(store.state.items),
1557
+ ([itemKey, item], ignore2) => {
1558
+ const payload = store.state.itemQueries[itemKey]?.payload;
1559
+ if (item === null || !payload)
1560
+ return ignore2;
1561
+ return itemsPayload(payload, item) ? { itemKey, payload } : ignore2;
1562
+ }
1563
+ );
1564
+ }
1565
+ return [{ payload: itemsPayload, itemKey: getItemKey(itemsPayload) }];
1566
+ }
1567
+ const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
1568
+ function invalidateItem(itemId, priority = "highPriority", ignoreInvalidationSync = false) {
1569
+ if (!fetchItemOrquestrator) {
1570
+ throw new Error(noFetchFnError);
1571
+ }
1572
+ const itemsKey = getItemsKeyArray(itemId);
1573
+ for (const { itemKey } of itemsKey) {
1574
+ store.produceState(
1575
+ (draft) => {
1576
+ const query = draft.itemQueries[itemKey];
1577
+ if (!query)
1578
+ return;
1579
+ query.refetchOnMount = priority;
1580
+ },
1581
+ { action: { type: "invalidate-item", queryKey: itemKey } }
1582
+ );
1583
+ itemInvalidationWasTriggered.delete(itemKey);
1584
+ storeEvents.emit("invalidateItem", { priority, itemKey });
1585
+ }
1586
+ if (syncMutationsAndInvalidations && !ignoreInvalidationSync) {
1587
+ invalidateQuery(
1588
+ (query) => itemsKey.some(
1589
+ ({ payload }) => syncMutationsAndInvalidations.syncItemAndQuery(payload, query)
1590
+ ),
1591
+ priority,
1592
+ true
1593
+ );
1594
+ }
1595
+ }
1596
+ function startItemMutation(itemId) {
1597
+ if (!fetchItemOrquestrator)
1598
+ throw new Error(noFetchFnError);
1599
+ const itemsKey = getItemsKeyArray(itemId);
1600
+ const endMutations = [];
1601
+ for (const { itemKey, payload } of itemsKey) {
1602
+ endMutations.push(fetchItemOrquestrator.get(itemKey).startMutation());
1603
+ if (syncMutationsAndInvalidations) {
1604
+ for (const [queryKey, query] of Object.entries(store.state.queries)) {
1605
+ if (syncMutationsAndInvalidations.syncItemAndQuery(
1606
+ payload,
1607
+ query.payload
1608
+ )) {
1609
+ endMutations.push(
1610
+ fetchQueryOrquestrator.get(queryKey).startMutation()
1611
+ );
1612
+ }
1613
+ }
1614
+ }
1615
+ }
1616
+ return () => {
1617
+ for (const endMutation of endMutations) {
1618
+ endMutation();
1619
+ }
1620
+ };
1621
+ }
1622
+ function defaultItemDataSelector(data) {
1623
+ return data;
1624
+ }
1625
+ function useMultipleItems(itemsPayload_, {
1626
+ selector = defaultItemDataSelector,
1627
+ returnIdleStatus,
1628
+ returnRefetchingStatus,
1629
+ disableRefetchOnMount
1630
+ } = {}) {
1631
+ const dataSelector = (0, import_react5.useCallback)(selector, []);
1632
+ const memoizedItemKeys = useDeepMemo(
1633
+ () => itemsPayload_.map(
1634
+ (itemPayload) => ({
1635
+ payload: itemPayload,
1636
+ itemKey: getItemKey(itemPayload)
1637
+ })
1638
+ ),
1639
+ [itemsPayload_]
1640
+ );
1641
+ const resultSelector = (0, import_react5.useCallback)(
1642
+ (state) => {
1643
+ return memoizedItemKeys.map(
1644
+ ({
1645
+ itemKey,
1646
+ payload
1647
+ }) => {
1648
+ const itemQuery = state.itemQueries[itemKey];
1649
+ const itemState = state.items[itemKey];
1650
+ if (itemQuery === null) {
1651
+ return {
1652
+ status: "deleted",
1653
+ error: null,
1654
+ isLoading: false,
1655
+ payload,
1656
+ data: dataSelector(null, itemKey)
1657
+ };
1658
+ }
1659
+ if (!itemQuery) {
1660
+ return {
1661
+ status: returnIdleStatus ? "idle" : "loading",
1662
+ error: null,
1663
+ isLoading: returnIdleStatus ? false : true,
1664
+ payload,
1665
+ data: dataSelector(null, itemKey)
1666
+ };
1667
+ }
1668
+ let status = itemQuery.status;
1669
+ if (!returnRefetchingStatus && itemQuery.status === "refetching") {
1670
+ status = "success";
1671
+ }
1672
+ return {
1673
+ status,
1674
+ error: itemQuery.error,
1675
+ isLoading: status === "loading",
1676
+ data: dataSelector(itemState ?? null, itemKey),
1677
+ payload
1678
+ };
1679
+ }
1680
+ );
1681
+ },
1682
+ [
1683
+ dataSelector,
1684
+ memoizedItemKeys,
1685
+ returnIdleStatus,
1686
+ returnRefetchingStatus
1687
+ ]
1688
+ );
1689
+ const storeState = store.useSelector(resultSelector, {
1690
+ equalityFn: import_t_state5.deepEqual,
1691
+ useExternalDeps: true
1692
+ });
1693
+ useOnMittEvent(storeEvents, "invalidateItem", (event) => {
1694
+ for (const { payload, itemKey } of memoizedItemKeys) {
1695
+ if (itemKey !== event.itemKey)
1696
+ continue;
1697
+ if (!itemInvalidationWasTriggered.has(itemKey)) {
1698
+ scheduleItemFetch(event.priority, payload);
1699
+ itemInvalidationWasTriggered.add(itemKey);
1700
+ }
1701
+ }
1702
+ });
1703
+ (0, import_react5.useEffect)(() => {
1704
+ for (const { payload, itemKey } of memoizedItemKeys) {
1705
+ if (itemKey) {
1706
+ if (disableRefetchOnMount) {
1707
+ const itemState = store.state.itemQueries[itemKey];
1708
+ const shouldFetch = !itemState || !itemState.wasLoaded || itemState.refetchOnMount;
1709
+ if (shouldFetch) {
1710
+ scheduleItemFetch(
1711
+ itemState?.refetchOnMount || "lowPriority",
1712
+ payload
1713
+ );
1714
+ return;
1715
+ }
1716
+ } else {
1717
+ scheduleItemFetch("lowPriority", payload);
1718
+ }
1719
+ }
1720
+ }
1721
+ }, [disableRefetchOnMount, memoizedItemKeys]);
1722
+ return storeState;
1723
+ }
1724
+ function useItem(itemPayload, options = {}) {
1725
+ const { ensureIsLoaded } = options;
1726
+ const query = (0, import_react5.useMemo)(
1727
+ () => itemPayload === false || itemPayload === null || itemPayload === void 0 ? [] : [itemPayload],
1728
+ [itemPayload]
1729
+ );
1730
+ const queryResult = useMultipleItems(query, options);
1731
+ const memoizedSelector = (0, import_react5.useCallback)(
1732
+ options.selector ?? defaultItemDataSelector,
1733
+ []
1734
+ );
1735
+ const result = (0, import_react5.useMemo)(
1736
+ () => queryResult[0] ?? {
1737
+ error: null,
1738
+ isLoading: false,
1739
+ status: "idle",
1740
+ data: memoizedSelector(null, ""),
1741
+ payload: itemPayload || null
1742
+ },
1743
+ [itemPayload, memoizedSelector, queryResult]
1744
+ );
1745
+ const [useModifyResult, emitIsLoadedEvt] = useEnsureIsLoaded(
1746
+ ensureIsLoaded,
1747
+ !!itemPayload,
1748
+ () => {
1749
+ if (itemPayload) {
1750
+ scheduleItemFetch("highPriority", itemPayload);
1751
+ }
1752
+ }
1753
+ );
1754
+ (0, import_t_state5.useSubscribeToStore)(store, ({ observe }) => {
1755
+ if (!ensureIsLoaded || !itemPayload)
1756
+ return;
1757
+ observe.ifSelector((state) => state.itemQueries[itemPayload]?.status).change.then(({ current }) => {
1758
+ if (current === "success" || current === "error") {
1759
+ emitIsLoadedEvt("isLoaded", true);
1760
+ }
1761
+ });
1762
+ });
1763
+ return useModifyResult(result);
1764
+ }
1765
+ function updateItemState(itemIds, produceNewData, ifNothingWasUpdated) {
1766
+ const itemKeys = getItemsKeyArray(itemIds);
1767
+ let someItemWasUpdated = false;
1768
+ store.batch(
1769
+ () => {
1770
+ store.produceState((draftState) => {
1771
+ for (const { itemKey, payload } of itemKeys) {
1772
+ const item = draftState.items[itemKey];
1773
+ if (!item)
1774
+ continue;
1775
+ someItemWasUpdated = true;
1776
+ const newData = produceNewData(item, payload);
1777
+ if (newData) {
1778
+ draftState.items[itemKey] = newData;
1779
+ }
1780
+ }
1781
+ });
1782
+ if (ifNothingWasUpdated && !someItemWasUpdated) {
1783
+ ifNothingWasUpdated();
1784
+ }
1785
+ },
1786
+ { type: "update-item-state", item: itemKeys }
1787
+ );
1788
+ return someItemWasUpdated;
1789
+ }
1790
+ function addItemToState(itemPayload, data) {
1791
+ const itemKey = getItemKey(itemPayload);
1792
+ store.produceState(
1793
+ (draftState) => {
1794
+ draftState.items[itemKey] = data;
1795
+ draftState.itemQueries[itemKey] = {
1796
+ status: "success",
1797
+ wasLoaded: true,
1798
+ refetchOnMount: false,
1799
+ error: null,
1800
+ payload: (0, import_json2.klona)(itemPayload)
1801
+ };
1802
+ },
1803
+ { action: { type: "create-item-state", itemPayload } }
1804
+ );
1805
+ }
1806
+ function deleteItemState(itemId) {
1807
+ const itemsId = getItemsKeyArray(itemId);
1808
+ store.produceState(
1809
+ (draftState) => {
1810
+ for (const { itemKey } of itemsId) {
1811
+ draftState.items[itemKey] = null;
1812
+ draftState.itemQueries[itemKey] = null;
1813
+ for (const query of Object.values(draftState.queries)) {
1814
+ if (query.items.includes(itemKey)) {
1815
+ query.items = query.items.filter((i) => i !== itemKey);
1816
+ }
1817
+ }
1818
+ }
1819
+ },
1820
+ { action: { type: "delete-item-state", itemId } }
1821
+ );
1822
+ }
1823
+ if (!disableRefetchOnWindowFocus) {
1824
+ let handleFocus2 = function() {
1825
+ invalidateQuery(() => true, "lowPriority");
1826
+ invalidateItem(() => true, "lowPriority");
1827
+ };
1828
+ var handleFocus = handleFocus2;
1829
+ window.addEventListener("focus", handleFocus2);
1830
+ window.addEventListener("visibilitychange", handleFocus2);
1831
+ }
1832
+ return {
1833
+ store,
1834
+ scheduleListQueryFetch,
1835
+ getQueryState,
1836
+ getQueryKey,
1837
+ deleteItemState,
1838
+ getItemState,
1839
+ loadMore,
1840
+ invalidateQuery,
1841
+ invalidateItem,
1842
+ scheduleItemFetch,
1843
+ awaitItemFetch,
1844
+ awaitListQueryFetch,
1845
+ useMultipleListQueries,
1846
+ useListQuery,
1847
+ getItemKey,
1848
+ useItem,
1849
+ useMultipleItems,
1850
+ addItemToState,
1851
+ updateItemState,
1852
+ startItemMutation
1853
+ };
1854
+ }
1855
+ // Annotate the CommonJS export names for ESM import in node:
1856
+ 0 && (module.exports = {
1857
+ newTSDFCollectionStore,
1858
+ newTSDFDocumentStore,
1859
+ newTSDFListQueryStore
1860
+ });