@tanstack/react-query-persist-client 5.0.0-alpha.9 → 5.0.0-alpha.91

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 (54) hide show
  1. package/build/legacy/PersistQueryClientProvider.cjs +80 -0
  2. package/build/legacy/PersistQueryClientProvider.cjs.map +1 -0
  3. package/build/legacy/PersistQueryClientProvider.d.cts +10 -0
  4. package/build/legacy/PersistQueryClientProvider.d.ts +10 -0
  5. package/build/legacy/PersistQueryClientProvider.js +46 -0
  6. package/build/legacy/PersistQueryClientProvider.js.map +1 -0
  7. package/build/legacy/index.cjs +27 -0
  8. package/build/legacy/index.cjs.map +1 -0
  9. package/build/legacy/index.d.cts +3 -0
  10. package/build/legacy/index.d.ts +3 -0
  11. package/build/legacy/index.js +4 -0
  12. package/build/legacy/index.js.map +1 -0
  13. package/build/modern/PersistQueryClientProvider.cjs +79 -0
  14. package/build/modern/PersistQueryClientProvider.cjs.map +1 -0
  15. package/build/modern/PersistQueryClientProvider.d.cts +10 -0
  16. package/build/modern/PersistQueryClientProvider.d.ts +10 -0
  17. package/build/modern/PersistQueryClientProvider.js +45 -0
  18. package/build/modern/PersistQueryClientProvider.js.map +1 -0
  19. package/build/modern/index.cjs +27 -0
  20. package/build/modern/index.cjs.map +1 -0
  21. package/build/modern/index.d.cts +3 -0
  22. package/build/modern/index.d.ts +3 -0
  23. package/build/modern/index.js +4 -0
  24. package/build/modern/index.js.map +1 -0
  25. package/package.json +24 -18
  26. package/src/PersistQueryClientProvider.tsx +9 -6
  27. package/src/__tests__/PersistQueryClientProvider.test.tsx +74 -9
  28. package/src/__tests__/utils.ts +2 -2
  29. package/build/lib/PersistQueryClientProvider.d.ts +0 -7
  30. package/build/lib/PersistQueryClientProvider.esm.js +0 -51
  31. package/build/lib/PersistQueryClientProvider.esm.js.map +0 -1
  32. package/build/lib/PersistQueryClientProvider.js +0 -72
  33. package/build/lib/PersistQueryClientProvider.js.map +0 -1
  34. package/build/lib/PersistQueryClientProvider.mjs +0 -51
  35. package/build/lib/PersistQueryClientProvider.mjs.map +0 -1
  36. package/build/lib/__tests__/PersistQueryClientProvider.test.d.ts +0 -1
  37. package/build/lib/__tests__/utils.d.ts +0 -7
  38. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -17
  39. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  40. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -19
  41. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  42. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -17
  43. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +0 -1
  44. package/build/lib/index.d.ts +0 -2
  45. package/build/lib/index.esm.js +0 -3
  46. package/build/lib/index.esm.js.map +0 -1
  47. package/build/lib/index.js +0 -15
  48. package/build/lib/index.js.map +0 -1
  49. package/build/lib/index.mjs +0 -3
  50. package/build/lib/index.mjs.map +0 -1
  51. package/build/umd/index.development.js +0 -320
  52. package/build/umd/index.development.js.map +0 -1
  53. package/build/umd/index.production.js +0 -2
  54. package/build/umd/index.production.js.map +0 -1
@@ -1,320 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@tanstack/react-query')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@tanstack/react-query'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React, global.ReactQuery));
5
- })(this, (function (exports, React, reactQuery) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
25
-
26
- // TYPES
27
-
28
- // FUNCTIONS
29
-
30
- function dehydrateMutation(mutation) {
31
- return {
32
- mutationKey: mutation.options.mutationKey,
33
- state: mutation.state
34
- };
35
- }
36
-
37
- // Most config is not dehydrated but instead meant to configure again when
38
- // consuming the de/rehydrated data, typically with useQuery on the client.
39
- // Sometimes it might make sense to prefetch data on the server and include
40
- // in the html-payload, but not consume it on the initial render.
41
- function dehydrateQuery(query) {
42
- return {
43
- state: query.state,
44
- queryKey: query.queryKey,
45
- queryHash: query.queryHash
46
- };
47
- }
48
- function defaultShouldDehydrateMutation(mutation) {
49
- return mutation.state.isPaused;
50
- }
51
- function defaultShouldDehydrateQuery(query) {
52
- return query.state.status === 'success';
53
- }
54
- function dehydrate(client, options = {}) {
55
- const mutations = [];
56
- const queries = [];
57
- if (options.dehydrateMutations !== false) {
58
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
59
- client.getMutationCache().getAll().forEach(mutation => {
60
- if (shouldDehydrateMutation(mutation)) {
61
- mutations.push(dehydrateMutation(mutation));
62
- }
63
- });
64
- }
65
- if (options.dehydrateQueries !== false) {
66
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
67
- client.getQueryCache().getAll().forEach(query => {
68
- if (shouldDehydrateQuery(query)) {
69
- queries.push(dehydrateQuery(query));
70
- }
71
- });
72
- }
73
- return {
74
- mutations,
75
- queries
76
- };
77
- }
78
- function hydrate(client, dehydratedState, options) {
79
- if (typeof dehydratedState !== 'object' || dehydratedState === null) {
80
- return;
81
- }
82
- const mutationCache = client.getMutationCache();
83
- const queryCache = client.getQueryCache();
84
-
85
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
86
- const mutations = dehydratedState.mutations || [];
87
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
88
- const queries = dehydratedState.queries || [];
89
- mutations.forEach(dehydratedMutation => {
90
- mutationCache.build(client, {
91
- ...options?.defaultOptions?.mutations,
92
- mutationKey: dehydratedMutation.mutationKey
93
- }, dehydratedMutation.state);
94
- });
95
- queries.forEach(dehydratedQuery => {
96
- const query = queryCache.get(dehydratedQuery.queryHash);
97
-
98
- // Reset fetch status to idle in the dehydrated state to avoid
99
- // query being stuck in fetching state upon hydration
100
- const dehydratedQueryState = {
101
- ...dehydratedQuery.state,
102
- fetchStatus: 'idle'
103
- };
104
-
105
- // Do not hydrate if an existing query exists with newer data
106
- if (query) {
107
- if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
108
- query.setState(dehydratedQueryState);
109
- }
110
- return;
111
- }
112
-
113
- // Restore query
114
- queryCache.build(client, {
115
- ...options?.defaultOptions?.queries,
116
- queryKey: dehydratedQuery.queryKey,
117
- queryHash: dehydratedQuery.queryHash
118
- }, dehydratedQueryState);
119
- });
120
- }
121
-
122
- /**
123
- * Checks if emitted event is about cache change and not about observers.
124
- * Useful for persist, where we only want to trigger save when cache is changed.
125
- */
126
- const cacheableEventTypes = ['added', 'removed', 'updated'];
127
- function isCacheableEventType(eventType) {
128
- return cacheableEventTypes.includes(eventType);
129
- }
130
-
131
- /**
132
- * Restores persisted data to the QueryCache
133
- * - data obtained from persister.restoreClient
134
- * - data is hydrated using hydrateOptions
135
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
136
- */
137
- async function persistQueryClientRestore({
138
- queryClient,
139
- persister,
140
- maxAge = 1000 * 60 * 60 * 24,
141
- buster = '',
142
- hydrateOptions
143
- }) {
144
- try {
145
- const persistedClient = await persister.restoreClient();
146
- if (persistedClient) {
147
- if (persistedClient.timestamp) {
148
- const expired = Date.now() - persistedClient.timestamp > maxAge;
149
- const busted = persistedClient.buster !== buster;
150
- if (expired || busted) {
151
- persister.removeClient();
152
- } else {
153
- hydrate(queryClient, persistedClient.clientState, hydrateOptions);
154
- }
155
- } else {
156
- persister.removeClient();
157
- }
158
- }
159
- } catch (err) {
160
- {
161
- console.error(err);
162
- console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
163
- }
164
- persister.removeClient();
165
- }
166
- }
167
-
168
- /**
169
- * Persists data from the QueryCache
170
- * - data dehydrated using dehydrateOptions
171
- * - data is persisted using persister.persistClient
172
- */
173
- async function persistQueryClientSave({
174
- queryClient,
175
- persister,
176
- buster = '',
177
- dehydrateOptions
178
- }) {
179
- const persistClient = {
180
- buster,
181
- timestamp: Date.now(),
182
- clientState: dehydrate(queryClient, dehydrateOptions)
183
- };
184
- await persister.persistClient(persistClient);
185
- }
186
-
187
- /**
188
- * Subscribe to QueryCache and MutationCache updates (for persisting)
189
- * @returns an unsubscribe function (to discontinue monitoring)
190
- */
191
- function persistQueryClientSubscribe(props) {
192
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
193
- if (isCacheableEventType(event.type)) {
194
- persistQueryClientSave(props);
195
- }
196
- });
197
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
198
- if (isCacheableEventType(event.type)) {
199
- persistQueryClientSave(props);
200
- }
201
- });
202
- return () => {
203
- unsubscribeQueryCache();
204
- unusbscribeMutationCache();
205
- };
206
- }
207
-
208
- /**
209
- * Restores persisted data to QueryCache and persists further changes.
210
- */
211
- function persistQueryClient(props) {
212
- let hasUnsubscribed = false;
213
- let persistQueryClientUnsubscribe;
214
- const unsubscribe = () => {
215
- hasUnsubscribed = true;
216
- persistQueryClientUnsubscribe?.();
217
- };
218
-
219
- // Attempt restore
220
- const restorePromise = persistQueryClientRestore(props).then(() => {
221
- if (!hasUnsubscribed) {
222
- // Subscribe to changes in the query cache to trigger the save
223
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
224
- }
225
- });
226
- return [unsubscribe, restorePromise];
227
- }
228
-
229
- const removeOldestQuery = ({
230
- persistedClient
231
- }) => {
232
- const mutations = [...persistedClient.clientState.mutations];
233
- const queries = [...persistedClient.clientState.queries];
234
- const client = {
235
- ...persistedClient,
236
- clientState: {
237
- mutations,
238
- queries
239
- }
240
- };
241
-
242
- // sort queries by dataUpdatedAt (oldest first)
243
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
244
-
245
- // clean oldest query
246
- if (sortedQueries.length > 0) {
247
- const oldestData = sortedQueries.shift();
248
- client.clientState.queries = queries.filter(q => q !== oldestData);
249
- return client;
250
- }
251
- return undefined;
252
- };
253
-
254
- function _extends() {
255
- _extends = Object.assign ? Object.assign.bind() : function (target) {
256
- for (var i = 1; i < arguments.length; i++) {
257
- var source = arguments[i];
258
- for (var key in source) {
259
- if (Object.prototype.hasOwnProperty.call(source, key)) {
260
- target[key] = source[key];
261
- }
262
- }
263
- }
264
- return target;
265
- };
266
- return _extends.apply(this, arguments);
267
- }
268
-
269
- const PersistQueryClientProvider = ({
270
- client,
271
- children,
272
- persistOptions,
273
- onSuccess,
274
- ...props
275
- }) => {
276
- const [isRestoring, setIsRestoring] = React__namespace.useState(true);
277
- const refs = React__namespace.useRef({
278
- persistOptions,
279
- onSuccess
280
- });
281
- React__namespace.useEffect(() => {
282
- refs.current = {
283
- persistOptions,
284
- onSuccess
285
- };
286
- });
287
- React__namespace.useEffect(() => {
288
- let isStale = false;
289
- setIsRestoring(true);
290
- const [unsubscribe, promise] = persistQueryClient({
291
- ...refs.current.persistOptions,
292
- queryClient: client
293
- });
294
- promise.then(() => {
295
- if (!isStale) {
296
- refs.current.onSuccess?.();
297
- setIsRestoring(false);
298
- }
299
- });
300
- return () => {
301
- isStale = true;
302
- unsubscribe();
303
- };
304
- }, [client]);
305
- return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _extends({
306
- client: client
307
- }, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
308
- value: isRestoring
309
- }, children));
310
- };
311
-
312
- exports.PersistQueryClientProvider = PersistQueryClientProvider;
313
- exports.persistQueryClient = persistQueryClient;
314
- exports.persistQueryClientRestore = persistQueryClientRestore;
315
- exports.persistQueryClientSave = persistQueryClientSave;
316
- exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
317
- exports.removeOldestQuery = removeOldestQuery;
318
-
319
- }));
320
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.development.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../../query-persist-client-core/build/lib/retryStrategies.mjs","../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["// TYPES\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = dehydratedState.mutations || [];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n mutationCache.build(client, {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n const query = queryCache.get(dehydratedQuery.queryHash);\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle'\n };\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n return;\n }\n\n // Restore query\n queryCache.build(client, {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\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 = ['added', 'removed', 'updated'];\nfunction isCacheableEventType(eventType) {\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 */\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\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 console.error(err);\n console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\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 */\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\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 */\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\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 return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = {\n ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n };\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);\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 return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["PersistQueryClientProvider","client","children","persistOptions","onSuccess","props","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","persistQueryClient","queryClient","then","QueryClientProvider","IsRestoringProvider"],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W,CAAA;EAC9C,GAAC,CAAC,CAAA;IAEFI,gBAAK,CAACI,SAAS,CAAC,MAAM;MACpB,IAAIE,OAAO,GAAG,KAAK,CAAA;MACnBP,cAAc,CAAC,IAAI,CAAC,CAAA;EACpB,IAAA,MAAM,CAACQ,WAAW,EAAEC,OAAO,CAAC,GAAGC,kBAAkB,CAAC;EAChD,MAAA,GAAGP,IAAI,CAACG,OAAO,CAACV,cAAc;EAC9Be,MAAAA,WAAW,EAAEjB,MAAAA;EACf,KAAC,CAAC,CAAA;MAEFe,OAAO,CAACG,IAAI,CAAC,MAAM;QACjB,IAAI,CAACL,OAAO,EAAE;EACZJ,QAAAA,IAAI,CAACG,OAAO,CAACT,SAAS,IAAI,CAAA;UAC1BG,cAAc,CAAC,KAAK,CAAC,CAAA;EACvB,OAAA;EACF,KAAC,CAAC,CAAA;EAEF,IAAA,OAAO,MAAM;EACXO,MAAAA,OAAO,GAAG,IAAI,CAAA;EACdC,MAAAA,WAAW,EAAE,CAAA;OACd,CAAA;EACH,GAAC,EAAE,CAACd,MAAM,CAAC,CAAC,CAAA;EAEZ,EAAA,oBACEO,+BAACY,8BAAmB,EAAA,QAAA,CAAA;EAAC,IAAA,MAAM,EAAEnB,MAAAA;KAAYI,EAAAA,KAAK,CAC5C,eAAAG,gBAAA,CAAA,aAAA,CAACa,8BAAmB,EAAA;EAAC,IAAA,KAAK,EAAEf,WAAAA;KAAcJ,EAAAA,QAAQ,CAAuB,CACrD,CAAA;EAE1B;;;;;;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React,e.ReactQuery)}(this,(function(e,t,r){"use strict";function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=n(t);function i(e){return e.state.isPaused}function u(e){return"success"===e.state.status}function a(e,t={}){const r=[],n=[];if(!1!==t.dehydrateMutations){const n=t.shouldDehydrateMutation||i;e.getMutationCache().getAll().forEach((e=>{n(e)&&r.push(function(e){return{mutationKey:e.options.mutationKey,state:e.state}}(e))}))}if(!1!==t.dehydrateQueries){const r=t.shouldDehydrateQuery||u;e.getQueryCache().getAll().forEach((e=>{r(e)&&n.push(function(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}(e))}))}return{mutations:r,queries:n}}const o=["added","removed","updated"];function c(e){return o.includes(e)}async function l({queryClient:e,persister:t,maxAge:r=864e5,buster:n="",hydrateOptions:s}){try{const i=await t.restoreClient();if(i)if(i.timestamp){const u=Date.now()-i.timestamp>r,a=i.buster!==n;u||a?t.removeClient():function(e,t,r){if("object"!=typeof t||null===t)return;const n=e.getMutationCache(),s=e.getQueryCache(),i=t.mutations||[],u=t.queries||[];i.forEach((t=>{n.build(e,{...r?.defaultOptions?.mutations,mutationKey:t.mutationKey},t.state)})),u.forEach((t=>{const n=s.get(t.queryHash),i={...t.state,fetchStatus:"idle"};n?n.state.dataUpdatedAt<i.dataUpdatedAt&&n.setState(i):s.build(e,{...r?.defaultOptions?.queries,queryKey:t.queryKey,queryHash:t.queryHash},i)}))}(e,i.clientState,s)}else t.removeClient()}catch(e){t.removeClient()}}async function y({queryClient:e,persister:t,buster:r="",dehydrateOptions:n}){const s={buster:r,timestamp:Date.now(),clientState:a(e,n)};await t.persistClient(s)}function f(e){const t=e.queryClient.getQueryCache().subscribe((t=>{c(t.type)&&y(e)})),r=e.queryClient.getMutationCache().subscribe((t=>{c(t.type)&&y(e)}));return()=>{t(),r()}}function d(e){let t,r=!1;return[()=>{r=!0,t?.()},l(e).then((()=>{r||(t=f(e))}))]}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},p.apply(this,arguments)}e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:i,...u})=>{const[a,o]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:i});return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{let t=!1;o(!0);const[r,n]=d({...c.current.persistOptions,queryClient:e});return n.then((()=>{t||(c.current.onSuccess?.(),o(!1))})),()=>{t=!0,r()}}),[e]),s.createElement(r.QueryClientProvider,p({client:e},u),s.createElement(r.IsRestoringProvider,{value:a},t))},e.persistQueryClient=d,e.persistQueryClientRestore=l,e.persistQueryClientSave=y,e.persistQueryClientSubscribe=f,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],r=[...e.clientState.queries],n={...e,clientState:{mutations:t,queries:r}},s=[...r].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(s.length>0){const e=s.shift();return n.clientState.queries=r.filter((t=>t!==e)),n}}}));
2
- //# sourceMappingURL=index.production.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.production.js","sources":["../../../query-core/build/lib/hydration.mjs","../../../query-persist-client-core/build/lib/persist.mjs","../../src/PersistQueryClientProvider.tsx","../../../query-persist-client-core/build/lib/retryStrategies.mjs"],"sourcesContent":["// TYPES\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state\n };\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query) {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === 'success';\n}\nfunction dehydrate(client, options = {}) {\n const mutations = [];\n const queries = [];\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;\n client.getMutationCache().getAll().forEach(mutation => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation));\n }\n });\n }\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;\n client.getQueryCache().getAll().forEach(query => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query));\n }\n });\n }\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = dehydratedState.mutations || [];\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = dehydratedState.queries || [];\n mutations.forEach(dehydratedMutation => {\n mutationCache.build(client, {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey\n }, dehydratedMutation.state);\n });\n queries.forEach(dehydratedQuery => {\n const query = queryCache.get(dehydratedQuery.queryHash);\n\n // Reset fetch status to idle in the dehydrated state to avoid\n // query being stuck in fetching state upon hydration\n const dehydratedQueryState = {\n ...dehydratedQuery.state,\n fetchStatus: 'idle'\n };\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {\n query.setState(dehydratedQueryState);\n }\n return;\n }\n\n // Restore query\n queryCache.build(client, {\n ...options?.defaultOptions?.queries,\n queryKey: dehydratedQuery.queryKey,\n queryHash: dehydratedQuery.queryHash\n }, dehydratedQueryState);\n });\n}\n\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };\n//# sourceMappingURL=hydration.mjs.map\n","import { hydrate, dehydrate } from '@tanstack/query-core';\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 = ['added', 'removed', 'updated'];\nfunction isCacheableEventType(eventType) {\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 */\nasync function persistQueryClientRestore({\n queryClient,\n persister,\n maxAge = 1000 * 60 * 60 * 24,\n buster = '',\n hydrateOptions\n}) {\n try {\n const persistedClient = await persister.restoreClient();\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 console.error(err);\n console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');\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 */\nasync function persistQueryClientSave({\n queryClient,\n persister,\n buster = '',\n dehydrateOptions\n}) {\n const persistClient = {\n buster,\n timestamp: Date.now(),\n clientState: dehydrate(queryClient, dehydrateOptions)\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 */\nfunction persistQueryClientSubscribe(props) {\n const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {\n if (isCacheableEventType(event.type)) {\n persistQueryClientSave(props);\n }\n });\n return () => {\n unsubscribeQueryCache();\n unusbscribeMutationCache();\n };\n}\n\n/**\n * Restores persisted data to QueryCache and persists further changes.\n */\nfunction persistQueryClient(props) {\n let hasUnsubscribed = false;\n let persistQueryClientUnsubscribe;\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 return [unsubscribe, restorePromise];\n}\n\nexport { persistQueryClient, persistQueryClientRestore, persistQueryClientSave, persistQueryClientSubscribe };\n//# sourceMappingURL=persist.mjs.map\n","'use client'\nimport * as React from 'react'\n\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport { persistQueryClient } from '@tanstack/query-persist-client-core'\nimport type { QueryClientProviderProps } from '@tanstack/react-query'\nimport { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => void\n}\n\nexport const PersistQueryClientProvider = ({\n client,\n children,\n persistOptions,\n onSuccess,\n ...props\n}: PersistQueryClientProviderProps): JSX.Element => {\n const [isRestoring, setIsRestoring] = React.useState(true)\n const refs = React.useRef({ persistOptions, onSuccess })\n\n React.useEffect(() => {\n refs.current = { persistOptions, onSuccess }\n })\n\n React.useEffect(() => {\n let isStale = false\n setIsRestoring(true)\n const [unsubscribe, promise] = persistQueryClient({\n ...refs.current.persistOptions,\n queryClient: client,\n })\n\n promise.then(() => {\n if (!isStale) {\n refs.current.onSuccess?.()\n setIsRestoring(false)\n }\n })\n\n return () => {\n isStale = true\n unsubscribe()\n }\n }, [client])\n\n return (\n <QueryClientProvider client={client} {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n","const removeOldestQuery = ({\n persistedClient\n}) => {\n const mutations = [...persistedClient.clientState.mutations];\n const queries = [...persistedClient.clientState.queries];\n const client = {\n ...persistedClient,\n clientState: {\n mutations,\n queries\n }\n };\n\n // sort queries by dataUpdatedAt (oldest first)\n const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);\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 return undefined;\n};\n\nexport { removeOldestQuery };\n//# sourceMappingURL=retryStrategies.mjs.map\n"],"names":["defaultShouldDehydrateMutation","mutation","state","isPaused","defaultShouldDehydrateQuery","query","status","dehydrate","client","options","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","mutationKey","dehydrateMutation","dehydrateQueries","shouldDehydrateQuery","getQueryCache","queryKey","queryHash","dehydrateQuery","cacheableEventTypes","isCacheableEventType","eventType","includes","async","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","dehydratedQuery","get","dehydratedQueryState","fetchStatus","dataUpdatedAt","setState","hydrate","clientState","err","persistQueryClientSave","dehydrateOptions","persistClient","persistQueryClientSubscribe","props","unsubscribeQueryCache","subscribe","event","type","unusbscribeMutationCache","persistQueryClient","persistQueryClientUnsubscribe","hasUnsubscribed","then","children","persistOptions","onSuccess","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","QueryClientProvider","_extends","createElement","IsRestoringProvider","value","sortedQueries","sort","a","b","length","oldestData","shift","filter","q"],"mappings":"wnBAsBA,SAASA,EAA+BC,GACtC,OAAOA,EAASC,MAAMC,QACxB,CACA,SAASC,EAA4BC,GACnC,MAA8B,YAAvBA,EAAMH,MAAMI,MACrB,CACA,SAASC,EAAUC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