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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/build/legacy/createPersister.cjs +172 -256
  2. package/build/legacy/createPersister.cjs.map +1 -1
  3. package/build/legacy/createPersister.d.cts +88 -6
  4. package/build/legacy/createPersister.d.cts.map +1 -0
  5. package/build/legacy/createPersister.d.ts +88 -6
  6. package/build/legacy/createPersister.d.ts.map +1 -0
  7. package/build/legacy/createPersister.js +170 -235
  8. package/build/legacy/createPersister.js.map +1 -1
  9. package/build/legacy/index.cjs +14 -27
  10. package/build/legacy/index.cjs.map +1 -1
  11. package/build/legacy/index.d.cts +4 -19
  12. package/build/legacy/index.d.ts +4 -19
  13. package/build/legacy/index.js +8 -4
  14. package/build/legacy/index.js.map +1 -1
  15. package/build/legacy/persist.cjs +82 -108
  16. package/build/legacy/persist.cjs.map +1 -1
  17. package/build/legacy/persist.d.cts +61 -11
  18. package/build/legacy/persist.d.cts.map +1 -0
  19. package/build/legacy/persist.d.ts +61 -11
  20. package/build/legacy/persist.d.ts.map +1 -0
  21. package/build/legacy/persist.js +77 -79
  22. package/build/legacy/persist.js.map +1 -1
  23. package/build/legacy/retryStrategies.cjs +20 -44
  24. package/build/legacy/retryStrategies.cjs.map +1 -1
  25. package/build/legacy/retryStrategies.d.cts +11 -2
  26. package/build/legacy/retryStrategies.d.cts.map +1 -0
  27. package/build/legacy/retryStrategies.d.ts +11 -2
  28. package/build/legacy/retryStrategies.d.ts.map +1 -0
  29. package/build/legacy/retryStrategies.js +20 -20
  30. package/build/legacy/retryStrategies.js.map +1 -1
  31. package/build/modern/createPersister.cjs +172 -256
  32. package/build/modern/createPersister.cjs.map +1 -1
  33. package/build/modern/createPersister.d.cts +88 -6
  34. package/build/modern/createPersister.d.cts.map +1 -0
  35. package/build/modern/createPersister.d.ts +88 -6
  36. package/build/modern/createPersister.d.ts.map +1 -0
  37. package/build/modern/createPersister.js +170 -235
  38. package/build/modern/createPersister.js.map +1 -1
  39. package/build/modern/index.cjs +14 -27
  40. package/build/modern/index.cjs.map +1 -1
  41. package/build/modern/index.d.cts +4 -19
  42. package/build/modern/index.d.ts +4 -19
  43. package/build/modern/index.js +8 -4
  44. package/build/modern/index.js.map +1 -1
  45. package/build/modern/persist.cjs +82 -108
  46. package/build/modern/persist.cjs.map +1 -1
  47. package/build/modern/persist.d.cts +61 -11
  48. package/build/modern/persist.d.cts.map +1 -0
  49. package/build/modern/persist.d.ts +61 -11
  50. package/build/modern/persist.d.ts.map +1 -0
  51. package/build/modern/persist.js +77 -79
  52. package/build/modern/persist.js.map +1 -1
  53. package/build/modern/retryStrategies.cjs +20 -44
  54. package/build/modern/retryStrategies.cjs.map +1 -1
  55. package/build/modern/retryStrategies.d.cts +11 -2
  56. package/build/modern/retryStrategies.d.cts.map +1 -0
  57. package/build/modern/retryStrategies.d.ts +11 -2
  58. package/build/modern/retryStrategies.d.ts.map +1 -0
  59. package/build/modern/retryStrategies.js +20 -20
  60. package/build/modern/retryStrategies.js.map +1 -1
  61. package/package.json +4 -6
  62. package/build/legacy/_tsup-dts-rollup.d.cts +0 -214
  63. package/build/legacy/_tsup-dts-rollup.d.ts +0 -214
  64. package/build/modern/_tsup-dts-rollup.d.cts +0 -214
  65. package/build/modern/_tsup-dts-rollup.d.ts +0 -214
@@ -1,89 +1,87 @@
1
- // src/persist.ts
2
1
  import { dehydrate, hydrate } from "@tanstack/query-core";
3
- var cacheEventTypes = ["added", "removed", "updated"];
2
+ //#region src/persist.ts
3
+ /**
4
+ * Checks if emitted event is about cache change and not about observers.
5
+ * Useful for persist, where we only want to trigger save when cache is changed.
6
+ */
7
+ const cacheEventTypes = [
8
+ "added",
9
+ "removed",
10
+ "updated"
11
+ ];
4
12
  function isCacheEventType(eventType) {
5
- return cacheEventTypes.includes(eventType);
13
+ return cacheEventTypes.includes(eventType);
6
14
  }
7
- async function persistQueryClientRestore({
8
- queryClient,
9
- persister,
10
- maxAge = 1e3 * 60 * 60 * 24,
11
- buster = "",
12
- hydrateOptions
13
- }) {
14
- try {
15
- const persistedClient = await persister.restoreClient();
16
- if (persistedClient) {
17
- if (persistedClient.timestamp) {
18
- const expired = Date.now() - persistedClient.timestamp > maxAge;
19
- const busted = persistedClient.buster !== buster;
20
- if (expired || busted) {
21
- return persister.removeClient();
22
- } else {
23
- hydrate(queryClient, persistedClient.clientState, hydrateOptions);
24
- }
25
- } else {
26
- return persister.removeClient();
27
- }
28
- }
29
- } catch (err) {
30
- if (process.env.NODE_ENV !== "production") {
31
- console.error(err);
32
- console.warn(
33
- "Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded."
34
- );
35
- }
36
- await persister.removeClient();
37
- throw err;
38
- }
15
+ /**
16
+ * Restores persisted data to the QueryCache
17
+ * - data obtained from persister.restoreClient
18
+ * - data is hydrated using hydrateOptions
19
+ * If data is expired, busted, empty, or throws, it runs persister.removeClient
20
+ */
21
+ async function persistQueryClientRestore({ queryClient, persister, maxAge = 864e5, buster = "", hydrateOptions }) {
22
+ try {
23
+ const persistedClient = await persister.restoreClient();
24
+ if (persistedClient) {
25
+ if (persistedClient.timestamp) {
26
+ const expired = Date.now() - persistedClient.timestamp > maxAge;
27
+ const busted = persistedClient.buster !== buster;
28
+ if (expired || busted) return persister.removeClient();
29
+ else hydrate(queryClient, persistedClient.clientState, hydrateOptions);
30
+ } else return persister.removeClient();
31
+ }
32
+ } catch (err) {
33
+ if (process.env.NODE_ENV !== "production") {
34
+ console.error(err);
35
+ console.warn("Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.");
36
+ }
37
+ await persister.removeClient();
38
+ throw err;
39
+ }
39
40
  }
40
- async function persistQueryClientSave({
41
- queryClient,
42
- persister,
43
- buster = "",
44
- dehydrateOptions
45
- }) {
46
- const persistClient = {
47
- buster,
48
- timestamp: Date.now(),
49
- clientState: dehydrate(queryClient, dehydrateOptions)
50
- };
51
- await persister.persistClient(persistClient);
41
+ /**
42
+ * Persists data from the QueryCache
43
+ * - data dehydrated using dehydrateOptions
44
+ * - data is persisted using persister.persistClient
45
+ */
46
+ async function persistQueryClientSave({ queryClient, persister, buster = "", dehydrateOptions }) {
47
+ const persistClient = {
48
+ buster,
49
+ timestamp: Date.now(),
50
+ clientState: dehydrate(queryClient, dehydrateOptions)
51
+ };
52
+ await persister.persistClient(persistClient);
52
53
  }
54
+ /**
55
+ * Subscribe to QueryCache and MutationCache updates (for persisting)
56
+ * @returns an unsubscribe function (to discontinue monitoring)
57
+ */
53
58
  function persistQueryClientSubscribe(props) {
54
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe((event) => {
55
- if (isCacheEventType(event.type)) {
56
- persistQueryClientSave(props);
57
- }
58
- });
59
- const unsubscribeMutationCache = props.queryClient.getMutationCache().subscribe((event) => {
60
- if (isCacheEventType(event.type)) {
61
- persistQueryClientSave(props);
62
- }
63
- });
64
- return () => {
65
- unsubscribeQueryCache();
66
- unsubscribeMutationCache();
67
- };
59
+ const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe((event) => {
60
+ if (isCacheEventType(event.type)) persistQueryClientSave(props);
61
+ });
62
+ const unsubscribeMutationCache = props.queryClient.getMutationCache().subscribe((event) => {
63
+ if (isCacheEventType(event.type)) persistQueryClientSave(props);
64
+ });
65
+ return () => {
66
+ unsubscribeQueryCache();
67
+ unsubscribeMutationCache();
68
+ };
68
69
  }
70
+ /**
71
+ * Restores persisted data to QueryCache and persists further changes.
72
+ */
69
73
  function persistQueryClient(props) {
70
- let hasUnsubscribed = false;
71
- let persistQueryClientUnsubscribe;
72
- const unsubscribe = () => {
73
- hasUnsubscribed = true;
74
- persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe();
75
- };
76
- const restorePromise = persistQueryClientRestore(props).then(() => {
77
- if (!hasUnsubscribed) {
78
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
79
- }
80
- });
81
- return [unsubscribe, restorePromise];
74
+ let hasUnsubscribed = false;
75
+ let persistQueryClientUnsubscribe;
76
+ const unsubscribe = () => {
77
+ hasUnsubscribed = true;
78
+ persistQueryClientUnsubscribe === null || persistQueryClientUnsubscribe === void 0 || persistQueryClientUnsubscribe();
79
+ };
80
+ return [unsubscribe, persistQueryClientRestore(props).then(() => {
81
+ if (!hasUnsubscribed) persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
82
+ })];
82
83
  }
83
- export {
84
- persistQueryClient,
85
- persistQueryClientRestore,
86
- persistQueryClientSave,
87
- persistQueryClientSubscribe
88
- };
84
+ //#endregion
85
+ export { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };
86
+
89
87
  //# sourceMappingURL=persist.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/persist.ts"],"sourcesContent":["import { dehydrate, hydrate } from '@tanstack/query-core'\nimport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n NotifyEventType,\n QueryClient,\n} from '@tanstack/query-core'\n\nexport type Promisable<T> = T | PromiseLike<T>\n\nexport interface Persister {\n persistClient: (persistClient: PersistedClient) => Promisable<void>\n restoreClient: () => Promisable<PersistedClient | undefined>\n removeClient: () => Promisable<void>\n}\n\nexport interface PersistedClient {\n timestamp: number\n buster: string\n clientState: DehydratedState\n}\n\nexport interface PersistQueryClientRootOptions {\n /** The QueryClient to persist */\n queryClient: QueryClient\n /** The Persister interface for storing and restoring the cache\n * to/from a persisted location */\n persister: Persister\n /** A unique string that can be used to forcefully\n * invalidate existing caches if they do not share the same buster string */\n buster?: string\n}\n\nexport interface PersistedQueryClientRestoreOptions extends PersistQueryClientRootOptions {\n /** The max-allowed age of the cache in milliseconds.\n * If a persisted cache is found that is older than this\n * time, it will be discarded */\n maxAge?: number\n /** The options passed to the hydrate function */\n hydrateOptions?: HydrateOptions\n}\n\nexport interface PersistedQueryClientSaveOptions extends PersistQueryClientRootOptions {\n /** The options passed to the dehydrate function */\n dehydrateOptions?: DehydrateOptions\n}\n\nexport interface PersistQueryClientOptions\n extends\n PersistedQueryClientRestoreOptions,\n PersistedQueryClientSaveOptions,\n PersistQueryClientRootOptions {}\n\n/**\n * Checks if emitted event is about cache change and not about observers.\n * Useful for persist, where we only want to trigger save when cache is changed.\n */\nconst cacheEventTypes: Array<NotifyEventType> = ['added', 'removed', 'updated']\n\nfunction isCacheEventType(eventType: NotifyEventType) {\n return cacheEventTypes.includes(eventType)\n}\n\n/**\n * Restores persisted data to the QueryCache\n * - data obtained from persister.restoreClient\n * - data is hydrated using hydrateOptions\n * If data is expired, busted, empty, or throws, it runs persister.removeClient\n */\nexport async function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions,\n}: PersistedQueryClientRestoreOptions) {\n try {\n const persistedClient = await persister.restoreClient()\n\n if (persistedClient) {\n if (persistedClient.timestamp) {\n const expired = Date.now() - persistedClient.timestamp > maxAge\n const busted = persistedClient.buster !== buster\n if (expired || busted) {\n return persister.removeClient()\n } else {\n hydrate(queryClient, persistedClient.clientState, hydrateOptions)\n }\n } else {\n return persister.removeClient()\n }\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(err)\n console.warn(\n 'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.',\n )\n }\n\n await persister.removeClient()\n\n throw err\n }\n}\n\n/**\n * Persists data from the QueryCache\n * - data dehydrated using dehydrateOptions\n * - data is persisted using persister.persistClient\n */\nexport async function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions,\n}: PersistedQueryClientSaveOptions) {\n const persistClient: PersistedClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions),\n }\n\n await persister.persistClient(persistClient)\n}\n\n/**\n * Subscribe to QueryCache and MutationCache updates (for persisting)\n * @returns an unsubscribe function (to discontinue monitoring)\n */\nexport function persistQueryClientSubscribe(\n props: PersistedQueryClientSaveOptions,\n) {\n const unsubscribeQueryCache = props.queryClient\n .getQueryCache()\n .subscribe((event) => {\n if (isCacheEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n const unsubscribeMutationCache = props.queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (isCacheEventType(event.type)) {\n persistQueryClientSave(props)\n }\n })\n\n return () => {\n unsubscribeQueryCache()\n unsubscribeMutationCache()\n }\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nexport function persistQueryClient(\n props: PersistQueryClientOptions,\n): [() => void, Promise<void>] {\n let hasUnsubscribed = false\n let persistQueryClientUnsubscribe: (() => void) | undefined\n const unsubscribe = () => {\n hasUnsubscribed = true\n persistQueryClientUnsubscribe?.()\n }\n\n // Attempt restore\n const restorePromise = persistQueryClientRestore(props).then(() => {\n if (!hasUnsubscribed) {\n // Subscribe to changes in the query cache to trigger the save\n persistQueryClientUnsubscribe = persistQueryClientSubscribe(props)\n }\n })\n\n return [unsubscribe, restorePromise]\n}\n"],"mappings":";AAAA,SAAS,WAAW,eAAe;AA0DnC,IAAM,kBAA0C,CAAC,SAAS,WAAW,SAAS;AAE9E,SAAS,iBAAiB,WAA4B;AACpD,SAAO,gBAAgB,SAAS,SAAS;AAC3C;AAQA,eAAsB,0BAA0B;AAAA,EAC9C;AAAA,EACA;AAAA,EACA,SAAS,MAAO,KAAK,KAAK;AAAA,EAC1B,SAAS;AAAA,EACT;AACF,GAAuC;AACrC,MAAI;AACF,UAAM,kBAAkB,MAAM,UAAU,cAAc;AAEtD,QAAI,iBAAiB;AACnB,UAAI,gBAAgB,WAAW;AAC7B,cAAM,UAAU,KAAK,IAAI,IAAI,gBAAgB,YAAY;AACzD,cAAM,SAAS,gBAAgB,WAAW;AAC1C,YAAI,WAAW,QAAQ;AACrB,iBAAO,UAAU,aAAa;AAAA,QAChC,OAAO;AACL,kBAAQ,aAAa,gBAAgB,aAAa,cAAc;AAAA,QAClE;AAAA,MACF,OAAO;AACL,eAAO,UAAU,aAAa;AAAA,MAChC;AAAA,IACF;AAAA,EACF,SAAS,KAAK;AACZ,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAQ,MAAM,GAAG;AACjB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAU,aAAa;AAE7B,UAAM;AAAA,EACR;AACF;AAOA,eAAsB,uBAAuB;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AACF,GAAoC;AAClC,QAAM,gBAAiC;AAAA,IACrC;AAAA,IACA,WAAW,KAAK,IAAI;AAAA,IACpB,aAAa,UAAU,aAAa,gBAAgB;AAAA,EACtD;AAEA,QAAM,UAAU,cAAc,aAAa;AAC7C;AAMO,SAAS,4BACd,OACA;AACA,QAAM,wBAAwB,MAAM,YACjC,cAAc,EACd,UAAU,CAAC,UAAU;AACpB,QAAI,iBAAiB,MAAM,IAAI,GAAG;AAChC,6BAAuB,KAAK;AAAA,IAC9B;AAAA,EACF,CAAC;AAEH,QAAM,2BAA2B,MAAM,YACpC,iBAAiB,EACjB,UAAU,CAAC,UAAU;AACpB,QAAI,iBAAiB,MAAM,IAAI,GAAG;AAChC,6BAAuB,KAAK;AAAA,IAC9B;AAAA,EACF,CAAC;AAEH,SAAO,MAAM;AACX,0BAAsB;AACtB,6BAAyB;AAAA,EAC3B;AACF;AAKO,SAAS,mBACd,OAC6B;AAC7B,MAAI,kBAAkB;AACtB,MAAI;AACJ,QAAM,cAAc,MAAM;AACxB,sBAAkB;AAClB;AAAA,EACF;AAGA,QAAM,iBAAiB,0BAA0B,KAAK,EAAE,KAAK,MAAM;AACjE,QAAI,CAAC,iBAAiB;AAEpB,sCAAgC,4BAA4B,KAAK;AAAA,IACnE;AAAA,EACF,CAAC;AAED,SAAO,CAAC,aAAa,cAAc;AACrC;","names":[]}
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/retryStrategies.ts
3
+ const removeOldestQuery = ({ persistedClient }) => {
4
+ const mutations = [...persistedClient.clientState.mutations];
5
+ const queries = [...persistedClient.clientState.queries];
6
+ const client = {
7
+ ...persistedClient,
8
+ clientState: {
9
+ mutations,
10
+ queries
11
+ }
12
+ };
13
+ const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
14
+ if (sortedQueries.length > 0) {
15
+ const oldestData = sortedQueries.shift();
16
+ client.clientState.queries = queries.filter((q) => q !== oldestData);
17
+ return client;
18
+ }
9
19
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ //#endregion
21
+ exports.removeOldestQuery = removeOldestQuery;
19
22
 
20
- // src/retryStrategies.ts
21
- var retryStrategies_exports = {};
22
- __export(retryStrategies_exports, {
23
- removeOldestQuery: () => removeOldestQuery
24
- });
25
- module.exports = __toCommonJS(retryStrategies_exports);
26
- var removeOldestQuery = ({ persistedClient }) => {
27
- const mutations = [...persistedClient.clientState.mutations];
28
- const queries = [...persistedClient.clientState.queries];
29
- const client = {
30
- ...persistedClient,
31
- clientState: { mutations, queries }
32
- };
33
- const sortedQueries = [...queries].sort(
34
- (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt
35
- );
36
- if (sortedQueries.length > 0) {
37
- const oldestData = sortedQueries.shift();
38
- client.clientState.queries = queries.filter((q) => q !== oldestData);
39
- return client;
40
- }
41
- return void 0;
42
- };
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- removeOldestQuery
46
- });
47
23
  //# sourceMappingURL=retryStrategies.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from './persist'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,IAAM,oBAAoC,CAAC,EAAE,gBAAgB,MAAM;AACxE,QAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;AAC3D,QAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;AACvD,QAAM,SAA0B;AAAA,IAC9B,GAAG;AAAA,IACH,aAAa,EAAE,WAAW,QAAQ;AAAA,EACpC;AAGA,QAAM,gBAAgB,CAAC,GAAG,OAAO,EAAE;AAAA,IACjC,CAAC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM;AAAA,EAC5C;AAGA,MAAI,cAAc,SAAS,GAAG;AAC5B,UAAM,aAAa,cAAc,MAAM;AACvC,WAAO,YAAY,UAAU,QAAQ,OAAO,CAAC,MAAM,MAAM,UAAU;AACnE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"file":"retryStrategies.cjs","names":[],"sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from './persist'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"mappings":";;AAQA,MAAa,qBAAqC,EAAE,sBAAsB;CACxE,MAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;CAC3D,MAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;CACvD,MAAM,SAA0B;EAC9B,GAAG;EACH,aAAa;GAAE;GAAW;EAAQ;CACpC;CAGA,MAAM,gBAAgB,CAAC,GAAG,OAAO,CAAC,CAAC,MAChC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM,aAC5C;CAGA,IAAI,cAAc,SAAS,GAAG;EAC5B,MAAM,aAAa,cAAc,MAAM;EACvC,OAAO,YAAY,UAAU,QAAQ,QAAQ,MAAM,MAAM,UAAU;EACnE,OAAO;CACT;AAGF"}
@@ -1,2 +1,11 @@
1
- export { PersistRetryer_alias_1 as PersistRetryer } from './_tsup-dts-rollup.cjs';
2
- export { removeOldestQuery_alias_1 as removeOldestQuery } from './_tsup-dts-rollup.cjs';
1
+ import { PersistedClient } from "./persist.cjs";
2
+ //#region src/retryStrategies.d.ts
3
+ type PersistRetryer = (props: {
4
+ persistedClient: PersistedClient;
5
+ error: Error;
6
+ errorCount: number;
7
+ }) => PersistedClient | undefined;
8
+ declare const removeOldestQuery: PersistRetryer;
9
+ //#endregion
10
+ export { PersistRetryer, removeOldestQuery };
11
+ //# sourceMappingURL=retryStrategies.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryStrategies.d.cts","names":[],"sources":["../../src/retryStrategies.ts"],"mappings":";;KAEY,kBAAkB;EAC5B,iBAAiB;EACjB,OAAO;EACP;MACI;cAEO,mBAAmB"}
@@ -1,2 +1,11 @@
1
- export { PersistRetryer_alias_1 as PersistRetryer } from './_tsup-dts-rollup.js';
2
- export { removeOldestQuery_alias_1 as removeOldestQuery } from './_tsup-dts-rollup.js';
1
+ import { PersistedClient } from "./persist.js";
2
+ //#region src/retryStrategies.d.ts
3
+ type PersistRetryer = (props: {
4
+ persistedClient: PersistedClient;
5
+ error: Error;
6
+ errorCount: number;
7
+ }) => PersistedClient | undefined;
8
+ declare const removeOldestQuery: PersistRetryer;
9
+ //#endregion
10
+ export { PersistRetryer, removeOldestQuery };
11
+ //# sourceMappingURL=retryStrategies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryStrategies.d.ts","names":[],"sources":["../../src/retryStrategies.ts"],"mappings":";;KAEY,kBAAkB;EAC5B,iBAAiB;EACjB,OAAO;EACP;MACI;cAEO,mBAAmB"}
@@ -1,22 +1,22 @@
1
- // src/retryStrategies.ts
2
- var removeOldestQuery = ({ persistedClient }) => {
3
- const mutations = [...persistedClient.clientState.mutations];
4
- const queries = [...persistedClient.clientState.queries];
5
- const client = {
6
- ...persistedClient,
7
- clientState: { mutations, queries }
8
- };
9
- const sortedQueries = [...queries].sort(
10
- (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt
11
- );
12
- if (sortedQueries.length > 0) {
13
- const oldestData = sortedQueries.shift();
14
- client.clientState.queries = queries.filter((q) => q !== oldestData);
15
- return client;
16
- }
17
- return void 0;
18
- };
19
- export {
20
- removeOldestQuery
1
+ //#region src/retryStrategies.ts
2
+ const removeOldestQuery = ({ persistedClient }) => {
3
+ const mutations = [...persistedClient.clientState.mutations];
4
+ const queries = [...persistedClient.clientState.queries];
5
+ const client = {
6
+ ...persistedClient,
7
+ clientState: {
8
+ mutations,
9
+ queries
10
+ }
11
+ };
12
+ const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
13
+ if (sortedQueries.length > 0) {
14
+ const oldestData = sortedQueries.shift();
15
+ client.clientState.queries = queries.filter((q) => q !== oldestData);
16
+ return client;
17
+ }
21
18
  };
19
+ //#endregion
20
+ export { removeOldestQuery };
21
+
22
22
  //# sourceMappingURL=retryStrategies.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from './persist'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"mappings":";AAQO,IAAM,oBAAoC,CAAC,EAAE,gBAAgB,MAAM;AACxE,QAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;AAC3D,QAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;AACvD,QAAM,SAA0B;AAAA,IAC9B,GAAG;AAAA,IACH,aAAa,EAAE,WAAW,QAAQ;AAAA,EACpC;AAGA,QAAM,gBAAgB,CAAC,GAAG,OAAO,EAAE;AAAA,IACjC,CAAC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM;AAAA,EAC5C;AAGA,MAAI,cAAc,SAAS,GAAG;AAC5B,UAAM,aAAa,cAAc,MAAM;AACvC,WAAO,YAAY,UAAU,QAAQ,OAAO,CAAC,MAAM,MAAM,UAAU;AACnE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"file":"retryStrategies.js","names":[],"sources":["../../src/retryStrategies.ts"],"sourcesContent":["import type { PersistedClient } from './persist'\n\nexport type PersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => PersistedClient | undefined\n\nexport const removeOldestQuery: PersistRetryer = ({ persistedClient }) => {\n const mutations = [...persistedClient.clientState.mutations]\n const queries = [...persistedClient.clientState.queries]\n const client: PersistedClient = {\n ...persistedClient,\n clientState: { mutations, queries },\n }\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort(\n (a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt,\n )\n\n // clean oldest query\n if (sortedQueries.length > 0) {\n const oldestData = sortedQueries.shift()\n client.clientState.queries = queries.filter((q) => q !== oldestData)\n return client\n }\n\n return undefined\n}\n"],"mappings":";AAQA,MAAa,qBAAqC,EAAE,sBAAsB;CACxE,MAAM,YAAY,CAAC,GAAG,gBAAgB,YAAY,SAAS;CAC3D,MAAM,UAAU,CAAC,GAAG,gBAAgB,YAAY,OAAO;CACvD,MAAM,SAA0B;EAC9B,GAAG;EACH,aAAa;GAAE;GAAW;EAAQ;CACpC;CAGA,MAAM,gBAAgB,CAAC,GAAG,OAAO,CAAC,CAAC,MAChC,GAAG,MAAM,EAAE,MAAM,gBAAgB,EAAE,MAAM,aAC5C;CAGA,IAAI,cAAc,SAAS,GAAG;EAC5B,MAAM,aAAa,cAAc,MAAM;EACvC,OAAO,YAAY,UAAU,QAAQ,QAAQ,MAAM,MAAM,UAAU;EACnE,OAAO;CACT;AAGF"}