@tanstack/query-persist-client-core 5.94.4 → 5.94.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/legacy/_tsup-dts-rollup.d.cts +246 -0
- package/build/legacy/_tsup-dts-rollup.d.ts +246 -0
- package/build/legacy/createPersister.cjs +258 -0
- package/build/legacy/createPersister.cjs.map +1 -0
- package/build/legacy/createPersister.d.cts +6 -0
- package/build/legacy/createPersister.d.ts +6 -0
- package/build/legacy/createPersister.js +237 -0
- package/build/legacy/createPersister.js.map +1 -0
- package/build/legacy/index.cjs +29 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +19 -0
- package/build/legacy/index.d.ts +19 -0
- package/build/legacy/index.js +5 -0
- package/build/legacy/index.js.map +1 -0
- package/build/legacy/persist.cjs +117 -0
- package/build/legacy/persist.cjs.map +1 -0
- package/build/legacy/persist.d.cts +11 -0
- package/build/legacy/persist.d.ts +11 -0
- package/build/legacy/persist.js +89 -0
- package/build/legacy/persist.js.map +1 -0
- package/build/legacy/retryStrategies.cjs +47 -0
- package/build/legacy/retryStrategies.cjs.map +1 -0
- package/build/legacy/retryStrategies.d.cts +2 -0
- package/build/legacy/retryStrategies.d.ts +2 -0
- package/build/legacy/retryStrategies.js +22 -0
- package/build/legacy/retryStrategies.js.map +1 -0
- 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 +258 -0
- package/build/modern/createPersister.cjs.map +1 -0
- package/build/modern/createPersister.d.cts +6 -0
- package/build/modern/createPersister.d.ts +6 -0
- package/build/modern/createPersister.js +237 -0
- package/build/modern/createPersister.js.map +1 -0
- package/build/modern/index.cjs +29 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +19 -0
- package/build/modern/index.d.ts +19 -0
- package/build/modern/index.js +5 -0
- package/build/modern/index.js.map +1 -0
- package/build/modern/persist.cjs +117 -0
- package/build/modern/persist.cjs.map +1 -0
- package/build/modern/persist.d.cts +11 -0
- package/build/modern/persist.d.ts +11 -0
- package/build/modern/persist.js +89 -0
- package/build/modern/persist.js.map +1 -0
- package/build/modern/retryStrategies.cjs +47 -0
- package/build/modern/retryStrategies.cjs.map +1 -0
- package/build/modern/retryStrategies.d.cts +2 -0
- package/build/modern/retryStrategies.d.ts +2 -0
- package/build/modern/retryStrategies.js +22 -0
- package/build/modern/retryStrategies.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/persist.ts
|
|
21
|
+
var persist_exports = {};
|
|
22
|
+
__export(persist_exports, {
|
|
23
|
+
persistQueryClient: () => persistQueryClient,
|
|
24
|
+
persistQueryClientRestore: () => persistQueryClientRestore,
|
|
25
|
+
persistQueryClientSave: () => persistQueryClientSave,
|
|
26
|
+
persistQueryClientSubscribe: () => persistQueryClientSubscribe
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(persist_exports);
|
|
29
|
+
var import_query_core = require("@tanstack/query-core");
|
|
30
|
+
var cacheEventTypes = ["added", "removed", "updated"];
|
|
31
|
+
function isCacheEventType(eventType) {
|
|
32
|
+
return cacheEventTypes.includes(eventType);
|
|
33
|
+
}
|
|
34
|
+
async function persistQueryClientRestore({
|
|
35
|
+
queryClient,
|
|
36
|
+
persister,
|
|
37
|
+
maxAge = 1e3 * 60 * 60 * 24,
|
|
38
|
+
buster = "",
|
|
39
|
+
hydrateOptions
|
|
40
|
+
}) {
|
|
41
|
+
try {
|
|
42
|
+
const persistedClient = await persister.restoreClient();
|
|
43
|
+
if (persistedClient) {
|
|
44
|
+
if (persistedClient.timestamp) {
|
|
45
|
+
const expired = Date.now() - persistedClient.timestamp > maxAge;
|
|
46
|
+
const busted = persistedClient.buster !== buster;
|
|
47
|
+
if (expired || busted) {
|
|
48
|
+
return persister.removeClient();
|
|
49
|
+
} else {
|
|
50
|
+
(0, import_query_core.hydrate)(queryClient, persistedClient.clientState, hydrateOptions);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
return persister.removeClient();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (process.env.NODE_ENV !== "production") {
|
|
58
|
+
console.error(err);
|
|
59
|
+
console.warn(
|
|
60
|
+
"Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
await persister.removeClient();
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function persistQueryClientSave({
|
|
68
|
+
queryClient,
|
|
69
|
+
persister,
|
|
70
|
+
buster = "",
|
|
71
|
+
dehydrateOptions
|
|
72
|
+
}) {
|
|
73
|
+
const persistClient = {
|
|
74
|
+
buster,
|
|
75
|
+
timestamp: Date.now(),
|
|
76
|
+
clientState: (0, import_query_core.dehydrate)(queryClient, dehydrateOptions)
|
|
77
|
+
};
|
|
78
|
+
await persister.persistClient(persistClient);
|
|
79
|
+
}
|
|
80
|
+
function persistQueryClientSubscribe(props) {
|
|
81
|
+
const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe((event) => {
|
|
82
|
+
if (isCacheEventType(event.type)) {
|
|
83
|
+
persistQueryClientSave(props);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const unsubscribeMutationCache = props.queryClient.getMutationCache().subscribe((event) => {
|
|
87
|
+
if (isCacheEventType(event.type)) {
|
|
88
|
+
persistQueryClientSave(props);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
unsubscribeQueryCache();
|
|
93
|
+
unsubscribeMutationCache();
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function persistQueryClient(props) {
|
|
97
|
+
let hasUnsubscribed = false;
|
|
98
|
+
let persistQueryClientUnsubscribe;
|
|
99
|
+
const unsubscribe = () => {
|
|
100
|
+
hasUnsubscribed = true;
|
|
101
|
+
persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
|
|
102
|
+
};
|
|
103
|
+
const restorePromise = persistQueryClientRestore(props).then(() => {
|
|
104
|
+
if (!hasUnsubscribed) {
|
|
105
|
+
persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return [unsubscribe, restorePromise];
|
|
109
|
+
}
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
persistQueryClient,
|
|
113
|
+
persistQueryClientRestore,
|
|
114
|
+
persistQueryClientSave,
|
|
115
|
+
persistQueryClientSubscribe
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=persist.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/persist.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n NotifyEventType,\n QueryClient,\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 PersistQueryClientRootOptions {\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 extends PersistQueryClientRootOptions {\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 extends PersistQueryClientRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends\n PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClientRootOptions {}\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheEventTypes: Array<NotifyEventType> = ['added', 'removed', 'updated']\n\nfunction isCacheEventType(eventType: NotifyEventType) {\n return cacheEventTypes.includes(eventType)\n}\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 return persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n return persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err)\n console.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\n await persister.removeClient()\n\n throw err\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((event) => {\n if (isCacheEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unsubscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unsubscribeMutationCache()\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAmC;AA0DnC,IAAM,kBAA0C,CAAC,SAAS,WAAW,SAAS;AAE9E,SAAS,iBAAiB,WAA4B;AACpD,SAAO,gBAAgB,SAAS,SAAS;AAC3C;AAQA,eAAsB,0BAA0B;AAAA,EAC9C;AAAA,EACA;AAAA,EACA,SAAS,MAAO,KAAK,KAAK;AAAA,EAC1B,SAAS;AAAA,EACT;AACF,GAAuC;AACrC,MAAI;AACF,UAAM,kBAAkB,MAAM,UAAU,cAAc;AAEtD,QAAI,iBAAiB;AACnB,UAAI,gBAAgB,WAAW;AAC7B,cAAM,UAAU,KAAK,IAAI,IAAI,gBAAgB,YAAY;AACzD,cAAM,SAAS,gBAAgB,WAAW;AAC1C,YAAI,WAAW,QAAQ;AACrB,iBAAO,UAAU,aAAa;AAAA,QAChC,OAAO;AACL,yCAAQ,aAAa,gBAAgB,aAAa,cAAc;AAAA,QAClE;AAAA,MACF,OAAO;AACL,eAAO,UAAU,aAAa;AAAA,MAChC;AAAA,IACF;AAAA,EACF,SAAS,KAAK;AACZ,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAQ,MAAM,GAAG;AACjB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAU,aAAa;AAE7B,UAAM;AAAA,EACR;AACF;AAOA,eAAsB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AACF,GAAoC;AAClC,QAAM,gBAAiC;AAAA,IACrC;AAAA,IACA,WAAW,KAAK,IAAI;AAAA,IACpB,iBAAa,6BAAU,aAAa,gBAAgB;AAAA,EACtD;AAEA,QAAM,UAAU,cAAc,aAAa;AAC7C;AAMO,SAAS,4BACd,OACA;AACA,QAAM,wBAAwB,MAAM,YACjC,cAAc,EACd,UAAU,CAAC,UAAU;AACpB,QAAI,iBAAiB,MAAM,IAAI,GAAG;AAChC,6BAAuB,KAAK;AAAA,IAC9B;AAAA,EACF,CAAC;AAEH,QAAM,2BAA2B,MAAM,YACpC,iBAAiB,EACjB,UAAU,CAAC,UAAU;AACpB,QAAI,iBAAiB,MAAM,IAAI,GAAG;AAChC,6BAAuB,KAAK;AAAA,IAC9B;AAAA,EACF,CAAC;AAEH,SAAO,MAAM;AACX,0BAAsB;AACtB,6BAAyB;AAAA,EAC3B;AACF;AAKO,SAAS,mBACd,OAC6B;AAC7B,MAAI,kBAAkB;AACtB,MAAI;AACJ,QAAM,cAAc,MAAM;AACxB,sBAAkB;AAClB;AAAA,EACF;AAGA,QAAM,iBAAiB,0BAA0B,KAAK,EAAE,KAAK,MAAM;AACjE,QAAI,CAAC,iBAAiB;AAEpB,sCAAgC,4BAA4B,KAAK;AAAA,IACnE;AAAA,EACF,CAAC;AAED,SAAO,CAAC,aAAa,cAAc;AACrC;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
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';
|
|
@@ -0,0 +1,11 @@
|
|
|
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';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/persist.ts
|
|
2
|
+
import { dehydrate, hydrate } from "@tanstack/query-core";
|
|
3
|
+
var cacheEventTypes = ["added", "removed", "updated"];
|
|
4
|
+
function isCacheEventType(eventType) {
|
|
5
|
+
return cacheEventTypes.includes(eventType);
|
|
6
|
+
}
|
|
7
|
+
async function persistQueryClientRestore({
|
|
8
|
+
queryClient,
|
|
9
|
+
persister,
|
|
10
|
+
maxAge = 1e3 * 60 * 60 * 24,
|
|
11
|
+
buster = "",
|
|
12
|
+
hydrateOptions
|
|
13
|
+
}) {
|
|
14
|
+
try {
|
|
15
|
+
const persistedClient = await persister.restoreClient();
|
|
16
|
+
if (persistedClient) {
|
|
17
|
+
if (persistedClient.timestamp) {
|
|
18
|
+
const expired = Date.now() - persistedClient.timestamp > maxAge;
|
|
19
|
+
const busted = persistedClient.buster !== buster;
|
|
20
|
+
if (expired || busted) {
|
|
21
|
+
return persister.removeClient();
|
|
22
|
+
} else {
|
|
23
|
+
hydrate(queryClient, persistedClient.clientState, hydrateOptions);
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
return persister.removeClient();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (process.env.NODE_ENV !== "production") {
|
|
31
|
+
console.error(err);
|
|
32
|
+
console.warn(
|
|
33
|
+
"Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded."
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
await persister.removeClient();
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function persistQueryClientSave({
|
|
41
|
+
queryClient,
|
|
42
|
+
persister,
|
|
43
|
+
buster = "",
|
|
44
|
+
dehydrateOptions
|
|
45
|
+
}) {
|
|
46
|
+
const persistClient = {
|
|
47
|
+
buster,
|
|
48
|
+
timestamp: Date.now(),
|
|
49
|
+
clientState: dehydrate(queryClient, dehydrateOptions)
|
|
50
|
+
};
|
|
51
|
+
await persister.persistClient(persistClient);
|
|
52
|
+
}
|
|
53
|
+
function persistQueryClientSubscribe(props) {
|
|
54
|
+
const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe((event) => {
|
|
55
|
+
if (isCacheEventType(event.type)) {
|
|
56
|
+
persistQueryClientSave(props);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const unsubscribeMutationCache = props.queryClient.getMutationCache().subscribe((event) => {
|
|
60
|
+
if (isCacheEventType(event.type)) {
|
|
61
|
+
persistQueryClientSave(props);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return () => {
|
|
65
|
+
unsubscribeQueryCache();
|
|
66
|
+
unsubscribeMutationCache();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function persistQueryClient(props) {
|
|
70
|
+
let hasUnsubscribed = false;
|
|
71
|
+
let persistQueryClientUnsubscribe;
|
|
72
|
+
const unsubscribe = () => {
|
|
73
|
+
hasUnsubscribed = true;
|
|
74
|
+
persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
|
|
75
|
+
};
|
|
76
|
+
const restorePromise = persistQueryClientRestore(props).then(() => {
|
|
77
|
+
if (!hasUnsubscribed) {
|
|
78
|
+
persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return [unsubscribe, restorePromise];
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
persistQueryClient,
|
|
85
|
+
persistQueryClientRestore,
|
|
86
|
+
persistQueryClientSave,
|
|
87
|
+
persistQueryClientSubscribe
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=persist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/persist.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n NotifyEventType,\n QueryClient,\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 PersistQueryClientRootOptions {\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 extends PersistQueryClientRootOptions {\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 extends PersistQueryClientRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends\n PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClientRootOptions {}\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheEventTypes: Array<NotifyEventType> = ['added', 'removed', 'updated']\n\nfunction isCacheEventType(eventType: NotifyEventType) {\n return cacheEventTypes.includes(eventType)\n}\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 return persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n return persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err)\n console.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\n await persister.removeClient()\n\n throw err\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((event) => {\n if (isCacheEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unsubscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unsubscribeMutationCache()\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"],"mappings":";AAAA,SAAS,WAAW,eAAe;AA0DnC,IAAM,kBAA0C,CAAC,SAAS,WAAW,SAAS;AAE9E,SAAS,iBAAiB,WAA4B;AACpD,SAAO,gBAAgB,SAAS,SAAS;AAC3C;AAQA,eAAsB,0BAA0B;AAAA,EAC9C;AAAA,EACA;AAAA,EACA,SAAS,MAAO,KAAK,KAAK;AAAA,EAC1B,SAAS;AAAA,EACT;AACF,GAAuC;AACrC,MAAI;AACF,UAAM,kBAAkB,MAAM,UAAU,cAAc;AAEtD,QAAI,iBAAiB;AACnB,UAAI,gBAAgB,WAAW;AAC7B,cAAM,UAAU,KAAK,IAAI,IAAI,gBAAgB,YAAY;AACzD,cAAM,SAAS,gBAAgB,WAAW;AAC1C,YAAI,WAAW,QAAQ;AACrB,iBAAO,UAAU,aAAa;AAAA,QAChC,OAAO;AACL,kBAAQ,aAAa,gBAAgB,aAAa,cAAc;AAAA,QAClE;AAAA,MACF,OAAO;AACL,eAAO,UAAU,aAAa;AAAA,MAChC;AAAA,IACF;AAAA,EACF,SAAS,KAAK;AACZ,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAQ,MAAM,GAAG;AACjB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAU,aAAa;AAE7B,UAAM;AAAA,EACR;AACF;AAOA,eAAsB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AACF,GAAoC;AAClC,QAAM,gBAAiC;AAAA,IACrC;AAAA,IACA,WAAW,KAAK,IAAI;AAAA,IACpB,aAAa,UAAU,aAAa,gBAAgB;AAAA,EACtD;AAEA,QAAM,UAAU,cAAc,aAAa;AAC7C;AAMO,SAAS,4BACd,OACA;AACA,QAAM,wBAAwB,MAAM,YACjC,cAAc,EACd,UAAU,CAAC,UAAU;AACpB,QAAI,iBAAiB,MAAM,IAAI,GAAG;AAChC,6BAAuB,KAAK;AAAA,IAC9B;AAAA,EACF,CAAC;AAEH,QAAM,2BAA2B,MAAM,YACpC,iBAAiB,EACjB,UAAU,CAAC,UAAU;AACpB,QAAI,iBAAiB,MAAM,IAAI,GAAG;AAChC,6BAAuB,KAAK;AAAA,IAC9B;AAAA,EACF,CAAC;AAEH,SAAO,MAAM;AACX,0BAAsB;AACtB,6BAAyB;AAAA,EAC3B;AACF;AAKO,SAAS,mBACd,OAC6B;AAC7B,MAAI,kBAAkB;AACtB,MAAI;AACJ,QAAM,cAAc,MAAM;AACxB,sBAAkB;AAClB;AAAA,EACF;AAGA,QAAM,iBAAiB,0BAA0B,KAAK,EAAE,KAAK,MAAM;AACjE,QAAI,CAAC,iBAAiB;AAEpB,sCAAgC,4BAA4B,KAAK;AAAA,IACnE;AAAA,EACF,CAAC;AAED,SAAO,CAAC,aAAa,cAAc;AACrC;","names":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/retryStrategies.ts
|
|
21
|
+
var retryStrategies_exports = {};
|
|
22
|
+
__export(retryStrategies_exports, {
|
|
23
|
+
removeOldestQuery: () => removeOldestQuery
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(retryStrategies_exports);
|
|
26
|
+
var removeOldestQuery = ({ persistedClient }) => {
|
|
27
|
+
const mutations = [...persistedClient.clientState.mutations];
|
|
28
|
+
const queries = [...persistedClient.clientState.queries];
|
|
29
|
+
const client = {
|
|
30
|
+
...persistedClient,
|
|
31
|
+
clientState: { mutations, queries }
|
|
32
|
+
};
|
|
33
|
+
const sortedQueries = [...queries].sort(
|
|
34
|
+
(a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt
|
|
35
|
+
);
|
|
36
|
+
if (sortedQueries.length > 0) {
|
|
37
|
+
const oldestData = sortedQueries.shift();
|
|
38
|
+
client.clientState.queries = queries.filter((q) => q !== oldestData);
|
|
39
|
+
return client;
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
removeOldestQuery
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=retryStrategies.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,IAAM,oBAAoC,CAAC,EAAE,gBAAgB,MAAM;AACxE,QAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;AAC3D,QAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;AACvD,QAAM,SAA0B;AAAA,IAC9B,GAAG;AAAA,IACH,aAAa,EAAE,WAAW,QAAQ;AAAA,EACpC;AAGA,QAAM,gBAAgB,CAAC,GAAG,OAAO,EAAE;AAAA,IACjC,CAAC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM;AAAA,EAC5C;AAGA,MAAI,cAAc,SAAS,GAAG;AAC5B,UAAM,aAAa,cAAc,MAAM;AACvC,WAAO,YAAY,UAAU,QAAQ,OAAO,CAAC,MAAM,MAAM,UAAU;AACnE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/retryStrategies.ts
|
|
2
|
+
var removeOldestQuery = ({ persistedClient }) => {
|
|
3
|
+
const mutations = [...persistedClient.clientState.mutations];
|
|
4
|
+
const queries = [...persistedClient.clientState.queries];
|
|
5
|
+
const client = {
|
|
6
|
+
...persistedClient,
|
|
7
|
+
clientState: { mutations, queries }
|
|
8
|
+
};
|
|
9
|
+
const sortedQueries = [...queries].sort(
|
|
10
|
+
(a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt
|
|
11
|
+
);
|
|
12
|
+
if (sortedQueries.length > 0) {
|
|
13
|
+
const oldestData = sortedQueries.shift();
|
|
14
|
+
client.clientState.queries = queries.filter((q) => q !== oldestData);
|
|
15
|
+
return client;
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
removeOldestQuery
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=retryStrategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { 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"],"mappings":";AAQO,IAAM,oBAAoC,CAAC,EAAE,gBAAgB,MAAM;AACxE,QAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;AAC3D,QAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;AACvD,QAAM,SAA0B;AAAA,IAC9B,GAAG;AAAA,IACH,aAAa,EAAE,WAAW,QAAQ;AAAA,EACpC;AAGA,QAAM,gBAAgB,CAAC,GAAG,OAAO,EAAE;AAAA,IACjC,CAAC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM;AAAA,EAC5C;AAGA,MAAI,cAAc,SAAS,GAAG;AAC5B,UAAM,aAAa,cAAc,MAAM;AACvC,WAAO,YAAY,UAAU,QAAQ,OAAO,CAAC,MAAM,MAAM,UAAU;AACnE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { DehydratedState } from '@tanstack/query-core';
|
|
2
|
+
import type { DehydrateOptions } from '@tanstack/query-core';
|
|
3
|
+
import type { HydrateOptions } from '@tanstack/query-core';
|
|
4
|
+
import { Options } from 'tsup';
|
|
5
|
+
import type { Query } from '@tanstack/query-core';
|
|
6
|
+
import type { QueryClient } from '@tanstack/query-core';
|
|
7
|
+
import type { QueryFilters } from '@tanstack/query-core';
|
|
8
|
+
import type { QueryFunctionContext } from '@tanstack/query-core';
|
|
9
|
+
import type { QueryKey } from '@tanstack/query-core';
|
|
10
|
+
import type { QueryState } from '@tanstack/query-core';
|
|
11
|
+
import { UserConfig } from 'vite';
|
|
12
|
+
|
|
13
|
+
declare interface AsyncStorage<TStorageValue = string> {
|
|
14
|
+
getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>;
|
|
15
|
+
setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>;
|
|
16
|
+
removeItem: (key: string) => MaybePromise<void>;
|
|
17
|
+
entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>;
|
|
18
|
+
}
|
|
19
|
+
export { AsyncStorage }
|
|
20
|
+
export { AsyncStorage as AsyncStorage_alias_1 }
|
|
21
|
+
|
|
22
|
+
export declare function createMockPersister(): Persister;
|
|
23
|
+
|
|
24
|
+
export declare function createSpyPersister(): Persister;
|
|
25
|
+
|
|
26
|
+
export declare const default_alias: any[];
|
|
27
|
+
|
|
28
|
+
export declare const default_alias_1: any[];
|
|
29
|
+
|
|
30
|
+
export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
|
31
|
+
|
|
32
|
+
export declare const default_alias_3: UserConfig;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Warning: experimental feature.
|
|
36
|
+
* This utility function enables fine-grained query persistence.
|
|
37
|
+
* Simple add it as a `persister` parameter to `useQuery` or `defaultOptions` on `queryClient`.
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* useQuery({
|
|
41
|
+
queryKey: ['myKey'],
|
|
42
|
+
queryFn: fetcher,
|
|
43
|
+
persister: createPersister({
|
|
44
|
+
storage: localStorage,
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
*/
|
|
49
|
+
declare function experimental_createQueryPersister<TStorageValue = string>({ storage, buster, maxAge, serialize, deserialize, prefix, refetchOnRestore, filters, }: StoragePersisterOptions<TStorageValue>): {
|
|
50
|
+
persisterFn: <T, TQueryKey extends QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>, ctx: QueryFunctionContext<TQueryKey>, query: Query) => Promise<T>;
|
|
51
|
+
persistQuery: (query: Query) => Promise<void>;
|
|
52
|
+
persistQueryByKey: (queryKey: QueryKey, queryClient: QueryClient) => Promise<void>;
|
|
53
|
+
retrieveQuery: <T>(queryHash: string, afterRestoreMacroTask?: (persistedQuery: PersistedQuery) => void) => Promise<T | undefined>;
|
|
54
|
+
persisterGc: () => Promise<void>;
|
|
55
|
+
restoreQueries: (queryClient: QueryClient, filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
|
|
56
|
+
removeQueries: (filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
export { experimental_createQueryPersister }
|
|
59
|
+
export { experimental_createQueryPersister as experimental_createQueryPersister_alias_1 }
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {Object} opts - Options for building configurations.
|
|
63
|
+
* @param {string[]} opts.entry - The entry array.
|
|
64
|
+
* @returns {import('tsup').Options}
|
|
65
|
+
*/
|
|
66
|
+
export declare function legacyConfig(opts: {
|
|
67
|
+
entry: string[];
|
|
68
|
+
}): Options;
|
|
69
|
+
|
|
70
|
+
declare type MaybePromise<T> = T | Promise<T>;
|
|
71
|
+
export { MaybePromise }
|
|
72
|
+
export { MaybePromise as MaybePromise_alias_1 }
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {Object} opts - Options for building configurations.
|
|
76
|
+
* @param {string[]} opts.entry - The entry array.
|
|
77
|
+
* @returns {import('tsup').Options}
|
|
78
|
+
*/
|
|
79
|
+
export declare function modernConfig(opts: {
|
|
80
|
+
entry: string[];
|
|
81
|
+
}): Options;
|
|
82
|
+
|
|
83
|
+
declare interface PersistedClient {
|
|
84
|
+
timestamp: number;
|
|
85
|
+
buster: string;
|
|
86
|
+
clientState: DehydratedState;
|
|
87
|
+
}
|
|
88
|
+
export { PersistedClient }
|
|
89
|
+
export { PersistedClient as PersistedClient_alias_1 }
|
|
90
|
+
|
|
91
|
+
declare interface PersistedQuery {
|
|
92
|
+
buster: string;
|
|
93
|
+
queryHash: string;
|
|
94
|
+
queryKey: QueryKey;
|
|
95
|
+
state: QueryState;
|
|
96
|
+
}
|
|
97
|
+
export { PersistedQuery }
|
|
98
|
+
export { PersistedQuery as PersistedQuery_alias_1 }
|
|
99
|
+
|
|
100
|
+
declare interface PersistedQueryClientRestoreOptions extends PersistQueryClientRootOptions {
|
|
101
|
+
/** The max-allowed age of the cache in milliseconds.
|
|
102
|
+
* If a persisted cache is found that is older than this
|
|
103
|
+
* time, it will be discarded */
|
|
104
|
+
maxAge?: number;
|
|
105
|
+
/** The options passed to the hydrate function */
|
|
106
|
+
hydrateOptions?: HydrateOptions;
|
|
107
|
+
}
|
|
108
|
+
export { PersistedQueryClientRestoreOptions }
|
|
109
|
+
export { PersistedQueryClientRestoreOptions as PersistedQueryClientRestoreOptions_alias_1 }
|
|
110
|
+
|
|
111
|
+
declare interface PersistedQueryClientSaveOptions extends PersistQueryClientRootOptions {
|
|
112
|
+
/** The options passed to the dehydrate function */
|
|
113
|
+
dehydrateOptions?: DehydrateOptions;
|
|
114
|
+
}
|
|
115
|
+
export { PersistedQueryClientSaveOptions }
|
|
116
|
+
export { PersistedQueryClientSaveOptions as PersistedQueryClientSaveOptions_alias_1 }
|
|
117
|
+
|
|
118
|
+
declare interface Persister {
|
|
119
|
+
persistClient: (persistClient: PersistedClient) => Promisable<void>;
|
|
120
|
+
restoreClient: () => Promisable<PersistedClient | undefined>;
|
|
121
|
+
removeClient: () => Promisable<void>;
|
|
122
|
+
}
|
|
123
|
+
export { Persister }
|
|
124
|
+
export { Persister as Persister_alias_1 }
|
|
125
|
+
|
|
126
|
+
declare const PERSISTER_KEY_PREFIX = "tanstack-query";
|
|
127
|
+
export { PERSISTER_KEY_PREFIX }
|
|
128
|
+
export { PERSISTER_KEY_PREFIX as PERSISTER_KEY_PREFIX_alias_1 }
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Restores persisted data to QueryCache and persists further changes.
|
|
132
|
+
*/
|
|
133
|
+
declare function persistQueryClient(props: PersistQueryClientOptions): [() => void, Promise<void>];
|
|
134
|
+
export { persistQueryClient }
|
|
135
|
+
export { persistQueryClient as persistQueryClient_alias_1 }
|
|
136
|
+
|
|
137
|
+
declare interface PersistQueryClientOptions extends PersistedQueryClientRestoreOptions, PersistedQueryClientSaveOptions, PersistQueryClientRootOptions {
|
|
138
|
+
}
|
|
139
|
+
export { PersistQueryClientOptions }
|
|
140
|
+
export { PersistQueryClientOptions as PersistQueryClientOptions_alias_1 }
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Restores persisted data to the QueryCache
|
|
144
|
+
* - data obtained from persister.restoreClient
|
|
145
|
+
* - data is hydrated using hydrateOptions
|
|
146
|
+
* If data is expired, busted, empty, or throws, it runs persister.removeClient
|
|
147
|
+
*/
|
|
148
|
+
declare function persistQueryClientRestore({ queryClient, persister, maxAge, buster, hydrateOptions, }: PersistedQueryClientRestoreOptions): Promise<void>;
|
|
149
|
+
export { persistQueryClientRestore }
|
|
150
|
+
export { persistQueryClientRestore as persistQueryClientRestore_alias_1 }
|
|
151
|
+
|
|
152
|
+
declare interface PersistQueryClientRootOptions {
|
|
153
|
+
/** The QueryClient to persist */
|
|
154
|
+
queryClient: QueryClient;
|
|
155
|
+
/** The Persister interface for storing and restoring the cache
|
|
156
|
+
* to/from a persisted location */
|
|
157
|
+
persister: Persister;
|
|
158
|
+
/** A unique string that can be used to forcefully
|
|
159
|
+
* invalidate existing caches if they do not share the same buster string */
|
|
160
|
+
buster?: string;
|
|
161
|
+
}
|
|
162
|
+
export { PersistQueryClientRootOptions }
|
|
163
|
+
export { PersistQueryClientRootOptions as PersistQueryClientRootOptions_alias_1 }
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Persists data from the QueryCache
|
|
167
|
+
* - data dehydrated using dehydrateOptions
|
|
168
|
+
* - data is persisted using persister.persistClient
|
|
169
|
+
*/
|
|
170
|
+
declare function persistQueryClientSave({ queryClient, persister, buster, dehydrateOptions, }: PersistedQueryClientSaveOptions): Promise<void>;
|
|
171
|
+
export { persistQueryClientSave }
|
|
172
|
+
export { persistQueryClientSave as persistQueryClientSave_alias_1 }
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Subscribe to QueryCache and MutationCache updates (for persisting)
|
|
176
|
+
* @returns an unsubscribe function (to discontinue monitoring)
|
|
177
|
+
*/
|
|
178
|
+
declare function persistQueryClientSubscribe(props: PersistedQueryClientSaveOptions): () => void;
|
|
179
|
+
export { persistQueryClientSubscribe }
|
|
180
|
+
export { persistQueryClientSubscribe as persistQueryClientSubscribe_alias_1 }
|
|
181
|
+
|
|
182
|
+
declare type PersistRetryer = (props: {
|
|
183
|
+
persistedClient: PersistedClient;
|
|
184
|
+
error: Error;
|
|
185
|
+
errorCount: number;
|
|
186
|
+
}) => PersistedClient | undefined;
|
|
187
|
+
export { PersistRetryer }
|
|
188
|
+
export { PersistRetryer as PersistRetryer_alias_1 }
|
|
189
|
+
|
|
190
|
+
declare type Promisable<T> = T | PromiseLike<T>;
|
|
191
|
+
export { Promisable }
|
|
192
|
+
export { Promisable as Promisable_alias_1 }
|
|
193
|
+
|
|
194
|
+
declare const removeOldestQuery: PersistRetryer;
|
|
195
|
+
export { removeOldestQuery }
|
|
196
|
+
export { removeOldestQuery as removeOldestQuery_alias_1 }
|
|
197
|
+
|
|
198
|
+
declare interface StoragePersisterOptions<TStorageValue = string> {
|
|
199
|
+
/** The storage client used for setting and retrieving items from cache.
|
|
200
|
+
* For SSR pass in `undefined`.
|
|
201
|
+
*/
|
|
202
|
+
storage: AsyncStorage<TStorageValue> | undefined | null;
|
|
203
|
+
/**
|
|
204
|
+
* How to serialize the data to storage.
|
|
205
|
+
* @default `JSON.stringify`
|
|
206
|
+
*/
|
|
207
|
+
serialize?: (persistedQuery: PersistedQuery) => MaybePromise<TStorageValue>;
|
|
208
|
+
/**
|
|
209
|
+
* How to deserialize the data from storage.
|
|
210
|
+
* @default `JSON.parse`
|
|
211
|
+
*/
|
|
212
|
+
deserialize?: (cachedString: TStorageValue) => MaybePromise<PersistedQuery>;
|
|
213
|
+
/**
|
|
214
|
+
* A unique string that can be used to forcefully invalidate existing caches,
|
|
215
|
+
* if they do not share the same buster string
|
|
216
|
+
*/
|
|
217
|
+
buster?: string;
|
|
218
|
+
/**
|
|
219
|
+
* The max-allowed age of the cache in milliseconds.
|
|
220
|
+
* If a persisted cache is found that is older than this
|
|
221
|
+
* time, it will be discarded
|
|
222
|
+
* @default 24 hours
|
|
223
|
+
*/
|
|
224
|
+
maxAge?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Prefix to be used for storage key.
|
|
227
|
+
* Storage key is a combination of prefix and query hash in a form of `prefix-queryHash`.
|
|
228
|
+
* @default 'tanstack-query'
|
|
229
|
+
*/
|
|
230
|
+
prefix?: string;
|
|
231
|
+
/**
|
|
232
|
+
* If set to `true`, the query will refetch on successful query restoration if the data is stale.
|
|
233
|
+
* If set to `false`, the query will not refetch on successful query restoration.
|
|
234
|
+
* If set to `'always'`, the query will always refetch on successful query restoration.
|
|
235
|
+
* Defaults to `true`.
|
|
236
|
+
*/
|
|
237
|
+
refetchOnRestore?: boolean | 'always';
|
|
238
|
+
/**
|
|
239
|
+
* Filters to narrow down which Queries should be persisted.
|
|
240
|
+
*/
|
|
241
|
+
filters?: QueryFilters;
|
|
242
|
+
}
|
|
243
|
+
export { StoragePersisterOptions }
|
|
244
|
+
export { StoragePersisterOptions as StoragePersisterOptions_alias_1 }
|
|
245
|
+
|
|
246
|
+
export { }
|