tsdf 17.0.0-alpha.15 → 17.0.0-alpha.17

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.
@@ -1,2 +1,2 @@
1
- import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-B-pdNeAs.js";
1
+ import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-CGfnsd9m.js";
2
2
  export { createAsyncStorageAdapter };
@@ -20,6 +20,25 @@ function scheduleIdleCleanup(callback) {
20
20
  return () => clearTimeout(timeoutId);
21
21
  }
22
22
  }
23
+ const INITIAL_MAINTENANCE_CLEANUP_DELAY_MS = 1e4;
24
+ /**
25
+ * Gives startup maintenance a short grace period before using the regular
26
+ * idle cleanup scheduling.
27
+ */
28
+ function scheduleInitialMaintenanceCleanup(callback) {
29
+ if (typeof requestIdleCallback !== "function") {
30
+ const timeoutId = setTimeout(callback, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS + 2e3);
31
+ return () => clearTimeout(timeoutId);
32
+ }
33
+ let cancelIdleCleanup = null;
34
+ const timeoutId = setTimeout(() => {
35
+ cancelIdleCleanup = scheduleIdleCleanup(callback);
36
+ }, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS);
37
+ return () => {
38
+ clearTimeout(timeoutId);
39
+ cancelIdleCleanup?.();
40
+ };
41
+ }
23
42
  //#endregion
24
43
  //#region src/persistentStorage/asyncStorageShared.ts
25
44
  const PAYLOAD_RECORD_PREFIX = "__tsdf_payload__:";
@@ -896,6 +915,7 @@ var ManagedAsyncStorageAdapter = class {
896
915
  #pendingNamespaceCommits = /* @__PURE__ */ new Map();
897
916
  #readCacheGeneration = 0;
898
917
  #recentTouchedBuckets = /* @__PURE__ */ new Map();
918
+ #cancelStartupCleanup = null;
899
919
  #startupCleanupScheduled = false;
900
920
  constructor(driver) {
901
921
  this.#driver = driver;
@@ -1019,6 +1039,8 @@ var ManagedAsyncStorageAdapter = class {
1019
1039
  this.#observedScopes.clear();
1020
1040
  this.#pendingNamespaceCommits.clear();
1021
1041
  this.#recentTouchedBuckets.clear();
1042
+ this.#cancelStartupCleanup?.();
1043
+ this.#cancelStartupCleanup = null;
1022
1044
  this.#startupCleanupScheduled = false;
1023
1045
  this.#driver.__resetForTests?.();
1024
1046
  }
@@ -1537,7 +1559,8 @@ var ManagedAsyncStorageAdapter = class {
1537
1559
  #scheduleStartupCleanupIfNeeded() {
1538
1560
  if (this.#startupCleanupScheduled) return;
1539
1561
  this.#startupCleanupScheduled = true;
1540
- scheduleIdleCleanup(() => {
1562
+ this.#cancelStartupCleanup = scheduleInitialMaintenanceCleanup(() => {
1563
+ this.#cancelStartupCleanup = null;
1541
1564
  this.#runStartupCleanupIfDue().catch(() => {});
1542
1565
  });
1543
1566
  }
@@ -1919,4 +1942,4 @@ function serializeProtectedRef(ref) {
1919
1942
  return serializeProtectedRef$1(ref);
1920
1943
  }
1921
1944
  //#endregion
1922
- export { offlineResolutionRecordSchema as A, getNamespaceId as B, OfflineResolutionConflictParseError as C, isModeEffectivelyActive as D, getIsOfflineModeFromStatus as E, warnIfNavigatorLockUnavailable as F, parsePersistedAsyncNamespaceKind as G, getPersistedNamespaceId as H, createCompactLocalStorageEntry as I, serializeProtectedRef$1 as K, parseCompactLocalStorageEntry as L, getSessionProtectedKeysSnapshot as M, setSessionProtectedKeysSnapshot as N, isOfflineModeStatusValue as O, getNavigatorLockManager as P, compareMetadata as R, serializeJsonForStorage as S, defaultOfflineRuntimeConfig as T, normalizeStaticPolicy as U, getPayloadRecordKey as V, parseAsyncStorageRecordKey as W, getDefaultMaxBytesForScope as _, estimateManagedAsyncStorageEntrySizeBytes as a, getSerializedStringSize as b, readAsyncStorageNamespaceIndexStateUsingDriver as c, unregisterAsyncStartupStoreCleanup as d, parseAsyncStorageNamespaceKind as f, resolveTSDFLogger as g, getTSDFDebugTimingMs as h, createAsyncStorageAdapter as i, clearSessionProtectedKeysSnapshot as j, offlineItemEntityRefSchema as k, registerAsyncStartupStoreCleanup as l, emitTSDFDebugLog as m, ASYNC_STORAGE_MAX_AGE_MS as n, getProtectedKeysFromMetadata as o, logPersistentStorageQuotaCleanup as p, scheduleIdleCleanup as q, buildPersistedStaticPolicy as r, mergeManagedAsyncStorageCustomMetadata as s, ASYNC_MAINTENANCE_LOCAL_STORAGE_KEY as t, serializeProtectedRef as u, createShouldIgnoreItemPredicate as v, compactOfflineStatusSnapshotSchema as w, keepEntriesWithinByteBudget as x, createTimedKeySet as y, encodePersistedAsyncNamespaceKind as z };
1945
+ export { offlineResolutionRecordSchema as A, getNamespaceId as B, OfflineResolutionConflictParseError as C, isModeEffectivelyActive as D, getIsOfflineModeFromStatus as E, warnIfNavigatorLockUnavailable as F, parsePersistedAsyncNamespaceKind as G, getPersistedNamespaceId as H, createCompactLocalStorageEntry as I, scheduleIdleCleanup as J, serializeProtectedRef$1 as K, parseCompactLocalStorageEntry as L, getSessionProtectedKeysSnapshot as M, setSessionProtectedKeysSnapshot as N, isOfflineModeStatusValue as O, getNavigatorLockManager as P, compareMetadata as R, serializeJsonForStorage as S, defaultOfflineRuntimeConfig as T, normalizeStaticPolicy as U, getPayloadRecordKey as V, parseAsyncStorageRecordKey as W, getDefaultMaxBytesForScope as _, estimateManagedAsyncStorageEntrySizeBytes as a, getSerializedStringSize as b, readAsyncStorageNamespaceIndexStateUsingDriver as c, unregisterAsyncStartupStoreCleanup as d, parseAsyncStorageNamespaceKind as f, resolveTSDFLogger as g, getTSDFDebugTimingMs as h, createAsyncStorageAdapter as i, clearSessionProtectedKeysSnapshot as j, offlineItemEntityRefSchema as k, registerAsyncStartupStoreCleanup as l, emitTSDFDebugLog as m, ASYNC_STORAGE_MAX_AGE_MS as n, getProtectedKeysFromMetadata as o, logPersistentStorageQuotaCleanup as p, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS as q, buildPersistedStaticPolicy as r, mergeManagedAsyncStorageCustomMetadata as s, ASYNC_MAINTENANCE_LOCAL_STORAGE_KEY as t, serializeProtectedRef as u, createShouldIgnoreItemPredicate as v, compactOfflineStatusSnapshotSchema as w, keepEntriesWithinByteBudget as x, createTimedKeySet as y, encodePersistedAsyncNamespaceKind as z };
@@ -1,3 +1,3 @@
1
- import { t as opfsPersistentStorage } from "./opfsPersistentStorage-DobQJr0X.js";
2
- import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-D35uqEXv.js";
1
+ import { t as opfsPersistentStorage } from "./opfsPersistentStorage-DqJXzF7M.js";
2
+ import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-BlhAkfaB.js";
3
3
  export { indexedDbPersistentStorage, opfsPersistentStorage };
@@ -1,2 +1,2 @@
1
- import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-D35uqEXv.js";
1
+ import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-BlhAkfaB.js";
2
2
  export { createIndexedDbPersistentStorage, indexedDbPersistentStorage };
@@ -1,4 +1,4 @@
1
- import { B as getNamespaceId, G as parsePersistedAsyncNamespaceKind, H as getPersistedNamespaceId, K as serializeProtectedRef, R as compareMetadata, S as serializeJsonForStorage, U as normalizeStaticPolicy, V as getPayloadRecordKey, W as parseAsyncStorageRecordKey, a as estimateManagedAsyncStorageEntrySizeBytes, h as getTSDFDebugTimingMs, i as createAsyncStorageAdapter, m as emitTSDFDebugLog, z as encodePersistedAsyncNamespaceKind } from "./asyncStorageAdapter-B-pdNeAs.js";
1
+ import { B as getNamespaceId, G as parsePersistedAsyncNamespaceKind, H as getPersistedNamespaceId, K as serializeProtectedRef, R as compareMetadata, S as serializeJsonForStorage, U as normalizeStaticPolicy, V as getPayloadRecordKey, W as parseAsyncStorageRecordKey, a as estimateManagedAsyncStorageEntrySizeBytes, h as getTSDFDebugTimingMs, i as createAsyncStorageAdapter, m as emitTSDFDebugLog, z as encodePersistedAsyncNamespaceKind } from "./asyncStorageAdapter-CGfnsd9m.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 offlineResolutionRecordSchema, C as OfflineResolutionConflictParseError, D as isModeEffectivelyActive, E as getIsOfflineModeFromStatus, F as warnIfNavigatorLockUnavailable, G as parsePersistedAsyncNamespaceKind, I as createCompactLocalStorageEntry, K as serializeProtectedRef, L as parseCompactLocalStorageEntry, M as getSessionProtectedKeysSnapshot, N as setSessionProtectedKeysSnapshot, O as isOfflineModeStatusValue, P as getNavigatorLockManager, S as serializeJsonForStorage, T as defaultOfflineRuntimeConfig, V as getPayloadRecordKey, _ as getDefaultMaxBytesForScope, a as estimateManagedAsyncStorageEntrySizeBytes, b as getSerializedStringSize, c as readAsyncStorageNamespaceIndexStateUsingDriver, d as unregisterAsyncStartupStoreCleanup, f as parseAsyncStorageNamespaceKind, g as resolveTSDFLogger, h as getTSDFDebugTimingMs, j as clearSessionProtectedKeysSnapshot, k as offlineItemEntityRefSchema, l as registerAsyncStartupStoreCleanup, m as emitTSDFDebugLog, o as getProtectedKeysFromMetadata, p as logPersistentStorageQuotaCleanup, q as scheduleIdleCleanup, r as buildPersistedStaticPolicy, s as mergeManagedAsyncStorageCustomMetadata, u as serializeProtectedRef$1, v as createShouldIgnoreItemPredicate, w as compactOfflineStatusSnapshotSchema, x as keepEntriesWithinByteBudget, y as createTimedKeySet } from "./asyncStorageAdapter-B-pdNeAs.js";
2
- import { a as encodePathSegment, i as getNavigatorStorageDirectory, n as getDirectoryHandleIfExists, r as getFileHandleIfExists } from "./opfsPersistentStorage-DobQJr0X.js";
1
+ import { A as offlineResolutionRecordSchema, C as OfflineResolutionConflictParseError, D as isModeEffectivelyActive, E as getIsOfflineModeFromStatus, F as warnIfNavigatorLockUnavailable, G as parsePersistedAsyncNamespaceKind, I as createCompactLocalStorageEntry, J as scheduleIdleCleanup, K as serializeProtectedRef, L as parseCompactLocalStorageEntry, M as getSessionProtectedKeysSnapshot, N as setSessionProtectedKeysSnapshot, O as isOfflineModeStatusValue, P as getNavigatorLockManager, S as serializeJsonForStorage, T as defaultOfflineRuntimeConfig, V as getPayloadRecordKey, _ as getDefaultMaxBytesForScope, a as estimateManagedAsyncStorageEntrySizeBytes, b as getSerializedStringSize, c as readAsyncStorageNamespaceIndexStateUsingDriver, d as unregisterAsyncStartupStoreCleanup, f as parseAsyncStorageNamespaceKind, g as resolveTSDFLogger, h as getTSDFDebugTimingMs, j as clearSessionProtectedKeysSnapshot, k as offlineItemEntityRefSchema, l as registerAsyncStartupStoreCleanup, m as emitTSDFDebugLog, o as getProtectedKeysFromMetadata, p as logPersistentStorageQuotaCleanup, q as INITIAL_MAINTENANCE_CLEANUP_DELAY_MS, r as buildPersistedStaticPolicy, s as mergeManagedAsyncStorageCustomMetadata, u as serializeProtectedRef$1, v as createShouldIgnoreItemPredicate, w as compactOfflineStatusSnapshotSchema, x as keepEntriesWithinByteBudget, y as createTimedKeySet } from "./asyncStorageAdapter-CGfnsd9m.js";
2
+ import { a as encodePathSegment, i as getNavigatorStorageDirectory, n as getDirectoryHandleIfExists, r as getFileHandleIfExists } from "./opfsPersistentStorage-DqJXzF7M.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";
@@ -1257,7 +1257,9 @@ function scheduleAdapterExpirationScan(adapter) {
1257
1257
  if (adapter === "local-sync") {
1258
1258
  if (localStorageExpirationScanScheduled) return;
1259
1259
  localStorageExpirationScanScheduled = true;
1260
- scheduleLocalStorageMaintenance();
1260
+ setTimeout(() => {
1261
+ scheduleLocalStorageMaintenance();
1262
+ }, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS);
1261
1263
  return;
1262
1264
  }
1263
1265
  if (scannedAsyncAdapters.has(adapter)) return;
@@ -2174,7 +2176,7 @@ async function clearSessionStorage(sessionKey, adapter) {
2174
2176
  }
2175
2177
  /** Clears all persistent storage entries for a given session key across built-in adapters. */
2176
2178
  async function clearAllSessionStorage(sessionKey) {
2177
- const { indexedDbPersistentStorage, opfsPersistentStorage } = await import("./asyncStorageAdapters-0ObaLfne.js");
2179
+ const { indexedDbPersistentStorage, opfsPersistentStorage } = await import("./asyncStorageAdapters-xME9-DVC.js");
2178
2180
  await Promise.all([
2179
2181
  clearSessionStorage(sessionKey, "local-sync"),
2180
2182
  clearSessionStorage(sessionKey, opfsPersistentStorage),
@@ -7708,15 +7710,15 @@ async function performMutationWithLifecycle(startMutation, mutation, onError, op
7708
7710
  //#endregion
7709
7711
  //#region src/utils/storeFocusLifecycle.ts
7710
7712
  /** @internal */
7711
- function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowCanRunRevalidation, onWindowFocus, onWindowCanRunRevalidation, onWindowFocusRevalidate, onTransportReconnectRevalidate, debug) {
7713
+ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, onWindowFocus, onWindowFocusRevalidate, onTransportReconnectRevalidate, debug) {
7712
7714
  let cleanupFocusListener = null;
7713
- let cleanupReconnectRevalidationListener = null;
7715
+ let cleanupReconnectFocusListener = null;
7714
7716
  let reconnectCooldownTimeoutId = null;
7715
- let hasPendingReconnectRevalidate = false;
7717
+ let hasPendingReconnectRevalidateOnFocus = false;
7716
7718
  let lastTransportReconnectRevalidateAt = Number.NEGATIVE_INFINITY;
7717
- function clearReconnectRevalidationListener() {
7718
- cleanupReconnectRevalidationListener?.();
7719
- cleanupReconnectRevalidationListener = null;
7719
+ function clearReconnectFocusListener() {
7720
+ cleanupReconnectFocusListener?.();
7721
+ cleanupReconnectFocusListener = null;
7720
7722
  }
7721
7723
  function clearReconnectCooldownTimeout() {
7722
7724
  if (reconnectCooldownTimeoutId !== null) {
@@ -7745,26 +7747,25 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
7745
7747
  lastTransportReconnectRevalidateAt = Date.now();
7746
7748
  onTransportReconnectRevalidate();
7747
7749
  }
7748
- function ensureReconnectRevalidationListener() {
7749
- if (cleanupReconnectRevalidationListener) return;
7750
- cleanupReconnectRevalidationListener = onWindowCanRunRevalidation(() => {
7751
- if (!getWindowCanRunRevalidation()) return;
7752
- clearReconnectRevalidationListener();
7753
- if (!hasPendingReconnectRevalidate) return;
7754
- hasPendingReconnectRevalidate = false;
7750
+ function ensureReconnectFocusListener() {
7751
+ if (cleanupReconnectFocusListener) return;
7752
+ cleanupReconnectFocusListener = onWindowFocus(() => {
7753
+ clearReconnectFocusListener();
7754
+ if (!hasPendingReconnectRevalidateOnFocus) return;
7755
+ hasPendingReconnectRevalidateOnFocus = false;
7755
7756
  runTransportReconnectRevalidate();
7756
7757
  });
7757
7758
  }
7758
7759
  function flushTransportReconnectRevalidate() {
7759
7760
  clearReconnectCooldownTimeout();
7760
- if (getWindowCanRunRevalidation()) {
7761
- hasPendingReconnectRevalidate = false;
7762
- clearReconnectRevalidationListener();
7761
+ if (getWindowIsFocused()) {
7762
+ hasPendingReconnectRevalidateOnFocus = false;
7763
+ clearReconnectFocusListener();
7763
7764
  runTransportReconnectRevalidate();
7764
7765
  return;
7765
7766
  }
7766
- hasPendingReconnectRevalidate = true;
7767
- ensureReconnectRevalidationListener();
7767
+ hasPendingReconnectRevalidateOnFocus = true;
7768
+ ensureReconnectFocusListener();
7768
7769
  }
7769
7770
  function scheduleTrailingTransportReconnectRevalidate() {
7770
7771
  clearReconnectCooldownTimeout();
@@ -7776,9 +7777,9 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
7776
7777
  function reset() {
7777
7778
  cleanupFocusListener?.();
7778
7779
  cleanupFocusListener = null;
7779
- clearReconnectRevalidationListener();
7780
+ clearReconnectFocusListener();
7780
7781
  clearReconnectCooldownTimeout();
7781
- hasPendingReconnectRevalidate = false;
7782
+ hasPendingReconnectRevalidateOnFocus = false;
7782
7783
  lastTransportReconnectRevalidateAt = Number.NEGATIVE_INFINITY;
7783
7784
  if (!revalidateOnWindowFocus) return;
7784
7785
  if (usesRealTimeUpdates) {
@@ -7807,9 +7808,9 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
7807
7808
  function dispose() {
7808
7809
  cleanupFocusListener?.();
7809
7810
  cleanupFocusListener = null;
7810
- clearReconnectRevalidationListener();
7811
+ clearReconnectFocusListener();
7811
7812
  clearReconnectCooldownTimeout();
7812
- hasPendingReconnectRevalidate = false;
7813
+ hasPendingReconnectRevalidateOnFocus = false;
7813
7814
  lastTransportReconnectRevalidateAt = Number.NEGATIVE_INFINITY;
7814
7815
  }
7815
7816
  function onTransportReconnect() {
@@ -7818,7 +7819,7 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
7818
7819
  flushTransportReconnectRevalidate();
7819
7820
  return;
7820
7821
  }
7821
- if (hasPendingReconnectRevalidate) return;
7822
+ if (hasPendingReconnectRevalidateOnFocus) return;
7822
7823
  if (Date.now() - lastTransportReconnectRevalidateAt >= transportReconnectCooldownMs) {
7823
7824
  flushTransportReconnectRevalidate();
7824
7825
  return;
@@ -7833,25 +7834,6 @@ function createStoreFocusLifecycle(revalidateOnWindowFocus, usesRealTimeUpdates,
7833
7834
  };
7834
7835
  }
7835
7836
  //#endregion
7836
- //#region src/utils/windowRevalidation.ts
7837
- /** @internal */
7838
- function isWindowVisible() {
7839
- return document.visibilityState === "visible";
7840
- }
7841
- /** @internal */
7842
- function onWindowVisible(handler) {
7843
- window.addEventListener("focus", handler);
7844
- window.addEventListener("pageshow", handler);
7845
- window.addEventListener("visibilitychange", handler);
7846
- document.addEventListener("visibilitychange", handler);
7847
- return () => {
7848
- window.removeEventListener("focus", handler);
7849
- window.removeEventListener("pageshow", handler);
7850
- window.removeEventListener("visibilitychange", handler);
7851
- document.removeEventListener("visibilitychange", handler);
7852
- };
7853
- }
7854
- //#endregion
7855
7837
  //#region src/collectionStore/collectionCacheLimits.ts
7856
7838
  /** @internal */
7857
7839
  function createCollectionCacheLimits(store, maxItems, itemCacheRuntime, isProtectedFromEviction, cleanupItemResources, onStateCleanup) {
@@ -8666,7 +8648,6 @@ function createCollectionStore(storeOptions) {
8666
8648
  return false;
8667
8649
  }
8668
8650
  const getWindowIsFocused = testOptions?.getWindowIsFocused ?? isWindowFocused;
8669
- const getWindowCanRunRevalidation = testOptions?.getWindowCanRunRevalidation ?? isWindowVisible;
8670
8651
  function runWithoutBroadcast(callback) {
8671
8652
  remoteApplyDepth++;
8672
8653
  try {
@@ -9227,7 +9208,7 @@ function createCollectionStore(storeOptions) {
9227
9208
  if (!offline && result.ok && result.value.kind === "online") return Result.ok(result.value.data);
9228
9209
  return result;
9229
9210
  }
9230
- const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowCanRunRevalidation, testOptions?.onWindowFocus ?? onWindowFocus, testOptions?.onWindowCanRunRevalidation ?? onWindowVisible, () => {
9211
+ const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, testOptions?.onWindowFocus ?? onWindowFocus, () => {
9231
9212
  invalidateItem(() => true, "lowPriority");
9232
9213
  }, () => {
9233
9214
  invalidateItem(() => true, "realtimeUpdate");
@@ -9250,12 +9231,12 @@ function createCollectionStore(storeOptions) {
9250
9231
  * items need to be revalidated.
9251
9232
  *
9252
9233
  * - No-op when `usesRealTimeUpdates` is `false`.
9253
- * - If the window is visible, the first reconnect invalidates all items
9234
+ * - If the window is focused, the first reconnect invalidates all items
9254
9235
  * immediately with `realtimeUpdate` priority.
9255
9236
  * - Additional reconnects within `transportReconnectCooldownMs` are
9256
9237
  * coalesced into one trailing invalidation.
9257
- * - If the window is hidden, reconnect invalidation waits until the next
9258
- * window visibility/resume event.
9238
+ * - If the window is **not** focused, reconnect invalidation waits until the
9239
+ * next window focus event.
9259
9240
  */
9260
9241
  function onTransportReconnect() {
9261
9242
  if (isDisposed) return;
@@ -9698,7 +9679,6 @@ function createDocumentStore(storeOptions) {
9698
9679
  const events = evtmitter();
9699
9680
  const storeEvents = evtmitter();
9700
9681
  const getWindowIsFocused = testOptions?.getWindowIsFocused ?? isWindowFocused;
9701
- const getWindowCanRunRevalidation = testOptions?.getWindowCanRunRevalidation ?? isWindowVisible;
9702
9682
  function runWithoutBroadcast(callback) {
9703
9683
  remoteApplyDepth++;
9704
9684
  try {
@@ -9859,7 +9839,7 @@ function createDocumentStore(storeOptions) {
9859
9839
  usesRealTimeUpdates
9860
9840
  });
9861
9841
  if (initialStatus !== "idle" || initialData !== null || initialError !== null) scheduler.setLastFetchStartTimeForRequest(DOC_REQUEST_ID, testOptions?.initialLastFetchStartTime ?? 0);
9862
- const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowCanRunRevalidation, testOptions?.onWindowFocus ?? onWindowFocus, testOptions?.onWindowCanRunRevalidation ?? onWindowVisible, () => {
9842
+ const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, testOptions?.onWindowFocus ?? onWindowFocus, () => {
9863
9843
  invalidateData("lowPriority");
9864
9844
  }, () => {
9865
9845
  invalidateData("realtimeUpdate");
@@ -9937,12 +9917,12 @@ function createDocumentStore(storeOptions) {
9937
9917
  * needs to be revalidated.
9938
9918
  *
9939
9919
  * - No-op when `usesRealTimeUpdates` is `false`.
9940
- * - If the window is visible, the first reconnect invalidates immediately with
9941
- * `realtimeUpdate` priority.
9920
+ * - If the window is focused, the first reconnect invalidates immediately
9921
+ * with `realtimeUpdate` priority.
9942
9922
  * - Additional reconnects within `transportReconnectCooldownMs` are coalesced
9943
9923
  * into one trailing invalidation.
9944
- * - If the window is hidden, reconnect invalidation waits until the next
9945
- * window visibility/resume event.
9924
+ * - If the window is **not** focused, reconnect invalidation waits until the
9925
+ * next window focus event.
9946
9926
  */
9947
9927
  function onTransportReconnect() {
9948
9928
  if (isDisposed) return;
@@ -14816,7 +14796,6 @@ function createListQueryStore(storeOptions) {
14816
14796
  return false;
14817
14797
  }
14818
14798
  const getWindowIsFocused = testOptions?.getWindowIsFocused ?? isWindowFocused;
14819
- const getWindowCanRunRevalidation = testOptions?.getWindowCanRunRevalidation ?? isWindowVisible;
14820
14799
  function runWithoutBroadcast(callback) {
14821
14800
  remoteApplyDepth++;
14822
14801
  try {
@@ -15371,7 +15350,7 @@ function createListQueryStore(storeOptions) {
15371
15350
  function useFindItem$1(findItemFn, options = {}) {
15372
15351
  return useFindItem(findItemFn, options, store, registerActiveStandaloneItems, touchItems);
15373
15352
  }
15374
- const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowCanRunRevalidation, testOptions?.onWindowFocus ?? onWindowFocus, testOptions?.onWindowCanRunRevalidation ?? onWindowVisible, () => {
15353
+ const focusLifecycle = createStoreFocusLifecycle(resolvedRevalidateOnWindowFocus, usesRealTimeUpdates, transportReconnectCooldownMs, getWindowIsFocused, testOptions?.onWindowFocus ?? onWindowFocus, () => {
15375
15354
  invalidateQueryAndItems({
15376
15355
  all: true,
15377
15356
  type: "lowPriority"
@@ -15406,12 +15385,12 @@ function createListQueryStore(storeOptions) {
15406
15385
  * queries and items need to be revalidated.
15407
15386
  *
15408
15387
  * - No-op when `usesRealTimeUpdates` is `false`.
15409
- * - If the window is visible, the first reconnect invalidates all queries
15388
+ * - If the window is focused, the first reconnect invalidates all queries
15410
15389
  * and items immediately with `realtimeUpdate` priority.
15411
15390
  * - Additional reconnects within `transportReconnectCooldownMs` are
15412
15391
  * coalesced into one trailing invalidation.
15413
- * - If the window is hidden, reconnect invalidation waits until the next
15414
- * window visibility/resume event.
15392
+ * - If the window is **not** focused, reconnect invalidation waits until the
15393
+ * next window focus event.
15415
15394
  */
15416
15395
  function onTransportReconnect() {
15417
15396
  if (isDisposed) return;
@@ -1,2 +1,2 @@
1
- import { t as opfsPersistentStorage } from "./opfsPersistentStorage-DobQJr0X.js";
1
+ import { t as opfsPersistentStorage } from "./opfsPersistentStorage-DqJXzF7M.js";
2
2
  export { opfsPersistentStorage };
@@ -1,4 +1,4 @@
1
- import { B as getNamespaceId, G as parsePersistedAsyncNamespaceKind, V as getPayloadRecordKey, W as parseAsyncStorageRecordKey, h as getTSDFDebugTimingMs, i as createAsyncStorageAdapter, m as emitTSDFDebugLog, z as encodePersistedAsyncNamespaceKind } from "./asyncStorageAdapter-B-pdNeAs.js";
1
+ import { B as getNamespaceId, G as parsePersistedAsyncNamespaceKind, V as getPayloadRecordKey, W as parseAsyncStorageRecordKey, h as getTSDFDebugTimingMs, i as createAsyncStorageAdapter, m as emitTSDFDebugLog, z as encodePersistedAsyncNamespaceKind } from "./asyncStorageAdapter-CGfnsd9m.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";
@@ -132,4 +132,4 @@ TSDF automatically invalidates data in these scenarios:
132
132
  - **Mutation error**: After a failed mutation, affected data is invalidated to revert optimistic updates
133
133
  - **Mutation success with `revalidateOnSuccess`**: Affected data is invalidated to fetch the server's actual state
134
134
  - **Window focus**: When `revalidateOnWindowFocus` is enabled, all data is invalidated with `lowPriority`
135
- - **Transport reconnect**: When `onTransportReconnect()` is called, all data is invalidated with `realtimeUpdate` priority as soon as the document is visible. See [Real-Time Updates](./real-time-updates.md)
135
+ - **Transport reconnect**: When `onTransportReconnect()` is called, all data is invalidated with `realtimeUpdate` priority. See [Real-Time Updates](./real-time-updates.md)
@@ -104,9 +104,9 @@ Store-level `store.onTransportReconnect()` remains available for stores backed b
104
104
 
105
105
  Behavior:
106
106
 
107
- - If the document is **visible**: all data is invalidated immediately with `realtimeUpdate` priority, even when the browser does not report strict focus
108
- - If the document is **hidden**: invalidation is deferred until the app becomes visible or resumes
109
- - Multiple reconnect calls while hidden are coalesced (only one invalidation fires on resume)
107
+ - If the window is **focused**: all data is invalidated immediately with `realtimeUpdate` priority
108
+ - If the window is **not focused**: invalidation is deferred until the window regains focus
109
+ - Multiple reconnect calls while unfocused are coalesced (only one invalidation fires on focus)
110
110
  - This is a no-op when `usesRealTimeUpdates` is `false`
111
111
 
112
112
  ## Pattern: WebSocket Integration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdf",
3
- "version": "17.0.0-alpha.15",
3
+ "version": "17.0.0-alpha.17",
4
4
  "description": "A data fetching solution based on t-state",
5
5
  "license": "PolyForm-Noncommercial-1.0.0",
6
6
  "author": "Lucas Santos",