@doeixd/machine 0.0.19 → 0.0.20

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.
@@ -1,4 +1,4 @@
1
- function D(e,n){let t=e(n),r=n;for(;;){let{value:a,done:o}=t.next(r);if(o)return a;r=a}}function ie(e){return function*(){return yield e}()}function se(e){return e}function ce(e,n){return n.reduce((t,r)=>D(r,t),e)}function de(e){return e}function ye(e,n,t=(r,a)=>{console.log(`Step ${r}:`,a.context)}){let r=e(n),a=n,o=0;for(t(o,a);;){let{value:i,done:s}=r.next(a);if(s)return console.log("Final:",i),i;a=i,o++,t(o,a)}}async function le(e,n){let t=e(n),r=n;for(;;){let{value:a,done:o}=await t.next(r);if(o)return a;r=a}}async function*ue(e){return yield e}var Me=Symbol("MachineMeta"),I=Symbol("__machine_runtime_meta__");function b(e,n){let t=e[I]||{},r={...t,...n};n.guards&&t.guards?r.guards=[...n.guards,...t.guards]:n.guards&&(r.guards=[...n.guards]),n.actions&&t.actions?r.actions=[...n.actions,...t.actions]:n.actions&&(r.actions=[...n.actions]),Object.defineProperty(e,I,{value:r,enumerable:!1,writable:!1,configurable:!0})}function xe(e,n){return b(n,{target:e.name||e.toString()}),n}function he(e,n){return b(n,{description:e}),n}function fe(e,n){return b(n,{guards:[e]}),n}function pe(e,n){return b(n,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),n}function Ce(e,n){return b(n,{actions:[e]}),n}function A(e,n,t={}){let{onFail:r="throw",errorMessage:a,description:o}=t,i={...t,onFail:r,errorMessage:a,description:o},s=function(...d){let c=typeof this=="object"&&"context"in this,y=c?this.context:this;if(e(y,...d)){let M=c?this.context:this;return n.apply(M,d)}else if(r==="throw"){let M=a||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:n,enumerable:!1}),Object.defineProperty(s,"options",{value:i,enumerable:!1}),b(s,{description:o||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:o||"Synchronous condition check"}]}),s}function R(e,n,t={}){let{onFail:r="throw",errorMessage:a,description:o}=t,i={...t,onFail:r,errorMessage:a,description:o},s=async function(...d){let c=typeof this=="object"&&"context"in this,y=c?this.context:this;if(await Promise.resolve(e(y,...d))){let M=c?this.context:this;return n.apply(M,d)}else if(r==="throw"){let M=a||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:n,enumerable:!1}),Object.defineProperty(s,"options",{value:i,enumerable:!1}),b(s,{description:o||"Runtime guarded transition",guards:[{name:"runtime_guard",description:o||"Runtime condition check"}]}),s}function ge(e){return{do(n){let t=A(e,n);return t.else=function(r){return A(e,n,{onFail:r})},t}}}function me(e){return{do(n){let t=R(e,n);return t.else=function(r){return R(e,n,{onFail:r})},t}}}function Te(e,n){return n}function be(e,n){let t=e,r=s=>{t=s,n==null||n(s)},{context:a,...o}=e,i=new Proxy({},{get(s,d){let c=t[d];if(typeof c=="function")return(...y)=>{let l=c.apply(t.context,y),M=Object.assign({context:l.context},o);return r(M),M}}});return{get state(){return t},get context(){return t.context},actions:i,setState:r}}function we(e,n,t){let r=()=>{let o=e.getContext(),i=t(o),s=n[i];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(i)}".`);return s(o)},a=new Proxy({},{get(o,i){let s=r(),d=s[i];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${i}" is not valid in the current state.`);return(...c)=>d.apply(s.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:a}}function De(e,n){return function(r){return we(e,r,n)}}function Ie(e,n){let t=be(n),r=e(t),a=r.next();for(;!a.done;)a=r.next();return a.value}function Ve(e,n){let t=e(n),r=t.next();for(;!r.done;)r=t.next();return r.value}var V=class{constructor(n){this.store=n}get context(){return this.store.getContext()}setContext(n){this.store.setContext(n)}};function Ue(e,n){let t=new e(n);return new Proxy({},{get(r,a){let o=n.getContext();if(a in o)return o[a];let i=t[a];if(typeof i=="function")return(...s)=>i.apply(t,s)},set(r,a,o){let i=n.getContext();if(a in i){let s={...i,[a]:o};return n.setContext(s),!0}return!1},has(r,a){let o=n.getContext();return a in o||typeof t[a]=="function"},ownKeys(r){let a=n.getContext(),o=Object.keys(a),i=Object.getOwnPropertyNames(Object.getPrototypeOf(t)).filter(s=>s!=="constructor"&&typeof t[s]=="function");return Array.from(new Set([...o,...i]))},getOwnPropertyDescriptor(r,a){let o=n.getContext();if(a in o||typeof t[a]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function Le(e,n,t){let r=()=>{let a=t(e),o=n[a];if(!o)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(a)}".`);return o(e)};return new Proxy(e,{get(a,o,i){if(o in a)return a[o];let s=r(),d=s[o];if(typeof d=="function")return(...c)=>{let y=d.apply(s.context,c);if(typeof y!="object"||y===null){console.warn(`[MutableMachine] Transition "${String(o)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(a).forEach(l=>delete a[l]),Object.assign(a,y)}},set(a,o,i,s){return a[o]=i,!0},has(a,o){let i=r();return o in a||typeof i[o]=="function"}})}function Ze(e){return function(...n){let t=this.context.child;if(typeof t[e]=="function"){let r=t[e](...n);return E(this,{...this.context,child:r})}return this}}function en(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),E(this,{...this.context,[e]:!this.context[e]})}}var S=class extends m{constructor(t){super({status:"idle"});this.config=t;this.fetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},w=class extends m{constructor(t,r,a){super({status:"loading",abortController:new AbortController,attempts:a});this.config=t;this.params=r;this.succeed=t=>{var r,a;return(a=(r=this.config).onSuccess)==null||a.call(r,t),new v(this.config,{status:"success",data:t})};this.fail=t=>{var a,o,i;let r=(a=this.config.maxRetries)!=null?a:3;return this.context.attempts<r?new j(this.config,this.params,t,this.context.attempts):((i=(o=this.config).onError)==null||i.call(o,t),new P(this.config,{status:"error",error:t}))};this.cancel=()=>(this.context.abortController.abort(),new O(this.config));this.execute()}async execute(){}},j=class extends m{constructor(t,r,a,o){super({status:"retrying",error:a,attempts:o});this.config=t;this.params=r;this.retry=t=>new w(this.config,t!=null?t:this.params,this.context.attempts+1)}},v=class extends m{constructor(t,r){super(r);this.config=t;this.refetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},P=class extends m{constructor(t,r){super(r);this.config=t;this.retry=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},O=class extends m{constructor(t){super({status:"canceled"});this.config=t;this.refetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}};function nn(e){return new S(e)}function U(e,n){let t={...e.context,...n.context},r={...e},a={...n};delete r.context,delete a.context;let o={};for(let i in r){let s=r[i];o[i]=(...d)=>{let c=s.apply(e.context,d);return U(c,n)}}for(let i in a){let s=a[i];o[i]=(...d)=>{let c=s.apply(n.context,d);return U(e,c)}}return{context:t,...o}}var L=Symbol("CANCEL");function g(e,n,t={}){let{continueOnError:r=!1,logErrors:a=!0,onError:o}=t,i={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(i[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let d=e[s];typeof d=="function"&&s!=="context"&&(i[s]=function(...c){let y=s,l=i.context,M=()=>{let u;try{u=d.apply(this,c)}catch(h){if(n.error)try{n.error({transitionName:y,context:l,args:[...c],error:h})}catch(f){if(!r)throw f;a&&console.error(`Middleware error hook error for ${y}:`,f),o==null||o(f,"error",{transitionName:y,context:l,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in i)Object.prototype.hasOwnProperty.call(i,f)&&f!=="context"&&!(f in h)&&(h[f]=i[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&i[f]&&(h[f]=i[f])}}return h};if(u&&typeof u.then=="function")return u.then(f=>{if(x(f),n.after)try{let C=n.after({transitionName:y,prevContext:l,nextContext:f.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>f)}catch(C){if(!r)throw C;a&&console.error(`Middleware after hook error for ${y}:`,C),o==null||o(C,"after",{transitionName:y,prevContext:l,nextContext:f.context,args:c})}return f});if(x(u),n.after)try{let h=n.after({transitionName:y,prevContext:l,nextContext:u.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>u).catch(f=>{if(!r)throw f;return a&&console.error(`Middleware after hook error for ${y}:`,f),o==null||o(f,"after",{transitionName:y,prevContext:l,nextContext:u.context,args:c}),u})}catch(h){if(!r)throw h;a&&console.error(`Middleware after hook error for ${y}:`,h),o==null||o(h,"after",{transitionName:y,prevContext:l,nextContext:u.context,args:c})}return u};if(n.before)try{let u=n.before({transitionName:y,context:l,args:[...c]});if(u&&typeof u=="object"&&u&&"then"in u)return u.then(x=>x===L?i:M()).catch(x=>{if(!r)throw x;return a&&console.error(`Middleware before hook error for ${y}:`,x),o==null||o(x,"before",{transitionName:y,context:l,args:c}),M()});if(u===L)return i}catch(u){if(!r)throw u;a&&console.error(`Middleware before hook error for ${y}:`,u),o==null||o(u,"before",{transitionName:y,context:l,args:c})}return M()})}return i}function q(e,n={}){let{logger:t=console.log,includeArgs:r=!1,includeContext:a=!0}=n;return g(e,{before:({transitionName:o,args:i})=>{let s=r?`→ ${o} [${i.join(", ")}]`:`→ ${o}`;t(s)},after:({transitionName:o,nextContext:i})=>{let s=a?` ${JSON.stringify(i)}`:"";t(`✓ ${o}${s}`)},error:({transitionName:o,error:i})=>{console.error(`[Machine] ${o} failed:`,i)}})}function J(e,n,t={}){let{eventPrefix:r="state_transition",includePrevContext:a=!1,includeArgs:o=!1}=t;return g(e,{after:({transitionName:i,prevContext:s,nextContext:d,args:c})=>{let y=`${r}.${i}`,l={transition:i};a&&(l.from=s),l.to=d,o&&(l.args=c),n(y,l)}})}function Y(e,n){return g(e,{before:t=>{if(n(t)===!1)throw new Error(`Validation failed for transition: ${t.transitionName}`)}})}function Q(e,n){return g(e,{before:t=>{if(!n(t))throw new Error(`Unauthorized transition: ${t.transitionName}`)}})}function X(e,n,t={}){let{includeArgs:r=!1}=t;return g(e,{error:a=>{let o={transition:a.transitionName,context:a.context,...r&&{args:a.args}};n(a.error,o)}})}function Z(e,n){let t=new Map;return g(e,{before:r=>{t.set(r.transitionName,Date.now())},after:r=>{let a=t.get(r.transitionName);if(a){let o=Date.now()-a;t.delete(r.transitionName);let i={transitionName:r.transitionName,duration:o,context:r.nextContext||r.prevContext};n(i)}}})}function ee(e,n={}){var d,c;let{maxAttempts:t=(d=n.maxRetries)!=null?d:3,shouldRetry:r=()=>!0,backoffMs:a=(c=n.delay)!=null?c:100,backoffMultiplier:o=2,onRetry:i}=n,s={...e};for(let y in e){if(!Object.prototype.hasOwnProperty.call(e,y))continue;let l=e[y];typeof l=="function"&&y!=="context"&&(s[y]=async function(...M){let u,x=0;for(;x<t;)try{return await l.apply(this,M)}catch(h){if(u=h,x++,x<t&&r(u,x)){i==null||i(u,x);let C=(typeof a=="function"?a(x):a)*Math.pow(o,x-1);await new Promise(T=>setTimeout(T,C))}else throw u}throw u})}return s}function rn(e,n){return t=>g(t,e,n)}function k(e,n={}){let{maxSize:t,serializer:r,onEntry:a}=n,o=[],i=0,s=g(e,{before:({transitionName:d,args:c})=>{let y={id:`entry-${i++}`,transitionName:d,args:[...c],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(c)}catch(l){console.error("Failed to serialize history args:",l)}o.push(y),t&&o.length>t&&o.shift(),a==null||a(y)}});return Object.assign(s,{history:o,clearHistory:()=>{o.length=0,i=0}})}function B(e,n={}){let{maxSize:t,serializer:r,captureSnapshot:a,onlyOnChange:o=!1}=n,i=[],s=0,d=g(e,{after:({transitionName:y,prevContext:l,nextContext:M})=>{if(o&&JSON.stringify(l)===JSON.stringify(M))return;let u={id:`snapshot-${s++}`,transitionName:y,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{u.serializedBefore=r.serialize(l),u.serializedAfter=r.serialize(M)}catch(x){console.error("Failed to serialize snapshot:",x)}if(a)try{u.diff=a(l,M)}catch(x){console.error("Failed to capture snapshot:",x)}i.push(u),t&&i.length>t&&i.shift()}});return Object.assign(d,{snapshots:i,clearSnapshots:()=>{i.length=0,s=0},restoreSnapshot:y=>{let l=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="snapshots"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&typeof e[M]=="function"));return Object.assign({context:y},l)}})}function N(e,n={}){let{maxSize:t,serializer:r,onRecord:a}=n,o=[],i=[],s=0,d=0,c=g(e,{before:({transitionName:M,args:u})=>{let x={id:`entry-${s++}`,transitionName:M,args:[...u],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(u)}catch(h){console.error("Failed to serialize history args:",h)}o.push(x),t&&o.length>t&&o.shift(),a==null||a("history",x)},after:({transitionName:M,prevContext:u,nextContext:x})=>{let h={id:`snapshot-${d++}`,transitionName:M,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(u),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}i.push(h),t&&i.length>t&&i.shift(),a==null||a("snapshot",h)}});return Object.assign(c,{history:o,snapshots:i,clearHistory:()=>{o.length=0,s=0},clearSnapshots:()=>{i.length=0,d=0},clearTimeTravel:()=>{o.length=0,i.length=0,s=0,d=0},restoreSnapshot:M=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:M},u)},replayFrom:M=>{var C;if(M<0||M>=o.length)throw new Error(`Invalid replay start index: ${M}`);let u=(C=i[M])==null?void 0:C.before;if(!u)throw new Error(`No snapshot available for index ${M}`);let x=o.slice(M),f=Object.assign({context:u},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let G=f[T.transitionName];G&&(f=G.apply(f.context,T.args))}return f}})}function fn(e,...n){return n.reduce((t,r)=>r(t),e)}function K(e,...n){return n.reduce((t,r)=>r(t),e)}var _=class e{constructor(n){this.machine=n}with(n){let t=n(this.machine);return new e(t)}build(){return this.machine}};function pn(e){return new _(e)}function z(e,n){let t=function(r){return n(r)?e(r):r};return t.middleware=e,t.when=n,t}function Cn(e){return z(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function gn(e,n,t){return z(t,r=>r.context[e]===n)}function mn(){let e=new Map;return{register(n,t,r,a){if(e.has(n))throw new Error(`Middleware '${n}' is already registered`);return e.set(n,{name:n,middleware:t,description:r,priority:a}),this},unregister(n){return e.delete(n)},has(n){return e.has(n)},get(n){return e.get(n)},list(){return Array.from(e.values()).sort((n,t)=>{var r,a;return((r=n.priority)!=null?r:0)-((a=t.priority)!=null?a:0)})},apply(n,t){let r=t.map(a=>{let o=e.get(a);if(!o)throw new Error(`Middleware '${a}' is not registered`);return o}).sort((a,o)=>{var i,s;return((i=a.priority)!=null?i:0)-((s=o.priority)!=null?s:0)});return K(n,...r.map(a=>a.middleware))},applyAll(n){let t=this.list();return K(n,...t.map(r=>r.middleware))}}}function Tn(e={}){let{continueOnError:n=!1,logErrors:t=!0,onError:r}=e;return(a,...o)=>{let i=a,s=[],d=!0;for(let c=0;c<o.length;c++){let y=o[c];try{if("middleware"in y&&"when"in y){if(!y.when(i))continue;i=y.middleware(i)}else i=y(i)}catch(l){if(d=!1,!n)throw l;s.push({error:l,middlewareIndex:c,middlewareName:y.name}),t&&console.error(`Pipeline middleware error at index ${c}:`,l),r==null||r(l,c,y.name)}}return{machine:i,errors:s,success:d}}}function bn(...e){return n=>K(n,...e)}function wn(e,n){return t=>{for(let[r,a]of e)if(r(t))return a(t);return n?n(t):t}}function ne(e){return typeof e=="function"&&e.length===1}function En(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ne(e.middleware)&&typeof e.when=="function"}function Fn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||F(e.prevContext,n)&&F(e.nextContext,n))}function An(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||F(e.context,n))}function Rn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!n||F(e.context,n))}function Sn(e,n){if(e===null||typeof e!="object")return!1;let t=e;return!("before"in t&&t.before!==void 0&&typeof t.before!="function"||"after"in t&&t.after!==void 0&&typeof t.after!="function"||"error"in t&&t.error!==void 0&&typeof t.error!="function")}function jn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function F(e,n){return e!==null&&typeof e=="object"}function vn(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ne(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Pn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var H=class{constructor(n){this.machine=n;this.middlewares=[]}withLogging(n){return this.middlewares.push(t=>q(t,n)),this}withAnalytics(n,t){return this.middlewares.push(r=>J(r,n,t)),this}withValidation(n,t){return this.middlewares.push(r=>Y(r,n)),this}withPermissions(n){return this.middlewares.push(t=>Q(t,n)),this}withErrorReporting(n,t){return this.middlewares.push(r=>X(r,n,t)),this}withPerformanceMonitoring(n,t){return this.middlewares.push(r=>Z(r,n)),this}withRetry(n){return this.middlewares.push(t=>ee(t,n)),this}withHistory(n){return this.middlewares.push(t=>k(t,n)),this}withSnapshot(n){return this.middlewares.push(t=>B(t,n)),this}withTimeTravel(n){return this.middlewares.push(t=>N(t,n)),this}withDebugging(){return this.middlewares.push(n=>Fe(n)),this}withCustom(n){return this.middlewares.push(n),this}withConditional(n,t){return this.middlewares.push(z(n,t)),this}build(){let n=this.machine;for(let t of this.middlewares)n=t(n);return n}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Ee(e){return new H(e)}function On(e={}){return{create:n=>{let t=Ee(n);return e.logging&&t.withLogging(e.logging),e.analytics&&t.withAnalytics(e.analytics.track,e.analytics.options),e.history&&t.withHistory(e.history),e.snapshot&&t.withSnapshot(e.snapshot),e.timeTravel&&t.withTimeTravel(e.timeTravel),e.retry&&t.withRetry(e.retry),t}}}function Fe(e){return N(B(k(e)))}function Ae(e,n){return e instanceof n}function Re(e,...n){return{type:e,args:n}}function Se(e,n){return E(e,t=>({...t,...n}))}async function je(e,...n){let t=e;for(let r of n)t=await r(t);return t}function ve(e,n){return n?console.log(n,e.context):console.log(e.context),e}function Pe(e,n){return function(...t){let r=n(this.context,...t);return p(r,e())}}function Oe(e,n,...t){return e.apply(n,t)}function te(e){return new Proxy(e,{get(n,t){let r=n[t];return typeof r=="function"?function(...a){let o=r.apply(n.context,a);return o&&typeof o=="object"&&"context"in o?te(o):o}:r}})}var W=class e{constructor(n){return this.wrappedMachine=n,new Proxy(this,{get:(t,r)=>{if(r==="wrappedMachine")return Reflect.get(t,r);if(r==="context")return this.wrappedMachine.context;let a=this.wrappedMachine[r];return typeof a=="function"?(...o)=>{let i=a.apply(this.wrappedMachine.context,o);return i&&typeof i=="object"&&"context"in i?new e(i):i}:a}})}};function ke(){return function(n){return function(...t){let r=n(this.context,...t);return p(r,this)}}}function re(e){return{machine:e,addTransition:function(n,t){let r=function(...o){let i=t(this.context,...o);return p(i,this)},a=oe(e,{[n]:r});return re(a)}}}function ae(e){return function(t){let r={},a=Object.fromEntries(Object.entries(t).map(([o,i])=>[o,function(...s){let d=i(this.context,...s);return p(d,r)}]));return Object.assign(r,a),p(e,r)}}function Be(e,n){return n!==void 0?p(e,n):ae(e)}function Ne(...e){let n=new Map;for(let[s,d,c]of e){if(n.has(s))throw new Error(`Duplicate matcher case name: "${s}"`);n.set(s,{predicate:c})}let t=new Proxy({},{get(s,d){return function(y){let l=n.get(d);if(!l){let M=Array.from(n.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${M}`)}return l.predicate(y)}}}),r=new Proxy({},{get(s,d){return function(y){if(!n.has(d)){let l=Array.from(n.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${l}`)}return{__brand:"CaseHandler",__name:d,__machine:void 0,__return:void 0,handler:y}}}}),a={__exhaustive:!0};function o(s){return{is(...d){if(d.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let c=d[d.length-1];if(!c||typeof c!="object"||!("__exhaustive"in c))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let y=d.slice(0,-1);for(let u of y){let x=u.__name,h=n.get(x);if(!h)throw new Error(`Internal error: Unknown matcher case in handler: ${x}`);if(h.predicate(s))return u.handler(s)}let l=y.map(u=>u.__name).join(", "),M=Array.from(n.keys()).join(", ");throw new Error(`Non-exhaustive pattern match at runtime: no handler matched the machine.
1
+ function D(e,n){let t=e(n),r=n;for(;;){let{value:a,done:o}=t.next(r);if(o)return a;r=a}}function ie(e){return function*(){return yield e}()}function se(e){return e}function ce(e,n){return n.reduce((t,r)=>D(r,t),e)}function de(e){return e}function ye(e,n,t=(r,a)=>{console.log(`Step ${r}:`,a.context)}){let r=e(n),a=n,o=0;for(t(o,a);;){let{value:i,done:s}=r.next(a);if(s)return console.log("Final:",i),i;a=i,o++,t(o,a)}}async function le(e,n){let t=e(n),r=n;for(;;){let{value:a,done:o}=await t.next(r);if(o)return a;r=a}}async function*ue(e){return yield e}var Me=Symbol("MachineMeta"),I=Symbol("__machine_runtime_meta__");function b(e,n){let t=e[I]||{},r={...t,...n};n.guards&&t.guards?r.guards=[...n.guards,...t.guards]:n.guards&&(r.guards=[...n.guards]),n.actions&&t.actions?r.actions=[...n.actions,...t.actions]:n.actions&&(r.actions=[...n.actions]),Object.defineProperty(e,I,{value:r,enumerable:!1,writable:!1,configurable:!0})}function xe(e,n){return b(n,{target:e.name||e.toString()}),n}function he(e,n){return b(n,{description:e}),n}function fe(e,n){return b(n,{guards:[e]}),n}function pe(e,n){return b(n,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),n}function Ce(e,n){return b(n,{actions:[e]}),n}function A(e,n,t={}){let{onFail:r="throw",errorMessage:a,description:o}=t,i={...t,onFail:r,errorMessage:a,description:o},s=function(...d){let c=typeof this=="object"&&"context"in this,y=c?this.context:this;if(e(y,...d)){let M=c?this.context:this;return n.apply(M,d)}else if(r==="throw"){let M=a||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:n,enumerable:!1}),Object.defineProperty(s,"options",{value:i,enumerable:!1}),b(s,{description:o||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:o||"Synchronous condition check"}]}),s}function R(e,n,t={}){let{onFail:r="throw",errorMessage:a,description:o}=t,i={...t,onFail:r,errorMessage:a,description:o},s=async function(...d){let c=typeof this=="object"&&"context"in this,y=c?this.context:this;if(await Promise.resolve(e(y,...d))){let M=c?this.context:this;return n.apply(M,d)}else if(r==="throw"){let M=a||"Guard condition failed";throw new Error(M)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:n,enumerable:!1}),Object.defineProperty(s,"options",{value:i,enumerable:!1}),b(s,{description:o||"Runtime guarded transition",guards:[{name:"runtime_guard",description:o||"Runtime condition check"}]}),s}function ge(e){return{do(n){let t=A(e,n);return t.else=function(r){return A(e,n,{onFail:r})},t}}}function me(e){return{do(n){let t=R(e,n);return t.else=function(r){return R(e,n,{onFail:r})},t}}}function Te(e,n){return n}function be(e,n){let t=e,r=s=>{t=s,n==null||n(s)},{context:a,...o}=e,i=new Proxy({},{get(s,d){let c=t[d];if(typeof c=="function")return(...y)=>{let l=c.apply(t.context,y),M=Object.assign({context:l.context},o);return r(M),M}}});return{get state(){return t},get context(){return t.context},actions:i,setState:r}}function we(e,n,t){let r=()=>{let o=e.getContext(),i=t(o),s=n[i];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(i)}".`);return s(o)},a=new Proxy({},{get(o,i){let s=r(),d=s[i];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${i}" is not valid in the current state.`);return(...c)=>d.apply(s.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:a}}function De(e,n){return function(r){return we(e,r,n)}}function Ie(e,n){let t=be(n),r=e(t),a=r.next();for(;!a.done;)a=r.next();return a.value}function Ve(e,n){let t=e(n),r=t.next();for(;!r.done;)r=t.next();return r.value}var V=class{constructor(n){this.store=n}get context(){return this.store.getContext()}setContext(n){this.store.setContext(n)}};function Ue(e,n){let t=new e(n);return new Proxy({},{get(r,a){let o=n.getContext();if(a in o)return o[a];let i=t[a];if(typeof i=="function")return(...s)=>i.apply(t,s)},set(r,a,o){let i=n.getContext();if(a in i){let s={...i,[a]:o};return n.setContext(s),!0}return!1},has(r,a){let o=n.getContext();return a in o||typeof t[a]=="function"},ownKeys(r){let a=n.getContext(),o=Object.keys(a),i=Object.getOwnPropertyNames(Object.getPrototypeOf(t)).filter(s=>s!=="constructor"&&typeof t[s]=="function");return Array.from(new Set([...o,...i]))},getOwnPropertyDescriptor(r,a){let o=n.getContext();if(a in o||typeof t[a]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function Le(e,n,t){let r=()=>{let a=t(e),o=n[a];if(!o)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(a)}".`);return o(e)};return new Proxy(e,{get(a,o,i){if(o in a)return a[o];let s=r(),d=s[o];if(typeof d=="function")return(...c)=>{let y=d.apply(s.context,c);if(typeof y!="object"||y===null){console.warn(`[MutableMachine] Transition "${String(o)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(a).forEach(l=>delete a[l]),Object.assign(a,y)}},set(a,o,i,s){return a[o]=i,!0},has(a,o){let i=r();return o in a||typeof i[o]=="function"}})}function Ze(e){return function(...n){let t=this.context.child;if(typeof t[e]=="function"){let r=t[e](...n);return E(this,{...this.context,child:r})}return this}}function en(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),E(this,{...this.context,[e]:!this.context[e]})}}var S=class extends m{constructor(t){super({status:"idle"});this.config=t;this.fetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},w=class extends m{constructor(t,r,a){super({status:"loading",abortController:new AbortController,attempts:a});this.config=t;this.params=r;this.succeed=t=>{var r,a;return(a=(r=this.config).onSuccess)==null||a.call(r,t),new v(this.config,{status:"success",data:t})};this.fail=t=>{var a,o,i;let r=(a=this.config.maxRetries)!=null?a:3;return this.context.attempts<r?new j(this.config,this.params,t,this.context.attempts):((i=(o=this.config).onError)==null||i.call(o,t),new P(this.config,{status:"error",error:t}))};this.cancel=()=>(this.context.abortController.abort(),new O(this.config));this.execute()}async execute(){}},j=class extends m{constructor(t,r,a,o){super({status:"retrying",error:a,attempts:o});this.config=t;this.params=r;this.retry=t=>new w(this.config,t!=null?t:this.params,this.context.attempts+1)}},v=class extends m{constructor(t,r){super(r);this.config=t;this.refetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},P=class extends m{constructor(t,r){super(r);this.config=t;this.retry=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}},O=class extends m{constructor(t){super({status:"canceled"});this.config=t;this.refetch=t=>new w(this.config,t!=null?t:this.config.initialParams,1)}};function nn(e){return new S(e)}function U(e,n){let t={...e.context,...n.context},r={...e},a={...n};delete r.context,delete a.context;let o={};for(let i in r){let s=r[i];o[i]=(...d)=>{let c=s.apply(e.context,d);return U(c,n)}}for(let i in a){let s=a[i];o[i]=(...d)=>{let c=s.apply(n.context,d);return U(e,c)}}return{context:t,...o}}var L=Symbol("CANCEL");function g(e,n,t={}){let{continueOnError:r=!1,logErrors:a=!0,onError:o}=t,i={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(i[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let d=e[s];typeof d=="function"&&s!=="context"&&(i[s]=function(...c){let y=s,l=i.context,M=()=>{let u;try{u=d.apply(this,c)}catch(h){if(n.error)try{n.error({transitionName:y,context:l,args:[...c],error:h})}catch(f){if(!r)throw f;a&&console.error(`Middleware error hook error for ${y}:`,f),o==null||o(f,"error",{transitionName:y,context:l,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in i)Object.prototype.hasOwnProperty.call(i,f)&&f!=="context"&&!(f in h)&&(h[f]=i[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&i[f]&&(h[f]=i[f])}}return h};if(u&&typeof u.then=="function")return u.then(f=>{if(x(f),n.after)try{let C=n.after({transitionName:y,prevContext:l,nextContext:f.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>f)}catch(C){if(!r)throw C;a&&console.error(`Middleware after hook error for ${y}:`,C),o==null||o(C,"after",{transitionName:y,prevContext:l,nextContext:f.context,args:c})}return f});if(x(u),n.after)try{let h=n.after({transitionName:y,prevContext:l,nextContext:u.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>u).catch(f=>{if(!r)throw f;return a&&console.error(`Middleware after hook error for ${y}:`,f),o==null||o(f,"after",{transitionName:y,prevContext:l,nextContext:u.context,args:c}),u})}catch(h){if(!r)throw h;a&&console.error(`Middleware after hook error for ${y}:`,h),o==null||o(h,"after",{transitionName:y,prevContext:l,nextContext:u.context,args:c})}return u};if(n.before)try{let u=n.before({transitionName:y,context:l,args:[...c]});if(u&&typeof u=="object"&&u&&"then"in u)return u.then(x=>x===L?i:M()).catch(x=>{if(!r)throw x;return a&&console.error(`Middleware before hook error for ${y}:`,x),o==null||o(x,"before",{transitionName:y,context:l,args:c}),M()});if(u===L)return i}catch(u){if(!r)throw u;a&&console.error(`Middleware before hook error for ${y}:`,u),o==null||o(u,"before",{transitionName:y,context:l,args:c})}return M()})}return i}function q(e,n={}){let{logger:t=console.log,includeArgs:r=!1,includeContext:a=!0}=n;return g(e,{before:({transitionName:o,args:i})=>{let s=r?`→ ${o} [${i.join(", ")}]`:`→ ${o}`;t(s)},after:({transitionName:o,nextContext:i})=>{let s=a?` ${JSON.stringify(i)}`:"";t(`✓ ${o}${s}`)},error:({transitionName:o,error:i})=>{console.error(`[Machine] ${o} failed:`,i)}})}function J(e,n,t={}){let{eventPrefix:r="state_transition",includePrevContext:a=!1,includeArgs:o=!1}=t;return g(e,{after:({transitionName:i,prevContext:s,nextContext:d,args:c})=>{let y=`${r}.${i}`,l={transition:i};a&&(l.from=s),l.to=d,o&&(l.args=c),n(y,l)}})}function Y(e,n){return g(e,{before:t=>{if(n(t)===!1)throw new Error(`Validation failed for transition: ${t.transitionName}`)}})}function Q(e,n){return g(e,{before:t=>{if(!n(t))throw new Error(`Unauthorized transition: ${t.transitionName}`)}})}function X(e,n,t={}){let{includeArgs:r=!1}=t;return g(e,{error:a=>{let o={transition:a.transitionName,context:a.context,...r&&{args:a.args}};n(a.error,o)}})}function Z(e,n){let t=new Map;return g(e,{before:r=>{t.set(r.transitionName,Date.now())},after:r=>{let a=t.get(r.transitionName);if(a){let o=Date.now()-a;t.delete(r.transitionName);let i={transitionName:r.transitionName,duration:o,context:r.nextContext||r.prevContext};n(i)}}})}function ee(e,n={}){var d,c;let{maxAttempts:t=(d=n.maxRetries)!=null?d:3,shouldRetry:r=()=>!0,backoffMs:a=(c=n.delay)!=null?c:100,backoffMultiplier:o=2,onRetry:i}=n,s={...e};for(let y in e){if(!Object.prototype.hasOwnProperty.call(e,y))continue;let l=e[y];typeof l=="function"&&y!=="context"&&(s[y]=async function(...M){let u,x=0;for(;x<t;)try{return await l.apply(this,M)}catch(h){if(u=h,x++,x<t&&r(u,x)){i==null||i(u,x);let C=(typeof a=="function"?a(x):a)*Math.pow(o,x-1);await new Promise(T=>setTimeout(T,C))}else throw u}throw u})}return s}function rn(e,n){return t=>g(t,e,n)}function k(e,n={}){let{maxSize:t,serializer:r,onEntry:a}=n,o=[],i=0,s=g(e,{before:({transitionName:d,args:c})=>{let y={id:`entry-${i++}`,transitionName:d,args:[...c],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(c)}catch(l){console.error("Failed to serialize history args:",l)}o.push(y),t&&o.length>t&&o.shift(),a==null||a(y)}});return Object.assign(s,{history:o,clearHistory:()=>{o.length=0,i=0}})}function N(e,n={}){let{maxSize:t,serializer:r,captureSnapshot:a,onlyOnChange:o=!1}=n,i=[],s=0,d=g(e,{after:({transitionName:y,prevContext:l,nextContext:M})=>{if(o&&JSON.stringify(l)===JSON.stringify(M))return;let u={id:`snapshot-${s++}`,transitionName:y,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{u.serializedBefore=r.serialize(l),u.serializedAfter=r.serialize(M)}catch(x){console.error("Failed to serialize snapshot:",x)}if(a)try{u.diff=a(l,M)}catch(x){console.error("Failed to capture snapshot:",x)}i.push(u),t&&i.length>t&&i.shift()}});return Object.assign(d,{snapshots:i,clearSnapshots:()=>{i.length=0,s=0},restoreSnapshot:y=>{let l=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="snapshots"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&typeof e[M]=="function"));return Object.assign({context:y},l)}})}function B(e,n={}){let{maxSize:t,serializer:r,onRecord:a}=n,o=[],i=[],s=0,d=0,c=g(e,{before:({transitionName:M,args:u})=>{let x={id:`entry-${s++}`,transitionName:M,args:[...u],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(u)}catch(h){console.error("Failed to serialize history args:",h)}o.push(x),t&&o.length>t&&o.shift(),a==null||a("history",x)},after:({transitionName:M,prevContext:u,nextContext:x})=>{let h={id:`snapshot-${d++}`,transitionName:M,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(u),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}i.push(h),t&&i.length>t&&i.shift(),a==null||a("snapshot",h)}});return Object.assign(c,{history:o,snapshots:i,clearHistory:()=>{o.length=0,s=0},clearSnapshots:()=>{i.length=0,d=0},clearTimeTravel:()=>{o.length=0,i.length=0,s=0,d=0},restoreSnapshot:M=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:M},u)},replayFrom:M=>{var C;if(M<0||M>=o.length)throw new Error(`Invalid replay start index: ${M}`);let u=(C=i[M])==null?void 0:C.before;if(!u)throw new Error(`No snapshot available for index ${M}`);let x=o.slice(M),f=Object.assign({context:u},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let G=f[T.transitionName];G&&(f=G.apply(f.context,T.args))}return f}})}function fn(e,...n){return n.reduce((t,r)=>r(t),e)}function K(e,...n){return n.reduce((t,r)=>r(t),e)}var _=class e{constructor(n){this.machine=n}with(n){let t=n(this.machine);return new e(t)}build(){return this.machine}};function pn(e){return new _(e)}function z(e,n){let t=function(r){return n(r)?e(r):r};return t.middleware=e,t.when=n,t}function Cn(e){return z(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function gn(e,n,t){return z(t,r=>r.context[e]===n)}function mn(){let e=new Map;return{register(n,t,r,a){if(e.has(n))throw new Error(`Middleware '${n}' is already registered`);return e.set(n,{name:n,middleware:t,description:r,priority:a}),this},unregister(n){return e.delete(n)},has(n){return e.has(n)},get(n){return e.get(n)},list(){return Array.from(e.values()).sort((n,t)=>{var r,a;return((r=n.priority)!=null?r:0)-((a=t.priority)!=null?a:0)})},apply(n,t){let r=t.map(a=>{let o=e.get(a);if(!o)throw new Error(`Middleware '${a}' is not registered`);return o}).sort((a,o)=>{var i,s;return((i=a.priority)!=null?i:0)-((s=o.priority)!=null?s:0)});return K(n,...r.map(a=>a.middleware))},applyAll(n){let t=this.list();return K(n,...t.map(r=>r.middleware))}}}function Tn(e={}){let{continueOnError:n=!1,logErrors:t=!0,onError:r}=e;return(a,...o)=>{let i=a,s=[],d=!0;for(let c=0;c<o.length;c++){let y=o[c];try{if("middleware"in y&&"when"in y){if(!y.when(i))continue;i=y.middleware(i)}else i=y(i)}catch(l){if(d=!1,!n)throw l;s.push({error:l,middlewareIndex:c,middlewareName:y.name}),t&&console.error(`Pipeline middleware error at index ${c}:`,l),r==null||r(l,c,y.name)}}return{machine:i,errors:s,success:d}}}function bn(...e){return n=>K(n,...e)}function wn(e,n){return t=>{for(let[r,a]of e)if(r(t))return a(t);return n?n(t):t}}function ne(e){return typeof e=="function"&&e.length===1}function En(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ne(e.middleware)&&typeof e.when=="function"}function Fn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||F(e.prevContext,n)&&F(e.nextContext,n))}function An(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!n||F(e.context,n))}function Rn(e,n){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!n||F(e.context,n))}function Sn(e,n){if(e===null||typeof e!="object")return!1;let t=e;return!("before"in t&&t.before!==void 0&&typeof t.before!="function"||"after"in t&&t.after!==void 0&&typeof t.after!="function"||"error"in t&&t.error!==void 0&&typeof t.error!="function")}function jn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function F(e,n){return e!==null&&typeof e=="object"}function vn(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ne(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Pn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var H=class{constructor(n){this.machine=n;this.middlewares=[]}withLogging(n){return this.middlewares.push(t=>q(t,n)),this}withAnalytics(n,t){return this.middlewares.push(r=>J(r,n,t)),this}withValidation(n,t){return this.middlewares.push(r=>Y(r,n)),this}withPermissions(n){return this.middlewares.push(t=>Q(t,n)),this}withErrorReporting(n,t){return this.middlewares.push(r=>X(r,n,t)),this}withPerformanceMonitoring(n,t){return this.middlewares.push(r=>Z(r,n)),this}withRetry(n){return this.middlewares.push(t=>ee(t,n)),this}withHistory(n){return this.middlewares.push(t=>k(t,n)),this}withSnapshot(n){return this.middlewares.push(t=>N(t,n)),this}withTimeTravel(n){return this.middlewares.push(t=>B(t,n)),this}withDebugging(){return this.middlewares.push(n=>Fe(n)),this}withCustom(n){return this.middlewares.push(n),this}withConditional(n,t){return this.middlewares.push(z(n,t)),this}build(){let n=this.machine;for(let t of this.middlewares)n=t(n);return n}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Ee(e){return new H(e)}function On(e={}){return{create:n=>{let t=Ee(n);return e.logging&&t.withLogging(e.logging),e.analytics&&t.withAnalytics(e.analytics.track,e.analytics.options),e.history&&t.withHistory(e.history),e.snapshot&&t.withSnapshot(e.snapshot),e.timeTravel&&t.withTimeTravel(e.timeTravel),e.retry&&t.withRetry(e.retry),t}}}function Fe(e){return B(N(k(e)))}function Ae(e,n){return e instanceof n}function Re(e,...n){return{type:e,args:n}}function Se(e,n){return E(e,t=>({...t,...n}))}async function je(e,...n){let t=e;for(let r of n)t=await r(t);return t}function ve(e,n){return n?console.log(n,e.context):console.log(e.context),e}function Pe(e,n){return function(...t){let r=n(this.context,...t);return p(r,e())}}function Oe(e,n,...t){return e.apply(n,t)}function te(e){return new Proxy(e,{get(n,t){let r=n[t];return typeof r=="function"?function(...a){let o=r.apply(n.context,a);return o&&typeof o=="object"&&"context"in o?te(o):o}:r}})}var $=class e{constructor(n){return this.wrappedMachine=n,new Proxy(this,{get:(t,r)=>{if(r==="wrappedMachine")return Reflect.get(t,r);if(r==="context")return this.wrappedMachine.context;let a=this.wrappedMachine[r];return typeof a=="function"?(...o)=>{let i=a.apply(this.wrappedMachine.context,o);return i&&typeof i=="object"&&"context"in i?new e(i):i}:a}})}};function ke(){return function(n){return function(...t){let r=n(this.context,...t);return p(r,this)}}}function re(e){return{machine:e,addTransition:function(n,t){let r=function(...o){let i=t(this.context,...o);return p(i,this)},a=oe(e,{[n]:r});return re(a)}}}function ae(e){return function(t){let r={},a=Object.fromEntries(Object.entries(t).map(([o,i])=>[o,function(...s){let d=i(this.context,...s);return p(d,r)}]));return Object.assign(r,a),p(e,r)}}function Ne(e,n){return n!==void 0?p(e,n):ae(e)}function Be(...e){let n=new Map;for(let[s,d,c]of e){if(n.has(s))throw new Error(`Duplicate matcher case name: "${s}"`);n.set(s,{predicate:c})}let t=new Proxy({},{get(s,d){return function(y){let l=n.get(d);if(!l){let M=Array.from(n.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${M}`)}return l.predicate(y)}}}),r=new Proxy({},{get(s,d){return function(y){if(!n.has(d)){let l=Array.from(n.keys()).join(", ");throw new Error(`Unknown matcher case: "${d}". Available cases: ${l}`)}return{__brand:"CaseHandler",__name:d,__machine:void 0,__return:void 0,handler:y}}}}),a={__exhaustive:!0};function o(s){return{is(...d){if(d.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let c=d[d.length-1];if(!c||typeof c!="object"||!("__exhaustive"in c))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let y=d.slice(0,-1);for(let u of y){let x=u.__name,h=n.get(x);if(!h)throw new Error(`Internal error: Unknown matcher case in handler: ${x}`);if(h.predicate(s))return u.handler(s)}let l=y.map(u=>u.__name).join(", "),M=Array.from(n.keys()).join(", ");throw new Error(`Non-exhaustive pattern match at runtime: no handler matched the machine.
2
2
  Handled cases: [${l}]
3
3
  All cases: [${M}]
4
- This may occur if predicates don't cover all runtime possibilities.`)}}}function i(s){for(let[d,c,y]of e)if(y(s))return d;return null}return Object.assign(i,{is:t,when:o,case:r,exhaustive:a})}function Ke(e,n){return[e,void 0,t=>t instanceof n]}function _e(e,n,t){return[e,void 0,r=>$(r,n,t)]}function He(e,n){return[e,void 0,n]}function ze(){return{case(e,n,t){return[e,void 0,r=>$(r,n,t)]}}}function p(e,n){if(typeof n=="function"){let a;a=n(s=>{let d=p(s,a),c=Object.fromEntries(Object.entries(a).map(([y,l])=>[y,l.bind(s)]));return Object.assign(d,c)});let i=Object.fromEntries(Object.entries(a).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},i)}let t="context"in n?Object.fromEntries(Object.entries(n).filter(([a])=>a!=="context")):n;return Object.assign({context:e},t)}function We(e,n){if(typeof n=="function"){let a;a=n(s=>{let d=We(s,a),c=Object.fromEntries(Object.entries(a).map(([y,l])=>[y,l.bind(s)]));return Object.assign(d,c)});let i=Object.fromEntries(Object.entries(a).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},i)}let t="context"in n?Object.fromEntries(Object.entries(n).filter(([a])=>a!=="context")):n;return Object.assign({context:e},t)}function Jn(){return e=>{let n=Object.fromEntries(Object.entries(e).map(([t,r])=>[t,function(...a){let o=r(this.context,...a);return p(o,n)}]));return t=>p(t,n)}}function E(e,n){let{context:t,...r}=e,a=typeof n=="function"?n(t):n;return p(a,r)}function Yn(e){return{context:e}}function Qn(e,n){let{context:t,...r}=e,a={...r,...n};return p(t,a)}function oe(e,n){let{context:t,...r}=e,a={...r,...n};return p(t,a)}function Xn(e,n){return(...t)=>{let r=e(...t),a=n(),o={...r.context,...a.context},{context:i,...s}=r,{context:d,...c}=a,y={...s,...c};return p(o,y)}}function Zn(e){let{context:n,...t}=e;return r=>p(r,t)}function et(e,n,t){let r=e.context[n],a=t[r];if(!a)throw new Error(`No handler found for state: ${String(r)}`);return a(e.context)}function $(e,n,t){return e.context[n]===t}function nt(e,n){let t=e,r=null;async function a(o){r&&(r.abort(),r=null);let i=t[o.type];if(typeof i!="function")throw new Error(`[Machine] Unknown event type '${String(o.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await i.apply(t.context,[...o.args,{signal:s.signal}]);return s.signal.aborted||(t=c,n==null||n(t)),t}finally{r===s&&(r=null)}}return{get state(){return t.context},dispatch:a,stop:()=>{r&&(r.abort(),r=null)}}}var m=class{constructor(n){this.context=n}};function tt(e,n){let{context:t,...r}=e;return p(n(t),r)}export{W as BoundMachine,L as CANCEL,Me as META_KEY,m as MachineBase,H as MiddlewareBuilder,V as MultiMachineBase,Ce as action,te as bindTransitions,wn as branch,Oe as call,pn as chain,Ke as classCase,bn as combine,Xn as combineFactories,fn as compose,K as composeTyped,We as createAsyncMachine,Yn as createContext,rn as createCustomMiddleware,we as createEnsemble,De as createEnsembleFactory,Re as createEvent,nn as createFetchMachine,de as createFlow,ae as createFunctionalMachine,p as createMachine,Zn as createMachineBuilder,Jn as createMachineFactory,Ne as createMatcher,g as createMiddleware,On as createMiddlewareFactory,mn as createMiddlewareRegistry,Ue as createMultiMachine,Le as createMutableMachine,U as createParallelMachine,Tn as createPipeline,be as createRunner,Pe as createTransition,re as createTransitionExtender,ke as createTransitionFactory,He as customCase,Ze as delegateToChild,he as describe,_e as discriminantCase,oe as extendTransitions,ze as forContext,A as guard,R as guardAsync,fe as guarded,$ as hasState,Cn as inDevelopment,pe as invoke,En as isConditionalMiddleware,An as isMiddlewareContext,Rn as isMiddlewareError,ne as isMiddlewareFn,Sn as isMiddlewareHooks,jn as isMiddlewareOptions,Fn as isMiddlewareResult,vn as isNamedMiddleware,Pn as isPipelineConfig,Ae as isState,ve as logState,et as matchMachine,Se as mergeContext,Te as metadata,Ee as middlewareBuilder,tt as next,Qn as overrideTransitions,je as pipeTransitions,D as run,le as runAsync,nt as runMachine,ce as runSequence,ye as runWithDebug,Ve as runWithEnsemble,Ie as runWithRunner,E as setContext,Be as state,ie as step,ue as stepAsync,en as toggle,xe as transitionTo,z as when,gn as whenContext,ge as whenGuard,me as whenGuardAsync,J as withAnalytics,Fe as withDebugging,X as withErrorReporting,k as withHistory,q as withLogging,Z as withPerformanceMonitoring,Q as withPermissions,ee as withRetry,B as withSnapshot,N as withTimeTravel,Y as withValidation,se as yieldMachine};
4
+ This may occur if predicates don't cover all runtime possibilities.`)}}}function i(s){for(let[d,c,y]of e)if(y(s))return d;return null}return Object.assign(i,{is:t,when:o,case:r,exhaustive:a})}function Ke(e,n){return[e,void 0,t=>t instanceof n]}function _e(e,n,t){return[e,void 0,r=>W(r,n,t)]}function He(e,n){return[e,void 0,n]}function ze(){return{case(e,n,t){return[e,void 0,r=>W(r,n,t)]}}}function p(e,n){if(typeof n=="function"){let a;a=n(s=>{let d=p(s,a),c=Object.fromEntries(Object.entries(a).map(([y,l])=>[y,l.bind(s)]));return Object.assign(d,c)});let i=Object.fromEntries(Object.entries(a).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},i)}let t="context"in n?Object.fromEntries(Object.entries(n).filter(([a])=>a!=="context")):n;return Object.assign({context:e},t)}function $e(e,n){if(typeof n=="function"){let a;a=n(s=>{let d=$e(s,a),c=Object.fromEntries(Object.entries(a).map(([y,l])=>[y,l.bind(s)]));return Object.assign(d,c)});let i=Object.fromEntries(Object.entries(a).map(([s,d])=>[s,d.bind(e)]));return Object.assign({context:e},i)}let t="context"in n?Object.fromEntries(Object.entries(n).filter(([a])=>a!=="context")):n;return Object.assign({context:e},t)}function Jn(){return e=>{let n=Object.fromEntries(Object.entries(e).map(([t,r])=>[t,function(...a){let o=r(this.context,...a);return p(o,n)}]));return t=>p(t,n)}}function E(e,n){let{context:t,...r}=e,a=typeof n=="function"?n(t):n;return p(a,r)}function Yn(e){return{context:e}}function Qn(e,n){let{context:t,...r}=e,a={...r,...n};return p(t,a)}function oe(e,n){let{context:t,...r}=e,a={...r,...n};return p(t,a)}function Xn(e,n){return(...t)=>{let r=e(...t),a=n(),o={...r.context,...a.context},{context:i,...s}=r,{context:d,...c}=a,y={...s,...c};return p(o,y)}}function Zn(e){let{context:n,...t}=e;return r=>p(r,t)}function et(e,n,t){let r=e.context[n],a=t[r];if(!a)throw new Error(`No handler found for state: ${String(r)}`);return a(e.context)}function W(e,n,t){return e.context[n]===t}function nt(e,n){let t=e,r=null;async function a(o){r&&(r.abort(),r=null);let i=t[o.type];if(typeof i!="function")throw new Error(`[Machine] Unknown event type '${String(o.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await i.apply(t.context,[...o.args,{signal:s.signal}]);return s.signal.aborted||(t=c,n==null||n(t)),t}finally{r===s&&(r=null)}}return{get state(){return t.context},dispatch:a,stop:()=>{r&&(r.abort(),r=null)}}}var m=class{constructor(n){this.context=n}};function tt(e,n){let{context:t,...r}=e;return p(n(t),r)}export{$ as BoundMachine,L as CANCEL,Me as META_KEY,m as MachineBase,H as MiddlewareBuilder,V as MultiMachineBase,Ce as action,te as bindTransitions,wn as branch,Oe as call,pn as chain,Ke as classCase,bn as combine,Xn as combineFactories,fn as compose,K as composeTyped,$e as createAsyncMachine,Yn as createContext,rn as createCustomMiddleware,we as createEnsemble,De as createEnsembleFactory,Re as createEvent,nn as createFetchMachine,de as createFlow,ae as createFunctionalMachine,p as createMachine,Zn as createMachineBuilder,Jn as createMachineFactory,Be as createMatcher,g as createMiddleware,On as createMiddlewareFactory,mn as createMiddlewareRegistry,Ue as createMultiMachine,Le as createMutableMachine,U as createParallelMachine,Tn as createPipeline,be as createRunner,Pe as createTransition,re as createTransitionExtender,ke as createTransitionFactory,He as customCase,Ze as delegateToChild,he as describe,_e as discriminantCase,oe as extendTransitions,ze as forContext,A as guard,R as guardAsync,fe as guarded,W as hasState,Cn as inDevelopment,pe as invoke,En as isConditionalMiddleware,An as isMiddlewareContext,Rn as isMiddlewareError,ne as isMiddlewareFn,Sn as isMiddlewareHooks,jn as isMiddlewareOptions,Fn as isMiddlewareResult,vn as isNamedMiddleware,Pn as isPipelineConfig,Ae as isState,ve as logState,et as matchMachine,Se as mergeContext,Te as metadata,Ee as middlewareBuilder,tt as next,Qn as overrideTransitions,je as pipeTransitions,D as run,le as runAsync,nt as runMachine,ce as runSequence,ye as runWithDebug,Ve as runWithEnsemble,Ie as runWithRunner,E as setContext,Ne as state,ie as step,ue as stepAsync,en as toggle,xe as transitionTo,z as when,gn as whenContext,ge as whenGuard,me as whenGuardAsync,J as withAnalytics,Fe as withDebugging,X as withErrorReporting,k as withHistory,q as withLogging,Z as withPerformanceMonitoring,Q as withPermissions,ee as withRetry,N as withSnapshot,B as withTimeTravel,Y as withValidation,se as yieldMachine};
@@ -85,7 +85,11 @@ export type ExhaustivenessMarker = {
85
85
  /**
86
86
  * Extracts machine types from an array of case handlers.
87
87
  */
88
- type HandledMachines<Handlers extends readonly any[]> = Handlers extends readonly [infer H, ...infer Rest] ? (H extends CaseHandler<any, infer M, any> ? M : never) | HandledMachines<Rest> : never;
88
+ type ExtractHandledMachines<H extends readonly any[]> = H extends readonly [infer First, ...infer Rest] ? (First extends CaseHandler<any, infer M, any> ? M : never) | ExtractHandledMachines<Rest> : never;
89
+ /**
90
+ * Extracts return types from an array of case handlers.
91
+ */
92
+ type ExtractHandlerReturn<H extends readonly any[]> = H extends readonly CaseHandler<any, any, infer R>[] ? R : never;
89
93
  /**
90
94
  * Checks if all machine types in Union have been handled.
91
95
  * Returns true if exhaustive, otherwise returns an error type with missing cases.
@@ -114,7 +118,14 @@ export interface WhenBuilder<_Cases extends readonly MatcherCase<any, any, any>[
114
118
  * );
115
119
  * ```
116
120
  */
117
- is<R>(...handlers: [...any[], ExhaustivenessMarker]): IsExhaustive<M, HandledMachines<typeof handlers>> extends true ? R : IsExhaustive<M, HandledMachines<typeof handlers>>;
121
+ /**
122
+ * Overload 1: Infer return type from handlers (Enables exhaustiveness checking).
123
+ */
124
+ is<H extends readonly CaseHandler<CaseNames<_Cases>, any, any>[]>(...handlers: [...H, ExhaustivenessMarker]): IsExhaustive<M, ExtractHandledMachines<H>> extends true ? ExtractHandlerReturn<H> : IsExhaustive<M, ExtractHandledMachines<H>>;
125
+ /**
126
+ * Overload 2: Explicit return type (No exhaustiveness checking).
127
+ */
128
+ is<R>(...handlers: [...CaseHandler<CaseNames<_Cases>, any, R>[], ExhaustivenessMarker]): R;
118
129
  }
119
130
  /**
120
131
  * The main Matcher interface with three APIs.
@@ -131,7 +142,7 @@ export interface Matcher<Cases extends readonly MatcherCase<any, any, any>[]> {
131
142
  * ```
132
143
  */
133
144
  readonly is: {
134
- [Name in CaseNames<Cases>]: <M>(machine: M) => machine is Extract<M, CasesToMapping<Cases>[Name]>;
145
+ [Name in CaseNames<Cases>]: (machine: any) => machine is CasesToMapping<Cases>[Name];
135
146
  };
136
147
  /**
137
148
  * API 2a: Pattern matching builder.
@@ -303,15 +314,11 @@ export declare function forContext<C extends object>(): {
303
314
  * Creates a discriminated union case with full type inference.
304
315
  */
305
316
  case<Name extends string, K extends keyof C, V extends C[K]>(name: Name, key: K, value: V): MatcherCase<Name, {
306
- readonly context: C;
307
- } & {
308
- context: Extract<C, { [P in K]: V; }>;
317
+ readonly context: Extract<C, { [P in K]: V; }>;
309
318
  }, (m: {
310
319
  readonly context: C;
311
320
  }) => m is {
312
- readonly context: C;
313
- } & {
314
- context: Extract<C, { [P in K]: V; }>;
321
+ readonly context: Extract<C, { [P in K]: V; }>;
315
322
  }>;
316
323
  };
317
324
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../../src/matcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+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1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doeixd/machine",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
package/src/matcher.ts CHANGED
@@ -69,7 +69,7 @@ type CaseToName<C> = C extends MatcherCase<infer Name, any, any> ? Name : never;
69
69
  * Builds a mapping from case names to their machine types.
70
70
  */
71
71
  export type CasesToMapping<Cases extends readonly MatcherCase<any, any, any>[]> = {
72
- [C in Cases[number] as CaseToName<C>]: CaseToMachine<C>;
72
+ [C in Cases[number]as CaseToName<C>]: CaseToMachine<C>;
73
73
  };
74
74
 
75
75
  /**
@@ -106,10 +106,16 @@ export type ExhaustivenessMarker = {
106
106
  /**
107
107
  * Extracts machine types from an array of case handlers.
108
108
  */
109
- type HandledMachines<Handlers extends readonly any[]> =
110
- Handlers extends readonly [infer H, ...infer Rest]
111
- ? (H extends CaseHandler<any, infer M, any> ? M : never) | HandledMachines<Rest>
112
- : never;
109
+ type ExtractHandledMachines<H extends readonly any[]> =
110
+ H extends readonly [infer First, ...infer Rest]
111
+ ? (First extends CaseHandler<any, infer M, any> ? M : never) | ExtractHandledMachines<Rest>
112
+ : never;
113
+
114
+ /**
115
+ * Extracts return types from an array of case handlers.
116
+ */
117
+ type ExtractHandlerReturn<H extends readonly any[]> =
118
+ H extends readonly CaseHandler<any, any, infer R>[] ? R : never;
113
119
 
114
120
  /**
115
121
  * Checks if all machine types in Union have been handled.
@@ -117,11 +123,11 @@ type HandledMachines<Handlers extends readonly any[]> =
117
123
  */
118
124
  export type IsExhaustive<Union, Handled> =
119
125
  Exclude<Union, Handled> extends never
120
- ? true
121
- : {
122
- readonly __error: 'Non-exhaustive match - missing cases';
123
- readonly __missing: Exclude<Union, Handled>;
124
- };
126
+ ? true
127
+ : {
128
+ readonly __error: 'Non-exhaustive match - missing cases';
129
+ readonly __missing: Exclude<Union, Handled>;
130
+ };
125
131
 
126
132
  /**
127
133
  * Pattern matching builder returned by matcher.when().
@@ -146,11 +152,21 @@ export interface WhenBuilder<
146
152
  * );
147
153
  * ```
148
154
  */
155
+ /**
156
+ * Overload 1: Infer return type from handlers (Enables exhaustiveness checking).
157
+ */
158
+ is<H extends readonly CaseHandler<CaseNames<_Cases>, any, any>[]>(
159
+ ...handlers: [...H, ExhaustivenessMarker]
160
+ ): IsExhaustive<M, ExtractHandledMachines<H>> extends true
161
+ ? ExtractHandlerReturn<H>
162
+ : IsExhaustive<M, ExtractHandledMachines<H>>;
163
+
164
+ /**
165
+ * Overload 2: Explicit return type (No exhaustiveness checking).
166
+ */
149
167
  is<R>(
150
- ...handlers: [...any[], ExhaustivenessMarker]
151
- ): IsExhaustive<M, HandledMachines<typeof handlers>> extends true
152
- ? R
153
- : IsExhaustive<M, HandledMachines<typeof handlers>>;
168
+ ...handlers: [...CaseHandler<CaseNames<_Cases>, any, R>[], ExhaustivenessMarker]
169
+ ): R;
154
170
  }
155
171
 
156
172
  /**
@@ -168,9 +184,9 @@ export interface Matcher<Cases extends readonly MatcherCase<any, any, any>[]> {
168
184
  * ```
169
185
  */
170
186
  readonly is: {
171
- [Name in CaseNames<Cases>]: <M>(
172
- machine: M
173
- ) => machine is Extract<M, CasesToMapping<Cases>[Name]>;
187
+ [Name in CaseNames<Cases>]: (
188
+ machine: any
189
+ ) => machine is CasesToMapping<Cases>[Name];
174
190
  };
175
191
 
176
192
  /**
@@ -265,7 +281,7 @@ export function createMatcher<
265
281
  // API 1: Type Guards (using Proxy for dynamic property access)
266
282
  const isProxy = new Proxy({} as any, {
267
283
  get(_target, prop: string) {
268
- return function isGuard<M>(machine: M): machine is any {
284
+ return function isGuard(machine: any): machine is any {
269
285
  const caseConfig = nameToCase.get(prop);
270
286
  if (!caseConfig) {
271
287
  const available = Array.from(nameToCase.keys()).join(', ');
@@ -515,7 +531,7 @@ export function customCase<
515
531
  * ```
516
532
  */
517
533
  export function forContext<C extends object>() {
518
- type MachineWithContext = { readonly context: C };
534
+
519
535
 
520
536
  return {
521
537
  /**
@@ -531,8 +547,8 @@ export function forContext<C extends object>() {
531
547
  value: V
532
548
  ): MatcherCase<
533
549
  Name,
534
- MachineWithContext & { context: Extract<C, { [P in K]: V }> },
535
- (m: MachineWithContext) => m is MachineWithContext & { context: Extract<C, { [P in K]: V }> }
550
+ { readonly context: Extract<C, { [P in K]: V }> },
551
+ (m: { readonly context: C }) => m is { readonly context: Extract<C, { [P in K]: V }> }
536
552
  > {
537
553
  return [
538
554
  name,