@tanstack/react-query-persist-client 4.0.0 → 4.0.5
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/build/stats-html.html +1 -1
- package/build/stats.json +217 -0
- package/build/types/packages/query-core/src/focusManager.d.ts +16 -0
- package/build/types/packages/query-core/src/hydration.d.ts +34 -0
- package/build/types/packages/query-core/src/index.d.ts +20 -0
- package/build/types/packages/query-core/src/infiniteQueryBehavior.d.ts +15 -0
- package/build/types/packages/query-core/src/infiniteQueryObserver.d.ts +18 -0
- package/build/types/packages/query-core/src/logger.d.ts +8 -0
- package/build/types/packages/query-core/src/mutation.d.ts +70 -0
- package/build/types/packages/query-core/src/mutationCache.d.ts +52 -0
- package/build/types/packages/query-core/src/mutationObserver.d.ts +23 -0
- package/build/types/packages/query-core/src/notifyManager.d.ts +18 -0
- package/build/types/packages/query-core/src/onlineManager.d.ts +16 -0
- package/build/types/packages/query-core/src/queriesObserver.d.ts +23 -0
- package/build/types/packages/query-core/src/query.d.ts +119 -0
- package/build/types/packages/query-core/src/queryCache.d.ts +59 -0
- package/build/types/packages/query-core/src/queryClient.d.ts +65 -0
- package/build/types/packages/query-core/src/queryObserver.d.ts +61 -0
- package/build/types/packages/query-core/src/removable.d.ts +9 -0
- package/build/types/packages/query-core/src/retryer.d.ts +33 -0
- package/build/types/packages/query-core/src/subscribable.d.ts +10 -0
- package/build/types/packages/query-core/src/types.d.ts +417 -0
- package/build/types/packages/query-core/src/utils.d.ts +99 -0
- package/build/types/packages/react-query/src/Hydrate.d.ts +10 -0
- package/build/types/packages/react-query/src/QueryClientProvider.d.ts +24 -0
- package/build/types/packages/react-query/src/QueryErrorResetBoundary.d.ts +12 -0
- package/build/types/packages/react-query/src/index.d.ts +17 -0
- package/build/types/packages/react-query/src/isRestoring.d.ts +3 -0
- package/build/types/packages/react-query/src/reactBatchedUpdates.d.ts +2 -0
- package/build/types/packages/react-query/src/setBatchUpdatesFn.d.ts +1 -0
- package/build/types/packages/react-query/src/types.d.ts +35 -0
- package/build/types/packages/react-query/src/useBaseQuery.d.ts +3 -0
- package/build/types/packages/react-query/src/useInfiniteQuery.d.ts +5 -0
- package/build/types/packages/react-query/src/useIsFetching.d.ts +7 -0
- package/build/types/packages/react-query/src/useIsMutating.d.ts +7 -0
- package/build/types/packages/react-query/src/useMutation.d.ts +6 -0
- package/build/types/packages/react-query/src/useQueries.d.ts +49 -0
- package/build/types/packages/react-query/src/useQuery.d.ts +20 -0
- package/build/types/packages/react-query/src/utils.d.ts +1 -0
- package/build/types/packages/react-query-persist-client/src/PersistQueryClientProvider.d.ts +8 -0
- package/build/types/packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.d.ts +1 -0
- package/build/types/packages/react-query-persist-client/src/__tests__/persist.test.d.ts +1 -0
- package/build/types/packages/react-query-persist-client/src/index.d.ts +3 -0
- package/build/types/packages/react-query-persist-client/src/persist.d.ts +58 -0
- package/build/types/packages/react-query-persist-client/src/retryStrategies.d.ts +7 -0
- package/build/types/tests/utils.d.ts +24 -0
- package/build/umd/index.development.js +1 -1
- package/build/umd/index.production.js +1 -1
- package/package.json +3 -3
- package/build/cjs/PersistQueryClientProvider.js +0 -83
- package/build/cjs/PersistQueryClientProvider.js.map +0 -1
- package/build/cjs/index.js +0 -27
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/persist.js +0 -119
- package/build/cjs/persist.js.map +0 -1
- package/build/cjs/retryStrategies.js +0 -39
- package/build/cjs/retryStrategies.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MutationKey, MutationFilters } from '@tanstack/query-core';
|
|
2
|
+
import { ContextOptions } from './types';
|
|
3
|
+
interface Options extends ContextOptions {
|
|
4
|
+
}
|
|
5
|
+
export declare function useIsMutating(filters?: MutationFilters, options?: Options): number;
|
|
6
|
+
export declare function useIsMutating(mutationKey?: MutationKey, filters?: Omit<MutationFilters, 'mutationKey'>, options?: Options): number;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MutationFunction, MutationKey } from '@tanstack/query-core';
|
|
2
|
+
import { UseMutationOptions, UseMutationResult } from './types';
|
|
3
|
+
export declare function useMutation<TData = unknown, TError = unknown, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
4
|
+
export declare function useMutation<TData = unknown, TError = unknown, TVariables = void, TContext = unknown>(mutationFn: MutationFunction<TData, TVariables>, options?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationFn'>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
5
|
+
export declare function useMutation<TData = unknown, TError = unknown, TVariables = void, TContext = unknown>(mutationKey: MutationKey, options?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey'>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
6
|
+
export declare function useMutation<TData = unknown, TError = unknown, TVariables = void, TContext = unknown>(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, TVariables>, options?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey' | 'mutationFn'>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { QueryKey, QueryFunction } from '@tanstack/query-core';
|
|
2
|
+
import { UseQueryOptions, UseQueryResult } from './types';
|
|
3
|
+
declare type UseQueryOptionsForUseQueries<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>;
|
|
4
|
+
declare type MAXIMUM_DEPTH = 20;
|
|
5
|
+
declare type GetOptions<T> = T extends {
|
|
6
|
+
queryFnData: infer TQueryFnData;
|
|
7
|
+
error?: infer TError;
|
|
8
|
+
data: infer TData;
|
|
9
|
+
} ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData> : T extends {
|
|
10
|
+
queryFnData: infer TQueryFnData;
|
|
11
|
+
error?: infer TError;
|
|
12
|
+
} ? UseQueryOptionsForUseQueries<TQueryFnData, TError> : T extends {
|
|
13
|
+
data: infer TData;
|
|
14
|
+
error?: infer TError;
|
|
15
|
+
} ? UseQueryOptionsForUseQueries<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? UseQueryOptionsForUseQueries<TQueryFnData, TError> : T extends [infer TQueryFnData] ? UseQueryOptionsForUseQueries<TQueryFnData> : T extends {
|
|
16
|
+
queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>;
|
|
17
|
+
select: (data: any) => infer TData;
|
|
18
|
+
} ? UseQueryOptionsForUseQueries<TQueryFnData, unknown, TData, TQueryKey> : T extends {
|
|
19
|
+
queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>;
|
|
20
|
+
} ? UseQueryOptionsForUseQueries<TQueryFnData, unknown, TQueryFnData, TQueryKey> : UseQueryOptionsForUseQueries;
|
|
21
|
+
declare type GetResults<T> = T extends {
|
|
22
|
+
queryFnData: any;
|
|
23
|
+
error?: infer TError;
|
|
24
|
+
data: infer TData;
|
|
25
|
+
} ? UseQueryResult<TData, TError> : T extends {
|
|
26
|
+
queryFnData: infer TQueryFnData;
|
|
27
|
+
error?: infer TError;
|
|
28
|
+
} ? UseQueryResult<TQueryFnData, TError> : T extends {
|
|
29
|
+
data: infer TData;
|
|
30
|
+
error?: infer TError;
|
|
31
|
+
} ? UseQueryResult<TData, TError> : T extends [any, infer TError, infer TData] ? UseQueryResult<TData, TError> : T extends [infer TQueryFnData, infer TError] ? UseQueryResult<TQueryFnData, TError> : T extends [infer TQueryFnData] ? UseQueryResult<TQueryFnData> : T extends {
|
|
32
|
+
queryFn?: QueryFunction<unknown, any>;
|
|
33
|
+
select: (data: any) => infer TData;
|
|
34
|
+
} ? UseQueryResult<TData> : T extends {
|
|
35
|
+
queryFn?: QueryFunction<infer TQueryFnData, any>;
|
|
36
|
+
} ? UseQueryResult<TQueryFnData> : UseQueryResult;
|
|
37
|
+
/**
|
|
38
|
+
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
39
|
+
*/
|
|
40
|
+
export declare type QueriesOptions<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? UseQueryOptionsForUseQueries[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]> : unknown[] extends T ? T : T extends UseQueryOptionsForUseQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[] : UseQueryOptionsForUseQueries[];
|
|
41
|
+
/**
|
|
42
|
+
* QueriesResults reducer recursively maps type param to results
|
|
43
|
+
*/
|
|
44
|
+
export declare type QueriesResults<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? UseQueryResult[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends UseQueryOptionsForUseQueries<infer TQueryFnData, infer TError, infer TData, any>[] ? UseQueryResult<unknown extends TData ? TQueryFnData : TData, TError>[] : UseQueryResult[];
|
|
45
|
+
export declare function useQueries<T extends any[]>({ queries, context, }: {
|
|
46
|
+
queries: readonly [...QueriesOptions<T>];
|
|
47
|
+
context?: UseQueryOptions['context'];
|
|
48
|
+
}): QueriesResults<T>;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QueryFunction, QueryKey } from '@tanstack/query-core';
|
|
2
|
+
import { DefinedUseQueryResult, UseQueryOptions, UseQueryResult } from './types';
|
|
3
|
+
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'initialData'> & {
|
|
4
|
+
initialData?: () => undefined;
|
|
5
|
+
}): UseQueryResult<TData, TError>;
|
|
6
|
+
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'initialData'> & {
|
|
7
|
+
initialData: TQueryFnData | (() => TQueryFnData);
|
|
8
|
+
}): DefinedUseQueryResult<TData, TError>;
|
|
9
|
+
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, options?: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey' | 'initialData'> & {
|
|
10
|
+
initialData?: () => undefined;
|
|
11
|
+
}): UseQueryResult<TData, TError>;
|
|
12
|
+
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, options?: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey' | 'initialData'> & {
|
|
13
|
+
initialData: TQueryFnData | (() => TQueryFnData);
|
|
14
|
+
}): DefinedUseQueryResult<TData, TError>;
|
|
15
|
+
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, queryFn: QueryFunction<TQueryFnData, TQueryKey>, options?: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey' | 'queryFn' | 'initialData'> & {
|
|
16
|
+
initialData?: () => undefined;
|
|
17
|
+
}): UseQueryResult<TData, TError>;
|
|
18
|
+
export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, queryFn: QueryFunction<TQueryFnData, TQueryKey>, options?: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey' | 'queryFn' | 'initialData'> & {
|
|
19
|
+
initialData: TQueryFnData | (() => TQueryFnData);
|
|
20
|
+
}): DefinedUseQueryResult<TData, TError>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shouldThrowError<T extends (...args: any[]) => boolean>(_useErrorBoundary: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PersistQueryClientOptions } from './persist';
|
|
3
|
+
import { QueryClientProviderProps } from '@tanstack/react-query';
|
|
4
|
+
export declare type PersistQueryClientProviderProps = QueryClientProviderProps & {
|
|
5
|
+
persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>;
|
|
6
|
+
onSuccess?: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const PersistQueryClientProvider: ({ client, children, persistOptions, onSuccess, ...props }: PersistQueryClientProviderProps) => JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { QueryClient, DehydratedState, DehydrateOptions, HydrateOptions } from '@tanstack/query-core';
|
|
2
|
+
export declare type Promisable<T> = T | PromiseLike<T>;
|
|
3
|
+
export interface Persister {
|
|
4
|
+
persistClient(persistClient: PersistedClient): Promisable<void>;
|
|
5
|
+
restoreClient(): Promisable<PersistedClient | undefined>;
|
|
6
|
+
removeClient(): Promisable<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface PersistedClient {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
buster: string;
|
|
11
|
+
clientState: DehydratedState;
|
|
12
|
+
}
|
|
13
|
+
export interface PersistQueryClienRootOptions {
|
|
14
|
+
/** The QueryClient to persist */
|
|
15
|
+
queryClient: QueryClient;
|
|
16
|
+
/** The Persister interface for storing and restoring the cache
|
|
17
|
+
* to/from a persisted location */
|
|
18
|
+
persister: Persister;
|
|
19
|
+
/** A unique string that can be used to forcefully
|
|
20
|
+
* invalidate existing caches if they do not share the same buster string */
|
|
21
|
+
buster?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PersistedQueryClientRestoreOptions extends PersistQueryClienRootOptions {
|
|
24
|
+
/** The max-allowed age of the cache in milliseconds.
|
|
25
|
+
* If a persisted cache is found that is older than this
|
|
26
|
+
* time, it will be discarded */
|
|
27
|
+
maxAge?: number;
|
|
28
|
+
/** The options passed to the hydrate function */
|
|
29
|
+
hydrateOptions?: HydrateOptions;
|
|
30
|
+
}
|
|
31
|
+
export interface PersistedQueryClientSaveOptions extends PersistQueryClienRootOptions {
|
|
32
|
+
/** The options passed to the dehydrate function */
|
|
33
|
+
dehydrateOptions?: DehydrateOptions;
|
|
34
|
+
}
|
|
35
|
+
export interface PersistQueryClientOptions extends PersistedQueryClientRestoreOptions, PersistedQueryClientSaveOptions, PersistQueryClienRootOptions {
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Restores persisted data to the QueryCache
|
|
39
|
+
* - data obtained from persister.restoreClient
|
|
40
|
+
* - data is hydrated using hydrateOptions
|
|
41
|
+
* If data is expired, busted, empty, or throws, it runs persister.removeClient
|
|
42
|
+
*/
|
|
43
|
+
export declare function persistQueryClientRestore({ queryClient, persister, maxAge, buster, hydrateOptions, }: PersistedQueryClientRestoreOptions): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Persists data from the QueryCache
|
|
46
|
+
* - data dehydrated using dehydrateOptions
|
|
47
|
+
* - data is persisted using persister.persistClient
|
|
48
|
+
*/
|
|
49
|
+
export declare function persistQueryClientSave({ queryClient, persister, buster, dehydrateOptions, }: PersistedQueryClientSaveOptions): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to QueryCache and MutationCache updates (for persisting)
|
|
52
|
+
* @returns an unsubscribe function (to discontinue monitoring)
|
|
53
|
+
*/
|
|
54
|
+
export declare function persistQueryClientSubscribe(props: PersistedQueryClientSaveOptions): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Restores persisted data to QueryCache and persists further changes.
|
|
57
|
+
*/
|
|
58
|
+
export declare function persistQueryClient(props: PersistQueryClientOptions): [() => void, Promise<void>];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { MutationOptions, QueryClient, QueryClientConfig } from '@tanstack/query-core';
|
|
4
|
+
export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
|
|
5
|
+
export declare function mockVisibilityState(value: DocumentVisibilityState): jest.SpyInstance<DocumentVisibilityState, []>;
|
|
6
|
+
export declare function mockNavigatorOnLine(value: boolean): jest.SpyInstance<boolean, []>;
|
|
7
|
+
export declare const mockLogger: {
|
|
8
|
+
log: jest.Mock<any, any>;
|
|
9
|
+
warn: jest.Mock<any, any>;
|
|
10
|
+
error: jest.Mock<any, any>;
|
|
11
|
+
};
|
|
12
|
+
export declare function queryKey(): Array<string>;
|
|
13
|
+
export declare function sleep(timeout: number): Promise<void>;
|
|
14
|
+
export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
|
|
15
|
+
/**
|
|
16
|
+
* Assert the parameter is of a specific type.
|
|
17
|
+
*/
|
|
18
|
+
export declare const expectType: <T>(_: T) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Assert the parameter is not typed as `any`
|
|
21
|
+
*/
|
|
22
|
+
export declare const expectTypeNotAny: <T>(_: 0 extends 1 & T ? never : T) => void;
|
|
23
|
+
export declare const executeMutation: (queryClient: QueryClient, options: MutationOptions<any, any, any, any>) => Promise<unknown>;
|
|
24
|
+
export declare function setIsServer(isServer: boolean): () => void;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@tanstack/react-query')) :
|
|
13
13
|
typeof define === 'function' && define.amd ? define(['exports', 'react', '@tanstack/react-query'], factory) :
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React, global.
|
|
14
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React, global.ReactQuery));
|
|
15
15
|
})(this, (function (exports, React, reactQuery) { 'use strict';
|
|
16
16
|
|
|
17
17
|
function _interopNamespace(e) {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React,e.
|
|
11
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React,e.ReactQuery)}(this,(function(e,t,n){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var i=s(t);
|
|
12
12
|
/**
|
|
13
13
|
* query-core
|
|
14
14
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query-persist-client",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "TODO",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
12
12
|
},
|
|
13
13
|
"module": "build/esm/index.js",
|
|
14
|
-
"main": "build/cjs/index.js",
|
|
14
|
+
"main": "build/cjs/react-query-persist-client/src/index.js",
|
|
15
15
|
"browser": "build/umd/index.production.js",
|
|
16
16
|
"types": "build/types/packages/react-query-persist-client/src/index.d.ts",
|
|
17
17
|
"files": [
|
|
18
|
-
"build",
|
|
18
|
+
"build/*",
|
|
19
19
|
"src"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-query-persist-client
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
16
|
-
var React = require('react');
|
|
17
|
-
var persist = require('./persist.js');
|
|
18
|
-
var reactQuery = require('@tanstack/react-query');
|
|
19
|
-
|
|
20
|
-
function _interopNamespace(e) {
|
|
21
|
-
if (e && e.__esModule) return e;
|
|
22
|
-
var n = Object.create(null);
|
|
23
|
-
if (e) {
|
|
24
|
-
Object.keys(e).forEach(function (k) {
|
|
25
|
-
if (k !== 'default') {
|
|
26
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return e[k]; }
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
n["default"] = e;
|
|
35
|
-
return Object.freeze(n);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
39
|
-
|
|
40
|
-
const PersistQueryClientProvider = ({
|
|
41
|
-
client,
|
|
42
|
-
children,
|
|
43
|
-
persistOptions,
|
|
44
|
-
onSuccess,
|
|
45
|
-
...props
|
|
46
|
-
}) => {
|
|
47
|
-
const [isRestoring, setIsRestoring] = React__namespace.useState(true);
|
|
48
|
-
const refs = React__namespace.useRef({
|
|
49
|
-
persistOptions,
|
|
50
|
-
onSuccess
|
|
51
|
-
});
|
|
52
|
-
React__namespace.useEffect(() => {
|
|
53
|
-
refs.current = {
|
|
54
|
-
persistOptions,
|
|
55
|
-
onSuccess
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
React__namespace.useEffect(() => {
|
|
59
|
-
let isStale = false;
|
|
60
|
-
setIsRestoring(true);
|
|
61
|
-
const [unsubscribe, promise] = persist.persistQueryClient({ ...refs.current.persistOptions,
|
|
62
|
-
queryClient: client
|
|
63
|
-
});
|
|
64
|
-
promise.then(() => {
|
|
65
|
-
if (!isStale) {
|
|
66
|
-
refs.current.onSuccess == null ? void 0 : refs.current.onSuccess();
|
|
67
|
-
setIsRestoring(false);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return () => {
|
|
71
|
-
isStale = true;
|
|
72
|
-
unsubscribe();
|
|
73
|
-
};
|
|
74
|
-
}, [client]);
|
|
75
|
-
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
|
|
76
|
-
client: client
|
|
77
|
-
}, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
|
|
78
|
-
value: isRestoring
|
|
79
|
-
}, children));
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
exports.PersistQueryClientProvider = PersistQueryClientProvider;
|
|
83
|
-
//# sourceMappingURL=PersistQueryClientProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.js","sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { persistQueryClient, PersistQueryClientOptions } from './persist'\nimport { QueryClientProvider, QueryClientProviderProps, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","_extends","IsRestoringProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,MAAMA,0BAA0B,GAAG,CAAC;AACzCC,EAAAA,MADyC;AAEzCC,EAAAA,QAFyC;AAGzCC,EAAAA,cAHyC;AAIzCC,EAAAA,SAJyC;AAKzC,EAAGC,GAAAA,KAAAA;AALsC,CAAD,KAMU;AAClD,EAAM,MAAA,CAACC,WAAD,EAAcC,cAAd,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AAA,CAACc,8BAAD,EAAA;AAAqB,IAAA,KAAK,EAAEhB,WAAAA;AAA5B,GAA0CJ,EAAAA,QAA1C,CADF,CADF,CAAA;AAKD;;;;"}
|
package/build/cjs/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-query-persist-client
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var persist = require('./persist.js');
|
|
16
|
-
var PersistQueryClientProvider = require('./PersistQueryClientProvider.js');
|
|
17
|
-
var retryStrategies = require('./retryStrategies.js');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports.persistQueryClient = persist.persistQueryClient;
|
|
22
|
-
exports.persistQueryClientRestore = persist.persistQueryClientRestore;
|
|
23
|
-
exports.persistQueryClientSave = persist.persistQueryClientSave;
|
|
24
|
-
exports.persistQueryClientSubscribe = persist.persistQueryClientSubscribe;
|
|
25
|
-
exports.PersistQueryClientProvider = PersistQueryClientProvider.PersistQueryClientProvider;
|
|
26
|
-
exports.removeOldestQuery = retryStrategies.removeOldestQuery;
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/cjs/persist.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-query-persist-client
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var queryCore = require('@tanstack/query-core');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Restores persisted data to the QueryCache
|
|
19
|
-
* - data obtained from persister.restoreClient
|
|
20
|
-
* - data is hydrated using hydrateOptions
|
|
21
|
-
* If data is expired, busted, empty, or throws, it runs persister.removeClient
|
|
22
|
-
*/
|
|
23
|
-
async function persistQueryClientRestore({
|
|
24
|
-
queryClient,
|
|
25
|
-
persister,
|
|
26
|
-
maxAge = 1000 * 60 * 60 * 24,
|
|
27
|
-
buster = '',
|
|
28
|
-
hydrateOptions
|
|
29
|
-
}) {
|
|
30
|
-
try {
|
|
31
|
-
const persistedClient = await persister.restoreClient();
|
|
32
|
-
|
|
33
|
-
if (persistedClient) {
|
|
34
|
-
if (persistedClient.timestamp) {
|
|
35
|
-
const expired = Date.now() - persistedClient.timestamp > maxAge;
|
|
36
|
-
const busted = persistedClient.buster !== buster;
|
|
37
|
-
|
|
38
|
-
if (expired || busted) {
|
|
39
|
-
persister.removeClient();
|
|
40
|
-
} else {
|
|
41
|
-
queryCore.hydrate(queryClient, persistedClient.clientState, hydrateOptions);
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
persister.removeClient();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
} catch (err) {
|
|
48
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
49
|
-
queryClient.getLogger().error(err);
|
|
50
|
-
queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
persister.removeClient();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Persists data from the QueryCache
|
|
58
|
-
* - data dehydrated using dehydrateOptions
|
|
59
|
-
* - data is persisted using persister.persistClient
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
async function persistQueryClientSave({
|
|
63
|
-
queryClient,
|
|
64
|
-
persister,
|
|
65
|
-
buster = '',
|
|
66
|
-
dehydrateOptions
|
|
67
|
-
}) {
|
|
68
|
-
const persistClient = {
|
|
69
|
-
buster,
|
|
70
|
-
timestamp: Date.now(),
|
|
71
|
-
clientState: queryCore.dehydrate(queryClient, dehydrateOptions)
|
|
72
|
-
};
|
|
73
|
-
await persister.persistClient(persistClient);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Subscribe to QueryCache and MutationCache updates (for persisting)
|
|
77
|
-
* @returns an unsubscribe function (to discontinue monitoring)
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
function persistQueryClientSubscribe(props) {
|
|
81
|
-
const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(() => {
|
|
82
|
-
persistQueryClientSave(props);
|
|
83
|
-
});
|
|
84
|
-
const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(() => {
|
|
85
|
-
persistQueryClientSave(props);
|
|
86
|
-
});
|
|
87
|
-
return () => {
|
|
88
|
-
unsubscribeQueryCache();
|
|
89
|
-
unusbscribeMutationCache();
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Restores persisted data to QueryCache and persists further changes.
|
|
94
|
-
*/
|
|
95
|
-
|
|
96
|
-
function persistQueryClient(props) {
|
|
97
|
-
let hasUnsubscribed = false;
|
|
98
|
-
let persistQueryClientUnsubscribe;
|
|
99
|
-
|
|
100
|
-
const unsubscribe = () => {
|
|
101
|
-
hasUnsubscribed = true;
|
|
102
|
-
persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
|
|
103
|
-
}; // Attempt restore
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const restorePromise = persistQueryClientRestore(props).then(() => {
|
|
107
|
-
if (!hasUnsubscribed) {
|
|
108
|
-
// Subscribe to changes in the query cache to trigger the save
|
|
109
|
-
persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return [unsubscribe, restorePromise];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
exports.persistQueryClient = persistQueryClient;
|
|
116
|
-
exports.persistQueryClientRestore = persistQueryClientRestore;
|
|
117
|
-
exports.persistQueryClientSave = persistQueryClientSave;
|
|
118
|
-
exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
|
|
119
|
-
//# sourceMappingURL=persist.js.map
|
package/build/cjs/persist.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persist.js","sources":["../../src/persist.ts"],"sourcesContent":["import {\n QueryClient,\n dehydrate,\n DehydratedState,\n DehydrateOptions,\n HydrateOptions,\n hydrate,\n} from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient(persistClient: PersistedClient): Promisable<void>\n restoreClient(): Promisable<PersistedClient | undefined>\n removeClient(): Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClienRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions\n extends PersistQueryClienRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions\n extends PersistQueryClienRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClienRootOptions {}\n\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\nexport async function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions,\n}: PersistedQueryClientRestoreOptions) {\n try {\n const persistedClient = await persister.restoreClient()\n\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge\n const busted = persistedClient.buster !== buster\n if (expired || busted) {\n persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err)\n queryClient\n .getLogger()\n .warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'\n )\n }\n persister.removeClient()\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe(() => {\n persistQueryClientSave(props)\n })\n\n const unusbscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe(() => {\n persistQueryClientSave(props)\n })\n\n return () => {\n unsubscribeQueryCache()\n unusbscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n"],"names":["persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","hydrate","clientState","err","process","env","NODE_ENV","getLogger","error","warn","persistQueryClientSave","dehydrateOptions","persistClient","dehydrate","persistQueryClientSubscribe","props","unsubscribeQueryCache","getQueryCache","subscribe","unusbscribeMutationCache","getMutationCache","persistQueryClient","hasUnsubscribed","persistQueryClientUnsubscribe","unsubscribe","restorePromise","then"],"mappings":";;;;;;;;;;;;;;;;AAuDA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,yBAAf,CAAyC;AAC9CC,EAAAA,WAD8C;AAE9CC,EAAAA,SAF8C;AAG9CC,EAAAA,MAAM,GAAG,IAAA,GAAO,EAAP,GAAY,EAAZ,GAAiB,EAHoB;AAI9CC,EAAAA,MAAM,GAAG,EAJqC;AAK9CC,EAAAA,cAAAA;AAL8C,CAAzC,EAMgC;AACrC,EAAI,IAAA;AACF,IAAA,MAAMC,eAAe,GAAG,MAAMJ,SAAS,CAACK,aAAV,EAA9B,CAAA;;AAEA,IAAA,IAAID,eAAJ,EAAqB;AACnB,MAAIA,IAAAA,eAAe,CAACE,SAApB,EAA+B;AAC7B,QAAMC,MAAAA,OAAO,GAAGC,IAAI,CAACC,GAAL,KAAaL,eAAe,CAACE,SAA7B,GAAyCL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-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
const removeOldestQuery = ({
|
|
16
|
-
persistedClient
|
|
17
|
-
}) => {
|
|
18
|
-
const mutations = [...persistedClient.clientState.mutations];
|
|
19
|
-
const queries = [...persistedClient.clientState.queries];
|
|
20
|
-
const client = { ...persistedClient,
|
|
21
|
-
clientState: {
|
|
22
|
-
mutations,
|
|
23
|
-
queries
|
|
24
|
-
}
|
|
25
|
-
}; // sort queries by dataUpdatedAt (oldest first)
|
|
26
|
-
|
|
27
|
-
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query
|
|
28
|
-
|
|
29
|
-
if (sortedQueries.length > 0) {
|
|
30
|
-
const oldestData = sortedQueries.shift();
|
|
31
|
-
client.clientState.queries = queries.filter(q => q !== oldestData);
|
|
32
|
-
return client;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return undefined;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
exports.removeOldestQuery = removeOldestQuery;
|
|
39
|
-
//# sourceMappingURL=retryStrategies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retryStrategies.js","sources":["../../src/retryStrategies.ts"],"sourcesContent":["import { PersistedClient } from './persist'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter(q => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"names":["removeOldestQuery","persistedClient","mutations","clientState","queries","client","sortedQueries","sort","a","b","state","dataUpdatedAt","length","oldestData","shift","filter","q","undefined"],"mappings":";;;;;;;;;;;;;;AAQO,MAAMA,iBAAiC,GAAG,CAAC;AAAEC,EAAAA,eAAAA;AAAF,CAAD,KAAyB;AACxE,EAAMC,MAAAA,SAAS,GAAG,CAAC,GAAGD,eAAe,CAACE,WAAhB,CAA4BD,SAAhC,CAAlB,CAAA;AACA,EAAME,MAAAA,OAAO,GAAG,CAAC,GAAGH,eAAe,CAACE,WAAhB,CAA4BC,OAAhC,CAAhB,CAAA;AACA,EAAA,MAAMC,MAAuB,GAAG,EAC9B,GAAGJ,eAD2B;AAE9BE,IAAAA,WAAW,EAAE;AAAED,MAAAA,SAAF;AAAaE,MAAAA,OAAAA;AAAb,KAAA;AAFiB,GAAhC,CAHwE;;AASxE,EAAME,MAAAA,aAAa,GAAG,CAAC,GAAGF,OAAJ,CAAaG,CAAAA,IAAb,CACpB,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACE,KAAF,CAAQC,aAAR,GAAwBF,CAAC,CAACC,KAAF,CAAQC,aADtB,CAAtB,CATwE;;AAcxE,EAAA,IAAIL,aAAa,CAACM,MAAd,GAAuB,CAA3B,EAA8B;AAC5B,IAAA,MAAMC,UAAU,GAAGP,aAAa,CAACQ,KAAd,EAAnB,CAAA;AACAT,IAAAA,MAAM,CAACF,WAAP,CAAmBC,OAAnB,GAA6BA,OAAO,CAACW,MAAR,CAAeC,CAAC,IAAIA,CAAC,KAAKH,UAA1B,CAA7B,CAAA;AACA,IAAA,OAAOR,MAAP,CAAA;AACD,GAAA;;AAED,EAAA,OAAOY,SAAP,CAAA;AACD;;;;"}
|