@storesjs/stores 0.10.0 → 0.11.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.
Files changed (48) hide show
  1. package/dist/createBaseStore.d.ts +2 -2
  2. package/dist/createQueryStore.d.ts +7 -13
  3. package/dist/internal/derivedStore/deriveProxy.d.ts +2 -2
  4. package/dist/internal/queryStore/queryParams.d.ts +18 -0
  5. package/dist/internal/runtime.d.ts +0 -1
  6. package/dist/internal/types/internalSubscribeTypes.d.ts +16 -0
  7. package/dist/native/index.js +1 -1
  8. package/dist/native/index.mjs +1 -1
  9. package/dist/queryStore/classes/SubscriptionManager.d.ts +3 -31
  10. package/dist/queryStore/queryKey.d.ts +9 -2
  11. package/dist/queryStore/queryParam.d.ts +37 -0
  12. package/dist/queryStore/types.d.ts +10 -52
  13. package/dist/{vanilla/internal/derivedStore → store}/cascadeScheduler.d.ts +13 -5
  14. package/dist/types/subscribe.d.ts +4 -5
  15. package/dist/types.d.ts +10 -8
  16. package/dist/utils/createMicrotaskScheduler.d.ts +2 -1
  17. package/dist/vanilla/createBaseStore.d.ts +2 -2
  18. package/dist/vanilla/createQueryStore.d.ts +7 -13
  19. package/dist/vanilla/index.js +1 -1
  20. package/dist/vanilla/index.mjs +1 -1
  21. package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +2 -2
  22. package/dist/vanilla/internal/queryStore/queryParams.d.ts +17 -0
  23. package/dist/vanilla/internal/runtime.d.ts +0 -1
  24. package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +15 -0
  25. package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +3 -31
  26. package/dist/vanilla/queryStore/queryKey.d.ts +9 -2
  27. package/dist/vanilla/queryStore/queryParam.d.ts +36 -0
  28. package/dist/vanilla/queryStore/types.d.ts +10 -52
  29. package/dist/{internal/derivedStore → vanilla/store}/cascadeScheduler.d.ts +12 -6
  30. package/dist/vanilla/types/subscribe.d.ts +4 -5
  31. package/dist/vanilla/types.d.ts +10 -8
  32. package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +2 -1
  33. package/dist/web/chrome.js +1 -1
  34. package/dist/web/chrome.mjs +1 -1
  35. package/dist/web/chunk-FENSEQ3V.mjs +1 -0
  36. package/dist/web/chunk-FPYZVFBM.mjs +1 -0
  37. package/dist/web/chunk-PLDNKWGX.mjs +1 -0
  38. package/dist/web/index.js +1 -1
  39. package/dist/web/index.mjs +1 -1
  40. package/dist/web/internal/runtime.js +1 -1
  41. package/dist/web/internal/runtime.mjs +1 -1
  42. package/package.json +1 -1
  43. package/dist/internal/signal.d.ts +0 -12
  44. package/dist/queryStore/signalTypes.d.ts +0 -14
  45. package/dist/vanilla/internal/signal.d.ts +0 -11
  46. package/dist/vanilla/queryStore/signalTypes.d.ts +0 -13
  47. package/dist/web/chunk-QJLWBD7M.mjs +0 -1
  48. package/dist/web/chunk-V4LHP7LR.mjs +0 -1
@@ -1 +1 @@
1
- import{useLayoutEffect as e,useRef as t,useSyncExternalStore as n,useDebugValue as r}from"react";import{Platform as o,unstable_batchedUpdates as i}from"react-native";var s=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),c="ios"===o.OS;o.OS;var a="development"===process.env.NODE_ENV,u="test"===process.env.NODE_ENV;function l(e){return e}function f(){return{__proto__:null}}function d(){}Object.freeze(Object.create(null));var y=Symbol("empty selection"),p=Object.is;function g(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===y?h(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===y||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===p?p(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===y)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 h(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==y)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return b(e,t)}function b(e,t){const n=e.value;if(n!==y&&p(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==y&&(e.equalityFn===p?p(n,r):e.equalityFn(n,r)))return m(e,t,n);const o=e.committedValue;return o!==y&&o!==n&&e.committedSource===e.source&&(e.equalityFn===p?p(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 S(e,o,i,s){return Object.assign(function(c,a){return function(e,o,i,s,c=p){const a=t(null);let u=e,l=o,f=i;if(s){let t=a.current;null===t&&(t=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:y,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return b(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>h(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:y,latestSource:y,selector:r,selectedSource:e,selectedSubscribe:()=>d,source:e,value:y,valueEqualityFn:o,valueSelector:r,valueSnapshot:y};return i.selectedSubscribe=g(i,e),i}(e,o,i,s,c),a.current=t),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=y),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=g(e,t))}(t,e,o,i,s,c),u=t.selectedSubscribe,l=t.getSelectedSnapshot,f=void 0===i?void 0:t.getSelectedServerSnapshot}const m=n(u,l,f);return r(m),m}(e.subscribe,o,i,c,a??s)},e)}function v(e){let t;function n(){if(t)return t;try{const n=function(e){const{createMMKV:t,MMKV:n}=s("react-native-mmkv");if("function"==typeof t)return t({id:e});if("function"==typeof n)return new n({id:e});throw new Error("[stores]: react-native-mmkv module does not export MMKV/createMMKV.")}(e);let r;if("function"==typeof n.delete?r=n.delete.bind(n):"function"==typeof n.remove&&(r=n.remove.bind(n)),"function"!=typeof r)throw new Error("[stores]: Storage instance does not conform to expected interface");const o={clearAll:n.clearAll.bind(n),contains:n.contains.bind(n),delete:r,get:n.getString.bind(n),getAllKeys:n.getAllKeys.bind(n),set:n.set.bind(n)};t=o}catch(e){throw new Error("[stores] react-native-mmkv could not be loaded.\n\nPersisted stores require a storage backend. Either:\n - Install MMKV (the default): yarn add react-native-mmkv\n - Or provide a custom adapter via configureStores()\n"+(e instanceof Error?`\n${e.message}`:""))}return function(e){if(!e||"function"!=typeof e.get||"function"!=typeof e.set||"function"!=typeof e.delete||"function"!=typeof e.clearAll)throw new Error("[stores]: Storage instance does not conform to expected interface")}(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}var w={debug:(e,t)=>{a&&console.debug(e,t)},error:(e,t)=>{a&&!u&&console.error(e,t)},info:(e,t)=>{a&&console.info(e,t)},warn:(e,t)=>{a&&console.warn(e,t)}},O=Object.prototype.hasOwnProperty;function q(e,t){return O.call(e,t)}function j(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function F(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var _=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 A(e){return e instanceof Error?e:new Error(String(e))}var I,C,k,T=class{destroy(){}publish(){}},E=class{constructor(){this.sessionId="noop"}register(e){return new T}},M=!1;function z(e){var t;a&&function(){if(M)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,w=t),C??(C=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),k??(k=P(e))}function D(){return k??(k=P(void 0))}function K(){M=!0}function P(e){return{storage:e?.storage??v(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(I||(I=new E),I)}}var x,R={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},$={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};function L(e,t){const n=t?.baseDelay??$.seconds(5),r=t?.maxDelay??$.minutes(5);return Math.min(n*Math.pow(2,e),r)}function N(e){return JSON.stringify(V(e))}function V(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=j(r)?V(r):r,t},{__proto__:null})}function H(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function W(e,t,n){if(!0===n)return U(t)?t(e):t;const r=U(t)?t(e):t;return Object.is(r,e)?e:F(e)&&F(r)?{...e,...r}:r}function U(e){return"function"==typeof e}function J(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function B(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}var Q=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function G(e,t){ee(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function X(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&G(n,t)}function Y(e){const t="function"==typeof(n=e)?n.name:"";var n;return ne(e)?e.persist.getOptions().name??t:t}function Z(e){return"getSnapshot"in e}function ee(e){return Q.QueryStore in e}function te(e){return"flushUpdates"in e}function ne(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function re(e){return Q.VirtualStore in e}function oe(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(a&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(re(e))for(const n in t)se(t,n)&&(r[n]=ie(e,n));else for(const e in t)se(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function ie(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 se(e,t){return"function"==typeof e[t]}function ce(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)||!ce(e[r],t[r]))return!1;return!0}function ae(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 ue(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(ue(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--&&ue(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(!ue(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)||!ue(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}function le(e){let t;const n=new Set;function r(...e){const r=W(t,...e);if(Object.is(r,t))return;const o=t;t=r,n.forEach(e=>e(t,o))}function o(){return t}const i={getInitialState:function(){return s},getState:o,setState:r,subscribe:function(...e){return 1===e.length?c(e[0]):function(e,n,r){const o=r?.equalityFn??Object.is;let i=e(t);return r?.fireImmediately&&n(i,i),c(function(t){const r=e(t);if(o(i,r))return;const s=i;i=r,n(r,s)})}(e[0],e[1],e[2])}},s=t=e(r,o,i);return i;function c(e){return n.add(e),()=>{n.delete(e)}}}function fe(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function de(e){return{...e,merge:e.merge??ye,skipHydration:e.skipHydration??!1}}function ye(e,t){return void 0===e?t:{...t,...e}}function pe(){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 ge=Math.max,he=Math.min;function be(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 g(){const e=me();if(p(e))return h(e);c=setTimeout(g,function(e){const n=t-(e-(a??0));return f&&void 0!==i?he(n,i-(e-u)):n}(e))}function h(e){return c=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=me(),i=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(g,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(g,t),y(a)}return void 0===c&&(c=setTimeout(g,t)),s}return t=Se(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?ge(Se(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:h(me())},b}function me(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function Se(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 ve(e){if(!j(e))return e;const t={__proto__:null},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 we=u?0:$.seconds(c?3:5);function Oe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??ve,c=t.deserializer??e.deserializer??je(o),a=t.serializer??e.serializer??Fe(o);function u(t,n,o){try{if(Ce(r))return;const c={state:s(n),version:o},u=Ae(r,i,c),l=a(c);try{e.set(t,l),Ie(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?be(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:c(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function qe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??ve,c=t.deserializer??e.deserializer??je(o),a=t.serializer??e.serializer??Fe(o);async function u(t,n,o){try{if(Ce(r))return;const c={state:s(n),version:o},u=Ae(r,i,c),l=a(c);try{await e.set(t,l),Ie(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?be(u,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}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:c(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function je(e){return t=>{if("string"!=typeof t)throw new _("[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?B:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Fe(e){return t=>function(e,t){try{return JSON.stringify(e,t?J:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var _e=Object.freeze({shouldClear:!1});function Ae(e,t,n){if(!t||!e)return _e;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 Ie(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function Ce(e){return!!e&&!!e.getIsApplyingRemote()}var[ke,Te]=[0,1];function Ee(e,t,n){if(!e)return!0;const r=e[ke],o=e[Te];return!(t<r)&&(t>r||n>o)}function Me(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function ze(e,t){if(!a)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 Ke(e,t){if(K(),!t)return le(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??D().storage:void 0,i=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new _("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,n),s=i?function(e,t,n){const r=t.engine??D().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:(i,s,c)=>{const a=new Map,u=[],l=[];let f=null,d=!1,y=!1,p=0,g=null,h=[],b=Promise.resolve(),m=!n;function S(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n={__proto__:null};for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function v(e,t){if(d||!g)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>p?e:p+1;return p=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=W(r,e,t);for(const e of h)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&S(n,o),i},u=t?i(c,!0):i(c);function b(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);f&&y?f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):l.push(e)}({keys:o,replace:t??!1,values:s,timestamp:n})}return fe(u)?u.finally(b):(b(),u)}const O=c.setState;c.setState=v;const q=e(v,s,c);if(h=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}(q),!h.length)return q;async function j(e){p=Math.max(p,e.timestamp);const n={__proto__:null},r=s(),i=e.timestamp;let c;if(e.replace)for(const t of h)Me(t,e.values)||Ee(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of h){if(!Me(o,e.values))continue;if(!g?.has(o))continue;if(!Ee(a.get(o),i,e.sessionId))continue;const s=t.merge?.[o];if(s){const t=e.values[o],c=r[o];if(void 0!==t){const u=s(t,c,r,e.values),l=void 0!==c?c:t;if(!ze(u,l))return void w.error(new _(`[sync] Merge function for field "${String(o)}" returned ${De(u)} but expected ${De(l)}`));n[o]=u,a.set(o,[i,e.sessionId])}}else n[o]=e.values[o],a.set(o,[i,e.sessionId])}if(Object.keys(n).length>0||c?.length){d=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(c?.length){t=!0;for(const t of c)delete e[t],a.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??O)(e,!0)}else await(o.setWithoutPersist??O)(n)}finally{d=!1,o&&o.setIsApplyingRemote(!1)}}}function F(e){n?b=b.then(()=>j(e)):j(e)}if(g=new Set(h),f=r.register({apply:e=>{m?F(e):u.push(e)},fields:h,getState:s,key:t.key}),f?.onFirstSubscribe||f?.onLastUnsubscribe){let e=0;const t=c.subscribe;c.subscribe=(...n)=>{e||f.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||f.onLastUnsubscribe?.()})}}}function A(){y=!0,function(){if(f&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);S(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function I(){m=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)F(t)}()}return n?(o.onHydrationComplete=A,o.onHydrationFlushEnd=I):f.onHydrated?(f.onHydrated(A),I()):(A(),I()),q},syncContext:o}}(e,i,o?.async??!1):void 0,c=s?.stateCreator??e;if(!r)return le(c);const a=function(e,t,n){const r=t??e.storage??D().storage,o=(e.sync?void 0:e.persistThrottleMs??we)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:qe(r,e,o,n),version:i}:{async:!1,persistStorage:Oe(r,e,o,n),version:i}}(t,o,s?.syncContext),u=a.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=pe()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)H(s.setState,e);c=void 0}},e(function(...e){return o?H(n,e):(t||(t=pe()),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(A(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,f=le(function(e,t){return(n,r,o)=>{let i,s,c,a=de(t),u=!1,l=0;function f(){return a.storage.setItem(a.name,r(),a.version)}const d=o.setState;o.setState=function(...e){return H(d,e),f()};const y=e(function(...e){return H(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,s?.forEach(e=>e(r()??y)),e}(),t=a.onRehydrateStorage?.(r()??y);try{const n=a.storage.getItem(a.name);return fe(n)?n.then(n=>g(e,n,t)).catch(n=>m(e,t,n)):g(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{a.storage.removeItem(a.name)},getOptions:()=>a,hasHydrated:()=>u,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{a=de({...a,...e,storage:e.storage??a.storage})}}}),a.skipHydration||p(),i??y;function g(e,t,n){const r=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error("State loaded from storage couldn't be migrated since no migrate function was provided"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return fe(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(a,t);return fe(r)?r.then(t=>h(e,t,n)).catch(t=>m(e,n,t)):h(e,r,n)}function h(e,t,o){const s=function(e,t){if(e!==l)return;const o=a.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(fe(s))return s.then(()=>b(e,o));b(e,o)}function b(e,t){if(e!==l)return;t?.(i,void 0);const n=r();i=n,u=!0,c?.forEach(e=>e(n))}function m(e,t,n){e===l&&t?.(void 0,n)}}}(u?(e,t,n)=>(s&&(s.syncContext.setWithoutPersist=n.setState),u.stateCreator(e,t,n)):c,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:a.persistStorage,version:a.version}));return u?Object.assign(f,{persist:Object.assign(f.persist,{hydrationPromise:u.hydrationPromise})}):f}function Pe(e,t,n="s"){return 1===t?e:`${e}${n}`}var xe=i,Re=!1,$e=!1,Le=new Map,Ne=new Map,Ve=new Map,He=null,We=1/0;function Ue(){return Re}function Je(){return He}function Be(){Re||(Re=!0,$e||($e=!0,queueMicrotask(()=>{$e=!1,xe(()=>{for(;Ne.size>0;){const e=We,t=Ve.get(e);if(t){Ve.delete(e);for(const e of t)Ne.delete(e);He=e;for(const e of t)e();if(He=null,Ve.size>0){We=1/0;for(const e of Ve.keys())e<We&&(We=e)}else We=1/0}else{We=1/0;for(const e of Ve.keys())e<We&&(We=e)}}for(;Le.size>0;){const e=Array.from(Le.values());Le.clear();for(const t of e)t()}}),Re=!1,He=null,Ne.clear(),Ve.clear(),We=1/0})))}function Qe(e,t){Re&&Le.set(e,t)}var Ge=Symbol("stores.deriveProxy.unwrap");function Xe(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?Ye(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(Z(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ye(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===Ge)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,{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,Ye(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 Ze(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Ge);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=tt(e,t);if(n)for(let t=0;t<e.length;t++)et(e,String(t),n)}(e,t):j(e)&&function(e,t){const n=tt(e,t);if(n)for(const t of Reflect.ownKeys(e))et(e,t,n)}(e,t),e)}function et(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Ze(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function tt(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var nt=Object.freeze([]);function rt(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)it(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?ut(n.path,n.invocation):at(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[📡 ${t} ${Pe("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}_${Pe("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i={__proto__:null},e.set(t,i)),ot(i,n,0,r,o)}}}function ot(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(st(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(st(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children={__proto__:null});const i=t[n];let s=e.children?.[i];s||(s={__proto__:null},e.children[i]=s),ot(s,t,n+1,r,o)}function it(e,t,n,r,o,i=2){const s=e.children;if(!s)return void ct(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){ct(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&it(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)it(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void it(s[e],t,[...n,e],r+1,o,i)}ct(e,t,n,o)}else ct(e,t,n,o)}function st(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function ct(e,t,n,r){const o=e.isLeaf??!1,i=e.invocation;if(!i)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:i,isLeaf:o});const s=e.extraInvocations;if(s)for(let e=0;e<s.length;e++)r.add({store:t,path:n,invocation:s[e],isLeaf:o})}function at(e){return t=>lt(t,e)}function ut(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=lt(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??nt):void 0}}function lt(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var ft=Symbol(),dt=Object.freeze({equalityFn:Object.is,isDerivedStore:!0});function yt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:s}="function"==typeof(f=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:f,keepAlive:!1,lockDependencies:!1}:{debounceOptions:f.debounce,debugMode:(a&&f.debugMode)??!1,equalityFn:f.equalityFn??Object.is,keepAlive:f.keepAlive??!1,lockDependencies:f.lockDependencies??!1},c=String(pt+=1),u=new Set;var f;i&&u.add(gt);const d=new Set;let y,p,g=ft,h=!1,b=!0,m=!0,S=0,v=!1,w=null,O=ft;function q(e,t,n){return m&&u.size?t?(d.add(e.subscribe(t,z,n?{equalityFn:n,isDerivedStore:!0}:dt)),t(Z(e)?e.getSnapshot():e.getState())):(y||(y=new WeakMap),p||(p=rt()),Xe(e,y,p.trackPath)):(t??l)(Z(e)?e.getSnapshot():e.getState())}function j(e){for(const t of d)t(e);d.clear()}let F=!0;function _(){if(!b&&ht(g))return g;b=!1,m&&j(!0);const t=g,n=ht(t);g=function(t){F=!0;const n=g,i=e(t),s=p?Ze(i):i;return ht(n)&&o(n,s)?(r&&console.log("[🥷 Derive Complete 🥷]: No change detected"),F=!1,n):s}(q);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} ${Pe("Selector Subscription",e)} 🎯]`)}return p&&m&&(p.buildProxySubscriptions((e,t)=>{d.add(e.subscribe(t,z,dt))},i),y=void 0,p.reset(),s&&(p=void 0)),F&&n&&function(e,t){const n=function(){const e=u.has(gt)?u.size-1:u.size;return S>0&&S<e}(),o=!S||n,i=n||null!==Je()||Ue()&&o;n&&Be(),r&&console.log(`[📻 Derive Complete 📻]: Notifying ${u.size} ${Pe("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?v||(v=!0,ht(O)||(O=t),Qe(c,I)):A(e,t)}(g,t),s&&(m=!1),g}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(b&&!S&&_(),!ht(g))return;const e=ht(O)?O:g;A(g,e),v=!1,O=ft}const C=n?be(T,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,k=C??(()=>{h||(h=!0,queueMicrotask(T))});function T(){h=!1,u.size?b&&_():K()}function E(e){e||C&&b?queueMicrotask(()=>{u.size||K()}):K()}function M(){T(),w=null}function z(){if(!b){if(b=!0,!C){if(S){Be();const e=Je(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Re)return;const n=t<0?0:0|t,r=Ne.get(e);if(void 0===r){Ne.set(e,n);let t=Ve.get(n);return t||(t=new Set,Ve.set(n,t)),t.add(e),void(n<We&&(We=n))}if(n>r){const t=Ve.get(r);if(t&&(t.delete(e),0===t.size&&(Ve.delete(r),r===We))){We=1/0;for(const e of Ve.keys())e<We&&(We=e)}Ne.set(e,n);let o=Ve.get(n);o||(o=new Set,Ve.set(n,o)),o.add(e),n<We&&(We=n)}}(M,t)}if(Ue())return void(v||(v=!0,ht(g)&&(O=g),Qe(c,I)))}w=null,k()}}function D(){return b||!ht(g)?u.size>0?_():e(q):g}function K(e=!0){i&&e||(C?.cancel(),j(),u.clear(),S=0,p=void 0,y=void 0,m=!0,h=!1,b=!0,g=ft,v=!1,O=ft,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){u.size&&(C?C.flush():b&&_())},getSnapshot:function(){if(!ht(g)){u.add(gt);const e=_();return u.delete(gt),e}return h&&T(),g},getState:D,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||ht(g)||D(),()=>{u.delete(t),u.size||E(!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(D()),i&&(S+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{u.delete(s),i&&(S-=1),u.size||E(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.")}}}var pt=0;function gt(){}function ht(e){return e!==ft}var bt=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=$.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)}}},mt=new WeakMap,St=new WeakMap;function vt(e,t=wt,n=ue){return function(e,t,n){let r=St.get(e);r||(r=new Map,St.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]=qt(e,t,n),u=new Map,l=e=>new Proxy({__proto__:null},{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 mt.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}}),f=l("");return s(()=>{}),mt.set(f,s),o.set(n,f),f}(e,t,n)}var wt=e=>e,Ot=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,i=e[r],s=Ot(i,o,n);if(ue(i,s))return e;const c=Array.isArray(e)?e.slice():{...e};return c[r]=s,c},qt=(e,t,n)=>{const r=new Set,o=Z(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!==wt)throw new Error("Cannot set a value with a selector");e.setState(e=>Ot(e,n,r),!0)}]};function jt(e){return mt.get(e)}var Ft={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},_t=Object.freeze({force:!0}),At=Object.freeze({once:!0}),It=Object.freeze({updateQueryKey:!0});function Ct(e,t,n,r){return r?Tt(r,n)?r:{...kt(e,t),...r}:kt(e,t)}function kt(e,t){const n=Object.assign({__proto__:null},t?.params);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function Tt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function Et(e){return"function"==typeof e}function Mt(e){return!Et(e)}function zt(e,t){return n=>{const r={...n},o={__proto__:null};for(const e in r)q(r,e)&&e in Ft&&(Ft[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):ve(r),...Dt(e,null,o)}}}function Dt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i={__proto__:null};let s=!1;for(const e in n.queryCache){if(!q(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 Kt(){return Object.create(null)}function Pt(e,t,n){return new _(`[createQueryStore: ${e}]: ${t} failed`,n)}function xt(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}function Rt(e,t){const n=Ke(e,t);return S(n,n.getState,n.getInitialState,Object.is)}function $t(e,t=Object.is){const n=yt(e,t);return S(n,n.getSnapshot)}function Lt(e,t,n){const r=function(e,t,n){K();const r="function"==typeof t?t:Kt,o="object"==typeof t?t:n,i=function(e){return"string"==typeof e?.storageKey}(o)?o:void 0,s=x??(x=function(){const e={abortInterruptedFetches:!0,cacheTime:$.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:L,staleTime:$.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(C)return C}()?.queryStoreDefaults;return t?{...e,...t}:e}()),c=s.minStaleTime,{fetcher:l,onError:f,onFetched:d,setData:y,transform:p,abortInterruptedFetches:g=s.abortInterruptedFetches,cacheTime:h=s.cacheTime,debugMode:b=s.debugMode,disableAutoRefetching:m=s.disableAutoRefetching,disableCache:S=!1,enabled:v=!0,keepPreviousData:O=s.keepPreviousData,maxRetries:j=s.maxRetries,paramChangeThrottle:F=s.paramChangeThrottle,params:I,retryDelay:k=s.retryDelay,staleTime:T=s.staleTime,suppressStaleTimeWarning:E=s.suppressStaleTimeWarning}=e;let M="function"==typeof T?s.staleTime:T;a&&!1!==c&&!m&&!E&&M<c&&console.warn(`[createQueryStore${i?.storageKey?`: ${i.storageKey}`:""}] ❌ Stale times under ${c/1e3} seconds are not recommended. Provided staleTime: ${M/1e3} seconds`);const z=new Error("[createQueryStore: AbortError] Fetch interrupted"),D="function"==typeof h,P=a&&b,V=e.params?Object.keys(e.params):[];let H=null,W=null,U=null,J=[],B=!1,G=!1,X=null,Y=null,Z=null,ee=null,te=null;const ne={enabled:"function"!=typeof v&&v,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:R.Idle},re=new bt({disableAutoRefetching:m,initialEnabled:ne.enabled});function oe(){X&&(Y=null,X.abort(),X=null)}function ie(t,n,o){const s=o.setState;function c(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=s(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&&te!==t&&(te=t,re.setEnabled(t),t?queueMicrotask(()=>u.fetch(void 0,It)):(Z||g)&&(g&&oe(),Z&&(clearTimeout(Z),Z=null)))}(r.enabled,i)),o});return n?.(),r}return s(e)}function a(e,t){if(m||t?.skipStoreUpdates)return;if(M<=0||M===1/0)return;Z&&(clearTimeout(Z),Z=null);const r=N(e),o=n(),i=(S?ee===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?M-(Date.now()-i):M;Z=setTimeout(()=>{const t=re.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,_t,!0)},s)}o.setState=c,re.init({onSubscribe:(r,o,i)=>{if(W||H||!I&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=kt(H,W),r=N(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?u.fetch(e,void 0,!0):a(e,void 0)}else m&&!i&&u.fetch(void 0,void 0,!0)}else B=!0},onLastUnsubscribe:e=>{Z&&(clearTimeout(Z),Z=null),g&&!e&&oe()}});const u={...r(c,n,o),...ne,async fetch(e,r,o=!1){const s=re.get();if(!r?.force&&!r?.skipStoreUpdates&&!s.enabled)return null;const b=n(),m=b.error,v=b.queryKey,q=b.status===R.Loading,F=Ct(H,W,V,e),I=N(F);if(q&&Y?.promise&&Y.key===I)return P&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(F)),Y.promise;const C=r?.staleTime??M,T=!!r?.skipStoreUpdates,E="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&O,K=(o||v===I||E)&&!T;if(g&&K&&oe(),!r?.force){const e=b.lastFetchedAt,n=b.queryCache[I],o=n?.lastFetchedAt,i=n?.errorInfo,c=i&&i.retryCount>=j,u=(S?ee===I&&e:o)||null;if(u&&!(Date.now()-u>=C)&&(!i||c||T))return K&&!Z&&s.subscriptionCount>0&&0!==M&&M!==1/0&&a(F,r),E&&t(e=>e.queryKey!==I?{queryKey:I}:e),P&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(F)),n?.data??null}K&&(Z&&(clearTimeout(Z),Z=null),!m&&q||t({error:null,status:R.Loading}),Y={key:I});const x=r?.cacheTime??(D?h(F):h);async function $(){const s=i?.storageKey||I;try{P&&(o||!e||Tt(e,V)?console.log("[🔄 Fetching 🔄] for params:",JSON.stringify(F)):console.log("[🔄 Fetching with Partial Params 🔄]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(F).filter(t=>!(t in e)).map(e=>[e,F[e]])))}`));const n=await(g&&K?async function(e){const t=new AbortController;X=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(z),At),Promise.resolve(l(e,t)).then(n,r)})}finally{X===t&&(X=null)}}(F):l(F,null)),i=Date.now();let f;P&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(F));try{f=function(e,t,n){return n?n(e,t):e}(n,F,p)}catch(e){throw Pt(s,"transform",e)}if(T)return P&&console.log("[🥷 Successful Parallel Fetch 🥷] for params:",JSON.stringify(F)),"withCache"===r.skipStoreUpdates&&t(e=>{if(!y)return S?e:{queryCache:{...e.queryCache,[I]:{cacheTime:x,data:f,errorInfo:null,lastFetchedAt:i}}};let t=e;const n=t.queryCache[I];try{y({data:f,params:F,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Pt(s,"setData",e)}return!S&&Object.is(n,t.queryCache[I])&&(t={...t,queryCache:{...t.queryCache,[I]:{cacheTime:x,data:null,errorInfo:null,lastFetchedAt:i}}}),t}),f;if((y?c:t)(e=>{let t={...e,error:null,lastFetchedAt:i,queryKey:E?I:e.queryKey,status:R.Success};if(y||S){if(y){P&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(F));const e=t.queryCache[I];try{y({data:f,params:F,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Pt(s,"setData",e)}!S&&Object.is(e,t.queryCache[I])&&(t.queryCache={...t.queryCache,[I]:{cacheTime:x,data:null,errorInfo:null,lastFetchedAt:i}})}}else P&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(F),"| Has previous data?:",!!t.queryCache[I]?.data),t.queryCache={...t.queryCache,[I]:{cacheTime:x,data:f,errorInfo:null,lastFetchedAt:i}};return S||h===1/0?t:Dt(O,I,t)}),K&&(ee=I,a(F,r)),d)try{d({data:f,fetch:u.fetch,params:F,set:c})}catch(e){w.error(Pt(s,"onFetched callback",e))}return f??null}catch(i){if(i===z)return P&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(F)),null;const c=!o&&!0===r?.throwOnError,a=A(i);if(a instanceof _&&w.error(a),!K){if(c)throw a;return null}const l=S?void 0:n().queryCache[I],d=l?.errorInfo?.retryCount??0,y=d+1;try{f?.(a,d)}catch(e){w.error(Pt(s,"onError callback",e))}if(d<j){if(re.get().subscriptionCount>0){const t="function"==typeof k?k(y,a):k;t!==1/0&&(Z&&clearTimeout(Z),Z=setTimeout(()=>{const t=re.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,_t,!0)},t))}t(e=>({error:a,queryCache:{...e.queryCache,[I]:{cacheTime:l?.cacheTime??x,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:y}}},queryKey:E?I:e.queryKey,status:R.Error}))}else t(e=>({error:a,queryCache:{...e.queryCache,[I]:{cacheTime:l?.cacheTime??x,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:j}}},queryKey:E?I:e.queryKey,status:R.Error}));if(c)throw a;return null}finally{K&&(Y=null)}}return K?(Y={key:I,promise:$()}).promise:$()},getCacheEntry(e){if(S)return null;const t=n(),r=e?"string"==typeof e?e:N(Ct(H,W,V,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(S)return null;const t=n().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){const t=n(),r=t.status;switch(e){case"isIdle":return r===R.Idle;case"isLoading":return r===R.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],i=S?r===R.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((S?ee===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===R.Idle,isLoading:r===R.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(S?ee===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=(S?ee===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??M;return Date.now()-o>=i},reset(e=!1){for(const e of J)e();J=[],H=null,W=null,U=null,oe(),Z&&(clearTimeout(Z),Z=null),Y=null,ee=null,e&&t(ne)}},b=o.subscribe;return o.subscribe=(...e)=>{const t=G?()=>{}:re.subscribe(),n=1===e.length?b(e[0]):b(e[0],e[1],e[2]);return e=>{t(e),n()}},u}const se=i?.storageKey?Ke(ie,(ce=i,void 0===(ae={partialize:zt(O,i.partialize)})?Object.assign({__proto__:null},ce):Object.assign({__proto__:null},ce,ae))):o&&!("storageKey"in o)?Ke(ie,o):Ke(ie);var ce,ae;const le=se.getState(),fe=le.error,de=le.enabled,ye=le.queryKey,pe=le.fetch;let ge;if(ye&&!fe&&(ee=ye),G=!0,I||"function"==typeof e.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:n,attachVals:r}=function(e,t,n){const r={__proto__:null},o={__proto__:null},i={__proto__:null};for(const e in t){if(!q(t,e))continue;const s=t[e];if(Et(s)){const t=s(vt,n);r[e]=t,i[e]=t.value}else Mt(s)&&(o[e]=s,i[e]=s)}let s,c=null,a=null;if(Et(e)){const t=e(vt,n);s=t.value,c=t}else s=e,a=e;return{attachVals:r,directValues:o,enabledAttachVal:c,enabledDirectValue:a,resolvedEnabled:s,resolvedParams:i}}(v,I,se);H={enabled:t,params:r},W={enabled:n,params:e}}"function"==typeof e.staleTime&&(U=e.staleTime(vt,se),M=U.value);const he=Object.freeze({updateQueryKey:O}),me=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{pe(e??kt(H,W),he)})(...e)}))}}();function Se(){let e;if(!O){e=kt(H,W);const t=N(e);se.setState({queryKey:t})}me(e)}const ve=u||!F?Se:be(Se,"number"==typeof F?F:F.delay,"number"==typeof F?{leading:!1,maxWait:F,trailing:!0}:F);for(const e in H?.params){const t=H.params[e];if(!t)continue;const n=jt(t);if(P&&console.log("[🌀 Param Subscription 🌀] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;ue(r,n)||(P&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,ve())});J.push(o)}}if(U){const e=jt(U);if(e){const t=U;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,pe())});J.push(r)}}if(H?.enabled){const e=H.enabled,t=jt(e);if(t){let n=e.value;de!==n&&((ge??(ge={})).enabled=n),n&&re.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,se.setState({enabled:t}))});J.push(r)}}else de!==ne.enabled&&((ge??(ge={})).enabled=ne.enabled);const we=N(kt(H,W));return we!==ye&&((ge??(ge={})).queryKey=we),ge&&se.setState(ge),G=!1,B&&queueMicrotask(ve),Oe=se,qe=Q.QueryStore,Object.assign(Oe,{[qe]:!0});var Oe,qe}(e,t,n);return S(r,r.getState,r.getInitialState,Object.is)}function Nt(e){return N(e)}function Vt(e){return function(e){return JSON.parse(e)}(e)}function Ht(e,t,n){const r=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,c=yt(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),G(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0}),a=Object.assign({[Q.VirtualStore]:!0,destroy:c.destroy,getInitialState:()=>c.getState().getInitialState(),getState:()=>c.getState().getState(),persist:(u=c.getState,{clearStorage:()=>u().persist?.clearStorage(),getOptions:()=>u().persist?.getOptions()??{},hasHydrated:()=>u().persist?.hasHydrated()??!0,hydrationPromise:()=>u().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>u().persist?.onFinishHydration(e)??d,onHydrate:e=>u().persist?.onHydrate(e)??d,rehydrate:()=>u().persist?.rehydrate(),setOptions:e=>u().persist?.setOptions(e)}),setState:xt(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 u;return a}(e,t,n);return S(r,r.getState,r.getInitialState)}var Wt=Symbol(),Ut=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Jt(n,r,o,i=Ut){const s=function(){const e=t(Wt);return e.current===Wt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:Gt(n),resubscribe:()=>{},unsubscribe:()=>{}}}(r,o,i)),e}(),c=function(e){return"function"==typeof e?Ut.enabled:e?.enabled??Ut.enabled}(i);return s.current.react=o,s.current.selector=r,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Ut)}(s,i),e(()=>{if(c)return Qt(n,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)},[c,n]),s}var Bt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Qt(e,t,n=Bt){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=Bt)=>Qt(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 Gt(e){return"function"==typeof e?{equalityFn:e}:e??Ut}var Xt=Symbol();function Yt(e){const n=t(Xt);return n.current===Xt&&(n.current=e()),n.current}export{R as QueryStatuses,_ as StoresError,W as applyStateUpdate,z as configureStores,Rt as createBaseStore,$t as createDerivedStore,Lt as createQueryStore,oe as createStoreActions,Ht as createVirtualStore,ce as deepEqual,L as defaultRetryDelay,G as destroyStore,X as destroyStores,Nt as getQueryKey,Y as getStoreName,Z as hasGetSnapshot,l as identity,te as isDerivedStore,ne as isPersistedStore,ee as isQueryStore,re as isVirtualStore,f as nullObject,Vt as parseQueryKey,J as replacer,B as reviver,ae as shallowEqual,$ as time,Jt as useListen,Yt as useStableValue};
1
+ import{useLayoutEffect as e,useRef as t,useSyncExternalStore as n,useDebugValue as r}from"react";import{Platform as o,unstable_batchedUpdates as i}from"react-native";var s=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),c="ios"===o.OS;o.OS;var a="development"===process.env.NODE_ENV,u="test"===process.env.NODE_ENV;function l(e){return e}function f(){return{__proto__:null}}function d(){}Object.freeze(Object.create(null));var y=Symbol("empty selection"),p=Object.is;function h(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===y?g(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===y||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===p?p(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===y)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 g(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==y)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return b(e,t)}function b(e,t){const n=e.value;if(n!==y&&p(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==y&&(e.equalityFn===p?p(n,r):e.equalityFn(n,r)))return m(e,t,n);const o=e.committedValue;return o!==y&&o!==n&&e.committedSource===e.source&&(e.equalityFn===p?p(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 S(e,o,i,s){return Object.assign(function(c,a){return function(e,o,i,s,c=p){const a=t(null);let u=e,l=o,f=i;if(s){let t=a.current;null===t&&(t=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:y,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return b(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>g(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:y,latestSource:y,selector:r,selectedSource:e,selectedSubscribe:()=>d,source:e,value:y,valueEqualityFn:o,valueSelector:r,valueSnapshot:y};return i.selectedSubscribe=h(i,e),i}(e,o,i,s,c),a.current=t),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=y),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=h(e,t))}(t,e,o,i,s,c),u=t.selectedSubscribe,l=t.getSelectedSnapshot,f=void 0===i?void 0:t.getSelectedServerSnapshot}const m=n(u,l,f);return r(m),m}(e.subscribe,o,i,c,a??s)},e)}function v(e){let t;function n(){if(t)return t;try{const n=function(e){const{createMMKV:t,MMKV:n}=s("react-native-mmkv");if("function"==typeof t)return t({id:e});if("function"==typeof n)return new n({id:e});throw new Error("[stores]: react-native-mmkv module does not export MMKV/createMMKV.")}(e);let r;if("function"==typeof n.delete?r=n.delete.bind(n):"function"==typeof n.remove&&(r=n.remove.bind(n)),"function"!=typeof r)throw new Error("[stores]: Storage instance does not conform to expected interface");const o={clearAll:n.clearAll.bind(n),contains:n.contains.bind(n),delete:r,get:n.getString.bind(n),getAllKeys:n.getAllKeys.bind(n),set:n.set.bind(n)};t=o}catch(e){throw new Error("[stores] react-native-mmkv could not be loaded.\n\nPersisted stores require a storage backend. Either:\n - Install MMKV (the default): yarn add react-native-mmkv\n - Or provide a custom adapter via configureStores()\n"+(e instanceof Error?`\n${e.message}`:""))}return function(e){if(!e||"function"!=typeof e.get||"function"!=typeof e.set||"function"!=typeof e.delete||"function"!=typeof e.clearAll)throw new Error("[stores]: Storage instance does not conform to expected interface")}(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}var w={debug:(e,t)=>{a&&console.debug(e,t)},error:(e,t)=>{a&&!u&&console.error(e,t)},info:(e,t)=>{a&&console.info(e,t)},warn:(e,t)=>{a&&console.warn(e,t)}},O=Object.prototype.hasOwnProperty;function q(e,t){return O.call(e,t)}function j(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function F(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var _=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 k(e){return e instanceof Error?e:new Error(String(e))}var I,A,C,z=class{destroy(){}publish(){}},T=class{constructor(){this.sessionId="noop"}register(e){return new z}},M=!1;function E(e){var t;a&&function(){if(M)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,w=t),A??(A=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),C??(C=D(e))}function P(){return C??(C=D(void 0))}function K(){M=!0}function D(e){return{storage:e?.storage??v(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(I||(I=new T),I)}}var x,R={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},$={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};function L(e,t){const n=t?.baseDelay??$.seconds(5),r=t?.maxDelay??$.minutes(5);return Math.min(n*Math.pow(2,e),r)}function N(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function V(e,t,n){if(!0===n)return H(t)?t(e):t;const r=H(t)?t(e):t;return Object.is(r,e)?e:F(e)&&F(r)?{...e,...r}:r}function H(e){return"function"==typeof e}function W(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}var U=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function B(e,t){Y(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function Q(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&B(n,t)}function G(e){const t="function"==typeof(n=e)?n.name:"";var n;return ee(e)?e.persist.getOptions().name??t:t}function X(e){return"getSnapshot"in e}function Y(e){return U.QueryStore in e}function Z(e){return"flushUpdates"in e}function ee(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function te(e){return U.VirtualStore in e}function ne(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(a&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(te(e))for(const n in t)oe(t,n)&&(r[n]=re(e,n));else for(const e in t)oe(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function re(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 oe(e,t){return"function"==typeof e[t]}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 se(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 ce(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(ce(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--&&ce(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(!ce(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)||!ce(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}var ae=i,ue=!1,le=!1,fe=!1,de=new Set,ye=new Map,pe=new Map,he=null,ge=1/0;function be(){return ue}function me(){return he}function Se(){ue||(ue=!0,fe||(fe=!0,queueMicrotask(()=>{fe=!1,ve()})))}function ve(){if(ue)if(le)Oe();else{le=!0;try{ae(Oe)}finally{Fe()}}}function we(e){ue&&de.add(e)}function Oe(){for(;ye.size>0||de.size>0;)qe(),je()}function qe(){for(;ye.size>0;){const e=ge,t=pe.get(e);if(t){pe.delete(e);for(const e of t)ye.delete(e);he=e;for(const e of t)e();he=null,ge=1/0;for(const e of pe.keys())e<ge&&(ge=e)}else{ge=1/0;for(const e of pe.keys())e<ge&&(ge=e)}}}function je(){for(const e of de)de.delete(e),e()}function Fe(){ue=!1,le=!1,he=null,de.clear(),ye.clear(),pe.clear(),ge=1/0}function _e(e){let t;const n=new Set;let r;function o(...e){const o=V(t,...e);if(Object.is(o,t))return;const i=t;if(t=o,r)for(const e of r)e(t,i);n.size&&ve();for(const e of n)e(t,i)}function i(){return t}const s={getInitialState:function(){return c},getState:i,setState:o,subscribe:function(...e){return 1===e.length?a(e[0]):function(e,n,o){const i=o?.equalityFn??Object.is,s=o?.isCascadeParticipant??!1;let c=e(t);function u(t){const r=e(t);if(i(c,r))return;const o=c;c=r,s&&Se(),n(r,o)}return o?.fireImmediately&&n(c,c),s?function(e){return(r??(r=new Set)).add(e),()=>{r?.delete(e),0===r?.size&&(r=void 0)}}(u):a(u)}(e[0],e[1],e[2])}},c=t=e(o,i,s);return s;function a(e){return n.add(e),()=>{n.delete(e)}}}function ke(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function Ie(e){return{...e,merge:e.merge??Ae,skipHydration:e.skipHydration??!1}}function Ae(e,t){return void 0===e?t:{...t,...e}}function Ce(){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 ze=Math.max,Te=Math.min;function Me(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=Ee();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==i?Te(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=Ee(),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=Pe(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?ze(Pe(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(Ee())},b}function Ee(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function Pe(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 Ke(e){if(!j(e))return e;const t={__proto__:null},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 De=u?0:$.seconds(c?3:5);function xe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Ke,c=t.deserializer??e.deserializer??$e(o),a=t.serializer??e.serializer??Le(o);function u(t,n,o){try{if(We(r))return;const c={state:s(n),version:o},u=Ve(r,i,c),l=a(c);try{e.set(t,l),He(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?Me(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:c(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function Re(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Ke,c=t.deserializer??e.deserializer??$e(o),a=t.serializer??e.serializer??Le(o);async function u(t,n,o){try{if(We(r))return;const c={state:s(n),version:o},u=Ve(r,i,c),l=a(c);try{await e.set(t,l),He(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?Me(u,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}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:c(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function $e(e){return t=>{if("string"!=typeof t)throw new _("[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 w.error(new _("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Le(e){return t=>function(e,t){try{return JSON.stringify(e,t?W:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var Ne=Object.freeze({shouldClear:!1});function Ve(e,t,n){if(!t||!e)return Ne;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 He(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function We(e){return!!e&&!!e.getIsApplyingRemote()}var[Je,Ue]=[0,1];function Be(e,t,n){if(!e)return!0;const r=e[Je],o=e[Ue];return!(t<r)&&(t>r||n>o)}function Qe(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Ge(e,t){if(!a)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 Xe(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Ye(e,t){if(K(),!t)return _e(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??P().storage:void 0,i=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new _("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,n),s=i?function(e,t,n){const r=t.engine??P().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:(i,s,c)=>{const a=new Map,u=[],l=[];let f=null,d=!1,y=!1,p=0,h=null,g=[],b=Promise.resolve(),m=!n;function S(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n={__proto__:null};for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function v(e,t){if(d||!h)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>p?e:p+1;return p=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=V(r,e,t);for(const e of g)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&S(n,o),i},u=t?i(c,!0):i(c);function b(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);f&&y?f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):l.push(e)}({keys:o,replace:t??!1,values:s,timestamp:n})}return ke(u)?u.finally(b):(b(),u)}const O=c.setState;c.setState=v;const q=e(v,s,c);if(g=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}(q),!g.length)return q;async function j(e){p=Math.max(p,e.timestamp);const n={__proto__:null},r=s(),i=e.timestamp;let c;if(e.replace)for(const t of g)Qe(t,e.values)||Be(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of g){if(!Qe(o,e.values))continue;if(!h?.has(o))continue;if(!Be(a.get(o),i,e.sessionId))continue;const s=t.merge?.[o];if(s){const t=e.values[o],c=r[o];if(void 0!==t){const u=s(t,c,r,e.values),l=void 0!==c?c:t;if(!Ge(u,l))return void w.error(new _(`[sync] Merge function for field "${String(o)}" returned ${Xe(u)} but expected ${Xe(l)}`));n[o]=u,a.set(o,[i,e.sessionId])}}else n[o]=e.values[o],a.set(o,[i,e.sessionId])}if(Object.keys(n).length>0||c?.length){d=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(c?.length){t=!0;for(const t of c)delete e[t],a.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??O)(e,!0)}else await(o.setWithoutPersist??O)(n)}finally{d=!1,o&&o.setIsApplyingRemote(!1)}}}function F(e){n?b=b.then(()=>j(e)):j(e)}if(h=new Set(g),f=r.register({apply:e=>{m?F(e):u.push(e)},fields:g,getState:s,key:t.key}),f?.onFirstSubscribe||f?.onLastUnsubscribe){let e=0;const t=c.subscribe;c.subscribe=(...n)=>{e||f.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||f.onLastUnsubscribe?.()})}}}function k(){y=!0,function(){if(f&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);S(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function I(){m=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)F(t)}()}return n?(o.onHydrationComplete=k,o.onHydrationFlushEnd=I):f.onHydrated?(f.onHydrated(k),I()):(k(),I()),q},syncContext:o}}(e,i,o?.async??!1):void 0,c=s?.stateCreator??e;if(!r)return _e(c);const a=function(e,t,n){const r=t??e.storage??P().storage,o=(e.sync?void 0:e.persistThrottleMs??De)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:Re(r,e,o,n),version:i}:{async:!1,persistStorage:xe(r,e,o,n),version:i}}(t,o,s?.syncContext),u=a.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=Ce()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)N(s.setState,e);c=void 0}},e(function(...e){return o?N(n,e):(t||(t=Ce()),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(k(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,f=_e(function(e,t){return(n,r,o)=>{let i,s,c,a=Ie(t),u=!1,l=0;function f(){return a.storage.setItem(a.name,r(),a.version)}const d=o.setState;o.setState=function(...e){return N(d,e),f()};const y=e(function(...e){return N(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,s?.forEach(e=>e(r()??y)),e}(),t=a.onRehydrateStorage?.(r()??y);try{const n=a.storage.getItem(a.name);return ke(n)?n.then(n=>h(e,n,t)).catch(n=>m(e,t,n)):h(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{a.storage.removeItem(a.name)},getOptions:()=>a,hasHydrated:()=>u,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{a=Ie({...a,...e,storage:e.storage??a.storage})}}}),a.skipHydration||p(),i??y;function h(e,t,n){const r=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error("State loaded from storage couldn't be migrated since no migrate function was provided"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return ke(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(a,t);return ke(r)?r.then(t=>g(e,t,n)).catch(t=>m(e,n,t)):g(e,r,n)}function g(e,t,o){const s=function(e,t){if(e!==l)return;const o=a.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(ke(s))return s.then(()=>b(e,o));b(e,o)}function b(e,t){if(e!==l)return;t?.(i,void 0);const n=r();i=n,u=!0,c?.forEach(e=>e(n))}function m(e,t,n){e===l&&t?.(void 0,n)}}}(u?(e,t,n)=>(s&&(s.syncContext.setWithoutPersist=n.setState),u.stateCreator(e,t,n)):c,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:a.persistStorage,version:a.version}));return u?Object.assign(f,{persist:Object.assign(f.persist,{hydrationPromise:u.hydrationPromise})}):f}function Ze(e,t,n="s"){return 1===t?e:`${e}${n}`}var et=Symbol("stores.deriveProxy.unwrap");function tt(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?nt(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(X(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function nt(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===et)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,{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,nt(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 rt(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,et);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=it(e,t);if(n)for(let t=0;t<e.length;t++)ot(e,String(t),n)}(e,t):j(e)&&function(e,t){const n=it(e,t);if(n)for(const t of Reflect.ownKeys(e))ot(e,t,n)}(e,t),e)}function ot(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=rt(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function it(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var st=Object.freeze([]);function ct(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)ut(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?yt(n.path,n.invocation):dt(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={__proto__:null},e.set(t,i)),at(i,n,0,r,o)}}}function at(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(lt(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(lt(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children={__proto__:null});const i=t[n];let s=e.children?.[i];s||(s={__proto__:null},e.children[i]=s),at(s,t,n+1,r,o)}function ut(e,t,n,r,o,i=2){const s=e.children;if(!s)return void ft(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){ft(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&ut(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)ut(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void ut(s[e],t,[...n,e],r+1,o,i)}ft(e,t,n,o)}else ft(e,t,n,o)}function lt(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function ft(e,t,n,r){const o=e.isLeaf??!1,i=e.invocation;if(!i)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:i,isLeaf:o});const s=e.extraInvocations;if(s)for(let e=0;e<s.length;e++)r.add({store:t,path:n,invocation:s[e],isLeaf:o})}function dt(e){return t=>pt(t,e)}function yt(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=pt(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??st):void 0}}function pt(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var ht=Symbol(),gt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function bt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:s}="function"==typeof(u=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:u,keepAlive:!1,lockDependencies:!1}:{debounceOptions:u.debounce,debugMode:(a&&u.debugMode)??!1,equalityFn:u.equalityFn??Object.is,keepAlive:u.keepAlive??!1,lockDependencies:u.lockDependencies??!1},c=new Set;var u;i&&c.add(mt);const f=new Set;let d,y,p=ht,h=!1,g=!1,b=!0,m=!0,S=0,v=!1,w=null,O=ht;function q(e,t,n){if(!m||!c.size)return(t??l)(e.getState());if(!t)return d||(d=new WeakMap),y||(y=ct()),tt(e,d,y.trackPath);const r=n?{equalityFn:n,isCascadeParticipant:!0}:gt;return f.add(e.subscribe(t,E,r)),t(X(e)?e.getSnapshot():e.getState())}function j(e){for(const t of f)t(e);f.clear()}let F=!0;function _(){if(!b&&St(p))return p;b=!1,m&&j(!0);const t=p,n=St(t);g=!0;try{p=function(t){F=!0;const n=p,i=e(t),s=y?rt(i):i;return St(n)&&o(n,s)?(r&&console.log("[🥷 Derive Complete 🥷]: No change detected"),F=!1,n):s}(q)}finally{g=!1}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=f.size;console.log(`[🎯 ${e} ${Ze("Selector Subscription",e)} 🎯]`)}return y&&m&&(y.buildProxySubscriptions((e,t)=>{f.add(e.subscribe(t,E,gt))},i),d=void 0,y.reset(),s&&(y=void 0)),F&&n&&function(e,t){const n=function(){const e=c.has(mt)?c.size-1:c.size;return S>0&&S<e}(),o=(!S||n)&&(n||null!==me()||be());n&&Se(),r&&console.log(`[📻 Derive Complete 📻]: Notifying ${c.size} ${Ze("watcher",c.size)}`);for(const t of c){if("function"==typeof t||!t.isCascadeParticipant)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}if(o)return St(O)||(O=t),void(v||(v=!0,we(I)));k(e,t)}(p,t),s&&(m=!1),p}function k(e,t){for(const n of c)if("function"==typeof n)n(e,t);else if(!n.isCascadeParticipant){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function I(){c.size&&b&&!S&&_();const e=O;v=!1,O=ht,c.size&&St(p)&&St(e)&&k(p,e)}const A=n?Me(z,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,C=A??(()=>{h||(h=!0,queueMicrotask(z))});function z(){h=!1,c.size?b&&_():D()}function T(e){e||A&&b?queueMicrotask(()=>{c.size||D()}):D()}function M(){z(),w=null}function E(){if(!g&&!b){if(b=!0,!A){if(S){Se();const e=me(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!ue)return;const n=t<0?0:0|t,r=ye.get(e);if(void 0===r){ye.set(e,n);let t=pe.get(n);return t||(t=new Set,pe.set(n,t)),t.add(e),void(n<ge&&(ge=n))}if(n>r){const t=pe.get(r);if(t&&(t.delete(e),0===t.size&&(pe.delete(r),r===ge))){ge=1/0;for(const e of pe.keys())e<ge&&(ge=e)}ye.set(e,n);let o=pe.get(n);o||(o=new Set,pe.set(n,o)),o.add(e),n<ge&&(ge=n)}}(M,t)}if(be())return void(v||(v=!0,we(I)))}w=null,C()}}function P(e){c.add(mt);try{return e()}finally{c.delete(mt)}}function K(){return be()&&function(){if(ue)if(le)null===he&&qe();else{le=!0;try{qe()}catch(e){throw Fe(),e}finally{le=!1,he=null}}}(),b||!St(p)?c.size>0?_():e(q):p}function D(e=!0){i&&e||(A?.cancel(),j(),c.clear(),S=0,y=void 0,d=void 0,m=!0,h=!1,g=!1,b=!0,p=ht,v=!1,O=ht,w=null)}return{destroy:()=>D(!1),flushUpdates:function(){c.size&&(A?A.flush():b&&_())},getSnapshot:function(){return St(p)?(h&&z(),p):c.size?_():P(_)},getState:K,subscribe:function(...e){if(1===e.length){const t=e[0];return c.add(t),St(p)||K(),()=>{c.delete(t),c.size||T(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isCascadeParticipant??!1,s=function(e){return e(c.size?K():P(K))}(t),a={currentSlice:s,equalityFn:o,isCascadeParticipant:i,listener:n,selector:t};return c.add(a),i&&(S+=1),r?.fireImmediately&&n(s,s),()=>{c.delete(a),i&&(S-=1),c.size||T(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.")}}}function mt(){}function St(e){return e!==ht}var vt=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=$.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs,n=t&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(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)}}},wt=Symbol("stores.queryParamConfig");function Ot(e,t){return{[wt]:!0,key:t.key,value:e}}function qt(e){return JSON.stringify(Ft(e))}function jt(e){return JSON.parse(e)}function Ft(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=j(r)?Ft(r):r,t},{__proto__:null})}var _t=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function kt(e,t,n){const r={__proto__:null};let o=null,i=!1;if(e)for(const n in e){if(!q(e,n))continue;const s=It(r,e[n],n,t);s&&((o??(o=f()))[n]=s,void 0!==s.key&&(i=!0))}return{buildKey:(e=r)=>qt(i?function(e,t){const n={__proto__:null};for(const r in t){if(!q(t,r))continue;const o=e?.[r];if(!1===o?.key)continue;const i=t[r];n[r]=o?.key?o.key(i):i}return n}(o,e):e),complete:e=>e?function(e,t){for(const n of t)if(!(n in e))return!1;return!0}(e,n)?e:{...r,...e}:zt(r),get:()=>zt(r),subscribe:e=>function(e,t,n){if(!e)return d;let r;for(const o in e){const i=e[o]?.tracked;i&&(r??(r=[])).push(i.subscribe(e=>{const r=t[o];ce(r,e)||(t[o]=e,n(o,r,e))}))}return r?e=>{for(const t of r)t(e)}:d}(o,r,e)}}function It(e,t,n,r){return(o=t)&&"object"==typeof o&&wt in o?Ct(e,t.value,n,r,t.key):Ct(e,t,n,r);var o}function At(e,t){const n=[];let r,o;function i(e,t=l){return t(Tt(e))}const s=e(function(e,t,i){return t?(n.push(n=>e.subscribe(t,n,function(e){return e?{equalityFn:e,isCascadeParticipant:!0}:_t}(i))),t(Tt(e))):(r??(r=ct()),o??(o=new WeakMap),tt(e,o,r.trackPath))},t),c=r?rt(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,_t))},!1),r.reset()),o=void 0,{initialValue:c,subscribe(r){const o=()=>r(e(i,t)),s=n.map(e=>e(o));return e=>{for(const t of s)t(e)}}}}function Ct(e,t,n,r,o){if(function(e){return"function"==typeof e}(t)){const i=At(t,r);return e[n]=i.initialValue,void 0===o?{tracked:i}:{key:o,tracked:i}}return e[n]=t,void 0===o?null:{key:o}}function zt(e){const t={__proto__:null};for(const n in e)q(e,n)&&(t[n]=e[n]);return t}function Tt(e){return X(e)?e.getSnapshot():e.getState()}var Mt={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},Et=Object.freeze({force:!0}),Pt=Object.freeze({once:!0}),Kt=new Set,Dt=!1;function xt(e){Kt.add(e),Dt||(Dt=!0,queueMicrotask(()=>{Dt=!1,ae(Rt)}))}function Rt(){for(const e of Kt)Kt.delete(e),e()}function $t(e,t){return n=>{const r={...n},o={__proto__:null};for(const e in r)q(r,e)&&e in Mt&&(Mt[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):Ke(r),...Lt(e,null,o)}}}function Lt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i={__proto__:null};let s=!1;for(const e in n.queryCache){if(!q(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 Nt(){return Object.create(null)}function Vt(e,t,n){return new _(`[createQueryStore: ${e}]: ${t} failed`,n)}function Ht(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}function Wt(e,t){const n=Ye(e,t);return S(n,n.getState,n.getInitialState,Object.is)}function Jt(e,t=Object.is){const n=bt(e,t);return S(n,n.getSnapshot)}function Ut(e,t,n){const r=function(e,t,n){K();const r="function"==typeof t?t:Nt,o="object"==typeof t?t:n,i=function(e){return"string"==typeof e?.storageKey}(o)?o:void 0,s=x??(x=function(){const e={abortInterruptedFetches:!0,cacheTime:$.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:L,staleTime:$.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(A)return A}()?.queryStoreDefaults;return t?{...e,...t}:e}()),c=s.minStaleTime,{fetcher:l,onError:f,onFetched:d,setData:y,transform:p,abortInterruptedFetches:h=s.abortInterruptedFetches,cacheTime:g=s.cacheTime,debugMode:b=s.debugMode,disableAutoRefetching:m=s.disableAutoRefetching,disableCache:S=!1,enabled:v=!0,keepPreviousData:O=s.keepPreviousData,maxRetries:q=s.maxRetries,paramChangeThrottle:j=s.paramChangeThrottle,params:F,retryDelay:I=s.retryDelay,staleTime:C=s.staleTime,suppressStaleTimeWarning:z=s.suppressStaleTimeWarning}=e;let T="function"==typeof C?s.staleTime:C;a&&!1!==c&&!m&&!z&&T<c&&console.warn(`[createQueryStore${i?.storageKey?`: ${i.storageKey}`:""}] ❌ Stale times under ${c/1e3} seconds are not recommended. Provided staleTime: ${T/1e3} seconds`);const M=new Error("[createQueryStore: AbortError] Fetch interrupted"),E="function"==typeof g,P=a&&b,D=e.params?Object.keys(e.params):[];let N,V=!1,H=[],W=null,J=null,B=null,Q=null,G=null,X=null,Y=null;const Z={enabled:"function"!=typeof v&&v,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:R.Idle},ee=new vt(m);function te(){B&&(Q=null,B.abort(),B=null)}function ne(){G&&(clearTimeout(G),G=null)}function re(e,t,n){const o=n.setState;function s(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&&Y!==t&&(Y=t,t&&ee.hasSubscribers()?queueMicrotask(()=>a.fetch(void 0,void 0,!0)):(G||h)&&(h&&te(),ne()))}(r.enabled,i)),o});return n?.(),r}return o(e)}function c(e){if(m||T<=0||T===1/0)return;if(!ee.hasSubscribers())return;ne();const n=t();if(!n.enabled)return;const r=N.buildKey(e),o=(S?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,i=o?T-(Date.now()-o):T;G=setTimeout(()=>{t().enabled&&a.fetch(e,Et,!0)},i)}n.setState=s,ee.init({onSubscribe:(n,r)=>{const o=t();if(o.enabled)if(n){const t=N.get(),n=N.buildKey(t);o.queryKey!==n&&e({queryKey:n}),o.isStale()?a.fetch(t,void 0,!0):c(t)}else m&&!r&&a.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{ne(),h&&!e&&te()}});const a={...r(s,t,n),...Z,async fetch(n,r,o=!1){const u=!!r?.skipStoreUpdates,b=t();if(!u){if(!b.enabled&&!r?.force)return null;if(o&&!ee.hasSubscribers())return null}const m=b.error,v=b.queryKey,j=b.status===R.Loading,F=N.complete(n),A=N.buildKey(F);if(j&&Q?.promise&&Q.key===A)return P&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(F)),Q.promise;const C=r?.staleTime??T,z="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&O,K=(o||v===A||z)&&!u,x=null!==Q;if(h&&K&&te(),!r?.force){const t=b.lastFetchedAt,n=b.queryCache[A],r=n?.lastFetchedAt,o=n?.errorInfo,i=o&&o.retryCount>=q,s=(S?X===A&&t:r)||null;if(s&&!(Date.now()-s>=C)&&(!o||i||u))return K&&!G&&0!==T&&T!==1/0&&c(F),z&&e(e=>e.queryKey!==A?{queryKey:A}:e),P&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(F)),n?.data??null}const $=K?{key:A}:null,L=r?.cacheTime??(E?g(F):g);async function V(){const b=i?.storageKey||A;try{P&&(!o&&n&&D.some(e=>!(e in n))?console.log("[🔄 Fetching with Partial Params 🔄]\n","- Provided params:",`${JSON.stringify(n)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(F).filter(e=>!(e in n)).map(e=>[e,F[e]])))}`):console.log("[🔄 Fetching 🔄] for params:",JSON.stringify(F)));const t=await(h&&K?async function(e){const t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(M),Pt),Promise.resolve(l(e,t)).then(n,r)})}finally{B===t&&(B=null)}}(F):l(F,null)),i=Date.now();let f;P&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(F));try{f=function(e,t,n){return n?n(e,t):e}(t,F,p)}catch(e){throw Vt(b,"transform",e)}if(u)return P&&console.log("[🥷 Successful Parallel Fetch 🥷] for params:",JSON.stringify(F)),"withCache"===r.skipStoreUpdates&&e(e=>{if(!y)return S?e:{queryCache:{...e.queryCache,[A]:{cacheTime:L,data:f,errorInfo:null,lastFetchedAt:i}}};let t=e;const n=t.queryCache[A];try{y({data:f,params:F,queryKey:A,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Vt(b,"setData",e)}return!S&&Object.is(n,t.queryCache[A])&&(t={...t,queryCache:{...t.queryCache,[A]:{cacheTime:L,data:null,errorInfo:null,lastFetchedAt:i}}}),t}),f;if((y?s:e)(e=>{let t={...e,error:null,lastFetchedAt:i,queryKey:z?A:e.queryKey,status:R.Success};if(y||S){if(y){P&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(F));const e=t.queryCache[A];try{y({data:f,params:F,queryKey:A,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Vt(b,"setData",e)}!S&&Object.is(e,t.queryCache[A])&&(t.queryCache={...t.queryCache,[A]:{cacheTime:L,data:null,errorInfo:null,lastFetchedAt:i}})}}else P&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(F),"| Has previous data?:",!!t.queryCache[A]?.data),t.queryCache={...t.queryCache,[A]:{cacheTime:L,data:f,errorInfo:null,lastFetchedAt:i}};return S||g===1/0?t:Lt(O,A,t)}),K&&(X=A,c(F)),d)try{d({data:f,fetch:a.fetch,params:F,set:s})}catch(e){w.error(Vt(b,"onFetched callback",e))}return f??null}catch(n){if(n===M)return P&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(F)),null;const i=!o&&!0===r?.throwOnError,s=k(n);if(s instanceof _&&w.error(s),!K){if(i)throw s;return null}const c=S?void 0:t().queryCache[A],u=c?.errorInfo?.retryCount??0,l=u+1;try{f?.(s,u)}catch(e){w.error(Vt(b,"onError callback",e))}if(u<q){if(t().enabled&&ee.hasSubscribers()){const e="function"==typeof I?I(l,s):I;e!==1/0&&(ne(),G=setTimeout(()=>{t().enabled&&a.fetch(F,Et,!0)},e))}e(e=>({error:s,queryCache:{...e.queryCache,[A]:{cacheTime:c?.cacheTime??L,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:l}}},queryKey:z?A:e.queryKey,status:R.Error}))}else e(e=>({error:s,queryCache:{...e.queryCache,[A]:{cacheTime:c?.cacheTime??L,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryCount:q}}},queryKey:z?A:e.queryKey,status:R.Error}));if(i)throw s;return null}finally{Q===$&&(Q=null)}}return $&&(ne(),z&&!x&&null===b.lastFetchedAt&&v!==A?e({error:null,queryKey:A,status:R.Loading}):!m&&j||e({error:null,status:R.Loading}),Q=$),$?($.promise=V(),$.promise):V()},getCacheEntry(e){if(S)return null;const n=t(),r=e?"string"==typeof e?e:N.buildKey(N.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(S)return null;const n=t().getCacheEntry(e);return n&&null!==n.data?O?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data:null},getStatus:function(e){const n=t(),r=n.status;switch(e){case"isIdle":return r===R.Idle;case"isLoading":return r===R.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const t=n.queryKey,o=n.queryCache[t],i=S?r===R.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((S?X===t&&n.lastFetchedAt:o?.lastFetchedAt)||null),c=!s&&!i&&n.enabled;if("isInitialLoad"===e)return c;const a=s&&!i;return"isSuccess"===e?a:{isError:i,isIdle:r===R.Idle,isLoading:r===R.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const n=t(),r=n.queryCache[n.queryKey],o=n.queryKey,i=n.lastFetchedAt,s=(S?X===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 n=t(),r=n.queryKey,o=(S?X===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??T;return Date.now()-o>=i},reset(t=!1){for(const e of H)e();H=[],N=kt(void 0,oe,D),W=null,J=null,te(),ne(),Q=null,X=null,t&&e(Z)}},u=n.subscribe;return n.subscribe=(...e)=>{const t=V?void 0:ee.subscribe(),n=1===e.length?u(e[0]):u(e[0],e[1],e[2]);return e=>{t?.(e),n()}},a}const oe=i?.storageKey?Ye(re,(ie=i,void 0===(se={partialize:$t(O,i.partialize)})?Object.assign({__proto__:null},ie):Object.assign({__proto__:null},ie,se))):o&&!("storageKey"in o)?Ye(re,o):Ye(re);var ie,se;const ce=oe.getState(),ae=ce.error,ue=ce.enabled,le=ce.queryKey,fe=ce.fetch;le&&!ae&&(X=le),V=!0,N=kt(F,oe,D),"function"==typeof v&&(W=At(v,oe)),"function"==typeof e.staleTime&&(J=At(e.staleTime,oe),T=J.initialValue);const de=function(e,t=queueMicrotask){let n,r=!1;function o(){r=!1,e(...n)}return function(...e){n=e,r||(r=!0,t(o))}}(e=>{fe(e,void 0,!0)},xt);function ye(){if(O)de(void 0);else{const e=N.get();oe.setState({queryKey:N.buildKey(e)}),de(e)}}const pe=u||!j?void 0:Me(ye,"number"==typeof j?j:j.delay,"number"==typeof j?{leading:!1,maxWait:j,trailing:!0}:j);if(H.push(N.subscribe((e,t,n)=>{P&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${t?.toString()},`,"[New]:",n?.toString()),function(){if(ne(),pe){const e=oe.getState();return void(O&&Q?.key===e.queryKey&&null===e.lastFetchedAt?ye():pe())}ye()}()})),J){let e=J.initialValue;P&&console.log("[🌀 StaleTime Subscription 🌀] Initial value:",e),H.push(J.subscribe(t=>{t!==e&&(P&&console.log("[🌀 StaleTime Change 🌀] - [Old]:",`${e},`,"[New]:",t),e=t,T=t,ne(),fe(void 0,void 0,!0))}))}let he;if(W){let e=W.initialValue;ue!==e&&((he??(he={})).enabled=e),P&&console.log("[🌀 Enabled Subscription 🌀] Initial value:",e),H.push(W.subscribe(t=>{t!==e&&(P&&console.log("[🌀 Enabled Change 🌀] - [Old]:",`${e},`,"[New]:",t),e=t,oe.setState({enabled:t}))}))}else ue!==Z.enabled&&((he??(he={})).enabled=Z.enabled);const ge=N.buildKey();return ge!==le&&((he??(he={})).queryKey=ge),he&&oe.setState(he),V=!1,be=oe,me=U.QueryStore,Object.assign(be,{[me]:!0});var be,me}(e,t,n);return S(r,r.getState,r.getInitialState,Object.is)}function Bt(e,t,n){const r=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set;let c;function a(e,t,n,r){u(e,t,n,r)&&Se()}function u(e,t,n,r){e.unsubscribe();const o=e.args;if(1===o.length){const i=o[0],s=t.subscribe(i);e.unsubscribe=s;const c=!Object.is(r,n);return c&&i(r,n),c}const i=o[0],s=o[1];let c=o[2];c?.fireImmediately&&(c={...c,fireImmediately:!1});const a=i(n),u=i(r),l=t.subscribe(i,s,c);return e.unsubscribe=l,!(c?.equalityFn??Object.is)(a,u)&&(s(u,a),!0)}function l(e,t){!function(e,t){const n=e.getState(),r=t.getState();if(c)for(const e of c)a(e,t,n,r);s.size&&ve();for(const e of s)u(e,t,n,r)}(t,e),B(t)}const f=bt(e,{debugMode:i?.debugMode??!1,lockDependencies:i?.lockDependencies??!0});let y;function p(){return y??(y=f.subscribe(l)),f.getState()}const h=Object.assign({[U.VirtualStore]:!0,destroy:()=>{y?.(),y=void 0,f.destroy()},getInitialState:()=>p().getInitialState(),getState:()=>p().getState(),persist:(g=p,{clearStorage:()=>g().persist?.clearStorage(),getOptions:()=>g().persist?.getOptions()??{},hasHydrated:()=>g().persist?.hasHydrated()??!0,hydrationPromise:()=>g().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>g().persist?.onFinishHydration(e)??d,onHydrate:e=>g().persist?.onHydrate(e)??d,rehydrate:()=>g().persist?.rehydrate(),setOptions:e=>g().persist?.setOptions(e)}),setState:Ht(p),subscribe:function(...e){const t=p(),n={args:e,unsubscribe:1===e.length?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(c??(c=new Set)).add(n):s.add(n),()=>{n.unsubscribe(),r?c?.delete(n)&&0===c.size&&(c=void 0):s.delete(n)}}},o?.(p));var g;return h}(e,t,n);return S(r,r.getState,r.getInitialState)}var Qt=Symbol(),Gt=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Xt(n,r,o,i=Gt){const s=function(){const e=t(Qt);return e.current===Qt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:en(n),resubscribe:d,unsubscribe:d}}(r,o,i)),e}(),c=function(e){return"function"==typeof e?Gt.enabled:e?.enabled??Gt.enabled}(i);return s.current.react=o,s.current.selector=r,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Gt)}(s,i),e(()=>{if(c)return Zt(n,s),()=>function(e){e.current.options.debugMode&&console.log("[🗑️ useListen 🗑️] Detaching listener"),e.current.resubscribe=d,e.current.unsubscribe(),e.current.unsubscribe=d,e.current.isActive=!1}(s)},[c,n]),s}var Yt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Zt(e,t,n=Yt){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=Yt)=>Zt(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 en(e){return"function"==typeof e?{equalityFn:e}:e??Gt}var tn=Symbol();function nn(e){const n=t(tn);return n.current===tn&&(n.current=e()),n.current}export{R as QueryStatuses,_ as StoresError,V as applyStateUpdate,E as configureStores,Wt as createBaseStore,Jt as createDerivedStore,Ut as createQueryStore,ne as createStoreActions,Bt as createVirtualStore,ie as deepEqual,L as defaultRetryDelay,B as destroyStore,Q as destroyStores,qt as getQueryKey,G as getStoreName,X as hasGetSnapshot,l as identity,Z as isDerivedStore,ee as isPersistedStore,Y as isQueryStore,te as isVirtualStore,f as nullObject,jt as parseQueryKey,Ot as queryParam,W as replacer,J as reviver,se as shallowEqual,$ as time,Xt as useListen,nn as useStableValue};
@@ -1,27 +1,13 @@
1
- /**
2
- * Initialization config for the SubscriptionManager.
3
- */
4
- interface SubscriptionManagerConfig {
5
- /**
6
- * The store's `disableAutoRefetching` option, passed through from the query config.
7
- */
8
- disableAutoRefetching: boolean;
9
- /**
10
- * The initial enabled state for the SubscriptionManager.
11
- */
12
- initialEnabled: boolean;
13
- }
14
1
  /**
15
2
  * Lazy initialization config for subscription handlers.
16
3
  */
17
4
  interface SubscriptionHandlerConfig {
18
5
  /**
19
6
  * Callback executed when a subscription is added.
20
- * @param enabled - The current enabled state
21
7
  * @param isFirstSubscription - Whether this is the first subscription
22
8
  * @param shouldThrottle - Whether to throttle the fetch
23
9
  */
24
- onSubscribe: (enabled: boolean, isFirstSubscription: boolean, shouldThrottle: boolean) => void;
10
+ onSubscribe: (isFirstSubscription: boolean, shouldThrottle: boolean) => void;
25
11
  /** Callback executed when the last remaining subscription is removed. */
26
12
  onLastUnsubscribe: (willResubscribe?: boolean) => void;
27
13
  }
@@ -30,7 +16,6 @@ interface SubscriptionHandlerConfig {
30
16
  */
31
17
  export declare class SubscriptionManager {
32
18
  private count;
33
- private enabled;
34
19
  private lastSubscriptionTime;
35
20
  private readonly fetchThrottleMs;
36
21
  private onSubscribe;
@@ -38,25 +23,12 @@ export declare class SubscriptionManager {
38
23
  /**
39
24
  * Creates a new SubscriptionManager instance.
40
25
  */
41
- constructor({ disableAutoRefetching, initialEnabled }: SubscriptionManagerConfig);
26
+ constructor(disableAutoRefetching: boolean);
42
27
  /**
43
28
  * Initializes subscription event handlers.
44
29
  */
45
30
  init({ onSubscribe, onLastUnsubscribe }: SubscriptionHandlerConfig): void;
46
- /**
47
- * Returns the current subscription state.
48
- * @returns An object containing `enabled`, `lastSubscriptionTime`, and `subscriptionCount`
49
- */
50
- get(): {
51
- enabled: boolean;
52
- lastSubscriptionTime: number | null;
53
- subscriptionCount: number;
54
- };
55
- /**
56
- * Updates the enabled state for queries.
57
- * @param enabled - The new enabled state
58
- */
59
- setEnabled(enabled: boolean): void;
31
+ hasSubscribers(): boolean;
60
32
  /**
61
33
  * Adds a new subscription and triggers relevant lifecycle callbacks.
62
34
  * @returns A cleanup function that removes the subscription when called
@@ -1,3 +1,10 @@
1
- export declare function getQueryKey<TParams extends Record<string, unknown>>(params: TParams): string;
2
- export declare function parseQueryKey<TParams extends Record<string, unknown>>(queryKey: string): TParams;
1
+ /**
2
+ * Generates a deterministic query store `queryKey` from the given
3
+ * key payload, consistent with internally generated keys.
4
+ */
5
+ export declare function getQueryKey<TKeyPayload extends Record<string, unknown>>(keyPayload: TKeyPayload): string;
6
+ /**
7
+ * Parses a query store `queryKey` into the key payload it encodes.
8
+ */
9
+ export declare function parseQueryKey<TKeyPayload extends Record<string, unknown> = Record<string, unknown>>(queryKey: string): TKeyPayload;
3
10
  //# sourceMappingURL=queryKey.d.ts.map
@@ -0,0 +1,37 @@
1
+ import type { StoreApi } from '../store/types';
2
+ import type { DeriveGetter } from '../types';
3
+ import type { NonFunction } from '../types/functions';
4
+ declare const QUERY_PARAM_CONFIG: unique symbol;
5
+ /**
6
+ * Selects how a query parameter participates in the query key.
7
+ */
8
+ export type QueryParamKey<T> = false | ((value: T) => unknown);
9
+ /**
10
+ * A query value derived from stores via `$`.
11
+ */
12
+ export type ReactiveParam<T, State> = ($: DeriveGetter, store: StoreApi<State>) => T;
13
+ /**
14
+ * Query parameter wrapper for values whose fetcher value and key value differ.
15
+ */
16
+ export type QueryParamConfig<T, State> = {
17
+ readonly [QUERY_PARAM_CONFIG]: true;
18
+ readonly key: QueryParamKey<T>;
19
+ readonly value: NonFunction<T> | ReactiveParam<T, State>;
20
+ };
21
+ /**
22
+ * A direct, reactive, or key-configured query parameter.
23
+ */
24
+ export type QueryParam<T, State> = NonFunction<T> | ReactiveParam<T, State> | QueryParamConfig<T, State>;
25
+ /**
26
+ * Wraps a query parameter when its full fetcher value should be excluded
27
+ * from the query key or represented by a smaller key value.
28
+ */
29
+ export declare function queryParam<T, State>(value: NonFunction<T> | ReactiveParam<T, State>, options: {
30
+ key: QueryParamKey<T>;
31
+ }): QueryParamConfig<T, State>;
32
+ /**
33
+ * Checks if a `QueryParam` value is a custom `queryParam(...)` config.
34
+ */
35
+ export declare function isQueryParamConfig<T, State>(value: QueryParam<T, State>): value is QueryParamConfig<T, State>;
36
+ export {};
37
+ //# sourceMappingURL=queryParam.d.ts.map
@@ -1,6 +1,6 @@
1
- import type { AttachValue, SignalFunction } from './signalTypes';
2
- import type { StoreApi } from '../store/types';
1
+ import type { QueryParam, ReactiveParam } from './queryParam';
3
2
  import type { DebounceOptions, SetPartial, Store } from '../types';
3
+ export type { QueryParam, QueryParamConfig, QueryParamKey, ReactiveParam } from './queryParam';
4
4
  /**
5
5
  * Helper type that represents the store returned by `createQueryStore()`.
6
6
  */
@@ -92,7 +92,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
92
92
  * When `false`, the store will not automatically fetch data until explicitly enabled.
93
93
  * @default true
94
94
  */
95
- enabled?: boolean | ReactiveParam<boolean, TParams, S, TData>;
95
+ enabled?: boolean | ReactiveParam<boolean, S>;
96
96
  /**
97
97
  * When `true`, the store's `getData` method will always return existing data from the cache if it exists,
98
98
  * regardless of whether the cached data is expired, until the data is pruned following a successful refetch.
@@ -116,8 +116,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
116
116
  */
117
117
  paramChangeThrottle?: false | number | DebounceOptions;
118
118
  /**
119
- * Parameters to be passed to the fetcher, defined as either direct values or `ReactiveParam` functions.
120
- * Dynamic parameters using `AttachValue` will cause the store to refetch when their values change.
119
+ * Reactive or static parameters to be passed to the fetcher.
121
120
  */
122
121
  params?: QueryStoreParams<TParams, TData, S, CustomState>;
123
122
  /**
@@ -135,7 +134,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
135
134
  * After becoming stale, the store may automatically refetch data in the background if there are active subscribers.
136
135
  * @default time.minutes(2)
137
136
  */
138
- staleTime?: number | ReactiveParam<number, TParams, S, TData>;
137
+ staleTime?: number | ReactiveParam<number, S>;
139
138
  /**
140
139
  * Suppresses warnings in the event a `staleTime` under the minimum is desired.
141
140
  * @default false
@@ -213,11 +212,11 @@ export type QueryStoreInternalState<TData, TParams extends Record<string, unknow
213
212
  */
214
213
  lastFetchedAt: number | null;
215
214
  /**
216
- * A cache of fetched data and metadata, keyed by query stringified params.
215
+ * A cache of fetched data and metadata, keyed by generated query keys.
217
216
  */
218
217
  queryCache: Record<string, CacheEntry<TData> | undefined>;
219
218
  /**
220
- * The current query key, which is a string representation of the current query parameter values.
219
+ * The current query key, generated deterministically from store parameters.
221
220
  */
222
221
  queryKey: string;
223
222
  /**
@@ -275,7 +274,8 @@ export type FetchOptions = {
275
274
  * `queryKey` (which determines where `getData()` points to).
276
275
  *
277
276
  * ---
278
- * Defaults to `true` unless `skipStoreUpdates: true` is specified, in which case the default is `false`.
277
+ * Manual fetches default to `false`. Internal query-store fetches default to the store's `keepPreviousData`
278
+ * behavior. When `skipStoreUpdates` is set, the query key is never updated.
279
279
  */
280
280
  updateQueryKey?: boolean;
281
281
  };
@@ -334,49 +334,7 @@ export type CacheEntry<T> = {
334
334
  * Internal helper type for the config’s params clause.
335
335
  */
336
336
  export type QueryStoreParams<TParams extends Record<string, unknown>, TData, S extends QueryStoreState<TData, TParams, CustomState>, CustomState = unknown> = [TParams] extends [Record<string, never>] ? undefined : {
337
- [K in keyof TParams]: ReactiveParam<TParams[K], TParams, S, TData>;
338
- };
339
- /**
340
- * Represents a parameter that can be provided directly or defined via a reactive `AttachValue`.
341
- * A parameter can be:
342
- * - A static value (e.g. `string`, `number`).
343
- * - A function that returns an `AttachValue<T>` when given a `SignalFunction`.
344
- */
345
- export type ReactiveParam<T, TParams extends Record<string, unknown>, S extends QueryStoreState<TData, TParams>, TData> = T | (($: SignalFunction, store: StoreApi<S>) => AttachValue<T>);
346
- export type AttachValueParams<TParams extends Record<string, unknown>> = Partial<Record<keyof TParams, AttachValue<TParams[Extract<keyof TParams, string>]>>>;
347
- /**
348
- * The result of resolving reactive and static parameter values.
349
- */
350
- export type ResolvedParamsResult<TParams extends Record<string, unknown>> = {
351
- /**
352
- * Reactive parameter values wrapped in `AttachValue`, which trigger refetches when they change.
353
- */
354
- attachVals: AttachValueParams<TParams>;
355
- /**
356
- * Direct, non-reactive values resolved from the initial configuration.
357
- */
358
- directValues: Partial<TParams>;
359
- /**
360
- * Fully resolved parameters, merging both direct and reactive values.
361
- */
362
- resolvedParams: TParams;
363
- };
364
- /**
365
- * The result of resolving the `enabled` option.
366
- */
367
- export type ResolvedEnabledResult = {
368
- /**
369
- * The reactive enabled state, if provided as a function returning an AttachValue.
370
- */
371
- enabledAttachVal: AttachValue<boolean> | null;
372
- /**
373
- * The static enabled state, if provided as a direct boolean value.
374
- */
375
- enabledDirectValue: boolean | null;
376
- /**
377
- * The final enabled state, derived from either the reactive or static value.
378
- */
379
- resolvedEnabled: boolean;
337
+ [K in keyof TParams]: QueryParam<TParams[K], S>;
380
338
  };
381
339
  /**
382
340
  * The keys that make up the internal state of the store.
@@ -4,10 +4,9 @@
4
4
  * - Coalesces derivations into a single microtask.
5
5
  * - Tasks run once at their maximum rank via a ranked dirty queue.
6
6
  * - Doesn't retain snapshots or dependency graphs.
7
- * - Component listeners get notified after all derivations have settled.
7
+ * - Deferred listeners run after all derivations have settled.
8
8
  */
9
9
  type Rank = number;
10
- type StoreId = string;
11
10
  type Task = () => void;
12
11
  export declare function isCascadeActive(): boolean;
13
12
  /**
@@ -19,12 +18,21 @@ export declare function getCurrentDeriveRank(): Rank | null;
19
18
  */
20
19
  export declare function activateCascade(): void;
21
20
  /**
22
- * Enlist one per-store component flush (idempotent per store).
21
+ * Synchronously drains the active cascade.
23
22
  */
24
- export declare function joinCascade(storeId: StoreId, task: Task): void;
23
+ export declare function flushCascade(): void;
24
+ /**
25
+ * Synchronously settles derivations without delivering deferred listeners.
26
+ */
27
+ export declare function settleCascadeDerivations(): void;
28
+ /**
29
+ * Enlist a deferred listener flush task.
30
+ */
31
+ export declare function joinCascade(task: Task): void;
25
32
  /**
26
33
  * Enqueue (or upgrade) a derive task with the given rank.
27
- * If the task is already present, we keep the maximum rank (run later).
34
+ * If the task is already present, its rank is upgraded and it is run later.
28
35
  */
29
36
  export declare function enqueueDerive(task: Task, rank: Rank): void;
30
37
  export {};
38
+ //# sourceMappingURL=cascadeScheduler.d.ts.map
@@ -10,7 +10,6 @@ export type SubscribableStore = {
10
10
  export type SubscribeOptions<Selected> = {
11
11
  equalityFn?: EqualityFn<Selected>;
12
12
  fireImmediately?: boolean;
13
- isDerivedStore?: boolean;
14
13
  };
15
14
  export type ListenerArgs<S> = [listener: Listener<S>];
16
15
  export type SelectorArgs<S, Selected> = [
@@ -19,10 +18,10 @@ export type SelectorArgs<S, Selected> = [
19
18
  options?: SubscribeOptions<Selected>
20
19
  ];
21
20
  export type SubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | SelectorArgs<S, Selected>;
22
- export type UnsubscribeFn<Options extends boolean = false> = Options extends true ? (skipAbortFetch?: boolean) => void : () => void;
21
+ export type UnsubscribeFn = () => void;
23
22
  export type SubscribeFn<S, Selected = S> = (...args: SubscribeArgs<S, Selected>) => UnsubscribeFn;
24
- export type SubscribeOverloads<S, ExtraOptions extends boolean = false> = {
25
- (listener: Listener<S>): UnsubscribeFn<ExtraOptions>;
26
- <Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn<ExtraOptions>;
23
+ export type SubscribeOverloads<S> = {
24
+ (listener: Listener<S>): UnsubscribeFn;
25
+ <Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn;
27
26
  };
28
27
  //# sourceMappingURL=subscribe.d.ts.map
package/dist/types.d.ts CHANGED
@@ -14,17 +14,19 @@ export type StateCreator<S, U = S> = StoreStateCreator<S, [], [], U>;
14
14
  export type UseBoundStoreWithEqualityFn<Store extends {
15
15
  getState: () => unknown;
16
16
  }, State = InferStoreState<Store>> = UseStoreCallSignatures<State> & Store;
17
- export type BaseStore<S, ExtraSubscribeOptions extends boolean = false> = UseBoundStoreWithEqualityFn<StoreApi<S>> & {
18
- subscribe: SubscribeOverloads<S, ExtraSubscribeOptions>;
17
+ export type BaseStore<S> = UseBoundStoreWithEqualityFn<StoreApi<S>> & {
18
+ subscribe: SubscribeOverloads<S>;
19
19
  };
20
- export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = UseStoreCallSignatures<S> & WithPersist<BaseStore<S, ExtraSubscribeOptions>, PersistedState, PersistReturn>;
21
- export type Store<S, PersistedState extends Partial<S> = never, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = [PersistedState] extends [never] ? BaseStore<S, ExtraSubscribeOptions> : PersistedStore<S, PersistedState, PersistReturn, ExtraSubscribeOptions>;
20
+ export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn extends void | Promise<void> = void | Promise<void>> = UseStoreCallSignatures<S> & WithPersist<BaseStore<S>, PersistedState, PersistReturn>;
21
+ export type Store<S, PersistedState extends Partial<S> = never, PersistReturn extends void | Promise<void> = void | Promise<void>> = [
22
+ PersistedState
23
+ ] extends [never] ? BaseStore<S> : PersistedStore<S, PersistedState, PersistReturn>;
22
24
  /**
23
25
  * Store returned by creators that accept optional persistence options.
24
26
  * `persist` exists only when persistence is configured.
25
27
  */
26
28
  export type OptionallyPersistedStore<S, PersistedState, PersistReturn extends void | Promise<void> = void> = UseStoreCallSignatures<S> & Omit<BaseStore<S>, 'setState'> & {
27
- persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
29
+ persist?: PersistedStore<S, PersistedState, PersistReturn>['persist'];
28
30
  setState(update: SetPartial<S>, replace?: false): PersistReturn;
29
31
  setState(update: SetFull<S>, replace: true): PersistReturn;
30
32
  };
@@ -51,13 +53,13 @@ export type InferSetStateReturn<Store> = Store extends {
51
53
  */
52
54
  export type InferPersistedState<PersistedStore> = PersistedStore extends Store<infer _, infer PersistedState> ? PersistedState : never;
53
55
  /**
54
- * Reads store state and records the dependencies of a derived computation.
56
+ * Reads store state and records dependencies for tracked computations.
55
57
  * - `$(store, selector, equalityFn?)` depends on the selected state
56
58
  * - `$(store)` depends on accessed state paths
57
59
  */
58
60
  export type DeriveGetter = {
59
- <S extends Store<InferStoreState<S>>>(store: S): InferStoreState<S>;
60
- <S extends Store<InferStoreState<S>>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
61
+ <Store extends StoreApi<InferStoreState<Store>>>(store: Store): InferStoreState<Store>;
62
+ <Store extends StoreApi<InferStoreState<Store>>, Selected>(store: Store, selector: Selector<InferStoreState<Store>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
61
63
  };
62
64
  export type DerivedStore<S> = WithFlushUpdates<ReadOnlyDerivedStore<BaseStore<S>>>;
63
65
  export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
@@ -10,6 +10,7 @@
10
10
  *
11
11
  * @template TArgs - The argument types of the function to schedule
12
12
  * @param fn - The function to schedule for microtask execution
13
+ * @param enqueue - The queue that should run the scheduled task
13
14
  * @returns A scheduler function with the same signature as the input function
14
15
  *
15
16
  * @example
@@ -24,5 +25,5 @@
24
25
  * // Logs "Updated: 3" once in the next microtask
25
26
  * ```
26
27
  */
27
- export declare function createMicrotaskScheduler<Args extends unknown[]>(fn: (...args: Args) => void): (...args: Args) => void;
28
+ export declare function createMicrotaskScheduler<Args extends unknown[]>(fn: (...args: Args) => void, enqueue?: (task: () => void) => void): (...args: Args) => void;
28
29
  //# sourceMappingURL=createMicrotaskScheduler.d.ts.map
@@ -11,14 +11,14 @@ export declare function createBaseStore<S>(createState: StateCreator<S>): Store<
11
11
  * @param options - The configuration options for persistence and sync.
12
12
  * @returns A store with the specified state and persistence.
13
13
  */
14
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn, false>;
14
+ export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn>;
15
15
  /**
16
16
  * Creates a base store with async persistence.
17
17
  * @param createState - The state creator function for the base store.
18
18
  * @param options - The configuration options for persistence and sync.
19
19
  * @returns A store with the specified state and persistence.
20
20
  */
21
- export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn, false>;
21
+ export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn>;
22
22
  /**
23
23
  * Creates a base store with optional persistence.
24
24
  * @param createState - The state creator function for the base store.