@tanstack/query-persist-client-core
Advanced tools
Comparing version 4.24.10 to 5.0.0-alpha.0
@@ -1,2 +0,1 @@ | ||
/// <reference types="jest" /> | ||
import type { QueryClientConfig } from '@tanstack/query-core'; | ||
@@ -6,9 +5,4 @@ import { QueryClient } from '@tanstack/query-core'; | ||
export declare function createQueryClient(config?: QueryClientConfig): QueryClient; | ||
export declare const mockLogger: { | ||
log: jest.Mock<any, any>; | ||
warn: jest.Mock<any, any>; | ||
error: jest.Mock<any, any>; | ||
}; | ||
export declare function sleep(timeout: number): Promise<void>; | ||
export declare const createMockPersister: () => Persister; | ||
export declare const createSpyablePersister: () => Persister; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var persist = require('./persist.js'); | ||
@@ -6,0 +4,0 @@ var retryStrategies = require('./retryStrategies.js'); |
@@ -8,6 +8,6 @@ import { hydrate, dehydrate } from '@tanstack/query-core'; | ||
const cacheableEventTypes = ['added', 'removed', 'updated']; | ||
function isCacheableEventType(eventType) { | ||
return cacheableEventTypes.includes(eventType); | ||
} | ||
/** | ||
@@ -19,4 +19,2 @@ * Restores persisted data to the QueryCache | ||
*/ | ||
async function persistQueryClientRestore({ | ||
@@ -31,3 +29,2 @@ queryClient, | ||
const persistedClient = await persister.restoreClient(); | ||
if (persistedClient) { | ||
@@ -37,3 +34,2 @@ if (persistedClient.timestamp) { | ||
const busted = persistedClient.buster !== buster; | ||
if (expired || busted) { | ||
@@ -50,9 +46,9 @@ persister.removeClient(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
queryClient.getLogger().error(err); | ||
queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'); | ||
console.error(err); | ||
console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'); | ||
} | ||
persister.removeClient(); | ||
} | ||
} | ||
/** | ||
@@ -63,3 +59,2 @@ * Persists data from the QueryCache | ||
*/ | ||
async function persistQueryClientSave({ | ||
@@ -78,2 +73,3 @@ queryClient, | ||
} | ||
/** | ||
@@ -83,3 +79,2 @@ * Subscribe to QueryCache and MutationCache updates (for persisting) | ||
*/ | ||
function persistQueryClientSubscribe(props) { | ||
@@ -101,16 +96,15 @@ const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => { | ||
} | ||
/** | ||
* Restores persisted data to QueryCache and persists further changes. | ||
*/ | ||
function persistQueryClient(props) { | ||
let hasUnsubscribed = false; | ||
let persistQueryClientUnsubscribe; | ||
const unsubscribe = () => { | ||
hasUnsubscribed = true; | ||
persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe(); | ||
}; // Attempt restore | ||
persistQueryClientUnsubscribe?.(); | ||
}; | ||
// Attempt restore | ||
const restorePromise = persistQueryClientRestore(props).then(() => { | ||
@@ -117,0 +111,0 @@ if (!hasUnsubscribed) { |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var queryCore = require('@tanstack/query-core'); | ||
@@ -12,6 +10,6 @@ | ||
const cacheableEventTypes = ['added', 'removed', 'updated']; | ||
function isCacheableEventType(eventType) { | ||
return cacheableEventTypes.includes(eventType); | ||
} | ||
/** | ||
@@ -23,4 +21,2 @@ * Restores persisted data to the QueryCache | ||
*/ | ||
async function persistQueryClientRestore({ | ||
@@ -35,3 +31,2 @@ queryClient, | ||
const persistedClient = await persister.restoreClient(); | ||
if (persistedClient) { | ||
@@ -41,3 +36,2 @@ if (persistedClient.timestamp) { | ||
const busted = persistedClient.buster !== buster; | ||
if (expired || busted) { | ||
@@ -54,9 +48,9 @@ persister.removeClient(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
queryClient.getLogger().error(err); | ||
queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'); | ||
console.error(err); | ||
console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'); | ||
} | ||
persister.removeClient(); | ||
} | ||
} | ||
/** | ||
@@ -67,3 +61,2 @@ * Persists data from the QueryCache | ||
*/ | ||
async function persistQueryClientSave({ | ||
@@ -82,2 +75,3 @@ queryClient, | ||
} | ||
/** | ||
@@ -87,3 +81,2 @@ * Subscribe to QueryCache and MutationCache updates (for persisting) | ||
*/ | ||
function persistQueryClientSubscribe(props) { | ||
@@ -105,16 +98,15 @@ const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => { | ||
} | ||
/** | ||
* Restores persisted data to QueryCache and persists further changes. | ||
*/ | ||
function persistQueryClient(props) { | ||
let hasUnsubscribed = false; | ||
let persistQueryClientUnsubscribe; | ||
const unsubscribe = () => { | ||
hasUnsubscribed = true; | ||
persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe(); | ||
}; // Attempt restore | ||
persistQueryClientUnsubscribe?.(); | ||
}; | ||
// Attempt restore | ||
const restorePromise = persistQueryClientRestore(props).then(() => { | ||
@@ -121,0 +113,0 @@ if (!hasUnsubscribed) { |
@@ -6,3 +6,4 @@ const removeOldestQuery = ({ | ||
const queries = [...persistedClient.clientState.queries]; | ||
const client = { ...persistedClient, | ||
const client = { | ||
...persistedClient, | ||
clientState: { | ||
@@ -12,6 +13,8 @@ mutations, | ||
} | ||
}; // sort queries by dataUpdatedAt (oldest first) | ||
}; | ||
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query | ||
// sort queries by dataUpdatedAt (oldest first) | ||
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); | ||
// clean oldest query | ||
if (sortedQueries.length > 0) { | ||
@@ -22,3 +25,2 @@ const oldestData = sortedQueries.shift(); | ||
} | ||
return undefined; | ||
@@ -25,0 +27,0 @@ }; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const removeOldestQuery = ({ | ||
@@ -10,3 +8,4 @@ persistedClient | ||
const queries = [...persistedClient.clientState.queries]; | ||
const client = { ...persistedClient, | ||
const client = { | ||
...persistedClient, | ||
clientState: { | ||
@@ -16,6 +15,8 @@ mutations, | ||
} | ||
}; // sort queries by dataUpdatedAt (oldest first) | ||
}; | ||
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query | ||
// sort queries by dataUpdatedAt (oldest first) | ||
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); | ||
// clean oldest query | ||
if (sortedQueries.length > 0) { | ||
@@ -26,3 +27,2 @@ const oldestData = sortedQueries.shift(); | ||
} | ||
return undefined; | ||
@@ -29,0 +29,0 @@ }; |
@@ -12,6 +12,6 @@ (function (global, factory) { | ||
const cacheableEventTypes = ['added', 'removed', 'updated']; | ||
function isCacheableEventType(eventType) { | ||
return cacheableEventTypes.includes(eventType); | ||
} | ||
/** | ||
@@ -23,4 +23,2 @@ * Restores persisted data to the QueryCache | ||
*/ | ||
async function persistQueryClientRestore({ | ||
@@ -35,3 +33,2 @@ queryClient, | ||
const persistedClient = await persister.restoreClient(); | ||
if (persistedClient) { | ||
@@ -41,3 +38,2 @@ if (persistedClient.timestamp) { | ||
const busted = persistedClient.buster !== buster; | ||
if (expired || busted) { | ||
@@ -54,9 +50,9 @@ persister.removeClient(); | ||
{ | ||
queryClient.getLogger().error(err); | ||
queryClient.getLogger().warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'); | ||
console.error(err); | ||
console.warn('Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.'); | ||
} | ||
persister.removeClient(); | ||
} | ||
} | ||
/** | ||
@@ -67,3 +63,2 @@ * Persists data from the QueryCache | ||
*/ | ||
async function persistQueryClientSave({ | ||
@@ -82,2 +77,3 @@ queryClient, | ||
} | ||
/** | ||
@@ -87,3 +83,2 @@ * Subscribe to QueryCache and MutationCache updates (for persisting) | ||
*/ | ||
function persistQueryClientSubscribe(props) { | ||
@@ -105,16 +100,15 @@ const unsubscribeQueryCache = props.queryClient.getQueryCache().subscribe(event => { | ||
} | ||
/** | ||
* Restores persisted data to QueryCache and persists further changes. | ||
*/ | ||
function persistQueryClient(props) { | ||
let hasUnsubscribed = false; | ||
let persistQueryClientUnsubscribe; | ||
const unsubscribe = () => { | ||
hasUnsubscribed = true; | ||
persistQueryClientUnsubscribe == null ? void 0 : persistQueryClientUnsubscribe(); | ||
}; // Attempt restore | ||
persistQueryClientUnsubscribe?.(); | ||
}; | ||
// Attempt restore | ||
const restorePromise = persistQueryClientRestore(props).then(() => { | ||
@@ -134,3 +128,4 @@ if (!hasUnsubscribed) { | ||
const queries = [...persistedClient.clientState.queries]; | ||
const client = { ...persistedClient, | ||
const client = { | ||
...persistedClient, | ||
clientState: { | ||
@@ -140,6 +135,8 @@ mutations, | ||
} | ||
}; // sort queries by dataUpdatedAt (oldest first) | ||
}; | ||
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); // clean oldest query | ||
// sort queries by dataUpdatedAt (oldest first) | ||
const sortedQueries = [...queries].sort((a, b) => a.state.dataUpdatedAt - b.state.dataUpdatedAt); | ||
// clean oldest query | ||
if (sortedQueries.length > 0) { | ||
@@ -150,3 +147,2 @@ const oldestData = sortedQueries.shift(); | ||
} | ||
return undefined; | ||
@@ -161,5 +157,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,require("@tanstack/query-core")):"function"==typeof define&&define.amd?define(["exports","@tanstack/query-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QueryPersistClientCore={},e.QueryCore)}(this,(function(e,t){"use strict";const i=["added","removed","updated"];function n(e){return i.includes(e)}async function r({queryClient:e,persister:i,maxAge:n=864e5,buster:r="",hydrateOptions:s}){try{const u=await i.restoreClient();if(u)if(u.timestamp){const a=Date.now()-u.timestamp>n,o=u.buster!==r;a||o?i.removeClient():t.hydrate(e,u.clientState,s)}else i.removeClient()}catch(e){i.removeClient()}}async function s({queryClient:e,persister:i,buster:n="",dehydrateOptions:r}){const s={buster:n,timestamp:Date.now(),clientState:t.dehydrate(e,r)};await i.persistClient(s)}function u(e){const t=e.queryClient.getQueryCache().subscribe((t=>{n(t.type)&&s(e)})),i=e.queryClient.getMutationCache().subscribe((t=>{n(t.type)&&s(e)}));return()=>{t(),i()}}e.persistQueryClient=function(e){let t,i=!1;return[()=>{i=!0,null==t||t()},r(e).then((()=>{i||(t=u(e))}))]},e.persistQueryClientRestore=r,e.persistQueryClientSave=s,e.persistQueryClientSubscribe=u,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],i=[...e.clientState.queries],n={...e,clientState:{mutations:t,queries:i}},r=[...i].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(r.length>0){const e=r.shift();return n.clientState.queries=i.filter((t=>t!==e)),n}},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/query-core")):"function"==typeof define&&define.amd?define(["exports","@tanstack/query-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QueryPersistClientCore={},e.QueryCore)}(this,(function(e,t){"use strict";const i=["added","removed","updated"];function n(e){return i.includes(e)}async function r({queryClient:e,persister:i,maxAge:n=864e5,buster:r="",hydrateOptions:s}){try{const a=await i.restoreClient();if(a)if(a.timestamp){const u=Date.now()-a.timestamp>n,o=a.buster!==r;u||o?i.removeClient():t.hydrate(e,a.clientState,s)}else i.removeClient()}catch(e){i.removeClient()}}async function s({queryClient:e,persister:i,buster:n="",dehydrateOptions:r}){const s={buster:n,timestamp:Date.now(),clientState:t.dehydrate(e,r)};await i.persistClient(s)}function a(e){const t=e.queryClient.getQueryCache().subscribe((t=>{n(t.type)&&s(e)})),i=e.queryClient.getMutationCache().subscribe((t=>{n(t.type)&&s(e)}));return()=>{t(),i()}}e.persistQueryClient=function(e){let t,i=!1;return[()=>{i=!0,t?.()},r(e).then((()=>{i||(t=a(e))}))]},e.persistQueryClientRestore=r,e.persistQueryClientSave=s,e.persistQueryClientSubscribe=a,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],i=[...e.clientState.queries],n={...e,clientState:{mutations:t,queries:i}},r=[...i].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(r.length>0){const e=r.shift();return n.clientState.queries=i.filter((t=>t!==e)),n}}})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/query-persist-client-core", | ||
"version": "4.24.10", | ||
"version": "5.0.0-alpha.0", | ||
"description": "Set of utilities for interacting with persisters, which can save your queryClient for later use", | ||
@@ -31,3 +31,3 @@ "author": "tannerlinsley", | ||
"dependencies": { | ||
"@tanstack/query-core": "4.24.10" | ||
"@tanstack/query-core": "5.0.0-alpha.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "scripts": { |
@@ -23,3 +23,2 @@ import { | ||
mutationFn: async (text: string) => text, | ||
variables: 'todo', | ||
}) | ||
@@ -26,0 +25,0 @@ |
@@ -9,12 +9,5 @@ import type { QueryClientConfig } from '@tanstack/query-core' | ||
export function createQueryClient(config?: QueryClientConfig): QueryClient { | ||
jest.spyOn(console, 'error').mockImplementation(() => undefined) | ||
return new QueryClient({ logger: mockLogger, ...config }) | ||
return new QueryClient(config) | ||
} | ||
export const mockLogger = { | ||
log: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
} | ||
export function sleep(timeout: number): Promise<void> { | ||
@@ -21,0 +14,0 @@ return new Promise((resolve, _reject) => { |
@@ -101,8 +101,6 @@ import type { | ||
if (process.env.NODE_ENV !== 'production') { | ||
queryClient.getLogger().error(err) | ||
queryClient | ||
.getLogger() | ||
.warn( | ||
'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.', | ||
) | ||
console.error(err) | ||
console.warn( | ||
'Encountered an error attempting to restore client cache from persisted location. As a precaution, the persisted cache will be discarded.', | ||
) | ||
} | ||
@@ -109,0 +107,0 @@ persister.removeClient() |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85710
895
2
+ Added@tanstack/query-core@5.0.0-alpha.0(transitive)
- Removed@tanstack/query-core@4.24.10(transitive)