tsdf 17.0.4 → 17.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/dist/async-storage.d.ts +1 -1
  2. package/dist/async-storage.js +1 -1
  3. package/dist/{asyncStorageAdapter-CMohMeKm.d.ts → asyncStorageAdapter-DgsuE-T8.d.ts} +1 -1
  4. package/dist/{asyncStorageAdapter-BuGjbXYA.js → asyncStorageAdapter-URS9eulL.js} +165 -25
  5. package/dist/{asyncStorageAdapters-ClUvxNQA.js → asyncStorageAdapters-Bxrrj_Mt.js} +2 -2
  6. package/dist/indexed-db-storage.d.ts +1 -1
  7. package/dist/indexed-db-storage.js +1 -1
  8. package/dist/{indexedDbPersistentStorage-BSlgLveB.js → indexedDbPersistentStorage-BameJ4st.js} +11 -1
  9. package/dist/main.d.ts +34 -30
  10. package/dist/main.js +856 -257
  11. package/dist/opfs-storage.d.ts +1 -1
  12. package/dist/opfs-storage.js +1 -1
  13. package/dist/{opfsPersistentStorage-Ci0JcCo5.d.ts → opfsPersistentStorage-BngS1m0X.d.ts} +1 -1
  14. package/dist/{opfsPersistentStorage-D_k77Srq.js → opfsPersistentStorage-JsSCNBTr.js} +1 -1
  15. package/dist/{types-D0ttVGmj.d.ts → types-BlyGC_PO.d.ts} +3 -3
  16. package/package.json +1 -1
  17. package/dist/src/async-storage.d.ts +0 -1
  18. package/dist/src/cacheLimits/lruCacheRuntime.d.ts +0 -9
  19. package/dist/src/cacheLimits/scheduleIdleThrottled.d.ts +0 -1
  20. package/dist/src/cacheLimits/useRegisterActiveKeys.d.ts +0 -1
  21. package/dist/src/collectionStore/collectionCacheLimits.d.ts +0 -1
  22. package/dist/src/collectionStore/collectionStore.d.ts +0 -385
  23. package/dist/src/collectionStore/executeBatchFetch.d.ts +0 -6
  24. package/dist/src/collectionStore/useItem.d.ts +0 -15
  25. package/dist/src/collectionStore/useMultipleItems.d.ts +0 -35
  26. package/dist/src/debug.d.ts +0 -30
  27. package/dist/src/documentStore.d.ts +0 -290
  28. package/dist/src/hooks/useListItem.d.ts +0 -22
  29. package/dist/src/hooks/useListItemIsDeleted.d.ts +0 -13
  30. package/dist/src/hooks/useListItemIsLoading.d.ts +0 -16
  31. package/dist/src/indexed-db-storage.d.ts +0 -1
  32. package/dist/src/internal/offlineTestInstrumentation.d.ts +0 -12
  33. package/dist/src/internal/testTimelineTypes.d.ts +0 -1
  34. package/dist/src/invalidationUtils.d.ts +0 -8
  35. package/dist/src/isOffScreenContext.d.ts +0 -16
  36. package/dist/src/listQueryStore/createFetchApi.d.ts +0 -1
  37. package/dist/src/listQueryStore/createMutationApi.d.ts +0 -1
  38. package/dist/src/listQueryStore/executeItemBatchFetch.d.ts +0 -20
  39. package/dist/src/listQueryStore/executeQueryFetch.d.ts +0 -7
  40. package/dist/src/listQueryStore/itemFieldUtils.d.ts +0 -77
  41. package/dist/src/listQueryStore/listQueryCacheLimits.d.ts +0 -1
  42. package/dist/src/listQueryStore/listQueryStore.d.ts +0 -538
  43. package/dist/src/listQueryStore/types.d.ts +0 -347
  44. package/dist/src/listQueryStore/useFindItem.d.ts +0 -7
  45. package/dist/src/listQueryStore/useItem.d.ts +0 -29
  46. package/dist/src/listQueryStore/useListQuery.d.ts +0 -29
  47. package/dist/src/listQueryStore/useMultipleItems.d.ts +0 -44
  48. package/dist/src/listQueryStore/useMultipleListQueries.d.ts +0 -46
  49. package/dist/src/listQueryStore/usePendingOfflineItems.d.ts +0 -19
  50. package/dist/src/main.d.ts +0 -23
  51. package/dist/src/opfs-storage.d.ts +0 -1
  52. package/dist/src/persistentStorage/asyncStorageAdapter.d.ts +0 -95
  53. package/dist/src/persistentStorage/asyncStorageAdapters.d.ts +0 -2
  54. package/dist/src/persistentStorage/asyncStorageShared.d.ts +0 -23
  55. package/dist/src/persistentStorage/collectionStorePersistence.d.ts +0 -26
  56. package/dist/src/persistentStorage/compactListQueryLocalStorageEntry.d.ts +0 -11
  57. package/dist/src/persistentStorage/compactLocalStorageEntry.d.ts +0 -8
  58. package/dist/src/persistentStorage/documentEntryKey.d.ts +0 -1
  59. package/dist/src/persistentStorage/documentStorePersistence.d.ts +0 -17
  60. package/dist/src/persistentStorage/indexedDbAsyncStorageAdapter.d.ts +0 -165
  61. package/dist/src/persistentStorage/indexedDbPersistentStorage.d.ts +0 -6
  62. package/dist/src/persistentStorage/listQueryStorePersistence.d.ts +0 -37
  63. package/dist/src/persistentStorage/localStorageMetadata.d.ts +0 -126
  64. package/dist/src/persistentStorage/navigatorLocks.d.ts +0 -3
  65. package/dist/src/persistentStorage/offline/entityMetadata.d.ts +0 -12
  66. package/dist/src/persistentStorage/offline/fetchRuntime.d.ts +0 -35
  67. package/dist/src/persistentStorage/offline/mutationRuntime.d.ts +0 -31
  68. package/dist/src/persistentStorage/offline/offlineResolution.typeGuards.d.ts +0 -1
  69. package/dist/src/persistentStorage/offline/overlayStoreLifecycle.d.ts +0 -13
  70. package/dist/src/persistentStorage/offline/sessionCoordinator.d.ts +0 -94
  71. package/dist/src/persistentStorage/offline/sessionProtectionRegistry.d.ts +0 -11
  72. package/dist/src/persistentStorage/offline/storeController.d.ts +0 -86
  73. package/dist/src/persistentStorage/offline/types.d.ts +0 -1255
  74. package/dist/src/persistentStorage/offlineUploadRegistry.d.ts +0 -11
  75. package/dist/src/persistentStorage/offlineUploadTypes.d.ts +0 -97
  76. package/dist/src/persistentStorage/offlineUploadsShared.d.ts +0 -4
  77. package/dist/src/persistentStorage/opfsAsyncStorageAdapter.d.ts +0 -24
  78. package/dist/src/persistentStorage/opfsFileNaming.d.ts +0 -23
  79. package/dist/src/persistentStorage/opfsHelpers.d.ts +0 -3
  80. package/dist/src/persistentStorage/opfsOfflineUploadAdapter.d.ts +0 -2
  81. package/dist/src/persistentStorage/opfsPersistentStorage.d.ts +0 -2
  82. package/dist/src/persistentStorage/parsePersistedData.d.ts +0 -45
  83. package/dist/src/persistentStorage/persistenceUtils.d.ts +0 -52
  84. package/dist/src/persistentStorage/persistentStorageDefaults.d.ts +0 -4
  85. package/dist/src/persistentStorage/persistentStorageManager.d.ts +0 -197
  86. package/dist/src/persistentStorage/quotaDebug.d.ts +0 -16
  87. package/dist/src/persistentStorage/scheduleIdleCleanup.d.ts +0 -28
  88. package/dist/src/persistentStorage/storageAdapter.d.ts +0 -41
  89. package/dist/src/persistentStorage/storageEntryPrefixes.d.ts +0 -16
  90. package/dist/src/persistentStorage/types.d.ts +0 -412
  91. package/dist/src/persistentStorage/validateWithSchema.d.ts +0 -12
  92. package/dist/src/requestScheduler.d.ts +0 -81
  93. package/dist/src/storeManager.d.ts +0 -160
  94. package/dist/src/utils/automaticFetchPolicy.d.ts +0 -29
  95. package/dist/src/utils/browserTabsPriority.d.ts +0 -43
  96. package/dist/src/utils/browserTabsSync.d.ts +0 -33
  97. package/dist/src/utils/optimisticMutationTracker.d.ts +0 -20
  98. package/dist/src/utils/optimisticRollback.d.ts +0 -11
  99. package/dist/src/utils/payloadDebounce.d.ts +0 -5
  100. package/dist/src/utils/performMutation.d.ts +0 -19
  101. package/dist/src/utils/reusePrevIfEqual.d.ts +0 -1
  102. package/dist/src/utils/storeFocusLifecycle.d.ts +0 -1
  103. package/dist/src/utils/storeShared.d.ts +0 -126
  104. package/dist/src/utils/useEnsureIsLoaded.d.ts +0 -6
  105. package/dist/src/utils/useRequireFreshData.d.ts +0 -6
  106. package/dist/tests/basic-functionality/collection-store.test.d.ts +0 -1
  107. package/dist/tests/basic-functionality/document-store.test.d.ts +0 -1
  108. package/dist/tests/basic-functionality/list-query-state-manipulation.test.d.ts +0 -1
  109. package/dist/tests/basic-functionality/list-query-store.test.d.ts +0 -1
  110. package/dist/tests/browser-tabs/browser-tabs-background-rtu-batch.test.d.ts +0 -1
  111. package/dist/tests/browser-tabs/browser-tabs-background-rtu.test.d.ts +0 -1
  112. package/dist/tests/browser-tabs/browser-tabs-background-scheduling.test.d.ts +0 -1
  113. package/dist/tests/browser-tabs/browser-tabs-list-query-pagination.test.d.ts +0 -1
  114. package/dist/tests/browser-tabs/browser-tabs-non-cancelable-fetches.test.d.ts +0 -1
  115. package/dist/tests/browser-tabs/browser-tabs-optimistic-sync.test.d.ts +0 -1
  116. package/dist/tests/browser-tabs/browser-tabs-partial-resources.test.d.ts +0 -1
  117. package/dist/tests/browser-tabs/browser-tabs-priority.test.d.ts +0 -1
  118. package/dist/tests/browser-tabs/browser-tabs-snapshot-consistency.test.d.ts +0 -1
  119. package/dist/tests/browser-tabs/browser-tabs-state-methods.test.d.ts +0 -1
  120. package/dist/tests/browser-tabs/browser-tabs-sync-coordinator.test.d.ts +0 -1
  121. package/dist/tests/browser-tabs/browser-tabs-test-helpers.d.ts +0 -69
  122. package/dist/tests/browser-tabs/focus-coordinator.test.d.ts +0 -1
  123. package/dist/tests/hooks/collection-hooks-2.test.d.ts +0 -1
  124. package/dist/tests/hooks/collection-hooks.test.d.ts +0 -1
  125. package/dist/tests/hooks/collection-useListItem.test.d.ts +0 -1
  126. package/dist/tests/hooks/debounce-payload-hooks.test.d.ts +0 -1
  127. package/dist/tests/hooks/disable-refetches.test.d.ts +0 -1
  128. package/dist/tests/hooks/document-hooks-2.test.d.ts +0 -1
  129. package/dist/tests/hooks/document-hooks.test.d.ts +0 -1
  130. package/dist/tests/hooks/document-useListItem.test.d.ts +0 -1
  131. package/dist/tests/hooks/fetch-error-recovery.test.d.ts +0 -1
  132. package/dist/tests/hooks/hook-memoization.test.d.ts +0 -1
  133. package/dist/tests/hooks/list-query-hooks-2.test.d.ts +0 -1
  134. package/dist/tests/hooks/list-query-hooks-3.test.d.ts +0 -1
  135. package/dist/tests/hooks/list-query-hooks-mutations.test.d.ts +0 -1
  136. package/dist/tests/hooks/list-query-hooks.test.d.ts +0 -1
  137. package/dist/tests/hooks/list-query-pending-offline-items.test.d.ts +0 -1
  138. package/dist/tests/hooks/off-screen-context.test.d.ts +0 -1
  139. package/dist/tests/list-query-features/list-query-derived-queries.test.d.ts +0 -1
  140. package/dist/tests/list-query-features/list-query-offset-pagination.test.d.ts +0 -1
  141. package/dist/tests/list-query-features/list-query-optimistic-filters.test.d.ts +0 -1
  142. package/dist/tests/list-query-features/list-query-partial-resources-2.test.d.ts +0 -1
  143. package/dist/tests/list-query-features/list-query-partial-resources-3.test.d.ts +0 -1
  144. package/dist/tests/list-query-features/list-query-partial-resources-regressions.test.d.ts +0 -1
  145. package/dist/tests/list-query-features/list-query-partial-resources-show-partial-status.test.d.ts +0 -1
  146. package/dist/tests/list-query-features/list-query-partial-resources.test.d.ts +0 -1
  147. package/dist/tests/list-query-features/list-query-size-coalescing-partial-resources.test.d.ts +0 -1
  148. package/dist/tests/mocks/browserTabsTestUtils.d.ts +0 -17
  149. package/dist/tests/mocks/collectionStoreTestEnv.d.ts +0 -265
  150. package/dist/tests/mocks/documentStoreTestEnv.d.ts +0 -140
  151. package/dist/tests/mocks/duplicateStoreGuard.test.d.ts +0 -1
  152. package/dist/tests/mocks/listQueryStoreTestEnv.d.ts +0 -295
  153. package/dist/tests/mocks/mockBrowserOpfs.d.ts +0 -70
  154. package/dist/tests/mocks/mockBrowserOpfs.test.d.ts +0 -1
  155. package/dist/tests/mocks/mockLocalStorageStore.d.ts +0 -61
  156. package/dist/tests/mocks/seedScenarioPersistentStorage.d.ts +0 -51
  157. package/dist/tests/mocks/serverMock.d.ts +0 -56
  158. package/dist/tests/mocks/serverTableMock.d.ts +0 -174
  159. package/dist/tests/mocks/testEnvUtils.d.ts +0 -120
  160. package/dist/tests/mocks/testScenarioPersistentStorage.test.d.ts +0 -1
  161. package/dist/tests/offline/offline-fetching-scenarios.test.d.ts +0 -1
  162. package/dist/tests/offline/offline-mixed-adapter-storage.test.d.ts +0 -1
  163. package/dist/tests/offline/offline-mutation-fallback.test.d.ts +0 -1
  164. package/dist/tests/offline/offline-network-recovery.test.d.ts +0 -1
  165. package/dist/tests/offline/offline-outage.test.d.ts +0 -1
  166. package/dist/tests/offline/offline-overlays.test.d.ts +0 -1
  167. package/dist/tests/offline/offline-query-replay.test.d.ts +0 -1
  168. package/dist/tests/offline/offline-reads.test.d.ts +0 -1
  169. package/dist/tests/offline/offline-replay-conflicts.test.d.ts +0 -1
  170. package/dist/tests/offline/offline-replay-queueing.test.d.ts +0 -1
  171. package/dist/tests/offline/offline-resolution-dependencies.test.d.ts +0 -1
  172. package/dist/tests/offline/offline-runtime-controls.test.d.ts +0 -1
  173. package/dist/tests/offline/offline-session-and-global-state.test.d.ts +0 -1
  174. package/dist/tests/offline/offline-storage.test.d.ts +0 -1
  175. package/dist/tests/offline/offline-uploads.test.d.ts +0 -1
  176. package/dist/tests/offline/offlineReplayTestShared.d.ts +0 -292
  177. package/dist/tests/offline/offlineTestShared.d.ts +0 -156
  178. package/dist/tests/perform-mutation/mutation-error-rollback.test.d.ts +0 -1
  179. package/dist/tests/perform-mutation/perform-mutation-block-window-close.test.d.ts +0 -1
  180. package/dist/tests/perform-mutation/perform-mutation-debounce.test.d.ts +0 -1
  181. package/dist/tests/perform-mutation/store-events.test.d.ts +0 -1
  182. package/dist/tests/persistent-storage/async-storage-efficiency/collection.test.d.ts +0 -1
  183. package/dist/tests/persistent-storage/async-storage-efficiency/document.test.d.ts +0 -1
  184. package/dist/tests/persistent-storage/async-storage-efficiency/list-query.test.d.ts +0 -1
  185. package/dist/tests/persistent-storage/async-storage-efficiency/maintenance.test.d.ts +0 -1
  186. package/dist/tests/persistent-storage/async-storage-efficiency/shared.d.ts +0 -804
  187. package/dist/tests/persistent-storage/async-storage-shared.test.d.ts +0 -1
  188. package/dist/tests/persistent-storage/collection-store-persistence.converted.opfs.test.d.ts +0 -1
  189. package/dist/tests/persistent-storage/collection-store-persistence.converted.test.d.ts +0 -1
  190. package/dist/tests/persistent-storage/collection-store-persistence.opfs.test.d.ts +0 -1
  191. package/dist/tests/persistent-storage/collection-store-persistence.test.d.ts +0 -1
  192. package/dist/tests/persistent-storage/document-store-persistence.converted.opfs.test.d.ts +0 -1
  193. package/dist/tests/persistent-storage/document-store-persistence.converted.test.d.ts +0 -1
  194. package/dist/tests/persistent-storage/document-store-persistence.opfs.test.d.ts +0 -1
  195. package/dist/tests/persistent-storage/document-store-persistence.test.d.ts +0 -1
  196. package/dist/tests/persistent-storage/expiration-scan.test.d.ts +0 -1
  197. package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/collection.test.d.ts +0 -1
  198. package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/document.test.d.ts +0 -1
  199. package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/list-query.test.d.ts +0 -1
  200. package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/maintenance.test.d.ts +0 -1
  201. package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/shared.d.ts +0 -780
  202. package/dist/tests/persistent-storage/indexeddb-storage-adapter.test.d.ts +0 -1
  203. package/dist/tests/persistent-storage/list-query-store-persistence.converted.opfs.test.d.ts +0 -1
  204. package/dist/tests/persistent-storage/list-query-store-persistence.converted.test.d.ts +0 -1
  205. package/dist/tests/persistent-storage/list-query-store-persistence.opfs.test.d.ts +0 -1
  206. package/dist/tests/persistent-storage/list-query-store-persistence.test.d.ts +0 -1
  207. package/dist/tests/persistent-storage/persistence-with-tabs-sync.test.d.ts +0 -1
  208. package/dist/tests/persistent-storage/persistentStorageByteBudgetTestUtils.d.ts +0 -18
  209. package/dist/tests/persistent-storage/quota-exceeded-recovery-no-locks.test.d.ts +0 -1
  210. package/dist/tests/persistent-storage/quota-exceeded-recovery.test.d.ts +0 -1
  211. package/dist/tests/persistent-storage/quotaRecoveryTestUtils.d.ts +0 -228
  212. package/dist/tests/persistent-storage/storage-adapter.test.d.ts +0 -1
  213. package/dist/tests/persistent-storage/sync-storage-efficiency/collection.test.d.ts +0 -1
  214. package/dist/tests/persistent-storage/sync-storage-efficiency/document.test.d.ts +0 -1
  215. package/dist/tests/persistent-storage/sync-storage-efficiency/list-query.test.d.ts +0 -1
  216. package/dist/tests/persistent-storage/sync-storage-efficiency/maintenance.test.d.ts +0 -1
  217. package/dist/tests/persistent-storage/sync-storage-efficiency/shared.d.ts +0 -784
  218. package/dist/tests/playwright/browser-tabs.spec.d.ts +0 -1
  219. package/dist/tests/playwright/persistent-storage.spec.d.ts +0 -1
  220. package/dist/tests/request-schedulling/batch-medium-priority.test.d.ts +0 -1
  221. package/dist/tests/request-schedulling/batch-realtime-updates.test.d.ts +0 -1
  222. package/dist/tests/request-schedulling/collection-batch-coalescing.test.d.ts +0 -1
  223. package/dist/tests/request-schedulling/collection-batch-key-grouping.test.d.ts +0 -1
  224. package/dist/tests/request-schedulling/collection-fetch-orchestration.test.d.ts +0 -1
  225. package/dist/tests/request-schedulling/document-await-fetch.test.d.ts +0 -1
  226. package/dist/tests/request-schedulling/document-base-coalescing.test.d.ts +0 -1
  227. package/dist/tests/request-schedulling/document-fetch-orchestration.test.d.ts +0 -1
  228. package/dist/tests/request-schedulling/document-medium-priority-fetch.test.d.ts +0 -1
  229. package/dist/tests/request-schedulling/document-realtime-updates.test.d.ts +0 -1
  230. package/dist/tests/request-schedulling/list-query-item-batch-coalescing.test.d.ts +0 -1
  231. package/dist/tests/request-schedulling/list-query-item-batch-key-grouping.test.d.ts +0 -1
  232. package/dist/tests/request-schedulling/list-query-size-coalescing.test.d.ts +0 -1
  233. package/dist/tests/request-schedulling/medium-vs-realtime.test.d.ts +0 -1
  234. package/dist/tests/request-schedulling/request-scheduler-cross-tab-sync.test.d.ts +0 -1
  235. package/dist/tests/request-schedulling/window-focus.test.d.ts +0 -1
  236. package/dist/tests/store-manager.test.d.ts +0 -1
  237. package/dist/tests/user-facing-api/collection-offline-usage.test.d.ts +0 -1
  238. package/dist/tests/user-facing-api/document-offline-usage.test.d.ts +0 -1
  239. package/dist/tests/user-facing-api/list-query-offline-usage.test.d.ts +0 -1
  240. package/dist/tests/user-facing-api/result-returning-callbacks.test.d.ts +0 -1
  241. package/dist/tests/utils/genericTestUtils.d.ts +0 -6
  242. package/dist/tests/utils/indexedDbPersistentStorageOptimizationTestUtils.d.ts +0 -79
  243. package/dist/tests/utils/indexedDbPersistentStorageTestStore.d.ts +0 -181
  244. package/dist/tests/utils/listQueryHooksTestUtils.d.ts +0 -8
  245. package/dist/tests/utils/networkMock.d.ts +0 -11
  246. package/dist/tests/utils/opfsPersistentStorageTestStore.d.ts +0 -220
  247. package/dist/tests/utils/persistentStorageOptimizationTestUtils.d.ts +0 -54
  248. package/dist/tests/utils/persistentStorageOptimizationTestUtils.test.d.ts +0 -1
  249. package/dist/tests/utils/persistentStorageTestStore.d.ts +0 -66
  250. package/dist/tests/utils/resetSessionForTests.d.ts +0 -3
  251. package/dist/tests/utils/withSuppressedActError.d.ts +0 -4
@@ -1,2 +1,2 @@
1
- import { t as createAsyncStorageAdapter } from "./asyncStorageAdapter-CMohMeKm.js";
1
+ import { t as createAsyncStorageAdapter } from "./asyncStorageAdapter-DgsuE-T8.js";
2
2
  export { createAsyncStorageAdapter };
@@ -1,2 +1,2 @@
1
- import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-BuGjbXYA.js";
1
+ import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-URS9eulL.js";
2
2
  export { createAsyncStorageAdapter };
@@ -1,4 +1,4 @@
1
- import { r as AsyncStorageDriver, t as AsyncStorageAdapter } from "./types-D0ttVGmj.js";
1
+ import { r as AsyncStorageDriver, t as AsyncStorageAdapter } from "./types-BlyGC_PO.js";
2
2
 
3
3
  //#region src/persistentStorage/asyncStorageAdapter.d.ts
4
4
  declare function createAsyncStorageAdapter(driver: AsyncStorageDriver): AsyncStorageAdapter;
@@ -1,8 +1,9 @@
1
+ import { filterAndMap } from "@ls-stack/utils/arrayUtils";
2
+ import { deepEqual } from "@ls-stack/utils/deepEqual";
1
3
  import { __LEGIT_CAST__ } from "@ls-stack/utils/saferTyping";
2
4
  import { klona } from "klona/json";
3
5
  import { isObject } from "@ls-stack/utils/typeGuards";
4
6
  import { createCache } from "@ls-stack/utils/cache";
5
- import { deepEqual } from "@ls-stack/utils/deepEqual";
6
7
  import { sleep } from "@ls-stack/utils/sleep";
7
8
  import { rc_array, rc_discriminated_union, rc_literals, rc_number, rc_object, rc_parse, rc_parse_json, rc_record, rc_string, rc_tuple, rc_unknown } from "runcheck";
8
9
  import { asPossiblyUndefined } from "@ls-stack/utils/typingFnUtils";
@@ -192,6 +193,10 @@ function compareMetadata(left, right, order) {
192
193
  if (left.lastAccessAt !== right.lastAccessAt) return order === "lru-asc" ? left.lastAccessAt - right.lastAccessAt : right.lastAccessAt - left.lastAccessAt;
193
194
  return left.key.localeCompare(right.key);
194
195
  }
196
+ /** Whether an entry still has the metadata a conditional remove expects. */
197
+ function matchesConditionalRemove(remove, lastAccessAt, sizeBytes, version, offlineProtected) {
198
+ return remove.lastAccessAt === lastAccessAt && remove.sizeBytes === sizeBytes && remove.version === version && remove.offlineProtected === offlineProtected;
199
+ }
195
200
  //#endregion
196
201
  //#region src/persistentStorage/compactLocalStorageEntry.ts
197
202
  function createCompactLocalStorageEntry(value, version) {
@@ -410,6 +415,41 @@ function serializeJsonForStorage(value) {
410
415
  sizeBytes: getSerializedStringSize(rawValue)
411
416
  };
412
417
  }
418
+ /**
419
+ * Removes planned async maintenance entries in bounded batches. Each batch is
420
+ * a conditional remove, so entries other code or tabs changed since planning
421
+ * are kept as stale in the same write instead of being deleted through an
422
+ * outdated plan. The plan itself is never restarted, so every deadline makes
423
+ * progress. `shouldContinue` is checked around every batch so a plan never
424
+ * outlives the session it was built for; `onRemoved` only runs while it holds.
425
+ */
426
+ async function removeAsyncMaintenanceEntriesIfUnchanged(plannedEntries, isOfflineProtected, removeIfUnchanged, onRemoved, batchSize, shouldContinue, idleContext) {
427
+ let hasStaleEntries = false;
428
+ for (let batchStart = 0; batchStart < plannedEntries.length; batchStart += batchSize) {
429
+ if (!await idleContext.yieldIfNeeded() || !shouldContinue()) return {
430
+ completed: false,
431
+ hasStaleEntries
432
+ };
433
+ const batch = plannedEntries.slice(batchStart, batchStart + batchSize).map((entry) => ({
434
+ key: entry.key,
435
+ lastAccessAt: entry.lastAccessAt,
436
+ sizeBytes: entry.sizeBytes,
437
+ version: entry.version,
438
+ offlineProtected: isOfflineProtected(entry.customMetadata)
439
+ }));
440
+ const staleKeys = await removeIfUnchanged(batch);
441
+ if (staleKeys === null || idleContext.isCanceled() || !shouldContinue()) return {
442
+ completed: false,
443
+ hasStaleEntries
444
+ };
445
+ if (staleKeys.size > 0) hasStaleEntries = true;
446
+ onRemoved(filterAndMap(batch, ({ key }) => staleKeys.has(key) ? false : key));
447
+ }
448
+ return {
449
+ completed: true,
450
+ hasStaleEntries
451
+ };
452
+ }
413
453
  function keepEntriesWithinByteBudget(entries, getKey, getLastAccessAt, getSizeBytes, isPinned, isProtected, maxBytes) {
414
454
  const keptKeys = /* @__PURE__ */ new Set();
415
455
  let unprotectedBytes = 0;
@@ -458,7 +498,7 @@ function keepEntriesWithinByteBudget(entries, getKey, getLastAccessAt, getSizeBy
458
498
  unprotectedBytes
459
499
  };
460
500
  }
461
- /** Deadline-aware variant used by synchronous localStorage maintenance. */
501
+ /** Deadline-aware variant used by background storage maintenance. */
462
502
  async function keepEntriesWithinByteBudgetDuringIdle(entries, getKey, getLastAccessAt, getSizeBytes, isPinned, isProtected, maxBytes, idleContext) {
463
503
  const keptKeys = /* @__PURE__ */ new Set();
464
504
  let unprotectedBytes = 0;
@@ -670,12 +710,12 @@ function getRecord(value) {
670
710
  if (!isObject(value)) return null;
671
711
  return value;
672
712
  }
673
- function isOfflineProtectedMetadata(customMetadata) {
713
+ function isAsyncStorageMetadataOfflineProtected(customMetadata) {
674
714
  return customMetadata?.o === true;
675
715
  }
676
716
  function getProtectedKeysFromMetadata(entries) {
677
717
  const keys = /* @__PURE__ */ new Set();
678
- for (const entry of entries) if (isOfflineProtectedMetadata(entry.customMetadata)) keys.add(entry.key);
718
+ for (const entry of entries) if (isAsyncStorageMetadataOfflineProtected(entry.customMetadata)) keys.add(entry.key);
679
719
  return keys;
680
720
  }
681
721
  function isSessionOfflineInLocalStorage(sessionKey) {
@@ -703,8 +743,8 @@ function mergeManagedAsyncStorageCustomMetadata(currentCustomMetadata, nextCusto
703
743
  if (protectedKeysSnapshotSet !== null) return setOfflineProtectionMetadata(mergedCustomMetadata, protectedKeysSnapshotSet?.has(serializeProtectedRef({
704
744
  ...scope,
705
745
  key
706
- })) === true || isOfflineProtectedMetadata(nextCustomMetadata) || isOfflineProtectedMetadata(currentCustomMetadata));
707
- return setOfflineProtectionMetadata(mergedCustomMetadata, isOfflineProtectedMetadata(nextCustomMetadata) || isOfflineProtectedMetadata(currentCustomMetadata));
746
+ })) === true || isAsyncStorageMetadataOfflineProtected(nextCustomMetadata) || isAsyncStorageMetadataOfflineProtected(currentCustomMetadata));
747
+ return setOfflineProtectionMetadata(mergedCustomMetadata, isAsyncStorageMetadataOfflineProtected(nextCustomMetadata) || isAsyncStorageMetadataOfflineProtected(currentCustomMetadata));
708
748
  }
709
749
  const ASYNC_METADATA_LAST_ACCESS_AT_KEY = "a";
710
750
  const ASYNC_METADATA_VERSION_KEY = "v";
@@ -1033,8 +1073,8 @@ var ManagedAsyncStorageNamespaceHandle = class {
1033
1073
  })) }).catch(() => {});
1034
1074
  return keys.map((key) => entryByKey.get(key) ?? null);
1035
1075
  }
1036
- commit(args) {
1037
- return this.#adapter.queueCommitToNamespace(this.#scope, args);
1076
+ async commit(args) {
1077
+ await this.#adapter.queueCommitToNamespace(this.#scope, args);
1038
1078
  }
1039
1079
  async listKeys() {
1040
1080
  await this.#adapter.flushPendingNamespaceCommit(this.#scope);
@@ -1112,7 +1152,7 @@ var ManagedAsyncStorageAdapter = class {
1112
1152
  await this.#runWithSessionWriterLock(sessionKey, async () => {
1113
1153
  await this.#flushPendingNamespaceCommitsForSessionUnlocked(sessionKey);
1114
1154
  const scopesToClear = await this.#listDiscoveredScopes(sessionKey);
1115
- await Promise.all(scopesToClear.map((scope) => this.#clearManagedNamespaceUnlocked(scope)));
1155
+ await Promise.all(scopesToClear.map((scope) => this.#clearManagedNamespaceUnlocked(scope, false)));
1116
1156
  });
1117
1157
  }
1118
1158
  async readProtectedStorageKeys(sessionKey, driver = this.#driver) {
@@ -1127,7 +1167,7 @@ var ManagedAsyncStorageAdapter = class {
1127
1167
  order: "key"
1128
1168
  });
1129
1169
  const refs = [];
1130
- for (const entry of metadataEntries) if (isOfflineProtectedMetadata(entry.customMetadata)) refs.push(serializeProtectedRef({
1170
+ for (const entry of metadataEntries) if (isAsyncStorageMetadataOfflineProtected(entry.customMetadata)) refs.push(serializeProtectedRef({
1131
1171
  ...scope,
1132
1172
  key: entry.key
1133
1173
  }));
@@ -1178,7 +1218,7 @@ var ManagedAsyncStorageAdapter = class {
1178
1218
  for (const [key, shouldProtect] of protectionByKey.entries()) {
1179
1219
  const existingMetadata = indexEntries.get(key);
1180
1220
  if (existingMetadata === void 0) continue;
1181
- if (isOfflineProtectedMetadata(existingMetadata.customMetadata) === shouldProtect) continue;
1221
+ if (isAsyncStorageMetadataOfflineProtected(existingMetadata.customMetadata) === shouldProtect) continue;
1182
1222
  const nextCustomMetadata = setOfflineProtectionMetadata(existingMetadata.customMetadata, shouldProtect);
1183
1223
  const nextMetadata = { ...existingMetadata };
1184
1224
  if (nextCustomMetadata !== void 0) nextMetadata.customMetadata = nextCustomMetadata;
@@ -1221,23 +1261,37 @@ var ManagedAsyncStorageAdapter = class {
1221
1261
  }
1222
1262
  #hasPendingBarrierForKeys(pending, keys) {
1223
1263
  return keys.some((key) => {
1224
- return pending.upserts.has(key) || pending.removes.has(key) || pending.inFlightBarrierKeys?.has(key) === true;
1264
+ return pending.upserts.has(key) || pending.removes.has(key) || pending.conditionalRemoves.has(key) || pending.inFlightBarrierKeys?.has(key) === true;
1225
1265
  });
1226
1266
  }
1267
+ /** Resolves with the `conditionalRemoves` keys kept because they changed. */
1227
1268
  async queueCommitToNamespace(scope, args) {
1228
1269
  const pending = this.#getOrCreatePendingNamespaceCommit(scope);
1229
1270
  const now = Date.now();
1230
- for (const touch of args.touches ?? []) pending.touches.set(touch.key, touch.lastAccessAt ?? now);
1271
+ for (const touch of args.touches ?? []) {
1272
+ this.#cancelPendingConditionalRemove(pending, touch.key);
1273
+ pending.touches.set(touch.key, touch.lastAccessAt ?? now);
1274
+ }
1231
1275
  for (const remove of args.removes ?? []) {
1232
1276
  pending.upserts.delete(remove);
1233
1277
  pending.touches.delete(remove);
1278
+ pending.conditionalRemoves.delete(remove);
1234
1279
  pending.removes.add(remove);
1235
1280
  }
1281
+ for (const remove of args.conditionalRemoves ?? []) {
1282
+ if (pending.upserts.has(remove.key) || pending.touches.has(remove.key)) {
1283
+ pending.staleConditionalRemoveKeys.add(remove.key);
1284
+ continue;
1285
+ }
1286
+ if (pending.removes.has(remove.key)) continue;
1287
+ pending.conditionalRemoves.set(remove.key, remove);
1288
+ }
1236
1289
  if ("staticPolicy" in args) {
1237
1290
  pending.hasStaticPolicyUpdate = true;
1238
1291
  pending.staticPolicy = args.staticPolicy ?? null;
1239
1292
  }
1240
1293
  for (const upsert of args.upserts ?? []) {
1294
+ this.#cancelPendingConditionalRemove(pending, upsert.key);
1241
1295
  pending.removes.delete(upsert.key);
1242
1296
  pending.upserts.set(upsert.key, __LEGIT_CAST__(upsert));
1243
1297
  }
@@ -1249,6 +1303,19 @@ var ManagedAsyncStorageAdapter = class {
1249
1303
  });
1250
1304
  });
1251
1305
  }
1306
+ /** A later write wins over a queued conditional remove of the same key. */
1307
+ #cancelPendingConditionalRemove(pending, key) {
1308
+ if (pending.conditionalRemoves.delete(key)) pending.staleConditionalRemoveKeys.add(key);
1309
+ }
1310
+ getMaintenanceRemoveBatchSize() {
1311
+ return getManagedDriverCapabilities(this.#driver)?.applyManagedCommit !== void 0 ? PER_KEY_COMMIT_MAINTENANCE_REMOVE_BATCH_SIZE : INDEX_REWRITE_COMMIT_MAINTENANCE_REMOVE_BATCH_SIZE;
1312
+ }
1313
+ async commitToNamespaceNow(scope, args) {
1314
+ const committed = this.queueCommitToNamespace(scope, args);
1315
+ const flushed = this.flushPendingNamespaceCommit(scope).then(() => this.flushPendingNamespaceCommit(scope));
1316
+ const [staleConditionalRemoveKeys] = await Promise.all([committed, flushed]);
1317
+ return staleConditionalRemoveKeys;
1318
+ }
1252
1319
  async flushPendingNamespaceCommit(scope, keys) {
1253
1320
  const namespaceKey = getNamespaceId(scope);
1254
1321
  const pending = this.#pendingNamespaceCommits.get(namespaceKey);
@@ -1271,37 +1338,47 @@ var ManagedAsyncStorageAdapter = class {
1271
1338
  pending.cancelFlush = null;
1272
1339
  const upserts = [...pending.upserts.values()];
1273
1340
  const removes = [...pending.removes];
1341
+ const conditionalRemoves = [...pending.conditionalRemoves.values()];
1342
+ const staleConditionalRemoveKeys = pending.staleConditionalRemoveKeys;
1274
1343
  const hasStaticPolicyUpdate = pending.hasStaticPolicyUpdate;
1275
1344
  const staticPolicy = pending.staticPolicy;
1276
1345
  const touches = [...pending.touches.entries()].map(([key, lastAccessAt]) => ({
1277
1346
  key,
1278
1347
  lastAccessAt
1279
1348
  }));
1280
- const inFlightBarrierKeys = new Set([...pending.upserts.keys(), ...pending.removes]);
1349
+ const inFlightBarrierKeys = new Set([
1350
+ ...pending.upserts.keys(),
1351
+ ...pending.removes,
1352
+ ...pending.conditionalRemoves.keys()
1353
+ ]);
1281
1354
  const waiters = [...pending.waiters];
1282
1355
  pending.hasStaticPolicyUpdate = false;
1283
1356
  pending.upserts = /* @__PURE__ */ new Map();
1284
1357
  pending.removes = /* @__PURE__ */ new Set();
1358
+ pending.conditionalRemoves = /* @__PURE__ */ new Map();
1359
+ pending.staleConditionalRemoveKeys = /* @__PURE__ */ new Set();
1285
1360
  pending.staticPolicy = null;
1286
1361
  pending.touches = /* @__PURE__ */ new Map();
1287
1362
  pending.waiters = [];
1288
1363
  pending.inFlightBarrierKeys = inFlightBarrierKeys.size > 0 ? inFlightBarrierKeys : null;
1289
- if (upserts.length === 0 && removes.length === 0 && touches.length === 0 && !hasStaticPolicyUpdate) {
1364
+ if (upserts.length === 0 && removes.length === 0 && conditionalRemoves.length === 0 && touches.length === 0 && !hasStaticPolicyUpdate) {
1290
1365
  this.#pendingNamespaceCommits.delete(namespaceKey);
1291
- for (const waiter of waiters) waiter.resolve();
1366
+ for (const waiter of waiters) waiter.resolve(staleConditionalRemoveKeys);
1292
1367
  return;
1293
1368
  }
1294
1369
  pending.flushPromise = this.#applyManagedCommit(scope, {
1295
1370
  upserts,
1296
1371
  removes,
1372
+ ...conditionalRemoves.length > 0 ? { conditionalRemoves } : {},
1297
1373
  ...hasStaticPolicyUpdate ? { staticPolicy } : {},
1298
1374
  touches
1299
- }).then(() => {
1375
+ }).then((committedStaleKeys) => {
1376
+ for (const key of committedStaleKeys) staleConditionalRemoveKeys.add(key);
1300
1377
  const currentBucket = getBucketId(Date.now());
1301
1378
  for (const touch of touches) this.#recentTouchedBuckets.set(`${namespaceKey}::${touch.key}`, getBucketId(touch.lastAccessAt));
1302
1379
  for (const upsert of upserts) this.#recentTouchedBuckets.set(`${namespaceKey}::${upsert.key}`, currentBucket);
1303
1380
  this.#pruneRecentTouchedBuckets(currentBucket);
1304
- for (const waiter of waiters) waiter.resolve();
1381
+ for (const waiter of waiters) waiter.resolve(staleConditionalRemoveKeys);
1305
1382
  }).catch((error) => {
1306
1383
  for (const waiter of waiters) waiter.reject(error);
1307
1384
  throw error;
@@ -1444,10 +1521,16 @@ var ManagedAsyncStorageAdapter = class {
1444
1521
  }
1445
1522
  async clearManagedNamespace(scope) {
1446
1523
  await this.#runWithSessionWriterLock(scope.sessionKey, async () => {
1447
- await this.#clearManagedNamespaceUnlocked(scope);
1524
+ await this.#clearManagedNamespaceUnlocked(scope, true);
1448
1525
  });
1449
1526
  }
1450
- async #clearManagedNamespaceUnlocked(scope) {
1527
+ /**
1528
+ * Commits still pending here were queued after the clear was requested,
1529
+ * because both clear paths flush first. A namespace clear keeps them so
1530
+ * they flush once the writer lock is released; a session clear discards
1531
+ * them with the session data.
1532
+ */
1533
+ async #clearManagedNamespaceUnlocked(scope, keepPendingCommits) {
1451
1534
  const managedCapabilities = getManagedDriverCapabilities(this.#driver);
1452
1535
  if (managedCapabilities?.clearManagedNamespace !== void 0) await managedCapabilities.clearManagedNamespace(scope);
1453
1536
  else await this.#driver.clear(scope);
@@ -1455,7 +1538,13 @@ var ManagedAsyncStorageAdapter = class {
1455
1538
  this.#broadcastNamespaceInvalidation(scope, "clear");
1456
1539
  const namespaceKey = getNamespaceId(scope);
1457
1540
  this.#observedScopes.delete(namespaceKey);
1458
- this.#pendingNamespaceCommits.delete(namespaceKey);
1541
+ const pending = this.#pendingNamespaceCommits.get(namespaceKey);
1542
+ if (pending && keepPendingCommits) this.#schedulePendingNamespaceFlush(pending);
1543
+ else if (pending) {
1544
+ this.#pendingNamespaceCommits.delete(namespaceKey);
1545
+ pending.cancelFlush?.();
1546
+ for (const waiter of pending.waiters) waiter.resolve(pending.staleConditionalRemoveKeys);
1547
+ }
1459
1548
  this.clearRecentTouchedBucketsForNamespace(scope);
1460
1549
  }
1461
1550
  #toPublicMetadata(key, metadata) {
@@ -1469,23 +1558,38 @@ var ManagedAsyncStorageAdapter = class {
1469
1558
  customMetadata: metadata.customMetadata ?? {}
1470
1559
  };
1471
1560
  }
1561
+ /** Resolves with the `conditionalRemoves` keys kept because they changed. */
1472
1562
  async #applyManagedCommit(scope, args) {
1473
1563
  const upserts = args.upserts ?? [];
1474
1564
  const removes = [...new Set(args.removes ?? [])];
1565
+ const conditionalRemoves = args.conditionalRemoves ?? [];
1475
1566
  const touches = args.touches ?? [];
1476
1567
  const touchedKeys = [...new Set(touches.map((touch) => touch.key))];
1477
1568
  const managedCapabilities = getManagedDriverCapabilities(this.#driver);
1478
1569
  if (managedCapabilities?.applyManagedCommit !== void 0) {
1479
- await managedCapabilities.applyManagedCommit(scope, args, { mergeOfflineProtectionMetadata: (key, nextCustomMetadata, currentCustomMetadata) => mergeManagedAsyncStorageCustomMetadata(currentCustomMetadata, nextCustomMetadata, getSessionProtectedKeysSnapshot(scope.sessionKey), scope, key) });
1570
+ const reportedStaleKeys = await managedCapabilities.applyManagedCommit(scope, args, { mergeOfflineProtectionMetadata: (key, nextCustomMetadata, currentCustomMetadata) => mergeManagedAsyncStorageCustomMetadata(currentCustomMetadata, nextCustomMetadata, getSessionProtectedKeysSnapshot(scope.sessionKey), scope, key) });
1480
1571
  this.#advanceNamespaceReadCacheGeneration(scope);
1481
1572
  this.#invalidateCachedNamespaceIndexState(scope);
1482
1573
  for (const key of removes) this.#invalidateCachedPayloadValue(scope, key);
1574
+ for (const { key } of conditionalRemoves) this.#invalidateCachedPayloadValue(scope, key);
1483
1575
  for (const upsert of upserts) this.#setCachedPayloadValue(scope, upsert.key, { value: upsert.value });
1484
1576
  this.#broadcastNamespaceInvalidation(scope, "commit");
1485
- return;
1577
+ return reportedStaleKeys ?? new Set(conditionalRemoves.map((remove) => remove.key));
1486
1578
  }
1579
+ if (conditionalRemoves.length > 0) this.#invalidateCachedNamespaceIndexState(scope);
1487
1580
  const currentIndexState = await this.#readNamespaceIndexStateUsingDriver(this.#driver, scope);
1488
1581
  const indexEntries = currentIndexState.valid && currentIndexState.entries !== null ? currentIndexState.entries : /* @__PURE__ */ new Map();
1582
+ const staleConditionalRemoveKeys = /* @__PURE__ */ new Set();
1583
+ for (const remove of conditionalRemoves) {
1584
+ if (!currentIndexState.valid) {
1585
+ staleConditionalRemoveKeys.add(remove.key);
1586
+ continue;
1587
+ }
1588
+ const metadata = indexEntries.get(remove.key);
1589
+ if (metadata === void 0) continue;
1590
+ if (matchesConditionalRemove(remove, metadata.lastAccessAt, metadata.sizeBytes, metadata.version, isAsyncStorageMetadataOfflineProtected(metadata.customMetadata))) removes.push(remove.key);
1591
+ else staleConditionalRemoveKeys.add(remove.key);
1592
+ }
1489
1593
  const now = Date.now();
1490
1594
  const touchesByKey = new Map(touches.map((touch) => [touch.key, touch.lastAccessAt ?? now]));
1491
1595
  const setEntries = [];
@@ -1553,6 +1657,7 @@ var ManagedAsyncStorageAdapter = class {
1553
1657
  valid: currentIndexState.valid
1554
1658
  });
1555
1659
  this.#broadcastNamespaceInvalidation(scope, "commit");
1660
+ return staleConditionalRemoveKeys;
1556
1661
  }
1557
1662
  async #removeManagedKeysUsingDriver(driver, scope, keys) {
1558
1663
  const uniqueKeys = [...new Set(keys)];
@@ -1702,10 +1807,12 @@ var ManagedAsyncStorageAdapter = class {
1702
1807
  const created = {
1703
1808
  scope,
1704
1809
  cancelFlush: null,
1810
+ conditionalRemoves: /* @__PURE__ */ new Map(),
1705
1811
  inFlightBarrierKeys: null,
1706
1812
  flushPromise: null,
1707
1813
  hasStaticPolicyUpdate: false,
1708
1814
  removes: /* @__PURE__ */ new Set(),
1815
+ staleConditionalRemoveKeys: /* @__PURE__ */ new Set(),
1709
1816
  staticPolicy: null,
1710
1817
  touches: /* @__PURE__ */ new Map(),
1711
1818
  upserts: /* @__PURE__ */ new Map(),
@@ -2002,7 +2109,7 @@ var ManagedAsyncStorageAdapter = class {
2002
2109
  const payloadRecordKeysToRemove = new Set(rawKeysToRemove);
2003
2110
  const candidateEntries = [];
2004
2111
  for (const [key, metadata] of indexState.entries.entries()) {
2005
- const isProtected = isOfflineProtectedMetadata(metadata.customMetadata) || args.protectedRefs?.has(serializeProtectedRef({
2112
+ const isProtected = isAsyncStorageMetadataOfflineProtected(metadata.customMetadata) || args.protectedRefs?.has(serializeProtectedRef({
2006
2113
  ...args.scope,
2007
2114
  key
2008
2115
  })) === true;
@@ -2107,8 +2214,41 @@ var ManagedAsyncStorageAdapter = class {
2107
2214
  function createAsyncStorageAdapter(driver) {
2108
2215
  return new ManagedAsyncStorageAdapter(driver);
2109
2216
  }
2217
+ /**
2218
+ * Drivers with a per-key managed commit (IndexedDB) keep each maintenance
2219
+ * transaction short. Drivers without one rewrite the whole namespace index on
2220
+ * every commit, so larger batches avoid repeating that work for every few
2221
+ * removals while still bounding concurrent driver requests.
2222
+ */
2223
+ const PER_KEY_COMMIT_MAINTENANCE_REMOVE_BATCH_SIZE = 25;
2224
+ const INDEX_REWRITE_COMMIT_MAINTENANCE_REMOVE_BATCH_SIZE = 250;
2225
+ /** Number of keys idle-deadline maintenance removes per commit. */
2226
+ function getAsyncStorageMaintenanceRemoveBatchSize(adapter) {
2227
+ return adapter instanceof ManagedAsyncStorageAdapter ? adapter.getMaintenanceRemoveBatchSize() : INDEX_REWRITE_COMMIT_MAINTENANCE_REMOVE_BATCH_SIZE;
2228
+ }
2229
+ /**
2230
+ * Removes entries only while they still have the metadata the caller read,
2231
+ * without waiting for the namespace batching debounce. Resolves with the keys
2232
+ * kept because they changed. Managed adapters check and remove atomically;
2233
+ * other adapters only get a best-effort metadata re-read before removing.
2234
+ */
2235
+ async function removeAsyncStorageNamespaceEntriesIfUnchanged(adapter, scope, entries) {
2236
+ if (adapter instanceof ManagedAsyncStorageAdapter) return adapter.commitToNamespaceNow(scope, { conditionalRemoves: entries });
2237
+ const namespace = adapter.openNamespace(scope);
2238
+ const currentEntries = new Map((await namespace.listMetadata()).map((entry) => [entry.key, entry]));
2239
+ const removes = [];
2240
+ const staleKeys = /* @__PURE__ */ new Set();
2241
+ for (const remove of entries) {
2242
+ const current = currentEntries.get(remove.key);
2243
+ if (current === void 0) continue;
2244
+ if (matchesConditionalRemove(remove, current.lastAccessAt, current.sizeBytes, current.version, isAsyncStorageMetadataOfflineProtected(current.customMetadata))) removes.push(remove.key);
2245
+ else staleKeys.add(remove.key);
2246
+ }
2247
+ if (removes.length > 0) await namespace.commit({ removes });
2248
+ return staleKeys;
2249
+ }
2110
2250
  function serializeProtectedRef(ref) {
2111
2251
  return serializeProtectedRef$1(ref);
2112
2252
  }
2113
2253
  //#endregion
2114
- export { scheduleIdleCleanup as $, getIsOfflineModeFromStatus as A, createCompactLocalStorageEntry as B, isQuotaExceededError as C, OfflineResolutionConflictParseError as D, serializeJsonForStorage as E, clearSessionProtectedKeysSnapshot as F, getPayloadRecordKey as G, compareMetadata as H, getSessionProtectedKeysSnapshot as I, parseAsyncStorageRecordKey as J, getPersistedNamespaceId as K, setSessionProtectedKeysSnapshot as L, isOfflineModeStatusValue as M, offlineItemEntityRefSchema as N, compactOfflineStatusSnapshotSchema as O, offlineResolutionRecordSchema as P, createIdleCleanupContext as Q, getNavigatorLockManager as R, getSerializedStringSize as S, keepEntriesWithinByteBudgetDuringIdle as T, encodePersistedAsyncNamespaceKind as U, parseCompactLocalStorageEntry as V, getNamespaceId as W, serializeProtectedRef$1 as X, parsePersistedAsyncNamespaceKind as Y, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS 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, isModeEffectivelyActive as j, defaultOfflineRuntimeConfig 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, normalizeStaticPolicy 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, warnIfNavigatorLockUnavailable as z };
2254
+ export { parseAsyncStorageRecordKey as $, serializeJsonForStorage as A, getSessionProtectedKeysSnapshot as B, createShouldIgnoreItemPredicate as C, keepEntriesWithinByteBudget as D, isQuotaExceededError as E, isModeEffectivelyActive as F, parseCompactLocalStorageEntry as G, getNavigatorLockManager as H, isOfflineModeStatusValue as I, getNamespaceId as J, compareMetadata as K, offlineItemEntityRefSchema as L, compactOfflineStatusSnapshotSchema as M, defaultOfflineRuntimeConfig as N, keepEntriesWithinByteBudgetDuringIdle as O, getIsOfflineModeFromStatus as P, normalizeStaticPolicy as Q, offlineResolutionRecordSchema as R, getDefaultMaxBytesForScope as S, getSerializedStringSize as T, warnIfNavigatorLockUnavailable as U, setSessionProtectedKeysSnapshot as V, createCompactLocalStorageEntry as W, getPersistedNamespaceId as X, getPayloadRecordKey as Y, matchesConditionalRemove as Z, getOfflineSessionStatusStorageKey as _, estimateManagedAsyncStorageEntrySizeBytes as a, getTSDFDebugTimingMs as b, isAsyncStorageMetadataOfflineProtected as c, registerAsyncStartupStoreCleanup as d, parsePersistedAsyncNamespaceKind as et, removeAsyncStorageNamespaceEntriesIfUnchanged as f, OFFLINE_SESSION_STATUS_STORE_NAME as g, parseAsyncStorageNamespaceKind as h, createAsyncStorageAdapter as i, scheduleIdleCleanup as it, OfflineResolutionConflictParseError as j, removeAsyncMaintenanceEntriesIfUnchanged as k, mergeManagedAsyncStorageCustomMetadata as l, unregisterAsyncStartupStoreCleanup as m, ASYNC_STORAGE_MAX_AGE_MS as n, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS as nt, getAsyncStorageMaintenanceRemoveBatchSize as o, serializeProtectedRef as p, encodePersistedAsyncNamespaceKind as q, buildPersistedStaticPolicy as r, createIdleCleanupContext as rt, getProtectedKeysFromMetadata as s, ASYNC_MAINTENANCE_LOCAL_STORAGE_KEY as t, serializeProtectedRef$1 as tt, readAsyncStorageNamespaceIndexStateUsingDriver as u, logPersistentStorageQuotaCleanup as v, createTimedKeySet as w, resolveTSDFLogger as x, emitTSDFDebugLog as y, clearSessionProtectedKeysSnapshot as z };
@@ -1,3 +1,3 @@
1
- import { t as opfsPersistentStorage } from "./opfsPersistentStorage-D_k77Srq.js";
2
- import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-BSlgLveB.js";
1
+ import { t as opfsPersistentStorage } from "./opfsPersistentStorage-JsSCNBTr.js";
2
+ import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-BameJ4st.js";
3
3
  export { indexedDbPersistentStorage, opfsPersistentStorage };
@@ -1,4 +1,4 @@
1
- import { t as AsyncStorageAdapter } from "./types-D0ttVGmj.js";
1
+ import { t as AsyncStorageAdapter } from "./types-BlyGC_PO.js";
2
2
  //#region src/persistentStorage/indexedDbAsyncStorageAdapter.d.ts
3
3
  /** Options for creating the IndexedDB persistent storage adapter. */
4
4
  type IndexedDbPersistentStorageOptions$1 = {
@@ -1,2 +1,2 @@
1
- import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-BSlgLveB.js";
1
+ import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-BameJ4st.js";
2
2
  export { createIndexedDbPersistentStorage, indexedDbPersistentStorage };
@@ -1,4 +1,4 @@
1
- import { E as serializeJsonForStorage, G as getPayloadRecordKey, H as compareMetadata, J as parseAsyncStorageRecordKey, K as getPersistedNamespaceId, U as encodePersistedAsyncNamespaceKind, W as getNamespaceId, X as serializeProtectedRef, Y as parsePersistedAsyncNamespaceKind, _ as getTSDFDebugTimingMs, a as estimateManagedAsyncStorageEntrySizeBytes, g as emitTSDFDebugLog, i as createAsyncStorageAdapter, q as normalizeStaticPolicy } from "./asyncStorageAdapter-BuGjbXYA.js";
1
+ import { $ as parseAsyncStorageRecordKey, A as serializeJsonForStorage, J as getNamespaceId, K as compareMetadata, Q as normalizeStaticPolicy, X as getPersistedNamespaceId, Y as getPayloadRecordKey, Z as matchesConditionalRemove, a as estimateManagedAsyncStorageEntrySizeBytes, b as getTSDFDebugTimingMs, et as parsePersistedAsyncNamespaceKind, i as createAsyncStorageAdapter, q as encodePersistedAsyncNamespaceKind, tt as serializeProtectedRef, y as emitTSDFDebugLog } from "./asyncStorageAdapter-URS9eulL.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
@@ -508,10 +508,12 @@ var IndexedDbAsyncStorageDriver = class {
508
508
  const policyStore = transaction.objectStore(INDEXED_DB_NAMESPACE_POLICY_STORE);
509
509
  const upserts = args.upserts ?? [];
510
510
  const removes = [...new Set(args.removes ?? [])];
511
+ const conditionalRemoves = args.conditionalRemoves ?? [];
511
512
  const touches = args.touches ?? [];
512
513
  const scopeId = createScopeId(scope.sessionKey, scope.storeName, scope.kind);
513
514
  const uniqueKeys = [...new Set([
514
515
  ...removes,
516
+ ...conditionalRemoves.map((remove) => remove.key),
515
517
  ...touches.map((touch) => touch.key),
516
518
  ...upserts.map((upsert) => upsert.key)
517
519
  ])];
@@ -524,6 +526,13 @@ var IndexedDbAsyncStorageDriver = class {
524
526
  const record = await openRequestAsPromise(entryStore.get(createEntryPrimaryKey(scope, key)));
525
527
  if (isValidEntryRecord(record)) existingEntries.set(key, toEntryRecordValue(record));
526
528
  }));
529
+ const staleConditionalRemoveKeys = /* @__PURE__ */ new Set();
530
+ for (const remove of conditionalRemoves) {
531
+ const existing = existingEntries.get(remove.key);
532
+ if (existing === void 0) continue;
533
+ if (matchesConditionalRemove(remove, existing.a, existing.z, existing.v ?? 1, existing.o === 1)) removes.push(remove.key);
534
+ else staleConditionalRemoveKeys.add(remove.key);
535
+ }
527
536
  for (const key of removes) entryStore.delete(createEntryPrimaryKey(scope, key));
528
537
  const upsertKeySet = new Set(upserts.map((upsert) => upsert.key));
529
538
  for (const upsert of upserts) {
@@ -585,6 +594,7 @@ var IndexedDbAsyncStorageDriver = class {
585
594
  type: "applyManagedCommit",
586
595
  upserts: upserts.map((upsert) => upsert.key).sort((left, right) => left.localeCompare(right))
587
596
  });
597
+ return staleConditionalRemoveKeys;
588
598
  }
589
599
  async readNamespaceIndexState(scope, knownRecordKeys_) {
590
600
  const transaction = (await this.#getDatabase()).transaction([INDEXED_DB_ENTRY_STORE, INDEXED_DB_NAMESPACE_POLICY_STORE], "readonly");