valdres 1.0.0-beta.26 → 1.0.0-beta.28

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 CHANGED
@@ -74,6 +74,6 @@ The versioned `valdres/adapter-internals/v1` entry is for framework bindings. It
74
74
 
75
75
  ## Beta compatibility
76
76
 
77
- `valdres@1.0.0-beta.24` and later v1 betas intentionally replace the legacy beta API. `valdres-react@1.0.0-beta.5` is certified with core versions accepted by its `^1.0.0-beta.24` peer range. Deferred framework adapters and plugins remain unsupported even when their published semver ranges allow npm to resolve this core; do not mix them with the new beta until they are migrated.
77
+ `valdres@1.0.0-beta.24` and later v1 betas intentionally replace the legacy beta API. `valdres-react@1.0.0-beta.6` is certified with `valdres@1.0.0-beta.27` and later v1 betas accepted by its `^1.0.0-beta.27` peer range. Deferred framework adapters and plugins remain unsupported even when their published semver ranges allow npm to resolve this core; do not mix them with the new beta until they are migrated.
78
78
 
79
79
  <!-- DOCS:END -->
@@ -1 +1 @@
1
- import{q as e}from"../chunk-wzf3zmr8.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
1
+ import{q as e}from"../chunk-6pxeaw0f.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
@@ -0,0 +1,2 @@
1
+ class x extends Error{seal(){Object.freeze(this)}}class se extends x{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class ye extends x{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class X extends x{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class P extends x{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Ae extends x{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ae extends x{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class be extends x{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Me=Object.freeze({kind:"not-thenable"}),ft=()=>{},ht=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ke extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class ve extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ce extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class Z extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ee extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class we extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ge extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Te extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class de extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var O=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},R=(e)=>{try{ht(e.then,e.target,[void 0,ft])}catch{}},te=(e)=>{let t=O(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return R(t),Object.freeze({kind:"error",error:new Z})},Oe=(e)=>{try{return te(e())}catch(t){let n=O(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return R(n),Object.freeze({kind:"error",error:new Z})}},ne=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},I=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},oe=(e,t,n)=>ne(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ne(e,Object.freeze({kind:"transaction",transaction:t}),n),le=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Re=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ue=(e,t,n)=>{if(!n)throw new ce;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ke;throw We(e,n).latchControlFault(r),r}}return"invalid"},E=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return I(e,r,()=>L(e,t,r))},re=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),fe=(e,t)=>Object.freeze(re({kind:e},t));var Ue=Object.freeze({kind:"not-thenable"}),St=()=>{},mt=Reflect.apply,qe=Symbol("selector dependency path root"),Ye=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},$e=(e)=>{try{mt(e.then,e.target,[void 0,St])}catch{}},pt=(e)=>Object.freeze(e),yt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=yt(o);return Object.freeze({selector:e,token:t,outcome:pt(n),dependencies:r,attemptedPrefix:n.kind==="value"?At:Object.freeze(r.map((i)=>i.node))})},At=Object.freeze([]),bt=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let d=n.getSelectorDependencyNodes(s);if(d===void 0)continue;for(let l of d){if(i.has(l))continue;i.set(l,s),r.push(l)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ge=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),new P(t);if(n.kind==="inspection-error")return n.error;return e},Ke=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),Object.freeze({kind:"error",error:new P(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},Qe=(e,t,n,o=bt)=>{let{node:r}=e,i=[],s=t.getSelectorRecord(r),a=s?.dependencies,c=a===void 0?new Set:void 0,d,l=0,f=t.getComparisonBaseline(r),b=!0,y=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let m of i)u.add(m.node);return c=u,u};n.enter(t,r,i);let k=t.getSelectorGraphVersion(),z=n.getSelectorGraphPublicationCount(t),G=k,K=z,Pe=k,Ie=z,me=(u,m,v,p)=>v-u===p-m,ze=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),v=me(G,K,u,m))=>{if(v){G=u,K=m;return}for(let p=0;p<i.length;p++){let F=i[p],N=o(F.node,r,t,n,0);if(!N)continue;if(c!==void 0)for(let A=i.length-1;A>=p;A--)c.delete(i[A].node);if(i.length=p,l++,n.getControlFault().kind==="fault")return;let M=new X(r,[r,...N]);n.latchCycle(t,r,M);return}G=u,K=m},pe=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Pe=u,Ie=m;let v=me(G,K,u,m);if(!v)n.revalidateAncestorPrefixes(t,r);ze(u,m,v)};n.setPrefixRevalidator(t,r,ze);let ut=(u)=>{if(!b)throw new be;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let v=n.getCycle(t,r);if(v!==void 0)throw v;let p=n.activeCyclePath(t,u);if(p){let h=new X(r,p);throw n.latchCycle(t,r,h),h}let F=i.length,N,D=!1;if(c===void 0){let h=a?.[F];if(h!==void 0&&Object.is(h.node,u))N=!1,D=!0;else N=y().has(u)}else N=c.has(u);if(!N&&!D&&a!==void 0&&a.length>0){let h=a[i.length];if(h!==void 0&&Object.is(h.node,u))D=!0;else{if(d===void 0){d=new Set;for(let B of a)d.add(B.node)}D=d.has(u)}}let M=l,A=t.serve(u,n);pe();let _=n.getCycle(t,r);if(_!==void 0)throw _;let Y=c!==void 0?c.has(u):l===M&&i.length===F?!1:y().has(u),j=Pe,H=Ie,V=Y||D&&j===k,ie=a===void 0&&me(k,z,j,H);if(!V&&!ie){let h=o(u,r,t,n,1);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Fe=new X(r,[r,...h]);throw n.latchCycle(t,r,Fe),Fe}}if(!Y){let h=s?.dependencies[i.length];c?.add(u),i.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(G=j,K=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(A.outcome.kind==="error")throw new ye(u,A.outcome.error);return A.outcome.value};try{let u,m,v=!1;try{u=e.get(ut)}catch(_){v=!0,m=_}finally{b=!1}if(v)m=Ge(m,"getter");let p=v?void 0:Ke(u,"getter");pe();let F=n.getControlFault();if(F.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:F.error},i);let N=n.getCycle(t,r);if(N!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:N},i);if(v)return g(r,t.createOutcomeToken(),{kind:"error",error:m instanceof P?m:new se(r,m)},i);if(p===void 0)throw Error("Selector result classification was not completed");let D=n.getControlFault();if(D.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:D.error},i);if(p.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:p.error instanceof P?p.error:new se(r,p.error)},i);let M=p.value,A;if(f){let _=e.equal??Object.is,Y,j,H=!1;try{Y=_(f.value,M)}catch(B){H=!0,j=Ge(B,"comparator")}let V=H?void 0:Ke(Y,"comparator");pe();let ie=n.getControlFault();if(ie.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:ie.error},i);let Q=n.getCycle(t,r);if(Q!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:Q},i);if(H)return g(r,t.createOutcomeToken(),{kind:"error",error:j instanceof P?j:new ae(r,j)},i);if(V===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:h.error},i);if(V.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:V.error instanceof P?V.error:new ae(r,V.error)},i);if(V.value!==!0&&V.value!==!1)return g(r,t.createOutcomeToken(),{kind:"error",error:new Ae},i);if(V.value===!0)M=f.value,A=f.current?f.token:void 0}return g(r,A??t.createOutcomeToken(),{kind:"value",value:M},i)}finally{n.leave(t,r)}};class S{#t=[];#n;#o=0;#i;#s=kt;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#r(e,t).cycleError}#r(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var kt=Object.freeze({kind:"none"});var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#i=new Map;#s;#r=1;#a=0;#c;constructor(e,t,n){this.#t=e,this.#s=t,this.#c=n}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#t=void 0}serve(e,t){let n=this.#d(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>this.#c(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#a++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#d().captureCommittedSelectorSuccess(e)??Xe,this.#i.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#d(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#s=new WeakMap;#r=new WeakSet;#a=0;#c;#d="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#l(),this.#n=this.#l()}get status(){return this.#d}get facade(){if(this.#c===void 0)throw Error("Store scope facade is not installed");return this.#c}installFacade(e){if(this.#c!==void 0)throw Error("Store scope facade is already installed");this.#c=e}markDisposing(){if(this.#d==="live")this.#d="disposing"}markDisposed(){this.#d="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#l()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#s.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#i=void 0,this.#s=new WeakMap,this.#r=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r,t),i=this.#o.get(r);if(i!==void 0&&!this.#r.has(r))return i.served;let s=oe(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#h(e,o?.dependencies??vt,t.dependencies))this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#h(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#s.get(o.node);if(r?.delete(e),r?.isEmpty())this.#s.delete(o.node)}for(let o of n){let r=this.#s.get(o.node);if(r===void 0)r=this.#l(),this.#s.set(o.node,r);r.add(e)}return!0}#l(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var vt=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#f;#h;#l;#b;#p;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#s!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#i===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#u(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#u();i.set(this.#n,o);let s=this.#u();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#y();return}let s=this.#u();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#u(),s=this.#u();if(s.set(r.atom,r),this.#i!==void 0)s.set(this.#i.atom,this.#i);i.set(this.#n,s);let a=this.#u();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#o=void 0,this.#i=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#i!==void 0)e(this.#n,this.#i);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#i;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#d!==void 0&&Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;if(this.#h!==void 0&&Object.is(this.#a,e)&&Object.is(this.#f,t))return this.#h;if(Object.is(this.#a,e))return this.#l?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#u(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#l;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#u();s.set(this.#a,r);let a=this.#u();a.set(t,n),s.set(e,a),this.#b=s,this.#l=void 0,this.#a=void 0}return}let i=this.#d;if(i===void 0){this.#a=e,this.#c=t,this.#d=n;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t))return;if(Object.is(this.#a,e)){let s=this.#h;if(s===void 0){this.#f=t,this.#h=n;return}if(Object.is(this.#f,t))return;let a=this.#u();a.set(this.#c,i),a.set(this.#f,s),a.set(t,n),this.#l=a}else{let s=this.#u(),a=this.#u();if(a.set(this.#c,i),this.#f!==void 0&&this.#h!==void 0)a.set(this.#f,this.#h);s.set(this.#a,a);let c=this.#u();c.set(t,n),s.set(e,c),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#p,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#p,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#p=e,this.#S=t;return}if(Object.is(this.#p,e)){this.#S=t;return}let o=this.#u();o.set(this.#p,this.#S),o.set(e,t),this.#m=o,this.#p=void 0,this.#S=void 0}forEachFallback(e){if(this.#p!==void 0&&this.#S!==void 0)e(this.#p,this.#S);if(this.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#l?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0,this.#l=void 0,this.#b=void 0,this.#p=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#u(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ne=(e,t,n)=>new Ze(e,t,n),Ve=(e)=>{let t=O(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw R(t),new J},et=(e)=>{let t=O(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw R(t),new J};var wt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},at=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31}),gt=32,ct=new WeakMap,Kt=()=>{let e=new Uint32Array(gt),t=Object.freeze({read(n){return e[at[n]]??0}});return ct.set(t,e),t},T=(e)=>Object.freeze({kind:"value",value:e}),Tt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):Tt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,Ee=2,rt=4,Ot=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Rt=(e)=>(e.onAllocation?.(),new Set),De=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Ct=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Rt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Nt=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class dt{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#f;#h;#l;#b=1;#p=0;#S;#m;#e;#y;#u;evaluate;constructor(e,t,n){this.#e=e,this.#y=t===void 0?void 0:ct.get(t),this.#u=n,this.evaluate=n?.evaluate??Qe,this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[at[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=E(this.#e,o,n),i=Re(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":E(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#l;if(a===void 0){if(a=new Map,this.#l=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return wt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#l,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#l=void 0}set(e,t,n){this.#O(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#O(e,t,"StoreTree.update","update",n)}reset(e,t){this.#O(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)E(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#Q(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Ne(this,o,e),i;try{i=Be(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new S;le(this.#e,s,()=>Ve(i)),this.#M(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new S,o=t,r=E(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#T(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#K(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=E(this.#e,o,r);if(ue(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#G(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#I(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")E(this.#e,n,i);ue(this.#e,e.transaction,e.active),this.#A(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ne(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return le(this.#e,f,()=>et(l))}let d=new S;return le(this.#e,d,()=>Ve(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#D(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#j(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n,this.#u);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#Y(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ge;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new Te;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ce;throw new de}throw new de}#A(e){if(e.status!=="live")throw new we}#$(e,t,n,o){let r=E(this.#e,t,n);C(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new S;this.#$(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#M(a)}finally{a.release()}}#Q(e){let t=this.#l,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#l=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=E(this.#e,n,o);ue(this.#e,e.transaction,e.active),this.#A(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=I(this.#e,r,()=>te(o));if(i.kind==="error")throw i.error;let s=this.#C(e,t,n,r);this.#q(e,t,n,i.value,s,r)}#I(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#C(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#Z(o,a.value,r);this.#q(e,t,n,c,s,r)}#z(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#N(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0})}#N(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(I(this.#e,n,()=>Oe(i)));return e.setFallback(t,a),a}#X(e,t,n,o){let r=this.#v(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#J(r,t,n,o)?t:n}#J(e,t,n,o){return I(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=O(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw R(a),new ee}let i=O(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw R(i),new ee;if(r!==!0&&r!==!1)throw new ee;return r})}#Z(e,t,n){return I(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=O(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw R(s),new Z}let r=te(o);if(r.kind==="error")throw r.error;return r.value})}#M(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=Ot(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#_(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#_(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#u?.(1,e,this.#e.atoms),this.#H(e,r),i!==void 0)for(let a of i)this.#H(e,a);let s=this.#B(r);if(i!==void 0)for(let a of i){let c=this.#B(a);s||=c}if(this.#L(r),i!==void 0)for(let a of i)this.#L(a);this.#se();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#V(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let y=this.#V(o,f,b);if(y!==void 0)if(a===void 0)a=y;else c=[y]}if(o.affected!==void 0)for(let[y,k]of o.affected){let z=this.#V(o,y,k);if(z===void 0)continue;if(a===void 0)a=z;else{if(c===void 0)c=[];c.push(z)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#u?.(2,a===void 0?0:1+(c?.length??0)),this.#ie(a,c)}catch(a){throw this.#w(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#W(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#H(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#B(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#V(e,t,n){let o=De(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#ee(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Ct(n,r))continue;let i=r.served.outcome,s=this.#W(e,r.scope,r.atom,n);if(nt(i,s))continue;Nt(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#W(e,t,n,o){let r=De(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=De(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#te(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#te(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ne(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#v(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#oe(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#ne(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#re(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#re(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#v(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(I(this.#e,t,()=>Oe(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#v(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#ie(e,t){if(e===void 0){this.#w();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0,this.#h=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],i=this.#r[o++];this.#E(r,i)}}finally{n=this.#h,this.#h=void 0,this.#s=!1,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#m=void 0,this.#p=this.#l===void 0?0:this.#b++}#w(){this.#p=0,this.#S=void 0,this.#m=void 0}reachSubscriptionTarget(e,t){let n=this.#p,o=this.#l?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#m===void 0)this.#m=[o];else this.#m.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#w(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#m;if(i!==void 0)for(let d of i)r(d);if(this.#w(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let y=d(),k=O(y);if(k.kind==="thenable")R(k);else if(k.kind==="inspection-error")f=!0,b=k.error}catch(y){f=!0,b=y;let k=O(y);if(k.kind==="thenable")R(k)}})}catch(y){f=!0,b=y}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new ve(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#U(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#E(e,t,n)}#E(e,t,n){if((this.#U(e,t)&(rt|Ee))!==0)return;this.#g(e,t,Ee);try{let r=e.getSelectorGraphVersion(),i=e.getCommittedSelectorDependencies(t);if(i!==void 0){for(let s of i)if(this.#e.selectors.has(s.node))this.#E(e,s.node)}if(e.isSelectorDirty(t)){let s=r===e.getSelectorGraphVersion();if(n!==void 0&&s)e.serve(t,n);else e.serve(t,new S)}this.#g(e,t,rt)}finally{this.#g(e,t,0,Ee)}}#U(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#f?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#a===void 0){this.#a=e,this.#c=t,this.#d=n&~o;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t)){this.#d=(this.#d|n)&~o;return}let r=this.#f;if(r===void 0)r=new Map,this.#f=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#h??=e}#q(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#X(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t,n){this.get=(o)=>e.get(t,o),this.sub=(o,r)=>e.sub(t,o,r),this.set=(o,r)=>e.set(t,o,r),this.update=(o,r)=>e.update(t,o,r),this.reset=(o)=>e.reset(t,o),this.txn=(o,r)=>e.txn(t,o,r),this.scope=function(o){return e.scope(t,arguments.length,o)},this.dispose=()=>e.dispose(t),t.installFacade(this),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return{...e.name===void 0?{}:{name:e.name},...e.equal===void 0?{}:{equal:e.equal}}},lt=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=I(t,l,()=>te(c));if(f.kind==="error")throw f.error;let b=fe("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=fe("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=fe("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.name===void 0?{}:{name:d.name},...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(E(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw Re(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,d)=>{C(t,"createStoreTree");let l=new dt(t,c,d);return new xe(l,l.rootScope,d)}})};var Vt=lt(),Qt=(e,t)=>Vt.createStoreTree(e,t);
2
+ export{X as a,Qe as b,ke as c,ve as d,W as e,U as f,q as g,ce as h,J as i,Z as j,ee as k,we as l,ge as m,Te as n,de as o,Kt as p,Vt as q,Qt as r};
@@ -1 +1 @@
1
- import{q as e}from"../chunk-wzf3zmr8.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
1
+ import{q as e}from"../chunk-6pxeaw0f.js";var t=e.adapter,a=t.assertStore,o=t.read,s=t.subscribe,n=t.readHydrationSnapshot;export{a as assertStore,o as read,n as readHydrationSnapshot,s as subscribe};
@@ -0,0 +1,2 @@
1
+ class x extends Error{seal(){Object.freeze(this)}}class se extends x{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class ye extends x{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class X extends x{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class P extends x{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Ae extends x{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ae extends x{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class be extends x{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Me=Object.freeze({kind:"not-thenable"}),ft=()=>{},ht=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ke extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class ve extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ce extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class Z extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ee extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class we extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ge extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Te extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class de extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var O=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},R=(e)=>{try{ht(e.then,e.target,[void 0,ft])}catch{}},te=(e)=>{let t=O(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return R(t),Object.freeze({kind:"error",error:new Z})},Oe=(e)=>{try{return te(e())}catch(t){let n=O(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return R(n),Object.freeze({kind:"error",error:new Z})}},ne=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},I=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},oe=(e,t,n)=>ne(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ne(e,Object.freeze({kind:"transaction",transaction:t}),n),le=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Re=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ue=(e,t,n)=>{if(!n)throw new ce;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ke;throw We(e,n).latchControlFault(r),r}}return"invalid"},E=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return I(e,r,()=>L(e,t,r))},re=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),fe=(e,t)=>Object.freeze(re({kind:e},t));var Ue=Object.freeze({kind:"not-thenable"}),St=()=>{},mt=Reflect.apply,qe=Symbol("selector dependency path root"),Ye=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},$e=(e)=>{try{mt(e.then,e.target,[void 0,St])}catch{}},pt=(e)=>Object.freeze(e),yt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=yt(o);return Object.freeze({selector:e,token:t,outcome:pt(n),dependencies:r,attemptedPrefix:n.kind==="value"?At:Object.freeze(r.map((i)=>i.node))})},At=Object.freeze([]),bt=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let d=n.getSelectorDependencyNodes(s);if(d===void 0)continue;for(let l of d){if(i.has(l))continue;i.set(l,s),r.push(l)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ge=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),new P(t);if(n.kind==="inspection-error")return n.error;return e},Ke=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),Object.freeze({kind:"error",error:new P(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},Qe=(e,t,n,o=bt)=>{let{node:r}=e,i=[],s=t.getSelectorRecord(r),a=s?.dependencies,c=a===void 0?new Set:void 0,d,l=0,f=t.getComparisonBaseline(r),b=!0,y=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let m of i)u.add(m.node);return c=u,u};n.enter(t,r,i);let k=t.getSelectorGraphVersion(),z=n.getSelectorGraphPublicationCount(t),G=k,K=z,Pe=k,Ie=z,me=(u,m,v,p)=>v-u===p-m,ze=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),v=me(G,K,u,m))=>{if(v){G=u,K=m;return}for(let p=0;p<i.length;p++){let F=i[p],N=o(F.node,r,t,n,0);if(!N)continue;if(c!==void 0)for(let A=i.length-1;A>=p;A--)c.delete(i[A].node);if(i.length=p,l++,n.getControlFault().kind==="fault")return;let M=new X(r,[r,...N]);n.latchCycle(t,r,M);return}G=u,K=m},pe=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Pe=u,Ie=m;let v=me(G,K,u,m);if(!v)n.revalidateAncestorPrefixes(t,r);ze(u,m,v)};n.setPrefixRevalidator(t,r,ze);let ut=(u)=>{if(!b)throw new be;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let v=n.getCycle(t,r);if(v!==void 0)throw v;let p=n.activeCyclePath(t,u);if(p){let h=new X(r,p);throw n.latchCycle(t,r,h),h}let F=i.length,N,D=!1;if(c===void 0){let h=a?.[F];if(h!==void 0&&Object.is(h.node,u))N=!1,D=!0;else N=y().has(u)}else N=c.has(u);if(!N&&!D&&a!==void 0&&a.length>0){let h=a[i.length];if(h!==void 0&&Object.is(h.node,u))D=!0;else{if(d===void 0){d=new Set;for(let B of a)d.add(B.node)}D=d.has(u)}}let M=l,A=t.serve(u,n);pe();let _=n.getCycle(t,r);if(_!==void 0)throw _;let Y=c!==void 0?c.has(u):l===M&&i.length===F?!1:y().has(u),j=Pe,H=Ie,V=Y||D&&j===k,ie=a===void 0&&me(k,z,j,H);if(!V&&!ie){let h=o(u,r,t,n,1);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Fe=new X(r,[r,...h]);throw n.latchCycle(t,r,Fe),Fe}}if(!Y){let h=s?.dependencies[i.length];c?.add(u),i.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(G=j,K=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(A.outcome.kind==="error")throw new ye(u,A.outcome.error);return A.outcome.value};try{let u,m,v=!1;try{u=e.get(ut)}catch(_){v=!0,m=_}finally{b=!1}if(v)m=Ge(m,"getter");let p=v?void 0:Ke(u,"getter");pe();let F=n.getControlFault();if(F.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:F.error},i);let N=n.getCycle(t,r);if(N!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:N},i);if(v)return g(r,t.createOutcomeToken(),{kind:"error",error:m instanceof P?m:new se(r,m)},i);if(p===void 0)throw Error("Selector result classification was not completed");let D=n.getControlFault();if(D.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:D.error},i);if(p.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:p.error instanceof P?p.error:new se(r,p.error)},i);let M=p.value,A;if(f){let _=e.equal??Object.is,Y,j,H=!1;try{Y=_(f.value,M)}catch(B){H=!0,j=Ge(B,"comparator")}let V=H?void 0:Ke(Y,"comparator");pe();let ie=n.getControlFault();if(ie.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:ie.error},i);let Q=n.getCycle(t,r);if(Q!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:Q},i);if(H)return g(r,t.createOutcomeToken(),{kind:"error",error:j instanceof P?j:new ae(r,j)},i);if(V===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:h.error},i);if(V.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:V.error instanceof P?V.error:new ae(r,V.error)},i);if(V.value!==!0&&V.value!==!1)return g(r,t.createOutcomeToken(),{kind:"error",error:new Ae},i);if(V.value===!0)M=f.value,A=f.current?f.token:void 0}return g(r,A??t.createOutcomeToken(),{kind:"value",value:M},i)}finally{n.leave(t,r)}};class S{#t=[];#n;#o=0;#i;#s=kt;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#r(e,t).cycleError}#r(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var kt=Object.freeze({kind:"none"});var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#i=new Map;#s;#r=1;#a=0;#c;constructor(e,t,n){this.#t=e,this.#s=t,this.#c=n}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#t=void 0}serve(e,t){let n=this.#d(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>this.#c(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#a++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#d().captureCommittedSelectorSuccess(e)??Xe,this.#i.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#d(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#s=new WeakMap;#r=new WeakSet;#a=0;#c;#d="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#l(),this.#n=this.#l()}get status(){return this.#d}get facade(){if(this.#c===void 0)throw Error("Store scope facade is not installed");return this.#c}installFacade(e){if(this.#c!==void 0)throw Error("Store scope facade is already installed");this.#c=e}markDisposing(){if(this.#d==="live")this.#d="disposing"}markDisposed(){this.#d="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#l()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#s.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#i=void 0,this.#s=new WeakMap,this.#r=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r,t),i=this.#o.get(r);if(i!==void 0&&!this.#r.has(r))return i.served;let s=oe(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#h(e,o?.dependencies??vt,t.dependencies))this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#h(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#s.get(o.node);if(r?.delete(e),r?.isEmpty())this.#s.delete(o.node)}for(let o of n){let r=this.#s.get(o.node);if(r===void 0)r=this.#l(),this.#s.set(o.node,r);r.add(e)}return!0}#l(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var vt=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#f;#h;#l;#b;#p;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#s!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#i===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#u(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#u();i.set(this.#n,o);let s=this.#u();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#y();return}let s=this.#u();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#u(),s=this.#u();if(s.set(r.atom,r),this.#i!==void 0)s.set(this.#i.atom,this.#i);i.set(this.#n,s);let a=this.#u();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#o=void 0,this.#i=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#i!==void 0)e(this.#n,this.#i);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#i;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#d!==void 0&&Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;if(this.#h!==void 0&&Object.is(this.#a,e)&&Object.is(this.#f,t))return this.#h;if(Object.is(this.#a,e))return this.#l?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#u(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#l;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#u();s.set(this.#a,r);let a=this.#u();a.set(t,n),s.set(e,a),this.#b=s,this.#l=void 0,this.#a=void 0}return}let i=this.#d;if(i===void 0){this.#a=e,this.#c=t,this.#d=n;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t))return;if(Object.is(this.#a,e)){let s=this.#h;if(s===void 0){this.#f=t,this.#h=n;return}if(Object.is(this.#f,t))return;let a=this.#u();a.set(this.#c,i),a.set(this.#f,s),a.set(t,n),this.#l=a}else{let s=this.#u(),a=this.#u();if(a.set(this.#c,i),this.#f!==void 0&&this.#h!==void 0)a.set(this.#f,this.#h);s.set(this.#a,a);let c=this.#u();c.set(t,n),s.set(e,c),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#p,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#p,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#p=e,this.#S=t;return}if(Object.is(this.#p,e)){this.#S=t;return}let o=this.#u();o.set(this.#p,this.#S),o.set(e,t),this.#m=o,this.#p=void 0,this.#S=void 0}forEachFallback(e){if(this.#p!==void 0&&this.#S!==void 0)e(this.#p,this.#S);if(this.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#l?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0,this.#l=void 0,this.#b=void 0,this.#p=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#u(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ne=(e,t,n)=>new Ze(e,t,n),Ve=(e)=>{let t=O(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw R(t),new J},et=(e)=>{let t=O(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw R(t),new J};var wt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},at=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31}),gt=32,ct=new WeakMap,Kt=()=>{let e=new Uint32Array(gt),t=Object.freeze({read(n){return e[at[n]]??0}});return ct.set(t,e),t},T=(e)=>Object.freeze({kind:"value",value:e}),Tt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):Tt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,Ee=2,rt=4,Ot=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Rt=(e)=>(e.onAllocation?.(),new Set),De=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Ct=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Rt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Nt=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class dt{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#f;#h;#l;#b=1;#p=0;#S;#m;#e;#y;#u;evaluate;constructor(e,t,n){this.#e=e,this.#y=t===void 0?void 0:ct.get(t),this.#u=n,this.evaluate=n?.evaluate??Qe,this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[at[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=E(this.#e,o,n),i=Re(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":E(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#l;if(a===void 0){if(a=new Map,this.#l=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return wt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#l,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#l=void 0}set(e,t,n){this.#O(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#O(e,t,"StoreTree.update","update",n)}reset(e,t){this.#O(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)E(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#Q(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Ne(this,o,e),i;try{i=Be(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new S;le(this.#e,s,()=>Ve(i)),this.#M(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new S,o=t,r=E(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#T(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#K(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=E(this.#e,o,r);if(ue(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#G(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#I(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")E(this.#e,n,i);ue(this.#e,e.transaction,e.active),this.#A(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ne(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return le(this.#e,f,()=>et(l))}let d=new S;return le(this.#e,d,()=>Ve(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#D(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#j(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n,this.#u);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#Y(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ge;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new Te;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ce;throw new de}throw new de}#A(e){if(e.status!=="live")throw new we}#$(e,t,n,o){let r=E(this.#e,t,n);C(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new S;this.#$(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#M(a)}finally{a.release()}}#Q(e){let t=this.#l,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#l=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=E(this.#e,n,o);ue(this.#e,e.transaction,e.active),this.#A(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=I(this.#e,r,()=>te(o));if(i.kind==="error")throw i.error;let s=this.#C(e,t,n,r);this.#q(e,t,n,i.value,s,r)}#I(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#C(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#Z(o,a.value,r);this.#q(e,t,n,c,s,r)}#z(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#N(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0})}#N(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(I(this.#e,n,()=>Oe(i)));return e.setFallback(t,a),a}#X(e,t,n,o){let r=this.#v(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#J(r,t,n,o)?t:n}#J(e,t,n,o){return I(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=O(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw R(a),new ee}let i=O(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw R(i),new ee;if(r!==!0&&r!==!1)throw new ee;return r})}#Z(e,t,n){return I(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=O(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw R(s),new Z}let r=te(o);if(r.kind==="error")throw r.error;return r.value})}#M(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=Ot(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#_(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#_(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#u?.(1,e,this.#e.atoms),this.#H(e,r),i!==void 0)for(let a of i)this.#H(e,a);let s=this.#B(r);if(i!==void 0)for(let a of i){let c=this.#B(a);s||=c}if(this.#L(r),i!==void 0)for(let a of i)this.#L(a);this.#se();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#V(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let y=this.#V(o,f,b);if(y!==void 0)if(a===void 0)a=y;else c=[y]}if(o.affected!==void 0)for(let[y,k]of o.affected){let z=this.#V(o,y,k);if(z===void 0)continue;if(a===void 0)a=z;else{if(c===void 0)c=[];c.push(z)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#u?.(2,a===void 0?0:1+(c?.length??0)),this.#ie(a,c)}catch(a){throw this.#w(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#W(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#H(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#B(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#V(e,t,n){let o=De(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#ee(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Ct(n,r))continue;let i=r.served.outcome,s=this.#W(e,r.scope,r.atom,n);if(nt(i,s))continue;Nt(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#W(e,t,n,o){let r=De(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=De(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#te(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#te(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ne(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#v(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#oe(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#ne(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#re(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#re(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#v(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(I(this.#e,t,()=>Oe(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#v(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#ie(e,t){if(e===void 0){this.#w();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0,this.#h=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],i=this.#r[o++];this.#E(r,i)}}finally{n=this.#h,this.#h=void 0,this.#s=!1,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#m=void 0,this.#p=this.#l===void 0?0:this.#b++}#w(){this.#p=0,this.#S=void 0,this.#m=void 0}reachSubscriptionTarget(e,t){let n=this.#p,o=this.#l?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#m===void 0)this.#m=[o];else this.#m.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#w(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#m;if(i!==void 0)for(let d of i)r(d);if(this.#w(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let y=d(),k=O(y);if(k.kind==="thenable")R(k);else if(k.kind==="inspection-error")f=!0,b=k.error}catch(y){f=!0,b=y;let k=O(y);if(k.kind==="thenable")R(k)}})}catch(y){f=!0,b=y}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new ve(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#U(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#E(e,t,n)}#E(e,t,n){if((this.#U(e,t)&(rt|Ee))!==0)return;this.#g(e,t,Ee);try{let r=e.getSelectorGraphVersion(),i=e.getCommittedSelectorDependencies(t);if(i!==void 0){for(let s of i)if(this.#e.selectors.has(s.node))this.#E(e,s.node)}if(e.isSelectorDirty(t)){let s=r===e.getSelectorGraphVersion();if(n!==void 0&&s)e.serve(t,n);else e.serve(t,new S)}this.#g(e,t,rt)}finally{this.#g(e,t,0,Ee)}}#U(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#f?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#a===void 0){this.#a=e,this.#c=t,this.#d=n&~o;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t)){this.#d=(this.#d|n)&~o;return}let r=this.#f;if(r===void 0)r=new Map,this.#f=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#h??=e}#q(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#X(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t,n){this.get=(o)=>e.get(t,o),this.sub=(o,r)=>e.sub(t,o,r),this.set=(o,r)=>e.set(t,o,r),this.update=(o,r)=>e.update(t,o,r),this.reset=(o)=>e.reset(t,o),this.txn=(o,r)=>e.txn(t,o,r),this.scope=function(o){return e.scope(t,arguments.length,o)},this.dispose=()=>e.dispose(t),t.installFacade(this),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return{...e.name===void 0?{}:{name:e.name},...e.equal===void 0?{}:{equal:e.equal}}},lt=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=I(t,l,()=>te(c));if(f.kind==="error")throw f.error;let b=fe("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=fe("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=fe("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.name===void 0?{}:{name:d.name},...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(E(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw Re(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,d)=>{C(t,"createStoreTree");let l=new dt(t,c,d);return new xe(l,l.rootScope,d)}})};var Vt=lt(),Qt=(e,t)=>Vt.createStoreTree(e,t);
2
+ export{X as a,Qe as b,ke as c,ve as d,W as e,U as f,q as g,ce as h,J as i,Z as j,ee as k,we as l,ge as m,Te as n,de as o,Kt as p,Vt as q,Qt as r};
@@ -1 +1 @@
1
- import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-wzf3zmr8.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=l,g=y,D=u,O=s,M=S,N=a,q=E,P=p,z=o,w=v,U=m,G=n,j=i,L=c;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
1
+ import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-6pxeaw0f.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=l,g=y,D=u,O=s,M=S,N=a,q=E,P=p,z=o,w=v,U=m,G=n,j=i,L=c;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
@@ -1 +1 @@
1
- import{b as F,d as H,p as B,r as K}from"./chunk-wzf3zmr8.js";var X=2048,Q=1e5,V=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},J=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},_=(e)=>e.length<=V?e:e.slice(0,V),C=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:C(),newEdgeProof:C()},scratch:{prefixRevalidation:C(),newEdgeProof:C()},hydration:{prefixRevalidation:C(),newEdgeProof:C()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],c=Math.min(e.length,D);for(let d=0;d<c;d++)s.push(O(e[d],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let c=Reflect.get(e,s);if(c===void 0)continue;r[s]=O(c,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},P=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...P(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return q;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:q}catch(t){return{kind:"inspection-error",error:t}}},q=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#l;#p="";#s=1;#b=1;#g=1;#S=1;#v=1;#k=1;#T=1;#R=1;#C=1;#n=[];#u=new WeakMap;#E=new WeakMap;#m=new WeakMap;#d=0;#a=0;#t;#f;#x;constructor(e,t){this.#x=t,this.#r=J(e.capacity?.summaries,X,"Inspection summary",!1),this.#l=J(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#l),this.#f=this.#h(),this.#w()}get recordingId(){return this.#p}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#u.get(e);if(o===void 0)o=this.#C++,this.#u.set(e,o);let r=this.#E.get(e);if(r===void 0&&n!==void 0)r=_(n),this.#E.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#T++;return this.#m.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#P(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#O(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:_(e.name),seqStart:this.#s++,startUs:this.#I(),fields:P(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#D(n);let o=this.#s++,r=Math.max(0,this.#I()-n.startUs),i=se(n.fields,t.fields),s=this.#V(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#d++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...P(e.fields),type:e.type,sequence:t,timeUs:this.#I(),...this.#O(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#D(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,c,d,g){let T=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:T,host:e,hostRef:t,start:this.#y(n),target:this.#y(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-d,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:g}}),a=[n],I=new Map([[n,z]]),p=0,u=0,l=1,R=0,S=0,v=0,b;while(a.length>0){let f=a.pop();if(p++,Object.is(f,o)){let m=[],k=f;while(k!==z)m.push(k),k=I.get(k);m.reverse(),b=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){R++,u+=y.length;for(let m of y){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){v++;continue}S++,u+=m.length;for(let k of m){if(I.has(k))continue;I.set(k,f),a.push(k)}if(a.length>l)l=a.length;continue}let x=r.getSelectorRecord(f);if(!x){v++;continue}S++,u+=x.dependencies.length;for(let m of x.dependencies){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:b===void 0?0:1,site:T,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:R,recordExpansions:S,terminalPrunes:v,found:b!==void 0,...b===void 0?{}:{path:b.map((f)=>this.#y(f))}}}),b}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#j("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#p,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#d===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#d,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#j("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#p=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#l),this.#s=1,this.#b=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#R=1,this.#C=1,this.#n=[],this.#u=new WeakMap,this.#m=new WeakMap,this.#d=0,this.#a=0,this.#t=void 0,this.#f=this.#h()}#P(e){if(e==="span")return this.#b++;if(e==="operation")return this.#g++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#v++;if(e==="cycle-search")return this.#k++;return this.#R++}#O(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#y(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#V(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#j(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(t)=>this.#x.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#D(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#h(){return globalThis.performance?.now()??Date.now()}#I(){return Math.max(0,Math.round((this.#h()-this.#f)*1000))}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,c)=>{if(e.hasActiveStoreOperation())return c();e.recordStoreEvent(0,r,i,i.name,s);try{let d=c();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof H?1:0),d}},n=(r,i,s)=>{if(r===0){let c=i,d=s,g=c,T=c.set,E=c.update,a=c.reset,I=c.txn;g.set=(p,u)=>t(0,d,void 0,()=>T(p,u)),g.update=(p,u)=>t(1,d,void 0,()=>E(p,u)),g.reset=(p)=>t(2,d,void 0,()=>a(p)),g.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return I(p,u);return t(3,d,u,()=>I(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let c=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=i.name,g=e.reference(i,c==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),T=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),a=i.getSelectorRecord(r.node)?.dependencies,I=a?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:c,hostRef:g,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:T,previousDependencyCount:I}});e.addWork({selectorEvaluations:1});let u=(l,R,S,v,b)=>e.findDependencyPath(c,g,l,R,S,v,b,T,E,a===void 0);try{let l=F(r,i,s,u),R=a===void 0||a.length!==l.dependencies.length||a.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),S=new Set(a?.map((y)=>y.node)),v=new Set(l.dependencies.map((y)=>y.node)),b=0,f=0;for(let y of v)if(!S.has(y))b++;for(let y of S)if(!v.has(y))f++;return e.addWork(R?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:R,proposedEdgesAdded:b,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
1
+ import{b as F,d as H,p as B,r as K}from"./chunk-6pxeaw0f.js";var X=2048,Q=1e5,P=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},q=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},J=(e)=>e.length<=P?e:e.slice(0,P),R=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:R(),newEdgeProof:R()},scratch:{prefixRevalidation:R(),newEdgeProof:R()},hydration:{prefixRevalidation:R(),newEdgeProof:R()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,D);for(let c=0;c<a;c++)s.push(O(e[c],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=O(a,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},V=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...V(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return _;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:_}catch(t){return{kind:"inspection-error",error:t}}},_=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#T=1;#C=1;#R=1;#E=1;#n=[];#m=new WeakMap;#x=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#y;#O;constructor(e,t){this.#O=t,this.#r=q(e.capacity?.summaries,X,"Inspection summary",!1),this.#u=q(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#u),this.#y=this.#p(),this.#j()}get recordingId(){return this.#d}registerStore(e,t){this.#w.set(e,t)}capture(e,t){let n=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=n===void 0?void 0:this.#w.get(n);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(t!==void 0){let s=typeof t==="object"&&t!==null||typeof t==="function"?t:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let c=a.atoms.get(s),I=a.selectors.get(s);if(c===void 0&&I===void 0)throw TypeError("Inspection capture requires a valid State");let S=c?.name??I?.name;r=this.reference(s,c===void 0?"selector":"atom",typeof S==="string"?S:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#P(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#h()})}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#m.get(e);if(o===void 0)o=this.#E++,this.#m.set(e,o);let r=this.#x.get(e);if(r===void 0&&n!==void 0)r=J(n),this.#x.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#f.get(e);if(t!==void 0)return t;let n=this.#C++;return this.#f.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#A(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#h(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:J(e.name),seqStart:this.#s++,startUs:this.#b(),fields:V(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#D():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#V(n);let o=this.#s++,r=Math.max(0,this.#b()-n.startUs),i=se(n.fields,t.fields),s=this.#z(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#l++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...V(e.fields),type:e.type,sequence:t,timeUs:this.#b(),...this.#h(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#V(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,a,c,I){let S=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:t,start:this.#I(n),target:this.#I(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-a,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-c,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:I}}),d=[n],b=new Map([[n,z]]),p=0,u=0,l=1,C=0,v=0,k=0,g;while(d.length>0){let f=d.pop();if(p++,Object.is(f,o)){let m=[],T=f;while(T!==z)m.push(T),T=b.get(T);m.reverse(),g=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){C++,u+=y.length;for(let m of y){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){k++;continue}v++,u+=m.length;for(let T of m){if(b.has(T))continue;b.set(T,f),d.push(T)}if(d.length>l)l=d.length;continue}let x=r.getSelectorRecord(f);if(!x){k++;continue}v++,u+=x.dependencies.length;for(let m of x.dependencies){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:g===void 0?0:1,site:S,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:C,recordExpansions:v,terminalPrunes:k,found:g!==void 0,...g===void 0?{}:{path:g.map((f)=>this.#I(f))}}}),g}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#N("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#N("reset"),this.#j()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(t,n)=>e.capture(t,n),span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#j(){this.#d=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#C=1,this.#R=1,this.#E=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#A(e){if(e==="span")return this.#g++;if(e==="operation")return this.#S++;if(e==="commit")return this.#v++;if(e==="selector-evaluation")return this.#k++;if(e==="cycle-search")return this.#T++;return this.#R++}#h(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#I(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#z(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#N(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#D(){let e=(t)=>this.#O.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#V(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#D();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#P(e){return Math.max(0,Math.round((e-this.#y)*1000))}#b(){return this.#P(this.#p())}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let c=a();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof H?1:0),c}},n=(r,i,s)=>{if(r===0){let a=i,c=s;e.registerStore(a,c);let I=a,S=a.set,E=a.update,d=a.reset,b=a.txn;I.set=(p,u)=>t(0,c,void 0,()=>S(p,u)),I.update=(p,u)=>t(1,c,void 0,()=>E(p,u)),I.reset=(p)=>t(2,c,void 0,()=>d(p)),I.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return b(p,u);return t(3,c,u,()=>b(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,I=e.reference(i,a==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),S=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),d=i.getSelectorRecord(r.node)?.dependencies,b=d?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:I,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:S,previousDependencyCount:b}});e.addWork({selectorEvaluations:1});let u=(l,C,v,k,g)=>e.findDependencyPath(a,I,l,C,v,k,g,S,E,d===void 0);try{let l=F(r,i,s,u),C=d===void 0||d.length!==l.dependencies.length||d.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),v=new Set(d?.map((y)=>y.node)),k=new Set(l.dependencies.map((y)=>y.node)),g=0,f=0;for(let y of k)if(!v.has(y))g++;for(let y of v)if(!k.has(y))f++;return e.addWork(C?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:C,proposedEdgesAdded:g,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-wzf3zmr8.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=l,g=y,D=u,O=s,M=S,N=a,q=E,P=p,z=o,w=v,U=m,G=n,j=i,L=c;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
1
+ import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-6pxeaw0f.js";var f=(r,e={})=>t.atomLazy(r,e),d=(r,e={})=>t.atom(r,e);Object.defineProperty(d,"lazy",{configurable:!1,enumerable:!0,value:f,writable:!1});var T=Object.freeze(d),x=(r,e={})=>t.selector(r,e);function V(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return t.createStoreTree()}var R=T,h=x,F=V,k=l,g=y,D=u,O=s,M=S,N=a,q=E,P=p,z=o,w=v,U=m,G=n,j=i,L=c;export{k as CallbackCapabilityError,g as InvalidAtomComparatorResultError,D as InvalidSynchronousAtomValueError,O as InvalidTransactionCallbackResultError,M as InvalidTransactionTargetError,N as RuntimeMismatchError,q as ScopeNotFoundError,P as SelectorCapabilityError,z as SelectorCircularDependencyError,w as StoreDisposedError,U as StoreTreeMismatchError,G as SubscriberNotificationError,j as TransactionClosedError,L as TransactionPhaseError,R as atom,h as selector,F as store};
package/dist/inspect.js CHANGED
@@ -1 +1 @@
1
- import{b as F,d as H,p as B,r as K}from"./chunk-wzf3zmr8.js";var X=2048,Q=1e5,V=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},J=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},_=(e)=>e.length<=V?e:e.slice(0,V),C=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:C(),newEdgeProof:C()},scratch:{prefixRevalidation:C(),newEdgeProof:C()},hydration:{prefixRevalidation:C(),newEdgeProof:C()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],c=Math.min(e.length,D);for(let d=0;d<c;d++)s.push(O(e[d],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let c=Reflect.get(e,s);if(c===void 0)continue;r[s]=O(c,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},P=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...P(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return q;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:q}catch(t){return{kind:"inspection-error",error:t}}},q=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#l;#p="";#s=1;#b=1;#g=1;#S=1;#v=1;#k=1;#T=1;#R=1;#C=1;#n=[];#u=new WeakMap;#E=new WeakMap;#m=new WeakMap;#d=0;#a=0;#t;#f;#x;constructor(e,t){this.#x=t,this.#r=J(e.capacity?.summaries,X,"Inspection summary",!1),this.#l=J(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#l),this.#f=this.#h(),this.#w()}get recordingId(){return this.#p}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#u.get(e);if(o===void 0)o=this.#C++,this.#u.set(e,o);let r=this.#E.get(e);if(r===void 0&&n!==void 0)r=_(n),this.#E.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#T++;return this.#m.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#P(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#O(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:_(e.name),seqStart:this.#s++,startUs:this.#I(),fields:P(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#D(n);let o=this.#s++,r=Math.max(0,this.#I()-n.startUs),i=se(n.fields,t.fields),s=this.#V(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#d++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...P(e.fields),type:e.type,sequence:t,timeUs:this.#I(),...this.#O(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#D(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,c,d,g){let T=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:T,host:e,hostRef:t,start:this.#y(n),target:this.#y(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-d,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:g}}),a=[n],I=new Map([[n,z]]),p=0,u=0,l=1,R=0,S=0,v=0,b;while(a.length>0){let f=a.pop();if(p++,Object.is(f,o)){let m=[],k=f;while(k!==z)m.push(k),k=I.get(k);m.reverse(),b=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){R++,u+=y.length;for(let m of y){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){v++;continue}S++,u+=m.length;for(let k of m){if(I.has(k))continue;I.set(k,f),a.push(k)}if(a.length>l)l=a.length;continue}let x=r.getSelectorRecord(f);if(!x){v++;continue}S++,u+=x.dependencies.length;for(let m of x.dependencies){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:b===void 0?0:1,site:T,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:R,recordExpansions:S,terminalPrunes:v,found:b!==void 0,...b===void 0?{}:{path:b.map((f)=>this.#y(f))}}}),b}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#j("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#p,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#d===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#d,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#j("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#p=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#l),this.#s=1,this.#b=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#R=1,this.#C=1,this.#n=[],this.#u=new WeakMap,this.#m=new WeakMap,this.#d=0,this.#a=0,this.#t=void 0,this.#f=this.#h()}#P(e){if(e==="span")return this.#b++;if(e==="operation")return this.#g++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#v++;if(e==="cycle-search")return this.#k++;return this.#R++}#O(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#y(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#V(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#j(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(t)=>this.#x.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#D(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#h(){return globalThis.performance?.now()??Date.now()}#I(){return Math.max(0,Math.round((this.#h()-this.#f)*1000))}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,c)=>{if(e.hasActiveStoreOperation())return c();e.recordStoreEvent(0,r,i,i.name,s);try{let d=c();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof H?1:0),d}},n=(r,i,s)=>{if(r===0){let c=i,d=s,g=c,T=c.set,E=c.update,a=c.reset,I=c.txn;g.set=(p,u)=>t(0,d,void 0,()=>T(p,u)),g.update=(p,u)=>t(1,d,void 0,()=>E(p,u)),g.reset=(p)=>t(2,d,void 0,()=>a(p)),g.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return I(p,u);return t(3,d,u,()=>I(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let c=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=i.name,g=e.reference(i,c==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),T=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),a=i.getSelectorRecord(r.node)?.dependencies,I=a?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:c,hostRef:g,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:T,previousDependencyCount:I}});e.addWork({selectorEvaluations:1});let u=(l,R,S,v,b)=>e.findDependencyPath(c,g,l,R,S,v,b,T,E,a===void 0);try{let l=F(r,i,s,u),R=a===void 0||a.length!==l.dependencies.length||a.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),S=new Set(a?.map((y)=>y.node)),v=new Set(l.dependencies.map((y)=>y.node)),b=0,f=0;for(let y of v)if(!S.has(y))b++;for(let y of S)if(!v.has(y))f++;return e.addWork(R?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:R,proposedEdgesAdded:b,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
1
+ import{b as F,d as H,p as B,r as K}from"./chunk-6pxeaw0f.js";var X=2048,Q=1e5,P=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},q=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},J=(e)=>e.length<=P?e:e.slice(0,P),R=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:R(),newEdgeProof:R()},scratch:{prefixRevalidation:R(),newEdgeProof:R()},hydration:{prefixRevalidation:R(),newEdgeProof:R()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,D);for(let c=0;c<a;c++)s.push(O(e[c],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=O(a,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},V=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...V(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return _;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:_}catch(t){return{kind:"inspection-error",error:t}}},_=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#T=1;#C=1;#R=1;#E=1;#n=[];#m=new WeakMap;#x=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#y;#O;constructor(e,t){this.#O=t,this.#r=q(e.capacity?.summaries,X,"Inspection summary",!1),this.#u=q(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#u),this.#y=this.#p(),this.#j()}get recordingId(){return this.#d}registerStore(e,t){this.#w.set(e,t)}capture(e,t){let n=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=n===void 0?void 0:this.#w.get(n);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(t!==void 0){let s=typeof t==="object"&&t!==null||typeof t==="function"?t:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let c=a.atoms.get(s),I=a.selectors.get(s);if(c===void 0&&I===void 0)throw TypeError("Inspection capture requires a valid State");let S=c?.name??I?.name;r=this.reference(s,c===void 0?"selector":"atom",typeof S==="string"?S:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#P(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#h()})}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#m.get(e);if(o===void 0)o=this.#E++,this.#m.set(e,o);let r=this.#x.get(e);if(r===void 0&&n!==void 0)r=J(n),this.#x.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#f.get(e);if(t!==void 0)return t;let n=this.#C++;return this.#f.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#A(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#h(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:J(e.name),seqStart:this.#s++,startUs:this.#b(),fields:V(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#D():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#V(n);let o=this.#s++,r=Math.max(0,this.#b()-n.startUs),i=se(n.fields,t.fields),s=this.#z(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#l++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...V(e.fields),type:e.type,sequence:t,timeUs:this.#b(),...this.#h(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#V(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,a,c,I){let S=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:t,start:this.#I(n),target:this.#I(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-a,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-c,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:I}}),d=[n],b=new Map([[n,z]]),p=0,u=0,l=1,C=0,v=0,k=0,g;while(d.length>0){let f=d.pop();if(p++,Object.is(f,o)){let m=[],T=f;while(T!==z)m.push(T),T=b.get(T);m.reverse(),g=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){C++,u+=y.length;for(let m of y){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){k++;continue}v++,u+=m.length;for(let T of m){if(b.has(T))continue;b.set(T,f),d.push(T)}if(d.length>l)l=d.length;continue}let x=r.getSelectorRecord(f);if(!x){k++;continue}v++,u+=x.dependencies.length;for(let m of x.dependencies){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:g===void 0?0:1,site:S,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:C,recordExpansions:v,terminalPrunes:k,found:g!==void 0,...g===void 0?{}:{path:g.map((f)=>this.#I(f))}}}),g}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#N("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#N("reset"),this.#j()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(t,n)=>e.capture(t,n),span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#j(){this.#d=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#C=1,this.#R=1,this.#E=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#A(e){if(e==="span")return this.#g++;if(e==="operation")return this.#S++;if(e==="commit")return this.#v++;if(e==="selector-evaluation")return this.#k++;if(e==="cycle-search")return this.#T++;return this.#R++}#h(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#I(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#z(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#N(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#D(){let e=(t)=>this.#O.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#V(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#D();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#P(e){return Math.max(0,Math.round((e-this.#y)*1000))}#b(){return this.#P(this.#p())}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let c=a();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof H?1:0),c}},n=(r,i,s)=>{if(r===0){let a=i,c=s;e.registerStore(a,c);let I=a,S=a.set,E=a.update,d=a.reset,b=a.txn;I.set=(p,u)=>t(0,c,void 0,()=>S(p,u)),I.update=(p,u)=>t(1,c,void 0,()=>E(p,u)),I.reset=(p)=>t(2,c,void 0,()=>d(p)),I.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return b(p,u);return t(3,c,u,()=>b(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,I=e.reference(i,a==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),S=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),d=i.getSelectorRecord(r.node)?.dependencies,b=d?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:I,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:S,previousDependencyCount:b}});e.addWork({selectorEvaluations:1});let u=(l,C,v,k,g)=>e.findDependencyPath(a,I,l,C,v,k,g,S,E,d===void 0);try{let l=F(r,i,s,u),C=d===void 0||d.length!==l.dependencies.length||d.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),v=new Set(d?.map((y)=>y.node)),k=new Set(l.dependencies.map((y)=>y.node)),g=0,f=0;for(let y of k)if(!v.has(y))g++;for(let y of v)if(!k.has(y))f++;return e.addWork(C?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:C,proposedEdgesAdded:g,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
@@ -1,5 +1,5 @@
1
1
  import type { Store } from "./v1.js";
2
- import type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StoreInspector } from "./v1-internal/inspection.js";
2
+ import type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector } from "./v1-internal/inspection.js";
3
3
  export interface InspectableStoreResult {
4
4
  readonly store: Store;
5
5
  readonly inspect: StoreInspector;
@@ -9,4 +9,4 @@ export interface InspectableStoreResult {
9
9
  * State values, callbacks, and Store internals never enter the recording.
10
10
  */
11
11
  export declare const createInspectableStore: (options?: InspectableStoreOptions) => InspectableStoreResult;
12
- export type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StoreInspector, };
12
+ export type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector, };
@@ -23,7 +23,7 @@ export interface StoreScopeCoordinator {
23
23
  createOutcomeToken(): OutcomeToken;
24
24
  serveScopeAtom(scope: StoreScopeNode, atom: AnyAtom, session: SelectorEvaluationSession<AnyState>): ServedSelectorOutcome<OutcomeToken>;
25
25
  enqueueSelector(scope: StoreScopeNode, selector: AnySelector): boolean;
26
- prepareSelectorRead(scope: StoreScopeNode, selector: AnySelector): void;
26
+ prepareSelectorRead(scope: StoreScopeNode, selector: AnySelector, session: SelectorEvaluationSession<AnyState>): void;
27
27
  reachSubscriptionTarget(scope: StoreScopeNode, state: AnyState): void;
28
28
  latchPropagationControlFault(error: unknown): void;
29
29
  recordCounter(counter: StoreTreeCounter, amount?: number): void;
@@ -1,4 +1,5 @@
1
1
  import { type InternalStoreTreeInstrumentation, type InternalStoreTreeTrace } from "./committed-store-tree/committed-store-tree.js";
2
+ import type { CommittedStoreTree, State } from "./committed-store-tree/types.js";
2
3
  import type { SelectorCycleSearchSite, SelectorEvaluationHost, SelectorEvaluationSession } from "./selector-evaluator/types.js";
3
4
  type StoreRecorderEvent = readonly [
4
5
  event: 0,
@@ -211,9 +212,28 @@ export interface InspectableStoreOptions {
211
212
  details?: number;
212
213
  }>;
213
214
  }
215
+ /** A point-in-time, value-free correlation token for companion adapters. */
216
+ export interface InspectionCapture {
217
+ readonly recordingId: string;
218
+ readonly timeUs: number;
219
+ readonly monotonicTimeMs: number;
220
+ readonly store: InspectionReference;
221
+ readonly state?: InspectionReference;
222
+ readonly spanId?: number;
223
+ readonly operationId?: number;
224
+ readonly commitId?: number;
225
+ readonly sessionId?: number;
226
+ readonly evaluationId?: number;
227
+ readonly searchId?: number;
228
+ }
229
+ export interface StateInspectionCapture extends InspectionCapture {
230
+ readonly state: InspectionReference;
231
+ }
214
232
  type SynchronousInspectionResult<Result> = Result extends PromiseLike<unknown> ? never : Result;
215
233
  export interface StoreInspector {
216
234
  readonly recordingId: string;
235
+ capture(store: CommittedStoreTree): InspectionCapture;
236
+ capture<Value>(store: CommittedStoreTree, state: State<Value>): StateInspectionCapture;
217
237
  span<Result>(name: string, callback: () => SynchronousInspectionResult<Result>): Result;
218
238
  export(): InspectionExport;
219
239
  reset(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valdres",
3
3
  "description": "Fast atom-based state management for JavaScript. Inspired by Recoil and Jotai.",
4
- "version": "1.0.0-beta.26",
4
+ "version": "1.0.0-beta.28",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Eigil Sagafos"
@@ -1,2 +0,0 @@
1
- class x extends Error{seal(){Object.freeze(this)}}class se extends x{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class ye extends x{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class X extends x{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class P extends x{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Ae extends x{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ae extends x{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class be extends x{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Me=Object.freeze({kind:"not-thenable"}),ft=()=>{},ht=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ke extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class ve extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ce extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class Z extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ee extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class we extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ge extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Te extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class de extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var O=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},R=(e)=>{try{ht(e.then,e.target,[void 0,ft])}catch{}},te=(e)=>{let t=O(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return R(t),Object.freeze({kind:"error",error:new Z})},Oe=(e)=>{try{return te(e())}catch(t){let n=O(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return R(n),Object.freeze({kind:"error",error:new Z})}},ne=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},I=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},oe=(e,t,n)=>ne(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ne(e,Object.freeze({kind:"transaction",transaction:t}),n),le=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Re=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ue=(e,t,n)=>{if(!n)throw new ce;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ke;throw We(e,n).latchControlFault(r),r}}return"invalid"},E=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return I(e,r,()=>L(e,t,r))},re=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),fe=(e,t)=>Object.freeze(re({kind:e},t));var Ue=Object.freeze({kind:"not-thenable"}),St=()=>{},mt=Reflect.apply,qe=Symbol("selector dependency path root"),Ye=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},$e=(e)=>{try{mt(e.then,e.target,[void 0,St])}catch{}},pt=(e)=>Object.freeze(e),yt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=yt(o);return Object.freeze({selector:e,token:t,outcome:pt(n),dependencies:r,attemptedPrefix:n.kind==="value"?At:Object.freeze(r.map((i)=>i.node))})},At=Object.freeze([]),bt=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let d=n.getSelectorDependencyNodes(s);if(d===void 0)continue;for(let l of d){if(i.has(l))continue;i.set(l,s),r.push(l)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ge=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),new P(t);if(n.kind==="inspection-error")return n.error;return e},Ke=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),Object.freeze({kind:"error",error:new P(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},Qe=(e,t,n,o=bt)=>{let{node:r}=e,i=[],s=t.getSelectorRecord(r),a=s?.dependencies,c=a===void 0?new Set:void 0,d,l=0,f=t.getComparisonBaseline(r),b=!0,y=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let m of i)u.add(m.node);return c=u,u};n.enter(t,r,i);let k=t.getSelectorGraphVersion(),z=n.getSelectorGraphPublicationCount(t),G=k,K=z,Pe=k,Ie=z,me=(u,m,v,p)=>v-u===p-m,ze=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),v=me(G,K,u,m))=>{if(v){G=u,K=m;return}for(let p=0;p<i.length;p++){let F=i[p],N=o(F.node,r,t,n,0);if(!N)continue;if(c!==void 0)for(let A=i.length-1;A>=p;A--)c.delete(i[A].node);if(i.length=p,l++,n.getControlFault().kind==="fault")return;let M=new X(r,[r,...N]);n.latchCycle(t,r,M);return}G=u,K=m},pe=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Pe=u,Ie=m;let v=me(G,K,u,m);if(!v)n.revalidateAncestorPrefixes(t,r);ze(u,m,v)};n.setPrefixRevalidator(t,r,ze);let ut=(u)=>{if(!b)throw new be;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let v=n.getCycle(t,r);if(v!==void 0)throw v;let p=n.activeCyclePath(t,u);if(p){let h=new X(r,p);throw n.latchCycle(t,r,h),h}let F=i.length,N,D=!1;if(c===void 0){let h=a?.[F];if(h!==void 0&&Object.is(h.node,u))N=!1,D=!0;else N=y().has(u)}else N=c.has(u);if(!N&&!D&&a!==void 0&&a.length>0){let h=a[i.length];if(h!==void 0&&Object.is(h.node,u))D=!0;else{if(d===void 0){d=new Set;for(let B of a)d.add(B.node)}D=d.has(u)}}let M=l,A=t.serve(u,n);pe();let _=n.getCycle(t,r);if(_!==void 0)throw _;let Y=c!==void 0?c.has(u):l===M&&i.length===F?!1:y().has(u),j=Pe,H=Ie,V=Y||D&&j===k,ie=a===void 0&&me(k,z,j,H);if(!V&&!ie){let h=o(u,r,t,n,1);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Fe=new X(r,[r,...h]);throw n.latchCycle(t,r,Fe),Fe}}if(!Y){let h=s?.dependencies[i.length];c?.add(u),i.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(G=j,K=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(A.outcome.kind==="error")throw new ye(u,A.outcome.error);return A.outcome.value};try{let u,m,v=!1;try{u=e.get(ut)}catch(_){v=!0,m=_}finally{b=!1}if(v)m=Ge(m,"getter");let p=v?void 0:Ke(u,"getter");pe();let F=n.getControlFault();if(F.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:F.error},i);let N=n.getCycle(t,r);if(N!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:N},i);if(v)return g(r,t.createOutcomeToken(),{kind:"error",error:m instanceof P?m:new se(r,m)},i);if(p===void 0)throw Error("Selector result classification was not completed");let D=n.getControlFault();if(D.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:D.error},i);if(p.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:p.error instanceof P?p.error:new se(r,p.error)},i);let M=p.value,A;if(f){let _=e.equal??Object.is,Y,j,H=!1;try{Y=_(f.value,M)}catch(B){H=!0,j=Ge(B,"comparator")}let V=H?void 0:Ke(Y,"comparator");pe();let ie=n.getControlFault();if(ie.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:ie.error},i);let Q=n.getCycle(t,r);if(Q!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:Q},i);if(H)return g(r,t.createOutcomeToken(),{kind:"error",error:j instanceof P?j:new ae(r,j)},i);if(V===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:h.error},i);if(V.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:V.error instanceof P?V.error:new ae(r,V.error)},i);if(V.value!==!0&&V.value!==!1)return g(r,t.createOutcomeToken(),{kind:"error",error:new Ae},i);if(V.value===!0)M=f.value,A=f.current?f.token:void 0}return g(r,A??t.createOutcomeToken(),{kind:"value",value:M},i)}finally{n.leave(t,r)}};class S{#t=[];#n;#o=0;#i;#s=kt;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#r(e,t).cycleError}#r(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var kt=Object.freeze({kind:"none"});var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#i=new Map;#s;#r=1;#a=0;#c;constructor(e,t,n){this.#t=e,this.#s=t,this.#c=n}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#t=void 0}serve(e,t){let n=this.#d(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>this.#c(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#a++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#d().captureCommittedSelectorSuccess(e)??Xe,this.#i.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#d(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#s=new WeakMap;#r=new WeakSet;#a=0;#c;#d="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#l(),this.#n=this.#l()}get status(){return this.#d}get facade(){if(this.#c===void 0)throw Error("Store scope facade is not installed");return this.#c}installFacade(e){if(this.#c!==void 0)throw Error("Store scope facade is already installed");this.#c=e}markDisposing(){if(this.#d==="live")this.#d="disposing"}markDisposed(){this.#d="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#l()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#s.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#i=void 0,this.#s=new WeakMap,this.#r=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r),i=this.#o.get(r);if(i!==void 0&&!this.#r.has(r))return i.served;let s=oe(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#h(e,o?.dependencies??vt,t.dependencies))this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#h(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#s.get(o.node);if(r?.delete(e),r?.isEmpty())this.#s.delete(o.node)}for(let o of n){let r=this.#s.get(o.node);if(r===void 0)r=this.#l(),this.#s.set(o.node,r);r.add(e)}return!0}#l(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var vt=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#f;#h;#l;#b;#p;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#s!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#i===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#u(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#u();i.set(this.#n,o);let s=this.#u();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#y();return}let s=this.#u();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#u(),s=this.#u();if(s.set(r.atom,r),this.#i!==void 0)s.set(this.#i.atom,this.#i);i.set(this.#n,s);let a=this.#u();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#o=void 0,this.#i=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#i!==void 0)e(this.#n,this.#i);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#i;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#d!==void 0&&Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;if(this.#h!==void 0&&Object.is(this.#a,e)&&Object.is(this.#f,t))return this.#h;if(Object.is(this.#a,e))return this.#l?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#u(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#l;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#u();s.set(this.#a,r);let a=this.#u();a.set(t,n),s.set(e,a),this.#b=s,this.#l=void 0,this.#a=void 0}return}let i=this.#d;if(i===void 0){this.#a=e,this.#c=t,this.#d=n;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t))return;if(Object.is(this.#a,e)){let s=this.#h;if(s===void 0){this.#f=t,this.#h=n;return}if(Object.is(this.#f,t))return;let a=this.#u();a.set(this.#c,i),a.set(this.#f,s),a.set(t,n),this.#l=a}else{let s=this.#u(),a=this.#u();if(a.set(this.#c,i),this.#f!==void 0&&this.#h!==void 0)a.set(this.#f,this.#h);s.set(this.#a,a);let c=this.#u();c.set(t,n),s.set(e,c),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#p,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#p,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#p=e,this.#S=t;return}if(Object.is(this.#p,e)){this.#S=t;return}let o=this.#u();o.set(this.#p,this.#S),o.set(e,t),this.#m=o,this.#p=void 0,this.#S=void 0}forEachFallback(e){if(this.#p!==void 0&&this.#S!==void 0)e(this.#p,this.#S);if(this.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#l?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0,this.#l=void 0,this.#b=void 0,this.#p=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#u(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ne=(e,t,n)=>new Ze(e,t,n),Ve=(e)=>{let t=O(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw R(t),new J},et=(e)=>{let t=O(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw R(t),new J};var wt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},at=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31}),gt=32,ct=new WeakMap,Kt=()=>{let e=new Uint32Array(gt),t=Object.freeze({read(n){return e[at[n]]??0}});return ct.set(t,e),t},T=(e)=>Object.freeze({kind:"value",value:e}),Tt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):Tt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,Ee=2,rt=4,Ot=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Rt=(e)=>(e.onAllocation?.(),new Set),De=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Ct=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Rt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Nt=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class dt{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#f;#h;#l;#b=1;#p=0;#S;#m;#e;#y;#u;evaluate;constructor(e,t,n){this.#e=e,this.#y=t===void 0?void 0:ct.get(t),this.#u=n,this.evaluate=n?.evaluate??Qe,this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[at[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=E(this.#e,o,n),i=Re(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":E(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#l;if(a===void 0){if(a=new Map,this.#l=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return wt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#l,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#l=void 0}set(e,t,n){this.#O(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#O(e,t,"StoreTree.update","update",n)}reset(e,t){this.#O(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)E(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#Q(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Ne(this,o,e),i;try{i=Be(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new S;le(this.#e,s,()=>Ve(i)),this.#M(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new S,o=t,r=E(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#T(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#K(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=E(this.#e,o,r);if(ue(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#G(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#I(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")E(this.#e,n,i);ue(this.#e,e.transaction,e.active),this.#A(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ne(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return le(this.#e,f,()=>et(l))}let d=new S;return le(this.#e,d,()=>Ve(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#D(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#j(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n,this.#u);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#Y(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ge;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new Te;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ce;throw new de}throw new de}#A(e){if(e.status!=="live")throw new we}#$(e,t,n,o){let r=E(this.#e,t,n);C(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new S;this.#$(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#M(a)}finally{a.release()}}#Q(e){let t=this.#l,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#l=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=E(this.#e,n,o);ue(this.#e,e.transaction,e.active),this.#A(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=I(this.#e,r,()=>te(o));if(i.kind==="error")throw i.error;let s=this.#C(e,t,n,r);this.#q(e,t,n,i.value,s,r)}#I(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#C(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#Z(o,a.value,r);this.#q(e,t,n,c,s,r)}#z(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#N(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0})}#N(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(I(this.#e,n,()=>Oe(i)));return e.setFallback(t,a),a}#X(e,t,n,o){let r=this.#v(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#J(r,t,n,o)?t:n}#J(e,t,n,o){return I(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=O(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw R(a),new ee}let i=O(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw R(i),new ee;if(r!==!0&&r!==!1)throw new ee;return r})}#Z(e,t,n){return I(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=O(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw R(s),new Z}let r=te(o);if(r.kind==="error")throw r.error;return r.value})}#M(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=Ot(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#_(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#_(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#u?.(1,e,this.#e.atoms),this.#H(e,r),i!==void 0)for(let a of i)this.#H(e,a);let s=this.#B(r);if(i!==void 0)for(let a of i){let c=this.#B(a);s||=c}if(this.#L(r),i!==void 0)for(let a of i)this.#L(a);this.#se();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#V(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let y=this.#V(o,f,b);if(y!==void 0)if(a===void 0)a=y;else c=[y]}if(o.affected!==void 0)for(let[y,k]of o.affected){let z=this.#V(o,y,k);if(z===void 0)continue;if(a===void 0)a=z;else{if(c===void 0)c=[];c.push(z)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#u?.(2,a===void 0?0:1+(c?.length??0)),this.#ie(a,c)}catch(a){throw this.#w(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#W(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#H(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#B(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#V(e,t,n){let o=De(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#ee(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Ct(n,r))continue;let i=r.served.outcome,s=this.#W(e,r.scope,r.atom,n);if(nt(i,s))continue;Nt(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#W(e,t,n,o){let r=De(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=De(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#te(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#te(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ne(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#v(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#oe(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#ne(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#re(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#re(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#v(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(I(this.#e,t,()=>Oe(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#v(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#ie(e,t){if(e===void 0){this.#w();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0,this.#h=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],i=this.#r[o++];this.#E(r,i)}}finally{n=this.#h,this.#h=void 0,this.#s=!1,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#m=void 0,this.#p=this.#l===void 0?0:this.#b++}#w(){this.#p=0,this.#S=void 0,this.#m=void 0}reachSubscriptionTarget(e,t){let n=this.#p,o=this.#l?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#m===void 0)this.#m=[o];else this.#m.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#w(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#m;if(i!==void 0)for(let d of i)r(d);if(this.#w(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let y=d(),k=O(y);if(k.kind==="thenable")R(k);else if(k.kind==="inspection-error")f=!0,b=k.error}catch(y){f=!0,b=y;let k=O(y);if(k.kind==="thenable")R(k)}})}catch(y){f=!0,b=y}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new ve(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#U(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t){if(this.#r===void 0)return;this.#E(e,t)}#E(e,t){if((this.#U(e,t)&(rt|Ee))!==0)return;this.#g(e,t,Ee);try{let o=e.getCommittedSelectorDependencies(t);if(o!==void 0){for(let r of o)if(this.#e.selectors.has(r.node))this.#E(e,r.node)}if(e.isSelectorDirty(t))e.serve(t,new S);this.#g(e,t,rt)}finally{this.#g(e,t,0,Ee)}}#U(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#f?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#a===void 0){this.#a=e,this.#c=t,this.#d=n&~o;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t)){this.#d=(this.#d|n)&~o;return}let r=this.#f;if(r===void 0)r=new Map,this.#f=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#h??=e}#q(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#X(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t,n){this.get=(o)=>e.get(t,o),this.sub=(o,r)=>e.sub(t,o,r),this.set=(o,r)=>e.set(t,o,r),this.update=(o,r)=>e.update(t,o,r),this.reset=(o)=>e.reset(t,o),this.txn=(o,r)=>e.txn(t,o,r),this.scope=function(o){return e.scope(t,arguments.length,o)},this.dispose=()=>e.dispose(t),t.installFacade(this),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return{...e.name===void 0?{}:{name:e.name},...e.equal===void 0?{}:{equal:e.equal}}},lt=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=I(t,l,()=>te(c));if(f.kind==="error")throw f.error;let b=fe("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=fe("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=fe("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.name===void 0?{}:{name:d.name},...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(E(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw Re(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,d)=>{C(t,"createStoreTree");let l=new dt(t,c,d);return new xe(l,l.rootScope,d)}})};var Vt=lt(),Qt=(e,t)=>Vt.createStoreTree(e,t);
2
- export{X as a,Qe as b,ke as c,ve as d,W as e,U as f,q as g,ce as h,J as i,Z as j,ee as k,we as l,ge as m,Te as n,de as o,Kt as p,Vt as q,Qt as r};
@@ -1,2 +0,0 @@
1
- class x extends Error{seal(){Object.freeze(this)}}class se extends x{code="VALDRES_SELECTOR_GETTER_ERROR";selector;cause;constructor(e,t){super("Selector getter failed");this.name="SelectorGetterError",this.selector=e,this.cause=t,this.seal()}}class ye extends x{code="VALDRES_SELECTOR_DEPENDENCY_ERROR";dependency;cause;constructor(e,t){super("Selector dependency failed");this.name="SelectorDependencyError",this.dependency=e,this.cause=t,this.seal()}}class X extends x{code="VALDRES_SELECTOR_CIRCULAR_DEPENDENCY";selector;path;constructor(e,t){super("Selector dependency graph must be acyclic");this.name="SelectorCircularDependencyError",this.selector=e,this.path=Object.freeze([...t]),this.seal()}}class P extends x{code="VALDRES_INVALID_SYNCHRONOUS_SELECTOR_RESULT";phase;constructor(e){super(`Selector ${e} returned or threw a thenable`);this.name="InvalidSynchronousSelectorResultError",this.phase=e,this.seal()}}class Ae extends x{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ae extends x{code="VALDRES_SELECTOR_COMPARATOR_ERROR";selector;cause;constructor(e,t){super("Selector comparator failed");this.name="SelectorComparatorError",this.selector=e,this.cause=t,this.seal()}}class be extends x{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Me=Object.freeze({kind:"not-thenable"}),ft=()=>{},ht=Reflect.apply,_e=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class ke extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class ve extends w{code="VALDRES_SUBSCRIBER_NOTIFICATION";cause;causes;committed=!0;phase="notifying";source="owned-mutation";constructor(e){super("One or more Store subscribers threw during notification");this.name="SubscriberNotificationError",this.causes=Object.freeze([...e]),this.cause=this.causes[0],this.seal()}}class W extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class U extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class q extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class ce extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class Z extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ee extends w{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class we extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class ge extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Te extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class de extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var O=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Me;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Me}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},R=(e)=>{try{ht(e.then,e.target,[void 0,ft])}catch{}},te=(e)=>{let t=O(e);if(t.kind==="not-thenable")return Object.freeze({kind:"value",value:e});if(t.kind==="inspection-error")return Object.freeze({kind:"error",error:t.error});return R(t),Object.freeze({kind:"error",error:new Z})},Oe=(e)=>{try{return te(e())}catch(t){let n=O(t);if(n.kind==="not-thenable")return Object.freeze({kind:"error",error:t});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return R(n),Object.freeze({kind:"error",error:new Z})}},ne=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},I=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"guarded-callback",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},He=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"subscriber",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},oe=(e,t,n)=>ne(e,Object.freeze({kind:"selector",session:t}),n),Be=(e,t,n)=>ne(e,Object.freeze({kind:"transaction",transaction:t}),n),le=(e,t,n)=>{try{let o=ne(e,Object.freeze({kind:"transaction-result",session:t}),n),r=t.getControlFault();if(r.kind==="fault")throw r.error;return o}catch(o){let r=t.getControlFault();if(r.kind==="fault")throw r.error;throw o}},C=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Re=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new U(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new q;throw new W},Le=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new U("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new q;throw new W},ue=(e,t,n)=>{if(!n)throw new ce;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new U("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new W;throw new q},We=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},L=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";if((typeof t==="object"||typeof t==="function")&&t!==null){let o=Object.getOwnPropertyDescriptor(t,_e);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new ke;throw We(e,n).latchControlFault(r),r}}return"invalid"},E=(e,t,n)=>{if((typeof t==="object"||typeof t==="function")&&t!==null&&(e.states.has(t)||e.stores.has(t)||e.transactionCursors.has(t)))return"local";let o=e.activity,r=We(e,n);if(o!==void 0&&"session"in o)try{let i=L(e,t,r),s=r.getControlFault();if(s.kind==="fault")throw s.error;return i}catch(i){let s=r.getControlFault();if(s.kind==="fault")throw s.error;throw i}return I(e,r,()=>L(e,t,r))},re=(e,t)=>(Object.defineProperty(e,_e,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),fe=(e,t)=>Object.freeze(re({kind:e},t));var Ue=Object.freeze({kind:"not-thenable"}),St=()=>{},mt=Reflect.apply,qe=Symbol("selector dependency path root"),Ye=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},$e=(e)=>{try{mt(e.then,e.target,[void 0,St])}catch{}},pt=(e)=>Object.freeze(e),yt=(e)=>Object.freeze(e),g=(e,t,n,o)=>{let r=yt(o);return Object.freeze({selector:e,token:t,outcome:pt(n),dependencies:r,attemptedPrefix:n.kind==="value"?At:Object.freeze(r.map((i)=>i.node))})},At=Object.freeze([]),bt=(e,t,n,o)=>{let r=[e],i=new Map([[e,qe]]);while(r.length>0){let s=r.pop();if(Object.is(s,t)){let d=[],l=s;while(l!==qe)d.push(l),l=i.get(l);return d.reverse(),Object.freeze(d)}let a=o.getTransientDependencies(n,s);if(a){for(let d of a){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let d=n.getSelectorDependencyNodes(s);if(d===void 0)continue;for(let l of d){if(i.has(l))continue;i.set(l,s),r.push(l)}continue}let c=n.getSelectorRecord(s);if(!c)continue;for(let d of c.dependencies){if(i.has(d.node))continue;i.set(d.node,s),r.push(d.node)}}return},Ge=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),new P(t);if(n.kind==="inspection-error")return n.error;return e},Ke=(e,t)=>{let n=Ye(e);if(n.kind==="thenable")return $e(n),Object.freeze({kind:"error",error:new P(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},Qe=(e,t,n,o=bt)=>{let{node:r}=e,i=[],s=t.getSelectorRecord(r),a=s?.dependencies,c=a===void 0?new Set:void 0,d,l=0,f=t.getComparisonBaseline(r),b=!0,y=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let m of i)u.add(m.node);return c=u,u};n.enter(t,r,i);let k=t.getSelectorGraphVersion(),z=n.getSelectorGraphPublicationCount(t),G=k,K=z,Pe=k,Ie=z,me=(u,m,v,p)=>v-u===p-m,ze=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),v=me(G,K,u,m))=>{if(v){G=u,K=m;return}for(let p=0;p<i.length;p++){let F=i[p],N=o(F.node,r,t,n,0);if(!N)continue;if(c!==void 0)for(let A=i.length-1;A>=p;A--)c.delete(i[A].node);if(i.length=p,l++,n.getControlFault().kind==="fault")return;let M=new X(r,[r,...N]);n.latchCycle(t,r,M);return}G=u,K=m},pe=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Pe=u,Ie=m;let v=me(G,K,u,m);if(!v)n.revalidateAncestorPrefixes(t,r);ze(u,m,v)};n.setPrefixRevalidator(t,r,ze);let ut=(u)=>{if(!b)throw new be;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let v=n.getCycle(t,r);if(v!==void 0)throw v;let p=n.activeCyclePath(t,u);if(p){let h=new X(r,p);throw n.latchCycle(t,r,h),h}let F=i.length,N,D=!1;if(c===void 0){let h=a?.[F];if(h!==void 0&&Object.is(h.node,u))N=!1,D=!0;else N=y().has(u)}else N=c.has(u);if(!N&&!D&&a!==void 0&&a.length>0){let h=a[i.length];if(h!==void 0&&Object.is(h.node,u))D=!0;else{if(d===void 0){d=new Set;for(let B of a)d.add(B.node)}D=d.has(u)}}let M=l,A=t.serve(u,n);pe();let _=n.getCycle(t,r);if(_!==void 0)throw _;let Y=c!==void 0?c.has(u):l===M&&i.length===F?!1:y().has(u),j=Pe,H=Ie,V=Y||D&&j===k,ie=a===void 0&&me(k,z,j,H);if(!V&&!ie){let h=o(u,r,t,n,1);if(h){let B=n.getControlFault();if(B.kind==="fault")throw B.error;let Fe=new X(r,[r,...h]);throw n.latchCycle(t,r,Fe),Fe}}if(!Y){let h=s?.dependencies[i.length];c?.add(u),i.push(h!==void 0&&Object.is(h.node,u)&&Object.is(h.token,A.token)?h:Object.freeze({node:u,token:A.token}))}if(G=j,K=H,A.outcome.kind==="control-error"){n.latchControlFault(A.outcome.error);let h=n.getControlFault();if(h.kind==="fault")throw h.error;throw A.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(A.outcome.kind==="error")throw new ye(u,A.outcome.error);return A.outcome.value};try{let u,m,v=!1;try{u=e.get(ut)}catch(_){v=!0,m=_}finally{b=!1}if(v)m=Ge(m,"getter");let p=v?void 0:Ke(u,"getter");pe();let F=n.getControlFault();if(F.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:F.error},i);let N=n.getCycle(t,r);if(N!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:N},i);if(v)return g(r,t.createOutcomeToken(),{kind:"error",error:m instanceof P?m:new se(r,m)},i);if(p===void 0)throw Error("Selector result classification was not completed");let D=n.getControlFault();if(D.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:D.error},i);if(p.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:p.error instanceof P?p.error:new se(r,p.error)},i);let M=p.value,A;if(f){let _=e.equal??Object.is,Y,j,H=!1;try{Y=_(f.value,M)}catch(B){H=!0,j=Ge(B,"comparator")}let V=H?void 0:Ke(Y,"comparator");pe();let ie=n.getControlFault();if(ie.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:ie.error},i);let Q=n.getCycle(t,r);if(Q!==void 0)return g(r,t.createOutcomeToken(),{kind:"error",error:Q},i);if(H)return g(r,t.createOutcomeToken(),{kind:"error",error:j instanceof P?j:new ae(r,j)},i);if(V===void 0)throw Error("Selector comparator classification was not completed");let h=n.getControlFault();if(h.kind==="fault")return g(r,t.createOutcomeToken(),{kind:"control-error",error:h.error},i);if(V.kind==="error")return g(r,t.createOutcomeToken(),{kind:"error",error:V.error instanceof P?V.error:new ae(r,V.error)},i);if(V.value!==!0&&V.value!==!1)return g(r,t.createOutcomeToken(),{kind:"error",error:new Ae},i);if(V.value===!0)M=f.value,A=f.current?f.token:void 0}return g(r,A??t.createOutcomeToken(),{kind:"value",value:M},i)}finally{n.leave(t,r)}};class S{#t=[];#n;#o=0;#i;#s=kt;latchControlFault(e){if(this.#s.kind==="fault")return;this.#s=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#s}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#a(e,t);o.cycleError??=n}getCycle(e,t){return this.#r(e,t).cycleError}#r(e,t){let n=this.#t[this.#t.length-1];if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame is not active");return n}#a(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var kt=Object.freeze({kind:"none"});var Xe=Symbol("no-committed-selector-baseline");class he{#t;#n=new Map;#o=new Map;#i=new Map;#s;#r=1;#a=0;#c;constructor(e,t,n){this.#t=e,this.#s=t,this.#c=n}readSelector(e){let t=new S,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#s+1)throw Error("Scratch selector generation is not contiguous");this.#s=e,this.#n.clear(),this.#o.clear()}revoke(){this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#t=void 0}serve(e,t){let n=this.#d(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>this.#c(o.definition,this,t));if(i.outcome.kind==="control-error")throw i.outcome.error;let s=Object.freeze({token:i.token,outcome:i.outcome});return this.#a++,t.noteSelectorGraphPublication(this),this.#n.set(e,Object.freeze({served:s,dependencies:i.dependencies})),s}getSelectorRecord(e){let t=this.#n.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#d().captureCommittedSelectorSuccess(e)??Xe,this.#i.set(e,t);return t===Xe?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#d(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}class Je{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Se{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#s=new WeakMap;#r=new WeakSet;#a=0;#c;#d="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#l(),this.#n=this.#l()}get status(){return this.#d}get facade(){if(this.#c===void 0)throw Error("Store scope facade is not installed");return this.#c}installFacade(e){if(this.#c!==void 0)throw Error("Store scope facade is already installed");this.#c=e}markDisposing(){if(this.#d==="live")this.#d="disposing"}markDisposed(){this.#d="disposed"}getAtomView(e){return this.#t.get(e)}getMaterializedServedOutcome(e){let t=this.#t.get(e);if(t!==void 0)return t.served;let n=e,o=this.#o.get(n);return o!==void 0&&!this.#r.has(n)?o.served:void 0}createAtomView(e,t,n){let o=this.#t.get(e);if(o!==void 0)return o;let r={scope:this,atom:e,served:Object.freeze({token:this.createOutcomeToken(),outcome:t}),inheritedFrom:n,inheritingChildren:this.#l()};if(this.#t.set(e,r),this.#n.add(r),n!==void 0)n.inheritingChildren.add(r),this.coordinator.recordCounter("routeAdds");return r}attachAtomView(e,t){if(Object.is(e.inheritedFrom,t))return;this.detachAtomView(e),e.inheritedFrom=t,t.inheritingChildren.add(e),this.coordinator.recordCounter("routeAdds")}detachAtomView(e){if(e.inheritedFrom===void 0)return;e.inheritedFrom.inheritingChildren.delete(e),e.inheritedFrom=void 0,this.coordinator.recordCounter("routeRemoves")}updateAtomView(e,t){e.served=Object.freeze({token:this.createOutcomeToken(),outcome:t}),this.coordinator.reachSubscriptionTarget(this,e.atom)}captureCommittedSelectorSuccess(e){let t=this.#o.get(e)?.lastSuccess;return t===void 0?void 0:Object.freeze({value:t.value})}isSelectorDirty(e){return this.#r.has(e)}getCommittedSelectorDependencies(e){return this.#o.get(e)?.dependencies}markDependents(e){this.#s.get(e)?.forEach((t)=>{if(this.coordinator.enqueueSelector(this,t))this.#r.add(t)})}dropRecords(){this.#n.forEach((e)=>{this.detachAtomView(e),e.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap,this.#t=new WeakMap,this.#o=new WeakMap,this.#i=void 0,this.#s=new WeakMap,this.#r=new WeakSet}serve(e,t){let n=this.coordinator.runtimeDomain;if(L(n,e,t)==="invalid")throw TypeError("Selector get requires a valid State");return this.serveKnownLocal(e,t)}serveKnownLocal(e,t){let n=this.coordinator.runtimeDomain;if(n.atoms.has(e)){let a=this.#t.get(e);if(a!==void 0)return a.served;return this.coordinator.serveScopeAtom(this,e,t)}let o=n.selectors.get(e);if(o===void 0)throw TypeError("Unknown committed StoreTree state");let r=e,i=this.#o.get(r);if(i!==void 0&&this.coordinator.postSourceApply)this.coordinator.prepareSelectorRead(this,r),i=this.#o.get(r);if(i!==void 0&&!this.#r.has(r))return i.served;let s=oe(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#f(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#a}getComparisonBaseline(e){let t=this.#o.get(e);if(t?.lastSuccess===void 0)return;return t.served.outcome.kind==="value"?Object.freeze({current:!0,value:t.lastSuccess.value,token:t.served.token}):Object.freeze({current:!1,value:t.lastSuccess.value})}createOutcomeToken(){return this.coordinator.createOutcomeToken()}#f(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess});if(this.#h(e,o?.dependencies??vt,t.dependencies))this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),o!==void 0&&!Object.is(o.served.token,t.token))this.coordinator.reachSubscriptionTarget(this,e),this.markDependents(e);if(t.outcome.kind==="control-error")this.coordinator.latchPropagationControlFault(t.outcome.error);return r}#h(e,t,n){if(t.length===n.length){let o=0;while(o<t.length&&Object.is(t[o].node,n[o].node))o++;if(o===t.length)return!1}for(let o of t){let r=this.#s.get(o.node);if(r?.delete(e),r?.isEmpty())this.#s.delete(o.node)}for(let o of n){let r=this.#s.get(o.node);if(r===void 0)r=this.#l(),this.#s.set(o.node,r);r.add(e)}return!0}#l(){return new Je(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var vt=Object.freeze([]);class Ce{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#f;#h;#l;#b;#p;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#s!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#i===void 0?this.#o:void 0}stage(e,t){let n=this.#r;if(n!==void 0){let i=n.get(e);if(i===void 0)i=this.#u(),n.set(e,i);i.set(t.atom,t),this.#y();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#u();i.set(this.#n,o);let s=this.#u();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#y();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#y();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#y();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#y();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#y();return}let s=this.#u();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#u(),s=this.#u();if(s.set(r.atom,r),this.#i!==void 0)s.set(this.#i.atom,this.#i);i.set(this.#n,s);let a=this.#u();a.set(t.atom,t),i.set(e,a),this.#r=i,this.#n=void 0}this.#o=void 0,this.#i=void 0,this.#y()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#i!==void 0)e(this.#n,this.#i);return}let n=this.#s;if(n!==void 0){let r=this.#n;for(let i of n.values())e(r,i);return}let o=this.#r;if(o===void 0)return;for(let[r,i]of o)for(let s of i.values())e(r,s)}getIntent(e,t){let n=this.#o;if(n!==void 0&&Object.is(this.#n,e)&&Object.is(n.atom,t))return n;let o=this.#i;if(o!==void 0&&Object.is(this.#n,e)&&Object.is(o.atom,t))return o;if(Object.is(this.#n,e))return this.#s?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#d!==void 0&&Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;if(this.#h!==void 0&&Object.is(this.#a,e)&&Object.is(this.#f,t))return this.#h;if(Object.is(this.#a,e))return this.#l?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#u(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#l;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#u();s.set(this.#a,r);let a=this.#u();a.set(t,n),s.set(e,a),this.#b=s,this.#l=void 0,this.#a=void 0}return}let i=this.#d;if(i===void 0){this.#a=e,this.#c=t,this.#d=n;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t))return;if(Object.is(this.#a,e)){let s=this.#h;if(s===void 0){this.#f=t,this.#h=n;return}if(Object.is(this.#f,t))return;let a=this.#u();a.set(this.#c,i),a.set(this.#f,s),a.set(t,n),this.#l=a}else{let s=this.#u(),a=this.#u();if(a.set(this.#c,i),this.#f!==void 0&&this.#h!==void 0)a.set(this.#f,this.#h);s.set(this.#a,a);let c=this.#u();c.set(t,n),s.set(e,c),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#p,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#p,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#p=e,this.#S=t;return}if(Object.is(this.#p,e)){this.#S=t;return}let o=this.#u();o.set(this.#p,this.#S),o.set(e,t),this.#m=o,this.#p=void 0,this.#S=void 0}forEachFallback(e){if(this.#p!==void 0&&this.#S!==void 0)e(this.#p,this.#S);if(this.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#y(){this.generation+=1;let e=this.#e;if(e!==void 0)for(let t of e.values())t.advanceGeneration(this.generation)}getScratchHost(e){return this.#e?.get(e)}installScratchHost(e,t){let n=this.#e,o=n===void 0;if(n===void 0)n=new Map,this.#e=n;return n.set(e,t),o}close(){if(!this.active)return;this.active=!1;let e=this.#e;if(e!==void 0){for(let t of e.values())t.revoke();e.clear()}this.#e=void 0}release(){if(this.#s?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#l?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=void 0,this.#f=void 0,this.#h=void 0,this.#l=void 0,this.#b=void 0,this.#p=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#u(){return this.#t?.(),new Map}}class Ze{get;set;update;reset;scope;constructor(e,t,n){this.get=(o)=>e.transactionGet(t,n,o),this.set=(o,r)=>e.transactionSet(t,n,o,r),this.update=(o,r)=>e.transactionUpdate(t,n,o,r),this.reset=(o)=>e.transactionReset(t,n,o),this.scope=(...o)=>e.transactionScope(t,n,o[0],o.length,o[1]),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ne=(e,t,n)=>new Ze(e,t,n),Ve=(e)=>{let t=O(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw R(t),new J},et=(e)=>{let t=O(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw R(t),new J};var wt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},at=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31}),gt=32,ct=new WeakMap,Kt=()=>{let e=new Uint32Array(gt),t=Object.freeze({read(n){return e[at[n]]??0}});return ct.set(t,e),t},T=(e)=>Object.freeze({kind:"value",value:e}),Tt=(e)=>Object.freeze({kind:"error",error:e}),tt=(e)=>e.kind==="value"?T(e.value):Tt(e.error),nt=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="value"&&t.kind==="value")return Object.is(e.value,t.value);return e.kind!=="value"&&t.kind!=="value"&&Object.is(e.error,t.error)},ot=1,Ee=2,rt=4,Ot=(e)=>({onAllocation:e,preflightAtom:void 0,preflightScope:void 0,preflightOutcome:void 0,secondPreflightAtom:void 0,secondPreflightScope:void 0,secondPreflightOutcome:void 0,preflight:void 0,consideredRecord:void 0,secondConsideredRecord:void 0,considered:void 0,affectedRecord:void 0,affectedBefore:void 0,secondAffectedRecord:void 0,secondAffectedBefore:void 0,affected:void 0}),je=(e)=>(e.onAllocation?.(),new Map),Rt=(e)=>(e.onAllocation?.(),new Set),De=(e,t,n)=>{if(e.preflightOutcome!==void 0&&Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return e.preflightOutcome;if(e.secondPreflightOutcome!==void 0&&Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return e.secondPreflightOutcome;return e.preflight?.get(t)?.get(n)},it=(e,t,n,o)=>{if(e.preflightOutcome===void 0){e.preflightAtom=t,e.preflightScope=n,e.preflightOutcome=o;return}if(Object.is(e.preflightAtom,t)&&Object.is(e.preflightScope,n))return;if(e.secondPreflightOutcome===void 0){e.secondPreflightAtom=t,e.secondPreflightScope=n,e.secondPreflightOutcome=o;return}if(Object.is(e.secondPreflightAtom,t)&&Object.is(e.secondPreflightScope,n))return;let r=e.preflight;if(r===void 0)r=je(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=je(e),r.set(t,i);i.set(n,o)},Ct=(e,t)=>{if(Object.is(e.consideredRecord,t)||Object.is(e.secondConsideredRecord,t))return!1;if(e.consideredRecord===void 0)return e.consideredRecord=t,!0;if(e.secondConsideredRecord===void 0)return e.secondConsideredRecord=t,!0;let n=e.considered;if(n===void 0)n=Rt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Nt=(e,t,n)=>{if(e.affectedRecord===void 0){e.affectedRecord=t,e.affectedBefore=n;return}if(e.secondAffectedRecord===void 0){e.secondAffectedRecord=t,e.secondAffectedBefore=n;return}let o=e.affected;if(o===void 0)o=je(e),e.affected=o;o.set(t,n)};class dt{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#f;#h;#l;#b=1;#p=0;#S;#m;#e;#y;#u;evaluate;constructor(e,t,n){this.#e=e,this.#y=t===void 0?void 0:ct.get(t),this.#u=n,this.evaluate=n?.evaluate??Qe,this.#n=new Se(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#y!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#y;if(n===void 0)return;n[at[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Ce(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new S,o=t,r=E(this.#e,o,n),i=Re(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":E(this.#e,o,r=new S);if(C(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new S);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#l;if(a===void 0){if(a=new Map,this.#l=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return wt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Le(this.#e);let{previous:n,next:o}=e;if(n===void 0)t.head=o;else n.next=o;if(o===void 0)t.tail=n;else o.previous=n;e.callback=void 0,e.target=void 0,e.previous=void 0,e.next=void 0;let r=this.instrumented;if(r)this.recordCounter("subscriptionRemovals"),this.recordCounter("activeSubscriptions",-1);if(t.head!==void 0)return;let i=this.#l,s=i?.get(t.scope);if(s?.get(t.state)===t){if(s.delete(t.state),r)this.recordCounter("activeSubscriptionTargets",-1)}if(s!==void 0&&s.size===0){if(i?.delete(t.scope),r)this.recordCounter("activeSubscriptionScopes",-1)}if(i?.size===0)this.#l=void 0}set(e,t,n){this.#O(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#O(e,t,"StoreTree.update","update",n)}reset(e,t){this.#O(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)E(this.#e,n,new S);if(C(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(C(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#Q(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(C(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Ne(this,o,e),i;try{i=Be(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new S;le(this.#e,s,()=>Ve(i)),this.#M(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new S,o=t,r=E(this.#e,o,n);if(C(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#T(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#K(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new S,i=E(this.#e,o,r);if(ue(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#G(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new S;this.#R(e,t,r,i,"Transaction.update"),this.#I(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new S;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new S;if(typeof n!=="string")E(this.#e,n,i);ue(this.#e,e.transaction,e.active),this.#A(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ne(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let f=new S;return le(this.#e,f,()=>et(l))}let d=new S;return le(this.#e,d,()=>Ve(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#G(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new he(Object.freeze({resolveState:(n,o)=>this.#D(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>oe(this.#e,n,o)}),e.generation,this.evaluate)}#D(e,t){if(L(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#j(e,t){let n=new Se(this,e,t);this.recordCounter("scopeNodesCreated");let o=new xe(this,n,this.#u);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#Y(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new ge;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new Te;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new ce;throw new de}throw new de}#A(e){if(e.status!=="live")throw new we}#$(e,t,n,o){let r=E(this.#e,t,n);C(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new S;this.#$(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#M(a)}finally{a.release()}}#Q(e){let t=this.#l,n=t?.get(e);if(n===void 0)return;let o=0;for(let r of n.values()){let i=r.head;while(i!==void 0){let s=i.next;i.callback=void 0,i.target=void 0,i.previous=void 0,i.next=void 0,o++,i=s}r.head=void 0,r.tail=void 0}if(t.delete(e),t.size===0)this.#l=void 0;if(this.instrumented)this.recordCounter("subscriptionRemovals",o),this.recordCounter("activeSubscriptions",-o),this.recordCounter("activeSubscriptionTargets",-n.size),this.recordCounter("activeSubscriptionScopes",-1)}#R(e,t,n,o,r){let i=E(this.#e,n,o);ue(this.#e,e.transaction,e.active),this.#A(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=I(this.#e,r,()=>te(o));if(i.kind==="error")throw i.error;let s=this.#C(e,t,n,r);this.#q(e,t,n,i.value,s,r)}#I(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#C(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#Z(o,a.value,r);this.#q(e,t,n,c,s,r)}#z(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0}):this.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=T(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#N(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:T(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:T(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0})}#N(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=tt(I(this.#e,n,()=>Oe(i)));return e.setFallback(t,a),a}#X(e,t,n,o){let r=this.#v(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#J(r,t,n,o)?t:n}#J(e,t,n,o){return I(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=O(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw R(a),new ee}let i=O(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw R(i),new ee;if(r!==!0&&r!==!1)throw new ee;return r})}#Z(e,t,n){return I(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=O(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw R(s),new Z}let r=te(o);if(r.kind==="error")throw r.error;return r.value})}#M(e){if(!e.hasIntents)return;let{singleIntent:t,singleIntentScope:n}=e;if(t?.kind==="reset"&&n!==void 0&&!t.publishDraftFallback&&e.getAtomBaseline(n,t.atom)?.owned===!1)return;let o=Ot(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#_(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#_(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#u?.(1,e,this.#e.atoms),this.#H(e,r),i!==void 0)for(let a of i)this.#H(e,a);let s=this.#B(r);if(i!==void 0)for(let a of i){let c=this.#B(a);s||=c}if(this.#L(r),i!==void 0)for(let a of i)this.#L(a);this.#se();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#V(o,d,l);let{secondAffectedRecord:f,secondAffectedBefore:b}=o;if(f!==void 0&&b!==void 0){let y=this.#V(o,f,b);if(y!==void 0)if(a===void 0)a=y;else c=[y]}if(o.affected!==void 0)for(let[y,k]of o.affected){let z=this.#V(o,y,k);if(z===void 0)continue;if(a===void 0)a=z;else{if(c===void 0)c=[];c.push(z)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#u?.(2,a===void 0?0:1+(c?.length??0)),this.#ie(a,c)}catch(a){throw this.#w(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#W(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#H(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#B(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#V(e,t,n){let o=De(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),nt(n,o))return;return t.scope.updateAtomView(t,o),t}#ee(e,t,n){let o=[t];while(o.length!==0){let r=o.pop();if(!Ct(n,r))continue;let i=r.served.outcome,s=this.#W(e,r.scope,r.atom,n);if(nt(i,s))continue;Nt(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#W(e,t,n,o){let r=De(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=De(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=T(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=T(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#te(e,n),s!==void 0)it(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)it(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#te(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return T(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ne(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#v(e);if(n.fallback.kind==="eager")return T(n.fallback.value);throw Error("Committed Atom fallback is not materialized")}#oe(e,t){let n=e,o=[],r;while(!0){let i=n.getAtomView(t);if(i!==void 0){r=i;break}if(n.atomOverrides.has(t)){r=n.createAtomView(t,T(n.atomOverrides.get(t)));break}if(n.parent===void 0){r=n.createAtomView(t,this.#ne(t));break}o.push(n),n=n.parent}for(let i=o.length-1;i>=0;i--)r=o[i].createAtomView(t,r.served.outcome,r);return r}serveScopeAtom(e,t,n){let o=e,r=[],i;while(!0){let s=o.getAtomView(t);if(s!==void 0){i=s;break}if(o.atomOverrides.has(t)){i=o.createAtomView(t,T(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#re(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#re(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#v(e);if(o.fallback.kind==="eager")return T(o.fallback.value);let r=o.fallback.initialize,i=tt(I(this.#e,t,()=>Oe(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#v(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#ie(e,t){if(e===void 0){this.#w();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0,this.#h=void 0,this.#s=!0;let n;try{if(e.scope.markDependents(e.atom),t!==void 0)for(let r of t)r.scope.markDependents(r.atom);let o=0;while(o<this.#r.length){let r=this.#r[o++],i=this.#r[o++];this.#E(r,i)}}finally{n=this.#h,this.#h=void 0,this.#s=!1,this.#r=void 0,this.#a=void 0,this.#c=void 0,this.#d=0,this.#f=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#m=void 0,this.#p=this.#l===void 0?0:this.#b++}#w(){this.#p=0,this.#S=void 0,this.#m=void 0}reachSubscriptionTarget(e,t){let n=this.#p,o=this.#l?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#m===void 0)this.#m=[o];else this.#m.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#w(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#m;if(i!==void 0)for(let d of i)r(d);if(this.#w(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new S,f=!1,b;try{He(this.#e,l,()=>{try{let y=d(),k=O(y);if(k.kind==="thenable")R(k);else if(k.kind==="inspection-error")f=!0,b=k.error}catch(y){f=!0,b=y;let k=O(y);if(k.kind==="thenable")R(k)}})}catch(y){f=!0,b=y}if(f){if(c===void 0)c=[];if(c.push(b),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new ve(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#U(e,t)&ot)!==0)return!0;return this.#g(e,t,ot),n.push(e,t),!0}prepareSelectorRead(e,t){if(this.#r===void 0)return;this.#E(e,t)}#E(e,t){if((this.#U(e,t)&(rt|Ee))!==0)return;this.#g(e,t,Ee);try{let o=e.getCommittedSelectorDependencies(t);if(o!==void 0){for(let r of o)if(this.#e.selectors.has(r.node))this.#E(e,r.node)}if(e.isSelectorDirty(t))e.serve(t,new S);this.#g(e,t,rt)}finally{this.#g(e,t,0,Ee)}}#U(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#f?.get(e)?.get(t)??0}#g(e,t,n,o=0){if(this.#a===void 0){this.#a=e,this.#c=t,this.#d=n&~o;return}if(Object.is(this.#a,e)&&Object.is(this.#c,t)){this.#d=(this.#d|n)&~o;return}let r=this.#f;if(r===void 0)r=new Map,this.#f=r;let i=r.get(e);if(i===void 0)i=new Map,r.set(e,i);i.set(t,((i.get(t)??0)|n)&~o)}latchPropagationControlFault(e){this.#h??=e}#q(e,t,n,o,r,i){let s=r.outcome.kind==="value"?this.#X(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t,n){this.get=(o)=>e.get(t,o),this.sub=(o,r)=>e.sub(t,o,r),this.set=(o,r)=>e.set(t,o,r),this.update=(o,r)=>e.update(t,o,r),this.reset=(o)=>e.reset(t,o),this.txn=(o,r)=>e.txn(t,o,r),this.scope=function(o){return e.scope(t,arguments.length,o)},this.dispose=()=>e.dispose(t),t.installFacade(this),re(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var st=(e)=>{if(e.equal!==void 0&&typeof e.equal!=="function")throw TypeError("Atom equal must be a function");return{...e.name===void 0?{}:{name:e.name},...e.equal===void 0?{}:{equal:e.equal}}},lt=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new S,f=I(t,l,()=>te(c));if(f.kind==="error")throw f.error;let b=fe("atom",t.ownerToken);return t.states.add(b),t.atoms.set(b,Object.freeze({fallback:Object.freeze({kind:"eager",value:f.value}),...st(d)})),b},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=fe("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...st(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=fe("selector",t.ownerToken),f=Object.freeze({node:l,get:c,...d.name===void 0?{}:{name:d.name},...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,f),l},i=(c)=>{let d=new S;if(E(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(C(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw Re(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw C(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw C(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,d)=>{C(t,"createStoreTree");let l=new dt(t,c,d);return new xe(l,l.rootScope,d)}})};var Vt=lt(),Qt=(e,t)=>Vt.createStoreTree(e,t);
2
- export{X as a,Qe as b,ke as c,ve as d,W as e,U as f,q as g,ce as h,J as i,Z as j,ee as k,we as l,ge as m,Te as n,de as o,Kt as p,Vt as q,Qt as r};