PageSourceSearch

https://trybrain.io/assets/query-persistence-DDl-jTjS.js

js trybrain.io collected 2026-09-24 15:06:06 UTC 5,387 bytes, 1 lines download raw bytes

1import{dq as A,dr as P,ds as S,dt as K}from"./index-DHwBXtP2.js";function O(e){return e}function _(e){return{mutationKey:e.options.mutationKey,state:e.state,...e.options.scope&&{scope:e.options.scope},...e.meta&&{meta:e.meta}}}function z(e,t,r){const n=()=>{const i=e.promise?.then(t).catch(s=>r(s)?Promise.reject(new Error("redacted")):Promise.reject(s));return i?.catch(P),i};return{dehydratedAt:Date.now(),state:{...e.state,...e.state.data!==void 0&&{data:t(e.state.data)}},queryKey:e.queryKey,queryHash:e.queryHash,...e.state.status==="pending"&&{promise:n()},...e.meta&&{meta:e.meta}}}function U(e){return e.state.isPaused}function F(e){return e.state.status==="success"}function j(e){return!0}function Y(e,t={}){const r=t.shouldDehydrateMutation??e.getDefaultOptions().dehydrate?.shouldDehydrateMutation??U,n=e.getMutationCache().getAll().flatMap(a=>r(a)?[_(a)]:[]),i=t.shouldDehydrateQuery??e.getDefaultOptions().dehydrate?.shouldDehydrateQuery??F,s=t.shouldRedactErrors??e.getDefaultOptions().dehydrate?.shouldRedactErrors??j,o=t.serializeData??e.getDefaultOptions().dehydrate?.serializeData??O,u=e.getQueryCache().getAll().flatMap(a=>i(a)?[z(a,o,s)]:[]);return{mutations:n,queries:u}}function B(e,t,r){if(typeof t!="object"||t===null)return;const n=e.getMutationCache(),i=e.getQueryCache(),s=r?.defaultOptions?.deserializeData??e.getDefaultOptions().hydrate?.deserializeData??O,o=t.mutations||[],u=t.queries||[];o.forEach(({state:a,...c})=>{n.build(e,{...e.getDefaultOptions().hydrate?.mutations,...r?.defaultOptions?.mutations,...c},a)}),u.forEach(({queryKey:a,state:c,queryHash:l,meta:M,promise:f,dehydratedAt:h})=>{const p=f?A(f):void 0,g=c.data===void 0?p?.data:c.data,y=g===void 0?g:s(g);let d=i.get(l);const R=d?.state.status==="pending",D=d?.state.fetchStatus==="fetching";if(d){const T=p&&h!==void 0&&h>d.state.dataUpdatedAt;if(c.dataUpdatedAt>d.state.dataUpdatedAt||T){const{fetchStatus:ee,...x}=c;d.setState({...x,data:y,...c.status==="pending"&&y!==void 0&&{status:"success",...!D&&{fetchStatus:"idle"}}})}}else d=i.build(e,{...e.getDefaultOptions().hydrate?.queries,...r?.defaultOptions?.queries,queryKey:a,queryHash:l,meta:M},{...c,data:y,fetchStatus:"idle",status:c.status==="pending"&&y!==void 0?"success":c.status});f&&!p&&!R&&!D&&(h===void 0||h>d.state.dataUpdatedAt)&&d.fetch(void 0,{initialPromise:Promise.resolve(f).then(s)}).catch(P)})}function v(){}function G(e,{interval:t=1e3,onError:r=v}={}){if(typeof e!="function")throw new Error("argument is not function.");let n=0,i=null,s=!1,o=!1;return async(...u)=>{if(i=u,!o){for(o=!0;s;)await new Promise(a=>S.setTimeout(a,t));for(;Date.now()<n;)await new Promise(a=>S.setTimeout(a,n-Date.now()));o=!1,s=!0;try{await e(...i)}catch(a){try{r(a)}catch{}}n=Date.now()+t,s=!1}}}var H=({storage:e,key:t="REACT_QUERY_OFFLINE_CACHE",throttleTime:r=1e3,serialize:n=JSON.stringify,deserialize:i=JSON.parse,retry:s})=>{if(e){const o=async u=>{try{const a=await n(u);await e.setItem(t,a);return}catch(a){return a}};return{persistClient:G(async u=>{let a=u,c=await o(a),l=0;for(;c&&a;)l++,a=await s?.({persistedClient:a,error:c,errorCount:l}),a&&(c=await o(a))},{interval:r}),restoreClient:async()=>{const u=await e.getItem(t);if(u)return await i(u)},removeClient:()=>e.removeItem(t)}}return{persistClient:v,restoreClient:()=>Promise.resolve(void 0),removeClient:v}},J=["added","removed","updated"];function b(e){return J.includes(e)}async function N({queryClient:e,persister:t,maxAge:r=1e3*60*60*24,buster:n="",hydrateOptions:i}){try{const s=await t.restoreClient();if(s)if(s.timestamp){const o=Date.now()-s.timestamp>r,u=s.buster!==n;if(o||u)return t.removeClient();B(e,s.clientState,i)}else return t.removeClient()}catch(s){throw await t.removeClient(),s}}async function E({queryClient:e,persister:t,buster:r="",dehydrateOptions:n}){const i={buster:r,timestamp:Date.now(),clientState:Y(e,n)};await t.persistClient(i)}function k(e){const t=e.queryClient.getQueryCache().subscribe(n=>{b(n.type)&&E(e)}),r=e.queryClient.getMutationCache().subscribe(n=>{b(n.type)&&E(e)});return()=>{t(),r()}}function L(e){let t=!1,r;const n=()=>{t=!0,r?.()},i=N(e).then(()=>{t||(r=k(e))});return[n,i]}function m(e){return new Promise((t,r)=>{e.oncomplete=e.onsuccess=()=>t(e.result),e.onabort=e.onerror=()=>r(e.error)})}function X(e,t){let r;const n=()=>
1{if(r)return r;const i=indexedDB.open(e);return i.onupgradeneeded=()=>i.result.createObjectStore(t),r=m(i),r.then(s=>{s.onclose=()=>r=void 0},()=>{}),r};return(i,s)=>n().then(o=>s(o.transaction(t,i).objectStore(t)))}let w;function C(){return w||(w=X("keyval-store","keyval")),w}function $(e,t=C()){return t("readonly",r=>m(r.get(e)))}function q(e,t,r=C()){return r("readwrite",n=>(n.put(t,e),m(n.transaction)))}function V(e,t=C()){return t("readwrite",r=>(r.delete(e),m(r.transaction)))}const I=new Set(K),W=e=>{const t=e[0];return typeof t=="string"&&I.has(t)},Z={getItem:e=>$(e).then(t=>t??null),setItem:(e,t)=>q(e,t).then(()=>{}),removeItem:e=>V(e).then(()=>{})};let Q=!1;function re(e){if(Q||typeof window>"u")return;Q=!0;for(const r of I){const n=e.getQueryDefaults([r])??{};e.setQueryDefaults([r],{...n,gcTime:1440*60*1e3})}const t=H({storage:Z,key:"brain-query-cache-v1",throttleTime:1500});L({queryClient:e,persister:t,maxAge:1440*60*1e3,dehydrateOptions:{shouldDehydrateQuery:r=>r.state.status!=="success"?!1:W(r.queryKey)},buster:"v1"})}export{re as installQueryPersistence};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.