@storesjs/stores 0.8.7 β 0.9.0
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.
- package/dist/config.d.ts +37 -7
- package/dist/createQueryStore.d.ts +3 -19
- package/dist/createStoreWithEqualityFn.d.ts +5 -0
- package/dist/createVirtualStore.d.ts +4 -3
- package/dist/derivedStore/cascadeScheduler.d.ts +8 -0
- package/dist/derivedStore/deriveProxy.d.ts +6 -16
- package/dist/derivedStore/pathFinder.d.ts +27 -0
- package/dist/errors.d.ts +14 -0
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +5 -0
- package/dist/index.d.ts +3 -1
- package/dist/logger.d.ts +0 -5
- package/dist/native/index.js +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +3 -1
- package/dist/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/queryStore/signalTypes.d.ts +13 -0
- package/dist/queryStore/types.d.ts +35 -30
- package/dist/signal.d.ts +2 -11
- package/dist/sync/syncEnhancer.d.ts +4 -0
- package/dist/sync/types.d.ts +53 -128
- package/dist/types/functions.d.ts +19 -2
- package/dist/types/objects.d.ts +10 -3
- package/dist/types.d.ts +26 -27
- package/dist/utils/core.d.ts +23 -4
- package/dist/utils/createStoreActions.d.ts +3 -3
- package/dist/utils/persistUtils.d.ts +2 -2
- package/dist/utils/storeUtils.d.ts +1 -1
- package/dist/utils/time.d.ts +0 -3
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/chunk-3U5A7HQV.mjs +1 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/package.json +10 -6
- package/dist/sync/transport.d.ts +0 -113
- package/dist/web/chunk-MMPMCVRC.mjs +0 -1
package/dist/web/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=require("zustand/middleware"),t=require("zustand/traditional"),r=require("use-sync-external-store/shim/with-selector"),n=require("react"),o="undefined"!=typeof window&&"undefined"!=typeof document,s="development"===process.env.NODE_ENV,i="test"===process.env.NODE_ENV;function a(){return"undefined"!=typeof window?window.localStorage:null}var c=class extends Error{constructor(e,t){super(e),this.name="StoresError",this.cause=l(t)}},u={debug:(e,t)=>{s&&console.debug(e,t)},error:(e,t)=>{s&&!i&&console.error(e,t)},info:(e,t)=>{s&&console.info(e,t)},warn:(e,t)=>{s&&console.warn(e,t)}};function l(e){return e instanceof Error?e:new Error(String(e))}var f="stores/core/sync-channel",d=`${f}:storage:`;function y(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var p,h,g,b=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=Object.create(null);for(const r of Object.entries(e.values))t[r[0]]=r[1];const r={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(r)}},m=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(d))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){u.error(new c("[sync] Failed to parse storage event payload"),{error:e})}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(f),this.storage=y(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),o&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const r=Object.create(null);for(const n of e.fields)Object.prototype.hasOwnProperty.call(t.values,n)&&(r[n]=t.values[n]);Object.keys(r).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:r})};let r=this.listeners.get(e.key);return r||(r=new Set,this.listeners.set(e.key,r)),r.add(t),new b({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){u.error(new c("[sync] Failed to broadcast update"),{error:e})}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const r of t)r(e)}removeListener(e,t){const r=this.listeners.get(e);r&&(r.delete(t),r.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=y()),!this.storage)return;const t=`${d}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){u.error(new c("[sync] Failed to write broadcast payload to storage"),{error:e})}}},S=class{destroy(){}publish(){}},v=class{constructor(){this.sessionId="noop"}register(e){return new S}},w=!1;function O(){return g??(g=q(void 0))}function j(){w=!0}function q(e){return{storage:e?.storage??(t=e?.storageKeyPrefix??"stores:",{clearAll(){try{const e=a();if(!e)return;const r=[];for(let n=0;n<e.length;n++){const o=e.key(n);o?.startsWith(t)&&r.push(o)}for(const t of r)e.removeItem(t)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const r=a();return null!==r?.getItem(`${t}${e}`)},delete(e){try{const r=a();r?.removeItem(`${t}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=a();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const r=a();return r?r.getItem(`${t}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,r){try{const n=a();n?.setItem(`${t}${e}`,r)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:e?.syncEngine??(o?(p||(p=new m),p):(h||(h=new v),h))};var t}function F(){let e,t,r=!1;return{complete:function(){!r&&e&&(r=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return r},fail:function(n){!r&&t&&(r=!0,t(n),t=void 0,e=void 0)},promise:new Promise((r,n)=>{e=r,t=n})}}var C=Math.max,I=Math.min;function A(e,t=0,r={}){let n,o,s,i,a,c,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const r=n,s=o;return n=o=void 0,u=t,i=r?e.apply(s,r):e.apply(s),i}function p(e){const r=e-(c??0);return void 0===c||r>=t||r<0||f&&void 0!==s&&e-u>=s}function h(){const e=k();if(p(e))return g(e);a=setTimeout(h,function(e){const r=t-(e-(c??0));return f&&void 0!==s?I(r,s-(e-u)):r}(e))}function g(e){return a=void 0,d&&n?y(e):(n=o=void 0,i)}function b(...e){const r=k(),s=p(r);if(n=e,o=this,c=r,s){if(void 0===a)return function(e){return u=e,a=setTimeout(h,t),l?y(e):i}(c);if(f)return clearTimeout(a),a=setTimeout(h,t),y(c)}return void 0===a&&(a=setTimeout(h,t)),i}return t=E(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(r)&&(l=!!r.leading,f="maxWait"in r,s=f?C(E(r.maxWait)||0,t):void 0,d="trailing"in r?!!r.trailing:d),b.cancel=function(){void 0!==a&&clearTimeout(a),u=0,n=c=o=a=void 0},b.flush=function(){return void 0===a?i:g(k())},b}function k(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function E(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e)}function T(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function K(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}function z(e){if(null!==e&&"object"==typeof e){const t={};for(const[r,n]of Object.entries(e))"function"!=typeof n&&(t[r]=n);return t}return e}var M={ms:e=>e,seconds:e=>1e3*e,minutes:e=>M.seconds(60*e),hours:e=>M.minutes(60*e),days:e=>M.hours(24*e),weeks:e=>M.days(7*e),infinity:1/0,zero:0},x=i?0:o?M.ms(200):M.seconds(5);function D(e){return t=>{if("string"!=typeof t)throw new c("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?K:void 0)}catch(e){throw u.error(new c("[createBaseStore]: Failed to deserialize persisted store data"),{error:e}),e}}(t,e)}}function $(e){return t=>function(e,t){try{return JSON.stringify(e,t?T:void 0)}catch(e){throw u.error(new c("[createBaseStore]: Failed to serialize store data"),{error:e}),e}}(t,e)}var L=Object.freeze({shouldClear:!1});function P(e,t,r){if(!t||!e)return L;const n=e.getFieldTimestampSnapshot();return function(e,t){const r=e.getSessionId(),n=e.getTimestamp();void 0!==r&&void 0!==n&&(t.syncMetadata={origin:r,timestamp:n})}(e,r),r.syncMetadata?n&&Object.keys(n).length>0?(r.syncMetadata.fields=n,{fieldSnapshot:n,shouldClear:!0}):(delete r.syncMetadata.fields,{fieldSnapshot:n,shouldClear:!1}):{fieldSnapshot:n,shouldClear:!1}}function N(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function R(e){return!!e&&!!e.getIsApplyingRemote()}var W=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function Q(e,...t){if(!0===t[1])return G(t[0])?t[0](e):t[0];const r=G(t[0])?t[0](e):t[0];return function(e){return Array.isArray(e)}(e)?r:{...e,...r}}function V(e,t){J(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function U(e){return B(e)?e.persist.getOptions().name??e.name:e.name}function _(e){return"getSnapshot"in e}function J(e){return W.QueryStore in e}function B(e){return"persist"in e}function H(e){return W.VirtualStore in e}function G(e){return"function"==typeof e}var[X,Y]=[0,1];function Z(e,t,r){if(!e)return!0;const n=e[X],o=e[Y];return!(t<n)&&(t>n||r>o)}function ee(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function te(e,t){if(!s)return!0;if(null===e||null===t)return e===t;const r=typeof e;return r===typeof t&&("object"!==r||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function re(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function ne(r,n){j();const o=void 0!==n&&"string"==typeof n.storageKey,s=o?n.storageKey:void 0,i=n?.sync?function(e,t){if(!e)return null;if(!0===e){if(!t)throw new c("[createBaseStore]: sync: true requires a storageKey to inherit the key from");return{key:t}}if("string"==typeof e)return{key:e};const r=e,n=r.key??t;if(!n)throw new c("[createBaseStore]: sync requires either a key in the config or a storageKey to inherit from");return{...r,key:n}}(n.sync,s):void 0,a=o?n.storage??O().storage:void 0,f=i?function(e,t,r){const n=t.engine??O().syncEngine,o=function(e){let t,r,n,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&n){for(const t of Object.entries(e)){const e=t[0],r=t[1];n[e]===r&&delete n[e]}Object.keys(n).length||(n=void 0)}},getFieldTimestampSnapshot:function(){if(n)return{...n}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>r,mergeFieldTimestamps:function(e){if(n)for(const t of Object.entries(e)){const e=t[0],r=t[1],o=n[e];(void 0===o||r>o)&&(n[e]=r)}else n={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>r=e,setWithoutPersist:void 0}}(r);return{stateCreator:(s,i,a)=>{const l=new Map,f=[],d=[];let y=null,p=!1,h=!1,g=0,b=null,m=[],S=Promise.resolve(),v=!r;const w=(e,t)=>{if(o?.setSessionId&&o?.setTimestamp&&n.sessionId&&(o.setSessionId(n.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const r=Object.create(null);for(const n of t)r[String(n)]=e;o.mergeFieldTimestamps(r)}},O=function(e,t){if(p||!b)return t?s(e,t):s(e);const r=(()=>{const e=Date.now(),t=e>g?e:g+1;return g=t,t})();let o=[],i=Object.create(null);const a=n=>{const s=Q(n,e,t);for(const e of m)Object.is(s[e],n[e])||(o.push(e),i[e]=s[e]);return o.length&&w(r,o),s},c=t?s(a,!0):s(a),u=()=>{o.length&&(e=>{const t=n.sessionId;for(const r of e.keys)l.set(r,[e.timestamp,t]);y&&h?y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):d.push(e)})({keys:o,replace:t??!1,values:i,timestamp:r})};return(f=c)&&"object"==typeof f&&"then"in f&&"function"==typeof f.then?c.finally(u):(u(),c);var f},j=a.setState;a.setState=O;const q=e(O,i,a);if(m=t.fields??function(e){const t=[];for(const r of Object.entries(e)){if("function"==typeof r[1])continue;const e=r[0];t.push(e)}return t}(q),!m.length)return q;b=new Set(m);const F=async e=>{g=Math.max(g,e.timestamp);const r=Object.create(null),n=i(),s=e.timestamp;let a;if(e.replace)for(const t of m)ee(t,e.values)||Z(l.get(t),s,e.sessionId)&&(a??(a=[])).push(t);for(const o of m){if(!ee(o,e.values))continue;if(!b?.has(o))continue;if(!Z(l.get(o),s,e.sessionId))continue;const i=t.merge?.[o];if(i){const t=e.values[o],a=n[o];if(void 0!==t){const f=i(t,a,n,e.values),d=void 0!==a?a:t;if(!te(f,d))return void u.error(new c(`[sync] Merge function for field "${String(o)}" returned ${re(f)} but expected ${re(d)}`));r[o]=f,l.set(o,[s,e.sessionId])}}else r[o]=e.values[o],l.set(o,[s,e.sessionId])}if(Object.keys(r).length>0||a?.length){p=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...n};let t=!1;if(a?.length){t=!0;for(const t of a)delete e[t],l.delete(t)}for(const n in r){if(!Object.prototype.hasOwnProperty.call(r,n))continue;const o=r[n];void 0!==o&&(Object.is(e[n],o)||(t=!0),e[n]=o)}if(!t)return;await(o.setWithoutPersist??j)(e,!0)}else await(o.setWithoutPersist??j)(r)}finally{p=!1,o&&o.setIsApplyingRemote(!1)}}},C=e=>{r?S=S.then(()=>F(e)):F(e)};y=n.register({apply:e=>{v?C(e):f.push(e)},delta:t.delta,fields:m,getState:i,key:t.key});const I=()=>{h=!0,(()=>{if(y&&d.length){for(const e of d){const t=n.sessionId;for(const r of e.keys)l.set(r,[e.timestamp,t]);w(e.timestamp,e.keys),y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}d.length=0}})()},A=()=>{v=!0,(()=>{if(!f.length)return;const e=f.slice();f.length=0;for(const t of e)C(t)})()};return r&&o?(o.onHydrationComplete=I,o.onHydrationFlushEnd=A):y.onHydrated?(y.onHydrated(I),A()):(I(),A()),q},syncContext:o}}(r,i,a?.async??!1):void 0,d=f?.stateCreator??r;if(!o)return t.createWithEqualityFn()(e.subscribeWithSelector(d),Object.is);const y=a?.async?function(e){let t,r,n,o=!1;return{hydrationPromise:()=>o?t?.promise??r??(r=Promise.resolve()):(t||(t=F()),t.promise),stateCreator:(r,s,i)=>{let a;return n=()=>{if(a?.length){for(const e of a)e[1]?i.setState(e[0],e[1]):i.setState(e[0]);a=void 0}},e((...e)=>o?!0===e[1]?r(e[0],e[1]):r(e[0]):(t||(t=F()),a||(a=[]),a.push(e),t.promise),s,i)},wrapOnRehydrateStorage:(e,r)=>s=>{const i=e?.(s);return(e,s)=>{o=!0,r?.onHydrationComplete?.(),n&&n(),r?.onHydrationFlushEnd?.(),s?t?.fail(l(s)):t?.complete(),i?.(e,s)}}}}(d):null,p=function(e,t,r){const n=t??e.storage??O().storage,o=(e.sync?void 0:e.persistThrottleMs??x)||void 0,s=e.version??0,i=n.async?function(e,t,r,n){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),i=t.partialize??z,a=t.deserializer??e.deserializer??D(o),l=t.serializer??e.serializer??$(o);async function f(t,r){try{if(R(n))return;r.state,r.state=i(r.state);const o=P(n,s,r),a=l(r);try{await e.set(t,a),N(n,o)}catch(e){u.error(new c("[createBaseStore]: Failed to persist store data"),{error:e})}}catch(e){u.error(new c("[createBaseStore]: Failed to serialize persisted store data"),{error:e})}}const d=void 0!==r?A(f,r,{leading:!1,maxWait:r,trailing:!0}):function(e){let t,r=null;return function(...n){return t=n,r||(r=new Promise(n=>{queueMicrotask(async()=>{try{await e(...t)}finally{r=null,n()}})})),r}}(f);return{getItem:async t=>{const r=await e.get(t);return void 0===r?null:a(r)},setItem:async(e,t)=>{if(!n?.getIsApplyingRemote())return await d(e,t)},removeItem:async t=>{try{await e.delete(t)}catch(e){u.error(new c("[createBaseStore]: Failed to delete persisted store data"),{error:e})}}}}(n,e,o,r):function(e,t,r,n){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),i=t.partialize??z,a=t.deserializer??e.deserializer??D(o),l=t.serializer??e.serializer??$(o);function f(t,r){try{if(R(n))return;r.state,r.state=i(r.state);const o=P(n,s,r),a=l(r);try{e.set(t,a),N(n,o)}catch(e){u.error(new c("[createBaseStore]: Failed to persist store data"),{error:e})}}catch(e){u.error(new c("[createBaseStore]: Failed to persist store data"),{error:e})}}const d=void 0!==r?A(f,r,{leading:!1,maxWait:r,trailing:!0}):f;return{getItem:t=>{const r=e.get(t);return void 0===r?null:a(r)},setItem:(e,t)=>{n?.getIsApplyingRemote()||d(e,t)},removeItem:t=>{try{e.delete(t)}catch(e){u.error(new c("[createBaseStore]: Failed to delete persisted store data"),{error:e})}}}}(n,e,o,r);return{persistStorage:i,version:s}}(n,a,f?.syncContext),h=y?y.wrapOnRehydrateStorage(n.onRehydrateStorage,f?.syncContext):n.onRehydrateStorage,g=y?(e,t,r)=>(f&&(f.syncContext.setWithoutPersist=r.setState),y.stateCreator(e,t,r)):d,b=t.createWithEqualityFn()(e.subscribeWithSelector(e.persist(g,function(e,t,r){const n={name:e.storageKey,onRehydrateStorage:r,storage:t.persistStorage,version:t.version};return void 0!==e.merge&&(n.merge=e.merge),void 0!==e.migrate&&(n.migrate=e.migrate),n}(n,p,h))),Object.is);return y?Object.assign(b,{persist:Object.assign(b.persist,{hydrationPromise:y.hydrationPromise})}):b}function oe(e,t,r="s"){return 1===t?e:`${e}${r}`}function se(e,t,r){const n=t.get(e);if(!n){const n=function(e,t,r,n=[]){return e&&"object"==typeof e?ie(e,n,t,r,new WeakSet,new WeakMap):(r(t,n,!0),e)}(_(e)?e.getSnapshot():e.getState(),e,r);return t.set(e,n),n}return n}function ie(e,t,r,n,o,s){return new Proxy(e,{get(i,a,c){if(o.has(i))return Reflect.get(i,a,c);if("__proto__"===a||"symbol"==typeof a)return a===Symbol.iterator&&(n(r,t,!0),o.add(i)),Reflect.get(i,a,c);const u=Reflect.get(i,a,i),l=String(a),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(i,a)?function(...e){return n(r,f,!0,{method:l,args:e.length?e:void 0}),Reflect.apply(u,i,e)}:(n(r,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return n(r,f,!d),d?(s.has(u)||s.set(u,ie(u,f,r,n,o,s)),s.get(u)):u},getOwnPropertyDescriptor:(e,s)=>(n(r,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,s)),has:(e,o)=>(n(r,t,!0),Reflect.has(e,o)),ownKeys:e=>(n(r,t,!0),o.add(e),Reflect.ownKeys(e))})}function ae(e){return t=>ue(t,e)}function ce(e,t){const r=e.slice(0,-1);return e=>{const n=ue(e,r),o=n?.[t.method];return"function"==typeof o?o.apply(n,t.args):void 0}}function ue(e,t){let r=e;for(const e of t){if(!r||"object"!=typeof r)return r;r=r[e]}return r}function le(){const e=new Map;return{buildProxySubscriptions(t,r){const n=new Set;for(const[t,r]of e)ye(r,t,[],0,n);!function(e,t,r){for(const r of e)t(r.store,r.invocation?ce(r.path,r.invocation):ae(r.path));r&&function(e){const t=e.size;console.log(`[π‘ ${t} ${oe("Proxy Subscription",t)} π‘]:`,JSON.stringify(Array.from(e).map(e=>{const t=U(e.store),r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const n=e.invocation.args?.length??0;return`$(${t}).${r}${n?`(${n}_${oe("arg",n)})`:"()"}`}),null,2))}(e)}(n,t,r)},trackPath(t,r,n,o){let s=e.get(t);s||(s=fe(),e.set(t,s)),de(s,r,0,n,o)}}}function fe(){return Object.create(null)}function de(e,t,r,n,o){if(r===t.length)return n&&(e.isLeaf=!0),void(o&&(e.invocation=o));e.children||(e.children=fe());const s=t[r];let i=e.children?.[s];i||(i=fe(),e.children[s]=i),de(i,t,r+1,n,o)}function ye(e,t,r,n,o,s=1){const i=e.children;if(!i)return void o.add({store:t,path:r,invocation:e.invocation,isLeaf:e.isLeaf??!1});const a=Object.keys(i),c=a.length;if(0!==c)if(e.isLeaf||n>=s&&c>1){o.add({store:t,path:r,invocation:e.invocation,isLeaf:e.isLeaf??!1});for(const e of a){const a=i[e];a.invocation&&ye(a,t,[...r,e],n+1,o,s)}}else if(n<s&&c>1&&!e.isLeaf)for(const e of a)ye(i[e],t,[...r,e],n+1,o,s);else{if(1===c){const e=a[0];return void ye(i[e],t,[...r,e],n+1,o,s)}o.add({store:t,path:r,invocation:e.invocation,isLeaf:e.isLeaf??!1})}else o.add({store:t,path:r,invocation:e.invocation,isLeaf:e.isLeaf??!1})}var pe=!1,he=!1,ge=new Map,be=new Map,me=new Map,Se=null,ve=1/0;function we(){return pe}function Oe(){return Se}function je(){pe||(pe=!0,he||(he=!0,queueMicrotask(()=>{he=!1,(()=>{for(;be.size>0;){const e=ve,t=me.get(e);if(t){me.delete(e);for(const e of t)be.delete(e);Se=e;for(const e of t)e();if(Se=null,me.size>0){ve=1/0;for(const e of me.keys())e<ve&&(ve=e)}else ve=1/0}else{ve=1/0;for(const e of me.keys())e<ve&&(ve=e)}}for(;ge.size>0;){const e=Array.from(ge.values());ge.clear();for(const t of e)t()}})(),pe=!1,Se=null,be.clear(),me.clear(),ve=1/0})))}function qe(e,t){pe&&ge.set(e,t)}var Fe=e=>e;function Ce(e,t=Object.is){return n=function(e,t=Object.is){const{debounceOptions:r,debugMode:n,equalityFn:o,keepAlive:i,lockDependencies:a}="function"==typeof(l=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:l,keepAlive:!1,lockDependencies:!1}:{debounceOptions:l.debounce,debugMode:(s&&l.debugMode)??!1,equalityFn:l.equalityFn??Object.is,keepAlive:l.keepAlive??!1,lockDependencies:l.lockDependencies??!1},c=String(Ae+=1),u=new Set;var l;i&&u.add(ke);const f=new Set;let d,y,p=Ie,h=!1,g=!0,b=!0,m=0,S=!1,v=null,w=Ie;function O(e,t,r){if(!b||!u.size)return(t??Fe)(_(e)?e.getSnapshot():e.getState());if(!t)return d||(d=new WeakMap),y||(y=le()),se(e,d,y.trackPath);const n=e.subscribe(t,M,{equalityFn:r??Object.is,isDerivedStore:!0});return f.add(n),t(_(e)?e.getSnapshot():e.getState())}function j(e){for(const t of f)t(e);f.clear()}let q=!0;function F(){if(!g&&Ee(p))return p;g=!1,b&&j(!0);const t=p,r=Ee(t);p=function(t){q=!0;const r=p,s=e(t);return Ee(r)&&o(r,s)?(n&&console.log("[π₯· Derive Complete π₯·]: No change detected"),q=!1,r):s}(O);const s=n&&(!r||"verbose"===n&&b);if(s){r?"verbose"===n&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=f.size;console.log(`[π― ${e} ${oe("Selector Subscription",e)} π―]`)}return y&&b&&(y.buildProxySubscriptions((e,t)=>{const r=e.subscribe(t,M,{equalityFn:Object.is,isDerivedStore:!0});f.add(r)},s),d=void 0,y=void 0),q&&r&&function(e,t){const r=function(){const e=u.has(ke)?u.size-1:u.size;return m>0&&m<e}(),o=!m||r,s=r||null!==Oe()||we()&&o;r&&je(),n&&console.log(`[π» Derive Complete π»]: Notifying ${u.size} ${oe("watcher",u.size)}`);for(const t of u){if("function"==typeof t||!t.isDerivedWatcher)continue;const r=t.selector(e);if(!t.equalityFn(t.currentSlice,r)){const e=t.currentSlice;t.currentSlice=r,t.listener(r,e)}}s?S||(S=!0,Ee(w)||(w=t),qe(c,I)):C(e,t)}(p,t),a&&(b=!1),p}function C(e,t){for(const r of u)if("function"==typeof r)r(e,t);else if(!r.isDerivedWatcher){const t=r.selector(e);if(!r.equalityFn(r.currentSlice,t)){const e=r.currentSlice;r.currentSlice=t,r.listener(t,e)}}}function I(){if(!u.size)return;if(g&&!m&&F(),!Ee(p))return;const e=Ee(w)?w:p;C(p,e),S=!1,w=Ie}const k=r?A(T,"number"==typeof r?r:r.delay,"number"==typeof r?{leading:!1,maxWait:r,trailing:!0}:r):void 0,E=k??(()=>{h||(h=!0,queueMicrotask(T))});function T(){u.size&&(h=!1,g&&F())}function K(e){e?queueMicrotask(()=>{u.size||D()}):D()}function z(){T(),v=null}function M(){if(!g){if(g=!0,!k){if(m){je();const e=Oe(),t=null===e?0:e+1;if(null!==v&&t<=v)return;return v=t,void function(e,t){if(!pe)return;const r=t<0?0:0|t,n=be.get(e);if(void 0===n){be.set(e,r);let t=me.get(r);return t||(t=new Set,me.set(r,t)),t.add(e),void(r<ve&&(ve=r))}if(r>n){const t=me.get(n);if(t&&(t.delete(e),0===t.size&&(me.delete(n),n===ve))){ve=1/0;for(const e of me.keys())e<ve&&(ve=e)}be.set(e,r);let o=me.get(r);o||(o=new Set,me.set(r,o)),o.add(e),r<ve&&(ve=r)}}(z,t)}if(we())return void(S||(S=!0,Ee(p)&&(w=p),qe(c,I)))}v=null,E()}}function x(){return g||!Ee(p)?u.size>0?F():e(O):p}function D(e=!0){i&&e||(k?.cancel(),j(),u.clear(),m=0,y=void 0,d=void 0,b=!0,h=!1,g=!0,p=Ie,S=!1,w=Ie,v=null)}return{destroy:()=>D(!1),flushUpdates:function(){u.size&&(k?k.flush():g&&F())},getSnapshot:function(){if(!Ee(p)){u.add(ke);const e=F();return u.delete(ke),e}return h&&T(),p},getState:x,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||Ee(p)||x(),()=>{u.delete(t),u.size||K(!1)}}const[t,r,n]=e,o=n?.equalityFn??Object.is,s=n?.isDerivedStore??!1,i={currentSlice:void 0,equalityFn:o,isDerivedWatcher:s,listener:r,selector:t};return u.add(i),i.currentSlice=t(x()),s&&(m+=1),n?.fireImmediately&&r(i.currentSlice,i.currentSlice),()=>{u.delete(i),s&&(m-=1),u.size||K(s)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}(e,t),Object.assign(function(e=Fe,t=void 0){return r.useSyncExternalStoreWithSelector(n.subscribe,n.getSnapshot,void 0,e,t)},n);var n}var Ie=Symbol(),Ae=0;function ke(){}function Ee(e){return e!==Ie}var Te=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=M.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},Ke={Error:"error",Idle:"idle",Loading:"loading",Success:"success"};function ze(e,t){const r=Object.prototype.hasOwnProperty;function n(e,t){for(const r of e.keys())if(ze(r,t))return r}let o,s,i;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((s=e.length)===t.length)for(;s--&&ze(e[s],t[s]););return-1===s}if(o===Set){if(e.size!==t.size)return!1;for(let r of e){if(i=r,i&&"object"==typeof i&&(i=n(t,i),!i))return!1;if(!t.has(i))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let r of e){if(i=r[0],i&&"object"==typeof i&&(i=n(t,i),!i))return!1;if(!ze(r[1],t.get(i)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((s=e.byteLength)===t.byteLength)for(;s--&&e.getInt8(s)===t.getInt8(s););return-1===s}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const r=e,n=t;if((s=r.byteLength)===n.byteLength)for(;s--&&r[s]===n[s];);return-1===s}if(!o||"object"==typeof e){s=0;for(const n in e){if(r.call(e,n)&&++s&&!r.call(t,n))return!1;if(!(n in t)||!ze(e[n],t[n]))return!1}return Object.keys(t).length===s}}return e!=e&&t!=t}var Me=new WeakMap,xe=new WeakMap;function De(e,t=$e,r=ze){return function(e,t,r){let n=xe.get(e);n||(n=new Map,xe.set(e,n));let o=n.get(t);o||(o=new Map,n.set(t,o));const s=o.get(r);if(s)return s;const[i,a,c]=Pe(e,t,r),u=new Map,l=e=>{const t={get(t,r){if("value"===r){let t=a();const r=e.split(".");for(const e of r)e&&(t=t[e]);return t}const n="string"==typeof r?r:r.toString(),o=e?`${e}.${n}`:n,s=u.get(o);if(s)return s;const c=l(o);return Me.set(c,i),u.set(o,c),c},set(t,r,n){const o=e.split(".");return""===o[0]&&o.shift(),c(o,n),!0}};return new Proxy(Object.create(null),t)},f=l("");return i(()=>{}),Me.set(f,i),o.set(r,f),f}(e,t,r)}var $e=e=>e,Le=(e,t,r)=>{if(!t.length)return r;const[n,...o]=t,s=e[n],i=Le(s,o,r);if(ze(s,i))return e;const a=Array.isArray(e)?e.slice():{...e};return a[n]=i,a},Pe=(e,t,r)=>{const n=new Set,o=_(e);let s,i=t(o?e.getSnapshot():e.getState());return[a=>(n.size||(s=e.subscribe(t,e=>{i=e,n.forEach(e=>e())},{equalityFn:r,isDerivedStore:o})),n.add(a),()=>{n.delete(a),!n.size&&s&&(s(),s=void 0)}),()=>(n.size||(i=t(e.getState())),i),(r,n)=>{if(t!==$e)throw new Error("Cannot set a value with a selector");e.setState(e=>Le(e,r,n),!0)}]},Ne=Object.prototype.hasOwnProperty;function Re(e,t){return Ne.call(e,t)}var[We,Qe]=[!0,!1],Ve={error:We,lastFetchedAt:We,queryCache:We,queryKey:We,status:We,enabled:Qe,fetch:Qe,getCacheEntry:Qe,getData:Qe,getStatus:Qe,isDataExpired:Qe,isStale:Qe,reset:Qe},Ue=M.seconds(5);function _e(e,t){const r=t?.baseDelay??M.seconds(5),n=t?.maxDelay??M.minutes(5),o=Math.pow(2,e);return Math.min(r*o,n)}function Je(e){return JSON.stringify(Object.keys(e).sort().map(t=>e[t]))}function Be(e){return JSON.stringify(He(e))}function He(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,r)=>{const n=e[r];return t[r]=null!==n&&"object"==typeof n?He(n):n,t},{})}function Ge(e,t,r,n){return n?Ze(n,r)?n:{...Xe(e,t),...n}:Xe(e,t)}function Xe(e,t){const r=t?.params??Object.create(null);for(const t in e?.params){const n=e.params[t];n&&(r[t]=n.value)}return r}function Ye(){return Object.create(null)}function Ze(e,t){if(!e)return!1;for(const r of t)if(!(r in e))return!1;return!0}function et(e,t,r){if(!r.queryCache)return r;const n=Date.now(),o=t??(e&&r.queryKey||null);let s=!1;const i=Object.create(null);for(const e in r.queryCache){if(!Re(r.queryCache,e))continue;const a=r.queryCache[e];a&&(n-(a.lastFetchedAt??a.errorInfo.lastFailedAt)<a.cacheTime||e===o)?!t&&a.errorInfo&&a.errorInfo.retryCount>0?(i[e]={...a,errorInfo:{...a.errorInfo,retryCount:0}},s=!0):i[e]=a:s=!0}return s?{...r,queryCache:i}:r}function tt(e){return"function"==typeof e}function rt(e){return!tt(e)}function nt(e,t){return r=>{const n={...r},o={};for(const e in n)Re(n,e)&&e in Ve&&(Ve[e]&&(o[e]=n[e]),delete n[e]);return{...t?t(n):z(n),...et(e,null,o)}}}var ot=Symbol(),st=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1}),it=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function at(e,t,r=it){if(t.current.isActive){if(!r?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(r=it)=>at(e,t,r);const n=e.subscribe(e=>t.current.selector(e),(e,r)=>t.current.react(e,r,()=>{n(),t.current.isActive=!1}),r.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(n(),t.current.isActive=!1)}}function ct(e){return"function"==typeof e?{equalityFn:e}:e??st}var ut=Symbol();function lt(e,t){return function(...r){const n=e.getState()[t];if("function"==typeof n)return n(...r);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function ft(e,t){return"function"==typeof e[t]}exports.QueryStatuses=Ke,exports.applyStateUpdate=Q,exports.configureStores=function(e){var t;s&&function(){if(w)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,u=t),g??(g=q(e))},exports.createBaseStore=ne,exports.createDerivedStore=Ce,exports.createQueryStore=function(e,t,r){j();const n="function"==typeof t?t:Ye,o="object"==typeof t?t:r,a=o&&"storageKey"in o?o:void 0,{fetcher:f,onError:d,onFetched:y,setData:p,transform:h,abortInterruptedFetches:g=!0,cacheTime:b=M.days(7),debugMode:m=!1,disableAutoRefetching:S=!1,disableCache:v=!1,enabled:w=!0,keepPreviousData:O=!1,maxRetries:q=5,paramChangeThrottle:F=!1,params:C,retryDelay:I=_e,suppressStaleTimeWarning:k=!1,useParsableQueryKeys:E=!0}=e;let T="function"==typeof e.staleTime?M.minutes(2):e.staleTime??M.minutes(2);s&&!S&&!k&&T<Ue&&console.warn(`[createQueryStore${a?.storageKey?`: ${a.storageKey}`:""}] β Stale times under ${Ue/1e3} seconds are not recommended. Provided staleTime: ${T/1e3} seconds`);const K=E?Be:Je,z=new Error("[createQueryStore: AbortError] Fetch interrupted"),x="function"==typeof b,D=s&&m,$=Object.keys(e.params??Object.create(null));let L=null,P=null,N=null,R=[],Q=!1,V=!1,U=null,_=null,J=null,B=null,H=null;const G={enabled:"function"!=typeof w&&w,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:Ke.Idle},X=new Te({disableAutoRefetching:S,initialEnabled:G.enabled}),Y=()=>{U&&(_=null,U.abort(),U=null)},Z=(t,r,o)=>{const s=o.setState,i=(e,t)=>{const r="function"==typeof e;if(r||void 0!==e.enabled){let t;const n=s(n=>{const s=r?e(n):e,i=void 0!==s.enabled?s.enabled:n.enabled;return i!==n.enabled&&(t=()=>((e,t)=>{e!==t&&H!==t&&(H=t,X.setEnabled(t),t?queueMicrotask(()=>o.getState().fetch(void 0,{updateQueryKey:!0})):(J||g)&&(g&&Y(),J&&(clearTimeout(J),J=null)))})(n.enabled,i)),s});return t?.(),n}return s(e)};o.setState=i,X.init({onSubscribe:(n,o,s)=>{if(P||L||!C&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(n)if(o){const e=Xe(L,P),n=K(e),o=r();o.queryKey!==n&&t(e=>({...e,queryKey:n})),o.isStale()?w.fetch(e,void 0,!0):m(e,void 0)}else S&&!s&&w.fetch(void 0,void 0,!0)}else Q=!0},onLastUnsubscribe:e=>{J&&(clearTimeout(J),J=null),g&&!e&&Y()}});const m=(e,t)=>{if(S||t?.skipStoreUpdates)return;if(T<=0||T===1/0)return;J&&(clearTimeout(J),J=null);const n=K(e),o=r(),s=(v?B===n&&o.lastFetchedAt:o.queryCache[n]?.lastFetchedAt)||null,i=s?T-(Date.now()-s):T;J=setTimeout(()=>{const t=X.get();t.enabled&&t.subscriptionCount>0&&w.fetch(e,{force:!0},!0)},i)},w={...n(i,r,o),...G,async fetch(e,n,o=!1){const s=X.get();if(!n?.force&&!n?.skipStoreUpdates&&!s.enabled)return null;const S=r(),j=S.error,F=S.queryKey,C=S.status,A=Ge(L,P,$,e),k=K(A),E=n?.staleTime??T,M=C===Ke.Loading,N=!!n?.skipStoreUpdates,R="boolean"==typeof n?.updateQueryKey?n.updateQueryKey:o?O:!N,W=o||!N&&(R||F===k);if(_?.promise&&_.key===k&&M)return D&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(A)),_.promise;if(g&&!N&&!1!==n?.updateQueryKey&&Y(),!n?.force){const e=S.lastFetchedAt,r=S.queryCache[k],o=r?.lastFetchedAt,i=r?.errorInfo,a=i&&i.retryCount>=q,c=(v?B===k&&e:o)||null;if(c&&!(Date.now()-c>=E)&&(!i||a||N))return W&&!N&&!J&&s.subscriptionCount>0&&0!==T&&T!==1/0&&m(A,n),R&&t(e=>e.queryKey!==k?{...e,queryKey:k}:e),D&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(A)),r?.data??null}!N&&W&&(J&&(clearTimeout(J),J=null),!j&&M||t(e=>({...e,error:null,status:Ke.Loading})),_={key:k});const Q=n?.cacheTime??(x?b(A):b),V=async()=>{try{D&&(o||!e||Ze(e,$)?console.log("[π Fetching π] for params:",JSON.stringify(A)):console.log("[π Fetching with Partial Params π]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(A).filter(t=>!(t in e)).map(e=>[e,A[e]])))}`));const r=await(g&&!N&&W?(async e=>{const t=new AbortController;U=t;try{return await new Promise((r,n)=>{t.signal.addEventListener("abort",()=>n(z),{once:!0}),Promise.resolve(f(e,t)).then(r,n)})}finally{U===t&&(U=null)}})(A):f(A,null)),s=Date.now();let l;D&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(A));try{l=h?h(r,A):r}catch(e){throw new c(`[createQueryStore: ${a?.storageKey||k}]: transform failed`,e)}if(N)return D&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(A)),"withCache"===n.skipStoreUpdates&&t(e=>{if(!p)return v?{...e,queryCache:{...e.queryCache,[k]:{cacheTime:Q,data:l,errorInfo:null,lastFetchedAt:s}}}:e;let t=e;const r=t.queryCache[k];return p({data:l,params:A,queryKey:k,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}}),!v&&Object.is(r,t.queryCache[k])&&(t={...t,queryCache:{...t.queryCache,[k]:{cacheTime:Q,data:l,errorInfo:null,lastFetchedAt:s}}}),t}),l;if((p?i:t)(e=>{let t={...e,error:null,lastFetchedAt:s,queryKey:R?k:e.queryKey,status:Ke.Success};if(p||v){if(p){D&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(A));const e=t.queryCache[k];p({data:l,params:A,queryKey:k,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}}),!v&&Object.is(e,t.queryCache[k])&&(t.queryCache={...t.queryCache,[k]:{cacheTime:Q,data:null,errorInfo:null,lastFetchedAt:s}})}}else D&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(A),"| Has previous data?:",!!t.queryCache[k]?.data),t.queryCache={...t.queryCache,[k]:{cacheTime:Q,data:l,errorInfo:null,lastFetchedAt:s}};return v||b===1/0?t:et(O,k,t)}),W&&(B=k,m(A,n)),y)try{y({data:l,fetch:w.fetch,params:A,set:i})}catch(e){u.error(new c(`[createQueryStore: ${a?.storageKey||k}]: onFetched callback failed`,e))}return l??null}catch(s){if(s===z)return D&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(A)),null;const i=!o&&!0===n?.throwOnError,f=l(s);if(N||!W){if(u.error(new c(`[createQueryStore: ${a?.storageKey||k}]: Failed to fetch data`,f)),i)throw f;return null}const y=v?void 0:r().queryCache[k],p=y?.errorInfo?.retryCount??0,h=p+1;if(d?.(f,p),p<q){if(X.get().subscriptionCount>0){const t="function"==typeof I?I(h,f):I;t!==1/0&&(J&&clearTimeout(J),J=setTimeout(()=>{const{enabled:t,subscriptionCount:r}=X.get();t&&r>0&&w.fetch(e,{force:!0},!0)},t))}t(e=>({...e,error:f,queryCache:{...e.queryCache,[k]:{cacheTime:y?.cacheTime??Q,data:y?.data??null,lastFetchedAt:y?.lastFetchedAt??null,errorInfo:{error:f,lastFailedAt:Date.now(),retryCount:h}}},queryKey:R?k:e.queryKey,status:Ke.Error}))}else t(e=>({...e,error:f,queryCache:{...e.queryCache,[k]:{cacheTime:y?.cacheTime??Q,data:y?.data??null,lastFetchedAt:y?.lastFetchedAt??null,errorInfo:{error:f,lastFailedAt:Date.now(),retryCount:q}}},queryKey:R?k:e.queryKey,status:Ke.Error}));if(u.error(new c(`[createQueryStore: ${a?.storageKey||k}]: Failed to fetch data`,f)),i)throw f;return null}finally{!N&&W&&(_=null)}};return N||!W?V():(_={key:k,promise:V()}).promise},getCacheEntry(e){if(v)return null;const t=r(),n=e?"string"==typeof e?e:K(Ge(L,P,$,e)):t.queryKey;return t.queryCache[n]??null},getData(e){if(v)return null;const t=r().getCacheEntry(e);return t&&null!==t.data?O?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){switch(e){case"isIdle":return r().status===Ke.Idle;case"isLoading":return r().status===Ke.Loading;case"isSuccess":{const e=r(),t=e.queryCache[e.queryKey]?.lastFetchedAt;return"number"==typeof t||e.status===Ke.Success}case"isError":case"isInitialLoad":case void 0:{const t=r(),n=t.queryCache[t.queryKey],o=(v?B===t.queryKey&&t.lastFetchedAt:n?.lastFetchedAt)||null,s=t.status;switch(e){case"isError":{const e=t.queryCache[t.queryKey];return v?"error"!==s:"number"==typeof e?.errorInfo?.lastFailedAt}case"isInitialLoad":return!o&&s===Ke.Loading}return{isError:s===Ke.Error,isIdle:s===Ke.Idle,isLoading:s===Ke.Loading,isInitialLoad:!o&&s===Ke.Loading,isSuccess:s===Ke.Success}}}},isDataExpired(e){const t=r(),n=t.queryCache[t.queryKey],o=t.queryKey,s=t.lastFetchedAt,i=(v?B===o&&s:n?.lastFetchedAt)||null;if(!i)return!0;const a=e??n?.cacheTime;return void 0===a||Date.now()-i>=a},isStale(e){const t=r(),n=t.queryKey,o=(v?B===n&&t.lastFetchedAt:t.queryCache[n]?.lastFetchedAt)||null;if(!o)return!0;const s=e??T;return Date.now()-o>=s},reset(e=!1){for(const e of R)e();R=[],L=null,P=null,N=null,Y(),J&&(clearTimeout(J),J=null),_=null,B=null,e&&t(e=>({...e,...G}))}},j=o.subscribe;return o.subscribe=(...e)=>{const t=V?()=>{}:X.subscribe(),r=1===e.length?j(e[0]):j(e[0],e[1],e[2]);return e=>{t(e),r()}},w},ee=a?.storageKey?ne(Z,Object.assign(Object.create(null),a,{partialize:nt(O,a.partialize)})):o&&!("storageKey"in o)?ne(Z,o):ne(Z),te=ee.getState(),re=te.error,oe=te.enabled,se=te.queryKey;if(se&&!re&&(B=se),V=!0,C||"function"==typeof e.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:r,attachVals:n}=function(e,t,r){const n=Object.create(null),o=Object.create(null),s=Object.create(null);for(const e in t){if(!Re(t,e))continue;const i=t[e];if(tt(i)){const t=i(De,r);n[e]=t,s[e]=t.value}else rt(i)&&(o[e]=i,s[e]=i)}let i,a=null,c=null;if(tt(e)){const t=e(De,r);i=t.value,a=t}else i=e,c=e;return{attachVals:n,directValues:o,enabledAttachVal:a,enabledDirectValue:c,resolvedEnabled:i,resolvedParams:s}}(w,C,ee);L={enabled:t,params:n},P={enabled:r,params:e}}"function"==typeof e.staleTime&&(N=e.staleTime(De,ee),T=N.value);const ie=function(){let e,t=!1;return function(...r){e=r,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{te.fetch(e??Xe(L,P),{updateQueryKey:O})})(...e)}))}}();function ae(){let e;if(!O){e=Xe(L,P);const t=K(e);ee.setState(e=>({...e,queryKey:t}))}ie(e)}const ce=i||!F?ae:A(ae,"number"==typeof F?F:F.delay,"number"==typeof F?{leading:!1,maxWait:F,trailing:!0}:F);if(L?.enabled){const e=L.enabled,t=Me.get(e);if(t){let r=e.value;oe!==r&&ee.setState(e=>({...e,enabled:r})),r&&X.setEnabled(r),D&&console.log("[π Enabled Subscription π] Initial value:",r);const n=t(()=>{const t=e.value;t!==r&&(D&&console.log("[π Enabled Change π] - [Old]:",`${r},`,"[New]:",t),r=t,ee.setState(e=>({...e,enabled:t})))});R.push(n)}}else oe!==G.enabled&&ee.setState(e=>({...e,enabled:G.enabled}));for(const e in L?.params){const t=L.params[e];if(!t)continue;const r=Me.get(t);if(D&&console.log("[π Param Subscription π] Subscribed to param:",e),r){let n=t.value;const o=r(()=>{const r=t.value;ze(n,r)||(D&&console.log("[π Param Change π] -",e,"- [Old]:",`${n?.toString()},`,"[New]:",r?.toString()),n=r,ce())});R.push(o)}}if(N){const e=Me.get(N);if(e){const t=N;let r=t.value;D&&console.log("[π StaleTime Subscription π] Initial value:",r);const n=e(()=>{const e=t.value;e!==r&&(D&&console.log("[π StaleTime Change π] - [Old]:",`${r},`,"[New]:",e),r=e,T=e,ee.getState().fetch())});R.push(n)}}return V=!1,Q&&queueMicrotask(ce),ue=ee,le=W.QueryStore,Object.assign(ue,{[le]:!0});var ue,le},exports.createStoreActions=function(e,t){const r=function(e){const t=e.getState(),r=Object.create(null);if(s&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(H(e)){for(const n in t)ft(t,n)&&(r[n]=lt(e,n));return r}for(const e in t)ft(t,e)&&(r[e]=t[e]);return r}(e);return t?Object.assign(r,t):r},exports.createVirtualStore=function(e,t,r){const n="function"==typeof t,o=n?t:void 0,s=n?r:t,i=new Set,a=Ce(e,{debugMode:s?.debugMode??!1,equalityFn:function(e,t){const r=Object.is(e,t);return r||(function(e,t){for(const r of i){r.unsubscribe();const n=r.args;if(1===n.length){const o=n[0],s=e.getState(),i=t.getState(),a=t.subscribe(o);r.unsubscribe=a,Object.is(i,s)||o(i,s);continue}const o=n[0],s=n[1];let i=n[2];i?.fireImmediately&&(i={...i,fireImmediately:!1});const a=o(e.getState()),c=o(t.getState()),u=t.subscribe(o,s,i);r.unsubscribe=u,(i?.equalityFn??Object.is)(a,c)||s(c,a)}}(e,t),V(e)),r},keepAlive:!0,lockDependencies:s?.lockDependencies??!0}),c=a.getState().persist,u=(l=a.getState,function(e,t){return t?l().setState(e,t):l().setState(e)});var l;return Object.assign(function(e,t){const r=a();return e?r(e,t):r()},{[W.VirtualStore]:!0,destroy:()=>a.destroy(),getInitialState:()=>a.getState().getInitialState(),getState:()=>a.getState().getState(),persist:c,setState:u,subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?a.getState().subscribe(e[0]):a.getState().subscribe(e[0],e[1],e[2])};return i.add(t),()=>{t.unsubscribe(),i.delete(t)}}},o?o(a.getState):void 0)},exports.deepEqual=function e(t,r){if("object"!=typeof t||null==t||"object"!=typeof r||null==r)return t===r;if(Object.is(t,r))return!0;const n=Object.keys(t);if(n.length!==Object.keys(r).length)return!1;for(const o of n)if(!(o in r)||!e(t[o],r[o]))return!1;return!0},exports.defaultRetryDelay=_e,exports.destroyStore=V,exports.destroyStores=function(e,t){for(const r of Array.isArray(e)?e:Object.values(e))r&&!t?.skipDestroy?.(r)&&V(r,t)},exports.getLegacyQueryKey=Je,exports.getQueryKey=Be,exports.getStoreName=U,exports.isDerivedStore=function(e){return"flushUpdates"in e},exports.isPersistedStore=B,exports.isQueryStore=J,exports.isVirtualStore=H,exports.parseQueryKey=function(e){return JSON.parse(e)},exports.replacer=T,exports.reviver=K,exports.shallowEqual=function(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(const n of r)if(!Object.is(e[n],t[n]))return!1;return!0},exports.time=M,exports.useListen=function(e,t,r,o=st){const s=function(){const e=n.useRef(ot);return e.current===ot&&(e.current=function(e,t,r){return{selector:e,react:t,isActive:!1,options:ct(r),resubscribe:()=>{},unsubscribe:()=>{}}}(t,r,o)),e}(),i=function(e){return"function"==typeof e?st.enabled:e?.enabled??st.enabled}(o);return s.current.react=r,s.current.selector=t,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??st)}(s,o),n.useLayoutEffect(()=>{if(i)return at(e,s),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(s)},[i,e]),s},exports.useStableValue=function(e){const t=n.useRef(ut);return t.current===ut&&(t.current=e()),t.current};
|
|
1
|
+
var e=require("zustand/middleware"),t=require("zustand/vanilla"),n=require("react"),r="undefined"!=typeof window&&"undefined"!=typeof document,o="development"===process.env.NODE_ENV,s="test"===process.env.NODE_ENV;function i(){return"undefined"!=typeof window?window.localStorage:null}var c={debug:(e,t)=>{o&&console.debug(e,t)},error:(e,t)=>{o&&!s&&console.error(e,t)},info:(e,t)=>{o&&console.info(e,t)},warn:(e,t)=>{o&&console.warn(e,t)}},a=class extends Error{constructor(e,t){super(e),this.name="StoresError",void 0!==t&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function u(e){return e instanceof Error?e:new Error(String(e))}var l=Object.prototype.hasOwnProperty;function f(e,t){return l.call(e,t)}function d(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}var y=Object.freeze(Object.create(null));function p(e){return e}function h(){return Object.create(y)}function g(){}var b="stores/core/sync-channel",m=`${b}:storage:`;function S(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var v,w,O,q,j=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=h();for(const n of Object.entries(e.values))t[n[0]]=n[1];const n={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(n)}},F=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(m))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){c.error(new a("[sync] Failed to parse storage event payload",e))}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(b),this.storage=S(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),r&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const n=h();for(const r of e.fields)f(t.values,r)&&(n[r]=t.values[r]);Object.keys(n).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:n})};let n=this.listeners.get(e.key);return n||(n=new Set,this.listeners.set(e.key,n)),n.add(t),new j({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){c.error(new a("[sync] Failed to broadcast update",e))}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const n of t)n(e)}removeListener(e,t){const n=this.listeners.get(e);n&&(n.delete(t),n.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=S()),!this.storage)return;const t=`${m}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){c.error(new a("[sync] Failed to write broadcast payload to storage",e))}}},I=class{destroy(){}publish(){}},A=class{constructor(){this.sessionId="noop"}register(e){return new I}},C=!1;function k(){return q??(q=E(void 0))}function T(){C=!0}function E(e){return{storage:e?.storage??(t=e?.storageKeyPrefix??"stores:",{clearAll(){try{const e=i();if(!e)return;const n=[];for(let r=0;r<e.length;r++){const o=e.key(r);o?.startsWith(t)&&n.push(o)}for(const t of n)e.removeItem(t)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const n=i();return null!==n?.getItem(`${t}${e}`)},delete(e){try{const n=i();n?.removeItem(`${t}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=i();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const n=i();return n?n.getItem(`${t}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,n){try{const r=i();r?.setItem(`${t}${e}`,n)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:e?.syncEngine??(r?(v||(v=new F),v):(w||(w=new A),w))};var t}var D=Symbol("empty selection"),z=Object.is;function x(e,t,r,o,s=z){const i=n.useRef(null);let c=e,a=t,u=r;if(o){let n=i.current;null===n&&(n=function(e,t,n,r,o){const s={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:D,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return $(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(s),getSelectedSnapshot:()=>K(s),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:D,latestSource:D,selector:r,selectedSource:e,selectedSubscribe:()=>g,source:e,value:D,valueEqualityFn:o,valueSelector:r,valueSnapshot:D};return s.selectedSubscribe=M(s,e),s}(e,t,r,o,s),i.current=n),function(e,t,n,r,o,s){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=D),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=s,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=M(e,t))}(n,e,t,r,o,s),c=n.selectedSubscribe,a=n.getSelectedSnapshot,u=void 0===r?void 0:n.getSelectedServerSnapshot}const l=n.useSyncExternalStore(c,a,u);return n.useDebugValue(l),l}function M(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===D?K(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===D||e.committedSource!==t)return void n();const s=e.committedSelector,i=e.committedEqualityFn;if(e.selector===s&&e.equalityFn===i){const t=s(r);if(i===z?z(o,t):i(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=i,e.valueSelector=s,e.valueSnapshot=r,void n()}if(e.source!==t)return void n();const c=e.value;if(c===D)return;const a=e.selector(r),u=e.equalityFn(c,a);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=P(e,r,u?c:a),u||n()}))}function K(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==D)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return $(e,t)}function $(e,t){const n=e.value;if(n!==D&&z(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==D&&(e.equalityFn===z?z(n,r):e.equalityFn(n,r)))return P(e,t,n);const o=e.committedValue;return o!==D&&o!==n&&e.committedSource===e.source&&(e.equalityFn===z?z(o,r):e.equalityFn(o,r))?P(e,t,o):P(e,t,r)}function P(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function R(e,n){return(e,n)=>function(e,n){const r=t.createStore(e);return Object.assign(function(e,t){return x(r.subscribe,r.getState,r.getInitialState,e,t??n)},r)}(e,n)}function L(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var N=Math.max,V=Math.min;function W(e,t=0,n={}){let r,o,s,i,c,a,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,s=o;return r=o=void 0,u=t,i=n?e.apply(s,n):e.apply(s),i}function p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==s&&e-u>=s}function h(){const e=U();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==s?V(n,s-(e-u)):n}(e))}function g(e){return c=void 0,d&&r?y(e):(r=o=void 0,i)}function b(...e){const n=U(),s=p(n);if(r=e,o=this,a=n,s){if(void 0===c)return function(e){return u=e,c=setTimeout(h,t),l?y(e):i}(a);if(f)return clearTimeout(c),c=setTimeout(h,t),y(a)}return void 0===c&&(c=setTimeout(h,t)),i}return t=_(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,s=f?N(_(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==c&&clearTimeout(c),u=0,r=a=o=c=void 0},b.flush=function(){return void 0===c?i:g(U())},b}function U(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function _(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e)}function B(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function J(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}function H(e){if(!d(e))return e;const t=h(),n=Object.keys(e);for(let r=0;r<n.length;r++){const o=n[r],s=e[o];"function"!=typeof s&&(t[o]=s)}return t}var Q={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0},G=s?0:r?Q.ms(200):Q.seconds(5);function X(e){return t=>{if("string"!=typeof t)throw new a("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?J:void 0)}catch(e){throw c.error(new a("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Y(e){return t=>function(e,t){try{return JSON.stringify(e,t?B:void 0)}catch(e){throw c.error(new a("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var Z=Object.freeze({shouldClear:!1});function ee(e,t,n){if(!t||!e)return Z;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function te(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function ne(e){return!!e&&!!e.getIsApplyingRemote()}var re=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function oe(e,...t){if(!0===t[1])return le(t[0])?t[0](e):t[0];const n=le(t[0])?t[0](e):t[0];return function(e){return Array.isArray(e)}(e)?n:{...e,...n}}function se(e,t){ce(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function ie(e){return"getSnapshot"in e}function ce(e){return re.QueryStore in e}function ae(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function ue(e){return re.VirtualStore in e}function le(e){return"function"==typeof e}var[fe,de]=[0,1];function ye(e,t,n){if(!e)return!0;const r=e[fe],o=e[de];return!(t<r)&&(t>r||n>o)}function pe(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function he(e,t){if(!o)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function ge(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function be(t,n){T();const r=void 0!==n&&"string"==typeof n.storageKey,o=r?n.storageKey:void 0,s=n?.sync?function(e,t){if(!e)return null;if(!0===e){if(!t)throw new a("[createBaseStore]: sync: true requires a storageKey to inherit the key from");return{key:t}}if("string"==typeof e)return{key:e};const n=e,r=n.key??t;if(!r)throw new a("[createBaseStore]: sync requires either a key in the config or a storageKey to inherit from");return{...n,key:r}}(n.sync,o):void 0,i=r?n.storage??k().storage:void 0,l=s?function(e,t,n){const r=t.engine??k().syncEngine,o=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(s,i,u)=>{const l=new Map,f=[],d=[];let y=null,p=!1,g=!1,b=0,m=null,S=[],v=Promise.resolve(),w=!n;function O(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n=h();for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function q(e,t){if(p||!m)return t?s(e,t):s(e);const n=function(){const e=Date.now(),t=e>b?e:b+1;return b=t,t}();let o=[],i=h();const c=r=>{const s=oe(r,e,t);for(const e of S)Object.is(s[e],r[e])||(o.push(e),i[e]=s[e]);return o.length&&O(n,o),s},a=t?s(c,!0):s(c);function u(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)l.set(n,[e.timestamp,t]);y&&g?y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):d.push(e)}({keys:o,replace:t??!1,values:i,timestamp:n})}return(f=a)&&"object"==typeof f&&"then"in f&&"function"==typeof f.then?a.finally(u):(u(),a);var f}const j=u.setState;u.setState=q;const F=e(q,i,u);if(S=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(F),!S.length)return F;async function I(e){b=Math.max(b,e.timestamp);const n=h(),r=i(),s=e.timestamp;let u;if(e.replace)for(const t of S)pe(t,e.values)||ye(l.get(t),s,e.sessionId)&&(u??(u=[])).push(t);for(const o of S){if(!pe(o,e.values))continue;if(!m?.has(o))continue;if(!ye(l.get(o),s,e.sessionId))continue;const i=t.merge?.[o];if(i){const t=e.values[o],u=r[o];if(void 0!==t){const f=i(t,u,r,e.values),d=void 0!==u?u:t;if(!he(f,d))return void c.error(new a(`[sync] Merge function for field "${String(o)}" returned ${ge(f)} but expected ${ge(d)}`));n[o]=f,l.set(o,[s,e.sessionId])}}else n[o]=e.values[o],l.set(o,[s,e.sessionId])}if(Object.keys(n).length>0||u?.length){p=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(u?.length){t=!0;for(const t of u)delete e[t],l.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(o.setWithoutPersist??j)(e,!0)}else await(o.setWithoutPersist??j)(n)}finally{p=!1,o&&o.setIsApplyingRemote(!1)}}}function A(e){n?v=v.then(()=>I(e)):I(e)}if(m=new Set(S),y=r.register({apply:e=>{w?A(e):f.push(e)},fields:S,getState:i,key:t.key}),y?.onFirstSubscribe||y?.onLastUnsubscribe){let e=0;const t=u.subscribe;u.subscribe=(...n)=>{e||y.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||y.onLastUnsubscribe?.()})}}}function C(){g=!0,function(){if(y&&d.length){for(const e of d){const t=r.sessionId;for(const n of e.keys)l.set(n,[e.timestamp,t]);O(e.timestamp,e.keys),y.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}d.length=0}}()}function k(){w=!0,function(){if(!f.length)return;const e=f.slice();f.length=0;for(const t of e)A(t)}()}return n?(o.onHydrationComplete=C,o.onHydrationFlushEnd=k):y.onHydrated?(y.onHydrated(C),k()):(C(),k()),F},syncContext:o}}(t,s,i?.async??!1):void 0,f=l?.stateCreator??t;if(!r)return R()(e.subscribeWithSelector(f),Object.is);const d=i?.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=L()),t.promise),stateCreator:(n,s,i)=>{let c;return r=()=>{if(c?.length){for(const e of c)e[1]?i.setState(e[0],e[1]):i.setState(e[0]);c=void 0}},e((...e)=>o?!0===e[1]?n(e[0],e[1]):n(e[0]):(t||(t=L()),c||(c=[]),c.push(e),t.promise),s,i)},wrapOnRehydrateStorage:(e,n)=>s=>{const i=e?.(s);return(e,s)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),s?t?.fail(u(s)):t?.complete(),i?.(e,s)}}}}(f):null,y=function(e,t,n){const r=t??e.storage??k().storage,o=(e.sync?void 0:e.persistThrottleMs??G)||void 0,s=e.version??0,i=r.async?function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),i=t.partialize??H,u=t.deserializer??e.deserializer??X(o),l=t.serializer??e.serializer??Y(o);async function f(t,n){try{if(ne(r))return;n.state,n.state=i(n.state);const o=ee(r,s,n),u=l(n);try{await e.set(t,u),te(r,o)}catch(e){c.error(new a("[createBaseStore]: Failed to persist store data",e))}}catch(e){c.error(new a("[createBaseStore]: Failed to serialize persisted store data",e))}}const d=void 0!==n?W(f,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(f);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:u(n)},setItem:async(e,t)=>{if(!r?.getIsApplyingRemote())return await d(e,t)},removeItem:async t=>{try{await e.delete(t)}catch(e){c.error(new a("[createBaseStore]: Failed to delete persisted store data",e))}}}}(r,e,o,n):function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),i=t.partialize??H,u=t.deserializer??e.deserializer??X(o),l=t.serializer??e.serializer??Y(o);function f(t,n){try{if(ne(r))return;n.state,n.state=i(n.state);const o=ee(r,s,n),u=l(n);try{e.set(t,u),te(r,o)}catch(e){c.error(new a("[createBaseStore]: Failed to persist store data",e))}}catch(e){c.error(new a("[createBaseStore]: Failed to persist store data",e))}}const d=void 0!==n?W(f,n,{leading:!1,maxWait:n,trailing:!0}):f;return{getItem:t=>{const n=e.get(t);return void 0===n?null:u(n)},setItem:(e,t)=>{r?.getIsApplyingRemote()||d(e,t)},removeItem:t=>{try{e.delete(t)}catch(e){c.error(new a("[createBaseStore]: Failed to delete persisted store data",e))}}}}(r,e,o,n);return{persistStorage:i,version:s}}(n,i,l?.syncContext),p=d?d.wrapOnRehydrateStorage(n.onRehydrateStorage,l?.syncContext):n.onRehydrateStorage,g=d?(e,t,n)=>(l&&(l.syncContext.setWithoutPersist=n.setState),d.stateCreator(e,t,n)):f,b=R()(e.subscribeWithSelector(e.persist(g,function(e,t,n){const r={name:e.storageKey,onRehydrateStorage:n,storage:t.persistStorage,version:t.version};return void 0!==e.merge&&(r.merge=e.merge),void 0!==e.migrate&&(r.migrate=e.migrate),r}(n,y,p))),Object.is);return d?Object.assign(b,{persist:Object.assign(b.persist,{hydrationPromise:d.hydrationPromise})}):b}var me=!1,Se=!1,ve=new Map,we=new Map,Oe=new Map,qe=null,je=1/0;function Fe(){return me}function Ie(){return qe}function Ae(){me||(me=!0,Se||(Se=!0,queueMicrotask(()=>{Se=!1,(()=>{for(;we.size>0;){const e=je,t=Oe.get(e);if(t){Oe.delete(e);for(const e of t)we.delete(e);qe=e;for(const e of t)e();if(qe=null,Oe.size>0){je=1/0;for(const e of Oe.keys())e<je&&(je=e)}else je=1/0}else{je=1/0;for(const e of Oe.keys())e<je&&(je=e)}}for(;ve.size>0;){const e=Array.from(ve.values());ve.clear();for(const t of e)t()}})(),me=!1,qe=null,we.clear(),Oe.clear(),je=1/0})))}function Ce(e,t){me&&ve.set(e,t)}var ke=Symbol("stores.deriveProxy.unwrap");function Te(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?Ee(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(ie(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ee(e,t,n,r,o,s){return new Proxy(e,{get(i,c,a){if(c===ke)return r(n,t,!0),i;if(o.has(i))return Reflect.get(i,c,a);if("__proto__"===c||"symbol"==typeof c)return c===Symbol.iterator&&(r(n,t,!0),o.add(i)),Reflect.get(i,c,a);const u=Reflect.get(i,c,i),l=String(c),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(i,c)?function(...e){return r(n,f,!0,{method:l,args:e.length?e:void 0}),Reflect.apply(u,i,e)}:(r(n,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(s.has(u)||s.set(u,Ee(u,f,n,r,o,s)),s.get(u)):u},getOwnPropertyDescriptor:(e,s)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,s)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function De(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,ke);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=xe(e,t);if(n)for(let t=0;t<e.length;t++)ze(e,String(t),n)}(e,t):d(e)&&function(e,t){const n=xe(e,t);if(n)for(const t of Reflect.ownKeys(e))ze(e,t,n)}(e,t),e)}function ze(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=De(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function xe(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function Me(e,t,n="s"){return 1===t?e:`${e}${n}`}var Ke=Object.freeze([]);function $e(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const s=new Set;for(const t of e)Le(t[1],t[0],[],0,s,r);!1!==o?.(s)&&function(e,t,n){for(const n of e){const e=n.invocation?Ve(n.path,n.invocation):Ne(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${Me("Proxy Subscription",t)} π‘]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${Me("arg",o)})`:"()"}`}),null,2))}(e)}(s,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let s=e.get(t);s||(s=Pe(),e.set(t,s)),Re(s,n,0,r,o)}}}function Pe(){return h()}function Re(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&(e.invocation=o));e.children||(e.children=Pe());const s=t[n];let i=e.children?.[s];i||(i=Pe(),e.children[s]=i),Re(i,t,n+1,r,o)}function Le(e,t,n,r,o,s=2){const i=e.children;if(!i)return void o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});const c=Object.keys(i),a=c.length;if(0!==a)if(e.isLeaf||r>=s&&a>1){o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});for(const e of c){const c=i[e];c.invocation&&Le(c,t,[...n,e],r+1,o,s)}}else if(r<s&&a>1&&!e.isLeaf)for(const e of c)Le(i[e],t,[...n,e],r+1,o,s);else{if(1===a){const e=c[0];return void Le(i[e],t,[...n,e],r+1,o,s)}o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}else o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}function Ne(e){return t=>We(t,e)}function Ve(e,t){const n=e.slice(0,-1);return e=>{const r=We(e,n),o=r&&"object"==typeof r?Reflect.get(r,t.method):void 0;return"function"==typeof o?Reflect.apply(o,r,t.args??Ke):void 0}}function We(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}function Ue(e,t=Object.is){return n=function(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:s,keepAlive:i,lockDependencies:c}="function"==typeof(l=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:l,keepAlive:!1,lockDependencies:!1}:{debounceOptions:l.debounce,debugMode:(o&&l.debugMode)??!1,equalityFn:l.equalityFn??Object.is,keepAlive:l.keepAlive??!1,lockDependencies:l.lockDependencies??!1},a=String(Je+=1),u=new Set;var l;i&&u.add(He);const f=new Set;let d,y,h=_e,g=!1,b=!0,m=!0,S=0,v=!1,w=null,O=_e;function q(e,t,n){return m&&u.size?t?(f.add(e.subscribe(t,x,n?{equalityFn:n,isDerivedStore:!0}:Be)),t(ie(e)?e.getSnapshot():e.getState())):(d||(d=new WeakMap),y||(y=$e()),Te(e,d,y.trackPath)):(t??p)(ie(e)?e.getSnapshot():e.getState())}function j(e){for(const t of f)t(e);f.clear()}let F=!0;function I(){if(!b&&Qe(h))return h;b=!1,m&&j(!0);const t=h,n=Qe(t);h=function(t){F=!0;const n=h,o=e(t),i=y?De(o):o;return Qe(n)&&s(n,i)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),F=!1,n):i}(q);const o=r&&(!n||"verbose"===r&&m);if(o){n?"verbose"===r&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=f.size;console.log(`[π― ${e} ${Me("Selector Subscription",e)} π―]`)}return y&&m&&(y.buildProxySubscriptions((e,t)=>{f.add(e.subscribe(t,x,Be))},o),d=void 0,y.reset(),c&&(y=void 0)),F&&n&&function(e,t){const n=function(){const e=u.has(He)?u.size-1:u.size;return S>0&&S<e}(),o=!S||n,s=n||null!==Ie()||Fe()&&o;n&&Ae(),r&&console.log(`[π» Derive Complete π»]: Notifying ${u.size} ${Me("watcher",u.size)}`);for(const t of u){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}s?v||(v=!0,Qe(O)||(O=t),Ce(a,C)):A(e,t)}(h,t),c&&(m=!1),h}function A(e,t){for(const n of u)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function C(){if(!u.size)return;if(b&&!S&&I(),!Qe(h))return;const e=Qe(O)?O:h;A(h,e),v=!1,O=_e}const k=n?W(E,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,T=k??(()=>{g||(g=!0,queueMicrotask(E))});function E(){g=!1,u.size?b&&I():K()}function D(e){e||k&&b?queueMicrotask(()=>{u.size||K()}):K()}function z(){E(),w=null}function x(){if(!b){if(b=!0,!k){if(S){Ae();const e=Ie(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!me)return;const n=t<0?0:0|t,r=we.get(e);if(void 0===r){we.set(e,n);let t=Oe.get(n);return t||(t=new Set,Oe.set(n,t)),t.add(e),void(n<je&&(je=n))}if(n>r){const t=Oe.get(r);if(t&&(t.delete(e),0===t.size&&(Oe.delete(r),r===je))){je=1/0;for(const e of Oe.keys())e<je&&(je=e)}we.set(e,n);let o=Oe.get(n);o||(o=new Set,Oe.set(n,o)),o.add(e),n<je&&(je=n)}}(z,t)}if(Fe())return void(v||(v=!0,Qe(h)&&(O=h),Ce(a,C)))}w=null,T()}}function M(){return b||!Qe(h)?u.size>0?I():e(q):h}function K(e=!0){i&&e||(k?.cancel(),j(),u.clear(),S=0,y=void 0,d=void 0,m=!0,g=!1,b=!0,h=_e,v=!1,O=_e,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){u.size&&(k?k.flush():b&&I())},getSnapshot:function(){if(!Qe(h)){u.add(He);const e=I();return u.delete(He),e}return g&&E(),h},getState:M,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||Qe(h)||M(),()=>{u.delete(t),u.size||D(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,s=r?.isDerivedStore??!1,i={currentSlice:void 0,equalityFn:o,isDerivedWatcher:s,listener:n,selector:t};return u.add(i),i.currentSlice=t(M()),s&&(S+=1),r?.fireImmediately&&n(i.currentSlice,i.currentSlice),()=>{u.delete(i),s&&(S-=1),u.size||D(s)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}(e,t),Object.assign(function(e=p,t){return x(n.subscribe,n.getSnapshot,void 0,e,t)},n);var n}var _e=Symbol(),Be=Object.freeze({equalityFn:Object.is,isDerivedStore:!0}),Je=0;function He(){}function Qe(e){return e!==_e}var Ge,Xe=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=Q.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Ye(e,t){const n=t?.baseDelay??Q.seconds(5),r=t?.maxDelay??Q.minutes(5);return Math.min(n*Math.pow(2,e),r)}var Ze={Error:"error",Idle:"idle",Loading:"loading",Success:"success"};function et(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(et(n,t))return n}let o,s,i;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((s=e.length)===t.length)for(;s--&&et(e[s],t[s]););return-1===s}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(i=n,i&&"object"==typeof i&&(i=r(t,i),!i))return!1;if(!t.has(i))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(i=n[0],i&&"object"==typeof i&&(i=r(t,i),!i))return!1;if(!et(n[1],t.get(i)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((s=e.byteLength)===t.byteLength)for(;s--&&e.getInt8(s)===t.getInt8(s););return-1===s}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((s=n.byteLength)===r.byteLength)for(;s--&&n[s]===r[s];);return-1===s}if(!o||"object"==typeof e){s=0;for(const r in e){if(n.call(e,r)&&++s&&!n.call(t,r))return!1;if(!(r in t)||!et(e[r],t[r]))return!1}return Object.keys(t).length===s}}return e!=e&&t!=t}var tt=new WeakMap,nt=new WeakMap;function rt(e,t=ot,n=et){return function(e,t,n){let r=nt.get(e);r||(r=new Map,nt.set(e,r));let o=r.get(t);o||(o=new Map,r.set(t,o));const s=o.get(n);if(s)return s;const[i,c,a]=it(e,t,n),u=new Map,l=e=>{const t={get(t,n){if("value"===n){let t=c();const n=e.split(".");for(const e of n)e&&(t=t[e]);return t}const r="string"==typeof n?n:n.toString(),o=e?`${e}.${r}`:r,s=u.get(o);if(s)return s;const a=l(o);return tt.set(a,i),u.set(o,a),a},set(t,n,r){const o=e.split(".");return""===o[0]&&o.shift(),a(o,r),!0}};return new Proxy(h(),t)},f=l("");return i(()=>{}),tt.set(f,i),o.set(n,f),f}(e,t,n)}var ot=e=>e,st=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,s=e[r],i=st(s,o,n);if(et(s,i))return e;const c=Array.isArray(e)?e.slice():{...e};return c[r]=i,c},it=(e,t,n)=>{const r=new Set,o=ie(e);let s,i=t(o?e.getSnapshot():e.getState());return[c=>(r.size||(s=e.subscribe(t,e=>{i=e,r.forEach(e=>e())},{equalityFn:n,isDerivedStore:o})),r.add(c),()=>{r.delete(c),!r.size&&s&&(s(),s=void 0)}),()=>(r.size||(i=t(e.getState())),i),(n,r)=>{if(t!==ot)throw new Error("Cannot set a value with a selector");e.setState(e=>st(e,n,r),!0)}]};function ct(e){return tt.get(e)}var at={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},ut=Object.freeze({force:!0}),lt=Object.freeze({once:!0}),ft=Object.freeze({updateQueryKey:!0});function dt(e){return JSON.stringify(yt(e))}function yt(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=d(r)?yt(r):r,t},h())}function pt(e,t,n,r){return r?gt(r,n)?r:{...ht(e,t),...r}:ht(e,t)}function ht(e,t){const n=Object.assign(h(),t?.params);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function gt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function bt(e){return"function"==typeof e}function mt(e){return!bt(e)}function St(e,t){return n=>{const r={...n},o=h();for(const e in r)f(r,e)&&e in at&&(at[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):H(r),...vt(e,null,o)}}}function vt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),s=h();let i=!1;for(const e in n.queryCache){if(!f(n.queryCache,e))continue;const c=n.queryCache[e];c&&(r-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===o)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(s[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},i=!0):s[e]=c:i=!0}return i?{...n,queryCache:s}:n}function wt(){return Object.create(null)}function Ot(e,t,n){return new a(`[createQueryStore: ${e}]: ${t} failed`,n)}function qt(e){return function(t,n){return n?e().setState(t,n):e().setState(t)}}var jt=Symbol(),Ft=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1}),It=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function At(e,t,n=It){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(n=It)=>At(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function Ct(e){return"function"==typeof e?{equalityFn:e}:e??Ft}var kt=Symbol();function Tt(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Et(e,t){return"function"==typeof e[t]}exports.QueryStatuses=Ze,exports.StoresError=a,exports.applyStateUpdate=oe,exports.configureStores=function(e){var t;o&&function(){if(C)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,c=t),O??(O=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),q??(q=E(e))},exports.createBaseStore=be,exports.createDerivedStore=Ue,exports.createQueryStore=function(e,t,n){T();const r="function"==typeof t?t:wt,i="object"==typeof t?t:n,l=i&&"storageKey"in i?i:void 0,d=Ge??(Ge=function(){const e={abortInterruptedFetches:!0,cacheTime:Q.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:Ye,staleTime:Q.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(O)return O}()?.queryStoreDefaults;return t?{...e,...t}:e}()),y=d.minStaleTime,{fetcher:p,onError:g,onFetched:b,setData:m,transform:S,abortInterruptedFetches:v=d.abortInterruptedFetches,cacheTime:w=d.cacheTime,debugMode:q=d.debugMode,disableAutoRefetching:j=d.disableAutoRefetching,disableCache:F=!1,enabled:I=!0,keepPreviousData:A=d.keepPreviousData,maxRetries:C=d.maxRetries,paramChangeThrottle:k=d.paramChangeThrottle,params:E,retryDelay:D=d.retryDelay,staleTime:z=d.staleTime,suppressStaleTimeWarning:x=d.suppressStaleTimeWarning}=e;let M="function"==typeof z?d.staleTime:z;o&&!1!==y&&!j&&!x&&M<y&&console.warn(`[createQueryStore${l?.storageKey?`: ${l.storageKey}`:""}] β Stale times under ${y/1e3} seconds are not recommended. Provided staleTime: ${M/1e3} seconds`);const K=new Error("[createQueryStore: AbortError] Fetch interrupted"),$="function"==typeof w,P=o&&q,R=e.params?Object.keys(e.params):[];let L=null,N=null,V=null,U=[],_=!1,B=!1,J=null,H=null,G=null,X=null,Y=null;const Z={enabled:"function"!=typeof I&&I,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:Ze.Idle},ee=new Xe({disableAutoRefetching:j,initialEnabled:Z.enabled});function te(){J&&(H=null,J.abort(),J=null)}function ne(t,n,o){const s=o.setState;function i(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=s(r=>{const o=t?e(r):e,s=void 0!==o.enabled?o.enabled:r.enabled;return s!==r.enabled&&(n=()=>function(e,t){e!==t&&Y!==t&&(Y=t,ee.setEnabled(t),t?queueMicrotask(()=>d.fetch(void 0,ft)):(G||v)&&(v&&te(),G&&(clearTimeout(G),G=null)))}(r.enabled,s)),o});return n?.(),r}return s(e)}function f(e,t){if(j||t?.skipStoreUpdates)return;if(M<=0||M===1/0)return;G&&(clearTimeout(G),G=null);const r=dt(e),o=n(),s=(F?X===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,i=s?M-(Date.now()-s):M;G=setTimeout(()=>{const t=ee.get();t.enabled&&t.subscriptionCount>0&&d.fetch(e,ut,!0)},i)}o.setState=i,ee.init({onSubscribe:(r,o,s)=>{if(N||L||!E&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=ht(L,N),r=dt(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?d.fetch(e,void 0,!0):f(e,void 0)}else j&&!s&&d.fetch(void 0,void 0,!0)}else _=!0},onLastUnsubscribe:e=>{G&&(clearTimeout(G),G=null),v&&!e&&te()}});const d={...r(i,n,o),...Z,async fetch(e,r,o=!1){const s=ee.get();if(!r?.force&&!r?.skipStoreUpdates&&!s.enabled)return null;const y=n(),h=y.error,O=y.queryKey,q=y.status===Ze.Loading,j=pt(L,N,R,e),I=dt(j);if(q&&H?.promise&&H.key===I)return P&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(j)),H.promise;const k=r?.staleTime??M,T=!!r?.skipStoreUpdates,E="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&A,z=(o||O===I||E)&&!T;if(v&&z&&te(),!r?.force){const e=y.lastFetchedAt,n=y.queryCache[I],o=n?.lastFetchedAt,i=n?.errorInfo,c=i&&i.retryCount>=C,a=(F?X===I&&e:o)||null;if(a&&!(Date.now()-a>=k)&&(!i||c||T))return z&&!G&&s.subscriptionCount>0&&0!==M&&M!==1/0&&f(j,r),E&&t(e=>e.queryKey!==I?{queryKey:I}:e),P&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(j)),n?.data??null}z&&(G&&(clearTimeout(G),G=null),!h&&q||t({error:null,status:Ze.Loading}),H={key:I});const x=r?.cacheTime??($?w(j):w);async function V(){const s=l?.storageKey||I;try{P&&(o||!e||gt(e,R)?console.log("[π Fetching π] for params:",JSON.stringify(j)):console.log("[π Fetching with Partial Params π]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(j).filter(t=>!(t in e)).map(e=>[e,j[e]])))}`));const n=await(v&&z?async function(e){const t=new AbortController;J=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(K),lt),Promise.resolve(p(e,t)).then(n,r)})}finally{J===t&&(J=null)}}(j):p(j,null)),a=Date.now();let u;P&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(j));try{u=function(e,t,n){return n?n(e,t):e}(n,j,S)}catch(e){throw Ot(s,"transform",e)}if(T)return P&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(j)),"withCache"===r.skipStoreUpdates&&t(e=>{if(!m)return F?e:{queryCache:{...e.queryCache,[I]:{cacheTime:x,data:u,errorInfo:null,lastFetchedAt:a}}};let t=e;const n=t.queryCache[I];try{m({data:u,params:j,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ot(s,"setData",e)}return!F&&Object.is(n,t.queryCache[I])&&(t={...t,queryCache:{...t.queryCache,[I]:{cacheTime:x,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),u;if((m?i:t)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:E?I:e.queryKey,status:Ze.Success};if(m||F){if(m){P&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(j));const e=t.queryCache[I];try{m({data:u,params:j,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ot(s,"setData",e)}!F&&Object.is(e,t.queryCache[I])&&(t.queryCache={...t.queryCache,[I]:{cacheTime:x,data:null,errorInfo:null,lastFetchedAt:a}})}}else P&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(j),"| Has previous data?:",!!t.queryCache[I]?.data),t.queryCache={...t.queryCache,[I]:{cacheTime:x,data:u,errorInfo:null,lastFetchedAt:a}};return F||w===1/0?t:vt(A,I,t)}),z&&(X=I,f(j,r)),b)try{b({data:u,fetch:d.fetch,params:j,set:i})}catch(e){c.error(Ot(s,"onFetched callback",e))}return u??null}catch(i){if(i===K)return P&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(j)),null;const l=!o&&!0===r?.throwOnError,f=u(i);if(f instanceof a&&c.error(f),!z){if(l)throw f;return null}const y=F?void 0:n().queryCache[I],p=y?.errorInfo?.retryCount??0,h=p+1;try{g?.(f,p)}catch(e){c.error(Ot(s,"onError callback",e))}if(p<C){if(ee.get().subscriptionCount>0){const t="function"==typeof D?D(h,f):D;t!==1/0&&(G&&clearTimeout(G),G=setTimeout(()=>{const t=ee.get();t.enabled&&t.subscriptionCount>0&&d.fetch(e,ut,!0)},t))}t(e=>({error:f,queryCache:{...e.queryCache,[I]:{cacheTime:y?.cacheTime??x,data:y?.data??null,lastFetchedAt:y?.lastFetchedAt??null,errorInfo:{error:f,lastFailedAt:Date.now(),retryCount:h}}},queryKey:E?I:e.queryKey,status:Ze.Error}))}else t(e=>({error:f,queryCache:{...e.queryCache,[I]:{cacheTime:y?.cacheTime??x,data:y?.data??null,lastFetchedAt:y?.lastFetchedAt??null,errorInfo:{error:f,lastFailedAt:Date.now(),retryCount:C}}},queryKey:E?I:e.queryKey,status:Ze.Error}));if(l)throw f;return null}finally{z&&(H=null)}}return z?(H={key:I,promise:V()}).promise:V()},getCacheEntry(e){if(F)return null;const t=n(),r=e?"string"==typeof e?e:dt(pt(L,N,R,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(F)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?A?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){const t=n(),r=t.status;switch(e){case"isIdle":return r===Ze.Idle;case"isLoading":return r===Ze.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],s=F?r===Ze.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return s;const i=null!==((F?X===n&&t.lastFetchedAt:o?.lastFetchedAt)||null),c=!i&&!s&&t.enabled;if("isInitialLoad"===e)return c;const a=i&&!s;return"isSuccess"===e?a:{isError:s,isIdle:r===Ze.Idle,isLoading:r===Ze.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,s=t.lastFetchedAt,i=(F?X===o&&s:r?.lastFetchedAt)||null;if(!i)return!0;const c=e??r?.cacheTime;return void 0===c||Date.now()-i>=c},isStale(e){const t=n(),r=t.queryKey,o=(F?X===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const s=e??M;return Date.now()-o>=s},reset(e=!1){for(const e of U)e();U=[],L=null,N=null,V=null,te(),G&&(clearTimeout(G),G=null),H=null,X=null,e&&t(Z)}},y=o.subscribe;return o.subscribe=(...e)=>{const t=B?()=>{}:ee.subscribe(),n=1===e.length?y(e[0]):y(e[0],e[1],e[2]);return e=>{t(e),n()}},d}const oe=l?.storageKey?be(ne,(se=l,void 0===(ie={partialize:St(A,l.partialize)})?Object.assign(h(),se):Object.assign(h(),se,ie))):i&&!("storageKey"in i)?be(ne,i):be(ne);var se,ie;const ce=oe.getState(),ae=ce.error,ue=ce.enabled,le=ce.queryKey,fe=ce.fetch;let de;if(le&&!ae&&(X=le),B=!0,E||"function"==typeof e.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:n,attachVals:r}=function(e,t,n){const r=h(),o=h(),s=h();for(const e in t){if(!f(t,e))continue;const i=t[e];if(bt(i)){const t=i(rt,n);r[e]=t,s[e]=t.value}else mt(i)&&(o[e]=i,s[e]=i)}let i,c=null,a=null;if(bt(e)){const t=e(rt,n);i=t.value,c=t}else i=e,a=e;return{attachVals:r,directValues:o,enabledAttachVal:c,enabledDirectValue:a,resolvedEnabled:i,resolvedParams:s}}(I,E,oe);L={enabled:t,params:r},N={enabled:n,params:e}}"function"==typeof e.staleTime&&(V=e.staleTime(rt,oe),M=V.value);const ye=Object.freeze({updateQueryKey:A}),pe=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{fe(e??ht(L,N),ye)})(...e)}))}}();function he(){let e;if(!A){e=ht(L,N);const t=dt(e);oe.setState({queryKey:t})}pe(e)}const ge=s||!k?he:W(he,"number"==typeof k?k:k.delay,"number"==typeof k?{leading:!1,maxWait:k,trailing:!0}:k);for(const e in L?.params){const t=L.params[e];if(!t)continue;const n=ct(t);if(P&&console.log("[π Param Subscription π] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;et(r,n)||(P&&console.log("[π Param Change π] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,ge())});U.push(o)}}if(V){const e=ct(V);if(e){const t=V;let n=t.value;P&&console.log("[π StaleTime Subscription π] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(P&&console.log("[π StaleTime Change π] - [Old]:",`${n},`,"[New]:",e),n=e,M=e,fe())});U.push(r)}}if(L?.enabled){const e=L.enabled,t=ct(e);if(t){let n=e.value;ue!==n&&((de??(de={})).enabled=n),n&&ee.setEnabled(n),P&&console.log("[π Enabled Subscription π] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(P&&console.log("[π Enabled Change π] - [Old]:",`${n},`,"[New]:",t),n=t,oe.setState({enabled:t}))});U.push(r)}}else ue!==Z.enabled&&((de??(de={})).enabled=Z.enabled);const me=dt(ht(L,N));return me!==le&&((de??(de={})).queryKey=me),de&&oe.setState(de),B=!1,_&&queueMicrotask(ge),Se=oe,ve=re.QueryStore,Object.assign(Se,{[ve]:!0});var Se,ve},exports.createStoreActions=function(e,t){const n=function(e){const t=e.getState(),n=h(),r=n;if(o&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(ue(e))for(const n in t)Et(t,n)&&(r[n]=Tt(e,n));else for(const e in t)Et(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n},exports.createVirtualStore=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,s=r?n:t,i=new Set,c=Ue(e,{debugMode:s?.debugMode??!1,equalityFn:function(e,t){const n=Object.is(e,t);return n||(function(e,t){for(const n of i){n.unsubscribe();const r=n.args;if(1===r.length){const o=r[0],s=e.getState(),i=t.getState(),c=t.subscribe(o);n.unsubscribe=c,Object.is(i,s)||o(i,s);continue}const o=r[0],s=r[1];let i=r[2];i?.fireImmediately&&(i={...i,fireImmediately:!1});const c=o(e.getState()),a=o(t.getState()),u=t.subscribe(o,s,i);n.unsubscribe=u,(i?.equalityFn??Object.is)(c,a)||s(a,c)}}(e,t),se(e)),n},keepAlive:!0,lockDependencies:s?.lockDependencies??!0});return Object.assign(function(e,t){const n=c();return e?n(e,t):n()},{[re.VirtualStore]:!0,destroy:c.destroy,getInitialState:()=>c.getState().getInitialState(),getState:()=>c.getState().getState(),persist:(a=c.getState,{clearStorage:()=>a().persist?.clearStorage(),getOptions:()=>a().persist?.getOptions()??{},hasHydrated:()=>a().persist?.hasHydrated()??!0,hydrationPromise:()=>a().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>a().persist?.onFinishHydration(e)??g,onHydrate:e=>a().persist?.onHydrate(e)??g,rehydrate:()=>a().persist?.rehydrate(),setOptions:e=>a().persist?.setOptions(e)}),setState:qt(c.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?c.getState().subscribe(e[0]):c.getState().subscribe(e[0],e[1],e[2])};return i.add(t),()=>{t.unsubscribe(),i.delete(t)}}},o?.(c.getState));var a},exports.deepEqual=function e(t,n){if("object"!=typeof t||null==t||"object"!=typeof n||null==n)return t===n;if(Object.is(t,n))return!0;const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const o of r)if(!(o in n)||!e(t[o],n[o]))return!1;return!0},exports.defaultRetryDelay=Ye,exports.destroyStore=se,exports.destroyStores=function(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&se(n,t)},exports.getQueryKey=dt,exports.getStoreName=function(e){return ae(e)?e.persist.getOptions().name??e.name:e.name},exports.hasGetSnapshot=ie,exports.identity=p,exports.isDerivedStore=function(e){return"flushUpdates"in e},exports.isPersistedStore=ae,exports.isQueryStore=ce,exports.isVirtualStore=ue,exports.nullObject=h,exports.parseQueryKey=function(e){return JSON.parse(e)},exports.replacer=B,exports.reviver=J,exports.shallowEqual=function(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0},exports.time=Q,exports.useListen=function(e,t,r,o=Ft){const s=function(){const e=n.useRef(jt);return e.current===jt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:Ct(n),resubscribe:()=>{},unsubscribe:()=>{}}}(t,r,o)),e}(),i=function(e){return"function"==typeof e?Ft.enabled:e?.enabled??Ft.enabled}(o);return s.current.react=r,s.current.selector=t,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Ft)}(s,o),n.useLayoutEffect(()=>{if(i)return At(e,s),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(s)},[i,e]),s},exports.useStableValue=function(e){const t=n.useRef(kt);return t.current===kt&&(t.current=e()),t.current};
|
package/dist/web/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{IS_TEST as e,IS_BROWSER as t,IS_IOS as n,markStoreCreated as r,getStoresConfig as o,StoresError as i,IS_DEV as s,hasOwn as c,logger as a,ensureError as u,isPromiseLike as l,unstable_batchedUpdates as f,reviver as d,replacer as y}from"./chunk-MMPMCVRC.mjs";export{configureStores,replacer,reviver}from"./chunk-MMPMCVRC.mjs";import{subscribeWithSelector as p,persist as h}from"zustand/middleware";import{createWithEqualityFn as g}from"zustand/traditional";import{useSyncExternalStoreWithSelector as b}from"use-sync-external-store/shim/with-selector";import{useLayoutEffect as m,useRef as S}from"react";function v(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var w=Math.max,O=Math.min;function j(e,t=0,n={}){let r,o,i,s,c,a,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function h(){const e=q();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==i?O(n,i-(e-u)):n}(e))}function g(e){return c=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=q(),i=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(h,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(h,t),y(a)}return void 0===c&&(c=setTimeout(h,t)),s}return t=C(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,i=f?w(C(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==c&&clearTimeout(c),u=0,r=a=o=c=void 0},b.flush=function(){return void 0===c?s:g(q())},b}function q(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function C(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e)}function F(e){if(null!==e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))"function"!=typeof r&&(t[n]=r);return t}return e}var A={ms:e=>e,seconds:e=>1e3*e,minutes:e=>A.seconds(60*e),hours:e=>A.minutes(60*e),days:e=>A.hours(24*e),weeks:e=>A.days(7*e),infinity:1/0,zero:0},I=e?0:t?A.ms(200):n?A.seconds(3):A.seconds(5);function k(e){return t=>{if("string"!=typeof t)throw new i("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?d:void 0)}catch(e){throw a.error(new i("[createBaseStore]: Failed to deserialize persisted store data"),{error:e}),e}}(t,e)}}function T(e){return t=>function(e,t){try{return JSON.stringify(e,t?y:void 0)}catch(e){throw a.error(new i("[createBaseStore]: Failed to serialize store data"),{error:e}),e}}(t,e)}var z=Object.freeze({shouldClear:!1});function M(e,t,n){if(!t||!e)return z;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function D(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function K(e){return!!e&&!!e.getIsApplyingRemote()}var $=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function E(e,...t){if(!0===t[1])return Q(t[0])?t[0](e):t[0];const n=Q(t[0])?t[0](e):t[0];return function(e){return Array.isArray(e)}(e)?n:{...e,...n}}function P(e,t){N(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function L(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&P(n,t)}function x(e){return V(e)?e.persist.getOptions().name??e.name:e.name}function R(e){return"getSnapshot"in e}function N(e){return $.QueryStore in e}function W(e){return"flushUpdates"in e}function V(e){return"persist"in e}function J(e){return $.VirtualStore in e}function Q(e){return"function"==typeof e}var[B,U]=[0,1];function H(e,t,n){if(!e)return!0;const r=e[B],o=e[U];return!(t<r)&&(t>r||n>o)}function _(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function G(e,t){if(!s)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function X(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Y(e,t){r();const n=void 0!==t&&"string"==typeof t.storageKey,s=n?t.storageKey:void 0,c=t?.sync?function(e,t){if(!e)return null;if(!0===e){if(!t)throw new i("[createBaseStore]: sync: true requires a storageKey to inherit the key from");return{key:t}}if("string"==typeof e)return{key:e};const n=e,r=n.key??t;if(!r)throw new i("[createBaseStore]: sync requires either a key in the config or a storageKey to inherit from");return{...n,key:r}}(t.sync,s):void 0,f=n?t.storage??o().storage:void 0,d=c?function(e,t,n){const r=t.engine??o().syncEngine,s=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(o,c,u)=>{const f=new Map,d=[],y=[];let p=null,h=!1,g=!1,b=0,m=null,S=[],v=Promise.resolve(),w=!n;const O=(e,t)=>{if(s?.setSessionId&&s?.setTimestamp&&r.sessionId&&(s.setSessionId(r.sessionId),s.setTimestamp(e),s.mergeFieldTimestamps&&t.length>0)){const n=Object.create(null);for(const r of t)n[String(r)]=e;s.mergeFieldTimestamps(n)}},j=function(e,t){if(h||!m)return t?o(e,t):o(e);const n=(()=>{const e=Date.now(),t=e>b?e:b+1;return b=t,t})();let i=[],s=Object.create(null);const c=r=>{const o=E(r,e,t);for(const e of S)Object.is(o[e],r[e])||(i.push(e),s[e]=o[e]);return i.length&&O(n,i),o},a=t?o(c,!0):o(c),u=()=>{i.length&&(e=>{const t=r.sessionId;for(const n of e.keys)f.set(n,[e.timestamp,t]);p&&g?p.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):y.push(e)})({keys:i,replace:t??!1,values:s,timestamp:n})};return l(a)?a.finally(u):(u(),a)},q=u.setState;u.setState=j;const C=e(j,c,u);if(S=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(C),!S.length)return C;m=new Set(S);const F=async e=>{b=Math.max(b,e.timestamp);const n=Object.create(null),r=c(),o=e.timestamp;let u;if(e.replace)for(const t of S)_(t,e.values)||H(f.get(t),o,e.sessionId)&&(u??(u=[])).push(t);for(const s of S){if(!_(s,e.values))continue;if(!m?.has(s))continue;if(!H(f.get(s),o,e.sessionId))continue;const c=t.merge?.[s];if(c){const t=e.values[s],u=r[s];if(void 0!==t){const l=c(t,u,r,e.values),d=void 0!==u?u:t;if(!G(l,d))return void a.error(new i(`[sync] Merge function for field "${String(s)}" returned ${X(l)} but expected ${X(d)}`));n[s]=l,f.set(s,[o,e.sessionId])}}else n[s]=e.values[s],f.set(s,[o,e.sessionId])}if(Object.keys(n).length>0||u?.length){h=!0,s&&s.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(u?.length){t=!0;for(const t of u)delete e[t],f.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(s.setWithoutPersist??q)(e,!0)}else await(s.setWithoutPersist??q)(n)}finally{h=!1,s&&s.setIsApplyingRemote(!1)}}},A=e=>{n?v=v.then(()=>F(e)):F(e)};p=r.register({apply:e=>{w?A(e):d.push(e)},delta:t.delta,fields:S,getState:c,key:t.key});const I=()=>{g=!0,(()=>{if(p&&y.length){for(const e of y){const t=r.sessionId;for(const n of e.keys)f.set(n,[e.timestamp,t]);O(e.timestamp,e.keys),p.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}y.length=0}})()},k=()=>{w=!0,(()=>{if(!d.length)return;const e=d.slice();d.length=0;for(const t of e)A(t)})()};return n&&s?(s.onHydrationComplete=I,s.onHydrationFlushEnd=k):p.onHydrated?(p.onHydrated(I),k()):(I(),k()),C},syncContext:s}}(e,c,f?.async??!1):void 0,y=d?.stateCreator??e;if(!n)return g()(p(y),Object.is);const b=f?.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=v()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)e[1]?s.setState(e[0],e[1]):s.setState(e[0]);c=void 0}},e((...e)=>o?!0===e[1]?n(e[0],e[1]):n(e[0]):(t||(t=v()),c||(c=[]),c.push(e),t.promise),i,s)},wrapOnRehydrateStorage:(e,n)=>i=>{const s=e?.(i);return(e,i)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),i?t?.fail(u(i)):t?.complete(),s?.(e,i)}}}}(y):null,m=function(e,t,n){const r=t??e.storage??o().storage,s=(e.sync?void 0:e.persistThrottleMs??I)||void 0,c=e.version??0,u=r.async?function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),c=t.partialize??F,u=t.deserializer??e.deserializer??k(o),l=t.serializer??e.serializer??T(o);async function f(t,n){try{if(K(r))return;n.state,n.state=c(n.state);const o=M(r,s,n),u=l(n);try{await e.set(t,u),D(r,o)}catch(e){a.error(new i("[createBaseStore]: Failed to persist store data"),{error:e})}}catch(e){a.error(new i("[createBaseStore]: Failed to serialize persisted store data"),{error:e})}}const d=void 0!==n?j(f,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(f);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:u(n)},setItem:async(e,t)=>{if(!r?.getIsApplyingRemote())return await d(e,t)},removeItem:async t=>{try{await e.delete(t)}catch(e){a.error(new i("[createBaseStore]: Failed to delete persisted store data"),{error:e})}}}}(r,e,s,n):function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),c=t.partialize??F,u=t.deserializer??e.deserializer??k(o),l=t.serializer??e.serializer??T(o);function f(t,n){try{if(K(r))return;n.state,n.state=c(n.state);const o=M(r,s,n),u=l(n);try{e.set(t,u),D(r,o)}catch(e){a.error(new i("[createBaseStore]: Failed to persist store data"),{error:e})}}catch(e){a.error(new i("[createBaseStore]: Failed to persist store data"),{error:e})}}const d=void 0!==n?j(f,n,{leading:!1,maxWait:n,trailing:!0}):f;return{getItem:t=>{const n=e.get(t);return void 0===n?null:u(n)},setItem:(e,t)=>{r?.getIsApplyingRemote()||d(e,t)},removeItem:t=>{try{e.delete(t)}catch(e){a.error(new i("[createBaseStore]: Failed to delete persisted store data"),{error:e})}}}}(r,e,s,n);return{persistStorage:u,version:c}}(t,f,d?.syncContext),S=b?b.wrapOnRehydrateStorage(t.onRehydrateStorage,d?.syncContext):t.onRehydrateStorage,w=b?(e,t,n)=>(d&&(d.syncContext.setWithoutPersist=n.setState),b.stateCreator(e,t,n)):y,O=g()(p(h(w,function(e,t,n){const r={name:e.storageKey,onRehydrateStorage:n,storage:t.persistStorage,version:t.version};return void 0!==e.merge&&(r.merge=e.merge),void 0!==e.migrate&&(r.migrate=e.migrate),r}(t,m,S))),Object.is);return b?Object.assign(O,{persist:Object.assign(O.persist,{hydrationPromise:b.hydrationPromise})}):O}function Z(e,t,n="s"){return 1===t?e:`${e}${n}`}function ee(e,t,n){const r=t.get(e);if(!r){const r=function(e,t,n,r=[]){return e&&"object"==typeof e?te(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(R(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,r),r}return r}function te(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(o.has(s))return Reflect.get(s,c,a);if("__proto__"===c||"symbol"==typeof c)return c===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,c,a);const u=Reflect.get(s,c,s),l=String(c),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(s,c)?function(...e){return r(n,f,!0,{method:l,args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,te(u,f,n,r,o,i)),i.get(u)):u},getOwnPropertyDescriptor:(e,i)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,i)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function ne(e){return t=>oe(t,e)}function re(e,t){const n=e.slice(0,-1);return e=>{const r=oe(e,n),o=r?.[t.method];return"function"==typeof o?o.apply(r,t.args):void 0}}function oe(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=n[e]}return n}function ie(){const e=new Map;return{buildProxySubscriptions(t,n){const r=new Set;for(const[t,n]of e)ae(n,t,[],0,r);!function(e,t,n){for(const n of e)t(n.store,n.invocation?re(n.path,n.invocation):ne(n.path));n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${Z("Proxy Subscription",t)} π‘]:`,JSON.stringify(Array.from(e).map(e=>{const t=x(e.store),n=e.path.join(".");if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;const r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${Z("arg",r)})`:"()"}`}),null,2))}(e)}(r,t,n)},trackPath(t,n,r,o){let i=e.get(t);i||(i=se(),e.set(t,i)),ce(i,n,0,r,o)}}}function se(){return Object.create(null)}function ce(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&(e.invocation=o));e.children||(e.children=se());const i=t[n];let s=e.children?.[i];s||(s=se(),e.children[i]=s),ce(s,t,n+1,r,o)}function ae(e,t,n,r,o,i=1){const s=e.children;if(!s)return void o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});for(const e of c){const c=s[e];c.invocation&&ae(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)ae(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void ae(s[e],t,[...n,e],r+1,o,i)}o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}else o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}var ue=!1,le=!1,fe=new Map,de=new Map,ye=new Map,pe=null,he=1/0;function ge(){return ue}function be(){return pe}function me(){ue||(ue=!0,le||(le=!0,queueMicrotask(()=>{le=!1,f(()=>{for(;de.size>0;){const e=he,t=ye.get(e);if(t){ye.delete(e);for(const e of t)de.delete(e);pe=e;for(const e of t)e();if(pe=null,ye.size>0){he=1/0;for(const e of ye.keys())e<he&&(he=e)}else he=1/0}else{he=1/0;for(const e of ye.keys())e<he&&(he=e)}}for(;fe.size>0;){const e=Array.from(fe.values());fe.clear();for(const t of e)t()}}),ue=!1,pe=null,de.clear(),ye.clear(),he=1/0})))}function Se(e,t){ue&&fe.set(e,t)}var ve=e=>e;function we(e,t=Object.is){return n=function(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:c}="function"==typeof(l=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:l,keepAlive:!1,lockDependencies:!1}:{debounceOptions:l.debounce,debugMode:(s&&l.debugMode)??!1,equalityFn:l.equalityFn??Object.is,keepAlive:l.keepAlive??!1,lockDependencies:l.lockDependencies??!1},a=String(je+=1),u=new Set;var l;i&&u.add(qe);const f=new Set;let d,y,p=Oe,h=!1,g=!0,b=!0,m=0,S=!1,v=null,w=Oe;function O(e,t,n){if(!b||!u.size)return(t??ve)(R(e)?e.getSnapshot():e.getState());if(!t)return d||(d=new WeakMap),y||(y=ie()),ee(e,d,y.trackPath);const r=e.subscribe(t,K,{equalityFn:n??Object.is,isDerivedStore:!0});return f.add(r),t(R(e)?e.getSnapshot():e.getState())}function q(e){for(const t of f)t(e);f.clear()}let C=!0;function F(){if(!g&&Ce(p))return p;g=!1,b&&q(!0);const t=p,n=Ce(t);p=function(t){C=!0;const n=p,i=e(t);return Ce(n)&&o(n,i)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),C=!1,n):i}(O);const i=r&&(!n||"verbose"===r&&b);if(i){n?"verbose"===r&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=f.size;console.log(`[π― ${e} ${Z("Selector Subscription",e)} π―]`)}return y&&b&&(y.buildProxySubscriptions((e,t)=>{const n=e.subscribe(t,K,{equalityFn:Object.is,isDerivedStore:!0});f.add(n)},i),d=void 0,y=void 0),C&&n&&function(e,t){const n=function(){const e=u.has(qe)?u.size-1:u.size;return m>0&&m<e}(),o=!m||n,i=n||null!==be()||ge()&&o;n&&me(),r&&console.log(`[π» Derive Complete π»]: Notifying ${u.size} ${Z("watcher",u.size)}`);for(const t of u){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}i?S||(S=!0,Ce(w)||(w=t),Se(a,I)):A(e,t)}(p,t),c&&(b=!1),p}function A(e,t){for(const n of u)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function I(){if(!u.size)return;if(g&&!m&&F(),!Ce(p))return;const e=Ce(w)?w:p;A(p,e),S=!1,w=Oe}const k=n?j(z,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,T=k??(()=>{h||(h=!0,queueMicrotask(z))});function z(){u.size&&(h=!1,g&&F())}function M(e){e?queueMicrotask(()=>{u.size||E()}):E()}function D(){z(),v=null}function K(){if(!g){if(g=!0,!k){if(m){me();const e=be(),t=null===e?0:e+1;if(null!==v&&t<=v)return;return v=t,void function(e,t){if(!ue)return;const n=t<0?0:0|t,r=de.get(e);if(void 0===r){de.set(e,n);let t=ye.get(n);return t||(t=new Set,ye.set(n,t)),t.add(e),void(n<he&&(he=n))}if(n>r){const t=ye.get(r);if(t&&(t.delete(e),0===t.size&&(ye.delete(r),r===he))){he=1/0;for(const e of ye.keys())e<he&&(he=e)}de.set(e,n);let o=ye.get(n);o||(o=new Set,ye.set(n,o)),o.add(e),n<he&&(he=n)}}(D,t)}if(ge())return void(S||(S=!0,Ce(p)&&(w=p),Se(a,I)))}v=null,T()}}function $(){return g||!Ce(p)?u.size>0?F():e(O):p}function E(e=!0){i&&e||(k?.cancel(),q(),u.clear(),m=0,y=void 0,d=void 0,b=!0,h=!1,g=!0,p=Oe,S=!1,w=Oe,v=null)}return{destroy:()=>E(!1),flushUpdates:function(){u.size&&(k?k.flush():g&&F())},getSnapshot:function(){if(!Ce(p)){u.add(qe);const e=F();return u.delete(qe),e}return h&&z(),p},getState:$,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||Ce(p)||$(),()=>{u.delete(t),u.size||M(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isDerivedStore??!1,s={currentSlice:void 0,equalityFn:o,isDerivedWatcher:i,listener:n,selector:t};return u.add(s),s.currentSlice=t($()),i&&(m+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{u.delete(s),i&&(m-=1),u.size||M(i)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}(e,t),Object.assign(function(e=ve,t=void 0){return b(n.subscribe,n.getSnapshot,void 0,e,t)},n);var n}var Oe=Symbol(),je=0;function qe(){}function Ce(e){return e!==Oe}var Fe=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=A.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},Ae={Error:"error",Idle:"idle",Loading:"loading",Success:"success"};function Ie(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!(r in t)||!Ie(e[r],t[r]))return!1;return!0}function ke(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Te(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(Te(n,t))return n}let o,i,s;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((i=e.length)===t.length)for(;i--&&Te(e[i],t[i]););return-1===i}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(s=n,s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!t.has(s))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(s=n[0],s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!Te(n[1],t.get(s)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((i=n.byteLength)===r.byteLength)for(;i--&&n[i]===r[i];);return-1===i}if(!o||"object"==typeof e){i=0;for(const r in e){if(n.call(e,r)&&++i&&!n.call(t,r))return!1;if(!(r in t)||!Te(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}var ze=new WeakMap,Me=new WeakMap;function De(e,t=Ke,n=Te){return function(e,t,n){let r=Me.get(e);r||(r=new Map,Me.set(e,r));let o=r.get(t);o||(o=new Map,r.set(t,o));const i=o.get(n);if(i)return i;const[s,c,a]=Ee(e,t,n),u=new Map,l=e=>{const t={get(t,n){if("value"===n){let t=c();const n=e.split(".");for(const e of n)e&&(t=t[e]);return t}const r="string"==typeof n?n:n.toString(),o=e?`${e}.${r}`:r,i=u.get(o);if(i)return i;const a=l(o);return ze.set(a,s),u.set(o,a),a},set(t,n,r){const o=e.split(".");return""===o[0]&&o.shift(),a(o,r),!0}};return new Proxy(Object.create(null),t)},f=l("");return s(()=>{}),ze.set(f,s),o.set(n,f),f}(e,t,n)}var Ke=e=>e,$e=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,i=e[r],s=$e(i,o,n);if(Te(i,s))return e;const c=Array.isArray(e)?e.slice():{...e};return c[r]=s,c},Ee=(e,t,n)=>{const r=new Set,o=R(e);let i,s=t(o?e.getSnapshot():e.getState());return[c=>(r.size||(i=e.subscribe(t,e=>{s=e,r.forEach(e=>e())},{equalityFn:n,isDerivedStore:o})),r.add(c),()=>{r.delete(c),!r.size&&i&&(i(),i=void 0)}),()=>(r.size||(s=t(e.getState())),s),(n,r)=>{if(t!==Ke)throw new Error("Cannot set a value with a selector");e.setState(e=>$e(e,n,r),!0)}]},[Pe,Le]=[!0,!1],xe={error:Pe,lastFetchedAt:Pe,queryCache:Pe,queryKey:Pe,status:Pe,enabled:Le,fetch:Le,getCacheEntry:Le,getData:Le,getStatus:Le,isDataExpired:Le,isStale:Le,reset:Le},Re=A.seconds(5);function Ne(t,n,o){r();const l="function"==typeof n?n:_e,f="object"==typeof n?n:o,d=f&&"storageKey"in f?f:void 0,{fetcher:y,onError:p,onFetched:h,setData:g,transform:b,abortInterruptedFetches:m=!0,cacheTime:S=A.days(7),debugMode:v=!1,disableAutoRefetching:w=!1,disableCache:O=!1,enabled:q=!0,keepPreviousData:C=!1,maxRetries:F=5,paramChangeThrottle:I=!1,params:k,retryDelay:T=We,suppressStaleTimeWarning:z=!1,useParsableQueryKeys:M=!0}=t;let D="function"==typeof t.staleTime?A.minutes(2):t.staleTime??A.minutes(2);s&&!w&&!z&&D<Re&&console.warn(`[createQueryStore${d?.storageKey?`: ${d.storageKey}`:""}] β Stale times under ${Re/1e3} seconds are not recommended. Provided staleTime: ${D/1e3} seconds`);const K=M?Je:Ve,E=new Error("[createQueryStore: AbortError] Fetch interrupted"),P="function"==typeof S,L=s&&v,x=Object.keys(t.params??Object.create(null));let R=null,N=null,W=null,V=[],J=!1,Q=!1,B=null,U=null,H=null,_=null,G=null;const X={enabled:"function"!=typeof q&&q,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:Ae.Idle},Z=new Fe({disableAutoRefetching:w,initialEnabled:X.enabled}),ee=()=>{B&&(U=null,B.abort(),B=null)},te=(e,n,r)=>{const o=r.setState,s=(e,t)=>{const n="function"==typeof e;if(n||void 0!==e.enabled){let t;const i=o(o=>{const i=n?e(o):e,s=void 0!==i.enabled?i.enabled:o.enabled;return s!==o.enabled&&(t=()=>((e,t)=>{e!==t&&G!==t&&(G=t,Z.setEnabled(t),t?queueMicrotask(()=>r.getState().fetch(void 0,{updateQueryKey:!0})):(H||m)&&(m&&ee(),H&&(clearTimeout(H),H=null)))})(o.enabled,s)),i});return t?.(),i}return o(e)};r.setState=s,Z.init({onSubscribe:(r,o,i)=>{if(N||R||!k&&"function"!=typeof t.enabled&&"function"!=typeof t.staleTime){if(r)if(o){const t=He(R,N),r=K(t),o=n();o.queryKey!==r&&e(e=>({...e,queryKey:r})),o.isStale()?f.fetch(t,void 0,!0):c(t,void 0)}else w&&!i&&f.fetch(void 0,void 0,!0)}else J=!0},onLastUnsubscribe:e=>{H&&(clearTimeout(H),H=null),m&&!e&&ee()}});const c=(e,t)=>{if(w||t?.skipStoreUpdates)return;if(D<=0||D===1/0)return;H&&(clearTimeout(H),H=null);const r=K(e),o=n(),i=(O?_===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?D-(Date.now()-i):D;H=setTimeout(()=>{const t=Z.get();t.enabled&&t.subscriptionCount>0&&f.fetch(e,{force:!0},!0)},s)},f={...l(s,n,r),...X,async fetch(t,r,o=!1){const l=Z.get();if(!r?.force&&!r?.skipStoreUpdates&&!l.enabled)return null;const v=n(),w=v.error,j=v.queryKey,q=v.status,A=Ue(R,N,x,t),I=K(A),k=r?.staleTime??D,z=q===Ae.Loading,M=!!r?.skipStoreUpdates,$="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:o?C:!M,W=o||!M&&($||j===I);if(U?.promise&&U.key===I&&z)return L&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(A)),U.promise;if(m&&!M&&!1!==r?.updateQueryKey&&ee(),!r?.force){const t=v.lastFetchedAt,n=v.queryCache[I],o=n?.lastFetchedAt,i=n?.errorInfo,s=i&&i.retryCount>=F,a=(O?_===I&&t:o)||null;if(a&&!(Date.now()-a>=k)&&(!i||s||M))return W&&!M&&!H&&l.subscriptionCount>0&&0!==D&&D!==1/0&&c(A,r),$&&e(e=>e.queryKey!==I?{...e,queryKey:I}:e),L&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(A)),n?.data??null}!M&&W&&(H&&(clearTimeout(H),H=null),!w&&z||e(e=>({...e,error:null,status:Ae.Loading})),U={key:I});const V=r?.cacheTime??(P?S(A):S),J=async()=>{try{L&&(o||!t||Ge(t,x)?console.log("[π Fetching π] for params:",JSON.stringify(A)):console.log("[π Fetching with Partial Params π]\n","- Provided params:",`${JSON.stringify(t)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(A).filter(e=>!(e in t)).map(e=>[e,A[e]])))}`));const n=await(m&&!M&&W?(async e=>{const t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(E),{once:!0}),Promise.resolve(y(e,t)).then(n,r)})}finally{B===t&&(B=null)}})(A):y(A,null)),u=Date.now();let l;L&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(A));try{l=b?b(n,A):n}catch(e){throw new i(`[createQueryStore: ${d?.storageKey||I}]: transform failed`,e)}if(M)return L&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(A)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!g)return O?{...e,queryCache:{...e.queryCache,[I]:{cacheTime:V,data:l,errorInfo:null,lastFetchedAt:u}}}:e;let t=e;const n=t.queryCache[I];return g({data:l,params:A,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}}),!O&&Object.is(n,t.queryCache[I])&&(t={...t,queryCache:{...t.queryCache,[I]:{cacheTime:V,data:l,errorInfo:null,lastFetchedAt:u}}}),t}),l;if((g?s:e)(e=>{let t={...e,error:null,lastFetchedAt:u,queryKey:$?I:e.queryKey,status:Ae.Success};if(g||O){if(g){L&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(A));const e=t.queryCache[I];g({data:l,params:A,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}}),!O&&Object.is(e,t.queryCache[I])&&(t.queryCache={...t.queryCache,[I]:{cacheTime:V,data:null,errorInfo:null,lastFetchedAt:u}})}}else L&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(A),"| Has previous data?:",!!t.queryCache[I]?.data),t.queryCache={...t.queryCache,[I]:{cacheTime:V,data:l,errorInfo:null,lastFetchedAt:u}};return O||S===1/0?t:Xe(C,I,t)}),W&&(_=I,c(A,r)),h)try{h({data:l,fetch:f.fetch,params:A,set:s})}catch(e){a.error(new i(`[createQueryStore: ${d?.storageKey||I}]: onFetched callback failed`,e))}return l??null}catch(s){if(s===E)return L&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(A)),null;const c=!o&&!0===r?.throwOnError,l=u(s);if(M||!W){if(a.error(new i(`[createQueryStore: ${d?.storageKey||I}]: Failed to fetch data`,l)),c)throw l;return null}const y=O?void 0:n().queryCache[I],h=y?.errorInfo?.retryCount??0,g=h+1;if(p?.(l,h),h<F){if(Z.get().subscriptionCount>0){const e="function"==typeof T?T(g,l):T;e!==1/0&&(H&&clearTimeout(H),H=setTimeout(()=>{const{enabled:e,subscriptionCount:n}=Z.get();e&&n>0&&f.fetch(t,{force:!0},!0)},e))}e(e=>({...e,error:l,queryCache:{...e.queryCache,[I]:{cacheTime:y?.cacheTime??V,data:y?.data??null,lastFetchedAt:y?.lastFetchedAt??null,errorInfo:{error:l,lastFailedAt:Date.now(),retryCount:g}}},queryKey:$?I:e.queryKey,status:Ae.Error}))}else e(e=>({...e,error:l,queryCache:{...e.queryCache,[I]:{cacheTime:y?.cacheTime??V,data:y?.data??null,lastFetchedAt:y?.lastFetchedAt??null,errorInfo:{error:l,lastFailedAt:Date.now(),retryCount:F}}},queryKey:$?I:e.queryKey,status:Ae.Error}));if(a.error(new i(`[createQueryStore: ${d?.storageKey||I}]: Failed to fetch data`,l)),c)throw l;return null}finally{!M&&W&&(U=null)}};return M||!W?J():(U={key:I,promise:J()}).promise},getCacheEntry(e){if(O)return null;const t=n(),r=e?"string"==typeof e?e:K(Ue(R,N,x,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(O)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?C?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){switch(e){case"isIdle":return n().status===Ae.Idle;case"isLoading":return n().status===Ae.Loading;case"isSuccess":{const e=n(),t=e.queryCache[e.queryKey]?.lastFetchedAt;return"number"==typeof t||e.status===Ae.Success}case"isError":case"isInitialLoad":case void 0:{const t=n(),r=t.queryCache[t.queryKey],o=(O?_===t.queryKey&&t.lastFetchedAt:r?.lastFetchedAt)||null,i=t.status;switch(e){case"isError":{const e=t.queryCache[t.queryKey];return O?"error"!==i:"number"==typeof e?.errorInfo?.lastFailedAt}case"isInitialLoad":return!o&&i===Ae.Loading}return{isError:i===Ae.Error,isIdle:i===Ae.Idle,isLoading:i===Ae.Loading,isInitialLoad:!o&&i===Ae.Loading,isSuccess:i===Ae.Success}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(O?_===o&&i:r?.lastFetchedAt)||null;if(!s)return!0;const c=e??r?.cacheTime;return void 0===c||Date.now()-s>=c},isStale(e){const t=n(),r=t.queryKey,o=(O?_===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??D;return Date.now()-o>=i},reset(t=!1){for(const e of V)e();V=[],R=null,N=null,W=null,ee(),H&&(clearTimeout(H),H=null),U=null,_=null,t&&e(e=>({...e,...X}))}},v=r.subscribe;return r.subscribe=(...e)=>{const t=Q?()=>{}:Z.subscribe(),n=1===e.length?v(e[0]):v(e[0],e[1],e[2]);return e=>{t(e),n()}},f},ne=d?.storageKey?Y(te,Object.assign(Object.create(null),d,{partialize:et(C,d.partialize)})):f&&!("storageKey"in f)?Y(te,f):Y(te),re=ne.getState(),oe=re.error,ie=re.enabled,se=re.queryKey;if(se&&!oe&&(_=se),Q=!0,k||"function"==typeof t.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:n,attachVals:r}=function(e,t,n){const r=Object.create(null),o=Object.create(null),i=Object.create(null);for(const e in t){if(!c(t,e))continue;const s=t[e];if(Ye(s)){const t=s(De,n);r[e]=t,i[e]=t.value}else Ze(s)&&(o[e]=s,i[e]=s)}let s,a=null,u=null;if(Ye(e)){const t=e(De,n);s=t.value,a=t}else s=e,u=e;return{attachVals:r,directValues:o,enabledAttachVal:a,enabledDirectValue:u,resolvedEnabled:s,resolvedParams:i}}(q,k,ne);R={enabled:t,params:r},N={enabled:n,params:e}}"function"==typeof t.staleTime&&(W=t.staleTime(De,ne),D=W.value);const ce=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{re.fetch(e??He(R,N),{updateQueryKey:C})})(...e)}))}}();function ae(){let e;if(!C){e=He(R,N);const t=K(e);ne.setState(e=>({...e,queryKey:t}))}ce(e)}const ue=e||!I?ae:j(ae,"number"==typeof I?I:I.delay,"number"==typeof I?{leading:!1,maxWait:I,trailing:!0}:I);if(R?.enabled){const e=R.enabled,t=ze.get(e);if(t){let n=e.value;ie!==n&&ne.setState(e=>({...e,enabled:n})),n&&Z.setEnabled(n),L&&console.log("[π Enabled Subscription π] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(L&&console.log("[π Enabled Change π] - [Old]:",`${n},`,"[New]:",t),n=t,ne.setState(e=>({...e,enabled:t})))});V.push(r)}}else ie!==X.enabled&&ne.setState(e=>({...e,enabled:X.enabled}));for(const e in R?.params){const t=R.params[e];if(!t)continue;const n=ze.get(t);if(L&&console.log("[π Param Subscription π] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;Te(r,n)||(L&&console.log("[π Param Change π] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,ue())});V.push(o)}}if(W){const e=ze.get(W);if(e){const t=W;let n=t.value;L&&console.log("[π StaleTime Subscription π] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(L&&console.log("[π StaleTime Change π] - [Old]:",`${n},`,"[New]:",e),n=e,D=e,ne.getState().fetch())});V.push(r)}}return Q=!1,J&&queueMicrotask(ue),le=ne,fe=$.QueryStore,Object.assign(le,{[fe]:!0});var le,fe}function We(e,t){const n=t?.baseDelay??A.seconds(5),r=t?.maxDelay??A.minutes(5),o=Math.pow(2,e);return Math.min(n*o,r)}function Ve(e){return JSON.stringify(Object.keys(e).sort().map(t=>e[t]))}function Je(e){return JSON.stringify(Be(e))}function Qe(e){return JSON.parse(e)}function Be(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=null!==r&&"object"==typeof r?Be(r):r,t},{})}function Ue(e,t,n,r){return r?Ge(r,n)?r:{...He(e,t),...r}:He(e,t)}function He(e,t){const n=t?.params??Object.create(null);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function _e(){return Object.create(null)}function Ge(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function Xe(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null);let i=!1;const s=Object.create(null);for(const e in n.queryCache){if(!c(n.queryCache,e))continue;const a=n.queryCache[e];a&&(r-(a.lastFetchedAt??a.errorInfo.lastFailedAt)<a.cacheTime||e===o)?!t&&a.errorInfo&&a.errorInfo.retryCount>0?(s[e]={...a,errorInfo:{...a.errorInfo,retryCount:0}},i=!0):s[e]=a:i=!0}return i?{...n,queryCache:s}:n}function Ye(e){return"function"==typeof e}function Ze(e){return!Ye(e)}function et(e,t){return n=>{const r={...n},o={};for(const e in r)c(r,e)&&e in xe&&(xe[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):F(r),...Xe(e,null,o)}}}function tt(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,c=we(e,{debugMode:i?.debugMode??!1,equalityFn:function(e,t){const n=Object.is(e,t);return n||(function(e,t){for(const n of s){n.unsubscribe();const r=n.args;if(1===r.length){const o=r[0],i=e.getState(),s=t.getState(),c=t.subscribe(o);n.unsubscribe=c,Object.is(s,i)||o(s,i);continue}const o=r[0],i=r[1];let s=r[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});const c=o(e.getState()),a=o(t.getState()),u=t.subscribe(o,i,s);n.unsubscribe=u,(s?.equalityFn??Object.is)(c,a)||i(a,c)}}(e,t),P(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0}),a=c.getState().persist,u=(l=c.getState,function(e,t){return t?l().setState(e,t):l().setState(e)});var l;return Object.assign(function(e,t){const n=c();return e?n(e,t):n()},{[$.VirtualStore]:!0,destroy:()=>c.destroy(),getInitialState:()=>c.getState().getInitialState(),getState:()=>c.getState().getState(),persist:a,setState:u,subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?c.getState().subscribe(e[0]):c.getState().subscribe(e[0],e[1],e[2])};return s.add(t),()=>{t.unsubscribe(),s.delete(t)}}},o?o(c.getState):void 0)}var nt=Symbol(),rt=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function ot(e,t,n,r=rt){const o=function(){const e=S(nt);return e.current===nt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:ct(n),resubscribe:()=>{},unsubscribe:()=>{}}}(t,n,r)),e}(),i=function(e){return"function"==typeof e?rt.enabled:e?.enabled??rt.enabled}(r);return o.current.react=n,o.current.selector=t,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??rt)}(o,r),m(()=>{if(i)return st(e,o),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(o)},[i,e]),o}var it=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function st(e,t,n=it){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(n=it)=>st(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function ct(e){return"function"==typeof e?{equalityFn:e}:e??rt}var at=Symbol();function ut(e){const t=S(at);return t.current===at&&(t.current=e()),t.current}function lt(e,t){const n=function(e){const t=e.getState(),n=Object.create(null);if(s&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(J(e)){for(const r in t)dt(t,r)&&(n[r]=ft(e,r));return n}for(const e in t)dt(t,e)&&(n[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function ft(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function dt(e,t){return"function"==typeof e[t]}export{Ae as QueryStatuses,E as applyStateUpdate,Y as createBaseStore,we as createDerivedStore,Ne as createQueryStore,lt as createStoreActions,tt as createVirtualStore,Ie as deepEqual,We as defaultRetryDelay,P as destroyStore,L as destroyStores,Ve as getLegacyQueryKey,Je as getQueryKey,x as getStoreName,W as isDerivedStore,V as isPersistedStore,N as isQueryStore,J as isVirtualStore,Qe as parseQueryKey,ke as shallowEqual,A as time,ot as useListen,ut as useStableValue};
|
|
1
|
+
import{IS_TEST as e,IS_BROWSER as t,IS_IOS as n,markStoreCreated as r,getStorageConfig as o,StoresError as i,identity as s,IS_DEV as c,buildNullObject as a,isPlainObject as u,nullObject as l,hasOwn as f,noop as d,logger as y,ensureError as p,unstable_batchedUpdates as h,getOptions as g,isPromiseLike as b,reviver as m,replacer as S}from"./chunk-3U5A7HQV.mjs";export{StoresError,configureStores,identity,nullObject,replacer,reviver}from"./chunk-3U5A7HQV.mjs";import{subscribeWithSelector as v,persist as w}from"zustand/middleware";import{createStore as F}from"zustand/vanilla";import{useLayoutEffect as O,useRef as q,useSyncExternalStore as j,useDebugValue as A}from"react";var C=Symbol("empty selection"),T=Object.is;function k(e,t,n,r,o=T){const i=q(null);let s=e,c=t,a=n;if(r){let u=i.current;null===u&&(u=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:C,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return D(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>z(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:C,latestSource:C,selector:r,selectedSource:e,selectedSubscribe:()=>d,source:e,value:C,valueEqualityFn:o,valueSelector:r,valueSnapshot:C};return i.selectedSubscribe=I(i,e),i}(e,t,n,r,o),i.current=u),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=C),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=I(e,t))}(u,e,t,n,r,o),s=u.selectedSubscribe,c=u.getSelectedSnapshot,a=void 0===n?void 0:u.getSelectedServerSnapshot}const u=j(s,c,a);return A(u),u}function I(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===C?z(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===C||e.committedSource!==t)return void n();const i=e.committedSelector,s=e.committedEqualityFn;if(e.selector===i&&e.equalityFn===s){const t=i(r);if(s===T?T(o,t):s(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=s,e.valueSelector=i,e.valueSnapshot=r,void n()}if(e.source!==t)return void n();const c=e.value;if(c===C)return;const a=e.selector(r),u=e.equalityFn(c,a);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=M(e,r,u?c:a),u||n()}))}function z(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==C)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return D(e,t)}function D(e,t){const n=e.value;if(n!==C&&T(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==C&&(e.equalityFn===T?T(n,r):e.equalityFn(n,r)))return M(e,t,n);const o=e.committedValue;return o!==C&&o!==n&&e.committedSource===e.source&&(e.equalityFn===T?T(o,r):e.equalityFn(o,r))?M(e,t,o):M(e,t,r)}function M(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function E(e,t){return(e,t)=>function(e,t){const n=F(e);return Object.assign(function(e,r){return k(n.subscribe,n.getState,n.getInitialState,e,r??t)},n)}(e,t)}function P(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var K=Math.max,R=Math.min;function $(e,t=0,n={}){let r,o,i,s,c,a,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function h(){const e=L();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==i?R(n,i-(e-u)):n}(e))}function g(e){return c=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=L(),i=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(h,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(h,t),y(a)}return void 0===c&&(c=setTimeout(h,t)),s}return t=x(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,i=f?K(x(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==c&&clearTimeout(c),u=0,r=a=o=c=void 0},b.flush=function(){return void 0===c?s:g(L())},b}function L(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function x(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e)}function N(e){if(!u(e))return e;const t=l(),n=Object.keys(e);for(let r=0;r<n.length;r++){const o=n[r],i=e[o];"function"!=typeof i&&(t[o]=i)}return t}var V={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0},W=e?0:t?V.ms(200):V.seconds(n?3:5);function H(e){return t=>{if("string"!=typeof t)throw new i("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?m:void 0)}catch(e){throw y.error(new i("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function U(e){return t=>function(e,t){try{return JSON.stringify(e,t?S:void 0)}catch(e){throw y.error(new i("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var J=Object.freeze({shouldClear:!1});function B(e,t,n){if(!t||!e)return J;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Q(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function _(e){return!!e&&!!e.getIsApplyingRemote()}var G=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function X(e,...t){if(!0===t[1])return se(t[0])?t[0](e):t[0];const n=se(t[0])?t[0](e):t[0];return function(e){return Array.isArray(e)}(e)?n:{...e,...n}}function Y(e,t){ne(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function Z(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&Y(n,t)}function ee(e){return oe(e)?e.persist.getOptions().name??e.name:e.name}function te(e){return"getSnapshot"in e}function ne(e){return G.QueryStore in e}function re(e){return"flushUpdates"in e}function oe(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function ie(e){return G.VirtualStore in e}function se(e){return"function"==typeof e}var[ce,ae]=[0,1];function ue(e,t,n){if(!e)return!0;const r=e[ce],o=e[ae];return!(t<r)&&(t>r||n>o)}function le(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function fe(e,t){if(!c)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function de(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function ye(e,t){r();const n=void 0!==t&&"string"==typeof t.storageKey,s=n?t.storageKey:void 0,c=t?.sync?function(e,t){if(!e)return null;if(!0===e){if(!t)throw new i("[createBaseStore]: sync: true requires a storageKey to inherit the key from");return{key:t}}if("string"==typeof e)return{key:e};const n=e,r=n.key??t;if(!r)throw new i("[createBaseStore]: sync requires either a key in the config or a storageKey to inherit from");return{...n,key:r}}(t.sync,s):void 0,a=n?t.storage??o().storage:void 0,u=c?function(e,t,n){const r=t.engine??o().syncEngine,s=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(o,c,a)=>{const u=new Map,f=[],d=[];let p=null,h=!1,g=!1,m=0,S=null,v=[],w=Promise.resolve(),F=!n;function O(e,t){if(s?.setSessionId&&s?.setTimestamp&&r.sessionId&&(s.setSessionId(r.sessionId),s.setTimestamp(e),s.mergeFieldTimestamps&&t.length>0)){const n=l();for(const r of t)n[String(r)]=e;s.mergeFieldTimestamps(n)}}function q(e,t){if(h||!S)return t?o(e,t):o(e);const n=function(){const e=Date.now(),t=e>m?e:m+1;return m=t,t}();let i=[],s=l();const c=r=>{const o=X(r,e,t);for(const e of v)Object.is(o[e],r[e])||(i.push(e),s[e]=o[e]);return i.length&&O(n,i),o},a=t?o(c,!0):o(c);function f(){i.length&&function(e){const t=r.sessionId;for(const n of e.keys)u.set(n,[e.timestamp,t]);p&&g?p.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):d.push(e)}({keys:i,replace:t??!1,values:s,timestamp:n})}return b(a)?a.finally(f):(f(),a)}const j=a.setState;a.setState=q;const A=e(q,c,a);if(v=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(A),!v.length)return A;async function C(e){m=Math.max(m,e.timestamp);const n=l(),r=c(),o=e.timestamp;let a;if(e.replace)for(const t of v)le(t,e.values)||ue(u.get(t),o,e.sessionId)&&(a??(a=[])).push(t);for(const s of v){if(!le(s,e.values))continue;if(!S?.has(s))continue;if(!ue(u.get(s),o,e.sessionId))continue;const c=t.merge?.[s];if(c){const t=e.values[s],a=r[s];if(void 0!==t){const l=c(t,a,r,e.values),f=void 0!==a?a:t;if(!fe(l,f))return void y.error(new i(`[sync] Merge function for field "${String(s)}" returned ${de(l)} but expected ${de(f)}`));n[s]=l,u.set(s,[o,e.sessionId])}}else n[s]=e.values[s],u.set(s,[o,e.sessionId])}if(Object.keys(n).length>0||a?.length){h=!0,s&&s.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(a?.length){t=!0;for(const t of a)delete e[t],u.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(s.setWithoutPersist??j)(e,!0)}else await(s.setWithoutPersist??j)(n)}finally{h=!1,s&&s.setIsApplyingRemote(!1)}}}function T(e){n?w=w.then(()=>C(e)):C(e)}if(S=new Set(v),p=r.register({apply:e=>{F?T(e):f.push(e)},fields:v,getState:c,key:t.key}),p?.onFirstSubscribe||p?.onLastUnsubscribe){let e=0;const t=a.subscribe;a.subscribe=(...n)=>{e||p.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||p.onLastUnsubscribe?.()})}}}function k(){g=!0,function(){if(p&&d.length){for(const e of d){const t=r.sessionId;for(const n of e.keys)u.set(n,[e.timestamp,t]);O(e.timestamp,e.keys),p.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}d.length=0}}()}function I(){F=!0,function(){if(!f.length)return;const e=f.slice();f.length=0;for(const t of e)T(t)}()}return n?(s.onHydrationComplete=k,s.onHydrationFlushEnd=I):p.onHydrated?(p.onHydrated(k),I()):(k(),I()),A},syncContext:s}}(e,c,a?.async??!1):void 0,f=u?.stateCreator??e;if(!n)return E()(v(f),Object.is);const d=a?.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=P()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)e[1]?s.setState(e[0],e[1]):s.setState(e[0]);c=void 0}},e((...e)=>o?!0===e[1]?n(e[0],e[1]):n(e[0]):(t||(t=P()),c||(c=[]),c.push(e),t.promise),i,s)},wrapOnRehydrateStorage:(e,n)=>i=>{const s=e?.(i);return(e,i)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),i?t?.fail(p(i)):t?.complete(),s?.(e,i)}}}}(f):null,h=function(e,t,n){const r=t??e.storage??o().storage,s=(e.sync?void 0:e.persistThrottleMs??W)||void 0,c=e.version??0,a=r.async?function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),c=t.partialize??N,a=t.deserializer??e.deserializer??H(o),u=t.serializer??e.serializer??U(o);async function l(t,n){try{if(_(r))return;n.state,n.state=c(n.state);const o=B(r,s,n),a=u(n);try{await e.set(t,a),Q(r,o)}catch(e){y.error(new i("[createBaseStore]: Failed to persist store data",e))}}catch(e){y.error(new i("[createBaseStore]: Failed to serialize persisted store data",e))}}const f=void 0!==n?$(l,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(l);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:a(n)},setItem:async(e,t)=>{if(!r?.getIsApplyingRemote())return await f(e,t)},removeItem:async t=>{try{await e.delete(t)}catch(e){y.error(new i("[createBaseStore]: Failed to delete persisted store data",e))}}}}(r,e,s,n):function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),s="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),c=t.partialize??N,a=t.deserializer??e.deserializer??H(o),u=t.serializer??e.serializer??U(o);function l(t,n){try{if(_(r))return;n.state,n.state=c(n.state);const o=B(r,s,n),a=u(n);try{e.set(t,a),Q(r,o)}catch(e){y.error(new i("[createBaseStore]: Failed to persist store data",e))}}catch(e){y.error(new i("[createBaseStore]: Failed to persist store data",e))}}const f=void 0!==n?$(l,n,{leading:!1,maxWait:n,trailing:!0}):l;return{getItem:t=>{const n=e.get(t);return void 0===n?null:a(n)},setItem:(e,t)=>{r?.getIsApplyingRemote()||f(e,t)},removeItem:t=>{try{e.delete(t)}catch(e){y.error(new i("[createBaseStore]: Failed to delete persisted store data",e))}}}}(r,e,s,n);return{persistStorage:a,version:c}}(t,a,u?.syncContext),g=d?d.wrapOnRehydrateStorage(t.onRehydrateStorage,u?.syncContext):t.onRehydrateStorage,m=d?(e,t,n)=>(u&&(u.syncContext.setWithoutPersist=n.setState),d.stateCreator(e,t,n)):f,S=E()(v(w(m,function(e,t,n){const r={name:e.storageKey,onRehydrateStorage:n,storage:t.persistStorage,version:t.version};return void 0!==e.merge&&(r.merge=e.merge),void 0!==e.migrate&&(r.migrate=e.migrate),r}(t,h,g))),Object.is);return d?Object.assign(S,{persist:Object.assign(S.persist,{hydrationPromise:d.hydrationPromise})}):S}var pe=!1,he=!1,ge=new Map,be=new Map,me=new Map,Se=null,ve=1/0;function we(){return pe}function Fe(){return Se}function Oe(){pe||(pe=!0,he||(he=!0,queueMicrotask(()=>{he=!1,h(()=>{for(;be.size>0;){const e=ve,t=me.get(e);if(t){me.delete(e);for(const e of t)be.delete(e);Se=e;for(const e of t)e();if(Se=null,me.size>0){ve=1/0;for(const e of me.keys())e<ve&&(ve=e)}else ve=1/0}else{ve=1/0;for(const e of me.keys())e<ve&&(ve=e)}}for(;ge.size>0;){const e=Array.from(ge.values());ge.clear();for(const t of e)t()}}),pe=!1,Se=null,be.clear(),me.clear(),ve=1/0})))}function qe(e,t){pe&&ge.set(e,t)}var je=Symbol("stores.deriveProxy.unwrap");function Ae(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?Ce(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(te(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ce(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===je)return r(n,t,!0),s;if(o.has(s))return Reflect.get(s,c,a);if("__proto__"===c||"symbol"==typeof c)return c===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,c,a);const u=Reflect.get(s,c,s),l=String(c),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(s,c)?function(...e){return r(n,f,!0,{method:l,args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,Ce(u,f,n,r,o,i)),i.get(u)):u},getOwnPropertyDescriptor:(e,i)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,i)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function Te(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,je);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=Ie(e,t);if(n)for(let t=0;t<e.length;t++)ke(e,String(t),n)}(e,t):u(e)&&function(e,t){const n=Ie(e,t);if(n)for(const t of Reflect.ownKeys(e))ke(e,t,n)}(e,t),e)}function ke(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Te(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function Ie(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function ze(e,t,n="s"){return 1===t?e:`${e}${n}`}var De=Object.freeze([]);function Me(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)Ke(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?$e(n.path,n.invocation):Re(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${ze("Proxy Subscription",t)} π‘]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${ze("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i=Ee(),e.set(t,i)),Pe(i,n,0,r,o)}}}function Ee(){return l()}function Pe(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&(e.invocation=o));e.children||(e.children=Ee());const i=t[n];let s=e.children?.[i];s||(s=Ee(),e.children[i]=s),Pe(s,t,n+1,r,o)}function Ke(e,t,n,r,o,i=2){const s=e.children;if(!s)return void o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});for(const e of c){const c=s[e];c.invocation&&Ke(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)Ke(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void Ke(s[e],t,[...n,e],r+1,o,i)}o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}else o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}function Re(e){return t=>Le(t,e)}function $e(e,t){const n=e.slice(0,-1);return e=>{const r=Le(e,n),o=r&&"object"==typeof r?Reflect.get(r,t.method):void 0;return"function"==typeof o?Reflect.apply(o,r,t.args??De):void 0}}function Le(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}function xe(e,t=Object.is){return n=function(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:a}="function"==typeof(f=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:f,keepAlive:!1,lockDependencies:!1}:{debounceOptions:f.debounce,debugMode:(c&&f.debugMode)??!1,equalityFn:f.equalityFn??Object.is,keepAlive:f.keepAlive??!1,lockDependencies:f.lockDependencies??!1},u=String(We+=1),l=new Set;var f;i&&l.add(He);const d=new Set;let y,p,h=Ne,g=!1,b=!0,m=!0,S=0,v=!1,w=null,F=Ne;function O(e,t,n){return m&&l.size?t?(d.add(e.subscribe(t,E,n?{equalityFn:n,isDerivedStore:!0}:Ve)),t(te(e)?e.getSnapshot():e.getState())):(y||(y=new WeakMap),p||(p=Me()),Ae(e,y,p.trackPath)):(t??s)(te(e)?e.getSnapshot():e.getState())}function q(e){for(const t of d)t(e);d.clear()}let j=!0;function A(){if(!b&&Ue(h))return h;b=!1,m&&q(!0);const t=h,n=Ue(t);h=function(t){j=!0;const n=h,i=e(t),s=p?Te(i):i;return Ue(n)&&o(n,s)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),j=!1,n):s}(O);const i=r&&(!n||"verbose"===r&&m);if(i){n?"verbose"===r&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=d.size;console.log(`[π― ${e} ${ze("Selector Subscription",e)} π―]`)}return p&&m&&(p.buildProxySubscriptions((e,t)=>{d.add(e.subscribe(t,E,Ve))},i),y=void 0,p.reset(),a&&(p=void 0)),j&&n&&function(e,t){const n=function(){const e=l.has(He)?l.size-1:l.size;return S>0&&S<e}(),o=!S||n,i=n||null!==Fe()||we()&&o;n&&Oe(),r&&console.log(`[π» Derive Complete π»]: Notifying ${l.size} ${ze("watcher",l.size)}`);for(const t of l){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}i?v||(v=!0,Ue(F)||(F=t),qe(u,T)):C(e,t)}(h,t),a&&(m=!1),h}function C(e,t){for(const n of l)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function T(){if(!l.size)return;if(b&&!S&&A(),!Ue(h))return;const e=Ue(F)?F:h;C(h,e),v=!1,F=Ne}const k=n?$(z,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,I=k??(()=>{g||(g=!0,queueMicrotask(z))});function z(){g=!1,l.size?b&&A():K()}function D(e){e||k&&b?queueMicrotask(()=>{l.size||K()}):K()}function M(){z(),w=null}function E(){if(!b){if(b=!0,!k){if(S){Oe();const e=Fe(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!pe)return;const n=t<0?0:0|t,r=be.get(e);if(void 0===r){be.set(e,n);let t=me.get(n);return t||(t=new Set,me.set(n,t)),t.add(e),void(n<ve&&(ve=n))}if(n>r){const t=me.get(r);if(t&&(t.delete(e),0===t.size&&(me.delete(r),r===ve))){ve=1/0;for(const e of me.keys())e<ve&&(ve=e)}be.set(e,n);let o=me.get(n);o||(o=new Set,me.set(n,o)),o.add(e),n<ve&&(ve=n)}}(M,t)}if(we())return void(v||(v=!0,Ue(h)&&(F=h),qe(u,T)))}w=null,I()}}function P(){return b||!Ue(h)?l.size>0?A():e(O):h}function K(e=!0){i&&e||(k?.cancel(),q(),l.clear(),S=0,p=void 0,y=void 0,m=!0,g=!1,b=!0,h=Ne,v=!1,F=Ne,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){l.size&&(k?k.flush():b&&A())},getSnapshot:function(){if(!Ue(h)){l.add(He);const e=A();return l.delete(He),e}return g&&z(),h},getState:P,subscribe:function(...e){if(1===e.length){const t=e[0];return l.add(t),1!==l.size||Ue(h)||P(),()=>{l.delete(t),l.size||D(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isDerivedStore??!1,s={currentSlice:void 0,equalityFn:o,isDerivedWatcher:i,listener:n,selector:t};return l.add(s),s.currentSlice=t(P()),i&&(S+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{l.delete(s),i&&(S-=1),l.size||D(i)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}(e,t),Object.assign(function(e=s,t){return k(n.subscribe,n.getSnapshot,void 0,e,t)},n);var n}var Ne=Symbol(),Ve=Object.freeze({equalityFn:Object.is,isDerivedStore:!0}),We=0;function He(){}function Ue(e){return e!==Ne}var Je,Be=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=V.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Qe(e,t){const n=t?.baseDelay??V.seconds(5),r=t?.maxDelay??V.minutes(5);return Math.min(n*Math.pow(2,e),r)}var _e={Error:"error",Idle:"idle",Loading:"loading",Success:"success"};function Ge(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!(r in t)||!Ge(e[r],t[r]))return!1;return!0}function Xe(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ye(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(Ye(n,t))return n}let o,i,s;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((i=e.length)===t.length)for(;i--&&Ye(e[i],t[i]););return-1===i}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(s=n,s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!t.has(s))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(s=n[0],s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!Ye(n[1],t.get(s)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((i=n.byteLength)===r.byteLength)for(;i--&&n[i]===r[i];);return-1===i}if(!o||"object"==typeof e){i=0;for(const r in e){if(n.call(e,r)&&++i&&!n.call(t,r))return!1;if(!(r in t)||!Ye(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}var Ze=new WeakMap,et=new WeakMap;function tt(e,t=nt,n=Ye){return function(e,t,n){let r=et.get(e);r||(r=new Map,et.set(e,r));let o=r.get(t);o||(o=new Map,r.set(t,o));const i=o.get(n);if(i)return i;const[s,c,a]=ot(e,t,n),u=new Map,f=e=>{const t={get(t,n){if("value"===n){let t=c();const n=e.split(".");for(const e of n)e&&(t=t[e]);return t}const r="string"==typeof n?n:n.toString(),o=e?`${e}.${r}`:r,i=u.get(o);if(i)return i;const a=f(o);return Ze.set(a,s),u.set(o,a),a},set(t,n,r){const o=e.split(".");return""===o[0]&&o.shift(),a(o,r),!0}};return new Proxy(l(),t)},d=f("");return s(()=>{}),Ze.set(d,s),o.set(n,d),d}(e,t,n)}var nt=e=>e,rt=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,i=e[r],s=rt(i,o,n);if(Ye(i,s))return e;const c=Array.isArray(e)?e.slice():{...e};return c[r]=s,c},ot=(e,t,n)=>{const r=new Set,o=te(e);let i,s=t(o?e.getSnapshot():e.getState());return[c=>(r.size||(i=e.subscribe(t,e=>{s=e,r.forEach(e=>e())},{equalityFn:n,isDerivedStore:o})),r.add(c),()=>{r.delete(c),!r.size&&i&&(i(),i=void 0)}),()=>(r.size||(s=t(e.getState())),s),(n,r)=>{if(t!==nt)throw new Error("Cannot set a value with a selector");e.setState(e=>rt(e,n,r),!0)}]};function it(e){return Ze.get(e)}var st={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},ct=Object.freeze({force:!0}),at=Object.freeze({once:!0}),ut=Object.freeze({updateQueryKey:!0});function lt(t,n,o){r();const s="function"==typeof n?n:wt,u="object"==typeof n?n:o,d=u&&"storageKey"in u?u:void 0,h=Je??(Je=function(){const e={abortInterruptedFetches:!0,cacheTime:V.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:Qe,staleTime:V.minutes(2),suppressStaleTimeWarning:!1},t=g()?.queryStoreDefaults;return t?{...e,...t}:e}()),b=h.minStaleTime,{fetcher:m,onError:S,onFetched:v,setData:w,transform:F,abortInterruptedFetches:O=h.abortInterruptedFetches,cacheTime:q=h.cacheTime,debugMode:j=h.debugMode,disableAutoRefetching:A=h.disableAutoRefetching,disableCache:C=!1,enabled:T=!0,keepPreviousData:k=h.keepPreviousData,maxRetries:I=h.maxRetries,paramChangeThrottle:z=h.paramChangeThrottle,params:D,retryDelay:M=h.retryDelay,staleTime:E=h.staleTime,suppressStaleTimeWarning:P=h.suppressStaleTimeWarning}=t;let K="function"==typeof E?h.staleTime:E;c&&!1!==b&&!A&&!P&&K<b&&console.warn(`[createQueryStore${d?.storageKey?`: ${d.storageKey}`:""}] β Stale times under ${b/1e3} seconds are not recommended. Provided staleTime: ${K/1e3} seconds`);const R=new Error("[createQueryStore: AbortError] Fetch interrupted"),L="function"==typeof q,x=c&&j,N=t.params?Object.keys(t.params):[];let W=null,H=null,U=null,J=[],B=!1,Q=!1,_=null,X=null,Y=null,Z=null,ee=null;const te={enabled:"function"!=typeof T&&T,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:_e.Idle},ne=new Be({disableAutoRefetching:A,initialEnabled:te.enabled});function re(){_&&(X=null,_.abort(),_=null)}function oe(e,n,r){const o=r.setState;function c(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=o(r=>{const o=t?e(r):e,i=void 0!==o.enabled?o.enabled:r.enabled;return i!==r.enabled&&(n=()=>function(e,t){e!==t&&ee!==t&&(ee=t,ne.setEnabled(t),t?queueMicrotask(()=>u.fetch(void 0,ut)):(Y||O)&&(O&&re(),Y&&(clearTimeout(Y),Y=null)))}(r.enabled,i)),o});return n?.(),r}return o(e)}function a(e,t){if(A||t?.skipStoreUpdates)return;if(K<=0||K===1/0)return;Y&&(clearTimeout(Y),Y=null);const r=ft(e),o=n(),i=(C?Z===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?K-(Date.now()-i):K;Y=setTimeout(()=>{const t=ne.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,ct,!0)},s)}r.setState=c,ne.init({onSubscribe:(r,o,i)=>{if(H||W||!D&&"function"!=typeof t.enabled&&"function"!=typeof t.staleTime){if(r)if(o){const t=ht(W,H),r=ft(t),o=n();o.queryKey!==r&&e({queryKey:r}),o.isStale()?u.fetch(t,void 0,!0):a(t,void 0)}else A&&!i&&u.fetch(void 0,void 0,!0)}else B=!0},onLastUnsubscribe:e=>{Y&&(clearTimeout(Y),Y=null),O&&!e&&re()}});const u={...s(c,n,r),...te,async fetch(t,r,o=!1){const s=ne.get();if(!r?.force&&!r?.skipStoreUpdates&&!s.enabled)return null;const l=n(),f=l.error,h=l.queryKey,g=l.status===_e.Loading,b=pt(W,H,N,t),j=ft(b);if(g&&X?.promise&&X.key===j)return x&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(b)),X.promise;const A=r?.staleTime??K,T=!!r?.skipStoreUpdates,z="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&k,D=(o||h===j||z)&&!T;if(O&&D&&re(),!r?.force){const t=l.lastFetchedAt,n=l.queryCache[j],o=n?.lastFetchedAt,i=n?.errorInfo,c=i&&i.retryCount>=I,u=(C?Z===j&&t:o)||null;if(u&&!(Date.now()-u>=A)&&(!i||c||T))return D&&!Y&&s.subscriptionCount>0&&0!==K&&K!==1/0&&a(b,r),z&&e(e=>e.queryKey!==j?{queryKey:j}:e),x&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(b)),n?.data??null}D&&(Y&&(clearTimeout(Y),Y=null),!f&&g||e({error:null,status:_e.Loading}),X={key:j});const E=r?.cacheTime??(L?q(b):q);async function P(){const s=d?.storageKey||j;try{x&&(o||!t||gt(t,N)?console.log("[π Fetching π] for params:",JSON.stringify(b)):console.log("[π Fetching with Partial Params π]\n","- Provided params:",`${JSON.stringify(t)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(b).filter(e=>!(e in t)).map(e=>[e,b[e]])))}`));const n=await(O&&D?async function(e){const t=new AbortController;_=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(R),at),Promise.resolve(m(e,t)).then(n,r)})}finally{_===t&&(_=null)}}(b):m(b,null)),i=Date.now();let l;x&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(b));try{l=function(e,t,n){return n?n(e,t):e}(n,b,F)}catch(e){throw Ft(s,"transform",e)}if(T)return x&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(b)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!w)return C?e:{queryCache:{...e.queryCache,[j]:{cacheTime:E,data:l,errorInfo:null,lastFetchedAt:i}}};let t=e;const n=t.queryCache[j];try{w({data:l,params:b,queryKey:j,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ft(s,"setData",e)}return!C&&Object.is(n,t.queryCache[j])&&(t={...t,queryCache:{...t.queryCache,[j]:{cacheTime:E,data:null,errorInfo:null,lastFetchedAt:i}}}),t}),l;if((w?c:e)(e=>{let t={...e,error:null,lastFetchedAt:i,queryKey:z?j:e.queryKey,status:_e.Success};if(w||C){if(w){x&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(b));const e=t.queryCache[j];try{w({data:l,params:b,queryKey:j,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ft(s,"setData",e)}!C&&Object.is(e,t.queryCache[j])&&(t.queryCache={...t.queryCache,[j]:{cacheTime:E,data:null,errorInfo:null,lastFetchedAt:i}})}}else x&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(b),"| Has previous data?:",!!t.queryCache[j]?.data),t.queryCache={...t.queryCache,[j]:{cacheTime:E,data:l,errorInfo:null,lastFetchedAt:i}};return C||q===1/0?t:vt(k,j,t)}),D&&(Z=j,a(b,r)),v)try{v({data:l,fetch:u.fetch,params:b,set:c})}catch(e){y.error(Ft(s,"onFetched callback",e))}return l??null}catch(c){if(c===R)return x&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(b)),null;const a=!o&&!0===r?.throwOnError,l=p(c);if(l instanceof i&&y.error(l),!D){if(a)throw l;return null}const f=C?void 0:n().queryCache[j],d=f?.errorInfo?.retryCount??0,h=d+1;try{S?.(l,d)}catch(e){y.error(Ft(s,"onError callback",e))}if(d<I){if(ne.get().subscriptionCount>0){const e="function"==typeof M?M(h,l):M;e!==1/0&&(Y&&clearTimeout(Y),Y=setTimeout(()=>{const e=ne.get();e.enabled&&e.subscriptionCount>0&&u.fetch(t,ct,!0)},e))}e(e=>({error:l,queryCache:{...e.queryCache,[j]:{cacheTime:f?.cacheTime??E,data:f?.data??null,lastFetchedAt:f?.lastFetchedAt??null,errorInfo:{error:l,lastFailedAt:Date.now(),retryCount:h}}},queryKey:z?j:e.queryKey,status:_e.Error}))}else e(e=>({error:l,queryCache:{...e.queryCache,[j]:{cacheTime:f?.cacheTime??E,data:f?.data??null,lastFetchedAt:f?.lastFetchedAt??null,errorInfo:{error:l,lastFailedAt:Date.now(),retryCount:I}}},queryKey:z?j:e.queryKey,status:_e.Error}));if(a)throw l;return null}finally{D&&(X=null)}}return D?(X={key:j,promise:P()}).promise:P()},getCacheEntry(e){if(C)return null;const t=n(),r=e?"string"==typeof e?e:ft(pt(W,H,N,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(C)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?k?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){const t=n(),r=t.status;switch(e){case"isIdle":return r===_e.Idle;case"isLoading":return r===_e.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],i=C?r===_e.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((C?Z===n&&t.lastFetchedAt:o?.lastFetchedAt)||null),c=!s&&!i&&t.enabled;if("isInitialLoad"===e)return c;const a=s&&!i;return"isSuccess"===e?a:{isError:i,isIdle:r===_e.Idle,isLoading:r===_e.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(C?Z===o&&i:r?.lastFetchedAt)||null;if(!s)return!0;const c=e??r?.cacheTime;return void 0===c||Date.now()-s>=c},isStale(e){const t=n(),r=t.queryKey,o=(C?Z===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??K;return Date.now()-o>=i},reset(t=!1){for(const e of J)e();J=[],W=null,H=null,U=null,re(),Y&&(clearTimeout(Y),Y=null),X=null,Z=null,t&&e(te)}},l=r.subscribe;return r.subscribe=(...e)=>{const t=Q?()=>{}:ne.subscribe(),n=1===e.length?l(e[0]):l(e[0],e[1],e[2]);return e=>{t(e),n()}},u}const ie=d?.storageKey?ye(oe,a(d,{partialize:St(k,d.partialize)})):u&&!("storageKey"in u)?ye(oe,u):ye(oe),se=ie.getState(),ce=se.error,ae=se.enabled,ue=se.queryKey,le=se.fetch;let fe;if(ue&&!ce&&(Z=ue),Q=!0,D||"function"==typeof t.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:n,attachVals:r}=function(e,t,n){const r=l(),o=l(),i=l();for(const e in t){if(!f(t,e))continue;const s=t[e];if(bt(s)){const t=s(tt,n);r[e]=t,i[e]=t.value}else mt(s)&&(o[e]=s,i[e]=s)}let s,c=null,a=null;if(bt(e)){const t=e(tt,n);s=t.value,c=t}else s=e,a=e;return{attachVals:r,directValues:o,enabledAttachVal:c,enabledDirectValue:a,resolvedEnabled:s,resolvedParams:i}}(T,D,ie);W={enabled:t,params:r},H={enabled:n,params:e}}"function"==typeof t.staleTime&&(U=t.staleTime(tt,ie),K=U.value);const de=Object.freeze({updateQueryKey:k}),pe=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{le(e??ht(W,H),de)})(...e)}))}}();function he(){let e;if(!k){e=ht(W,H);const t=ft(e);ie.setState({queryKey:t})}pe(e)}const ge=e||!z?he:$(he,"number"==typeof z?z:z.delay,"number"==typeof z?{leading:!1,maxWait:z,trailing:!0}:z);for(const e in W?.params){const t=W.params[e];if(!t)continue;const n=it(t);if(x&&console.log("[π Param Subscription π] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;Ye(r,n)||(x&&console.log("[π Param Change π] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,ge())});J.push(o)}}if(U){const e=it(U);if(e){const t=U;let n=t.value;x&&console.log("[π StaleTime Subscription π] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(x&&console.log("[π StaleTime Change π] - [Old]:",`${n},`,"[New]:",e),n=e,K=e,le())});J.push(r)}}if(W?.enabled){const e=W.enabled,t=it(e);if(t){let n=e.value;ae!==n&&((fe??(fe={})).enabled=n),n&&ne.setEnabled(n),x&&console.log("[π Enabled Subscription π] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(x&&console.log("[π Enabled Change π] - [Old]:",`${n},`,"[New]:",t),n=t,ie.setState({enabled:t}))});J.push(r)}}else ae!==te.enabled&&((fe??(fe={})).enabled=te.enabled);const be=ft(ht(W,H));return be!==ue&&((fe??(fe={})).queryKey=be),fe&&ie.setState(fe),Q=!1,B&&queueMicrotask(ge),me=ie,Se=G.QueryStore,Object.assign(me,{[Se]:!0});var me,Se}function ft(e){return JSON.stringify(yt(e))}function dt(e){return JSON.parse(e)}function yt(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=u(r)?yt(r):r,t},l())}function pt(e,t,n,r){return r?gt(r,n)?r:{...ht(e,t),...r}:ht(e,t)}function ht(e,t){const n=Object.assign(l(),t?.params);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function gt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function bt(e){return"function"==typeof e}function mt(e){return!bt(e)}function St(e,t){return n=>{const r={...n},o=l();for(const e in r)f(r,e)&&e in st&&(st[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):N(r),...vt(e,null,o)}}}function vt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i=l();let s=!1;for(const e in n.queryCache){if(!f(n.queryCache,e))continue;const c=n.queryCache[e];c&&(r-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===o)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(i[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},s=!0):i[e]=c:s=!0}return s?{...n,queryCache:i}:n}function wt(){return Object.create(null)}function Ft(e,t,n){return new i(`[createQueryStore: ${e}]: ${t} failed`,n)}function Ot(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,c=xe(e,{debugMode:i?.debugMode??!1,equalityFn:function(e,t){const n=Object.is(e,t);return n||(function(e,t){for(const n of s){n.unsubscribe();const r=n.args;if(1===r.length){const o=r[0],i=e.getState(),s=t.getState(),c=t.subscribe(o);n.unsubscribe=c,Object.is(s,i)||o(s,i);continue}const o=r[0],i=r[1];let s=r[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});const c=o(e.getState()),a=o(t.getState()),u=t.subscribe(o,i,s);n.unsubscribe=u,(s?.equalityFn??Object.is)(c,a)||i(a,c)}}(e,t),Y(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0});return Object.assign(function(e,t){const n=c();return e?n(e,t):n()},{[G.VirtualStore]:!0,destroy:c.destroy,getInitialState:()=>c.getState().getInitialState(),getState:()=>c.getState().getState(),persist:(a=c.getState,{clearStorage:()=>a().persist?.clearStorage(),getOptions:()=>a().persist?.getOptions()??{},hasHydrated:()=>a().persist?.hasHydrated()??!0,hydrationPromise:()=>a().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>a().persist?.onFinishHydration(e)??d,onHydrate:e=>a().persist?.onHydrate(e)??d,rehydrate:()=>a().persist?.rehydrate(),setOptions:e=>a().persist?.setOptions(e)}),setState:qt(c.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?c.getState().subscribe(e[0]):c.getState().subscribe(e[0],e[1],e[2])};return s.add(t),()=>{t.unsubscribe(),s.delete(t)}}},o?.(c.getState));var a}function qt(e){return function(t,n){return n?e().setState(t,n):e().setState(t)}}var jt=Symbol(),At=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Ct(e,t,n,r=At){const o=function(){const e=q(jt);return e.current===jt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:It(n),resubscribe:()=>{},unsubscribe:()=>{}}}(t,n,r)),e}(),i=function(e){return"function"==typeof e?At.enabled:e?.enabled??At.enabled}(r);return o.current.react=n,o.current.selector=t,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??At)}(o,r),O(()=>{if(i)return kt(e,o),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(o)},[i,e]),o}var Tt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function kt(e,t,n=Tt){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(n=Tt)=>kt(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function It(e){return"function"==typeof e?{equalityFn:e}:e??At}var zt=Symbol();function Dt(e){const t=q(zt);return t.current===zt&&(t.current=e()),t.current}function Mt(e,t){const n=function(e){const t=e.getState(),n=l(),r=n;if(c&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(ie(e))for(const n in t)Pt(t,n)&&(r[n]=Et(e,n));else for(const e in t)Pt(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function Et(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Pt(e,t){return"function"==typeof e[t]}export{_e as QueryStatuses,X as applyStateUpdate,ye as createBaseStore,xe as createDerivedStore,lt as createQueryStore,Mt as createStoreActions,Ot as createVirtualStore,Ge as deepEqual,Qe as defaultRetryDelay,Y as destroyStore,Z as destroyStores,ft as getQueryKey,ee as getStoreName,te as hasGetSnapshot,re as isDerivedStore,oe as isPersistedStore,ne as isQueryStore,ie as isVirtualStore,dt as parseQueryKey,Xe as shallowEqual,V as time,Ct as useListen,Dt as useStableValue};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storesjs/stores",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"repository": {
|
|
@@ -41,12 +41,11 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"use-sync-external-store": "1.6.0",
|
|
45
44
|
"zustand": "5.0.10"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
|
-
"react": ">=
|
|
49
|
-
"react-native": ">=0.
|
|
47
|
+
"react": ">=18.0.0",
|
|
48
|
+
"react-native": ">=0.69.0",
|
|
50
49
|
"react-native-mmkv": ">=2.0.0"
|
|
51
50
|
},
|
|
52
51
|
"peerDependenciesMeta": {
|
|
@@ -62,9 +61,12 @@
|
|
|
62
61
|
"@types/jest": "^29.5.14",
|
|
63
62
|
"@types/node": "^22.19.5",
|
|
64
63
|
"@types/react": "^19.1.1",
|
|
65
|
-
"@types/
|
|
64
|
+
"@types/react-dom": "^19.1.1",
|
|
66
65
|
"esbuild": "^0.25.10",
|
|
66
|
+
"happy-dom": "^20.9.0",
|
|
67
67
|
"jest": "^29.7.0",
|
|
68
|
+
"madge": "^8.0.0",
|
|
69
|
+
"react-dom": "^19.1.1",
|
|
68
70
|
"terser": "^5.44.0",
|
|
69
71
|
"ts-jest": "^29.3.4",
|
|
70
72
|
"tsup": "^8.5.0",
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"build:web": "pnpm run -s prebuild:web && tsup --config tsup.config.ts --out-dir dist/web && pnpm run -s postbuild:web",
|
|
81
83
|
"generate:exports": "tsx --tsconfig scripts/tsconfig.json scripts/generate-exports.ts",
|
|
82
84
|
"lint": "pnpm -w run lint",
|
|
85
|
+
"lint:circular": "madge --circular --extensions ts,tsx src",
|
|
83
86
|
"lint:eslint": "pnpm -w run lint:eslint",
|
|
84
87
|
"lint:format": "prettier --write --log-level warn --ignore-path ../../.prettierignore .",
|
|
85
88
|
"lint:prettier": "pnpm -w run lint:prettier",
|
|
@@ -87,9 +90,10 @@
|
|
|
87
90
|
"postbuild:web": "rm -f src/storesStorage.ts src/env.ts",
|
|
88
91
|
"prebuild:native": "cp src/storesStorage.native.ts src/storesStorage.ts && cp src/env.native.ts src/env.ts",
|
|
89
92
|
"prebuild:web": "cp src/storesStorage.web.ts src/storesStorage.ts && cp src/env.web.ts src/env.ts",
|
|
90
|
-
"test": "
|
|
93
|
+
"test": "tsx --tsconfig scripts/tsconfig.json scripts/test.ts",
|
|
91
94
|
"test:all": "pnpm run test && pnpm run test:chrome",
|
|
92
95
|
"test:chrome": "vitest run src/plugins/chrome",
|
|
96
|
+
"test:plugins": "vitest run src/plugins",
|
|
93
97
|
"test:treeshake": "tsx --tsconfig scripts/tsconfig.json scripts/treeshake.ts"
|
|
94
98
|
}
|
|
95
99
|
}
|
package/dist/sync/transport.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { SyncAuthPayload, SyncUpdate } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* ### `SyncTransportMessage`
|
|
4
|
-
*
|
|
5
|
-
* Message envelope for sync engine communication over a transport layer.
|
|
6
|
-
* Supports sync updates and presence coordination.
|
|
7
|
-
*/
|
|
8
|
-
export type SyncTransportMessage<T extends Record<string, unknown> = Record<string, unknown>> = PingMessage | {
|
|
9
|
-
type: 'sync-update';
|
|
10
|
-
storeKey: string;
|
|
11
|
-
update: SyncUpdate<T>;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'auth-challenge';
|
|
14
|
-
code: string;
|
|
15
|
-
message?: string;
|
|
16
|
-
} | {
|
|
17
|
-
type: 'auth-error';
|
|
18
|
-
code: string;
|
|
19
|
-
message?: string;
|
|
20
|
-
} | {
|
|
21
|
-
type: 'presence-join';
|
|
22
|
-
storeKey: string;
|
|
23
|
-
userId: string;
|
|
24
|
-
userData?: unknown;
|
|
25
|
-
} | {
|
|
26
|
-
type: 'presence-leave';
|
|
27
|
-
storeKey: string;
|
|
28
|
-
userId: string;
|
|
29
|
-
} | {
|
|
30
|
-
type: 'presence-update';
|
|
31
|
-
storeKey: string;
|
|
32
|
-
userId: string;
|
|
33
|
-
userData: unknown;
|
|
34
|
-
};
|
|
35
|
-
export type PingMessage = {
|
|
36
|
-
readonly type: 'ping';
|
|
37
|
-
} | {
|
|
38
|
-
readonly type: 'pong';
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* ### `SyncTransport`
|
|
42
|
-
*
|
|
43
|
-
* Abstract transport interface for network-based sync engines.
|
|
44
|
-
* Implementations can use WebSockets, SSE, HTTP long-polling, or any other
|
|
45
|
-
* bidirectional communication protocol.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const transport = new WebSocketTransport('ws://localhost:3000');
|
|
50
|
-
* await transport.connect();
|
|
51
|
-
*
|
|
52
|
-
* transport.onMessage(message => {
|
|
53
|
-
* if (message.type === 'sync-update') {
|
|
54
|
-
* // Handle update
|
|
55
|
-
* }
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* transport.send({
|
|
59
|
-
* type: 'sync-update',
|
|
60
|
-
* storeKey: 'my-store',
|
|
61
|
-
* update: { ... }
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export interface SyncTransport {
|
|
66
|
-
/**
|
|
67
|
-
* Establishes connection to the transport endpoint.
|
|
68
|
-
* @throws {Error} If connection fails
|
|
69
|
-
*/
|
|
70
|
-
connect(options?: SyncTransportConnectOptions): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Closes the transport connection and cleans up resources.
|
|
73
|
-
*/
|
|
74
|
-
disconnect(): void;
|
|
75
|
-
/**
|
|
76
|
-
* Sends a message through the transport.
|
|
77
|
-
* Messages sent while disconnected may be queued or dropped depending on implementation.
|
|
78
|
-
*
|
|
79
|
-
* @param message - The message to send
|
|
80
|
-
*/
|
|
81
|
-
send(message: SyncTransportMessage): void;
|
|
82
|
-
/**
|
|
83
|
-
* Registers a handler for incoming messages.
|
|
84
|
-
* Only one handler can be registered at a time; subsequent calls replace the previous handler.
|
|
85
|
-
*
|
|
86
|
-
* @param handler - Function to call when messages arrive
|
|
87
|
-
*/
|
|
88
|
-
onMessage(handler: (message: SyncTransportMessage) => void): void;
|
|
89
|
-
/**
|
|
90
|
-
* Registers a handler for connection state changes.
|
|
91
|
-
*
|
|
92
|
-
* @param handler - Function to call when connection state changes
|
|
93
|
-
*/
|
|
94
|
-
onConnectionChange(handler: (connected: boolean) => void): void;
|
|
95
|
-
/**
|
|
96
|
-
* Updates the active authentication payload. Transports may choose to
|
|
97
|
-
* reconnect automatically or apply the metadata lazily on the next handshake.
|
|
98
|
-
*/
|
|
99
|
-
updateAuth?(auth: SyncAuthPayload | null): void;
|
|
100
|
-
/**
|
|
101
|
-
* Current connection status.
|
|
102
|
-
*/
|
|
103
|
-
readonly connected: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Unique identifier for this transport client.
|
|
106
|
-
* Used to filter self-updates in distributed sync.
|
|
107
|
-
*/
|
|
108
|
-
readonly clientId: string;
|
|
109
|
-
}
|
|
110
|
-
export type SyncTransportConnectOptions = {
|
|
111
|
-
readonly auth?: SyncAuthPayload | null;
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=transport.d.ts.map
|