tsdf 17.0.0-alpha.4 → 17.0.0-alpha.6
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/main.d.ts +79 -36
- package/dist/main.js +22 -28
- package/docs/README.md +1 -1
- package/docs/collection-store.md +1 -1
- package/docs/document-store.md +1 -1
- package/docs/invalidation.md +3 -3
- package/docs/list-query-store.md +1 -1
- package/docs/mutations.md +5 -2
- package/docs/shared-types.md +12 -0
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -53,6 +53,17 @@ type MutationSkipped = {
|
|
|
53
53
|
kind: 'skipped';
|
|
54
54
|
};
|
|
55
55
|
declare const mutationSkipped: MutationSkipped;
|
|
56
|
+
/** Options passed to mutation error handlers. */
|
|
57
|
+
type StoreMutationErrorOptions = {
|
|
58
|
+
/**
|
|
59
|
+
* True when the mutation caller asked the shared error handler to stay quiet.
|
|
60
|
+
*
|
|
61
|
+
* Handlers are still called so apps can keep centralized logging, metrics, or
|
|
62
|
+
* custom recovery behavior while suppressing user-facing noise such as toast
|
|
63
|
+
* notifications.
|
|
64
|
+
*/
|
|
65
|
+
silentErrors?: boolean;
|
|
66
|
+
};
|
|
56
67
|
declare class StoreMutationError extends Error {
|
|
57
68
|
readonly kind = "error";
|
|
58
69
|
code: number;
|
|
@@ -1426,10 +1437,7 @@ type StoreManagerStoreDefaults = {
|
|
|
1426
1437
|
readonly blockWindowClose: BlockWindowCloseHandler | null; /** Default focus revalidation policy for attached stores. */
|
|
1427
1438
|
readonly revalidateOnWindowFocus: boolean | (() => boolean) | undefined;
|
|
1428
1439
|
};
|
|
1429
|
-
type StoreManagerMutationErrorHandler = (error: unknown, options:
|
|
1430
|
-
dontShowToast?: boolean;
|
|
1431
|
-
silentErrors?: boolean;
|
|
1432
|
-
}) => void;
|
|
1440
|
+
type StoreManagerMutationErrorHandler = (error: unknown, options: StoreMutationErrorOptions) => void;
|
|
1433
1441
|
type StoreManagerOfflineApi<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1434
1442
|
/** Returns the shared offline config, when configured. */getOfflineConfig: () => OfflineSessionConfig<TUploadRef> | undefined; /** Latest effective runtime config for this manager's offline session. */
|
|
1435
1443
|
getOfflineRuntimeConfig: () => OfflineRuntimeConfig; /** Updates runtime controls for this manager's offline session. */
|
|
@@ -1656,9 +1664,13 @@ type CollectionStoreOptions<ItemState extends ValidStoreState, ItemPayload exten
|
|
|
1656
1664
|
transportReconnectCooldownMs?: number;
|
|
1657
1665
|
onInvalidate?: OnCollectionItemInvalidate<ItemState, ItemPayload>;
|
|
1658
1666
|
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1667
|
+
/**
|
|
1668
|
+
* Store-specific mutation error handler.
|
|
1669
|
+
*
|
|
1670
|
+
* Overrides the manager fallback. Use `null` to disable inherited mutation
|
|
1671
|
+
* error handling for this store.
|
|
1672
|
+
*/
|
|
1673
|
+
onMutationError?: ((error: unknown, options: StoreMutationErrorOptions) => void) | null;
|
|
1662
1674
|
usesRealTimeUpdates?: boolean;
|
|
1663
1675
|
/** Opt-in persistent storage configuration. When provided, cached items are loaded
|
|
1664
1676
|
* from storage on first read and saved back on successful fetches.
|
|
@@ -1678,11 +1690,22 @@ type CollectionMutationPayload<ItemPayload extends ValidPayload> = ItemPayload |
|
|
|
1678
1690
|
type CollectionMutationTarget<ItemPayload extends ValidPayload> = ItemPayload | ItemPayload[];
|
|
1679
1691
|
type CollectionMutationPayloadToUse<ItemPayload extends ValidPayload> = CollectionMutationTarget<ItemPayload>;
|
|
1680
1692
|
type CollectionMutationArgsBase<T, ItemPayload extends ValidPayload> = {
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1693
|
+
/**
|
|
1694
|
+
* Applies optimistic updates for the affected item payloads before the
|
|
1695
|
+
* mutation runs. Return `false` to cancel the mutation before the async
|
|
1696
|
+
* mutation function is called.
|
|
1697
|
+
*/
|
|
1698
|
+
optimisticUpdate?: (payload: CollectionMutationPayloadToUse<ItemPayload>) => void | boolean; /** Performs the server mutation for the affected item payloads. */
|
|
1699
|
+
mutation: (payload: CollectionMutationPayloadToUse<ItemPayload>) => Promise<T>; /** Called after a successful online mutation. */
|
|
1700
|
+
onSuccess?: (response: Awaited<T>, payload: CollectionMutationPayloadToUse<ItemPayload>) => void; /** Invalidates affected items after a successful online mutation. */
|
|
1684
1701
|
revalidateOnSuccess?: boolean;
|
|
1685
|
-
|
|
1702
|
+
/**
|
|
1703
|
+
* Passes `{ silentErrors: true }` to `onMutationError`.
|
|
1704
|
+
*
|
|
1705
|
+
* The handler is still called so centralized logging and recovery can run,
|
|
1706
|
+
* but UI handlers can suppress user-facing notifications.
|
|
1707
|
+
*/
|
|
1708
|
+
silentErrors?: boolean; /** Debounces mutations with the same context and payload. Superseded calls are skipped. */
|
|
1686
1709
|
debounce?: {
|
|
1687
1710
|
context: string;
|
|
1688
1711
|
payload: __LEGIT_ANY__;
|
|
@@ -1866,9 +1889,13 @@ type DocumentStoreOptions<State extends ValidStoreState, TOfflineOperations exte
|
|
|
1866
1889
|
transportReconnectCooldownMs?: number;
|
|
1867
1890
|
mediumPriorityDelayMs?: number;
|
|
1868
1891
|
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1892
|
+
/**
|
|
1893
|
+
* Store-specific mutation error handler.
|
|
1894
|
+
*
|
|
1895
|
+
* Overrides the manager fallback. Use `null` to disable inherited mutation
|
|
1896
|
+
* error handling for this store.
|
|
1897
|
+
*/
|
|
1898
|
+
onMutationError?: ((error: unknown, options: StoreMutationErrorOptions) => void) | null;
|
|
1872
1899
|
usesRealTimeUpdates?: boolean;
|
|
1873
1900
|
/** Opt-in persistent storage configuration. When provided, cached data is loaded
|
|
1874
1901
|
* from storage on first read and saved back on successful fetches.
|
|
@@ -1879,18 +1906,30 @@ type DocumentStoreOptions<State extends ValidStoreState, TOfflineOperations exte
|
|
|
1879
1906
|
type ResolvedDocumentOfflineOperations<TOfflineOperations> = TOfflineOperations extends null ? Record<never, never> : Exclude<TOfflineOperations, null>;
|
|
1880
1907
|
type DocumentUpdateState<State extends ValidStoreState> = (produceNewData: (draftData: State) => State | void | undefined) => boolean;
|
|
1881
1908
|
type DocumentMutationContext<State extends ValidStoreState> = {
|
|
1882
|
-
updateState: DocumentUpdateState<State>;
|
|
1909
|
+
/** Updates the current document state during the mutation. Returns `false` when no document data is loaded. */updateState: DocumentUpdateState<State>; /** Document state at the moment the mutation function runs. */
|
|
1883
1910
|
currentState: State | null;
|
|
1884
1911
|
};
|
|
1885
1912
|
type DocumentMutationArgsBase<State extends ValidStoreState, T> = {
|
|
1886
|
-
|
|
1887
|
-
|
|
1913
|
+
/**
|
|
1914
|
+
* Applies an optimistic document update before the mutation runs.
|
|
1915
|
+
*
|
|
1916
|
+
* Return `false` to cancel the mutation before the async mutation function is
|
|
1917
|
+
* called.
|
|
1918
|
+
*/
|
|
1919
|
+
optimisticUpdate?: (currentState: State | null) => void | boolean; /** Performs the server mutation. */
|
|
1920
|
+
mutation: (ctx: DocumentMutationContext<State>) => Promise<T>; /** Debounces mutations with the same context and payload. Superseded calls are skipped. */
|
|
1888
1921
|
debounce?: {
|
|
1889
1922
|
context: string;
|
|
1890
1923
|
payload: __LEGIT_ANY__;
|
|
1891
1924
|
ms: number;
|
|
1892
1925
|
};
|
|
1893
|
-
|
|
1926
|
+
/**
|
|
1927
|
+
* Passes `{ silentErrors: true }` to `onMutationError`.
|
|
1928
|
+
*
|
|
1929
|
+
* The handler is still called so centralized logging and recovery can run,
|
|
1930
|
+
* but UI handlers can suppress user-facing notifications.
|
|
1931
|
+
*/
|
|
1932
|
+
silentErrors?: boolean; /** Invalidates the document after a successful online mutation. */
|
|
1894
1933
|
revalidateOnSuccess?: boolean;
|
|
1895
1934
|
};
|
|
1896
1935
|
type DocumentOnlineMutationArgs<State extends ValidStoreState, T> = DocumentMutationArgsBase<State, T> & {
|
|
@@ -2425,6 +2464,19 @@ type ListQueryAddItemToStateApi<ItemState extends ValidStoreState, QueryPayload
|
|
|
2425
2464
|
};
|
|
2426
2465
|
}) => void;
|
|
2427
2466
|
type ListQueryDeleteItemStateApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (itemId: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>) => void;
|
|
2467
|
+
type ListQueryInvalidateQueryAndItemsArgs<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
2468
|
+
/** Invalidate every cached query and every cached item. */all: true;
|
|
2469
|
+
type?: FetchType;
|
|
2470
|
+
fields?: string[];
|
|
2471
|
+
itemPayload?: undefined;
|
|
2472
|
+
queryPayload?: undefined;
|
|
2473
|
+
} | {
|
|
2474
|
+
all?: undefined;
|
|
2475
|
+
itemPayload: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload> | false;
|
|
2476
|
+
queryPayload: QueryPayload | QueryPayload[] | ListQueryFilterQuery<QueryPayload> | false;
|
|
2477
|
+
type?: FetchType;
|
|
2478
|
+
fields?: string[];
|
|
2479
|
+
};
|
|
2428
2480
|
type ListQueryStore<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean = false, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload> = null> = {
|
|
2429
2481
|
store: Store<TSFDListQueryState<ItemState, QueryPayload, ItemPayload>>;
|
|
2430
2482
|
events: Emitter<ListQueryStoreEvents>;
|
|
@@ -2467,12 +2519,7 @@ type ListQueryStore<ItemState extends ValidStoreState, QueryPayload extends Vali
|
|
|
2467
2519
|
scheduleItemFetch: ListQueryScheduleItemFetchApi<ItemPayload, TPartialResources>;
|
|
2468
2520
|
awaitItemFetch: ListQueryAwaitItemFetchApi<ItemState, ItemPayload, TPartialResources>;
|
|
2469
2521
|
getItemFromStateOrFetch: ListQueryGetItemFromStateOrFetchApi<ItemState, ItemPayload, TPartialResources>;
|
|
2470
|
-
invalidateQueryAndItems: (args:
|
|
2471
|
-
itemPayload: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload> | false;
|
|
2472
|
-
queryPayload: QueryPayload | QueryPayload[] | ListQueryFilterQuery<QueryPayload> | false;
|
|
2473
|
-
type?: FetchType;
|
|
2474
|
-
fields?: string[];
|
|
2475
|
-
}) => void;
|
|
2522
|
+
invalidateQueryAndItems: (args: ListQueryInvalidateQueryAndItemsArgs<ItemState, QueryPayload, ItemPayload>) => void;
|
|
2476
2523
|
invalidateItem: (itemId: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>, priority?: FetchType) => void;
|
|
2477
2524
|
startItemMutation: (itemId: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>) => () => void;
|
|
2478
2525
|
updateItemState: ListQueryUpdateItemStateApi<ItemState, ItemPayload>;
|
|
@@ -2592,9 +2639,13 @@ type ListQueryStoreOptionsBase<ItemState extends ValidStoreState, QueryPayload e
|
|
|
2592
2639
|
onInvalidateQuery?: OnListQueryInvalidate<QueryPayload>;
|
|
2593
2640
|
onInvalidateItem?: OnListQueryItemInvalidate<ItemState, ItemPayload>;
|
|
2594
2641
|
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2642
|
+
/**
|
|
2643
|
+
* Store-specific mutation error handler.
|
|
2644
|
+
*
|
|
2645
|
+
* Overrides the manager fallback. Use `null` to disable inherited mutation
|
|
2646
|
+
* error handling for this store.
|
|
2647
|
+
*/
|
|
2648
|
+
onMutationError?: ((error: unknown, options: StoreMutationErrorOptions) => void) | null; /** Opt-in hook-level query derivation from locally materialized items. */
|
|
2598
2649
|
derivedQueries?: DerivedQueriesConfig<ItemState, QueryPayload, ItemPayload>;
|
|
2599
2650
|
getQueryKey?: (params: QueryPayload) => ValidPayload | unknown[];
|
|
2600
2651
|
getItemKey?: (params: ItemPayload) => ValidPayload | unknown[];
|
|
@@ -2626,14 +2677,6 @@ declare function createListQueryStore<ItemState extends ValidStoreState, QueryPa
|
|
|
2626
2677
|
* `getQueriesState`.
|
|
2627
2678
|
*/
|
|
2628
2679
|
declare const GET_ALL: (...args: unknown[]) => true;
|
|
2629
|
-
/**
|
|
2630
|
-
* Shared List Query invalidation target for invalidating every cached query and
|
|
2631
|
-
* every cached item.
|
|
2632
|
-
*/
|
|
2633
|
-
declare const ALL_QUERY_AND_ITEMS: {
|
|
2634
|
-
readonly queryPayload: typeof GET_ALL;
|
|
2635
|
-
readonly itemPayload: typeof GET_ALL;
|
|
2636
|
-
};
|
|
2637
2680
|
//#endregion
|
|
2638
2681
|
//#region src/isOffScreenContext.d.ts
|
|
2639
2682
|
/**
|
|
@@ -2786,4 +2829,4 @@ declare function clearAllSessionStorage(sessionKey: string): Promise<void>;
|
|
|
2786
2829
|
//#region src/persistentStorage/opfsOfflineUploadAdapter.d.ts
|
|
2787
2830
|
declare const opfsOfflineUploadAdapter: OfflineUploadAdapter;
|
|
2788
2831
|
//#endregion
|
|
2789
|
-
export {
|
|
2832
|
+
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, CollectionBrowserTabsMessage, CollectionInitialStateItem, CollectionItemStatus, 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, DocumentBrowserTabsMessage, type DocumentOfflineOperationDefinition, type DocumentPersistentStorageConfig, DocumentStatus, DocumentStore, DocumentStoreOptions, DocumentStoreState, DocumentStoreStoreEvents, type FetchListFnReturn, type FetchListFnReturnItem, type FieldsInput, type FieldsOption, GET_ALL, type GlobalOfflineEntity, type GlobalOfflineStatus, type IndexedDbPersistentStorageOptions, IsOffScreenContext, type ListQueryOfflineEntityRef, type ListQueryOfflineOperationDefinition, type ListQueryPersistentStorageConfig, type ListQueryStore, type ListQueryStoreEvents, type ListQueryStoreInitialData, type ListQueryStoreOptions, type ListQueryUseMultipleItemsQuery, type ListQueryUseMultipleListQueriesQuery, 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 TSDFItemQuery, type TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, type TSFDListQuery, type TSFDListQueryState, TSFDUseCollectionItemReturn, type TSFDUseListItemReturn, type TSFDUseListQueryReturn, type TSFDUsePendingOfflineItemsReturn, type ValidPayload, type ValidStoreState, clearAllSessionStorage, clearSessionStorage, createAsyncStorageAdapter, createCollectionStore, createDocumentStore, createIndexedDbPersistentStorage, createListQueryStore, createStoreManager, defaultOfflineRuntimeConfig, fetchTypePriority, getGlobalOfflineEntities, getGlobalOfflineResolutions, getGlobalOfflineStatus, indexedDbPersistentStorage, localPersistentStorage, mutationSkipped, opfsOfflineUploadAdapter, opfsPersistentStorage, useGlobalOfflineEntities, useGlobalOfflineResolutions, useGlobalOfflineStatus };
|
package/dist/main.js
CHANGED
|
@@ -12225,7 +12225,7 @@ function createCollectionStore({ id, storeManager, fetchFn, batchFetchFn, getIte
|
|
|
12225
12225
|
});
|
|
12226
12226
|
if (restoredItemKeys.length > 0) touchItemsAndMaybeEnforceLimits(restoredItemKeys);
|
|
12227
12227
|
}
|
|
12228
|
-
if (
|
|
12228
|
+
if (resolvedOnMutationError) resolvedOnMutationError(exception, { silentErrors });
|
|
12229
12229
|
return error;
|
|
12230
12230
|
}
|
|
12231
12231
|
});
|
|
@@ -13047,7 +13047,7 @@ function createDocumentStore({ id, storeManager, fetchFn, lowPriorityThrottleMs:
|
|
|
13047
13047
|
function startMutation() {
|
|
13048
13048
|
return scheduler.startMutation(DOC_REQUEST_ID);
|
|
13049
13049
|
}
|
|
13050
|
-
async function performMutation({ optimisticUpdate, mutation, debounce,
|
|
13050
|
+
async function performMutation({ optimisticUpdate, mutation, debounce, silentErrors, revalidateOnSuccess, offline, upload }) {
|
|
13051
13051
|
if (offline && offlineController && !offlineController.canQueueMutation()) return Result.err(toStoreMutationError(new OfflineSessionUnavailableError(), errorNormalizer));
|
|
13052
13052
|
const mutationId = getAutoIncrementId();
|
|
13053
13053
|
storeEvents.emit("mutationStart", { mutationId });
|
|
@@ -13078,7 +13078,7 @@ function createDocumentStore({ id, storeManager, fetchFn, lowPriorityThrottleMs:
|
|
|
13078
13078
|
store.setKey("data", optimisticRollbackSnapshot ?? null, { action: "rollback-mutation-error" });
|
|
13079
13079
|
publishDocumentSnapshot();
|
|
13080
13080
|
});
|
|
13081
|
-
if (resolvedOnMutationError) resolvedOnMutationError(exception, {
|
|
13081
|
+
if (resolvedOnMutationError) resolvedOnMutationError(exception, { silentErrors });
|
|
13082
13082
|
return toStoreMutationError(exception, errorNormalizer);
|
|
13083
13083
|
}
|
|
13084
13084
|
});
|
|
@@ -15874,6 +15874,16 @@ function createFetchApi({ store, normalizedFetchListFn, offsetPagination, fetchI
|
|
|
15874
15874
|
};
|
|
15875
15875
|
}
|
|
15876
15876
|
//#endregion
|
|
15877
|
+
//#region src/invalidationUtils.ts
|
|
15878
|
+
/**
|
|
15879
|
+
* Predicate that matches every currently known payload.
|
|
15880
|
+
*
|
|
15881
|
+
* Use it with APIs that accept payload filters, such as
|
|
15882
|
+
* `invalidateQueryAndItems`, `invalidateItem`, `getItemState`, and
|
|
15883
|
+
* `getQueriesState`.
|
|
15884
|
+
*/
|
|
15885
|
+
const GET_ALL = () => true;
|
|
15886
|
+
//#endregion
|
|
15877
15887
|
//#region src/listQueryStore/createMutationApi.ts
|
|
15878
15888
|
/** @internal */
|
|
15879
15889
|
function createMutationApi({ store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, onMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, emitInvalidateQuery, emitInvalidateItem, blockWindowClose, offlineController, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, onOfflineTimelineEvent }) {
|
|
@@ -15937,7 +15947,11 @@ function createMutationApi({ store, fetchItemFn, partialResources, optimisticLis
|
|
|
15937
15947
|
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
15938
15948
|
const itemFieldInvalidationPriorities = /* @__PURE__ */ new Map();
|
|
15939
15949
|
const itemPendingInvalidationFields = /* @__PURE__ */ new Map();
|
|
15940
|
-
function invalidateQueryAndItems(
|
|
15950
|
+
function invalidateQueryAndItems(args) {
|
|
15951
|
+
const itemPayload = args.all ? GET_ALL : args.itemPayload;
|
|
15952
|
+
const queryPayload = args.all ? GET_ALL : args.queryPayload;
|
|
15953
|
+
const priority = args.type ?? "highPriority";
|
|
15954
|
+
const invalidateFields = args.fields;
|
|
15941
15955
|
const queriesKey = queryPayload ? getQueriesKeyArray(queryPayload) : [];
|
|
15942
15956
|
for (const { key, payload } of queriesKey) {
|
|
15943
15957
|
const queryState = store.state.queries[key];
|
|
@@ -16316,7 +16330,7 @@ function createMutationApi({ store, fetchItemFn, partialResources, optimisticLis
|
|
|
16316
16330
|
itemSnapshots: itemRollbackSnapshots,
|
|
16317
16331
|
querySnapshots: queryRollbackSnapshots
|
|
16318
16332
|
});
|
|
16319
|
-
if (
|
|
16333
|
+
if (onMutationError) onMutationError(exception, { silentErrors });
|
|
16320
16334
|
if (onError) onError(error);
|
|
16321
16335
|
return error;
|
|
16322
16336
|
}
|
|
@@ -18473,15 +18487,13 @@ function createListQueryStore(storeOptions) {
|
|
|
18473
18487
|
onWindowFocus: testOptions?.onWindowFocus ?? onWindowFocus,
|
|
18474
18488
|
onWindowFocusRevalidate: () => {
|
|
18475
18489
|
invalidateQueryAndItems({
|
|
18476
|
-
|
|
18477
|
-
itemPayload: () => true,
|
|
18490
|
+
all: true,
|
|
18478
18491
|
type: "lowPriority"
|
|
18479
18492
|
});
|
|
18480
18493
|
},
|
|
18481
18494
|
onTransportReconnectRevalidate: () => {
|
|
18482
18495
|
invalidateQueryAndItems({
|
|
18483
|
-
|
|
18484
|
-
itemPayload: () => true,
|
|
18496
|
+
all: true,
|
|
18485
18497
|
type: "realtimeUpdate"
|
|
18486
18498
|
});
|
|
18487
18499
|
}
|
|
@@ -18740,24 +18752,6 @@ function createListQueryStore(storeOptions) {
|
|
|
18740
18752
|
};
|
|
18741
18753
|
}
|
|
18742
18754
|
//#endregion
|
|
18743
|
-
//#region src/invalidationUtils.ts
|
|
18744
|
-
/**
|
|
18745
|
-
* Predicate that matches every currently known payload.
|
|
18746
|
-
*
|
|
18747
|
-
* Use it with APIs that accept payload filters, such as
|
|
18748
|
-
* `invalidateQueryAndItems`, `invalidateItem`, `getItemState`, and
|
|
18749
|
-
* `getQueriesState`.
|
|
18750
|
-
*/
|
|
18751
|
-
const GET_ALL = () => true;
|
|
18752
|
-
/**
|
|
18753
|
-
* Shared List Query invalidation target for invalidating every cached query and
|
|
18754
|
-
* every cached item.
|
|
18755
|
-
*/
|
|
18756
|
-
const ALL_QUERY_AND_ITEMS = {
|
|
18757
|
-
queryPayload: GET_ALL,
|
|
18758
|
-
itemPayload: GET_ALL
|
|
18759
|
-
};
|
|
18760
|
-
//#endregion
|
|
18761
18755
|
//#region src/persistentStorage/opfsOfflineUploadAdapter.ts
|
|
18762
18756
|
const OPFS_UPLOADS_ROOT_DIR = "tsdf-uploads";
|
|
18763
18757
|
const METADATA_FILE_NAME = "metadata.json";
|
|
@@ -18930,4 +18924,4 @@ var OpfsOfflineUploadDriver = class {
|
|
|
18930
18924
|
};
|
|
18931
18925
|
const opfsOfflineUploadAdapter = new OpfsOfflineUploadDriver();
|
|
18932
18926
|
//#endregion
|
|
18933
|
-
export {
|
|
18927
|
+
export { GET_ALL, IsOffScreenContext, StoreFetchError, StoreMutationError, clearAllSessionStorage, clearSessionStorage, createAsyncStorageAdapter, createCollectionStore, createDocumentStore, createIndexedDbPersistentStorage, createListQueryStore, createStoreManager, defaultOfflineRuntimeConfig, fetchTypePriority, getGlobalOfflineEntities, getGlobalOfflineResolutions, getGlobalOfflineStatus, indexedDbPersistentStorage, localPersistentStorage, mutationSkipped, opfsOfflineUploadAdapter, opfsPersistentStorage, useGlobalOfflineEntities, useGlobalOfflineResolutions, useGlobalOfflineStatus };
|
package/docs/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Notable additions:
|
|
|
36
36
|
|
|
37
37
|
- Hook payload debouncing is documented in [React Hooks](./hooks.md#debouncepayload)
|
|
38
38
|
- The exported `PayloadDebounce` type is documented in [Shared Types](./shared-types.md#payloaddebounce)
|
|
39
|
-
- `GET_ALL` and `
|
|
39
|
+
- `GET_ALL` and `{ all: true }` invalidation are documented in [Invalidation](./invalidation.md#list-query-store)
|
|
40
40
|
|
|
41
41
|
## Quick Start
|
|
42
42
|
|
package/docs/collection-store.md
CHANGED
|
@@ -49,7 +49,7 @@ const productStore = createCollectionStore<Product, string>({
|
|
|
49
49
|
| `persistentStorage` | `CollectionPersistentStorageConfig<ItemState, ItemPayload>` | No | Configure cache persistence. See [Persistent Storage](./persistent-storage.md) |
|
|
50
50
|
| `onInvalidate` | `(props: { itemState, payload, priority }) => void` | No | Called when an item is invalidated |
|
|
51
51
|
| `onSchedulerEvent` | `(event, data?) => void` | No | Scheduler event listener |
|
|
52
|
-
| `onMutationError` | `(error, options: { silentErrors
|
|
52
|
+
| `onMutationError` | `(error, options: { silentErrors?: boolean }) => void` | No | Global mutation error handler |
|
|
53
53
|
|
|
54
54
|
## Item State Shape
|
|
55
55
|
|
package/docs/document-store.md
CHANGED
|
@@ -42,7 +42,7 @@ const userStore = createDocumentStore<User>({
|
|
|
42
42
|
| `usesRealTimeUpdates` | `boolean` | No | Enables [Real-Time Updates](./real-time-updates.md) mode |
|
|
43
43
|
| `persistentStorage` | `DocumentPersistentStorageConfig<State>` | No | Configure cache persistence. See [Persistent Storage](./persistent-storage.md) |
|
|
44
44
|
| `onSchedulerEvent` | `(event) => void` | No | Scheduler event listener |
|
|
45
|
-
| `onMutationError` | `(error, options: {
|
|
45
|
+
| `onMutationError` | `(error, options: { silentErrors?: boolean }) => void` | No | Global mutation error handler |
|
|
46
46
|
|
|
47
47
|
## State Shape
|
|
48
48
|
|
package/docs/invalidation.md
CHANGED
|
@@ -45,10 +45,10 @@ store.invalidateItem('item-1', 'lowPriority');
|
|
|
45
45
|
The List Query Store has the most flexible invalidation through `invalidateQueryAndItems`:
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
-
import {
|
|
48
|
+
import { GET_ALL } from 'tsdf';
|
|
49
49
|
|
|
50
50
|
// Invalidate all queries and all items
|
|
51
|
-
store.invalidateQueryAndItems(
|
|
51
|
+
store.invalidateQueryAndItems({ all: true });
|
|
52
52
|
|
|
53
53
|
// Invalidate specific queries only (skip items)
|
|
54
54
|
store.invalidateQueryAndItems({
|
|
@@ -69,7 +69,7 @@ store.invalidateQueryAndItems({
|
|
|
69
69
|
type: 'lowPriority',
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
// Reuse the all-payload predicate
|
|
72
|
+
// Reuse the all-payload predicate when only one side should match everything
|
|
73
73
|
store.invalidateQueryAndItems({ queryPayload: GET_ALL, itemPayload: false });
|
|
74
74
|
```
|
|
75
75
|
|
package/docs/list-query-store.md
CHANGED
|
@@ -80,7 +80,7 @@ The type parameters are:
|
|
|
80
80
|
| `onInvalidateItem` | `(props: { itemState, payload, priority }) => void` | Called when an item is invalidated |
|
|
81
81
|
| `persistentStorage` | `ListQueryPersistentStorageConfig<ItemState, QueryPayload, ItemPayload>` | Configure cache persistence. See [Persistent Storage](./persistent-storage.md) |
|
|
82
82
|
| `onSchedulerEvent` | `(event, data?) => void` | Scheduler event listener |
|
|
83
|
-
| `onMutationError` | `(error, options) => void`
|
|
83
|
+
| `onMutationError` | `(error, options: { silentErrors?: boolean }) => void` | Global mutation error handler |
|
|
84
84
|
|
|
85
85
|
### FetchListFnReturn
|
|
86
86
|
|
package/docs/mutations.md
CHANGED
|
@@ -25,6 +25,9 @@ const result = await store.performMutation({
|
|
|
25
25
|
|
|
26
26
|
// After success, invalidate data to refetch from the server
|
|
27
27
|
revalidateOnSuccess: true,
|
|
28
|
+
|
|
29
|
+
// Ask the global/store onMutationError handler to stay quiet
|
|
30
|
+
silentErrors: true,
|
|
28
31
|
});
|
|
29
32
|
|
|
30
33
|
if (result.ok) {
|
|
@@ -81,7 +84,7 @@ The payload can be:
|
|
|
81
84
|
3. **Debounce** (optional): Waits for `ms` milliseconds. During debounce, the window close is blocked
|
|
82
85
|
4. **Execute mutation**: The async mutation function runs
|
|
83
86
|
5. **On success**: Calls `onSuccess`, optionally invalidates data
|
|
84
|
-
6. **On error**:
|
|
87
|
+
6. **On error**: Rolls back optimistic state, normalizes the error, and calls `onMutationError` with the `silentErrors` flag
|
|
85
88
|
7. **Unlock**: The scheduler is unlocked, pending fetches resume
|
|
86
89
|
|
|
87
90
|
## Return Value
|
|
@@ -178,7 +181,7 @@ await store.performMutation(payload, {
|
|
|
178
181
|
items: false,
|
|
179
182
|
},
|
|
180
183
|
|
|
181
|
-
//
|
|
184
|
+
// Ask the global/store onMutationError handler to stay quiet
|
|
182
185
|
silentErrors: true,
|
|
183
186
|
|
|
184
187
|
// Callbacks
|
package/docs/shared-types.md
CHANGED
|
@@ -32,6 +32,18 @@ It contains the normalized `StoreError` fields plus:
|
|
|
32
32
|
- `kind: 'error'`
|
|
33
33
|
- `cause` — the original thrown value, preserved via `Error.cause`
|
|
34
34
|
|
|
35
|
+
## StoreMutationErrorOptions
|
|
36
|
+
|
|
37
|
+
Options passed to store-level and manager-level `onMutationError` handlers:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
type StoreMutationErrorOptions = { silentErrors?: boolean };
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
When `silentErrors` is true, the handler is still called. Use the flag to keep
|
|
44
|
+
centralized logging or recovery behavior while suppressing user-facing
|
|
45
|
+
notifications such as error toasts.
|
|
46
|
+
|
|
35
47
|
## MutationSkipped
|
|
36
48
|
|
|
37
49
|
A sentinel returned by `performMutation` when the mutation is intentionally not
|