@tanstack/query-persist-client-core 4.36.1 → 4.39.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-persist-client-core",
3
- "version": "4.36.1",
3
+ "version": "4.39.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",
@@ -32,14 +32,7 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@tanstack/query-core": "4.36.1"
35
+ "@tanstack/query-core": "4.39.0"
36
36
  },
37
- "scripts": {
38
- "clean": "rimraf ./build",
39
- "test:eslint": "eslint --ext .ts,.tsx ./src",
40
- "test:types": "tsc",
41
- "test:lib": "jest --config ./jest.config.ts",
42
- "test:lib:dev": "pnpm run test:lib --watch",
43
- "build:types": "tsc --build"
44
- }
37
+ "scripts": {}
45
38
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"persist.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/persist.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAEV,SAAS,EACV,MAAM,qCAAqC,CAAA;AAE5C,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAGzE;AAED,eAAO,MAAM,UAAU;;;;CAItB,CAAA;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED,eAAO,MAAM,mBAAmB,QAAO,SAetC,CAAA;AAED,eAAO,MAAM,sBAAsB,QAAO,SAMzC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA"}
@@ -1,3 +0,0 @@
1
- export { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe } from './persist.esm.js';
2
- export { removeOldestQuery } from './retryStrategies.esm.js';
3
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var persist = require('./persist.js');
6
- var retryStrategies = require('./retryStrategies.js');
7
-
8
-
9
-
10
- exports.persistQueryClient = persist.persistQueryClient;
11
- exports.persistQueryClientRestore = persist.persistQueryClientRestore;
12
- exports.persistQueryClientSave = persist.persistQueryClientSave;
13
- exports.persistQueryClientSubscribe = persist.persistQueryClientSubscribe;
14
- exports.removeOldestQuery = retryStrategies.removeOldestQuery;
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- export { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe } from './persist.mjs';
2
- export { removeOldestQuery } from './retryStrategies.mjs';
3
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../../src/persist.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,WAAW,EACZ,MAAM,sBAAsB,CAAA;AAG7B,o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G;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,yBAAyB,GAC/B,CAAC,MAAM,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAiB7B"}
@@ -1,117 +0,0 @@
1
- import { hydrate, dehydrate } from '@tanstack/query-core';
2
-
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 cacheableEventTypes = ['added', 'removed', 'updated'];
8
-
9
- function isCacheableEventType(eventType) {
10
- return cacheableEventTypes.includes(eventType);
11
- }
12
- /**
13
- * Restores persisted data to the QueryCache
14
- * - data obtained from persister.restoreClient
15
- * - data is hydrated using hydrateOptions
16
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
17
- */
18
-
19
-
20
- async function persistQueryClientRestore({
21
- queryClient,
22
- persister,
23
- maxAge = 1000 * 60 * 60 * 24,
24
- buster = '',
25
- hydrateOptions
26
- }) {
27
- try {
28
- const persistedClient = await persister.restoreClient();
29
-
30
- if (persistedClient) {
31
- if (persistedClient.timestamp) {
32
- const expired = Date.now() - persistedClient.timestamp > maxAge;
33
- const busted = persistedClient.buster !== buster;
34
-
35
- if (expired || busted) {
36
- persister.removeClient();
37
- } else {
38
- hydrate(queryClient, persistedClient.clientState, hydrateOptions);
39
- }
40
- } else {
41
- persister.removeClient();
42
- }
43
- }
44
- } catch (err) {
45
- if (process.env.NODE_ENV !== 'production') {
46
- queryClient.getLogger().error(err);
47
- queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
48
- }
49
-
50
- persister.removeClient();
51
- }
52
- }
53
- /**
54
- * Persists data from the QueryCache
55
- * - data dehydrated using dehydrateOptions
56
- * - data is persisted using persister.persistClient
57
- */
58
-
59
- async function persistQueryClientSave({
60
- queryClient,
61
- persister,
62
- buster = '',
63
- dehydrateOptions
64
- }) {
65
- const persistClient = {
66
- buster,
67
- timestamp: Date.now(),
68
- clientState: dehydrate(queryClient, dehydrateOptions)
69
- };
70
- await persister.persistClient(persistClient);
71
- }
72
- /**
73
- * Subscribe to QueryCache and MutationCache updates (for persisting)
74
- * @returns an unsubscribe function (to discontinue monitoring)
75
- */
76
-
77
- function persistQueryClientSubscribe(props) {
78
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
79
- if (isCacheableEventType(event.type)) {
80
- persistQueryClientSave(props);
81
- }
82
- });
83
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
84
- if (isCacheableEventType(event.type)) {
85
- persistQueryClientSave(props);
86
- }
87
- });
88
- return () => {
89
- unsubscribeQueryCache();
90
- unusbscribeMutationCache();
91
- };
92
- }
93
- /**
94
- * Restores persisted data to QueryCache and persists further changes.
95
- */
96
-
97
- function persistQueryClient(props) {
98
- let hasUnsubscribed = false;
99
- let persistQueryClientUnsubscribe;
100
-
101
- const unsubscribe = () => {
102
- hasUnsubscribed = true;
103
- persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
104
- }; // Attempt restore
105
-
106
-
107
- const restorePromise = persistQueryClientRestore(props).then(() => {
108
- if (!hasUnsubscribed) {
109
- // Subscribe to changes in the query cache to trigger the save
110
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
111
- }
112
- });
113
- return [unsubscribe, restorePromise];
114
- }
115
-
116
- export { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };
117
- //# sourceMappingURL=persist.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persist.esm.js","sources":["../../src/persist.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/query-core'\nimport type { NotifyEventType } from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient(persistClient: PersistedClient): Promisable<void>\n restoreClient(): Promisable<PersistedClient | undefined>\n removeClient(): Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClienRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions\n extends PersistQueryClienRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions\n extends PersistQueryClienRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClienRootOptions {}\n\n/**\n * 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 cacheableEventTypes: Array<NotifyEventType> = [\n 'added',\n 'removed',\n 'updated',\n]\n\nfunction isCacheableEventType(eventType: NotifyEventType) {\n return cacheableEventTypes.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 persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err)\n queryClient\n .getLogger()\n .warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.',\n )\n }\n persister.removeClient()\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions,\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unusbscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unusbscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions,\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n"],"names":["cacheableEventTypes","isCacheableEventType","eventType","includes","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","hydrate","clientState","err","process","env","NODE_ENV","getLogger","error","warn","persistQueryClientSave","dehydrateOptions","persistClient","dehydrate","persistQueryClientSubscribe","props","unsubscribeQueryCache","getQueryCache","subscribe","event","type","unusbscribeMutationCache","getMutationCache","persistQueryClient","hasUnsubscribed","persistQueryClientUnsubscribe","unsubscribe","restorePromise","then"],"mappings":";;AAuDA;AACA;AACA;AACA;AACA,MAAMA,mBAA2C,GAAG,CAClD,OADkD,EAElD,SAFkD,EAGlD,SAHkD,CAApD,CAAA;;AAMA,SAASC,oBAAT,CAA8BC,SAA9B,EAA0D;AACxD,EAAA,OAAOF,mBAAmB,CAACG,QAApB,CAA6BD,SAA7B,CAAP,CAAA;AACD,CAAA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,eAAeE,yBAAf,CAAyC;EAC9CC,WAD8C;EAE9CC,SAF8C;AAG9CC,EAAAA,MAAM,GAAG,IAAO,GAAA,EAAP,GAAY,EAAZ,GAAiB,EAHoB;AAI9CC,EAAAA,MAAM,GAAG,EAJqC;AAK9CC,EAAAA,cAAAA;AAL8C,CAAzC,EAMgC;EACrC,IAAI;AACF,IAAA,MAAMC,eAAe,GAAG,MAAMJ,SAAS,CAACK,aAAV,EAA9B,CAAA;;AAEA,IAAA,IAAID,eAAJ,EAAqB;MACnB,IAAIA,eAAe,CAACE,SAApB,EAA+B;QAC7B,MAAMC,OAAO,GAAGC,IAAI,CAACC,GAAL,KAAaL,eAAe,CAACE,SAA7B,GAAyCL,MAAzD,CAAA;AACA,QAAA,MAAMS,MAAM,GAAGN,eAAe,CAACF,MAAhB,KAA2BA,MAA1C,CAAA;;QACA,IAAIK,OAAO,IAAIG,MAAf,EAAuB;AACrBV,UAAAA,SAAS,CAACW,YAAV,EAAA,CAAA;AACD,SAFD,MAEO;UACLC,OAAO,CAACb,WAAD,EAAcK,eAAe,CAACS,WAA9B,EAA2CV,cAA3C,CAAP,CAAA;AACD,SAAA;AACF,OARD,MAQO;AACLH,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8B,CAEnBC,KAAD,IAAW;AACpB,IAAA,IAAInC,oBAAoB,CAACmC,KAAK,CAACC,IAAP,CAAxB,EAAsC;MACpCV,sBAAsB,CAACK,KAAD,CAAtB,CAAA;AACD,KAAA;AACF,GAN8B,CAAjC,CAAA;AAQA,EAAA,OAAO,MAAM;IACXC,qBAAqB,EAAA,CAAA;IACrBK,wBAAwB,EAAA,CAAA;GAF1B,CAAA;AAID,CAAA;AAED;AACA;AACA;;AACO,SAASE,kBAAT,CACLR,KADK,EAEwB;EAC7B,IAAIS,eAAe,GAAG,KAAtB,CAAA;AACA,EAAA,IAAIC,6BAAJ,CAAA;;EACA,MAAMC,WAAW,GAAG,MAAM;AACxBF,IAAAA,eAAe,GAAG,IAAlB,CAAA;IACAC,6BAA6B,IAAA,IAA7B,YAAAA,6BAA6B,EAAA,CAAA;AAC9B,GAHD,CAH6B;;;EAS7B,MAAME,cAAc,GAAGxC,yBAAyB,CAAC4B,KAAD,CAAzB,CAAiCa,IAAjC,CAAsC,MAAM;IACjE,IAAI,CAACJ,eAAL,EAAsB;AACpB;AACAC,MAAAA,6BAA6B,GAAGX,2BAA2B,CAACC,KAAD,CAA3D,CAAA;AACD,KAAA;AACF,GALsB,CAAvB,CAAA;AAOA,EAAA,OAAO,CAACW,WAAD,EAAcC,cAAd,CAAP,CAAA;AACD;;;;"}
@@ -1,124 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var queryCore = require('@tanstack/query-core');
6
-
7
- /**
8
- * Checks if emitted event is about cache change and not about observers.
9
- * Useful for persist, where we only want to trigger save when cache is changed.
10
- */
11
- const cacheableEventTypes = ['added', 'removed', 'updated'];
12
-
13
- function isCacheableEventType(eventType) {
14
- return cacheableEventTypes.includes(eventType);
15
- }
16
- /**
17
- * Restores persisted data to the QueryCache
18
- * - data obtained from persister.restoreClient
19
- * - data is hydrated using hydrateOptions
20
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
21
- */
22
-
23
-
24
- async function persistQueryClientRestore({
25
- queryClient,
26
- persister,
27
- maxAge = 1000 * 60 * 60 * 24,
28
- buster = '',
29
- hydrateOptions
30
- }) {
31
- try {
32
- const persistedClient = await persister.restoreClient();
33
-
34
- if (persistedClient) {
35
- if (persistedClient.timestamp) {
36
- const expired = Date.now() - persistedClient.timestamp > maxAge;
37
- const busted = persistedClient.buster !== buster;
38
-
39
- if (expired || busted) {
40
- persister.removeClient();
41
- } else {
42
- queryCore.hydrate(queryClient, persistedClient.clientState, hydrateOptions);
43
- }
44
- } else {
45
- persister.removeClient();
46
- }
47
- }
48
- } catch (err) {
49
- if (process.env.NODE_ENV !== 'production') {
50
- queryClient.getLogger().error(err);
51
- queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
52
- }
53
-
54
- persister.removeClient();
55
- }
56
- }
57
- /**
58
- * Persists data from the QueryCache
59
- * - data dehydrated using dehydrateOptions
60
- * - data is persisted using persister.persistClient
61
- */
62
-
63
- async function persistQueryClientSave({
64
- queryClient,
65
- persister,
66
- buster = '',
67
- dehydrateOptions
68
- }) {
69
- const persistClient = {
70
- buster,
71
- timestamp: Date.now(),
72
- clientState: queryCore.dehydrate(queryClient, dehydrateOptions)
73
- };
74
- await persister.persistClient(persistClient);
75
- }
76
- /**
77
- * Subscribe to QueryCache and MutationCache updates (for persisting)
78
- * @returns an unsubscribe function (to discontinue monitoring)
79
- */
80
-
81
- function persistQueryClientSubscribe(props) {
82
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
83
- if (isCacheableEventType(event.type)) {
84
- persistQueryClientSave(props);
85
- }
86
- });
87
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
88
- if (isCacheableEventType(event.type)) {
89
- persistQueryClientSave(props);
90
- }
91
- });
92
- return () => {
93
- unsubscribeQueryCache();
94
- unusbscribeMutationCache();
95
- };
96
- }
97
- /**
98
- * Restores persisted data to QueryCache and persists further changes.
99
- */
100
-
101
- function persistQueryClient(props) {
102
- let hasUnsubscribed = false;
103
- let persistQueryClientUnsubscribe;
104
-
105
- const unsubscribe = () => {
106
- hasUnsubscribed = true;
107
- persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
108
- }; // Attempt restore
109
-
110
-
111
- const restorePromise = persistQueryClientRestore(props).then(() => {
112
- if (!hasUnsubscribed) {
113
- // Subscribe to changes in the query cache to trigger the save
114
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
115
- }
116
- });
117
- return [unsubscribe, restorePromise];
118
- }
119
-
120
- exports.persistQueryClient = persistQueryClient;
121
- exports.persistQueryClientRestore = persistQueryClientRestore;
122
- exports.persistQueryClientSave = persistQueryClientSave;
123
- exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
124
- //# sourceMappingURL=persist.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persist.js","sources":["../../src/persist.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/query-core'\nimport type { NotifyEventType } from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient(persistClient: PersistedClient): Promisable<void>\n restoreClient(): Promisable<PersistedClient | undefined>\n removeClient(): Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClienRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions\n extends PersistQueryClienRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions\n extends PersistQueryClienRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClienRootOptions {}\n\n/**\n * 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 cacheableEventTypes: Array<NotifyEventType> = [\n 'added',\n 'removed',\n 'updated',\n]\n\nfunction isCacheableEventType(eventType: NotifyEventType) {\n return cacheableEventTypes.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 persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err)\n queryClient\n .getLogger()\n .warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.',\n )\n }\n persister.removeClient()\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions,\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unusbscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unusbscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions,\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n"],"names":["cacheableEventTypes","isCacheableEventType","eventType","includes","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","hydrate","clientState","err","process","env","NODE_ENV","getLogger","error","warn","persistQueryClientSave","dehydrateOptions","persistClient","dehydrate","persistQueryClientSubscribe","props","unsubscribeQueryCache","getQueryCache","subscribe","event","type","unusbscribeMutationCache","getMutationCache","persistQueryClient","hasUnsubscribed","persistQueryClientUnsubscribe","unsubscribe","restorePromise","then"],"mappings":";;;;;;AAuDA;AACA;AACA;AACA;AACA,MAAMA,mBAA2C,GAAG,CAClD,OADkD,EAElD,SAFkD,EAGlD,SAHkD,CAApD,CAAA;;AAMA,SAASC,oBAAT,CAA8BC,SAA9B,EAA0D;AACxD,EA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,CAAA;;EACA,MAAMC,WAAW,GAAG,MAAM;AACxBF,IAAAA,eAAe,GAAG,IAAlB,CAAA;IACAC,6BAA6B,IAAA,IAA7B,YAAAA,6BAA6B,EAAA,CAAA;AAC9B,GAHD,CAH6B;;;EAS7B,MAAME,cAAc,GAAGxC,yBAAyB,CAAC4B,KAAD,CAAzB,CAAiCa,IAAjC,CAAsC,MAAM;IACjE,IAAI,CAACJ,eAAL,EAAsB;AACpB;AACAC,MAAAA,6BAA6B,GAAGX,2BAA2B,CAACC,KAAD,CAA3D,CAAA;AACD,KAAA;AACF,GALsB,CAAvB,CAAA;AAOA,EAAA,OAAO,CAACW,WAAD,EAAcC,cAAd,CAAP,CAAA;AACD;;;;;;;"}
@@ -1,117 +0,0 @@
1
- import { hydrate, dehydrate } from '@tanstack/query-core';
2
-
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 cacheableEventTypes = ['added', 'removed', 'updated'];
8
-
9
- function isCacheableEventType(eventType) {
10
- return cacheableEventTypes.includes(eventType);
11
- }
12
- /**
13
- * Restores persisted data to the QueryCache
14
- * - data obtained from persister.restoreClient
15
- * - data is hydrated using hydrateOptions
16
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
17
- */
18
-
19
-
20
- async function persistQueryClientRestore({
21
- queryClient,
22
- persister,
23
- maxAge = 1000 * 60 * 60 * 24,
24
- buster = '',
25
- hydrateOptions
26
- }) {
27
- try {
28
- const persistedClient = await persister.restoreClient();
29
-
30
- if (persistedClient) {
31
- if (persistedClient.timestamp) {
32
- const expired = Date.now() - persistedClient.timestamp > maxAge;
33
- const busted = persistedClient.buster !== buster;
34
-
35
- if (expired || busted) {
36
- persister.removeClient();
37
- } else {
38
- hydrate(queryClient, persistedClient.clientState, hydrateOptions);
39
- }
40
- } else {
41
- persister.removeClient();
42
- }
43
- }
44
- } catch (err) {
45
- if (process.env.NODE_ENV !== 'production') {
46
- queryClient.getLogger().error(err);
47
- queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
48
- }
49
-
50
- persister.removeClient();
51
- }
52
- }
53
- /**
54
- * Persists data from the QueryCache
55
- * - data dehydrated using dehydrateOptions
56
- * - data is persisted using persister.persistClient
57
- */
58
-
59
- async function persistQueryClientSave({
60
- queryClient,
61
- persister,
62
- buster = '',
63
- dehydrateOptions
64
- }) {
65
- const persistClient = {
66
- buster,
67
- timestamp: Date.now(),
68
- clientState: dehydrate(queryClient, dehydrateOptions)
69
- };
70
- await persister.persistClient(persistClient);
71
- }
72
- /**
73
- * Subscribe to QueryCache and MutationCache updates (for persisting)
74
- * @returns an unsubscribe function (to discontinue monitoring)
75
- */
76
-
77
- function persistQueryClientSubscribe(props) {
78
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
79
- if (isCacheableEventType(event.type)) {
80
- persistQueryClientSave(props);
81
- }
82
- });
83
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
84
- if (isCacheableEventType(event.type)) {
85
- persistQueryClientSave(props);
86
- }
87
- });
88
- return () => {
89
- unsubscribeQueryCache();
90
- unusbscribeMutationCache();
91
- };
92
- }
93
- /**
94
- * Restores persisted data to QueryCache and persists further changes.
95
- */
96
-
97
- function persistQueryClient(props) {
98
- let hasUnsubscribed = false;
99
- let persistQueryClientUnsubscribe;
100
-
101
- const unsubscribe = () => {
102
- hasUnsubscribed = true;
103
- persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
104
- }; // Attempt restore
105
-
106
-
107
- const restorePromise = persistQueryClientRestore(props).then(() => {
108
- if (!hasUnsubscribed) {
109
- // Subscribe to changes in the query cache to trigger the save
110
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
111
- }
112
- });
113
- return [unsubscribe, restorePromise];
114
- }
115
-
116
- export { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };
117
- //# sourceMappingURL=persist.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"persist.mjs","sources":["../../src/persist.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/query-core'\nimport type { NotifyEventType } from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient(persistClient: PersistedClient): Promisable<void>\n restoreClient(): Promisable<PersistedClient | undefined>\n removeClient(): Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClienRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions\n extends PersistQueryClienRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions\n extends PersistQueryClienRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClienRootOptions {}\n\n/**\n * 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 cacheableEventTypes: Array<NotifyEventType> = [\n 'added',\n 'removed',\n 'updated',\n]\n\nfunction isCacheableEventType(eventType: NotifyEventType) {\n return cacheableEventTypes.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 persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err)\n queryClient\n .getLogger()\n .warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.',\n )\n }\n persister.removeClient()\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions,\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unusbscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unusbscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions,\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n"],"names":["cacheableEventTypes","isCacheableEventType","eventType","includes","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","hydrate","clientState","err","process","env","NODE_ENV","getLogger","error","warn","persistQueryClientSave","dehydrateOptions","persistClient","dehydrate","persistQueryClientSubscribe","props","unsubscribeQueryCache","getQueryCache","subscribe","event","type","unusbscribeMutationCache","getMutationCache","persistQueryClient","hasUnsubscribed","persistQueryClientUnsubscribe","unsubscribe","restorePromise","then"],"mappings":";;AAuDA;AACA;AACA;AACA;AACA,MAAMA,mBAA2C,GAAG,CAClD,OADkD,EAElD,SAFkD,EAGlD,SAHkD,CAApD,CAAA;;AAMA,SAASC,oBAAT,CAA8BC,SAA9B,EAA0D;AACxD,EAAA,OAAOF,mBAAmB,CAACG,QAApB,CAA6BD,SAA7B,CAAP,CAAA;AACD,CAAA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,eAAeE,yBAAf,CAAyC;EAC9CC,WAD8C;EAE9CC,SAF8C;AAG9CC,EAAAA,MAAM,GAAG,IAAO,GAAA,EAAP,GAAY,EAAZ,GAAiB,EAHoB;AAI9CC,EAAAA,MAAM,GAAG,EAJqC;AAK9CC,EAAAA,cAAAA;AAL8C,CAAzC,EAMgC;EACrC,IAAI;AACF,IAAA,MAAMC,eAAe,GAAG,MAAMJ,SAAS,CAACK,aAAV,EAA9B,CAAA;;AAEA,IAAA,IAAID,eAAJ,EAAqB;MACnB,IAAIA,eAAe,CAACE,SAApB,EAA+B;QAC7B,MAAMC,OAAO,GAAGC,IAAI,CAACC,GAAL,KAAaL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ategies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAE1E,oBAAY,cAAc,GAAG,CAAC,KAAK,EAAE;IACnC,eAAe,EAAE,eAAe,CAAA;IAChC,KAAK,EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB,KAAK,eAAe,GAAG,SAAS,CAAA;AAEjC,eAAO,MAAM,iBAAiB,EAAE,cAqB/B,CAAA"}
@@ -1,25 +0,0 @@
1
- const removeOldestQuery = ({
2
- persistedClient
3
- }) => {
4
- const mutations = [...persistedClient.clientState.mutations];
5
- const queries = [...persistedClient.clientState.queries];
6
- const client = { ...persistedClient,
7
- clientState: {
8
- mutations,
9
- queries
10
- }
11
- }; // sort queries by dataUpdatedAt (oldest first)
12
-
13
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query
14
-
15
- if (sortedQueries.length > 0) {
16
- const oldestData = sortedQueries.shift();
17
- client.clientState.queries = queries.filter(q => q !== oldestData);
18
- return client;
19
- }
20
-
21
- return undefined;
22
- };
23
-
24
- export { removeOldestQuery };
25
- //# sourceMappingURL=retryStrategies.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retryStrategies.esm.js","sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from '@tanstack/query-persist-client-core'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"names":["removeOldestQuery","persistedClient","mutations","clientState","queries","client","sortedQueries","sort","a","b","state","dataUpdatedAt","length","oldestData","shift","filter","q","undefined"],"mappings":"AAQO,MAAMA,iBAAiC,GAAG,CAAC;AAAEC,EAAAA,eAAAA;AAAF,CAAD,KAAyB;EACxE,MAAMC,SAAS,GAAG,CAAC,GAAGD,eAAe,CAACE,WAAhB,CAA4BD,SAAhC,CAAlB,CAAA;EACA,MAAME,OAAO,GAAG,CAAC,GAAGH,eAAe,CAACE,WAAhB,CAA4BC,OAAhC,CAAhB,CAAA;AACA,EAAA,MAAMC,MAAuB,GAAG,EAC9B,GAAGJ,eAD2B;AAE9BE,IAAAA,WAAW,EAAE;MAAED,SAAF;AAAaE,MAAAA,OAAAA;AAAb,KAAA;AAFiB,GAAhC,CAHwE;;EASxE,MAAME,aAAa,GAAG,CAAC,GAAGF,OAAJ,CAAaG,CAAAA,IAAb,CACpB,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACE,KAAF,CAAQC,aAAR,GAAwBF,CAAC,CAACC,KAAF,CAAQC,aADtB,CAAtB,CATwE;;AAcxE,EAAA,IAAIL,aAAa,CAACM,MAAd,GAAuB,CAA3B,EAA8B;AAC5B,IAAA,MAAMC,UAAU,GAAGP,aAAa,CAACQ,KAAd,EAAnB,CAAA;AACAT,IAAAA,MAAM,CAACF,WAAP,CAAmBC,OAAnB,GAA6BA,OAAO,CAACW,MAAR,CAAgBC,CAAD,IAAOA,CAAC,KAAKH,UAA5B,CAA7B,CAAA;AACA,IAAA,OAAOR,MAAP,CAAA;AACD,GAAA;;AAED,EAAA,OAAOY,SAAP,CAAA;AACD;;;;"}
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const removeOldestQuery = ({
6
- persistedClient
7
- }) => {
8
- const mutations = [...persistedClient.clientState.mutations];
9
- const queries = [...persistedClient.clientState.queries];
10
- const client = { ...persistedClient,
11
- clientState: {
12
- mutations,
13
- queries
14
- }
15
- }; // sort queries by dataUpdatedAt (oldest first)
16
-
17
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query
18
-
19
- if (sortedQueries.length > 0) {
20
- const oldestData = sortedQueries.shift();
21
- client.clientState.queries = queries.filter(q => q !== oldestData);
22
- return client;
23
- }
24
-
25
- return undefined;
26
- };
27
-
28
- exports.removeOldestQuery = removeOldestQuery;
29
- //# sourceMappingURL=retryStrategies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retryStrategies.js","sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from '@tanstack/query-persist-client-core'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"names":["removeOldestQuery","persistedClient","mutations","clientState","queries","client","sortedQueries","sort","a","b","state","dataUpdatedAt","length","oldestData","shift","filter","q","undefined"],"mappings":";;;;AAQO,MAAMA,iBAAiC,GAAG,CAAC;AAAEC,EAAAA,eAAAA;AAAF,CAAD,KAAyB;EACxE,MAAMC,SAAS,GAAG,CAAC,GAAGD,eAAe,CAACE,WAAhB,CAA4BD,SAAhC,CAAlB,CAAA;EACA,MAAME,OAAO,GAAG,CAAC,GAAGH,eAAe,CAACE,WAAhB,CAA4BC,OAAhC,CAAhB,CAAA;AACA,EAAA,MAAMC,MAAuB,GAAG,EAC9B,GAAGJ,eAD2B;AAE9BE,IAAAA,WAAW,EAAE;MAAED,SAAF;AAAaE,MAAAA,OAAAA;AAAb,KAAA;AAFiB,GAAhC,CAHwE;;EASxE,MAAME,aAAa,GAAG,CAAC,GAAGF,OAAJ,CAAaG,CAAAA,IAAb,CACpB,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACE,KAAF,CAAQC,aAAR,GAAwBF,CAAC,CAACC,KAAF,CAAQC,aADtB,CAAtB,CATwE;;AAcxE,EAAA,IAAIL,aAAa,CAACM,MAAd,GAAuB,CAA3B,EAA8B;AAC5B,IAAA,MAAMC,UAAU,GAAGP,aAAa,CAACQ,KAAd,EAAnB,CAAA;AACAT,IAAAA,MAAM,CAACF,WAAP,CAAmBC,OAAnB,GAA6BA,OAAO,CAACW,MAAR,CAAgBC,CAAD,IAAOA,CAAC,KAAKH,UAA5B,CAA7B,CAAA;AACA,IAAA,OAAOR,MAAP,CAAA;AACD,GAAA;;AAED,EAAA,OAAOY,SAAP,CAAA;AACD;;;;"}
@@ -1,25 +0,0 @@
1
- const removeOldestQuery = ({
2
- persistedClient
3
- }) => {
4
- const mutations = [...persistedClient.clientState.mutations];
5
- const queries = [...persistedClient.clientState.queries];
6
- const client = { ...persistedClient,
7
- clientState: {
8
- mutations,
9
- queries
10
- }
11
- }; // sort queries by dataUpdatedAt (oldest first)
12
-
13
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query
14
-
15
- if (sortedQueries.length > 0) {
16
- const oldestData = sortedQueries.shift();
17
- client.clientState.queries = queries.filter(q => q !== oldestData);
18
- return client;
19
- }
20
-
21
- return undefined;
22
- };
23
-
24
- export { removeOldestQuery };
25
- //# sourceMappingURL=retryStrategies.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retryStrategies.mjs","sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from '@tanstack/query-persist-client-core'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"names":["removeOldestQuery","persistedClient","mutations","clientState","queries","client","sortedQueries","sort","a","b","state","dataUpdatedAt","length","oldestData","shift","filter","q","undefined"],"mappings":"AAQO,MAAMA,iBAAiC,GAAG,CAAC;AAAEC,EAAAA,eAAAA;AAAF,CAAD,KAAyB;EACxE,MAAMC,SAAS,GAAG,CAAC,GAAGD,eAAe,CAACE,WAAhB,CAA4BD,SAAhC,CAAlB,CAAA;EACA,MAAME,OAAO,GAAG,CAAC,GAAGH,eAAe,CAACE,WAAhB,CAA4BC,OAAhC,CAAhB,CAAA;AACA,EAAA,MAAMC,MAAuB,GAAG,EAC9B,GAAGJ,eAD2B;AAE9BE,IAAAA,WAAW,EAAE;MAAED,SAAF;AAAaE,MAAAA,OAAAA;AAAb,KAAA;AAFiB,GAAhC,CAHwE;;EASxE,MAAME,aAAa,GAAG,CAAC,GAAGF,OAAJ,CAAaG,CAAAA,IAAb,CACpB,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACE,KAAF,CAAQC,aAAR,GAAwBF,CAAC,CAACC,KAAF,CAAQC,aADtB,CAAtB,CATwE;;AAcxE,EAAA,IAAIL,aAAa,CAACM,MAAd,GAAuB,CAA3B,EAA8B;AAC5B,IAAA,MAAMC,UAAU,GAAGP,aAAa,CAACQ,KAAd,EAAnB,CAAA;AACAT,IAAAA,MAAM,CAACF,WAAP,CAAmBC,OAAnB,GAA6BA,OAAO,CAACW,MAAR,CAAgBC,CAAD,IAAOA,CAAC,KAAKH,UAA5B,CAA7B,CAAA;AACA,IAAA,OAAOR,MAAP,CAAA;AACD,GAAA;;AAED,EAAA,OAAOY,SAAP,CAAA;AACD;;;;"}
@@ -1,152 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tanstack/query-core')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tanstack/query-core'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.QueryPersistClientCore = {}, global.QueryCore));
5
- })(this, (function (exports, queryCore) { 'use strict';
6
-
7
- /**
8
- * Checks if emitted event is about cache change and not about observers.
9
- * Useful for persist, where we only want to trigger save when cache is changed.
10
- */
11
- const cacheableEventTypes = ['added', 'removed', 'updated'];
12
-
13
- function isCacheableEventType(eventType) {
14
- return cacheableEventTypes.includes(eventType);
15
- }
16
- /**
17
- * Restores persisted data to the QueryCache
18
- * - data obtained from persister.restoreClient
19
- * - data is hydrated using hydrateOptions
20
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
21
- */
22
-
23
-
24
- async function persistQueryClientRestore({
25
- queryClient,
26
- persister,
27
- maxAge = 1000 * 60 * 60 * 24,
28
- buster = '',
29
- hydrateOptions
30
- }) {
31
- try {
32
- const persistedClient = await persister.restoreClient();
33
-
34
- if (persistedClient) {
35
- if (persistedClient.timestamp) {
36
- const expired = Date.now() - persistedClient.timestamp > maxAge;
37
- const busted = persistedClient.buster !== buster;
38
-
39
- if (expired || busted) {
40
- persister.removeClient();
41
- } else {
42
- queryCore.hydrate(queryClient, persistedClient.clientState, hydrateOptions);
43
- }
44
- } else {
45
- persister.removeClient();
46
- }
47
- }
48
- } catch (err) {
49
- {
50
- queryClient.getLogger().error(err);
51
- queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
52
- }
53
-
54
- persister.removeClient();
55
- }
56
- }
57
- /**
58
- * Persists data from the QueryCache
59
- * - data dehydrated using dehydrateOptions
60
- * - data is persisted using persister.persistClient
61
- */
62
-
63
- async function persistQueryClientSave({
64
- queryClient,
65
- persister,
66
- buster = '',
67
- dehydrateOptions
68
- }) {
69
- const persistClient = {
70
- buster,
71
- timestamp: Date.now(),
72
- clientState: queryCore.dehydrate(queryClient, dehydrateOptions)
73
- };
74
- await persister.persistClient(persistClient);
75
- }
76
- /**
77
- * Subscribe to QueryCache and MutationCache updates (for persisting)
78
- * @returns an unsubscribe function (to discontinue monitoring)
79
- */
80
-
81
- function persistQueryClientSubscribe(props) {
82
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
83
- if (isCacheableEventType(event.type)) {
84
- persistQueryClientSave(props);
85
- }
86
- });
87
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
88
- if (isCacheableEventType(event.type)) {
89
- persistQueryClientSave(props);
90
- }
91
- });
92
- return () => {
93
- unsubscribeQueryCache();
94
- unusbscribeMutationCache();
95
- };
96
- }
97
- /**
98
- * Restores persisted data to QueryCache and persists further changes.
99
- */
100
-
101
- function persistQueryClient(props) {
102
- let hasUnsubscribed = false;
103
- let persistQueryClientUnsubscribe;
104
-
105
- const unsubscribe = () => {
106
- hasUnsubscribed = true;
107
- persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
108
- }; // Attempt restore
109
-
110
-
111
- const restorePromise = persistQueryClientRestore(props).then(() => {
112
- if (!hasUnsubscribed) {
113
- // Subscribe to changes in the query cache to trigger the save
114
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
115
- }
116
- });
117
- return [unsubscribe, restorePromise];
118
- }
119
-
120
- const removeOldestQuery = ({
121
- persistedClient
122
- }) => {
123
- const mutations = [...persistedClient.clientState.mutations];
124
- const queries = [...persistedClient.clientState.queries];
125
- const client = { ...persistedClient,
126
- clientState: {
127
- mutations,
128
- queries
129
- }
130
- }; // sort queries by dataUpdatedAt (oldest first)
131
-
132
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query
133
-
134
- if (sortedQueries.length > 0) {
135
- const oldestData = sortedQueries.shift();
136
- client.clientState.queries = queries.filter(q => q !== oldestData);
137
- return client;
138
- }
139
-
140
- return undefined;
141
- };
142
-
143
- exports.persistQueryClient = persistQueryClient;
144
- exports.persistQueryClientRestore = persistQueryClientRestore;
145
- exports.persistQueryClientSave = persistQueryClientSave;
146
- exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
147
- exports.removeOldestQuery = removeOldestQuery;
148
-
149
- Object.defineProperty(exports, '__esModule', { value: true });
150
-
151
- }));
152
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.development.js","sources":["../../src/persist.ts","../../src/retryStrategies.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/query-core'\nimport type { NotifyEventType } from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient(persistClient: PersistedClient): Promisable<void>\n restoreClient(): Promisable<PersistedClient | undefined>\n removeClient(): Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClienRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions\n extends PersistQueryClienRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions\n extends PersistQueryClienRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClienRootOptions {}\n\n/**\n * 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 cacheableEventTypes: Array<NotifyEventType> = [\n 'added',\n 'removed',\n 'updated',\n]\n\nfunction isCacheableEventType(eventType: NotifyEventType) {\n return cacheableEventTypes.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 persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err)\n queryClient\n .getLogger()\n .warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.',\n )\n }\n persister.removeClient()\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions,\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unusbscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unusbscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions,\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n","import type { PersistedClient } from '@tanstack/query-persist-client-core'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"names":["cacheableEventTypes","isCacheableEventType","eventType","includes","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","hydrate","clientState","err","getLogger","error","warn","persistQueryClientSave","dehydrateOptions","persistClient","dehydrate","persistQueryClientSubscribe","props","unsubscribeQueryCache","getQueryCache","subscribe","event","type","unusbscribeMutationCache","getMutationCache","persistQueryClient","hasUnsubscribed","persistQueryClientUnsubscribe","unsubscribe","restorePromise","then","removeOldestQuery","mutations","queries","client","sortedQueries","sort","a","b","state","dataUpdatedAt","length","oldestData","shift","filter","q","undefined"],"mappings":";;;;;;EAuDA;EACA;EACA;EACA;EACA,MAAMA,mBAA2C,GAAG,CAClD,OADkD,EAElD,SAFkD,EAGlD,SAHkD,CAApD,CAAA;;EAMA,SAASC,oBAAT,CAA8BC,SAA9B,EAA0D;EACxD,EAAA,OAAOF,mBAAmB,CAACG,QAApB,CAA6BD,SAA7B,CAAP,CAAA;EACD,CAAA;EAED;EACA;EACA;EACA;EACA;EACA;;;EACO,eAAeE,yBAAf,CAAyC;IAC9CC,WAD8C;IAE9CC,SAF8C;EAG9CC,EAAAA,MAAM,GAAG,IAAO,GAAA,EAAP,GAAY,EAAZ,GAAiB,EAHoB;EAI9CC,EAAAA,MAAM,GAAG,EAJqC;EAK9CC,EAAAA,cAAAA;EAL8C,CAAzC,EAMgC;IACrC,IAAI;EACF,IAAA,MAAMC,eAAe,GAAG,MAAMJ,SAAS,CAACK,aAAV,EAA9B,CAAA;;EAEA,IAAA,IAAID,eAAJ,EAAqB;QACnB,IAAIA,eAAe,CAACE,SAApB,EAA+B;UAC7B,MAAMC,OAAO,GAAGC,IAAI,CAACC,GAAL,KAAaL,eAAe,CAACE,SAA7B,GAAyCL,MAAzD,CAAA;EACA,QAAA,MAAMS,MAAM,GAAGN,eAAe,CAACF,MAAhB,KAA2BA,MAA1C,CAAA;;UACA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A,EAAA,MAAMC,MAAuB,GAAG,EAC9B,GAAGpC,eAD2B;EAE9BS,IAAAA,WAAW,EAAE;QAAEyB,SAAF;EAAaC,MAAAA,OAAAA;EAAb,KAAA;EAFiB,GAAhC,CAHwE;;IASxE,MAAME,aAAa,GAAG,CAAC,GAAGF,OAAJ,CAAaG,CAAAA,IAAb,CACpB,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACE,KAAF,CAAQC,aAAR,GAAwBF,CAAC,CAACC,KAAF,CAAQC,aADtB,CAAtB,CATwE;;EAcxE,EAAA,IAAIL,aAAa,CAACM,MAAd,GAAuB,CAA3B,EAA8B;EAC5B,IAAA,MAAMC,UAAU,GAAGP,aAAa,CAACQ,KAAd,EAAnB,CAAA;EACAT,IAAAA,MAAM,CAAC3B,WAAP,CAAmB0B,OAAnB,GAA6BA,OAAO,CAACW,MAAR,CAAgBC,CAAD,IAAOA,CAAC,KAAKH,UAA5B,CAA7B,CAAA;EACA,IAAA,OAAOR,MAAP,CAAA;EACD,GAAA;;EAED,EAAA,OAAOY,SAAP,CAAA;EACD;;;;;;;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/query-core")):"function"==typeof define&&define.amd?define(["exports","@tanstack/query-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QueryPersistClientCore={},e.QueryCore)}(this,(function(e,t){"use strict";const i=["added","removed","updated"];function n(e){return i.includes(e)}async function r({queryClient:e,persister:i,maxAge:n=864e5,buster:r="",hydrateOptions:s}){try{const u=await i.restoreClient();if(u)if(u.timestamp){const a=Date.now()-u.timestamp>n,o=u.buster!==r;a||o?i.removeClient():t.hydrate(e,u.clientState,s)}else i.removeClient()}catch(e){i.removeClient()}}async function s({queryClient:e,persister:i,buster:n="",dehydrateOptions:r}){const s={buster:n,timestamp:Date.now(),clientState:t.dehydrate(e,r)};await i.persistClient(s)}function u(e){const t=e.queryClient.getQueryCache().subscribe((t=>{n(t.type)&&s(e)})),i=e.queryClient.getMutationCache().subscribe((t=>{n(t.type)&&s(e)}));return()=>{t(),i()}}e.persistQueryClient=function(e){let t,i=!1;return[()=>{i=!0,null==t||t()},r(e).then((()=>{i||(t=u(e))}))]},e.persistQueryClientRestore=r,e.persistQueryClientSave=s,e.persistQueryClientSubscribe=u,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],i=[...e.clientState.queries],n={...e,clientState:{mutations:t,queries:i}},r=[...i].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(r.length>0){const e=r.shift();return n.clientState.queries=i.filter((t=>t!==e)),n}},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=index.production.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.production.js","sources":["../../src/persist.ts","../../src/retryStrategies.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n QueryClient,\n} from '@tanstack/query-core'\nimport type { NotifyEventType } from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient(persistClient: PersistedClient): Promisable<void>\n restoreClient(): Promisable<PersistedClient | undefined>\n removeClient(): Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClienRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions\n extends PersistQueryClienRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions\n extends PersistQueryClienRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClienRootOptions {}\n\n/**\n * 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 cacheableEventTypes: Array<NotifyEventType> = [\n 'added',\n 'removed',\n 'updated',\n]\n\nfunction isCacheableEventType(eventType: NotifyEventType) {\n return cacheableEventTypes.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 persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n queryClient.getLogger().error(err)\n queryClient\n .getLogger()\n .warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.',\n )\n }\n persister.removeClient()\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions,\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unusbscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unusbscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions,\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n","import type { PersistedClient } from '@tanstack/query-persist-client-core'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"names":["cacheableEventTypes","isCacheableEventType","eventType","includes","async","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","hydrate","clientState","err","persistQueryClientSave","dehydrateOptions","persistClient","dehydrate","persistQueryClientSubscribe","props","unsubscribeQueryCache","getQueryCache","subscribe","event","type","unusbscribeMutationCache","getMutationCache","persistQueryClientUnsubscribe","hasUnsubscribed","then","mutations","queries","client","sortedQueries","sort","a","b","state","dataUpdatedAt","length","oldestData","shift","filter","q"],"mappings":"mUA2DA,MAAMA,EAA8C,CAClD,QACA,UACA,WAGF,SAASC,EAAqBC,GAC5B,OAAOF,EAAoBG,SAASD,GAS/BE,eAAeC,GAA0BC,YAC9CA,EAD8CC,UAE9CA,EAF8CC,OAG9CA,EAAS,MAHqCC,OAI9CA,EAAS,GAJqCC,eAK9CA,IAEA,IACE,MAAMC,QAAwBJ,EAAUK,gBAExC,GAAID,EACF,GAAIA,EAAgBE,UAAW,CAC7B,MAAMC,EAAUC,KAAKC,MAAQL,EAAgBE,UAAYL,EACnDS,EAASN,EAAgBF,SAAWA,EACtCK,GAAWG,EACbV,EAAUW,eAEVC,EAAAA,QAAQb,EAAaK,EAAgBS,YAAaV,QAGpDH,EAAUW,eAGd,MAAOG,GASPd,EAAUW,gBASPd,eAAekB,GAAuBhB,YAC3CA,EAD2CC,UAE3CA,EAF2CE,OAG3CA,EAAS,GAHkCc,iBAI3CA,IAEA,MAAMC,EAAiC,CACrCf,SACAI,UAAWE,KAAKC,MAChBI,YAAaK,EAAAA,UAAUnB,EAAaiB,UAGhChB,EAAUiB,cAAcA,GAOzB,SAASE,EACdC,GAEA,MAAMC,EAAwBD,EAAMrB,YACjCuB,gBACAC,WAAWC,IACN9B,EAAqB8B,EAAMC,OAC7BV,EAAuBK,MAIvBM,EAA2BN,EAAMrB,YACpC4B,mBACAJ,WAAWC,IACN9B,EAAqB8B,EAAMC,OAC7BV,EAAuBK,MAI7B,MAAO,KACLC,IACAK,0BAOG,SACLN,GAEA,IACIQ,EADAC,GAAkB,EAetB,MAAO,C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