@storesjs/stores 0.9.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.
- package/README.md +55 -29
- package/dist/createBaseStore.d.ts +8 -8
- package/dist/createDerivedStore.d.ts +9 -17
- package/dist/createQueryStore.d.ts +11 -16
- package/dist/createVirtualStore.d.ts +1 -2
- package/dist/env.native.d.ts +0 -2
- package/dist/env.web.d.ts +0 -1
- package/dist/hooks/useListen.d.ts +2 -2
- package/dist/index.d.ts +1 -16
- package/dist/index.shared.d.ts +14 -0
- package/dist/index.vanilla.d.ts +2 -0
- package/dist/internal/baseStore.d.ts +2 -0
- package/dist/{config.d.ts → internal/config.d.ts} +5 -11
- package/dist/{utils → internal}/createStoreActions.d.ts +4 -5
- package/dist/{derivedStore → internal/derivedStore}/deriveProxy.d.ts +2 -2
- package/dist/{derivedStore → internal/derivedStore}/pathFinder.d.ts +1 -2
- package/dist/internal/derivedStore.d.ts +2 -0
- package/dist/{errors.d.ts → internal/errors.d.ts} +0 -4
- package/dist/{logger.d.ts → internal/logger.d.ts} +0 -2
- package/dist/internal/middleware/createHydrationGate.d.ts +20 -0
- package/dist/internal/queryStore/queryParams.d.ts +18 -0
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/internal/queryStore.d.ts +2 -0
- package/dist/internal/runtime.d.ts +12 -0
- package/dist/internal/storage/storageCreators.d.ts +12 -0
- package/dist/{utils → internal}/storeUtils.d.ts +3 -21
- package/dist/internal/sync/browserSyncEngine.d.ts +3 -0
- package/dist/internal/sync/noopSyncEngine.d.ts +3 -0
- package/dist/internal/sync/syncEnhancer.d.ts +26 -0
- package/dist/{sync → internal/sync}/syncUtils.d.ts +1 -1
- package/dist/internal/types/internalSubscribeTypes.d.ts +16 -0
- package/dist/internal/utils/persistUtils.d.ts +9 -0
- package/dist/internal/virtualStore.d.ts +2 -0
- package/dist/native/index.js +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/queryStore/classes/SubscriptionManager.d.ts +3 -31
- package/dist/queryStore/queryKey.d.ts +10 -0
- package/dist/queryStore/queryParam.d.ts +37 -0
- package/dist/queryStore/types.d.ts +12 -53
- package/dist/store/attachStoreHook.react.d.ts +5 -0
- package/dist/store/attachStoreHook.vanilla.d.ts +6 -0
- package/dist/store/batchStoreNotifications.native.d.ts +3 -0
- package/dist/store/batchStoreNotifications.web.d.ts +2 -0
- package/dist/store/cascadeScheduler.d.ts +38 -0
- package/dist/store/createStore.d.ts +6 -0
- package/dist/store/persist.d.ts +14 -0
- package/dist/store/stateUpdate.d.ts +10 -0
- package/dist/store/types.d.ts +108 -0
- package/dist/types/setState.d.ts +22 -0
- package/dist/types/subscribe.d.ts +27 -0
- package/dist/types/useStoreCallSignatures.d.ts +2 -0
- package/dist/types/useStoreCallSignatures.react.d.ts +6 -0
- package/dist/types/useStoreCallSignatures.vanilla.d.ts +2 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types.d.ts +46 -94
- package/dist/utils/createMicrotaskScheduler.d.ts +2 -1
- package/dist/utils/time.d.ts +0 -7
- package/dist/vanilla/createBaseStore.d.ts +35 -0
- package/dist/vanilla/createDerivedStore.d.ts +62 -0
- package/dist/vanilla/createQueryStore.d.ts +110 -0
- package/dist/vanilla/createVirtualStore.d.ts +39 -0
- package/dist/vanilla/env.web.d.ts +6 -0
- package/dist/vanilla/index.d.ts +1 -0
- package/dist/vanilla/index.js +1 -0
- package/dist/vanilla/index.mjs +1 -0
- package/dist/vanilla/index.shared.d.ts +13 -0
- package/dist/vanilla/index.vanilla.d.ts +1 -0
- package/dist/vanilla/internal/baseStore.d.ts +1 -0
- package/dist/vanilla/internal/config.d.ts +63 -0
- package/dist/vanilla/internal/createStoreActions.d.ts +23 -0
- package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +14 -0
- package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +25 -0
- package/dist/vanilla/internal/derivedStore.d.ts +1 -0
- package/dist/vanilla/internal/errors.d.ts +9 -0
- package/dist/vanilla/internal/logger.d.ts +9 -0
- package/dist/{middleware → vanilla/internal/middleware}/createHydrationGate.d.ts +1 -2
- package/dist/vanilla/internal/queryStore/queryParams.d.ts +17 -0
- package/dist/{queryStore → vanilla/internal/queryStore}/queryStoreDefaults.d.ts +1 -2
- package/dist/vanilla/internal/queryStore.d.ts +1 -0
- package/dist/vanilla/internal/runtime.d.ts +11 -0
- package/dist/vanilla/internal/storage/storageCreators.d.ts +11 -0
- package/dist/vanilla/internal/storeUtils.d.ts +45 -0
- package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +2 -0
- package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +2 -0
- package/dist/{sync → vanilla/internal/sync}/syncEnhancer.d.ts +2 -3
- package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +15 -0
- package/dist/{utils → vanilla/internal/utils}/persistUtils.d.ts +1 -2
- package/dist/vanilla/internal/virtualStore.d.ts +1 -0
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +38 -0
- package/dist/vanilla/queryStore/queryKey.d.ts +9 -0
- package/dist/vanilla/queryStore/queryParam.d.ts +36 -0
- package/dist/vanilla/queryStore/types.d.ts +360 -0
- package/dist/vanilla/storage/storageTypes.d.ts +12 -0
- package/dist/vanilla/store/attachStoreHook.d.ts +5 -0
- package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +5 -0
- package/dist/vanilla/store/batchStoreNotifications.web.d.ts +1 -0
- package/dist/{derivedStore → vanilla/store}/cascadeScheduler.d.ts +12 -6
- package/dist/vanilla/store/createStore.d.ts +5 -0
- package/dist/vanilla/store/persist.d.ts +13 -0
- package/dist/vanilla/store/stateUpdate.d.ts +9 -0
- package/dist/vanilla/store/types.d.ts +107 -0
- package/dist/vanilla/storesStorage.web.d.ts +2 -0
- package/dist/vanilla/sync/types.d.ts +114 -0
- package/dist/vanilla/types/functions.d.ts +23 -0
- package/dist/vanilla/types/objects.d.ts +10 -0
- package/dist/vanilla/types/setState.d.ts +21 -0
- package/dist/vanilla/types/subscribe.d.ts +26 -0
- package/dist/vanilla/types/useStoreCallSignatures.d.ts +1 -0
- package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +1 -0
- package/dist/vanilla/types/utils.d.ts +12 -0
- package/dist/vanilla/types.d.ts +287 -0
- package/dist/vanilla/utils/core.d.ts +25 -0
- package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +34 -0
- package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +28 -0
- package/dist/vanilla/utils/debounce.d.ts +21 -0
- package/dist/vanilla/utils/equality.d.ts +37 -0
- package/dist/vanilla/utils/hydrationCoordinator.d.ts +12 -0
- package/dist/vanilla/utils/promiseUtils.d.ts +1 -0
- package/dist/vanilla/utils/serialization.d.ts +13 -0
- package/dist/vanilla/utils/stringUtils.d.ts +6 -0
- package/dist/vanilla/utils/time.d.ts +36 -0
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/chunk-FENSEQ3V.mjs +1 -0
- package/dist/web/chunk-FPYZVFBM.mjs +1 -0
- package/dist/web/chunk-PLDNKWGX.mjs +1 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/dist/web/internal/runtime.js +1 -0
- package/dist/web/internal/runtime.mjs +1 -0
- package/package.json +13 -11
- package/dist/createStoreWithEqualityFn.d.ts +0 -5
- package/dist/hooks/compareHooks.d.ts +0 -50
- package/dist/queryStore/signalTypes.d.ts +0 -13
- package/dist/signal.d.ts +0 -11
- package/dist/storage/storageCreators.d.ts +0 -22
- package/dist/sync/browserSyncEngine.d.ts +0 -3
- package/dist/sync/noopSyncEngine.d.ts +0 -3
- package/dist/web/chunk-3U5A7HQV.mjs +0 -1
package/dist/native/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Platform as e,unstable_batchedUpdates as t}from"react-native";import{subscribeWithSelector as n,persist as r}from"zustand/middleware";import{createStore as o}from"zustand/vanilla";import{useLayoutEffect as i,useRef as s,useSyncExternalStore as c,useDebugValue as a}from"react";var u=(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')}),l="ios"===e.OS;e.OS;var f="development"===process.env.NODE_ENV,d="test"===process.env.NODE_ENV;function y(e){let t;function n(){if(t)return t;try{const n=function(e){const{createMMKV:t,MMKV:n}=u("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 p={debug:(e,t)=>{f&&console.debug(e,t)},error:(e,t)=>{f&&!d&&console.error(e,t)},info:(e,t)=>{f&&console.info(e,t)},warn:(e,t)=>{f&&console.warn(e,t)}},h=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 g(e){return e instanceof Error?e:new Error(String(e))}var b=Object.prototype.hasOwnProperty;function m(e,t){return b.call(e,t)}function S(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function v(e){return e}function w(){return{__proto__:null}}function O(){}Object.freeze(Object.create(null));var q,j,F,_=class{destroy(){}publish(){}},A=class{constructor(){this.sessionId="noop"}register(e){return new _}},C=!1;function k(e){var t;f&&function(){if(C)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,p=t),j??(j=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),F??(F=E(e))}function I(){return F??(F=E(void 0))}function T(){C=!0}function E(e){return{storage:e?.storage??y(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(q||(q=new A),q)}}var M=Symbol("empty selection"),z=Object.is;function D(e,t,n,r,o=z){const i=s(null);let u=e,l=t,f=n;if(r){let s=i.current;null===s&&(s=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:M,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return $(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>P(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:M,latestSource:M,selector:r,selectedSource:e,selectedSubscribe:()=>O,source:e,value:M,valueEqualityFn:o,valueSelector:r,valueSnapshot:M};return i.selectedSubscribe=K(i,e),i}(e,t,n,r,o),i.current=s),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=M),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=K(e,t))}(s,e,t,n,r,o),u=s.selectedSubscribe,l=s.getSelectedSnapshot,f=void 0===n?void 0:s.getSelectedServerSnapshot}const d=c(u,l,f);return a(d),d}function K(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===M?P(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===M||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===z?z(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===M)return;const a=e.selector(r),u=e.equalityFn(c,a);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=R(e,r,u?c:a),u||n()}))}function P(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==M)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return $(e,t)}function $(e,t){const n=e.value;if(n!==M&&z(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==M&&(e.equalityFn===z?z(n,r):e.equalityFn(n,r)))return R(e,t,n);const o=e.committedValue;return o!==M&&o!==n&&e.committedSource===e.source&&(e.equalityFn===z?z(o,r):e.equalityFn(o,r))?R(e,t,o):R(e,t,r)}function R(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function x(e,t){return(e,t)=>function(e,t){const n=o(e);return Object.assign(function(e,r){return D(n.subscribe,n.getState,n.getInitialState,e,r??t)},n)}(e,t)}function L(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var N=Math.max,V=Math.min;function W(e,t=0,n={}){let r,o,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=H();if(p(e))return g(e);c=setTimeout(h,function(e){const n=t-(e-(a??0));return f&&void 0!==i?V(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=H(),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=U(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?N(U(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(H())},b}function H(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function U(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 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}function Q(e){if(!S(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 G={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},X=d?0:G.seconds(l?3:5);function Y(e){return t=>{if("string"!=typeof t)throw new h("[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 p.error(new h("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Z(e){return t=>function(e,t){try{return JSON.stringify(e,t?J:void 0)}catch(e){throw p.error(new h("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var ee=Object.freeze({shouldClear:!1});function te(e,t,n){if(!t||!e)return ee;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 ne(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function re(e){return!!e&&!!e.getIsApplyingRemote()}var oe=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function ie(e,...t){if(!0===t[1])return pe(t[0])?t[0](e):t[0];const n=pe(t[0])?t[0](e):t[0];return function(e){return Array.isArray(e)}(e)?n:{...e,...n}}function se(e,t){le(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function ce(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&se(n,t)}function ae(e){return de(e)?e.persist.getOptions().name??e.name:e.name}function ue(e){return"getSnapshot"in e}function le(e){return oe.QueryStore in e}function fe(e){return"flushUpdates"in e}function de(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function ye(e){return oe.VirtualStore in e}function pe(e){return"function"==typeof e}var[he,ge]=[0,1];function be(e,t,n){if(!e)return!0;const r=e[he],o=e[ge];return!(t<r)&&(t>r||n>o)}function me(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Se(e,t){if(!f)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 ve(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function we(e,t){T();const o=void 0!==t&&"string"==typeof t.storageKey,i=o?t.storageKey:void 0,s=t?.sync?function(e,t){if(!e)return null;if(!0===e){if(!t)throw new h("[createBaseStore]: sync: true requires a storageKey to inherit the key from");return{key:t}}if("string"==typeof e)return{key:e};const n=e,r=n.key??t;if(!r)throw new h("[createBaseStore]: sync requires either a key in the config or a storageKey to inherit from");return{...n,key:r}}(t.sync,i):void 0,c=o?t.storage??I().storage:void 0,a=s?function(e,t,n){const r=t.engine??I().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,g=0,b=null,m=[],S=Promise.resolve(),v=!n;function w(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 O(e,t){if(d||!b)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>g?e:g+1;return g=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=ie(r,e,t);for(const e of m)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&w(n,o),i},u=t?i(c,!0):i(c);function p(){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(h=u)&&"object"==typeof h&&"then"in h&&"function"==typeof h.then?u.finally(p):(p(),u);var h}const q=c.setState;c.setState=O;const j=e(O,s,c);if(m=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}(j),!m.length)return j;async function F(e){g=Math.max(g,e.timestamp);const n={__proto__:null},r=s(),i=e.timestamp;let c;if(e.replace)for(const t of m)me(t,e.values)||be(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of m){if(!me(o,e.values))continue;if(!b?.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(!Se(u,l))return void p.error(new h(`[sync] Merge function for field "${String(o)}" returned ${ve(u)} but expected ${ve(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??q)(e,!0)}else await(o.setWithoutPersist??q)(n)}finally{d=!1,o&&o.setIsApplyingRemote(!1)}}}function _(e){n?S=S.then(()=>F(e)):F(e)}if(b=new Set(m),f=r.register({apply:e=>{v?_(e):u.push(e)},fields:m,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]);w(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function C(){v=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)_(t)}()}return n?(o.onHydrationComplete=A,o.onHydrationFlushEnd=C):f.onHydrated?(f.onHydrated(A),C()):(A(),C()),j},syncContext:o}}(e,s,c?.async??!1):void 0,u=a?.stateCreator??e;if(!o)return x()(n(u),Object.is);const l=c?.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=L()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)e[1]?s.setState(e[0],e[1]):s.setState(e[0]);c=void 0}},e((...e)=>o?!0===e[1]?n(e[0],e[1]):n(e[0]):(t||(t=L()),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(g(i)):t?.complete(),s?.(e,i)}}}}(u):null,f=function(e,t,n){const r=t??e.storage??I().storage,o=(e.sync?void 0:e.persistThrottleMs??X)||void 0,i=e.version??0,s=r.async?function(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??Q,c=t.deserializer??e.deserializer??Y(o),a=t.serializer??e.serializer??Z(o);async function u(t,n){try{if(re(r))return;n.state,n.state=s(n.state);const o=te(r,i,n),c=a(n);try{await e.set(t,c),ne(r,o)}catch(e){p.error(new h("[createBaseStore]: Failed to persist store data",e))}}catch(e){p.error(new h("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?W(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)=>{if(!r?.getIsApplyingRemote())return await l(e,t)},removeItem:async t=>{try{await e.delete(t)}catch(e){p.error(new h("[createBaseStore]: Failed to delete persisted store data",e))}}}}(r,e,o,n):function(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??Q,c=t.deserializer??e.deserializer??Y(o),a=t.serializer??e.serializer??Z(o);function u(t,n){try{if(re(r))return;n.state,n.state=s(n.state);const o=te(r,i,n),c=a(n);try{e.set(t,c),ne(r,o)}catch(e){p.error(new h("[createBaseStore]: Failed to persist store data",e))}}catch(e){p.error(new h("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?W(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)=>{r?.getIsApplyingRemote()||l(e,t)},removeItem:t=>{try{e.delete(t)}catch(e){p.error(new h("[createBaseStore]: Failed to delete persisted store data",e))}}}}(r,e,o,n);return{persistStorage:s,version:i}}(t,c,a?.syncContext),d=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,a?.syncContext):t.onRehydrateStorage,y=l?(e,t,n)=>(a&&(a.syncContext.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):u,b=x()(n(r(y,function(e,t,n){const r={name:e.storageKey,onRehydrateStorage:n,storage:t.persistStorage,version:t.version};return void 0!==e.merge&&(r.merge=e.merge),void 0!==e.migrate&&(r.migrate=e.migrate),r}(t,f,d))),Object.is);return l?Object.assign(b,{persist:Object.assign(b.persist,{hydrationPromise:l.hydrationPromise})}):b}var Oe=!1,qe=!1,je=new Map,Fe=new Map,_e=new Map,Ae=null,Ce=1/0;function ke(){return Oe}function Ie(){return Ae}function Te(){Oe||(Oe=!0,qe||(qe=!0,queueMicrotask(()=>{qe=!1,t(()=>{for(;Fe.size>0;){const e=Ce,t=_e.get(e);if(t){_e.delete(e);for(const e of t)Fe.delete(e);Ae=e;for(const e of t)e();if(Ae=null,_e.size>0){Ce=1/0;for(const e of _e.keys())e<Ce&&(Ce=e)}else Ce=1/0}else{Ce=1/0;for(const e of _e.keys())e<Ce&&(Ce=e)}}for(;je.size>0;){const e=Array.from(je.values());je.clear();for(const t of e)t()}}),Oe=!1,Ae=null,Fe.clear(),_e.clear(),Ce=1/0})))}function Ee(e,t){Oe&&je.set(e,t)}var Me=Symbol("stores.deriveProxy.unwrap");function ze(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?De(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(ue(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function De(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===Me)return r(n,t,!0),s;if(o.has(s))return Reflect.get(s,c,a);if("__proto__"===c||"symbol"==typeof c)return c===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,c,a);const u=Reflect.get(s,c,s),l=String(c),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(s,c)?function(...e){return r(n,f,!0,{method:l,args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,De(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 Ke(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Me);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=$e(e,t);if(n)for(let t=0;t<e.length;t++)Pe(e,String(t),n)}(e,t):S(e)&&function(e,t){const n=$e(e,t);if(n)for(const t of Reflect.ownKeys(e))Pe(e,t,n)}(e,t),e)}function Pe(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Ke(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function $e(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function Re(e,t,n="s"){return 1===t?e:`${e}${n}`}var xe=Object.freeze([]);function Le(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)Ve(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?He(n.path,n.invocation):We(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[📡 ${t} ${Re("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}_${Re("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)),Ne(i,n,0,r,o)}}}function Ne(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&(e.invocation=o));e.children||(e.children={__proto__:null});const i=t[n];let s=e.children?.[i];s||(s={__proto__:null},e.children[i]=s),Ne(s,t,n+1,r,o)}function Ve(e,t,n,r,o,i=2){const s=e.children;if(!s)return void o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1});for(const e of c){const c=s[e];c.invocation&&Ve(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)Ve(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void Ve(s[e],t,[...n,e],r+1,o,i)}o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}else o.add({store:t,path:n,invocation:e.invocation,isLeaf:e.isLeaf??!1})}function We(e){return t=>Ue(t,e)}function He(e,t){const n=e.slice(0,-1);return e=>{const r=Ue(e,n),o=r&&"object"==typeof r?Reflect.get(r,t.method):void 0;return"function"==typeof o?Reflect.apply(o,r,t.args??xe):void 0}}function Ue(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}function Je(e,t=Object.is){return n=function(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:(f&&u.debugMode)??!1,equalityFn:u.equalityFn??Object.is,keepAlive:u.keepAlive??!1,lockDependencies:u.lockDependencies??!1},c=String(Ge+=1),a=new Set;var u;i&&a.add(Xe);const l=new Set;let d,y,p=Be,h=!1,g=!0,b=!0,m=0,S=!1,w=null,O=Be;function q(e,t,n){return b&&a.size?t?(l.add(e.subscribe(t,z,n?{equalityFn:n,isDerivedStore:!0}:Qe)),t(ue(e)?e.getSnapshot():e.getState())):(d||(d=new WeakMap),y||(y=Le()),ze(e,d,y.trackPath)):(t??v)(ue(e)?e.getSnapshot():e.getState())}function j(e){for(const t of l)t(e);l.clear()}let F=!0;function _(){if(!g&&Ye(p))return p;g=!1,b&&j(!0);const t=p,n=Ye(t);p=function(t){F=!0;const n=p,i=e(t),s=y?Ke(i):i;return Ye(n)&&o(n,s)?(r&&console.log("[🥷 Derive Complete 🥷]: No change detected"),F=!1,n):s}(q);const i=r&&(!n||"verbose"===r&&b);if(i){n?"verbose"===r&&console.log("[🌀 Rebuilding Subscriptions 🌀]: Created…"):console.log("[🌀 Initial Derive Complete 🌀]: Created…");const e=l.size;console.log(`[🎯 ${e} ${Re("Selector Subscription",e)} 🎯]`)}return y&&b&&(y.buildProxySubscriptions((e,t)=>{l.add(e.subscribe(t,z,Qe))},i),d=void 0,y.reset(),s&&(y=void 0)),F&&n&&function(e,t){const n=function(){const e=a.has(Xe)?a.size-1:a.size;return m>0&&m<e}(),o=!m||n,i=n||null!==Ie()||ke()&&o;n&&Te(),r&&console.log(`[📻 Derive Complete 📻]: Notifying ${a.size} ${Re("watcher",a.size)}`);for(const t of a){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}i?S||(S=!0,Ye(O)||(O=t),Ee(c,C)):A(e,t)}(p,t),s&&(b=!1),p}function A(e,t){for(const n of a)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function C(){if(!a.size)return;if(g&&!m&&_(),!Ye(p))return;const e=Ye(O)?O:p;A(p,e),S=!1,O=Be}const k=n?W(T,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,I=k??(()=>{h||(h=!0,queueMicrotask(T))});function T(){h=!1,a.size?g&&_():K()}function E(e){e||k&&g?queueMicrotask(()=>{a.size||K()}):K()}function M(){T(),w=null}function z(){if(!g){if(g=!0,!k){if(m){Te();const e=Ie(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Oe)return;const n=t<0?0:0|t,r=Fe.get(e);if(void 0===r){Fe.set(e,n);let t=_e.get(n);return t||(t=new Set,_e.set(n,t)),t.add(e),void(n<Ce&&(Ce=n))}if(n>r){const t=_e.get(r);if(t&&(t.delete(e),0===t.size&&(_e.delete(r),r===Ce))){Ce=1/0;for(const e of _e.keys())e<Ce&&(Ce=e)}Fe.set(e,n);let o=_e.get(n);o||(o=new Set,_e.set(n,o)),o.add(e),n<Ce&&(Ce=n)}}(M,t)}if(ke())return void(S||(S=!0,Ye(p)&&(O=p),Ee(c,C)))}w=null,I()}}function D(){return g||!Ye(p)?a.size>0?_():e(q):p}function K(e=!0){i&&e||(k?.cancel(),j(),a.clear(),m=0,y=void 0,d=void 0,b=!0,h=!1,g=!0,p=Be,S=!1,O=Be,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){a.size&&(k?k.flush():g&&_())},getSnapshot:function(){if(!Ye(p)){a.add(Xe);const e=_();return a.delete(Xe),e}return h&&T(),p},getState:D,subscribe:function(...e){if(1===e.length){const t=e[0];return a.add(t),1!==a.size||Ye(p)||D(),()=>{a.delete(t),a.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 a.add(s),s.currentSlice=t(D()),i&&(m+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{a.delete(s),i&&(m-=1),a.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.")}}}(e,t),Object.assign(function(e=v,t){return D(n.subscribe,n.getSnapshot,void 0,e,t)},n);var n}var Be=Symbol(),Qe=Object.freeze({equalityFn:Object.is,isDerivedStore:!0}),Ge=0;function Xe(){}function Ye(e){return e!==Be}var Ze,et=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=G.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function tt(e,t){const n=t?.baseDelay??G.seconds(5),r=t?.maxDelay??G.minutes(5);return Math.min(n*Math.pow(2,e),r)}var nt={Error:"error",Idle:"idle",Loading:"loading",Success:"success"};function rt(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)||!rt(e[r],t[r]))return!1;return!0}function ot(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 it(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(it(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--&&it(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(!it(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)||!it(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}var st=new WeakMap,ct=new WeakMap;function at(e,t=ut,n=it){return function(e,t,n){let r=ct.get(e);r||(r=new Map,ct.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]=ft(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 st.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(()=>{}),st.set(f,s),o.set(n,f),f}(e,t,n)}var ut=e=>e,lt=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,i=e[r],s=lt(i,o,n);if(it(i,s))return e;const c=Array.isArray(e)?e.slice():{...e};return c[r]=s,c},ft=(e,t,n)=>{const r=new Set,o=ue(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!==ut)throw new Error("Cannot set a value with a selector");e.setState(e=>lt(e,n,r),!0)}]};function dt(e){return st.get(e)}var yt={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},pt=Object.freeze({force:!0}),ht=Object.freeze({once:!0}),gt=Object.freeze({updateQueryKey:!0});function bt(e,t,n){T();const r="function"==typeof t?t:Ct,o="object"==typeof t?t:n,i=o&&"storageKey"in o?o:void 0,s=Ze??(Ze=function(){const e={abortInterruptedFetches:!0,cacheTime:G.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:tt,staleTime:G.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(j)return j}()?.queryStoreDefaults;return t?{...e,...t}:e}()),c=s.minStaleTime,{fetcher:a,onError:u,onFetched:l,setData:y,transform:b,abortInterruptedFetches:S=s.abortInterruptedFetches,cacheTime:v=s.cacheTime,debugMode:w=s.debugMode,disableAutoRefetching:O=s.disableAutoRefetching,disableCache:q=!1,enabled:F=!0,keepPreviousData:_=s.keepPreviousData,maxRetries:A=s.maxRetries,paramChangeThrottle:C=s.paramChangeThrottle,params:k,retryDelay:I=s.retryDelay,staleTime:E=s.staleTime,suppressStaleTimeWarning:M=s.suppressStaleTimeWarning}=e;let z="function"==typeof E?s.staleTime:E;f&&!1!==c&&!O&&!M&&z<c&&console.warn(`[createQueryStore${i?.storageKey?`: ${i.storageKey}`:""}] ❌ Stale times under ${c/1e3} seconds are not recommended. Provided staleTime: ${z/1e3} seconds`);const D=new Error("[createQueryStore: AbortError] Fetch interrupted"),K="function"==typeof v,P=f&&w,$=e.params?Object.keys(e.params):[];let R=null,x=null,L=null,N=[],V=!1,H=!1,U=null,J=null,B=null,Q=null,X=null;const Y={enabled:"function"!=typeof F&&F,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:nt.Idle},Z=new et({disableAutoRefetching:O,initialEnabled:Y.enabled});function ee(){U&&(J=null,U.abort(),U=null)}function te(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&&X!==t&&(X=t,Z.setEnabled(t),t?queueMicrotask(()=>d.fetch(void 0,gt)):(B||S)&&(S&&ee(),B&&(clearTimeout(B),B=null)))}(r.enabled,i)),o});return n?.(),r}return s(e)}function f(e,t){if(O||t?.skipStoreUpdates)return;if(z<=0||z===1/0)return;B&&(clearTimeout(B),B=null);const r=mt(e),o=n(),i=(q?Q===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?z-(Date.now()-i):z;B=setTimeout(()=>{const t=Z.get();t.enabled&&t.subscriptionCount>0&&d.fetch(e,pt,!0)},s)}o.setState=c,Z.init({onSubscribe:(r,o,i)=>{if(x||R||!k&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=Ot(R,x),r=mt(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?d.fetch(e,void 0,!0):f(e,void 0)}else O&&!i&&d.fetch(void 0,void 0,!0)}else V=!0},onLastUnsubscribe:e=>{B&&(clearTimeout(B),B=null),S&&!e&&ee()}});const d={...r(c,n,o),...Y,async fetch(e,r,o=!1){const s=Z.get();if(!r?.force&&!r?.skipStoreUpdates&&!s.enabled)return null;const m=n(),w=m.error,O=m.queryKey,j=m.status===nt.Loading,F=wt(R,x,$,e),C=mt(F);if(j&&J?.promise&&J.key===C)return P&&console.log("[🔄 Using Active Fetch 🔄] for params:",JSON.stringify(F)),J.promise;const k=r?.staleTime??z,T=!!r?.skipStoreUpdates,E="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&_,M=(o||O===C||E)&&!T;if(S&&M&&ee(),!r?.force){const e=m.lastFetchedAt,n=m.queryCache[C],o=n?.lastFetchedAt,i=n?.errorInfo,c=i&&i.retryCount>=A,a=(q?Q===C&&e:o)||null;if(a&&!(Date.now()-a>=k)&&(!i||c||T))return M&&!B&&s.subscriptionCount>0&&0!==z&&z!==1/0&&f(F,r),E&&t(e=>e.queryKey!==C?{queryKey:C}:e),P&&console.log("[💾 Returning Cached Data 💾] for params:",JSON.stringify(F)),n?.data??null}M&&(B&&(clearTimeout(B),B=null),!w&&j||t({error:null,status:nt.Loading}),J={key:C});const L=r?.cacheTime??(K?v(F):v);async function N(){const s=i?.storageKey||C;try{P&&(o||!e||qt(e,$)?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(S&&M?async function(e){const t=new AbortController;U=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(D),ht),Promise.resolve(a(e,t)).then(n,r)})}finally{U===t&&(U=null)}}(F):a(F,null)),i=Date.now();let u;P&&console.log("[✅ Fetch Successful ✅] for params:",JSON.stringify(F));try{u=function(e,t,n){return n?n(e,t):e}(n,F,b)}catch(e){throw kt(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 q?e:{queryCache:{...e.queryCache,[C]:{cacheTime:L,data:u,errorInfo:null,lastFetchedAt:i}}};let t=e;const n=t.queryCache[C];try{y({data:u,params:F,queryKey:C,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw kt(s,"setData",e)}return!q&&Object.is(n,t.queryCache[C])&&(t={...t,queryCache:{...t.queryCache,[C]:{cacheTime:L,data:null,errorInfo:null,lastFetchedAt:i}}}),t}),u;if((y?c:t)(e=>{let t={...e,error:null,lastFetchedAt:i,queryKey:E?C:e.queryKey,status:nt.Success};if(y||q){if(y){P&&console.log("[💾 Setting Data 💾] for params:",JSON.stringify(F));const e=t.queryCache[C];try{y({data:u,params:F,queryKey:C,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw kt(s,"setData",e)}!q&&Object.is(e,t.queryCache[C])&&(t.queryCache={...t.queryCache,[C]:{cacheTime:L,data:null,errorInfo:null,lastFetchedAt:i}})}}else P&&console.log("[💾 Setting Cache 💾] for params:",JSON.stringify(F),"| Has previous data?:",!!t.queryCache[C]?.data),t.queryCache={...t.queryCache,[C]:{cacheTime:L,data:u,errorInfo:null,lastFetchedAt:i}};return q||v===1/0?t:At(_,C,t)}),M&&(Q=C,f(F,r)),l)try{l({data:u,fetch:d.fetch,params:F,set:c})}catch(e){p.error(kt(s,"onFetched callback",e))}return u??null}catch(i){if(i===D)return P&&console.log("[❌ Fetch Aborted ❌] for params:",JSON.stringify(F)),null;const c=!o&&!0===r?.throwOnError,a=g(i);if(a instanceof h&&p.error(a),!M){if(c)throw a;return null}const l=q?void 0:n().queryCache[C],f=l?.errorInfo?.retryCount??0,y=f+1;try{u?.(a,f)}catch(e){p.error(kt(s,"onError callback",e))}if(f<A){if(Z.get().subscriptionCount>0){const t="function"==typeof I?I(y,a):I;t!==1/0&&(B&&clearTimeout(B),B=setTimeout(()=>{const t=Z.get();t.enabled&&t.subscriptionCount>0&&d.fetch(e,pt,!0)},t))}t(e=>({error:a,queryCache:{...e.queryCache,[C]:{cacheTime:l?.cacheTime??L,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:y}}},queryKey:E?C:e.queryKey,status:nt.Error}))}else t(e=>({error:a,queryCache:{...e.queryCache,[C]:{cacheTime:l?.cacheTime??L,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:A}}},queryKey:E?C:e.queryKey,status:nt.Error}));if(c)throw a;return null}finally{M&&(J=null)}}return M?(J={key:C,promise:N()}).promise:N()},getCacheEntry(e){if(q)return null;const t=n(),r=e?"string"==typeof e?e:mt(wt(R,x,$,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(q)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?_?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===nt.Idle;case"isLoading":return r===nt.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],i=q?r===nt.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((q?Q===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===nt.Idle,isLoading:r===nt.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(q?Q===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=(q?Q===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??z;return Date.now()-o>=i},reset(e=!1){for(const e of N)e();N=[],R=null,x=null,L=null,ee(),B&&(clearTimeout(B),B=null),J=null,Q=null,e&&t(Y)}},m=o.subscribe;return o.subscribe=(...e)=>{const t=H?()=>{}:Z.subscribe(),n=1===e.length?m(e[0]):m(e[0],e[1],e[2]);return e=>{t(e),n()}},d}const ne=i?.storageKey?we(te,(re=i,void 0===(ie={partialize:_t(_,i.partialize)})?Object.assign({__proto__:null},re):Object.assign({__proto__:null},re,ie))):o&&!("storageKey"in o)?we(te,o):we(te);var re,ie;const se=ne.getState(),ce=se.error,ae=se.enabled,ue=se.queryKey,le=se.fetch;let fe;if(ue&&!ce&&(Q=ue),H=!0,k||"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(!m(t,e))continue;const s=t[e];if(jt(s)){const t=s(at,n);r[e]=t,i[e]=t.value}else Ft(s)&&(o[e]=s,i[e]=s)}let s,c=null,a=null;if(jt(e)){const t=e(at,n);s=t.value,c=t}else s=e,a=e;return{attachVals:r,directValues:o,enabledAttachVal:c,enabledDirectValue:a,resolvedEnabled:s,resolvedParams:i}}(F,k,ne);R={enabled:t,params:r},x={enabled:n,params:e}}"function"==typeof e.staleTime&&(L=e.staleTime(at,ne),z=L.value);const de=Object.freeze({updateQueryKey:_}),ye=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{le(e??Ot(R,x),de)})(...e)}))}}();function pe(){let e;if(!_){e=Ot(R,x);const t=mt(e);ne.setState({queryKey:t})}ye(e)}const he=d||!C?pe:W(pe,"number"==typeof C?C:C.delay,"number"==typeof C?{leading:!1,maxWait:C,trailing:!0}:C);for(const e in R?.params){const t=R.params[e];if(!t)continue;const n=dt(t);if(P&&console.log("[🌀 Param Subscription 🌀] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;it(r,n)||(P&&console.log("[🌀 Param Change 🌀] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,he())});N.push(o)}}if(L){const e=dt(L);if(e){const t=L;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,z=e,le())});N.push(r)}}if(R?.enabled){const e=R.enabled,t=dt(e);if(t){let n=e.value;ae!==n&&((fe??(fe={})).enabled=n),n&&Z.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,ne.setState({enabled:t}))});N.push(r)}}else ae!==Y.enabled&&((fe??(fe={})).enabled=Y.enabled);const ge=mt(Ot(R,x));return ge!==ue&&((fe??(fe={})).queryKey=ge),fe&&ne.setState(fe),H=!1,V&&queueMicrotask(he),be=ne,me=oe.QueryStore,Object.assign(be,{[me]:!0});var be,me}function mt(e){return JSON.stringify(vt(e))}function St(e){return JSON.parse(e)}function vt(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=S(r)?vt(r):r,t},{__proto__:null})}function wt(e,t,n,r){return r?qt(r,n)?r:{...Ot(e,t),...r}:Ot(e,t)}function Ot(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 qt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function jt(e){return"function"==typeof e}function Ft(e){return!jt(e)}function _t(e,t){return n=>{const r={...n},o={__proto__:null};for(const e in r)m(r,e)&&e in yt&&(yt[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):Q(r),...At(e,null,o)}}}function At(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(!m(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 Ct(){return Object.create(null)}function kt(e,t,n){return new h(`[createQueryStore: ${e}]: ${t} failed`,n)}function It(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,c=Je(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),se(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0});return Object.assign(function(e,t){const n=c();return e?n(e,t):n()},{[oe.VirtualStore]:!0,destroy:c.destroy,getInitialState:()=>c.getState().getInitialState(),getState:()=>c.getState().getState(),persist:(a=c.getState,{clearStorage:()=>a().persist?.clearStorage(),getOptions:()=>a().persist?.getOptions()??{},hasHydrated:()=>a().persist?.hasHydrated()??!0,hydrationPromise:()=>a().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>a().persist?.onFinishHydration(e)??O,onHydrate:e=>a().persist?.onHydrate(e)??O,rehydrate:()=>a().persist?.rehydrate(),setOptions:e=>a().persist?.setOptions(e)}),setState:Tt(c.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?c.getState().subscribe(e[0]):c.getState().subscribe(e[0],e[1],e[2])};return s.add(t),()=>{t.unsubscribe(),s.delete(t)}}},o?.(c.getState));var a}function Tt(e){return function(t,n){return n?e().setState(t,n):e().setState(t)}}var Et=Symbol(),Mt=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function zt(e,t,n,r=Mt){const o=function(){const e=s(Et);return e.current===Et&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:Pt(n),resubscribe:()=>{},unsubscribe:()=>{}}}(t,n,r)),e}(),c=function(e){return"function"==typeof e?Mt.enabled:e?.enabled??Mt.enabled}(r);return o.current.react=n,o.current.selector=t,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Mt)}(o,r),i(()=>{if(c)return Kt(e,o),()=>function(e){e.current.options.debugMode&&console.log("[🗑️ useListen 🗑️] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(o)},[c,e]),o}var Dt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Kt(e,t,n=Dt){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=Dt)=>Kt(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function Pt(e){return"function"==typeof e?{equalityFn:e}:e??Mt}var $t=Symbol();function Rt(e){const t=s($t);return t.current===$t&&(t.current=e()),t.current}function xt(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(f&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(ye(e))for(const n in t)Nt(t,n)&&(r[n]=Lt(e,n));else for(const e in t)Nt(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function Lt(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 Nt(e,t){return"function"==typeof e[t]}export{nt as QueryStatuses,h as StoresError,ie as applyStateUpdate,k as configureStores,we as createBaseStore,Je as createDerivedStore,bt as createQueryStore,xt as createStoreActions,It as createVirtualStore,rt as deepEqual,tt as defaultRetryDelay,se as destroyStore,ce as destroyStores,mt as getQueryKey,ae as getStoreName,ue as hasGetSnapshot,v as identity,fe as isDerivedStore,de as isPersistedStore,le as isQueryStore,ye as isVirtualStore,w as nullObject,St as parseQueryKey,J as replacer,B as reviver,ot as shallowEqual,G as time,zt as useListen,Rt 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: (
|
|
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(
|
|
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
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { QueryParam, ReactiveParam } from './queryParam';
|
|
2
|
+
import type { DebounceOptions, SetPartial, Store } from '../types';
|
|
3
|
+
export type { QueryParam, QueryParamConfig, QueryParamKey, ReactiveParam } from './queryParam';
|
|
3
4
|
/**
|
|
4
5
|
* Helper type that represents the store returned by `createQueryStore()`.
|
|
5
6
|
*/
|
|
@@ -91,7 +92,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
|
|
|
91
92
|
* When `false`, the store will not automatically fetch data until explicitly enabled.
|
|
92
93
|
* @default true
|
|
93
94
|
*/
|
|
94
|
-
enabled?: boolean | ReactiveParam<boolean,
|
|
95
|
+
enabled?: boolean | ReactiveParam<boolean, S>;
|
|
95
96
|
/**
|
|
96
97
|
* When `true`, the store's `getData` method will always return existing data from the cache if it exists,
|
|
97
98
|
* regardless of whether the cached data is expired, until the data is pruned following a successful refetch.
|
|
@@ -115,8 +116,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
|
|
|
115
116
|
*/
|
|
116
117
|
paramChangeThrottle?: false | number | DebounceOptions;
|
|
117
118
|
/**
|
|
118
|
-
*
|
|
119
|
-
* 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.
|
|
120
120
|
*/
|
|
121
121
|
params?: QueryStoreParams<TParams, TData, S, CustomState>;
|
|
122
122
|
/**
|
|
@@ -134,7 +134,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
|
|
|
134
134
|
* After becoming stale, the store may automatically refetch data in the background if there are active subscribers.
|
|
135
135
|
* @default time.minutes(2)
|
|
136
136
|
*/
|
|
137
|
-
staleTime?: number | ReactiveParam<number,
|
|
137
|
+
staleTime?: number | ReactiveParam<number, S>;
|
|
138
138
|
/**
|
|
139
139
|
* Suppresses warnings in the event a `staleTime` under the minimum is desired.
|
|
140
140
|
* @default false
|
|
@@ -172,7 +172,7 @@ export type QueryStoreInternalState<TData, TParams extends Record<string, unknow
|
|
|
172
172
|
* Pass a status key to avoid building the full status object.
|
|
173
173
|
* @example
|
|
174
174
|
* ```ts
|
|
175
|
-
* const isInitialLoad =
|
|
175
|
+
* const isInitialLoad = myQueryStore.getState().getStatus('isInitialLoad');
|
|
176
176
|
* ```
|
|
177
177
|
* @returns The requested status, or the full status object if no key is provided.
|
|
178
178
|
*/
|
|
@@ -212,11 +212,11 @@ export type QueryStoreInternalState<TData, TParams extends Record<string, unknow
|
|
|
212
212
|
*/
|
|
213
213
|
lastFetchedAt: number | null;
|
|
214
214
|
/**
|
|
215
|
-
* A cache of fetched data and metadata, keyed by query
|
|
215
|
+
* A cache of fetched data and metadata, keyed by generated query keys.
|
|
216
216
|
*/
|
|
217
217
|
queryCache: Record<string, CacheEntry<TData> | undefined>;
|
|
218
218
|
/**
|
|
219
|
-
* The current query key,
|
|
219
|
+
* The current query key, generated deterministically from store parameters.
|
|
220
220
|
*/
|
|
221
221
|
queryKey: string;
|
|
222
222
|
/**
|
|
@@ -274,7 +274,8 @@ export type FetchOptions = {
|
|
|
274
274
|
* `queryKey` (which determines where `getData()` points to).
|
|
275
275
|
*
|
|
276
276
|
* ---
|
|
277
|
-
*
|
|
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.
|
|
278
279
|
*/
|
|
279
280
|
updateQueryKey?: boolean;
|
|
280
281
|
};
|
|
@@ -333,49 +334,7 @@ export type CacheEntry<T> = {
|
|
|
333
334
|
* Internal helper type for the config’s params clause.
|
|
334
335
|
*/
|
|
335
336
|
export type QueryStoreParams<TParams extends Record<string, unknown>, TData, S extends QueryStoreState<TData, TParams, CustomState>, CustomState = unknown> = [TParams] extends [Record<string, never>] ? undefined : {
|
|
336
|
-
[K in keyof TParams]:
|
|
337
|
-
};
|
|
338
|
-
/**
|
|
339
|
-
* Represents a parameter that can be provided directly or defined via a reactive `AttachValue`.
|
|
340
|
-
* A parameter can be:
|
|
341
|
-
* - A static value (e.g. `string`, `number`).
|
|
342
|
-
* - A function that returns an `AttachValue<T>` when given a `SignalFunction`.
|
|
343
|
-
*/
|
|
344
|
-
export type ReactiveParam<T, TParams extends Record<string, unknown>, S extends QueryStoreState<TData, TParams>, TData> = T | (($: SignalFunction, store: BaseStore<S>) => AttachValue<T>);
|
|
345
|
-
export type AttachValueParams<TParams extends Record<string, unknown>> = Partial<Record<keyof TParams, AttachValue<TParams[Extract<keyof TParams, string>]>>>;
|
|
346
|
-
/**
|
|
347
|
-
* The result of resolving reactive and static parameter values.
|
|
348
|
-
*/
|
|
349
|
-
export type ResolvedParamsResult<TParams extends Record<string, unknown>> = {
|
|
350
|
-
/**
|
|
351
|
-
* Reactive parameter values wrapped in `AttachValue`, which trigger refetches when they change.
|
|
352
|
-
*/
|
|
353
|
-
attachVals: AttachValueParams<TParams>;
|
|
354
|
-
/**
|
|
355
|
-
* Direct, non-reactive values resolved from the initial configuration.
|
|
356
|
-
*/
|
|
357
|
-
directValues: Partial<TParams>;
|
|
358
|
-
/**
|
|
359
|
-
* Fully resolved parameters, merging both direct and reactive values.
|
|
360
|
-
*/
|
|
361
|
-
resolvedParams: TParams;
|
|
362
|
-
};
|
|
363
|
-
/**
|
|
364
|
-
* The result of resolving the `enabled` option.
|
|
365
|
-
*/
|
|
366
|
-
export type ResolvedEnabledResult = {
|
|
367
|
-
/**
|
|
368
|
-
* The reactive enabled state, if provided as a function returning an AttachValue.
|
|
369
|
-
*/
|
|
370
|
-
enabledAttachVal: AttachValue<boolean> | null;
|
|
371
|
-
/**
|
|
372
|
-
* The static enabled state, if provided as a direct boolean value.
|
|
373
|
-
*/
|
|
374
|
-
enabledDirectValue: boolean | null;
|
|
375
|
-
/**
|
|
376
|
-
* The final enabled state, derived from either the reactive or static value.
|
|
377
|
-
*/
|
|
378
|
-
resolvedEnabled: boolean;
|
|
337
|
+
[K in keyof TParams]: QueryParam<TParams[K], S>;
|
|
379
338
|
};
|
|
380
339
|
/**
|
|
381
340
|
* The keys that make up the internal state of the store.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EqualityFn, SubscribeOverloads, UseStoreCallSignatures } from '../types';
|
|
2
|
+
export declare function attachStoreHook<State, Store extends {
|
|
3
|
+
subscribe: SubscribeOverloads<State>;
|
|
4
|
+
}>(store: Store, getSnapshot: () => State, getServerSnapshot?: () => State, defaultEqualityFn?: EqualityFn): UseStoreCallSignatures<State> & Store;
|
|
5
|
+
//# sourceMappingURL=attachStoreHook.react.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EqualityFn, SubscribeOverloads } from '../types';
|
|
2
|
+
import type { UseStoreCallSignatures } from '../types/useStoreCallSignatures.vanilla';
|
|
3
|
+
export declare function attachStoreHook<State, Store extends {
|
|
4
|
+
subscribe: SubscribeOverloads<State>;
|
|
5
|
+
}>(store: Store, _getSnapshot: () => State, _getServerSnapshot?: () => State, _defaultEqualityFn?: EqualityFn): UseStoreCallSignatures<State> & Store;
|
|
6
|
+
//# sourceMappingURL=attachStoreHook.vanilla.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cascade Scheduler
|
|
3
|
+
*
|
|
4
|
+
* - Coalesces derivations into a single microtask.
|
|
5
|
+
* - Tasks run once at their maximum rank via a ranked dirty queue.
|
|
6
|
+
* - Doesn't retain snapshots or dependency graphs.
|
|
7
|
+
* - Deferred listeners run after all derivations have settled.
|
|
8
|
+
*/
|
|
9
|
+
type Rank = number;
|
|
10
|
+
type Task = () => void;
|
|
11
|
+
export declare function isCascadeActive(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Rank of the currently running derive batch, or null if not in a batch.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getCurrentDeriveRank(): Rank | null;
|
|
16
|
+
/**
|
|
17
|
+
* Arms the cascade and schedules a single microtask flush.
|
|
18
|
+
*/
|
|
19
|
+
export declare function activateCascade(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Synchronously drains the active cascade.
|
|
22
|
+
*/
|
|
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;
|
|
32
|
+
/**
|
|
33
|
+
* Enqueue (or upgrade) a derive task with the given rank.
|
|
34
|
+
* If the task is already present, its rank is upgraded and it is run later.
|
|
35
|
+
*/
|
|
36
|
+
export declare function enqueueDerive(task: Task, rank: Rank): void;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=cascadeScheduler.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Mutate, StateCreator, StoreApi, StoreMutators } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the internal core store API.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createStore<State, Mutators extends StoreMutators = []>(createState: StateCreator<State, [], Mutators>): Mutate<StoreApi<State>, Mutators>;
|
|
6
|
+
//# sourceMappingURL=createStore.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PersistOptions, StateCreator, StoreMutators } from './types';
|
|
2
|
+
type PersistMutators<PersistedState, PersistReturn, Mutators extends StoreMutators> = [
|
|
3
|
+
[
|
|
4
|
+
'stores/persist',
|
|
5
|
+
[PersistedState, PersistReturn]
|
|
6
|
+
],
|
|
7
|
+
...Mutators
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Wraps a state creator with persistence.
|
|
11
|
+
*/
|
|
12
|
+
export declare function persist<State, PersistedState extends Partial<State>, PersistReturn extends void | Promise<void> = void, Mutators extends StoreMutators = []>(createState: StateCreator<State, [], Mutators>, initialOptions: PersistOptions<State, PersistedState>): StateCreator<State, [], PersistMutators<PersistedState, PersistReturn, Mutators>>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=persist.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SetStateArgs, SetStateOverloads } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calls a `setState` function with captured `setState` arguments.
|
|
4
|
+
*/
|
|
5
|
+
export declare function applySetState<S, SetReturn extends Promise<void> | void>(set: SetStateOverloads<S, SetReturn>, args: SetStateArgs<S>): SetReturn;
|
|
6
|
+
/**
|
|
7
|
+
* Applies a `setState` payload to the current state.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyStateUpdate<S>(state: S, ...setArgs: SetStateArgs<S>): S;
|
|
10
|
+
//# sourceMappingURL=stateUpdate.d.ts.map
|