@tanstack/query-persist-client-core 5.101.4 → 5.102.0

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.
Files changed (65) hide show
  1. package/build/legacy/createPersister.cjs +172 -256
  2. package/build/legacy/createPersister.cjs.map +1 -1
  3. package/build/legacy/createPersister.d.cts +88 -6
  4. package/build/legacy/createPersister.d.cts.map +1 -0
  5. package/build/legacy/createPersister.d.ts +88 -6
  6. package/build/legacy/createPersister.d.ts.map +1 -0
  7. package/build/legacy/createPersister.js +170 -235
  8. package/build/legacy/createPersister.js.map +1 -1
  9. package/build/legacy/index.cjs +14 -27
  10. package/build/legacy/index.cjs.map +1 -1
  11. package/build/legacy/index.d.cts +4 -19
  12. package/build/legacy/index.d.ts +4 -19
  13. package/build/legacy/index.js +8 -4
  14. package/build/legacy/index.js.map +1 -1
  15. package/build/legacy/persist.cjs +82 -108
  16. package/build/legacy/persist.cjs.map +1 -1
  17. package/build/legacy/persist.d.cts +61 -11
  18. package/build/legacy/persist.d.cts.map +1 -0
  19. package/build/legacy/persist.d.ts +61 -11
  20. package/build/legacy/persist.d.ts.map +1 -0
  21. package/build/legacy/persist.js +77 -79
  22. package/build/legacy/persist.js.map +1 -1
  23. package/build/legacy/retryStrategies.cjs +20 -44
  24. package/build/legacy/retryStrategies.cjs.map +1 -1
  25. package/build/legacy/retryStrategies.d.cts +11 -2
  26. package/build/legacy/retryStrategies.d.cts.map +1 -0
  27. package/build/legacy/retryStrategies.d.ts +11 -2
  28. package/build/legacy/retryStrategies.d.ts.map +1 -0
  29. package/build/legacy/retryStrategies.js +20 -20
  30. package/build/legacy/retryStrategies.js.map +1 -1
  31. package/build/modern/createPersister.cjs +172 -256
  32. package/build/modern/createPersister.cjs.map +1 -1
  33. package/build/modern/createPersister.d.cts +88 -6
  34. package/build/modern/createPersister.d.cts.map +1 -0
  35. package/build/modern/createPersister.d.ts +88 -6
  36. package/build/modern/createPersister.d.ts.map +1 -0
  37. package/build/modern/createPersister.js +170 -235
  38. package/build/modern/createPersister.js.map +1 -1
  39. package/build/modern/index.cjs +14 -27
  40. package/build/modern/index.cjs.map +1 -1
  41. package/build/modern/index.d.cts +4 -19
  42. package/build/modern/index.d.ts +4 -19
  43. package/build/modern/index.js +8 -4
  44. package/build/modern/index.js.map +1 -1
  45. package/build/modern/persist.cjs +82 -108
  46. package/build/modern/persist.cjs.map +1 -1
  47. package/build/modern/persist.d.cts +61 -11
  48. package/build/modern/persist.d.cts.map +1 -0
  49. package/build/modern/persist.d.ts +61 -11
  50. package/build/modern/persist.d.ts.map +1 -0
  51. package/build/modern/persist.js +77 -79
  52. package/build/modern/persist.js.map +1 -1
  53. package/build/modern/retryStrategies.cjs +20 -44
  54. package/build/modern/retryStrategies.cjs.map +1 -1
  55. package/build/modern/retryStrategies.d.cts +11 -2
  56. package/build/modern/retryStrategies.d.cts.map +1 -0
  57. package/build/modern/retryStrategies.d.ts +11 -2
  58. package/build/modern/retryStrategies.d.ts.map +1 -0
  59. package/build/modern/retryStrategies.js +20 -20
  60. package/build/modern/retryStrategies.js.map +1 -1
  61. package/package.json +4 -6
  62. package/build/legacy/_tsup-dts-rollup.d.cts +0 -214
  63. package/build/legacy/_tsup-dts-rollup.d.ts +0 -214
  64. package/build/modern/_tsup-dts-rollup.d.cts +0 -214
  65. package/build/modern/_tsup-dts-rollup.d.ts +0 -214
@@ -1,89 +1,87 @@
1
- // src/persist.ts
2
1
  import { dehydrate, hydrate } from "@tanstack/query-core";
3
- var cacheEventTypes = ["added", "removed", "updated"];
2
+ //#region src/persist.ts
3
+ /**
4
+ * Checks if emitted event is about cache change and not about observers.
5
+ * Useful for persist, where we only want to trigger save when cache is changed.
6
+ */
7
+ const cacheEventTypes = [
8
+ "added",
9
+ "removed",
10
+ "updated"
11
+ ];
4
12
  function isCacheEventType(eventType) {
5
- return cacheEventTypes.includes(eventType);
13
+ return cacheEventTypes.includes(eventType);
6
14
  }
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
- }
15
+ /**
16
+ * Restores persisted data to the QueryCache
17
+ * - data obtained from persister.restoreClient
18
+ * - data is hydrated using hydrateOptions
19
+ * If data is expired, busted, empty, or throws, it runs persister.removeClient
20
+ */
21
+ async function persistQueryClientRestore({ queryClient, persister, maxAge = 864e5, buster = "", hydrateOptions }) {
22
+ try {
23
+ const persistedClient = await persister.restoreClient();
24
+ if (persistedClient) {
25
+ if (persistedClient.timestamp) {
26
+ const expired = Date.now() - persistedClient.timestamp > maxAge;
27
+ const busted = persistedClient.buster !== buster;
28
+ if (expired || busted) return persister.removeClient();
29
+ else hydrate(queryClient, persistedClient.clientState, hydrateOptions);
30
+ } else return persister.removeClient();
31
+ }
32
+ } catch (err) {
33
+ if (process.env.NODE_ENV !== "production") {
34
+ console.error(err);
35
+ console.warn("Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.");
36
+ }
37
+ await persister.removeClient();
38
+ throw err;
39
+ }
39
40
  }
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);
41
+ /**
42
+ * Persists data from the QueryCache
43
+ * - data dehydrated using dehydrateOptions
44
+ * - data is persisted using persister.persistClient
45
+ */
46
+ async function persistQueryClientSave({ queryClient, persister, buster = "", dehydrateOptions }) {
47
+ const persistClient = {
48
+ buster,
49
+ timestamp: Date.now(),
50
+ clientState: dehydrate(queryClient, dehydrateOptions)
51
+ };
52
+ await persister.persistClient(persistClient);
52
53
  }
54
+ /**
55
+ * Subscribe to QueryCache and MutationCache updates (for persisting)
56
+ * @returns an unsubscribe function (to discontinue monitoring)
57
+ */
53
58
  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
- };
59
+ const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe((event) => {
60
+ if (isCacheEventType(event.type)) persistQueryClientSave(props);
61
+ });
62
+ const unsubscribeMutationCache = props.queryClient.getMutationCache().subscribe((event) => {
63
+ if (isCacheEventType(event.type)) persistQueryClientSave(props);
64
+ });
65
+ return () => {
66
+ unsubscribeQueryCache();
67
+ unsubscribeMutationCache();
68
+ };
68
69
  }
70
+ /**
71
+ * Restores persisted data to QueryCache and persists further changes.
72
+ */
69
73
  function persistQueryClient(props) {
70
- let hasUnsubscribed = false;
71
- let persistQueryClientUnsubscribe;
72
- const unsubscribe = () => {
73
- hasUnsubscribed = true;
74
- persistQueryClientUnsubscribe?.();
75
- };
76
- const restorePromise = persistQueryClientRestore(props).then(() => {
77
- if (!hasUnsubscribed) {
78
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
79
- }
80
- });
81
- return [unsubscribe, restorePromise];
74
+ let hasUnsubscribed = false;
75
+ let persistQueryClientUnsubscribe;
76
+ const unsubscribe = () => {
77
+ hasUnsubscribed = true;
78
+ persistQueryClientUnsubscribe?.();
79
+ };
80
+ return [unsubscribe, persistQueryClientRestore(props).then(() => {
81
+ if (!hasUnsubscribed) persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
82
+ })];
82
83
  }
83
- export {
84
- persistQueryClient,
85
- persistQueryClientRestore,
86
- persistQueryClientSave,
87
- persistQueryClientSubscribe
88
- };
84
+ //#endregion
85
+ export { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };
86
+
89
87
  //# sourceMappingURL=persist.js.map
@@ -1 +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,oCAAgC;AAAA,EAClC;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":[]}
1
+ {"version":3,"file":"persist.js","names":[],"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":";;;;;;AA0DA,MAAM,kBAA0C;CAAC;CAAS;CAAW;AAAS;AAE9E,SAAS,iBAAiB,WAA4B;CACpD,OAAO,gBAAgB,SAAS,SAAS;AAC3C;;;;;;;AAQA,eAAsB,0BAA0B,EAC9C,aACA,WACA,SAAS,OACT,SAAS,IACT,kBACqC;CACrC,IAAI;EACF,MAAM,kBAAkB,MAAM,UAAU,cAAc;EAEtD,IAAI,iBAAiB;GACnB,IAAI,gBAAgB,WAAW;IAC7B,MAAM,UAAU,KAAK,IAAI,IAAI,gBAAgB,YAAY;IACzD,MAAM,SAAS,gBAAgB,WAAW;IAC1C,IAAI,WAAW,QACb,OAAO,UAAU,aAAa;SAE9B,QAAQ,aAAa,gBAAgB,aAAa,cAAc;GAEpE,OACE,OAAO,UAAU,aAAa;EAElC;CACF,SAAS,KAAK;EACZ,IAAI,QAAQ,IAAI,aAAa,cAAc;GACzC,QAAQ,MAAM,GAAG;GACjB,QAAQ,KACN,0IACF;EACF;EAEA,MAAM,UAAU,aAAa;EAE7B,MAAM;CACR;AACF;;;;;;AAOA,eAAsB,uBAAuB,EAC3C,aACA,WACA,SAAS,IACT,oBACkC;CAClC,MAAM,gBAAiC;EACrC;EACA,WAAW,KAAK,IAAI;EACpB,aAAa,UAAU,aAAa,gBAAgB;CACtD;CAEA,MAAM,UAAU,cAAc,aAAa;AAC7C;;;;;AAMA,SAAgB,4BACd,OACA;CACA,MAAM,wBAAwB,MAAM,YACjC,cAAc,CAAC,CACf,WAAW,UAAU;EACpB,IAAI,iBAAiB,MAAM,IAAI,GAC7B,uBAAuB,KAAK;CAEhC,CAAC;CAEH,MAAM,2BAA2B,MAAM,YACpC,iBAAiB,CAAC,CAClB,WAAW,UAAU;EACpB,IAAI,iBAAiB,MAAM,IAAI,GAC7B,uBAAuB,KAAK;CAEhC,CAAC;CAEH,aAAa;EACX,sBAAsB;EACtB,yBAAyB;CAC3B;AACF;;;;AAKA,SAAgB,mBACd,OAC6B;CAC7B,IAAI,kBAAkB;CACtB,IAAI;CACJ,MAAM,oBAAoB;EACxB,kBAAkB;EAClB,gCAAgC;CAClC;CAUA,OAAO,CAAC,aAPe,0BAA0B,KAAK,CAAC,CAAC,WAAW;EACjE,IAAI,CAAC,iBAEH,gCAAgC,4BAA4B,KAAK;CAErE,CAEkC,CAAC;AACrC"}
@@ -1,47 +1,23 @@
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 });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/retryStrategies.ts
3
+ const removeOldestQuery = ({ persistedClient }) => {
4
+ const mutations = [...persistedClient.clientState.mutations];
5
+ const queries = [...persistedClient.clientState.queries];
6
+ const client = {
7
+ ...persistedClient,
8
+ clientState: {
9
+ mutations,
10
+ queries
11
+ }
12
+ };
13
+ const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
14
+ if (sortedQueries.length > 0) {
15
+ const oldestData = sortedQueries.shift();
16
+ client.clientState.queries = queries.filter((q) => q !== oldestData);
17
+ return client;
18
+ }
9
19
  };
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);
20
+ //#endregion
21
+ exports.removeOldestQuery = removeOldestQuery;
19
22
 
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
23
  //# sourceMappingURL=retryStrategies.cjs.map
@@ -1 +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":[]}
1
+ {"version":3,"file":"retryStrategies.cjs","names":[],"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":";;AAQA,MAAa,qBAAqC,EAAE,sBAAsB;CACxE,MAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;CAC3D,MAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;CACvD,MAAM,SAA0B;EAC9B,GAAG;EACH,aAAa;GAAE;GAAW;EAAQ;CACpC;CAGA,MAAM,gBAAgB,CAAC,GAAG,OAAO,CAAC,CAAC,MAChC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM,aAC5C;CAGA,IAAI,cAAc,SAAS,GAAG;EAC5B,MAAM,aAAa,cAAc,MAAM;EACvC,OAAO,YAAY,UAAU,QAAQ,QAAQ,MAAM,MAAM,UAAU;EACnE,OAAO;CACT;AAGF"}
@@ -1,2 +1,11 @@
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
+ import { PersistedClient } from "./persist.cjs";
2
+ //#region src/retryStrategies.d.ts
3
+ type PersistRetryer = (props: {
4
+ persistedClient: PersistedClient;
5
+ error: Error;
6
+ errorCount: number;
7
+ }) => PersistedClient | undefined;
8
+ declare const removeOldestQuery: PersistRetryer;
9
+ //#endregion
10
+ export { PersistRetryer, removeOldestQuery };
11
+ //# sourceMappingURL=retryStrategies.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryStrategies.d.cts","names":[],"sources":["../../src/retryStrategies.ts"],"mappings":";;KAEY,kBAAkB;EAC5B,iBAAiB;EACjB,OAAO;EACP;MACI;cAEO,mBAAmB"}
@@ -1,2 +1,11 @@
1
- export { PersistRetryer_alias_1 as PersistRetryer } from './_tsup-dts-rollup.js';
2
- export { removeOldestQuery_alias_1 as removeOldestQuery } from './_tsup-dts-rollup.js';
1
+ import { PersistedClient } from "./persist.js";
2
+ //#region src/retryStrategies.d.ts
3
+ type PersistRetryer = (props: {
4
+ persistedClient: PersistedClient;
5
+ error: Error;
6
+ errorCount: number;
7
+ }) => PersistedClient | undefined;
8
+ declare const removeOldestQuery: PersistRetryer;
9
+ //#endregion
10
+ export { PersistRetryer, removeOldestQuery };
11
+ //# sourceMappingURL=retryStrategies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryStrategies.d.ts","names":[],"sources":["../../src/retryStrategies.ts"],"mappings":";;KAEY,kBAAkB;EAC5B,iBAAiB;EACjB,OAAO;EACP;MACI;cAEO,mBAAmB"}
@@ -1,22 +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
1
+ //#region src/retryStrategies.ts
2
+ const removeOldestQuery = ({ persistedClient }) => {
3
+ const mutations = [...persistedClient.clientState.mutations];
4
+ const queries = [...persistedClient.clientState.queries];
5
+ const client = {
6
+ ...persistedClient,
7
+ clientState: {
8
+ mutations,
9
+ queries
10
+ }
11
+ };
12
+ const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
13
+ if (sortedQueries.length > 0) {
14
+ const oldestData = sortedQueries.shift();
15
+ client.clientState.queries = queries.filter((q) => q !== oldestData);
16
+ return client;
17
+ }
21
18
  };
19
+ //#endregion
20
+ export { removeOldestQuery };
21
+
22
22
  //# sourceMappingURL=retryStrategies.js.map
@@ -1 +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":[]}
1
+ {"version":3,"file":"retryStrategies.js","names":[],"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":";AAQA,MAAa,qBAAqC,EAAE,sBAAsB;CACxE,MAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;CAC3D,MAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;CACvD,MAAM,SAA0B;EAC9B,GAAG;EACH,aAAa;GAAE;GAAW;EAAQ;CACpC;CAGA,MAAM,gBAAgB,CAAC,GAAG,OAAO,CAAC,CAAC,MAChC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM,aAC5C;CAGA,IAAI,cAAc,SAAS,GAAG;EAC5B,MAAM,aAAa,cAAc,MAAM;EACvC,OAAO,YAAY,UAAU,QAAQ,QAAQ,MAAM,MAAM,UAAU;EACnE,OAAO;CACT;AAGF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-persist-client-core",
3
- "version": "5.101.4",
3
+ "version": "5.102.0",
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.101.4"
43
+ "@tanstack/query-core": "5.102.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "npm-run-all2": "^5.0.0",
@@ -51,17 +51,15 @@
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:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build",
55
- "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build",
56
54
  "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build",
57
55
  "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build",
58
56
  "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --build",
59
57
  "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --build",
60
58
  "test:types:tscurrent": "tsc --build",
61
- "test:types:ts60": "node ../../node_modules/typescript60/lib/tsc.js --build",
59
+ "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --build",
62
60
  "test:lib": "vitest",
63
61
  "test:lib:dev": "pnpm run test:lib --watch",
64
62
  "test:build": "publint --strict && attw --pack",
65
- "build": "tsup --tsconfig tsconfig.prod.json"
63
+ "build": "tsdown --tsconfig tsconfig.prod.json"
66
64
  }
67
65
  }
@@ -1,214 +0,0 @@
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 type { Query } from '@tanstack/query-core';
5
- import type { QueryClient } from '@tanstack/query-core';
6
- import type { QueryFilters } from '@tanstack/query-core';
7
- import type { QueryFunctionContext } from '@tanstack/query-core';
8
- import type { QueryKey } from '@tanstack/query-core';
9
- import type { QueryState } from '@tanstack/query-core';
10
-
11
- declare interface AsyncStorage<TStorageValue = string> {
12
- getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>;
13
- setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>;
14
- removeItem: (key: string) => MaybePromise<void>;
15
- entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>;
16
- }
17
- export { AsyncStorage }
18
- export { AsyncStorage as AsyncStorage_alias_1 }
19
-
20
- /**
21
- * Warning: experimental feature.
22
- * This utility function enables fine-grained query persistence.
23
- * Simple add it as a `persister` parameter to `useQuery` or `defaultOptions` on `queryClient`.
24
- *
25
- * ```
26
- * useQuery({
27
- queryKey: ['myKey'],
28
- queryFn: fetcher,
29
- persister: createPersister({
30
- storage: localStorage,
31
- }),
32
- })
33
- ```
34
- */
35
- declare function experimental_createQueryPersister<TStorageValue = string>({ storage, buster, maxAge, serialize, deserialize, prefix, refetchOnRestore, filters, }: StoragePersisterOptions<TStorageValue>): {
36
- persisterFn: <T, TQueryKey extends QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>, ctx: QueryFunctionContext<TQueryKey>, query: Query) => Promise<T>;
37
- persistQuery: (query: Query) => Promise<void>;
38
- persistQueryByKey: (queryKey: QueryKey, queryClient: QueryClient) => Promise<void>;
39
- retrieveQuery: <T>(queryHash: string, afterRestoreMacroTask?: (persistedQuery: PersistedQuery) => void) => Promise<T | undefined>;
40
- persisterGc: () => Promise<void>;
41
- restoreQueries: (queryClient: QueryClient, filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
42
- removeQueries: (filters?: Pick<QueryFilters, "queryKey" | "exact">) => Promise<void>;
43
- };
44
- export { experimental_createQueryPersister }
45
- export { experimental_createQueryPersister as experimental_createQueryPersister_alias_1 }
46
-
47
- declare type MaybePromise<T> = T | Promise<T>;
48
- export { MaybePromise }
49
- export { MaybePromise as MaybePromise_alias_1 }
50
-
51
- declare interface PersistedClient {
52
- timestamp: number;
53
- buster: string;
54
- clientState: DehydratedState;
55
- }
56
- export { PersistedClient }
57
- export { PersistedClient as PersistedClient_alias_1 }
58
-
59
- declare interface PersistedQuery {
60
- buster: string;
61
- queryHash: string;
62
- queryKey: QueryKey;
63
- state: QueryState;
64
- }
65
- export { PersistedQuery }
66
- export { PersistedQuery as PersistedQuery_alias_1 }
67
-
68
- declare interface PersistedQueryClientRestoreOptions extends PersistQueryClientRootOptions {
69
- /** The max-allowed age of the cache in milliseconds.
70
- * If a persisted cache is found that is older than this
71
- * time, it will be discarded */
72
- maxAge?: number;
73
- /** The options passed to the hydrate function */
74
- hydrateOptions?: HydrateOptions;
75
- }
76
- export { PersistedQueryClientRestoreOptions }
77
- export { PersistedQueryClientRestoreOptions as PersistedQueryClientRestoreOptions_alias_1 }
78
-
79
- declare interface PersistedQueryClientSaveOptions extends PersistQueryClientRootOptions {
80
- /** The options passed to the dehydrate function */
81
- dehydrateOptions?: DehydrateOptions;
82
- }
83
- export { PersistedQueryClientSaveOptions }
84
- export { PersistedQueryClientSaveOptions as PersistedQueryClientSaveOptions_alias_1 }
85
-
86
- declare interface Persister {
87
- persistClient: (persistClient: PersistedClient) => Promisable<void>;
88
- restoreClient: () => Promisable<PersistedClient | undefined>;
89
- removeClient: () => Promisable<void>;
90
- }
91
- export { Persister }
92
- export { Persister as Persister_alias_1 }
93
-
94
- declare const PERSISTER_KEY_PREFIX = "tanstack-query";
95
- export { PERSISTER_KEY_PREFIX }
96
- export { PERSISTER_KEY_PREFIX as PERSISTER_KEY_PREFIX_alias_1 }
97
-
98
- /**
99
- * Restores persisted data to QueryCache and persists further changes.
100
- */
101
- declare function persistQueryClient(props: PersistQueryClientOptions): [() => void, Promise<void>];
102
- export { persistQueryClient }
103
- export { persistQueryClient as persistQueryClient_alias_1 }
104
-
105
- declare interface PersistQueryClientOptions extends PersistedQueryClientRestoreOptions, PersistedQueryClientSaveOptions, PersistQueryClientRootOptions {
106
- }
107
- export { PersistQueryClientOptions }
108
- export { PersistQueryClientOptions as PersistQueryClientOptions_alias_1 }
109
-
110
- /**
111
- * Restores persisted data to the QueryCache
112
- * - data obtained from persister.restoreClient
113
- * - data is hydrated using hydrateOptions
114
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
115
- */
116
- declare function persistQueryClientRestore({ queryClient, persister, maxAge, buster, hydrateOptions, }: PersistedQueryClientRestoreOptions): Promise<void>;
117
- export { persistQueryClientRestore }
118
- export { persistQueryClientRestore as persistQueryClientRestore_alias_1 }
119
-
120
- declare interface PersistQueryClientRootOptions {
121
- /** The QueryClient to persist */
122
- queryClient: QueryClient;
123
- /** The Persister interface for storing and restoring the cache
124
- * to/from a persisted location */
125
- persister: Persister;
126
- /** A unique string that can be used to forcefully
127
- * invalidate existing caches if they do not share the same buster string */
128
- buster?: string;
129
- }
130
- export { PersistQueryClientRootOptions }
131
- export { PersistQueryClientRootOptions as PersistQueryClientRootOptions_alias_1 }
132
-
133
- /**
134
- * Persists data from the QueryCache
135
- * - data dehydrated using dehydrateOptions
136
- * - data is persisted using persister.persistClient
137
- */
138
- declare function persistQueryClientSave({ queryClient, persister, buster, dehydrateOptions, }: PersistedQueryClientSaveOptions): Promise<void>;
139
- export { persistQueryClientSave }
140
- export { persistQueryClientSave as persistQueryClientSave_alias_1 }
141
-
142
- /**
143
- * Subscribe to QueryCache and MutationCache updates (for persisting)
144
- * @returns an unsubscribe function (to discontinue monitoring)
145
- */
146
- declare function persistQueryClientSubscribe(props: PersistedQueryClientSaveOptions): () => void;
147
- export { persistQueryClientSubscribe }
148
- export { persistQueryClientSubscribe as persistQueryClientSubscribe_alias_1 }
149
-
150
- declare type PersistRetryer = (props: {
151
- persistedClient: PersistedClient;
152
- error: Error;
153
- errorCount: number;
154
- }) => PersistedClient | undefined;
155
- export { PersistRetryer }
156
- export { PersistRetryer as PersistRetryer_alias_1 }
157
-
158
- declare type Promisable<T> = T | PromiseLike<T>;
159
- export { Promisable }
160
- export { Promisable as Promisable_alias_1 }
161
-
162
- declare const removeOldestQuery: PersistRetryer;
163
- export { removeOldestQuery }
164
- export { removeOldestQuery as removeOldestQuery_alias_1 }
165
-
166
- declare interface StoragePersisterOptions<TStorageValue = string> {
167
- /** The storage client used for setting and retrieving items from cache.
168
- * For SSR pass in `undefined`.
169
- */
170
- storage: AsyncStorage<TStorageValue> | undefined | null;
171
- /**
172
- * How to serialize the data to storage.
173
- * @default `JSON.stringify`
174
- */
175
- serialize?: (persistedQuery: PersistedQuery) => MaybePromise<TStorageValue>;
176
- /**
177
- * How to deserialize the data from storage.
178
- * @default `JSON.parse`
179
- */
180
- deserialize?: (cachedString: TStorageValue) => MaybePromise<PersistedQuery>;
181
- /**
182
- * A unique string that can be used to forcefully invalidate existing caches,
183
- * if they do not share the same buster string
184
- */
185
- buster?: string;
186
- /**
187
- * The max-allowed age of the cache in milliseconds.
188
- * If a persisted cache is found that is older than this
189
- * time, it will be discarded
190
- * @default 24 hours
191
- */
192
- maxAge?: number;
193
- /**
194
- * Prefix to be used for storage key.
195
- * Storage key is a combination of prefix and query hash in a form of `prefix-queryHash`.
196
- * @default 'tanstack-query'
197
- */
198
- prefix?: string;
199
- /**
200
- * If set to `true`, the query will refetch on successful query restoration if the data is stale.
201
- * If set to `false`, the query will not refetch on successful query restoration.
202
- * If set to `'always'`, the query will always refetch on successful query restoration.
203
- * Defaults to `true`.
204
- */
205
- refetchOnRestore?: boolean | 'always';
206
- /**
207
- * Filters to narrow down which Queries should be persisted.
208
- */
209
- filters?: QueryFilters;
210
- }
211
- export { StoragePersisterOptions }
212
- export { StoragePersisterOptions as StoragePersisterOptions_alias_1 }
213
-
214
- export { }