@tanstack/react-query-persist-client 5.0.0-alpha.49 → 5.0.0-alpha.50

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.
@@ -53,7 +53,7 @@ const PersistQueryClientProvider = ({
53
53
  promise.then(async () => {
54
54
  if (!isStale) {
55
55
  try {
56
- await (refs.current.onSuccess == null ? void 0 : refs.current.onSuccess());
56
+ await refs.current.onSuccess?.();
57
57
  } finally {
58
58
  setIsRestoring(false);
59
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-persist-client",
3
- "version": "5.0.0-alpha.49",
3
+ "version": "5.0.0-alpha.50",
4
4
  "description": "React bindings to work with persisters in TanStack/react-query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -25,7 +25,6 @@
25
25
  "sideEffects": false,
26
26
  "files": [
27
27
  "build/lib/*",
28
- "build/umd/*",
29
28
  "src"
30
29
  ],
31
30
  "dependencies": {
@@ -1,309 +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 filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
56
- const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
57
- const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
58
- const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);
59
- return {
60
- mutations,
61
- queries
62
- };
63
- }
64
- function hydrate(client, dehydratedState, options) {
65
- if (typeof dehydratedState !== 'object' || dehydratedState === null) {
66
- return;
67
- }
68
- const mutationCache = client.getMutationCache();
69
- const queryCache = client.getQueryCache();
70
-
71
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
72
- const mutations = dehydratedState.mutations || [];
73
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
74
- const queries = dehydratedState.queries || [];
75
- mutations.forEach(dehydratedMutation => {
76
- mutationCache.build(client, {
77
- ...options?.defaultOptions?.mutations,
78
- mutationKey: dehydratedMutation.mutationKey
79
- }, dehydratedMutation.state);
80
- });
81
- queries.forEach(dehydratedQuery => {
82
- const query = queryCache.get(dehydratedQuery.queryHash);
83
-
84
- // Reset fetch status to idle in the dehydrated state to avoid
85
- // query being stuck in fetching state upon hydration
86
- const dehydratedQueryState = {
87
- ...dehydratedQuery.state,
88
- fetchStatus: 'idle'
89
- };
90
-
91
- // Do not hydrate if an existing query exists with newer data
92
- if (query) {
93
- if (query.state.dataUpdatedAt < dehydratedQueryState.dataUpdatedAt) {
94
- query.setState(dehydratedQueryState);
95
- }
96
- return;
97
- }
98
-
99
- // Restore query
100
- queryCache.build(client, {
101
- ...options?.defaultOptions?.queries,
102
- queryKey: dehydratedQuery.queryKey,
103
- queryHash: dehydratedQuery.queryHash
104
- }, dehydratedQueryState);
105
- });
106
- }
107
-
108
- /**
109
- * Checks if emitted event is about cache change and not about observers.
110
- * Useful for persist, where we only want to trigger save when cache is changed.
111
- */
112
- const cacheableEventTypes = ['added', 'removed', 'updated'];
113
- function isCacheableEventType(eventType) {
114
- return cacheableEventTypes.includes(eventType);
115
- }
116
-
117
- /**
118
- * Restores persisted data to the QueryCache
119
- * - data obtained from persister.restoreClient
120
- * - data is hydrated using hydrateOptions
121
- * If data is expired, busted, empty, or throws, it runs persister.removeClient
122
- */
123
- async function persistQueryClientRestore({
124
- queryClient,
125
- persister,
126
- maxAge = 1000 * 60 * 60 * 24,
127
- buster = '',
128
- hydrateOptions
129
- }) {
130
- try {
131
- const persistedClient = await persister.restoreClient();
132
- if (persistedClient) {
133
- if (persistedClient.timestamp) {
134
- const expired = Date.now() - persistedClient.timestamp > maxAge;
135
- const busted = persistedClient.buster !== buster;
136
- if (expired || busted) {
137
- persister.removeClient();
138
- } else {
139
- hydrate(queryClient, persistedClient.clientState, hydrateOptions);
140
- }
141
- } else {
142
- persister.removeClient();
143
- }
144
- }
145
- } catch (err) {
146
- {
147
- console.error(err);
148
- console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.');
149
- }
150
- persister.removeClient();
151
- }
152
- }
153
-
154
- /**
155
- * Persists data from the QueryCache
156
- * - data dehydrated using dehydrateOptions
157
- * - data is persisted using persister.persistClient
158
- */
159
- async function persistQueryClientSave({
160
- queryClient,
161
- persister,
162
- buster = '',
163
- dehydrateOptions
164
- }) {
165
- const persistClient = {
166
- buster,
167
- timestamp: Date.now(),
168
- clientState: dehydrate(queryClient, dehydrateOptions)
169
- };
170
- await persister.persistClient(persistClient);
171
- }
172
-
173
- /**
174
- * Subscribe to QueryCache and MutationCache updates (for persisting)
175
- * @returns an unsubscribe function (to discontinue monitoring)
176
- */
177
- function persistQueryClientSubscribe(props) {
178
- const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => {
179
- if (isCacheableEventType(event.type)) {
180
- persistQueryClientSave(props);
181
- }
182
- });
183
- const unusbscribeMutationCache = props.queryClient.getMutationCache().subscribe(event => {
184
- if (isCacheableEventType(event.type)) {
185
- persistQueryClientSave(props);
186
- }
187
- });
188
- return () => {
189
- unsubscribeQueryCache();
190
- unusbscribeMutationCache();
191
- };
192
- }
193
-
194
- /**
195
- * Restores persisted data to QueryCache and persists further changes.
196
- */
197
- function persistQueryClient(props) {
198
- let hasUnsubscribed = false;
199
- let persistQueryClientUnsubscribe;
200
- const unsubscribe = () => {
201
- hasUnsubscribed = true;
202
- persistQueryClientUnsubscribe?.();
203
- };
204
-
205
- // Attempt restore
206
- const restorePromise = persistQueryClientRestore(props).then(() => {
207
- if (!hasUnsubscribed) {
208
- // Subscribe to changes in the query cache to trigger the save
209
- persistQueryClientUnsubscribe = persistQueryClientSubscribe(props);
210
- }
211
- });
212
- return [unsubscribe, restorePromise];
213
- }
214
-
215
- const removeOldestQuery = ({
216
- persistedClient
217
- }) => {
218
- const mutations = [...persistedClient.clientState.mutations];
219
- const queries = [...persistedClient.clientState.queries];
220
- const client = {
221
- ...persistedClient,
222
- clientState: {
223
- mutations,
224
- queries
225
- }
226
- };
227
-
228
- // sort queries by dataUpdatedAt (oldest first)
229
- const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt);
230
-
231
- // clean oldest query
232
- if (sortedQueries.length > 0) {
233
- const oldestData = sortedQueries.shift();
234
- client.clientState.queries = queries.filter(q => q !== oldestData);
235
- return client;
236
- }
237
- return undefined;
238
- };
239
-
240
- function _extends() {
241
- _extends = Object.assign ? Object.assign.bind() : function (target) {
242
- for (var i = 1; i < arguments.length; i++) {
243
- var source = arguments[i];
244
- for (var key in source) {
245
- if (Object.prototype.hasOwnProperty.call(source, key)) {
246
- target[key] = source[key];
247
- }
248
- }
249
- }
250
- return target;
251
- };
252
- return _extends.apply(this, arguments);
253
- }
254
-
255
- const PersistQueryClientProvider = ({
256
- client,
257
- children,
258
- persistOptions,
259
- onSuccess,
260
- ...props
261
- }) => {
262
- const [isRestoring, setIsRestoring] = React__namespace.useState(true);
263
- const refs = React__namespace.useRef({
264
- persistOptions,
265
- onSuccess
266
- });
267
- React__namespace.useEffect(() => {
268
- refs.current = {
269
- persistOptions,
270
- onSuccess
271
- };
272
- });
273
- React__namespace.useEffect(() => {
274
- let isStale = false;
275
- setIsRestoring(true);
276
- const [unsubscribe, promise] = persistQueryClient({
277
- ...refs.current.persistOptions,
278
- queryClient: client
279
- });
280
- promise.then(async () => {
281
- if (!isStale) {
282
- try {
283
- await refs.current.onSuccess?.();
284
- } finally {
285
- setIsRestoring(false);
286
- }
287
- }
288
- });
289
- return () => {
290
- isStale = true;
291
- unsubscribe();
292
- };
293
- }, [client]);
294
- return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _extends({
295
- client: client
296
- }, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
297
- value: isRestoring
298
- }, children));
299
- };
300
-
301
- exports.PersistQueryClientProvider = PersistQueryClientProvider;
302
- exports.persistQueryClient = persistQueryClient;
303
- exports.persistQueryClientRestore = persistQueryClientRestore;
304
- exports.persistQueryClientSave = persistQueryClientSave;
305
- exports.persistQueryClientSubscribe = persistQueryClientSubscribe;
306
- exports.removeOldestQuery = removeOldestQuery;
307
-
308
- }));
309
- //# 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 filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;\n const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);\n const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;\n const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);\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?: () => Promise<unknown> | unknown\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(async () => {\n if (!isStale) {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\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","createElement","QueryClientProvider","_extends","IsRestoringProvider","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAAA;AACA;EACA;AACA;EACA,SAAS,iBAAiB,CAAC,QAAQ,EAAE;EACrC,EAAE,OAAO;EACT,IAAI,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW;EAC7C,IAAI,KAAK,EAAE,QAAQ,CAAC,KAAK;EACzB,GAAG,CAAC;EACJ,CAAC;AACD;EACA;EACA;EACA;EACA;EACA,SAAS,cAAc,CAAC,KAAK,EA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,CAAA;EACdC,MAAAA,WAAW,EAAE,CAAA;OACd,CAAA;EACH,GAAC,EAAE,CAACd,MAAM,CAAC,CAAC,CAAA;EAEZ,EAAA,oBACEO,gBAAA,CAAAY,aAAA,CAACC,8BAAmB,EAAAC,QAAA,CAAA;EAACrB,IAAAA,MAAM,EAAEA,MAAAA;EAAO,GAAA,EAAKI,KAAK,CAC5CG,eAAAA,gBAAA,CAAAY,aAAA,CAACG,8BAAmB,EAAA;EAACC,IAAAA,KAAK,EAAElB,WAAAA;KAAcJ,EAAAA,QAA8B,CACrD,CAAC,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{mutationKey:e.options.mutationKey,state:e.state}}function u(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}function a(e){return e.state.isPaused}function c(e){return"success"===e.state.status}function o(e,t={}){const r=t.shouldDehydrateMutation??a,n=e.getMutationCache().getAll().flatMap((e=>r(e)?[i(e)]:[])),s=t.shouldDehydrateQuery??c;return{mutations:n,queries:e.getQueryCache().getAll().flatMap((e=>s(e)?[u(e)]:[]))}}const l=["added","removed","updated"];function y(e){return l.includes(e)}async function f({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 d({queryClient:e,persister:t,buster:r="",dehydrateOptions:n}){const s={buster:r,timestamp:Date.now(),clientState:o(e,n)};await t.persistClient(s)}function p(e){const t=e.queryClient.getQueryCache().subscribe((t=>{y(t.type)&&d(e)})),r=e.queryClient.getMutationCache().subscribe((t=>{y(t.type)&&d(e)}));return()=>{t(),r()}}function h(e){let t,r=!1;return[()=>{r=!0,t?.()},f(e).then((()=>{r||(t=p(e))}))]}function b(){return b=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},b.apply(this,arguments)}e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:i,...u})=>{const[a,c]=s.useState(!0),o=s.useRef({persistOptions:n,onSuccess:i});return s.useEffect((()=>{o.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{let t=!1;c(!0);const[r,n]=h({...o.current.persistOptions,queryClient:e});return n.then((async()=>{if(!t)try{await(o.current.onSuccess?.())}finally{c(!1)}})),()=>{t=!0,r()}}),[e]),s.createElement(r.QueryClientProvider,b({client:e},u),s.createElement(r.IsRestoringProvider,{value:a},t))},e.persistQueryClient=h,e.persistQueryClientRestore=f,e.persistQueryClientSave=d,e.persistQueryClientSubscribe=p,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 filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;\n const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);\n const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;\n const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);\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?: () => Promise<unknown> | unknown\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(async () => {\n if (!isStale) {\n try {\n await refs.current.onSuccess?.()\n } finally {\n setIsRestoring(false)\n }\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":["dehydrateMutation","mutation","mutationKey","options","state","dehydrateQuery","query","queryKey","queryHash","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","status","dehydrate","client","filterMutation","shouldDehydrateMutation","mutations","getMutationCache","getAll","flatMap","filterQuery","shouldDehydrateQuery","queries","getQueryCache","cacheableEventTypes","isCacheableEventType","eventType","includes","async","persistQueryClientRestore","queryClient","persister","maxAge","buster","hydrateOptions","persistedClient","restoreClient","timestamp","expired","Date","now","busted","removeClient","dehydratedState","mutationCache","queryCache","forEach","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","PersistQueryClientProvider","children","persistOptions","onSuccess","isRestoring","setIsRestoring","React","useState","refs","useRef","useEffect","current","isStale","unsubscribe","promise","createElement","QueryClientProvider","_extends","IsRestoringProvider","value","sortedQueries","sort","a","b","length","oldestData","shift","filter","q"],"mappings":"wnBAIA,SAASA,EAAkBC,GACzB,MAAO,CACLC,YAAaD,EAASE,QAAQD,YAC9BE,MAAOH,EAASG,MAEpB,CAMA,SAASC,EAAeC,GACtB,MAAO,CACLF,MAAOE,EAAMF,MACbG,SAAUD,EAAMC,SAChBC,UAAWF,EAAME,UAErB,CACA,SAASC,EAA+BR,GACtC,OAAOA,EAASG,MAAMM,QACxB,CACA,SAASC,EAA4BL,GACnC,MAA8B,YAAvBA,EAAMF,MAAMQ,MACrB,CACA,SAASC,EAAUC,EAAQX,EAAU,IACnC,MAAMY,EAAiBZ,EAAQa,yBAA2BP,EACpDQ,EAAYH,EAAOI,mBAAmBC,SAASC,SAAQnB,GAAYc,EAAed,GAAY,CAACD,EAAkBC,IAAa,KAC9HoB,EAAclB,EAAQmB,sBAAwBX,EAEpD,MAAO,CACLM,YACAM,QAHcT,EAAOU,gBAAgBL,SAASC,SAAQd,GAASe,EAAYf,GAAS,CAACD,EAAeC,IAAU,KAKlH,CC/BA,MAAMmB,EAAsB,CAAC,QAAS,UAAW,WACjD,SAASC,EAAqBC,GAC5B,OAAOF,EAAoBG,SAASD,EACtC,CAQAE,eAAeC,GAA0BC,YACvCA,EAAWC,UACXA,EAASC,OACTA,EAAS,MAAmBC,OAC5BA,EAAS,GAAEC,eACXA,I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