tsdf 18.2.0 → 18.3.1
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.d.ts +1 -1
- package/dist/async-storage.js +1 -1
- package/dist/{asyncStorageAdapter-Bbepjtkd.d.ts → asyncStorageAdapter-D_Ltk0xg.d.ts} +1 -1
- package/dist/{asyncStorageAdapter-YuIJ7hwm.js → asyncStorageAdapter-NrI38v4g.js} +83 -1
- package/dist/{asyncStorageAdapters-Rh3o1FAG.js → asyncStorageAdapters-Daewq7dv.js} +2 -2
- package/dist/indexed-db-storage.d.ts +1 -1
- package/dist/indexed-db-storage.js +1 -1
- package/dist/{indexedDbPersistentStorage-CFH2BFL-.js → indexedDbPersistentStorage-JJdUGGI8.js} +5 -3
- package/dist/main.d.ts +87 -16
- package/dist/main.js +929 -126
- package/dist/opfs-storage.d.ts +1 -1
- package/dist/opfs-storage.js +1 -1
- package/dist/{opfsPersistentStorage-CapHC7zC.d.ts → opfsPersistentStorage-HRMP5gzd.d.ts} +1 -1
- package/dist/{opfsPersistentStorage-6OuHQ3d-.js → opfsPersistentStorage-amwSWm_p.js} +27 -4
- package/dist/{types-DDjEjIqQ.d.ts → types-DeZ9VDOe.d.ts} +98 -12
- package/docs/list-query-store.md +1 -0
- package/docs/offline.md +129 -3
- package/docs/persistent-storage.md +51 -3
- package/docs/store-manager.md +27 -5
- package/package.json +1 -1
package/dist/async-storage.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createAsyncStorageAdapter } from "./asyncStorageAdapter-
|
|
1
|
+
import { t as createAsyncStorageAdapter } from "./asyncStorageAdapter-D_Ltk0xg.js";
|
|
2
2
|
export { createAsyncStorageAdapter };
|
package/dist/async-storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-
|
|
1
|
+
import { i as createAsyncStorageAdapter } from "./asyncStorageAdapter-NrI38v4g.js";
|
|
2
2
|
export { createAsyncStorageAdapter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as AsyncStorageDriver, t as AsyncStorageAdapter } from "./types-
|
|
1
|
+
import { r as AsyncStorageDriver, t as AsyncStorageAdapter } from "./types-DeZ9VDOe.js";
|
|
2
2
|
|
|
3
3
|
//#region src/persistentStorage/asyncStorageAdapter.d.ts
|
|
4
4
|
declare function createAsyncStorageAdapter(driver: AsyncStorageDriver): AsyncStorageAdapter;
|
|
@@ -358,6 +358,30 @@ var OfflineResolutionConflictParseError = class extends Error {
|
|
|
358
358
|
this.validationError = args.validationError;
|
|
359
359
|
}
|
|
360
360
|
};
|
|
361
|
+
const offlineResolutionActionErrorMessages = {
|
|
362
|
+
"offline-not-configured": "Offline is not configured for this manager",
|
|
363
|
+
"resolution-not-found": "Offline resolution not found in the active session",
|
|
364
|
+
"store-not-registered": "The store that owns this offline resolution is not registered in this manager",
|
|
365
|
+
"retry-not-supported": "Only retry-exhausted offline resolutions can be retried",
|
|
366
|
+
"resolution-blocked": "Cannot resolve a blocked offline resolution before its blocking dependencies are cleared",
|
|
367
|
+
"action-failed": "Failed to apply the offline resolution action"
|
|
368
|
+
};
|
|
369
|
+
/** Error returned when a manager-level offline resolution action is not applied. */
|
|
370
|
+
var OfflineResolutionActionError = class extends Error {
|
|
371
|
+
/** Reason the action was not applied. */
|
|
372
|
+
code;
|
|
373
|
+
/** Resolution id the action was requested for. */
|
|
374
|
+
resolutionId;
|
|
375
|
+
/** Store that owns the resolution, when the resolution was found. */
|
|
376
|
+
storeName;
|
|
377
|
+
constructor(code, resolutionId, storeName, cause) {
|
|
378
|
+
super(`[tsdf] ${offlineResolutionActionErrorMessages[code]}${cause ? `: ${cause.message}` : ""}`, cause && { cause });
|
|
379
|
+
this.name = "OfflineResolutionActionError";
|
|
380
|
+
this.code = code;
|
|
381
|
+
this.resolutionId = resolutionId;
|
|
382
|
+
this.storeName = storeName;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
361
385
|
//#endregion
|
|
362
386
|
//#region src/persistentStorage/persistenceUtils.ts
|
|
363
387
|
const MAINTENANCE_SORT_CHUNK_SIZE = 100;
|
|
@@ -1526,6 +1550,48 @@ var ManagedAsyncStorageAdapter = class {
|
|
|
1526
1550
|
if (managedCapabilities?.listManagedKeys !== void 0) return managedCapabilities.listManagedKeys(scope);
|
|
1527
1551
|
return [...(await this.#readNamespaceIndexEntriesUsingDriver(this.#driver, scope)).keys()].sort((left, right) => left.localeCompare(right));
|
|
1528
1552
|
}
|
|
1553
|
+
/** Stable id of the storage behind this adapter, if its driver has one. */
|
|
1554
|
+
get storageId() {
|
|
1555
|
+
return this.#driver.storageId;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Lists every scope of the given stores, in every session. Uses the
|
|
1559
|
+
* isolated cleanup driver when available, so this full scan does not fill
|
|
1560
|
+
* the caches of the stores the app is using.
|
|
1561
|
+
*/
|
|
1562
|
+
async #listStoreScopes(storeNames) {
|
|
1563
|
+
return (await this.#withCleanupDriver((driver) => this.#listDiscoveredScopes(void 0, driver))).filter((scope) => storeNames.has(scope.storeName));
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Removes every namespace of the given stores, in every session. Returns how
|
|
1567
|
+
* many queued offline mutations and pending resolutions each store lost, and
|
|
1568
|
+
* the first failure when some of their data could not be removed.
|
|
1569
|
+
*/
|
|
1570
|
+
async removeStores(storeNames) {
|
|
1571
|
+
const unsentRecordsByStore = /* @__PURE__ */ new Map();
|
|
1572
|
+
let failure = null;
|
|
1573
|
+
for (const scope of await this.#listStoreScopes(storeNames)) try {
|
|
1574
|
+
const unsentRecords = await this.#runWithSessionWriterLock(scope.sessionKey, async () => {
|
|
1575
|
+
const count = scope.kind === "offline.queue" || scope.kind === "offline.conflict" ? (await this.listManagedKeys(scope)).length : 0;
|
|
1576
|
+
await this.#clearManagedNamespaceUnlocked(scope, true);
|
|
1577
|
+
return count;
|
|
1578
|
+
});
|
|
1579
|
+
unsentRecordsByStore.set(scope.storeName, (unsentRecordsByStore.get(scope.storeName) ?? 0) + unsentRecords);
|
|
1580
|
+
} catch (error) {
|
|
1581
|
+
failure ??= error;
|
|
1582
|
+
}
|
|
1583
|
+
if (failure === null) {
|
|
1584
|
+
const remainingScopes = await this.#listStoreScopes(storeNames);
|
|
1585
|
+
if (remainingScopes.length > 0) {
|
|
1586
|
+
const storesWithData = new Set(remainingScopes.map(({ storeName }) => `"${storeName}"`));
|
|
1587
|
+
failure = /* @__PURE__ */ new Error(`[tsdf] Some persisted data of removed store(s) ${[...storesWithData].join(", ")} could not be deleted. The cleanup retries on the next page load.`);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return {
|
|
1591
|
+
unsentRecordsByStore,
|
|
1592
|
+
failure
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1529
1595
|
async clearManagedNamespace(scope) {
|
|
1530
1596
|
await this.#runWithSessionWriterLock(scope.sessionKey, async () => {
|
|
1531
1597
|
await this.#clearManagedNamespaceUnlocked(scope, true);
|
|
@@ -2222,6 +2288,22 @@ function createAsyncStorageAdapter(driver) {
|
|
|
2222
2288
|
return new ManagedAsyncStorageAdapter(driver);
|
|
2223
2289
|
}
|
|
2224
2290
|
/**
|
|
2291
|
+
* Returns the adapter's managed implementation and the stable id of its
|
|
2292
|
+
* storage, or `null` when TSDF cannot clean removed stores from it: the
|
|
2293
|
+
* adapter was not created with `createAsyncStorageAdapter` (TSDF cannot list
|
|
2294
|
+
* its namespaces), or its driver has no `storageId` (TSDF cannot remember
|
|
2295
|
+
* across page loads that the cleanup already ran).
|
|
2296
|
+
*/
|
|
2297
|
+
function getRemovableStoresAsyncStorage(adapter) {
|
|
2298
|
+
const managedAdapter = managedAsyncStorageAdapters.get(adapter);
|
|
2299
|
+
const storageId = managedAdapter?.storageId;
|
|
2300
|
+
if (managedAdapter === void 0 || storageId === void 0) return null;
|
|
2301
|
+
return {
|
|
2302
|
+
storageId,
|
|
2303
|
+
removeStores: (storeNames) => managedAdapter.removeStores(storeNames)
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2225
2307
|
* Drivers with a per-key managed commit (IndexedDB) keep each maintenance
|
|
2226
2308
|
* transaction short. Drivers without one rewrite the whole namespace index on
|
|
2227
2309
|
* every commit, so larger batches avoid repeating that work for every few
|
|
@@ -2260,4 +2342,4 @@ function serializeProtectedRef(ref) {
|
|
|
2260
2342
|
return serializeProtectedRef$1(ref);
|
|
2261
2343
|
}
|
|
2262
2344
|
//#endregion
|
|
2263
|
-
export {
|
|
2345
|
+
export { matchesConditionalRemove as $, removeAsyncMaintenanceEntriesIfUnchanged as A, offlineResolutionRecordSchema as B, getDefaultMaxBytesForScope as C, isQuotaExceededError as D, getSerializedStringSize as E, defaultOfflineRuntimeConfig as F, warnIfNavigatorLockUnavailable as G, getSessionProtectedKeysSnapshot as H, getIsOfflineModeFromStatus as I, compareMetadata as J, createCompactLocalStorageEntry as K, isModeEffectivelyActive as L, OfflineResolutionActionError as M, OfflineResolutionConflictParseError as N, keepEntriesWithinByteBudget as O, compactOfflineStatusSnapshotSchema as P, getPersistedNamespaceId as Q, isOfflineModeStatusValue as R, resolveTSDFLogger as S, createTimedKeySet as T, setSessionProtectedKeysSnapshot as U, clearSessionProtectedKeysSnapshot as V, getNavigatorLockManager as W, getNamespaceId as X, encodePersistedAsyncNamespaceKind as Y, getPayloadRecordKey as Z, OFFLINE_SESSION_STATUS_STORE_NAME as _, estimateManagedAsyncStorageEntrySizeBytes as a, createIdleCleanupContext as at, emitTSDFDebugLog as b, getRemovableStoresAsyncStorage as c, readAsyncStorageNamespaceIndexStateUsingDriver as d, normalizeStaticPolicy as et, registerAsyncStartupStoreCleanup as f, parseAsyncStorageNamespaceKind as g, unregisterAsyncStartupStoreCleanup as h, createAsyncStorageAdapter as i, INITIAL_MAINTENANCE_CLEANUP_DELAY_MS as it, serializeJsonForStorage as j, keepEntriesWithinByteBudgetDuringIdle as k, isAsyncStorageMetadataOfflineProtected as l, serializeProtectedRef as m, ASYNC_STORAGE_MAX_AGE_MS as n, parsePersistedAsyncNamespaceKind as nt, getAsyncStorageMaintenanceRemoveBatchSize as o, scheduleIdleCleanup as ot, removeAsyncStorageNamespaceEntriesIfUnchanged as p, parseCompactLocalStorageEntry as q, buildPersistedStaticPolicy as r, serializeProtectedRef$1 as rt, getProtectedKeysFromMetadata as s, scheduleInitialMaintenanceCleanup as st, ASYNC_MAINTENANCE_LOCAL_STORAGE_KEY as t, parseAsyncStorageRecordKey as tt, mergeManagedAsyncStorageCustomMetadata as u, getOfflineSessionStatusStorageKey as v, createShouldIgnoreItemPredicate as w, getTSDFDebugTimingMs as x, logPersistentStorageQuotaCleanup as y, offlineItemEntityRefSchema 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-amwSWm_p.js";
|
|
2
|
+
import { n as indexedDbPersistentStorage } from "./indexedDbPersistentStorage-JJdUGGI8.js";
|
|
3
3
|
export { indexedDbPersistentStorage, opfsPersistentStorage };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as AsyncStorageAdapter } from "./types-
|
|
1
|
+
import { t as AsyncStorageAdapter } from "./types-DeZ9VDOe.js";
|
|
2
2
|
//#region src/persistentStorage/indexedDbAsyncStorageAdapter.d.ts
|
|
3
3
|
/** Options for creating the IndexedDB persistent storage adapter. */
|
|
4
4
|
type IndexedDbPersistentStorageOptions = {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-
|
|
1
|
+
import { n as indexedDbPersistentStorage, t as createIndexedDbPersistentStorage } from "./indexedDbPersistentStorage-JJdUGGI8.js";
|
|
2
2
|
export { createIndexedDbPersistentStorage, indexedDbPersistentStorage };
|
package/dist/{indexedDbPersistentStorage-CFH2BFL-.js → indexedDbPersistentStorage-JJdUGGI8.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as matchesConditionalRemove, J as compareMetadata, Q as getPersistedNamespaceId, X as getNamespaceId, Y as encodePersistedAsyncNamespaceKind, Z as getPayloadRecordKey, a as estimateManagedAsyncStorageEntrySizeBytes, b as emitTSDFDebugLog, et as normalizeStaticPolicy, i as createAsyncStorageAdapter, j as serializeJsonForStorage, nt as parsePersistedAsyncNamespaceKind, rt as serializeProtectedRef, tt as parseAsyncStorageRecordKey, x as getTSDFDebugTimingMs } from "./asyncStorageAdapter-NrI38v4g.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
|
|
@@ -256,8 +256,10 @@ var IndexedDbAsyncStorageDriver = class {
|
|
|
256
256
|
#databasePromise = null;
|
|
257
257
|
#instrumentation;
|
|
258
258
|
databaseName;
|
|
259
|
+
storageId;
|
|
259
260
|
constructor(databaseName = DEFAULT_INDEXED_DB_NAME, instrumentation = void 0) {
|
|
260
261
|
this.databaseName = databaseName;
|
|
262
|
+
this.storageId = `indexedDb:${databaseName}`;
|
|
261
263
|
this.#instrumentation = instrumentation;
|
|
262
264
|
}
|
|
263
265
|
async get(scope, key) {
|
|
@@ -369,11 +371,11 @@ var IndexedDbAsyncStorageDriver = class {
|
|
|
369
371
|
const entryStore = transaction.objectStore(INDEXED_DB_ENTRY_STORE);
|
|
370
372
|
const policyStore = transaction.objectStore(INDEXED_DB_NAMESPACE_POLICY_STORE);
|
|
371
373
|
const discoveredScopes = [];
|
|
372
|
-
await iterateCursor(sessionKey === void 0 ? policyStore.
|
|
374
|
+
await iterateCursor(sessionKey === void 0 ? policyStore.openKeyCursor() : policyStore.index("bySession").openKeyCursor(IDBKeyRange.only(sessionKey)), async (cursor) => {
|
|
373
375
|
const scope = getScopeFromPrimaryKey(cursor.primaryKey);
|
|
374
376
|
if (scope === null) return;
|
|
375
377
|
const keys = new Set(["_i"]);
|
|
376
|
-
await iterateCursor(entryStore.
|
|
378
|
+
await iterateCursor(entryStore.openKeyCursor(createScopeKeyRange(scope)), (entryCursor) => {
|
|
377
379
|
const entryKey = getEntryKeyFromPrimaryKey(entryCursor.primaryKey);
|
|
378
380
|
if (entryKey === null) return;
|
|
379
381
|
keys.add(getPayloadRecordKey(entryKey));
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as OfflineResolutionConflictParseError, $t as TSFDUseListQueryReturn, A as DefineListQueryOfflineOperations, At as OfflineUploadTransportContext, B as OfflineEntityMutationKind, Bt as ListQueryUseMultipleItemsQuery, C as PersistentStorageSchema, Cn as TSDFFocusDebugOperation, Ct as OfflineSessionUploadsConfig, D as CollectionOfflineOperationDefinition, Dt as OfflineUploadProgress, E as CollectionOfflineEntityRef, Et as OfflineUploadAdapter, F as ListQueryOfflineEntityRef, Ft as DerivedQuerySource, G as OfflineMutationQueueingPolicy, Gt as OptimisticListUpdate, H as OfflineMutationInput, Ht as OffsetPaginationConfig, I as ListQueryOfflineOperationDefinition, It as FetchListFnReturn, J as OfflineReplayRetryConfig, Jt as QueryStatus, K as OfflineOperationKind, Kt as PartialResourcesConfig, L as OfflineAccumulationConfig, Lt as FetchListFnReturnItem, M as DocumentOfflineOperationDefinition, Mt as SaveOfflineUploadArgs, N as GlobalOfflineEntity, Nt as DerivedQueriesConfig, O as DefineCollectionOfflineOperations, Ot as OfflineUploadSource, P as GlobalOfflineStatus, Pt as DerivedQueryContext, Q as OfflineResolutionActionForOperation, Qt as TSFDUseListItemReturn, R as OfflineAccumulationMergeContext, Rt as FieldsInput, S as PersistentStoragePreloadResult, Sn as TSDFDebugLogger, St as OfflineOperationUploadsContext, T as AnyOfflineOperationDefinition, Tt as OfflineUpload, U as OfflineMutationQueueingCause, Ut as OnListQueryInvalidate, V as OfflineMutationDescriptor, Vt as ListQueryUseMultipleListQueriesQuery, W as OfflineMutationQueueingConfig, Wt as OnListQueryItemInvalidate, X as OfflineResolutionActionError, Xt as TSFDListQuery, Y as OfflineResolutionAction, Yt as TSDFItemQuery, Z as OfflineResolutionActionErrorCode, Zt as TSFDListQueryState, _ as ListQueryOfflineOperationsConfig, _n as ScheduleFetchOptions, _t as OperationResult, a as AsyncStorageMetadataOrder, an as StoreFetchError, at as OfflineRetryExhaustedResolutionAction, b as PersistentStorageDataSchema, bn as TSDFDebugLogEntry, bt as defaultOfflineRuntimeConfig, c as AsyncStorageNamespaceCommitUpsert, cn as TSDFStatus, ct as OfflineSession, d as AsyncStorageNamespaceKind, dn as ValidStoreState, dt as OfflineSyncState, en as TSFDUsePendingOfflineItemsReturn, et as OfflineResolutionConflictParseErrorCode, f as AsyncStorageNamespaceScope, fn as fetchTypePriority, ft as OfflineTempEntitiesConfig, g as DocumentPersistentStorageConfig, gn as RequestSchedulerEvents, gt as OperationConflict, h as ConvertedPersistentStorageDataSchema, hn as RequestSchedulerEventData, ht as OfflineTempEntityPendingEntry, i as AsyncStorageDriverSetEntry, in as StoreError, it as OfflineResolutionRecordForStore, j as DefineOfflineOperation, jt as ReplaceOfflineUploadArgs, k as DefineDocumentOfflineOperations, kt as OfflineUploadState, l as AsyncStorageNamespaceGetResult, ln as UnwrapTSDFResult, lt as OfflineSessionConfig, m as CollectionPersistentStorageConfig, mn as FetchType, mt as OfflineTempEntityConfig, n as AsyncStorageDiscoveredScope, nn as MutationSkipped, nt as OfflineResolutionRecord, o as AsyncStorageNamespaceCommitArgs, on as StoreMutationError, ot as OfflineRuntimeConfig, p as AsyncStorageReadOptions, pn as mutationSkipped, pt as OfflineTempEntitiesReconciliation, q as OfflineQueueEntry, qt as QueryFetchPayload, r as AsyncStorageDriver, rn as PayloadDebounce, rt as OfflineResolutionRecordForOperation, s as AsyncStorageNamespaceCommitTouch, sn as StoreMutationErrorOptions, st as OfflineRuntimeConfigUpdate, t as AsyncStorageAdapter, tn as MaybeTSDFResult, tt as OfflineResolutionGenericAction, u as AsyncStorageNamespaceHandle, un as ValidPayload, ut as OfflineSupersedeConfig, v as ListQueryPersistentStorageConfig, vn as ScheduleFetchResults, vt as ParsedOfflineResolutionConflictResultForOperation, w as StorageAdapter, wn as TSDFLoggerOptions, wt as OfflineStoredUploadRecord, x as PersistentStorageErrorHandler, xn as TSDFDebugLogLevel, xt as OfflineMutationUploadsInput, y as PersistentStorageBaseConfig, yn as TSDFDebugLogArea, yt as ParsedOfflineResolutionConflictResultForStore, z as OfflineConflictResolutionAction, zt as FieldsOption } from "./types-DeZ9VDOe.js";
|
|
2
2
|
import { __LEGIT_ANY__ } from "@ls-stack/utils/saferTyping";
|
|
3
3
|
import { Emitter } from "evtmitter";
|
|
4
4
|
import { Context } from "react";
|
|
@@ -19,6 +19,19 @@ type OfflineMutationResult<T> = {
|
|
|
19
19
|
/** The mutation was durably queued for offline replay. */kind: 'queued';
|
|
20
20
|
};
|
|
21
21
|
//#endregion
|
|
22
|
+
//#region src/persistentStorage/removedStoresCleanup.d.ts
|
|
23
|
+
/** A store deleted from the app, declared in `createStoreManager({ removedStores })`. */
|
|
24
|
+
type RemovedStore = {
|
|
25
|
+
/** Id the deleted store used. */readonly id: string;
|
|
26
|
+
/**
|
|
27
|
+
* Adapter the deleted store persisted its data with. Add one entry per
|
|
28
|
+
* adapter when the store used more than one. Custom async adapters must be
|
|
29
|
+
* created with `createAsyncStorageAdapter` from a driver with a
|
|
30
|
+
* `storageId`.
|
|
31
|
+
*/
|
|
32
|
+
readonly adapter: StorageAdapter;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
22
35
|
//#region src/utils/performMutation.d.ts
|
|
23
36
|
/** Starts a temporary window-close block while a mutation is in progress. */
|
|
24
37
|
type BlockWindowCloseHandler = () => {
|
|
@@ -56,18 +69,29 @@ type StoreManagerOfflineApi<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
|
56
69
|
resetOfflineRuntimeConfig: () => void; /** Returns the latest aggregated offline status for this manager. */
|
|
57
70
|
getOfflineStatus: () => GlobalOfflineStatus; /** Returns the latest aggregated offline entities for this manager. */
|
|
58
71
|
getOfflineEntities: () => readonly GlobalOfflineEntity[]; /** Returns the latest aggregated offline resolutions for this manager. */
|
|
59
|
-
getOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
72
|
+
getOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
73
|
+
/**
|
|
74
|
+
* Applies a generic `retry` / `discard` action to any resolution listed by
|
|
75
|
+
* `getOfflineResolutions()` / `useOfflineResolutions()`, delegating to the
|
|
76
|
+
* store that owns it. Equivalent to calling that store's
|
|
77
|
+
* `resolveOfflineResolution(id, operation, { action })`, without needing the
|
|
78
|
+
* store instance or the operation name.
|
|
79
|
+
*
|
|
80
|
+
* Failures are returned instead of thrown: when the action is not applied,
|
|
81
|
+
* the result is an `OfflineResolutionActionError` whose `code` says why
|
|
82
|
+
* (unknown id, owning store not created with this manager, `retry` on a
|
|
83
|
+
* conflict, blocked resolution, ...). `requeue` and `commit` need
|
|
84
|
+
* operation-typed input and stay on the owning store API.
|
|
85
|
+
*
|
|
86
|
+
* A record can be retried when `kind === 'retry-exhausted'`, and can be
|
|
87
|
+
* retried or discarded only while `blockedResolutionCount === 0`.
|
|
88
|
+
*/
|
|
89
|
+
resolveOfflineResolution: (resolutionId: string, action: OfflineResolutionGenericAction) => Promise<Result<void, OfflineResolutionActionError>>; /** Returns the latest session-scoped offline uploads for this manager. */
|
|
60
90
|
getOfflineUploads: () => readonly OfflineUpload<TUploadRef>[]; /** Resolves a staged upload id to its latest final ref, uploading first if needed. */
|
|
61
91
|
resolveOfflineUpload: (id: string) => Promise<Result<TUploadRef, Error>>; /** Resolves multiple staged upload ids to their latest final refs. */
|
|
62
92
|
resolveOfflineUploads: (ids: readonly string[]) => Promise<Result<Record<string, TUploadRef>, Error>>; /** Saves a session-scoped upload locally for later dependency resolution. */
|
|
63
|
-
saveOfflineUpload: (args:
|
|
64
|
-
|
|
65
|
-
file: Blob | File;
|
|
66
|
-
}) => Promise<Result<void, Error>>; /** Replaces a previously stored session-scoped upload. */
|
|
67
|
-
replaceOfflineUpload: (args: {
|
|
68
|
-
id: string;
|
|
69
|
-
file: Blob | File;
|
|
70
|
-
}) => Promise<Result<void, Error>>; /** Loads a previously stored session-scoped upload. */
|
|
93
|
+
saveOfflineUpload: (args: SaveOfflineUploadArgs) => Promise<Result<void, Error>>; /** Replaces a previously stored session-scoped upload, keeping its metadata unless new metadata is passed. */
|
|
94
|
+
replaceOfflineUpload: (args: ReplaceOfflineUploadArgs) => Promise<Result<void, Error>>; /** Loads a previously stored session-scoped upload. */
|
|
71
95
|
loadOfflineUpload: (id: string) => Promise<Result<File | null, Error>>; /** Deletes a stored upload when it is no longer referenced. */
|
|
72
96
|
deleteOfflineUpload: (id: string) => Promise<Result<void, Error>>; /** React hook subscribing to the manager's aggregated offline status. */
|
|
73
97
|
useOfflineStatus: () => GlobalOfflineStatus; /** React hook subscribing to the manager's aggregated offline entities. */
|
|
@@ -85,7 +109,14 @@ type StoreManager<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
|
85
109
|
onMutationError: StoreManagerMutationErrorHandler | undefined; /** Shared defaults used by attached stores unless a store-level override exists. */
|
|
86
110
|
storeDefaults: StoreManagerStoreDefaults; /** Returns the unique ids of all currently registered store instances. */
|
|
87
111
|
getAllStoreIds: () => string[]; /** Resets all registered stores except the ignored logical ids. */
|
|
88
|
-
resetAll: (ignoreStores: string[]) => void;
|
|
112
|
+
resetAll: (ignoreStores: string[]) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Signals a shared real-time transport reconnect to all registered stores.
|
|
115
|
+
* While the offline session is in offline mode it only re-checks
|
|
116
|
+
* connectivity instead: each store is revalidated when it recovers (the session is back online, its queued
|
|
117
|
+
* mutations finished replaying and the store has nothing left waiting for
|
|
118
|
+
* a manual resolution).
|
|
119
|
+
*/
|
|
89
120
|
onTransportReconnect: () => void;
|
|
90
121
|
} & StoreManagerOfflineApi<TUploadRef>;
|
|
91
122
|
/** Options used to create a shared TSDF store manager. */
|
|
@@ -114,6 +145,32 @@ type CreateStoreManagerOptions<TUploadRef extends ValidPayload = ValidPayload> =
|
|
|
114
145
|
debugLogger?: TSDFLoggerOptions; /** Enables low-volume production-safe logs. Defaults to console logging; pass `false` to disable. */
|
|
115
146
|
logger?: TSDFLoggerOptions; /** Optional shared offline session config for every attached store. */
|
|
116
147
|
offlineSession?: OfflineSessionConfig<TUploadRef>;
|
|
148
|
+
/**
|
|
149
|
+
* Stores deleted from the app whose persisted data should be removed.
|
|
150
|
+
*
|
|
151
|
+
* Once, during idle time after startup, TSDF removes everything each listed
|
|
152
|
+
* store persisted with its adapter, in every session: cached data, offline
|
|
153
|
+
* entity records, and any queued offline mutations or pending resolutions,
|
|
154
|
+
* which no store can replay anymore. Unsent records it deletes are reported
|
|
155
|
+
* once through `onPersistentStorageError`. Later startups only read a small
|
|
156
|
+
* marker listing the id and adapter pairs already cleaned, so entries can be
|
|
157
|
+
* removed from this list once every user has run a version that includes
|
|
158
|
+
* them. An adapter that fails is reported and retried on the next startup.
|
|
159
|
+
*
|
|
160
|
+
* A listed id cannot be used by a store attached to this manager.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* createStoreManager({
|
|
165
|
+
* // ...
|
|
166
|
+
* removedStores: [
|
|
167
|
+
* { id: 'legacy-settings', adapter: 'local-sync' },
|
|
168
|
+
* { id: 'old-feed', adapter: indexedDbPersistentStorage },
|
|
169
|
+
* ],
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
removedStores?: readonly RemovedStore[];
|
|
117
174
|
};
|
|
118
175
|
declare function createStoreManager<TUploadRef extends ValidPayload = ValidPayload>(options: CreateStoreManagerOptions<TUploadRef>): StoreManager<TUploadRef>;
|
|
119
176
|
//#endregion
|
|
@@ -205,7 +262,11 @@ type CollectionStoreStoreEvents<ItemPayload extends ValidPayload> = {
|
|
|
205
262
|
mutationId: number;
|
|
206
263
|
items: ItemPayload[];
|
|
207
264
|
status: 'success' | 'error' | 'skipped';
|
|
208
|
-
};
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Emitted when an offline temp item is reconciled to its final payload, in
|
|
268
|
+
* every tab of the session, not only the one that sent the creation.
|
|
269
|
+
*/
|
|
209
270
|
tempEntityReconciled: {
|
|
210
271
|
tempId: ItemPayload;
|
|
211
272
|
finalPayload: ItemPayload;
|
|
@@ -248,7 +309,9 @@ type CollectionStoreOptions<ItemState extends ValidStoreState, ItemPayload exten
|
|
|
248
309
|
revalidateOnWindowFocus?: boolean | (() => boolean);
|
|
249
310
|
/** Reconnect-specific cooldown. Defaults to 2,000ms. The first reconnect revalidates immediately;
|
|
250
311
|
* additional reconnects within the cooldown are coalesced into one trailing
|
|
251
|
-
* revalidation.
|
|
312
|
+
* revalidation. Recovering from offline mode waits one cooldown for a
|
|
313
|
+
* reconnect before revalidating, so the two share one revalidation. Set to
|
|
314
|
+
* `0` to disable this cooldown. */
|
|
252
315
|
transportReconnectCooldownMs?: number; /** Called when an already-loaded item is invalidated. */
|
|
253
316
|
onInvalidate?: OnCollectionItemInvalidate<ItemState, ItemPayload>; /** Observes request scheduler lifecycle events for this store. */
|
|
254
317
|
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
@@ -475,7 +538,9 @@ type DocumentStoreOptions<State extends ValidStoreState, TOfflineOperations exte
|
|
|
475
538
|
revalidateOnWindowFocus?: boolean | (() => boolean);
|
|
476
539
|
/** Reconnect-specific cooldown. Defaults to 2,000ms. The first reconnect revalidates immediately;
|
|
477
540
|
* additional reconnects within the cooldown are coalesced into one trailing
|
|
478
|
-
* revalidation.
|
|
541
|
+
* revalidation. Recovering from offline mode waits one cooldown for a
|
|
542
|
+
* reconnect before revalidating, so the two share one revalidation. Set to
|
|
543
|
+
* `0` to disable this cooldown. */
|
|
479
544
|
transportReconnectCooldownMs?: number; /** Delay applied to medium-priority requests before they enter the scheduler. */
|
|
480
545
|
mediumPriorityDelayMs?: number; /** Observes request scheduler lifecycle events for this store. */
|
|
481
546
|
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
@@ -767,6 +832,10 @@ type ListQueryStoreStoreEvents<ItemPayload extends ValidPayload> = {
|
|
|
767
832
|
items: ItemPayload[];
|
|
768
833
|
status: 'success' | 'error' | 'skipped';
|
|
769
834
|
};
|
|
835
|
+
/**
|
|
836
|
+
* Emitted when an offline temp item is reconciled to its final payload, in
|
|
837
|
+
* every tab of the session, not only the one that sent the creation.
|
|
838
|
+
*/
|
|
770
839
|
tempEntityReconciled: {
|
|
771
840
|
tempId: ItemPayload;
|
|
772
841
|
finalPayload: ItemPayload;
|
|
@@ -1111,7 +1180,9 @@ type ListQueryStoreOptionsBase<ItemState extends ValidStoreState, QueryPayload e
|
|
|
1111
1180
|
revalidateOnWindowFocus?: boolean | (() => boolean);
|
|
1112
1181
|
/** Reconnect-specific cooldown. Defaults to 2,000ms. The first reconnect revalidates immediately;
|
|
1113
1182
|
* additional reconnects within the cooldown are coalesced into one trailing
|
|
1114
|
-
* revalidation.
|
|
1183
|
+
* revalidation. Recovering from offline mode waits one cooldown for a
|
|
1184
|
+
* reconnect before revalidating, so the two share one revalidation. Set to
|
|
1185
|
+
* `0` to disable this cooldown. */
|
|
1115
1186
|
transportReconnectCooldownMs?: number; /** Rules that keep cached query membership in sync after item updates. */
|
|
1116
1187
|
optimisticListUpdates?: OptimisticListUpdate<ItemState, QueryPayload, ItemPayload>[]; /** Called when an already-loaded query is invalidated. */
|
|
1117
1188
|
onInvalidateQuery?: OnListQueryInvalidate<QueryPayload>; /** Called when an already-loaded item is invalidated. */
|
|
@@ -1318,4 +1389,4 @@ declare function clearAllSessionStorage(sessionKey: string): Promise<void>;
|
|
|
1318
1389
|
//#region src/persistentStorage/opfsOfflineUploadAdapter.d.ts
|
|
1319
1390
|
declare const opfsOfflineUploadAdapter: OfflineUploadAdapter;
|
|
1320
1391
|
//#endregion
|
|
1321
|
-
export { type AsyncStorageAdapter, type AsyncStorageDiscoveredScope, type AsyncStorageDriver, type AsyncStorageDriverSetEntry, type AsyncStorageMetadataOrder, type AsyncStorageNamespaceCommitArgs, type AsyncStorageNamespaceCommitTouch, type AsyncStorageNamespaceCommitUpsert, type AsyncStorageNamespaceGetResult, type AsyncStorageNamespaceHandle, type AsyncStorageNamespaceKind, type AsyncStorageNamespaceScope, type AsyncStorageReadOptions, type BlockWindowCloseHandler, type CollectionOfflineEntityRef, type CollectionOfflineOperationDefinition, type CollectionPersistentStorageConfig, CollectionStateCleanup, CollectionStore, CollectionStoreEvents, CollectionStoreOptions, CollectionStoreStoreEvents, CollectionUseMultipleItemsQuery, type ConvertedPersistentStorageDataSchema, type CreateStoreManagerOptions, type DefineCollectionOfflineOperations, type DefineDocumentOfflineOperations, type DefineListQueryOfflineOperations, type DefineOfflineOperation, type DerivedQueriesConfig, type DerivedQueryContext, type DerivedQuerySource, type DocumentOfflineOperationDefinition, type DocumentPersistentStorageConfig, DocumentStatus, DocumentStore, DocumentStoreOptions, DocumentStoreState, DocumentStoreStoreEvents, type DynamicRealtimeThrottleMs, type FetchListFnReturn, type FetchListFnReturnItem, type FieldsInput, type FieldsOption, GET_ALL, type GlobalOfflineEntity, type GlobalOfflineStatus, IsOffScreenContext, type ListQueryOfflineEntityRef, type ListQueryOfflineOperationDefinition, type ListQueryPersistentStorageConfig, type ListQueryStore, type ListQueryStoreEvents, type ListQueryStoreOptions, type ListQueryUseMultipleItemsQuery, type ListQueryUseMultipleListQueriesQuery, type MaybeTSDFResult, type MutationDebounce, type MutationSkipped, type OfflineAccumulationConfig, type OfflineAccumulationMergeContext, type OfflineConflictResolutionAction, type OfflineEntityMutationKind, type OfflineMutationDescriptor, type OfflineMutationInput, type OfflineMutationQueueingCause, type OfflineMutationQueueingConfig, type OfflineMutationQueueingPolicy, type OfflineMutationResult, type OfflineMutationUploadsInput, type OfflineOperationKind, type OfflineOperationUploadsContext, type OfflineQueueEntry, type OfflineReplayRetryConfig, type OfflineResolutionAction, type OfflineResolutionActionForOperation, type OfflineResolutionConflictParseError, type OfflineResolutionConflictParseErrorCode, type OfflineResolutionRecord, type OfflineResolutionRecordForOperation, type OfflineResolutionRecordForStore, type OfflineRetryExhaustedResolutionAction, type OfflineRuntimeConfig, type OfflineRuntimeConfigUpdate, type OfflineSession, type OfflineSessionConfig, type OfflineSessionUploadsConfig, type OfflineStoredUploadRecord, type OfflineSupersedeConfig, type OfflineSyncState, type OfflineTempEntitiesConfig, type OfflineTempEntitiesReconciliation, type OfflineTempEntityConfig, type OfflineTempEntityPendingEntry, type OfflineUpload, type OfflineUploadAdapter, type OfflineUploadProgress, type OfflineUploadSource, type OfflineUploadState, type OfflineUploadTransportContext, type OffsetPaginationConfig, OnCollectionItemInvalidate, OnDocumentInvalidate, type OnListQueryInvalidate, type OnListQueryItemInvalidate, type OperationConflict, type OperationResult, type OptimisticListUpdate, type ParsedOfflineResolutionConflictResultForOperation, type PartialResourcesConfig, type PayloadDebounce, type PersistentStorageBaseConfig, type PersistentStorageDataSchema, type PersistentStoragePreloadResult, type PersistentStorageSchema, type QueryFetchPayload, type QueryStatus, type StorageAdapter, type StoreError, StoreFetchError, type StoreManager, StoreMutationError, type StoreMutationErrorOptions, type TSDFDebugLogArea, type TSDFDebugLogEntry, type TSDFDebugLogLevel, type TSDFDebugLogger, type TSDFFocusDebugOperation, type TSDFItemQuery, type TSDFLoggerOptions, type TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, type TSFDListQuery, type TSFDListQueryState, TSFDUseCollectionItemReturn, type TSFDUseListItemReturn, type TSFDUseListQueryReturn, type TSFDUsePendingOfflineItemsReturn, type ValidPayload, type ValidStoreState, clearAllSessionStorage, clearSessionStorage, createCollectionStore, createDocumentStore, createListQueryStore, createStoreManager, defaultOfflineRuntimeConfig, fetchTypePriority, getGlobalOfflineEntities, getGlobalOfflineResolutions, getGlobalOfflineStatus, localPersistentStorage, mutationSkipped, opfsOfflineUploadAdapter, useGlobalOfflineEntities, useGlobalOfflineResolutions, useGlobalOfflineStatus };
|
|
1392
|
+
export { type AsyncStorageAdapter, type AsyncStorageDiscoveredScope, type AsyncStorageDriver, type AsyncStorageDriverSetEntry, type AsyncStorageMetadataOrder, type AsyncStorageNamespaceCommitArgs, type AsyncStorageNamespaceCommitTouch, type AsyncStorageNamespaceCommitUpsert, type AsyncStorageNamespaceGetResult, type AsyncStorageNamespaceHandle, type AsyncStorageNamespaceKind, type AsyncStorageNamespaceScope, type AsyncStorageReadOptions, type BlockWindowCloseHandler, type CollectionOfflineEntityRef, type CollectionOfflineOperationDefinition, type CollectionPersistentStorageConfig, CollectionStateCleanup, CollectionStore, CollectionStoreEvents, CollectionStoreOptions, CollectionStoreStoreEvents, CollectionUseMultipleItemsQuery, type ConvertedPersistentStorageDataSchema, type CreateStoreManagerOptions, type DefineCollectionOfflineOperations, type DefineDocumentOfflineOperations, type DefineListQueryOfflineOperations, type DefineOfflineOperation, type DerivedQueriesConfig, type DerivedQueryContext, type DerivedQuerySource, type DocumentOfflineOperationDefinition, type DocumentPersistentStorageConfig, DocumentStatus, DocumentStore, DocumentStoreOptions, DocumentStoreState, DocumentStoreStoreEvents, type DynamicRealtimeThrottleMs, type FetchListFnReturn, type FetchListFnReturnItem, type FieldsInput, type FieldsOption, GET_ALL, type GlobalOfflineEntity, type GlobalOfflineStatus, IsOffScreenContext, type ListQueryOfflineEntityRef, type ListQueryOfflineOperationDefinition, type ListQueryPersistentStorageConfig, type ListQueryStore, type ListQueryStoreEvents, type ListQueryStoreOptions, type ListQueryUseMultipleItemsQuery, type ListQueryUseMultipleListQueriesQuery, type MaybeTSDFResult, type MutationDebounce, type MutationSkipped, type OfflineAccumulationConfig, type OfflineAccumulationMergeContext, type OfflineConflictResolutionAction, type OfflineEntityMutationKind, type OfflineMutationDescriptor, type OfflineMutationInput, type OfflineMutationQueueingCause, type OfflineMutationQueueingConfig, type OfflineMutationQueueingPolicy, type OfflineMutationResult, type OfflineMutationUploadsInput, type OfflineOperationKind, type OfflineOperationUploadsContext, type OfflineQueueEntry, type OfflineReplayRetryConfig, type OfflineResolutionAction, type OfflineResolutionActionError, type OfflineResolutionActionErrorCode, type OfflineResolutionActionForOperation, type OfflineResolutionConflictParseError, type OfflineResolutionConflictParseErrorCode, type OfflineResolutionGenericAction, type OfflineResolutionRecord, type OfflineResolutionRecordForOperation, type OfflineResolutionRecordForStore, type OfflineRetryExhaustedResolutionAction, type OfflineRuntimeConfig, type OfflineRuntimeConfigUpdate, type OfflineSession, type OfflineSessionConfig, type OfflineSessionUploadsConfig, type OfflineStoredUploadRecord, type OfflineSupersedeConfig, type OfflineSyncState, type OfflineTempEntitiesConfig, type OfflineTempEntitiesReconciliation, type OfflineTempEntityConfig, type OfflineTempEntityPendingEntry, type OfflineUpload, type OfflineUploadAdapter, type OfflineUploadProgress, type OfflineUploadSource, type OfflineUploadState, type OfflineUploadTransportContext, type OffsetPaginationConfig, OnCollectionItemInvalidate, OnDocumentInvalidate, type OnListQueryInvalidate, type OnListQueryItemInvalidate, type OperationConflict, type OperationResult, type OptimisticListUpdate, type ParsedOfflineResolutionConflictResultForOperation, type PartialResourcesConfig, type PayloadDebounce, type PersistentStorageBaseConfig, type PersistentStorageDataSchema, type PersistentStoragePreloadResult, type PersistentStorageSchema, type QueryFetchPayload, type QueryStatus, type RemovedStore, type ReplaceOfflineUploadArgs, type SaveOfflineUploadArgs, type StorageAdapter, type StoreError, StoreFetchError, type StoreManager, StoreMutationError, type StoreMutationErrorOptions, type TSDFDebugLogArea, type TSDFDebugLogEntry, type TSDFDebugLogLevel, type TSDFDebugLogger, type TSDFFocusDebugOperation, type TSDFItemQuery, type TSDFLoggerOptions, type TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, type TSFDListQuery, type TSFDListQueryState, TSFDUseCollectionItemReturn, type TSFDUseListItemReturn, type TSFDUseListQueryReturn, type TSFDUsePendingOfflineItemsReturn, type ValidPayload, type ValidStoreState, clearAllSessionStorage, clearSessionStorage, createCollectionStore, createDocumentStore, createListQueryStore, createStoreManager, defaultOfflineRuntimeConfig, fetchTypePriority, getGlobalOfflineEntities, getGlobalOfflineResolutions, getGlobalOfflineStatus, localPersistentStorage, mutationSkipped, opfsOfflineUploadAdapter, useGlobalOfflineEntities, useGlobalOfflineResolutions, useGlobalOfflineStatus };
|