@tanstack/query-sync-storage-persister
Advanced tools
Comparing version 4.24.10 to 5.0.0-alpha.0
function createSyncStoragePersister({ | ||
storage, | ||
key = "REACT_QUERY_OFFLINE_CACHE", | ||
key = `REACT_QUERY_OFFLINE_CACHE`, | ||
throttleTime = 1000, | ||
@@ -18,3 +18,2 @@ serialize = JSON.stringify, | ||
}; | ||
return { | ||
@@ -25,6 +24,5 @@ persistClient: throttle(persistedClient => { | ||
let errorCount = 0; | ||
while (error && client) { | ||
errorCount++; | ||
client = retry == null ? void 0 : retry({ | ||
client = retry?.({ | ||
persistedClient: client, | ||
@@ -34,3 +32,2 @@ error, | ||
}); | ||
if (client) { | ||
@@ -43,7 +40,5 @@ error = trySave(client); | ||
const cacheString = storage.getItem(key); | ||
if (!cacheString) { | ||
return; | ||
} | ||
return deserialize(cacheString); | ||
@@ -56,3 +51,2 @@ }, | ||
} | ||
return { | ||
@@ -64,3 +58,2 @@ persistClient: noop, | ||
} | ||
function throttle(func, wait = 100) { | ||
@@ -71,3 +64,2 @@ let timer = null; | ||
params = args; | ||
if (timer === null) { | ||
@@ -80,5 +72,5 @@ timer = setTimeout(() => { | ||
}; | ||
} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function noop() {} | ||
@@ -85,0 +77,0 @@ |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function createSyncStoragePersister({ | ||
storage, | ||
key = "REACT_QUERY_OFFLINE_CACHE", | ||
key = `REACT_QUERY_OFFLINE_CACHE`, | ||
throttleTime = 1000, | ||
@@ -22,3 +20,2 @@ serialize = JSON.stringify, | ||
}; | ||
return { | ||
@@ -29,6 +26,5 @@ persistClient: throttle(persistedClient => { | ||
let errorCount = 0; | ||
while (error && client) { | ||
errorCount++; | ||
client = retry == null ? void 0 : retry({ | ||
client = retry?.({ | ||
persistedClient: client, | ||
@@ -38,3 +34,2 @@ error, | ||
}); | ||
if (client) { | ||
@@ -47,7 +42,5 @@ error = trySave(client); | ||
const cacheString = storage.getItem(key); | ||
if (!cacheString) { | ||
return; | ||
} | ||
return deserialize(cacheString); | ||
@@ -60,3 +53,2 @@ }, | ||
} | ||
return { | ||
@@ -68,3 +60,2 @@ persistClient: noop, | ||
} | ||
function throttle(func, wait = 100) { | ||
@@ -75,3 +66,2 @@ let timer = null; | ||
params = args; | ||
if (timer === null) { | ||
@@ -84,5 +74,5 @@ timer = setTimeout(() => { | ||
}; | ||
} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function noop() {} | ||
@@ -89,0 +79,0 @@ |
@@ -9,3 +9,3 @@ (function (global, factory) { | ||
storage, | ||
key = "REACT_QUERY_OFFLINE_CACHE", | ||
key = `REACT_QUERY_OFFLINE_CACHE`, | ||
throttleTime = 1000, | ||
@@ -25,3 +25,2 @@ serialize = JSON.stringify, | ||
}; | ||
return { | ||
@@ -32,6 +31,5 @@ persistClient: throttle(persistedClient => { | ||
let errorCount = 0; | ||
while (error && client) { | ||
errorCount++; | ||
client = retry == null ? void 0 : retry({ | ||
client = retry?.({ | ||
persistedClient: client, | ||
@@ -41,3 +39,2 @@ error, | ||
}); | ||
if (client) { | ||
@@ -50,7 +47,5 @@ error = trySave(client); | ||
const cacheString = storage.getItem(key); | ||
if (!cacheString) { | ||
return; | ||
} | ||
return deserialize(cacheString); | ||
@@ -63,3 +58,2 @@ }, | ||
} | ||
return { | ||
@@ -71,3 +65,2 @@ persistClient: noop, | ||
} | ||
function throttle(func, wait = 100) { | ||
@@ -78,3 +71,2 @@ let timer = null; | ||
params = args; | ||
if (timer === null) { | ||
@@ -87,5 +79,5 @@ timer = setTimeout(() => { | ||
}; | ||
} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function noop() {} | ||
@@ -95,5 +87,3 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
//# sourceMappingURL=index.development.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QuerySyncStoragePersister={})}(this,(function(e){"use strict";function t(e,t=100){let r,n=null;return function(...i){r=i,null===n&&(n=setTimeout((()=>{e(...r),n=null}),t))}}function r(){}e.createSyncStoragePersister=function({storage:e,key:n="REACT_QUERY_OFFLINE_CACHE",throttleTime:i=1e3,serialize:o=JSON.stringify,deserialize:s=JSON.parse,retry:l}){if(void 0!==e){const r=t=>{try{return void e.setItem(n,o(t))}catch(e){return e}};return{persistClient:t((e=>{let t=e,n=r(t),i=0;for(;n&&t;)i++,t=null==l?void 0:l({persistedClient:t,error:n,errorCount:i}),t&&(n=r(t))}),i),restoreClient:()=>{const t=e.getItem(n);if(t)return s(t)},removeClient:()=>{e.removeItem(n)}}}return{persistClient:r,restoreClient:()=>{},removeClient:r}},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QuerySyncStoragePersister={})}(this,(function(e){"use strict";function t(e,t=100){let r,n=null;return function(...i){r=i,null===n&&(n=setTimeout((()=>{e(...r),n=null}),t))}}function r(){}e.createSyncStoragePersister=function({storage:e,key:n="REACT_QUERY_OFFLINE_CACHE",throttleTime:i=1e3,serialize:o=JSON.stringify,deserialize:s=JSON.parse,retry:l}){if(void 0!==e){const r=t=>{try{return void e.setItem(n,o(t))}catch(e){return e}};return{persistClient:t((e=>{let t=e,n=r(t),i=0;for(;n&&t;)i++,t=l?.({persistedClient:t,error:n,errorCount:i}),t&&(n=r(t))}),i),restoreClient:()=>{const t=e.getItem(n);if(t)return s(t)},removeClient:()=>{e.removeItem(n)}}}return{persistClient:r,restoreClient:()=>{},removeClient:r}}})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/query-sync-storage-persister", | ||
"version": "4.24.10", | ||
"version": "5.0.0-alpha.0", | ||
"description": "A persister for synchronous storages, to be used with TanStack/Query", | ||
@@ -31,3 +31,3 @@ "author": "tannerlinsley", | ||
"dependencies": { | ||
"@tanstack/query-persist-client-core": "4.24.10" | ||
"@tanstack/query-persist-client-core": "5.0.0-alpha.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "scripts": { |
@@ -54,9 +54,22 @@ import { | ||
await queryClient.prefetchQuery(['string'], () => Promise.resolve('string')) | ||
await queryClient.prefetchQuery(['number'], () => Promise.resolve(1)) | ||
await queryClient.prefetchQuery(['boolean'], () => Promise.resolve(true)) | ||
await queryClient.prefetchQuery(['null'], () => Promise.resolve(null)) | ||
await queryClient.prefetchQuery(['array'], () => | ||
Promise.resolve(['string', 0]), | ||
) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['string'], | ||
queryFn: () => Promise.resolve('string'), | ||
}) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['number'], | ||
queryFn: () => Promise.resolve(1), | ||
}) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['boolean'], | ||
queryFn: () => Promise.resolve(true), | ||
}) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['null'], | ||
queryFn: () => Promise.resolve(null), | ||
}) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['array'], | ||
queryFn: () => Promise.resolve(['string', 0]), | ||
}) | ||
@@ -87,12 +100,27 @@ const persistClient = { | ||
await queryClient.prefetchQuery(['A'], () => Promise.resolve('A'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['A'], | ||
queryFn: () => Promise.resolve('A'.repeat(N)), | ||
}) | ||
await sleep(1) | ||
await queryClient.prefetchQuery(['B'], () => Promise.resolve('B'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['B'], | ||
queryFn: () => Promise.resolve('B'.repeat(N)), | ||
}) | ||
await sleep(1) | ||
await queryClient.prefetchQuery(['C'], () => Promise.resolve('C'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['C'], | ||
queryFn: () => Promise.resolve('C'.repeat(N)), | ||
}) | ||
await sleep(1) | ||
await queryClient.prefetchQuery(['D'], () => Promise.resolve('D'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['D'], | ||
queryFn: () => Promise.resolve('D'.repeat(N)), | ||
}) | ||
await sleep(1) | ||
await queryClient.prefetchQuery(['E'], () => Promise.resolve('E'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['E'], | ||
queryFn: () => Promise.resolve('E'.repeat(N)), | ||
}) | ||
@@ -116,3 +144,6 @@ const persistClient = { | ||
// update query Data | ||
await queryClient.prefetchQuery(['A'], () => Promise.resolve('a'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['A'], | ||
queryFn: () => Promise.resolve('a'.repeat(N)), | ||
}) | ||
const updatedPersistClient = { | ||
@@ -147,3 +178,6 @@ buster: 'test-limit', | ||
await queryClient.prefetchQuery(['A'], () => Promise.resolve('A'.repeat(N))) | ||
await queryClient.prefetchQuery({ | ||
queryKey: ['A'], | ||
queryFn: () => Promise.resolve('A'.repeat(N)), | ||
}) | ||
await sleep(1) | ||
@@ -150,0 +184,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
603
44381
1
+ Added@tanstack/query-core@5.0.0-alpha.0(transitive)
+ Added@tanstack/query-persist-client-core@5.0.0-alpha.0(transitive)
- Removed@tanstack/query-core@4.24.10(transitive)
- Removed@tanstack/query-persist-client-core@4.24.10(transitive)