Socket
Socket
Sign inDemoInstall

@tanstack/react-query-persist-client

Package Overview
Dependencies
Maintainers
1
Versions
323
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/react-query-persist-client - npm Package Compare versions

Comparing version 4.0.0 to 4.0.2

build/cjs/react-query/build/esm/index.js

6

build/cjs/react-query-persist-client/src/PersistQueryClientProvider.js

@@ -18,3 +18,3 @@ /**

var persist = require('./persist.js');
var reactQuery = require('@tanstack/react-query');
var index = require('../../react-query/build/esm/index.js');

@@ -76,5 +76,5 @@ function _interopNamespace(e) {

}, [client]);
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
return /*#__PURE__*/React__namespace.createElement(index.QueryClientProvider, _rollupPluginBabelHelpers["extends"]({
client: client
}, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
}, props), /*#__PURE__*/React__namespace.createElement(index.IsRestoringProvider, {
value: isRestoring

@@ -81,0 +81,0 @@ }, children));

@@ -12,3 +12,3 @@ /**

import * as React from 'react';
import { QueryClientProvider, IsRestoringProvider } from '@tanstack/react-query';
import 'use-sync-external-store/shim';

@@ -25,3 +25,3 @@ /**

*/
class Subscribable {
class Subscribable$1 {
constructor() {

@@ -55,5 +55,5 @@ this.listeners = [];

// UTILS
const isServer = typeof window === 'undefined';
const isServer$1 = typeof window === 'undefined';
class FocusManager extends Subscribable {
class FocusManager$1 extends Subscribable$1 {
constructor() {

@@ -65,3 +65,3 @@ super();

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
if (!isServer$1 && window.addEventListener) {
const listener = () => onFocus(); // Listen to visibillitychange and focus

@@ -138,5 +138,5 @@

}
new FocusManager();
new FocusManager$1();
class OnlineManager extends Subscribable {
class OnlineManager$1 extends Subscribable$1 {
constructor() {

@@ -148,3 +148,3 @@ super();

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
if (!isServer$1 && window.addEventListener) {
const listener = () => onOnline(); // Listen to online

@@ -220,3 +220,3 @@

}
new OnlineManager();
new OnlineManager$1();

@@ -433,2 +433,262 @@ // TYPES

/**
* react-query
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/**
* query-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
class Subscribable {
constructor() {
this.listeners = [];
this.subscribe = this.subscribe.bind(this);
}
subscribe(listener) {
this.listeners.push(listener);
this.onSubscribe();
return () => {
this.listeners = this.listeners.filter(x => x !== listener);
this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.length > 0;
}
onSubscribe() {// Do nothing
}
onUnsubscribe() {// Do nothing
}
}
// TYPES
// UTILS
const isServer = typeof window === 'undefined';
class FocusManager extends Subscribable {
constructor() {
super();
this.setup = onFocus => {
// addEventListener does not exist in React Native, but window does
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
const listener = () => onFocus(); // Listen to visibillitychange and focus
window.addEventListener('visibilitychange', listener, false);
window.addEventListener('focus', listener, false);
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('visibilitychange', listener);
window.removeEventListener('focus', listener);
};
}
};
}
onSubscribe() {
if (!this.cleanup) {
this.setEventListener(this.setup);
}
}
onUnsubscribe() {
if (!this.hasListeners()) {
var _this$cleanup;
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
this.cleanup = undefined;
}
}
setEventListener(setup) {
var _this$cleanup2;
this.setup = setup;
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
this.cleanup = setup(focused => {
if (typeof focused === 'boolean') {
this.setFocused(focused);
} else {
this.onFocus();
}
});
}
setFocused(focused) {
this.focused = focused;
if (focused) {
this.onFocus();
}
}
onFocus() {
this.listeners.forEach(listener => {
listener();
});
}
isFocused() {
if (typeof this.focused === 'boolean') {
return this.focused;
} // document global can be unavailable in react native
if (typeof document === 'undefined') {
return true;
}
return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
}
}
new FocusManager();
class OnlineManager extends Subscribable {
constructor() {
super();
this.setup = onOnline => {
// addEventListener does not exist in React Native, but window does
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
const listener = () => onOnline(); // Listen to online
window.addEventListener('online', listener, false);
window.addEventListener('offline', listener, false);
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('online', listener);
window.removeEventListener('offline', listener);
};
}
};
}
onSubscribe() {
if (!this.cleanup) {
this.setEventListener(this.setup);
}
}
onUnsubscribe() {
if (!this.hasListeners()) {
var _this$cleanup;
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
this.cleanup = undefined;
}
}
setEventListener(setup) {
var _this$cleanup2;
this.setup = setup;
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
this.cleanup = setup(online => {
if (typeof online === 'boolean') {
this.setOnline(online);
} else {
this.onOnline();
}
});
}
setOnline(online) {
this.online = online;
if (online) {
this.onOnline();
}
}
onOnline() {
this.listeners.forEach(listener => {
listener();
});
}
isOnline() {
if (typeof this.online === 'boolean') {
return this.online;
}
if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
return true;
}
return navigator.onLine;
}
}
new OnlineManager();
const defaultContext = /*#__PURE__*/React.createContext(undefined);
const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
// Otherwise, if contextSharing is on, we share the first and at least one
// instance of the context across the window
// to ensure that if React Query is used across
// different bundles or microfrontends they will
// all use the same **instance** of context, regardless
// of module scoping.
function getQueryClientContext(context, contextSharing) {
if (context) {
return context;
}
if (contextSharing && typeof window !== 'undefined') {
if (!window.ReactQueryClientContext) {
window.ReactQueryClientContext = defaultContext;
}
return window.ReactQueryClientContext;
}
return defaultContext;
}
const QueryClientProvider = ({
client,
children,
context,
contextSharing = false
}) => {
React.useEffect(() => {
client.mount();
return () => {
client.unmount();
};
}, [client]);
const Context = getQueryClientContext(context, contextSharing);
return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
value: !context && contextSharing
}, /*#__PURE__*/React.createElement(Context.Provider, {
value: client
}, children));
};
const IsRestoringContext = /*#__PURE__*/React.createContext(false);
const IsRestoringProvider = IsRestoringContext.Provider;
const PersistQueryClientProvider = ({

@@ -435,0 +695,0 @@ client,

@@ -12,6 +12,6 @@ /**

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@tanstack/react-query')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', '@tanstack/react-query'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React, global.reactQuery));
})(this, (function (exports, React, reactQuery) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('use-sync-external-store/shim')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'use-sync-external-store/shim'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryPersistClient = {}, global.React));
})(this, (function (exports, React) { 'use strict';

@@ -48,3 +48,3 @@ function _interopNamespace(e) {

*/
class Subscribable {
class Subscribable$1 {
constructor() {

@@ -78,5 +78,5 @@ this.listeners = [];

// UTILS
const isServer = typeof window === 'undefined';
const isServer$1 = typeof window === 'undefined';
class FocusManager extends Subscribable {
class FocusManager$1 extends Subscribable$1 {
constructor() {

@@ -88,3 +88,3 @@ super();

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
if (!isServer$1 && window.addEventListener) {
const listener = () => onFocus(); // Listen to visibillitychange and focus

@@ -161,5 +161,5 @@

}
new FocusManager();
new FocusManager$1();
class OnlineManager extends Subscribable {
class OnlineManager$1 extends Subscribable$1 {
constructor() {

@@ -171,3 +171,3 @@ super();

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
if (!isServer$1 && window.addEventListener) {
const listener = () => onOnline(); // Listen to online

@@ -243,3 +243,3 @@

}
new OnlineManager();
new OnlineManager$1();

@@ -456,2 +456,262 @@ // TYPES

/**
* react-query
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/**
* query-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
class Subscribable {
constructor() {
this.listeners = [];
this.subscribe = this.subscribe.bind(this);
}
subscribe(listener) {
this.listeners.push(listener);
this.onSubscribe();
return () => {
this.listeners = this.listeners.filter(x => x !== listener);
this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.length > 0;
}
onSubscribe() {// Do nothing
}
onUnsubscribe() {// Do nothing
}
}
// TYPES
// UTILS
const isServer = typeof window === 'undefined';
class FocusManager extends Subscribable {
constructor() {
super();
this.setup = onFocus => {
// addEventListener does not exist in React Native, but window does
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
const listener = () => onFocus(); // Listen to visibillitychange and focus
window.addEventListener('visibilitychange', listener, false);
window.addEventListener('focus', listener, false);
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('visibilitychange', listener);
window.removeEventListener('focus', listener);
};
}
};
}
onSubscribe() {
if (!this.cleanup) {
this.setEventListener(this.setup);
}
}
onUnsubscribe() {
if (!this.hasListeners()) {
var _this$cleanup;
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
this.cleanup = undefined;
}
}
setEventListener(setup) {
var _this$cleanup2;
this.setup = setup;
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
this.cleanup = setup(focused => {
if (typeof focused === 'boolean') {
this.setFocused(focused);
} else {
this.onFocus();
}
});
}
setFocused(focused) {
this.focused = focused;
if (focused) {
this.onFocus();
}
}
onFocus() {
this.listeners.forEach(listener => {
listener();
});
}
isFocused() {
if (typeof this.focused === 'boolean') {
return this.focused;
} // document global can be unavailable in react native
if (typeof document === 'undefined') {
return true;
}
return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
}
}
new FocusManager();
class OnlineManager extends Subscribable {
constructor() {
super();
this.setup = onOnline => {
// addEventListener does not exist in React Native, but window does
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isServer && window.addEventListener) {
const listener = () => onOnline(); // Listen to online
window.addEventListener('online', listener, false);
window.addEventListener('offline', listener, false);
return () => {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('online', listener);
window.removeEventListener('offline', listener);
};
}
};
}
onSubscribe() {
if (!this.cleanup) {
this.setEventListener(this.setup);
}
}
onUnsubscribe() {
if (!this.hasListeners()) {
var _this$cleanup;
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
this.cleanup = undefined;
}
}
setEventListener(setup) {
var _this$cleanup2;
this.setup = setup;
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
this.cleanup = setup(online => {
if (typeof online === 'boolean') {
this.setOnline(online);
} else {
this.onOnline();
}
});
}
setOnline(online) {
this.online = online;
if (online) {
this.onOnline();
}
}
onOnline() {
this.listeners.forEach(listener => {
listener();
});
}
isOnline() {
if (typeof this.online === 'boolean') {
return this.online;
}
if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
return true;
}
return navigator.onLine;
}
}
new OnlineManager();
const defaultContext = /*#__PURE__*/React__namespace.createContext(undefined);
const QueryClientSharingContext = /*#__PURE__*/React__namespace.createContext(false); // If we are given a context, we will use it.
// Otherwise, if contextSharing is on, we share the first and at least one
// instance of the context across the window
// to ensure that if React Query is used across
// different bundles or microfrontends they will
// all use the same **instance** of context, regardless
// of module scoping.
function getQueryClientContext(context, contextSharing) {
if (context) {
return context;
}
if (contextSharing && typeof window !== 'undefined') {
if (!window.ReactQueryClientContext) {
window.ReactQueryClientContext = defaultContext;
}
return window.ReactQueryClientContext;
}
return defaultContext;
}
const QueryClientProvider = ({
client,
children,
context,
contextSharing = false
}) => {
React__namespace.useEffect(() => {
client.mount();
return () => {
client.unmount();
};
}, [client]);
const Context = getQueryClientContext(context, contextSharing);
return /*#__PURE__*/React__namespace.createElement(QueryClientSharingContext.Provider, {
value: !context && contextSharing
}, /*#__PURE__*/React__namespace.createElement(Context.Provider, {
value: client
}, children));
};
const IsRestoringContext = /*#__PURE__*/React__namespace.createContext(false);
const IsRestoringProvider = IsRestoringContext.Provider;
const PersistQueryClientProvider = ({

@@ -492,5 +752,5 @@ client,

}, [client]);
return /*#__PURE__*/React__namespace.createElement(reactQuery.QueryClientProvider, _extends({
return /*#__PURE__*/React__namespace.createElement(QueryClientProvider, _extends({
client: client
}, props), /*#__PURE__*/React__namespace.createElement(reactQuery.IsRestoringProvider, {
}, props), /*#__PURE__*/React__namespace.createElement(IsRestoringProvider, {
value: isRestoring

@@ -497,0 +757,0 @@ }, children));

@@ -11,3 +11,3 @@ /**

*/
!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,n){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var i=s(t);
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("use-sync-external-store/shim")):"function"==typeof define&&define.amd?define(["exports","react","use-sync-external-store/shim"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React)}(this,(function(e,t){"use strict";function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var s=n(t);
/**

@@ -22,3 +22,23 @@ * query-core

* @license MIT
*/class r{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.push(e),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((t=>t!==e)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const u="undefined"==typeof window;new class extends r{constructor(){super(),this.setup=e=>{if(!u&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),window.addEventListener("focus",t,!1),()=>{window.removeEventListener("visibilitychange",t),window.removeEventListener("focus",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()}))}setFocused(e){this.focused=e,e&&this.onFocus()}onFocus(){this.listeners.forEach((e=>{e()}))}isFocused(){return"boolean"==typeof this.focused?this.focused:"undefined"==typeof document||[void 0,"visible","prerender"].includes(document.visibilityState)}};function o(e){return e.state.isPaused}function a(e){return"success"===e.state.status}function c(e,t={}){const n=[],s=[];if(!1!==t.dehydrateMutations){const s=t.shouldDehydrateMutation||o;e.getMutationCache().getAll().forEach((e=>{s(e)&&n.push(function(e){return{mutationKey:e.options.mutationKey,state:e.state}}(e))}))}if(!1!==t.dehydrateQueries){const n=t.shouldDehydrateQuery||a;e.getQueryCache().getAll().forEach((e=>{n(e)&&s.push(function(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}(e))}))}return{mutations:n,queries:s}}async function l({queryClient:e,persister:t,maxAge:n=864e5,buster:s="",hydrateOptions:i}){try{const r=await t.restoreClient();if(r)if(r.timestamp){const u=Date.now()-r.timestamp>n,o=r.buster!==s;u||o?t.removeClient():function(e,t,n){if("object"!=typeof t||null===t)return;const s=e.getMutationCache(),i=e.getQueryCache(),r=t.mutations||[],u=t.queries||[];r.forEach((t=>{var i;s.build(e,{...null==n||null==(i=n.defaultOptions)?void 0:i.mutations,mutationKey:t.mutationKey},t.state)})),u.forEach((t=>{var s;const r=i.get(t.queryHash);r?r.state.dataUpdatedAt<t.state.dataUpdatedAt&&r.setState(t.state):i.build(e,{...null==n||null==(s=n.defaultOptions)?void 0:s.queries,queryKey:t.queryKey,queryHash:t.queryHash},t.state)}))}(e,r.clientState,i)}else t.removeClient()}catch(e){t.removeClient()}}async function d({queryClient:e,persister:t,buster:n="",dehydrateOptions:s}){const i={buster:n,timestamp:Date.now(),clientState:c(e,s)};await t.persistClient(i)}function h(e){const t=e.queryClient.getQueryCache().subscribe((()=>{d(e)})),n=e.queryClient.getMutationCache().subscribe((()=>{d(e)}));return()=>{t(),n()}}function f(e){let t,n=!1;return[()=>{n=!0,null==t||t()},l(e).then((()=>{n||(t=h(e))}))]}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},p.apply(this,arguments)}new class extends r{constructor(){super(),this.setup=e=>{if(!u&&window.addEventListener){const t=()=>e();return window.addEventListener("online",t,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setOnline(e):this.onOnline()}))}setOnline(e){this.online=e,e&&this.onOnline()}onOnline(){this.listeners.forEach((e=>{e()}))}isOnline(){return"boolean"==typeof this.online?this.online:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};e.PersistQueryClientProvider=({client:e,children:t,persistOptions:s,onSuccess:r,...u})=>{const[o,a]=i.useState(!0),c=i.useRef({persistOptions:s,onSuccess:r});return i.useEffect((()=>{c.current={persistOptions:s,onSuccess:r}})),i.useEffect((()=>{let t=!1;a(!0);const[n,s]=f({...c.current.persistOptions,queryClient:e});return s.then((()=>{t||(null==c.current.onSuccess||c.current.onSuccess(),a(!1))})),()=>{t=!0,n()}}),[e]),i.createElement(n.QueryClientProvider,p({client:e},u),i.createElement(n.IsRestoringProvider,{value:o},t))},e.persistQueryClient=f,e.persistQueryClientRestore=l,e.persistQueryClientSave=d,e.persistQueryClientSubscribe=h,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],n=[...e.clientState.queries],s={...e,clientState:{mutations:t,queries:n}},i=[...n].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(i.length>0){const e=i.shift();return s.clientState.queries=n.filter((t=>t!==e)),s}},Object.defineProperty(e,"__esModule",{value:!0})}));
*/class i{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.push(e),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((t=>t!==e)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const r="undefined"==typeof window;new class extends i{constructor(){super(),this.setup=e=>{if(!r&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),window.addEventListener("focus",t,!1),()=>{window.removeEventListener("visibilitychange",t),window.removeEventListener("focus",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()}))}setFocused(e){this.focused=e,e&&this.onFocus()}onFocus(){this.listeners.forEach((e=>{e()}))}isFocused(){return"boolean"==typeof this.focused?this.focused:"undefined"==typeof document||[void 0,"visible","prerender"].includes(document.visibilityState)}};function o(e){return e.state.isPaused}function u(e){return"success"===e.state.status}function c(e,t={}){const n=[],s=[];if(!1!==t.dehydrateMutations){const s=t.shouldDehydrateMutation||o;e.getMutationCache().getAll().forEach((e=>{s(e)&&n.push(function(e){return{mutationKey:e.options.mutationKey,state:e.state}}(e))}))}if(!1!==t.dehydrateQueries){const n=t.shouldDehydrateQuery||u;e.getQueryCache().getAll().forEach((e=>{n(e)&&s.push(function(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}(e))}))}return{mutations:n,queries:s}}async function a({queryClient:e,persister:t,maxAge:n=864e5,buster:s="",hydrateOptions:i}){try{const r=await t.restoreClient();if(r)if(r.timestamp){const o=Date.now()-r.timestamp>n,u=r.buster!==s;o||u?t.removeClient():function(e,t,n){if("object"!=typeof t||null===t)return;const s=e.getMutationCache(),i=e.getQueryCache(),r=t.mutations||[],o=t.queries||[];r.forEach((t=>{var i;s.build(e,{...null==n||null==(i=n.defaultOptions)?void 0:i.mutations,mutationKey:t.mutationKey},t.state)})),o.forEach((t=>{var s;const r=i.get(t.queryHash);r?r.state.dataUpdatedAt<t.state.dataUpdatedAt&&r.setState(t.state):i.build(e,{...null==n||null==(s=n.defaultOptions)?void 0:s.queries,queryKey:t.queryKey,queryHash:t.queryHash},t.state)}))}(e,r.clientState,i)}else t.removeClient()}catch(e){t.removeClient()}}async function l({queryClient:e,persister:t,buster:n="",dehydrateOptions:s}){const i={buster:n,timestamp:Date.now(),clientState:c(e,s)};await t.persistClient(i)}function h(e){const t=e.queryClient.getQueryCache().subscribe((()=>{l(e)})),n=e.queryClient.getMutationCache().subscribe((()=>{l(e)}));return()=>{t(),n()}}function d(e){let t,n=!1;return[()=>{n=!0,null==t||t()},a(e).then((()=>{n||(t=h(e))}))]}function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},f.apply(this,arguments)}
/**
* react-query
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/**
* query-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/new class extends i{constructor(){super(),this.setup=e=>{if(!r&&window.addEventListener){const t=()=>e();return window.addEventListener("online",t,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setOnline(e):this.onOnline()}))}setOnline(e){this.online=e,e&&this.onOnline()}onOnline(){this.listeners.forEach((e=>{e()}))}isOnline(){return"boolean"==typeof this.online?this.online:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};class p{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.push(e),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((t=>t!==e)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const v="undefined"==typeof window;new class extends p{constructor(){super(),this.setup=e=>{if(!v&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),window.addEventListener("focus",t,!1),()=>{window.removeEventListener("visibilitychange",t),window.removeEventListener("focus",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()}))}setFocused(e){this.focused=e,e&&this.onFocus()}onFocus(){this.listeners.forEach((e=>{e()}))}isFocused(){return"boolean"==typeof this.focused?this.focused:"undefined"==typeof document||[void 0,"visible","prerender"].includes(document.visibilityState)}};new class extends p{constructor(){super(),this.setup=e=>{if(!v&&window.addEventListener){const t=()=>e();return window.addEventListener("online",t,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setOnline(e):this.onOnline()}))}setOnline(e){this.online=e,e&&this.onOnline()}onOnline(){this.listeners.forEach((e=>{e()}))}isOnline(){return"boolean"==typeof this.online?this.online:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};const b=s.createContext(void 0),y=s.createContext(!1);const w=({client:e,children:t,context:n,contextSharing:i=!1})=>{s.useEffect((()=>(e.mount(),()=>{e.unmount()})),[e]);const r=function(e,t){return e||(t&&"undefined"!=typeof window?(window.ReactQueryClientContext||(window.ReactQueryClientContext=b),window.ReactQueryClientContext):b)}(n,i);return s.createElement(y.Provider,{value:!n&&i},s.createElement(r.Provider,{value:e},t))},E=s.createContext(!1).Provider;e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:i,...r})=>{const[o,u]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:i});return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{let t=!1;u(!0);const[n,s]=d({...c.current.persistOptions,queryClient:e});return s.then((()=>{t||(null==c.current.onSuccess||c.current.onSuccess(),u(!1))})),()=>{t=!0,n()}}),[e]),s.createElement(w,f({client:e},r),s.createElement(E,{value:o},t))},e.persistQueryClient=d,e.persistQueryClientRestore=a,e.persistQueryClientSave=l,e.persistQueryClientSubscribe=h,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],n=[...e.clientState.queries],s={...e,clientState:{mutations:t,queries:n}},i=[...n].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(i.length>0){const e=i.shift();return s.clientState.queries=n.filter((t=>t!==e)),s}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.production.js.map
{
"name": "@tanstack/react-query-persist-client",
"version": "4.0.0",
"version": "4.0.2",
"description": "TODO",

@@ -14,7 +14,7 @@ "author": "tannerlinsley",

"module": "build/esm/index.js",
"main": "build/cjs/index.js",
"main": "build/cjs/react-query-persist-client/src/index.js",
"browser": "build/umd/index.production.js",
"types": "build/types/packages/react-query-persist-client/src/index.d.ts",
"files": [
"build",
"build/*",
"src"

@@ -21,0 +21,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc