@storesjs/stores 0.10.0 β 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1583 -4
- package/dist/native/index.js +7 -1
- package/dist/native/index.mjs +7 -1
- package/dist/plugins/chrome/index.d.ts +186 -4
- package/dist/vanilla/index.js +1 -1
- package/dist/vanilla/index.mjs +1 -1
- package/dist/vanilla/index.vanilla.d.ts +1469 -1
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/dist/web/internal/runtime.js +2 -1
- package/dist/web/internal/runtime.mjs +2 -1
- package/dist/web/queryParam-Ckp7Zi5t.mjs +1 -0
- package/dist/web/queryParam-Ctnhipnd.js +1 -0
- package/dist/web/serialization-BgaGfw_1.mjs +1 -0
- package/dist/web/serialization-Dau9pNHc.js +1 -0
- package/dist/web/utils-Ba1RIeAA.mjs +1 -0
- package/dist/web/utils-CwejruRb.js +1 -0
- package/package.json +7 -7
- package/dist/createBaseStore.d.ts +0 -36
- package/dist/createDerivedStore.d.ts +0 -63
- package/dist/createQueryStore.d.ts +0 -117
- package/dist/createVirtualStore.d.ts +0 -40
- package/dist/env.native.d.ts +0 -7
- package/dist/env.web.d.ts +0 -7
- package/dist/hooks/useLazyRef.d.ts +0 -13
- package/dist/hooks/useListen.d.ts +0 -98
- package/dist/hooks/useStableValue.d.ts +0 -16
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +0 -5
- package/dist/index.shared.d.ts +0 -14
- package/dist/index.vanilla.d.ts +0 -2
- package/dist/internal/baseStore.d.ts +0 -2
- package/dist/internal/config.d.ts +0 -64
- package/dist/internal/createStoreActions.d.ts +0 -24
- package/dist/internal/derivedStore/cascadeScheduler.d.ts +0 -31
- package/dist/internal/derivedStore/deriveProxy.d.ts +0 -15
- package/dist/internal/derivedStore/pathFinder.d.ts +0 -26
- package/dist/internal/derivedStore.d.ts +0 -2
- package/dist/internal/errors.d.ts +0 -10
- package/dist/internal/logger.d.ts +0 -10
- package/dist/internal/middleware/createHydrationGate.d.ts +0 -20
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +0 -8
- package/dist/internal/queryStore.d.ts +0 -2
- package/dist/internal/runtime.d.ts +0 -13
- package/dist/internal/signal.d.ts +0 -12
- package/dist/internal/storage/storageCreators.d.ts +0 -12
- package/dist/internal/storeUtils.d.ts +0 -46
- package/dist/internal/sync/browserSyncEngine.d.ts +0 -3
- package/dist/internal/sync/noopSyncEngine.d.ts +0 -3
- package/dist/internal/sync/syncEnhancer.d.ts +0 -26
- package/dist/internal/sync/syncUtils.d.ts +0 -6
- package/dist/internal/utils/persistUtils.d.ts +0 -9
- package/dist/internal/virtualStore.d.ts +0 -2
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +0 -30
- package/dist/plugins/chrome/chromeStorageAdapter.d.ts +0 -31
- package/dist/plugins/chrome/createSyncedChromeStorage.d.ts +0 -14
- package/dist/queryStore/classes/SubscriptionManager.d.ts +0 -67
- package/dist/queryStore/queryKey.d.ts +0 -3
- package/dist/queryStore/signalTypes.d.ts +0 -14
- package/dist/queryStore/types.d.ts +0 -403
- package/dist/storage/storageTypes.d.ts +0 -13
- package/dist/store/attachStoreHook.react.d.ts +0 -5
- package/dist/store/attachStoreHook.vanilla.d.ts +0 -6
- package/dist/store/batchStoreNotifications.native.d.ts +0 -3
- package/dist/store/batchStoreNotifications.web.d.ts +0 -2
- package/dist/store/createStore.d.ts +0 -6
- package/dist/store/persist.d.ts +0 -14
- package/dist/store/stateUpdate.d.ts +0 -10
- package/dist/store/types.d.ts +0 -108
- package/dist/storesStorage.native.d.ts +0 -3
- package/dist/storesStorage.web.d.ts +0 -3
- package/dist/sync/types.d.ts +0 -115
- package/dist/types/functions.d.ts +0 -24
- package/dist/types/objects.d.ts +0 -11
- package/dist/types/setState.d.ts +0 -22
- package/dist/types/subscribe.d.ts +0 -28
- package/dist/types/useStoreCallSignatures.d.ts +0 -2
- package/dist/types/useStoreCallSignatures.react.d.ts +0 -6
- package/dist/types/useStoreCallSignatures.vanilla.d.ts +0 -2
- package/dist/types/utils.d.ts +0 -13
- package/dist/types.d.ts +0 -286
- package/dist/utils/core.d.ts +0 -26
- package/dist/utils/createAsyncMicrotaskScheduler.d.ts +0 -35
- package/dist/utils/createMicrotaskScheduler.d.ts +0 -28
- package/dist/utils/debounce.d.ts +0 -22
- package/dist/utils/equality.d.ts +0 -38
- package/dist/utils/hydrationCoordinator.d.ts +0 -13
- package/dist/utils/promiseUtils.d.ts +0 -2
- package/dist/utils/serialization.d.ts +0 -14
- package/dist/utils/stringUtils.d.ts +0 -7
- package/dist/utils/time.d.ts +0 -37
- package/dist/vanilla/createBaseStore.d.ts +0 -35
- package/dist/vanilla/createDerivedStore.d.ts +0 -62
- package/dist/vanilla/createQueryStore.d.ts +0 -116
- package/dist/vanilla/createVirtualStore.d.ts +0 -39
- package/dist/vanilla/env.web.d.ts +0 -6
- package/dist/vanilla/index.d.ts +0 -1
- package/dist/vanilla/index.shared.d.ts +0 -13
- package/dist/vanilla/internal/baseStore.d.ts +0 -1
- package/dist/vanilla/internal/config.d.ts +0 -63
- package/dist/vanilla/internal/createStoreActions.d.ts +0 -23
- package/dist/vanilla/internal/derivedStore/cascadeScheduler.d.ts +0 -30
- package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +0 -14
- package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +0 -25
- package/dist/vanilla/internal/derivedStore.d.ts +0 -1
- package/dist/vanilla/internal/errors.d.ts +0 -9
- package/dist/vanilla/internal/logger.d.ts +0 -9
- package/dist/vanilla/internal/middleware/createHydrationGate.d.ts +0 -19
- package/dist/vanilla/internal/queryStore/queryStoreDefaults.d.ts +0 -7
- package/dist/vanilla/internal/queryStore.d.ts +0 -1
- package/dist/vanilla/internal/runtime.d.ts +0 -12
- package/dist/vanilla/internal/signal.d.ts +0 -11
- package/dist/vanilla/internal/storage/storageCreators.d.ts +0 -11
- package/dist/vanilla/internal/storeUtils.d.ts +0 -45
- package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +0 -2
- package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +0 -2
- package/dist/vanilla/internal/sync/syncEnhancer.d.ts +0 -25
- package/dist/vanilla/internal/utils/persistUtils.d.ts +0 -8
- package/dist/vanilla/internal/virtualStore.d.ts +0 -1
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +0 -66
- package/dist/vanilla/queryStore/queryKey.d.ts +0 -2
- package/dist/vanilla/queryStore/signalTypes.d.ts +0 -13
- package/dist/vanilla/queryStore/types.d.ts +0 -402
- package/dist/vanilla/storage/storageTypes.d.ts +0 -12
- package/dist/vanilla/store/attachStoreHook.d.ts +0 -5
- package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +0 -5
- package/dist/vanilla/store/batchStoreNotifications.web.d.ts +0 -1
- package/dist/vanilla/store/createStore.d.ts +0 -5
- package/dist/vanilla/store/persist.d.ts +0 -13
- package/dist/vanilla/store/stateUpdate.d.ts +0 -9
- package/dist/vanilla/store/types.d.ts +0 -107
- package/dist/vanilla/storesStorage.web.d.ts +0 -2
- package/dist/vanilla/sync/types.d.ts +0 -114
- package/dist/vanilla/types/functions.d.ts +0 -23
- package/dist/vanilla/types/objects.d.ts +0 -10
- package/dist/vanilla/types/setState.d.ts +0 -21
- package/dist/vanilla/types/subscribe.d.ts +0 -27
- package/dist/vanilla/types/useStoreCallSignatures.d.ts +0 -1
- package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +0 -1
- package/dist/vanilla/types/utils.d.ts +0 -12
- package/dist/vanilla/types.d.ts +0 -285
- package/dist/vanilla/utils/core.d.ts +0 -25
- package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +0 -34
- package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +0 -27
- package/dist/vanilla/utils/debounce.d.ts +0 -21
- package/dist/vanilla/utils/equality.d.ts +0 -37
- package/dist/vanilla/utils/hydrationCoordinator.d.ts +0 -12
- package/dist/vanilla/utils/promiseUtils.d.ts +0 -1
- package/dist/vanilla/utils/serialization.d.ts +0 -13
- package/dist/vanilla/utils/stringUtils.d.ts +0 -6
- package/dist/vanilla/utils/time.d.ts +0 -36
- package/dist/web/chunk-QJLWBD7M.mjs +0 -1
- package/dist/web/chunk-V4LHP7LR.mjs +0 -1
package/dist/native/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=require("react-native"),n=(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')}),r="ios"===t.Platform.OS;t.Platform.OS;var o="development"===process.env.NODE_ENV,i="test"===process.env.NODE_ENV;function s(e){return e}function c(){}Object.freeze(Object.create(null));var a=Symbol("empty selection"),u=Object.is;function l(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===a?f(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===a||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===u?u(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===a)return;const l=e.selector(r),f=e.equalityFn(c,l);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=y(e,r,f?c:l),f||n()}))}function f(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==a)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return d(e,t)}function d(e,t){const n=e.value;if(n!==a&&u(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==a&&(e.equalityFn===u?u(n,r):e.equalityFn(n,r)))return y(e,t,n);const o=e.committedValue;return o!==a&&o!==n&&e.committedSource===e.source&&(e.equalityFn===u?u(o,r):e.equalityFn(o,r))?y(e,t,o):y(e,t,r)}function y(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function p(t,n,r,o){return Object.assign(function(i,s){return function(t,n,r,o,i=u){const s=e.useRef(null);let y=t,p=n,g=r;if(o){let e=s.current;null===e&&(e=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:a,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return d(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>f(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:a,latestSource:a,selector:r,selectedSource:e,selectedSubscribe:()=>c,source:e,value:a,valueEqualityFn:o,valueSelector:r,valueSnapshot:a};return i.selectedSubscribe=l(i,e),i}(t,n,r,o,i),s.current=e),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=a),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=l(e,t))}(e,t,n,r,o,i),y=e.selectedSubscribe,p=e.getSelectedSnapshot,g=void 0===r?void 0:e.getSelectedServerSnapshot}const h=e.useSyncExternalStore(y,p,g);return e.useDebugValue(h),h}(t.subscribe,n,r,i,s??o)},t)}function g(e){let t;function r(){if(t)return t;try{const r=function(e){const{createMMKV:t,MMKV:r}=n("react-native-mmkv");if("function"==typeof t)return t({id:e});if("function"==typeof r)return new r({id:e});throw new Error("[stores]: react-native-mmkv module does not export MMKV/createMMKV.")}(e);let o;if("function"==typeof r.delete?o=r.delete.bind(r):"function"==typeof r.remove&&(o=r.remove.bind(r)),"function"!=typeof o)throw new Error("[stores]: Storage instance does not conform to expected interface");const i={clearAll:r.clearAll.bind(r),contains:r.contains.bind(r),delete:o,get:r.getString.bind(r),getAllKeys:r.getAllKeys.bind(r),set:r.set.bind(r)};t=i}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:()=>r().clearAll(),contains:e=>r().contains(e),delete:e=>r().delete(e),get:e=>r().get(e),getAllKeys:()=>r().getAllKeys(),set:(e,t)=>r().set(e,t)}}var h={debug:(e,t)=>{o&&console.debug(e,t)},error:(e,t)=>{o&&!i&&console.error(e,t)},info:(e,t)=>{o&&console.info(e,t)},warn:(e,t)=>{o&&console.warn(e,t)}},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 null!==e&&"object"==typeof e&&!Array.isArray(e)}var w=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 O(e){return e instanceof Error?e:new Error(String(e))}var q,j,F,_=class{destroy(){}publish(){}},A=class{constructor(){this.sessionId="noop"}register(e){return new _}},I=!1;function C(){return F??(F=E(void 0))}function k(){I=!0}function E(e){return{storage:e?.storage??g(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(q||(q=new A),q)}}var T,x={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},D={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 M(e,t){const n=t?.baseDelay??D.seconds(5),r=t?.maxDelay??D.minutes(5);return Math.min(n*Math.pow(2,e),r)}function z(e){return JSON.stringify(P(e))}function P(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=S(r)?P(r):r,t},{__proto__:null})}function K(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function R(e,t,n){if(!0===n)return $(t)?t(e):t;const r=$(t)?t(e):t;return Object.is(r,e)?e:v(e)&&v(r)?{...e,...r}:r}function $(e){return"function"==typeof e}function L(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function V(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 N=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function H(e,t){U(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function W(e){return"getSnapshot"in e}function U(e){return N.QueryStore in e}function Q(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function J(e){return N.VirtualStore in e}function B(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 G(e,t){return"function"==typeof e[t]}function X(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(X(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--&&X(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(!X(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)||!X(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}function Y(e){let t;const n=new Set;function r(...e){const r=R(t,...e);if(Object.is(r,t))return;const o=t;t=r,n.forEach(e=>e(t,o))}function o(){return t}const i={getInitialState:function(){return s},getState:o,setState:r,subscribe:function(...e){return 1===e.length?c(e[0]):function(e,n,r){const o=r?.equalityFn??Object.is;let i=e(t);return r?.fireImmediately&&n(i,i),c(function(t){const r=e(t);if(o(i,r))return;const s=i;i=r,n(r,s)})}(e[0],e[1],e[2])}},s=t=e(r,o,i);return i;function c(e){return n.add(e),()=>{n.delete(e)}}}function Z(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function ee(e){return{...e,merge:e.merge??te,skipHydration:e.skipHydration??!1}}function te(e,t){return void 0===e?t:{...t,...e}}function ne(){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 re=Math.max,oe=Math.min;function ie(e,t=0,n={}){let r,o,i,s,c,a,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function g(){const e=se();if(p(e))return h(e);c=setTimeout(g,function(e){const n=t-(e-(a??0));return f&&void 0!==i?oe(n,i-(e-u)):n}(e))}function h(e){return c=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=se(),i=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(g,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(g,t),y(a)}return void 0===c&&(c=setTimeout(g,t)),s}return t=ce(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?re(ce(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==c&&clearTimeout(c),u=0,r=a=o=c=void 0},b.flush=function(){return void 0===c?s:h(se())},b}function se(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function ce(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 ae(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 ue=i?0:D.seconds(r?3:5);function le(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??ae,c=t.deserializer??e.deserializer??de(o),a=t.serializer??e.serializer??ye(o);function u(t,n,o){try{if(be(r))return;const c={state:s(n),version:o},u=ge(r,i,c),l=a(c);try{e.set(t,l),he(r,u)}catch(e){h.error(new w("[createBaseStore]: Failed to persist store data",e))}}catch(e){h.error(new w("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?ie(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){h.error(new w("[createBaseStore]: Failed to delete persisted store data",e))}}}}function fe(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??ae,c=t.deserializer??e.deserializer??de(o),a=t.serializer??e.serializer??ye(o);async function u(t,n,o){try{if(be(r))return;const c={state:s(n),version:o},u=ge(r,i,c),l=a(c);try{await e.set(t,l),he(r,u)}catch(e){h.error(new w("[createBaseStore]: Failed to persist store data",e))}}catch(e){h.error(new w("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?ie(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){h.error(new w("[createBaseStore]: Failed to delete persisted store data",e))}}}}function de(e){return t=>{if("string"!=typeof t)throw new w("[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?V:void 0)}catch(e){throw h.error(new w("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function ye(e){return t=>function(e,t){try{return JSON.stringify(e,t?L:void 0)}catch(e){throw h.error(new w("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var pe=Object.freeze({shouldClear:!1});function ge(e,t,n){if(!t||!e)return pe;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 be(e){return!!e&&!!e.getIsApplyingRemote()}var[me,Se]=[0,1];function ve(e,t,n){if(!e)return!0;const r=e[me],o=e[Se];return!(t<r)&&(t>r||n>o)}function we(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function Oe(e,t){if(!o)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function qe(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function je(e,t){if(k(),!t)return Y(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??C().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 w("[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??C().syncEngine,o=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(i,s,c)=>{const a=new Map,u=[],l=[];let f=null,d=!1,y=!1,p=0,g=null,b=[],m=Promise.resolve(),S=!n;function v(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||!g)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>p?e:p+1;return p=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=R(r,e,t);for(const e of b)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&v(n,o),i},u=t?i(c,!0):i(c);function h(){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 Z(u)?u.finally(h):(h(),u)}const q=c.setState;c.setState=O;const j=e(O,s,c);if(b=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),!b.length)return j;async function F(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 b)we(t,e.values)||ve(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of b){if(!we(o,e.values))continue;if(!g?.has(o))continue;if(!ve(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(!Oe(u,l))return void h.error(new w(`[sync] Merge function for field "${String(o)}" returned ${qe(u)} but expected ${qe(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?m=m.then(()=>F(e)):F(e)}if(g=new Set(b),f=r.register({apply:e=>{S?_(e):u.push(e)},fields:b,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]);v(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function I(){S=!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=I):f.onHydrated?(f.onHydrated(A),I()):(A(),I()),j},syncContext:o}}(e,i,o?.async??!1):void 0,c=s?.stateCreator??e;if(!r)return Y(c);const a=function(e,t,n){const r=t??e.storage??C().storage,o=(e.sync?void 0:e.persistThrottleMs??ue)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:fe(r,e,o,n),version:i}:{async:!1,persistStorage:le(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=ne()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)K(s.setState,e);c=void 0}},e(function(...e){return o?K(n,e):(t||(t=ne()),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(O(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,f=Y(function(e,t){return(n,r,o)=>{let i,s,c,a=ee(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 K(d,e),f()};const y=e(function(...e){return K(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 Z(n)?n.then(n=>g(e,n,t)).catch(n=>m(e,t,n)):g(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{a.storage.removeItem(a.name)},getOptions:()=>a,hasHydrated:()=>u,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{a=ee({...a,...e,storage:e.storage??a.storage})}}}),a.skipHydration||p(),i??y;function g(e,t,n){const r=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error("State loaded from storage couldn't be migrated since no migrate function was provided"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return Z(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(a,t);return Z(r)?r.then(t=>h(e,t,n)).catch(t=>m(e,n,t)):h(e,r,n)}function h(e,t,o){const s=function(e,t){if(e!==l)return;const o=a.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(Z(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 Fe(e,t,n="s"){return 1===t?e:`${e}${n}`}var _e=t.unstable_batchedUpdates,Ae=!1,Ie=!1,Ce=new Map,ke=new Map,Ee=new Map,Te=null,xe=1/0;function De(){return Ae}function Me(){return Te}function ze(){Ae||(Ae=!0,Ie||(Ie=!0,queueMicrotask(()=>{Ie=!1,_e(()=>{for(;ke.size>0;){const e=xe,t=Ee.get(e);if(t){Ee.delete(e);for(const e of t)ke.delete(e);Te=e;for(const e of t)e();if(Te=null,Ee.size>0){xe=1/0;for(const e of Ee.keys())e<xe&&(xe=e)}else xe=1/0}else{xe=1/0;for(const e of Ee.keys())e<xe&&(xe=e)}}for(;Ce.size>0;){const e=Array.from(Ce.values());Ce.clear();for(const t of e)t()}}),Ae=!1,Te=null,ke.clear(),Ee.clear(),xe=1/0})))}function Pe(e,t){Ae&&Ce.set(e,t)}var Ke=Symbol("stores.deriveProxy.unwrap");function Re(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?$e(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(W(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function $e(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===Ke)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,$e(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 Le(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Ke);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=Ne(e,t);if(n)for(let t=0;t<e.length;t++)Ve(e,String(t),n)}(e,t):S(e)&&function(e,t){const n=Ne(e,t);if(n)for(const t of Reflect.ownKeys(e))Ve(e,t,n)}(e,t),e)}function Ve(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Le(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function Ne(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var He=Object.freeze([]);function We(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)Qe(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?Xe(n.path,n.invocation):Ge(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${Fe("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}_${Fe("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)),Ue(i,n,0,r,o)}}}function Ue(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(Je(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(Je(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),Ue(s,t,n+1,r,o)}function Qe(e,t,n,r,o,i=2){const s=e.children;if(!s)return void Be(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){Be(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&Qe(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)Qe(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void Qe(s[e],t,[...n,e],r+1,o,i)}Be(e,t,n,o)}else Be(e,t,n,o)}function Je(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 Be(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 Ge(e){return t=>Ye(t,e)}function Xe(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=Ye(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??He):void 0}}function Ye(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 Ze=Symbol(),et=Object.freeze({equalityFn:Object.is,isDerivedStore:!0});function tt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:i,keepAlive:c,lockDependencies:a}="function"==typeof(f=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:f,keepAlive:!1,lockDependencies:!1}:{debounceOptions:f.debounce,debugMode:(o&&f.debugMode)??!1,equalityFn:f.equalityFn??Object.is,keepAlive:f.keepAlive??!1,lockDependencies:f.lockDependencies??!1},u=String(nt+=1),l=new Set;var f;c&&l.add(rt);const d=new Set;let y,p,g=Ze,h=!1,b=!0,m=!0,S=0,v=!1,w=null,O=Ze;function q(e,t,n){return m&&l.size?t?(d.add(e.subscribe(t,D,n?{equalityFn:n,isDerivedStore:!0}:et)),t(W(e)?e.getSnapshot():e.getState())):(y||(y=new WeakMap),p||(p=We()),Re(e,y,p.trackPath)):(t??s)(W(e)?e.getSnapshot():e.getState())}function j(e){for(const t of d)t(e);d.clear()}let F=!0;function _(){if(!b&&ot(g))return g;b=!1,m&&j(!0);const t=g,n=ot(t);g=function(t){F=!0;const n=g,o=e(t),s=p?Le(o):o;return ot(n)&&i(n,s)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),F=!1,n):s}(q);const o=r&&(!n||"verbose"===r&&m);if(o){n?"verbose"===r&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=d.size;console.log(`[π― ${e} ${Fe("Selector Subscription",e)} π―]`)}return p&&m&&(p.buildProxySubscriptions((e,t)=>{d.add(e.subscribe(t,D,et))},o),y=void 0,p.reset(),a&&(p=void 0)),F&&n&&function(e,t){const n=function(){const e=l.has(rt)?l.size-1:l.size;return S>0&&S<e}(),o=!S||n,i=n||null!==Me()||De()&&o;n&&ze(),r&&console.log(`[π» Derive Complete π»]: Notifying ${l.size} ${Fe("watcher",l.size)}`);for(const t of l){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}i?v||(v=!0,ot(O)||(O=t),Pe(u,I)):A(e,t)}(g,t),a&&(m=!1),g}function A(e,t){for(const n of l)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function I(){if(!l.size)return;if(b&&!S&&_(),!ot(g))return;const e=ot(O)?O:g;A(g,e),v=!1,O=Ze}const C=n?ie(E,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,k=C??(()=>{h||(h=!0,queueMicrotask(E))});function E(){h=!1,l.size?b&&_():z()}function T(e){e||C&&b?queueMicrotask(()=>{l.size||z()}):z()}function x(){E(),w=null}function D(){if(!b){if(b=!0,!C){if(S){ze();const e=Me(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Ae)return;const n=t<0?0:0|t,r=ke.get(e);if(void 0===r){ke.set(e,n);let t=Ee.get(n);return t||(t=new Set,Ee.set(n,t)),t.add(e),void(n<xe&&(xe=n))}if(n>r){const t=Ee.get(r);if(t&&(t.delete(e),0===t.size&&(Ee.delete(r),r===xe))){xe=1/0;for(const e of Ee.keys())e<xe&&(xe=e)}ke.set(e,n);let o=Ee.get(n);o||(o=new Set,Ee.set(n,o)),o.add(e),n<xe&&(xe=n)}}(x,t)}if(De())return void(v||(v=!0,ot(g)&&(O=g),Pe(u,I)))}w=null,k()}}function M(){return b||!ot(g)?l.size>0?_():e(q):g}function z(e=!0){c&&e||(C?.cancel(),j(),l.clear(),S=0,p=void 0,y=void 0,m=!0,h=!1,b=!0,g=Ze,v=!1,O=Ze,w=null)}return{destroy:()=>z(!1),flushUpdates:function(){l.size&&(C?C.flush():b&&_())},getSnapshot:function(){if(!ot(g)){l.add(rt);const e=_();return l.delete(rt),e}return h&&E(),g},getState:M,subscribe:function(...e){if(1===e.length){const t=e[0];return l.add(t),1!==l.size||ot(g)||M(),()=>{l.delete(t),l.size||T(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isDerivedStore??!1,s={currentSlice:void 0,equalityFn:o,isDerivedWatcher:i,listener:n,selector:t};return l.add(s),s.currentSlice=t(M()),i&&(S+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{l.delete(s),i&&(S-=1),l.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.")}}}var nt=0;function rt(){}function ot(e){return e!==Ze}var it=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=D.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)}}},st=new WeakMap,ct=new WeakMap;function at(e,t=ut,n=X){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(X(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=W(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}),gt=Object.freeze({once:!0}),ht=Object.freeze({updateQueryKey:!0});function bt(e,t,n,r){return r?St(r,n)?r:{...mt(e,t),...r}:mt(e,t)}function mt(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 St(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function vt(e){return"function"==typeof e}function wt(e){return!vt(e)}function Ot(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):ae(r),...qt(e,null,o)}}}function qt(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 jt(){return Object.create(null)}function Ft(e,t,n){return new w(`[createQueryStore: ${e}]: ${t} failed`,n)}function _t(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}var At=Symbol(),It=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1}),Ct=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function kt(e,t,n=Ct){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=Ct)=>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 Et(e){return"function"==typeof e?{equalityFn:e}:e??It}var Tt=Symbol();exports.QueryStatuses=x,exports.StoresError=w,exports.applyStateUpdate=R,exports.configureStores=function(e){var t;o&&function(){if(I)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,h=t),j??(j=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),F??(F=E(e))},exports.createBaseStore=function(e,t){const n=je(e,t);return p(n,n.getState,n.getInitialState,Object.is)},exports.createDerivedStore=function(e,t=Object.is){const n=tt(e,t);return p(n,n.getSnapshot)},exports.createQueryStore=function(e,t,n){const r=function(e,t,n){k();const r="function"==typeof t?t:jt,s="object"==typeof t?t:n,c=function(e){return"string"==typeof e?.storageKey}(s)?s:void 0,a=T??(T=function(){const e={abortInterruptedFetches:!0,cacheTime:D.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:M,staleTime:D.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(j)return j}()?.queryStoreDefaults;return t?{...e,...t}:e}()),u=a.minStaleTime,{fetcher:l,onError:f,onFetched:d,setData:y,transform:p,abortInterruptedFetches:g=a.abortInterruptedFetches,cacheTime:b=a.cacheTime,debugMode:S=a.debugMode,disableAutoRefetching:v=a.disableAutoRefetching,disableCache:q=!1,enabled:F=!0,keepPreviousData:_=a.keepPreviousData,maxRetries:A=a.maxRetries,paramChangeThrottle:I=a.paramChangeThrottle,params:C,retryDelay:E=a.retryDelay,staleTime:P=a.staleTime,suppressStaleTimeWarning:K=a.suppressStaleTimeWarning}=e;let R="function"==typeof P?a.staleTime:P;o&&!1!==u&&!v&&!K&&R<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:""}] β Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${R/1e3} seconds`);const $=new Error("[createQueryStore: AbortError] Fetch interrupted"),L="function"==typeof b,V=o&&S,H=e.params?Object.keys(e.params):[];let W=null,U=null,Q=null,J=[],B=!1,G=!1,Y=null,Z=null,ee=null,te=null,ne=null;const re={enabled:"function"!=typeof F&&F,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:x.Idle},oe=new it({disableAutoRefetching:v,initialEnabled:re.enabled});function se(){Y&&(Z=null,Y.abort(),Y=null)}function ce(t,n,o){const i=o.setState;function s(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=i(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&&ne!==t&&(ne=t,oe.setEnabled(t),t?queueMicrotask(()=>u.fetch(void 0,ht)):(ee||g)&&(g&&se(),ee&&(clearTimeout(ee),ee=null)))}(r.enabled,i)),o});return n?.(),r}return i(e)}function a(e,t){if(v||t?.skipStoreUpdates)return;if(R<=0||R===1/0)return;ee&&(clearTimeout(ee),ee=null);const r=z(e),o=n(),i=(q?te===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?R-(Date.now()-i):R;ee=setTimeout(()=>{const t=oe.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,pt,!0)},s)}o.setState=s,oe.init({onSubscribe:(r,o,i)=>{if(U||W||!C&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=mt(W,U),r=z(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?u.fetch(e,void 0,!0):a(e,void 0)}else v&&!i&&u.fetch(void 0,void 0,!0)}else B=!0},onLastUnsubscribe:e=>{ee&&(clearTimeout(ee),ee=null),g&&!e&&se()}});const u={...r(s,n,o),...re,async fetch(e,r,o=!1){const i=oe.get();if(!r?.force&&!r?.skipStoreUpdates&&!i.enabled)return null;const m=n(),S=m.error,v=m.queryKey,j=m.status===x.Loading,F=bt(W,U,H,e),I=z(F);if(j&&Z?.promise&&Z.key===I)return V&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(F)),Z.promise;const C=r?.staleTime??R,k=!!r?.skipStoreUpdates,T="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&_,D=(o||v===I||T)&&!k;if(g&&D&&se(),!r?.force){const e=m.lastFetchedAt,n=m.queryCache[I],o=n?.lastFetchedAt,s=n?.errorInfo,c=s&&s.retryCount>=A,u=(q?te===I&&e:o)||null;if(u&&!(Date.now()-u>=C)&&(!s||c||k))return D&&!ee&&i.subscriptionCount>0&&0!==R&&R!==1/0&&a(F,r),T&&t(e=>e.queryKey!==I?{queryKey:I}:e),V&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(F)),n?.data??null}D&&(ee&&(clearTimeout(ee),ee=null),!S&&j||t({error:null,status:x.Loading}),Z={key:I});const M=r?.cacheTime??(L?b(F):b);async function P(){const i=c?.storageKey||I;try{V&&(o||!e||St(e,H)?console.log("[π Fetching π] for params:",JSON.stringify(F)):console.log("[π Fetching with Partial Params π]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(F).filter(t=>!(t in e)).map(e=>[e,F[e]])))}`));const n=await(g&&D?async function(e){const t=new AbortController;Y=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r($),gt),Promise.resolve(l(e,t)).then(n,r)})}finally{Y===t&&(Y=null)}}(F):l(F,null)),c=Date.now();let f;V&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(F));try{f=function(e,t,n){return n?n(e,t):e}(n,F,p)}catch(e){throw Ft(i,"transform",e)}if(k)return V&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(F)),"withCache"===r.skipStoreUpdates&&t(e=>{if(!y)return q?e:{queryCache:{...e.queryCache,[I]:{cacheTime:M,data:f,errorInfo:null,lastFetchedAt:c}}};let t=e;const n=t.queryCache[I];try{y({data:f,params:F,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ft(i,"setData",e)}return!q&&Object.is(n,t.queryCache[I])&&(t={...t,queryCache:{...t.queryCache,[I]:{cacheTime:M,data:null,errorInfo:null,lastFetchedAt:c}}}),t}),f;if((y?s:t)(e=>{let t={...e,error:null,lastFetchedAt:c,queryKey:T?I:e.queryKey,status:x.Success};if(y||q){if(y){V&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(F));const e=t.queryCache[I];try{y({data:f,params:F,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Ft(i,"setData",e)}!q&&Object.is(e,t.queryCache[I])&&(t.queryCache={...t.queryCache,[I]:{cacheTime:M,data:null,errorInfo:null,lastFetchedAt:c}})}}else V&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(F),"| Has previous data?:",!!t.queryCache[I]?.data),t.queryCache={...t.queryCache,[I]:{cacheTime:M,data:f,errorInfo:null,lastFetchedAt:c}};return q||b===1/0?t:qt(_,I,t)}),D&&(te=I,a(F,r)),d)try{d({data:f,fetch:u.fetch,params:F,set:s})}catch(e){h.error(Ft(i,"onFetched callback",e))}return f??null}catch(s){if(s===$)return V&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(F)),null;const c=!o&&!0===r?.throwOnError,a=O(s);if(a instanceof w&&h.error(a),!D){if(c)throw a;return null}const l=q?void 0:n().queryCache[I],d=l?.errorInfo?.retryCount??0,y=d+1;try{f?.(a,d)}catch(e){h.error(Ft(i,"onError callback",e))}if(d<A){if(oe.get().subscriptionCount>0){const t="function"==typeof E?E(y,a):E;t!==1/0&&(ee&&clearTimeout(ee),ee=setTimeout(()=>{const t=oe.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,pt,!0)},t))}t(e=>({error:a,queryCache:{...e.queryCache,[I]:{cacheTime:l?.cacheTime??M,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:y}}},queryKey:T?I:e.queryKey,status:x.Error}))}else t(e=>({error:a,queryCache:{...e.queryCache,[I]:{cacheTime:l?.cacheTime??M,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:A}}},queryKey:T?I:e.queryKey,status:x.Error}));if(c)throw a;return null}finally{D&&(Z=null)}}return D?(Z={key:I,promise:P()}).promise:P()},getCacheEntry(e){if(q)return null;const t=n(),r=e?"string"==typeof e?e:z(bt(W,U,H,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===x.Idle;case"isLoading":return r===x.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],i=q?r===x.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((q?te===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===x.Idle,isLoading:r===x.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(q?te===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?te===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??R;return Date.now()-o>=i},reset(e=!1){for(const e of J)e();J=[],W=null,U=null,Q=null,se(),ee&&(clearTimeout(ee),ee=null),Z=null,te=null,e&&t(re)}},m=o.subscribe;return o.subscribe=(...e)=>{const t=G?()=>{}:oe.subscribe(),n=1===e.length?m(e[0]):m(e[0],e[1],e[2]);return e=>{t(e),n()}},u}const ae=c?.storageKey?je(ce,(ue=c,void 0===(le={partialize:Ot(_,c.partialize)})?Object.assign({__proto__:null},ue):Object.assign({__proto__:null},ue,le))):s&&!("storageKey"in s)?je(ce,s):je(ce);var ue,le;const fe=ae.getState(),de=fe.error,ye=fe.enabled,pe=fe.queryKey,ge=fe.fetch;let he;if(pe&&!de&&(te=pe),G=!0,C||"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(vt(s)){const t=s(at,n);r[e]=t,i[e]=t.value}else wt(s)&&(o[e]=s,i[e]=s)}let s,c=null,a=null;if(vt(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,C,ae);W={enabled:t,params:r},U={enabled:n,params:e}}"function"==typeof e.staleTime&&(Q=e.staleTime(at,ae),R=Q.value);const be=Object.freeze({updateQueryKey:_}),me=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{ge(e??mt(W,U),be)})(...e)}))}}();function Se(){let e;if(!_){e=mt(W,U);const t=z(e);ae.setState({queryKey:t})}me(e)}const ve=i||!I?Se:ie(Se,"number"==typeof I?I:I.delay,"number"==typeof I?{leading:!1,maxWait:I,trailing:!0}:I);for(const e in W?.params){const t=W.params[e];if(!t)continue;const n=dt(t);if(V&&console.log("[π Param Subscription π] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;X(r,n)||(V&&console.log("[π Param Change π] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,ve())});J.push(o)}}if(Q){const e=dt(Q);if(e){const t=Q;let n=t.value;V&&console.log("[π StaleTime Subscription π] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(V&&console.log("[π StaleTime Change π] - [Old]:",`${n},`,"[New]:",e),n=e,R=e,ge())});J.push(r)}}if(W?.enabled){const e=W.enabled,t=dt(e);if(t){let n=e.value;ye!==n&&((he??(he={})).enabled=n),n&&oe.setEnabled(n),V&&console.log("[π Enabled Subscription π] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(V&&console.log("[π Enabled Change π] - [Old]:",`${n},`,"[New]:",t),n=t,ae.setState({enabled:t}))});J.push(r)}}else ye!==re.enabled&&((he??(he={})).enabled=re.enabled);const we=z(mt(W,U));return we!==pe&&((he??(he={})).queryKey=we),he&&ae.setState(he),G=!1,B&&queueMicrotask(ve),Oe=ae,qe=N.QueryStore,Object.assign(Oe,{[qe]:!0});var Oe,qe}(e,t,n);return p(r,r.getState,r.getInitialState,Object.is)},exports.createStoreActions=function(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(o&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(J(e))for(const n in t)G(t,n)&&(r[n]=B(e,n));else for(const e in t)G(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n},exports.createVirtualStore=function(e,t,n){const r=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,a=tt(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),H(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0}),u=Object.assign({[N.VirtualStore]:!0,destroy:a.destroy,getInitialState:()=>a.getState().getInitialState(),getState:()=>a.getState().getState(),persist:(l=a.getState,{clearStorage:()=>l().persist?.clearStorage(),getOptions:()=>l().persist?.getOptions()??{},hasHydrated:()=>l().persist?.hasHydrated()??!0,hydrationPromise:()=>l().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>l().persist?.onFinishHydration(e)??c,onHydrate:e=>l().persist?.onHydrate(e)??c,rehydrate:()=>l().persist?.rehydrate(),setOptions:e=>l().persist?.setOptions(e)}),setState:_t(a.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?a.getState().subscribe(e[0]):a.getState().subscribe(e[0],e[1],e[2])};return s.add(t),()=>{t.unsubscribe(),s.delete(t)}}},o?.(a.getState));var l;return u}(e,t,n);return p(r,r.getState,r.getInitialState)},exports.deepEqual=function e(t,n){if("object"!=typeof t||null==t||"object"!=typeof n||null==n)return t===n;if(Object.is(t,n))return!0;const r=Object.keys(t);if(r.length!==Object.keys(n).length)return!1;for(const o of r)if(!(o in n)||!e(t[o],n[o]))return!1;return!0},exports.defaultRetryDelay=M,exports.destroyStore=H,exports.destroyStores=function(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&H(n,t)},exports.getQueryKey=function(e){return z(e)},exports.getStoreName=function(e){const t="function"==typeof(n=e)?n.name:"";var n;return Q(e)?e.persist.getOptions().name??t:t},exports.hasGetSnapshot=W,exports.identity=s,exports.isDerivedStore=function(e){return"flushUpdates"in e},exports.isPersistedStore=Q,exports.isQueryStore=U,exports.isVirtualStore=J,exports.nullObject=function(){return{__proto__:null}},exports.parseQueryKey=function(e){return function(e){return JSON.parse(e)}(e)},exports.replacer=L,exports.reviver=V,exports.shallowEqual=function(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0},exports.time=D,exports.useListen=function(t,n,r,o=It){const i=function(){const t=e.useRef(At);return t.current===At&&(t.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:Et(n),resubscribe:()=>{},unsubscribe:()=>{}}}(n,r,o)),t}(),s=function(e){return"function"==typeof e?It.enabled:e?.enabled??It.enabled}(o);return i.current.react=r,i.current.selector=n,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??It)}(i,o),e.useLayoutEffect(()=>{if(s)return kt(t,i),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(i)},[s,t]),i},exports.useStableValue=function(t){const n=e.useRef(Tt);return n.current===Tt&&(n.current=t()),n.current};
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react-native");const n=t.Platform.OS===`ios`;t.Platform.OS;const r=process.env.NODE_ENV===`development`,i=process.env.NODE_ENV===`test`;Object.freeze(Object.create(null));function a(e){return e}function o(){return{__proto__:null}}function s(e,t){return t===void 0?Object.assign(o(),e):Object.assign(o(),e,t)}function c(){}function l(e,t,n){e(t,n)}const u=Symbol(`empty selection`),d=Object.is;function f(t,n,r,i,a=d){let o=(0,e.useRef)(null),s=t,c=n,l=r;if(i){let e=o.current;e===null&&(e=p(t,n,r,i,a),o.current=e),m(e,t,n,r,i,a),s=e.selectedSubscribe,c=e.getSelectedSnapshot,l=r===void 0?void 0:e.getSelectedServerSnapshot}let u=(0,e.useSyncExternalStore)(s,c,l);return(0,e.useDebugValue)(u),u}function p(e,t,n,r,i){let a={committedEqualityFn:i,committedSelector:r,committedSource:e,committedValue:u,equalityFn:i,getSelectedServerSnapshot:()=>_(a),getSelectedSnapshot:()=>g(a),getServerStoreSnapshot:n,getStoreSnapshot:t,selector:r,selectedSource:e,selectedSubscribe:()=>c,source:e,value:u,valueEqualityFn:i,valueSelector:r,valueSnapshot:u};return a.selectedSubscribe=h(a,e),a}function m(e,t,n,r,i,a){e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=i,e.equalityFn=a,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=h(e,t))}function h(e,t){return n=>(b(e),t(r=>{let i=e.committedValue;if(i===u||e.committedSource!==t){n();return}let a=e.committedSelector,o=e.committedEqualityFn;if(e.selector===a&&e.equalityFn===o){let t=a(r);if(o===d?d(i,t):o(i,t))return;e.committedValue=t,e.value=t,e.valueEqualityFn=o,e.valueSelector=a,e.valueSnapshot=r,n();return}if(e.source!==t){n();return}let s=e.value;if(s===u)return;let c=e.selector(r),l=e.equalityFn(s,c);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=y(e,r,l?s:c),l||n()}))}function g(e){return v(e,e.getStoreSnapshot())}function _(e){return v(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}function v(e,t){let n=e.value;if(n!==u&&d(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;let r=e.selector(t);if(n!==u&&(e.equalityFn===d?d(n,r):e.equalityFn(n,r)))return y(e,t,n);let i=e.committedValue;return i!==u&&i!==n&&e.committedSource===e.source&&(e.equalityFn===d?d(i,r):e.equalityFn(i,r))?y(e,t,i):y(e,t,r)}function y(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function b(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===u?g(e):e.value}function x(e,t,n,r){let i=e.subscribe;function a(e,a){return f(i,t,n,e,a??r)}return Object.assign(a,e)}function S(e){let t;function n(){if(t)return t;try{let n=C(e),r;if(typeof n.delete==`function`?r=n.delete.bind(n):typeof n.remove==`function`&&(r=n.remove.bind(n)),typeof r!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`);t={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)}}catch(e){throw Error(`[stores] react-native-mmkv could not be loaded.
|
|
2
|
+
|
|
3
|
+
Persisted stores require a storage backend. Either:
|
|
4
|
+
- Install MMKV (the default): yarn add react-native-mmkv
|
|
5
|
+
- Or provide a custom adapter via configureStores()
|
|
6
|
+
`+(e instanceof Error?`\n${e.message}`:``))}return w(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)}}function C(e){let{createMMKV:t,MMKV:n}=require("react-native-mmkv");if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function w(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let T={debug:(e,t)=>{r&&console.debug(e,t)},error:(e,t)=>{r&&!i&&console.error(e,t)},info:(e,t)=>{r&&console.info(e,t)},warn:(e,t)=>{r&&console.warn(e,t)}};function E(e){T=e}const D=Object.prototype.hasOwnProperty;function O(e,t){return D.call(e,t)}function ee(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function k(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var j=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function M(e){return e instanceof Error?e:Error(String(e))}var te=class{destroy(){}publish(){}},N=class{constructor(){this.sessionId=`noop`}register(e){return new te}};let ne;function P(){return ne||(ne=new N),ne}let F,I,L=!1;function R(e){r&&ie(),e.logger&&E(e.logger),F??(F=V(e)),I??(I=H(e))}function z(){if(F)return F}function B(){return I??(I=H(void 0))}function re(){L=!0}function V(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function H(e){return{storage:e?.storage??S(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??P()}}function ie(){if(L)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const U={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},W={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let G;function ae(){return G??(G=oe())}function oe(){let e=z()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??W.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??W.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function se(e,t){let n=t?.baseDelay??W.seconds(5),r=t?.maxDelay??W.minutes(5);return Math.min(n*2**e,r)}function K(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function ce(e,t,n){if(n===!0)return le(t)?t(e):t;let r=le(t)?t(e):t;return Object.is(r,e)?e:!A(e)||!A(r)?r:{...e,...r}}function le(e){return typeof e==`function`}function q(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ue(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function de(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function fe(e,t){return q(t)?new Map(t.entries):ue(t)?new Set(t.values):t}const pe=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function me(e,t){return Object.assign(e,{[t]:!0})}function he(e,t){J(e)?e.getState().reset(t?.clearQueryCache):ye(e)&&e.destroy()}function ge(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||he(n,t)}function _e(e){let t=ve(e);return Se(e)?e.persist.getOptions().name??t:t}function ve(e){return typeof e==`function`?e.name:``}function ye(e){return`destroy`in e}function be(e){return`getSnapshot`in e}function J(e){return pe.QueryStore in e}function xe(e){return`flushUpdates`in e}function Se(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function Ce(e){return pe.VirtualStore in e}function we(e,t){let n=Te(e);return t?Object.assign(n,t):n}function Te(e){let t=e.getState(),n=o(),i=n;if(r&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(Ce(e))for(let n in t)De(t,n)&&(i[n]=Ee(e,n));else for(let e in t)De(t,e)&&(i[e]=t[e]);return n}function Ee(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function De(e,t){return typeof e[t]==`function`}function Oe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Oe(e[r],t[r]))return!1;return!0}function ke(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ae(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ae(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ae(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ae(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ae(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function je(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Me(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function Ne(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Pe(e,t){t>1&&e.clear()}const Fe=t.unstable_batchedUpdates;let Y=!1,Ie=!1,Le=!1,X,Re,ze=0;const Be=new Map;let Ve=0,He=null,Z=1/0;function Ue(){return Y}function We(){return He}function Ge(){Y||(Y=!0,!Le&&(Le=!0,queueMicrotask(()=>{Le=!1,Ke()})))}function Ke(){if(Y){if(Ie){Xe();return}Ie=!0;try{Fe(Xe)}finally{et()}}}function qe(){if(Y){if(Ie){He===null&&Ze();return}Ie=!0;try{Ze()}catch(e){throw et(),e}finally{Ie=!1,He=null}}}function Je(e){if(Y){if(Re){Re.push(e);return}if(!X){X=e;return}Re=[X,e],X=void 0}}function Ye(e,t){if(!Y)return;let n=t<0?0:t|0,r=Be.get(n);r||(r=[],Be.set(n,r)),r.push(e),Ve+=1,n<Z&&(Z=n)}function Xe(){for(;Ve>0||tt();)Ze(),$e()}function Ze(){for(;Ve>0;){let e=Z,t=Be.get(e);if(!t){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e);continue}Be.delete(e),Ve-=t.length,Qe(),He=e;for(let e=0;e<t.length;e++)t[e]();He=null}}function Qe(){Z=1/0;for(let e of Be.keys())e<Z&&(Z=e)}function $e(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=Re;if(!t)return;for(;ze<t.length;)t[ze++]();Re=void 0,ze=0;return}}function et(){Y=!1,Ie=!1,He=null,X=void 0,Re=void 0,ze=0,Be.clear(),Ve=0,Z=1/0}function tt(){return!!X||!!Re}const Q=Symbol(`stores.subscribeCascadeState`);function nt(e){return Q in e}function rt(e,t){nt(e)&&(e[Q]=t(e[Q]))}const it=Symbol(),at=Symbol();function ot(e){let t,n,r,i=0;function a(e,a,o){let s=ce(t,e,a);if(Object.is(s,t))return o===it?at:void 0;let c=t;if(t=s,Ne(r,i,l,t,c),n){Ke();for(let e of n)e(t,c)}}function o(){return t}function s(){return d}function c(e,t,n){return t?g(e,t,n):f(e)}let u={[Q]:m,getInitialState:s,getState:o,setState:a,subscribe:c},d=t=st(e)?e(a,o,u):e;return u;function f(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function p(e){let t=je(r,i,e);return t!==null&&(r=t,i+=1),()=>h(e)}function m(e){function t(t,n){Ge(),e(t,n)}return p(t)}function h(e){let t=Me(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ge(),n(r,s)}return r?.fireImmediately&&n(o,o),a?p(s):f(s)}}function st(e){return typeof e==`function`}function ct(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const lt=Object.freeze({migrated:!1,state:void 0});function ut(e,t,n){return(r,i,a)=>{let o=ft(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,it):r(e,!1,it))===at?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return ct(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=dt(o,t);return ct(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(ct(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=ft({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function dt(e,t){if(!t)return lt;if(typeof t.version!=`number`||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`),lt;let n=e.migrate(t.state,t.version);return ct(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function ft(e){return{...e,merge:e.merge??pt,skipHydration:e.skipHydration??!1}}function pt(e,t){return e===void 0?t:{...t,...e}}function mt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function ht(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=mt()),t.promise),stateCreator:(r,a,o)=>{let s;function c(...e){return n?K(r,e):(t||(t=mt()),s||(s=[]),s.push(e),t.promise)}return i=()=>{if(s?.length){for(let e of s)K(o.setState,e);s=void 0}},e(c,a,o)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?t?.fail(M(a)):t?.complete(),o?.(e,a)}}}}function gt(e){let t,n=null;function r(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}return r}const _t=Math.max,vt=Math.min;function yt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=xt(t)||0,St(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?_t(xt(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?vt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=bt();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(bt())}function x(...e){let n=bt(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function bt(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function xt(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(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):e===0?e:+e}function St(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function Ct(e){if(!k(e))return e;let t=o(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function wt(e,t){try{return JSON.stringify(e,t?de:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to serialize store data`,e)),e}}function Tt(e,t){try{return JSON.parse(e,t?fe:void 0)}catch(e){throw T.error(new j(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Et=i?0:n?W.seconds(3):W.seconds(5);function Dt(e,t,n){let r=t??e.storage??B().storage,i=(e.sync?void 0:e.persistThrottleMs??Et)||void 0,a=e.version??0;return r.async?{async:!0,persistStorage:kt(r,e,i,n),version:a}:{async:!1,persistStorage:Ot(r,e,i,n),version:a}}function Ot(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??Ct,s=t.deserializer??e.deserializer??At(i),c=t.serializer??e.serializer??jt(i);function l(t,n,i){try{if(It(r))return;let s={state:o(n),version:i},l=Nt(r,a,s),u=c(s);try{e.set(t,u),Pt(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:yt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function kt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??Ct,s=t.deserializer??e.deserializer??At(i),c=t.serializer??e.serializer??jt(i);async function l(t,n,i){try{if(It(r))return;let s={state:o(n),version:i},l=Nt(r,a,s),u=c(s);try{await e.set(t,u),Pt(r,l)}catch(e){T.error(new j(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){T.error(new j(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let u=n===void 0?gt(l):yt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:s(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await u(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){T.error(new j(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function At(e){return t=>{if(typeof t!=`string`)throw new j(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return Tt(t,e)}}function jt(e){return t=>wt(t,e)}const Mt=Object.freeze({shouldClear:!1});function Nt(e,t,n){if(!t||!e)return Mt;let r=e.getFieldTimestampSnapshot();return Ft(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 Pt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Ft(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function It(e){return e?!!e.getIsApplyingRemote():!1}function Lt(e,t,n){let r=t.engine??B().syncEngine;return(i,a,s)=>{let c=new Map,l=[],u=[],d=null,f=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=o();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)c.set(t,[n,a]);!d||!p?u.push({keys:e,replace:i,timestamp:n,values:t}):d.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!d||!u.length)){for(let e of u){let t=r.sessionId;for(let n of e.keys)c.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),d.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}u.length=0}}function C(e,t){if(f||!h)return t?i(e,t):i(e);let n=y(),r,a,s=t?i(c,!0):i(c);if(!r||!a)return s;function c(i){let s=ce(i,e,t);for(let e of g)Object.is(s[e],i[e])||((r??(r=[])).push(e),(a??(a=o()))[e]=s[e]);return r&&b(n,r),s}return ct(s)?s.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),s)}let w=s.setState;s.setState=C;let E=e(C,a,s);if(g=t.fields??Bt(E),!g.length)return E;h=new Set(g);async function D(e){m=Math.max(m,e.timestamp);let r=o(),i=a(),s=e.timestamp,l;if(e.replace)for(let t of g)O(e.values,t)||zt(c.get(t),s,e.sessionId)&&(l??(l=[])).push(t);for(let n of g){if(!Ut(e.values,n)||!h?.has(n)||!zt(c.get(n),s,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],o=i[n];if(t!==void 0){let l=a(t,o,i,e.values),u=o===void 0?t:o;if(!Ht(l,u)){T.error(new j(`[sync] Merge function for field "${String(n)}" returned ${Vt(l)} but expected ${Vt(u)}`));return}r[n]=l,c.set(n,[s,e.sessionId])}}else r[n]=e.values[n],c.set(n,[s,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!l?.length)){f=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(l?.length){t=!0;for(let t of l)delete e[t],c.delete(t)}for(let n in r){if(!O(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{f=!1,n?.setIsApplyingRemote(!1)}}}function ee(e){n?.isAsync?_=_.then(()=>D(e)):D(e)}function k(){if(!l.length)return;let e=l.slice();l.length=0;for(let t of e)ee(t)}if(d=r.register({apply:e=>{if(!v){l.push(e);return}ee(e)},fields:g,getState:a,key:t.key}),d?.onFirstSubscribe||d?.onLastUnsubscribe){let e=d,t=0,n=s.subscribe;function A(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}s.subscribe=(...e)=>A(e.length===1?n(e[0]):n(e[0],e[1],e[2])),rt(s,e=>t=>A(e(t)))}function M(){p=!0,S()}function te(){v=!0,k()}return n?.isAsync?(n.onHydrationComplete=M,n.onHydrationFlushEnd=te):d.onHydrated?(d.onHydrated(M),te()):(M(),te()),E}}function Rt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function zt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Bt(e){let t=[];for(let n of Object.keys(e))Wt(e,n)&&t.push(n);return t}function Vt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Ht(e,t){if(!r)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Ut(e,t){return O(e,t)}function Wt(e,t){return typeof e[t]!=`function`}function Gt(e,t){if(re(),!t)return ot(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??B().storage:void 0,a=Kt(t.sync,n),o=!i||!a?void 0:Rt(i.async??!1),s=a?Lt(e,a,o):e;if(!r)return ot(s);let c=Dt(t,i,o),l=c.async?ht(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ot(ut(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function Kt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new j(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function qt(e,t,n=`s`){return t===1?e:`${e}${n}`}const Jt=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var Yt=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return nt(e)?e[Q](this.invalidate):e.subscribe(a,this.invalidate,Jt)}},Xt=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=je(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,en(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Me(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,en(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=je(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Me(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){Ne(this.cascadeStateListeners,this.cascadeStateListenerCount,l,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&Ne(this.watchers,this.watcherCount,Zt,e,t)}notifyOrdinary(e,t){Ne(this.watchers,this.watcherCount,Qt,e,t)}clear(){this.watchers=Pe(this.watchers,this.watcherCount),this.cascadeStateListeners=Pe(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function Zt(e,t,n){typeof e==`function`||!e.isCascadeParticipant||$t(e,t)}function Qt(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||$t(e,t)}function $t(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function en(e){return typeof e!=`function`&&e.isCascadeParticipant}const tn=Symbol(`stores.deriveProxy.unwrap`);function nn(e,t,n,r){let i=n.get(e);if(fn(i))return i;let a=rn(t,e,r);return n.set(e,a),a}function rn(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):an(e,r,t,n,new WeakSet,new WeakMap)}function an(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===tn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&ee(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return O(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));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,an(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function on(e,t){return!e||typeof e!=`object`?e:un(e)||(Array.isArray(e)?sn(e,t):k(e)&&cn(e,t),e)}function sn(e,t){let n=dn(e,t);if(n)for(let t=0;t<e.length;t++)ln(e,String(t),n)}function cn(e,t){let n=dn(e,t);if(n)for(let t of Reflect.ownKeys(e))ln(e,t,n)}function ln(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=on(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function un(e){let t=Reflect.get(e,tn);return t&&typeof t==`object`?t:void 0}function dn(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function fn(e){return e!==void 0}const pn=Object.freeze([]);function mn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)_n(s,c,[],0,o,a);else if(n)for(let e of n)_n(e[1],e[0],[],0,o,a);xn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=hn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=hn(),i.set(r,s))):(s=hn(),e=r,t=s)}gn(s,i,a,o)}}}function hn(){return o()}function gn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=hn());else if(a=i.child,!a)a=hn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=hn();t[e]=a,a=t[n]=hn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&vn(i,r)}function _n(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(bn(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){bn(e,t,n,i);return}n.push(s),_n(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){bn(e,t,n,i);return}if(e.isLeaf||r>=a){bn(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),_n(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),_n(s[e],t,n,r+1,i,a),n.pop()}function vn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(yn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(yn(r[e],t))return;r.push(t)}function yn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function bn(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function xn(e,t,n){for(let n of e){let e=n.invocation?Cn(n.path,n.invocation):Sn(n.path);t(n.store,e,n.path)}n&&Tn(e)}function Sn(e){return e.length?t=>wn(t,e):a}function Cn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=wn(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??pn):void 0}}function wn(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function Tn(e){let t=e.length;console.log(`[π‘ ${t} ${qt(`Proxy Subscription`,t)} π‘]:`,JSON.stringify(e.map(e=>{let t=En(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${qt(`arg`,r)})`:`()`}`}),null,2))}function En(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Dn=Symbol(),On=Symbol(),kn=Symbol(`stores.derivedStore.readDependencyState`);function An(e,t=Object.is){let n,i=!1,o,s=!1,c=!1;typeof t==`function`?o=t:(n=t.debounce,i=r?t.debugMode??!1:!1,o=t.equalityFn??Object.is,s=t.keepAlive??!1,c=t.lockDependencies??!1);let l=new Xt,u=new Yt(k),d=+!!s,f,p,m=Dn,h=!1,g=!1,_=!0,v=!0,y=null,b=On;function x(e,t,n){if(!v)return(t??a)(Nn(e));if(!d)return(t??a)(e.getState());if(!t){let t=Nn(e);return!t||typeof t!=`object`?(u.retainState(e),t):(f||(f=new WeakMap),p||(p=mn()),nn(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:Jt;return u.addSelector(e.subscribe(t,k,r)),t(Nn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&u.beginRebuild(!0);let t=!0,n=m,r=$(n);g=!0;try{let a=e(x),s=p?on(a):a;r&&o(n,s)?(i&&console.log(`[π₯· Derive Complete π₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&u.finishRebuild(!0)}let a=i&&(!r||i===`verbose`&&v);if(a){r?i===`verbose`&&console.log(`[π Rebuilding Subscriptions π]: Createdβ¦`):console.log(`[π Initial Derive Complete π]: Createdβ¦`);let e=u.size;console.log(`[π― ${e} ${qt(`Selector Subscription`,e)} π―]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{u.addSelector(e.subscribe(t,k,Jt))},a),f=void 0,c?p=void 0:p.reset()),t&&r&&C(m,n),c&&(v=!1),m}function C(e,t){let n=l.cascadeParticipantCount,r=n>0&&l.ordinaryWatcherCount>0,a=l.ordinaryWatcherCount>0&&(r||We()!==null||Ue());if(r&&Ge(),i){let e=l.ordinaryWatcherCount+n;console.log(`[π» Derive Complete π»]: Notifying ${e} ${qt(`watcher`,e)}`)}if(n&&l.notifyCascade(e,t),l.ordinaryWatcherCount){if(a){b===On?(b=t,Je(w)):$(b)||(b=t);return}l.notifyOrdinary(e,t)}}function w(){d&&_&&!l.cascadeParticipantCount&&S();let e=b;b=On,l.ordinaryWatcherCount&&$(m)&&e!==On&&$(e)&&l.notifyOrdinary(m,e)}let T=n?yt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!d){s||P();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!d&&!s&&P()}function ee(){let e=y;e===We()&&(D(),y===e&&(y=null))}function k(){if(!g){if(!T){if(l.cascadeParticipantCount){_=!0,Ge();let e=We(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,Ye(ee,t);return}if(_)return;if(_=!0,Ue()){b===On&&(b=Dn,Je(w));return}}_||(_=!0,y=null,E())}}function A(e){d+=1;try{return e()}finally{--d}}function j(){return _||!$(m)?d?S():A(S):(h&&d&&D(),m)}function M(){return Ue()&&We()===null&&qe(),_||!$(m)?d?S():e(x):m}function te(...e){if(e.length===1){let t=e[0];return l.addWatcher(t)&&(d+=1),$(m)||M(),()=>{l.deleteWatcher(t)&&(--d,d||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(d?M():A(M)),s={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return l.addWatcher(s),d+=1,r?.fireImmediately&&n(o,o),()=>{l.deleteWatcher(s)&&(--d,d||O(a))}}function N(e){return d?M():A(M),l.addCascadeStateListener(e)&&(d+=1),()=>{l.deleteCascadeStateListener(e)&&(--d,d||O(!0))}}function ne(){d&&(T?T.flush():_&&S())}function P(){T?.cancel(),u.clear(),l.clear(),d=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Dn,b=On,y=null}function F(){return _||h||!$(m)?d?S():A(S):m}return{[kn]:F,[Q]:N,destroy:P,flushUpdates:ne,getSnapshot:j,getState:M,subscribe:te,getInitialState:jn,setState:Mn}}function jn(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Mn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function Nn(e){let t=e[kn];return t?t():e.getState()}function $(e){return e!==Dn}var Pn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=W.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Fn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const In=Symbol(`stores.queryParamConfig`);function Ln(e,t){return{[In]:!0,key:t.key,value:e}}function Rn(e){return!!e&&typeof e==`object`&&In in e}function zn(e){return JSON.stringify(Vn(e))}function Bn(e){return JSON.parse(e)}function Vn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=k(r)?Vn(r):r,t},o())}const Hn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Un(e,t,n){let r=o(),i=null,a=!1;if(e)for(let n in e){if(!O(e,n))continue;let s=Wn(r,e[n],n,t);s&&((i??(i=o()))[n]=s,s.key!==void 0&&(a=!0))}return{buildKey(e=r){return zn(a?Yn(i,e):e)},complete(e){return e?Qn(e,n)?e:{...r,...e}:qn(r)},get(){return qn(r)},subscribe(e){return Jn(i,r,e)}}}function Wn(e,t,n,r){return Rn(t)?Kn(e,t.value,n,r,t.key):Kn(e,t,n,r)}function Gn(e,t){let n=[],r,i;function o(e,t,a){return t?(n.push(n=>e.subscribe(t,n,Xn(a))),t(Zn(e))):(r??(r=mn()),i??(i=new WeakMap),nn(e,Zn(e),i,r.trackPath))}function s(e,t=a){return t(Zn(e))}let c=e(o,t),l=r?on(c):c;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Hn))},!1),r=void 0),i=void 0,{initialValue:l,subscribe(r){let i=()=>r(e(s,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function Kn(e,t,n,r,i){if($n(t)){let a=Gn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function qn(e){let t=o();for(let n in e)O(e,n)&&(t[n]=e[n]);return t}function Jn(e,t,n){if(!e)return c;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ae(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:c}function Yn(e,t){let n=o();for(let r in t){if(!O(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function Xn(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Hn}function Zn(e){return be(e)?e.getSnapshot():e.getState()}function Qn(e,t){for(let n of t)if(!(n in e))return!1;return!0}function $n(e){return typeof e==`function`}const er={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},tr=Object.freeze({force:!0}),nr=Object.freeze({once:!0}),rr=new Set;let ir=!1;function ar(e){rr.add(e),!ir&&(ir=!0,queueMicrotask(()=>{ir=!1,Fe(or)}))}function or(){for(let e of rr)rr.delete(e),e()}function sr(e,t,n){re();let a=typeof t==`function`?t:dr,o=typeof t==`object`?t:n,c=cr(o)?o:void 0,l=ae(),u=l.minStaleTime,{fetcher:d,onError:f=l.onError,onFetched:p,setData:m,transform:h,abortInterruptedFetches:g=l.abortInterruptedFetches,cacheTime:_=l.cacheTime,debugMode:v=l.debugMode,disableAutoRefetching:y=l.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=l.keepPreviousData,paramChangeThrottle:C=l.paramChangeThrottle,params:w,retry:E=l.retry,retryDelay:D=l.retryDelay,staleTime:O=l.staleTime,suppressStaleTimeWarning:ee=l.suppressStaleTimeWarning}=e,k=typeof O==`function`?l.staleTime:O;r&&u!==!1&&!y&&!ee&&k<u&&console.warn(`[createQueryStore${c?.storageKey?`: ${c.storageKey}`:``}] β Stale times under ${u/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),te=typeof _==`function`,N=r&&v,ne=e.params?Object.keys(e.params):[],P=!1,F,I=[],L=null,R=null,z=null,B=null,V=null,H=null,ie=null,W={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:U.Idle},G=new Pn(y);function oe(){z&&(B=null,z.abort(),z=null)}function K(){V&&(clearTimeout(V),V=null)}async function ce(e){let t=new AbortController;z=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),nr),Promise.resolve(d(e,t)).then(n,r)})}finally{z===t&&(z=null)}}function le(e,t,n){let r=n.setState;function i(e,t){e!==t&&ie!==t&&(ie=t,t&&G.hasSubscribers()?queueMicrotask(()=>u.fetch(void 0,void 0,!0)):(V||g)&&(g&&oe(),K()))}function o(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,a=r(r=>{let a=t?e(r):e,o=a.enabled===void 0?r.enabled:a.enabled;return o!==r.enabled&&(n=()=>i(r.enabled,o)),a});return n?.(),a}else return r(e)}n.setState=o,G.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?u.fetch(t,void 0,!0):s(t)}else y&&!r&&u.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{K(),g&&!e&&oe()}});function s(e){if(y||k<=0||k===1/0||!G.hasSubscribers())return;K();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;V=setTimeout(()=>{t().enabled&&u.fetch(e,tr,!0)},a)}function l(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===U.Idle;case`isLoading`:return r===U.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===U.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?H===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===U.Idle,isLoading:r===U.Loading,isInitialLoad:s,isSuccess:c}}}}let u={...a(o,t,n),...W,async fetch(n,r,i=!1,a=0){let l=!!r?.skipStoreUpdates,v=t();if(!l&&(!v.enabled&&!r?.force||i&&!G.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===U.Loading,w=F.complete(n),O=F.buildKey(w);if(C&&B?.promise&&B.key===O)return N&&console.log(`[π Using Active Fetch π] for params:`,JSON.stringify(w)),B.promise;let ee=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===O||P)&&!l,L=B!==null;if(g&&I&&oe(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[O],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?H===O&&t:r)||null;if(!(!a||Date.now()-a>=ee)&&(!i||!i.retryAllowed||l))return I&&!V&&k!==0&&k!==1/0&&s(w),P&&e(e=>e.queryKey===O?e:{queryKey:O}),N&&console.log(`[πΎ Returning Cached Data πΎ] for params:`,JSON.stringify(w)),n?.data??null}let R=I?{key:O}:null,z=r?.cacheTime??(te?_(w):_);R&&(K(),P&&!L&&v.lastFetchedAt===null&&x!==O?e({error:null,queryKey:O,status:U.Loading}):(y||!C)&&e({error:null,status:U.Loading}),B=R);async function re(){let v=c?.storageKey||O;try{N&&(!i&&n&&ne.some(e=>!(e in n))?console.log(`[π Fetching with Partial Params π]
|
|
7
|
+
`,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[π Fetching π] for params:`,JSON.stringify(w)));let t=await(g&&I?ce(w):d(w,null)),a=Date.now();N&&console.log(`[β
Fetch Successful β
] for params:`,JSON.stringify(w));let c;try{c=pr(t,w,h)}catch(e){throw fr(v,`transform`,e)}if(l)return N&&console.log(`[π₯· Successful Parallel Fetch π₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw fr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[O])&&(t={...t,queryCache:{...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),c;if((m?o:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:P?O:e.queryKey,status:U.Success};if(!m&&!b)N&&console.log(`[πΎ Setting Cache πΎ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[O]?.data),t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:c,errorInfo:null,lastFetchedAt:a}};else if(m){N&&console.log(`[πΎ Setting Data πΎ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[O];try{m({data:c,params:w,queryKey:O,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw fr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[O])&&(t.queryCache={...t.queryCache,[O]:{cacheTime:z,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:ur(S,O,t)}),I&&(H=O,s(w)),p)try{p({data:c,fetch:u.fetch,params:w,set:o})}catch(e){T.error(fr(v,`onFetched callback`,e))}return c??null}catch(n){if(n===A)return N&&console.log(`[β Fetch Aborted β] for params:`,JSON.stringify(w)),null;let o=!i&&r?.throwOnError===!0,s=M(n);if(s instanceof j&&T.error(s),!I){if(o)throw s;return null}let c=b?void 0:t().queryCache[O],l,d;if(typeof E==`function`){l={error:s,params:w,queryKey:O,retryCount:a};try{d=E(l)}catch(e){T.error(fr(v,`retry callback`,e)),d=!1}}else d=E!==!1&&a<E;let p;if(d&&t().enabled&&G.hasSubscribers())if(D===void 0)p=se(a);else if(typeof D==`number`)p=D;else{l??(l={error:s,params:w,queryKey:O,retryCount:a});try{p=D(l)}catch(e){T.error(fr(v,`retryDelay callback`,e)),d=!1}}let m=p!==void 0;if(p!==void 0&&(K(),V=setTimeout(()=>{t().enabled&&u.fetch(w,tr,!0,a+1)},p)),e(b?e=>({error:s,queryKey:P?O:e.queryKey,status:U.Error}):e=>({error:s,queryCache:{...e.queryCache,[O]:{cacheTime:c?.cacheTime??z,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:d,retryCount:a}}},queryKey:P?O:e.queryKey,status:U.Error})),f)try{f({error:s,params:w,queryKey:O,retryCount:a,willRetry:m})}catch(e){T.error(fr(v,`onError callback`,e))}if(o)throw s;return null}finally{B===R&&(B=null)}}return R?(R.promise=re(),R.promise):re()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:l,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?H===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?H===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Un(void 0,q,ne),L=null,R=null,oe(),K(),ye?.cancel(),B=null,H=null,t&&e(W)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:G.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},rt(n,e=>t=>{let n=P?void 0:G.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),u}let q=c?.storageKey?Gt(le,s(c,{partialize:lr(S,c.partialize)})):o&&!(`storageKey`in o)?Gt(le,o):Gt(le),ue=q.getState(),de=ue.error,fe=ue.enabled,he=ue.queryKey,ge=ue.fetch;he&&!de&&(H=he),P=!0,F=Un(w,q,ne),typeof x==`function`&&(L=Gn(x,q)),typeof e.staleTime==`function`&&(R=Gn(e.staleTime,q),k=R.initialValue);let _e=Fn(e=>{ge(e,void 0,!0)},ar);function ve(){if(S)_e(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),_e(e)}}let ye=i||!C?void 0:yt(ve,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function be(){if(K(),ye){let e=q.getState();S&&B?.key===e.queryKey&&e.lastFetchedAt===null?ve():ye();return}ve()}if(I.push(F.subscribe((e,t,n)=>{N&&console.log(`[π Param Change π] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),be()})),R){let e=R.initialValue;N&&console.log(`[π StaleTime Subscription π] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(N&&console.log(`[π StaleTime Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,K(),ge(void 0,void 0,!0))}))}let J;if(L){let e=L.initialValue;fe!==e&&((J??(J={})).enabled=e),N&&console.log(`[π Enabled Subscription π] Initial value:`,e),I.push(L.subscribe(t=>{t!==e&&(N&&console.log(`[π Enabled Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==W.enabled&&((J??(J={})).enabled=W.enabled);let xe=F.buildKey();return xe!==he&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,me(q,pe.QueryStore)}function cr(e){return typeof e?.storageKey==`string`}function lr(e,t){return n=>{let r={...n},i=o();for(let e in r)O(r,e)&&e in er&&(er[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):Ct(r),...ur(e,null,i)}}}function ur(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=t??(e&&n.queryKey||null),a=o(),s=!1;for(let e in n.queryCache){if(!O(n.queryCache,e))continue;let t=n.queryCache[e];t&&(r-(t.lastFetchedAt??t.errorInfo.lastFailedAt)<t.cacheTime||e===i)?a[e]=t:s=!0}return s?{...n,queryCache:a}:n}function dr(){return Object.create(null)}function fr(e,t,n){return new j(`[createQueryStore: ${e}]: ${t} failed`,n)}function pr(e,t,n){return n?n(e,t):e}const mr=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function hr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Ke();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=gr(t,e.listener),!Object.is(r,n)&&(Ge(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ge()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),he(t)}let m=An(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:gr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[pe.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:_r(g),setState:vr(g),subscribe:_},i?.(g))}function gr(e,t){return nt(e)?e[Q](t):e.subscribe(a,t,mr)}function _r(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??c,onHydrate:t=>e().persist?.onHydrate(t)??c,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function vr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function yr(e,t){let n=Gt(e,t);return x(n,n.getState,n.getInitialState)}function br(e,t=Object.is){let n=An(e,t);return x(n,n.getSnapshot,void 0)}function xr(e,t,n){let r=sr(e,t,n);return x(r,r.getState,r.getInitialState)}function Sr(e,t,n){let r=hr(e,t,n);return x(r,r.getState,r.getInitialState)}const Cr=Symbol();function wr(t){let n=(0,e.useRef)(Cr);return n.current===Cr&&(n.current=t()),n}const Tr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Er(t,n,r,i=Tr){let a=wr(()=>Ar(n,r,i)),o=Mr(i);return Nr(a,n,r,i),(0,e.useLayoutEffect)(()=>{if(o)return Or(t,a),()=>kr(a)},[o,t]),a}const Dr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Or(e,t,n=Dr){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=Dr)=>Or(e,t,n);let r=e.subscribe(e=>t.current.selector(e),(n,i)=>t.current.react(n,i,e.getState,()=>{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 kr(e){e.current.options.debugMode&&console.log(`[ποΈ useListen ποΈ] Detaching listener`),e.current.resubscribe=c,e.current.unsubscribe(),e.current.unsubscribe=c,e.current.isActive=!1}function Ar(e,t,n){return{selector:e,react:t,isActive:!1,options:jr(n),resubscribe:c,unsubscribe:c}}function jr(e){return typeof e==`function`?{equalityFn:e}:e??Tr}function Mr(e){return typeof e==`function`?Tr.enabled:e?.enabled??Tr.enabled}function Nr(e,t,n,r){e.current.selector=t,e.current.react=n,typeof r==`function`?e.current.options.equalityFn=r:r&&(e.current.options=r??Tr)}const Pr=Symbol();function Fr(t){let n=(0,e.useRef)(Pr);return n.current===Pr&&(n.current=t()),n.current}exports.QueryStatuses=U,exports.StoresError=j,exports.applyStateUpdate=ce,exports.configureStores=R,exports.createBaseStore=yr,exports.createDerivedStore=br,exports.createQueryStore=xr,exports.createStoreActions=we,exports.createVirtualStore=Sr,exports.deepEqual=Oe,exports.defaultRetryDelay=se,exports.destroyStore=he,exports.destroyStores=ge,exports.getQueryKey=zn,exports.getStoreName=_e,exports.hasGetSnapshot=be,exports.identity=a,exports.isDerivedStore=xe,exports.isPersistedStore=Se,exports.isQueryStore=J,exports.isVirtualStore=Ce,exports.nullObject=o,exports.parseQueryKey=Bn,exports.queryParam=Ln,exports.replacer=de,exports.reviver=fe,exports.shallowEqual=ke,exports.time=W,exports.useListen=Er,exports.useStableValue=Fr;
|
package/dist/native/index.mjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{useLayoutEffect as e,useRef as t,useSyncExternalStore as n,useDebugValue as r}from"react";import{Platform as o,unstable_batchedUpdates as i}from"react-native";var s=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),c="ios"===o.OS;o.OS;var a="development"===process.env.NODE_ENV,u="test"===process.env.NODE_ENV;function l(e){return e}function f(){return{__proto__:null}}function d(){}Object.freeze(Object.create(null));var y=Symbol("empty selection"),p=Object.is;function g(e,t){return n=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===y?h(e):e.value}(e),t(r=>{e.latestSnapshot=r,e.latestSource=t;const o=e.committedValue;if(o===y||e.committedSource!==t)return void n();const i=e.committedSelector,s=e.committedEqualityFn;if(e.selector===i&&e.equalityFn===s){const t=i(r);if(s===p?p(o,t):s(o,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=s,e.valueSelector=i,e.valueSnapshot=r,void n()}if(e.source!==t)return void n();const c=e.value;if(c===y)return;const a=e.selector(r),u=e.equalityFn(c,a);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=m(e,r,u?c:a),u||n()}))}function h(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==y)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return b(e,t)}function b(e,t){const n=e.value;if(n!==y&&p(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;const r=e.selector(t);if(n!==y&&(e.equalityFn===p?p(n,r):e.equalityFn(n,r)))return m(e,t,n);const o=e.committedValue;return o!==y&&o!==n&&e.committedSource===e.source&&(e.equalityFn===p?p(o,r):e.equalityFn(o,r))?m(e,t,o):m(e,t,r)}function m(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function S(e,o,i,s){return Object.assign(function(c,a){return function(e,o,i,s,c=p){const a=t(null);let u=e,l=o,f=i;if(s){let t=a.current;null===t&&(t=function(e,t,n,r,o){const i={committedEqualityFn:o,committedSelector:r,committedSource:e,committedValue:y,equalityFn:o,getSelectedServerSnapshot:()=>function(e){return b(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(i),getSelectedSnapshot:()=>h(i),getServerStoreSnapshot:n,getStoreSnapshot:t,latestSnapshot:y,latestSource:y,selector:r,selectedSource:e,selectedSubscribe:()=>d,source:e,value:y,valueEqualityFn:o,valueSelector:r,valueSnapshot:y};return i.selectedSubscribe=g(i,e),i}(e,o,i,s,c),a.current=t),function(e,t,n,r,o,i){e.source===t&&e.getStoreSnapshot===n||(e.latestSnapshot=y),e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=o,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=g(e,t))}(t,e,o,i,s,c),u=t.selectedSubscribe,l=t.getSelectedSnapshot,f=void 0===i?void 0:t.getSelectedServerSnapshot}const m=n(u,l,f);return r(m),m}(e.subscribe,o,i,c,a??s)},e)}function v(e){let t;function n(){if(t)return t;try{const n=function(e){const{createMMKV:t,MMKV:n}=s("react-native-mmkv");if("function"==typeof t)return t({id:e});if("function"==typeof n)return new n({id:e});throw new Error("[stores]: react-native-mmkv module does not export MMKV/createMMKV.")}(e);let r;if("function"==typeof n.delete?r=n.delete.bind(n):"function"==typeof n.remove&&(r=n.remove.bind(n)),"function"!=typeof r)throw new Error("[stores]: Storage instance does not conform to expected interface");const o={clearAll:n.clearAll.bind(n),contains:n.contains.bind(n),delete:r,get:n.getString.bind(n),getAllKeys:n.getAllKeys.bind(n),set:n.set.bind(n)};t=o}catch(e){throw new Error("[stores] react-native-mmkv could not be loaded.\n\nPersisted stores require a storage backend. Either:\n - Install MMKV (the default): yarn add react-native-mmkv\n - Or provide a custom adapter via configureStores()\n"+(e instanceof Error?`\n${e.message}`:""))}return function(e){if(!e||"function"!=typeof e.get||"function"!=typeof e.set||"function"!=typeof e.delete||"function"!=typeof e.clearAll)throw new Error("[stores]: Storage instance does not conform to expected interface")}(t),t}return{clearAll:()=>n().clearAll(),contains:e=>n().contains(e),delete:e=>n().delete(e),get:e=>n().get(e),getAllKeys:()=>n().getAllKeys(),set:(e,t)=>n().set(e,t)}}var w={debug:(e,t)=>{a&&console.debug(e,t)},error:(e,t)=>{a&&!u&&console.error(e,t)},info:(e,t)=>{a&&console.info(e,t)},warn:(e,t)=>{a&&console.warn(e,t)}},O=Object.prototype.hasOwnProperty;function q(e,t){return O.call(e,t)}function j(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function F(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}var _=class extends Error{constructor(e,t){super(e),this.name="StoresError",void 0!==t&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function A(e){return e instanceof Error?e:new Error(String(e))}var I,C,k,T=class{destroy(){}publish(){}},E=class{constructor(){this.sessionId="noop"}register(e){return new T}},M=!1;function z(e){var t;a&&function(){if(M)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,w=t),C??(C=function(e){return e?.queryStoreDefaults?{queryStoreDefaults:e.queryStoreDefaults}:void 0}(e)),k??(k=P(e))}function D(){return k??(k=P(void 0))}function K(){M=!0}function P(e){return{storage:e?.storage??v(e?.storageKeyPrefix??"stores:"),syncEngine:e?.syncEngine??(I||(I=new E),I)}}var x,R={Error:"error",Idle:"idle",Loading:"loading",Success:"success"},$={ms:e=>e,seconds:e=>1e3*e,minutes:e=>6e4*e,hours:e=>36e5*e,days:e=>864e5*e,weeks:e=>6048e5*e,infinity:1/0,zero:0};function L(e,t){const n=t?.baseDelay??$.seconds(5),r=t?.maxDelay??$.minutes(5);return Math.min(n*Math.pow(2,e),r)}function N(e){return JSON.stringify(V(e))}function V(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,n)=>{const r=e[n];return t[n]=j(r)?V(r):r,t},{__proto__:null})}function H(e,t){return!0===t[1]?e(t[0],!0):e(t[0])}function W(e,t,n){if(!0===n)return U(t)?t(e):t;const r=U(t)?t(e):t;return Object.is(r,e)?e:F(e)&&F(r)?{...e,...r}:r}function U(e){return"function"==typeof e}function J(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function B(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}var Q=Object.freeze({QueryStore:Symbol("queryStore"),VirtualStore:Symbol("virtualStore")});function G(e,t){ee(e)?e.getState().reset(t?.clearQueryCache):function(e){return"destroy"in e}(e)&&e.destroy()}function X(e,t){for(const n of Array.isArray(e)?e:Object.values(e))n&&!t?.skipDestroy?.(n)&&G(n,t)}function Y(e){const t="function"==typeof(n=e)?n.name:"";var n;return ne(e)?e.persist.getOptions().name??t:t}function Z(e){return"getSnapshot"in e}function ee(e){return Q.QueryStore in e}function te(e){return"flushUpdates"in e}function ne(e){return!(!("persist"in e)||!e.persist)&&"string"==typeof e.persist.getOptions().name}function re(e){return Q.VirtualStore in e}function oe(e,t){const n=function(e){const t=e.getState(),n={__proto__:null},r=n;if(a&&("object"!=typeof t||null===t))throw new Error("[createStoreActions]: State is not an object");if(re(e))for(const n in t)se(t,n)&&(r[n]=ie(e,n));else for(const e in t)se(t,e)&&(r[e]=t[e]);return n}(e);return t?Object.assign(n,t):n}function ie(e,t){return function(...n){const r=e.getState()[t];if("function"==typeof r)return r(...n);throw new Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function se(e,t){return"function"==typeof e[t]}function ce(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!(r in t)||!ce(e[r],t[r]))return!1;return!0}function ae(e,t){if("object"!=typeof e||null==e||"object"!=typeof t||null==t)return e===t;if(Object.is(e,t))return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function ue(e,t){const n=Object.prototype.hasOwnProperty;function r(e,t){for(const n of e.keys())if(ue(n,t))return n}let o,i,s;if(e===t)return!0;if(e&&t&&(o=e.constructor)===t.constructor){if(o===Date)return e.getTime()===t.getTime();if(o===RegExp)return e.toString()===t.toString();if(o===Array){if((i=e.length)===t.length)for(;i--&&ue(e[i],t[i]););return-1===i}if(o===Set){if(e.size!==t.size)return!1;for(let n of e){if(s=n,s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!t.has(s))return!1}return!0}if(o===Map){if(e.size!==t.size)return!1;for(let n of e){if(s=n[0],s&&"object"==typeof s&&(s=r(t,s),!s))return!1;if(!ue(n[1],t.get(s)))return!1}return!0}if(o===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(o===DataView){if((i=e.byteLength)===t.byteLength)for(;i--&&e.getInt8(i)===t.getInt8(i););return-1===i}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){const n=e,r=t;if((i=n.byteLength)===r.byteLength)for(;i--&&n[i]===r[i];);return-1===i}if(!o||"object"==typeof e){i=0;for(const r in e){if(n.call(e,r)&&++i&&!n.call(t,r))return!1;if(!(r in t)||!ue(e[r],t[r]))return!1}return Object.keys(t).length===i}}return e!=e&&t!=t}function le(e){let t;const n=new Set;function r(...e){const r=W(t,...e);if(Object.is(r,t))return;const o=t;t=r,n.forEach(e=>e(t,o))}function o(){return t}const i={getInitialState:function(){return s},getState:o,setState:r,subscribe:function(...e){return 1===e.length?c(e[0]):function(e,n,r){const o=r?.equalityFn??Object.is;let i=e(t);return r?.fireImmediately&&n(i,i),c(function(t){const r=e(t);if(o(i,r))return;const s=i;i=r,n(r,s)})}(e[0],e[1],e[2])}},s=t=e(r,o,i);return i;function c(e){return n.add(e),()=>{n.delete(e)}}}function fe(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}function de(e){return{...e,merge:e.merge??ye,skipHydration:e.skipHydration??!1}}function ye(e,t){return void 0===e?t:{...t,...e}}function pe(){let e,t,n=!1;return{complete:function(){!n&&e&&(n=!0,e(),e=void 0,t=void 0)},isHydrated:function(){return n},fail:function(r){!n&&t&&(n=!0,t(r),t=void 0,e=void 0)},promise:new Promise((n,r)=>{e=n,t=r})}}var ge=Math.max,he=Math.min;function be(e,t=0,n={}){let r,o,i,s,c,a,u=0,l=!1,f=!1,d=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function y(t){const n=r,i=o;return r=o=void 0,u=t,s=n?e.apply(i,n):e.apply(i),s}function p(e){const n=e-(a??0);return void 0===a||n>=t||n<0||f&&void 0!==i&&e-u>=i}function g(){const e=me();if(p(e))return h(e);c=setTimeout(g,function(e){const n=t-(e-(a??0));return f&&void 0!==i?he(n,i-(e-u)):n}(e))}function h(e){return c=void 0,d&&r?y(e):(r=o=void 0,s)}function b(...e){const n=me(),i=p(n);if(r=e,o=this,a=n,i){if(void 0===c)return function(e){return u=e,c=setTimeout(g,t),l?y(e):s}(a);if(f)return clearTimeout(c),c=setTimeout(g,t),y(a)}return void 0===c&&(c=setTimeout(g,t)),s}return t=Se(t)||0,function(e){const t=typeof e;return null!==e&&("object"===t||"function"===t)}(n)&&(l=!!n.leading,f="maxWait"in n,i=f?ge(Se(n.maxWait)||0,t):void 0,d="trailing"in n?!!n.trailing:d),b.cancel=function(){void 0!==c&&clearTimeout(c),u=0,r=a=o=c=void 0},b.flush=function(){return void 0===c?s:h(me())},b}function me(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}function Se(e){if("number"==typeof e)return e;if("symbol"==typeof e||void 0===e)return NaN;if("object"==typeof e&&null!==e){const t="function"==typeof e.valueOf?e.valueOf():e;e="object"==typeof t?t+"":t}return"string"!=typeof e?0===e?e:+e:(e=e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),/^0b[01]+$/i.test(e)?parseInt(e.slice(2),2):/^0o[0-7]+$/i.test(e)?parseInt(e.slice(2),8):/^[-+]0x[0-9a-f]+$/i.test(e)?NaN:+e)}function ve(e){if(!j(e))return e;const t={__proto__:null},n=Object.keys(e);for(let r=0;r<n.length;r++){const o=n[r],i=e[o];"function"!=typeof i&&(t[o]=i)}return t}var we=u?0:$.seconds(c?3:5);function Oe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??ve,c=t.deserializer??e.deserializer??je(o),a=t.serializer??e.serializer??Fe(o);function u(t,n,o){try{if(Ce(r))return;const c={state:s(n),version:o},u=Ae(r,i,c),l=a(c);try{e.set(t,l),Ie(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}const l=void 0!==n?be(u,n,{leading:!1,maxWait:n,trailing:!0}):u;return{getItem:t=>{const n=e.get(t);return void 0===n?null:c(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||l(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function qe(e,t,n,r){const o=!(t.deserializer||t.serializer||e.deserializer||e.serializer),i="object"==typeof t.sync&&!0===(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata),s=t.partialize??ve,c=t.deserializer??e.deserializer??je(o),a=t.serializer??e.serializer??Fe(o);async function u(t,n,o){try{if(Ce(r))return;const c={state:s(n),version:o},u=Ae(r,i,c),l=a(c);try{await e.set(t,l),Ie(r,u)}catch(e){w.error(new _("[createBaseStore]: Failed to persist store data",e))}}catch(e){w.error(new _("[createBaseStore]: Failed to serialize persisted store data",e))}}const l=void 0!==n?be(u,n,{leading:!1,maxWait:n,trailing:!0}):function(e){let t,n=null;return function(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}}(u);return{getItem:async t=>{const n=await e.get(t);return void 0===n?null:c(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await l(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){w.error(new _("[createBaseStore]: Failed to delete persisted store data",e))}}}}function je(e){return t=>{if("string"!=typeof t)throw new _("[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.");return function(e,t){try{return JSON.parse(e,t?B:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to deserialize persisted store data",e)),e}}(t,e)}}function Fe(e){return t=>function(e,t){try{return JSON.stringify(e,t?J:void 0)}catch(e){throw w.error(new _("[createBaseStore]: Failed to serialize store data",e)),e}}(t,e)}var _e=Object.freeze({shouldClear:!1});function Ae(e,t,n){if(!t||!e)return _e;const r=e.getFieldTimestampSnapshot();return function(e,t){const n=e.getSessionId(),r=e.getTimestamp();void 0!==n&&void 0!==r&&(t.syncMetadata={origin:n,timestamp:r})}(e,n),n.syncMetadata?r&&Object.keys(r).length>0?(n.syncMetadata.fields=r,{fieldSnapshot:r,shouldClear:!0}):(delete n.syncMetadata.fields,{fieldSnapshot:r,shouldClear:!1}):{fieldSnapshot:r,shouldClear:!1}}function Ie(e,t){e&&t.shouldClear&&t.fieldSnapshot&&Object.keys(t.fieldSnapshot).length&&e.clearFieldTimestamps(t.fieldSnapshot)}function Ce(e){return!!e&&!!e.getIsApplyingRemote()}var[ke,Te]=[0,1];function Ee(e,t,n){if(!e)return!0;const r=e[ke],o=e[Te];return!(t<r)&&(t>r||n>o)}function Me(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function ze(e,t){if(!a)return!0;if(null===e||null===t)return e===t;const n=typeof e;return n===typeof t&&("object"!==n||Object.prototype.toString.call(e)===Object.prototype.toString.call(t))}function De(e){if(null===e)return"null";const t=typeof e;return"object"===t?Object.prototype.toString.call(e):t}function Ke(e,t){if(K(),!t)return le(e);const n=t.storageKey,r="string"==typeof n,o=r?t.storage??D().storage:void 0,i=function(e,t){if(!e)return null;const n="object"==typeof e,r=n?e.key??t:!0===e?t:e;if(!r)throw new _("[createBaseStore]: sync requires a key to be specified either directly or via storageKey");return n?{...e,key:r}:{key:r}}(t.sync,n),s=i?function(e,t,n){const r=t.engine??D().syncEngine,o=function(e){let t,n,r,o=!1;return{isAsync:e,clearFieldTimestamps:function(e){if(e&&r){for(const t of Object.entries(e)){const e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}},getFieldTimestampSnapshot:function(){if(r)return{...r}},getIsApplyingRemote:()=>o,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:function(e){if(r)for(const t of Object.entries(e)){const e=t[0],n=t[1],o=r[e];(void 0===o||n>o)&&(r[e]=n)}else r={...e}},onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>o=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}(n);return{stateCreator:(i,s,c)=>{const a=new Map,u=[],l=[];let f=null,d=!1,y=!1,p=0,g=null,h=[],b=Promise.resolve(),m=!n;function S(e,t){if(o?.setSessionId&&o?.setTimestamp&&r.sessionId&&(o.setSessionId(r.sessionId),o.setTimestamp(e),o.mergeFieldTimestamps&&t.length>0)){const n={__proto__:null};for(const r of t)n[String(r)]=e;o.mergeFieldTimestamps(n)}}function v(e,t){if(d||!g)return t?i(e,t):i(e);const n=function(){const e=Date.now(),t=e>p?e:p+1;return p=t,t}();let o=[],s={__proto__:null};const c=r=>{const i=W(r,e,t);for(const e of h)Object.is(i[e],r[e])||(o.push(e),s[e]=i[e]);return o.length&&S(n,o),i},u=t?i(c,!0):i(c);function b(){o.length&&function(e){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);f&&y?f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values}):l.push(e)}({keys:o,replace:t??!1,values:s,timestamp:n})}return fe(u)?u.finally(b):(b(),u)}const O=c.setState;c.setState=v;const q=e(v,s,c);if(h=t.fields??function(e){const t=[];for(const n of Object.entries(e)){if("function"==typeof n[1])continue;const e=n[0];t.push(e)}return t}(q),!h.length)return q;async function j(e){p=Math.max(p,e.timestamp);const n={__proto__:null},r=s(),i=e.timestamp;let c;if(e.replace)for(const t of h)Me(t,e.values)||Ee(a.get(t),i,e.sessionId)&&(c??(c=[])).push(t);for(const o of h){if(!Me(o,e.values))continue;if(!g?.has(o))continue;if(!Ee(a.get(o),i,e.sessionId))continue;const s=t.merge?.[o];if(s){const t=e.values[o],c=r[o];if(void 0!==t){const u=s(t,c,r,e.values),l=void 0!==c?c:t;if(!ze(u,l))return void w.error(new _(`[sync] Merge function for field "${String(o)}" returned ${De(u)} but expected ${De(l)}`));n[o]=u,a.set(o,[i,e.sessionId])}}else n[o]=e.values[o],a.set(o,[i,e.sessionId])}if(Object.keys(n).length>0||c?.length){d=!0,o&&o.setIsApplyingRemote(!0);try{if(e.replace){const e={...r};let t=!1;if(c?.length){t=!0;for(const t of c)delete e[t],a.delete(t)}for(const r in n){if(!Object.prototype.hasOwnProperty.call(n,r))continue;const o=n[r];void 0!==o&&(Object.is(e[r],o)||(t=!0),e[r]=o)}if(!t)return;await(o.setWithoutPersist??O)(e,!0)}else await(o.setWithoutPersist??O)(n)}finally{d=!1,o&&o.setIsApplyingRemote(!1)}}}function F(e){n?b=b.then(()=>j(e)):j(e)}if(g=new Set(h),f=r.register({apply:e=>{m?F(e):u.push(e)},fields:h,getState:s,key:t.key}),f?.onFirstSubscribe||f?.onLastUnsubscribe){let e=0;const t=c.subscribe;c.subscribe=(...n)=>{e||f.onFirstSubscribe?.(),e+=1;const r=1===n.length?t(n[0]):t(n[0],n[1],n[2]);return()=>{r(),e-=1,e||queueMicrotask(()=>{e||f.onLastUnsubscribe?.()})}}}function A(){y=!0,function(){if(f&&l.length){for(const e of l){const t=r.sessionId;for(const n of e.keys)a.set(n,[e.timestamp,t]);S(e.timestamp,e.keys),f.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}()}function I(){m=!0,function(){if(!u.length)return;const e=u.slice();u.length=0;for(const t of e)F(t)}()}return n?(o.onHydrationComplete=A,o.onHydrationFlushEnd=I):f.onHydrated?(f.onHydrated(A),I()):(A(),I()),q},syncContext:o}}(e,i,o?.async??!1):void 0,c=s?.stateCreator??e;if(!r)return le(c);const a=function(e,t,n){const r=t??e.storage??D().storage,o=(e.sync?void 0:e.persistThrottleMs??we)||void 0,i=e.version??0;return r.async?{async:!0,persistStorage:qe(r,e,o,n),version:i}:{async:!1,persistStorage:Oe(r,e,o,n),version:i}}(t,o,s?.syncContext),u=a.async?function(e){let t,n,r,o=!1;return{hydrationPromise:()=>o?t?.promise??n??(n=Promise.resolve()):(t||(t=pe()),t.promise),stateCreator:(n,i,s)=>{let c;return r=()=>{if(c?.length){for(const e of c)H(s.setState,e);c=void 0}},e(function(...e){return o?H(n,e):(t||(t=pe()),c||(c=[]),c.push(e),t.promise)},i,s)},wrapOnRehydrateStorage:(e,n)=>i=>{const s=e?.(i);return(e,i)=>{o=!0,n?.onHydrationComplete?.(),r&&r(),n?.onHydrationFlushEnd?.(),i?t?.fail(A(i)):t?.complete(),s?.(e,i)}}}}(c):void 0,l=u?u.wrapOnRehydrateStorage(t.onRehydrateStorage,s?.syncContext):t.onRehydrateStorage,f=le(function(e,t){return(n,r,o)=>{let i,s,c,a=de(t),u=!1,l=0;function f(){return a.storage.setItem(a.name,r(),a.version)}const d=o.setState;o.setState=function(...e){return H(d,e),f()};const y=e(function(...e){return H(n,e),f()},r,o);function p(){const e=function(){const e=++l;return u=!1,s?.forEach(e=>e(r()??y)),e}(),t=a.onRehydrateStorage?.(r()??y);try{const n=a.storage.getItem(a.name);return fe(n)?n.then(n=>g(e,n,t)).catch(n=>m(e,t,n)):g(e,n,t)}catch(n){m(e,t,n)}}return o.getInitialState=()=>y,Object.assign(o,{persist:{clearStorage:()=>{a.storage.removeItem(a.name)},getOptions:()=>a,hasHydrated:()=>u,onFinishHydration:e=>(c??(c=new Set),c.add(e),()=>{c?.delete(e),0===c?.size&&(c=void 0)}),onHydrate:e=>(s??(s=new Set),s.add(e),()=>{s?.delete(e),0===s?.size&&(s=void 0)}),rehydrate:p,setOptions:e=>{a=de({...a,...e,storage:e.storage??a.storage})}}}),a.skipHydration||p(),i??y;function g(e,t,n){const r=function(e,t){if(!t)return{migrated:!1,state:void 0};if("number"!=typeof t.version||t.version===e.version)return{migrated:!1,state:t.state};if(!e.migrate)return console.error("State loaded from storage couldn't be migrated since no migrate function was provided"),{migrated:!1,state:void 0};const n=e.migrate(t.state,t.version);return fe(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}(a,t);return fe(r)?r.then(t=>h(e,t,n)).catch(t=>m(e,n,t)):h(e,r,n)}function h(e,t,o){const s=function(e,t){if(e!==l)return;const o=a.merge(t.state,r()??y);return i=o,n(o,!0),t.migrated?f():void 0}(e,t);if(fe(s))return s.then(()=>b(e,o));b(e,o)}function b(e,t){if(e!==l)return;t?.(i,void 0);const n=r();i=n,u=!0,c?.forEach(e=>e(n))}function m(e,t,n){e===l&&t?.(void 0,n)}}}(u?(e,t,n)=>(s&&(s.syncContext.setWithoutPersist=n.setState),u.stateCreator(e,t,n)):c,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:l,storage:a.persistStorage,version:a.version}));return u?Object.assign(f,{persist:Object.assign(f.persist,{hydrationPromise:u.hydrationPromise})}):f}function Pe(e,t,n="s"){return 1===t?e:`${e}${n}`}var xe=i,Re=!1,$e=!1,Le=new Map,Ne=new Map,Ve=new Map,He=null,We=1/0;function Ue(){return Re}function Je(){return He}function Be(){Re||(Re=!0,$e||($e=!0,queueMicrotask(()=>{$e=!1,xe(()=>{for(;Ne.size>0;){const e=We,t=Ve.get(e);if(t){Ve.delete(e);for(const e of t)Ne.delete(e);He=e;for(const e of t)e();if(He=null,Ve.size>0){We=1/0;for(const e of Ve.keys())e<We&&(We=e)}else We=1/0}else{We=1/0;for(const e of Ve.keys())e<We&&(We=e)}}for(;Le.size>0;){const e=Array.from(Le.values());Le.clear();for(const t of e)t()}}),Re=!1,He=null,Ne.clear(),Ve.clear(),We=1/0})))}function Qe(e,t){Re&&Le.set(e,t)}var Ge=Symbol("stores.deriveProxy.unwrap");function Xe(e,t,n){const r=t.get(e);if(void 0!==r)return r;const o=function(e,t,n,r=[]){return e&&"object"==typeof e?Ye(e,r,t,n,new WeakSet,new WeakMap):(n(t,r,!0),e)}(Z(e)?e.getSnapshot():e.getState(),e,n);return t.set(e,o),o}function Ye(e,t,n,r,o,i){return new Proxy(e,{get(s,c,a){if(c===Ge)return r(n,t,!0),s;if(o.has(s))return Reflect.get(s,c,a);if("__proto__"===c||"symbol"==typeof c)return c===Symbol.iterator&&(r(n,t,!0),o.add(s)),Reflect.get(s,c,a);const u=Reflect.get(s,c,s),l=String(c),f=t.concat(l);if("function"==typeof u)return Object.prototype.hasOwnProperty.call(s,c)?function(...e){return r(n,f,!0,{args:e.length?e:void 0}),Reflect.apply(u,s,e)}:(r(n,t,!0),u.bind(e));const d=!!u&&"object"==typeof u;return r(n,f,!d),d?(i.has(u)||i.set(u,Ye(u,f,n,r,o,i)),i.get(u)):u},getOwnPropertyDescriptor:(e,i)=>(r(n,t,!0),o.add(e),Reflect.getOwnPropertyDescriptor(e,i)),has:(e,o)=>(r(n,t,!0),Reflect.has(e,o)),ownKeys:e=>(r(n,t,!0),o.add(e),Reflect.ownKeys(e))})}function Ze(e,t){if(!e||"object"!=typeof e)return e;const n=function(e){const t=Reflect.get(e,Ge);return t&&"object"==typeof t?t:void 0}(e);return n||(Array.isArray(e)?function(e,t){const n=tt(e,t);if(n)for(let t=0;t<e.length;t++)et(e,String(t),n)}(e,t):j(e)&&function(e,t){const n=tt(e,t);if(n)for(const t of Reflect.ownKeys(e))et(e,t,n)}(e,t),e)}function et(e,t,n){const r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!("value"in r))return;const o=Ze(r.value,n);o!==r.value&&(r.value=o,Reflect.defineProperty(e,t,r))}function tt(e,t){const n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}var nt=Object.freeze([]);function rt(){const e=new Map;return{buildProxySubscriptions(t,n,r,o){const i=new Set;for(const t of e)it(t[1],t[0],[],0,i,r);!1!==o?.(i)&&function(e,t,n){for(const n of e){const e=n.invocation?ut(n.path,n.invocation):at(n.path);t(n.store,e,n.path)}n&&function(e){const t=e.size;console.log(`[π‘ ${t} ${Pe("Proxy Subscription",t)} π‘]:`,JSON.stringify(Array.from(e).map(e=>{const t="name"in(n=e.store)&&"string"==typeof n.name?n.name:"store";var n;const r=e.path.join(".");if(!e.invocation)return r?`$(${t}).${r}`:`$(${t})`;const o=e.invocation.args?.length??0;return`$(${t}).${r}${o?`(${o}_${Pe("arg",o)})`:"()"}`}),null,2))}(e)}(i,t,n)},reset(){e.clear()},trackPath(t,n,r,o){let i=e.get(t);i||(i={__proto__:null},e.set(t,i)),ot(i,n,0,r,o)}}}function ot(e,t,n,r,o){if(n===t.length)return r&&(e.isLeaf=!0),void(o&&function(e,t){const n=e.invocation;if(!n)return void(e.invocation=t);if(st(n,t))return;const r=e.extraInvocations;if(r){for(let e=0;e<r.length;e++)if(st(r[e],t))return;r.push(t)}else e.extraInvocations=[t]}(e,o));e.children||(e.children={__proto__:null});const i=t[n];let s=e.children?.[i];s||(s={__proto__:null},e.children[i]=s),ot(s,t,n+1,r,o)}function it(e,t,n,r,o,i=2){const s=e.children;if(!s)return void ct(e,t,n,o);const c=Object.keys(s),a=c.length;if(0!==a)if(e.isLeaf||r>=i&&a>1){ct(e,t,n,o);for(const e of c){const c=s[e];c.invocation&&it(c,t,[...n,e],r+1,o,i)}}else if(r<i&&a>1&&!e.isLeaf)for(const e of c)it(s[e],t,[...n,e],r+1,o,i);else{if(1===a){const e=c[0];return void it(s[e],t,[...n,e],r+1,o,i)}ct(e,t,n,o)}else ct(e,t,n,o)}function st(e,t){const n=e.args,r=t.args,o=n?.length??0;if(o!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<o;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function ct(e,t,n,r){const o=e.isLeaf??!1,i=e.invocation;if(!i)return void r.add({store:t,path:n,isLeaf:o});r.add({store:t,path:n,invocation:i,isLeaf:o});const s=e.extraInvocations;if(s)for(let e=0;e<s.length;e++)r.add({store:t,path:n,invocation:s[e],isLeaf:o})}function at(e){return t=>lt(t,e)}function ut(e,t){const n=e.slice(0,-1),r=e[e.length-1];return e=>{const o=lt(e,n),i=o&&"object"==typeof o?Reflect.get(o,r):void 0;return"function"==typeof i?Reflect.apply(i,o,t.args??nt):void 0}}function lt(e,t){let n=e;for(const e of t){if(!n||"object"!=typeof n)return n;n=Reflect.get(n,e)}return n}var ft=Symbol(),dt=Object.freeze({equalityFn:Object.is,isDerivedStore:!0});function yt(e,t=Object.is){const{debounceOptions:n,debugMode:r,equalityFn:o,keepAlive:i,lockDependencies:s}="function"==typeof(f=t)?{debounceOptions:void 0,debugMode:!1,equalityFn:f,keepAlive:!1,lockDependencies:!1}:{debounceOptions:f.debounce,debugMode:(a&&f.debugMode)??!1,equalityFn:f.equalityFn??Object.is,keepAlive:f.keepAlive??!1,lockDependencies:f.lockDependencies??!1},c=String(pt+=1),u=new Set;var f;i&&u.add(gt);const d=new Set;let y,p,g=ft,h=!1,b=!0,m=!0,S=0,v=!1,w=null,O=ft;function q(e,t,n){return m&&u.size?t?(d.add(e.subscribe(t,z,n?{equalityFn:n,isDerivedStore:!0}:dt)),t(Z(e)?e.getSnapshot():e.getState())):(y||(y=new WeakMap),p||(p=rt()),Xe(e,y,p.trackPath)):(t??l)(Z(e)?e.getSnapshot():e.getState())}function j(e){for(const t of d)t(e);d.clear()}let F=!0;function _(){if(!b&&ht(g))return g;b=!1,m&&j(!0);const t=g,n=ht(t);g=function(t){F=!0;const n=g,i=e(t),s=p?Ze(i):i;return ht(n)&&o(n,s)?(r&&console.log("[π₯· Derive Complete π₯·]: No change detected"),F=!1,n):s}(q);const i=r&&(!n||"verbose"===r&&m);if(i){n?"verbose"===r&&console.log("[π Rebuilding Subscriptions π]: Createdβ¦"):console.log("[π Initial Derive Complete π]: Createdβ¦");const e=d.size;console.log(`[π― ${e} ${Pe("Selector Subscription",e)} π―]`)}return p&&m&&(p.buildProxySubscriptions((e,t)=>{d.add(e.subscribe(t,z,dt))},i),y=void 0,p.reset(),s&&(p=void 0)),F&&n&&function(e,t){const n=function(){const e=u.has(gt)?u.size-1:u.size;return S>0&&S<e}(),o=!S||n,i=n||null!==Je()||Ue()&&o;n&&Be(),r&&console.log(`[π» Derive Complete π»]: Notifying ${u.size} ${Pe("watcher",u.size)}`);for(const t of u){if("function"==typeof t||!t.isDerivedWatcher)continue;const n=t.selector(e);if(!t.equalityFn(t.currentSlice,n)){const e=t.currentSlice;t.currentSlice=n,t.listener(n,e)}}i?v||(v=!0,ht(O)||(O=t),Qe(c,I)):A(e,t)}(g,t),s&&(m=!1),g}function A(e,t){for(const n of u)if("function"==typeof n)n(e,t);else if(!n.isDerivedWatcher){const t=n.selector(e);if(!n.equalityFn(n.currentSlice,t)){const e=n.currentSlice;n.currentSlice=t,n.listener(t,e)}}}function I(){if(!u.size)return;if(b&&!S&&_(),!ht(g))return;const e=ht(O)?O:g;A(g,e),v=!1,O=ft}const C=n?be(T,"number"==typeof n?n:n.delay,"number"==typeof n?{leading:!1,maxWait:n,trailing:!0}:n):void 0,k=C??(()=>{h||(h=!0,queueMicrotask(T))});function T(){h=!1,u.size?b&&_():K()}function E(e){e||C&&b?queueMicrotask(()=>{u.size||K()}):K()}function M(){T(),w=null}function z(){if(!b){if(b=!0,!C){if(S){Be();const e=Je(),t=null===e?0:e+1;if(null!==w&&t<=w)return;return w=t,void function(e,t){if(!Re)return;const n=t<0?0:0|t,r=Ne.get(e);if(void 0===r){Ne.set(e,n);let t=Ve.get(n);return t||(t=new Set,Ve.set(n,t)),t.add(e),void(n<We&&(We=n))}if(n>r){const t=Ve.get(r);if(t&&(t.delete(e),0===t.size&&(Ve.delete(r),r===We))){We=1/0;for(const e of Ve.keys())e<We&&(We=e)}Ne.set(e,n);let o=Ve.get(n);o||(o=new Set,Ve.set(n,o)),o.add(e),n<We&&(We=n)}}(M,t)}if(Ue())return void(v||(v=!0,ht(g)&&(O=g),Qe(c,I)))}w=null,k()}}function D(){return b||!ht(g)?u.size>0?_():e(q):g}function K(e=!0){i&&e||(C?.cancel(),j(),u.clear(),S=0,p=void 0,y=void 0,m=!0,h=!1,b=!0,g=ft,v=!1,O=ft,w=null)}return{destroy:()=>K(!1),flushUpdates:function(){u.size&&(C?C.flush():b&&_())},getSnapshot:function(){if(!ht(g)){u.add(gt);const e=_();return u.delete(gt),e}return h&&T(),g},getState:D,subscribe:function(...e){if(1===e.length){const t=e[0];return u.add(t),1!==u.size||ht(g)||D(),()=>{u.delete(t),u.size||E(!1)}}const[t,n,r]=e,o=r?.equalityFn??Object.is,i=r?.isDerivedStore??!1,s={currentSlice:void 0,equalityFn:o,isDerivedWatcher:i,listener:n,selector:t};return u.add(s),s.currentSlice=t(D()),i&&(S+=1),r?.fireImmediately&&n(s.currentSlice,s.currentSlice),()=>{u.delete(s),i&&(S-=1),u.size||E(i)}},getInitialState:()=>{throw new Error("[createDerivedStore]: getInitialState() is not available on derived stores.")},setState:()=>{throw new Error("[createDerivedStore]: setState() is not available on derived stores.")}}}var pt=0;function gt(){}function ht(e){return e!==ft}var bt=class{constructor({disableAutoRefetching:e,initialEnabled:t}){this.count=0,this.enabled=!1,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,this.enabled=t,e&&(this.fetchThrottleMs=$.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}get(){return{enabled:this.enabled,lastSubscriptionTime:this.lastSubscriptionTime,subscriptionCount:this.count}}setEnabled(e){this.enabled=e}subscribe(){const e=0===this.count,t=null!==this.fetchThrottleMs&&null!==this.lastSubscriptionTime&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.onSubscribe?.(this.enabled,e,t),this.count+=1,this.lastSubscriptionTime=Date.now(),e=>{const t=1===this.count;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}},mt=new WeakMap,St=new WeakMap;function vt(e,t=wt,n=ue){return function(e,t,n){let r=St.get(e);r||(r=new Map,St.set(e,r));let o=r.get(t);o||(o=new Map,r.set(t,o));const i=o.get(n);if(i)return i;const[s,c,a]=qt(e,t,n),u=new Map,l=e=>new Proxy({__proto__:null},{get(t,n){if("value"===n){let t=c();const n=e.split(".");for(const e of n)e&&(t=t[e]);return t}const r="string"==typeof n?n:n.toString(),o=e?`${e}.${r}`:r,i=u.get(o);if(i)return i;const a=l(o);return mt.set(a,s),u.set(o,a),a},set(t,n,r){const o=e.split(".");return""===o[0]&&o.shift(),a(o,r),!0}}),f=l("");return s(()=>{}),mt.set(f,s),o.set(n,f),f}(e,t,n)}var wt=e=>e,Ot=(e,t,n)=>{if(!t.length)return n;const[r,...o]=t,i=e[r],s=Ot(i,o,n);if(ue(i,s))return e;const c=Array.isArray(e)?e.slice():{...e};return c[r]=s,c},qt=(e,t,n)=>{const r=new Set,o=Z(e);let i,s=t(o?e.getSnapshot():e.getState());return[c=>(r.size||(i=e.subscribe(t,e=>{s=e,r.forEach(e=>e())},{equalityFn:n,isDerivedStore:o})),r.add(c),()=>{r.delete(c),!r.size&&i&&(i(),i=void 0)}),()=>(r.size||(s=t(e.getState())),s),(n,r)=>{if(t!==wt)throw new Error("Cannot set a value with a selector");e.setState(e=>Ot(e,n,r),!0)}]};function jt(e){return mt.get(e)}var Ft={error:!0,lastFetchedAt:!0,queryCache:!0,queryKey:!0,status:!0,enabled:!1,fetch:!1,getCacheEntry:!1,getData:!1,getStatus:!1,isDataExpired:!1,isStale:!1,reset:!1},_t=Object.freeze({force:!0}),At=Object.freeze({once:!0}),It=Object.freeze({updateQueryKey:!0});function Ct(e,t,n,r){return r?Tt(r,n)?r:{...kt(e,t),...r}:kt(e,t)}function kt(e,t){const n=Object.assign({__proto__:null},t?.params);for(const t in e?.params){const r=e.params[t];r&&(n[t]=r.value)}return n}function Tt(e,t){if(!e)return!1;for(const n of t)if(!(n in e))return!1;return!0}function Et(e){return"function"==typeof e}function Mt(e){return!Et(e)}function zt(e,t){return n=>{const r={...n},o={__proto__:null};for(const e in r)q(r,e)&&e in Ft&&(Ft[e]&&(o[e]=r[e]),delete r[e]);return{...t?t(r):ve(r),...Dt(e,null,o)}}}function Dt(e,t,n){if(!n.queryCache)return n;const r=Date.now(),o=t??(e&&n.queryKey||null),i={__proto__:null};let s=!1;for(const e in n.queryCache){if(!q(n.queryCache,e))continue;const c=n.queryCache[e];c&&(r-(c.lastFetchedAt??c.errorInfo.lastFailedAt)<c.cacheTime||e===o)?!t&&c.errorInfo&&c.errorInfo.retryCount>0?(i[e]={...c,errorInfo:{...c.errorInfo,retryCount:0}},s=!0):i[e]=c:s=!0}return s?{...n,queryCache:i}:n}function Kt(){return Object.create(null)}function Pt(e,t,n){return new _(`[createQueryStore: ${e}]: ${t} failed`,n)}function xt(e){return function(...t){return!0===t[1]?e().setState(t[0],!0):e().setState(t[0])}}function Rt(e,t){const n=Ke(e,t);return S(n,n.getState,n.getInitialState,Object.is)}function $t(e,t=Object.is){const n=yt(e,t);return S(n,n.getSnapshot)}function Lt(e,t,n){const r=function(e,t,n){K();const r="function"==typeof t?t:Kt,o="object"==typeof t?t:n,i=function(e){return"string"==typeof e?.storageKey}(o)?o:void 0,s=x??(x=function(){const e={abortInterruptedFetches:!0,cacheTime:$.days(7),debugMode:!1,disableAutoRefetching:!1,keepPreviousData:!1,maxRetries:5,minStaleTime:!1,paramChangeThrottle:!1,retryDelay:L,staleTime:$.minutes(2),suppressStaleTimeWarning:!1},t=function(){if(C)return C}()?.queryStoreDefaults;return t?{...e,...t}:e}()),c=s.minStaleTime,{fetcher:l,onError:f,onFetched:d,setData:y,transform:p,abortInterruptedFetches:g=s.abortInterruptedFetches,cacheTime:h=s.cacheTime,debugMode:b=s.debugMode,disableAutoRefetching:m=s.disableAutoRefetching,disableCache:S=!1,enabled:v=!0,keepPreviousData:O=s.keepPreviousData,maxRetries:j=s.maxRetries,paramChangeThrottle:F=s.paramChangeThrottle,params:I,retryDelay:k=s.retryDelay,staleTime:T=s.staleTime,suppressStaleTimeWarning:E=s.suppressStaleTimeWarning}=e;let M="function"==typeof T?s.staleTime:T;a&&!1!==c&&!m&&!E&&M<c&&console.warn(`[createQueryStore${i?.storageKey?`: ${i.storageKey}`:""}] β Stale times under ${c/1e3} seconds are not recommended. Provided staleTime: ${M/1e3} seconds`);const z=new Error("[createQueryStore: AbortError] Fetch interrupted"),D="function"==typeof h,P=a&&b,V=e.params?Object.keys(e.params):[];let H=null,W=null,U=null,J=[],B=!1,G=!1,X=null,Y=null,Z=null,ee=null,te=null;const ne={enabled:"function"!=typeof v&&v,error:null,lastFetchedAt:null,queryCache:{},queryKey:"",status:R.Idle},re=new bt({disableAutoRefetching:m,initialEnabled:ne.enabled});function oe(){X&&(Y=null,X.abort(),X=null)}function ie(t,n,o){const s=o.setState;function c(e){const t="function"==typeof e;if(t||void 0!==e.enabled){let n;const r=s(r=>{const o=t?e(r):e,i=void 0!==o.enabled?o.enabled:r.enabled;return i!==r.enabled&&(n=()=>function(e,t){e!==t&&te!==t&&(te=t,re.setEnabled(t),t?queueMicrotask(()=>u.fetch(void 0,It)):(Z||g)&&(g&&oe(),Z&&(clearTimeout(Z),Z=null)))}(r.enabled,i)),o});return n?.(),r}return s(e)}function a(e,t){if(m||t?.skipStoreUpdates)return;if(M<=0||M===1/0)return;Z&&(clearTimeout(Z),Z=null);const r=N(e),o=n(),i=(S?ee===r&&o.lastFetchedAt:o.queryCache[r]?.lastFetchedAt)||null,s=i?M-(Date.now()-i):M;Z=setTimeout(()=>{const t=re.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,_t,!0)},s)}o.setState=c,re.init({onSubscribe:(r,o,i)=>{if(W||H||!I&&"function"!=typeof e.enabled&&"function"!=typeof e.staleTime){if(r)if(o){const e=kt(H,W),r=N(e),o=n();o.queryKey!==r&&t({queryKey:r}),o.isStale()?u.fetch(e,void 0,!0):a(e,void 0)}else m&&!i&&u.fetch(void 0,void 0,!0)}else B=!0},onLastUnsubscribe:e=>{Z&&(clearTimeout(Z),Z=null),g&&!e&&oe()}});const u={...r(c,n,o),...ne,async fetch(e,r,o=!1){const s=re.get();if(!r?.force&&!r?.skipStoreUpdates&&!s.enabled)return null;const b=n(),m=b.error,v=b.queryKey,q=b.status===R.Loading,F=Ct(H,W,V,e),I=N(F);if(q&&Y?.promise&&Y.key===I)return P&&console.log("[π Using Active Fetch π] for params:",JSON.stringify(F)),Y.promise;const C=r?.staleTime??M,T=!!r?.skipStoreUpdates,E="boolean"==typeof r?.updateQueryKey?r.updateQueryKey:!!o&&O,K=(o||v===I||E)&&!T;if(g&&K&&oe(),!r?.force){const e=b.lastFetchedAt,n=b.queryCache[I],o=n?.lastFetchedAt,i=n?.errorInfo,c=i&&i.retryCount>=j,u=(S?ee===I&&e:o)||null;if(u&&!(Date.now()-u>=C)&&(!i||c||T))return K&&!Z&&s.subscriptionCount>0&&0!==M&&M!==1/0&&a(F,r),E&&t(e=>e.queryKey!==I?{queryKey:I}:e),P&&console.log("[πΎ Returning Cached Data πΎ] for params:",JSON.stringify(F)),n?.data??null}K&&(Z&&(clearTimeout(Z),Z=null),!m&&q||t({error:null,status:R.Loading}),Y={key:I});const x=r?.cacheTime??(D?h(F):h);async function $(){const s=i?.storageKey||I;try{P&&(o||!e||Tt(e,V)?console.log("[π Fetching π] for params:",JSON.stringify(F)):console.log("[π Fetching with Partial Params π]\n","- Provided params:",`${JSON.stringify(e)}\n`,"- Filled in params:",`${JSON.stringify(Object.fromEntries(Object.keys(F).filter(t=>!(t in e)).map(e=>[e,F[e]])))}`));const n=await(g&&K?async function(e){const t=new AbortController;X=t;try{return await new Promise((n,r)=>{t.signal.addEventListener("abort",()=>r(z),At),Promise.resolve(l(e,t)).then(n,r)})}finally{X===t&&(X=null)}}(F):l(F,null)),i=Date.now();let f;P&&console.log("[β
Fetch Successful β
] for params:",JSON.stringify(F));try{f=function(e,t,n){return n?n(e,t):e}(n,F,p)}catch(e){throw Pt(s,"transform",e)}if(T)return P&&console.log("[π₯· Successful Parallel Fetch π₯·] for params:",JSON.stringify(F)),"withCache"===r.skipStoreUpdates&&t(e=>{if(!y)return S?e:{queryCache:{...e.queryCache,[I]:{cacheTime:x,data:f,errorInfo:null,lastFetchedAt:i}}};let t=e;const n=t.queryCache[I];try{y({data:f,params:F,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Pt(s,"setData",e)}return!S&&Object.is(n,t.queryCache[I])&&(t={...t,queryCache:{...t.queryCache,[I]:{cacheTime:x,data:null,errorInfo:null,lastFetchedAt:i}}}),t}),f;if((y?c:t)(e=>{let t={...e,error:null,lastFetchedAt:i,queryKey:E?I:e.queryKey,status:R.Success};if(y||S){if(y){P&&console.log("[πΎ Setting Data πΎ] for params:",JSON.stringify(F));const e=t.queryCache[I];try{y({data:f,params:F,queryKey:I,set:e=>{t="function"==typeof e?{...t,...e(t)}:{...t,...e}}})}catch(e){throw Pt(s,"setData",e)}!S&&Object.is(e,t.queryCache[I])&&(t.queryCache={...t.queryCache,[I]:{cacheTime:x,data:null,errorInfo:null,lastFetchedAt:i}})}}else P&&console.log("[πΎ Setting Cache πΎ] for params:",JSON.stringify(F),"| Has previous data?:",!!t.queryCache[I]?.data),t.queryCache={...t.queryCache,[I]:{cacheTime:x,data:f,errorInfo:null,lastFetchedAt:i}};return S||h===1/0?t:Dt(O,I,t)}),K&&(ee=I,a(F,r)),d)try{d({data:f,fetch:u.fetch,params:F,set:c})}catch(e){w.error(Pt(s,"onFetched callback",e))}return f??null}catch(i){if(i===z)return P&&console.log("[β Fetch Aborted β] for params:",JSON.stringify(F)),null;const c=!o&&!0===r?.throwOnError,a=A(i);if(a instanceof _&&w.error(a),!K){if(c)throw a;return null}const l=S?void 0:n().queryCache[I],d=l?.errorInfo?.retryCount??0,y=d+1;try{f?.(a,d)}catch(e){w.error(Pt(s,"onError callback",e))}if(d<j){if(re.get().subscriptionCount>0){const t="function"==typeof k?k(y,a):k;t!==1/0&&(Z&&clearTimeout(Z),Z=setTimeout(()=>{const t=re.get();t.enabled&&t.subscriptionCount>0&&u.fetch(e,_t,!0)},t))}t(e=>({error:a,queryCache:{...e.queryCache,[I]:{cacheTime:l?.cacheTime??x,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:y}}},queryKey:E?I:e.queryKey,status:R.Error}))}else t(e=>({error:a,queryCache:{...e.queryCache,[I]:{cacheTime:l?.cacheTime??x,data:l?.data??null,lastFetchedAt:l?.lastFetchedAt??null,errorInfo:{error:a,lastFailedAt:Date.now(),retryCount:j}}},queryKey:E?I:e.queryKey,status:R.Error}));if(c)throw a;return null}finally{K&&(Y=null)}}return K?(Y={key:I,promise:$()}).promise:$()},getCacheEntry(e){if(S)return null;const t=n(),r=e?"string"==typeof e?e:N(Ct(H,W,V,e)):t.queryKey;return t.queryCache[r]??null},getData(e){if(S)return null;const t=n().getCacheEntry(e);return t&&null!==t.data?O?t.data:t.lastFetchedAt&&Date.now()-t.lastFetchedAt>=t.cacheTime?null:t.data:null},getStatus:function(e){const t=n(),r=t.status;switch(e){case"isIdle":return r===R.Idle;case"isLoading":return r===R.Loading;case"isError":case"isInitialLoad":case"isSuccess":case void 0:{const n=t.queryKey,o=t.queryCache[n],i=S?r===R.Error:"number"==typeof o?.errorInfo?.lastFailedAt;if("isError"===e)return i;const s=null!==((S?ee===n&&t.lastFetchedAt:o?.lastFetchedAt)||null),c=!s&&!i&&t.enabled;if("isInitialLoad"===e)return c;const a=s&&!i;return"isSuccess"===e?a:{isError:i,isIdle:r===R.Idle,isLoading:r===R.Loading,isInitialLoad:c,isSuccess:a}}}},isDataExpired(e){const t=n(),r=t.queryCache[t.queryKey],o=t.queryKey,i=t.lastFetchedAt,s=(S?ee===o&&i:r?.lastFetchedAt)||null;if(!s)return!0;const c=e??r?.cacheTime;return void 0===c||Date.now()-s>=c},isStale(e){const t=n(),r=t.queryKey,o=(S?ee===r&&t.lastFetchedAt:t.queryCache[r]?.lastFetchedAt)||null;if(!o)return!0;const i=e??M;return Date.now()-o>=i},reset(e=!1){for(const e of J)e();J=[],H=null,W=null,U=null,oe(),Z&&(clearTimeout(Z),Z=null),Y=null,ee=null,e&&t(ne)}},b=o.subscribe;return o.subscribe=(...e)=>{const t=G?()=>{}:re.subscribe(),n=1===e.length?b(e[0]):b(e[0],e[1],e[2]);return e=>{t(e),n()}},u}const se=i?.storageKey?Ke(ie,(ce=i,void 0===(ae={partialize:zt(O,i.partialize)})?Object.assign({__proto__:null},ce):Object.assign({__proto__:null},ce,ae))):o&&!("storageKey"in o)?Ke(ie,o):Ke(ie);var ce,ae;const le=se.getState(),fe=le.error,de=le.enabled,ye=le.queryKey,pe=le.fetch;let ge;if(ye&&!fe&&(ee=ye),G=!0,I||"function"==typeof e.enabled){const{directValues:e,enabledAttachVal:t,enabledDirectValue:n,attachVals:r}=function(e,t,n){const r={__proto__:null},o={__proto__:null},i={__proto__:null};for(const e in t){if(!q(t,e))continue;const s=t[e];if(Et(s)){const t=s(vt,n);r[e]=t,i[e]=t.value}else Mt(s)&&(o[e]=s,i[e]=s)}let s,c=null,a=null;if(Et(e)){const t=e(vt,n);s=t.value,c=t}else s=e,a=e;return{attachVals:r,directValues:o,enabledAttachVal:c,enabledDirectValue:a,resolvedEnabled:s,resolvedParams:i}}(v,I,se);H={enabled:t,params:r},W={enabled:n,params:e}}"function"==typeof e.staleTime&&(U=e.staleTime(vt,se),M=U.value);const he=Object.freeze({updateQueryKey:O}),me=function(){let e,t=!1;return function(...n){e=n,t||(t=!0,queueMicrotask(()=>{t=!1,(e=>{pe(e??kt(H,W),he)})(...e)}))}}();function Se(){let e;if(!O){e=kt(H,W);const t=N(e);se.setState({queryKey:t})}me(e)}const ve=u||!F?Se:be(Se,"number"==typeof F?F:F.delay,"number"==typeof F?{leading:!1,maxWait:F,trailing:!0}:F);for(const e in H?.params){const t=H.params[e];if(!t)continue;const n=jt(t);if(P&&console.log("[π Param Subscription π] Subscribed to param:",e),n){let r=t.value;const o=n(()=>{const n=t.value;ue(r,n)||(P&&console.log("[π Param Change π] -",e,"- [Old]:",`${r?.toString()},`,"[New]:",n?.toString()),r=n,ve())});J.push(o)}}if(U){const e=jt(U);if(e){const t=U;let n=t.value;P&&console.log("[π StaleTime Subscription π] Initial value:",n);const r=e(()=>{const e=t.value;e!==n&&(P&&console.log("[π StaleTime Change π] - [Old]:",`${n},`,"[New]:",e),n=e,M=e,pe())});J.push(r)}}if(H?.enabled){const e=H.enabled,t=jt(e);if(t){let n=e.value;de!==n&&((ge??(ge={})).enabled=n),n&&re.setEnabled(n),P&&console.log("[π Enabled Subscription π] Initial value:",n);const r=t(()=>{const t=e.value;t!==n&&(P&&console.log("[π Enabled Change π] - [Old]:",`${n},`,"[New]:",t),n=t,se.setState({enabled:t}))});J.push(r)}}else de!==ne.enabled&&((ge??(ge={})).enabled=ne.enabled);const we=N(kt(H,W));return we!==ye&&((ge??(ge={})).queryKey=we),ge&&se.setState(ge),G=!1,B&&queueMicrotask(ve),Oe=se,qe=Q.QueryStore,Object.assign(Oe,{[qe]:!0});var Oe,qe}(e,t,n);return S(r,r.getState,r.getInitialState,Object.is)}function Nt(e){return N(e)}function Vt(e){return function(e){return JSON.parse(e)}(e)}function Ht(e,t,n){const r=function(e,t,n){const r="function"==typeof t,o=r?t:void 0,i=r?n:t,s=new Set,c=yt(e,{debugMode:i?.debugMode??!1,equalityFn:function(e,t){const n=Object.is(e,t);return n||(function(e,t){for(const n of s){n.unsubscribe();const r=n.args;if(1===r.length){const o=r[0],i=e.getState(),s=t.getState(),c=t.subscribe(o);n.unsubscribe=c,Object.is(s,i)||o(s,i);continue}const o=r[0],i=r[1];let s=r[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});const c=o(e.getState()),a=o(t.getState()),u=t.subscribe(o,i,s);n.unsubscribe=u,(s?.equalityFn??Object.is)(c,a)||i(a,c)}}(e,t),G(e)),n},keepAlive:!0,lockDependencies:i?.lockDependencies??!0}),a=Object.assign({[Q.VirtualStore]:!0,destroy:c.destroy,getInitialState:()=>c.getState().getInitialState(),getState:()=>c.getState().getState(),persist:(u=c.getState,{clearStorage:()=>u().persist?.clearStorage(),getOptions:()=>u().persist?.getOptions()??{},hasHydrated:()=>u().persist?.hasHydrated()??!0,hydrationPromise:()=>u().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:e=>u().persist?.onFinishHydration(e)??d,onHydrate:e=>u().persist?.onHydrate(e)??d,rehydrate:()=>u().persist?.rehydrate(),setOptions:e=>u().persist?.setOptions(e)}),setState:xt(c.getState),subscribe:function(...e){const t={args:e,unsubscribe:1===e.length?c.getState().subscribe(e[0]):c.getState().subscribe(e[0],e[1],e[2])};return s.add(t),()=>{t.unsubscribe(),s.delete(t)}}},o?.(c.getState));var u;return a}(e,t,n);return S(r,r.getState,r.getInitialState)}var Wt=Symbol(),Ut=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Jt(n,r,o,i=Ut){const s=function(){const e=t(Wt);return e.current===Wt&&(e.current=function(e,t,n){return{selector:e,react:t,isActive:!1,options:Gt(n),resubscribe:()=>{},unsubscribe:()=>{}}}(r,o,i)),e}(),c=function(e){return"function"==typeof e?Ut.enabled:e?.enabled??Ut.enabled}(i);return s.current.react=o,s.current.selector=r,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??Ut)}(s,i),e(()=>{if(c)return Qt(n,s),()=>function(e){e.current.options.debugMode&&console.log("[ποΈ useListen ποΈ] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(s)},[c,n]),s}var Bt=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Qt(e,t,n=Bt){if(t.current.isActive){if(!n?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[π‘ useListen π‘] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(n=Bt)=>Qt(e,t,n);const r=e.subscribe(e=>t.current.selector(e),(e,n)=>t.current.react(e,n,()=>{r(),t.current.isActive=!1}),n.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(r(),t.current.isActive=!1)}}function Gt(e){return"function"==typeof e?{equalityFn:e}:e??Ut}var Xt=Symbol();function Yt(e){const n=t(Xt);return n.current===Xt&&(n.current=e()),n.current}export{R as QueryStatuses,_ as StoresError,W as applyStateUpdate,z as configureStores,Rt as createBaseStore,$t as createDerivedStore,Lt as createQueryStore,oe as createStoreActions,Ht as createVirtualStore,ce as deepEqual,L as defaultRetryDelay,G as destroyStore,X as destroyStores,Nt as getQueryKey,Y as getStoreName,Z as hasGetSnapshot,l as identity,te as isDerivedStore,ne as isPersistedStore,ee as isQueryStore,re as isVirtualStore,f as nullObject,Vt as parseQueryKey,J as replacer,B as reviver,ae as shallowEqual,$ as time,Jt as useListen,Yt as useStableValue};
|
|
1
|
+
import{createRequire as e}from"node:module";import{useDebugValue as t,useLayoutEffect as n,useRef as r,useSyncExternalStore as i}from"react";import{Platform as a,unstable_batchedUpdates as o}from"react-native";var s=e(import.meta.url);const c=a.OS===`ios`;a.OS;const l=process.env.NODE_ENV===`development`,u=process.env.NODE_ENV===`test`;Object.freeze(Object.create(null));function d(e){return e}function f(){return{__proto__:null}}function p(e,t){return t===void 0?Object.assign(f(),e):Object.assign(f(),e,t)}function m(){}function h(e,t,n){e(t,n)}const g=Symbol(`empty selection`),_=Object.is;function v(e,n,a,o,s=_){let c=r(null),l=e,u=n,d=a;if(o){let t=c.current;t===null&&(t=y(e,n,a,o,s),c.current=t),b(t,e,n,a,o,s),l=t.selectedSubscribe,u=t.getSelectedSnapshot,d=a===void 0?void 0:t.getSelectedServerSnapshot}let f=i(l,u,d);return t(f),f}function y(e,t,n,r,i){let a={committedEqualityFn:i,committedSelector:r,committedSource:e,committedValue:g,equalityFn:i,getSelectedServerSnapshot:()=>C(a),getSelectedSnapshot:()=>S(a),getServerStoreSnapshot:n,getStoreSnapshot:t,selector:r,selectedSource:e,selectedSubscribe:()=>m,source:e,value:g,valueEqualityFn:i,valueSelector:r,valueSnapshot:g};return a.selectedSubscribe=x(a,e),a}function b(e,t,n,r,i,a){e.source=t,e.getStoreSnapshot=n,e.getServerStoreSnapshot=r,e.selector=i,e.equalityFn=a,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=x(e,t))}function x(e,t){return n=>(E(e),t(r=>{let i=e.committedValue;if(i===g||e.committedSource!==t){n();return}let a=e.committedSelector,o=e.committedEqualityFn;if(e.selector===a&&e.equalityFn===o){let t=a(r);if(o===_?_(i,t):o(i,t))return;e.committedValue=t,e.value=t,e.valueEqualityFn=o,e.valueSelector=a,e.valueSnapshot=r,n();return}if(e.source!==t){n();return}let s=e.value;if(s===g)return;let c=e.selector(r),l=e.equalityFn(s,c);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=T(e,r,l?s:c),l||n()}))}function S(e){return w(e,e.getStoreSnapshot())}function C(e){return w(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}function w(e,t){let n=e.value;if(n!==g&&_(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return n;let r=e.selector(t);if(n!==g&&(e.equalityFn===_?_(n,r):e.equalityFn(n,r)))return T(e,t,n);let i=e.committedValue;return i!==g&&i!==n&&e.committedSource===e.source&&(e.equalityFn===_?_(i,r):e.equalityFn(i,r))?T(e,t,i):T(e,t,r)}function T(e,t,n){return e.value=n,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,n}function E(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===g?S(e):e.value}function D(e,t,n,r){let i=e.subscribe;function a(e,a){return v(i,t,n,e,a??r)}return Object.assign(a,e)}function O(e){let t;function n(){if(t)return t;try{let n=k(e),r;if(typeof n.delete==`function`?r=n.delete.bind(n):typeof n.remove==`function`&&(r=n.remove.bind(n)),typeof r!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`);t={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)}}catch(e){throw Error(`[stores] react-native-mmkv could not be loaded.
|
|
2
|
+
|
|
3
|
+
Persisted stores require a storage backend. Either:
|
|
4
|
+
- Install MMKV (the default): yarn add react-native-mmkv
|
|
5
|
+
- Or provide a custom adapter via configureStores()
|
|
6
|
+
`+(e instanceof Error?`\n${e.message}`:``))}return A(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)}}function k(e){let{createMMKV:t,MMKV:n}=s(`react-native-mmkv`);if(typeof t==`function`)return t({id:e});if(typeof n==`function`)return new n({id:e});throw Error(`[stores]: react-native-mmkv module does not export MMKV/createMMKV.`)}function A(e){if(!e||typeof e.get!=`function`||typeof e.set!=`function`||typeof e.delete!=`function`||typeof e.clearAll!=`function`)throw Error(`[stores]: Storage instance does not conform to expected interface`)}let j={debug:(e,t)=>{l&&console.debug(e,t)},error:(e,t)=>{l&&!u&&console.error(e,t)},info:(e,t)=>{l&&console.info(e,t)},warn:(e,t)=>{l&&console.warn(e,t)}};function ee(e){j=e}const M=Object.prototype.hasOwnProperty;function N(e,t){return M.call(e,t)}function P(e){let t=e.charCodeAt(0);if(t<48||t>57)return!1;let n=Number(e);return Number.isInteger(n)&&n<4294967295&&String(n)===e}function F(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var L=class extends Error{constructor(e,t){super(e),this.name=`StoresError`,t!==void 0&&Object.defineProperty(this,"cause",{configurable:!0,value:t,writable:!0})}};function te(e){return e instanceof Error?e:Error(String(e))}var R=class{destroy(){}publish(){}},z=class{constructor(){this.sessionId=`noop`}register(e){return new R}};let B;function V(){return B||(B=new z),B}let H,U,ne=!1;function re(e){l&&se(),e.logger&&ee(e.logger),H??(H=G(e)),U??(U=oe(e))}function W(){if(H)return H}function ie(){return U??(U=oe(void 0))}function ae(){ne=!0}function G(e){if(e?.queryStoreDefaults)return{queryStoreDefaults:e.queryStoreDefaults}}function oe(e){return{storage:e?.storage??O(e?.storageKeyPrefix??`stores:`),syncEngine:e?.syncEngine??V()}}function se(){if(ne)throw Error(`[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.`)}const K={Error:`error`,Idle:`idle`,Loading:`loading`,Success:`success`},q={ms:e=>{"worklet";return e},seconds:e=>{"worklet";return e*1e3},minutes:e=>{"worklet";return e*6e4},hours:e=>{"worklet";return e*36e5},days:e=>{"worklet";return e*864e5},weeks:e=>{"worklet";return e*6048e5},infinity:1/0,zero:0};let ce;function le(){return ce??(ce=ue())}function ue(){let e=W()?.queryStoreDefaults;return{abortInterruptedFetches:e?.abortInterruptedFetches??!0,cacheTime:e?.cacheTime??q.days(7),debugMode:e?.debugMode??!1,disableAutoRefetching:e?.disableAutoRefetching??!1,keepPreviousData:e?.keepPreviousData??!1,minStaleTime:e?.minStaleTime??!1,onError:e?.onError,paramChangeThrottle:e?.paramChangeThrottle??!1,retry:e?.retry??5,retryDelay:e?.retryDelay,staleTime:e?.staleTime??q.minutes(2),suppressStaleTimeWarning:e?.suppressStaleTimeWarning??!1}}function de(e,t){let n=t?.baseDelay??q.seconds(5),r=t?.maxDelay??q.minutes(5);return Math.min(n*2**e,r)}function fe(e,t){return t[1]===!0?e(t[0],!0):e(t[0])}function pe(e,t,n){if(n===!0)return me(t)?t(e):t;let r=me(t)?t(e):t;return Object.is(r,e)?e:!I(e)||!I(r)?r:{...e,...r}}function me(e){return typeof e==`function`}function he(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Map`}function ge(e){return typeof e==`object`&&!!e&&`__type`in e&&e.__type===`Set`}function _e(e,t){return t instanceof Map?{__type:`Map`,entries:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,values:Array.from(t)}:t}function ve(e,t){return he(t)?new Map(t.entries):ge(t)?new Set(t.values):t}const ye=Object.freeze({QueryStore:Symbol(`queryStore`),VirtualStore:Symbol(`virtualStore`)});function be(e,t){return Object.assign(e,{[t]:!0})}function J(e,t){Ee(e)?e.getState().reset(t?.clearQueryCache):we(e)&&e.destroy()}function xe(e,t){for(let n of Array.isArray(e)?e:Object.values(e))!n||t?.skipDestroy?.(n)||J(n,t)}function Se(e){let t=Ce(e);return Oe(e)?e.persist.getOptions().name??t:t}function Ce(e){return typeof e==`function`?e.name:``}function we(e){return`destroy`in e}function Te(e){return`getSnapshot`in e}function Ee(e){return ye.QueryStore in e}function De(e){return`flushUpdates`in e}function Oe(e){return!(`persist`in e)||!e.persist?!1:typeof e.persist.getOptions().name==`string`}function ke(e){return ye.VirtualStore in e}function Ae(e,t){let n=je(e);return t?Object.assign(n,t):n}function je(e){let t=e.getState(),n=f(),r=n;if(l&&!(typeof t==`object`&&t))throw Error(`[createStoreActions]: State is not an object`);if(ke(e))for(let n in t)Ne(t,n)&&(r[n]=Me(e,n));else for(let e in t)Ne(t,e)&&(r[e]=t[e]);return n}function Me(e,t){return function(...n){let r=e.getState()[t];if(typeof r==`function`)return r(...n);throw Error(`[createVirtualStoreAction]: Method ${String(t)} is not a function`)}}function Ne(e,t){return typeof e[t]==`function`}function Pe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!(r in t)||!Pe(e[r],t[r]))return!1;return!0}function Fe(e,t){"worklet";if(typeof e!=`object`||!e||e===void 0||typeof t!=`object`||!t||t===void 0)return e===t;if(Object.is(e,t))return!0;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.is(e[r],t[r]))return!1;return!0}function Ie(e,t){let n=Object.prototype.hasOwnProperty;function r(e,t){for(let n of e.keys())if(Ie(n,t))return n}let i,a,o;if(e===t)return!0;if(e&&t&&(i=e.constructor)===t.constructor){if(i===Date)return e.getTime()===t.getTime();if(i===RegExp)return e.toString()===t.toString();if(i===Array){if((a=e.length)===t.length)for(;a--&&Ie(e[a],t[a]););return a===-1}if(i===Set){if(e.size!==t.size)return!1;for(let n of e)if(o=n,o&&typeof o==`object`&&(o=r(t,o),!o)||!t.has(o))return!1;return!0}if(i===Map){if(e.size!==t.size)return!1;for(let n of e)if(o=n[0],o&&typeof o==`object`&&(o=r(t,o),!o)||!Ie(n[1],t.get(o)))return!1;return!0}if(i===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(i===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return a===-1}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){let n=e,r=t;if((a=n.byteLength)===r.byteLength)for(;a--&&n[a]===r[a];);return a===-1}if(!i||typeof e==`object`){a=0;for(let r in e)if(n.call(e,r)&&++a&&!n.call(t,r)||!(r in t)||!Ie(e[r],t[r]))return!1;return Object.keys(t).length===a}}return e!==e&&t!==t}function Le(e,t,n){if(t===0)return n;if(t===1){if(e===n)return null;let t=new Set;return t.add(e),t.add(n),t}return e.add(n),e.size===t?null:e}function Re(e,t,n){if(t===0)return null;if(t===1)return e===n?void 0:null;if(!e.delete(n))return null;if(t!==2)return e;for(let t of e)return t}function ze(e,t,n,r,i){if(t!==0){if(t===1){n(e,r,i);return}for(let t of e)n(t,r,i)}}function Be(e,t){t>1&&e.clear()}const Ve=o;let Y=!1,He=!1,Ue=!1,X,We,Ge=0;const Ke=new Map;let qe=0,Je=null,Z=1/0;function Ye(){return Y}function Xe(){return Je}function Ze(){Y||(Y=!0,!Ue&&(Ue=!0,queueMicrotask(()=>{Ue=!1,Qe()})))}function Qe(){if(Y){if(He){nt();return}He=!0;try{Ve(nt)}finally{ot()}}}function $e(){if(Y){if(He){Je===null&&rt();return}He=!0;try{rt()}catch(e){throw ot(),e}finally{He=!1,Je=null}}}function et(e){if(Y){if(We){We.push(e);return}if(!X){X=e;return}We=[X,e],X=void 0}}function tt(e,t){if(!Y)return;let n=t<0?0:t|0,r=Ke.get(n);r||(r=[],Ke.set(n,r)),r.push(e),qe+=1,n<Z&&(Z=n)}function nt(){for(;qe>0||st();)rt(),at()}function rt(){for(;qe>0;){let e=Z,t=Ke.get(e);if(!t){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e);continue}Ke.delete(e),qe-=t.length,it(),Je=e;for(let e=0;e<t.length;e++)t[e]();Je=null}}function it(){Z=1/0;for(let e of Ke.keys())e<Z&&(Z=e)}function at(){for(;;){let e=X;if(e){X=void 0,e();continue}let t=We;if(!t)return;for(;Ge<t.length;)t[Ge++]();We=void 0,Ge=0;return}}function ot(){Y=!1,He=!1,Je=null,X=void 0,We=void 0,Ge=0,Ke.clear(),qe=0,Z=1/0}function st(){return!!X||!!We}const Q=Symbol(`stores.subscribeCascadeState`);function ct(e){return Q in e}function lt(e,t){ct(e)&&(e[Q]=t(e[Q]))}const ut=Symbol(),dt=Symbol();function ft(e){let t,n,r,i=0;function a(e,a,o){let s=pe(t,e,a);if(Object.is(s,t))return o===ut?dt:void 0;let c=t;if(t=s,ze(r,i,h,t,c),n){Qe();for(let e of n)e(t,c)}}function o(){return t}function s(){return u}function c(e,t,n){return t?g(e,t,n):d(e)}let l={[Q]:p,getInitialState:s,getState:o,setState:a,subscribe:c},u=t=pt(e)?e(a,o,l):e;return l;function d(e){return(n??(n=new Set)).add(e),()=>{n?.delete(e),n?.size===0&&(n=void 0)}}function f(e){let t=Le(r,i,e);return t!==null&&(r=t,i+=1),()=>m(e)}function p(e){function t(t,n){Ze(),e(t,n)}return f(t)}function m(e){let t=Re(r,i,e);t!==null&&(r=t,--i)}function g(e,n,r){let i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=e(t);function s(t){let r=e(t);if(i(o,r))return;let s=o;o=r,a&&Ze(),n(r,s)}return r?.fireImmediately&&n(o,o),a?f(s):d(s)}}function pt(e){return typeof e==`function`}function mt(e){return!!e&&typeof e==`object`&&`then`in e&&typeof e.then==`function`}const ht=Object.freeze({migrated:!1,state:void 0});function gt(e,t,n){return(r,i,a)=>{let o=vt(t),s,c=!1,l=0,u,d,f;function p(e){return o.storage.setItem(o.name,e,o.version)}function m(e,t){return(t===!0?r(e,t,ut):r(e,!1,ut))===dt?n?s??(s=Promise.resolve()):void 0:p(i())}a.setState=m;let h=e(m,i,a);a.getInitialState=()=>h;function g(){let e=x(),t=o.onRehydrateStorage?.(i()??h);try{let n=o.storage.getItem(o.name);return mt(n)?n.then(n=>_(e,n,t)).catch(n=>C(e,t,n)):_(e,n,t)}catch(n){C(e,t,n)}}return Object.assign(a,{persist:b()}),o.skipHydration||g(),u??h;function _(e,t,n){let r=_t(o,t);return mt(r)?r.then(t=>v(e,t,n)).catch(t=>C(e,n,t)):v(e,r,n)}function v(e,t,n){let r=y(e,t);if(mt(r))return r.then(()=>S(e,n));S(e,n)}function y(e,t){if(e!==l)return;let n=o.merge(t.state,i()??h);if(u=n,r(n,!0),t.migrated)return p(i())}function b(){return{clearStorage:()=>{o.storage.removeItem(o.name)},getOptions:()=>o,hasHydrated:()=>c,onFinishHydration:e=>(f??(f=new Set),f.add(e),()=>{f?.delete(e),f?.size===0&&(f=void 0)}),onHydrate:e=>(d??(d=new Set),d.add(e),()=>{d?.delete(e),d?.size===0&&(d=void 0)}),rehydrate:g,setOptions:e=>{o=vt({...o,...e,storage:e.storage??o.storage})}}}function x(){let e=++l;return c=!1,d?.forEach(e=>e(i()??h)),e}function S(e,t){if(e!==l)return;t?.(u,void 0);let n=i();u=n,c=!0,f?.forEach(e=>e(n))}function C(e,t,n){e===l&&t?.(void 0,n)}}}function _t(e,t){if(!t)return ht;if(typeof t.version!=`number`||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`),ht;let n=e.migrate(t.state,t.version);return mt(n)?n.then(e=>({migrated:!0,state:e})):{migrated:!0,state:n}}function vt(e){return{...e,merge:e.merge??yt,skipHydration:e.skipHydration??!1}}function yt(e,t){return e===void 0?t:{...t,...e}}function bt(){let e=!1,t,n,r=new Promise((e,r)=>{t=e,n=r});function i(){e||!t||(e=!0,t(),t=void 0,n=void 0)}function a(r){e||!n||(e=!0,n(r),n=void 0,t=void 0)}function o(){return e}return{complete:i,isHydrated:o,fail:a,promise:r}}function xt(e){let t,n=!1,r,i;return{hydrationPromise:()=>n?t?.promise??r??(r=Promise.resolve()):(t||(t=bt()),t.promise),stateCreator:(r,a,o)=>{let s;function c(...e){return n?fe(r,e):(t||(t=bt()),s||(s=[]),s.push(e),t.promise)}return i=()=>{if(s?.length){for(let e of s)fe(o.setState,e);s=void 0}},e(c,a,o)},wrapOnRehydrateStorage:(e,r)=>a=>{let o=e?.(a);return(e,a)=>{n=!0,r?.onHydrationComplete?.(),i&&i(),r?.onHydrationFlushEnd?.(),a?t?.fail(te(a)):t?.complete(),o?.(e,a)}}}}function St(e){let t,n=null;function r(...r){return t=r,n||(n=new Promise(r=>{queueMicrotask(async()=>{try{await e(...t)}finally{n=null,r()}})})),n}return r}const Ct=Math.max,wt=Math.min;function Tt(e,t=0,n={}){let r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=Dt(t)||0,Ot(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?Ct(Dt(n.maxWait)||0,t):void 0,f=`trailing`in n?!!n.trailing:f);function p(t){let n=r,a=i;return r=i=void 0,l=t,o=n?e.apply(a,n):e.apply(a),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){let n=e-(c??0),r=e-l,i=t-n;return d&&a!==void 0?wt(i,a-r):i}function g(e){let n=e-(c??0),r=e-l;return c===void 0||n>=t||n<0||d&&a!==void 0&&r>=a}function _(){let e=Et();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function y(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function b(){return s===void 0?o:v(Et())}function x(...e){let n=Et(),a=g(n);if(r=e,i=this,c=n,a){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return x.cancel=y,x.flush=b,x}function Et(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function Dt(e){if(typeof e==`number`)return e;if(typeof e==`symbol`||e===void 0)return NaN;if(typeof e==`object`&&e){let t=typeof e.valueOf==`function`?e.valueOf():e;e=typeof t==`object`?t+``:t}return typeof e==`string`?(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):e===0?e:+e}function Ot(e){let t=typeof e;return e!==null&&(t===`object`||t===`function`)}function kt(e){if(!F(e))return e;let t=f(),n=Object.keys(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];typeof a!=`function`&&(t[i]=a)}return t}function At(e,t){try{return JSON.stringify(e,t?_e:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to serialize store data`,e)),e}}function jt(e,t){try{return JSON.parse(e,t?ve:void 0)}catch(e){throw j.error(new L(`[createBaseStore]: Failed to deserialize persisted store data`,e)),e}}const Mt=u?0:c?q.seconds(3):q.seconds(5);function Nt(e,t,n){let r=t??e.storage??ie().storage,i=(e.sync?void 0:e.persistThrottleMs??Mt)||void 0,a=e.version??0;return r.async?{async:!0,persistStorage:Ft(r,e,i,n),version:a}:{async:!1,persistStorage:Pt(r,e,i,n),version:a}}function Pt(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??kt,s=t.deserializer??e.deserializer??It(i),c=t.serializer??e.serializer??Lt(i);function l(t,n,i){try{if(Ht(r))return;let s={state:o(n),version:i},l=zt(r,a,s),u=c(s);try{e.set(t,u),Bt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}let u=n===void 0?l:Tt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:t=>{let n=e.get(t);return n===void 0?null:s(n)},setItem:(e,t,n)=>{r?.getIsApplyingRemote()||u(e,t,n)},removeItem:t=>{try{e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function Ft(e,t,n,r){let i=!t.deserializer&&!t.serializer&&!e.deserializer&&!e.serializer,a=typeof t.sync==`object`&&(t.sync.injectStorageMetadata??t.sync.engine?.injectStorageMetadata)===!0,o=t.partialize??kt,s=t.deserializer??e.deserializer??It(i),c=t.serializer??e.serializer??Lt(i);async function l(t,n,i){try{if(Ht(r))return;let s={state:o(n),version:i},l=zt(r,a,s),u=c(s);try{await e.set(t,u),Bt(r,l)}catch(e){j.error(new L(`[createBaseStore]: Failed to persist store data`,e))}}catch(e){j.error(new L(`[createBaseStore]: Failed to serialize persisted store data`,e))}}let u=n===void 0?St(l):Tt(l,n,{leading:!1,maxWait:n,trailing:!0});return{getItem:async t=>{let n=await e.get(t);return n===void 0?null:s(n)},setItem:async(e,t,n)=>{if(!r?.getIsApplyingRemote())return await u(e,t,n)},removeItem:async t=>{try{await e.delete(t)}catch(e){j.error(new L(`[createBaseStore]: Failed to delete persisted store data`,e))}}}}function It(e){return t=>{if(typeof t!=`string`)throw new L(`[createBaseStore]: Received non-string serialized state without a custom deserializer. Provide a deserializer on the store or storage adapter.`);return jt(t,e)}}function Lt(e){return t=>At(t,e)}const Rt=Object.freeze({shouldClear:!1});function zt(e,t,n){if(!t||!e)return Rt;let r=e.getFieldTimestampSnapshot();return Vt(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 Bt(e,t){!e||!t.shouldClear||!t.fieldSnapshot||!Object.keys(t.fieldSnapshot).length||e.clearFieldTimestamps(t.fieldSnapshot)}function Vt(e,t){let n=e.getSessionId(),r=e.getTimestamp();n!==void 0&&r!==void 0&&(t.syncMetadata={origin:n,timestamp:r})}function Ht(e){return e?!!e.getIsApplyingRemote():!1}function Ut(e,t,n){let r=t.engine??ie().syncEngine;return(i,a,o)=>{let s=new Map,c=[],l=[],u=null,d=!1,p=!1,m=0,h=null,g=[],_=Promise.resolve(),v=!n?.isAsync;function y(){let e=Date.now(),t=e>m?e:m+1;return m=t,t}function b(e,t){if(!(!n||!r.sessionId)&&(n.setSessionId(r.sessionId),n.setTimestamp(e),t.length>0)){let r=f();for(let n of t)r[String(n)]=e;n.mergeFieldTimestamps(r)}}function x(e,t,n,i=!1){let a=r.sessionId;for(let t of e)s.set(t,[n,a]);!u||!p?l.push({keys:e,replace:i,timestamp:n,values:t}):u.publish?.({replace:i,sessionId:a,timestamp:n,values:t})}function S(){if(!(!u||!l.length)){for(let e of l){let t=r.sessionId;for(let n of e.keys)s.set(n,[e.timestamp,t]);b(e.timestamp,e.keys),u.publish?.({replace:e.replace,sessionId:t,timestamp:e.timestamp,values:e.values})}l.length=0}}function C(e,t){if(d||!h)return t?i(e,t):i(e);let n=y(),r,a,o=t?i(s,!0):i(s);if(!r||!a)return o;function s(i){let o=pe(i,e,t);for(let e of g)Object.is(o[e],i[e])||((r??(r=[])).push(e),(a??(a=f()))[e]=o[e]);return r&&b(n,r),o}return mt(o)?o.finally(x.bind(void 0,r,a,n,t)):(x(r,a,n,t),o)}let w=o.setState;o.setState=C;let T=e(C,a,o);if(g=t.fields??Kt(T),!g.length)return T;h=new Set(g);async function E(e){m=Math.max(m,e.timestamp);let r=f(),i=a(),o=e.timestamp,c;if(e.replace)for(let t of g)N(e.values,t)||Gt(s.get(t),o,e.sessionId)&&(c??(c=[])).push(t);for(let n of g){if(!Yt(e.values,n)||!h?.has(n)||!Gt(s.get(n),o,e.sessionId))continue;let a=t.merge?.[n];if(a){let t=e.values[n],c=i[n];if(t!==void 0){let l=a(t,c,i,e.values),u=c===void 0?t:c;if(!Jt(l,u)){j.error(new L(`[sync] Merge function for field "${String(n)}" returned ${qt(l)} but expected ${qt(u)}`));return}r[n]=l,s.set(n,[o,e.sessionId])}}else r[n]=e.values[n],s.set(n,[o,e.sessionId])}if(!(!(Object.keys(r).length>0)&&!c?.length)){d=!0,n?.setIsApplyingRemote(!0);try{if(e.replace){let e={...i},t=!1;if(c?.length){t=!0;for(let t of c)delete e[t],s.delete(t)}for(let n in r){if(!N(r,n))continue;let i=r[n];if(i===void 0)continue;Object.is(e[n],i)||(t=!0);let a=e;a[n]=i}if(!t)return;await(n?.setWithoutPersist??w)(e,!0)}else await(n?.setWithoutPersist??w)(r)}finally{d=!1,n?.setIsApplyingRemote(!1)}}}function D(e){n?.isAsync?_=_.then(()=>E(e)):E(e)}function O(){if(!c.length)return;let e=c.slice();c.length=0;for(let t of e)D(t)}if(u=r.register({apply:e=>{if(!v){c.push(e);return}D(e)},fields:g,getState:a,key:t.key}),u?.onFirstSubscribe||u?.onLastUnsubscribe){let e=u,t=0,n=o.subscribe;function r(n){return t++===0&&e.onFirstSubscribe?.(),r=>{n(r),--t,t||queueMicrotask(()=>{t||e.onLastUnsubscribe?.()})}}o.subscribe=(...e)=>r(e.length===1?n(e[0]):n(e[0],e[1],e[2])),lt(o,e=>t=>r(e(t)))}function k(){p=!0,S()}function A(){v=!0,O()}return n?.isAsync?(n.onHydrationComplete=k,n.onHydrationFlushEnd=A):u.onHydrated?(u.onHydrated(k),A()):(k(),A()),T}}function Wt(e){let t,n,r,i=!1;function a(e){if(!(!e||!r)){for(let t of Object.entries(e)){let e=t[0],n=t[1];r[e]===n&&delete r[e]}Object.keys(r).length||(r=void 0)}}function o(){if(r)return{...r}}function s(e){if(!r){r={...e};return}for(let t of Object.entries(e)){let e=t[0],n=t[1],i=r[e];(i===void 0||n>i)&&(r[e]=n)}}return{isAsync:e,clearFieldTimestamps:a,getFieldTimestampSnapshot:o,getIsApplyingRemote:()=>i,getSessionId:()=>t,getTimestamp:()=>n,mergeFieldTimestamps:s,onHydrationComplete:void 0,onHydrationFlushEnd:void 0,setIsApplyingRemote:e=>i=e,setSessionId:e=>t=e,setTimestamp:e=>n=e,setWithoutPersist:void 0}}function Gt(e,t,n){if(!e)return!0;let r=e[0],i=e[1];return t<r?!1:t>r?!0:n>i}function Kt(e){let t=[];for(let n of Object.keys(e))Xt(e,n)&&t.push(n);return t}function qt(e){if(e===null)return`null`;let t=typeof e;return t===`object`?Object.prototype.toString.call(e):t}function Jt(e,t){if(!l)return!0;if(e===null||t===null)return e===t;let n=typeof e;return n===typeof t?n===`object`?Object.prototype.toString.call(e)===Object.prototype.toString.call(t):!0:!1}function Yt(e,t){return N(e,t)}function Xt(e,t){return typeof e[t]!=`function`}function Zt(e,t){if(ae(),!t)return ft(e);let n=t.storageKey,r=typeof n==`string`,i=r?t.storage??ie().storage:void 0,a=Qt(t.sync,n),o=!i||!a?void 0:Wt(i.async??!1),s=a?Ut(e,a,o):e;if(!r)return ft(s);let c=Nt(t,i,o),l=c.async?xt(s):void 0,u=l?l.wrapOnRehydrateStorage(t.onRehydrateStorage,o):t.onRehydrateStorage,d=ft(gt(l?(e,t,n)=>(o&&(o.setWithoutPersist=n.setState),l.stateCreator(e,t,n)):s,{merge:t.merge,migrate:t.migrate,name:n,onRehydrateStorage:u,storage:c.persistStorage,version:c.version},c.async));return l?Object.assign(d,{persist:Object.assign(d.persist,{hydrationPromise:l.hydrationPromise})}):d}function Qt(e,t){if(!e)return null;let n=typeof e==`object`,r=n?e.key??t:e===!0?t:e;if(!r)throw new L(`[createBaseStore]: sync requires a key to be specified either directly or via storageKey`);return n?{...e,key:r}:{key:r}}function $t(e,t,n=`s`){return t===1?e:`${e}${n}`}const en=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});var tn=class{constructor(e){this.invalidate=e,this.stateDependencyRevisionStamp=0,this.stateDependencyRevision=0}beginRebuild(e){this.clearSelectors(e),this.stateDependencyRevision+=1}addSelector(e){let t=this.selectorUnsubscribes;if(!t){this.selectorUnsubscribes=e;return}if(typeof t==`function`){this.selectorUnsubscribes=[t,e];return}t.push(e)}retainState(e){let t=this.stateDependencies;if(t){let n=t.get(e);if(n){n.revision=this.stateDependencyRevision;return}t.set(e,this.createStateDependency(e));return}let n=this.stateDependencyStore;if(!n){this.stateDependencyStore=e,this.stateDependencyRevisionStamp=this.stateDependencyRevision,this.stateDependencyUnsubscribe=this.subscribeState(e);return}if(n===e){this.stateDependencyRevisionStamp=this.stateDependencyRevision;return}let r=this.stateDependencyUnsubscribe;this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0,this.stateDependencies=new Map,r&&this.stateDependencies.set(n,{revision:this.stateDependencyRevisionStamp,unsubscribe:r}),this.stateDependencies.set(e,this.createStateDependency(e))}finishRebuild(e){this.stateDependencyStore&&this.stateDependencyRevisionStamp!==this.stateDependencyRevision&&(this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0);let t=this.stateDependencies;if(t){for(let n of t){let r=n[1];r.revision!==this.stateDependencyRevision&&(r.unsubscribe(e),t.delete(n[0]))}if(!t.size){this.stateDependencies=void 0;return}if(t.size===1){for(let e of t){this.stateDependencyStore=e[0],this.stateDependencyRevisionStamp=e[1].revision,this.stateDependencyUnsubscribe=e[1].unsubscribe;break}this.stateDependencies=void 0}}}clear(e){this.clearSelectors(e),this.stateDependencyUnsubscribe?.(e),this.stateDependencyStore=void 0,this.stateDependencyUnsubscribe=void 0;let t=this.stateDependencies;if(t){for(let n of t)n[1].unsubscribe(e);this.stateDependencies=void 0}}get size(){let e=this.selectorUnsubscribes;return(typeof e==`function`?1:e?.length??0)+ +!!this.stateDependencyStore+(this.stateDependencies?.size??0)}clearSelectors(e){let t=this.selectorUnsubscribes;if(this.selectorUnsubscribes=void 0,t){if(typeof t==`function`){t(e);return}for(let n=0;n<t.length;n++)t[n](e)}}createStateDependency(e){return{revision:this.stateDependencyRevision,unsubscribe:this.subscribeState(e)}}subscribeState(e){return ct(e)?e[Q](this.invalidate):e.subscribe(d,this.invalidate,en)}},nn=class{constructor(){this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}addWatcher(e){let t=Le(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,this.watcherCount+=1,sn(e)?this.cascadeParticipantCount+=1:this.ordinaryWatcherCount+=1,!0)}deleteWatcher(e){let t=Re(this.watchers,this.watcherCount,e);return t===null?!1:(this.watchers=t,--this.watcherCount,sn(e)?--this.cascadeParticipantCount:--this.ordinaryWatcherCount,!0)}addCascadeStateListener(e){let t=Le(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,this.cascadeParticipantCount+=1,this.cascadeStateListenerCount+=1,!0)}deleteCascadeStateListener(e){let t=Re(this.cascadeStateListeners,this.cascadeStateListenerCount,e);return t===null?!1:(this.cascadeStateListeners=t,--this.cascadeParticipantCount,--this.cascadeStateListenerCount,!0)}notifyCascade(e,t){ze(this.cascadeStateListeners,this.cascadeStateListenerCount,h,e,t),this.cascadeParticipantCount!==this.cascadeStateListenerCount&&ze(this.watchers,this.watcherCount,rn,e,t)}notifyOrdinary(e,t){ze(this.watchers,this.watcherCount,an,e,t)}clear(){this.watchers=Be(this.watchers,this.watcherCount),this.cascadeStateListeners=Be(this.cascadeStateListeners,this.cascadeStateListenerCount),this.watcherCount=0,this.ordinaryWatcherCount=0,this.cascadeParticipantCount=0,this.cascadeStateListenerCount=0}};function rn(e,t,n){typeof e==`function`||!e.isCascadeParticipant||on(e,t)}function an(e,t,n){if(typeof e==`function`){e(t,n);return}e.isCascadeParticipant||on(e,t)}function on(e,t){let n=e.selector(t);if(e.equalityFn(e.currentSlice,n))return;let r=e.currentSlice;e.currentSlice=n,e.listener(n,r)}function sn(e){return typeof e!=`function`&&e.isCascadeParticipant}const cn=Symbol(`stores.deriveProxy.unwrap`);function ln(e,t,n,r){let i=n.get(e);if(vn(i))return i;let a=un(t,e,r);return n.set(e,a),a}function un(e,t,n,r=[]){return!e||typeof e!=`object`?(n(t,r,!0),e):dn(e,r,t,n,new WeakSet,new WeakMap)}function dn(e,t,n,r,i,a){let o=Array.isArray(e);return new Proxy(e,{get(s,c,l){if(c===cn)return r(n,t,!0),s;if(i.has(s))return Reflect.get(s,c,l);if(c===`__proto__`||typeof c==`symbol`)return c===Symbol.iterator&&(r(n,t,!0),i.add(s)),Reflect.get(s,c,l);if(o&&P(c))return r(n,t,!0),i.add(s),Reflect.get(s,c,l);let u=Reflect.get(s,c,s),d=String(c),f=t.concat(d);if(typeof u==`function`)return N(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));let p=!!u&&typeof u==`object`;return r(n,f,!p),p?(a.has(u)||a.set(u,dn(u,f,n,r,i,a)),a.get(u)):u},getOwnPropertyDescriptor(e,a){return r(n,t,!0),i.add(e),Reflect.getOwnPropertyDescriptor(e,a)},has(e,i){return r(n,t,!0),Reflect.has(e,i)},ownKeys(e){return r(n,t,!0),i.add(e),Reflect.ownKeys(e)}})}function fn(e,t){return!e||typeof e!=`object`?e:gn(e)||(Array.isArray(e)?pn(e,t):F(e)&&mn(e,t),e)}function pn(e,t){let n=_n(e,t);if(n)for(let t=0;t<e.length;t++)hn(e,String(t),n)}function mn(e,t){let n=_n(e,t);if(n)for(let t of Reflect.ownKeys(e))hn(e,t,n)}function hn(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(!r||!(`value`in r))return;let i=fn(r.value,n);i!==r.value&&(r.value=i,Reflect.defineProperty(e,t,r))}function gn(e){let t=Reflect.get(e,cn);return t&&typeof t==`object`?t:void 0}function _n(e,t){let n=t??new WeakSet;return n.has(e)?null:(n.add(e),n)}function vn(e){return e!==void 0}const yn=Object.freeze([]);function bn(){let e,t,n;return{buildProxySubscriptions(r,i,a){let o=[],s=t,c=e;if(s&&c)Cn(s,c,[],0,o,a);else if(n)for(let e of n)Cn(e[1],e[0],[],0,o,a);Dn(o,r,i)},reset(){e=void 0,t=void 0,n=void 0},trackPath(r,i,a,o){let s=t;if(s){let i=e;if(i!==r)if(!i)e=r;else{let a=n??(n=new Map);a.set(i,s),s=xn(),a.set(r,s),e=void 0,t=void 0}}else{let i=n;i?(s=i.get(r),s||(s=xn(),i.set(r,s))):(s=xn(),e=r,t=s)}Sn(s,i,a,o)}}}function xn(){return f()}function Sn(e,t,n,r){let i=e;for(let e=0;e<t.length;e++){let n=t[e],r=i.children,a;if(r)a=r[n],a||(a=r[n]=xn());else if(a=i.child,!a)a=xn(),i.child=a,i.childKey=n;else if(i.childKey!==n){let e=i.childKey;if(e===void 0)i.childKey=n;else{let t=xn();t[e]=a,a=t[n]=xn(),i.child=void 0,i.childKey=void 0,i.children=t}}i=a}n&&(i.isLeaf=!0),r&&wn(i,r)}function Cn(e,t,n,r,i,a=2){let o=e.child;if(o){let s=e.childKey;if(e.isLeaf){if(En(e,t,n,i),!o.invocation||s===void 0)return}else if(s===void 0){En(e,t,n,i);return}n.push(s),Cn(o,t,n,r+1,i,a),n.pop();return}let s=e.children;if(!s){En(e,t,n,i);return}if(e.isLeaf||r>=a){En(e,t,n,i);for(let e in s){let o=s[e];o.invocation&&(n.push(e),Cn(o,t,n,r+1,i,a),n.pop())}return}for(let e in s)n.push(e),Cn(s[e],t,n,r+1,i,a),n.pop()}function wn(e,t){let n=e.invocation;if(!n){e.invocation=t;return}if(Tn(n,t))return;let r=e.extraInvocations;if(!r){e.extraInvocations=[t];return}for(let e=0;e<r.length;e++)if(Tn(r[e],t))return;r.push(t)}function Tn(e,t){let n=e.args,r=t.args,i=n?.length??0;if(i!==(r?.length??0))return!1;if(!n||!r)return!0;for(let e=0;e<i;e++)if(!Object.is(n[e],r[e]))return!1;return!0}function En(e,t,n,r){let i=n.slice(),a=e.invocation;if(!a){r.push({store:t,path:i});return}r.push({store:t,path:i,invocation:a});let o=e.extraInvocations;if(o)for(let e=0;e<o.length;e++)r.push({store:t,path:i,invocation:o[e]})}function Dn(e,t,n){for(let n of e){let e=n.invocation?kn(n.path,n.invocation):On(n.path);t(n.store,e,n.path)}n&&jn(e)}function On(e){return e.length?t=>An(t,e):d}function kn(e,t){let n=e.slice(0,-1),r=e[e.length-1];return e=>{let i=An(e,n),a=i&&typeof i==`object`?Reflect.get(i,r):void 0;return typeof a==`function`?Reflect.apply(a,i,t.args??yn):void 0}}function An(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n||typeof n!=`object`)return n;n=Reflect.get(n,t[e])}return n}function jn(e){let t=e.length;console.log(`[π‘ ${t} ${$t(`Proxy Subscription`,t)} π‘]:`,JSON.stringify(e.map(e=>{let t=Mn(e.store),n=e.path.join(`.`);if(!e.invocation)return n?`$(${t}).${n}`:`$(${t})`;let r=e.invocation.args?.length??0;return`$(${t}).${n}${r?`(${r}_${$t(`arg`,r)})`:`()`}`}),null,2))}function Mn(e){return`name`in e&&typeof e.name==`string`?e.name:`store`}const Nn=Symbol(),Pn=Symbol(),Fn=Symbol(`stores.derivedStore.readDependencyState`);function In(e,t=Object.is){let n,r=!1,i,a=!1,o=!1;typeof t==`function`?i=t:(n=t.debounce,r=l?t.debugMode??!1:!1,i=t.equalityFn??Object.is,a=t.keepAlive??!1,o=t.lockDependencies??!1);let s=new nn,c=new tn(A),u=+!!a,f,p,m=Nn,h=!1,g=!1,_=!0,v=!0,y=null,b=Pn;function x(e,t,n){if(!v)return(t??d)(zn(e));if(!u)return(t??d)(e.getState());if(!t){let t=zn(e);return!t||typeof t!=`object`?(c.retainState(e),t):(f||(f=new WeakMap),p||(p=bn()),ln(e,t,f,p.trackPath))}let r=n?{equalityFn:n,isCascadeParticipant:!0}:en;return c.addSelector(e.subscribe(t,A,r)),t(zn(e))}function S(){if(!_&&$(m))return m;_=!1,v&&c.beginRebuild(!0);let t=!0,n=m,a=$(n);g=!0;try{let o=e(x),s=p?fn(o):o;a&&i(n,s)?(r&&console.log(`[π₯· Derive Complete π₯·]: No change detected`),t=!1,m=n):m=s}finally{g=!1,v&&c.finishRebuild(!0)}let s=r&&(!a||r===`verbose`&&v);if(s){a?r===`verbose`&&console.log(`[π Rebuilding Subscriptions π]: Createdβ¦`):console.log(`[π Initial Derive Complete π]: Createdβ¦`);let e=c.size;console.log(`[π― ${e} ${$t(`Selector Subscription`,e)} π―]`)}return p&&v&&(p.buildProxySubscriptions((e,t)=>{c.addSelector(e.subscribe(t,A,en))},s),f=void 0,o?p=void 0:p.reset()),t&&a&&C(m,n),o&&(v=!1),m}function C(e,t){let n=s.cascadeParticipantCount,i=n>0&&s.ordinaryWatcherCount>0,a=s.ordinaryWatcherCount>0&&(i||Xe()!==null||Ye());if(i&&Ze(),r){let e=s.ordinaryWatcherCount+n;console.log(`[π» Derive Complete π»]: Notifying ${e} ${$t(`watcher`,e)}`)}if(n&&s.notifyCascade(e,t),s.ordinaryWatcherCount){if(a){b===Pn?(b=t,et(w)):$(b)||(b=t);return}s.notifyOrdinary(e,t)}}function w(){u&&_&&!s.cascadeParticipantCount&&S();let e=b;b=Pn,s.ordinaryWatcherCount&&$(m)&&e!==Pn&&$(e)&&s.notifyOrdinary(m,e)}let T=n?Tt(D,typeof n==`number`?n:n.delay,typeof n==`number`?{leading:!1,maxWait:n,trailing:!0}:n):void 0,E=T??(()=>{h||(h=!0,queueMicrotask(D))});function D(){if(h=!1,!u){a||I();return}_&&S()}function O(e){if(e!==void 0&&(e||T&&_)){queueMicrotask(O);return}!u&&!a&&I()}function k(){let e=y;e===Xe()&&(D(),y===e&&(y=null))}function A(){if(!g){if(!T){if(s.cascadeParticipantCount){_=!0,Ze();let e=Xe(),t=e===null?0:e+1;if(y!==null&&t<=y)return;y=t,tt(k,t);return}if(_)return;if(_=!0,Ye()){b===Pn&&(b=Nn,et(w));return}}_||(_=!0,y=null,E())}}function j(e){u+=1;try{return e()}finally{--u}}function ee(){return _||!$(m)?u?S():j(S):(h&&u&&D(),m)}function M(){return Ye()&&Xe()===null&&$e(),_||!$(m)?u?S():e(x):m}function N(...e){if(e.length===1){let t=e[0];return s.addWatcher(t)&&(u+=1),$(m)||M(),()=>{s.deleteWatcher(t)&&(--u,u||O(!1))}}let[t,n,r]=e,i=r?.equalityFn??Object.is,a=r?.isCascadeParticipant??!1,o=t(u?M():j(M)),c={currentSlice:o,equalityFn:i,isCascadeParticipant:a,listener:n,selector:t};return s.addWatcher(c),u+=1,r?.fireImmediately&&n(o,o),()=>{s.deleteWatcher(c)&&(--u,u||O(a))}}function P(e){return u?M():j(M),s.addCascadeStateListener(e)&&(u+=1),()=>{s.deleteCascadeStateListener(e)&&(--u,u||O(!0))}}function F(){u&&(T?T.flush():_&&S())}function I(){T?.cancel(),c.clear(),s.clear(),u=0,p=void 0,f=void 0,v=!0,h=!1,g=!1,_=!0,m=Nn,b=Pn,y=null}function L(){return _||h||!$(m)?u?S():j(S):m}return{[Fn]:L,[Q]:P,destroy:I,flushUpdates:F,getSnapshot:ee,getState:M,subscribe:N,getInitialState:Ln,setState:Rn}}function Ln(){throw Error(`[createDerivedStore]: getInitialState() is not available on derived stores.`)}function Rn(){throw Error(`[createDerivedStore]: setState() is not available on derived stores.`)}function zn(e){let t=e[Fn];return t?t():e.getState()}function $(e){return e!==Nn}var Bn=class{constructor(e){this.count=0,this.lastSubscriptionTime=null,this.fetchThrottleMs=null,this.onSubscribe=null,this.onLastUnsubscribe=null,e&&(this.fetchThrottleMs=q.seconds(5))}init({onSubscribe:e,onLastUnsubscribe:t}){this.onSubscribe=e,this.onLastUnsubscribe=t}hasSubscribers(){return this.count>0}subscribe(){let e=this.count===0,t=this.fetchThrottleMs!==null,n=t&&this.lastSubscriptionTime!==null&&!e&&Date.now()-this.lastSubscriptionTime<=this.fetchThrottleMs;return this.count+=1,this.onSubscribe?.(e,n),t&&(this.lastSubscriptionTime=Date.now()),e=>{let t=this.count===1;this.count=Math.max(this.count-1,0),t&&(this.onLastUnsubscribe?.(e),this.lastSubscriptionTime=null)}}};function Vn(e,t=queueMicrotask){let n=!1,r;function i(){n=!1,e(...r)}function a(...e){r=e,!n&&(n=!0,t(i))}return a}const Hn=Symbol(`stores.queryParamConfig`);function Un(e,t){return{[Hn]:!0,key:t.key,value:e}}function Wn(e){return!!e&&typeof e==`object`&&Hn in e}function Gn(e){return JSON.stringify(qn(e))}function Kn(e){return JSON.parse(e)}function qn(e){return typeof e!=`object`||!e?e:Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=F(r)?qn(r):r,t},f())}const Jn=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function Yn(e,t,n){let r=f(),i=null,a=!1;if(e)for(let n in e){if(!N(e,n))continue;let o=Xn(r,e[n],n,t);o&&((i??(i=f()))[n]=o,o.key!==void 0&&(a=!0))}return{buildKey(e=r){return Gn(a?tr(i,e):e)},complete(e){return e?ir(e,n)?e:{...r,...e}:$n(r)},get(){return $n(r)},subscribe(e){return er(i,r,e)}}}function Xn(e,t,n,r){return Wn(t)?Qn(e,t.value,n,r,t.key):Qn(e,t,n,r)}function Zn(e,t){let n=[],r,i;function a(e,t,a){return t?(n.push(n=>e.subscribe(t,n,nr(a))),t(rr(e))):(r??(r=bn()),i??(i=new WeakMap),ln(e,rr(e),i,r.trackPath))}function o(e,t=d){return t(rr(e))}let s=e(a,t),c=r?fn(s):s;return r&&(r.buildProxySubscriptions((e,t)=>{n.push(n=>e.subscribe(t,n,Jn))},!1),r=void 0),i=void 0,{initialValue:c,subscribe(r){let i=()=>r(e(o,t)),a=n.map(e=>e(i));return e=>{for(let t of a)t(e)}}}}function Qn(e,t,n,r,i){if(ar(t)){let a=Zn(t,r);return e[n]=a.initialValue,i===void 0?{tracked:a}:{key:i,tracked:a}}return e[n]=t,i===void 0?null:{key:i}}function $n(e){let t=f();for(let n in e)N(e,n)&&(t[n]=e[n]);return t}function er(e,t,n){if(!e)return m;let r;for(let i in e){let a=e[i]?.tracked;a&&(r??(r=[])).push(a.subscribe(e=>{let r=t[i];Ie(r,e)||(t[i]=e,n(i,r,e))}))}return r?e=>{for(let t of r)t(e)}:m}function tr(e,t){let n=f();for(let r in t){if(!N(t,r))continue;let i=e?.[r];if(i?.key===!1)continue;let a=t[r];n[r]=i?.key?i.key(a):a}return n}function nr(e){return e?{equalityFn:e,isCascadeParticipant:!0}:Jn}function rr(e){return Te(e)?e.getSnapshot():e.getState()}function ir(e,t){for(let n of t)if(!(n in e))return!1;return!0}function ar(e){return typeof e==`function`}const or={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},sr=Object.freeze({force:!0}),cr=Object.freeze({once:!0}),lr=new Set;let ur=!1;function dr(e){lr.add(e),!ur&&(ur=!0,queueMicrotask(()=>{ur=!1,Ve(fr)}))}function fr(){for(let e of lr)lr.delete(e),e()}function pr(e,t,n){ae();let r=typeof t==`function`?t:_r,i=typeof t==`object`?t:n,a=mr(i)?i:void 0,o=le(),s=o.minStaleTime,{fetcher:c,onError:d=o.onError,onFetched:f,setData:m,transform:h,abortInterruptedFetches:g=o.abortInterruptedFetches,cacheTime:_=o.cacheTime,debugMode:v=o.debugMode,disableAutoRefetching:y=o.disableAutoRefetching,disableCache:b=!1,enabled:x=!0,keepPreviousData:S=o.keepPreviousData,paramChangeThrottle:C=o.paramChangeThrottle,params:w,retry:T=o.retry,retryDelay:E=o.retryDelay,staleTime:D=o.staleTime,suppressStaleTimeWarning:O=o.suppressStaleTimeWarning}=e,k=typeof D==`function`?o.staleTime:D;l&&s!==!1&&!y&&!O&&k<s&&console.warn(`[createQueryStore${a?.storageKey?`: ${a.storageKey}`:``}] β Stale times under ${s/1e3} seconds are not recommended. Provided staleTime: ${k/1e3} seconds`);let A=Error(`[createQueryStore: AbortError] Fetch interrupted`),ee=typeof _==`function`,M=l&&v,N=e.params?Object.keys(e.params):[],P=!1,F,I=[],R=null,z=null,B=null,V=null,H=null,U=null,ne=null,re={enabled:typeof x==`function`?!1:x,error:null,lastFetchedAt:null,queryCache:{},queryKey:``,status:K.Idle},W=new Bn(y);function ie(){B&&(V=null,B.abort(),B=null)}function G(){H&&(clearTimeout(H),H=null)}async function oe(e){let t=new AbortController;B=t;try{return await new Promise((n,r)=>{t.signal.addEventListener(`abort`,()=>r(A),cr),Promise.resolve(c(e,t)).then(n,r)})}finally{B===t&&(B=null)}}function se(e,t,n){let i=n.setState;function o(e,t){e!==t&&ne!==t&&(ne=t,t&&W.hasSubscribers()?queueMicrotask(()=>p.fetch(void 0,void 0,!0)):(H||g)&&(g&&ie(),G()))}function s(e){let t=typeof e==`function`;if(t||e.enabled!==void 0){let n,r=i(r=>{let i=t?e(r):e,a=i.enabled===void 0?r.enabled:i.enabled;return a!==r.enabled&&(n=()=>o(r.enabled,a)),i});return n?.(),r}else return i(e)}n.setState=s,W.init({onSubscribe:(n,r)=>{let i=t();if(i.enabled)if(n){let t=F.get(),n=F.buildKey(t);i.queryKey!==n&&e({queryKey:n}),i.isStale()?p.fetch(t,void 0,!0):l(t)}else y&&!r&&p.fetch(void 0,void 0,!0)},onLastUnsubscribe:e=>{G(),g&&!e&&ie()}});function l(e){if(y||k<=0||k===1/0||!W.hasSubscribers())return;G();let n=t();if(!n.enabled)return;let r=F.buildKey(e),i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null,a=i?k-(Date.now()-i):k;H=setTimeout(()=>{t().enabled&&p.fetch(e,sr,!0)},a)}function u(e){let n=t(),r=n.status;switch(e){case`isIdle`:return r===K.Idle;case`isLoading`:return r===K.Loading;case`isError`:case`isInitialLoad`:case`isSuccess`:case void 0:{let t=n.queryKey,i=b?void 0:n.queryCache[t],a=b?r===K.Error:typeof i?.errorInfo?.lastFailedAt==`number`;if(e===`isError`)return a;let o=((b?U===t&&n.lastFetchedAt:i?.lastFetchedAt)||null)!==null,s=!o&&!a&&n.enabled;if(e===`isInitialLoad`)return s;let c=o&&!a;return e===`isSuccess`?c:{isError:a,isIdle:r===K.Idle,isLoading:r===K.Loading,isInitialLoad:s,isSuccess:c}}}}let p={...r(s,t,n),...re,async fetch(n,r,i=!1,o=0){let u=!!r?.skipStoreUpdates,v=t();if(!u&&(!v.enabled&&!r?.force||i&&!W.hasSubscribers()))return null;let y=v.error,x=v.queryKey,C=v.status===K.Loading,w=F.complete(n),D=F.buildKey(w);if(C&&V?.promise&&V.key===D)return M&&console.log(`[π Using Active Fetch π] for params:`,JSON.stringify(w)),V.promise;let O=r?.staleTime??k,P=typeof r?.updateQueryKey==`boolean`?r.updateQueryKey:i?S:!1,I=(i||x===D||P)&&!u,R=V!==null;if(g&&I&&ie(),!r?.force){let t=v.lastFetchedAt,n=b?void 0:v.queryCache[D],r=n?.lastFetchedAt,i=n?.errorInfo,a=(b?U===D&&t:r)||null;if(!(!a||Date.now()-a>=O)&&(!i||!i.retryAllowed||u))return I&&!H&&k!==0&&k!==1/0&&l(w),P&&e(e=>e.queryKey===D?e:{queryKey:D}),M&&console.log(`[πΎ Returning Cached Data πΎ] for params:`,JSON.stringify(w)),n?.data??null}let z=I?{key:D}:null,B=r?.cacheTime??(ee?_(w):_);z&&(G(),P&&!R&&v.lastFetchedAt===null&&x!==D?e({error:null,queryKey:D,status:K.Loading}):(y||!C)&&e({error:null,status:K.Loading}),V=z);async function ne(){let v=a?.storageKey||D;try{M&&(!i&&n&&N.some(e=>!(e in n))?console.log(`[π Fetching with Partial Params π]
|
|
7
|
+
`,`- Provided params:`,`${JSON.stringify(n)}\n`,`- Filled in params:`,`${JSON.stringify(Object.fromEntries(Object.keys(w).filter(e=>!(e in n)).map(e=>[e,w[e]])))}`):console.log(`[π Fetching π] for params:`,JSON.stringify(w)));let t=await(g&&I?oe(w):c(w,null)),a=Date.now();M&&console.log(`[β
Fetch Successful β
] for params:`,JSON.stringify(w));let o;try{o=yr(t,w,h)}catch(e){throw vr(v,`transform`,e)}if(u)return M&&console.log(`[π₯· Successful Parallel Fetch π₯·] for params:`,JSON.stringify(w)),r.skipStoreUpdates===`withCache`&&e(e=>{if(!m)return b?e:{queryCache:{...e.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}}};let t=e,n=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw vr(v,`setData`,e)}return!b&&Object.is(n,t.queryCache[D])&&(t={...t,queryCache:{...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}}}),t}),o;if((m?s:e)(e=>{let t={...e,error:null,lastFetchedAt:a,queryKey:P?D:e.queryKey,status:K.Success};if(!m&&!b)M&&console.log(`[πΎ Setting Cache πΎ] for params:`,JSON.stringify(w),`| Has previous data?:`,!!t.queryCache[D]?.data),t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:o,errorInfo:null,lastFetchedAt:a}};else if(m){M&&console.log(`[πΎ Setting Data πΎ] for params:`,JSON.stringify(w));let e=b?void 0:t.queryCache[D];try{m({data:o,params:w,queryKey:D,set:e=>{t=typeof e==`function`?{...t,...e(t)}:{...t,...e}}})}catch(e){throw vr(v,`setData`,e)}!b&&Object.is(e,t.queryCache[D])&&(t.queryCache={...t.queryCache,[D]:{cacheTime:B,data:null,errorInfo:null,lastFetchedAt:a}})}return b||_===1/0?t:gr(S,D,t)}),I&&(U=D,l(w)),f)try{f({data:o,fetch:p.fetch,params:w,set:s})}catch(e){j.error(vr(v,`onFetched callback`,e))}return o??null}catch(n){if(n===A)return M&&console.log(`[β Fetch Aborted β] for params:`,JSON.stringify(w)),null;let a=!i&&r?.throwOnError===!0,s=te(n);if(s instanceof L&&j.error(s),!I){if(a)throw s;return null}let c=b?void 0:t().queryCache[D],l,u;if(typeof T==`function`){l={error:s,params:w,queryKey:D,retryCount:o};try{u=T(l)}catch(e){j.error(vr(v,`retry callback`,e)),u=!1}}else u=T!==!1&&o<T;let f;if(u&&t().enabled&&W.hasSubscribers())if(E===void 0)f=de(o);else if(typeof E==`number`)f=E;else{l??(l={error:s,params:w,queryKey:D,retryCount:o});try{f=E(l)}catch(e){j.error(vr(v,`retryDelay callback`,e)),u=!1}}let m=f!==void 0;if(f!==void 0&&(G(),H=setTimeout(()=>{t().enabled&&p.fetch(w,sr,!0,o+1)},f)),e(b?e=>({error:s,queryKey:P?D:e.queryKey,status:K.Error}):e=>({error:s,queryCache:{...e.queryCache,[D]:{cacheTime:c?.cacheTime??B,data:c?.data??null,lastFetchedAt:c?.lastFetchedAt??null,errorInfo:{error:s,lastFailedAt:Date.now(),retryAllowed:u,retryCount:o}}},queryKey:P?D:e.queryKey,status:K.Error})),d)try{d({error:s,params:w,queryKey:D,retryCount:o,willRetry:m})}catch(e){j.error(vr(v,`onError callback`,e))}if(a)throw s;return null}finally{V===z&&(V=null)}}return z?(z.promise=ne(),z.promise):ne()},getCacheEntry(e){if(b)return null;let n=t(),r=e?typeof e==`string`?e:F.buildKey(F.complete(e)):n.queryKey;return n.queryCache[r]??null},getData(e){if(b)return null;let n=t().getCacheEntry(e);return!n||n.data===null?null:S?n.data:n.lastFetchedAt&&Date.now()-n.lastFetchedAt>=n.cacheTime?null:n.data},getStatus:u,isDataExpired(e){let n=t(),r=n.queryKey,i=b?void 0:n.queryCache[r],a=n.lastFetchedAt,o=(b?U===r&&a:i?.lastFetchedAt)||null;if(!o)return!0;let s=e??i?.cacheTime;return s===void 0||Date.now()-o>=s},isStale(e){let n=t(),r=n.queryKey,i=(b?U===r&&n.lastFetchedAt:n.queryCache[r]?.lastFetchedAt)||null;if(!i)return!0;let a=e??k;return Date.now()-i>=a},reset(t=!1){for(let e of I)e();I=[],F=Yn(void 0,q,N),R=null,z=null,ie(),G(),_e?.cancel(),V=null,U=null,t&&e(re)}},v=n.subscribe;return n.subscribe=(...e)=>{let t=P?void 0:W.subscribe(),n=e.length===1?v(e[0]):v(e[0],e[1],e[2]);return e=>{t?.(e),n(e)}},lt(n,e=>t=>{let n=P?void 0:W.subscribe(),r=e(t);return e=>{n?.(e),r(e)}}),p}let q=a?.storageKey?Zt(se,p(a,{partialize:hr(S,a.partialize)})):i&&!(`storageKey`in i)?Zt(se,i):Zt(se),ce=q.getState(),ue=ce.error,fe=ce.enabled,pe=ce.queryKey,me=ce.fetch;pe&&!ue&&(U=pe),P=!0,F=Yn(w,q,N),typeof x==`function`&&(R=Zn(x,q)),typeof e.staleTime==`function`&&(z=Zn(e.staleTime,q),k=z.initialValue);let he=Vn(e=>{me(e,void 0,!0)},dr);function ge(){if(S)he(void 0);else{let e=F.get();q.setState({queryKey:F.buildKey(e)}),he(e)}}let _e=u||!C?void 0:Tt(ge,typeof C==`number`?C:C.delay,typeof C==`number`?{leading:!1,maxWait:C,trailing:!0}:C);function ve(){if(G(),_e){let e=q.getState();S&&V?.key===e.queryKey&&e.lastFetchedAt===null?ge():_e();return}ge()}if(I.push(F.subscribe((e,t,n)=>{M&&console.log(`[π Param Change π] -`,e,`- [Old]:`,`${t?.toString()},`,`[New]:`,n?.toString()),ve()})),z){let e=z.initialValue;M&&console.log(`[π StaleTime Subscription π] Initial value:`,e),I.push(z.subscribe(t=>{t!==e&&(M&&console.log(`[π StaleTime Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,k=t,G(),me(void 0,void 0,!0))}))}let J;if(R){let e=R.initialValue;fe!==e&&((J??(J={})).enabled=e),M&&console.log(`[π Enabled Subscription π] Initial value:`,e),I.push(R.subscribe(t=>{t!==e&&(M&&console.log(`[π Enabled Change π] - [Old]:`,`${e},`,`[New]:`,t),e=t,q.setState({enabled:t}))}))}else fe!==re.enabled&&((J??(J={})).enabled=re.enabled);let xe=F.buildKey();return xe!==pe&&((J??(J={})).queryKey=xe),J&&q.setState(J),P=!1,be(q,ye.QueryStore)}function mr(e){return typeof e?.storageKey==`string`}function hr(e,t){return n=>{let r={...n},i=f();for(let e in r)N(r,e)&&e in or&&(or[e]&&(i[e]=r[e]),delete r[e]);return{...t?t(r):kt(r),...gr(e,null,i)}}}function gr(e,t,n){if(!n.queryCache)return n;let r=Date.now(),i=t??(e&&n.queryKey||null),a=f(),o=!1;for(let e in n.queryCache){if(!N(n.queryCache,e))continue;let t=n.queryCache[e];t&&(r-(t.lastFetchedAt??t.errorInfo.lastFailedAt)<t.cacheTime||e===i)?a[e]=t:o=!0}return o?{...n,queryCache:a}:n}function _r(){return Object.create(null)}function vr(e,t,n){return new L(`[createQueryStore: ${e}]: ${t} failed`,n)}function yr(e,t,n){return n?n(e,t):e}const br=Object.freeze({equalityFn:Object.is,isCascadeParticipant:!0});function xr(e,t,n){let r=typeof t==`function`,i=r?t:void 0,a=r?n:t,o=new Set,s,c;function l(e,t){let n=e.getState(),r=t.getState();if(c)for(let e of c)u(e,t,n,r);if(s)for(let e of s)d(e,t,n,r);o.size&&Qe();for(let e of o)f(e,t,n,r)}function u(e,t,n,r){e.unsubscribe(),e.unsubscribe=Sr(t,e.listener),!Object.is(r,n)&&(Ze(),e.listener(r,n))}function d(e,t,n,r){f(e,t,n,r)&&Ze()}function f(e,t,n,r){e.unsubscribe();let i=e.args;if(i.length===1){let a=i[0];e.unsubscribe=t.subscribe(a);let o=!Object.is(r,n);return o&&a(r,n),o}let a=i[0],o=i[1],s=i[2];s?.fireImmediately&&(s={...s,fireImmediately:!1});let c=a(n),l=a(r);return e.unsubscribe=t.subscribe(a,o,s),(s?.equalityFn??Object.is)(c,l)?!1:(o(l,c),!0)}function p(e,t){l(t,e),J(t)}let m=In(e,{debugMode:a?.debugMode??!1,lockDependencies:a?.lockDependencies??!0}),h;function g(){return h??(h=m.subscribe(p)),m.getState()}function _(...e){let t=g(),n={args:e,unsubscribe:e.length===1?t.subscribe(e[0]):t.subscribe(e[0],e[1],e[2])},r=e[2]?.isCascadeParticipant??!1;return r?(s??(s=new Set)).add(n):o.add(n),()=>{n.unsubscribe(),r?s?.delete(n)&&s.size===0&&(s=void 0):o.delete(n)}}function v(e){let t={listener:e,unsubscribe:Sr(g(),e)};return(c??(c=new Set)).add(t),e=>{t.unsubscribe(e),c?.delete(t)&&c.size===0&&(c=void 0)}}return Object.assign({[Q]:v,[ye.VirtualStore]:!0,destroy:()=>{h?.(),h=void 0,m.destroy()},getInitialState:()=>g().getInitialState(),getState:()=>g().getState(),persist:Cr(g),setState:wr(g),subscribe:_},i?.(g))}function Sr(e,t){return ct(e)?e[Q](t):e.subscribe(d,t,br)}function Cr(e){return{clearStorage:()=>e().persist?.clearStorage(),getOptions:()=>e().persist?.getOptions()??{},hasHydrated:()=>e().persist?.hasHydrated()??!0,hydrationPromise:()=>e().persist?.hydrationPromise?.()??Promise.resolve(),onFinishHydration:t=>e().persist?.onFinishHydration(t)??m,onHydrate:t=>e().persist?.onHydrate(t)??m,rehydrate:()=>e().persist?.rehydrate(),setOptions:t=>e().persist?.setOptions(t)}}function wr(e){return function(...t){return t[1]===!0?e().setState(t[0],!0):e().setState(t[0])}}function Tr(e,t){let n=Zt(e,t);return D(n,n.getState,n.getInitialState)}function Er(e,t=Object.is){let n=In(e,t);return D(n,n.getSnapshot,void 0)}function Dr(e,t,n){let r=pr(e,t,n);return D(r,r.getState,r.getInitialState)}function Or(e,t,n){let r=xr(e,t,n);return D(r,r.getState,r.getInitialState)}const kr=Symbol();function Ar(e){let t=r(kr);return t.current===kr&&(t.current=e()),t}const jr=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1});function Mr(e,t,r,i=jr){let a=Ar(()=>Ir(t,r,i)),o=Rr(i);return zr(a,t,r,i),n(()=>{if(o)return Pr(e,a),()=>Fr(a)},[o,e]),a}const Nr=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function Pr(e,t,n=Nr){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=Nr)=>Pr(e,t,n);let r=e.subscribe(e=>t.current.selector(e),(n,i)=>t.current.react(n,i,e.getState,()=>{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 Fr(e){e.current.options.debugMode&&console.log(`[ποΈ useListen ποΈ] Detaching listener`),e.current.resubscribe=m,e.current.unsubscribe(),e.current.unsubscribe=m,e.current.isActive=!1}function Ir(e,t,n){return{selector:e,react:t,isActive:!1,options:Lr(n),resubscribe:m,unsubscribe:m}}function Lr(e){return typeof e==`function`?{equalityFn:e}:e??jr}function Rr(e){return typeof e==`function`?jr.enabled:e?.enabled??jr.enabled}function zr(e,t,n,r){e.current.selector=t,e.current.react=n,typeof r==`function`?e.current.options.equalityFn=r:r&&(e.current.options=r??jr)}const Br=Symbol();function Vr(e){let t=r(Br);return t.current===Br&&(t.current=e()),t.current}export{K as QueryStatuses,L as StoresError,pe as applyStateUpdate,re as configureStores,Tr as createBaseStore,Er as createDerivedStore,Dr as createQueryStore,Ae as createStoreActions,Or as createVirtualStore,Pe as deepEqual,de as defaultRetryDelay,J as destroyStore,xe as destroyStores,Gn as getQueryKey,Se as getStoreName,Te as hasGetSnapshot,d as identity,De as isDerivedStore,Oe as isPersistedStore,Ee as isQueryStore,ke as isVirtualStore,f as nullObject,Kn as parseQueryKey,Un as queryParam,_e as replacer,ve as reviver,Fe as shallowEqual,q as time,Mr as useListen,Vr as useStableValue};
|