tsdf 17.0.6 → 18.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +29 -29
- package/package.json +3 -3
package/dist/main.js
CHANGED
|
@@ -12,7 +12,7 @@ import { Result, isResult, resultify, unknownToError } from "t-result";
|
|
|
12
12
|
import { Store, useSubscribeToStore } from "t-state";
|
|
13
13
|
import { useOnChange } from "@ls-stack/react-utils/useOnChange";
|
|
14
14
|
import { useConst } from "@ls-stack/react-utils/useConst";
|
|
15
|
-
import {
|
|
15
|
+
import { useLatestCb } from "@ls-stack/react-utils/useLatestValue";
|
|
16
16
|
import { useTimeout } from "@ls-stack/react-utils/useTimeout";
|
|
17
17
|
import { isObject, isPromise } from "@ls-stack/utils/typeGuards";
|
|
18
18
|
import { rc_array, rc_boolean, rc_literals, rc_number, rc_object, rc_parse, rc_parse_json, rc_record, rc_string, rc_union, rc_unknown } from "runcheck";
|
|
@@ -146,8 +146,8 @@ function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadIte
|
|
|
146
146
|
const ignoreSetWillBeRefetched = useRef(false);
|
|
147
147
|
const itemWasRefetched = useConst(() => /* @__PURE__ */ new Set());
|
|
148
148
|
if (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && itemId && !itemWasRefetched.has(itemId)) setWillBeRefetched(true);
|
|
149
|
-
const
|
|
150
|
-
const latestLoadItemFallback =
|
|
149
|
+
const getIsLoadingOrRefetching = useLatestCb(() => listIsLoading || isRefetching);
|
|
150
|
+
const latestLoadItemFallback = useLatestCb(loadItemFallback);
|
|
151
151
|
useEffect(() => {
|
|
152
152
|
if (isRefetching) {
|
|
153
153
|
if (itemId) itemWasRefetched.add(itemId);
|
|
@@ -165,8 +165,8 @@ function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadIte
|
|
|
165
165
|
useEffect(() => {
|
|
166
166
|
if (willBeRefetched) {
|
|
167
167
|
callFallbackLoadItemTimeout.call(() => {
|
|
168
|
-
if (!
|
|
169
|
-
latestLoadItemFallback
|
|
168
|
+
if (!getIsLoadingOrRefetching()) {
|
|
169
|
+
latestLoadItemFallback();
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
});
|
|
@@ -185,7 +185,7 @@ function useListItemIsLoading({ listIsLoading, isRefetching, itemExists, loadIte
|
|
|
185
185
|
}, [
|
|
186
186
|
resetWillBeRefetchedTimeout,
|
|
187
187
|
willBeRefetched,
|
|
188
|
-
|
|
188
|
+
getIsLoadingOrRefetching,
|
|
189
189
|
latestLoadItemFallback,
|
|
190
190
|
callFallbackLoadItemTimeout
|
|
191
191
|
]);
|
|
@@ -5507,22 +5507,22 @@ function createOfflineSession(args) {
|
|
|
5507
5507
|
useOfflineStatus: () => {
|
|
5508
5508
|
const coordinator = useSessionCoordinator();
|
|
5509
5509
|
const statusSelector = useCallback((state) => state.status, []);
|
|
5510
|
-
return coordinator.store.
|
|
5510
|
+
return coordinator.store.useSelector(statusSelector);
|
|
5511
5511
|
},
|
|
5512
5512
|
useOfflineEntities: () => {
|
|
5513
5513
|
const coordinator = useSessionCoordinator();
|
|
5514
5514
|
const entitiesSelector = useCallback((state) => state.entities.map(stripInternalEntityPayload), []);
|
|
5515
|
-
return coordinator.store.
|
|
5515
|
+
return coordinator.store.useSelector(entitiesSelector, { equalityFn: deepEqual });
|
|
5516
5516
|
},
|
|
5517
5517
|
useOfflineResolutions: () => {
|
|
5518
5518
|
const coordinator = useSessionCoordinator();
|
|
5519
5519
|
const resolutionsSelector = useCallback((state) => state.resolutions, []);
|
|
5520
|
-
return coordinator.store.
|
|
5520
|
+
return coordinator.store.useSelector(resolutionsSelector, { equalityFn: deepEqual });
|
|
5521
5521
|
},
|
|
5522
5522
|
useOfflineUploads: () => {
|
|
5523
5523
|
const coordinator = useSessionCoordinator();
|
|
5524
5524
|
const uploadsSelector = useCallback((state) => state.uploads, []);
|
|
5525
|
-
return castUploads(coordinator.store.
|
|
5525
|
+
return castUploads(coordinator.store.useSelector(uploadsSelector, { equalityFn: deepEqual }));
|
|
5526
5526
|
}
|
|
5527
5527
|
};
|
|
5528
5528
|
uploadsConfigByOfflineSession.set(eraseOfflineSession(session), eraseUploadsConfig(uploads));
|
|
@@ -5554,7 +5554,7 @@ function useConfiguredSessionOfflineCoordinator(sessionKey, config, uploads, boo
|
|
|
5554
5554
|
function useGlobalOfflineStatus(sessionKey) {
|
|
5555
5555
|
const coordinator = useSessionOfflineCoordinator(sessionKey, true);
|
|
5556
5556
|
const statusSelector = useCallback((state) => state.status, []);
|
|
5557
|
-
return coordinator.store.
|
|
5557
|
+
return coordinator.store.useSelector(statusSelector);
|
|
5558
5558
|
}
|
|
5559
5559
|
/**
|
|
5560
5560
|
* React hook that subscribes to the offline entities stream for a session.
|
|
@@ -5562,7 +5562,7 @@ function useGlobalOfflineStatus(sessionKey) {
|
|
|
5562
5562
|
function useGlobalOfflineEntities(sessionKey) {
|
|
5563
5563
|
const coordinator = useSessionOfflineCoordinator(sessionKey, true);
|
|
5564
5564
|
const entitiesSelector = useCallback((state) => state.entities.map(stripInternalEntityPayload), []);
|
|
5565
|
-
return coordinator.store.
|
|
5565
|
+
return coordinator.store.useSelector(entitiesSelector, { equalityFn: deepEqual });
|
|
5566
5566
|
}
|
|
5567
5567
|
/**
|
|
5568
5568
|
* React hook returning global offline conflict/retry resolutions for a session.
|
|
@@ -5570,7 +5570,7 @@ function useGlobalOfflineEntities(sessionKey) {
|
|
|
5570
5570
|
function useGlobalOfflineResolutions(sessionKey) {
|
|
5571
5571
|
const coordinator = useSessionOfflineCoordinator(sessionKey, true);
|
|
5572
5572
|
const resolutionsSelector = useCallback((state) => state.resolutions, []);
|
|
5573
|
-
return coordinator.store.
|
|
5573
|
+
return coordinator.store.useSelector(resolutionsSelector, { equalityFn: deepEqual });
|
|
5574
5574
|
}
|
|
5575
5575
|
/**
|
|
5576
5576
|
* React hook returning offline entities for a specific store in a session.
|
|
@@ -5581,7 +5581,7 @@ function useOfflineStoreEntitiesWithPayload(args) {
|
|
|
5581
5581
|
if (!args.storeName) return [];
|
|
5582
5582
|
return state.entities.filter((entity) => entity.storeName === args.storeName);
|
|
5583
5583
|
}, [args.storeName]);
|
|
5584
|
-
return coordinator.store.
|
|
5584
|
+
return coordinator.store.useSelector(entitiesSelector, { equalityFn: deepEqual });
|
|
5585
5585
|
}
|
|
5586
5586
|
function useOfflineStoreEntities(args) {
|
|
5587
5587
|
const entities = useOfflineStoreEntitiesWithPayload(args);
|
|
@@ -5593,7 +5593,7 @@ function useOfflineStoreEntities(args) {
|
|
|
5593
5593
|
function useOfflineStoreStatus(args) {
|
|
5594
5594
|
const coordinator = useSessionOfflineCoordinator(resolveOfflineSessionScope(args.sessionKey, args.inactiveScope), false);
|
|
5595
5595
|
const statusSelector = useCallback((state) => state.status, []);
|
|
5596
|
-
return coordinator.store.
|
|
5596
|
+
return coordinator.store.useSelector(statusSelector);
|
|
5597
5597
|
}
|
|
5598
5598
|
/**
|
|
5599
5599
|
* React hook returning offline conflict/retry resolutions for a specific store in a session.
|
|
@@ -5604,7 +5604,7 @@ function useOfflineStoreResolutions(args) {
|
|
|
5604
5604
|
if (!args.storeName) return [];
|
|
5605
5605
|
return state.resolutions.filter((resolution) => resolution.storeName === args.storeName);
|
|
5606
5606
|
}, [args.storeName]);
|
|
5607
|
-
return coordinator.store.
|
|
5607
|
+
return coordinator.store.useSelector(resolutionsSelector, { equalityFn: deepEqual });
|
|
5608
5608
|
}
|
|
5609
5609
|
//#endregion
|
|
5610
5610
|
//#region src/persistentStorage/offline/storeController.ts
|
|
@@ -9291,7 +9291,7 @@ function useMultipleItems$1(items, { selector, returnIdleStatus: allItemsReturnI
|
|
|
9291
9291
|
queriesWithId,
|
|
9292
9292
|
selector
|
|
9293
9293
|
]);
|
|
9294
|
-
const storeState = store.
|
|
9294
|
+
const storeState = store.useSelector(resultSelector, { equalityFn: deepEqual });
|
|
9295
9295
|
const automaticRetryState = useConst(() => /* @__PURE__ */ new Map());
|
|
9296
9296
|
const visibleStoreState = useMemo(() => {
|
|
9297
9297
|
return storeState.map((result, index) => {
|
|
@@ -10012,7 +10012,7 @@ function createCollectionStore(storeOptions) {
|
|
|
10012
10012
|
const offlineOverlaysSelector = useCallback((state) => {
|
|
10013
10013
|
return state;
|
|
10014
10014
|
}, []);
|
|
10015
|
-
const offlineOverlays = offlineOverlayStore.
|
|
10015
|
+
const offlineOverlays = offlineOverlayStore.useSelector(offlineOverlaysSelector);
|
|
10016
10016
|
return useMultipleItems$1(items, options, store, events, getItemKey, getItemState, persistence?.readHydratedItem, registerActiveItems, touchItems, persistence ? (payloads) => persistence.maybeHydrateItems(payloads.map((payload) => getItemKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, scheduleAutomaticFetch, invalidationWasTriggered, globalDisableRefetchOnMount, offlineEntities, offlineOverlays);
|
|
10017
10017
|
}
|
|
10018
10018
|
function useItem(payload, options = {}) {
|
|
@@ -11053,7 +11053,7 @@ function createDocumentStore(storeOptions) {
|
|
|
11053
11053
|
});
|
|
11054
11054
|
const offlineEntitiesByKey = useMemo(() => createOfflineEntityLookup(offlineEntities), [offlineEntities]);
|
|
11055
11055
|
const offlineOverlaySelector = useCallback((state) => state, []);
|
|
11056
|
-
const offlineOverlay = offlineOverlayStore.
|
|
11056
|
+
const offlineOverlay = offlineOverlayStore.useSelector(offlineOverlaySelector);
|
|
11057
11057
|
const isOffScreenFromContext = useContext(IsOffScreenContext);
|
|
11058
11058
|
const disabled = disabledProp ?? isOffScreenProp ?? isOffScreenFromContext;
|
|
11059
11059
|
const returnIdleStatus = returnIdleStatusProp ?? !!disabled;
|
|
@@ -11079,7 +11079,7 @@ function createDocumentStore(storeOptions) {
|
|
|
11079
11079
|
returnIdleStatus,
|
|
11080
11080
|
returnRefetchingStatus
|
|
11081
11081
|
]);
|
|
11082
|
-
const storeState = store.
|
|
11082
|
+
const storeState = store.useSelector(storeStateSelector, { equalityFn: deepEqual });
|
|
11083
11083
|
const automaticRetryState = useConst(() => /* @__PURE__ */ new Map());
|
|
11084
11084
|
useEffect(() => {
|
|
11085
11085
|
if (disabled) {
|
|
@@ -15326,7 +15326,7 @@ function useFindItem(findItemFn, { selector }, store, registerActiveItems, touch
|
|
|
15326
15326
|
value: selector ? selector(matchedItem.item, matchedItem.itemQuery.payload) : __LEGIT_CAST__(matchedItem.item)
|
|
15327
15327
|
};
|
|
15328
15328
|
}, [findItemFn, selector]);
|
|
15329
|
-
const selectedItem = store.
|
|
15329
|
+
const selectedItem = store.useSelector(selectedItemSelector, { equalityFn: deepEqual });
|
|
15330
15330
|
useRegisterActiveKeys(selectedItem?.itemKey ? [selectedItem.itemKey] : [], registerActiveItems, touchItems);
|
|
15331
15331
|
return selectedItem?.value ?? null;
|
|
15332
15332
|
}
|
|
@@ -15655,7 +15655,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
15655
15655
|
partialResources,
|
|
15656
15656
|
queriesWithId
|
|
15657
15657
|
]);
|
|
15658
|
-
const storeState = store.
|
|
15658
|
+
const storeState = store.useSelector(resultSelector, { equalityFn: deepEqual });
|
|
15659
15659
|
const visibleStoreState = useMemo(() => {
|
|
15660
15660
|
return storeState.map((result, index) => {
|
|
15661
15661
|
const query = queriesWithId[index];
|
|
@@ -15712,7 +15712,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
15712
15712
|
selector,
|
|
15713
15713
|
storeState
|
|
15714
15714
|
]);
|
|
15715
|
-
const autoFetchSignals = store.
|
|
15715
|
+
const autoFetchSignals = store.useSelector(autoFetchSignalSelector, { equalityFn: deepEqual });
|
|
15716
15716
|
const automaticRetryState = useConst(() => /* @__PURE__ */ new Map());
|
|
15717
15717
|
useEffect(() => {
|
|
15718
15718
|
for (const { itemKey, isOffScreen, retrySignature } of queriesWithId) {
|
|
@@ -16228,7 +16228,7 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
16228
16228
|
resolveEffectiveQuery,
|
|
16229
16229
|
selectVisibleItems
|
|
16230
16230
|
]);
|
|
16231
|
-
const storeState = store.
|
|
16231
|
+
const storeState = store.useSelector(resultSelector, { equalityFn: deepEqual });
|
|
16232
16232
|
const visibleStoreState = useMemo(() => {
|
|
16233
16233
|
return storeState.map((result, index) => {
|
|
16234
16234
|
const queryConfig = queriesWithId[index];
|
|
@@ -16287,7 +16287,7 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
16287
16287
|
selectVisibleItems,
|
|
16288
16288
|
stickyDerivedQueryKeys
|
|
16289
16289
|
]);
|
|
16290
|
-
const autoFetchSignals = store.
|
|
16290
|
+
const autoFetchSignals = store.useSelector(useCallback((state) => {
|
|
16291
16291
|
if (!partialResources) return [];
|
|
16292
16292
|
return queriesWithId.map((queryConfig) => {
|
|
16293
16293
|
const effectiveQuery = resolveEffectiveQuery(state, queryConfig);
|
|
@@ -16652,7 +16652,7 @@ function usePendingOfflineItems({ selector, filterPayload, includeResolutionRequ
|
|
|
16652
16652
|
readHydratedItem,
|
|
16653
16653
|
selector
|
|
16654
16654
|
]);
|
|
16655
|
-
return store.
|
|
16655
|
+
return store.useSelector(resultSelector, { equalityFn: deepEqual });
|
|
16656
16656
|
}
|
|
16657
16657
|
//#endregion
|
|
16658
16658
|
//#region src/listQueryStore/listQueryStore.ts
|
|
@@ -17398,7 +17398,7 @@ function createListQueryStore(storeOptions) {
|
|
|
17398
17398
|
const offlineOverlaysSelector = useCallback((state) => {
|
|
17399
17399
|
return state;
|
|
17400
17400
|
}, []);
|
|
17401
|
-
const offlineOverlays = offlineOverlayStore.
|
|
17401
|
+
const offlineOverlays = offlineOverlayStore.useSelector(offlineOverlaysSelector);
|
|
17402
17402
|
return useMultipleListQueries(queries, options, store, events, getQueryKey, registerActiveQueryRefs, touchQueries, getQueryState, persistence?.readHydratedQuery, persistence ? (payloads) => persistence.maybeHydrateQueries(payloads.map((payload) => getQueryKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence && derivedQueries ? (payloads) => persistence.preloadItemsByDerivedQueryGroup(payloads.map((payload) => derivedQueries.getQueryGroup(payload))) : void 0, persistence?.readHydratedItem, scheduleAutomaticListQueryFetch, queryInvalidationWasTriggered, itemPendingInvalidationFields, itemsPendingFullInvalidation, globalDisableRefetchOnMount, partialResources, derivedQueries, isStoreOfflineMode, offlineEntities, offlineOverlays);
|
|
17403
17403
|
};
|
|
17404
17404
|
const useListQuery$2 = function useListQuery$1(payload, options = {}) {
|
|
@@ -17413,7 +17413,7 @@ function createListQueryStore(storeOptions) {
|
|
|
17413
17413
|
const offlineOverlaysSelector = useCallback((state) => {
|
|
17414
17414
|
return state;
|
|
17415
17415
|
}, []);
|
|
17416
|
-
const offlineOverlays = offlineOverlayStore.
|
|
17416
|
+
const offlineOverlays = offlineOverlayStore.useSelector(offlineOverlaysSelector);
|
|
17417
17417
|
return useMultipleItems(items, options, store, events, getItemKey, registerActiveStandaloneItems, touchItems, scheduleAutomaticItemFetch, persistence ? (payloads) => persistence.maybeHydrateItems(payloads.map((payload) => getItemKey(payload))) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence?.readHydratedItem, itemInvalidationWasTriggered, itemPendingInvalidationFields, itemsPendingFullInvalidation, globalDisableRefetchOnMount, fetchItemFn, partialResources, offlineEntities, offlineOverlays);
|
|
17418
17418
|
};
|
|
17419
17419
|
const useItem$3 = function useItem$2(itemPayload, options = {}) {
|
|
@@ -17434,7 +17434,7 @@ function createListQueryStore(storeOptions) {
|
|
|
17434
17434
|
const offlineOverlaysSelector = useCallback((state) => {
|
|
17435
17435
|
return state;
|
|
17436
17436
|
}, []);
|
|
17437
|
-
const offlineOverlays = offlineOverlayStore.
|
|
17437
|
+
const offlineOverlays = offlineOverlayStore.useSelector(offlineOverlaysSelector);
|
|
17438
17438
|
return usePendingOfflineItems(options, store, registerActiveStandaloneItems, touchItems, persistence?.preloadItems ? (itemKeys) => persistence.preloadItems(itemKeys) : void 0, !!persistence && !persistence.hasAsyncPreload, persistence?.readHydratedItem, offlineEntities, offlineOverlays);
|
|
17439
17439
|
};
|
|
17440
17440
|
function useFindItem$1(findItemFn, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.1",
|
|
4
4
|
"description": "A data fetching solution based on t-state",
|
|
5
5
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
6
|
"author": "Lucas Santos",
|
|
@@ -70,14 +70,14 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@evtmitter/react": "^0.1.0",
|
|
72
72
|
"@ls-stack/browser-utils": "^0.3.5",
|
|
73
|
-
"@ls-stack/react-utils": "^0.13.
|
|
73
|
+
"@ls-stack/react-utils": "^0.13.3",
|
|
74
74
|
"@ls-stack/utils": "^4.0.0",
|
|
75
75
|
"@standard-schema/spec": "^1.1.0",
|
|
76
76
|
"evtmitter": "^1.0.2",
|
|
77
77
|
"klona": "^2.0.6",
|
|
78
78
|
"runcheck": "^1.15.0",
|
|
79
79
|
"t-result": "^0.6.1",
|
|
80
|
-
"t-state": "^
|
|
80
|
+
"t-state": "^10.0.0"
|
|
81
81
|
},
|
|
82
82
|
"simple-git-hooks": {
|
|
83
83
|
"pre-commit": "node --no-warnings scripts/preCommitHook.ts"
|