tsdf 17.0.0-beta.6 → 17.0.0-rc.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/dist/async-storage.js +1 -1
- package/dist/{asyncStorageAdapter-CsFvYNBT.js → asyncStorageAdapter-BBKVK1S_.js} +10 -2
- package/dist/{asyncStorageAdapters-Bz2Ni2XW.js → asyncStorageAdapters-CkGt87Po.js} +2 -2
- package/dist/indexed-db-storage.js +1 -1
- package/dist/{indexedDbPersistentStorage-IOCYNcQS.js → indexedDbPersistentStorage-D5tGmD77.js} +1 -1
- package/dist/main.js +335 -163
- package/dist/opfs-storage.js +1 -1
- package/dist/{opfsPersistentStorage-413IafdY.js → opfsPersistentStorage-B_lVflof.js} +1 -1
- package/docs/partial-resources.md +2 -0
- package/docs/persistent-storage.md +1 -1
- package/package.json +1 -1
package/dist/async-storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-
|
|
1
|
+
import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-BBKVK1S_.js";
|
|
2
2
|
export { createAsyncStorageAdapter };
|
|
@@ -481,6 +481,14 @@ function logPersistentStorageQuotaCleanup(args) {
|
|
|
481
481
|
});
|
|
482
482
|
}
|
|
483
483
|
//#endregion
|
|
484
|
+
//#region src/persistentStorage/storageEntryPrefixes.ts
|
|
485
|
+
/** Store name of the per-session offline mode status entry. */
|
|
486
|
+
const OFFLINE_SESSION_STATUS_STORE_NAME = "_o_.s";
|
|
487
|
+
/** Builds the `localStorage` key holding a session's offline mode status. */
|
|
488
|
+
function getOfflineSessionStatusStorageKey(sessionKey) {
|
|
489
|
+
return `tsdf.${sessionKey}.${OFFLINE_SESSION_STATUS_STORE_NAME}`;
|
|
490
|
+
}
|
|
491
|
+
//#endregion
|
|
484
492
|
//#region src/persistentStorage/types.ts
|
|
485
493
|
function parseAsyncStorageNamespaceKind(value) {
|
|
486
494
|
switch (value) {
|
|
@@ -524,7 +532,7 @@ function getProtectedKeysFromMetadata(entries) {
|
|
|
524
532
|
function isSessionOfflineInLocalStorage(sessionKey) {
|
|
525
533
|
if (typeof window === "undefined") return false;
|
|
526
534
|
try {
|
|
527
|
-
return isOfflineModeStatusValue(parseCompactLocalStorageEntry(localStorage.getItem(
|
|
535
|
+
return isOfflineModeStatusValue(parseCompactLocalStorageEntry(localStorage.getItem(getOfflineSessionStatusStorageKey(sessionKey)))?.value.d ?? null);
|
|
528
536
|
} catch {
|
|
529
537
|
return false;
|
|
530
538
|
}
|
|
@@ -1954,4 +1962,4 @@ function serializeProtectedRef(ref) {
|
|
|
1954
1962
|
return serializeProtectedRef$1(ref);
|
|
1955
1963
|
}
|
|
1956
1964
|
//#endregion
|
|
1957
|
-
export {
|
|
1965
|
+
export { isModeEffectivelyActive as A, parseCompactLocalStorageEntry as B, isQuotaExceededError as C, compactOfflineStatusSnapshotSchema as D, OfflineResolutionConflictParseError as E, getSessionProtectedKeysSnapshot as F, getPersistedNamespaceId as G, encodePersistedAsyncNamespaceKind as H, setSessionProtectedKeysSnapshot as I, parsePersistedAsyncNamespaceKind as J, normalizeStaticPolicy as K, getNavigatorLockManager as L, offlineItemEntityRefSchema as M, offlineResolutionRecordSchema as N, defaultOfflineRuntimeConfig as O, clearSessionProtectedKeysSnapshot as P, warnIfNavigatorLockUnavailable as R, getSerializedStringSize as S, serializeJsonForStorage as T, getNamespaceId as U, compareMetadata as V, getPayloadRecordKey as W, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS as X, serializeProtectedRef$1 as Y, scheduleIdleCleanup as Z, getTSDFDebugTimingMs as _, estimateManagedAsyncStorageEntrySizeBytes as a, createShouldIgnoreItemPredicate as b, readAsyncStorageNamespaceIndexStateUsingDriver as c, unregisterAsyncStartupStoreCleanup as d, parseAsyncStorageNamespaceKind as f, emitTSDFDebugLog as g, logPersistentStorageQuotaCleanup as h, createAsyncStorageAdapter as i, isOfflineModeStatusValue as j, getIsOfflineModeFromStatus as k, registerAsyncStartupStoreCleanup as l, getOfflineSessionStatusStorageKey as m, ASYNC_STORAGE_MAX_AGE_MS as n, getProtectedKeysFromMetadata as o, OFFLINE_SESSION_STATUS_STORE_NAME as p, parseAsyncStorageRecordKey as q, buildPersistedStaticPolicy as r, mergeManagedAsyncStorageCustomMetadata as s, ASYNC_MAINTENANCE_LOCAL_STORAGE_KEY as t, serializeProtectedRef as u, resolveTSDFLogger as v, keepEntriesWithinByteBudget as w, createTimedKeySet as x, getDefaultMaxBytesForScope as y, createCompactLocalStorageEntry as z };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as opfsPersistentStorage } from "./opfsPersistentStorage-
|
|
2
|
-
import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-
|
|
1
|
+
import { t as opfsPersistentStorage } from "./opfsPersistentStorage-B_lVflof.js";
|
|
2
|
+
import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-D5tGmD77.js";
|
|
3
3
|
export { indexedDbPersistentStorage, opfsPersistentStorage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-
|
|
1
|
+
import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-D5tGmD77.js";
|
|
2
2
|
export { createIndexedDbPersistentStorage, indexedDbPersistentStorage };
|
package/dist/{indexedDbPersistentStorage-IOCYNcQS.js → indexedDbPersistentStorage-D5tGmD77.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as getPersistedNamespaceId, H as encodePersistedAsyncNamespaceKind, J as parsePersistedAsyncNamespaceKind, K as normalizeStaticPolicy, T as serializeJsonForStorage, U as getNamespaceId, V as compareMetadata, W as getPayloadRecordKey, Y as serializeProtectedRef, _ as getTSDFDebugTimingMs, a as estimateManagedAsyncStorageEntrySizeBytes, g as emitTSDFDebugLog, i as createAsyncStorageAdapter, q as parseAsyncStorageRecordKey } from "./asyncStorageAdapter-BBKVK1S_.js";
|
|
2
2
|
import { __LEGIT_CAST__ } from "@ls-stack/utils/saferTyping";
|
|
3
3
|
import { isObject } from "@ls-stack/utils/typeGuards";
|
|
4
4
|
//#region src/persistentStorage/indexedDbAsyncStorageAdapter.ts
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { a as encodePathSegment, i as getNavigatorStorageDirectory, n as getDirectoryHandleIfExists, r as getFileHandleIfExists } from "./opfsPersistentStorage-
|
|
1
|
+
import { A as isModeEffectivelyActive, B as parseCompactLocalStorageEntry, C as isQuotaExceededError, D as compactOfflineStatusSnapshotSchema, E as OfflineResolutionConflictParseError, F as getSessionProtectedKeysSnapshot, I as setSessionProtectedKeysSnapshot, J as parsePersistedAsyncNamespaceKind, L as getNavigatorLockManager, M as offlineItemEntityRefSchema, N as offlineResolutionRecordSchema, O as defaultOfflineRuntimeConfig, P as clearSessionProtectedKeysSnapshot, R as warnIfNavigatorLockUnavailable, S as getSerializedStringSize, T as serializeJsonForStorage, W as getPayloadRecordKey, X as INITIAL_MAINTENANCE_CLEANUP_DELAY_MS, Y as serializeProtectedRef, Z as scheduleIdleCleanup, _ as getTSDFDebugTimingMs, a as estimateManagedAsyncStorageEntrySizeBytes, b as createShouldIgnoreItemPredicate, c as readAsyncStorageNamespaceIndexStateUsingDriver, d as unregisterAsyncStartupStoreCleanup, f as parseAsyncStorageNamespaceKind, g as emitTSDFDebugLog, h as logPersistentStorageQuotaCleanup, j as isOfflineModeStatusValue, k as getIsOfflineModeFromStatus, l as registerAsyncStartupStoreCleanup, m as getOfflineSessionStatusStorageKey, o as getProtectedKeysFromMetadata, p as OFFLINE_SESSION_STATUS_STORE_NAME, r as buildPersistedStaticPolicy, s as mergeManagedAsyncStorageCustomMetadata, u as serializeProtectedRef$1, v as resolveTSDFLogger, w as keepEntriesWithinByteBudget, x as createTimedKeySet, y as getDefaultMaxBytesForScope, z as createCompactLocalStorageEntry } from "./asyncStorageAdapter-BBKVK1S_.js";
|
|
2
|
+
import { a as encodePathSegment, i as getNavigatorStorageDirectory, n as getDirectoryHandleIfExists, r as getFileHandleIfExists } from "./opfsPersistentStorage-B_lVflof.js";
|
|
3
3
|
import { isWindowFocused, onWindowFocus } from "@ls-stack/browser-utils/window";
|
|
4
4
|
import { filterAndMap, findAndMap, sortBy } from "@ls-stack/utils/arrayUtils";
|
|
5
5
|
import { getCompositeKey } from "@ls-stack/utils/getCompositeKey";
|
|
@@ -296,6 +296,55 @@ function isLocalStorageQuotaWritesDisabled() {
|
|
|
296
296
|
return managedLocalStorageQuotaWritesDisabled;
|
|
297
297
|
}
|
|
298
298
|
/**
|
|
299
|
+
* Keys written by the currently running locked mutation. When a later write
|
|
300
|
+
* of the same mutation hits the quota, these keys must not be evicted by the
|
|
301
|
+
* recovery: a fresh payload is not referenced by any manifest until the
|
|
302
|
+
* (possibly deferred) manifest write lands, so the orphan-eviction pass would
|
|
303
|
+
* otherwise delete the very data the mutation just persisted.
|
|
304
|
+
*/
|
|
305
|
+
const inFlightMutationWrittenKeys = /* @__PURE__ */ new Set();
|
|
306
|
+
let inFlightMutationDepth = 0;
|
|
307
|
+
/**
|
|
308
|
+
* Runs a locked `localStorage` mutation while tracking every key it writes,
|
|
309
|
+
* so a quota recovery triggered mid-mutation never evicts them.
|
|
310
|
+
*/
|
|
311
|
+
async function trackManagedLocalStorageMutationWrites(callback) {
|
|
312
|
+
inFlightMutationDepth++;
|
|
313
|
+
try {
|
|
314
|
+
return await callback();
|
|
315
|
+
} finally {
|
|
316
|
+
inFlightMutationDepth--;
|
|
317
|
+
if (inFlightMutationDepth === 0) inFlightMutationWrittenKeys.clear();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Terminal quota-disable error raised on a code path with no
|
|
322
|
+
* `onPersistentStorageError` to report it to (e.g. a deferred manifest
|
|
323
|
+
* flush). It is stashed here and delivered by the next persistence operation
|
|
324
|
+
* that hits the quota-writes-disabled guard, preserving the "exactly one
|
|
325
|
+
* error reaches the app" invariant.
|
|
326
|
+
*/
|
|
327
|
+
let pendingQuotaWritesDisabledError = null;
|
|
328
|
+
function takePendingQuotaWritesDisabledError() {
|
|
329
|
+
const error = pendingQuotaWritesDisabledError;
|
|
330
|
+
pendingQuotaWritesDisabledError = null;
|
|
331
|
+
return error;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Error sink for background persistence work (idle flushes, scheduled
|
|
335
|
+
* removals) that has no caller to propagate errors to. The terminal
|
|
336
|
+
* quota-disable error is stashed for later delivery through
|
|
337
|
+
* `onPersistentStorageError`; anything else is only logged, since a dropped
|
|
338
|
+
* background write self-heals via maintenance sweeps.
|
|
339
|
+
*/
|
|
340
|
+
function handleManagedLocalStorageBackgroundError(error) {
|
|
341
|
+
if (managedLocalStorageQuotaWritesDisabled) {
|
|
342
|
+
pendingQuotaWritesDisabledError = error;
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
console.error(error);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
299
348
|
* Writes to `localStorage`, recovering from `QuotaExceededError` by evicting
|
|
300
349
|
* TSDF-managed entries: first the least recently used half of the evictable
|
|
301
350
|
* bytes, then everything unprotected. If the write still fails, persistence
|
|
@@ -308,6 +357,7 @@ function setManagedLocalStorageItemWithQuotaRecovery(key, value, io) {
|
|
|
308
357
|
if (managedLocalStorageQuotaWritesDisabled) return false;
|
|
309
358
|
try {
|
|
310
359
|
localStorage.setItem(key, value);
|
|
360
|
+
if (inFlightMutationDepth > 0) inFlightMutationWrittenKeys.add(key);
|
|
311
361
|
return true;
|
|
312
362
|
} catch (error) {
|
|
313
363
|
if (!isQuotaExceededError(error) || managedLocalStorageQuotaRecoveryActive) throw error;
|
|
@@ -317,6 +367,7 @@ function setManagedLocalStorageItemWithQuotaRecovery(key, value, io) {
|
|
|
317
367
|
runManagedLocalStorageQuotaEviction(io, evictAllUnprotected);
|
|
318
368
|
try {
|
|
319
369
|
localStorage.setItem(key, value);
|
|
370
|
+
if (inFlightMutationDepth > 0) inFlightMutationWrittenKeys.add(key);
|
|
320
371
|
return true;
|
|
321
372
|
} catch (retryError) {
|
|
322
373
|
if (!isQuotaExceededError(retryError)) throw retryError;
|
|
@@ -361,6 +412,7 @@ function runManagedLocalStorageQuotaEviction(io, evictAllUnprotected) {
|
|
|
361
412
|
manifestOwnedPayloadKeys.add(payloadKey);
|
|
362
413
|
if (isOfflineOwned || isOfflineRelatedPayloadKey(payloadKey)) continue;
|
|
363
414
|
if (isManagedLocalStorageEntryOfflineProtected(entry.meta)) continue;
|
|
415
|
+
if (inFlightMutationWrittenKeys.has(payloadKey)) continue;
|
|
364
416
|
candidates.push({
|
|
365
417
|
payloadKey,
|
|
366
418
|
lastAccessAt: entry.lastAccessAt,
|
|
@@ -382,6 +434,7 @@ function runManagedLocalStorageQuotaEviction(io, evictAllUnprotected) {
|
|
|
382
434
|
}
|
|
383
435
|
for (const key of compactListQueryKeys) {
|
|
384
436
|
if (manifestOwnedPayloadKeys.has(key) || isOfflineRelatedPayloadKey(key)) continue;
|
|
437
|
+
if (inFlightMutationWrittenKeys.has(key)) continue;
|
|
385
438
|
const entry = readCompactListQueryEntry(key, io);
|
|
386
439
|
if (entry?.offlineProtected === true) continue;
|
|
387
440
|
candidates.push({
|
|
@@ -394,6 +447,7 @@ function runManagedLocalStorageQuotaEviction(io, evictAllUnprotected) {
|
|
|
394
447
|
}
|
|
395
448
|
for (const key of manifestBackedPayloadKeys) {
|
|
396
449
|
if (manifestOwnedPayloadKeys.has(key) || isOfflineRelatedPayloadKey(key)) continue;
|
|
450
|
+
if (inFlightMutationWrittenKeys.has(key)) continue;
|
|
397
451
|
candidates.push({
|
|
398
452
|
payloadKey: key,
|
|
399
453
|
lastAccessAt: 0,
|
|
@@ -434,12 +488,23 @@ function runManagedLocalStorageQuotaEviction(io, evictAllUnprotected) {
|
|
|
434
488
|
}
|
|
435
489
|
}
|
|
436
490
|
}
|
|
491
|
+
/** Matches every payload key under the reserved `tsdf.<sessionKey>._o_.*` root. */
|
|
492
|
+
const OFFLINE_ROOT_KEY_INFIX = `._o_.`;
|
|
493
|
+
const OFFLINE_SESSION_STATUS_KEY_SUFFIX = `.${OFFLINE_SESSION_STATUS_STORE_NAME}`;
|
|
494
|
+
const OFFLINE_NAMESPACE_STORAGE_PREFIX_SUFFIXES = [
|
|
495
|
+
`.oq.`,
|
|
496
|
+
`.oc.`,
|
|
497
|
+
`.oe.`
|
|
498
|
+
];
|
|
499
|
+
function isOfflineNamespaceStoragePrefix(storagePrefix) {
|
|
500
|
+
return OFFLINE_NAMESPACE_STORAGE_PREFIX_SUFFIXES.some((suffix) => storagePrefix.endsWith(suffix));
|
|
501
|
+
}
|
|
437
502
|
function isOfflineOwnedManifestLocation(manifestLocation) {
|
|
438
|
-
if (manifestLocation.kind === "single") return manifestLocation.payloadKey.includes(
|
|
439
|
-
return
|
|
503
|
+
if (manifestLocation.kind === "single") return manifestLocation.payloadKey.includes(OFFLINE_ROOT_KEY_INFIX);
|
|
504
|
+
return isOfflineNamespaceStoragePrefix(manifestLocation.storagePrefix);
|
|
440
505
|
}
|
|
441
506
|
function isOfflineRelatedPayloadKey(payloadKey) {
|
|
442
|
-
return payloadKey.includes(
|
|
507
|
+
return payloadKey.includes(OFFLINE_ROOT_KEY_INFIX);
|
|
443
508
|
}
|
|
444
509
|
function getManagedLocalStorageRuntimeConfig() {
|
|
445
510
|
return managedLocalStorageRuntimeConfig;
|
|
@@ -487,13 +552,13 @@ function normalizeRootIdentityValue(value) {
|
|
|
487
552
|
return value.startsWith("tsdf.") ? value.slice(5) : value;
|
|
488
553
|
}
|
|
489
554
|
const COMPRESSED_NAMESPACE_ROOT_SUFFIXES = [
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
];
|
|
555
|
+
"ci",
|
|
556
|
+
"li",
|
|
557
|
+
"lq",
|
|
558
|
+
"oq",
|
|
559
|
+
"oc",
|
|
560
|
+
"oe"
|
|
561
|
+
].map((prefix) => [`.${prefix}.`, `.${prefix}`]);
|
|
497
562
|
function compactNamespaceRootIdentityValue(storagePrefix) {
|
|
498
563
|
const normalized = normalizeRootIdentityValue(storagePrefix);
|
|
499
564
|
for (const [suffix, compactSuffix] of COMPRESSED_NAMESPACE_ROOT_SUFFIXES) if (normalized.endsWith(suffix)) return `${normalized.slice(0, -suffix.length)}${compactSuffix}`;
|
|
@@ -846,7 +911,7 @@ function getCachedOfflineStatus(sessionKey, io, cache) {
|
|
|
846
911
|
return result;
|
|
847
912
|
}
|
|
848
913
|
function isSessionOfflineDuringManagedCleanup(sessionKey, io) {
|
|
849
|
-
const rawStatus = parseCompactLocalStorageEntry(io.getItem(
|
|
914
|
+
const rawStatus = parseCompactLocalStorageEntry(io.getItem(getOfflineSessionStatusStorageKey(sessionKey)))?.value;
|
|
850
915
|
return isOfflineModeStatusValue(isObject(rawStatus) && isObject(rawStatus.d) ? rawStatus.d : rawStatus ?? null);
|
|
851
916
|
}
|
|
852
917
|
function clearManagedLocalStorageSession(sessionKey, io = directManagedLocalStorageIo) {
|
|
@@ -925,15 +990,19 @@ function collectManagedLocalStorageSweepTargets(io) {
|
|
|
925
990
|
manifestKeys: allKeys.filter((key) => {
|
|
926
991
|
if (!isManagedLocalStorageManifestKey(key)) return false;
|
|
927
992
|
const manifestLocation = parseManagedLocalStorageManifestKey(key);
|
|
928
|
-
if (manifestLocation?.kind === "single" &&
|
|
929
|
-
if (manifestLocation?.kind === "namespace" && (manifestLocation.storagePrefix
|
|
993
|
+
if (manifestLocation?.kind === "single" && isOfflinePayloadKey(manifestLocation.payloadKey)) return false;
|
|
994
|
+
if (manifestLocation?.kind === "namespace" && isOfflineNamespaceStoragePrefix(manifestLocation.storagePrefix)) return false;
|
|
930
995
|
return true;
|
|
931
996
|
}),
|
|
932
997
|
knownKeys: new Set(allKeys)
|
|
933
998
|
};
|
|
934
999
|
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Offline-owned payload keys, excluding the session status entry (which is
|
|
1002
|
+
* cleaned up like regular data so stale sessions do not pin it forever).
|
|
1003
|
+
*/
|
|
935
1004
|
function isOfflinePayloadKey(payloadKey) {
|
|
936
|
-
return payloadKey.includes(
|
|
1005
|
+
return payloadKey.includes(OFFLINE_ROOT_KEY_INFIX) && !payloadKey.endsWith(OFFLINE_SESSION_STATUS_KEY_SUFFIX);
|
|
937
1006
|
}
|
|
938
1007
|
function runGenericCleanupForManifest(manifestKey, knownKeys, io, offlineSessionCache) {
|
|
939
1008
|
const manifestLocation = parseManagedLocalStorageManifestKey(manifestKey);
|
|
@@ -948,7 +1017,7 @@ function runGenericCleanupForManifest(manifestKey, knownKeys, io, offlineSession
|
|
|
948
1017
|
}
|
|
949
1018
|
const now = Date.now();
|
|
950
1019
|
const sessionKey = getSessionKeyForManifestLocation(manifestLocation);
|
|
951
|
-
const offlineStatusKey = sessionKey === null ? null :
|
|
1020
|
+
const offlineStatusKey = sessionKey === null ? null : getOfflineSessionStatusStorageKey(sessionKey);
|
|
952
1021
|
const skipExpiration = sessionKey !== null && offlineStatusKey !== null && knownKeys !== null && knownKeys.has(offlineStatusKey) && getCachedOfflineStatus(sessionKey, io, offlineSessionCache);
|
|
953
1022
|
const nextEntries = /* @__PURE__ */ new Map();
|
|
954
1023
|
for (const entry of manifest.entries.values()) {
|
|
@@ -1164,9 +1233,10 @@ function createCachedManagedLocalStorageIo() {
|
|
|
1164
1233
|
if (pendingManifestWrites.size === 0) return;
|
|
1165
1234
|
for (const [key, value] of pendingManifestWrites) if (value === null) localStorage.removeItem(key);
|
|
1166
1235
|
else try {
|
|
1167
|
-
setManagedLocalStorageItemWithQuotaRecovery(key, value, io);
|
|
1236
|
+
if (!setManagedLocalStorageItemWithQuotaRecovery(key, value, io)) cache.delete(key);
|
|
1168
1237
|
} catch (error) {
|
|
1169
|
-
|
|
1238
|
+
cache.delete(key);
|
|
1239
|
+
handleManagedLocalStorageBackgroundError(error);
|
|
1170
1240
|
}
|
|
1171
1241
|
pendingManifestWrites.clear();
|
|
1172
1242
|
}
|
|
@@ -1208,6 +1278,7 @@ function createCachedManagedLocalStorageIo() {
|
|
|
1208
1278
|
else setManagedLocalStorageItemWithQuotaRecovery(key, value, directManagedLocalStorageIo);
|
|
1209
1279
|
return;
|
|
1210
1280
|
}
|
|
1281
|
+
if (value !== null && isLocalStorageQuotaWritesDisabled()) return;
|
|
1211
1282
|
cache.set(key, value);
|
|
1212
1283
|
pendingManifestWrites.set(key, value);
|
|
1213
1284
|
schedulePendingManifestFlush();
|
|
@@ -1247,9 +1318,9 @@ async function runWithManagedLocalStorageLock(callback) {
|
|
|
1247
1318
|
const lockManager = getNavigatorLockManager();
|
|
1248
1319
|
if (lockManager === null) {
|
|
1249
1320
|
warnIfNavigatorLockUnavailable(MANAGED_LOCAL_STORAGE_LOCK_WARNING);
|
|
1250
|
-
return await callback
|
|
1321
|
+
return await trackManagedLocalStorageMutationWrites(callback);
|
|
1251
1322
|
}
|
|
1252
|
-
return lockManager.request(MANAGED_LOCAL_STORAGE_LOCK_NAME, () => withManagedLocalStorageIoCache(callback));
|
|
1323
|
+
return lockManager.request(MANAGED_LOCAL_STORAGE_LOCK_NAME, () => trackManagedLocalStorageMutationWrites(() => withManagedLocalStorageIoCache(callback)));
|
|
1253
1324
|
}
|
|
1254
1325
|
const localPersistentStorage = {
|
|
1255
1326
|
/** Identifier for adapter type and sync runtime behavior. */
|
|
@@ -1463,6 +1534,17 @@ function preserveOfflineProtectionFlag(sessionKey, storageKey, nextMeta, current
|
|
|
1463
1534
|
async function runLocalStorageMutation(callback) {
|
|
1464
1535
|
return localPersistentStorage.runLocked(callback);
|
|
1465
1536
|
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Delivers the terminal quota-disable error to the app when it was raised on
|
|
1539
|
+
* a background code path with no error handler (e.g. a deferred manifest
|
|
1540
|
+
* flush). Only consumes the stashed error when a handler exists, so the
|
|
1541
|
+
* first store with an `onPersistentStorageError` reports it exactly once.
|
|
1542
|
+
*/
|
|
1543
|
+
function deliverPendingQuotaWritesDisabledError(onPersistentStorageError) {
|
|
1544
|
+
if (!onPersistentStorageError) return;
|
|
1545
|
+
const pendingError = takePendingQuotaWritesDisabledError();
|
|
1546
|
+
if (pendingError !== null) onPersistentStorageError(pendingError);
|
|
1547
|
+
}
|
|
1466
1548
|
function recordLocalStorageTouch(key, timestamp) {
|
|
1467
1549
|
localStorageTouchTimestamps.set(key, timestamp);
|
|
1468
1550
|
}
|
|
@@ -1495,7 +1577,7 @@ function scheduleLocalStorageRemoval(key, options) {
|
|
|
1495
1577
|
scheduleIdleCleanup(() => {
|
|
1496
1578
|
runLocalStorageMutation(() => {
|
|
1497
1579
|
localPersistentStorage.remove(key, options);
|
|
1498
|
-
});
|
|
1580
|
+
}).catch(handleManagedLocalStorageBackgroundError);
|
|
1499
1581
|
});
|
|
1500
1582
|
}
|
|
1501
1583
|
function refreshLocalStorageTimestampUnlocked(key, options) {
|
|
@@ -1657,6 +1739,7 @@ function createPersistentStorageHandle(config, { asyncValueCodec, getManifestMet
|
|
|
1657
1739
|
return;
|
|
1658
1740
|
}
|
|
1659
1741
|
if (isLocalStorageQuotaWritesDisabled()) {
|
|
1742
|
+
deliverPendingQuotaWritesDisabledError(onPersistentStorageError);
|
|
1660
1743
|
if (import.meta.env.DEV) logPersistentStorageOperation(withPersistentStorageDebugKey(debugContext, key), "write", "skipped", startTime, { reason: "quota-writes-disabled" });
|
|
1661
1744
|
return;
|
|
1662
1745
|
}
|
|
@@ -1824,6 +1907,14 @@ function createPersistentStorageNamespaceHandle(config, { asyncValueCodec, getMa
|
|
|
1824
1907
|
return;
|
|
1825
1908
|
}
|
|
1826
1909
|
if (isLocalStorageQuotaWritesDisabled()) {
|
|
1910
|
+
deliverPendingQuotaWritesDisabledError(onPersistentStorageError);
|
|
1911
|
+
const removes = args.removes ?? [];
|
|
1912
|
+
if (removes.length > 0) await runLocalStorageMutation(() => {
|
|
1913
|
+
for (const entryKey of removes) localPersistentStorage.remove(`${prefix}${entryKey}`, {
|
|
1914
|
+
metadata: "namespace",
|
|
1915
|
+
namespacePrefix: prefix
|
|
1916
|
+
});
|
|
1917
|
+
});
|
|
1827
1918
|
if (import.meta.env.DEV) logPersistentStorageOperation(debugContext, "commit", "skipped", startTime, {
|
|
1828
1919
|
...operationDetails,
|
|
1829
1920
|
reason: "quota-writes-disabled"
|
|
@@ -2340,7 +2431,7 @@ async function clearSessionStorage(sessionKey, adapter) {
|
|
|
2340
2431
|
else {
|
|
2341
2432
|
await adapter.clearSession(sessionKey);
|
|
2342
2433
|
await runLocalStorageMutation(() => {
|
|
2343
|
-
const sessionOfflineStatusKey = getStorageKey(sessionKey,
|
|
2434
|
+
const sessionOfflineStatusKey = getStorageKey(sessionKey, OFFLINE_SESSION_STATUS_STORE_NAME);
|
|
2344
2435
|
localPersistentStorage.clearManifest(localPersistentStorage.getManifestKeyForSingle(sessionOfflineStatusKey));
|
|
2345
2436
|
});
|
|
2346
2437
|
}
|
|
@@ -2348,7 +2439,7 @@ async function clearSessionStorage(sessionKey, adapter) {
|
|
|
2348
2439
|
}
|
|
2349
2440
|
/** Clears all persistent storage entries for a given session key across built-in adapters. */
|
|
2350
2441
|
async function clearAllSessionStorage(sessionKey) {
|
|
2351
|
-
const { indexedDbPersistentStorage, opfsPersistentStorage } = await import("./asyncStorageAdapters-
|
|
2442
|
+
const { indexedDbPersistentStorage, opfsPersistentStorage } = await import("./asyncStorageAdapters-CkGt87Po.js");
|
|
2352
2443
|
await Promise.all([
|
|
2353
2444
|
clearSessionStorage(sessionKey, "local-sync"),
|
|
2354
2445
|
clearSessionStorage(sessionKey, opfsPersistentStorage),
|
|
@@ -3702,9 +3793,6 @@ function createDefaultStatus(sessionKey) {
|
|
|
3702
3793
|
lastRecoveryCheckAt: null
|
|
3703
3794
|
};
|
|
3704
3795
|
}
|
|
3705
|
-
function getOfflineStatusStorageKey(sessionKey) {
|
|
3706
|
-
return `tsdf.${sessionKey}._o_.s`;
|
|
3707
|
-
}
|
|
3708
3796
|
function normalizeCompactModeState(value) {
|
|
3709
3797
|
return {
|
|
3710
3798
|
enabled: value?.e === 1,
|
|
@@ -3750,7 +3838,7 @@ function normalizePersistedOfflineStatus(sessionKey, rawStatus) {
|
|
|
3750
3838
|
function readPersistedLocalSessionSnapshot(sessionKey) {
|
|
3751
3839
|
if (!isWindowAvailable()) return null;
|
|
3752
3840
|
try {
|
|
3753
|
-
const entry = parseCompactLocalStorageEntry(localStorage.getItem(
|
|
3841
|
+
const entry = parseCompactLocalStorageEntry(localStorage.getItem(getOfflineSessionStatusStorageKey(sessionKey)));
|
|
3754
3842
|
if (!entry) return null;
|
|
3755
3843
|
return normalizePersistedLocalSessionSnapshot(sessionKey, entry.value);
|
|
3756
3844
|
} catch {}
|
|
@@ -3861,7 +3949,7 @@ function normalizePersistedLocalSessionSnapshot(sessionKey, rawSnapshot) {
|
|
|
3861
3949
|
function createSessionPersistenceHandle(sessionKey, enabled, onPersistentStorageError, debugLogger) {
|
|
3862
3950
|
if (!enabled) return createNoopPersistentStorageHandle();
|
|
3863
3951
|
return createPersistentStorageHandle({
|
|
3864
|
-
storeName:
|
|
3952
|
+
storeName: OFFLINE_SESSION_STATUS_STORE_NAME,
|
|
3865
3953
|
adapter: "local-sync",
|
|
3866
3954
|
getSessionKey: () => sessionKey,
|
|
3867
3955
|
onPersistentStorageError,
|
|
@@ -6964,6 +7052,10 @@ const fetchTypePriority = {
|
|
|
6964
7052
|
mediumPriority: 2,
|
|
6965
7053
|
highPriority: 3
|
|
6966
7054
|
};
|
|
7055
|
+
/** Returns the higher-priority fetch type, treating a missing `a` as lower. */
|
|
7056
|
+
function higherFetchType(a, b) {
|
|
7057
|
+
return a && fetchTypePriority[a] > fetchTypePriority[b] ? a : b;
|
|
7058
|
+
}
|
|
6967
7059
|
const mutationSkipped = { kind: "skipped" };
|
|
6968
7060
|
/**
|
|
6969
7061
|
* Resolves a store-level option that may inherit from a manager-level fallback.
|
|
@@ -8665,7 +8757,7 @@ function useMultipleItems$1(items, { selector, returnIdleStatus: allItemsReturnI
|
|
|
8665
8757
|
if (!item) return;
|
|
8666
8758
|
item.refetchOnMount = false;
|
|
8667
8759
|
});
|
|
8668
|
-
scheduleAutomaticFetch(event.priority, payload);
|
|
8760
|
+
scheduleAutomaticFetch(event.priority !== "highPriority" && !store.state[itemKey]?.wasLoaded ? "highPriority" : event.priority, payload);
|
|
8669
8761
|
invalidationWasTriggered.add(itemKey);
|
|
8670
8762
|
}
|
|
8671
8763
|
}
|
|
@@ -12164,6 +12256,29 @@ function getGenuinelyMissingRequestedFields(itemKey, fallbackItemState, requeste
|
|
|
12164
12256
|
return fallbackMissingFields.filter((field) => !unresolvedPendingInvalidationFields.includes(field));
|
|
12165
12257
|
}
|
|
12166
12258
|
/**
|
|
12259
|
+
* Highest tracked invalidation priority owed to `requestedFields` (or to any
|
|
12260
|
+
* unresolved field when `requestedFields` is `undefined` — an unbounded hook).
|
|
12261
|
+
* Fields without a tracked priority (e.g. invalidations adopted from another
|
|
12262
|
+
* tab via state sync) contribute nothing, so an all-unknown result stays
|
|
12263
|
+
* `undefined` and callers treat the refetch as untracked (ungated, immediate).
|
|
12264
|
+
* The full-invalidation marker owes a requested field only when that field is
|
|
12265
|
+
* neither reloaded nor covered by a per-field entry (an entry supersedes the
|
|
12266
|
+
* marker for its field). A `'*'`-loaded item has already resolved the marker
|
|
12267
|
+
* (it only awaits pruning), so the marker contributes nothing then.
|
|
12268
|
+
*/
|
|
12269
|
+
function getPendingInvalidationPriorityOfFields(requestedFields, loadedFields, unresolvedPendingInvalidationFields, pendingFieldPriorities, fullInvalidationPriority) {
|
|
12270
|
+
let highestPriority;
|
|
12271
|
+
const fieldsToCheck = requestedFields ? requestedFields.filter((field) => unresolvedPendingInvalidationFields.includes(field)) : unresolvedPendingInvalidationFields;
|
|
12272
|
+
for (const field of fieldsToCheck) {
|
|
12273
|
+
const fieldPriority = pendingFieldPriorities?.get(field);
|
|
12274
|
+
if (fieldPriority) highestPriority = higherFetchType(highestPriority, fieldPriority);
|
|
12275
|
+
}
|
|
12276
|
+
if (fullInvalidationPriority !== void 0 && loadedFields !== "*") {
|
|
12277
|
+
if (requestedFields ? requestedFields.some((field) => !(loadedFields?.includes(field) ?? false) && !pendingFieldPriorities?.has(field)) : true) highestPriority = higherFetchType(highestPriority, fullInvalidationPriority);
|
|
12278
|
+
}
|
|
12279
|
+
return highestPriority;
|
|
12280
|
+
}
|
|
12281
|
+
/**
|
|
12167
12282
|
* Returns the fields from `requestedFields` that are not yet present in
|
|
12168
12283
|
* `loadedFields`. When either argument is `undefined` or empty, returns `[]`.
|
|
12169
12284
|
*/
|
|
@@ -12969,7 +13084,8 @@ function createFetchApi(store, normalizedFetchListFn, offsetPagination, fetchIte
|
|
|
12969
13084
|
function getUnresolvedPendingInvalidationFields(itemKey) {
|
|
12970
13085
|
const stateInvalidationFields = store.state.itemFieldInvalidationFields[itemKey];
|
|
12971
13086
|
if (stateInvalidationFields && stateInvalidationFields.length > 0) return stateInvalidationFields;
|
|
12972
|
-
|
|
13087
|
+
const pendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
13088
|
+
return excludeLoadedFields(store.state.itemLoadedFields[itemKey], pendingFields && Array.from(pendingFields.keys()));
|
|
12973
13089
|
}
|
|
12974
13090
|
/**
|
|
12975
13091
|
* Whether an item snapshot is fresh enough for a require-fresh
|
|
@@ -13257,7 +13373,7 @@ const GET_ALL = () => true;
|
|
|
13257
13373
|
//#endregion
|
|
13258
13374
|
//#region src/listQueryStore/createMutationApi.ts
|
|
13259
13375
|
/** @internal */
|
|
13260
|
-
function createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, onMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, emitInvalidateQuery, emitInvalidateItem, blockWindowClose, offlineController, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, onOfflineTimelineEvent, itemPendingInvalidationFields, itemsPendingFullInvalidation, itemDroppedFieldInvalidations) {
|
|
13376
|
+
function createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, onMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, emitInvalidateQuery, emitInvalidateItem, blockWindowClose, offlineController, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, onOfflineTimelineEvent, itemPendingInvalidationFields, itemsPendingFullInvalidation, itemDroppedFieldInvalidations, itemMutationCountsWithoutScheduler) {
|
|
13261
13377
|
const storeEvents = evtmitter();
|
|
13262
13378
|
const deferredOptimisticQueryInvalidationsStack = [];
|
|
13263
13379
|
const optimisticMutationQueryContextStack = [];
|
|
@@ -13284,10 +13400,12 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13284
13400
|
else draftState.queries[snapshot.queryKey] = snapshot.query;
|
|
13285
13401
|
}, { action: "rollback-mutation-error" });
|
|
13286
13402
|
for (const snapshot of itemSnapshots) {
|
|
13287
|
-
if (snapshot.invalidationPriority === void 0) itemFieldInvalidationPriorities.delete(snapshot.itemKey);
|
|
13288
|
-
else itemFieldInvalidationPriorities.set(snapshot.itemKey, snapshot.invalidationPriority);
|
|
13289
13403
|
if (snapshot.pendingInvalidationFields === void 0) itemPendingInvalidationFields.delete(snapshot.itemKey);
|
|
13290
|
-
else itemPendingInvalidationFields.set(snapshot.itemKey, snapshot.pendingInvalidationFields);
|
|
13404
|
+
else itemPendingInvalidationFields.set(snapshot.itemKey, new Map(snapshot.pendingInvalidationFields));
|
|
13405
|
+
if (snapshot.pendingFullInvalidation === void 0) itemsPendingFullInvalidation.delete(snapshot.itemKey);
|
|
13406
|
+
else itemsPendingFullInvalidation.set(snapshot.itemKey, snapshot.pendingFullInvalidation);
|
|
13407
|
+
if (snapshot.droppedFieldInvalidations === void 0) itemDroppedFieldInvalidations.delete(snapshot.itemKey);
|
|
13408
|
+
else itemDroppedFieldInvalidations.set(snapshot.itemKey, new Map(snapshot.droppedFieldInvalidations));
|
|
13291
13409
|
if (snapshot.invalidationWasTriggered) itemInvalidationWasTriggered.add(snapshot.itemKey);
|
|
13292
13410
|
else itemInvalidationWasTriggered.delete(snapshot.itemKey);
|
|
13293
13411
|
publishItemSnapshot(snapshot.itemKey);
|
|
@@ -13316,7 +13434,6 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13316
13434
|
}
|
|
13317
13435
|
const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
13318
13436
|
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
13319
|
-
const itemFieldInvalidationPriorities = /* @__PURE__ */ new Map();
|
|
13320
13437
|
/**
|
|
13321
13438
|
* The staleness baseline for invalidations: a field is invalidatable
|
|
13322
13439
|
* exactly when it is displayable, and hooks display the UNION of the
|
|
@@ -13361,8 +13478,6 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13361
13478
|
}
|
|
13362
13479
|
if (itemPayload) if (partialResources && invalidateFields) {
|
|
13363
13480
|
const itemsKey = getItemsKeyArray(itemPayload);
|
|
13364
|
-
const nextInvalidationPriorityByItemKey = /* @__PURE__ */ new Map();
|
|
13365
|
-
const nextPendingInvalidationFieldsByItemKey = /* @__PURE__ */ new Map();
|
|
13366
13481
|
const staleInvalidateFieldsByItemKey = /* @__PURE__ */ new Map();
|
|
13367
13482
|
for (const { itemKey } of itemsKey) {
|
|
13368
13483
|
const effectiveLoadedFields = getInvalidationBaselineFields(itemKey);
|
|
@@ -13378,19 +13493,29 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13378
13493
|
const existingDropped = droppedForItem.get(field);
|
|
13379
13494
|
droppedForItem.set(field, {
|
|
13380
13495
|
invalidatedAt: Date.now(),
|
|
13381
|
-
priority: existingDropped
|
|
13496
|
+
priority: higherFetchType(existingDropped?.priority, priority)
|
|
13382
13497
|
});
|
|
13383
13498
|
}
|
|
13384
13499
|
}
|
|
13385
13500
|
if (staleInvalidateFields.length === 0) continue;
|
|
13386
13501
|
staleInvalidateFieldsByItemKey.set(itemKey, staleInvalidateFields);
|
|
13387
|
-
const existingPriority = itemFieldInvalidationPriorities.get(itemKey);
|
|
13388
|
-
const existingPendingFields = itemPendingInvalidationFields.get(itemKey) ?? [];
|
|
13389
|
-
nextPendingInvalidationFieldsByItemKey.set(itemKey, Array.from(new Set([...existingPendingFields, ...staleInvalidateFields])).sort());
|
|
13390
|
-
nextInvalidationPriorityByItemKey.set(itemKey, existingPriority && fetchTypePriority[existingPriority] > fetchTypePriority[priority] ? existingPriority : priority);
|
|
13391
13502
|
}
|
|
13392
|
-
for (const [itemKey,
|
|
13393
|
-
|
|
13503
|
+
for (const [itemKey, staleInvalidateFields] of staleInvalidateFieldsByItemKey) {
|
|
13504
|
+
let pendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
13505
|
+
if (!pendingFields) {
|
|
13506
|
+
pendingFields = /* @__PURE__ */ new Map();
|
|
13507
|
+
itemPendingInvalidationFields.set(itemKey, pendingFields);
|
|
13508
|
+
}
|
|
13509
|
+
const fullInvalidationPriority = itemsPendingFullInvalidation.get(itemKey);
|
|
13510
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
13511
|
+
for (const field of staleInvalidateFields) {
|
|
13512
|
+
const existingPriority = pendingFields.get(field);
|
|
13513
|
+
if (existingPriority === null) continue;
|
|
13514
|
+
let fieldPriority = higherFetchType(existingPriority, priority);
|
|
13515
|
+
if (fullInvalidationPriority !== void 0 && loadedFields !== "*" && !(loadedFields?.includes(field) ?? false)) fieldPriority = higherFetchType(fullInvalidationPriority, fieldPriority);
|
|
13516
|
+
pendingFields.set(field, fieldPriority);
|
|
13517
|
+
}
|
|
13518
|
+
}
|
|
13394
13519
|
store.produceState((draft) => {
|
|
13395
13520
|
for (const [itemKey, staleInvalidateFields] of staleInvalidateFieldsByItemKey) {
|
|
13396
13521
|
const loadedFields = draft.itemLoadedFields[itemKey];
|
|
@@ -13403,7 +13528,7 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13403
13528
|
for (const [itemKey, staleInvalidateFields] of staleInvalidateFieldsByItemKey) {
|
|
13404
13529
|
itemInvalidationWasTriggered.delete(itemKey);
|
|
13405
13530
|
emitInvalidateItem({
|
|
13406
|
-
priority
|
|
13531
|
+
priority,
|
|
13407
13532
|
itemKey,
|
|
13408
13533
|
invalidateFields: staleInvalidateFields
|
|
13409
13534
|
});
|
|
@@ -13418,39 +13543,51 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13418
13543
|
if (!item) continue;
|
|
13419
13544
|
const effectiveLoadedFields = getInvalidationBaselineFields(itemKey);
|
|
13420
13545
|
const itemWasFullyLoaded = partialResources && effectiveLoadedFields === "*";
|
|
13421
|
-
const
|
|
13422
|
-
const
|
|
13423
|
-
|
|
13424
|
-
if ((item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1) >= fetchTypePriority[nextInvalidationPriority]) continue;
|
|
13546
|
+
const existingPendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
13547
|
+
const trackedInvalidationFields = partialResources && !itemWasFullyLoaded ? Array.from(new Set([...effectiveLoadedFields === "*" ? [] : effectiveLoadedFields ?? [], ...existingPendingFields?.keys() ?? []])).sort() : [];
|
|
13548
|
+
if ((item.refetchOnMount ? fetchTypePriority[item.refetchOnMount] : -1) >= fetchTypePriority[priority]) continue;
|
|
13425
13549
|
if (itemWasFullyLoaded) {
|
|
13426
|
-
itemsPendingFullInvalidation.
|
|
13427
|
-
|
|
13428
|
-
|
|
13550
|
+
itemsPendingFullInvalidation.set(itemKey, higherFetchType(itemsPendingFullInvalidation.get(itemKey), priority));
|
|
13551
|
+
if (existingPendingFields) {
|
|
13552
|
+
for (const [field, fieldPriority] of existingPendingFields) if (fieldPriority !== null) existingPendingFields.set(field, higherFetchType(fieldPriority, priority));
|
|
13553
|
+
}
|
|
13554
|
+
const trackedLoadedFields = store.state.itemLoadedFields[itemKey];
|
|
13555
|
+
if (trackedLoadedFields && trackedLoadedFields !== "*") {
|
|
13556
|
+
const pendingFields = existingPendingFields ?? /* @__PURE__ */ new Map();
|
|
13557
|
+
for (const field of trackedLoadedFields) if (!pendingFields.has(field)) pendingFields.set(field, priority);
|
|
13558
|
+
if (pendingFields.size > 0) itemPendingInvalidationFields.set(itemKey, pendingFields);
|
|
13559
|
+
}
|
|
13429
13560
|
} else if (trackedInvalidationFields.length > 0) {
|
|
13430
|
-
|
|
13431
|
-
|
|
13432
|
-
|
|
13433
|
-
|
|
13434
|
-
|
|
13435
|
-
|
|
13561
|
+
const markerPriority = itemsPendingFullInvalidation.get(itemKey);
|
|
13562
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
13563
|
+
const pendingFields = existingPendingFields ?? /* @__PURE__ */ new Map();
|
|
13564
|
+
for (const field of trackedInvalidationFields) {
|
|
13565
|
+
const existingPriority = pendingFields.get(field);
|
|
13566
|
+
if (existingPriority === null) continue;
|
|
13567
|
+
let fieldPriority = higherFetchType(existingPriority, priority);
|
|
13568
|
+
if (markerPriority !== void 0 && loadedFields !== "*" && !(loadedFields?.includes(field) ?? false)) fieldPriority = higherFetchType(markerPriority, fieldPriority);
|
|
13569
|
+
pendingFields.set(field, fieldPriority);
|
|
13570
|
+
}
|
|
13571
|
+
itemPendingInvalidationFields.set(itemKey, pendingFields);
|
|
13572
|
+
} else itemPendingInvalidationFields.delete(itemKey);
|
|
13436
13573
|
itemInvalidationWasTriggered.delete(itemKey);
|
|
13437
13574
|
store.produceState((draft) => {
|
|
13438
13575
|
const query = draft.itemQueries[itemKey];
|
|
13439
13576
|
if (!query) return;
|
|
13440
|
-
query.refetchOnMount =
|
|
13577
|
+
query.refetchOnMount = priority;
|
|
13441
13578
|
if (partialResources) {
|
|
13442
13579
|
draft.itemLoadedFields[itemKey] = [];
|
|
13443
13580
|
delete draft.itemFieldInvalidationFields[itemKey];
|
|
13444
13581
|
}
|
|
13445
13582
|
}, { action: "invalidate-item" });
|
|
13446
13583
|
emitInvalidateItem({
|
|
13447
|
-
priority
|
|
13584
|
+
priority,
|
|
13448
13585
|
itemKey
|
|
13449
13586
|
});
|
|
13450
13587
|
if (onInvalidateItem) {
|
|
13451
13588
|
const itemState = store.state.items[itemKey];
|
|
13452
13589
|
if (itemState) onInvalidateItem({
|
|
13453
|
-
priority
|
|
13590
|
+
priority,
|
|
13454
13591
|
itemState,
|
|
13455
13592
|
payload
|
|
13456
13593
|
});
|
|
@@ -13473,23 +13610,29 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13473
13610
|
const droppedForItem = itemDroppedFieldInvalidations.get(itemKey);
|
|
13474
13611
|
if (!droppedForItem) continue;
|
|
13475
13612
|
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
13476
|
-
let
|
|
13613
|
+
let staleFieldPriorities;
|
|
13477
13614
|
let stalePriority;
|
|
13478
13615
|
for (const [field, dropped] of droppedForItem) {
|
|
13479
13616
|
if (!(loadedFields === "*" || (loadedFields?.includes(field) ?? false))) continue;
|
|
13480
13617
|
droppedForItem.delete(field);
|
|
13481
13618
|
if (dropped.invalidatedAt > fetchStartedAt) {
|
|
13482
|
-
(
|
|
13483
|
-
|
|
13619
|
+
(staleFieldPriorities ??= /* @__PURE__ */ new Map()).set(field, dropped.priority);
|
|
13620
|
+
stalePriority = higherFetchType(stalePriority, dropped.priority);
|
|
13484
13621
|
}
|
|
13485
13622
|
}
|
|
13486
13623
|
if (droppedForItem.size === 0) itemDroppedFieldInvalidations.delete(itemKey);
|
|
13487
|
-
if (!
|
|
13488
|
-
const
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13624
|
+
if (!staleFieldPriorities || !stalePriority) continue;
|
|
13625
|
+
const staleFields = Array.from(staleFieldPriorities.keys());
|
|
13626
|
+
let pendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
13627
|
+
if (!pendingFields) {
|
|
13628
|
+
pendingFields = /* @__PURE__ */ new Map();
|
|
13629
|
+
itemPendingInvalidationFields.set(itemKey, pendingFields);
|
|
13630
|
+
}
|
|
13631
|
+
for (const [field, fieldPriority] of staleFieldPriorities) {
|
|
13632
|
+
const existingPriority = pendingFields.get(field);
|
|
13633
|
+
if (existingPriority === null) continue;
|
|
13634
|
+
pendingFields.set(field, higherFetchType(existingPriority, fieldPriority));
|
|
13635
|
+
}
|
|
13493
13636
|
const staleFieldsToApply = staleFields;
|
|
13494
13637
|
store.produceState((draft) => {
|
|
13495
13638
|
const draftLoadedFields = draft.itemLoadedFields[itemKey];
|
|
@@ -13500,7 +13643,7 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13500
13643
|
}, { action: "invalidate-item-fields" });
|
|
13501
13644
|
itemInvalidationWasTriggered.delete(itemKey);
|
|
13502
13645
|
emitInvalidateItem({
|
|
13503
|
-
priority:
|
|
13646
|
+
priority: stalePriority,
|
|
13504
13647
|
itemKey,
|
|
13505
13648
|
invalidateFields: staleFields
|
|
13506
13649
|
});
|
|
@@ -13513,6 +13656,17 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13513
13656
|
if (fetchItemFn) {
|
|
13514
13657
|
const itemScheduler = getOrCreateItemScheduler(itemKey, payload);
|
|
13515
13658
|
endMutations.push(itemScheduler.startMutation(itemKey));
|
|
13659
|
+
} else {
|
|
13660
|
+
itemMutationCountsWithoutScheduler.set(itemKey, (itemMutationCountsWithoutScheduler.get(itemKey) ?? 0) + 1);
|
|
13661
|
+
let ended = false;
|
|
13662
|
+
endMutations.push(() => {
|
|
13663
|
+
if (ended) return false;
|
|
13664
|
+
ended = true;
|
|
13665
|
+
const count = itemMutationCountsWithoutScheduler.get(itemKey) ?? 0;
|
|
13666
|
+
if (count <= 1) itemMutationCountsWithoutScheduler.delete(itemKey);
|
|
13667
|
+
else itemMutationCountsWithoutScheduler.set(itemKey, count - 1);
|
|
13668
|
+
return true;
|
|
13669
|
+
});
|
|
13516
13670
|
}
|
|
13517
13671
|
for (const [queryKey, query] of Object.entries(store.state.queries)) if (query.items.includes(itemKey)) endMutations.push(getOrCreateQueryScheduler(queryKey).startMutation(queryKey));
|
|
13518
13672
|
}
|
|
@@ -13707,7 +13861,6 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13707
13861
|
}
|
|
13708
13862
|
}, { action: "delete-item-state" });
|
|
13709
13863
|
for (const { itemKey } of itemsId) {
|
|
13710
|
-
itemFieldInvalidationPriorities.delete(itemKey);
|
|
13711
13864
|
itemPendingInvalidationFields.delete(itemKey);
|
|
13712
13865
|
itemsPendingFullInvalidation.delete(itemKey);
|
|
13713
13866
|
itemDroppedFieldInvalidations.delete(itemKey);
|
|
@@ -13720,7 +13873,6 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13720
13873
|
function resetInvalidationTracking() {
|
|
13721
13874
|
queryInvalidationWasTriggered.clear();
|
|
13722
13875
|
itemInvalidationWasTriggered.clear();
|
|
13723
|
-
itemFieldInvalidationPriorities.clear();
|
|
13724
13876
|
itemPendingInvalidationFields.clear();
|
|
13725
13877
|
itemsPendingFullInvalidation.clear();
|
|
13726
13878
|
itemDroppedFieldInvalidations.clear();
|
|
@@ -13739,16 +13891,21 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13739
13891
|
lockedQueryKeys: /* @__PURE__ */ new Set(),
|
|
13740
13892
|
queryRollbackSnapshots: /* @__PURE__ */ new Map()
|
|
13741
13893
|
};
|
|
13742
|
-
if (affectedItemEntries) itemRollbackSnapshots = affectedItemEntries.map(({ itemKey }) =>
|
|
13743
|
-
itemKey
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13894
|
+
if (affectedItemEntries) itemRollbackSnapshots = affectedItemEntries.map(({ itemKey }) => {
|
|
13895
|
+
const pendingInvalidationFields = itemPendingInvalidationFields.get(itemKey);
|
|
13896
|
+
const droppedFieldInvalidations = itemDroppedFieldInvalidations.get(itemKey);
|
|
13897
|
+
return {
|
|
13898
|
+
itemKey,
|
|
13899
|
+
item: klona(store.state.items[itemKey]),
|
|
13900
|
+
itemQuery: klona(store.state.itemQueries[itemKey]),
|
|
13901
|
+
loadedFields: klona(store.state.itemLoadedFields[itemKey]),
|
|
13902
|
+
invalidationFields: klona(store.state.itemFieldInvalidationFields[itemKey]),
|
|
13903
|
+
pendingInvalidationFields: pendingInvalidationFields && new Map(pendingInvalidationFields),
|
|
13904
|
+
pendingFullInvalidation: itemsPendingFullInvalidation.get(itemKey),
|
|
13905
|
+
droppedFieldInvalidations: droppedFieldInvalidations && new Map(droppedFieldInvalidations),
|
|
13906
|
+
invalidationWasTriggered: itemInvalidationWasTriggered.has(itemKey)
|
|
13907
|
+
};
|
|
13908
|
+
});
|
|
13752
13909
|
storeEvents.emit("mutationStart", {
|
|
13753
13910
|
mutationId,
|
|
13754
13911
|
items: affectedItems
|
|
@@ -13802,7 +13959,6 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13802
13959
|
storeEvents,
|
|
13803
13960
|
queryInvalidationWasTriggered,
|
|
13804
13961
|
itemInvalidationWasTriggered,
|
|
13805
|
-
itemFieldInvalidationPriorities,
|
|
13806
13962
|
invalidateQueryAndItems,
|
|
13807
13963
|
invalidateItem,
|
|
13808
13964
|
reannounceInvalidationsDroppedDuringFetch,
|
|
@@ -14168,7 +14324,7 @@ const cacheMissError = {
|
|
|
14168
14324
|
id: "cache-miss",
|
|
14169
14325
|
message: "Cache miss"
|
|
14170
14326
|
};
|
|
14171
|
-
function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, showPartialAsRefetching: allItemsShowPartialAsRefetching, disableRefetches: allItemsDisableRefetches, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, debouncePayload }, store, events, getItemKey, registerActiveItems, touchItems, scheduleAutomaticItemFetch, preloadItems, preloadItemsBeforePaint, readFallbackItemState, itemInvalidationWasTriggered,
|
|
14327
|
+
function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, showPartialAsRefetching: allItemsShowPartialAsRefetching, disableRefetches: allItemsDisableRefetches, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, debouncePayload }, store, events, getItemKey, registerActiveItems, touchItems, scheduleAutomaticItemFetch, preloadItems, preloadItemsBeforePaint, readFallbackItemState, itemInvalidationWasTriggered, itemPendingInvalidationFields, itemsPendingFullInvalidation, globalDisableRefetchOnMount, fetchItemFn, partialResources, offlineEntities, offlineOverlays) {
|
|
14172
14328
|
const isOffScreenFromContext = useContext(IsOffScreenContext);
|
|
14173
14329
|
const queriesWithId = useMemo(() => {
|
|
14174
14330
|
return items.map((itemProps) => {
|
|
@@ -14210,7 +14366,9 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14210
14366
|
const getUnresolvedPendingInvalidationFields = useCallback((itemKey, state) => {
|
|
14211
14367
|
const stateInvalidationFields = (state ? state.itemFieldInvalidationFields : store.state.itemFieldInvalidationFields)[itemKey];
|
|
14212
14368
|
if (stateInvalidationFields && stateInvalidationFields.length > 0) return stateInvalidationFields;
|
|
14213
|
-
|
|
14369
|
+
const itemLoadedFields = state ? state.itemLoadedFields : store.state.itemLoadedFields;
|
|
14370
|
+
const pendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
14371
|
+
return excludeLoadedFields(itemLoadedFields[itemKey], pendingFields && Array.from(pendingFields.keys()));
|
|
14214
14372
|
}, [itemPendingInvalidationFields, store]);
|
|
14215
14373
|
const resultSelector = useCallback((state) => {
|
|
14216
14374
|
return queriesWithId.map(({ itemKey, payload, fields, returnIdleStatus, returnRefetchingStatus, showPartialAsRefetching, queryMetadata }) => {
|
|
@@ -14409,6 +14567,25 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14409
14567
|
visibleStoreState
|
|
14410
14568
|
]);
|
|
14411
14569
|
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
14570
|
+
const itemHasMissingRequestedData = useCallback((itemKey, fields) => {
|
|
14571
|
+
const itemState = store.state.itemQueries[itemKey];
|
|
14572
|
+
if (itemState === null) return false;
|
|
14573
|
+
if (!itemState?.wasLoaded) return true;
|
|
14574
|
+
if (!partialResources) return false;
|
|
14575
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
14576
|
+
const item = store.state.items[itemKey];
|
|
14577
|
+
if (Array.isArray(fields) && fields.length > 0) return getGenuinelyMissingRequestedFields(itemKey, {
|
|
14578
|
+
item,
|
|
14579
|
+
loadedFields
|
|
14580
|
+
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey)).length > 0;
|
|
14581
|
+
if (fields === "*") return !(itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields) && !!item) && !snapshotIsFullyLoaded(loadedFields, item, partialResources.inferFields);
|
|
14582
|
+
return false;
|
|
14583
|
+
}, [
|
|
14584
|
+
getUnresolvedPendingInvalidationFields,
|
|
14585
|
+
itemsPendingFullInvalidation,
|
|
14586
|
+
partialResources,
|
|
14587
|
+
store
|
|
14588
|
+
]);
|
|
14412
14589
|
useOnEvtmitterEvent(events, "invalidateItem", ({ payload: event }) => {
|
|
14413
14590
|
if (loadFromStateOnly || !fetchItemFn) return;
|
|
14414
14591
|
const queriesForItem = fetchQueriesWithId.filter(({ itemKey }) => itemKey === event.itemKey);
|
|
@@ -14416,7 +14593,8 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14416
14593
|
if (event.invalidateFields && event.invalidateFields.length > 0) fieldsToFetch = Array.from(new Set(event.invalidateFields)).sort();
|
|
14417
14594
|
const hasUnresolvedFullInvalidation = itemsPendingFullInvalidation.has(event.itemKey);
|
|
14418
14595
|
const loadedFields = store.state.itemLoadedFields[event.itemKey];
|
|
14419
|
-
const
|
|
14596
|
+
const eventItemPendingFields = itemPendingInvalidationFields.get(event.itemKey);
|
|
14597
|
+
const owedStaleFields = new Set([...store.state.itemFieldInvalidationFields[event.itemKey] ?? [], ...excludeLoadedFields(loadedFields, eventItemPendingFields && Array.from(eventItemPendingFields.keys()))]);
|
|
14420
14598
|
const affectedQueries = fieldsToFetch ? queriesForItem.filter(({ fields }) => {
|
|
14421
14599
|
if (fields === "*") return true;
|
|
14422
14600
|
if (!fields || fields.length === 0) return true;
|
|
@@ -14432,11 +14610,12 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14432
14610
|
if (!firstQuery) return;
|
|
14433
14611
|
const hookFields = firstQuery.fields;
|
|
14434
14612
|
const isUnboundedHook = !hookFields || hookFields === "*" || hookFields.length === 0;
|
|
14613
|
+
const fetchPriority = event.priority !== "highPriority" && itemHasMissingRequestedData(event.itemKey, hookFields) ? "highPriority" : event.priority;
|
|
14435
14614
|
if (itemInvalidationWasTriggered.has(event.itemKey)) {
|
|
14436
14615
|
if (!fieldsToFetch) return;
|
|
14437
14616
|
const contributionFields = hasUnresolvedFullInvalidation ? isUnboundedHook ? void 0 : excludeLoadedFields(loadedFields, hookFields) : isUnboundedHook ? Array.from(owedStaleFields) : hookFields.filter((field) => owedStaleFields.has(field));
|
|
14438
14617
|
if (contributionFields && contributionFields.length === 0) return;
|
|
14439
|
-
scheduleAutomaticItemFetch(
|
|
14618
|
+
scheduleAutomaticItemFetch(fetchPriority, firstQuery.payload, { fields: contributionFields });
|
|
14440
14619
|
return;
|
|
14441
14620
|
}
|
|
14442
14621
|
if (fieldsToFetch) if (hasUnresolvedFullInvalidation) fieldsToFetch = isUnboundedHook ? void 0 : Array.from(new Set([...fieldsToFetch, ...excludeLoadedFields(loadedFields, hookFields)])).sort();
|
|
@@ -14449,7 +14628,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14449
14628
|
if (!query?.refetchOnMount) return;
|
|
14450
14629
|
query.refetchOnMount = false;
|
|
14451
14630
|
});
|
|
14452
|
-
scheduleAutomaticItemFetch(
|
|
14631
|
+
scheduleAutomaticItemFetch(fetchPriority, firstQuery.payload, { fields: fieldsToFetch ?? firstQuery.fields });
|
|
14453
14632
|
itemInvalidationWasTriggered.add(event.itemKey);
|
|
14454
14633
|
});
|
|
14455
14634
|
useLayoutEffect(() => {
|
|
@@ -14486,7 +14665,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14486
14665
|
const item = store.state.items[itemKey];
|
|
14487
14666
|
const unresolvedPendingInvalidationFields = getUnresolvedPendingInvalidationFields(itemKey);
|
|
14488
14667
|
const hasUnresolvedFullInvalidation = itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields);
|
|
14489
|
-
const invalidationPriority =
|
|
14668
|
+
const invalidationPriority = getPendingInvalidationPriorityOfFields(Array.isArray(fields) && fields.length > 0 ? fields : void 0, loadedFields, unresolvedPendingInvalidationFields, itemPendingInvalidationFields.get(itemKey), hasUnresolvedFullInvalidation ? itemsPendingFullInvalidation.get(itemKey) : void 0);
|
|
14490
14669
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
14491
14670
|
const staleOrMissingFields = getStaleOrMissingRequestedFields(itemKey, loadedFields, item, fields, partialResources.inferFields, itemsPendingFullInvalidation, unresolvedPendingInvalidationFields);
|
|
14492
14671
|
const missingFields = getGenuinelyMissingRequestedFields(itemKey, {
|
|
@@ -14517,18 +14696,11 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14517
14696
|
}
|
|
14518
14697
|
}
|
|
14519
14698
|
}
|
|
14520
|
-
if (itemState?.refetchOnMount && fetchType !== "highPriority")
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
|
|
14525
|
-
if (Array.isArray(fields) && fields.length > 0) hasMissingRequestedData = getGenuinelyMissingRequestedFields(itemKey, {
|
|
14526
|
-
item,
|
|
14527
|
-
loadedFields
|
|
14528
|
-
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey)).length > 0;
|
|
14529
|
-
else if (fields === "*") hasMissingRequestedData = !(itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields) && !!item) && !snapshotIsFullyLoaded(loadedFields, item, partialResources.inferFields);
|
|
14530
|
-
}
|
|
14531
|
-
if (hasMissingRequestedData) fetchType = "highPriority";
|
|
14699
|
+
if (itemState?.refetchOnMount && fetchType !== "highPriority" && itemHasMissingRequestedData(itemKey, fields)) fetchType = "highPriority";
|
|
14700
|
+
if (partialResources && itemState?.refetchOnMount && fetchType !== "highPriority") {
|
|
14701
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
14702
|
+
const invalidationPriority = getPendingInvalidationPriorityOfFields(Array.isArray(fields) && fields.length > 0 ? fields : void 0, loadedFields, getUnresolvedPendingInvalidationFields(itemKey), itemPendingInvalidationFields.get(itemKey), hasFullyLoadedFields(loadedFields) ? void 0 : itemsPendingFullInvalidation.get(itemKey));
|
|
14703
|
+
if (invalidationPriority && fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
14532
14704
|
}
|
|
14533
14705
|
if (!shouldFetch && ignoreItemsInRefetchOnMount.has(itemKey)) continue;
|
|
14534
14706
|
ignoreItemsInRefetchOnMount.add(itemKey);
|
|
@@ -14546,7 +14718,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14546
14718
|
fetchQueriesWithId,
|
|
14547
14719
|
getUnresolvedPendingInvalidationFields,
|
|
14548
14720
|
ignoreItemsInRefetchOnMount,
|
|
14549
|
-
|
|
14721
|
+
itemHasMissingRequestedData,
|
|
14550
14722
|
itemPendingInvalidationFields,
|
|
14551
14723
|
itemsPendingFullInvalidation,
|
|
14552
14724
|
loadFromStateOnly,
|
|
@@ -14560,7 +14732,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14560
14732
|
}
|
|
14561
14733
|
//#endregion
|
|
14562
14734
|
//#region src/listQueryStore/useMultipleListQueries.ts
|
|
14563
|
-
function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, showPartialAsRefetching: allItemsShowPartialAsRefetching, omitPayload: allItemsOmitPayload, disableRefetches: allItemsDisableRefetches, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, loadSize: allItemsLoadSize, debouncePayload }, store, events, getQueryKey, registerActiveQueries, touchQueries, getQueryState, readFallbackQueryState, preloadQueries, preloadQueriesBeforePaint, preloadDerivedQueryItems, readFallbackItemState, scheduleAutomaticListQueryFetch, queryInvalidationWasTriggered,
|
|
14735
|
+
function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, showPartialAsRefetching: allItemsShowPartialAsRefetching, omitPayload: allItemsOmitPayload, disableRefetches: allItemsDisableRefetches, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, loadSize: allItemsLoadSize, debouncePayload }, store, events, getQueryKey, registerActiveQueries, touchQueries, getQueryState, readFallbackQueryState, preloadQueries, preloadQueriesBeforePaint, preloadDerivedQueryItems, readFallbackItemState, scheduleAutomaticListQueryFetch, queryInvalidationWasTriggered, itemPendingInvalidationFields, itemsPendingFullInvalidation, globalDisableRefetchOnMount, partialResources, derivedQueries, isOfflineMode, offlineEntities, offlineOverlays) {
|
|
14564
14736
|
const isOffScreenFromContext = useContext(IsOffScreenContext);
|
|
14565
14737
|
const queriesWithId = useMemo(() => {
|
|
14566
14738
|
return queries.map((queryProps) => {
|
|
@@ -14671,23 +14843,21 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14671
14843
|
const getUnresolvedPendingInvalidationFields = useCallback((itemKey, state) => {
|
|
14672
14844
|
const stateInvalidationFields = (state ? state.itemFieldInvalidationFields : store.state.itemFieldInvalidationFields)[itemKey];
|
|
14673
14845
|
if (stateInvalidationFields && stateInvalidationFields.length > 0) return stateInvalidationFields;
|
|
14674
|
-
|
|
14846
|
+
const itemLoadedFields = state ? state.itemLoadedFields : store.state.itemLoadedFields;
|
|
14847
|
+
const pendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
14848
|
+
return excludeLoadedFields(itemLoadedFields[itemKey], pendingFields && Array.from(pendingFields.keys()));
|
|
14675
14849
|
}, [itemPendingInvalidationFields, store]);
|
|
14676
14850
|
const getHighestPendingInvalidationPriority = useCallback((itemKeys, requestedFields) => {
|
|
14677
14851
|
let highestPriority;
|
|
14678
14852
|
for (const itemKey of itemKeys) {
|
|
14679
|
-
const
|
|
14680
|
-
const
|
|
14681
|
-
if (
|
|
14682
|
-
if (!hasUnresolvedFullInvalidation && requestedFields && !requestedFields.some((field) => unresolvedInvalidationFields.includes(field))) continue;
|
|
14683
|
-
const itemPriority = itemFieldInvalidationPriorities.get(itemKey);
|
|
14684
|
-
if (!itemPriority) continue;
|
|
14685
|
-
if (!highestPriority || fetchTypePriority[itemPriority] > fetchTypePriority[highestPriority]) highestPriority = itemPriority;
|
|
14853
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
14854
|
+
const itemPriority = getPendingInvalidationPriorityOfFields(requestedFields, loadedFields, getUnresolvedPendingInvalidationFields(itemKey), itemPendingInvalidationFields.get(itemKey), loadedFields === "*" ? void 0 : itemsPendingFullInvalidation.get(itemKey));
|
|
14855
|
+
if (itemPriority) highestPriority = higherFetchType(highestPriority, itemPriority);
|
|
14686
14856
|
}
|
|
14687
14857
|
return highestPriority;
|
|
14688
14858
|
}, [
|
|
14689
14859
|
getUnresolvedPendingInvalidationFields,
|
|
14690
|
-
|
|
14860
|
+
itemPendingInvalidationFields,
|
|
14691
14861
|
itemsPendingFullInvalidation,
|
|
14692
14862
|
store
|
|
14693
14863
|
]);
|
|
@@ -15013,6 +15183,27 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
15013
15183
|
visibleStoreState
|
|
15014
15184
|
]);
|
|
15015
15185
|
const pendingOffScreenQueryInvalidations = useConst(() => /* @__PURE__ */ new Map());
|
|
15186
|
+
const queryItemsHaveMissingRequestedData = useCallback((itemKeys, fields) => {
|
|
15187
|
+
if (!partialResources) return false;
|
|
15188
|
+
if (Array.isArray(fields) && fields.length > 0) {
|
|
15189
|
+
for (const itemKey of itemKeys) if (getGenuinelyMissingRequestedFields(itemKey, {
|
|
15190
|
+
item: store.state.items[itemKey],
|
|
15191
|
+
loadedFields: store.state.itemLoadedFields[itemKey]
|
|
15192
|
+
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey)).length > 0) return true;
|
|
15193
|
+
return false;
|
|
15194
|
+
}
|
|
15195
|
+
if (fields === "*") for (const itemKey of itemKeys) {
|
|
15196
|
+
const item = store.state.items[itemKey];
|
|
15197
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
15198
|
+
if (!(itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields) && !!item) && !snapshotIsFullyLoaded(loadedFields, item, partialResources.inferFields)) return true;
|
|
15199
|
+
}
|
|
15200
|
+
return false;
|
|
15201
|
+
}, [
|
|
15202
|
+
getUnresolvedPendingInvalidationFields,
|
|
15203
|
+
itemsPendingFullInvalidation,
|
|
15204
|
+
partialResources,
|
|
15205
|
+
store
|
|
15206
|
+
]);
|
|
15016
15207
|
useOnEvtmitterEvent(events, "invalidateQuery", ({ payload: event }) => {
|
|
15017
15208
|
for (const { key, payload, fields, loadSize, isOffScreen, disableRefetches } of fetchQueriesWithId) {
|
|
15018
15209
|
if (key !== event.queryKey) continue;
|
|
@@ -15036,7 +15227,7 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
15036
15227
|
});
|
|
15037
15228
|
queryInvalidationWasTriggered.add(key);
|
|
15038
15229
|
}
|
|
15039
|
-
scheduleAutomaticListQueryFetch(event.priority, payload, loadSize, { fields });
|
|
15230
|
+
scheduleAutomaticListQueryFetch(event.priority !== "highPriority" && (!resolvedQuery || !resolvedQuery.query.wasLoaded && !resolvedQuery.isDerived || queryItemsHaveMissingRequestedData(resolvedQuery.query.items, fields)) ? "highPriority" : event.priority, payload, loadSize, { fields });
|
|
15040
15231
|
}
|
|
15041
15232
|
});
|
|
15042
15233
|
const ignoreQueriesInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
@@ -15132,27 +15323,10 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
15132
15323
|
}
|
|
15133
15324
|
}
|
|
15134
15325
|
}
|
|
15135
|
-
if (queryState?.refetchOnMount && fetchType !== "highPriority")
|
|
15136
|
-
|
|
15137
|
-
|
|
15138
|
-
|
|
15139
|
-
for (const itemKey of effectiveQueryState.items) if (getGenuinelyMissingRequestedFields(itemKey, {
|
|
15140
|
-
item: store.state.items[itemKey],
|
|
15141
|
-
loadedFields: store.state.itemLoadedFields[itemKey]
|
|
15142
|
-
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey)).length > 0) {
|
|
15143
|
-
hasMissingRequestedData = true;
|
|
15144
|
-
break;
|
|
15145
|
-
}
|
|
15146
|
-
} else if (fields === "*") for (const itemKey of effectiveQueryState.items) {
|
|
15147
|
-
const item = store.state.items[itemKey];
|
|
15148
|
-
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
15149
|
-
if (!(itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields) && !!item) && !snapshotIsFullyLoaded(loadedFields, item, partialResources.inferFields)) {
|
|
15150
|
-
hasMissingRequestedData = true;
|
|
15151
|
-
break;
|
|
15152
|
-
}
|
|
15153
|
-
}
|
|
15154
|
-
}
|
|
15155
|
-
if (hasMissingRequestedData) fetchType = "highPriority";
|
|
15326
|
+
if (queryState?.refetchOnMount && fetchType !== "highPriority" && (requiredFetch || effectiveQueryState && queryItemsHaveMissingRequestedData(effectiveQueryState.items, fields))) fetchType = "highPriority";
|
|
15327
|
+
if (partialResources && queryState?.refetchOnMount && fetchType !== "highPriority" && effectiveQueryState) {
|
|
15328
|
+
const invalidationPriority = getHighestPendingInvalidationPriority(effectiveQueryState.items, Array.isArray(fields) && fields.length > 0 ? fields : void 0);
|
|
15329
|
+
if (invalidationPriority && fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
15156
15330
|
}
|
|
15157
15331
|
const offScreenInvalidationPriority = pendingOffScreenQueryInvalidations.get(queryId);
|
|
15158
15332
|
if (offScreenInvalidationPriority !== void 0) {
|
|
@@ -15187,11 +15361,11 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
15187
15361
|
partialResources,
|
|
15188
15362
|
autoFetchSignals,
|
|
15189
15363
|
automaticRetryState,
|
|
15190
|
-
itemFieldInvalidationPriorities,
|
|
15191
15364
|
itemPendingInvalidationFields,
|
|
15192
15365
|
itemsPendingFullInvalidation,
|
|
15193
15366
|
getHighestPendingInvalidationPriority,
|
|
15194
15367
|
getUnresolvedPendingInvalidationFields,
|
|
15368
|
+
queryItemsHaveMissingRequestedData,
|
|
15195
15369
|
stickyDerivedQueryKeys
|
|
15196
15370
|
]);
|
|
15197
15371
|
useEffect(() => {
|
|
@@ -15598,8 +15772,9 @@ function createListQueryStore(storeOptions) {
|
|
|
15598
15772
|
}));
|
|
15599
15773
|
}
|
|
15600
15774
|
const itemPendingInvalidationFields = /* @__PURE__ */ new Map();
|
|
15601
|
-
const itemsPendingFullInvalidation = /* @__PURE__ */ new
|
|
15775
|
+
const itemsPendingFullInvalidation = /* @__PURE__ */ new Map();
|
|
15602
15776
|
const itemDroppedFieldInvalidations = /* @__PURE__ */ new Map();
|
|
15777
|
+
const itemMutationCountsWithoutScheduler = /* @__PURE__ */ new Map();
|
|
15603
15778
|
const { getQueryState, getQueriesKeyArray, getQueriesState, getQueriesRelatedToItem, getItemsKeyArray, getItemState, scheduleListQueryFetch, loadMore, awaitListQueryFetch, getQueryFromStateOrFetch, scheduleItemFetch, awaitItemFetch, getItemFromStateOrFetch, getOrCreateQueryScheduler, getOrCreateItemScheduler, getKnownQueryScheduler, getKnownItemScheduler, syncRemoteFetchStart, syncRemoteFetchSuccess, deleteQueryFetchResources, deleteItemFetchResources, resetSchedulers, reevaluateDelayedRTUs } = createFetchApi(store, normalizedFetchListFn, offsetPagination, fetchItemFn, batchFetchItemFn, getItemsBatchKey, errorNormalizer, partialResources, lowPriorityThrottleMs, getCoalescingWindowMs, mediumPriorityDelayMs, wrappedDynamicRealtimeThrottleMs, onSchedulerEvent, usesRealTimeUpdates, defaultQuerySize, maxItemBatchSize, getQueryKey, getItemKey, normalizeFieldsOption, !!persistence && !persistence.hasAsyncPreload, persistence ? (queryKeys) => persistence.preloadQueries(queryKeys) : void 0, persistence ? (itemKeys) => persistence.preloadItems(itemKeys) : void 0, persistence, testOptions?.initialLastFetchStartTime, (requests, startedAt) => {
|
|
15604
15779
|
const queryKey = requests[0]?.requestId;
|
|
15605
15780
|
if (!queryKey) return;
|
|
@@ -15666,11 +15841,11 @@ function createListQueryStore(storeOptions) {
|
|
|
15666
15841
|
for (const { itemKey } of successfulItems) publishItemSnapshot(itemKey, "confirmed");
|
|
15667
15842
|
}
|
|
15668
15843
|
}, offlineFetchController, itemPendingInvalidationFields, itemsPendingFullInvalidation);
|
|
15669
|
-
const { storeEvents, queryInvalidationWasTriggered, itemInvalidationWasTriggered,
|
|
15844
|
+
const { storeEvents, queryInvalidationWasTriggered, itemInvalidationWasTriggered, invalidateQueryAndItems, invalidateItem, reannounceInvalidationsDroppedDuringFetch, startItemMutation, updateItemState: updateItemStateBase, addItemToState: addItemToStateBase, deleteItemState: deleteItemStateBase, resetInvalidationTracking, performMutation: performMutationBase } = createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, resolvedOnMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, (event) => {
|
|
15670
15845
|
events.emit("invalidateQuery", event);
|
|
15671
15846
|
}, (event) => {
|
|
15672
15847
|
events.emit("invalidateItem", event);
|
|
15673
|
-
}, blockWindowClose, resolvedOfflineConfig ? offlineMutationController : null, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, void 0, itemPendingInvalidationFields, itemsPendingFullInvalidation, itemDroppedFieldInvalidations);
|
|
15848
|
+
}, blockWindowClose, resolvedOfflineConfig ? offlineMutationController : null, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, void 0, itemPendingInvalidationFields, itemsPendingFullInvalidation, itemDroppedFieldInvalidations, itemMutationCountsWithoutScheduler);
|
|
15674
15849
|
if (resolvedPersistentStorageConfig && resolvedOfflineConfig) offlineController = createOfflineStoreController(id, "listQuery", getSessionKeyForRuntime, resolvedPersistentStorageConfig.onPersistentStorageError, import.meta.env.DEV ? storeManager.debugLogger : void 0, resolvedPersistentStorageConfig.adapter, {
|
|
15675
15850
|
normalizeEntityRefs: (entityRefs) => entityRefs.map((ref) => {
|
|
15676
15851
|
const normalizedRef = offlineItemEntityRefSchema.parse(ref).unwrapOrNull();
|
|
@@ -15767,45 +15942,42 @@ function createListQueryStore(storeOptions) {
|
|
|
15767
15942
|
* a repeat cycle requires a new pending fetch at snapshot arrival.
|
|
15768
15943
|
*/
|
|
15769
15944
|
function emitRemainingInvalidationFieldsAfterSnapshot(itemKey) {
|
|
15770
|
-
const
|
|
15771
|
-
if (
|
|
15945
|
+
const fullInvalidationPriority = itemsPendingFullInvalidation.get(itemKey);
|
|
15946
|
+
if (fullInvalidationPriority !== void 0) {
|
|
15772
15947
|
events.emit("invalidateItem", {
|
|
15773
|
-
priority,
|
|
15948
|
+
priority: fullInvalidationPriority,
|
|
15774
15949
|
itemKey
|
|
15775
15950
|
});
|
|
15776
15951
|
return;
|
|
15777
15952
|
}
|
|
15953
|
+
const pendingFields = itemPendingInvalidationFields.get(itemKey);
|
|
15778
15954
|
const stateInvalidationFields = store.state.itemFieldInvalidationFields[itemKey];
|
|
15779
|
-
const remainingFields = stateInvalidationFields && stateInvalidationFields.length > 0 ? stateInvalidationFields : excludeLoadedFields(store.state.itemLoadedFields[itemKey],
|
|
15955
|
+
const remainingFields = stateInvalidationFields && stateInvalidationFields.length > 0 ? stateInvalidationFields : excludeLoadedFields(store.state.itemLoadedFields[itemKey], pendingFields && Array.from(pendingFields.keys()));
|
|
15780
15956
|
if (remainingFields.length === 0) return;
|
|
15957
|
+
let priority;
|
|
15958
|
+
for (const field of remainingFields) priority = higherFetchType(priority, pendingFields?.get(field) ?? "highPriority");
|
|
15781
15959
|
events.emit("invalidateItem", {
|
|
15782
|
-
priority,
|
|
15960
|
+
priority: priority ?? "highPriority",
|
|
15783
15961
|
itemKey,
|
|
15784
15962
|
invalidateFields: remainingFields
|
|
15785
15963
|
});
|
|
15786
15964
|
}
|
|
15787
15965
|
function pruneItemInvalidationTracking() {
|
|
15788
15966
|
for (const [itemKey, pendingFields] of itemPendingInvalidationFields) {
|
|
15789
|
-
const
|
|
15967
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
15790
15968
|
const stateInvalidationFields = store.state.itemFieldInvalidationFields[itemKey];
|
|
15791
|
-
|
|
15792
|
-
|
|
15793
|
-
|
|
15794
|
-
continue;
|
|
15969
|
+
for (const field of pendingFields.keys()) {
|
|
15970
|
+
if (stateInvalidationFields?.includes(field)) continue;
|
|
15971
|
+
if (loadedFields === "*" || (loadedFields?.includes(field) ?? false)) pendingFields.delete(field);
|
|
15795
15972
|
}
|
|
15796
|
-
if (
|
|
15797
|
-
|
|
15798
|
-
|
|
15799
|
-
|
|
15800
|
-
for (const itemKey of itemFieldInvalidationPriorities.keys()) {
|
|
15801
|
-
const hasPendingStateInvalidation = !!store.state.itemFieldInvalidationFields[itemKey];
|
|
15802
|
-
const hasPendingTrackedInvalidation = (itemPendingInvalidationFields.get(itemKey)?.length ?? 0) > 0;
|
|
15803
|
-
const hasPendingFullInvalidation = itemsPendingFullInvalidation.has(itemKey);
|
|
15804
|
-
if (!hasPendingStateInvalidation && !hasPendingTrackedInvalidation && !hasPendingFullInvalidation) itemFieldInvalidationPriorities.delete(itemKey);
|
|
15973
|
+
if (stateInvalidationFields) {
|
|
15974
|
+
for (const field of stateInvalidationFields) if (!pendingFields.has(field)) pendingFields.set(field, null);
|
|
15975
|
+
}
|
|
15976
|
+
if (pendingFields.size === 0) itemPendingInvalidationFields.delete(itemKey);
|
|
15805
15977
|
}
|
|
15978
|
+
for (const itemKey of itemsPendingFullInvalidation.keys()) if (store.state.itemLoadedFields[itemKey] === "*") itemsPendingFullInvalidation.delete(itemKey);
|
|
15806
15979
|
}
|
|
15807
15980
|
function cleanupItemStateMetadata(itemKey) {
|
|
15808
|
-
itemFieldInvalidationPriorities.delete(itemKey);
|
|
15809
15981
|
itemPendingInvalidationFields.delete(itemKey);
|
|
15810
15982
|
itemsPendingFullInvalidation.delete(itemKey);
|
|
15811
15983
|
itemDroppedFieldInvalidations.delete(itemKey);
|
|
@@ -15859,7 +16031,7 @@ function createListQueryStore(storeOptions) {
|
|
|
15859
16031
|
if (itemCacheRuntime.isActive(itemKey)) return true;
|
|
15860
16032
|
const scheduler = getKnownItemScheduler(itemKey);
|
|
15861
16033
|
if (itemQuery.status === "loading" || itemQuery.status === "refetching" || scheduler?.getFetchIsInProgress()) return true;
|
|
15862
|
-
return scheduler?.isMutationInProgress(itemKey) ?? false;
|
|
16034
|
+
return (scheduler?.isMutationInProgress(itemKey) ?? false) || itemMutationCountsWithoutScheduler.has(itemKey);
|
|
15863
16035
|
}
|
|
15864
16036
|
function mergeIncomingItemSnapshot(currentItem, incomingItem) {
|
|
15865
16037
|
if (!partialResources || incomingItem === null) return incomingItem;
|
|
@@ -16024,7 +16196,7 @@ function createListQueryStore(storeOptions) {
|
|
|
16024
16196
|
return state;
|
|
16025
16197
|
}, []);
|
|
16026
16198
|
const offlineOverlays = offlineOverlayStore.useSelectorRC(offlineOverlaysSelector);
|
|
16027
|
-
return useMultipleListQueries(queries, options, store, events, getQueryKey, registerActiveQueryRefs, touchQueries, getQueryState, persistence?.readHydratedQuery, persistence ? (payloads) => persistence.maybeHydrateQueries(payloads.map((payload) => getQueryKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence && derivedQueries ? (payloads) => persistence.preloadItemsByDerivedQueryGroup(payloads.map((payload) => derivedQueries.getQueryGroup(payload))) : void 0, persistence?.readHydratedItem, scheduleAutomaticListQueryFetch, queryInvalidationWasTriggered,
|
|
16199
|
+
return useMultipleListQueries(queries, options, store, events, getQueryKey, registerActiveQueryRefs, touchQueries, getQueryState, persistence?.readHydratedQuery, persistence ? (payloads) => persistence.maybeHydrateQueries(payloads.map((payload) => getQueryKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence && derivedQueries ? (payloads) => persistence.preloadItemsByDerivedQueryGroup(payloads.map((payload) => derivedQueries.getQueryGroup(payload))) : void 0, persistence?.readHydratedItem, scheduleAutomaticListQueryFetch, queryInvalidationWasTriggered, itemPendingInvalidationFields, itemsPendingFullInvalidation, globalDisableRefetchOnMount, partialResources, derivedQueries, isStoreOfflineMode, offlineEntities, offlineOverlays);
|
|
16028
16200
|
};
|
|
16029
16201
|
const useListQuery$2 = function useListQuery$1(payload, options = {}) {
|
|
16030
16202
|
return useListQuery(payload, options, store, getQueryKey, scheduleListQueryFetch, useMultipleListQueries$2);
|
|
@@ -16039,7 +16211,7 @@ function createListQueryStore(storeOptions) {
|
|
|
16039
16211
|
return state;
|
|
16040
16212
|
}, []);
|
|
16041
16213
|
const offlineOverlays = offlineOverlayStore.useSelectorRC(offlineOverlaysSelector);
|
|
16042
|
-
return useMultipleItems(items, options, store, events, getItemKey, registerActiveStandaloneItems, touchItems, scheduleAutomaticItemFetch, persistence ? (payloads) => persistence.maybeHydrateItems(payloads.map((payload) => getItemKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence?.readHydratedItem, itemInvalidationWasTriggered,
|
|
16214
|
+
return useMultipleItems(items, options, store, events, getItemKey, registerActiveStandaloneItems, touchItems, scheduleAutomaticItemFetch, persistence ? (payloads) => persistence.maybeHydrateItems(payloads.map((payload) => getItemKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence?.readHydratedItem, itemInvalidationWasTriggered, itemPendingInvalidationFields, itemsPendingFullInvalidation, globalDisableRefetchOnMount, fetchItemFn, partialResources, offlineEntities, offlineOverlays);
|
|
16043
16215
|
};
|
|
16044
16216
|
const useItem$3 = function useItem$2(itemPayload, options = {}) {
|
|
16045
16217
|
return useItem(itemPayload, options, store, scheduleItemFetch, useMultipleItems$3);
|
package/dist/opfs-storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as opfsPersistentStorage } from "./opfsPersistentStorage-
|
|
1
|
+
import { t as opfsPersistentStorage } from "./opfsPersistentStorage-B_lVflof.js";
|
|
2
2
|
export { opfsPersistentStorage };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as encodePersistedAsyncNamespaceKind, J as parsePersistedAsyncNamespaceKind, U as getNamespaceId, W as getPayloadRecordKey, _ as getTSDFDebugTimingMs, g as emitTSDFDebugLog, i as createAsyncStorageAdapter, q as parseAsyncStorageRecordKey } from "./asyncStorageAdapter-BBKVK1S_.js";
|
|
2
2
|
import { getCompositeKey } from "@ls-stack/utils/getCompositeKey";
|
|
3
3
|
import { __LEGIT_CAST__ } from "@ls-stack/utils/saferTyping";
|
|
4
4
|
import { isObject } from "@ls-stack/utils/typeGuards";
|
|
@@ -130,6 +130,8 @@ userStore.invalidateQueryAndItems({
|
|
|
130
130
|
|
|
131
131
|
This removes the specified fields from `itemLoadedFields`, causing hooks that request those fields to trigger a refetch — but only for those fields.
|
|
132
132
|
|
|
133
|
+
Invalidation priorities are tracked per field: each field keeps the highest priority it was invalidated with since it was last reloaded, and hooks adopt priorities only from the fields they actually request. A leftover obligation on a field no mounted hook displays (e.g. after a full high-priority invalidation followed by a narrower refetch) never escalates unrelated refetches, so scheduler throttling — such as `dynamicRealtimeThrottleMs` for realtime updates — keeps working.
|
|
134
|
+
|
|
133
135
|
## Loading Behavior
|
|
134
136
|
|
|
135
137
|
When a hook requests fields that are partially loaded:
|
|
@@ -137,7 +137,7 @@ TSDF does not choose a persistence adapter automatically. Pass one of the built-
|
|
|
137
137
|
- Can hydrate synchronously during initial state creation for `DocumentStore`.
|
|
138
138
|
- `CollectionStore` and `ListQueryStore` use lazy hydration for unknown entries from initial keys scan.
|
|
139
139
|
- Writes are debounced and may be dropped if serialization errors occur.
|
|
140
|
-
- When a write hits the browser `QuotaExceededError` (the shared origin quota is full, e.g. because other parts of the app filled `localStorage`), TSDF automatically evicts its own least recently used entries — across all TSDF stores and sessions — and retries, escalating to all non-offline-protected entries if needed. Offline data and non-TSDF keys are never touched. If even that cannot free enough space, a single descriptive error is reported through `onPersistentStorageError` and persistence writes are silently skipped until the next page load.
|
|
140
|
+
- When a write hits the browser `QuotaExceededError` (the shared origin quota is full, e.g. because other parts of the app filled `localStorage`), TSDF automatically evicts its own least recently used entries — across all TSDF stores and sessions — and retries, escalating to all non-offline-protected entries if needed. Offline data and non-TSDF keys are never touched. If even that cannot free enough space, a single descriptive error is reported through `onPersistentStorageError` and persistence writes are silently skipped until the next page load. Removals of persisted entries (e.g. after deleting an item) still go through while writes are disabled, so deleted data never resurrects on the next load.
|
|
141
141
|
|
|
142
142
|
Use it with:
|
|
143
143
|
|