tsdf 17.0.3 → 17.0.4
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-URS9eulL.js → asyncStorageAdapter-BuGjbXYA.js} +25 -165
- package/dist/{asyncStorageAdapter-DgsuE-T8.d.ts → asyncStorageAdapter-CMohMeKm.d.ts} +1 -1
- package/dist/{asyncStorageAdapters-Bxrrj_Mt.js → asyncStorageAdapters-ClUvxNQA.js} +2 -2
- package/dist/indexed-db-storage.d.ts +1 -1
- package/dist/indexed-db-storage.js +1 -1
- package/dist/{indexedDbPersistentStorage-BameJ4st.js → indexedDbPersistentStorage-BSlgLveB.js} +1 -11
- package/dist/main.d.ts +30 -34
- package/dist/main.js +257 -856
- package/dist/opfs-storage.d.ts +1 -1
- package/dist/opfs-storage.js +1 -1
- package/dist/{opfsPersistentStorage-BngS1m0X.d.ts → opfsPersistentStorage-Ci0JcCo5.d.ts} +1 -1
- package/dist/{opfsPersistentStorage-JsSCNBTr.js → opfsPersistentStorage-D_k77Srq.js} +1 -1
- package/dist/src/async-storage.d.ts +1 -0
- package/dist/src/cacheLimits/lruCacheRuntime.d.ts +9 -0
- package/dist/src/cacheLimits/scheduleIdleThrottled.d.ts +1 -0
- package/dist/src/cacheLimits/useRegisterActiveKeys.d.ts +1 -0
- package/dist/src/collectionStore/collectionCacheLimits.d.ts +1 -0
- package/dist/src/collectionStore/collectionStore.d.ts +385 -0
- package/dist/src/collectionStore/executeBatchFetch.d.ts +6 -0
- package/dist/src/collectionStore/useItem.d.ts +15 -0
- package/dist/src/collectionStore/useMultipleItems.d.ts +35 -0
- package/dist/src/debug.d.ts +30 -0
- package/dist/src/documentStore.d.ts +290 -0
- package/dist/src/hooks/useListItem.d.ts +22 -0
- package/dist/src/hooks/useListItemIsDeleted.d.ts +13 -0
- package/dist/src/hooks/useListItemIsLoading.d.ts +16 -0
- package/dist/src/indexed-db-storage.d.ts +1 -0
- package/dist/src/internal/offlineTestInstrumentation.d.ts +12 -0
- package/dist/src/internal/testTimelineTypes.d.ts +1 -0
- package/dist/src/invalidationUtils.d.ts +8 -0
- package/dist/src/isOffScreenContext.d.ts +16 -0
- package/dist/src/listQueryStore/createFetchApi.d.ts +1 -0
- package/dist/src/listQueryStore/createMutationApi.d.ts +1 -0
- package/dist/src/listQueryStore/executeItemBatchFetch.d.ts +20 -0
- package/dist/src/listQueryStore/executeQueryFetch.d.ts +7 -0
- package/dist/src/listQueryStore/itemFieldUtils.d.ts +77 -0
- package/dist/src/listQueryStore/listQueryCacheLimits.d.ts +1 -0
- package/dist/src/listQueryStore/listQueryStore.d.ts +538 -0
- package/dist/src/listQueryStore/types.d.ts +347 -0
- package/dist/src/listQueryStore/useFindItem.d.ts +7 -0
- package/dist/src/listQueryStore/useItem.d.ts +29 -0
- package/dist/src/listQueryStore/useListQuery.d.ts +29 -0
- package/dist/src/listQueryStore/useMultipleItems.d.ts +44 -0
- package/dist/src/listQueryStore/useMultipleListQueries.d.ts +46 -0
- package/dist/src/listQueryStore/usePendingOfflineItems.d.ts +19 -0
- package/dist/src/main.d.ts +23 -0
- package/dist/src/opfs-storage.d.ts +1 -0
- package/dist/src/persistentStorage/asyncStorageAdapter.d.ts +95 -0
- package/dist/src/persistentStorage/asyncStorageAdapters.d.ts +2 -0
- package/dist/src/persistentStorage/asyncStorageShared.d.ts +23 -0
- package/dist/src/persistentStorage/collectionStorePersistence.d.ts +26 -0
- package/dist/src/persistentStorage/compactListQueryLocalStorageEntry.d.ts +11 -0
- package/dist/src/persistentStorage/compactLocalStorageEntry.d.ts +8 -0
- package/dist/src/persistentStorage/documentEntryKey.d.ts +1 -0
- package/dist/src/persistentStorage/documentStorePersistence.d.ts +17 -0
- package/dist/src/persistentStorage/indexedDbAsyncStorageAdapter.d.ts +165 -0
- package/dist/src/persistentStorage/indexedDbPersistentStorage.d.ts +6 -0
- package/dist/src/persistentStorage/listQueryStorePersistence.d.ts +37 -0
- package/dist/src/persistentStorage/localStorageMetadata.d.ts +126 -0
- package/dist/src/persistentStorage/navigatorLocks.d.ts +3 -0
- package/dist/src/persistentStorage/offline/entityMetadata.d.ts +12 -0
- package/dist/src/persistentStorage/offline/fetchRuntime.d.ts +35 -0
- package/dist/src/persistentStorage/offline/mutationRuntime.d.ts +31 -0
- package/dist/src/persistentStorage/offline/offlineResolution.typeGuards.d.ts +1 -0
- package/dist/src/persistentStorage/offline/overlayStoreLifecycle.d.ts +13 -0
- package/dist/src/persistentStorage/offline/sessionCoordinator.d.ts +94 -0
- package/dist/src/persistentStorage/offline/sessionProtectionRegistry.d.ts +11 -0
- package/dist/src/persistentStorage/offline/storeController.d.ts +86 -0
- package/dist/src/persistentStorage/offline/types.d.ts +1255 -0
- package/dist/src/persistentStorage/offlineUploadRegistry.d.ts +11 -0
- package/dist/src/persistentStorage/offlineUploadTypes.d.ts +97 -0
- package/dist/src/persistentStorage/offlineUploadsShared.d.ts +4 -0
- package/dist/src/persistentStorage/opfsAsyncStorageAdapter.d.ts +24 -0
- package/dist/src/persistentStorage/opfsFileNaming.d.ts +23 -0
- package/dist/src/persistentStorage/opfsHelpers.d.ts +3 -0
- package/dist/src/persistentStorage/opfsOfflineUploadAdapter.d.ts +2 -0
- package/dist/src/persistentStorage/opfsPersistentStorage.d.ts +2 -0
- package/dist/src/persistentStorage/parsePersistedData.d.ts +45 -0
- package/dist/src/persistentStorage/persistenceUtils.d.ts +52 -0
- package/dist/src/persistentStorage/persistentStorageDefaults.d.ts +4 -0
- package/dist/src/persistentStorage/persistentStorageManager.d.ts +197 -0
- package/dist/src/persistentStorage/quotaDebug.d.ts +16 -0
- package/dist/src/persistentStorage/scheduleIdleCleanup.d.ts +28 -0
- package/dist/src/persistentStorage/storageAdapter.d.ts +41 -0
- package/dist/src/persistentStorage/storageEntryPrefixes.d.ts +16 -0
- package/dist/src/persistentStorage/types.d.ts +412 -0
- package/dist/src/persistentStorage/validateWithSchema.d.ts +12 -0
- package/dist/src/requestScheduler.d.ts +81 -0
- package/dist/src/storeManager.d.ts +160 -0
- package/dist/src/utils/automaticFetchPolicy.d.ts +29 -0
- package/dist/src/utils/browserTabsPriority.d.ts +43 -0
- package/dist/src/utils/browserTabsSync.d.ts +33 -0
- package/dist/src/utils/optimisticMutationTracker.d.ts +20 -0
- package/dist/src/utils/optimisticRollback.d.ts +11 -0
- package/dist/src/utils/payloadDebounce.d.ts +5 -0
- package/dist/src/utils/performMutation.d.ts +19 -0
- package/dist/src/utils/reusePrevIfEqual.d.ts +1 -0
- package/dist/src/utils/storeFocusLifecycle.d.ts +1 -0
- package/dist/src/utils/storeShared.d.ts +126 -0
- package/dist/src/utils/useEnsureIsLoaded.d.ts +6 -0
- package/dist/src/utils/useRequireFreshData.d.ts +6 -0
- package/dist/tests/basic-functionality/collection-store.test.d.ts +1 -0
- package/dist/tests/basic-functionality/document-store.test.d.ts +1 -0
- package/dist/tests/basic-functionality/list-query-state-manipulation.test.d.ts +1 -0
- package/dist/tests/basic-functionality/list-query-store.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-background-rtu-batch.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-background-rtu.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-background-scheduling.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-list-query-pagination.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-non-cancelable-fetches.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-optimistic-sync.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-partial-resources.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-priority.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-snapshot-consistency.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-state-methods.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-sync-coordinator.test.d.ts +1 -0
- package/dist/tests/browser-tabs/browser-tabs-test-helpers.d.ts +69 -0
- package/dist/tests/browser-tabs/focus-coordinator.test.d.ts +1 -0
- package/dist/tests/hooks/collection-hooks-2.test.d.ts +1 -0
- package/dist/tests/hooks/collection-hooks.test.d.ts +1 -0
- package/dist/tests/hooks/collection-useListItem.test.d.ts +1 -0
- package/dist/tests/hooks/debounce-payload-hooks.test.d.ts +1 -0
- package/dist/tests/hooks/disable-refetches.test.d.ts +1 -0
- package/dist/tests/hooks/document-hooks-2.test.d.ts +1 -0
- package/dist/tests/hooks/document-hooks.test.d.ts +1 -0
- package/dist/tests/hooks/document-useListItem.test.d.ts +1 -0
- package/dist/tests/hooks/fetch-error-recovery.test.d.ts +1 -0
- package/dist/tests/hooks/hook-memoization.test.d.ts +1 -0
- package/dist/tests/hooks/list-query-hooks-2.test.d.ts +1 -0
- package/dist/tests/hooks/list-query-hooks-3.test.d.ts +1 -0
- package/dist/tests/hooks/list-query-hooks-mutations.test.d.ts +1 -0
- package/dist/tests/hooks/list-query-hooks.test.d.ts +1 -0
- package/dist/tests/hooks/list-query-pending-offline-items.test.d.ts +1 -0
- package/dist/tests/hooks/off-screen-context.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-derived-queries.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-offset-pagination.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-optimistic-filters.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-partial-resources-2.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-partial-resources-3.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-partial-resources-regressions.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-partial-resources-show-partial-status.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-partial-resources.test.d.ts +1 -0
- package/dist/tests/list-query-features/list-query-size-coalescing-partial-resources.test.d.ts +1 -0
- package/dist/tests/mocks/browserTabsTestUtils.d.ts +17 -0
- package/dist/tests/mocks/collectionStoreTestEnv.d.ts +265 -0
- package/dist/tests/mocks/documentStoreTestEnv.d.ts +140 -0
- package/dist/tests/mocks/duplicateStoreGuard.test.d.ts +1 -0
- package/dist/tests/mocks/listQueryStoreTestEnv.d.ts +295 -0
- package/dist/tests/mocks/mockBrowserOpfs.d.ts +70 -0
- package/dist/tests/mocks/mockBrowserOpfs.test.d.ts +1 -0
- package/dist/tests/mocks/mockLocalStorageStore.d.ts +61 -0
- package/dist/tests/mocks/seedScenarioPersistentStorage.d.ts +51 -0
- package/dist/tests/mocks/serverMock.d.ts +56 -0
- package/dist/tests/mocks/serverTableMock.d.ts +174 -0
- package/dist/tests/mocks/testEnvUtils.d.ts +120 -0
- package/dist/tests/mocks/testScenarioPersistentStorage.test.d.ts +1 -0
- package/dist/tests/offline/offline-fetching-scenarios.test.d.ts +1 -0
- package/dist/tests/offline/offline-mixed-adapter-storage.test.d.ts +1 -0
- package/dist/tests/offline/offline-mutation-fallback.test.d.ts +1 -0
- package/dist/tests/offline/offline-network-recovery.test.d.ts +1 -0
- package/dist/tests/offline/offline-outage.test.d.ts +1 -0
- package/dist/tests/offline/offline-overlays.test.d.ts +1 -0
- package/dist/tests/offline/offline-query-replay.test.d.ts +1 -0
- package/dist/tests/offline/offline-reads.test.d.ts +1 -0
- package/dist/tests/offline/offline-replay-conflicts.test.d.ts +1 -0
- package/dist/tests/offline/offline-replay-queueing.test.d.ts +1 -0
- package/dist/tests/offline/offline-resolution-dependencies.test.d.ts +1 -0
- package/dist/tests/offline/offline-runtime-controls.test.d.ts +1 -0
- package/dist/tests/offline/offline-session-and-global-state.test.d.ts +1 -0
- package/dist/tests/offline/offline-storage.test.d.ts +1 -0
- package/dist/tests/offline/offline-uploads.test.d.ts +1 -0
- package/dist/tests/offline/offlineReplayTestShared.d.ts +292 -0
- package/dist/tests/offline/offlineTestShared.d.ts +156 -0
- package/dist/tests/perform-mutation/mutation-error-rollback.test.d.ts +1 -0
- package/dist/tests/perform-mutation/perform-mutation-block-window-close.test.d.ts +1 -0
- package/dist/tests/perform-mutation/perform-mutation-debounce.test.d.ts +1 -0
- package/dist/tests/perform-mutation/store-events.test.d.ts +1 -0
- package/dist/tests/persistent-storage/async-storage-efficiency/collection.test.d.ts +1 -0
- package/dist/tests/persistent-storage/async-storage-efficiency/document.test.d.ts +1 -0
- package/dist/tests/persistent-storage/async-storage-efficiency/list-query.test.d.ts +1 -0
- package/dist/tests/persistent-storage/async-storage-efficiency/maintenance.test.d.ts +1 -0
- package/dist/tests/persistent-storage/async-storage-efficiency/shared.d.ts +804 -0
- package/dist/tests/persistent-storage/async-storage-shared.test.d.ts +1 -0
- package/dist/tests/persistent-storage/collection-store-persistence.converted.opfs.test.d.ts +1 -0
- package/dist/tests/persistent-storage/collection-store-persistence.converted.test.d.ts +1 -0
- package/dist/tests/persistent-storage/collection-store-persistence.opfs.test.d.ts +1 -0
- package/dist/tests/persistent-storage/collection-store-persistence.test.d.ts +1 -0
- package/dist/tests/persistent-storage/document-store-persistence.converted.opfs.test.d.ts +1 -0
- package/dist/tests/persistent-storage/document-store-persistence.converted.test.d.ts +1 -0
- package/dist/tests/persistent-storage/document-store-persistence.opfs.test.d.ts +1 -0
- package/dist/tests/persistent-storage/document-store-persistence.test.d.ts +1 -0
- package/dist/tests/persistent-storage/expiration-scan.test.d.ts +1 -0
- package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/collection.test.d.ts +1 -0
- package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/document.test.d.ts +1 -0
- package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/list-query.test.d.ts +1 -0
- package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/maintenance.test.d.ts +1 -0
- package/dist/tests/persistent-storage/indexeddb-async-storage-efficiency/shared.d.ts +780 -0
- package/dist/tests/persistent-storage/indexeddb-storage-adapter.test.d.ts +1 -0
- package/dist/tests/persistent-storage/list-query-store-persistence.converted.opfs.test.d.ts +1 -0
- package/dist/tests/persistent-storage/list-query-store-persistence.converted.test.d.ts +1 -0
- package/dist/tests/persistent-storage/list-query-store-persistence.opfs.test.d.ts +1 -0
- package/dist/tests/persistent-storage/list-query-store-persistence.test.d.ts +1 -0
- package/dist/tests/persistent-storage/persistence-with-tabs-sync.test.d.ts +1 -0
- package/dist/tests/persistent-storage/persistentStorageByteBudgetTestUtils.d.ts +18 -0
- package/dist/tests/persistent-storage/quota-exceeded-recovery-no-locks.test.d.ts +1 -0
- package/dist/tests/persistent-storage/quota-exceeded-recovery.test.d.ts +1 -0
- package/dist/tests/persistent-storage/quotaRecoveryTestUtils.d.ts +228 -0
- package/dist/tests/persistent-storage/storage-adapter.test.d.ts +1 -0
- package/dist/tests/persistent-storage/sync-storage-efficiency/collection.test.d.ts +1 -0
- package/dist/tests/persistent-storage/sync-storage-efficiency/document.test.d.ts +1 -0
- package/dist/tests/persistent-storage/sync-storage-efficiency/list-query.test.d.ts +1 -0
- package/dist/tests/persistent-storage/sync-storage-efficiency/maintenance.test.d.ts +1 -0
- package/dist/tests/persistent-storage/sync-storage-efficiency/shared.d.ts +784 -0
- package/dist/tests/playwright/browser-tabs.spec.d.ts +1 -0
- package/dist/tests/playwright/persistent-storage.spec.d.ts +1 -0
- package/dist/tests/request-schedulling/batch-medium-priority.test.d.ts +1 -0
- package/dist/tests/request-schedulling/batch-realtime-updates.test.d.ts +1 -0
- package/dist/tests/request-schedulling/collection-batch-coalescing.test.d.ts +1 -0
- package/dist/tests/request-schedulling/collection-batch-key-grouping.test.d.ts +1 -0
- package/dist/tests/request-schedulling/collection-fetch-orchestration.test.d.ts +1 -0
- package/dist/tests/request-schedulling/document-await-fetch.test.d.ts +1 -0
- package/dist/tests/request-schedulling/document-base-coalescing.test.d.ts +1 -0
- package/dist/tests/request-schedulling/document-fetch-orchestration.test.d.ts +1 -0
- package/dist/tests/request-schedulling/document-medium-priority-fetch.test.d.ts +1 -0
- package/dist/tests/request-schedulling/document-realtime-updates.test.d.ts +1 -0
- package/dist/tests/request-schedulling/list-query-item-batch-coalescing.test.d.ts +1 -0
- package/dist/tests/request-schedulling/list-query-item-batch-key-grouping.test.d.ts +1 -0
- package/dist/tests/request-schedulling/list-query-size-coalescing.test.d.ts +1 -0
- package/dist/tests/request-schedulling/medium-vs-realtime.test.d.ts +1 -0
- package/dist/tests/request-schedulling/request-scheduler-cross-tab-sync.test.d.ts +1 -0
- package/dist/tests/request-schedulling/window-focus.test.d.ts +1 -0
- package/dist/tests/store-manager.test.d.ts +1 -0
- package/dist/tests/user-facing-api/collection-offline-usage.test.d.ts +1 -0
- package/dist/tests/user-facing-api/document-offline-usage.test.d.ts +1 -0
- package/dist/tests/user-facing-api/list-query-offline-usage.test.d.ts +1 -0
- package/dist/tests/user-facing-api/result-returning-callbacks.test.d.ts +1 -0
- package/dist/tests/utils/genericTestUtils.d.ts +6 -0
- package/dist/tests/utils/indexedDbPersistentStorageOptimizationTestUtils.d.ts +79 -0
- package/dist/tests/utils/indexedDbPersistentStorageTestStore.d.ts +181 -0
- package/dist/tests/utils/listQueryHooksTestUtils.d.ts +8 -0
- package/dist/tests/utils/networkMock.d.ts +11 -0
- package/dist/tests/utils/opfsPersistentStorageTestStore.d.ts +220 -0
- package/dist/tests/utils/persistentStorageOptimizationTestUtils.d.ts +54 -0
- package/dist/tests/utils/persistentStorageOptimizationTestUtils.test.d.ts +1 -0
- package/dist/tests/utils/persistentStorageTestStore.d.ts +66 -0
- package/dist/tests/utils/resetSessionForTests.d.ts +3 -0
- package/dist/tests/utils/withSuppressedActError.d.ts +4 -0
- package/dist/{types-BlyGC_PO.d.ts → types-D0ttVGmj.d.ts} +3 -3
- package/package.json +2 -2
|
@@ -0,0 +1,1255 @@
|
|
|
1
|
+
import type { __LEGIT_ANY__ } from '@ls-stack/utils/saferTyping';
|
|
2
|
+
import type { Result as ResultType } from 't-result';
|
|
3
|
+
import type { ValidPayload, ValidStoreState } from '../../utils/storeShared';
|
|
4
|
+
import type { OfflineAttachedUploadIds, OfflineOperationUploadsContext, OfflineSessionUploadsConfig, OfflineUpload } from '../offlineUploadTypes';
|
|
5
|
+
import type { PersistentStorageSchema } from '../types';
|
|
6
|
+
import type { SchemaValidationError } from '../validateWithSchema';
|
|
7
|
+
/** Store kinds supported by offline replay and sync state tracking. */
|
|
8
|
+
export type OfflineStoreType = 'document' | 'collection' | 'listQuery';
|
|
9
|
+
/** Phase where a failure occurred during offline-enabled operation flow. */
|
|
10
|
+
export type OfflineFailurePhase = 'fetch' | 'mutation' | 'sync';
|
|
11
|
+
/** High-level classification used by outage detection. */
|
|
12
|
+
export type OfflineFailureClassification = 'outage' | 'network' | 'ignore';
|
|
13
|
+
/** Kinds of entities participating in offline conflict/sync tracking. */
|
|
14
|
+
export type OfflineEntityKind = 'document' | 'item' | 'query';
|
|
15
|
+
/** Lifecycle declared per offline operation definition. */
|
|
16
|
+
export type OfflineOperationKind = 'create' | 'update' | 'delete';
|
|
17
|
+
/** Effective lifecycle derived for an offline entity across queued work. */
|
|
18
|
+
export type OfflineEntityMutationKind = 'create' | 'createAndUpdate' | 'update' | 'delete';
|
|
19
|
+
/** Connectivity cause currently governing offline mutation queueing. */
|
|
20
|
+
export type OfflineMutationQueueingCause = 'network' | 'outage';
|
|
21
|
+
/** Root policy value for whether offline-enabled mutations may queue. */
|
|
22
|
+
export type OfflineMutationQueueingPolicy = 'allow' | 'disallow';
|
|
23
|
+
/** Root mutation queueing policy shared by all configured offline operations. */
|
|
24
|
+
export type OfflineMutationQueueingConfig = {
|
|
25
|
+
/**
|
|
26
|
+
* Controls whether offline-enabled mutations may queue while network mode is
|
|
27
|
+
* active, including browser-detected offline and classified network failures.
|
|
28
|
+
* @default 'allow'
|
|
29
|
+
*/
|
|
30
|
+
network?: OfflineMutationQueueingPolicy;
|
|
31
|
+
/**
|
|
32
|
+
* Controls whether offline-enabled mutations may queue while outage mode is
|
|
33
|
+
* active.
|
|
34
|
+
* @default 'allow'
|
|
35
|
+
*/
|
|
36
|
+
outage?: OfflineMutationQueueingPolicy;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Effective runtime offline controls exposed through an offline session.
|
|
40
|
+
*
|
|
41
|
+
* All fields are session-scoped and affect every store attached to the same
|
|
42
|
+
* offline session.
|
|
43
|
+
*/
|
|
44
|
+
export type OfflineRuntimeConfig = {
|
|
45
|
+
/** Whether future operations may enter network offline handling. */
|
|
46
|
+
network: {
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
};
|
|
49
|
+
/** Whether future operations may enter outage offline handling. */
|
|
50
|
+
outage: {
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
};
|
|
53
|
+
/** Effective queue admission policy for offline-enabled mutations. */
|
|
54
|
+
mutationQueueing: {
|
|
55
|
+
network: OfflineMutationQueueingPolicy;
|
|
56
|
+
outage: OfflineMutationQueueingPolicy;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** Default runtime config when offline is not configured or no session exists. */
|
|
60
|
+
export declare const defaultOfflineRuntimeConfig: OfflineRuntimeConfig;
|
|
61
|
+
/**
|
|
62
|
+
* Partial runtime offline control update accepted by an offline session.
|
|
63
|
+
*
|
|
64
|
+
* Provided fields shallow-merge into the current runtime config.
|
|
65
|
+
*/
|
|
66
|
+
export type OfflineRuntimeConfigUpdate = {
|
|
67
|
+
/** Optional session-scoped update for network mode enablement. */
|
|
68
|
+
network?: {
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
};
|
|
71
|
+
/** Optional session-scoped update for outage mode enablement. */
|
|
72
|
+
outage?: {
|
|
73
|
+
enabled?: boolean;
|
|
74
|
+
};
|
|
75
|
+
/** Optional session-scoped update for offline mutation queue admission policy. */
|
|
76
|
+
mutationQueueing?: {
|
|
77
|
+
network?: OfflineMutationQueueingPolicy;
|
|
78
|
+
outage?: OfflineMutationQueueingPolicy;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/** Context passed into offline failure classification hooks. */
|
|
82
|
+
export type OfflineFailureContext = {
|
|
83
|
+
/** Phase in which the failure was detected. */
|
|
84
|
+
phase: OfflineFailurePhase;
|
|
85
|
+
/** Store type affected by the failure. */
|
|
86
|
+
storeType: OfflineStoreType;
|
|
87
|
+
/** Optional operation name associated with the failure. */
|
|
88
|
+
operationName?: string;
|
|
89
|
+
/** Session key used by browser tab and persistence scoping. */
|
|
90
|
+
sessionKey: string;
|
|
91
|
+
};
|
|
92
|
+
/** Re-check strategy for recovery probing. Omitted fields use built-in defaults (which differ between network and outage modes). */
|
|
93
|
+
export type OfflineRecoveryProbeConfig = {
|
|
94
|
+
/**
|
|
95
|
+
* Initial recovery check delay, in milliseconds.
|
|
96
|
+
* @default 5_000 (network) / 30_000 (outage)
|
|
97
|
+
*/
|
|
98
|
+
initialIntervalMs?: number;
|
|
99
|
+
/**
|
|
100
|
+
* Maximum recovery check delay, in milliseconds.
|
|
101
|
+
* @default 60_000 (network) / 300_000 (outage)
|
|
102
|
+
*/
|
|
103
|
+
maxIntervalMs?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Multiplicative backoff between recovery probes.
|
|
106
|
+
* @default 2
|
|
107
|
+
*/
|
|
108
|
+
backoffMultiplier?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Jitter ratio (0-1) applied to the recovery probe delay.
|
|
111
|
+
* @default 0.2
|
|
112
|
+
*/
|
|
113
|
+
jitterRatio?: number;
|
|
114
|
+
};
|
|
115
|
+
/** Network availability mode configuration for offline controls. */
|
|
116
|
+
export type OfflineNetworkModeConfig = {
|
|
117
|
+
/** Enable network connectivity detection and tracking. */
|
|
118
|
+
enabled: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* If true, subscribe to browser `online` / `offline` events.
|
|
121
|
+
* @default true
|
|
122
|
+
*/
|
|
123
|
+
listenToBrowserEvents?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Optional override for network connectivity checks.
|
|
126
|
+
* Return `true` when network should be considered offline.
|
|
127
|
+
*/
|
|
128
|
+
getIsOffline?: () => boolean | Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Probe whether classified network recovery has completed.
|
|
131
|
+
* Return `true` when the session should leave network offline mode.
|
|
132
|
+
*/
|
|
133
|
+
recoveryCheck?: (ctx: {
|
|
134
|
+
sessionKey: string;
|
|
135
|
+
}) => Promise<boolean> | boolean;
|
|
136
|
+
/** Optional probe config to tune classified network recovery behavior. */
|
|
137
|
+
recoveryProbe?: OfflineRecoveryProbeConfig;
|
|
138
|
+
};
|
|
139
|
+
/** Server outage detection and recovery configuration. */
|
|
140
|
+
export type OfflineOutageModeConfig = {
|
|
141
|
+
/** Enable outage mode logic and confirmation retry flow. */
|
|
142
|
+
enabled: boolean;
|
|
143
|
+
/** Probe the remote service to confirm outage recovery. */
|
|
144
|
+
recoveryCheck: (ctx: {
|
|
145
|
+
sessionKey: string;
|
|
146
|
+
}) => Promise<boolean> | boolean;
|
|
147
|
+
/** Optional probe config to tune recovery behavior. */
|
|
148
|
+
recoveryProbe?: OfflineRecoveryProbeConfig;
|
|
149
|
+
};
|
|
150
|
+
/** Fixed replay retry policy for healthy online replay failures. Omitted fields use built-in defaults. */
|
|
151
|
+
export type OfflineReplayRetryConfig = {
|
|
152
|
+
/**
|
|
153
|
+
* Max counted failures before manual resolution is required.
|
|
154
|
+
* @default 3
|
|
155
|
+
*/
|
|
156
|
+
maxFailures?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Fixed delay between replay retries, in milliseconds.
|
|
159
|
+
* @default 5000
|
|
160
|
+
*/
|
|
161
|
+
intervalMs?: number;
|
|
162
|
+
};
|
|
163
|
+
/** Shared offline/session policy reused by every store in the same session. */
|
|
164
|
+
export type OfflineSessionConfig<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
165
|
+
/**
|
|
166
|
+
* Classify a remote failure as `outage`, `network`, or `ignore`.
|
|
167
|
+
* `outage` activates outage recovery behavior.
|
|
168
|
+
* `network` activates network offline handling for future operations only
|
|
169
|
+
* when `network.enabled` is true. Existing offline recovery may keep using
|
|
170
|
+
* classifications until already-active work finishes recovering.
|
|
171
|
+
*/
|
|
172
|
+
classifyFailure?: (error: unknown, ctx: OfflineFailureContext) => Promise<OfflineFailureClassification> | OfflineFailureClassification;
|
|
173
|
+
/**
|
|
174
|
+
* Optional replay-only classifier for ambiguous sync failures that stayed
|
|
175
|
+
* online (`classifyFailure(...) === 'ignore'`).
|
|
176
|
+
*
|
|
177
|
+
* Return `true` only when automatically re-sending the replayed mutation is
|
|
178
|
+
* known to be safe. Return `false` to avoid auto-replay retries; in that
|
|
179
|
+
* case the entry still enters `needs-confirmation` so `shouldSkipSync` /
|
|
180
|
+
* conflict checks can run before the mutation is promoted to manual
|
|
181
|
+
* resolution.
|
|
182
|
+
*/
|
|
183
|
+
classifyRetryableFailure?: (error: unknown, ctx: OfflineFailureContext) => Promise<boolean> | boolean;
|
|
184
|
+
/** Network detection strategy and browser integration. */
|
|
185
|
+
network?: OfflineNetworkModeConfig;
|
|
186
|
+
/** Outage detection and recovery strategy for remote failures. */
|
|
187
|
+
outage?: OfflineOutageModeConfig;
|
|
188
|
+
/** Fixed retry policy for healthy online replay failures. */
|
|
189
|
+
replayRetry?: OfflineReplayRetryConfig;
|
|
190
|
+
/**
|
|
191
|
+
* Root policy controlling whether offline-enabled mutations may enter the
|
|
192
|
+
* durable offline queue for each active offline cause.
|
|
193
|
+
* @default undefined
|
|
194
|
+
*/
|
|
195
|
+
mutationQueueing?: OfflineMutationQueueingConfig;
|
|
196
|
+
/** Optional upload transport/storage config shared by the whole session. */
|
|
197
|
+
uploads?: OfflineSessionUploadsConfig<TUploadRef>;
|
|
198
|
+
};
|
|
199
|
+
/** Per-session offline status snapshot shared across tabs. */
|
|
200
|
+
export type GlobalOfflineStatus = {
|
|
201
|
+
/** Session key for this status bucket. */
|
|
202
|
+
sessionKey: string;
|
|
203
|
+
/**
|
|
204
|
+
* Network mode admission enablement plus the last observed network-offline
|
|
205
|
+
* state for this session. `active` is preserved even while new admission is
|
|
206
|
+
* disabled so existing offline work can recover and sync safely.
|
|
207
|
+
*/
|
|
208
|
+
network: {
|
|
209
|
+
enabled: boolean;
|
|
210
|
+
active: boolean;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Outage mode admission enablement plus the last observed outage-active
|
|
214
|
+
* state for this session. `active` is preserved even while new admission is
|
|
215
|
+
* disabled so existing offline work can recover and sync safely.
|
|
216
|
+
*/
|
|
217
|
+
outage: {
|
|
218
|
+
enabled: boolean;
|
|
219
|
+
active: boolean;
|
|
220
|
+
};
|
|
221
|
+
/** Whether the session currently has any active offline cause. */
|
|
222
|
+
isOfflineMode: boolean;
|
|
223
|
+
/** Whether this tab currently acts as leader for this session. */
|
|
224
|
+
isLeader: boolean;
|
|
225
|
+
/** Timestamp when this status entry was last updated. */
|
|
226
|
+
updatedAt: number;
|
|
227
|
+
/** Timestamp of the last failure, if any. */
|
|
228
|
+
lastFailureAt: number | null;
|
|
229
|
+
/** Timestamp of last recovery probe execution, if any. */
|
|
230
|
+
lastRecoveryCheckAt: number | null;
|
|
231
|
+
};
|
|
232
|
+
/** Queue state of an offline mutation entry. */
|
|
233
|
+
export type OfflineSyncState = 'pending' | 'syncing' | 'needs-confirmation';
|
|
234
|
+
/** Aggregated offline status for a tracked document/item/query entity. */
|
|
235
|
+
export type GlobalOfflineEntity = {
|
|
236
|
+
/** Internal entity identifier tracked by offline machinery. */
|
|
237
|
+
id: string;
|
|
238
|
+
/** Session key for this offline entity. */
|
|
239
|
+
sessionKey: string;
|
|
240
|
+
/** Store name where the entity is defined. */
|
|
241
|
+
storeName: string;
|
|
242
|
+
/** Store type this entity belongs to. */
|
|
243
|
+
storeType: OfflineStoreType;
|
|
244
|
+
/** Entity key used for deduping and conflict scoping. */
|
|
245
|
+
entityKey: string;
|
|
246
|
+
/** Entity kind used in queue partitioning. */
|
|
247
|
+
entityKind: OfflineEntityKind;
|
|
248
|
+
/** Effective lifecycle derived from queued operations targeting this entity. */
|
|
249
|
+
kind: OfflineEntityMutationKind;
|
|
250
|
+
/** Number of pending mutations waiting for sync. */
|
|
251
|
+
pendingMutations: number;
|
|
252
|
+
/** Current sync state for the entity. */
|
|
253
|
+
syncState: OfflineSyncState | 'resolution-required';
|
|
254
|
+
/** Whether the entity currently requires manual resolution. */
|
|
255
|
+
requiresResolution: boolean;
|
|
256
|
+
/** Resolution ids currently blocking this entity from being resolved/applied. */
|
|
257
|
+
blockedByResolutionIds: string[];
|
|
258
|
+
/** Child resolution ids currently derived from this entity's dependency chain. */
|
|
259
|
+
childResolutionIds: string[];
|
|
260
|
+
/** Number of blocking parent resolutions currently affecting this entity. */
|
|
261
|
+
blockedResolutionCount: number;
|
|
262
|
+
/** Number of child resolutions currently derived from this entity's dependency chain. */
|
|
263
|
+
childResolutionCount: number;
|
|
264
|
+
/** Creation timestamp for lifecycle bookkeeping. */
|
|
265
|
+
createdAt: number;
|
|
266
|
+
/** Last mutation/update timestamp. */
|
|
267
|
+
updatedAt: number;
|
|
268
|
+
/** Optional temporary ID for optimistic create flows. */
|
|
269
|
+
tempId?: ValidPayload;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Internal variant of {@link GlobalOfflineEntity} that carries an optional
|
|
273
|
+
* derived item payload for hooks that need to resolve payloads from offline
|
|
274
|
+
* metadata without a mounted query. Not part of the public API.
|
|
275
|
+
*/
|
|
276
|
+
export type InternalGlobalOfflineEntity = GlobalOfflineEntity & {
|
|
277
|
+
payload?: ValidPayload;
|
|
278
|
+
};
|
|
279
|
+
/** Reference to an entity participating in offline sync tracking. */
|
|
280
|
+
export type OfflineEntityRef = {
|
|
281
|
+
entityKey: string;
|
|
282
|
+
entityKind: OfflineEntityKind;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Persisted offline conflict payload.
|
|
286
|
+
*
|
|
287
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
288
|
+
* @typeParam TInput - Original mutation input associated with the conflict.
|
|
289
|
+
*/
|
|
290
|
+
type OfflineConflictResolutionRecordBase<TConflict = unknown, TInput = unknown> = {
|
|
291
|
+
/** Resolution record identifier. */
|
|
292
|
+
id: string;
|
|
293
|
+
/** Resolution kind. */
|
|
294
|
+
kind: 'conflict';
|
|
295
|
+
/** Queue entry identifier that produced this conflict. */
|
|
296
|
+
entryId: string;
|
|
297
|
+
/** Session key that owns this conflict record. */
|
|
298
|
+
sessionKey: string;
|
|
299
|
+
/** Store name associated with the conflict. */
|
|
300
|
+
storeName: string;
|
|
301
|
+
/** Store type associated with the conflict. */
|
|
302
|
+
storeType: OfflineStoreType;
|
|
303
|
+
/** Operation name linked to the conflict. */
|
|
304
|
+
operation: string;
|
|
305
|
+
/** Input value that triggered the conflict. */
|
|
306
|
+
input: TInput;
|
|
307
|
+
/** Conflict payload returned by the resolver. */
|
|
308
|
+
conflict: TConflict;
|
|
309
|
+
/** Timestamp when the original queued mutation was enqueued. */
|
|
310
|
+
enqueuedAt: number;
|
|
311
|
+
/** Entity references involved in the conflict. */
|
|
312
|
+
entityRefs: OfflineEntityRef[];
|
|
313
|
+
/** Conflict creation timestamp. */
|
|
314
|
+
createdAt: number;
|
|
315
|
+
/** Conflict update timestamp. */
|
|
316
|
+
updatedAt: number;
|
|
317
|
+
/** Optional temporary IDs associated with optimistic entity flow. */
|
|
318
|
+
tempIds?: ValidPayload[];
|
|
319
|
+
/** Maps original direct-upload keys to their persisted session upload ids. */
|
|
320
|
+
attachedUploadIds?: OfflineAttachedUploadIds;
|
|
321
|
+
/** Session upload ids that must resolve before replaying the mutation. */
|
|
322
|
+
dependencyUploadIds?: string[];
|
|
323
|
+
};
|
|
324
|
+
/** Derived dependency metadata exposed for offline manual resolutions. */
|
|
325
|
+
export type OfflineResolutionDependencyMetadata = {
|
|
326
|
+
/** Parent resolution ids that must be cleared before this resolution can be retried or discarded. */
|
|
327
|
+
blockedByResolutionIds: string[];
|
|
328
|
+
/** Child manual resolutions currently derived from this resolution's dependency chain. */
|
|
329
|
+
childResolutionIds: string[];
|
|
330
|
+
/** Number of blocking parent resolutions affecting this resolution. */
|
|
331
|
+
blockedResolutionCount: number;
|
|
332
|
+
/** Number of child manual resolutions currently derived from this resolution. */
|
|
333
|
+
childResolutionCount: number;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Persisted offline conflict payload with derived dependency metadata.
|
|
337
|
+
*
|
|
338
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
339
|
+
* @typeParam TInput - Original mutation input associated with the conflict.
|
|
340
|
+
*/
|
|
341
|
+
export type OfflineConflictResolutionRecord<TConflict = unknown, TInput = unknown> = OfflineConflictResolutionRecordBase<TConflict, TInput> & OfflineResolutionDependencyMetadata;
|
|
342
|
+
/**
|
|
343
|
+
* Persisted resolution record created when replay retries are exhausted.
|
|
344
|
+
*
|
|
345
|
+
* @typeParam TInput - Original mutation input associated with the replay failure.
|
|
346
|
+
*/
|
|
347
|
+
type OfflineRetryExhaustedResolutionRecordBase<TInput = unknown> = {
|
|
348
|
+
/** Resolution record identifier. */
|
|
349
|
+
id: string;
|
|
350
|
+
/** Resolution kind. */
|
|
351
|
+
kind: 'retry-exhausted';
|
|
352
|
+
/** Queue entry identifier that exhausted replay retries. */
|
|
353
|
+
entryId: string;
|
|
354
|
+
/** Session key that owns this resolution record. */
|
|
355
|
+
sessionKey: string;
|
|
356
|
+
/** Store name associated with the resolution. */
|
|
357
|
+
storeName: string;
|
|
358
|
+
/** Store type associated with the resolution. */
|
|
359
|
+
storeType: OfflineStoreType;
|
|
360
|
+
/** Operation name linked to the replay failure. */
|
|
361
|
+
operation: string;
|
|
362
|
+
/** Input value that exhausted replay retries. */
|
|
363
|
+
input: TInput;
|
|
364
|
+
/** Timestamp when the original queued mutation was enqueued. */
|
|
365
|
+
enqueuedAt: number;
|
|
366
|
+
/** Entity references involved in the resolution. */
|
|
367
|
+
entityRefs: OfflineEntityRef[];
|
|
368
|
+
/** Last replay error snapshot captured before exhaustion. */
|
|
369
|
+
lastReplayError: {
|
|
370
|
+
message: string;
|
|
371
|
+
};
|
|
372
|
+
/** Resolution creation timestamp. */
|
|
373
|
+
createdAt: number;
|
|
374
|
+
/** Resolution update timestamp. */
|
|
375
|
+
updatedAt: number;
|
|
376
|
+
/** Optional temporary IDs associated with optimistic entity flow. */
|
|
377
|
+
tempIds?: ValidPayload[];
|
|
378
|
+
/** Maps original direct-upload keys to their persisted session upload ids. */
|
|
379
|
+
attachedUploadIds?: OfflineAttachedUploadIds;
|
|
380
|
+
/** Session upload ids that must resolve before replaying the mutation. */
|
|
381
|
+
dependencyUploadIds?: string[];
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Persisted resolution record created when replay retries are exhausted, plus
|
|
385
|
+
* derived dependency metadata.
|
|
386
|
+
*
|
|
387
|
+
* @typeParam TInput - Original mutation input associated with the replay failure.
|
|
388
|
+
*/
|
|
389
|
+
export type OfflineRetryExhaustedResolutionRecord<TInput = unknown> = OfflineRetryExhaustedResolutionRecordBase<TInput> & OfflineResolutionDependencyMetadata;
|
|
390
|
+
/**
|
|
391
|
+
* Persisted offline resolution payload.
|
|
392
|
+
*
|
|
393
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
394
|
+
* @typeParam TInput - Original mutation input associated with the resolution.
|
|
395
|
+
*/
|
|
396
|
+
export type OfflineResolutionRecord<TConflict = unknown, TInput = unknown> = OfflineConflictResolutionRecord<TConflict, TInput> | OfflineRetryExhaustedResolutionRecord<TInput>;
|
|
397
|
+
/** Session-scoped offline controller shared across stores in the same session. */
|
|
398
|
+
export type OfflineSession<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
399
|
+
/** Returns the active session key used to scope shared offline state. */
|
|
400
|
+
getSessionKey: () => string | false;
|
|
401
|
+
/** Shared static session configuration used by attached stores. */
|
|
402
|
+
getConfig: () => OfflineSessionConfig<TUploadRef>;
|
|
403
|
+
/** Latest effective runtime config for this session. */
|
|
404
|
+
getOfflineRuntimeConfig: () => OfflineRuntimeConfig;
|
|
405
|
+
/** Updates runtime controls for this session. */
|
|
406
|
+
setOfflineRuntimeConfig: (update: OfflineRuntimeConfigUpdate) => void;
|
|
407
|
+
/** Resets runtime controls back to the static session config. */
|
|
408
|
+
resetOfflineRuntimeConfig: () => void;
|
|
409
|
+
/** Returns the latest global offline status for the session. */
|
|
410
|
+
getOfflineStatus: () => GlobalOfflineStatus;
|
|
411
|
+
/** Returns the latest aggregated offline entities for the session. */
|
|
412
|
+
getOfflineEntities: () => readonly GlobalOfflineEntity[];
|
|
413
|
+
/** Returns the latest aggregated conflict/retry resolutions for the session. */
|
|
414
|
+
getOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
415
|
+
/** Returns the latest session-scoped offline uploads for the session. */
|
|
416
|
+
getOfflineUploads: () => readonly OfflineUpload<TUploadRef>[];
|
|
417
|
+
/** Resolves a staged upload id to its latest final ref, uploading first if needed. */
|
|
418
|
+
resolveOfflineUpload: (id: string) => Promise<TUploadRef>;
|
|
419
|
+
/** Resolves multiple staged upload ids to their latest final refs. */
|
|
420
|
+
resolveOfflineUploads: (ids: readonly string[]) => Promise<Record<string, TUploadRef>>;
|
|
421
|
+
/** Saves a session-scoped upload locally for later dependency resolution or ref usage. */
|
|
422
|
+
saveOfflineUpload: (args: {
|
|
423
|
+
id: string;
|
|
424
|
+
file: Blob | File;
|
|
425
|
+
}) => Promise<void>;
|
|
426
|
+
/** Replaces a previously stored session-scoped upload. */
|
|
427
|
+
replaceOfflineUpload: (args: {
|
|
428
|
+
id: string;
|
|
429
|
+
file: Blob | File;
|
|
430
|
+
}) => Promise<void>;
|
|
431
|
+
/** Loads a previously stored session-scoped upload. */
|
|
432
|
+
loadOfflineUpload: (id: string) => Promise<File | null>;
|
|
433
|
+
/** Deletes a stored upload when it is no longer referenced. */
|
|
434
|
+
deleteOfflineUpload: (id: string) => Promise<void>;
|
|
435
|
+
/** React hook subscribing to the session's global offline status. */
|
|
436
|
+
useOfflineStatus: () => GlobalOfflineStatus;
|
|
437
|
+
/** React hook subscribing to the session's aggregated offline entities. */
|
|
438
|
+
useOfflineEntities: () => readonly GlobalOfflineEntity[];
|
|
439
|
+
/** React hook subscribing to the session's aggregated conflict/retry resolutions. */
|
|
440
|
+
useOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
441
|
+
/** React hook subscribing to the session's upload list. */
|
|
442
|
+
useOfflineUploads: () => readonly OfflineUpload<TUploadRef>[];
|
|
443
|
+
};
|
|
444
|
+
export declare function isModeEffectivelyActive(mode: {
|
|
445
|
+
enabled: boolean;
|
|
446
|
+
active: boolean;
|
|
447
|
+
}): boolean;
|
|
448
|
+
export declare function getIsOfflineModeFromStatus(status: {
|
|
449
|
+
network: {
|
|
450
|
+
enabled: boolean;
|
|
451
|
+
active: boolean;
|
|
452
|
+
};
|
|
453
|
+
outage: {
|
|
454
|
+
enabled: boolean;
|
|
455
|
+
active: boolean;
|
|
456
|
+
};
|
|
457
|
+
}): boolean;
|
|
458
|
+
export declare function isOfflineModeStatusValue(value: unknown): boolean;
|
|
459
|
+
/**
|
|
460
|
+
* Persisted offline resolution payload without any derived dependency metadata.
|
|
461
|
+
*
|
|
462
|
+
* This shape is what gets serialized to storage and hydrated back into memory.
|
|
463
|
+
*
|
|
464
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
465
|
+
* @typeParam TInput - Original mutation input associated with the resolution.
|
|
466
|
+
*/
|
|
467
|
+
export type PersistedOfflineResolutionRecord<TConflict = unknown, TInput = unknown> = OfflineConflictResolutionRecordBase<TConflict, TInput> | OfflineRetryExhaustedResolutionRecordBase<TInput>;
|
|
468
|
+
/**
|
|
469
|
+
* Persisted offline mutation queue entry.
|
|
470
|
+
*
|
|
471
|
+
* @typeParam TInput - Serialized input payload for the queued mutation.
|
|
472
|
+
* @typeParam TConflict - Conflict payload that may be attached while waiting for confirmation or resolution.
|
|
473
|
+
*/
|
|
474
|
+
export type OfflineQueueEntry<TInput = unknown, TConflict = unknown> = {
|
|
475
|
+
/** Queue entry identifier. */
|
|
476
|
+
id: string;
|
|
477
|
+
/** Session key for queue scoping. */
|
|
478
|
+
sessionKey: string;
|
|
479
|
+
/** Store name where operation is defined. */
|
|
480
|
+
storeName: string;
|
|
481
|
+
/** Store type for this queued operation. */
|
|
482
|
+
storeType: OfflineStoreType;
|
|
483
|
+
/** Operation name registered in offline configuration. */
|
|
484
|
+
operation: string;
|
|
485
|
+
/** Operation input payload persisted with the entry. */
|
|
486
|
+
input: TInput;
|
|
487
|
+
/** Stable ordering key used to replay queued operations deterministically. */
|
|
488
|
+
queueOrder: number;
|
|
489
|
+
/** Entity references tied to this mutation. */
|
|
490
|
+
entityRefs: OfflineEntityRef[];
|
|
491
|
+
/** Number of execution attempts so far. */
|
|
492
|
+
attempts: number;
|
|
493
|
+
/** Queue entry creation timestamp. */
|
|
494
|
+
createdAt: number;
|
|
495
|
+
/** Last entry update timestamp. */
|
|
496
|
+
updatedAt: number;
|
|
497
|
+
/** Timestamp of last execution attempt, if any. */
|
|
498
|
+
lastAttemptAt: number | null;
|
|
499
|
+
/** Synchronization state for this entry. */
|
|
500
|
+
syncState: OfflineSyncState;
|
|
501
|
+
/** Optional temporary IDs for optimistic create operations. */
|
|
502
|
+
tempIds?: ValidPayload[];
|
|
503
|
+
/** Maps original direct-upload keys to their persisted session upload ids. */
|
|
504
|
+
attachedUploadIds?: OfflineAttachedUploadIds;
|
|
505
|
+
/** Session upload ids that must resolve before replaying the mutation. */
|
|
506
|
+
dependencyUploadIds?: string[];
|
|
507
|
+
/** Last recorded sync error if replay failed. */
|
|
508
|
+
lastError?: {
|
|
509
|
+
message: string;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Whether a `needs-confirmation` entry may auto-resend during healthy replay
|
|
513
|
+
* retries after confirmation checks finish.
|
|
514
|
+
*/
|
|
515
|
+
allowReplayRetry?: boolean;
|
|
516
|
+
/** Pending conflict payload when confirmation or resolution is required. */
|
|
517
|
+
pendingConflict?: TConflict;
|
|
518
|
+
};
|
|
519
|
+
/** Built-in resolution actions for retry exhaustion records. */
|
|
520
|
+
export type OfflineRetryExhaustedResolutionAction = {
|
|
521
|
+
/** Requeues the failed mutation for another replay attempt. */
|
|
522
|
+
action: 'retry';
|
|
523
|
+
/**
|
|
524
|
+
* Controls whether retrying a resolution should also requeue retryable
|
|
525
|
+
* descendants from the same temp-lifecycle dependency chain.
|
|
526
|
+
* @default 'self-and-descendants'
|
|
527
|
+
*/
|
|
528
|
+
scope?: 'self' | 'self-and-descendants';
|
|
529
|
+
} | {
|
|
530
|
+
/** Discards the exhausted mutation and clears its resolution record. */
|
|
531
|
+
action: 'discard';
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Built-in resolution actions for persisted conflict records.
|
|
535
|
+
*
|
|
536
|
+
* `commit` is intended for flows where the final API call has already been made
|
|
537
|
+
* externally and the store only needs to clear bookkeeping plus reconcile any
|
|
538
|
+
* temp-entity lifecycle using the accepted server result.
|
|
539
|
+
*
|
|
540
|
+
* @typeParam TInput - Input type expected when requeueing a replacement mutation.
|
|
541
|
+
* @typeParam TResult - Result shape returned by the external conflict resolution call.
|
|
542
|
+
*/
|
|
543
|
+
export type OfflineConflictResolutionAction<TInput = unknown, TResult = unknown> = {
|
|
544
|
+
/** Discards the conflict and clears its resolution record. */
|
|
545
|
+
action: 'discard';
|
|
546
|
+
} | {
|
|
547
|
+
/** Requeues the operation with replacement input. */
|
|
548
|
+
action: 'requeue';
|
|
549
|
+
/** Replacement operation input. */
|
|
550
|
+
input: TInput;
|
|
551
|
+
} | {
|
|
552
|
+
/** Commits an externally resolved conflict and clears bookkeeping. */
|
|
553
|
+
action: 'commit';
|
|
554
|
+
/** Result returned by the external conflict resolution call, when needed for reconciliation. */
|
|
555
|
+
result?: TResult;
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Built-in resolution actions accepted by `resolveOfflineResolution(...)`.
|
|
559
|
+
*
|
|
560
|
+
* @typeParam TInput - Input type expected when requeueing a replacement mutation.
|
|
561
|
+
* @typeParam TResult - Result shape returned by an externally completed conflict resolution call.
|
|
562
|
+
*/
|
|
563
|
+
export type OfflineResolutionAction<TInput = unknown, TResult = unknown> = OfflineRetryExhaustedResolutionAction | OfflineConflictResolutionAction<TInput, TResult>;
|
|
564
|
+
/**
|
|
565
|
+
* Extracts operation input type from a schema map.
|
|
566
|
+
*
|
|
567
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
568
|
+
* @typeParam TName - Operation name whose input type should be extracted.
|
|
569
|
+
*/
|
|
570
|
+
export type OperationInput<TOperations, TName extends keyof TOperations> = TOperations[TName] extends {
|
|
571
|
+
inputSchema: PersistentStorageSchema<infer TInput>;
|
|
572
|
+
} ? TInput : never;
|
|
573
|
+
/**
|
|
574
|
+
* A typed operation descriptor for an offline mutation queue entry.
|
|
575
|
+
*
|
|
576
|
+
* @typeParam TOperations - Operation registry that defines valid operation names and input schemas.
|
|
577
|
+
* @typeParam TName - Operation name to describe. Defaults to all operation names in the registry.
|
|
578
|
+
*/
|
|
579
|
+
export type OfflineMutationDescriptor<TOperations extends Record<string, {
|
|
580
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
581
|
+
}>, TName extends keyof TOperations & string = keyof TOperations & string> = {
|
|
582
|
+
[K in TName]: {
|
|
583
|
+
/** Operation key from the offline operations registry. */
|
|
584
|
+
operation: K;
|
|
585
|
+
/** Input resolved from the registered operation schema. */
|
|
586
|
+
input: OperationInput<TOperations, K>;
|
|
587
|
+
};
|
|
588
|
+
}[TName];
|
|
589
|
+
/**
|
|
590
|
+
* Public offline mutation input accepted by store mutation APIs.
|
|
591
|
+
*
|
|
592
|
+
* Callers queue exactly one descriptor per mutation fallback.
|
|
593
|
+
*/
|
|
594
|
+
export type OfflineMutationInput<TOperations extends Record<string, {
|
|
595
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
596
|
+
}>, TName extends keyof TOperations & string = keyof TOperations & string> = OfflineMutationDescriptor<TOperations, TName>;
|
|
597
|
+
/**
|
|
598
|
+
* Extracts operation result type from a registered operation map.
|
|
599
|
+
*
|
|
600
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
601
|
+
* @typeParam TName - Operation name whose result type should be extracted.
|
|
602
|
+
*/
|
|
603
|
+
export type OperationResult<TOperations, TName extends keyof TOperations> = TOperations[TName] extends {
|
|
604
|
+
execute: (...args: __LEGIT_ANY__[]) => infer TResult;
|
|
605
|
+
} ? Awaited<TResult> : never;
|
|
606
|
+
/**
|
|
607
|
+
* Resolution action accepted for a specific registered offline operation.
|
|
608
|
+
*
|
|
609
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
610
|
+
* @typeParam TName - Operation name whose resolution payload should be extracted.
|
|
611
|
+
*/
|
|
612
|
+
export type OfflineResolutionActionForOperation<TOperations, TName extends keyof TOperations> = OfflineResolutionAction<OperationInput<TOperations, TName>, OperationResult<TOperations, TName>>;
|
|
613
|
+
/**
|
|
614
|
+
* Context passed into offline mutation accumulation hooks.
|
|
615
|
+
*
|
|
616
|
+
* @typeParam TInput - Input type shared by the existing and incoming queued mutations.
|
|
617
|
+
*/
|
|
618
|
+
export type OfflineAccumulationMergeContext<TInput> = {
|
|
619
|
+
/** Session key used to isolate queued mutations. */
|
|
620
|
+
sessionKey: string;
|
|
621
|
+
/** Existing input already present in queue. */
|
|
622
|
+
existingInput: TInput;
|
|
623
|
+
/** Incoming input for merge attempt. */
|
|
624
|
+
incomingInput: TInput;
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
* Optional in-memory accumulation strategy for queued offline mutations.
|
|
628
|
+
*
|
|
629
|
+
* @typeParam TInput - Input type that will be merged and revalidated before persisting.
|
|
630
|
+
*/
|
|
631
|
+
export type OfflineAccumulationConfig<TInput> = {
|
|
632
|
+
/** Merge function for combining existing and incoming mutation inputs. */
|
|
633
|
+
mergeInput: (ctx: OfflineAccumulationMergeContext<TInput>) => Promise<TInput> | TInput;
|
|
634
|
+
};
|
|
635
|
+
/**
|
|
636
|
+
* Optional queue-pruning strategy for queued offline mutations.
|
|
637
|
+
*
|
|
638
|
+
* `same-entity` only applies to operations that resolve exactly one entity ref.
|
|
639
|
+
* When enabled, the new operation may remove earlier unattempted pending entries
|
|
640
|
+
* targeting that same single entity before the new entry is persisted.
|
|
641
|
+
*/
|
|
642
|
+
export type OfflineSupersedeConfig = {
|
|
643
|
+
/** Drop earlier unattempted pending entries for the same single entity. */
|
|
644
|
+
scope: 'same-entity';
|
|
645
|
+
/**
|
|
646
|
+
* Limits which earlier operations may be pruned for that entity.
|
|
647
|
+
*
|
|
648
|
+
* Omit this to prune every earlier pending operation for the entity,
|
|
649
|
+
* use `'self'` to prune only earlier entries of the current operation,
|
|
650
|
+
* or provide explicit operation names to target a specific related set.
|
|
651
|
+
*/
|
|
652
|
+
operations?: 'self' | readonly string[];
|
|
653
|
+
/**
|
|
654
|
+
* When the pruned entries include a temp-entity lifecycle, drop the current
|
|
655
|
+
* operation itself instead of persisting a replacement entry.
|
|
656
|
+
*/
|
|
657
|
+
dropSelfIfTempLifecycleCancelled?: boolean;
|
|
658
|
+
};
|
|
659
|
+
/** Shared context passed to offline replay lifecycle hooks. */
|
|
660
|
+
type OperationBaseContext<TInput> = {
|
|
661
|
+
/** Input payload for the queued mutation currently being processed. */
|
|
662
|
+
input: TInput;
|
|
663
|
+
/** Timestamp when the operation was originally enqueued. */
|
|
664
|
+
enqueuedAt: number;
|
|
665
|
+
/** Timestamp when the queued entry or conflict record was last updated. */
|
|
666
|
+
updatedAt: number;
|
|
667
|
+
/**
|
|
668
|
+
* Resolves a previously temp-backed entity ref to its latest known final ref
|
|
669
|
+
* when one has been reconciled.
|
|
670
|
+
*/
|
|
671
|
+
resolveEntityRef: <TEntityRef extends ValidPayload>(entityRef: TEntityRef) => TEntityRef;
|
|
672
|
+
};
|
|
673
|
+
type OperationExecuteContext<TInput, TUploadRef extends ValidPayload = ValidPayload> = OperationBaseContext<TInput> & {
|
|
674
|
+
uploads: OfflineOperationUploadsContext<TUploadRef>;
|
|
675
|
+
};
|
|
676
|
+
/** Context passed to the post-replay success hook after `execute(...)` settles. */
|
|
677
|
+
export type OfflineOperationExecuteSuccessContext<TInput, TResult> = OperationBaseContext<TInput> & {
|
|
678
|
+
/** Replay result returned by `execute(...)`. */
|
|
679
|
+
result: TResult;
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Optional callback used to synchronize UI/cache state after a successful
|
|
683
|
+
* offline replay execute.
|
|
684
|
+
*/
|
|
685
|
+
export type OfflineOperationExecuteSuccessHandler<TInput, TResult> = (ctx: OfflineOperationExecuteSuccessContext<TInput, TResult>) => Promise<void> | void;
|
|
686
|
+
type IsUnknown<T> = unknown extends T ? [keyof T] extends [never] ? true : false : false;
|
|
687
|
+
/** Context passed to replay checks that may use a fresh server snapshot. */
|
|
688
|
+
type OperationReplayCheckContext<TInput, TServerSnapshot> = OperationBaseContext<TInput> & {
|
|
689
|
+
/**
|
|
690
|
+
* Optional snapshot fetched immediately before `shouldSkipSync` and
|
|
691
|
+
* `detectConflict`.
|
|
692
|
+
*/
|
|
693
|
+
serverSnapshot: IsUnknown<TServerSnapshot> extends true ? undefined : TServerSnapshot;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* Conflict hook configuration for a queued offline operation.
|
|
697
|
+
*
|
|
698
|
+
* @typeParam TInput - Input type of the queued operation being checked and potentially requeued.
|
|
699
|
+
* @typeParam TConflict - Conflict payload produced by detection and persisted for later external resolution.
|
|
700
|
+
*/
|
|
701
|
+
export type OfflineConflictHandlingConfig<TInput, TConflict, TServerSnapshot = unknown> = {
|
|
702
|
+
/** Schema used to validate and sanitize persisted conflict payloads. */
|
|
703
|
+
schema: PersistentStorageSchema<TConflict>;
|
|
704
|
+
/**
|
|
705
|
+
* Inspect remote state before replaying the mutation and return conflict payload
|
|
706
|
+
* when the queued mutation can no longer be applied safely.
|
|
707
|
+
*/
|
|
708
|
+
detectConflict: (ctx: OperationReplayCheckContext<TInput, TServerSnapshot>) => Promise<TConflict | false | null> | TConflict | false | null;
|
|
709
|
+
};
|
|
710
|
+
type ConflictHandlingField<TInput, TConflict, TServerSnapshot> = IsUnknown<TConflict> extends true ? {
|
|
711
|
+
/**
|
|
712
|
+
* Optional conflict strategy when a queued operation diverges from remote state.
|
|
713
|
+
*/
|
|
714
|
+
conflictHandling?: OfflineConflictHandlingConfig<TInput, TConflict, TServerSnapshot>;
|
|
715
|
+
} : {
|
|
716
|
+
/**
|
|
717
|
+
* Conflict strategy required when the operation declares a concrete
|
|
718
|
+
* conflict payload type.
|
|
719
|
+
*/
|
|
720
|
+
conflictHandling: OfflineConflictHandlingConfig<TInput, TConflict, TServerSnapshot>;
|
|
721
|
+
};
|
|
722
|
+
type ServerSnapshotField<TInput, TServerSnapshot> = IsUnknown<TServerSnapshot> extends true ? {
|
|
723
|
+
/**
|
|
724
|
+
* Optionally loads a fresh server-side snapshot before replay checks run.
|
|
725
|
+
* The result is passed to `shouldSkipSync` and `detectConflict` as
|
|
726
|
+
* `ctx.serverSnapshot`.
|
|
727
|
+
*/
|
|
728
|
+
getServerSnapshot?: (ctx: OperationBaseContext<TInput>) => Promise<TServerSnapshot> | TServerSnapshot;
|
|
729
|
+
} : {
|
|
730
|
+
/**
|
|
731
|
+
* Required when the operation declares a concrete server snapshot type.
|
|
732
|
+
* The result is passed to `shouldSkipSync` and `detectConflict` as
|
|
733
|
+
* `ctx.serverSnapshot`.
|
|
734
|
+
*/
|
|
735
|
+
getServerSnapshot: (ctx: OperationBaseContext<TInput>) => Promise<TServerSnapshot> | TServerSnapshot;
|
|
736
|
+
};
|
|
737
|
+
/**
|
|
738
|
+
* Replacement data returned by `tempEntity.reconcileServerEntity(...)`.
|
|
739
|
+
*
|
|
740
|
+
* @typeParam TFinalPayload - Final payload that should replace the temporary one.
|
|
741
|
+
* @typeParam TFinalData - Optional replacement entity data for the final payload.
|
|
742
|
+
*/
|
|
743
|
+
export type OfflineTempEntityReconciliation<TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
744
|
+
/** Final payload that should replace the temporary optimistic one. */
|
|
745
|
+
finalPayload: TFinalPayload;
|
|
746
|
+
/**
|
|
747
|
+
* Optional replacement data for the final payload.
|
|
748
|
+
* Omit this to keep the current optimistic entity data and only swap the
|
|
749
|
+
* payload/identity.
|
|
750
|
+
*/
|
|
751
|
+
finalData?: TFinalData;
|
|
752
|
+
};
|
|
753
|
+
/**
|
|
754
|
+
* Replacement data returned by `tempEntities.reconcileServerEntities(...)`.
|
|
755
|
+
*
|
|
756
|
+
* @typeParam TTempId - Temporary payload that should be reconciled.
|
|
757
|
+
* @typeParam TFinalPayload - Final payload that should replace the temporary one.
|
|
758
|
+
* @typeParam TFinalData - Optional replacement entity data for the final payload.
|
|
759
|
+
*/
|
|
760
|
+
export type OfflineTempEntitiesReconciliation<TTempId extends ValidPayload = ValidPayload, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = OfflineTempEntityReconciliation<TFinalPayload, TFinalData> & {
|
|
761
|
+
/** Temporary payload that should be reconciled. */
|
|
762
|
+
tempId: TTempId;
|
|
763
|
+
};
|
|
764
|
+
/**
|
|
765
|
+
* Pending temp-entity returned by `tempEntities.buildPendingEntities(...)`.
|
|
766
|
+
*
|
|
767
|
+
* @typeParam TTempId - Temporary payload used to track the optimistic entity.
|
|
768
|
+
* @typeParam TPendingEntity - Pending entity snapshot to insert locally.
|
|
769
|
+
*/
|
|
770
|
+
export type OfflineTempEntityPendingEntry<TTempId extends ValidPayload = ValidPayload, TPendingEntity = unknown> = {
|
|
771
|
+
/** Temporary payload that identifies the optimistic entity. */
|
|
772
|
+
tempId: TTempId;
|
|
773
|
+
/** Pending entity snapshot inserted while the mutation is queued. */
|
|
774
|
+
pendingEntity: TPendingEntity;
|
|
775
|
+
};
|
|
776
|
+
/**
|
|
777
|
+
* Optional temp-id lifecycle for optimistic offline create flows.
|
|
778
|
+
*
|
|
779
|
+
* @typeParam TInput - Input type used to derive the temporary entity and identifier.
|
|
780
|
+
* @typeParam TTempResult - Result returned by `execute`, used only by `tempEntity.reconcileServerEntity(...)`.
|
|
781
|
+
* @typeParam TTempId - Temporary payload used to track optimistic entities before reconciliation.
|
|
782
|
+
*/
|
|
783
|
+
export type OfflineTempEntityConfig<TInput, TTempResult, TTempId extends ValidPayload = string, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
784
|
+
/**
|
|
785
|
+
* Builds the optimistic entity inserted into local state while the mutation
|
|
786
|
+
* is queued offline.
|
|
787
|
+
*
|
|
788
|
+
* `tempId` is the temporary payload used to identify the optimistic entity
|
|
789
|
+
* until replay succeeds and the final server entity can replace it.
|
|
790
|
+
*/
|
|
791
|
+
buildPendingEntity: (input: TInput, tempId: TTempId) => TPendingEntity;
|
|
792
|
+
/**
|
|
793
|
+
* Reconciles the optimistic temp entity with the successful replay result.
|
|
794
|
+
*/
|
|
795
|
+
reconcileServerEntity: (result: TTempResult, tempId: TTempId) => OfflineTempEntityReconciliation<TFinalPayload, TFinalData>;
|
|
796
|
+
};
|
|
797
|
+
/**
|
|
798
|
+
* Optional temp-id lifecycle for optimistic offline batch-create flows.
|
|
799
|
+
*
|
|
800
|
+
* @typeParam TInput - Input type used to derive the temporary entities and identifiers.
|
|
801
|
+
* @typeParam TTempResult - Result returned by `execute`, used only by `tempEntities.reconcileServerEntities(...)`.
|
|
802
|
+
* @typeParam TTempId - Temporary payload used to track optimistic entities before reconciliation.
|
|
803
|
+
*/
|
|
804
|
+
export type OfflineTempEntitiesConfig<TInput, TTempResult, TTempId extends ValidPayload = string, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
805
|
+
/**
|
|
806
|
+
* Builds the optimistic entities inserted into local state while the mutation
|
|
807
|
+
* is queued offline.
|
|
808
|
+
*
|
|
809
|
+
* `tempIds` are the temporary payloads derived from the operation entity refs
|
|
810
|
+
* and used until replay succeeds and the final server entities can replace them.
|
|
811
|
+
*/
|
|
812
|
+
buildPendingEntities: (input: TInput, tempIds: readonly TTempId[]) => readonly OfflineTempEntityPendingEntry<TTempId, TPendingEntity>[];
|
|
813
|
+
/**
|
|
814
|
+
* Reconciles the optimistic temp entities with the successful replay result.
|
|
815
|
+
*/
|
|
816
|
+
reconcileServerEntities: (result: TTempResult, tempIds: readonly TTempId[]) => readonly OfflineTempEntitiesReconciliation<TTempId, TFinalPayload, TFinalData>[];
|
|
817
|
+
};
|
|
818
|
+
type NoTempEntityFields = {
|
|
819
|
+
tempEntity?: never;
|
|
820
|
+
tempEntities?: never;
|
|
821
|
+
};
|
|
822
|
+
type ConfiguredTempEntityFields<TInput, TTempResult, TTempId extends ValidPayload, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
823
|
+
tempEntity: OfflineTempEntityConfig<TInput, TTempResult, TTempId, TPendingEntity, TFinalPayload, TFinalData>;
|
|
824
|
+
tempEntities?: never;
|
|
825
|
+
} | {
|
|
826
|
+
tempEntity?: never;
|
|
827
|
+
tempEntities: OfflineTempEntitiesConfig<TInput, TTempResult, TTempId, TPendingEntity, TFinalPayload, TFinalData>;
|
|
828
|
+
};
|
|
829
|
+
/**
|
|
830
|
+
* Shape used by `persistentStorage.offline.operations` for each operation name.
|
|
831
|
+
*
|
|
832
|
+
* @typeParam TInput - The persisted input payload for the queued offline operation.
|
|
833
|
+
* @typeParam TConflict - The conflict payload produced by pre-execution conflict detection.
|
|
834
|
+
* @typeParam TTempResult - Result returned by `execute`, used only when `tempEntity` or `tempEntities` needs to reconcile the final server entity. Defaults to `void`.
|
|
835
|
+
*/
|
|
836
|
+
export type OfflineOperationDefinition<TInput, TConflict, TTempResult = void, TServerSnapshot = unknown, TTempId extends ValidPayload = string, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown, TUploadRef extends ValidPayload = ValidPayload> = {
|
|
837
|
+
/** Schema used to validate incoming operation input. */
|
|
838
|
+
inputSchema: PersistentStorageSchema<TInput>;
|
|
839
|
+
/** Lifecycle classification for the queued operation. */
|
|
840
|
+
kind: OfflineOperationKind;
|
|
841
|
+
/**
|
|
842
|
+
* Optional queue pruning for newer operations that supersede older queued work.
|
|
843
|
+
*
|
|
844
|
+
* This is mutually exclusive with `accumulation`.
|
|
845
|
+
*/
|
|
846
|
+
supersedes?: OfflineSupersedeConfig;
|
|
847
|
+
/**
|
|
848
|
+
* Executes the queued mutation against the remote source during replay.
|
|
849
|
+
* This may run multiple times when transient failures occur.
|
|
850
|
+
*/
|
|
851
|
+
execute: (ctx: OperationExecuteContext<TInput, TUploadRef>) => Promise<TTempResult> | TTempResult;
|
|
852
|
+
/**
|
|
853
|
+
* Optional check executed before retrying a previously failed sync attempt.
|
|
854
|
+
* Return `true` to drop the queued entry because the remote side already reflects it.
|
|
855
|
+
* Return `false` to continue with normal replay.
|
|
856
|
+
*/
|
|
857
|
+
shouldSkipSync?: (ctx: OperationReplayCheckContext<TInput, TServerSnapshot>) => Promise<boolean> | boolean;
|
|
858
|
+
} & ConflictHandlingField<TInput, TConflict, TServerSnapshot> & ServerSnapshotField<TInput, TServerSnapshot> & (({
|
|
859
|
+
/**
|
|
860
|
+
* Explicit store-sync step that runs after `execute(...)` succeeds during
|
|
861
|
+
* offline replay.
|
|
862
|
+
*
|
|
863
|
+
* Provide a callback when replay should update the live store after the
|
|
864
|
+
* server-side execute succeeds.
|
|
865
|
+
*/
|
|
866
|
+
onSuccessExecute: OfflineOperationExecuteSuccessHandler<TInput, TTempResult>;
|
|
867
|
+
/**
|
|
868
|
+
* Optional queue compaction for consecutive mutations with same refs.
|
|
869
|
+
*/
|
|
870
|
+
accumulation?: OfflineAccumulationConfig<TInput>;
|
|
871
|
+
} & NoTempEntityFields) | ({
|
|
872
|
+
/**
|
|
873
|
+
* Temp-entity operations already reconcile the live store through
|
|
874
|
+
* `tempEntity` / `tempEntities`, so they must not declare an extra
|
|
875
|
+
* success sync callback.
|
|
876
|
+
*/
|
|
877
|
+
onSuccessExecute?: undefined;
|
|
878
|
+
/** Temp-entity operations cannot compact multiple queued creates. */
|
|
879
|
+
accumulation?: never;
|
|
880
|
+
} & ConfiguredTempEntityFields<TInput, TTempResult, TTempId, TPendingEntity, TFinalPayload, TFinalData>));
|
|
881
|
+
type WithoutTempEntity<T extends {
|
|
882
|
+
tempEntity?: unknown;
|
|
883
|
+
tempEntities?: unknown;
|
|
884
|
+
}> = Omit<T, 'tempEntity' | 'tempEntities'> & {
|
|
885
|
+
/** Document stores do not support optimistic temp entities. */
|
|
886
|
+
tempEntity?: never;
|
|
887
|
+
/** Document stores do not support optimistic batch temp entities. */
|
|
888
|
+
tempEntities?: never;
|
|
889
|
+
};
|
|
890
|
+
/** Context used to resolve which entities a queued mutation affects. */
|
|
891
|
+
type OperationEntityRefsContext<TInput> = {
|
|
892
|
+
/** Input payload for the queued mutation. */
|
|
893
|
+
input: TInput;
|
|
894
|
+
};
|
|
895
|
+
/** Non-store-specific offline operation definition alias. */
|
|
896
|
+
export type AnyOfflineOperationDefinition<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
897
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
898
|
+
kind: OfflineOperationKind;
|
|
899
|
+
conflictHandling?: {
|
|
900
|
+
schema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
901
|
+
detectConflict: (ctx: __LEGIT_ANY__) => unknown;
|
|
902
|
+
};
|
|
903
|
+
accumulation?: OfflineAccumulationConfig<__LEGIT_ANY__>;
|
|
904
|
+
supersedes?: OfflineSupersedeConfig;
|
|
905
|
+
tempEntity?: OfflineTempEntityConfig<__LEGIT_ANY__, __LEGIT_ANY__, __LEGIT_ANY__>;
|
|
906
|
+
tempEntities?: OfflineTempEntitiesConfig<__LEGIT_ANY__, __LEGIT_ANY__, __LEGIT_ANY__>;
|
|
907
|
+
getServerSnapshot?: (ctx: OperationBaseContext<__LEGIT_ANY__>) => unknown;
|
|
908
|
+
execute: (ctx: OperationExecuteContext<__LEGIT_ANY__, TUploadRef>) => unknown;
|
|
909
|
+
onSuccessExecute?: OfflineOperationExecuteSuccessHandler<__LEGIT_ANY__, __LEGIT_ANY__>;
|
|
910
|
+
shouldSkipSync?: (ctx: OperationReplayCheckContext<__LEGIT_ANY__, __LEGIT_ANY__>) => Promise<boolean> | boolean;
|
|
911
|
+
} & {
|
|
912
|
+
getEntityRefs?: (ctx: OperationEntityRefsContext<__LEGIT_ANY__>) => unknown[];
|
|
913
|
+
dependsOn?: (ctx: OperationEntityRefsContext<__LEGIT_ANY__>) => __LEGIT_ANY__[];
|
|
914
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<__LEGIT_ANY__>) => string[];
|
|
915
|
+
};
|
|
916
|
+
/**
|
|
917
|
+
* Compact type-spec helper for a single offline operation.
|
|
918
|
+
*
|
|
919
|
+
* Use this helper with {@link DefineDocumentOfflineOperations} to describe each
|
|
920
|
+
* operation using generic parameters instead of inline object literals.
|
|
921
|
+
*
|
|
922
|
+
* The generic order is `input`, `conflict`, `temp result`, then `server snapshot`.
|
|
923
|
+
*
|
|
924
|
+
* @typeParam TInput - Input payload accepted by the operation.
|
|
925
|
+
* @typeParam TConflict - Conflict payload produced by optional conflict handling.
|
|
926
|
+
* @typeParam TTempResult - Result returned by `execute`, also reused when externally committed conflict resolution needs temp-entity reconciliation.
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```ts
|
|
930
|
+
* type UpdateName = DefineOfflineOperation<
|
|
931
|
+
* { name: string },
|
|
932
|
+
* { remoteName: string },
|
|
933
|
+
* { name: string }
|
|
934
|
+
* >;
|
|
935
|
+
* ```
|
|
936
|
+
*/
|
|
937
|
+
export type DefineOfflineOperation<TInput = unknown, TConflict = unknown, TTempResult = unknown, TServerSnapshot = unknown> = {
|
|
938
|
+
/** Input type accepted by the operation. */
|
|
939
|
+
input?: TInput;
|
|
940
|
+
/** Conflict payload type produced by the optional conflict handler. */
|
|
941
|
+
conflict?: TConflict;
|
|
942
|
+
/** Result returned by `execute`, also reused by externally committed conflict resolution for temp-entity reconciliation. */
|
|
943
|
+
result?: TTempResult;
|
|
944
|
+
/** Snapshot type returned by `getServerSnapshot` and exposed to replay checks. */
|
|
945
|
+
serverSnapshot?: TServerSnapshot;
|
|
946
|
+
};
|
|
947
|
+
type DocumentOperationInput<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
948
|
+
input?: infer TInput;
|
|
949
|
+
} ? TInput : unknown;
|
|
950
|
+
type DocumentOperationConflict<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
951
|
+
conflict?: infer TConflict;
|
|
952
|
+
} ? TConflict : unknown;
|
|
953
|
+
type DocumentOperationResult<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
954
|
+
result?: infer TTempResult;
|
|
955
|
+
} ? TTempResult : unknown;
|
|
956
|
+
type DocumentOperationServerSnapshot<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
957
|
+
serverSnapshot?: infer TServerSnapshot;
|
|
958
|
+
} ? TServerSnapshot : unknown;
|
|
959
|
+
/**
|
|
960
|
+
* Document-store specific offline operation definition.
|
|
961
|
+
*
|
|
962
|
+
* Prefer this alias when manually typing a single operation inside
|
|
963
|
+
* `persistentStorage.offline.operations` for a document store.
|
|
964
|
+
*
|
|
965
|
+
* `TOptions` is usually provided with {@link DefineOfflineOperation}, which lets
|
|
966
|
+
* callers specify the queued `input`, replay `result`, and optional `conflict`
|
|
967
|
+
* payload concisely. Document stores do not support `tempEntity`.
|
|
968
|
+
*
|
|
969
|
+
* Omitted properties default to `unknown`.
|
|
970
|
+
*
|
|
971
|
+
* @typeParam State - Document state type for the owning store.
|
|
972
|
+
* @typeParam TOptions - Operation typing options, usually created with {@link DefineOfflineOperation}.
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```ts
|
|
976
|
+
* type RenameOperation = DocumentOfflineOperationDefinition<
|
|
977
|
+
* UserDoc,
|
|
978
|
+
* DefineOfflineOperation<
|
|
979
|
+
* { name: string },
|
|
980
|
+
* { remoteName: string },
|
|
981
|
+
* { name: string }
|
|
982
|
+
* >
|
|
983
|
+
* >;
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
export type DocumentOfflineOperationDefinition<State extends ValidStoreState, TOptions extends DefineOfflineOperation = DefineOfflineOperation, TUploadRef extends ValidPayload = ValidPayload> = WithoutTempEntity<OfflineOperationDefinition<DocumentOperationInput<TOptions>, DocumentOperationConflict<TOptions>, DocumentOperationResult<TOptions>, DocumentOperationServerSnapshot<TOptions>, string, unknown, ValidPayload, unknown, TUploadRef>> & {
|
|
987
|
+
/** Declares which upload ids must finish before replaying this operation. */
|
|
988
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<DocumentOperationInput<TOptions>>) => string[];
|
|
989
|
+
} & ([State] extends [never] ? never : unknown);
|
|
990
|
+
/**
|
|
991
|
+
* Builds a document offline operations map from a compact operation spec.
|
|
992
|
+
*
|
|
993
|
+
* This is the recommended way to type a document store's full offline operation map.
|
|
994
|
+
* Each operation key is typically described with {@link DefineOfflineOperation},
|
|
995
|
+
* and this helper expands that into the full
|
|
996
|
+
* {@link DocumentOfflineOperationDefinition} map expected by the store.
|
|
997
|
+
*
|
|
998
|
+
* @typeParam State - Document state type for the owning store.
|
|
999
|
+
* @typeParam TOperations - Operation map where each key declares its input, replay result, and optional conflict payload.
|
|
1000
|
+
*
|
|
1001
|
+
* @example
|
|
1002
|
+
* ```ts
|
|
1003
|
+
* type Operations = DefineDocumentOfflineOperations<
|
|
1004
|
+
* UserDoc,
|
|
1005
|
+
* {
|
|
1006
|
+
* updateName: DefineOfflineOperation<
|
|
1007
|
+
* { name: string },
|
|
1008
|
+
* unknown,
|
|
1009
|
+
* { name: string }
|
|
1010
|
+
* >;
|
|
1011
|
+
* archive: DefineOfflineOperation<
|
|
1012
|
+
* { reason: string },
|
|
1013
|
+
* { code: string }
|
|
1014
|
+
* >;
|
|
1015
|
+
* }
|
|
1016
|
+
* >;
|
|
1017
|
+
* ```
|
|
1018
|
+
*
|
|
1019
|
+
* Then use the resulting type as the `operations` object contract:
|
|
1020
|
+
*
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* const operations: Operations = {
|
|
1023
|
+
* updateName: {
|
|
1024
|
+
* inputSchema: z.object({ name: z.string() }),
|
|
1025
|
+
* kind: 'update',
|
|
1026
|
+
* execute: ({ input }) => ({ name: input.name }),
|
|
1027
|
+
* },
|
|
1028
|
+
* archive: {
|
|
1029
|
+
* inputSchema: z.object({ reason: z.string() }),
|
|
1030
|
+
* kind: 'delete',
|
|
1031
|
+
* conflictHandling: {
|
|
1032
|
+
* schema: z.object({ code: z.string() }),
|
|
1033
|
+
* detectConflict: () => false,
|
|
1034
|
+
* },
|
|
1035
|
+
* execute: () => undefined,
|
|
1036
|
+
* },
|
|
1037
|
+
* };
|
|
1038
|
+
* ```
|
|
1039
|
+
*/
|
|
1040
|
+
export type DefineDocumentOfflineOperations<State extends ValidStoreState, TOperations extends Record<string, DefineOfflineOperation>, TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1041
|
+
[TName in keyof TOperations]: DocumentOfflineOperationDefinition<State, TOperations[TName], TUploadRef>;
|
|
1042
|
+
};
|
|
1043
|
+
/**
|
|
1044
|
+
* Collection offline entity reference.
|
|
1045
|
+
*
|
|
1046
|
+
* Collection operations return raw item payloads, which are normalized to the
|
|
1047
|
+
* internal item key by the store.
|
|
1048
|
+
*
|
|
1049
|
+
* @typeParam ItemPayload - Collection item payload type for the owning store.
|
|
1050
|
+
*/
|
|
1051
|
+
export type CollectionOfflineEntityRef<ItemPayload extends ValidPayload> = ItemPayload;
|
|
1052
|
+
/**
|
|
1053
|
+
* Collection-store specific offline operation definition.
|
|
1054
|
+
*
|
|
1055
|
+
* @typeParam ItemState - Collection item state type for the owning store.
|
|
1056
|
+
* @typeParam ItemPayloadUnused - Collection payload type used to anchor the operation to the owning store type.
|
|
1057
|
+
* @typeParam TInput - Input type accepted by the offline operation.
|
|
1058
|
+
* @typeParam TConflict - Conflict payload type produced by the optional conflict handler.
|
|
1059
|
+
* @typeParam TTempResult - Result returned by `execute`.
|
|
1060
|
+
* When `tempEntity` or `tempEntities` is provided, the pending builders must
|
|
1061
|
+
* return `ItemState`, and the reconciliation hooks must return an
|
|
1062
|
+
* `ItemPayload` plus optional `ItemState` replacement data.
|
|
1063
|
+
*/
|
|
1064
|
+
export type CollectionOfflineOperationDefinition<ItemState extends ValidStoreState, ItemPayloadUnused extends ValidPayload, TInput = unknown, TConflict = unknown, TTempResult = unknown, TServerSnapshot = unknown, TUploadRef extends ValidPayload = ValidPayload> = OfflineOperationDefinition<TInput, TConflict, TTempResult, TServerSnapshot, ItemPayloadUnused, ItemState, ItemPayloadUnused, ItemState, TUploadRef> & {
|
|
1065
|
+
/**
|
|
1066
|
+
* Declares which collection items are affected by this queued mutation.
|
|
1067
|
+
*
|
|
1068
|
+
* Return the raw collection payloads for the affected items. The store will
|
|
1069
|
+
* convert each payload with the configured item key logic.
|
|
1070
|
+
*/
|
|
1071
|
+
getEntityRefs: (ctx: OperationEntityRefsContext<TInput>) => CollectionOfflineEntityRef<ItemPayloadUnused>[];
|
|
1072
|
+
/**
|
|
1073
|
+
* Declares which collection item refs must resolve before replaying this
|
|
1074
|
+
* operation.
|
|
1075
|
+
*/
|
|
1076
|
+
dependsOn?: (ctx: OperationEntityRefsContext<TInput>) => CollectionOfflineEntityRef<ItemPayloadUnused>[];
|
|
1077
|
+
/** Declares which upload ids must finish before replaying this operation. */
|
|
1078
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<TInput>) => string[];
|
|
1079
|
+
} & ([ItemState | ItemPayloadUnused] extends [never] ? never : unknown);
|
|
1080
|
+
/**
|
|
1081
|
+
* Builds a collection offline operations map from a compact operation spec.
|
|
1082
|
+
*
|
|
1083
|
+
* Use this helper to define the full `persistentStorage.offline.operations` contract for a
|
|
1084
|
+
* collection store while keeping each operation's type declaration short.
|
|
1085
|
+
*
|
|
1086
|
+
* Each operation key is described with {@link DefineOfflineOperation}, and this
|
|
1087
|
+
* helper expands it into the corresponding
|
|
1088
|
+
* {@link CollectionOfflineOperationDefinition}. The runtime operation object
|
|
1089
|
+
* still needs to provide `getEntityRefs(...)`.
|
|
1090
|
+
*
|
|
1091
|
+
* @typeParam ItemState - Collection item state type for the owning store.
|
|
1092
|
+
* @typeParam ItemPayload - Collection payload type for the owning store.
|
|
1093
|
+
* @typeParam TOperations - Operation map where each key declares its input, optional conflict payload, and optional temp-result type.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```ts
|
|
1097
|
+
* type Operations = DefineCollectionOfflineOperations<
|
|
1098
|
+
* TodoItem,
|
|
1099
|
+
* string,
|
|
1100
|
+
* {
|
|
1101
|
+
* renameTodo: DefineOfflineOperation<
|
|
1102
|
+
* { id: string; title: string }
|
|
1103
|
+
* >;
|
|
1104
|
+
* createTodo: DefineOfflineOperation<
|
|
1105
|
+
* { title: string },
|
|
1106
|
+
* unknown,
|
|
1107
|
+
* { id: string; title: string }
|
|
1108
|
+
* >;
|
|
1109
|
+
* }
|
|
1110
|
+
* >;
|
|
1111
|
+
* ```
|
|
1112
|
+
*/
|
|
1113
|
+
export type DefineCollectionOfflineOperations<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOperations extends Record<string, DefineOfflineOperation>, TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1114
|
+
[TName in keyof TOperations]: CollectionOfflineOperationDefinition<ItemState, ItemPayload, DocumentOperationInput<TOperations[TName]>, DocumentOperationConflict<TOperations[TName]>, DocumentOperationResult<TOperations[TName]>, DocumentOperationServerSnapshot<TOperations[TName]>, TUploadRef>;
|
|
1115
|
+
};
|
|
1116
|
+
/**
|
|
1117
|
+
* List-query offline entity reference.
|
|
1118
|
+
*
|
|
1119
|
+
* List-query operations return raw item payloads, which are normalized to the
|
|
1120
|
+
* internal item key by the store.
|
|
1121
|
+
*
|
|
1122
|
+
* @typeParam ItemPayload - Item payload type for the owning list-query store.
|
|
1123
|
+
*/
|
|
1124
|
+
export type ListQueryOfflineEntityRef<ItemPayload extends ValidPayload> = ItemPayload;
|
|
1125
|
+
/**
|
|
1126
|
+
* List-query-store specific offline operation definition.
|
|
1127
|
+
*
|
|
1128
|
+
* @typeParam ItemState - List item state type for the owning store.
|
|
1129
|
+
* @typeParam QueryPayload - Query payload type used by the list store.
|
|
1130
|
+
* @typeParam ItemPayloadUnused - Item payload type used to anchor the operation to the owning store type.
|
|
1131
|
+
* @typeParam TInput - Input type accepted by the offline operation.
|
|
1132
|
+
* @typeParam TConflict - Conflict payload type produced by the optional conflict handler.
|
|
1133
|
+
* @typeParam TTempResult - Result returned by `execute`.
|
|
1134
|
+
* When `tempEntity` or `tempEntities` is provided, the pending builders must
|
|
1135
|
+
* return `ItemState`, and the reconciliation hooks must return an
|
|
1136
|
+
* `ItemPayload` plus optional `ItemState` replacement data.
|
|
1137
|
+
*/
|
|
1138
|
+
export type ListQueryOfflineOperationDefinition<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayloadUnused extends ValidPayload, TInput = unknown, TConflict = unknown, TTempResult = unknown, TServerSnapshot = unknown, TUploadRef extends ValidPayload = ValidPayload> = OfflineOperationDefinition<TInput, TConflict, TTempResult, TServerSnapshot, ItemPayloadUnused, ItemState, ItemPayloadUnused, ItemState, TUploadRef> & {
|
|
1139
|
+
/**
|
|
1140
|
+
* Declares which list-query entities are affected by this queued mutation.
|
|
1141
|
+
*
|
|
1142
|
+
* Return the raw item payloads for the affected items. The store will
|
|
1143
|
+
* convert each payload with the configured item key logic.
|
|
1144
|
+
*/
|
|
1145
|
+
getEntityRefs: (ctx: OperationEntityRefsContext<TInput>) => ListQueryOfflineEntityRef<ItemPayloadUnused>[];
|
|
1146
|
+
/**
|
|
1147
|
+
* Declares which list item refs must resolve before replaying this
|
|
1148
|
+
* operation.
|
|
1149
|
+
*/
|
|
1150
|
+
dependsOn?: (ctx: OperationEntityRefsContext<TInput>) => ListQueryOfflineEntityRef<ItemPayloadUnused>[];
|
|
1151
|
+
/** Declares which upload ids must finish before replaying this operation. */
|
|
1152
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<TInput>) => string[];
|
|
1153
|
+
} & ([ItemState | QueryPayload | ItemPayloadUnused] extends [never] ? never : unknown);
|
|
1154
|
+
/**
|
|
1155
|
+
* Builds a list-query offline operations map from a compact operation spec.
|
|
1156
|
+
*
|
|
1157
|
+
* Use this helper to define the full `persistentStorage.offline.operations` contract for a
|
|
1158
|
+
* list-query store while keeping each operation's type declaration short.
|
|
1159
|
+
*
|
|
1160
|
+
* Each operation key is described with {@link DefineOfflineOperation}, and this
|
|
1161
|
+
* helper expands it into the corresponding
|
|
1162
|
+
* {@link ListQueryOfflineOperationDefinition}. The runtime operation object
|
|
1163
|
+
* still needs to provide `getEntityRefs(...)`.
|
|
1164
|
+
*
|
|
1165
|
+
* @typeParam ItemState - List item state type for the owning store.
|
|
1166
|
+
* @typeParam QueryPayload - Query payload type used by the list store.
|
|
1167
|
+
* @typeParam ItemPayload - Item payload type used by the list store.
|
|
1168
|
+
* @typeParam TOperations - Operation map where each key declares its input, optional conflict payload, and optional temp-result type.
|
|
1169
|
+
*
|
|
1170
|
+
* @example
|
|
1171
|
+
* ```ts
|
|
1172
|
+
* type Operations = DefineListQueryOfflineOperations<
|
|
1173
|
+
* User,
|
|
1174
|
+
* { tableId: 'users' },
|
|
1175
|
+
* { tableId: 'users'; id: number } | string,
|
|
1176
|
+
* {
|
|
1177
|
+
* renameUser: DefineOfflineOperation<
|
|
1178
|
+
* { id: number; name: string }
|
|
1179
|
+
* >;
|
|
1180
|
+
* createUser: DefineOfflineOperation<
|
|
1181
|
+
* { name: string },
|
|
1182
|
+
* unknown,
|
|
1183
|
+
* { id: number; name: string }
|
|
1184
|
+
* >;
|
|
1185
|
+
* }
|
|
1186
|
+
* >;
|
|
1187
|
+
* ```
|
|
1188
|
+
*/
|
|
1189
|
+
export type DefineListQueryOfflineOperations<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TOperations extends Record<string, DefineOfflineOperation>, TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1190
|
+
[TName in keyof TOperations]: ListQueryOfflineOperationDefinition<ItemState, QueryPayload, ItemPayload, DocumentOperationInput<TOperations[TName]>, DocumentOperationConflict<TOperations[TName]>, DocumentOperationResult<TOperations[TName]>, DocumentOperationServerSnapshot<TOperations[TName]>, TUploadRef>;
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* Extracts operation conflict payload from a registered operation map.
|
|
1194
|
+
*
|
|
1195
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
1196
|
+
* @typeParam TName - Operation name whose conflict payload should be extracted.
|
|
1197
|
+
*/
|
|
1198
|
+
export type OperationConflict<TOperations, TName extends keyof TOperations> = TOperations[TName] extends {
|
|
1199
|
+
conflictHandling?: OfflineConflictHandlingConfig<__LEGIT_ANY__, infer TConflict>;
|
|
1200
|
+
} ? TConflict : never;
|
|
1201
|
+
/**
|
|
1202
|
+
* Result returned when decoding a stored offline conflict payload.
|
|
1203
|
+
*
|
|
1204
|
+
* `ok: true` contains the typed conflict payload. `ok: false` contains a
|
|
1205
|
+
* machine-readable parse error describing why decoding was not possible.
|
|
1206
|
+
*/
|
|
1207
|
+
export type ParsedOfflineResolutionConflictResultForOperation<TOperations, TName extends keyof TOperations & string> = ResultType<OperationConflict<TOperations, TName>, OfflineResolutionConflictParseError>;
|
|
1208
|
+
export type ParsedOfflineResolutionConflictResultForStore<TOperations> = ParsedOfflineResolutionConflictResultForOperation<TOperations, keyof TOperations & string>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Operation-aware offline resolution record for a specific registered operation.
|
|
1211
|
+
*
|
|
1212
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
1213
|
+
* @typeParam TName - Operation name whose stored resolution shape should be extracted.
|
|
1214
|
+
*/
|
|
1215
|
+
export type OfflineResolutionRecordForOperation<TOperations, TName extends keyof TOperations & string> = (OfflineConflictResolutionRecord<OperationConflict<TOperations, TName>, OperationInput<TOperations, TName>> & {
|
|
1216
|
+
/** Operation name associated with this resolution record. */
|
|
1217
|
+
operation: TName;
|
|
1218
|
+
}) | (OfflineRetryExhaustedResolutionRecord<OperationInput<TOperations, TName>> & {
|
|
1219
|
+
/** Operation name associated with this resolution record. */
|
|
1220
|
+
operation: TName;
|
|
1221
|
+
});
|
|
1222
|
+
/**
|
|
1223
|
+
* Union of operation-aware offline resolution records for an operation registry.
|
|
1224
|
+
*
|
|
1225
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
1226
|
+
* @typeParam TName - Optional subset of operation names to include.
|
|
1227
|
+
*/
|
|
1228
|
+
export type OfflineResolutionRecordForStore<TOperations, TName extends keyof TOperations & string = keyof TOperations & string> = {
|
|
1229
|
+
[K in TName]: OfflineResolutionRecordForOperation<TOperations, K>;
|
|
1230
|
+
}[TName];
|
|
1231
|
+
/** Failure code returned when parsing a stored offline conflict payload. */
|
|
1232
|
+
export type OfflineResolutionConflictParseErrorCode = 'not-conflict' | 'offline-not-configured' | 'operation-not-found' | 'conflict-handling-missing' | 'invalid-conflict-payload';
|
|
1233
|
+
/** Error returned when decoding a stored offline conflict payload fails. */
|
|
1234
|
+
export declare class OfflineResolutionConflictParseError extends Error {
|
|
1235
|
+
code: OfflineResolutionConflictParseErrorCode;
|
|
1236
|
+
operation: string;
|
|
1237
|
+
kind?: OfflineResolutionRecord['kind'];
|
|
1238
|
+
rawValue?: unknown;
|
|
1239
|
+
validationError?: SchemaValidationError;
|
|
1240
|
+
constructor(args: {
|
|
1241
|
+
code: OfflineResolutionConflictParseErrorCode;
|
|
1242
|
+
operation: string;
|
|
1243
|
+
kind?: OfflineResolutionRecord['kind'];
|
|
1244
|
+
rawValue?: unknown;
|
|
1245
|
+
validationError?: SchemaValidationError;
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Base shape for each offline operation entry in `persistentStorage.offline.operations`.
|
|
1250
|
+
* The `inputSchema` is used for both validation and queue serialization.
|
|
1251
|
+
*/
|
|
1252
|
+
export type OfflineOperationSchemaShape = {
|
|
1253
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
1254
|
+
};
|
|
1255
|
+
export {};
|