1 import { asIfNotOptimistic } from '@proton/pass/store/optimistic/selectors/select-is-optimistic';
2 import { reducerMap } from '@proton/pass/store/reducers';
3 import type { State } from '@proton/pass/store/types';
4 import { objectFilter } from '@proton/pass/utils/object/filter';
5 import { objectMap } from '@proton/pass/utils/object/map';
6 import { partialMerge } from '@proton/pass/utils/object/merge';
8 export const selectCachableState = (state: State) => {
9 const whiteListedState = asIfNotOptimistic(state, reducerMap);
11 /** Remove "hot" data that should never be cached.
12 * These should be revalidated on boot or via polling. */
13 whiteListedState.monitor = null;
14 whiteListedState.items.secureLinks = {};
15 whiteListedState.invites = {};
16 whiteListedState.user = partialMerge(whiteListedState.user, { devices: [] });
17 whiteListedState.shares = objectMap(whiteListedState.shares, (_, share) => ({
23 /** Filter stale request metadata and optimisticIds */
24 whiteListedState.items.byOptimisticId = {};
25 whiteListedState.request = objectFilter(
26 whiteListedState.request,
27 (_, request) => request.status === 'success' && request.maxAge !== undefined
30 return whiteListedState;