comwit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ TODO
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),Te=require("react/jsx-runtime"),Pe=Symbol(),Z=Object.getPrototypeOf,N=new WeakMap,Re=e=>e&&(N.has(e)?N.get(e):Z(e)===Object.prototype||Z(e)===Array.prototype),Ee=e=>Re(e)&&e[Pe]||null,J=(e,t=!0)=>{N.set(e,t)},I={},$=e=>typeof e=="object"&&e!==null,ve=e=>$(e)&&!Q.has(e)&&(Array.isArray(e)||!(Symbol.iterator in e))&&!(e instanceof WeakMap)&&!(e instanceof WeakSet)&&!(e instanceof Error)&&!(e instanceof Number)&&!(e instanceof Date)&&!(e instanceof String)&&!(e instanceof RegExp)&&!(e instanceof ArrayBuffer)&&!(e instanceof Promise),ue=(e,t)=>{const r=X.get(e);if(r?.[0]===t)return r[1];const n=Array.isArray(e)?[]:Object.create(Object.getPrototypeOf(e));return J(n,!0),X.set(e,[t,n]),Reflect.ownKeys(e).forEach(o=>{if(Object.getOwnPropertyDescriptor(n,o))return;const c=Reflect.get(e,o),{enumerable:i}=Reflect.getOwnPropertyDescriptor(e,o),s={value:c,enumerable:i,configurable:!0};if(Q.has(c))J(c,!1);else if(R.has(c)){const[u,l]=R.get(c);s.value=ue(u,l())}Object.defineProperty(n,o,s)}),Object.preventExtensions(n)},xe=(e,t,r,n)=>({deleteProperty(o,c){Reflect.get(o,c),r(c);const i=Reflect.deleteProperty(o,c);return i&&n(void 0),i},set(o,c,i,s){const u=!e()&&Reflect.has(o,c),l=Reflect.get(o,c,s);if(u&&(ee(l,i)||F.has(i)&&ee(l,F.get(i))))return!0;r(c),$(i)&&(i=Ee(i)||i);const d=!R.has(i)&&ke(i)?ae(i):i;return t(c,d),Reflect.set(o,c,d,s),n(void 0),!0}}),R=new WeakMap,Q=new WeakSet,X=new WeakMap,q=[1],F=new WeakMap;let ee=Object.is,De=(e,t)=>new Proxy(e,t),ke=ve,_e=ue,ze=xe;function ae(e={}){if(!$(e))throw new Error("object required");const t=F.get(e);if(t)return t;let r=q[0];const n=new Set,o=(f,g=++q[0])=>{r!==g&&(c=r=g,n.forEach(p=>p(f,g)))};let c=r;const i=(f=q[0])=>(c!==f&&(c=f,u.forEach(([g])=>{const p=g[1](f);p>r&&(r=p)})),r),s=f=>(g,p)=>{let j;g&&(j=[...g],j[1]=[f,...j[1]]),o(j,p)},u=new Map,l=(f,g)=>{const p=!Q.has(g)&&R.get(g);if(p){if((I?"production":void 0)!=="production"&&u.has(f))throw new Error("prop listener already exists");if(n.size){const j=p[2](s(f));u.set(f,[p,j])}else u.set(f,[p])}},d=f=>{var g;const p=u.get(f);p&&(u.delete(f),(g=p[1])==null||g.call(p))},O=f=>(n.add(f),n.size===1&&u.forEach(([p,j],T)=>{if((I?"production":void 0)!=="production"&&j)throw new Error("remove already exists");const _=p[2](s(T));u.set(T,[p,_])}),()=>{n.delete(f),n.size===0&&u.forEach(([p,j],T)=>{j&&(j(),u.set(T,[p]))})});let b=!0;const y=ze(()=>b,l,d,o),a=De(e,y);F.set(e,a);const h=[e,i,O];return R.set(a,h),Reflect.ownKeys(e).forEach(f=>{const g=Object.getOwnPropertyDescriptor(e,f);"value"in g&&g.writable&&(a[f]=e[f])}),b=!1,a}function Ie(e,t,r){const n=R.get(e);(I?"production":void 0)!=="production"&&!n&&console.warn("Please use proxy object");let o;const c=[],i=n[2];let s=!1;const l=i(d=>{d&&c.push(d),o||(o=Promise.resolve().then(()=>{o=void 0,s&&t(c.splice(0))}))});return s=!0,()=>{s=!1,l()}}function Fe(e){const t=R.get(e);(I?"production":void 0)!=="production"&&!t&&console.warn("Please use proxy object");const[r,n]=t;return _e(r,n())}function Me(e){return ae(e)}function M(e){return Fe(e)}function Le(e,t){return Ie(e,t)}const H=Symbol("comwit-resource");function qe(e,t){return t}const Ce=new Set(["force","placeholderData","staleTime","cacheTime","gcTime"]);function fe(){return{boundResourceValue:new WeakMap,boundPathProxy:new WeakMap,boundResourceRuntime:new WeakMap}}function Be(e){const t={data:e.initialData,isLoading:!1,isFetching:!1,isSuccess:!1,isError:!1,error:null},{initialData:r,queryFn:n,...o}=e;return{...t,kind:"single",[H]:!0,initialState:t,options:o,queryFn:n}}function Ne(e){const t={data:e.initialData,cursor:null,hasMore:!1,isLoading:!1,isFetching:!1,isSuccess:!1,isError:!1,error:null},{initialData:r,queryFn:n,...o}=e;return{...t,kind:"infinite",[H]:!0,initialState:t,options:o,queryFn:n}}const Ue=Object.assign(e=>Be(e),{infinite:Ne});function We(e){return typeof e=="object"&&e!==null&&e[H]===!0}function Ke(e,t){const r=`${t}.`,n=`${t}[`;for(const o of e.keys())if(o===t||o.startsWith(r)||o.startsWith(n))return!0;return!1}function $e(e){return e instanceof Error?e.message:"Unknown error"}function D(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function le(e){if(!D(e))return!1;for(const t of Object.keys(e))if(Ce.has(t))return!0;return!1}function Qe(e){if(typeof e.cacheTime=="number")return e.cacheTime;if(typeof e.gcTime=="number")return e.gcTime}function He(e,t,r=!1){if(t!==void 0){if(Array.isArray(t)){e.data=t;return}if(D(t)){const n="data"in t;if(r&&n&&Array.isArray(e.data)&&Array.isArray(t.data)){const o={...t,data:[...e.data,...t.data]};Object.assign(e,o);return}if(n){Object.assign(e,t);return}Object.assign(e,t);return}e.data=t}}function te(e){return{state:M(e)}}function C(e){return e.length===1&&le(e[0])?{hasArg:!1,arg:void 0,options:e[0]}:e.length===0?{hasArg:!1,arg:void 0,options:void 0}:{hasArg:!0,arg:e[0],options:e[1]}}function U(e,t=new WeakSet){if(e===null||typeof e!="object")return e;if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(c=>U(c,t));if(t.has(e))return"[Circular]";t.add(e);const r=e,n=Object.keys(r).sort(),o={};for(const c of n)o[c]=U(r[c],t);return t.delete(e),o}function Ve(e){try{const t=JSON.stringify(U(e));return t===void 0?"__undefined__":t}catch{return`__unserializable__:${String(e)}`}}function Ye(e){return{path:e,lastArg:void 0,activeKey:void 0,cacheEntries:new Map}}function Ge(e,t,r,n){return{key:t,arg:r,hasQueried:!1,lastFetchedAt:0,cursorHistory:[],gcTime:n,state:M(e)}}function ne(e,t){Object.assign(e,t.state),e.isLoading=!1,e.isFetching=!1}function Ze(e,t){e.state=M(t)}function Je(e,t){for(const[r,n]of e.cacheEntries)typeof n.gcTime=="number"&&n.lastFetchedAt!==0&&(t-n.lastFetchedAt<n.gcTime||(e.cacheEntries.delete(r),e.activeKey===r&&(e.activeKey=void 0,e.lastArg=void 0)))}function Xe(e,t,r){if(r!==void 0){if(typeof r=="function"){e.data=r(t,e.data);return}e.data=r}}function et(e,t,r){const n=e.options;return{...t,...n,...le(r)?r:{}}}function tt(e,t,r,n,o){if(o.boundResourceValue.has(e))return o.boundResourceValue.get(e);const c=o.boundResourceRuntime.get(e)??Ye(r);c.path=r,o.boundResourceRuntime.set(e,c);const i=()=>{if(c.activeKey)return c.cacheEntries.get(c.activeKey)},s=async(y,a,h,f,g=!1)=>{const p=i();if(g&&!p?.hasQueried)return;const j=et(t,n,a),T=typeof j.staleTime=="number"?j.staleTime:0,_=Qe(j),G=Date.now();Je(c,G);const P=g?p?.arg:h?y:c.lastArg,z=Ve(P);c.lastArg=P,c.activeKey=z;let m=c.cacheEntries.get(z);if(m||(m=Ge(e,z,P,_),c.cacheEntries.set(z,m)),m.gcTime=_,m.arg=P,!(g||!m.hasQueried||j.force===!0||T===0||G-m.lastFetchedAt>=T)&&m.hasQueried)return ne(e,m),m.lastResult;if(m.hasQueried&&ne(e,m),Xe(e,P,j.placeholderData),t.kind==="infinite"){const A=m.cursorHistory,w=e.cursor;f==="replace"?A.length===0?A.push(w):(A.length=1,A[0]=w):f==="append"&&A[A.length-1]!==w&&A.push(w)}e.isLoading=!e.isSuccess&&!e.isError,e.isFetching=!0,e.isError=!1,e.error=null;try{let A;if(t.kind==="single"?(A=await t.queryFn(P,te(e)),A!==void 0&&(e.data=A)):(A=await t.queryFn(P,te(e)),He(e,A,f==="append")),e.isSuccess=!0,m.hasQueried=!0,m.lastFetchedAt=Date.now(),m.lastResult=A,Ze(m,e),t.kind==="infinite"){const w=m.cursorHistory,L=e.cursor;f==="append"&&w[w.length-1]!==L?w.push(L):f==="replace"&&w.length>0&&(w[w.length-1]=L)}return A}catch(A){throw e.isError=!0,e.isSuccess=!1,e.error=$e(A),A}finally{e.isLoading=!1,e.isFetching=!1}},u=(...y)=>{const a=C(y);return s(a.arg,a.options,a.hasArg,"replace",!1)},l=()=>{const y=i();if(y?.hasQueried)return s(y.arg,void 0,!0,"replace",!0)},d=(...y)=>{const a=C(y);if(t.kind!=="infinite"||!e.hasMore)return;const h=i();if(!h)return;const f=a.hasArg?a.arg:h.arg;return s(f,a.options,!0,"append",!1)},O=(...y)=>{const a=C(y);if(t.kind!=="infinite")return;const h=i();if(!h)return;if(h.cursorHistory.length<2)return h.lastResult;h.cursorHistory.pop();const f=a.hasArg?a.arg:h.arg;return s(f,a.options,!0,"replace",!1)},b=new Proxy(e,{get(y,a){return a==="query"?u:a==="refetch"?l:a==="nextFetch"?t.kind==="infinite"?d:void 0:a==="previousFetch"?t.kind==="infinite"?O:void 0:a==="set"?h=>(D(h)?Object.assign(y,h):y.data=h,y.isSuccess=!0,y.isError=!1,y.error=null,h):Reflect.get(y,a)}});return o.boundResourceValue.set(e,b),b}function ye(e,t,r="",n,o){if(!t.size)return e;const c=o.boundPathProxy.get(e);if(c?.has(r))return c.get(r);const i=new Proxy(e,{get(u,l,d){if(typeof l=="symbol")return Reflect.get(u,l,d);const O=String(l),b=r?Array.isArray(u)?`${r}[${O}]`:`${r}.${O}`:O,y=t.get(b),a=Reflect.get(u,l,d);return y&&D(a)?tt(a,y,b,n,o):D(a)&&Ke(t,b)?ye(a,t,b,n,o):a}}),s=o.boundPathProxy.get(e)??new Map;return s.set(r,i),o.boundPathProxy.set(e,s),i}function nt(e,t,r,n=fe()){return t.size?ye(e,t,"",r,n):e}const de=S.createContext(null);function ge(){const e=S.useContext(de);if(!e)throw new Error("Wrap your app with <MuchaProvider>");return e}function rt({children:e,defaultOptions:t,context:r={}}){const n=S.useRef({queryDefaults:t?.query,context:{},stores:new Map,queryBinding:fe(),get(o){const c=n.current.stores.get(o.key);if(c)return c;const i=o.instance();return n.current.stores.set(o.key,i),i}});return Object.keys(n.current.context).forEach(o=>delete n.current.context[o]),Object.assign(n.current.context,r),n.current.queryDefaults=t?.query,Te.jsx(de.Provider,{value:n.current,children:e})}function pe(e,t,{signal:r,edges:n}={}){let o,c=null;const i=n!=null&&n.includes("leading"),s=n==null||n.includes("trailing"),u=()=>{c!==null&&(e.apply(o,c),o=void 0,c=null)},l=()=>{s&&u(),y()};let d=null;const O=()=>{d!=null&&clearTimeout(d),d=setTimeout(()=>{d=null,l()},t)},b=()=>{d!==null&&(clearTimeout(d),d=null)},y=()=>{b(),o=void 0,c=null},a=()=>{u()},h=function(...f){if(r?.aborted)return;o=this,c=f;const g=d==null;O(),i&&g&&u()};return h.schedule=O,h.cancel=y,h.flush=a,r?.addEventListener("abort",y,{once:!0}),h}function ot(...e){return function(...t){let r=e.length?e[0].apply(this,t):t[0];for(let n=1;n<e.length;n++)r=e[n].call(this,r);return r}}function ct(){}function it(e,t,{signal:r,edges:n=["leading","trailing"]}={}){let o=null;const c=pe(function(...s){o=Date.now(),e.apply(this,s)},t,{signal:r,edges:n}),i=function(...s){if(o==null&&(o=Date.now()),Date.now()-o>=t){o=Date.now(),e.apply(this,s),c.cancel(),c.schedule();return}c.apply(this,s)};return i.cancel=c.cancel,i.flush=c.flush,i}function re(e){return Object.getOwnPropertySymbols(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function oe(e){return e==null?e===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const st="[object RegExp]",ut="[object String]",at="[object Number]",ft="[object Boolean]",ce="[object Arguments]",lt="[object Symbol]",yt="[object Date]",dt="[object Map]",gt="[object Set]",pt="[object Array]",ht="[object Function]",bt="[object ArrayBuffer]",B="[object Object]",mt="[object Error]",At="[object DataView]",jt="[object Uint8Array]",Ot="[object Uint8ClampedArray]",wt="[object Uint16Array]",St="[object Uint32Array]",Tt="[object BigUint64Array]",Pt="[object Int8Array]",Rt="[object Int16Array]",Et="[object Int32Array]",vt="[object BigInt64Array]",xt="[object Float32Array]",Dt="[object Float64Array]";function ie(e){if(!e||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(e)==="[object Object]":!1}function kt(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function _t(e,t,r){return v(e,t,void 0,void 0,void 0,void 0,r)}function v(e,t,r,n,o,c,i){const s=i(e,t,r,n,o,c);if(s!==void 0)return s;if(typeof e==typeof t)switch(typeof e){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return e===t;case"number":return e===t||Object.is(e,t);case"function":return e===t;case"object":return x(e,t,c,i)}return x(e,t,c,i)}function x(e,t,r,n){if(Object.is(e,t))return!0;let o=oe(e),c=oe(t);if(o===ce&&(o=B),c===ce&&(c=B),o!==c)return!1;switch(o){case ut:return e.toString()===t.toString();case at:{const u=e.valueOf(),l=t.valueOf();return kt(u,l)}case ft:case yt:case lt:return Object.is(e.valueOf(),t.valueOf());case st:return e.source===t.source&&e.flags===t.flags;case ht:return e===t}r=r??new Map;const i=r.get(e),s=r.get(t);if(i!=null&&s!=null)return i===t;r.set(e,t),r.set(t,e);try{switch(o){case dt:{if(e.size!==t.size)return!1;for(const[u,l]of e.entries())if(!t.has(u)||!v(l,t.get(u),u,e,t,r,n))return!1;return!0}case gt:{if(e.size!==t.size)return!1;const u=Array.from(e.values()),l=Array.from(t.values());for(let d=0;d<u.length;d++){const O=u[d],b=l.findIndex(y=>v(O,y,void 0,e,t,r,n));if(b===-1)return!1;l.splice(b,1)}return!0}case pt:case jt:case Ot:case wt:case St:case Tt:case Pt:case Rt:case Et:case vt:case xt:case Dt:{if(typeof Buffer<"u"&&Buffer.isBuffer(e)!==Buffer.isBuffer(t)||e.length!==t.length)return!1;for(let u=0;u<e.length;u++)if(!v(e[u],t[u],u,e,t,r,n))return!1;return!0}case bt:return e.byteLength!==t.byteLength?!1:x(new Uint8Array(e),new Uint8Array(t),r,n);case At:return e.byteLength!==t.byteLength||e.byteOffset!==t.byteOffset?!1:x(new Uint8Array(e),new Uint8Array(t),r,n);case mt:return e.name===t.name&&e.message===t.message;case B:{if(!(x(e.constructor,t.constructor,r,n)||ie(e)&&ie(t)))return!1;const l=[...Object.keys(e),...re(e)],d=[...Object.keys(t),...re(t)];if(l.length!==d.length)return!1;for(let O=0;O<l.length;O++){const b=l[O],y=e[b];if(!Object.hasOwn(t,b))return!1;const a=t[b];if(!v(y,a,b,e,t,r,n))return!1}return!0}default:return!1}}finally{r.delete(e),r.delete(t)}}function zt(e,t){return _t(e,t,ct)}let W=!1;function It(e){W=!0;try{e()}finally{W=!1}}function Ft(){return W}function Mt(e){const t=new Map,r=K(e,"",t),n=()=>structuredClone(r);return{key:Symbol(),resources:t,instance(){const c=Me(n());return{proxy:c,getSnapshot(){return M(c)},subscribe(i){return Le(c,()=>{Ft()||i()})}}}}}function he(e,t){const n=ge().get(e),o=S.useRef(null),c=S.useCallback(s=>n.subscribe(s),[n]),i=()=>{const s=n.getSnapshot(),u=t?t(s):s;return o.current!==null&&zt(o.current,u)?o.current:(o.current=u,u)};return S.useSyncExternalStore(c,i,i)}function K(e,t,r){if(We(e)){if(!t)throw new Error("query() entry must be assigned to a model field");return r.set(t,e),e.initialState}if(!e||typeof e!="object")return e;if(Array.isArray(e))return e.map((o,c)=>K(o,`${t}[${c}]`,r));const n={};for(const o of Object.keys(e)){const c=t?`${t}.${o}`:o;n[o]=K(e[o],c,r)}return n}const V=Symbol("mucha.lazyInterceptors");function Lt(e,t){const r=Y(e);return r.length?Object.defineProperty(t,V,{value:[...r],configurable:!0,enumerable:!1,writable:!1}):t}function k(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}function qt(e){return t=>e.reduceRight((r,n)=>n(r),t)}function Ct(e){return(t,r,n)=>{if(!n||typeof n.value!="function")return;const o=n.value;o[V]=[...Y(o),e]}}function Y(e){if(!e||typeof e!="function")return[];const t=e[V];return Array.isArray(t)?t:[]}function E(e){return(t,r,n)=>{if(!n||typeof n.value!="function")return;const o=Lt(n.value,e(n.value));n.value=o}}function Bt(e){return t=>{const r=e(t);return Nt(r,t)}}function be(e){const t=ge(),r=S.useRef(null),n=S.useRef(new Map);if(!r.current){const o=i=>{const s=n.current.get(i.key);if(s)return s;const u=t.get(i);if(!i.resources.size)return n.current.set(i.key,u.proxy),u.proxy;const l=nt(u.proxy,i.resources,t.queryDefaults,t.queryBinding);return n.current.set(i.key,l),l},c=t.context??{};r.current=Object.assign({},...e.map(i=>i({state:o,context:c})))}return r.current}function Nt(e,t){if(!e||typeof e!="object")return{};const r={},n=e;for(const o of Object.getOwnPropertyNames(n)){const c=n[o];if(typeof c!="function"){r[o]=c;continue}r[o]=se(c,n,t)}for(let o=Object.getPrototypeOf(n);o&&o!==Object.prototype;o=Object.getPrototypeOf(o))for(const c of Object.getOwnPropertyNames(o)){if(c==="constructor")continue;const s=Object.getOwnPropertyDescriptor(o,c)?.value;typeof s=="function"&&(r[c]=se(s,n,t))}return r}function se(e,t,r){return Ut(e,r).bind(t)}function Ut(e,t){const r=Y(e);if(!r.length)return e;let n=e;for(const o of r){const c=o({state:t.state,context:t.context});if(typeof c!="function")continue;const i={configurable:!0,enumerable:!0,writable:!0,value:n};c({},"__mucha-action",i),n=i.value}return n}function Wt(e,t){function r(n){const o=be(t.actions),c=s=>({...s,actions:o});return he(e,n?s=>n(c(s)):s=>c(s))}return r}function me(e){return(t=>function(...r){try{const n=t.apply(this,r);return k(n)?Promise.resolve(n).catch(o=>{throw e(o),o}):n}catch(n){throw e(n),n}})}function Kt(e){return E(me(e))}function Ae(e){return(t=>function(...r){const n=t.apply(this,r);return k(n)?Promise.resolve(n).then(o=>(e(o),o)):(e(n),n)})}function $t(e){return E(Ae(e))}function je(e,t){return r=>{const o=pe(function(...c){r.apply(this,c)},e,t);return function(...c){return o.apply(this,c)}}}function Qt(e,t){return E(je(e,t))}function Oe(e,t){return r=>{const o=it(function(...c){r.apply(this,c)},e,t);return function(...c){return o.apply(this,c)}}}function Ht(e,t){return E(Oe(e,t))}function we(){return e=>e}function Vt(){return E(we())}function Se(e){return(t=>function(...r){const n=()=>{if(!e.onDeny)return;const c=e.onDeny();return k(c)?c.then(()=>{}):void 0},o=e.when();return k(o)?Promise.resolve(o).then(c=>c?t.apply(this,r):n()):o?t.apply(this,r):n()})}function Yt(e){return E(Se(e))}exports.Authorized=Yt;exports.Debounce=Qt;exports.MuchaProvider=rt;exports.OnError=Kt;exports.OnSuccess=$t;exports.Throttle=Ht;exports.Transaction=Vt;exports.action=Bt;exports.composeInterceptors=qt;exports.create=Wt;exports.createDecorator=E;exports.createInterceptor=Ct;exports.debounce=je;exports.isThenable=k;exports.keepPreviousData=qe;exports.model=Mt;exports.onAuthorized=Se;exports.onError=me;exports.onSuccess=Ae;exports.pipe=ot;exports.query=Ue;exports.silent=It;exports.throttle=Oe;exports.transaction=we;exports.useAction=be;exports.useModel=he;
package/dist/comwit.js ADDED
@@ -0,0 +1,929 @@
1
+ import { createContext as he, useRef as _, useContext as be, useCallback as me, useSyncExternalStore as Ae } from "react";
2
+ import { jsx as je } from "react/jsx-runtime";
3
+ const Oe = /* @__PURE__ */ Symbol(), Z = Object.getPrototypeOf, N = /* @__PURE__ */ new WeakMap(), we = (e) => e && (N.has(e) ? N.get(e) : Z(e) === Object.prototype || Z(e) === Array.prototype), Se = (e) => we(e) && e[Oe] || null, J = (e, t = !0) => {
4
+ N.set(e, t);
5
+ }, F = {}, $ = (e) => typeof e == "object" && e !== null, Te = (e) => $(e) && !Q.has(e) && (Array.isArray(e) || !(Symbol.iterator in e)) && !(e instanceof WeakMap) && !(e instanceof WeakSet) && !(e instanceof Error) && !(e instanceof Number) && !(e instanceof Date) && !(e instanceof String) && !(e instanceof RegExp) && !(e instanceof ArrayBuffer) && !(e instanceof Promise), ue = (e, t) => {
6
+ const r = X.get(e);
7
+ if (r?.[0] === t)
8
+ return r[1];
9
+ const n = Array.isArray(e) ? [] : Object.create(Object.getPrototypeOf(e));
10
+ return J(n, !0), X.set(e, [t, n]), Reflect.ownKeys(e).forEach((o) => {
11
+ if (Object.getOwnPropertyDescriptor(n, o))
12
+ return;
13
+ const c = Reflect.get(e, o), { enumerable: i } = Reflect.getOwnPropertyDescriptor(
14
+ e,
15
+ o
16
+ ), s = {
17
+ value: c,
18
+ enumerable: i,
19
+ // This is intentional to avoid copying with proxy-compare.
20
+ // It's still non-writable, so it avoids assigning a value.
21
+ configurable: !0
22
+ };
23
+ if (Q.has(c))
24
+ J(c, !1);
25
+ else if (P.has(c)) {
26
+ const [u, l] = P.get(
27
+ c
28
+ );
29
+ s.value = ue(u, l());
30
+ }
31
+ Object.defineProperty(n, o, s);
32
+ }), Object.preventExtensions(n);
33
+ }, Pe = (e, t, r, n) => ({
34
+ deleteProperty(o, c) {
35
+ Reflect.get(o, c), r(c);
36
+ const i = Reflect.deleteProperty(o, c);
37
+ return i && n(void 0), i;
38
+ },
39
+ set(o, c, i, s) {
40
+ const u = !e() && Reflect.has(o, c), l = Reflect.get(o, c, s);
41
+ if (u && (ee(l, i) || z.has(i) && ee(l, z.get(i))))
42
+ return !0;
43
+ r(c), $(i) && (i = Se(i) || i);
44
+ const d = !P.has(i) && Re(i) ? fe(i) : i;
45
+ return t(c, d), Reflect.set(o, c, d, s), n(void 0), !0;
46
+ }
47
+ }), P = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakSet(), X = /* @__PURE__ */ new WeakMap(), C = [1], z = /* @__PURE__ */ new WeakMap();
48
+ let ee = Object.is, Ee = (e, t) => new Proxy(e, t), Re = Te, ve = ue, xe = Pe;
49
+ function fe(e = {}) {
50
+ if (!$(e))
51
+ throw new Error("object required");
52
+ const t = z.get(e);
53
+ if (t)
54
+ return t;
55
+ let r = C[0];
56
+ const n = /* @__PURE__ */ new Set(), o = (a, g = ++C[0]) => {
57
+ r !== g && (c = r = g, n.forEach((p) => p(a, g)));
58
+ };
59
+ let c = r;
60
+ const i = (a = C[0]) => (c !== a && (c = a, u.forEach(([g]) => {
61
+ const p = g[1](a);
62
+ p > r && (r = p);
63
+ })), r), s = (a) => (g, p) => {
64
+ let j;
65
+ g && (j = [...g], j[1] = [a, ...j[1]]), o(j, p);
66
+ }, u = /* @__PURE__ */ new Map(), l = (a, g) => {
67
+ const p = !Q.has(g) && P.get(g);
68
+ if (p) {
69
+ if ((F ? "production" : void 0) !== "production" && u.has(a))
70
+ throw new Error("prop listener already exists");
71
+ if (n.size) {
72
+ const j = p[2](s(a));
73
+ u.set(a, [p, j]);
74
+ } else
75
+ u.set(a, [p]);
76
+ }
77
+ }, d = (a) => {
78
+ var g;
79
+ const p = u.get(a);
80
+ p && (u.delete(a), (g = p[1]) == null || g.call(p));
81
+ }, O = (a) => (n.add(a), n.size === 1 && u.forEach(([p, j], S) => {
82
+ if ((F ? "production" : void 0) !== "production" && j)
83
+ throw new Error("remove already exists");
84
+ const D = p[2](s(S));
85
+ u.set(S, [p, D]);
86
+ }), () => {
87
+ n.delete(a), n.size === 0 && u.forEach(([p, j], S) => {
88
+ j && (j(), u.set(S, [p]));
89
+ });
90
+ });
91
+ let b = !0;
92
+ const y = xe(
93
+ () => b,
94
+ l,
95
+ d,
96
+ o
97
+ ), f = Ee(e, y);
98
+ z.set(e, f);
99
+ const h = [e, i, O];
100
+ return P.set(f, h), Reflect.ownKeys(e).forEach((a) => {
101
+ const g = Object.getOwnPropertyDescriptor(
102
+ e,
103
+ a
104
+ );
105
+ "value" in g && g.writable && (f[a] = e[a]);
106
+ }), b = !1, f;
107
+ }
108
+ function De(e, t, r) {
109
+ const n = P.get(e);
110
+ (F ? "production" : void 0) !== "production" && !n && console.warn("Please use proxy object");
111
+ let o;
112
+ const c = [], i = n[2];
113
+ let s = !1;
114
+ const l = i((d) => {
115
+ d && c.push(d), o || (o = Promise.resolve().then(() => {
116
+ o = void 0, s && t(c.splice(0));
117
+ }));
118
+ });
119
+ return s = !0, () => {
120
+ s = !1, l();
121
+ };
122
+ }
123
+ function ke(e) {
124
+ const t = P.get(e);
125
+ (F ? "production" : void 0) !== "production" && !t && console.warn("Please use proxy object");
126
+ const [r, n] = t;
127
+ return ve(r, n());
128
+ }
129
+ function _e(e) {
130
+ return fe(e);
131
+ }
132
+ function L(e) {
133
+ return ke(e);
134
+ }
135
+ function Fe(e, t) {
136
+ return De(e, t);
137
+ }
138
+ const H = /* @__PURE__ */ Symbol("comwit-resource");
139
+ function Nt(e, t) {
140
+ return t;
141
+ }
142
+ const ze = /* @__PURE__ */ new Set([
143
+ "force",
144
+ "placeholderData",
145
+ "staleTime",
146
+ "cacheTime",
147
+ "gcTime"
148
+ ]);
149
+ function ae() {
150
+ return {
151
+ boundResourceValue: /* @__PURE__ */ new WeakMap(),
152
+ boundPathProxy: /* @__PURE__ */ new WeakMap(),
153
+ boundResourceRuntime: /* @__PURE__ */ new WeakMap()
154
+ };
155
+ }
156
+ function Ie(e) {
157
+ const t = {
158
+ data: e.initialData,
159
+ isLoading: !1,
160
+ isFetching: !1,
161
+ isSuccess: !1,
162
+ isError: !1,
163
+ error: null
164
+ }, {
165
+ initialData: r,
166
+ queryFn: n,
167
+ ...o
168
+ } = e;
169
+ return {
170
+ ...t,
171
+ kind: "single",
172
+ [H]: !0,
173
+ initialState: t,
174
+ options: o,
175
+ queryFn: n
176
+ };
177
+ }
178
+ function Le(e) {
179
+ const t = {
180
+ data: e.initialData,
181
+ cursor: null,
182
+ hasMore: !1,
183
+ isLoading: !1,
184
+ isFetching: !1,
185
+ isSuccess: !1,
186
+ isError: !1,
187
+ error: null
188
+ }, {
189
+ initialData: r,
190
+ queryFn: n,
191
+ ...o
192
+ } = e;
193
+ return {
194
+ ...t,
195
+ kind: "infinite",
196
+ [H]: !0,
197
+ initialState: t,
198
+ options: o,
199
+ queryFn: n
200
+ };
201
+ }
202
+ const Ut = Object.assign(
203
+ (e) => Ie(e),
204
+ {
205
+ infinite: Le
206
+ }
207
+ );
208
+ function Me(e) {
209
+ return typeof e == "object" && e !== null && e[H] === !0;
210
+ }
211
+ function Ce(e, t) {
212
+ const r = `${t}.`, n = `${t}[`;
213
+ for (const o of e.keys())
214
+ if (o === t || o.startsWith(r) || o.startsWith(n)) return !0;
215
+ return !1;
216
+ }
217
+ function qe(e) {
218
+ return e instanceof Error ? e.message : "Unknown error";
219
+ }
220
+ function x(e) {
221
+ return typeof e == "object" && e !== null && !Array.isArray(e);
222
+ }
223
+ function le(e) {
224
+ if (!x(e)) return !1;
225
+ for (const t of Object.keys(e))
226
+ if (ze.has(t)) return !0;
227
+ return !1;
228
+ }
229
+ function Be(e) {
230
+ if (typeof e.cacheTime == "number") return e.cacheTime;
231
+ if (typeof e.gcTime == "number") return e.gcTime;
232
+ }
233
+ function Ne(e, t, r = !1) {
234
+ if (t !== void 0) {
235
+ if (Array.isArray(t)) {
236
+ e.data = t;
237
+ return;
238
+ }
239
+ if (x(t)) {
240
+ const n = "data" in t;
241
+ if (r && n && Array.isArray(e.data) && Array.isArray(t.data)) {
242
+ const o = {
243
+ ...t,
244
+ data: [...e.data, ...t.data]
245
+ };
246
+ Object.assign(e, o);
247
+ return;
248
+ }
249
+ if (n) {
250
+ Object.assign(e, t);
251
+ return;
252
+ }
253
+ Object.assign(e, t);
254
+ return;
255
+ }
256
+ e.data = t;
257
+ }
258
+ }
259
+ function te(e) {
260
+ return { state: L(e) };
261
+ }
262
+ function q(e) {
263
+ return e.length === 1 && le(e[0]) ? {
264
+ hasArg: !1,
265
+ arg: void 0,
266
+ options: e[0]
267
+ } : e.length === 0 ? {
268
+ hasArg: !1,
269
+ arg: void 0,
270
+ options: void 0
271
+ } : {
272
+ hasArg: !0,
273
+ arg: e[0],
274
+ options: e[1]
275
+ };
276
+ }
277
+ function U(e, t = /* @__PURE__ */ new WeakSet()) {
278
+ if (e === null || typeof e != "object") return e;
279
+ if (e instanceof Date) return e.toISOString();
280
+ if (Array.isArray(e))
281
+ return e.map((c) => U(c, t));
282
+ if (t.has(e))
283
+ return "[Circular]";
284
+ t.add(e);
285
+ const r = e, n = Object.keys(r).sort(), o = {};
286
+ for (const c of n)
287
+ o[c] = U(r[c], t);
288
+ return t.delete(e), o;
289
+ }
290
+ function Ue(e) {
291
+ try {
292
+ const t = JSON.stringify(U(e));
293
+ return t === void 0 ? "__undefined__" : t;
294
+ } catch {
295
+ return `__unserializable__:${String(e)}`;
296
+ }
297
+ }
298
+ function We(e) {
299
+ return {
300
+ path: e,
301
+ lastArg: void 0,
302
+ activeKey: void 0,
303
+ cacheEntries: /* @__PURE__ */ new Map()
304
+ };
305
+ }
306
+ function Ke(e, t, r, n) {
307
+ return {
308
+ key: t,
309
+ arg: r,
310
+ hasQueried: !1,
311
+ lastFetchedAt: 0,
312
+ cursorHistory: [],
313
+ gcTime: n,
314
+ state: L(e)
315
+ };
316
+ }
317
+ function ne(e, t) {
318
+ Object.assign(e, t.state), e.isLoading = !1, e.isFetching = !1;
319
+ }
320
+ function $e(e, t) {
321
+ e.state = L(t);
322
+ }
323
+ function Qe(e, t) {
324
+ for (const [r, n] of e.cacheEntries)
325
+ typeof n.gcTime == "number" && n.lastFetchedAt !== 0 && (t - n.lastFetchedAt < n.gcTime || (e.cacheEntries.delete(r), e.activeKey === r && (e.activeKey = void 0, e.lastArg = void 0)));
326
+ }
327
+ function He(e, t, r) {
328
+ if (r !== void 0) {
329
+ if (typeof r == "function") {
330
+ e.data = r(
331
+ t,
332
+ e.data
333
+ );
334
+ return;
335
+ }
336
+ e.data = r;
337
+ }
338
+ }
339
+ function Ve(e, t, r) {
340
+ const n = e.options;
341
+ return {
342
+ ...t,
343
+ ...n,
344
+ ...le(r) ? r : {}
345
+ };
346
+ }
347
+ function Ye(e, t, r, n, o) {
348
+ if (o.boundResourceValue.has(e))
349
+ return o.boundResourceValue.get(e);
350
+ const c = o.boundResourceRuntime.get(e) ?? We(r);
351
+ c.path = r, o.boundResourceRuntime.set(e, c);
352
+ const i = () => {
353
+ if (c.activeKey)
354
+ return c.cacheEntries.get(c.activeKey);
355
+ }, s = async (y, f, h, a, g = !1) => {
356
+ const p = i();
357
+ if (g && !p?.hasQueried)
358
+ return;
359
+ const j = Ve(
360
+ t,
361
+ n,
362
+ f
363
+ ), S = typeof j.staleTime == "number" ? j.staleTime : 0, D = Be(j), G = Date.now();
364
+ Qe(c, G);
365
+ const T = g ? p?.arg : h ? y : c.lastArg, k = Ue(T);
366
+ c.lastArg = T, c.activeKey = k;
367
+ let m = c.cacheEntries.get(k);
368
+ if (m || (m = Ke(e, k, T, D), c.cacheEntries.set(k, m)), m.gcTime = D, m.arg = T, !(g || !m.hasQueried || j.force === !0 || S === 0 || G - m.lastFetchedAt >= S) && m.hasQueried)
369
+ return ne(e, m), m.lastResult;
370
+ if (m.hasQueried && ne(e, m), He(
371
+ e,
372
+ T,
373
+ j.placeholderData
374
+ ), t.kind === "infinite") {
375
+ const A = m.cursorHistory, w = e.cursor;
376
+ a === "replace" ? A.length === 0 ? A.push(w) : (A.length = 1, A[0] = w) : a === "append" && A[A.length - 1] !== w && A.push(w);
377
+ }
378
+ e.isLoading = !e.isSuccess && !e.isError, e.isFetching = !0, e.isError = !1, e.error = null;
379
+ try {
380
+ let A;
381
+ if (t.kind === "single" ? (A = await t.queryFn(
382
+ T,
383
+ te(e)
384
+ ), A !== void 0 && (e.data = A)) : (A = await t.queryFn(
385
+ T,
386
+ te(e)
387
+ ), Ne(e, A, a === "append")), e.isSuccess = !0, m.hasQueried = !0, m.lastFetchedAt = Date.now(), m.lastResult = A, $e(m, e), t.kind === "infinite") {
388
+ const w = m.cursorHistory, M = e.cursor;
389
+ a === "append" && w[w.length - 1] !== M ? w.push(M) : a === "replace" && w.length > 0 && (w[w.length - 1] = M);
390
+ }
391
+ return A;
392
+ } catch (A) {
393
+ throw e.isError = !0, e.isSuccess = !1, e.error = qe(A), A;
394
+ } finally {
395
+ e.isLoading = !1, e.isFetching = !1;
396
+ }
397
+ }, u = (...y) => {
398
+ const f = q(y);
399
+ return s(f.arg, f.options, f.hasArg, "replace", !1);
400
+ }, l = () => {
401
+ const y = i();
402
+ if (y?.hasQueried)
403
+ return s(y.arg, void 0, !0, "replace", !0);
404
+ }, d = (...y) => {
405
+ const f = q(y);
406
+ if (t.kind !== "infinite" || !e.hasMore) return;
407
+ const h = i();
408
+ if (!h) return;
409
+ const a = f.hasArg ? f.arg : h.arg;
410
+ return s(a, f.options, !0, "append", !1);
411
+ }, O = (...y) => {
412
+ const f = q(y);
413
+ if (t.kind !== "infinite") return;
414
+ const h = i();
415
+ if (!h) return;
416
+ if (h.cursorHistory.length < 2)
417
+ return h.lastResult;
418
+ h.cursorHistory.pop();
419
+ const a = f.hasArg ? f.arg : h.arg;
420
+ return s(a, f.options, !0, "replace", !1);
421
+ }, b = new Proxy(e, {
422
+ get(y, f) {
423
+ return f === "query" ? u : f === "refetch" ? l : f === "nextFetch" ? t.kind === "infinite" ? d : void 0 : f === "previousFetch" ? t.kind === "infinite" ? O : void 0 : f === "set" ? (h) => (x(h) ? Object.assign(y, h) : y.data = h, y.isSuccess = !0, y.isError = !1, y.error = null, h) : Reflect.get(y, f);
424
+ }
425
+ });
426
+ return o.boundResourceValue.set(e, b), b;
427
+ }
428
+ function ye(e, t, r = "", n, o) {
429
+ if (!t.size) return e;
430
+ const c = o.boundPathProxy.get(e);
431
+ if (c?.has(r))
432
+ return c.get(r);
433
+ const i = new Proxy(e, {
434
+ get(u, l, d) {
435
+ if (typeof l == "symbol") return Reflect.get(u, l, d);
436
+ const O = String(l), b = r ? Array.isArray(u) ? `${r}[${O}]` : `${r}.${O}` : O, y = t.get(b), f = Reflect.get(u, l, d);
437
+ return y && x(f) ? Ye(
438
+ f,
439
+ y,
440
+ b,
441
+ n,
442
+ o
443
+ ) : x(f) && Ce(t, b) ? ye(f, t, b, n, o) : f;
444
+ }
445
+ }), s = o.boundPathProxy.get(e) ?? /* @__PURE__ */ new Map();
446
+ return s.set(r, i), o.boundPathProxy.set(e, s), i;
447
+ }
448
+ function Ge(e, t, r, n = ae()) {
449
+ return t.size ? ye(e, t, "", r, n) : e;
450
+ }
451
+ const de = he(null);
452
+ function ge() {
453
+ const e = be(de);
454
+ if (!e) throw new Error("Wrap your app with <MuchaProvider>");
455
+ return e;
456
+ }
457
+ function Wt({ children: e, defaultOptions: t, context: r = {} }) {
458
+ const n = _({
459
+ queryDefaults: t?.query,
460
+ context: {},
461
+ stores: /* @__PURE__ */ new Map(),
462
+ queryBinding: ae(),
463
+ get(o) {
464
+ const c = n.current.stores.get(o.key);
465
+ if (c) return c;
466
+ const i = o.instance();
467
+ return n.current.stores.set(o.key, i), i;
468
+ }
469
+ });
470
+ return Object.keys(n.current.context).forEach((o) => delete n.current.context[o]), Object.assign(n.current.context, r), n.current.queryDefaults = t?.query, /* @__PURE__ */ je(de.Provider, { value: n.current, children: e });
471
+ }
472
+ function pe(e, t, { signal: r, edges: n } = {}) {
473
+ let o, c = null;
474
+ const i = n != null && n.includes("leading"), s = n == null || n.includes("trailing"), u = () => {
475
+ c !== null && (e.apply(o, c), o = void 0, c = null);
476
+ }, l = () => {
477
+ s && u(), y();
478
+ };
479
+ let d = null;
480
+ const O = () => {
481
+ d != null && clearTimeout(d), d = setTimeout(() => {
482
+ d = null, l();
483
+ }, t);
484
+ }, b = () => {
485
+ d !== null && (clearTimeout(d), d = null);
486
+ }, y = () => {
487
+ b(), o = void 0, c = null;
488
+ }, f = () => {
489
+ u();
490
+ }, h = function(...a) {
491
+ if (r?.aborted)
492
+ return;
493
+ o = this, c = a;
494
+ const g = d == null;
495
+ O(), i && g && u();
496
+ };
497
+ return h.schedule = O, h.cancel = y, h.flush = f, r?.addEventListener("abort", y, { once: !0 }), h;
498
+ }
499
+ function Kt(...e) {
500
+ return function(...t) {
501
+ let r = e.length ? e[0].apply(this, t) : t[0];
502
+ for (let n = 1; n < e.length; n++)
503
+ r = e[n].call(this, r);
504
+ return r;
505
+ };
506
+ }
507
+ function Ze() {
508
+ }
509
+ function Je(e, t, { signal: r, edges: n = ["leading", "trailing"] } = {}) {
510
+ let o = null;
511
+ const c = pe(function(...s) {
512
+ o = Date.now(), e.apply(this, s);
513
+ }, t, { signal: r, edges: n }), i = function(...s) {
514
+ if (o == null && (o = Date.now()), Date.now() - o >= t) {
515
+ o = Date.now(), e.apply(this, s), c.cancel(), c.schedule();
516
+ return;
517
+ }
518
+ c.apply(this, s);
519
+ };
520
+ return i.cancel = c.cancel, i.flush = c.flush, i;
521
+ }
522
+ function re(e) {
523
+ return Object.getOwnPropertySymbols(e).filter((t) => Object.prototype.propertyIsEnumerable.call(e, t));
524
+ }
525
+ function oe(e) {
526
+ return e == null ? e === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(e);
527
+ }
528
+ const Xe = "[object RegExp]", et = "[object String]", tt = "[object Number]", nt = "[object Boolean]", ce = "[object Arguments]", rt = "[object Symbol]", ot = "[object Date]", ct = "[object Map]", it = "[object Set]", st = "[object Array]", ut = "[object Function]", ft = "[object ArrayBuffer]", B = "[object Object]", at = "[object Error]", lt = "[object DataView]", yt = "[object Uint8Array]", dt = "[object Uint8ClampedArray]", gt = "[object Uint16Array]", pt = "[object Uint32Array]", ht = "[object BigUint64Array]", bt = "[object Int8Array]", mt = "[object Int16Array]", At = "[object Int32Array]", jt = "[object BigInt64Array]", Ot = "[object Float32Array]", wt = "[object Float64Array]";
529
+ function ie(e) {
530
+ if (!e || typeof e != "object")
531
+ return !1;
532
+ const t = Object.getPrototypeOf(e);
533
+ return t === null || t === Object.prototype || Object.getPrototypeOf(t) === null ? Object.prototype.toString.call(e) === "[object Object]" : !1;
534
+ }
535
+ function St(e, t) {
536
+ return e === t || Number.isNaN(e) && Number.isNaN(t);
537
+ }
538
+ function Tt(e, t, r) {
539
+ return R(e, t, void 0, void 0, void 0, void 0, r);
540
+ }
541
+ function R(e, t, r, n, o, c, i) {
542
+ const s = i(e, t, r, n, o, c);
543
+ if (s !== void 0)
544
+ return s;
545
+ if (typeof e == typeof t)
546
+ switch (typeof e) {
547
+ case "bigint":
548
+ case "string":
549
+ case "boolean":
550
+ case "symbol":
551
+ case "undefined":
552
+ return e === t;
553
+ case "number":
554
+ return e === t || Object.is(e, t);
555
+ case "function":
556
+ return e === t;
557
+ case "object":
558
+ return v(e, t, c, i);
559
+ }
560
+ return v(e, t, c, i);
561
+ }
562
+ function v(e, t, r, n) {
563
+ if (Object.is(e, t))
564
+ return !0;
565
+ let o = oe(e), c = oe(t);
566
+ if (o === ce && (o = B), c === ce && (c = B), o !== c)
567
+ return !1;
568
+ switch (o) {
569
+ case et:
570
+ return e.toString() === t.toString();
571
+ case tt: {
572
+ const u = e.valueOf(), l = t.valueOf();
573
+ return St(u, l);
574
+ }
575
+ case nt:
576
+ case ot:
577
+ case rt:
578
+ return Object.is(e.valueOf(), t.valueOf());
579
+ case Xe:
580
+ return e.source === t.source && e.flags === t.flags;
581
+ case ut:
582
+ return e === t;
583
+ }
584
+ r = r ?? /* @__PURE__ */ new Map();
585
+ const i = r.get(e), s = r.get(t);
586
+ if (i != null && s != null)
587
+ return i === t;
588
+ r.set(e, t), r.set(t, e);
589
+ try {
590
+ switch (o) {
591
+ case ct: {
592
+ if (e.size !== t.size)
593
+ return !1;
594
+ for (const [u, l] of e.entries())
595
+ if (!t.has(u) || !R(l, t.get(u), u, e, t, r, n))
596
+ return !1;
597
+ return !0;
598
+ }
599
+ case it: {
600
+ if (e.size !== t.size)
601
+ return !1;
602
+ const u = Array.from(e.values()), l = Array.from(t.values());
603
+ for (let d = 0; d < u.length; d++) {
604
+ const O = u[d], b = l.findIndex((y) => R(O, y, void 0, e, t, r, n));
605
+ if (b === -1)
606
+ return !1;
607
+ l.splice(b, 1);
608
+ }
609
+ return !0;
610
+ }
611
+ case st:
612
+ case yt:
613
+ case dt:
614
+ case gt:
615
+ case pt:
616
+ case ht:
617
+ case bt:
618
+ case mt:
619
+ case At:
620
+ case jt:
621
+ case Ot:
622
+ case wt: {
623
+ if (typeof Buffer < "u" && Buffer.isBuffer(e) !== Buffer.isBuffer(t) || e.length !== t.length)
624
+ return !1;
625
+ for (let u = 0; u < e.length; u++)
626
+ if (!R(e[u], t[u], u, e, t, r, n))
627
+ return !1;
628
+ return !0;
629
+ }
630
+ case ft:
631
+ return e.byteLength !== t.byteLength ? !1 : v(new Uint8Array(e), new Uint8Array(t), r, n);
632
+ case lt:
633
+ return e.byteLength !== t.byteLength || e.byteOffset !== t.byteOffset ? !1 : v(new Uint8Array(e), new Uint8Array(t), r, n);
634
+ case at:
635
+ return e.name === t.name && e.message === t.message;
636
+ case B: {
637
+ if (!(v(e.constructor, t.constructor, r, n) || ie(e) && ie(t)))
638
+ return !1;
639
+ const l = [...Object.keys(e), ...re(e)], d = [...Object.keys(t), ...re(t)];
640
+ if (l.length !== d.length)
641
+ return !1;
642
+ for (let O = 0; O < l.length; O++) {
643
+ const b = l[O], y = e[b];
644
+ if (!Object.hasOwn(t, b))
645
+ return !1;
646
+ const f = t[b];
647
+ if (!R(y, f, b, e, t, r, n))
648
+ return !1;
649
+ }
650
+ return !0;
651
+ }
652
+ default:
653
+ return !1;
654
+ }
655
+ } finally {
656
+ r.delete(e), r.delete(t);
657
+ }
658
+ }
659
+ function Pt(e, t) {
660
+ return Tt(e, t, Ze);
661
+ }
662
+ let W = !1;
663
+ function $t(e) {
664
+ W = !0;
665
+ try {
666
+ e();
667
+ } finally {
668
+ W = !1;
669
+ }
670
+ }
671
+ function Et() {
672
+ return W;
673
+ }
674
+ function Qt(e) {
675
+ const t = /* @__PURE__ */ new Map(), r = K(e, "", t), n = () => structuredClone(r);
676
+ return {
677
+ key: /* @__PURE__ */ Symbol(),
678
+ resources: t,
679
+ instance() {
680
+ const c = _e(n());
681
+ return {
682
+ proxy: c,
683
+ getSnapshot() {
684
+ return L(c);
685
+ },
686
+ subscribe(i) {
687
+ return Fe(c, () => {
688
+ Et() || i();
689
+ });
690
+ }
691
+ };
692
+ }
693
+ };
694
+ }
695
+ function Rt(e, t) {
696
+ const n = ge().get(e), o = _(null), c = me((s) => n.subscribe(s), [n]), i = () => {
697
+ const s = n.getSnapshot(), u = t ? t(s) : s;
698
+ return o.current !== null && Pt(o.current, u) ? o.current : (o.current = u, u);
699
+ };
700
+ return Ae(c, i, i);
701
+ }
702
+ function K(e, t, r) {
703
+ if (Me(e)) {
704
+ if (!t) throw new Error("query() entry must be assigned to a model field");
705
+ return r.set(t, e), e.initialState;
706
+ }
707
+ if (!e || typeof e != "object") return e;
708
+ if (Array.isArray(e))
709
+ return e.map((o, c) => K(o, `${t}[${c}]`, r));
710
+ const n = {};
711
+ for (const o of Object.keys(e)) {
712
+ const c = t ? `${t}.${o}` : o;
713
+ n[o] = K(e[o], c, r);
714
+ }
715
+ return n;
716
+ }
717
+ const V = /* @__PURE__ */ Symbol("mucha.lazyInterceptors");
718
+ function vt(e, t) {
719
+ const r = Y(e);
720
+ return r.length ? Object.defineProperty(t, V, {
721
+ value: [...r],
722
+ configurable: !0,
723
+ enumerable: !1,
724
+ writable: !1
725
+ }) : t;
726
+ }
727
+ function I(e) {
728
+ return e !== null && typeof e == "object" && typeof e.then == "function";
729
+ }
730
+ function Ht(e) {
731
+ return (t) => e.reduceRight((r, n) => n(r), t);
732
+ }
733
+ function Vt(e) {
734
+ return (t, r, n) => {
735
+ if (!n || typeof n.value != "function") return;
736
+ const o = n.value;
737
+ o[V] = [
738
+ ...Y(o),
739
+ e
740
+ ];
741
+ };
742
+ }
743
+ function Y(e) {
744
+ if (!e || typeof e != "function") return [];
745
+ const t = e[V];
746
+ return Array.isArray(t) ? t : [];
747
+ }
748
+ function E(e) {
749
+ return (t, r, n) => {
750
+ if (!n || typeof n.value != "function") return;
751
+ const o = vt(n.value, e(n.value));
752
+ n.value = o;
753
+ };
754
+ }
755
+ function Yt(e) {
756
+ return (t) => {
757
+ const r = e(t);
758
+ return Dt(r, t);
759
+ };
760
+ }
761
+ function xt(e) {
762
+ const t = ge(), r = _(null), n = _(/* @__PURE__ */ new Map());
763
+ if (!r.current) {
764
+ const o = (i) => {
765
+ const s = n.current.get(i.key);
766
+ if (s) return s;
767
+ const u = t.get(i);
768
+ if (!i.resources.size)
769
+ return n.current.set(i.key, u.proxy), u.proxy;
770
+ const l = Ge(
771
+ u.proxy,
772
+ i.resources,
773
+ t.queryDefaults,
774
+ t.queryBinding
775
+ );
776
+ return n.current.set(i.key, l), l;
777
+ }, c = t.context ?? {};
778
+ r.current = Object.assign(
779
+ {},
780
+ ...e.map((i) => i({ state: o, context: c }))
781
+ );
782
+ }
783
+ return r.current;
784
+ }
785
+ function Dt(e, t) {
786
+ if (!e || typeof e != "object") return {};
787
+ const r = {}, n = e;
788
+ for (const o of Object.getOwnPropertyNames(n)) {
789
+ const c = n[o];
790
+ if (typeof c != "function") {
791
+ r[o] = c;
792
+ continue;
793
+ }
794
+ r[o] = se(c, n, t);
795
+ }
796
+ for (let o = Object.getPrototypeOf(n); o && o !== Object.prototype; o = Object.getPrototypeOf(o))
797
+ for (const c of Object.getOwnPropertyNames(o)) {
798
+ if (c === "constructor") continue;
799
+ const s = Object.getOwnPropertyDescriptor(o, c)?.value;
800
+ typeof s == "function" && (r[c] = se(s, n, t));
801
+ }
802
+ return r;
803
+ }
804
+ function se(e, t, r) {
805
+ return kt(e, r).bind(t);
806
+ }
807
+ function kt(e, t) {
808
+ const r = Y(e);
809
+ if (!r.length) return e;
810
+ let n = e;
811
+ for (const o of r) {
812
+ const c = o({ state: t.state, context: t.context });
813
+ if (typeof c != "function") continue;
814
+ const i = {
815
+ configurable: !0,
816
+ enumerable: !0,
817
+ writable: !0,
818
+ value: n
819
+ };
820
+ c({}, "__mucha-action", i), n = i.value;
821
+ }
822
+ return n;
823
+ }
824
+ function Gt(e, t) {
825
+ function r(n) {
826
+ const o = xt(t.actions), c = (s) => ({ ...s, actions: o });
827
+ return Rt(e, n ? (s) => n(c(s)) : (s) => c(s));
828
+ }
829
+ return r;
830
+ }
831
+ function _t(e) {
832
+ return ((t) => function(...r) {
833
+ try {
834
+ const n = t.apply(this, r);
835
+ return I(n) ? Promise.resolve(n).catch((o) => {
836
+ throw e(o), o;
837
+ }) : n;
838
+ } catch (n) {
839
+ throw e(n), n;
840
+ }
841
+ });
842
+ }
843
+ function Zt(e) {
844
+ return E(_t(e));
845
+ }
846
+ function Ft(e) {
847
+ return ((t) => function(...r) {
848
+ const n = t.apply(this, r);
849
+ return I(n) ? Promise.resolve(n).then((o) => (e(o), o)) : (e(n), n);
850
+ });
851
+ }
852
+ function Jt(e) {
853
+ return E(Ft(e));
854
+ }
855
+ function zt(e, t) {
856
+ return (r) => {
857
+ const o = pe(function(...c) {
858
+ r.apply(this, c);
859
+ }, e, t);
860
+ return function(...c) {
861
+ return o.apply(this, c);
862
+ };
863
+ };
864
+ }
865
+ function Xt(e, t) {
866
+ return E(zt(e, t));
867
+ }
868
+ function It(e, t) {
869
+ return (r) => {
870
+ const o = Je(function(...c) {
871
+ r.apply(this, c);
872
+ }, e, t);
873
+ return function(...c) {
874
+ return o.apply(this, c);
875
+ };
876
+ };
877
+ }
878
+ function en(e, t) {
879
+ return E(It(e, t));
880
+ }
881
+ function Lt() {
882
+ return (e) => e;
883
+ }
884
+ function tn() {
885
+ return E(Lt());
886
+ }
887
+ function Mt(e) {
888
+ return ((t) => function(...r) {
889
+ const n = () => {
890
+ if (!e.onDeny)
891
+ return;
892
+ const c = e.onDeny();
893
+ return I(c) ? c.then(() => {
894
+ }) : void 0;
895
+ }, o = e.when();
896
+ return I(o) ? Promise.resolve(o).then((c) => c ? t.apply(this, r) : n()) : o ? t.apply(this, r) : n();
897
+ });
898
+ }
899
+ function nn(e) {
900
+ return E(Mt(e));
901
+ }
902
+ export {
903
+ nn as Authorized,
904
+ Xt as Debounce,
905
+ Wt as MuchaProvider,
906
+ Zt as OnError,
907
+ Jt as OnSuccess,
908
+ en as Throttle,
909
+ tn as Transaction,
910
+ Yt as action,
911
+ Ht as composeInterceptors,
912
+ Gt as create,
913
+ E as createDecorator,
914
+ Vt as createInterceptor,
915
+ zt as debounce,
916
+ I as isThenable,
917
+ Nt as keepPreviousData,
918
+ Qt as model,
919
+ Mt as onAuthorized,
920
+ _t as onError,
921
+ Ft as onSuccess,
922
+ Kt as pipe,
923
+ Ut as query,
924
+ $t as silent,
925
+ It as throttle,
926
+ Lt as transaction,
927
+ xt as useAction,
928
+ Rt as useModel
929
+ };
@@ -0,0 +1,11 @@
1
+ import { BoundResourceState } from './query';
2
+ export type State = <T extends object>(model: Model<T>) => BoundResourceState<T>;
3
+ export type ActionContext<TContext extends object = Record<string, never>> = {
4
+ state: State;
5
+ context: TContext;
6
+ };
7
+ export type ActionFactory<A, TContext extends object = Record<string, never>> = (ctx: ActionContext<TContext>) => A;
8
+ export declare function action<A, C extends object = Record<string, never>>(factory: ActionFactory<A, C>): ActionFactory<A, C>;
9
+ export declare function useAction<A, C extends object = Record<string, never>>(factories: ActionFactory<Partial<A>, C>[]): A;
10
+ type Model<T extends object> = import('./model').Model<T>;
11
+ export {};
@@ -0,0 +1,17 @@
1
+ import { model, Model, useModel } from './model';
2
+ import { action, ActionFactory, useAction } from './action';
3
+ import { MuchaProvider } from './provider';
4
+ import { silent } from './silent';
5
+ import { keepPreviousData, PlaceholderData, Query, QueryDefaultOptions, QueryQueryOptions, query } from './query';
6
+ declare function create<S extends object, A>(m: Model<S>, options: {
7
+ actions: ActionFactory<Partial<A>, any>[];
8
+ }): {
9
+ (): S & {
10
+ actions: A;
11
+ };
12
+ <R>(selector: (state: S & {
13
+ actions: A;
14
+ }) => R): R;
15
+ };
16
+ export { model, action, useAction, useModel, create, silent, MuchaProvider, query, keepPreviousData, };
17
+ export type { Query, PlaceholderData, QueryDefaultOptions, QueryQueryOptions };
@@ -0,0 +1,14 @@
1
+ import { ResourceDescriptorMap } from './query';
2
+ export type StoreEntry<T extends object = any> = {
3
+ proxy: T;
4
+ getSnapshot(): T;
5
+ subscribe(listener: () => void): () => void;
6
+ };
7
+ export declare function model<T extends object>(initial: T): Model<T>;
8
+ export type Model<T extends object> = {
9
+ key: symbol;
10
+ resources: ResourceDescriptorMap;
11
+ instance(): StoreEntry<T>;
12
+ };
13
+ export declare function useModel<T extends object>(m: Model<T>): T;
14
+ export declare function useModel<T extends object, R>(m: Model<T>, selector: (state: T) => R): R;
@@ -0,0 +1,19 @@
1
+ import { default as React } from 'react';
2
+ import { QueryBindingRegistry, QueryDefaultOptions } from './query';
3
+ import { Model, StoreEntry } from './model';
4
+ export type RegistryDefaults = {
5
+ query?: QueryDefaultOptions;
6
+ };
7
+ export type MuchaProviderProps = {
8
+ children: React.ReactNode;
9
+ context?: Record<string, unknown>;
10
+ defaultOptions?: RegistryDefaults;
11
+ };
12
+ export type StoreRegistry = {
13
+ get<T extends object>(model: Model<T>): StoreEntry<T>;
14
+ context?: Record<string, unknown>;
15
+ queryDefaults?: RegistryDefaults['query'];
16
+ queryBinding: QueryBindingRegistry;
17
+ };
18
+ export declare function useStoreRegistry(): StoreRegistry;
19
+ export declare function MuchaProvider({ children, defaultOptions, context }: MuchaProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ export declare function createProxy<T extends object>(initialValue: T): T;
2
+ export declare function snapshot<T extends object>(state: T): T;
3
+ export declare function subscribe<T extends object>(state: T, listener: () => void): () => void;
@@ -0,0 +1,120 @@
1
+ declare const RESOURCE_BRAND: unique symbol;
2
+ type AsyncResult<T> = T | Promise<T>;
3
+ type ResourceKind = 'single' | 'infinite';
4
+ type ResourceDataLike = Record<string, unknown>;
5
+ type ResourceResultShape<TState extends ResourceDataLike, TData = TState extends {
6
+ data: infer T;
7
+ } ? T : never> = TState | ({
8
+ data: TData;
9
+ } & Partial<Omit<TState, 'data'>>) | undefined;
10
+ export type PlaceholderData<TData, TArg = void> = TData | ((arg: TArg, previousData: TData) => TData);
11
+ export declare function keepPreviousData<TData, TArg = void>(_: TArg, previousData: TData): TData;
12
+ export type QueryDefaultOptions = {
13
+ staleTime?: number;
14
+ cacheTime?: number;
15
+ gcTime?: number;
16
+ placeholderData?: PlaceholderData<unknown, unknown>;
17
+ };
18
+ export type QueryQueryOptions<TData, TArg> = QueryDefaultOptions & {
19
+ placeholderData?: PlaceholderData<TData, TArg>;
20
+ force?: boolean;
21
+ };
22
+ type ResourceQueryOptions<TData, TArg> = QueryQueryOptions<TData, TArg>;
23
+ export type ResourceContext<TState> = {
24
+ state: Readonly<TState>;
25
+ };
26
+ export type ResourceBaseState<TData> = {
27
+ data: TData;
28
+ isLoading: boolean;
29
+ isFetching: boolean;
30
+ isSuccess: boolean;
31
+ isError: boolean;
32
+ error: string | null;
33
+ };
34
+ export type ResourceSingleState<TData> = ResourceBaseState<TData>;
35
+ export type ResourceInfiniteState<TData> = ResourceBaseState<TData> & {
36
+ cursor: string | null;
37
+ hasMore: boolean;
38
+ };
39
+ export type ResourceResult<TData> = ResourceResultShape<ResourceBaseState<TData>, TData>;
40
+ export type Query<TData, TArg = void> = SingleResourceDescriptor<TData, TArg>;
41
+ export declare namespace Query {
42
+ type Single<TData, TArg = void> = Query<TData, TArg>;
43
+ type Infinite<TData, TArg = void> = InfiniteResourceDescriptor<TData, TArg>;
44
+ }
45
+ export type QueryInfinite<TData, TArg = void> = InfiniteResourceDescriptor<TData, TArg>;
46
+ type SingleResourceLoadResult<TData> = TData | ResourceResult<TData>;
47
+ type InfiniteResourceLoadResult<TData> = ResourceInfiniteState<TData> | ({
48
+ data: TData;
49
+ } & Partial<Omit<ResourceInfiniteState<TData>, 'data'>>);
50
+ type BaseResourceDescriptor<TState extends ResourceDataLike, TArg, TResult> = {
51
+ [RESOURCE_BRAND]: true;
52
+ kind: ResourceKind;
53
+ initialState: TState;
54
+ options: Omit<ResourceQueryOptions<TState extends ResourceBaseState<infer TData> ? TData : never, unknown>, 'force'>;
55
+ queryFn: (arg: TArg, context: ResourceContext<TState>) => AsyncResult<TResult>;
56
+ };
57
+ type SingleResourceDescriptor<TData, TArg = void> = BaseResourceDescriptor<ResourceSingleState<TData>, TArg, SingleResourceLoadResult<TData>> & ResourceSingleState<TData> & {
58
+ kind: 'single';
59
+ };
60
+ type InfiniteResourceDescriptor<TData, TArg = void> = BaseResourceDescriptor<ResourceInfiniteState<TData>, TArg, InfiniteResourceLoadResult<TData>> & ResourceInfiniteState<TData> & {
61
+ kind: 'infinite';
62
+ };
63
+ export type AnyResourceDescriptor = SingleResourceDescriptor<unknown, unknown> | InfiniteResourceDescriptor<unknown, unknown>;
64
+ export type ResourceDescriptorMap = Map<string, AnyResourceDescriptor>;
65
+ interface ResourceSingleQueryController<TData, TArg> {
66
+ query(arg: TArg, options?: ResourceQueryOptions<TData, TArg>): Promise<unknown>;
67
+ query(options?: ResourceQueryOptions<TData, TArg>): Promise<unknown>;
68
+ refetch(): Promise<unknown>;
69
+ set(next: unknown): unknown;
70
+ }
71
+ interface ResourceInfiniteQueryController<TData, TArg> extends ResourceSingleQueryController<TData, TArg> {
72
+ nextFetch(arg: TArg, options?: ResourceQueryOptions<TData, TArg>): Promise<unknown>;
73
+ nextFetch(options?: ResourceQueryOptions<TData, TArg>): Promise<unknown>;
74
+ previousFetch(arg: TArg, options?: ResourceQueryOptions<TData, TArg>): Promise<unknown>;
75
+ previousFetch(options?: ResourceQueryOptions<TData, TArg>): Promise<unknown>;
76
+ }
77
+ export type BoundSingleResourceState<TData, TArg = unknown> = ResourceSingleState<TData> & ResourceSingleQueryController<TData, TArg>;
78
+ export type BoundInfiniteResourceState<TData, TArg = unknown> = ResourceInfiniteState<TData> & ResourceInfiniteQueryController<TData, TArg>;
79
+ export type BoundResourceState<T> = T extends InfiniteResourceDescriptor<infer TData, infer TArg> ? BoundInfiniteResourceState<TData, TArg> : T extends SingleResourceDescriptor<infer TData, infer TArg> ? BoundSingleResourceState<TData, TArg> : T extends ResourceInfiniteState<infer TData> ? BoundInfiniteResourceState<TData, unknown> : T extends ResourceSingleState<infer TData> ? BoundSingleResourceState<TData, unknown> : T extends (infer U)[] ? BoundResourceState<U>[] : T extends object ? {
80
+ [K in keyof T]: BoundResourceState<T[K]>;
81
+ } : T;
82
+ type SingleResourceBuilderOptions<TData, TArg = void> = {
83
+ initialData: TData;
84
+ queryFn: (arg: TArg, context: ResourceContext<ResourceSingleState<TData>>) => AsyncResult<SingleResourceLoadResult<TData>>;
85
+ } & Omit<ResourceQueryOptions<TData, TArg>, 'force'>;
86
+ type InfiniteResourceBuilderOptions<TData, TArg = void> = {
87
+ initialData: TData;
88
+ queryFn: (arg: TArg, context: ResourceContext<ResourceInfiniteState<TData>>) => AsyncResult<InfiniteResourceLoadResult<TData>>;
89
+ } & Omit<ResourceQueryOptions<TData, TArg>, 'force'>;
90
+ type ResourceFactory = {
91
+ <TData, TArg = void>(opts: SingleResourceBuilderOptions<TData, TArg>): SingleResourceDescriptor<TData, TArg>;
92
+ infinite: <TData, TArg = void>(opts: InfiniteResourceBuilderOptions<TData, TArg>) => InfiniteResourceDescriptor<TData, TArg>;
93
+ };
94
+ type QueryCacheKey = string;
95
+ type QueryCacheEntry = {
96
+ key: QueryCacheKey;
97
+ arg: unknown;
98
+ hasQueried: boolean;
99
+ lastFetchedAt: number;
100
+ lastResult?: unknown;
101
+ cursorHistory: Array<string | null>;
102
+ gcTime?: number;
103
+ state: ResourceDataLike;
104
+ };
105
+ export type QueryBindingRegistry = {
106
+ boundResourceValue: WeakMap<object, Record<string, unknown>>;
107
+ boundPathProxy: WeakMap<object, Map<string, object>>;
108
+ boundResourceRuntime: WeakMap<object, ResourceRuntimeState>;
109
+ };
110
+ export declare function createQueryBindingRegistry(): QueryBindingRegistry;
111
+ type ResourceRuntimeState = {
112
+ path: string;
113
+ lastArg?: unknown;
114
+ activeKey?: QueryCacheKey;
115
+ cacheEntries: Map<QueryCacheKey, QueryCacheEntry>;
116
+ };
117
+ export declare const query: ResourceFactory;
118
+ export declare function isResourceDescriptor(value: unknown): value is AnyResourceDescriptor;
119
+ export declare function bindResourceState<T extends object>(modelState: T, resourceDescriptors: ResourceDescriptorMap, defaults?: QueryDefaultOptions, registry?: QueryBindingRegistry): T;
120
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function silent(fn: () => void): void;
2
+ export declare function isSilent(): boolean;
@@ -0,0 +1,3 @@
1
+ export { model, action, useAction, useModel, create, silent, MuchaProvider, keepPreviousData, query, } from './core';
2
+ export type { Query, QueryDefaultOptions, QueryQueryOptions, PlaceholderData } from './core';
3
+ export * from './interceptors';
@@ -0,0 +1,8 @@
1
+ import { AnyFunction } from './utils';
2
+ type AuthorizedOptions = {
3
+ when: () => boolean | Promise<boolean>;
4
+ onDeny: () => void | Promise<void>;
5
+ };
6
+ export declare function onAuthorized<T extends AnyFunction>(options: AuthorizedOptions): (next: T) => T;
7
+ export declare function Authorized(options: AuthorizedOptions): MethodDecorator;
8
+ export {};
@@ -0,0 +1,4 @@
1
+ import { DebounceOptions } from '../utils';
2
+ import { AnyFunction, Interceptor } from './utils';
3
+ export declare function debounce<T extends AnyFunction>(waitMs: number, options?: DebounceOptions): Interceptor;
4
+ export declare function Debounce(waitMs: number, options?: DebounceOptions): MethodDecorator;
@@ -0,0 +1,3 @@
1
+ import { AnyFunction } from './utils';
2
+ export declare function onError<T extends AnyFunction>(handler: (error: unknown) => void): (next: T) => T;
3
+ export declare function OnError(handler: (error: unknown) => any): MethodDecorator;
@@ -0,0 +1,8 @@
1
+ export { type AnyFunction, type Interceptor, isThenable, composeInterceptors, createDecorator, createInterceptor, } from './utils';
2
+ export { pipe } from '../utils';
3
+ export { onError, OnError } from './error';
4
+ export { onSuccess, OnSuccess } from './success';
5
+ export { debounce, Debounce } from './debounce';
6
+ export { throttle, Throttle } from './throttle';
7
+ export { transaction, Transaction } from './transaction';
8
+ export { onAuthorized, Authorized } from './authorized';
@@ -0,0 +1,3 @@
1
+ import { AnyFunction } from './utils';
2
+ export declare function onSuccess<T extends AnyFunction>(handler: (result: Awaited<ReturnType<T>>) => void): (next: T) => T;
3
+ export declare function OnSuccess<R>(handler: (result: R) => void): MethodDecorator;
@@ -0,0 +1,4 @@
1
+ import { ThrottleOptions } from '../utils';
2
+ import { AnyFunction, Interceptor } from './utils';
3
+ export declare function throttle<T extends AnyFunction>(waitMs: number, options?: ThrottleOptions): Interceptor;
4
+ export declare function Throttle(waitMs: number, options?: ThrottleOptions): MethodDecorator;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Experimental placeholder.
3
+ *
4
+ * Current implementation does not provide write-safe rollback. It keeps the
5
+ * public API (`@Transaction`, `transaction`) in place for planning, but the
6
+ * behavior is intentionally not enabled until a scoped proxy snapshot strategy
7
+ * is implemented.
8
+ */
9
+ export declare function transaction(): <T extends (...args: any[]) => any>(next: T) => T;
10
+ export declare function Transaction(): MethodDecorator;
@@ -0,0 +1,16 @@
1
+ import { BoundResourceState } from '../core/query';
2
+ import { Model } from '../core/model';
3
+ export type AnyFunction = (...args: any[]) => any;
4
+ export type Interceptor<T extends AnyFunction = AnyFunction> = (next: T) => T;
5
+ type ActionState = <T extends object>(model: Model<T>) => BoundResourceState<T>;
6
+ export type ActionContext<TContext extends object = Record<string, never>> = {
7
+ state: ActionState;
8
+ context: TContext;
9
+ };
10
+ export type LazyInterceptorFactory<TContext extends object = Record<string, never>> = (ctx: ActionContext<TContext>) => MethodDecorator;
11
+ export declare function isThenable<T>(value: unknown): value is PromiseLike<T>;
12
+ export declare function composeInterceptors<T extends AnyFunction>(interceptors: Interceptor<T>[]): Interceptor<T>;
13
+ export declare function createInterceptor<TContext extends object = Record<string, never>>(factory: LazyInterceptorFactory<TContext>): MethodDecorator;
14
+ export declare function getLazyInterceptorFactories(target: unknown): LazyInterceptorFactory[];
15
+ export declare function createDecorator<T extends AnyFunction>(interceptor: Interceptor<T>): MethodDecorator;
16
+ export {};
@@ -0,0 +1,9 @@
1
+ export { isEqual } from 'es-toolkit';
2
+ export { debounce, type DebounceOptions, type DebouncedFunction } from 'es-toolkit';
3
+ export { throttle, type ThrottleOptions, type ThrottledFunction } from 'es-toolkit';
4
+ export { flow as pipe, flowRight as compose } from 'es-toolkit';
5
+ export type ArrayElement<T extends readonly unknown[]> = T[number];
6
+ export type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
7
+ export type Prettify<T> = {
8
+ [K in keyof T]: T[K];
9
+ } & {};
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "comwit",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "homepage": "https://comwit.io",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/meursyphus/comwit.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/meursyphus/comwit/issues"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "type": "module",
17
+ "description": "LLM-friendly React state helper library.",
18
+ "main": "dist/comwit.cjs",
19
+ "module": "dist/comwit.js",
20
+ "types": "dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/comwit.js",
25
+ "require": "./dist/comwit.cjs"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "scripts": {
33
+ "dev": "vite build --watch",
34
+ "build": "vite build",
35
+ "typecheck": "tsc -p tsconfig.json"
36
+ },
37
+ "peerDependencies": {
38
+ "react": "^18.0.0 || ^19.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/react": "^19.2.7",
42
+ "@types/react-dom": "^19.2.3",
43
+ "@vitejs/plugin-react": "^5.1.1",
44
+ "typescript": "^5.9.3",
45
+ "vite": "^7.3.1",
46
+ "vite-plugin-dts": "^4.5.4"
47
+ },
48
+ "dependencies": {
49
+ "es-toolkit": "^1.44.0",
50
+ "immer": "^11.1.4",
51
+ "overlay-kit": "^1.8.6",
52
+ "sonner": "^2.0.7",
53
+ "valtio": "^2.3.0"
54
+ }
55
+ }