@tanstack/query-persist-client-core 5.101.4 → 5.102.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/createPersister.cjs +172 -256
- package/build/legacy/createPersister.cjs.map +1 -1
- package/build/legacy/createPersister.d.cts +88 -6
- package/build/legacy/createPersister.d.cts.map +1 -0
- package/build/legacy/createPersister.d.ts +88 -6
- package/build/legacy/createPersister.d.ts.map +1 -0
- package/build/legacy/createPersister.js +170 -235
- package/build/legacy/createPersister.js.map +1 -1
- package/build/legacy/index.cjs +14 -27
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +4 -19
- package/build/legacy/index.d.ts +4 -19
- package/build/legacy/index.js +8 -4
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/persist.cjs +82 -108
- package/build/legacy/persist.cjs.map +1 -1
- package/build/legacy/persist.d.cts +61 -11
- package/build/legacy/persist.d.cts.map +1 -0
- package/build/legacy/persist.d.ts +61 -11
- package/build/legacy/persist.d.ts.map +1 -0
- package/build/legacy/persist.js +77 -79
- package/build/legacy/persist.js.map +1 -1
- package/build/legacy/retryStrategies.cjs +20 -44
- package/build/legacy/retryStrategies.cjs.map +1 -1
- package/build/legacy/retryStrategies.d.cts +11 -2
- package/build/legacy/retryStrategies.d.cts.map +1 -0
- package/build/legacy/retryStrategies.d.ts +11 -2
- package/build/legacy/retryStrategies.d.ts.map +1 -0
- package/build/legacy/retryStrategies.js +20 -20
- package/build/legacy/retryStrategies.js.map +1 -1
- package/build/modern/createPersister.cjs +172 -256
- package/build/modern/createPersister.cjs.map +1 -1
- package/build/modern/createPersister.d.cts +88 -6
- package/build/modern/createPersister.d.cts.map +1 -0
- package/build/modern/createPersister.d.ts +88 -6
- package/build/modern/createPersister.d.ts.map +1 -0
- package/build/modern/createPersister.js +170 -235
- package/build/modern/createPersister.js.map +1 -1
- package/build/modern/index.cjs +14 -27
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +4 -19
- package/build/modern/index.d.ts +4 -19
- package/build/modern/index.js +8 -4
- package/build/modern/index.js.map +1 -1
- package/build/modern/persist.cjs +82 -108
- package/build/modern/persist.cjs.map +1 -1
- package/build/modern/persist.d.cts +61 -11
- package/build/modern/persist.d.cts.map +1 -0
- package/build/modern/persist.d.ts +61 -11
- package/build/modern/persist.d.ts.map +1 -0
- package/build/modern/persist.js +77 -79
- package/build/modern/persist.js.map +1 -1
- package/build/modern/retryStrategies.cjs +20 -44
- package/build/modern/retryStrategies.cjs.map +1 -1
- package/build/modern/retryStrategies.d.cts +11 -2
- package/build/modern/retryStrategies.d.cts.map +1 -0
- package/build/modern/retryStrategies.d.ts +11 -2
- package/build/modern/retryStrategies.d.ts.map +1 -0
- package/build/modern/retryStrategies.js +20 -20
- package/build/modern/retryStrategies.js.map +1 -1
- package/package.json +4 -6
- package/build/legacy/_tsup-dts-rollup.d.cts +0 -214
- package/build/legacy/_tsup-dts-rollup.d.ts +0 -214
- package/build/modern/_tsup-dts-rollup.d.cts +0 -214
- package/build/modern/_tsup-dts-rollup.d.ts +0 -214
package/build/legacy/persist.js
CHANGED
|
@@ -1,89 +1,87 @@
|
|
|
1
|
-
// src/persist.ts
|
|
2
1
|
import { dehydrate, hydrate } from "@tanstack/query-core";
|
|
3
|
-
|
|
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
|
-
|
|
13
|
+
return cacheEventTypes.includes(eventType);
|
|
6
14
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
persister
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return [unsubscribe, restorePromise];
|
|
74
|
+
let hasUnsubscribed = false;
|
|
75
|
+
let persistQueryClientUnsubscribe;
|
|
76
|
+
const unsubscribe = () => {
|
|
77
|
+
hasUnsubscribed = true;
|
|
78
|
+
persistQueryClientUnsubscribe === null || persistQueryClientUnsubscribe === void 0 || persistQueryClientUnsubscribe();
|
|
79
|
+
};
|
|
80
|
+
return [unsubscribe, persistQueryClientRestore(props).then(() => {
|
|
81
|
+
if (!hasUnsubscribed) persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
|
|
82
|
+
})];
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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":"
|
|
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,kCAAA,QAAA,kCAAA,KAAA,KAAA,8BAAgC;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
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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":"
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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":";
|
|
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"}
|