@tanstack/query-persist-client-core 5.92.0 → 5.92.2
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/legacy/_tsup-dts-rollup.d.cts +246 -0
- package/build/legacy/_tsup-dts-rollup.d.ts +246 -0
- package/build/legacy/createPersister.cjs +25 -5
- package/build/legacy/createPersister.cjs.map +1 -1
- package/build/legacy/createPersister.d.cts +6 -87
- package/build/legacy/createPersister.d.ts +6 -87
- package/build/legacy/createPersister.js +25 -5
- package/build/legacy/createPersister.js.map +1 -1
- package/build/legacy/index.d.cts +19 -4
- package/build/legacy/index.d.ts +19 -4
- package/build/legacy/persist.d.cts +11 -61
- package/build/legacy/persist.d.ts +11 -61
- package/build/legacy/retryStrategies.d.cts +2 -11
- package/build/legacy/retryStrategies.d.ts +2 -11
- package/build/modern/_tsup-dts-rollup.d.cts +246 -0
- package/build/modern/_tsup-dts-rollup.d.ts +246 -0
- package/build/modern/createPersister.cjs +25 -5
- package/build/modern/createPersister.cjs.map +1 -1
- package/build/modern/createPersister.d.cts +6 -87
- package/build/modern/createPersister.d.ts +6 -87
- package/build/modern/createPersister.js +25 -5
- package/build/modern/createPersister.js.map +1 -1
- package/build/modern/index.d.cts +19 -4
- package/build/modern/index.d.ts +19 -4
- package/build/modern/persist.d.cts +11 -61
- package/build/modern/persist.d.ts +11 -61
- package/build/modern/retryStrategies.d.cts +2 -11
- package/build/modern/retryStrategies.d.ts +2 -11
- package/package.json +5 -6
- package/src/createPersister.ts +25 -7
|
@@ -1,87 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
state: QueryState;
|
|
8
|
-
}
|
|
9
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
10
|
-
interface AsyncStorage<TStorageValue = string> {
|
|
11
|
-
getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>;
|
|
12
|
-
setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>;
|
|
13
|
-
removeItem: (key: string) => MaybePromise<void>;
|
|
14
|
-
entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>;
|
|
15
|
-
}
|
|
16
|
-
interface StoragePersisterOptions<TStorageValue = string> {
|
|
17
|
-
/** The storage client used for setting and retrieving items from cache.
|
|
18
|
-
* For SSR pass in `undefined`.
|
|
19
|
-
*/
|
|
20
|
-
storage: AsyncStorage<TStorageValue> | undefined | null;
|
|
21
|
-
/**
|
|
22
|
-
* How to serialize the data to storage.
|
|
23
|
-
* @default `JSON.stringify`
|
|
24
|
-
*/
|
|
25
|
-
serialize?: (persistedQuery: PersistedQuery) => MaybePromise<TStorageValue>;
|
|
26
|
-
/**
|
|
27
|
-
* How to deserialize the data from storage.
|
|
28
|
-
* @default `JSON.parse`
|
|
29
|
-
*/
|
|
30
|
-
deserialize?: (cachedString: TStorageValue) => MaybePromise<PersistedQuery>;
|
|
31
|
-
/**
|
|
32
|
-
* A unique string that can be used to forcefully invalidate existing caches,
|
|
33
|
-
* if they do not share the same buster string
|
|
34
|
-
*/
|
|
35
|
-
buster?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The max-allowed age of the cache in milliseconds.
|
|
38
|
-
* If a persisted cache is found that is older than this
|
|
39
|
-
* time, it will be discarded
|
|
40
|
-
* @default 24 hours
|
|
41
|
-
*/
|
|
42
|
-
maxAge?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Prefix to be used for storage key.
|
|
45
|
-
* Storage key is a combination of prefix and query hash in a form of `prefix-queryHash`.
|
|
46
|
-
* @default 'tanstack-query'
|
|
47
|
-
*/
|
|
48
|
-
prefix?: string;
|
|
49
|
-
/**
|
|
50
|
-
* If set to `true`, the query will refetch on successful query restoration if the data is stale.
|
|
51
|
-
* If set to `false`, the query will not refetch on successful query restoration.
|
|
52
|
-
* If set to `'always'`, the query will always refetch on successful query restoration.
|
|
53
|
-
* Defaults to `true`.
|
|
54
|
-
*/
|
|
55
|
-
refetchOnRestore?: boolean | 'always';
|
|
56
|
-
/**
|
|
57
|
-
* Filters to narrow down which Queries should be persisted.
|
|
58
|
-
*/
|
|
59
|
-
filters?: QueryFilters;
|
|
60
|
-
}
|
|
61
|
-
declare const PERSISTER_KEY_PREFIX = "tanstack-query";
|
|
62
|
-
/**
|
|
63
|
-
* Warning: experimental feature.
|
|
64
|
-
* This utility function enables fine-grained query persistence.
|
|
65
|
-
* Simple add it as a `persister` parameter to `useQuery` or `defaultOptions` on `queryClient`.
|
|
66
|
-
*
|
|
67
|
-
* ```
|
|
68
|
-
* useQuery({
|
|
69
|
-
queryKey: ['myKey'],
|
|
70
|
-
queryFn: fetcher,
|
|
71
|
-
persister: createPersister({
|
|
72
|
-
storage: localStorage,
|
|
73
|
-
}),
|
|
74
|
-
})
|
|
75
|
-
```
|
|
76
|
-
*/
|
|
77
|
-
declare function experimental_createQueryPersister<TStorageValue = string>({ storage, buster, maxAge, serialize, deserialize, prefix, refetchOnRestore, filters, }: StoragePersisterOptions<TStorageValue>): {
|
|
78
|
-
persisterFn: <T, TQueryKey extends QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>, ctx: QueryFunctionContext<TQueryKey>, query: Query) => Promise<T>;
|
|
79
|
-
persistQuery: (query: Query) => Promise<void>;
|
|
80
|
-
persistQueryByKey: (queryKey: QueryKey, queryClient: QueryClient) => Promise<void>;
|
|
81
|
-
retrieveQuery: <T>(queryHash: string, afterRestoreMacroTask?: (persistedQuery: PersistedQuery) => void) => Promise<T | undefined>;
|
|
82
|
-
persisterGc: () => Promise<void>;
|
|
83
|
-
restoreQueries: (queryClient: QueryClient, filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
|
|
84
|
-
removeQueries: (filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export { type AsyncStorage, type MaybePromise, PERSISTER_KEY_PREFIX, type PersistedQuery, type StoragePersisterOptions, experimental_createQueryPersister };
|
|
1
|
+
export { experimental_createQueryPersister } from './_tsup-dts-rollup.cjs';
|
|
2
|
+
export { PersistedQuery } from './_tsup-dts-rollup.cjs';
|
|
3
|
+
export { MaybePromise } from './_tsup-dts-rollup.cjs';
|
|
4
|
+
export { AsyncStorage } from './_tsup-dts-rollup.cjs';
|
|
5
|
+
export { StoragePersisterOptions } from './_tsup-dts-rollup.cjs';
|
|
6
|
+
export { PERSISTER_KEY_PREFIX } from './_tsup-dts-rollup.cjs';
|
|
@@ -1,87 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
state: QueryState;
|
|
8
|
-
}
|
|
9
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
10
|
-
interface AsyncStorage<TStorageValue = string> {
|
|
11
|
-
getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>;
|
|
12
|
-
setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>;
|
|
13
|
-
removeItem: (key: string) => MaybePromise<void>;
|
|
14
|
-
entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>;
|
|
15
|
-
}
|
|
16
|
-
interface StoragePersisterOptions<TStorageValue = string> {
|
|
17
|
-
/** The storage client used for setting and retrieving items from cache.
|
|
18
|
-
* For SSR pass in `undefined`.
|
|
19
|
-
*/
|
|
20
|
-
storage: AsyncStorage<TStorageValue> | undefined | null;
|
|
21
|
-
/**
|
|
22
|
-
* How to serialize the data to storage.
|
|
23
|
-
* @default `JSON.stringify`
|
|
24
|
-
*/
|
|
25
|
-
serialize?: (persistedQuery: PersistedQuery) => MaybePromise<TStorageValue>;
|
|
26
|
-
/**
|
|
27
|
-
* How to deserialize the data from storage.
|
|
28
|
-
* @default `JSON.parse`
|
|
29
|
-
*/
|
|
30
|
-
deserialize?: (cachedString: TStorageValue) => MaybePromise<PersistedQuery>;
|
|
31
|
-
/**
|
|
32
|
-
* A unique string that can be used to forcefully invalidate existing caches,
|
|
33
|
-
* if they do not share the same buster string
|
|
34
|
-
*/
|
|
35
|
-
buster?: string;
|
|
36
|
-
/**
|
|
37
|
-
* The max-allowed age of the cache in milliseconds.
|
|
38
|
-
* If a persisted cache is found that is older than this
|
|
39
|
-
* time, it will be discarded
|
|
40
|
-
* @default 24 hours
|
|
41
|
-
*/
|
|
42
|
-
maxAge?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Prefix to be used for storage key.
|
|
45
|
-
* Storage key is a combination of prefix and query hash in a form of `prefix-queryHash`.
|
|
46
|
-
* @default 'tanstack-query'
|
|
47
|
-
*/
|
|
48
|
-
prefix?: string;
|
|
49
|
-
/**
|
|
50
|
-
* If set to `true`, the query will refetch on successful query restoration if the data is stale.
|
|
51
|
-
* If set to `false`, the query will not refetch on successful query restoration.
|
|
52
|
-
* If set to `'always'`, the query will always refetch on successful query restoration.
|
|
53
|
-
* Defaults to `true`.
|
|
54
|
-
*/
|
|
55
|
-
refetchOnRestore?: boolean | 'always';
|
|
56
|
-
/**
|
|
57
|
-
* Filters to narrow down which Queries should be persisted.
|
|
58
|
-
*/
|
|
59
|
-
filters?: QueryFilters;
|
|
60
|
-
}
|
|
61
|
-
declare const PERSISTER_KEY_PREFIX = "tanstack-query";
|
|
62
|
-
/**
|
|
63
|
-
* Warning: experimental feature.
|
|
64
|
-
* This utility function enables fine-grained query persistence.
|
|
65
|
-
* Simple add it as a `persister` parameter to `useQuery` or `defaultOptions` on `queryClient`.
|
|
66
|
-
*
|
|
67
|
-
* ```
|
|
68
|
-
* useQuery({
|
|
69
|
-
queryKey: ['myKey'],
|
|
70
|
-
queryFn: fetcher,
|
|
71
|
-
persister: createPersister({
|
|
72
|
-
storage: localStorage,
|
|
73
|
-
}),
|
|
74
|
-
})
|
|
75
|
-
```
|
|
76
|
-
*/
|
|
77
|
-
declare function experimental_createQueryPersister<TStorageValue = string>({ storage, buster, maxAge, serialize, deserialize, prefix, refetchOnRestore, filters, }: StoragePersisterOptions<TStorageValue>): {
|
|
78
|
-
persisterFn: <T, TQueryKey extends QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>, ctx: QueryFunctionContext<TQueryKey>, query: Query) => Promise<T>;
|
|
79
|
-
persistQuery: (query: Query) => Promise<void>;
|
|
80
|
-
persistQueryByKey: (queryKey: QueryKey, queryClient: QueryClient) => Promise<void>;
|
|
81
|
-
retrieveQuery: <T>(queryHash: string, afterRestoreMacroTask?: (persistedQuery: PersistedQuery) => void) => Promise<T | undefined>;
|
|
82
|
-
persisterGc: () => Promise<void>;
|
|
83
|
-
restoreQueries: (queryClient: QueryClient, filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
|
|
84
|
-
removeQueries: (filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export { type AsyncStorage, type MaybePromise, PERSISTER_KEY_PREFIX, type PersistedQuery, type StoragePersisterOptions, experimental_createQueryPersister };
|
|
1
|
+
export { experimental_createQueryPersister } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { PersistedQuery } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { MaybePromise } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { AsyncStorage } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { StoragePersisterOptions } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { PERSISTER_KEY_PREFIX } from './_tsup-dts-rollup.js';
|
|
@@ -34,7 +34,13 @@ function experimental_createQueryPersister({
|
|
|
34
34
|
try {
|
|
35
35
|
const storedData = await storage.getItem(storageKey);
|
|
36
36
|
if (storedData) {
|
|
37
|
-
|
|
37
|
+
let persistedQuery;
|
|
38
|
+
try {
|
|
39
|
+
persistedQuery = await deserialize(storedData);
|
|
40
|
+
} catch {
|
|
41
|
+
await storage.removeItem(storageKey);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
38
44
|
if (isExpiredOrBusted(persistedQuery)) {
|
|
39
45
|
await storage.removeItem(storageKey);
|
|
40
46
|
} else {
|
|
@@ -116,10 +122,17 @@ function experimental_createQueryPersister({
|
|
|
116
122
|
}
|
|
117
123
|
async function persisterGc() {
|
|
118
124
|
if (storage?.entries) {
|
|
125
|
+
const storageKeyPrefix = `${prefix}-`;
|
|
119
126
|
const entries = await storage.entries();
|
|
120
127
|
for (const [key, value] of entries) {
|
|
121
|
-
if (key.startsWith(
|
|
122
|
-
|
|
128
|
+
if (key.startsWith(storageKeyPrefix)) {
|
|
129
|
+
let persistedQuery;
|
|
130
|
+
try {
|
|
131
|
+
persistedQuery = await deserialize(value);
|
|
132
|
+
} catch {
|
|
133
|
+
await storage.removeItem(key);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
123
136
|
if (isExpiredOrBusted(persistedQuery)) {
|
|
124
137
|
await storage.removeItem(key);
|
|
125
138
|
}
|
|
@@ -134,10 +147,17 @@ function experimental_createQueryPersister({
|
|
|
134
147
|
async function restoreQueries(queryClient, filters2 = {}) {
|
|
135
148
|
const { exact, queryKey } = filters2;
|
|
136
149
|
if (storage?.entries) {
|
|
150
|
+
const storageKeyPrefix = `${prefix}-`;
|
|
137
151
|
const entries = await storage.entries();
|
|
138
152
|
for (const [key, value] of entries) {
|
|
139
|
-
if (key.startsWith(
|
|
140
|
-
|
|
153
|
+
if (key.startsWith(storageKeyPrefix)) {
|
|
154
|
+
let persistedQuery;
|
|
155
|
+
try {
|
|
156
|
+
persistedQuery = await deserialize(value);
|
|
157
|
+
} catch {
|
|
158
|
+
await storage.removeItem(key);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
141
161
|
if (isExpiredOrBusted(persistedQuery)) {
|
|
142
162
|
await storage.removeItem(key);
|
|
143
163
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/createPersister.ts"],"sourcesContent":["import {\n hashKey,\n matchQuery,\n notifyManager,\n partialMatchKey,\n} from '@tanstack/query-core'\nimport type {\n Query,\n QueryClient,\n QueryFilters,\n QueryFunctionContext,\n QueryKey,\n QueryState,\n} from '@tanstack/query-core'\n\nexport interface PersistedQuery {\n buster: string\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport type MaybePromise<T> = T | Promise<T>\n\nexport interface AsyncStorage<TStorageValue = string> {\n getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>\n setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>\n removeItem: (key: string) => MaybePromise<void>\n entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>\n}\n\nexport interface StoragePersisterOptions<TStorageValue = string> {\n /** The storage client used for setting and retrieving items from cache.\n * For SSR pass in `undefined`.\n */\n storage: AsyncStorage<TStorageValue> | undefined | null\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (persistedQuery: PersistedQuery) => MaybePromise<TStorageValue>\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: TStorageValue) => MaybePromise<PersistedQuery>\n /**\n * A unique string that can be used to forcefully invalidate existing caches,\n * if they do not share the same buster string\n */\n buster?: string\n /**\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 * @default 24 hours\n */\n maxAge?: number\n /**\n * Prefix to be used for storage key.\n * Storage key is a combination of prefix and query hash in a form of `prefix-queryHash`.\n * @default 'tanstack-query'\n */\n prefix?: string\n /**\n * If set to `true`, the query will refetch on successful query restoration if the data is stale.\n * If set to `false`, the query will not refetch on successful query restoration.\n * If set to `'always'`, the query will always refetch on successful query restoration.\n * Defaults to `true`.\n */\n refetchOnRestore?: boolean | 'always'\n /**\n * Filters to narrow down which Queries should be persisted.\n */\n filters?: QueryFilters\n}\n\nexport const PERSISTER_KEY_PREFIX = 'tanstack-query'\n\n/**\n * Warning: experimental feature.\n * This utility function enables fine-grained query persistence.\n * Simple add it as a `persister` parameter to `useQuery` or `defaultOptions` on `queryClient`.\n *\n * ```\n * useQuery({\n queryKey: ['myKey'],\n queryFn: fetcher,\n persister: createPersister({\n storage: localStorage,\n }),\n })\n ```\n */\nexport function experimental_createQueryPersister<TStorageValue = string>({\n storage,\n buster = '',\n maxAge = 1000 * 60 * 60 * 24,\n serialize = JSON.stringify as Required<\n StoragePersisterOptions<TStorageValue>\n >['serialize'],\n deserialize = JSON.parse as Required<\n StoragePersisterOptions<TStorageValue>\n >['deserialize'],\n prefix = PERSISTER_KEY_PREFIX,\n refetchOnRestore = true,\n filters,\n}: StoragePersisterOptions<TStorageValue>) {\n function isExpiredOrBusted(persistedQuery: PersistedQuery) {\n if (persistedQuery.state.dataUpdatedAt) {\n const queryAge = Date.now() - persistedQuery.state.dataUpdatedAt\n const expired = queryAge > maxAge\n const busted = persistedQuery.buster !== buster\n\n if (expired || busted) {\n return true\n }\n\n return false\n }\n\n return true\n }\n\n async function retrieveQuery<T>(\n queryHash: string,\n afterRestoreMacroTask?: (persistedQuery: PersistedQuery) => void,\n ) {\n if (storage != null) {\n const storageKey = `${prefix}-${queryHash}`\n try {\n const storedData = await storage.getItem(storageKey)\n if (storedData) {\n const persistedQuery = await deserialize(storedData)\n\n if (isExpiredOrBusted(persistedQuery)) {\n await storage.removeItem(storageKey)\n } else {\n if (afterRestoreMacroTask) {\n // Just after restoring we want to get fresh data from the server if it's stale\n notifyManager.schedule(() =>\n afterRestoreMacroTask(persistedQuery),\n )\n }\n // We must resolve the promise here, as otherwise we will have `loading` state in the app until `queryFn` resolves\n return persistedQuery.state.data as T\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV === 'development') {\n console.error(err)\n console.warn(\n 'Encountered an error attempting to restore query cache from persisted location.',\n )\n }\n await storage.removeItem(storageKey)\n }\n }\n\n return\n }\n\n async function persistQueryByKey(\n queryKey: QueryKey,\n queryClient: QueryClient,\n ) {\n if (storage != null) {\n const query = queryClient.getQueryCache().find({ queryKey })\n if (query) {\n await persistQuery(query)\n } else {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n 'Could not find query to be persisted. QueryKey:',\n JSON.stringify(queryKey),\n )\n }\n }\n }\n }\n\n async function persistQuery(query: Query) {\n if (storage != null) {\n const storageKey = `${prefix}-${query.queryHash}`\n storage.setItem(\n storageKey,\n await serialize({\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n buster: buster,\n }),\n )\n }\n }\n\n async function persisterFn<T, TQueryKey extends QueryKey>(\n queryFn: (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>,\n ctx: QueryFunctionContext<TQueryKey>,\n query: Query,\n ) {\n const matchesFilter = filters ? matchQuery(filters, query) : true\n\n // Try to restore only if we do not have any data in the cache and we have persister defined\n if (matchesFilter && query.state.data === undefined && storage != null) {\n const restoredData = await retrieveQuery(\n query.queryHash,\n (persistedQuery: PersistedQuery) => {\n // Set proper updatedAt, since resolving in the first pass overrides those values\n query.setState({\n dataUpdatedAt: persistedQuery.state.dataUpdatedAt,\n errorUpdatedAt: persistedQuery.state.errorUpdatedAt,\n })\n\n if (\n refetchOnRestore === 'always' ||\n (refetchOnRestore === true && query.isStale())\n ) {\n query.fetch()\n }\n },\n )\n\n if (restoredData !== undefined) {\n return Promise.resolve(restoredData as T)\n }\n }\n\n // If we did not restore, or restoration failed - fetch\n const queryFnResult = await queryFn(ctx)\n\n if (matchesFilter && storage != null) {\n // Persist if we have storage defined, we use timeout to get proper state to be persisted\n notifyManager.schedule(() => {\n persistQuery(query)\n })\n }\n\n return Promise.resolve(queryFnResult)\n }\n\n async function persisterGc() {\n if (storage?.entries) {\n const entries = await storage.entries()\n for (const [key, value] of entries) {\n if (key.startsWith(prefix)) {\n const persistedQuery = await deserialize(value)\n\n if (isExpiredOrBusted(persistedQuery)) {\n await storage.removeItem(key)\n }\n }\n }\n } else if (process.env.NODE_ENV === 'development') {\n throw new Error(\n 'Provided storage does not implement `entries` method. Garbage collection is not possible without ability to iterate over storage items.',\n )\n }\n }\n\n async function restoreQueries(\n queryClient: QueryClient,\n filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},\n ): Promise<void> {\n const { exact, queryKey } = filters\n\n if (storage?.entries) {\n const entries = await storage.entries()\n for (const [key, value] of entries) {\n if (key.startsWith(prefix)) {\n const persistedQuery = await deserialize(value)\n\n if (isExpiredOrBusted(persistedQuery)) {\n await storage.removeItem(key)\n continue\n }\n\n if (queryKey) {\n if (exact) {\n if (persistedQuery.queryHash !== hashKey(queryKey)) {\n continue\n }\n } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) {\n continue\n }\n }\n\n queryClient.setQueryData(\n persistedQuery.queryKey,\n persistedQuery.state.data,\n {\n updatedAt: persistedQuery.state.dataUpdatedAt,\n },\n )\n }\n }\n } else if (process.env.NODE_ENV === 'development') {\n throw new Error(\n 'Provided storage does not implement `entries` method. Restoration of all stored entries is not possible without ability to iterate over storage items.',\n )\n }\n }\n\n async function removeQueries(\n filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},\n ): Promise<void> {\n const { exact, queryKey } = filters\n\n if (storage?.entries) {\n const entries = await storage.entries()\n const storageKeyPrefix = `${prefix}-`\n for (const [key, value] of entries) {\n if (key.startsWith(storageKeyPrefix)) {\n if (!queryKey) {\n await storage.removeItem(key)\n continue\n }\n\n let persistedQuery: PersistedQuery\n try {\n persistedQuery = await deserialize(value)\n } catch {\n await storage.removeItem(key)\n continue\n }\n\n if (exact) {\n if (persistedQuery.queryHash !== hashKey(queryKey)) {\n continue\n }\n } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) {\n continue\n }\n\n await storage.removeItem(key)\n }\n }\n } else if (process.env.NODE_ENV === 'development') {\n throw new Error(\n 'Provided storage does not implement `entries` method. Removal of stored entries is not possible without ability to iterate over storage items.',\n )\n }\n }\n\n return {\n persisterFn,\n persistQuery,\n persistQueryByKey,\n retrieveQuery,\n persisterGc,\n restoreQueries,\n removeQueries,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwEA,IAAM,u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AM,QAAQ,QAAQ;AACtC,YAAM,mBAAmB,GAAG,MAAM;AAClC,iBAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,YAAI,IAAI,WAAW,gBAAgB,GAAG;AACpC,cAAI,CAAC,UAAU;AACb,kBAAM,QAAQ,WAAW,GAAG;AAC5B;AAAA,UACF;AAEA,cAAI;AACJ,cAAI;AACF,6BAAiB,MAAM,YAAY,KAAK;AAAA,UAC1C,QAAQ;AACN,kBAAM,QAAQ,WAAW,GAAG;AAC5B;AAAA,UACF;AAEA,cAAI,OAAO;AACT,gBAAI,eAAe,cAAc,QAAQ,QAAQ,GAAG;AAClD;AAAA,YACF;AAAA,UACF,WAAW,CAAC,gBAAgB,eAAe,UAAU,QAAQ,GAAG;AAC9D;AAAA,UACF;AAEA,gBAAM,QAAQ,WAAW,GAAG;AAAA,QAC9B;AAAA,MACF;AAAA,IACF,WAAW,QAAQ,IAAI,aAAa,eAAe;AACjD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["filters"]}
|
|
1
|
+
{"version":3,"sources":["../../src/createPersister.ts"],"sourcesContent":["import {\n hashKey,\n matchQuery,\n notifyManager,\n partialMatchKey,\n} from '@tanstack/query-core'\nimport type {\n Query,\n QueryClient,\n QueryFilters,\n QueryFunctionContext,\n QueryKey,\n QueryState,\n} from '@tanstack/query-core'\n\nexport interface PersistedQuery {\n buster: string\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport type MaybePromise<T> = T | Promise<T>\n\nexport interface AsyncStorage<TStorageValue = string> {\n getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>\n setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>\n removeItem: (key: string) => MaybePromise<void>\n entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>\n}\n\nexport interface StoragePersisterOptions<TStorageValue = string> {\n /** The storage client used for setting and retrieving items from cache.\n * For SSR pass in `undefined`.\n */\n storage: AsyncStorage<TStorageValue> | undefined | null\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (persistedQuery: PersistedQuery) => MaybePromise<TStorageValue>\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: TStorageValue) => MaybePromise<PersistedQuery>\n /**\n * A unique string that can be used to forcefully invalidate existing caches,\n * if they do not share the same buster string\n */\n buster?: string\n /**\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 * @default 24 hours\n */\n maxAge?: number\n /**\n * Prefix to be used for storage key.\n * Storage key is a combination of prefix and query hash in a form of `prefix-queryHash`.\n * @default 'tanstack-query'\n */\n prefix?: string\n /**\n * If set to `true`, the query will refetch on successful query restoration if the data is stale.\n * If set to `false`, the query will not refetch on successful query restoration.\n * If set to `'always'`, the query will always refetch on successful query restoration.\n * Defaults to `true`.\n */\n refetchOnRestore?: boolean | 'always'\n /**\n * Filters to narrow down which Queries should be persisted.\n */\n filters?: QueryFilters\n}\n\nexport const PERSISTER_KEY_PREFIX = 'tanstack-query'\n\n/**\n * Warning: experimental feature.\n * This utility function enables fine-grained query persistence.\n * Simple add it as a `persister` parameter to `useQuery` or `defaultOptions` on `queryClient`.\n *\n * ```\n * useQuery({\n queryKey: ['myKey'],\n queryFn: fetcher,\n persister: createPersister({\n storage: localStorage,\n }),\n })\n ```\n */\nexport function experimental_createQueryPersister<TStorageValue = string>({\n storage,\n buster = '',\n maxAge = 1000 * 60 * 60 * 24,\n serialize = JSON.stringify as Required<\n StoragePersisterOptions<TStorageValue>\n >['serialize'],\n deserialize = JSON.parse as Required<\n StoragePersisterOptions<TStorageValue>\n >['deserialize'],\n prefix = PERSISTER_KEY_PREFIX,\n refetchOnRestore = true,\n filters,\n}: StoragePersisterOptions<TStorageValue>) {\n function isExpiredOrBusted(persistedQuery: PersistedQuery) {\n if (persistedQuery.state.dataUpdatedAt) {\n const queryAge = Date.now() - persistedQuery.state.dataUpdatedAt\n const expired = queryAge > maxAge\n const busted = persistedQuery.buster !== buster\n\n if (expired || busted) {\n return true\n }\n\n return false\n }\n\n return true\n }\n\n async function retrieveQuery<T>(\n queryHash: string,\n afterRestoreMacroTask?: (persistedQuery: PersistedQuery) => void,\n ) {\n if (storage != null) {\n const storageKey = `${prefix}-${queryHash}`\n try {\n const storedData = await storage.getItem(storageKey)\n if (storedData) {\n let persistedQuery: PersistedQuery\n try {\n persistedQuery = await deserialize(storedData)\n } catch {\n await storage.removeItem(storageKey)\n return\n }\n\n if (isExpiredOrBusted(persistedQuery)) {\n await storage.removeItem(storageKey)\n } else {\n if (afterRestoreMacroTask) {\n // Just after restoring we want to get fresh data from the server if it's stale\n notifyManager.schedule(() =>\n afterRestoreMacroTask(persistedQuery),\n )\n }\n // We must resolve the promise here, as otherwise we will have `loading` state in the app until `queryFn` resolves\n return persistedQuery.state.data as T\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV === 'development') {\n console.error(err)\n console.warn(\n 'Encountered an error attempting to restore query cache from persisted location.',\n )\n }\n await storage.removeItem(storageKey)\n }\n }\n\n return\n }\n\n async function persistQueryByKey(\n queryKey: QueryKey,\n queryClient: QueryClient,\n ) {\n if (storage != null) {\n const query = queryClient.getQueryCache().find({ queryKey })\n if (query) {\n await persistQuery(query)\n } else {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n 'Could not find query to be persisted. QueryKey:',\n JSON.stringify(queryKey),\n )\n }\n }\n }\n }\n\n async function persistQuery(query: Query) {\n if (storage != null) {\n const storageKey = `${prefix}-${query.queryHash}`\n storage.setItem(\n storageKey,\n await serialize({\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n buster: buster,\n }),\n )\n }\n }\n\n async function persisterFn<T, TQueryKey extends QueryKey>(\n queryFn: (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>,\n ctx: QueryFunctionContext<TQueryKey>,\n query: Query,\n ) {\n const matchesFilter = filters ? matchQuery(filters, query) : true\n\n // Try to restore only if we do not have any data in the cache and we have persister defined\n if (matchesFilter && query.state.data === undefined && storage != null) {\n const restoredData = await retrieveQuery(\n query.queryHash,\n (persistedQuery: PersistedQuery) => {\n // Set proper updatedAt, since resolving in the first pass overrides those values\n query.setState({\n dataUpdatedAt: persistedQuery.state.dataUpdatedAt,\n errorUpdatedAt: persistedQuery.state.errorUpdatedAt,\n })\n\n if (\n refetchOnRestore === 'always' ||\n (refetchOnRestore === true && query.isStale())\n ) {\n query.fetch()\n }\n },\n )\n\n if (restoredData !== undefined) {\n return Promise.resolve(restoredData as T)\n }\n }\n\n // If we did not restore, or restoration failed - fetch\n const queryFnResult = await queryFn(ctx)\n\n if (matchesFilter && storage != null) {\n // Persist if we have storage defined, we use timeout to get proper state to be persisted\n notifyManager.schedule(() => {\n persistQuery(query)\n })\n }\n\n return Promise.resolve(queryFnResult)\n }\n\n async function persisterGc() {\n if (storage?.entries) {\n const storageKeyPrefix = `${prefix}-`\n const entries = await storage.entries()\n for (const [key, value] of entries) {\n if (key.startsWith(storageKeyPrefix)) {\n let persistedQuery: PersistedQuery\n try {\n persistedQuery = await deserialize(value)\n } catch {\n await storage.removeItem(key)\n continue\n }\n if (isExpiredOrBusted(persistedQuery)) {\n await storage.removeItem(key)\n }\n }\n }\n } else if (process.env.NODE_ENV === 'development') {\n throw new Error(\n 'Provided storage does not implement `entries` method. Garbage collection is not possible without ability to iterate over storage items.',\n )\n }\n }\n\n async function restoreQueries(\n queryClient: QueryClient,\n filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},\n ): Promise<void> {\n const { exact, queryKey } = filters\n\n if (storage?.entries) {\n const storageKeyPrefix = `${prefix}-`\n const entries = await storage.entries()\n for (const [key, value] of entries) {\n if (key.startsWith(storageKeyPrefix)) {\n let persistedQuery: PersistedQuery\n try {\n persistedQuery = await deserialize(value)\n } catch {\n await storage.removeItem(key)\n continue\n }\n if (isExpiredOrBusted(persistedQuery)) {\n await storage.removeItem(key)\n continue\n }\n\n if (queryKey) {\n if (exact) {\n if (persistedQuery.queryHash !== hashKey(queryKey)) {\n continue\n }\n } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) {\n continue\n }\n }\n\n queryClient.setQueryData(\n persistedQuery.queryKey,\n persistedQuery.state.data,\n {\n updatedAt: persistedQuery.state.dataUpdatedAt,\n },\n )\n }\n }\n } else if (process.env.NODE_ENV === 'development') {\n throw new Error(\n 'Provided storage does not implement `entries` method. Restoration of all stored entries is not possible without ability to iterate over storage items.',\n )\n }\n }\n\n async function removeQueries(\n filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},\n ): Promise<void> {\n const { exact, queryKey } = filters\n\n if (storage?.entries) {\n const entries = await storage.entries()\n const storageKeyPrefix = `${prefix}-`\n for (const [key, value] of entries) {\n if (key.startsWith(storageKeyPrefix)) {\n if (!queryKey) {\n await storage.removeItem(key)\n continue\n }\n\n let persistedQuery: PersistedQuery\n try {\n persistedQuery = await deserialize(value)\n } catch {\n await storage.removeItem(key)\n continue\n }\n\n if (exact) {\n if (persistedQuery.queryHash !== hashKey(queryKey)) {\n continue\n }\n } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) {\n continue\n }\n\n await storage.removeItem(key)\n }\n }\n } else if (process.env.NODE_ENV === 'development') {\n throw new Error(\n 'Provided storage does not implement `entries` method. Removal of stored entries is not possible without ability to iterate over storage items.',\n )\n }\n }\n\n return {\n persisterFn,\n persistQuery,\n persistQueryByKey,\n retrieveQuery,\n persisterGc,\n restoreQueries,\n removeQueries,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwEA,IAAM,uBAAuB;AAiB7B,SAAS,kCAA0D;AAAA,EACxE;AAAA,EACA,SAAS;AAAA,EACT,SAAS,MAAO,KAAK,KAAK;AAAA,EAC1B,YAAY,KAAK;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AI,aAAa,eAAe;AACjD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,iBAAe,cACbA,WAAoD,CAAC,GACtC;AACf,UAAM,EAAE,OAAO,SAAS,IAAIA;AAE5B,QAAI,SAAS,SAAS;AACpB,YAAM,UAAU,MAAM,QAAQ,QAAQ;AACtC,YAAM,mBAAmB,GAAG,MAAM;AAClC,iBAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,YAAI,IAAI,WAAW,gBAAgB,GAAG;AACpC,cAAI,CAAC,UAAU;AACb,kBAAM,QAAQ,WAAW,GAAG;AAC5B;AAAA,UACF;AAEA,cAAI;AACJ,cAAI;AACF,6BAAiB,MAAM,YAAY,KAAK;AAAA,UAC1C,QAAQ;AACN,kBAAM,QAAQ,WAAW,GAAG;AAC5B;AAAA,UACF;AAEA,cAAI,OAAO;AACT,gBAAI,eAAe,cAAc,QAAQ,QAAQ,GAAG;AAClD;AAAA,YACF;AAAA,UACF,WAAW,CAAC,gBAAgB,eAAe,UAAU,QAAQ,GAAG;AAC9D;AAAA,UACF;AAEA,gBAAM,QAAQ,WAAW,GAAG;AAAA,QAC9B;AAAA,MACF;AAAA,IACF,WAAW,QAAQ,IAAI,aAAa,eAAe;AACjD,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["filters"]}
|
package/build/modern/index.d.cts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
|
|
1
|
+
export { persistQueryClientRestore } from './_tsup-dts-rollup.cjs';
|
|
2
|
+
export { persistQueryClientSave } from './_tsup-dts-rollup.cjs';
|
|
3
|
+
export { persistQueryClientSubscribe } from './_tsup-dts-rollup.cjs';
|
|
4
|
+
export { persistQueryClient } from './_tsup-dts-rollup.cjs';
|
|
5
|
+
export { Promisable } from './_tsup-dts-rollup.cjs';
|
|
6
|
+
export { Persister } from './_tsup-dts-rollup.cjs';
|
|
7
|
+
export { PersistedClient } from './_tsup-dts-rollup.cjs';
|
|
8
|
+
export { PersistQueryClientRootOptions } from './_tsup-dts-rollup.cjs';
|
|
9
|
+
export { PersistedQueryClientRestoreOptions } from './_tsup-dts-rollup.cjs';
|
|
10
|
+
export { PersistedQueryClientSaveOptions } from './_tsup-dts-rollup.cjs';
|
|
11
|
+
export { PersistQueryClientOptions } from './_tsup-dts-rollup.cjs';
|
|
12
|
+
export { PersistRetryer } from './_tsup-dts-rollup.cjs';
|
|
13
|
+
export { removeOldestQuery } from './_tsup-dts-rollup.cjs';
|
|
14
|
+
export { experimental_createQueryPersister_alias_1 as experimental_createQueryPersister } from './_tsup-dts-rollup.cjs';
|
|
15
|
+
export { PersistedQuery_alias_1 as PersistedQuery } from './_tsup-dts-rollup.cjs';
|
|
16
|
+
export { MaybePromise_alias_1 as MaybePromise } from './_tsup-dts-rollup.cjs';
|
|
17
|
+
export { AsyncStorage_alias_1 as AsyncStorage } from './_tsup-dts-rollup.cjs';
|
|
18
|
+
export { StoragePersisterOptions_alias_1 as StoragePersisterOptions } from './_tsup-dts-rollup.cjs';
|
|
19
|
+
export { PERSISTER_KEY_PREFIX_alias_1 as PERSISTER_KEY_PREFIX } from './_tsup-dts-rollup.cjs';
|
package/build/modern/index.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
|
|
1
|
+
export { persistQueryClientRestore } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { persistQueryClientSave } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { persistQueryClientSubscribe } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { persistQueryClient } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { Promisable } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { Persister } from './_tsup-dts-rollup.js';
|
|
7
|
+
export { PersistedClient } from './_tsup-dts-rollup.js';
|
|
8
|
+
export { PersistQueryClientRootOptions } from './_tsup-dts-rollup.js';
|
|
9
|
+
export { PersistedQueryClientRestoreOptions } from './_tsup-dts-rollup.js';
|
|
10
|
+
export { PersistedQueryClientSaveOptions } from './_tsup-dts-rollup.js';
|
|
11
|
+
export { PersistQueryClientOptions } from './_tsup-dts-rollup.js';
|
|
12
|
+
export { PersistRetryer } from './_tsup-dts-rollup.js';
|
|
13
|
+
export { removeOldestQuery } from './_tsup-dts-rollup.js';
|
|
14
|
+
export { experimental_createQueryPersister_alias_1 as experimental_createQueryPersister } from './_tsup-dts-rollup.js';
|
|
15
|
+
export { PersistedQuery_alias_1 as PersistedQuery } from './_tsup-dts-rollup.js';
|
|
16
|
+
export { MaybePromise_alias_1 as MaybePromise } from './_tsup-dts-rollup.js';
|
|
17
|
+
export { AsyncStorage_alias_1 as AsyncStorage } from './_tsup-dts-rollup.js';
|
|
18
|
+
export { StoragePersisterOptions_alias_1 as StoragePersisterOptions } from './_tsup-dts-rollup.js';
|
|
19
|
+
export { PERSISTER_KEY_PREFIX_alias_1 as PERSISTER_KEY_PREFIX } from './_tsup-dts-rollup.js';
|
|
@@ -1,61 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
clientState: DehydratedState;
|
|
13
|
-
}
|
|
14
|
-
interface PersistQueryClientRootOptions {
|
|
15
|
-
/** The QueryClient to persist */
|
|
16
|
-
queryClient: QueryClient;
|
|
17
|
-
/** The Persister interface for storing and restoring the cache
|
|
18
|
-
* to/from a persisted location */
|
|
19
|
-
persister: Persister;
|
|
20
|
-
/** A unique string that can be used to forcefully
|
|
21
|
-
* invalidate existing caches if they do not share the same buster string */
|
|
22
|
-
buster?: string;
|
|
23
|
-
}
|
|
24
|
-
interface PersistedQueryClientRestoreOptions extends PersistQueryClientRootOptions {
|
|
25
|
-
/** The max-allowed age of the cache in milliseconds.
|
|
26
|
-
* If a persisted cache is found that is older than this
|
|
27
|
-
* time, it will be discarded */
|
|
28
|
-
maxAge?: number;
|
|
29
|
-
/** The options passed to the hydrate function */
|
|
30
|
-
hydrateOptions?: HydrateOptions;
|
|
31
|
-
}
|
|
32
|
-
interface PersistedQueryClientSaveOptions extends PersistQueryClientRootOptions {
|
|
33
|
-
/** The options passed to the dehydrate function */
|
|
34
|
-
dehydrateOptions?: DehydrateOptions;
|
|
35
|
-
}
|
|
36
|
-
interface PersistQueryClientOptions extends PersistedQueryClientRestoreOptions, PersistedQueryClientSaveOptions, PersistQueryClientRootOptions {
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Restores persisted data to the QueryCache
|
|
40
|
-
* - data obtained from persister.restoreClient
|
|
41
|
-
* - data is hydrated using hydrateOptions
|
|
42
|
-
* If data is expired, busted, empty, or throws, it runs persister.removeClient
|
|
43
|
-
*/
|
|
44
|
-
declare function persistQueryClientRestore({ queryClient, persister, maxAge, buster, hydrateOptions, }: PersistedQueryClientRestoreOptions): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Persists data from the QueryCache
|
|
47
|
-
* - data dehydrated using dehydrateOptions
|
|
48
|
-
* - data is persisted using persister.persistClient
|
|
49
|
-
*/
|
|
50
|
-
declare function persistQueryClientSave({ queryClient, persister, buster, dehydrateOptions, }: PersistedQueryClientSaveOptions): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Subscribe to QueryCache and MutationCache updates (for persisting)
|
|
53
|
-
* @returns an unsubscribe function (to discontinue monitoring)
|
|
54
|
-
*/
|
|
55
|
-
declare function persistQueryClientSubscribe(props: PersistedQueryClientSaveOptions): () => void;
|
|
56
|
-
/**
|
|
57
|
-
* Restores persisted data to QueryCache and persists further changes.
|
|
58
|
-
*/
|
|
59
|
-
declare function persistQueryClient(props: PersistQueryClientOptions): [() => void, Promise<void>];
|
|
60
|
-
|
|
61
|
-
export { type PersistQueryClientOptions, type PersistQueryClientRootOptions, type PersistedClient, type PersistedQueryClientRestoreOptions, type PersistedQueryClientSaveOptions, type Persister, type Promisable, persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };
|
|
1
|
+
export { persistQueryClientRestore_alias_1 as persistQueryClientRestore } from './_tsup-dts-rollup.cjs';
|
|
2
|
+
export { persistQueryClientSave_alias_1 as persistQueryClientSave } from './_tsup-dts-rollup.cjs';
|
|
3
|
+
export { persistQueryClientSubscribe_alias_1 as persistQueryClientSubscribe } from './_tsup-dts-rollup.cjs';
|
|
4
|
+
export { persistQueryClient_alias_1 as persistQueryClient } from './_tsup-dts-rollup.cjs';
|
|
5
|
+
export { Promisable_alias_1 as Promisable } from './_tsup-dts-rollup.cjs';
|
|
6
|
+
export { Persister_alias_1 as Persister } from './_tsup-dts-rollup.cjs';
|
|
7
|
+
export { PersistedClient_alias_1 as PersistedClient } from './_tsup-dts-rollup.cjs';
|
|
8
|
+
export { PersistQueryClientRootOptions_alias_1 as PersistQueryClientRootOptions } from './_tsup-dts-rollup.cjs';
|
|
9
|
+
export { PersistedQueryClientRestoreOptions_alias_1 as PersistedQueryClientRestoreOptions } from './_tsup-dts-rollup.cjs';
|
|
10
|
+
export { PersistedQueryClientSaveOptions_alias_1 as PersistedQueryClientSaveOptions } from './_tsup-dts-rollup.cjs';
|
|
11
|
+
export { PersistQueryClientOptions_alias_1 as PersistQueryClientOptions } from './_tsup-dts-rollup.cjs';
|
|
@@ -1,61 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
clientState: DehydratedState;
|
|
13
|
-
}
|
|
14
|
-
interface PersistQueryClientRootOptions {
|
|
15
|
-
/** The QueryClient to persist */
|
|
16
|
-
queryClient: QueryClient;
|
|
17
|
-
/** The Persister interface for storing and restoring the cache
|
|
18
|
-
* to/from a persisted location */
|
|
19
|
-
persister: Persister;
|
|
20
|
-
/** A unique string that can be used to forcefully
|
|
21
|
-
* invalidate existing caches if they do not share the same buster string */
|
|
22
|
-
buster?: string;
|
|
23
|
-
}
|
|
24
|
-
interface PersistedQueryClientRestoreOptions extends PersistQueryClientRootOptions {
|
|
25
|
-
/** The max-allowed age of the cache in milliseconds.
|
|
26
|
-
* If a persisted cache is found that is older than this
|
|
27
|
-
* time, it will be discarded */
|
|
28
|
-
maxAge?: number;
|
|
29
|
-
/** The options passed to the hydrate function */
|
|
30
|
-
hydrateOptions?: HydrateOptions;
|
|
31
|
-
}
|
|
32
|
-
interface PersistedQueryClientSaveOptions extends PersistQueryClientRootOptions {
|
|
33
|
-
/** The options passed to the dehydrate function */
|
|
34
|
-
dehydrateOptions?: DehydrateOptions;
|
|
35
|
-
}
|
|
36
|
-
interface PersistQueryClientOptions extends PersistedQueryClientRestoreOptions, PersistedQueryClientSaveOptions, PersistQueryClientRootOptions {
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Restores persisted data to the QueryCache
|
|
40
|
-
* - data obtained from persister.restoreClient
|
|
41
|
-
* - data is hydrated using hydrateOptions
|
|
42
|
-
* If data is expired, busted, empty, or throws, it runs persister.removeClient
|
|
43
|
-
*/
|
|
44
|
-
declare function persistQueryClientRestore({ queryClient, persister, maxAge, buster, hydrateOptions, }: PersistedQueryClientRestoreOptions): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Persists data from the QueryCache
|
|
47
|
-
* - data dehydrated using dehydrateOptions
|
|
48
|
-
* - data is persisted using persister.persistClient
|
|
49
|
-
*/
|
|
50
|
-
declare function persistQueryClientSave({ queryClient, persister, buster, dehydrateOptions, }: PersistedQueryClientSaveOptions): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Subscribe to QueryCache and MutationCache updates (for persisting)
|
|
53
|
-
* @returns an unsubscribe function (to discontinue monitoring)
|
|
54
|
-
*/
|
|
55
|
-
declare function persistQueryClientSubscribe(props: PersistedQueryClientSaveOptions): () => void;
|
|
56
|
-
/**
|
|
57
|
-
* Restores persisted data to QueryCache and persists further changes.
|
|
58
|
-
*/
|
|
59
|
-
declare function persistQueryClient(props: PersistQueryClientOptions): [() => void, Promise<void>];
|
|
60
|
-
|
|
61
|
-
export { type PersistQueryClientOptions, type PersistQueryClientRootOptions, type PersistedClient, type PersistedQueryClientRestoreOptions, type PersistedQueryClientSaveOptions, type Persister, type Promisable, persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };
|
|
1
|
+
export { persistQueryClientRestore_alias_1 as persistQueryClientRestore } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { persistQueryClientSave_alias_1 as persistQueryClientSave } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { persistQueryClientSubscribe_alias_1 as persistQueryClientSubscribe } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { persistQueryClient_alias_1 as persistQueryClient } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { Promisable_alias_1 as Promisable } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { Persister_alias_1 as Persister } from './_tsup-dts-rollup.js';
|
|
7
|
+
export { PersistedClient_alias_1 as PersistedClient } from './_tsup-dts-rollup.js';
|
|
8
|
+
export { PersistQueryClientRootOptions_alias_1 as PersistQueryClientRootOptions } from './_tsup-dts-rollup.js';
|
|
9
|
+
export { PersistedQueryClientRestoreOptions_alias_1 as PersistedQueryClientRestoreOptions } from './_tsup-dts-rollup.js';
|
|
10
|
+
export { PersistedQueryClientSaveOptions_alias_1 as PersistedQueryClientSaveOptions } from './_tsup-dts-rollup.js';
|
|
11
|
+
export { PersistQueryClientOptions_alias_1 as PersistQueryClientOptions } from './_tsup-dts-rollup.js';
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type PersistRetryer = (props: {
|
|
5
|
-
persistedClient: PersistedClient;
|
|
6
|
-
error: Error;
|
|
7
|
-
errorCount: number;
|
|
8
|
-
}) => PersistedClient | undefined;
|
|
9
|
-
declare const removeOldestQuery: PersistRetryer;
|
|
10
|
-
|
|
11
|
-
export { type PersistRetryer, removeOldestQuery };
|
|
1
|
+
export { PersistRetryer_alias_1 as PersistRetryer } from './_tsup-dts-rollup.cjs';
|
|
2
|
+
export { removeOldestQuery_alias_1 as removeOldestQuery } from './_tsup-dts-rollup.cjs';
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type PersistRetryer = (props: {
|
|
5
|
-
persistedClient: PersistedClient;
|
|
6
|
-
error: Error;
|
|
7
|
-
errorCount: number;
|
|
8
|
-
}) => PersistedClient | undefined;
|
|
9
|
-
declare const removeOldestQuery: PersistRetryer;
|
|
10
|
-
|
|
11
|
-
export { type PersistRetryer, removeOldestQuery };
|
|
1
|
+
export { PersistRetryer_alias_1 as PersistRetryer } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { removeOldestQuery_alias_1 as removeOldestQuery } from './_tsup-dts-rollup.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-persist-client-core",
|
|
3
|
-
"version": "5.92.
|
|
3
|
+
"version": "5.92.2",
|
|
4
4
|
"description": "Set of utilities for interacting with persisters, which can save your queryClient for later use",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"!src/__tests__"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tanstack/query-core": "5.
|
|
43
|
+
"@tanstack/query-core": "5.91.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"npm-run-all2": "^5.0.0",
|
|
@@ -51,15 +51,14 @@
|
|
|
51
51
|
"compile": "tsc --build",
|
|
52
52
|
"test:eslint": "eslint --concurrency=auto ./src",
|
|
53
53
|
"test:types": "npm-run-all --serial test:types:*",
|
|
54
|
-
"test:types:ts50": "node ../../node_modules/typescript50/lib/tsc.js --build",
|
|
55
|
-
"test:types:ts51": "node ../../node_modules/typescript51/lib/tsc.js --build",
|
|
56
|
-
"test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js --build",
|
|
57
|
-
"test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build",
|
|
58
54
|
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build",
|
|
59
55
|
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build",
|
|
60
56
|
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build",
|
|
61
57
|
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build",
|
|
58
|
+
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --build",
|
|
59
|
+
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --build",
|
|
62
60
|
"test:types:tscurrent": "tsc --build",
|
|
61
|
+
"test:types:ts60": "node ../../node_modules/typescript60/lib/tsc.js --build",
|
|
63
62
|
"test:lib": "vitest",
|
|
64
63
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
65
64
|
"test:build": "publint --strict && attw --pack",
|
package/src/createPersister.ts
CHANGED
|
@@ -131,7 +131,13 @@ export function experimental_createQueryPersister<TStorageValue = string>({
|
|
|
131
131
|
try {
|
|
132
132
|
const storedData = await storage.getItem(storageKey)
|
|
133
133
|
if (storedData) {
|
|
134
|
-
|
|
134
|
+
let persistedQuery: PersistedQuery
|
|
135
|
+
try {
|
|
136
|
+
persistedQuery = await deserialize(storedData)
|
|
137
|
+
} catch {
|
|
138
|
+
await storage.removeItem(storageKey)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
135
141
|
|
|
136
142
|
if (isExpiredOrBusted(persistedQuery)) {
|
|
137
143
|
await storage.removeItem(storageKey)
|
|
@@ -241,11 +247,17 @@ export function experimental_createQueryPersister<TStorageValue = string>({
|
|
|
241
247
|
|
|
242
248
|
async function persisterGc() {
|
|
243
249
|
if (storage?.entries) {
|
|
250
|
+
const storageKeyPrefix = `${prefix}-`
|
|
244
251
|
const entries = await storage.entries()
|
|
245
252
|
for (const [key, value] of entries) {
|
|
246
|
-
if (key.startsWith(
|
|
247
|
-
|
|
248
|
-
|
|
253
|
+
if (key.startsWith(storageKeyPrefix)) {
|
|
254
|
+
let persistedQuery: PersistedQuery
|
|
255
|
+
try {
|
|
256
|
+
persistedQuery = await deserialize(value)
|
|
257
|
+
} catch {
|
|
258
|
+
await storage.removeItem(key)
|
|
259
|
+
continue
|
|
260
|
+
}
|
|
249
261
|
if (isExpiredOrBusted(persistedQuery)) {
|
|
250
262
|
await storage.removeItem(key)
|
|
251
263
|
}
|
|
@@ -265,11 +277,17 @@ export function experimental_createQueryPersister<TStorageValue = string>({
|
|
|
265
277
|
const { exact, queryKey } = filters
|
|
266
278
|
|
|
267
279
|
if (storage?.entries) {
|
|
280
|
+
const storageKeyPrefix = `${prefix}-`
|
|
268
281
|
const entries = await storage.entries()
|
|
269
282
|
for (const [key, value] of entries) {
|
|
270
|
-
if (key.startsWith(
|
|
271
|
-
|
|
272
|
-
|
|
283
|
+
if (key.startsWith(storageKeyPrefix)) {
|
|
284
|
+
let persistedQuery: PersistedQuery
|
|
285
|
+
try {
|
|
286
|
+
persistedQuery = await deserialize(value)
|
|
287
|
+
} catch {
|
|
288
|
+
await storage.removeItem(key)
|
|
289
|
+
continue
|
|
290
|
+
}
|
|
273
291
|
if (isExpiredOrBusted(persistedQuery)) {
|
|
274
292
|
await storage.removeItem(key)
|
|
275
293
|
continue
|