valdres 1.0.0-beta.34 → 1.0.0-beta.35

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
@@ -66,7 +66,7 @@ const report = inspect.export()
66
66
  inspect.reset()
67
67
  ```
68
68
 
69
- The report correlates human labels with opaque operation, commit, evaluation, session, and search IDs. It includes selector work, proposed topology changes, forward cycle-search visits by host and call site, bounded reverse-proof outcomes and work, aggregate negative-proof memo admission/probe/prune counters, transient selector-host counts, and propagation/notification totals. Completed summaries and details use separate bounded rings with explicit overflow. Exports are immutable and JSON-safe; application values, callbacks, errors, and live State handles are never recorded. Labels are metadata, not identity. The core inspection schema is version 4.
69
+ The report correlates human labels with opaque operation, commit, evaluation, session, and search IDs. It includes selector work, proposed topology changes, forward cycle-search visits by host and call site, bounded reverse-proof outcomes and work, topology-delta reverse-snapshot attempts/outcomes/scanned and captured work, aggregate negative-proof memo admission/probe/prune counters, transient selector-host counts, and propagation/notification totals. Completed summaries and details use separate bounded rings with explicit overflow. Exports are immutable and JSON-safe; application values, callbacks, errors, and live State handles are never recorded. Labels are metadata, not identity. The core inspection schema is version 5.
70
70
 
71
71
  Inspection adds recording and timing work only to the Store created by `createInspectableStore`. The recorder stays outside the ordinary root entry and ordinary consumer bundles remain within their existing size budget.
72
72
 
@@ -1 +1 @@
1
- import{r as e}from"../chunk-fbqtxaaa.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{r as e}from"../chunk-y5ja7h9m.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 B extends Error{seal(){Object.freeze(this)}}class he extends B{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 Ee extends B{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 ne extends B{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 H extends B{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 De extends B{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class Se extends B{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 Ve extends B{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Qe=Object.freeze({kind:"not-thenable"}),Vt=()=>{},Pt=Reflect.apply,Ze=Symbol.for("valdres.runtime-owner/v1");class O extends Error{seal(){Object.freeze(this)}}class Pe extends O{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class xe extends O{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 Y extends O{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class X extends O{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class Q extends O{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class pe extends O{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class oe extends O{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class re extends O{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ie extends O{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class je extends O{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class Ie extends O{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Me extends O{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class me extends O{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var P=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Qe;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Qe}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},x=(e)=>{try{Pt(e.then,e.target,[void 0,Vt])}catch{}},se=(e)=>{let t=P(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 x(t),Object.freeze({kind:"error",error:new re})},ze=(e)=>{try{return se(e())}catch(t){let n=P(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 x(n),Object.freeze({kind:"error",error:new re})}},ae=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},G=(e,t,n)=>{try{let o=ae(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}},Je=(e,t,n)=>{try{let o=ae(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}},de=(e,t,n)=>ae(e,Object.freeze({kind:"selector",session:t}),n),et=(e,t,n)=>ae(e,Object.freeze({kind:"transaction",transaction:t}),n),ye=(e,t,n)=>{try{let o=ae(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}},j=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new X(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Q;throw new Y},Fe=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new X(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Q;throw new Y},tt=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new X("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new Q;throw new Y},be=(e,t,n)=>{if(!n)throw new pe;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new X("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new Y;throw new Q},nt=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},K=(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,Ze);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Pe;throw nt(e,n).latchControlFault(r),r}}return"invalid"},z=(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=nt(e,n);if(o!==void 0&&"session"in o)try{let i=K(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 G(e,r,()=>K(e,t,r))},ce=(e,t)=>(Object.defineProperty(e,Ze,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),Ae=(e,t)=>Object.freeze(ce({kind:e},t));var ot=Object.freeze({kind:"not-thenable"}),xt=()=>{},jt=Reflect.apply,rt=Symbol("selector dependency path root"),at=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return ot;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):ot}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},dt=(e)=>{try{jt(e.then,e.target,[void 0,xt])}catch{}},It=(e)=>Object.freeze(e),Mt=(e)=>Object.freeze(e),C=(e,t,n,o)=>{let r=Mt(o);return Object.freeze({selector:e,token:t,outcome:It(n),dependencies:r,attemptedPrefix:n.kind==="value"?zt:Object.freeze(r.map((i)=>i.node))})},zt=Object.freeze([]),ve=32,Z=8192,Ft=2*ve,ct=128,_t=4096;class lt{passiveSearches;searches=0;constructor(e,t){if(this.passiveSearches=e,t!==void 0)this.diagnostics=t}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let e=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(e)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(e&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(Z,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,t.has(e))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,n.has(e))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(e){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let n=e.size>=ve&&e.size<=Z,o;if(this.searches===1&&n)this.first=e,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>Z){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=ve&&e.size<=Z;if(this.first===void 0){if(t)this.first=e,this.firstIndependentlyClosed=!0;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,ve),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Ft){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(e){if(!this.enabled||e===void 0)return this.reset(),!1;let t=this.firstIndependentlyClosed===!0?this.first:void 0,n=this.secondIndependentlyClosed===!0?this.second:void 0,o=t===void 0||n!==void 0&&n.size>t.size?n:t;if(o===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(Z,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>Z||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=e,this.firstIndependentlyClosed=t,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,this.secondIndependentlyClosed=t,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}hasWithinCrossVersionBudget(e,t){let n=this.passiveProbeBudget;if(n===void 0||n===0)return;let o=e.has(t);return this.passiveProbeBudget=n-1,o}completeDiagnostics(e,t){let n=this.diagnostics;if(n===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let o=this.mapProbes??0;n.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",e,t,o,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var Bt=(e,t)=>new lt(e,t),L=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=ct-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},Ht=(e,t,n,o,r,i=!0,s)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let a=n.visitSelectorDependents;if(a===void 0)return"unsupported";if(s===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let y=s===void 0?void 0:o.getTransientDependencies(n,e);if(y!==void 0){if(y.length===0)return"proven-terminal"}else{let p=n.getSelectorDependencyNodes;if(p!==void 0){let b=p.call(n,e);if(b===void 0||b.length===0)return"proven-terminal"}}}if(!i)return"disabled";let d={remaining:ct},c=[t],l=new Set(c),h=0,u=0,S=1;while(c.length>0){if(d.remaining===0)return L("budget-exhausted",d,h,u,S,r);d.remaining--,h++;let y=c.pop();if(Object.is(y,e))return L("path-possible",d,h,u,S,r);let p=!1,b=(k)=>{if(u++,Object.is(k,e))return p=!0,!1;if(!l.has(k)){if(l.add(k),c.push(k),c.length>S)S=c.length}return!0},J=a.call(n,y,d,b);if(p)return L("path-possible",d,h,u,S,r);if(!J)return L("budget-exhausted",d,h,u,S,r);let D=s?.get(y);if(D!==void 0)for(let k of D){if(d.remaining===0)return L("budget-exhausted",d,h,u,S,r);if(d.remaining--,!b(k))return L("path-possible",d,h,u,S,r)}}return L("proven-reverse",d,h,u,S,r)},Gt=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let u=Ht(e,t,n,o,void 0,r===1?s?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(u==="proven-terminal"||u==="proven-reverse")return;if(u==="budget-exhausted"){if(r===1&&s!==void 0)s.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=s?.(),c=d?.beginSearch()??!1,l=[e],h=new Map([[e,rt]]);while(l.length>0){let u=l.pop();if(Object.is(u,t)){let p=[],b=u;while(b!==rt)p.push(b),b=h.get(b);return p.reverse(),d?.completePositive(),Object.freeze(p)}let S=o.getTransientDependencies(n,u);if(S){if(S.length===0)continue;if(c){let p=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(p)continue}for(let p of S){if(h.has(p.node))continue;h.set(p.node,u),l.push(p.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let p=n.getSelectorDependencyNodes(u);if(p===void 0||p.length===0)continue;if(c){let b=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(b)continue}for(let b of p){if(h.has(b))continue;h.set(b,u),l.push(b)}continue}let y=n.getSelectorRecord(u);if(!y||y.dependencies.length===0)continue;if(c){let p=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(p)continue}for(let p of y.dependencies){if(h.has(p.node))continue;h.set(p.node,u),l.push(p.node)}}d?.completeNegative(h);return},it=(e,t)=>{let n=at(e);if(n.kind==="thenable")return dt(n),new H(t);if(n.kind==="inspection-error")return n.error;return e},st=(e,t)=>{let n=at(e);if(n.kind==="thenable")return dt(n),Object.freeze({kind:"error",error:new H(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},ut=(e,t,n,o=Gt,r,i)=>{let{node:s}=e,a=[],d=t.getSelectorRecord(s),c=d?.dependencies,l=c===void 0?new Set:void 0,h,u=0,S=t.getComparisonBaseline(s),y=!0,p=()=>{let f=l;if(f!==void 0)return f;f=new Set;for(let m of a)f.add(m.node);return l=f,f};n.enter(t,s,a);let b=t.getSelectorGraphVersion(),J=n.getSelectorGraphPublicationCount(t),D=b,k=J,Ue=b,Ke=J,we,Te=!1,Oe=b,le=0,W,Ye=b,ue,Re=(f,m)=>{if(f===Oe)return;if(Oe=f,W===void 0){le=0;return}if(W.advanceGraphVersion(m))return;le=0,r?.graphVersionReset()},Ct=(f)=>{if(f!==Oe)Re(f,void 0);if(le++,(c?.length??0)===0&&le<3){r?.admissionSkipped();return}if(W===void 0){let m=c!==void 0&&c.length>0&&c.length<3;W=Bt(m?3:0,r)}if(!W.enabled){r?.disabled();return}return W},Et=(f)=>{if(Te)return;let m=t.beginSelectorGraphObservation?.(f);if(m===void 0)return;Te=!0,we=m},Ne=(f,m,w,g)=>w-f===g-m,Xe=(f=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),w=Ne(D,k,f,m))=>{if(f===D)return;if(!Te&&t.beginSelectorGraphObservation!==void 0){Re(f,void 0),D=f,k=m;return}let g=we?.takeAddedEdges();if(Re(f,g),w){D=f,k=m;return}if(g!==void 0){let R=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,_t,i),V=g.length===0?void 0:{transientDependents:R,reverseProofEnabled:!0},T=!1;for(let F of g)if(o(F.head,F.tail,t,n,2,a.length,void 0,V)!==void 0){T=!0;break}if(!T){D=f,k=m;return}}for(let R=0;R<a.length;R++){let V=a[R],T=o(V.node,s,t,n,0,a.length);if(!T)continue;if(l!==void 0)for(let I=a.length-1;I>=R;I--)l.delete(a[I].node);if(a.length=R,u++,n.getControlFault().kind==="fault")return;let N=new ne(s,[s,...T]);n.latchCycle(t,s,N);return}D=f,k=m},Ce=()=>{let f=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Ue=f,Ke=m;let w=Ne(D,k,f,m);if(!w)n.revalidateAncestorPrefixes(t,s);Xe(f,m,w)};n.setPrefixRevalidator(t,s,Xe);let Dt=(f)=>{if(!y)throw new Ve;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let w=n.getCycle(t,s);if(w!==void 0)throw w;let g=n.activeCyclePath(t,f);if(g){let A=new ne(s,g);throw n.latchCycle(t,s,A),A}let R=a.length,V,T=!1;if(l===void 0){let A=c?.[R];if(A!==void 0&&Object.is(A.node,f))V=!1,T=!0;else V=p().has(f)}else V=l.has(f);if(!V&&!T&&c!==void 0&&c.length>0){let A=c[a.length];if(A!==void 0&&Object.is(A.node,f))T=!0;else{if(h===void 0){h=new Set;for(let U of c)h.add(U.node)}T=h.has(f)}}let F=u,N=t.serve(f,n);Ce();let I=n.getCycle(t,s);if(I!==void 0)throw I;let ee=l!==void 0?l.has(f):u===F&&a.length===R?!1:p().has(f),_=Ue,q=Ke,M=ee||T&&_===b,fe=c===void 0&&Ne(b,J,_,q);if(!M&&!fe){if(Ye=_,ue===void 0)ue=()=>Ct(Ye),ue.reverseProofEnabled=!0;let A=o(f,s,t,n,1,a.length,ue);if(A){let U=n.getControlFault();if(U.kind==="fault")throw U.error;let $e=new ne(s,[s,...A]);throw n.latchCycle(t,s,$e),$e}}if(!ee){let A=d?.dependencies[a.length];l?.add(f),a.push(A!==void 0&&Object.is(A.node,f)&&Object.is(A.token,N.token)?A:Object.freeze({node:f,token:N.token})),Et(f)}if(D=_,k=q,N.outcome.kind==="control-error"){n.latchControlFault(N.outcome.error);let A=n.getControlFault();if(A.kind==="fault")throw A.error;throw N.outcome.error}let te=n.getControlFault();if(te.kind==="fault")throw te.error;if(N.outcome.kind==="error")throw new Ee(f,N.outcome.error);return N.outcome.value};try{let f,m,w=!1;try{f=e.get(Dt)}catch(I){w=!0,m=I}finally{y=!1}if(w)m=it(m,"getter");let g=w?void 0:st(f,"getter");Ce();let R=n.getControlFault();if(R.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:R.error},a);let V=n.getCycle(t,s);if(V!==void 0)return C(s,t.createOutcomeToken(),{kind:"error",error:V},a);if(w)return C(s,t.createOutcomeToken(),{kind:"error",error:m instanceof H?m:new he(s,m)},a);if(g===void 0)throw Error("Selector result classification was not completed");let T=n.getControlFault();if(T.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:T.error},a);if(g.kind==="error")return C(s,t.createOutcomeToken(),{kind:"error",error:g.error instanceof H?g.error:new he(s,g.error)},a);let F=g.value,N;if(S){let I=e.equal??Object.is,ee,_,q=!1;try{ee=I(S.value,F)}catch(U){q=!0,_=it(U,"comparator")}let M=q?void 0:st(ee,"comparator");Ce();let fe=n.getControlFault();if(fe.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:fe.error},a);let te=n.getCycle(t,s);if(te!==void 0)return C(s,t.createOutcomeToken(),{kind:"error",error:te},a);if(q)return C(s,t.createOutcomeToken(),{kind:"error",error:_ instanceof H?_:new Se(s,_)},a);if(M===void 0)throw Error("Selector comparator classification was not completed");let A=n.getControlFault();if(A.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:A.error},a);if(M.kind==="error")return C(s,t.createOutcomeToken(),{kind:"error",error:M.error instanceof H?M.error:new Se(s,M.error)},a);if(M.value!==!0&&M.value!==!1)return C(s,t.createOutcomeToken(),{kind:"error",error:new De},a);if(M.value===!0)F=S.value,N=S.current?S.token:void 0}return C(s,N??t.createOutcomeToken(),{kind:"value",value:F},a)}finally{try{we?.close()}finally{n.leave(t,s)}}};class v{#t=[];#n;#o=0;#i;#s=Lt;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))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#t){if(!Object.is(o.host,e))continue;if(n||!Object.is(o.selector,t))return!1;n=!0}return n}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}captureTransientReverseDependents(e,t,n,o,r){let i=new Set,s=new Map,a=!1,d=0,c=0,l=0;for(let u of this.#t){if(d++,d>o){r?.recordSnapshot("overflow",d,c,l);return}if(!Object.is(u.host,e))continue;if(c++,u.revalidatePrefix===void 0||i.has(u.selector)){r?.recordSnapshot("unavailable",d,c,l);return}if(i.add(u.selector),Object.is(u.selector,t)){if(a||u.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,c,l);return}a=!0}for(let S of u.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,c,l);return}let y=s.get(S.node);if(y===void 0)s.set(S.node,[u.selector]);else y.push(u.selector)}}if(!a){r?.recordSnapshot("unavailable",d,c,l);return}let h=new Map;for(let[u,S]of s)h.set(u,Object.freeze(S));return r?.recordSnapshot("completed",d,c,l),h}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 Lt=Object.freeze({kind:"none"});var ft=Symbol("no-committed-selector-baseline");class ge{#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 v,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 d=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,d),d}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)??ft,this.#i.set(e,t);return t===ft?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}}var ht=4096,Wt=Object.freeze([]);class pt{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)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}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 ke{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=0;#d;#l=!1;#h;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#m(),this.#n=this.#m()}get status(){return this.#u}get facade(){if(this.#h===void 0)throw Error("Store scope facade is not installed");return this.#h}installFacade(e){if(this.#h!==void 0)throw Error("Store scope facade is already installed");this.#h=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="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.#m()};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,this.#a++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(K(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=de(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#b(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}visitSelectorDependents(e,t,n){return this.#s.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#a}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#c===0)this.#d=[],this.#l=!1;this.#c++;let t=this.#d?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#d;if(o===void 0)return;if(t===o.length)return Wt;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#c--,this.#c!==0)return;this.#d=void 0,this.#l=!1}})}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()}#b(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}),s=this.#y(e,o?.dependencies??St,t.dependencies),a=s?this.#S(e,o?.dependencies??St,t.dependencies):void 0;if(s)this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),a!==void 0)this.#p(a);if(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}#y(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.#m(),this.#s.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#c===0||this.#l)return;let o=this.#d;if(o===void 0){this.#e();return}let r=ht-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let d of t)if(i.has(d.node))s.add(d.node);let a=[];for(let d of n)if(i.has(d.node)&&!s.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#e();return}}return a}#p(e){if(e.length===0)return;let t=this.#d;if(t===void 0||t.length+e.length>ht){this.#e();return}t.push(...e)}#e(){if(this.#c===0)return;this.#d=[],this.#l=!0}#m(){return new pt(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var St=Object.freeze([]);class _e{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#l;#h;#u;#b;#y;#S;#p;#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.#f(),n.set(e,i);i.set(t.atom,t),this.#m();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#f();i.set(this.#n,o);let s=this.#f();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#m();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#m();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#m();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#m();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#m();return}let s=this.#f();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#f(),s=this.#f();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.#f();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.#m()}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.#l,t))return this.#h;if(Object.is(this.#a,e))return this.#u?.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.#f(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#a,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#b=s,this.#u=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.#l=t,this.#h=n;return}if(Object.is(this.#l,t))return;let a=this.#f();a.set(this.#c,i),a.set(this.#l,s),a.set(t,n),this.#u=a}else{let s=this.#f(),a=this.#f();if(a.set(this.#c,i),this.#l!==void 0&&this.#h!==void 0)a.set(this.#l,this.#h);s.set(this.#a,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#l=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#y,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#y,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#y=e,this.#S=t;return}if(Object.is(this.#y,e)){this.#S=t;return}let o=this.#f();o.set(this.#y,this.#S),o.set(e,t),this.#p=o,this.#y=void 0,this.#S=void 0}forEachFallback(e){if(this.#y!==void 0&&this.#S!==void 0)e(this.#y,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#m(){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.#u?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.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.#l=void 0,this.#h=void 0,this.#u=void 0,this.#b=void 0,this.#y=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class mt{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]),ce(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Be=(e,t,n)=>new mt(e,t,n),He=(e)=>{let t=P(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw x(t),new oe},yt=(e)=>{let t=P(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw x(t),new oe};var qt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},Tt=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}),Ut=32,Ot=new WeakMap,yn=()=>{let e=new Uint32Array(Ut),t=Object.freeze({read(n){return e[Tt[n]]??0}});return Ot.set(t,e),t},E=(e)=>Object.freeze({kind:"value",value:e}),Kt=(e)=>Object.freeze({kind:"error",error:e}),bt=(e)=>e.kind==="value"?E(e.value):Kt(e.error),At=(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)},vt=1,Ge=2,gt=4,Yt=(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}),We=(e)=>(e.onAllocation?.(),new Map),Xt=(e)=>(e.onAllocation?.(),new Set),Le=(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)},kt=(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=We(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=We(e),r.set(t,i);i.set(n,o)},$t=(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=Xt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Qt=(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=We(e),e.affected=o;o.set(t,n)};class Rt{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#l;#h;#u;#b=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:Ot.get(t),this.#f=n,this.evaluate=n?.evaluate??ut,this.#n=new ke(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#m!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#m;if(n===void 0)return;n[Tt[e]]+=t}#T(){return this.recordCounter("draftCreations"),new _e(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new v,o=t,r=z(this.#e,o,n),i=Fe(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":z(this.#e,o,r=new v);if(j(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 v);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#u;if(a===void 0){if(a=new Map,this.#u=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let d=a.get(e);if(d===void 0){if(d=new Map,a.set(e,d),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let c=d.get(o);if(c===void 0){if(c={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,c),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:c,previous:c.tail,next:void 0};if(c.tail===void 0)c.head=l;else c.tail.next=l;if(c.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return qt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;tt(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.#u,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.#u=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)z(this.#e,n,new v);if(j(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#P(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.#P(e,n)}dispose(e){if(j(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.#$(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(j(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=Be(this,o,e),i;try{i=et(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new v;ye(this.#e,s,()=>He(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new v,o=t,r=z(this.#e,o,n);if(j(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.#v(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,d)=>{if(this.#t.has(a))return;this.#t.set(a,d),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new v,i=z(this.#e,o,r);if(be(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.#v(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.#U(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new v;this.#R(e,t,r,i,"Transaction.set"),this.#j(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new v;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 v;this.#R(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new v;if(typeof n!=="string")z(this.#e,n,i);be(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=Be(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let d;try{d=r(a)}catch(l){let h=new v;return ye(this.#e,h,()=>yt(l))}let c=new v;return ye(this.#e,c,()=>He(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#U(e,t){return this.recordCounter("scratchHostAllocations"),new ge(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>de(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new ge(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>de(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(K(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})}#P(e,t){let n=new ke(this,e,t);this.recordCounter("scopeNodesCreated");let o=new qe(this,n,this.#f);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 Ie;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 Me;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new pe;throw new me}throw new me}#A(e){if(e.status!=="live")throw new je}#X(e,t,n,o){let r=z(this.#e,t,n);j(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new v;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#j(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#M(a,e,i,s)}catch(d){throw a.close(),a.release(),d}a.close();try{this.#F(a)}finally{a.release()}}#$(e){let t=this.#u,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.#u=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=z(this.#e,n,o);be(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`)}#j(e,t,n,o,r){let i=G(this.#e,r,()=>se(o));if(i.kind==="error")throw i.error;let s=this.#N(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.#N(e,t,n,r),a=e.hasIntents?this.#v(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let d=this.#J(o,a.value,r);this.#q(e,t,n,d,s,r)}#M(e,t,n,o){this.#N(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#z(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}))}#N(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=E(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,c=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}#v(e,t,n,o){return this.#z(e,t,n,o).outcome}#z(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:E(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:E(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#g(t);if(r.fallback.kind==="eager")return E(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=bt(G(this.#e,n,()=>ze(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#g(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#Z(r,t,n,o)?t:n}#Z(e,t,n,o){return G(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=P(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw x(a),new ie}let i=P(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw x(i),new ie;if(r!==!0&&r!==!1)throw new ie;return r})}#J(e,t,n){return G(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=P(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw x(s),new re}let r=se(o);if(r.kind==="error")throw r.error;return r.value})}#F(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=Yt(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,d)=>{let c=this.#_(e,a,d,o);if(r===void 0){r=c;return}if(i===void 0)i=[];i.push(c)});if(r===void 0)return;if(this.#f?.(1,e,this.#e.atoms),this.#B(e,r),i!==void 0)for(let a of i)this.#B(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let d=this.#H(a);s||=d}if(this.#G(r),i!==void 0)for(let a of i)this.#G(a);this.#se();try{let a,d,c=o.affectedRecord,l=o.affectedBefore;if(c!==void 0&&l!==void 0)a=this.#E(o,c,l);let{secondAffectedRecord:h,secondAffectedBefore:u}=o;if(h!==void 0&&u!==void 0){let S=this.#E(o,h,u);if(S!==void 0)if(a===void 0)a=S;else d=[S]}if(o.affected!==void 0)for(let[S,y]of o.affected){let p=this.#E(o,S,y);if(p===void 0)continue;if(a===void 0)a=p;else{if(d===void 0)d=[];d.push(p)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(d?.length??0)),this.#ie(a,d)}catch(a){throw this.#k(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(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}#B(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")}#H(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}#G({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))}#E(e,t,n){let o=Le(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),At(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(!$t(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(At(i,s))continue;Qt(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),o.push(d)});for(let d=a,c=o.length-1;d<c;d++,c--){let l=o[d];o[d]=o[c],o[c]=l}}}#L(e,t,n,o){let r=Le(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=Le(o,n,i);if(c!==void 0){d=c;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"){d=E(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=E(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)kt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)kt(o,n,c,d),this.recordCounter("finalPreflightVisits");return d}#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.#g(t);if(r.fallback.kind==="eager")return E(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.#g(e);if(n.fallback.kind==="eager")return E(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,E(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,E(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.#g(e);if(o.fallback.kind==="eager")return E(o.fallback.value);let r=o.fallback.initialize,i=bt(G(this.#e,t,()=>ze(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#g(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.#k();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#l=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.#D(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.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#p=void 0,this.#y=this.#u===void 0?0:this.#b++}#k(){this.#y=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#y,o=this.#u?.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.#p===void 0)this.#p=[o];else this.#p.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#k(),e!==void 0)throw e;return}let n,o,r=(c)=>{let l=c.head;while(l!==void 0){let h=l.callback;if(h!==void 0)if(n===void 0)n=h;else if(o===void 0)o=[n,h];else o.push(h);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let c of i)r(c);if(this.#k(),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 d;for(let c of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new v,h=!1,u;try{Je(this.#e,l,()=>{try{let S=c(),y=P(S);if(y.kind==="thenable")x(y);else if(y.kind==="inspection-error")h=!0,u=y.error}catch(S){h=!0,u=S;let y=P(S);if(y.kind==="thenable")x(y)}})}catch(S){h=!0,u=S}if(h){if(d===void 0)d=[];if(d.push(u),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new xe(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&vt)!==0)return!0;return this.#w(e,t,vt),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#D(e,t,n)}#D(e,t,n){if((this.#W(e,t)&(gt|Ge))!==0)return;this.#w(e,t,Ge);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.#D(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 v)}this.#w(e,t,gt)}finally{this.#w(e,t,0,Ge)}}#W(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#l?.get(e)?.get(t)??0}#w(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.#l;if(r===void 0)r=new Map,this.#l=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.#Q(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 qe{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),ce(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var wt=(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}}},Nt=(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=(d,c={})=>{let l=new v,h=G(t,l,()=>se(d));if(h.kind==="error")throw h.error;let u=Ae("atom",t.ownerToken);return t.states.add(u),t.atoms.set(u,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...wt(c)})),u},o=(d,c={})=>{if(typeof d!=="function")throw TypeError("atomLazy requires an initializer function");let l=Ae("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:d}),...wt(c)})),l},r=(d,c={})=>{if(typeof d!=="function")throw TypeError("selector requires a getter function");if(c.equal!==void 0&&typeof c.equal!=="function")throw TypeError("selector equal must be a function");let l=Ae("selector",t.ownerToken),h=Object.freeze({node:l,get:d,...c.name===void 0?{}:{name:c.name},...c.equal===void 0?{}:{equal:c.equal}});return t.states.add(l),t.selectors.set(l,h),l},i=(d)=>{let c=new v;if(z(t,d,c)==="invalid")return;return t.stores.get(d)},a=Object.freeze({assertStore:(d)=>{let c=i(d);if(j(t,"adapter assertStore"),c===void 0)throw TypeError("assertStore requires a valid Store")},read:(d,c)=>{if(i(d)===void 0)throw Fe(t,"adapter read"),TypeError("read requires a valid Store");return d.get(c)},subscribe:(d,c,l)=>{if(i(d)===void 0)throw j(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return d.sub(c,l)},readHydrationSnapshot:(d,c)=>{let l=i(d);if(l===void 0)throw j(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,c)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(d=e,c)=>{j(t,"createStoreTree");let l=new Rt(t,d,c);return new qe(l,l.rootScope,c)}})};var Zt=Nt(),vn=(e,t)=>Zt.createStoreTree(e,t);
2
+ export{ne as a,Ht as b,ut as c,Pe as d,xe as e,Y as f,X as g,Q as h,pe as i,oe as j,re as k,ie as l,je as m,Ie as n,Me as o,me as p,yn as q,Zt as r,vn as s};
@@ -1 +1 @@
1
- import{r as e}from"../chunk-fbqtxaaa.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{r as e}from"../chunk-y5ja7h9m.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 B extends Error{seal(){Object.freeze(this)}}class he extends B{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 Ee extends B{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 ne extends B{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 H extends B{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 De extends B{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class Se extends B{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 Ve extends B{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Qe=Object.freeze({kind:"not-thenable"}),Vt=()=>{},Pt=Reflect.apply,Ze=Symbol.for("valdres.runtime-owner/v1");class O extends Error{seal(){Object.freeze(this)}}class Pe extends O{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class xe extends O{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 Y extends O{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class X extends O{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class Q extends O{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class pe extends O{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class oe extends O{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class re extends O{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ie extends O{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class je extends O{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class Ie extends O{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Me extends O{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class me extends O{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var P=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Qe;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Qe}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},x=(e)=>{try{Pt(e.then,e.target,[void 0,Vt])}catch{}},se=(e)=>{let t=P(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 x(t),Object.freeze({kind:"error",error:new re})},ze=(e)=>{try{return se(e())}catch(t){let n=P(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 x(n),Object.freeze({kind:"error",error:new re})}},ae=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},G=(e,t,n)=>{try{let o=ae(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}},Je=(e,t,n)=>{try{let o=ae(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}},de=(e,t,n)=>ae(e,Object.freeze({kind:"selector",session:t}),n),et=(e,t,n)=>ae(e,Object.freeze({kind:"transaction",transaction:t}),n),ye=(e,t,n)=>{try{let o=ae(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}},j=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new X(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Q;throw new Y},Fe=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new X(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Q;throw new Y},tt=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new X("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new Q;throw new Y},be=(e,t,n)=>{if(!n)throw new pe;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new X("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new Y;throw new Q},nt=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},K=(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,Ze);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Pe;throw nt(e,n).latchControlFault(r),r}}return"invalid"},z=(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=nt(e,n);if(o!==void 0&&"session"in o)try{let i=K(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 G(e,r,()=>K(e,t,r))},ce=(e,t)=>(Object.defineProperty(e,Ze,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),Ae=(e,t)=>Object.freeze(ce({kind:e},t));var ot=Object.freeze({kind:"not-thenable"}),xt=()=>{},jt=Reflect.apply,rt=Symbol("selector dependency path root"),at=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return ot;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):ot}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},dt=(e)=>{try{jt(e.then,e.target,[void 0,xt])}catch{}},It=(e)=>Object.freeze(e),Mt=(e)=>Object.freeze(e),C=(e,t,n,o)=>{let r=Mt(o);return Object.freeze({selector:e,token:t,outcome:It(n),dependencies:r,attemptedPrefix:n.kind==="value"?zt:Object.freeze(r.map((i)=>i.node))})},zt=Object.freeze([]),ve=32,Z=8192,Ft=2*ve,ct=128,_t=4096;class lt{passiveSearches;searches=0;constructor(e,t){if(this.passiveSearches=e,t!==void 0)this.diagnostics=t}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let e=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(e)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(e&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(Z,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,t.has(e))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,n.has(e))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(e){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let n=e.size>=ve&&e.size<=Z,o;if(this.searches===1&&n)this.first=e,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>Z){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=ve&&e.size<=Z;if(this.first===void 0){if(t)this.first=e,this.firstIndependentlyClosed=!0;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,ve),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Ft){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(e){if(!this.enabled||e===void 0)return this.reset(),!1;let t=this.firstIndependentlyClosed===!0?this.first:void 0,n=this.secondIndependentlyClosed===!0?this.second:void 0,o=t===void 0||n!==void 0&&n.size>t.size?n:t;if(o===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(Z,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>Z||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=e,this.firstIndependentlyClosed=t,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,this.secondIndependentlyClosed=t,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}hasWithinCrossVersionBudget(e,t){let n=this.passiveProbeBudget;if(n===void 0||n===0)return;let o=e.has(t);return this.passiveProbeBudget=n-1,o}completeDiagnostics(e,t){let n=this.diagnostics;if(n===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let o=this.mapProbes??0;n.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",e,t,o,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var Bt=(e,t)=>new lt(e,t),L=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=ct-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},Ht=(e,t,n,o,r,i=!0,s)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let a=n.visitSelectorDependents;if(a===void 0)return"unsupported";if(s===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let y=s===void 0?void 0:o.getTransientDependencies(n,e);if(y!==void 0){if(y.length===0)return"proven-terminal"}else{let p=n.getSelectorDependencyNodes;if(p!==void 0){let b=p.call(n,e);if(b===void 0||b.length===0)return"proven-terminal"}}}if(!i)return"disabled";let d={remaining:ct},c=[t],l=new Set(c),h=0,u=0,S=1;while(c.length>0){if(d.remaining===0)return L("budget-exhausted",d,h,u,S,r);d.remaining--,h++;let y=c.pop();if(Object.is(y,e))return L("path-possible",d,h,u,S,r);let p=!1,b=(k)=>{if(u++,Object.is(k,e))return p=!0,!1;if(!l.has(k)){if(l.add(k),c.push(k),c.length>S)S=c.length}return!0},J=a.call(n,y,d,b);if(p)return L("path-possible",d,h,u,S,r);if(!J)return L("budget-exhausted",d,h,u,S,r);let D=s?.get(y);if(D!==void 0)for(let k of D){if(d.remaining===0)return L("budget-exhausted",d,h,u,S,r);if(d.remaining--,!b(k))return L("path-possible",d,h,u,S,r)}}return L("proven-reverse",d,h,u,S,r)},Gt=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let u=Ht(e,t,n,o,void 0,r===1?s?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(u==="proven-terminal"||u==="proven-reverse")return;if(u==="budget-exhausted"){if(r===1&&s!==void 0)s.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=s?.(),c=d?.beginSearch()??!1,l=[e],h=new Map([[e,rt]]);while(l.length>0){let u=l.pop();if(Object.is(u,t)){let p=[],b=u;while(b!==rt)p.push(b),b=h.get(b);return p.reverse(),d?.completePositive(),Object.freeze(p)}let S=o.getTransientDependencies(n,u);if(S){if(S.length===0)continue;if(c){let p=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(p)continue}for(let p of S){if(h.has(p.node))continue;h.set(p.node,u),l.push(p.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let p=n.getSelectorDependencyNodes(u);if(p===void 0||p.length===0)continue;if(c){let b=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(b)continue}for(let b of p){if(h.has(b))continue;h.set(b,u),l.push(b)}continue}let y=n.getSelectorRecord(u);if(!y||y.dependencies.length===0)continue;if(c){let p=d.hasProvenNoPath(u);if(!d.enabled)c=!1;if(p)continue}for(let p of y.dependencies){if(h.has(p.node))continue;h.set(p.node,u),l.push(p.node)}}d?.completeNegative(h);return},it=(e,t)=>{let n=at(e);if(n.kind==="thenable")return dt(n),new H(t);if(n.kind==="inspection-error")return n.error;return e},st=(e,t)=>{let n=at(e);if(n.kind==="thenable")return dt(n),Object.freeze({kind:"error",error:new H(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},ut=(e,t,n,o=Gt,r,i)=>{let{node:s}=e,a=[],d=t.getSelectorRecord(s),c=d?.dependencies,l=c===void 0?new Set:void 0,h,u=0,S=t.getComparisonBaseline(s),y=!0,p=()=>{let f=l;if(f!==void 0)return f;f=new Set;for(let m of a)f.add(m.node);return l=f,f};n.enter(t,s,a);let b=t.getSelectorGraphVersion(),J=n.getSelectorGraphPublicationCount(t),D=b,k=J,Ue=b,Ke=J,we,Te=!1,Oe=b,le=0,W,Ye=b,ue,Re=(f,m)=>{if(f===Oe)return;if(Oe=f,W===void 0){le=0;return}if(W.advanceGraphVersion(m))return;le=0,r?.graphVersionReset()},Ct=(f)=>{if(f!==Oe)Re(f,void 0);if(le++,(c?.length??0)===0&&le<3){r?.admissionSkipped();return}if(W===void 0){let m=c!==void 0&&c.length>0&&c.length<3;W=Bt(m?3:0,r)}if(!W.enabled){r?.disabled();return}return W},Et=(f)=>{if(Te)return;let m=t.beginSelectorGraphObservation?.(f);if(m===void 0)return;Te=!0,we=m},Ne=(f,m,w,g)=>w-f===g-m,Xe=(f=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),w=Ne(D,k,f,m))=>{if(f===D)return;if(!Te&&t.beginSelectorGraphObservation!==void 0){Re(f,void 0),D=f,k=m;return}let g=we?.takeAddedEdges();if(Re(f,g),w){D=f,k=m;return}if(g!==void 0){let R=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,_t,i),V=g.length===0?void 0:{transientDependents:R,reverseProofEnabled:!0},T=!1;for(let F of g)if(o(F.head,F.tail,t,n,2,a.length,void 0,V)!==void 0){T=!0;break}if(!T){D=f,k=m;return}}for(let R=0;R<a.length;R++){let V=a[R],T=o(V.node,s,t,n,0,a.length);if(!T)continue;if(l!==void 0)for(let I=a.length-1;I>=R;I--)l.delete(a[I].node);if(a.length=R,u++,n.getControlFault().kind==="fault")return;let N=new ne(s,[s,...T]);n.latchCycle(t,s,N);return}D=f,k=m},Ce=()=>{let f=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);Ue=f,Ke=m;let w=Ne(D,k,f,m);if(!w)n.revalidateAncestorPrefixes(t,s);Xe(f,m,w)};n.setPrefixRevalidator(t,s,Xe);let Dt=(f)=>{if(!y)throw new Ve;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let w=n.getCycle(t,s);if(w!==void 0)throw w;let g=n.activeCyclePath(t,f);if(g){let A=new ne(s,g);throw n.latchCycle(t,s,A),A}let R=a.length,V,T=!1;if(l===void 0){let A=c?.[R];if(A!==void 0&&Object.is(A.node,f))V=!1,T=!0;else V=p().has(f)}else V=l.has(f);if(!V&&!T&&c!==void 0&&c.length>0){let A=c[a.length];if(A!==void 0&&Object.is(A.node,f))T=!0;else{if(h===void 0){h=new Set;for(let U of c)h.add(U.node)}T=h.has(f)}}let F=u,N=t.serve(f,n);Ce();let I=n.getCycle(t,s);if(I!==void 0)throw I;let ee=l!==void 0?l.has(f):u===F&&a.length===R?!1:p().has(f),_=Ue,q=Ke,M=ee||T&&_===b,fe=c===void 0&&Ne(b,J,_,q);if(!M&&!fe){if(Ye=_,ue===void 0)ue=()=>Ct(Ye),ue.reverseProofEnabled=!0;let A=o(f,s,t,n,1,a.length,ue);if(A){let U=n.getControlFault();if(U.kind==="fault")throw U.error;let $e=new ne(s,[s,...A]);throw n.latchCycle(t,s,$e),$e}}if(!ee){let A=d?.dependencies[a.length];l?.add(f),a.push(A!==void 0&&Object.is(A.node,f)&&Object.is(A.token,N.token)?A:Object.freeze({node:f,token:N.token})),Et(f)}if(D=_,k=q,N.outcome.kind==="control-error"){n.latchControlFault(N.outcome.error);let A=n.getControlFault();if(A.kind==="fault")throw A.error;throw N.outcome.error}let te=n.getControlFault();if(te.kind==="fault")throw te.error;if(N.outcome.kind==="error")throw new Ee(f,N.outcome.error);return N.outcome.value};try{let f,m,w=!1;try{f=e.get(Dt)}catch(I){w=!0,m=I}finally{y=!1}if(w)m=it(m,"getter");let g=w?void 0:st(f,"getter");Ce();let R=n.getControlFault();if(R.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:R.error},a);let V=n.getCycle(t,s);if(V!==void 0)return C(s,t.createOutcomeToken(),{kind:"error",error:V},a);if(w)return C(s,t.createOutcomeToken(),{kind:"error",error:m instanceof H?m:new he(s,m)},a);if(g===void 0)throw Error("Selector result classification was not completed");let T=n.getControlFault();if(T.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:T.error},a);if(g.kind==="error")return C(s,t.createOutcomeToken(),{kind:"error",error:g.error instanceof H?g.error:new he(s,g.error)},a);let F=g.value,N;if(S){let I=e.equal??Object.is,ee,_,q=!1;try{ee=I(S.value,F)}catch(U){q=!0,_=it(U,"comparator")}let M=q?void 0:st(ee,"comparator");Ce();let fe=n.getControlFault();if(fe.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:fe.error},a);let te=n.getCycle(t,s);if(te!==void 0)return C(s,t.createOutcomeToken(),{kind:"error",error:te},a);if(q)return C(s,t.createOutcomeToken(),{kind:"error",error:_ instanceof H?_:new Se(s,_)},a);if(M===void 0)throw Error("Selector comparator classification was not completed");let A=n.getControlFault();if(A.kind==="fault")return C(s,t.createOutcomeToken(),{kind:"control-error",error:A.error},a);if(M.kind==="error")return C(s,t.createOutcomeToken(),{kind:"error",error:M.error instanceof H?M.error:new Se(s,M.error)},a);if(M.value!==!0&&M.value!==!1)return C(s,t.createOutcomeToken(),{kind:"error",error:new De},a);if(M.value===!0)F=S.value,N=S.current?S.token:void 0}return C(s,N??t.createOutcomeToken(),{kind:"value",value:F},a)}finally{try{we?.close()}finally{n.leave(t,s)}}};class v{#t=[];#n;#o=0;#i;#s=Lt;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))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#t){if(!Object.is(o.host,e))continue;if(n||!Object.is(o.selector,t))return!1;n=!0}return n}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}captureTransientReverseDependents(e,t,n,o,r){let i=new Set,s=new Map,a=!1,d=0,c=0,l=0;for(let u of this.#t){if(d++,d>o){r?.recordSnapshot("overflow",d,c,l);return}if(!Object.is(u.host,e))continue;if(c++,u.revalidatePrefix===void 0||i.has(u.selector)){r?.recordSnapshot("unavailable",d,c,l);return}if(i.add(u.selector),Object.is(u.selector,t)){if(a||u.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,c,l);return}a=!0}for(let S of u.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,c,l);return}let y=s.get(S.node);if(y===void 0)s.set(S.node,[u.selector]);else y.push(u.selector)}}if(!a){r?.recordSnapshot("unavailable",d,c,l);return}let h=new Map;for(let[u,S]of s)h.set(u,Object.freeze(S));return r?.recordSnapshot("completed",d,c,l),h}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 Lt=Object.freeze({kind:"none"});var ft=Symbol("no-committed-selector-baseline");class ge{#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 v,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 d=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,d),d}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)??ft,this.#i.set(e,t);return t===ft?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}}var ht=4096,Wt=Object.freeze([]);class pt{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)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}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 ke{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=0;#d;#l=!1;#h;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#m(),this.#n=this.#m()}get status(){return this.#u}get facade(){if(this.#h===void 0)throw Error("Store scope facade is not installed");return this.#h}installFacade(e){if(this.#h!==void 0)throw Error("Store scope facade is already installed");this.#h=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="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.#m()};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,this.#a++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(K(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=de(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#b(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}visitSelectorDependents(e,t,n){return this.#s.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#a}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#c===0)this.#d=[],this.#l=!1;this.#c++;let t=this.#d?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#d;if(o===void 0)return;if(t===o.length)return Wt;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#c--,this.#c!==0)return;this.#d=void 0,this.#l=!1}})}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()}#b(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}),s=this.#y(e,o?.dependencies??St,t.dependencies),a=s?this.#S(e,o?.dependencies??St,t.dependencies):void 0;if(s)this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),a!==void 0)this.#p(a);if(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}#y(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.#m(),this.#s.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#c===0||this.#l)return;let o=this.#d;if(o===void 0){this.#e();return}let r=ht-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let d of t)if(i.has(d.node))s.add(d.node);let a=[];for(let d of n)if(i.has(d.node)&&!s.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#e();return}}return a}#p(e){if(e.length===0)return;let t=this.#d;if(t===void 0||t.length+e.length>ht){this.#e();return}t.push(...e)}#e(){if(this.#c===0)return;this.#d=[],this.#l=!0}#m(){return new pt(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var St=Object.freeze([]);class _e{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#l;#h;#u;#b;#y;#S;#p;#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.#f(),n.set(e,i);i.set(t.atom,t),this.#m();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#f();i.set(this.#n,o);let s=this.#f();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#m();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#m();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#m();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#m();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#m();return}let s=this.#f();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#f(),s=this.#f();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.#f();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.#m()}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.#l,t))return this.#h;if(Object.is(this.#a,e))return this.#u?.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.#f(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#a,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#b=s,this.#u=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.#l=t,this.#h=n;return}if(Object.is(this.#l,t))return;let a=this.#f();a.set(this.#c,i),a.set(this.#l,s),a.set(t,n),this.#u=a}else{let s=this.#f(),a=this.#f();if(a.set(this.#c,i),this.#l!==void 0&&this.#h!==void 0)a.set(this.#l,this.#h);s.set(this.#a,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#l=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#y,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#y,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#y=e,this.#S=t;return}if(Object.is(this.#y,e)){this.#S=t;return}let o=this.#f();o.set(this.#y,this.#S),o.set(e,t),this.#p=o,this.#y=void 0,this.#S=void 0}forEachFallback(e){if(this.#y!==void 0&&this.#S!==void 0)e(this.#y,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#m(){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.#u?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.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.#l=void 0,this.#h=void 0,this.#u=void 0,this.#b=void 0,this.#y=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class mt{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]),ce(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Be=(e,t,n)=>new mt(e,t,n),He=(e)=>{let t=P(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw x(t),new oe},yt=(e)=>{let t=P(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw x(t),new oe};var qt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},Tt=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}),Ut=32,Ot=new WeakMap,yn=()=>{let e=new Uint32Array(Ut),t=Object.freeze({read(n){return e[Tt[n]]??0}});return Ot.set(t,e),t},E=(e)=>Object.freeze({kind:"value",value:e}),Kt=(e)=>Object.freeze({kind:"error",error:e}),bt=(e)=>e.kind==="value"?E(e.value):Kt(e.error),At=(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)},vt=1,Ge=2,gt=4,Yt=(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}),We=(e)=>(e.onAllocation?.(),new Map),Xt=(e)=>(e.onAllocation?.(),new Set),Le=(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)},kt=(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=We(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=We(e),r.set(t,i);i.set(n,o)},$t=(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=Xt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Qt=(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=We(e),e.affected=o;o.set(t,n)};class Rt{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#l;#h;#u;#b=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:Ot.get(t),this.#f=n,this.evaluate=n?.evaluate??ut,this.#n=new ke(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#m!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#m;if(n===void 0)return;n[Tt[e]]+=t}#T(){return this.recordCounter("draftCreations"),new _e(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new v,o=t,r=z(this.#e,o,n),i=Fe(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":z(this.#e,o,r=new v);if(j(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 v);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#u;if(a===void 0){if(a=new Map,this.#u=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let d=a.get(e);if(d===void 0){if(d=new Map,a.set(e,d),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let c=d.get(o);if(c===void 0){if(c={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,c),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:c,previous:c.tail,next:void 0};if(c.tail===void 0)c.head=l;else c.tail.next=l;if(c.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return qt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;tt(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.#u,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.#u=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)z(this.#e,n,new v);if(j(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#P(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.#P(e,n)}dispose(e){if(j(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.#$(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(j(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=Be(this,o,e),i;try{i=et(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new v;ye(this.#e,s,()=>He(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new v,o=t,r=z(this.#e,o,n);if(j(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.#v(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,d)=>{if(this.#t.has(a))return;this.#t.set(a,d),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new v,i=z(this.#e,o,r);if(be(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.#v(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.#U(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new v;this.#R(e,t,r,i,"Transaction.set"),this.#j(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new v;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 v;this.#R(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new v;if(typeof n!=="string")z(this.#e,n,i);be(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=Be(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let d;try{d=r(a)}catch(l){let h=new v;return ye(this.#e,h,()=>yt(l))}let c=new v;return ye(this.#e,c,()=>He(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#U(e,t){return this.recordCounter("scratchHostAllocations"),new ge(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>de(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new ge(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>de(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(K(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})}#P(e,t){let n=new ke(this,e,t);this.recordCounter("scopeNodesCreated");let o=new qe(this,n,this.#f);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 Ie;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 Me;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new pe;throw new me}throw new me}#A(e){if(e.status!=="live")throw new je}#X(e,t,n,o){let r=z(this.#e,t,n);j(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new v;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#j(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#M(a,e,i,s)}catch(d){throw a.close(),a.release(),d}a.close();try{this.#F(a)}finally{a.release()}}#$(e){let t=this.#u,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.#u=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=z(this.#e,n,o);be(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`)}#j(e,t,n,o,r){let i=G(this.#e,r,()=>se(o));if(i.kind==="error")throw i.error;let s=this.#N(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.#N(e,t,n,r),a=e.hasIntents?this.#v(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let d=this.#J(o,a.value,r);this.#q(e,t,n,d,s,r)}#M(e,t,n,o){this.#N(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#z(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}))}#N(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=E(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,c=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}#v(e,t,n,o){return this.#z(e,t,n,o).outcome}#z(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:E(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:E(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#g(t);if(r.fallback.kind==="eager")return E(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=bt(G(this.#e,n,()=>ze(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#g(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#Z(r,t,n,o)?t:n}#Z(e,t,n,o){return G(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=P(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw x(a),new ie}let i=P(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw x(i),new ie;if(r!==!0&&r!==!1)throw new ie;return r})}#J(e,t,n){return G(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=P(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw x(s),new re}let r=se(o);if(r.kind==="error")throw r.error;return r.value})}#F(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=Yt(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,d)=>{let c=this.#_(e,a,d,o);if(r===void 0){r=c;return}if(i===void 0)i=[];i.push(c)});if(r===void 0)return;if(this.#f?.(1,e,this.#e.atoms),this.#B(e,r),i!==void 0)for(let a of i)this.#B(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let d=this.#H(a);s||=d}if(this.#G(r),i!==void 0)for(let a of i)this.#G(a);this.#se();try{let a,d,c=o.affectedRecord,l=o.affectedBefore;if(c!==void 0&&l!==void 0)a=this.#E(o,c,l);let{secondAffectedRecord:h,secondAffectedBefore:u}=o;if(h!==void 0&&u!==void 0){let S=this.#E(o,h,u);if(S!==void 0)if(a===void 0)a=S;else d=[S]}if(o.affected!==void 0)for(let[S,y]of o.affected){let p=this.#E(o,S,y);if(p===void 0)continue;if(a===void 0)a=p;else{if(d===void 0)d=[];d.push(p)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(d?.length??0)),this.#ie(a,d)}catch(a){throw this.#k(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(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}#B(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")}#H(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}#G({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))}#E(e,t,n){let o=Le(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),At(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(!$t(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(At(i,s))continue;Qt(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),o.push(d)});for(let d=a,c=o.length-1;d<c;d++,c--){let l=o[d];o[d]=o[c],o[c]=l}}}#L(e,t,n,o){let r=Le(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=Le(o,n,i);if(c!==void 0){d=c;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"){d=E(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=E(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)kt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)kt(o,n,c,d),this.recordCounter("finalPreflightVisits");return d}#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.#g(t);if(r.fallback.kind==="eager")return E(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.#g(e);if(n.fallback.kind==="eager")return E(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,E(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,E(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.#g(e);if(o.fallback.kind==="eager")return E(o.fallback.value);let r=o.fallback.initialize,i=bt(G(this.#e,t,()=>ze(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#g(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.#k();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#l=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.#D(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.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#p=void 0,this.#y=this.#u===void 0?0:this.#b++}#k(){this.#y=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#y,o=this.#u?.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.#p===void 0)this.#p=[o];else this.#p.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#k(),e!==void 0)throw e;return}let n,o,r=(c)=>{let l=c.head;while(l!==void 0){let h=l.callback;if(h!==void 0)if(n===void 0)n=h;else if(o===void 0)o=[n,h];else o.push(h);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let c of i)r(c);if(this.#k(),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 d;for(let c of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new v,h=!1,u;try{Je(this.#e,l,()=>{try{let S=c(),y=P(S);if(y.kind==="thenable")x(y);else if(y.kind==="inspection-error")h=!0,u=y.error}catch(S){h=!0,u=S;let y=P(S);if(y.kind==="thenable")x(y)}})}catch(S){h=!0,u=S}if(h){if(d===void 0)d=[];if(d.push(u),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new xe(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&vt)!==0)return!0;return this.#w(e,t,vt),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#D(e,t,n)}#D(e,t,n){if((this.#W(e,t)&(gt|Ge))!==0)return;this.#w(e,t,Ge);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.#D(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 v)}this.#w(e,t,gt)}finally{this.#w(e,t,0,Ge)}}#W(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#l?.get(e)?.get(t)??0}#w(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.#l;if(r===void 0)r=new Map,this.#l=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.#Q(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 qe{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),ce(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var wt=(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}}},Nt=(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=(d,c={})=>{let l=new v,h=G(t,l,()=>se(d));if(h.kind==="error")throw h.error;let u=Ae("atom",t.ownerToken);return t.states.add(u),t.atoms.set(u,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...wt(c)})),u},o=(d,c={})=>{if(typeof d!=="function")throw TypeError("atomLazy requires an initializer function");let l=Ae("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:d}),...wt(c)})),l},r=(d,c={})=>{if(typeof d!=="function")throw TypeError("selector requires a getter function");if(c.equal!==void 0&&typeof c.equal!=="function")throw TypeError("selector equal must be a function");let l=Ae("selector",t.ownerToken),h=Object.freeze({node:l,get:d,...c.name===void 0?{}:{name:c.name},...c.equal===void 0?{}:{equal:c.equal}});return t.states.add(l),t.selectors.set(l,h),l},i=(d)=>{let c=new v;if(z(t,d,c)==="invalid")return;return t.stores.get(d)},a=Object.freeze({assertStore:(d)=>{let c=i(d);if(j(t,"adapter assertStore"),c===void 0)throw TypeError("assertStore requires a valid Store")},read:(d,c)=>{if(i(d)===void 0)throw Fe(t,"adapter read"),TypeError("read requires a valid Store");return d.get(c)},subscribe:(d,c,l)=>{if(i(d)===void 0)throw j(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return d.sub(c,l)},readHydrationSnapshot:(d,c)=>{let l=i(d);if(l===void 0)throw j(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,c)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(d=e,c)=>{j(t,"createStoreTree");let l=new Rt(t,d,c);return new qe(l,l.rootScope,c)}})};var Zt=Nt(),vn=(e,t)=>Zt.createStoreTree(e,t);
2
+ export{ne as a,Ht as b,ut as c,Pe as d,xe as e,Y as f,X as g,Q as h,pe as i,oe as j,re as k,ie as l,je as m,Ie as n,Me as o,me as p,yn as q,Zt as r,vn as s};
@@ -1 +1 @@
1
- import{a as o,d as a,e as n,f as l,g as p,h as c,i,j as s,k as u,l as y,m as v,n as E,o as m,p as S,r as t}from"./chunk-fbqtxaaa.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,d as a,e as n,f as l,g as p,h as c,i,j as s,k as u,l as y,m as v,n as E,o as m,p as S,r as t}from"./chunk-y5ja7h9m.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 Q,c as Z,e as ee,q as ne,s as ae}from"./chunk-fbqtxaaa.js";var ce=2048,de=1e5,q=256,H=1024,W=1e4,le=32,pe=20000,A=new Set(["span","operation","commit"]),ue=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),te=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),me=()=>{},J=Symbol("inspection dependency path root"),_=(e)=>e==="proven-terminal"?"terminal":e==="proven-reverse"?"proven":e==="ineligible-active-frames"?"active-frames":e,fe=1;class O{#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 L=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??r??0),t=Math.max(t,o.seqEnd??r??0)}return Object.freeze({firstSequence:n,lastSequence:t})},U=(e,n,t,o)=>{let r=e??n;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},G=(e)=>e.length<=q?e:e.slice(0,q),E=()=>({searches:0,visits:0,maxVisits:0,found:0}),oe=()=>({admissionSkipped:0,observing:0,consultedNoPrune:0,consultedPruned:0,disabled:0,mapProbes:0,prunedNodes:0,graphVersionResets:0,initialSeeds:0,activationReplacementSeeds:0,secondarySeeds:0,hitDerivedSeeds:0,missBudgetDisables:0,oversizedHitApproachDisables:0,passiveProbeBudgetDisables:0,maxRetainedEntries:0}),re=(e)=>Object.freeze({admissionSkipped:e.admissionSkipped,observing:e.observing,consultedNoPrune:e.consultedNoPrune,consultedPruned:e.consultedPruned,disabled:e.disabled,mapProbes:e.mapProbes,prunedNodes:e.prunedNodes,resets:Object.freeze({graphVersion:e.graphVersionResets}),seeds:Object.freeze({initial:e.initialSeeds,activationReplacement:e.activationReplacementSeeds,secondary:e.secondarySeeds,hitDerived:e.hitDerivedSeeds}),disables:Object.freeze({missBudget:e.missBudgetDisables,oversizedHitApproach:e.oversizedHitApproachDisables,passiveProbeBudget:e.passiveProbeBudgetDisables}),retained:Object.freeze({maxEntries:e.maxRetainedEntries})}),be=(e)=>{let n=oe(),t=!1;return Object.freeze({sink:Object.freeze({admissionSkipped(){t=!0,n.admissionSkipped++,e({admissionSkipped:1})},disabled(){t=!0,n.disabled++,e({disabled:1})},graphVersionReset(){t=!0,n.graphVersionResets++,e({graphVersionResets:1})},recordMapProbes(r){if(r===0)return;t=!0,n.mapProbes+=r,e({mapProbes:r})},completeSearch(r,i,s,a=0,d=0,b=0){if(t=!0,r==="observing")n.observing++;else if(r==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=a,n.prunedNodes+=d,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,b),i==="initial")n.initialSeeds++;else if(i==="activation-replacement")n.activationReplacementSeeds++;else if(i==="secondary")n.secondarySeeds++;else if(i==="hit-derived")n.hitDerivedSeeds++;if(s==="miss-budget")n.missBudgetDisables++;else if(s==="over-cap-hit")n.oversizedHitApproachDisables++;else if(s==="passive-probe-budget")n.passiveProbeBudgetDisables++;e({...r==="observing"?{observing:1}:r==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:a,prunedNodes:d,maxRetainedEntries:b,...i==="initial"?{initialSeeds:1}:i==="activation-replacement"?{activationReplacementSeeds:1}:i==="secondary"?{secondarySeeds:1}:i==="hit-derived"?{hitDerivedSeeds:1}:{},...s==="miss-budget"?{missBudgetDisables:1}:s==="over-cap-hit"?{oversizedHitApproachDisables:1}:s==="passive-probe-budget"?{passiveProbeBudgetDisables:1}:{}})}}),finish:()=>t?n:void 0})},ye=()=>({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,topologyDeltaProof:0,committed:0,scratch:0,hydration:0,newEdgeProofMemo:oe(),reverseProof:{terminal:0,proven:0,pathPossible:0,budgetExhausted:0,disabled:0,activeFrames:0,unsupported:0,nodeVisits:0,dependentProbes:0,liveDependents:0,maxWork:0,maxFrontier:0},lanes:{committed:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},scratch:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},hydration:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()}}}}),B=(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,topologyDeltaProof:e.cycle.topologyDeltaProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),newEdgeProofMemo:re(e.cycle.newEdgeProofMemo),reverseProof:Object.freeze({...e.cycle.reverseProof}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.committed.topologyDeltaProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.scratch.topologyDeltaProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.hydration.topologyDeltaProof})})})})}),z=(e,n,t,o)=>{if(n.remaining--<=0||o>le)return null;if(e===null)return null;if(typeof e==="string")return e.length<=H?e:e.slice(0,H);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,W);for(let d=0;d<a;d++)s.push(z(e[d],n,t,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,W);for(let s of i){if(te.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=z(a,n,t,o+1)}return Object.freeze(r)}finally{t.delete(e)}},F=(e)=>{if(e===void 0)return he;let n={},t={remaining:pe};for(let o of Object.keys(e).slice(0,W)){if(ue.has(o)||te.has(o))continue;let r=e[o];if(r===void 0)continue;n[o]=z(r,t,new Set,0)}return Object.freeze(n)},he=Object.freeze({}),Ie=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...F(n)})},c=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,ge=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Y;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:Y}catch(n){return{kind:"inspection-error",error:n}}},Y=Object.freeze({kind:"not-thenable"});class se{#o;#e;#r;#u;#d="";#i=1;#g=1;#S=1;#v=1;#P=1;#R=1;#E=1;#k=1;#T=1;#n=[];#m=new WeakMap;#x=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#b;#C;constructor(e,n){this.#C=n,this.#r=U(e.capacity?.summaries,ce,"Inspection summary",!1),this.#u=U(e.capacity?.details,de,"Inspection detail",!0),this.#o=new O(this.#r),this.#e=new O(this.#u),this.#b=this.#p(),this.#D()}get recordingId(){return this.#d}registerStore(e,n){this.#w.set(e,n)}capture(e,n){let t=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=t===void 0?void 0:this.#w.get(t);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(n!==void 0){let s=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let d=a.atoms.get(s),b=a.selectors.get(s);if(d===void 0&&b===void 0)throw TypeError("Inspection capture requires a valid State");let R=d?.name??b?.name;r=this.reference(s,d===void 0?"selector":"atom",typeof R==="string"?R:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#y()})}reference(e,n,t){if(this.#t!==void 0)return K;try{let o=this.#m.get(e);if(o===void 0)o=this.#T++,this.#m.set(e,o);let r=this.#x.get(e);if(r===void 0&&t!==void 0)r=G(t),this.#x.set(e,r);return Object.freeze({id:o,kind:n,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),K}}sessionId(e){let n=this.#f.get(e);if(n!==void 0)return n;let t=this.#E++;return this.#f.set(e,t),t}beginInterval(e){if(this.#t!==void 0)return X;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#y(),...e.links}),r={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:G(e.name),seqStart:this.#i++,startUs:this.#I(),fields:F(e.fields),totals:A.has(e.type)?ye():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:A.has(e.type)?this.#O():void 0};if(e.type==="commit"){let i=this.#s("operation");if(i!==void 0)i.commitId=n}return this.#n.push(r),t}catch{return this.#c("begin-interval"),X}}finishInterval(e,n={}){if(e.id===0||this.#t!==void 0)return;try{let t=this.#n.pop();if(t===void 0||!Object.is(t.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#j(t);let o=this.#i++,r=Math.max(0,this.#I()-t.startUs),i=Ie(t.fields,n.fields),s=this.#z(t,o,r,i,n.result);if(A.has(t.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 n=this.#i++,t=Object.freeze({...F(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#y(),...e.links});if(this.#e.add(t))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let n of this.#n){let t=n.totals;if(t===void 0)continue;t.selectorEvaluations=c(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=c(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=c(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=c(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=c(t.propagationSettled,e.propagationSettled),t.notificationTargets=c(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=c(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=c(t.cycle.searches,o.searches),t.cycle.visits=c(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=c(t.cycle.found,o.found);let r=o.newEdgeProofMemo;if(r!==void 0){let s=t.cycle.newEdgeProofMemo;s.admissionSkipped=c(s.admissionSkipped,r.admissionSkipped),s.observing=c(s.observing,r.observing),s.consultedNoPrune=c(s.consultedNoPrune,r.consultedNoPrune),s.consultedPruned=c(s.consultedPruned,r.consultedPruned),s.disabled=c(s.disabled,r.disabled),s.mapProbes=c(s.mapProbes,r.mapProbes),s.prunedNodes=c(s.prunedNodes,r.prunedNodes),s.graphVersionResets=c(s.graphVersionResets,r.graphVersionResets),s.initialSeeds=c(s.initialSeeds,r.initialSeeds),s.activationReplacementSeeds=c(s.activationReplacementSeeds,r.activationReplacementSeeds),s.secondarySeeds=c(s.secondarySeeds,r.secondarySeeds),s.hitDerivedSeeds=c(s.hitDerivedSeeds,r.hitDerivedSeeds),s.missBudgetDisables=c(s.missBudgetDisables,r.missBudgetDisables),s.oversizedHitApproachDisables=c(s.oversizedHitApproachDisables,r.oversizedHitApproachDisables),s.passiveProbeBudgetDisables=c(s.passiveProbeBudgetDisables,r.passiveProbeBudgetDisables),s.maxRetainedEntries=Math.max(s.maxRetainedEntries,r.maxRetainedEntries??0)}let i=o.reverseProof;if(i!==void 0){let s=t.cycle.reverseProof;if(i.outcome==="terminal")s.terminal++;else if(i.outcome==="proven")s.proven++;else if(i.outcome==="path-possible")s.pathPossible++;else if(i.outcome==="budget-exhausted")s.budgetExhausted++;else if(i.outcome==="disabled")s.disabled++;else if(i.outcome==="active-frames")s.activeFrames++;else s.unsupported++;s.nodeVisits=c(s.nodeVisits,i.nodeVisits),s.dependentProbes=c(s.dependentProbes,i.dependentProbes),s.liveDependents=c(s.liveDependents,i.liveDependents),s.maxWork=Math.max(s.maxWork,i.nodeVisits+i.dependentProbes),s.maxFrontier=Math.max(s.maxFrontier,i.maxFrontier)}if(o.site==="prefix-revalidation")t.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")t.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")t.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)t.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let s=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",a=t.cycle.lanes[o.host][s];a.searches=c(a.searches,o.searches),a.visits=c(a.visits,o.visits),a.maxVisits=Math.max(a.maxVisits,o.maxVisits??0),a.found=c(a.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,n){let t=this.#s("operation"),o=t===void 0||!Object.is(t.token,e)||t.commitId===void 0||!t.commitSourceApplied?"none":n==="returned"?"committed":t.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:n,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,n){let t=this.#s("operation");if(t!==void 0)t.commitSourceApplied||=n.sourceApplied,t.commitFailurePhase=n.failurePhase;this.finishInterval(e,{result:n.result,fields:{intents:n.intents,...n.changedSources===void 0?{}:{changedSources:n.changedSources},...n.ownershipChanged===void 0?{}:{ownershipChanged:n.ownershipChanged},sourceApplied:n.sourceApplied,notificationsCompleted:n.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 n=e[0];if(n===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(n===1){let o=e[1]===0?"returned":"threw",r=this.#s("operation");if(r===void 0)return;let i=this.#s("commit");if(i!==void 0)this.#j(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(n===2){let o=this.#s("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#s("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#s("operation");if(t!==void 0)t.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.#s("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let r=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,n,t,o,r,i,s,a,d,b,R,k){let S=s===0?"prefix-revalidation":s===1?"new-edge-proof":"topology-delta-proof",D=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-d,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-b,acceptedPrefixLength:a,parentWasCold:R}}),m={nodeVisits:0,dependentProbes:0,liveDependents:0,maxFrontier:0},l=s===1?Q(t,o,r,i,m,k?.reverseProofEnabled??!0):void 0;if(l==="budget-exhausted"&&k!==void 0)k.reverseProofEnabled=!1;let j=l==="proven-terminal"||l==="proven-reverse",N=0,p=0,y=0,C=0,T=0,x=0,g;if(!j){let h=k?.(),f=h?.beginSearch()??!1,I=[t],w=new Map([[t,J]]);y=1;while(I.length>0){let v=I.pop();if(N++,Object.is(v,o)){let u=[],P=v;while(P!==J)u.push(P),P=w.get(P);u.reverse(),g=Object.freeze(u);break}let M=i.getTransientDependencies(r,v);if(M){if(C++,M.length===0)continue;if(f){let u=h.hasProvenNoPathMeasured(v);if(!h.enabled)f=!1;if(u)continue}p+=M.length;for(let u of M){if(w.has(u.node))continue;w.set(u.node,v),I.push(u.node)}if(I.length>y)y=I.length;continue}if(r.getSelectorDependencyNodes!==void 0){let u=r.getSelectorDependencyNodes(v);if(u===void 0){x++;continue}if(T++,u.length===0)continue;if(f){let P=h.hasProvenNoPathMeasured(v);if(!h.enabled)f=!1;if(P)continue}p+=u.length;for(let P of u){if(w.has(P))continue;w.set(P,v),I.push(P)}if(I.length>y)y=I.length;continue}let V=r.getSelectorRecord(v);if(!V){x++;continue}if(T++,V.dependencies.length===0)continue;if(f){let u=h.hasProvenNoPathMeasured(v);if(!h.enabled)f=!1;if(u)continue}p+=V.dependencies.length;for(let u of V.dependencies){if(w.has(u.node))continue;w.set(u.node,v),I.push(u.node)}if(I.length>y)y=I.length}if(g===void 0)h?.completeNegative(w);else h?.completePositive()}return this.addWork({cycle:{searches:1,visits:N,maxVisits:N,found:g===void 0?0:1,site:S,host:e,...l===void 0?{}:{reverseProof:{outcome:_(l),...m}}}}),this.finishInterval(D,{result:"returned",fields:{visits:N,edges:p,maxFrontier:y,transientExpansions:C,recordExpansions:T,terminalPrunes:x,...l===void 0?{}:{reverseProof:{outcome:_(l),...m}},found:g!==void 0,...g===void 0?{}:{path:g.map((h)=>this.#h(h))}}}),g}span(e,n){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof n!=="function")throw TypeError("Inspection span callback must be a function");let t=this.beginInterval({type:"span",name:e}),o;try{o=n()}catch(i){throw this.finishInterval(t,{result:"threw"}),i}let r=ge(o);if(r.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,me])}catch{}throw this.finishInterval(t,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(t,{result:"returned"}),o}export(){this.#N("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),n=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),t=L(e),o=L(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:4,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(n),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...t===void 0?{}:{summaries:t},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#N("reset"),this.#D()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(n,t)=>e.capture(n,t),span:(n,t)=>e.span(n,t),export:()=>e.export(),reset:()=>e.reset()})}#D(){this.#d=`inspection-${fe++}`,this.#o=new O(this.#r),this.#e=new O(this.#u),this.#i=1,this.#g=1,this.#S=1,this.#v=1,this.#P=1,this.#R=1,this.#E=1,this.#k=1,this.#T=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#b=this.#p()}#V(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.#P++;if(e==="cycle-search")return this.#R++;return this.#k++}#y(){let e={};for(let n of this.#n){let{id:t,type:o}=n.token;if(n.links.sessionId!==void 0)e.sessionId=n.links.sessionId;if(o==="span")e.spanId=t;else if(o==="operation")e.operationId=t;else if(o==="commit")e.commitId=t;else if(o==="selector-evaluation")e.evaluationId=t;else if(o==="cycle-search")e.searchId=t}return e}#s(e){for(let n=this.#n.length-1;n>=0;n--){let t=this.#n[n];if(t.token.type===e)return t}return}#h(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):z(e,{remaining:1},new Set,0)}#z(e,n,t,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:n,startUs:e.startUs,durationUs:t,...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:B(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:B(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:B(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`)}#O(){let e=(n)=>this.#C.read(n);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#j(e){let n=e.counterStart;if(n===void 0)return;e.counterStart=void 0;let t=this.#O();if(e.token.type==="commit")e.commitOwnershipChanged=t.sourceEpoch!==n.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=t.transientSelectorHostsCreated-n.transientSelectorHostsCreated,o.propagationSettled+=t.propagationSettled-n.propagationSettled,o.notificationTargets+=t.notificationTargets-n.notificationTargets,o.subscriberCallbacks+=t.subscriberCallbacks-n.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let n=this.#i++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:n}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#M(e){return Math.max(0,Math.round((e-this.#b)*1000))}#I(){return this.#M(this.#p())}}var K=Object.freeze({id:0,kind:"store"}),X=Object.freeze({id:0,type:"operation"}),Se=(e)=>{let n=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let d=a();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof ee?1:0),d}},t=(r,i,s)=>{if(r===0){let a=i,d=s;e.registerStore(a,d);let b=a,R=a.set,k=a.update,S=a.reset,D=a.txn;b.set=(m,l)=>n(0,d,void 0,()=>R(m,l)),b.update=(m,l)=>n(1,d,void 0,()=>k(m,l)),b.reset=(m)=>n(2,d,void 0,()=>S(m)),b.txn=(m,l)=>{if(typeof m!=="function"||l!==void 0&&typeof l!=="string")return D(m,l);return n(3,d,l,()=>D(m,l))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(t,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=i.name,b=e.reference(i,a==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),R=i.getSelectorGraphVersion(),k=s.getSelectorGraphPublicationCount(i),S=i.getSelectorRecord(r.node)?.dependencies,D=S?.length??0,m=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:b,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:R,previousDependencyCount:D}});e.addWork({selectorEvaluations:1});let l=be((p)=>e.addWork({cycle:{newEdgeProofMemo:p}})),j=()=>{let p=l.finish();if(p===void 0)return;return re(p)},N=(p,y,C,T,x,g,h)=>e.findDependencyPath(a,b,p,y,C,T,x,g,R,k,S===void 0,h);try{let p=Z(r,i,s,N,l.sink),y=S===void 0||S.length!==p.dependencies.length||S.some((f,I)=>!Object.is(f.node,p.dependencies[I]?.node)),C=new Set(S?.map((f)=>f.node)),T=new Set(p.dependencies.map((f)=>f.node)),x=0,g=0;for(let f of T)if(!C.has(f))x++;for(let f of C)if(!T.has(f))g++;e.addWork(y?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let h=j();return e.finishInterval(m,{result:"returned",fields:{outcome:p.outcome.kind,dependencyCount:p.dependencies.length,proposedTopologyChanged:y,proposedEdgesAdded:x,proposedEdgesRemoved:g,graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:h}}),p}catch(p){let y=j();throw e.finishInterval(m,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:y}}),p}}}),Object.freeze(t)},ie=(e={})=>{let n=ne(),t=new se(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:Se(t)})};var Te=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=ie(e),r=ae(t,o);return Object.freeze({store:r,inspect:n})};export{Te as createInspectableStore};
1
+ import{b as Z,c as ee,e as ne,q as te,s as pe}from"./chunk-y5ja7h9m.js";var ue=2048,me=1e5,q=256,H=1024,B=1e4,fe=32,be=20000,F=new Set(["span","operation","commit"]),ye=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),oe=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),he=()=>{},_=Symbol("inspection dependency path root"),L=(e)=>e==="proven-terminal"?"terminal":e==="proven-reverse"?"proven":e==="ineligible-active-frames"?"active-frames":e,Ie=1;class j{#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 U=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??r??0),t=Math.max(t,o.seqEnd??r??0)}return Object.freeze({firstSequence:n,lastSequence:t})},G=(e,n,t,o)=>{let r=e??n;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},Y=(e)=>e.length<=q?e:e.slice(0,q),D=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({admissionSkipped:0,observing:0,consultedNoPrune:0,consultedPruned:0,disabled:0,mapProbes:0,prunedNodes:0,graphVersionResets:0,initialSeeds:0,activationReplacementSeeds:0,secondarySeeds:0,hitDerivedSeeds:0,missBudgetDisables:0,oversizedHitApproachDisables:0,passiveProbeBudgetDisables:0,maxRetainedEntries:0}),se=(e)=>Object.freeze({admissionSkipped:e.admissionSkipped,observing:e.observing,consultedNoPrune:e.consultedNoPrune,consultedPruned:e.consultedPruned,disabled:e.disabled,mapProbes:e.mapProbes,prunedNodes:e.prunedNodes,resets:Object.freeze({graphVersion:e.graphVersionResets}),seeds:Object.freeze({initial:e.initialSeeds,activationReplacement:e.activationReplacementSeeds,secondary:e.secondarySeeds,hitDerived:e.hitDerivedSeeds}),disables:Object.freeze({missBudget:e.missBudgetDisables,oversizedHitApproach:e.oversizedHitApproachDisables,passiveProbeBudget:e.passiveProbeBudgetDisables}),retained:Object.freeze({maxEntries:e.maxRetainedEntries})}),ie=()=>({attempts:0,completed:0,overflow:0,unavailable:0,scannedActiveFrames:0,scannedPrefixEdges:0,maxScannedActiveFrames:0,maxScannedPrefixEdges:0,capturedActiveFrames:0,capturedPrefixEdges:0,maxCapturedActiveFrames:0,maxCapturedPrefixEdges:0}),ae=(e,n)=>{if(e.attempts++,n.outcome==="completed")e.completed++;else if(n.outcome==="overflow")e.overflow++;else e.unavailable++;if(e.scannedActiveFrames=d(e.scannedActiveFrames,n.scannedFrames),e.scannedPrefixEdges=d(e.scannedPrefixEdges,n.prefixEdges),e.maxScannedActiveFrames=Math.max(e.maxScannedActiveFrames,n.scannedFrames),e.maxScannedPrefixEdges=Math.max(e.maxScannedPrefixEdges,n.prefixEdges),n.outcome!=="completed")return;e.capturedActiveFrames=d(e.capturedActiveFrames,n.activeFrames),e.capturedPrefixEdges=d(e.capturedPrefixEdges,n.prefixEdges),e.maxCapturedActiveFrames=Math.max(e.maxCapturedActiveFrames,n.activeFrames),e.maxCapturedPrefixEdges=Math.max(e.maxCapturedPrefixEdges,n.prefixEdges)},ce=(e)=>Object.freeze({...e}),ge=(e)=>{let n=ie();return Object.freeze({sink:Object.freeze({recordSnapshot(o,r,i,a){let s={outcome:o,scannedFrames:r,activeFrames:i,prefixEdges:a};ae(n,s),e(s)}}),finish:()=>n.attempts===0?void 0:n})},ve=(e)=>{let n=re(),t=!1;return Object.freeze({sink:Object.freeze({admissionSkipped(){t=!0,n.admissionSkipped++,e({admissionSkipped:1})},disabled(){t=!0,n.disabled++,e({disabled:1})},graphVersionReset(){t=!0,n.graphVersionResets++,e({graphVersionResets:1})},recordMapProbes(r){if(r===0)return;t=!0,n.mapProbes+=r,e({mapProbes:r})},completeSearch(r,i,a,s=0,c=0,b=0){if(t=!0,r==="observing")n.observing++;else if(r==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=s,n.prunedNodes+=c,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,b),i==="initial")n.initialSeeds++;else if(i==="activation-replacement")n.activationReplacementSeeds++;else if(i==="secondary")n.secondarySeeds++;else if(i==="hit-derived")n.hitDerivedSeeds++;if(a==="miss-budget")n.missBudgetDisables++;else if(a==="over-cap-hit")n.oversizedHitApproachDisables++;else if(a==="passive-probe-budget")n.passiveProbeBudgetDisables++;e({...r==="observing"?{observing:1}:r==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:s,prunedNodes:c,maxRetainedEntries:b,...i==="initial"?{initialSeeds:1}:i==="activation-replacement"?{activationReplacementSeeds:1}:i==="secondary"?{secondarySeeds:1}:i==="hit-derived"?{hitDerivedSeeds:1}:{},...a==="miss-budget"?{missBudgetDisables:1}:a==="over-cap-hit"?{oversizedHitApproachDisables:1}:a==="passive-probe-budget"?{passiveProbeBudgetDisables:1}:{}})}}),finish:()=>t?n:void 0})},Se=()=>({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,topologyDeltaProof:0,committed:0,scratch:0,hydration:0,newEdgeProofMemo:re(),reverseProof:{terminal:0,proven:0,pathPossible:0,budgetExhausted:0,disabled:0,activeFrames:0,unsupported:0,nodeVisits:0,dependentProbes:0,liveDependents:0,maxWork:0,maxFrontier:0,topologyDeltaSnapshot:ie()},lanes:{committed:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},scratch:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},hydration:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()}}}}),W=(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,topologyDeltaProof:e.cycle.topologyDeltaProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),newEdgeProofMemo:se(e.cycle.newEdgeProofMemo),reverseProof:Object.freeze({...e.cycle.reverseProof,topologyDeltaSnapshot:ce(e.cycle.reverseProof.topologyDeltaSnapshot)}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.committed.topologyDeltaProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.scratch.topologyDeltaProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.hydration.topologyDeltaProof})})})})}),z=(e,n,t,o)=>{if(n.remaining--<=0||o>fe)return null;if(e===null)return null;if(typeof e==="string")return e.length<=H?e:e.slice(0,H);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){let a=[],s=Math.min(e.length,B);for(let c=0;c<s;c++)a.push(z(e[c],n,t,o+1));return Object.freeze(a)}let r={},i=Object.keys(e).slice(0,B);for(let a of i){if(oe.has(a))continue;let s=Reflect.get(e,a);if(s===void 0)continue;r[a]=z(s,n,t,o+1)}return Object.freeze(r)}finally{t.delete(e)}},J=(e)=>{if(e===void 0)return Pe;let n={},t={remaining:be};for(let o of Object.keys(e).slice(0,B)){if(ye.has(o)||oe.has(o))continue;let r=e[o];if(r===void 0)continue;n[o]=z(r,t,new Set,0)}return Object.freeze(n)},Pe=Object.freeze({}),Re=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...J(n)})},d=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,Ee=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return K;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:K}catch(n){return{kind:"inspection-error",error:n}}},K=Object.freeze({kind:"not-thenable"});class de{#o;#e;#r;#u;#d="";#i=1;#g=1;#v=1;#S=1;#P=1;#R=1;#E=1;#x=1;#T=1;#n=[];#m=new WeakMap;#D=new WeakMap;#k=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#b;#C;constructor(e,n){this.#C=n,this.#r=G(e.capacity?.summaries,ue,"Inspection summary",!1),this.#u=G(e.capacity?.details,me,"Inspection detail",!0),this.#o=new j(this.#r),this.#e=new j(this.#u),this.#b=this.#p(),this.#w()}get recordingId(){return this.#d}registerStore(e,n){this.#k.set(e,n)}capture(e,n){let t=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=t===void 0?void 0:this.#k.get(t);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(n!==void 0){let a=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,s=o.coordinator.runtimeDomain;if(a===void 0||!s.states.has(a))throw TypeError("Inspection capture requires a valid State");let c=s.atoms.get(a),b=s.selectors.get(a);if(c===void 0&&b===void 0)throw TypeError("Inspection capture requires a valid State");let x=c?.name??b?.name;r=this.reference(a,c===void 0?"selector":"atom",typeof x==="string"?x:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#y()})}reference(e,n,t){if(this.#t!==void 0)return X;try{let o=this.#m.get(e);if(o===void 0)o=this.#T++,this.#m.set(e,o);let r=this.#D.get(e);if(r===void 0&&t!==void 0)r=Y(t),this.#D.set(e,r);return Object.freeze({id:o,kind:n,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),X}}sessionId(e){let n=this.#f.get(e);if(n!==void 0)return n;let t=this.#E++;return this.#f.set(e,t),t}beginInterval(e){if(this.#t!==void 0)return Q;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#y(),...e.links}),r={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:Y(e.name),seqStart:this.#i++,startUs:this.#I(),fields:J(e.fields),totals:F.has(e.type)?Se():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:F.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#s("operation");if(i!==void 0)i.commitId=n}return this.#n.push(r),t}catch{return this.#c("begin-interval"),Q}}finishInterval(e,n={}){if(e.id===0||this.#t!==void 0)return;try{let t=this.#n.pop();if(t===void 0||!Object.is(t.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#j(t);let o=this.#i++,r=Math.max(0,this.#I()-t.startUs),i=Re(t.fields,n.fields),a=this.#A(t,o,r,i,n.result);if(F.has(t.token.type)){if(this.#o.add(a))this.#l++}else if(this.#e.add(a))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let n=this.#i++,t=Object.freeze({...J(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#y(),...e.links});if(this.#e.add(t))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let n of this.#n){let t=n.totals;if(t===void 0)continue;t.selectorEvaluations=d(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=d(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=d(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=d(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=d(t.propagationSettled,e.propagationSettled),t.notificationTargets=d(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=d(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=d(t.cycle.searches,o.searches),t.cycle.visits=d(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=d(t.cycle.found,o.found);let r=o.newEdgeProofMemo;if(r!==void 0){let s=t.cycle.newEdgeProofMemo;s.admissionSkipped=d(s.admissionSkipped,r.admissionSkipped),s.observing=d(s.observing,r.observing),s.consultedNoPrune=d(s.consultedNoPrune,r.consultedNoPrune),s.consultedPruned=d(s.consultedPruned,r.consultedPruned),s.disabled=d(s.disabled,r.disabled),s.mapProbes=d(s.mapProbes,r.mapProbes),s.prunedNodes=d(s.prunedNodes,r.prunedNodes),s.graphVersionResets=d(s.graphVersionResets,r.graphVersionResets),s.initialSeeds=d(s.initialSeeds,r.initialSeeds),s.activationReplacementSeeds=d(s.activationReplacementSeeds,r.activationReplacementSeeds),s.secondarySeeds=d(s.secondarySeeds,r.secondarySeeds),s.hitDerivedSeeds=d(s.hitDerivedSeeds,r.hitDerivedSeeds),s.missBudgetDisables=d(s.missBudgetDisables,r.missBudgetDisables),s.oversizedHitApproachDisables=d(s.oversizedHitApproachDisables,r.oversizedHitApproachDisables),s.passiveProbeBudgetDisables=d(s.passiveProbeBudgetDisables,r.passiveProbeBudgetDisables),s.maxRetainedEntries=Math.max(s.maxRetainedEntries,r.maxRetainedEntries??0)}let i=o.topologyDeltaReverseSnapshot;if(i!==void 0)ae(t.cycle.reverseProof.topologyDeltaSnapshot,i);let a=o.reverseProof;if(a!==void 0){let s=t.cycle.reverseProof;if(a.outcome==="terminal")s.terminal++;else if(a.outcome==="proven")s.proven++;else if(a.outcome==="path-possible")s.pathPossible++;else if(a.outcome==="budget-exhausted")s.budgetExhausted++;else if(a.outcome==="disabled")s.disabled++;else if(a.outcome==="active-frames")s.activeFrames++;else s.unsupported++;s.nodeVisits=d(s.nodeVisits,a.nodeVisits),s.dependentProbes=d(s.dependentProbes,a.dependentProbes),s.liveDependents=d(s.liveDependents,a.liveDependents),s.maxWork=Math.max(s.maxWork,a.nodeVisits+a.dependentProbes),s.maxFrontier=Math.max(s.maxFrontier,a.maxFrontier)}if(o.site==="prefix-revalidation")t.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")t.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")t.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)t.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let s=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",c=t.cycle.lanes[o.host][s];c.searches=d(c.searches,o.searches),c.visits=d(c.visits,o.visits),c.maxVisits=Math.max(c.maxVisits,o.maxVisits??0),c.found=d(c.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,n){let t=this.#s("operation"),o=t===void 0||!Object.is(t.token,e)||t.commitId===void 0||!t.commitSourceApplied?"none":n==="returned"?"committed":t.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:n,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,n){let t=this.#s("operation");if(t!==void 0)t.commitSourceApplied||=n.sourceApplied,t.commitFailurePhase=n.failurePhase;this.finishInterval(e,{result:n.result,fields:{intents:n.intents,...n.changedSources===void 0?{}:{changedSources:n.changedSources},...n.ownershipChanged===void 0?{}:{ownershipChanged:n.ownershipChanged},sourceApplied:n.sourceApplied,notificationsCompleted:n.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 n=e[0];if(n===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(n===1){let o=e[1]===0?"returned":"threw",r=this.#s("operation");if(r===void 0)return;let i=this.#s("commit");if(i!==void 0)this.#j(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(n===2){let o=this.#s("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#s("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#s("operation");if(t!==void 0)t.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.#s("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let r=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,n,t,o,r,i,a,s,c,b,x,k,I){let w=a===0?"prefix-revalidation":a===1?"new-edge-proof":"topology-delta-proof",h=this.beginInterval({type:"cycle-search",fields:{site:w,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-b,acceptedPrefixLength:s,parentWasCold:x}}),m={nodeVisits:0,dependentProbes:0,liveDependents:0,maxFrontier:0},S=a===1||a===2?Z(t,o,r,i,m,a===1?k?.reverseProofEnabled??!0:I?.reverseProofEnabled??!0,I?.transientDependents):void 0;if(S==="budget-exhausted"){if(a===1&&k!==void 0)k.reverseProofEnabled=!1;else if(I!==void 0)I.reverseProofEnabled=!1}let M=S==="proven-terminal"||S==="proven-reverse",O=0,N=0,l=0,T=0,P=0,C=0,v;if(!M){let f=k?.(),R=f?.beginSearch()??!1,y=[t],u=new Map([[t,_]]);l=1;while(y.length>0){let g=y.pop();if(O++,Object.is(g,o)){let p=[],E=g;while(E!==_)p.push(E),E=u.get(E);p.reverse(),v=Object.freeze(p);break}let V=i.getTransientDependencies(r,g);if(V){if(T++,V.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=V.length;for(let p of V){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length;continue}if(r.getSelectorDependencyNodes!==void 0){let p=r.getSelectorDependencyNodes(g);if(p===void 0){C++;continue}if(P++,p.length===0)continue;if(R){let E=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(E)continue}N+=p.length;for(let E of p){if(u.has(E))continue;u.set(E,g),y.push(E)}if(y.length>l)l=y.length;continue}let A=r.getSelectorRecord(g);if(!A){C++;continue}if(P++,A.dependencies.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=A.dependencies.length;for(let p of A.dependencies){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length}if(v===void 0)f?.completeNegative(u);else f?.completePositive()}return this.addWork({cycle:{searches:1,visits:O,maxVisits:O,found:v===void 0?0:1,site:w,host:e,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}}}}),this.finishInterval(h,{result:"returned",fields:{visits:O,edges:N,maxFrontier:l,transientExpansions:T,recordExpansions:P,terminalPrunes:C,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}},found:v!==void 0,...v===void 0?{}:{path:v.map((f)=>this.#h(f))}}}),v}span(e,n){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof n!=="function")throw TypeError("Inspection span callback must be a function");let t=this.beginInterval({type:"span",name:e}),o;try{o=n()}catch(i){throw this.finishInterval(t,{result:"threw"}),i}let r=Ee(o);if(r.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,he])}catch{}throw this.finishInterval(t,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(t,{result:"returned"}),o}export(){this.#O("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),n=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),t=U(e),o=U(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:5,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(n),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...t===void 0?{}:{summaries:t},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#O("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(n,t)=>e.capture(n,t),span:(n,t)=>e.span(n,t),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#d=`inspection-${Ie++}`,this.#o=new j(this.#r),this.#e=new j(this.#u),this.#i=1,this.#g=1,this.#v=1,this.#S=1,this.#P=1,this.#R=1,this.#E=1,this.#x=1,this.#T=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#b=this.#p()}#V(e){if(e==="span")return this.#g++;if(e==="operation")return this.#v++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#P++;if(e==="cycle-search")return this.#R++;return this.#x++}#y(){let e={};for(let n of this.#n){let{id:t,type:o}=n.token;if(n.links.sessionId!==void 0)e.sessionId=n.links.sessionId;if(o==="span")e.spanId=t;else if(o==="operation")e.operationId=t;else if(o==="commit")e.commitId=t;else if(o==="selector-evaluation")e.evaluationId=t;else if(o==="cycle-search")e.searchId=t}return e}#s(e){for(let n=this.#n.length-1;n>=0;n--){let t=this.#n[n];if(t.token.type===e)return t}return}#h(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):z(e,{remaining:1},new Set,0)}#A(e,n,t,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:n,startUs:e.startUs,durationUs:t,...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:W(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:W(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:W(e.totals)});let a=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,...a})}#O(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(n)=>this.#C.read(n);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#j(e){let n=e.counterStart;if(n===void 0)return;e.counterStart=void 0;let t=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=t.sourceEpoch!==n.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=t.transientSelectorHostsCreated-n.transientSelectorHostsCreated,o.propagationSettled+=t.propagationSettled-n.propagationSettled,o.notificationTargets+=t.notificationTargets-n.notificationTargets,o.subscriberCallbacks+=t.subscriberCallbacks-n.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let n=this.#i++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:n}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#M(e){return Math.max(0,Math.round((e-this.#b)*1000))}#I(){return this.#M(this.#p())}}var X=Object.freeze({id:0,kind:"store"}),Q=Object.freeze({id:0,type:"operation"}),xe=(e)=>{let n=(r,i,a,s)=>{if(e.hasActiveStoreOperation())return s();e.recordStoreEvent(0,r,i,i.name,a);try{let c=s();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof ne?1:0),c}},t=(r,i,a)=>{if(r===0){let s=i,c=a;e.registerStore(s,c);let b=s,x=s.set,k=s.update,I=s.reset,w=s.txn;b.set=(h,m)=>n(0,c,void 0,()=>x(h,m)),b.update=(h,m)=>n(1,c,void 0,()=>k(h,m)),b.reset=(h)=>n(2,c,void 0,()=>I(h)),b.txn=(h,m)=>{if(typeof h!=="function"||m!==void 0&&typeof m!=="string")return w(h,m);return n(3,c,m,()=>w(h,m))};return}if(r===1){e.beginDraftCommit(i,a);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(t,{evaluate:(r,i,a)=>{let s=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,b=e.reference(i,s==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),x=i.getSelectorGraphVersion(),k=a.getSelectorGraphPublicationCount(i),I=i.getSelectorRecord(r.node)?.dependencies,w=I?.length??0,h=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(a)},fields:{host:s,hostRef:b,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:x,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let m=ve((l)=>e.addWork({cycle:{newEdgeProofMemo:l}})),S=()=>{let l=m.finish();if(l===void 0)return;return se(l)},M=ge((l)=>e.addWork({cycle:{topologyDeltaReverseSnapshot:l}})),O=()=>{let l=M.finish();if(l===void 0)return;return ce(l)},N=(l,T,P,C,v,f,R,y)=>e.findDependencyPath(s,b,l,T,P,C,v,f,x,k,I===void 0,R,y);try{let l=ee(r,i,a,N,m.sink,M.sink),T=I===void 0||I.length!==l.dependencies.length||I.some((u,g)=>!Object.is(u.node,l.dependencies[g]?.node)),P=new Set(I?.map((u)=>u.node)),C=new Set(l.dependencies.map((u)=>u.node)),v=0,f=0;for(let u of C)if(!P.has(u))v++;for(let u of P)if(!C.has(u))f++;e.addWork(T?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let R=S(),y=O();return e.finishInterval(h,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:T,proposedEdgesAdded:v,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:R,topologyDeltaReverseSnapshot:y}}),l}catch(l){let T=S(),P=O();throw e.finishInterval(h,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:T,topologyDeltaReverseSnapshot:P}}),l}}}),Object.freeze(t)},le=(e={})=>{let n=te(),t=new de(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:xe(t)})};var Oe=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=le(e),r=pe(t,o);return Object.freeze({store:r,inspect:n})};export{Oe as createInspectableStore};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as o,d as a,e as n,f as l,g as p,h as c,i,j as s,k as u,l as y,m as v,n as E,o as m,p as S,r as t}from"./chunk-fbqtxaaa.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,d as a,e as n,f as l,g as p,h as c,i,j as s,k as u,l as y,m as v,n as E,o as m,p as S,r as t}from"./chunk-y5ja7h9m.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 Q,c as Z,e as ee,q as ne,s as ae}from"./chunk-fbqtxaaa.js";var ce=2048,de=1e5,q=256,H=1024,W=1e4,le=32,pe=20000,A=new Set(["span","operation","commit"]),ue=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),te=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),me=()=>{},J=Symbol("inspection dependency path root"),_=(e)=>e==="proven-terminal"?"terminal":e==="proven-reverse"?"proven":e==="ineligible-active-frames"?"active-frames":e,fe=1;class O{#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 L=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??r??0),t=Math.max(t,o.seqEnd??r??0)}return Object.freeze({firstSequence:n,lastSequence:t})},U=(e,n,t,o)=>{let r=e??n;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},G=(e)=>e.length<=q?e:e.slice(0,q),E=()=>({searches:0,visits:0,maxVisits:0,found:0}),oe=()=>({admissionSkipped:0,observing:0,consultedNoPrune:0,consultedPruned:0,disabled:0,mapProbes:0,prunedNodes:0,graphVersionResets:0,initialSeeds:0,activationReplacementSeeds:0,secondarySeeds:0,hitDerivedSeeds:0,missBudgetDisables:0,oversizedHitApproachDisables:0,passiveProbeBudgetDisables:0,maxRetainedEntries:0}),re=(e)=>Object.freeze({admissionSkipped:e.admissionSkipped,observing:e.observing,consultedNoPrune:e.consultedNoPrune,consultedPruned:e.consultedPruned,disabled:e.disabled,mapProbes:e.mapProbes,prunedNodes:e.prunedNodes,resets:Object.freeze({graphVersion:e.graphVersionResets}),seeds:Object.freeze({initial:e.initialSeeds,activationReplacement:e.activationReplacementSeeds,secondary:e.secondarySeeds,hitDerived:e.hitDerivedSeeds}),disables:Object.freeze({missBudget:e.missBudgetDisables,oversizedHitApproach:e.oversizedHitApproachDisables,passiveProbeBudget:e.passiveProbeBudgetDisables}),retained:Object.freeze({maxEntries:e.maxRetainedEntries})}),be=(e)=>{let n=oe(),t=!1;return Object.freeze({sink:Object.freeze({admissionSkipped(){t=!0,n.admissionSkipped++,e({admissionSkipped:1})},disabled(){t=!0,n.disabled++,e({disabled:1})},graphVersionReset(){t=!0,n.graphVersionResets++,e({graphVersionResets:1})},recordMapProbes(r){if(r===0)return;t=!0,n.mapProbes+=r,e({mapProbes:r})},completeSearch(r,i,s,a=0,d=0,b=0){if(t=!0,r==="observing")n.observing++;else if(r==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=a,n.prunedNodes+=d,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,b),i==="initial")n.initialSeeds++;else if(i==="activation-replacement")n.activationReplacementSeeds++;else if(i==="secondary")n.secondarySeeds++;else if(i==="hit-derived")n.hitDerivedSeeds++;if(s==="miss-budget")n.missBudgetDisables++;else if(s==="over-cap-hit")n.oversizedHitApproachDisables++;else if(s==="passive-probe-budget")n.passiveProbeBudgetDisables++;e({...r==="observing"?{observing:1}:r==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:a,prunedNodes:d,maxRetainedEntries:b,...i==="initial"?{initialSeeds:1}:i==="activation-replacement"?{activationReplacementSeeds:1}:i==="secondary"?{secondarySeeds:1}:i==="hit-derived"?{hitDerivedSeeds:1}:{},...s==="miss-budget"?{missBudgetDisables:1}:s==="over-cap-hit"?{oversizedHitApproachDisables:1}:s==="passive-probe-budget"?{passiveProbeBudgetDisables:1}:{}})}}),finish:()=>t?n:void 0})},ye=()=>({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,topologyDeltaProof:0,committed:0,scratch:0,hydration:0,newEdgeProofMemo:oe(),reverseProof:{terminal:0,proven:0,pathPossible:0,budgetExhausted:0,disabled:0,activeFrames:0,unsupported:0,nodeVisits:0,dependentProbes:0,liveDependents:0,maxWork:0,maxFrontier:0},lanes:{committed:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},scratch:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},hydration:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()}}}}),B=(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,topologyDeltaProof:e.cycle.topologyDeltaProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),newEdgeProofMemo:re(e.cycle.newEdgeProofMemo),reverseProof:Object.freeze({...e.cycle.reverseProof}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.committed.topologyDeltaProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.scratch.topologyDeltaProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.hydration.topologyDeltaProof})})})})}),z=(e,n,t,o)=>{if(n.remaining--<=0||o>le)return null;if(e===null)return null;if(typeof e==="string")return e.length<=H?e:e.slice(0,H);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,W);for(let d=0;d<a;d++)s.push(z(e[d],n,t,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,W);for(let s of i){if(te.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=z(a,n,t,o+1)}return Object.freeze(r)}finally{t.delete(e)}},F=(e)=>{if(e===void 0)return he;let n={},t={remaining:pe};for(let o of Object.keys(e).slice(0,W)){if(ue.has(o)||te.has(o))continue;let r=e[o];if(r===void 0)continue;n[o]=z(r,t,new Set,0)}return Object.freeze(n)},he=Object.freeze({}),Ie=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...F(n)})},c=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,ge=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Y;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:Y}catch(n){return{kind:"inspection-error",error:n}}},Y=Object.freeze({kind:"not-thenable"});class se{#o;#e;#r;#u;#d="";#i=1;#g=1;#S=1;#v=1;#P=1;#R=1;#E=1;#k=1;#T=1;#n=[];#m=new WeakMap;#x=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#b;#C;constructor(e,n){this.#C=n,this.#r=U(e.capacity?.summaries,ce,"Inspection summary",!1),this.#u=U(e.capacity?.details,de,"Inspection detail",!0),this.#o=new O(this.#r),this.#e=new O(this.#u),this.#b=this.#p(),this.#D()}get recordingId(){return this.#d}registerStore(e,n){this.#w.set(e,n)}capture(e,n){let t=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=t===void 0?void 0:this.#w.get(t);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(n!==void 0){let s=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let d=a.atoms.get(s),b=a.selectors.get(s);if(d===void 0&&b===void 0)throw TypeError("Inspection capture requires a valid State");let R=d?.name??b?.name;r=this.reference(s,d===void 0?"selector":"atom",typeof R==="string"?R:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#y()})}reference(e,n,t){if(this.#t!==void 0)return K;try{let o=this.#m.get(e);if(o===void 0)o=this.#T++,this.#m.set(e,o);let r=this.#x.get(e);if(r===void 0&&t!==void 0)r=G(t),this.#x.set(e,r);return Object.freeze({id:o,kind:n,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),K}}sessionId(e){let n=this.#f.get(e);if(n!==void 0)return n;let t=this.#E++;return this.#f.set(e,t),t}beginInterval(e){if(this.#t!==void 0)return X;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#y(),...e.links}),r={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:G(e.name),seqStart:this.#i++,startUs:this.#I(),fields:F(e.fields),totals:A.has(e.type)?ye():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:A.has(e.type)?this.#O():void 0};if(e.type==="commit"){let i=this.#s("operation");if(i!==void 0)i.commitId=n}return this.#n.push(r),t}catch{return this.#c("begin-interval"),X}}finishInterval(e,n={}){if(e.id===0||this.#t!==void 0)return;try{let t=this.#n.pop();if(t===void 0||!Object.is(t.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#j(t);let o=this.#i++,r=Math.max(0,this.#I()-t.startUs),i=Ie(t.fields,n.fields),s=this.#z(t,o,r,i,n.result);if(A.has(t.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 n=this.#i++,t=Object.freeze({...F(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#y(),...e.links});if(this.#e.add(t))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let n of this.#n){let t=n.totals;if(t===void 0)continue;t.selectorEvaluations=c(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=c(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=c(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=c(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=c(t.propagationSettled,e.propagationSettled),t.notificationTargets=c(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=c(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=c(t.cycle.searches,o.searches),t.cycle.visits=c(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=c(t.cycle.found,o.found);let r=o.newEdgeProofMemo;if(r!==void 0){let s=t.cycle.newEdgeProofMemo;s.admissionSkipped=c(s.admissionSkipped,r.admissionSkipped),s.observing=c(s.observing,r.observing),s.consultedNoPrune=c(s.consultedNoPrune,r.consultedNoPrune),s.consultedPruned=c(s.consultedPruned,r.consultedPruned),s.disabled=c(s.disabled,r.disabled),s.mapProbes=c(s.mapProbes,r.mapProbes),s.prunedNodes=c(s.prunedNodes,r.prunedNodes),s.graphVersionResets=c(s.graphVersionResets,r.graphVersionResets),s.initialSeeds=c(s.initialSeeds,r.initialSeeds),s.activationReplacementSeeds=c(s.activationReplacementSeeds,r.activationReplacementSeeds),s.secondarySeeds=c(s.secondarySeeds,r.secondarySeeds),s.hitDerivedSeeds=c(s.hitDerivedSeeds,r.hitDerivedSeeds),s.missBudgetDisables=c(s.missBudgetDisables,r.missBudgetDisables),s.oversizedHitApproachDisables=c(s.oversizedHitApproachDisables,r.oversizedHitApproachDisables),s.passiveProbeBudgetDisables=c(s.passiveProbeBudgetDisables,r.passiveProbeBudgetDisables),s.maxRetainedEntries=Math.max(s.maxRetainedEntries,r.maxRetainedEntries??0)}let i=o.reverseProof;if(i!==void 0){let s=t.cycle.reverseProof;if(i.outcome==="terminal")s.terminal++;else if(i.outcome==="proven")s.proven++;else if(i.outcome==="path-possible")s.pathPossible++;else if(i.outcome==="budget-exhausted")s.budgetExhausted++;else if(i.outcome==="disabled")s.disabled++;else if(i.outcome==="active-frames")s.activeFrames++;else s.unsupported++;s.nodeVisits=c(s.nodeVisits,i.nodeVisits),s.dependentProbes=c(s.dependentProbes,i.dependentProbes),s.liveDependents=c(s.liveDependents,i.liveDependents),s.maxWork=Math.max(s.maxWork,i.nodeVisits+i.dependentProbes),s.maxFrontier=Math.max(s.maxFrontier,i.maxFrontier)}if(o.site==="prefix-revalidation")t.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")t.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")t.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)t.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let s=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",a=t.cycle.lanes[o.host][s];a.searches=c(a.searches,o.searches),a.visits=c(a.visits,o.visits),a.maxVisits=Math.max(a.maxVisits,o.maxVisits??0),a.found=c(a.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,n){let t=this.#s("operation"),o=t===void 0||!Object.is(t.token,e)||t.commitId===void 0||!t.commitSourceApplied?"none":n==="returned"?"committed":t.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:n,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,n){let t=this.#s("operation");if(t!==void 0)t.commitSourceApplied||=n.sourceApplied,t.commitFailurePhase=n.failurePhase;this.finishInterval(e,{result:n.result,fields:{intents:n.intents,...n.changedSources===void 0?{}:{changedSources:n.changedSources},...n.ownershipChanged===void 0?{}:{ownershipChanged:n.ownershipChanged},sourceApplied:n.sourceApplied,notificationsCompleted:n.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 n=e[0];if(n===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(n===1){let o=e[1]===0?"returned":"threw",r=this.#s("operation");if(r===void 0)return;let i=this.#s("commit");if(i!==void 0)this.#j(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(n===2){let o=this.#s("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#s("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#s("operation");if(t!==void 0)t.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.#s("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let r=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,n,t,o,r,i,s,a,d,b,R,k){let S=s===0?"prefix-revalidation":s===1?"new-edge-proof":"topology-delta-proof",D=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-d,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-b,acceptedPrefixLength:a,parentWasCold:R}}),m={nodeVisits:0,dependentProbes:0,liveDependents:0,maxFrontier:0},l=s===1?Q(t,o,r,i,m,k?.reverseProofEnabled??!0):void 0;if(l==="budget-exhausted"&&k!==void 0)k.reverseProofEnabled=!1;let j=l==="proven-terminal"||l==="proven-reverse",N=0,p=0,y=0,C=0,T=0,x=0,g;if(!j){let h=k?.(),f=h?.beginSearch()??!1,I=[t],w=new Map([[t,J]]);y=1;while(I.length>0){let v=I.pop();if(N++,Object.is(v,o)){let u=[],P=v;while(P!==J)u.push(P),P=w.get(P);u.reverse(),g=Object.freeze(u);break}let M=i.getTransientDependencies(r,v);if(M){if(C++,M.length===0)continue;if(f){let u=h.hasProvenNoPathMeasured(v);if(!h.enabled)f=!1;if(u)continue}p+=M.length;for(let u of M){if(w.has(u.node))continue;w.set(u.node,v),I.push(u.node)}if(I.length>y)y=I.length;continue}if(r.getSelectorDependencyNodes!==void 0){let u=r.getSelectorDependencyNodes(v);if(u===void 0){x++;continue}if(T++,u.length===0)continue;if(f){let P=h.hasProvenNoPathMeasured(v);if(!h.enabled)f=!1;if(P)continue}p+=u.length;for(let P of u){if(w.has(P))continue;w.set(P,v),I.push(P)}if(I.length>y)y=I.length;continue}let V=r.getSelectorRecord(v);if(!V){x++;continue}if(T++,V.dependencies.length===0)continue;if(f){let u=h.hasProvenNoPathMeasured(v);if(!h.enabled)f=!1;if(u)continue}p+=V.dependencies.length;for(let u of V.dependencies){if(w.has(u.node))continue;w.set(u.node,v),I.push(u.node)}if(I.length>y)y=I.length}if(g===void 0)h?.completeNegative(w);else h?.completePositive()}return this.addWork({cycle:{searches:1,visits:N,maxVisits:N,found:g===void 0?0:1,site:S,host:e,...l===void 0?{}:{reverseProof:{outcome:_(l),...m}}}}),this.finishInterval(D,{result:"returned",fields:{visits:N,edges:p,maxFrontier:y,transientExpansions:C,recordExpansions:T,terminalPrunes:x,...l===void 0?{}:{reverseProof:{outcome:_(l),...m}},found:g!==void 0,...g===void 0?{}:{path:g.map((h)=>this.#h(h))}}}),g}span(e,n){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof n!=="function")throw TypeError("Inspection span callback must be a function");let t=this.beginInterval({type:"span",name:e}),o;try{o=n()}catch(i){throw this.finishInterval(t,{result:"threw"}),i}let r=ge(o);if(r.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,me])}catch{}throw this.finishInterval(t,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(t,{result:"returned"}),o}export(){this.#N("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),n=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),t=L(e),o=L(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:4,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(n),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...t===void 0?{}:{summaries:t},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#N("reset"),this.#D()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(n,t)=>e.capture(n,t),span:(n,t)=>e.span(n,t),export:()=>e.export(),reset:()=>e.reset()})}#D(){this.#d=`inspection-${fe++}`,this.#o=new O(this.#r),this.#e=new O(this.#u),this.#i=1,this.#g=1,this.#S=1,this.#v=1,this.#P=1,this.#R=1,this.#E=1,this.#k=1,this.#T=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#b=this.#p()}#V(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.#P++;if(e==="cycle-search")return this.#R++;return this.#k++}#y(){let e={};for(let n of this.#n){let{id:t,type:o}=n.token;if(n.links.sessionId!==void 0)e.sessionId=n.links.sessionId;if(o==="span")e.spanId=t;else if(o==="operation")e.operationId=t;else if(o==="commit")e.commitId=t;else if(o==="selector-evaluation")e.evaluationId=t;else if(o==="cycle-search")e.searchId=t}return e}#s(e){for(let n=this.#n.length-1;n>=0;n--){let t=this.#n[n];if(t.token.type===e)return t}return}#h(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):z(e,{remaining:1},new Set,0)}#z(e,n,t,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:n,startUs:e.startUs,durationUs:t,...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:B(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:B(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:B(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`)}#O(){let e=(n)=>this.#C.read(n);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#j(e){let n=e.counterStart;if(n===void 0)return;e.counterStart=void 0;let t=this.#O();if(e.token.type==="commit")e.commitOwnershipChanged=t.sourceEpoch!==n.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=t.transientSelectorHostsCreated-n.transientSelectorHostsCreated,o.propagationSettled+=t.propagationSettled-n.propagationSettled,o.notificationTargets+=t.notificationTargets-n.notificationTargets,o.subscriberCallbacks+=t.subscriberCallbacks-n.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let n=this.#i++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:n}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#M(e){return Math.max(0,Math.round((e-this.#b)*1000))}#I(){return this.#M(this.#p())}}var K=Object.freeze({id:0,kind:"store"}),X=Object.freeze({id:0,type:"operation"}),Se=(e)=>{let n=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let d=a();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof ee?1:0),d}},t=(r,i,s)=>{if(r===0){let a=i,d=s;e.registerStore(a,d);let b=a,R=a.set,k=a.update,S=a.reset,D=a.txn;b.set=(m,l)=>n(0,d,void 0,()=>R(m,l)),b.update=(m,l)=>n(1,d,void 0,()=>k(m,l)),b.reset=(m)=>n(2,d,void 0,()=>S(m)),b.txn=(m,l)=>{if(typeof m!=="function"||l!==void 0&&typeof l!=="string")return D(m,l);return n(3,d,l,()=>D(m,l))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(t,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=i.name,b=e.reference(i,a==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),R=i.getSelectorGraphVersion(),k=s.getSelectorGraphPublicationCount(i),S=i.getSelectorRecord(r.node)?.dependencies,D=S?.length??0,m=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:b,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:R,previousDependencyCount:D}});e.addWork({selectorEvaluations:1});let l=be((p)=>e.addWork({cycle:{newEdgeProofMemo:p}})),j=()=>{let p=l.finish();if(p===void 0)return;return re(p)},N=(p,y,C,T,x,g,h)=>e.findDependencyPath(a,b,p,y,C,T,x,g,R,k,S===void 0,h);try{let p=Z(r,i,s,N,l.sink),y=S===void 0||S.length!==p.dependencies.length||S.some((f,I)=>!Object.is(f.node,p.dependencies[I]?.node)),C=new Set(S?.map((f)=>f.node)),T=new Set(p.dependencies.map((f)=>f.node)),x=0,g=0;for(let f of T)if(!C.has(f))x++;for(let f of C)if(!T.has(f))g++;e.addWork(y?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let h=j();return e.finishInterval(m,{result:"returned",fields:{outcome:p.outcome.kind,dependencyCount:p.dependencies.length,proposedTopologyChanged:y,proposedEdgesAdded:x,proposedEdgesRemoved:g,graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:h}}),p}catch(p){let y=j();throw e.finishInterval(m,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:y}}),p}}}),Object.freeze(t)},ie=(e={})=>{let n=ne(),t=new se(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:Se(t)})};var Te=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=ie(e),r=ae(t,o);return Object.freeze({store:r,inspect:n})};export{Te as createInspectableStore};
1
+ import{b as Z,c as ee,e as ne,q as te,s as pe}from"./chunk-y5ja7h9m.js";var ue=2048,me=1e5,q=256,H=1024,B=1e4,fe=32,be=20000,F=new Set(["span","operation","commit"]),ye=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),oe=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),he=()=>{},_=Symbol("inspection dependency path root"),L=(e)=>e==="proven-terminal"?"terminal":e==="proven-reverse"?"proven":e==="ineligible-active-frames"?"active-frames":e,Ie=1;class j{#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 U=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??r??0),t=Math.max(t,o.seqEnd??r??0)}return Object.freeze({firstSequence:n,lastSequence:t})},G=(e,n,t,o)=>{let r=e??n;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},Y=(e)=>e.length<=q?e:e.slice(0,q),D=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({admissionSkipped:0,observing:0,consultedNoPrune:0,consultedPruned:0,disabled:0,mapProbes:0,prunedNodes:0,graphVersionResets:0,initialSeeds:0,activationReplacementSeeds:0,secondarySeeds:0,hitDerivedSeeds:0,missBudgetDisables:0,oversizedHitApproachDisables:0,passiveProbeBudgetDisables:0,maxRetainedEntries:0}),se=(e)=>Object.freeze({admissionSkipped:e.admissionSkipped,observing:e.observing,consultedNoPrune:e.consultedNoPrune,consultedPruned:e.consultedPruned,disabled:e.disabled,mapProbes:e.mapProbes,prunedNodes:e.prunedNodes,resets:Object.freeze({graphVersion:e.graphVersionResets}),seeds:Object.freeze({initial:e.initialSeeds,activationReplacement:e.activationReplacementSeeds,secondary:e.secondarySeeds,hitDerived:e.hitDerivedSeeds}),disables:Object.freeze({missBudget:e.missBudgetDisables,oversizedHitApproach:e.oversizedHitApproachDisables,passiveProbeBudget:e.passiveProbeBudgetDisables}),retained:Object.freeze({maxEntries:e.maxRetainedEntries})}),ie=()=>({attempts:0,completed:0,overflow:0,unavailable:0,scannedActiveFrames:0,scannedPrefixEdges:0,maxScannedActiveFrames:0,maxScannedPrefixEdges:0,capturedActiveFrames:0,capturedPrefixEdges:0,maxCapturedActiveFrames:0,maxCapturedPrefixEdges:0}),ae=(e,n)=>{if(e.attempts++,n.outcome==="completed")e.completed++;else if(n.outcome==="overflow")e.overflow++;else e.unavailable++;if(e.scannedActiveFrames=d(e.scannedActiveFrames,n.scannedFrames),e.scannedPrefixEdges=d(e.scannedPrefixEdges,n.prefixEdges),e.maxScannedActiveFrames=Math.max(e.maxScannedActiveFrames,n.scannedFrames),e.maxScannedPrefixEdges=Math.max(e.maxScannedPrefixEdges,n.prefixEdges),n.outcome!=="completed")return;e.capturedActiveFrames=d(e.capturedActiveFrames,n.activeFrames),e.capturedPrefixEdges=d(e.capturedPrefixEdges,n.prefixEdges),e.maxCapturedActiveFrames=Math.max(e.maxCapturedActiveFrames,n.activeFrames),e.maxCapturedPrefixEdges=Math.max(e.maxCapturedPrefixEdges,n.prefixEdges)},ce=(e)=>Object.freeze({...e}),ge=(e)=>{let n=ie();return Object.freeze({sink:Object.freeze({recordSnapshot(o,r,i,a){let s={outcome:o,scannedFrames:r,activeFrames:i,prefixEdges:a};ae(n,s),e(s)}}),finish:()=>n.attempts===0?void 0:n})},ve=(e)=>{let n=re(),t=!1;return Object.freeze({sink:Object.freeze({admissionSkipped(){t=!0,n.admissionSkipped++,e({admissionSkipped:1})},disabled(){t=!0,n.disabled++,e({disabled:1})},graphVersionReset(){t=!0,n.graphVersionResets++,e({graphVersionResets:1})},recordMapProbes(r){if(r===0)return;t=!0,n.mapProbes+=r,e({mapProbes:r})},completeSearch(r,i,a,s=0,c=0,b=0){if(t=!0,r==="observing")n.observing++;else if(r==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=s,n.prunedNodes+=c,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,b),i==="initial")n.initialSeeds++;else if(i==="activation-replacement")n.activationReplacementSeeds++;else if(i==="secondary")n.secondarySeeds++;else if(i==="hit-derived")n.hitDerivedSeeds++;if(a==="miss-budget")n.missBudgetDisables++;else if(a==="over-cap-hit")n.oversizedHitApproachDisables++;else if(a==="passive-probe-budget")n.passiveProbeBudgetDisables++;e({...r==="observing"?{observing:1}:r==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:s,prunedNodes:c,maxRetainedEntries:b,...i==="initial"?{initialSeeds:1}:i==="activation-replacement"?{activationReplacementSeeds:1}:i==="secondary"?{secondarySeeds:1}:i==="hit-derived"?{hitDerivedSeeds:1}:{},...a==="miss-budget"?{missBudgetDisables:1}:a==="over-cap-hit"?{oversizedHitApproachDisables:1}:a==="passive-probe-budget"?{passiveProbeBudgetDisables:1}:{}})}}),finish:()=>t?n:void 0})},Se=()=>({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,topologyDeltaProof:0,committed:0,scratch:0,hydration:0,newEdgeProofMemo:re(),reverseProof:{terminal:0,proven:0,pathPossible:0,budgetExhausted:0,disabled:0,activeFrames:0,unsupported:0,nodeVisits:0,dependentProbes:0,liveDependents:0,maxWork:0,maxFrontier:0,topologyDeltaSnapshot:ie()},lanes:{committed:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},scratch:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},hydration:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()}}}}),W=(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,topologyDeltaProof:e.cycle.topologyDeltaProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),newEdgeProofMemo:se(e.cycle.newEdgeProofMemo),reverseProof:Object.freeze({...e.cycle.reverseProof,topologyDeltaSnapshot:ce(e.cycle.reverseProof.topologyDeltaSnapshot)}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.committed.topologyDeltaProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.scratch.topologyDeltaProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.hydration.topologyDeltaProof})})})})}),z=(e,n,t,o)=>{if(n.remaining--<=0||o>fe)return null;if(e===null)return null;if(typeof e==="string")return e.length<=H?e:e.slice(0,H);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){let a=[],s=Math.min(e.length,B);for(let c=0;c<s;c++)a.push(z(e[c],n,t,o+1));return Object.freeze(a)}let r={},i=Object.keys(e).slice(0,B);for(let a of i){if(oe.has(a))continue;let s=Reflect.get(e,a);if(s===void 0)continue;r[a]=z(s,n,t,o+1)}return Object.freeze(r)}finally{t.delete(e)}},J=(e)=>{if(e===void 0)return Pe;let n={},t={remaining:be};for(let o of Object.keys(e).slice(0,B)){if(ye.has(o)||oe.has(o))continue;let r=e[o];if(r===void 0)continue;n[o]=z(r,t,new Set,0)}return Object.freeze(n)},Pe=Object.freeze({}),Re=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...J(n)})},d=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,Ee=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return K;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:K}catch(n){return{kind:"inspection-error",error:n}}},K=Object.freeze({kind:"not-thenable"});class de{#o;#e;#r;#u;#d="";#i=1;#g=1;#v=1;#S=1;#P=1;#R=1;#E=1;#x=1;#T=1;#n=[];#m=new WeakMap;#D=new WeakMap;#k=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#b;#C;constructor(e,n){this.#C=n,this.#r=G(e.capacity?.summaries,ue,"Inspection summary",!1),this.#u=G(e.capacity?.details,me,"Inspection detail",!0),this.#o=new j(this.#r),this.#e=new j(this.#u),this.#b=this.#p(),this.#w()}get recordingId(){return this.#d}registerStore(e,n){this.#k.set(e,n)}capture(e,n){let t=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=t===void 0?void 0:this.#k.get(t);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(n!==void 0){let a=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,s=o.coordinator.runtimeDomain;if(a===void 0||!s.states.has(a))throw TypeError("Inspection capture requires a valid State");let c=s.atoms.get(a),b=s.selectors.get(a);if(c===void 0&&b===void 0)throw TypeError("Inspection capture requires a valid State");let x=c?.name??b?.name;r=this.reference(a,c===void 0?"selector":"atom",typeof x==="string"?x:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#y()})}reference(e,n,t){if(this.#t!==void 0)return X;try{let o=this.#m.get(e);if(o===void 0)o=this.#T++,this.#m.set(e,o);let r=this.#D.get(e);if(r===void 0&&t!==void 0)r=Y(t),this.#D.set(e,r);return Object.freeze({id:o,kind:n,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),X}}sessionId(e){let n=this.#f.get(e);if(n!==void 0)return n;let t=this.#E++;return this.#f.set(e,t),t}beginInterval(e){if(this.#t!==void 0)return Q;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#y(),...e.links}),r={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:Y(e.name),seqStart:this.#i++,startUs:this.#I(),fields:J(e.fields),totals:F.has(e.type)?Se():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:F.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#s("operation");if(i!==void 0)i.commitId=n}return this.#n.push(r),t}catch{return this.#c("begin-interval"),Q}}finishInterval(e,n={}){if(e.id===0||this.#t!==void 0)return;try{let t=this.#n.pop();if(t===void 0||!Object.is(t.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#j(t);let o=this.#i++,r=Math.max(0,this.#I()-t.startUs),i=Re(t.fields,n.fields),a=this.#A(t,o,r,i,n.result);if(F.has(t.token.type)){if(this.#o.add(a))this.#l++}else if(this.#e.add(a))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let n=this.#i++,t=Object.freeze({...J(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#y(),...e.links});if(this.#e.add(t))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let n of this.#n){let t=n.totals;if(t===void 0)continue;t.selectorEvaluations=d(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=d(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=d(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=d(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=d(t.propagationSettled,e.propagationSettled),t.notificationTargets=d(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=d(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=d(t.cycle.searches,o.searches),t.cycle.visits=d(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=d(t.cycle.found,o.found);let r=o.newEdgeProofMemo;if(r!==void 0){let s=t.cycle.newEdgeProofMemo;s.admissionSkipped=d(s.admissionSkipped,r.admissionSkipped),s.observing=d(s.observing,r.observing),s.consultedNoPrune=d(s.consultedNoPrune,r.consultedNoPrune),s.consultedPruned=d(s.consultedPruned,r.consultedPruned),s.disabled=d(s.disabled,r.disabled),s.mapProbes=d(s.mapProbes,r.mapProbes),s.prunedNodes=d(s.prunedNodes,r.prunedNodes),s.graphVersionResets=d(s.graphVersionResets,r.graphVersionResets),s.initialSeeds=d(s.initialSeeds,r.initialSeeds),s.activationReplacementSeeds=d(s.activationReplacementSeeds,r.activationReplacementSeeds),s.secondarySeeds=d(s.secondarySeeds,r.secondarySeeds),s.hitDerivedSeeds=d(s.hitDerivedSeeds,r.hitDerivedSeeds),s.missBudgetDisables=d(s.missBudgetDisables,r.missBudgetDisables),s.oversizedHitApproachDisables=d(s.oversizedHitApproachDisables,r.oversizedHitApproachDisables),s.passiveProbeBudgetDisables=d(s.passiveProbeBudgetDisables,r.passiveProbeBudgetDisables),s.maxRetainedEntries=Math.max(s.maxRetainedEntries,r.maxRetainedEntries??0)}let i=o.topologyDeltaReverseSnapshot;if(i!==void 0)ae(t.cycle.reverseProof.topologyDeltaSnapshot,i);let a=o.reverseProof;if(a!==void 0){let s=t.cycle.reverseProof;if(a.outcome==="terminal")s.terminal++;else if(a.outcome==="proven")s.proven++;else if(a.outcome==="path-possible")s.pathPossible++;else if(a.outcome==="budget-exhausted")s.budgetExhausted++;else if(a.outcome==="disabled")s.disabled++;else if(a.outcome==="active-frames")s.activeFrames++;else s.unsupported++;s.nodeVisits=d(s.nodeVisits,a.nodeVisits),s.dependentProbes=d(s.dependentProbes,a.dependentProbes),s.liveDependents=d(s.liveDependents,a.liveDependents),s.maxWork=Math.max(s.maxWork,a.nodeVisits+a.dependentProbes),s.maxFrontier=Math.max(s.maxFrontier,a.maxFrontier)}if(o.site==="prefix-revalidation")t.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")t.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")t.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)t.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let s=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",c=t.cycle.lanes[o.host][s];c.searches=d(c.searches,o.searches),c.visits=d(c.visits,o.visits),c.maxVisits=Math.max(c.maxVisits,o.maxVisits??0),c.found=d(c.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,n){let t=this.#s("operation"),o=t===void 0||!Object.is(t.token,e)||t.commitId===void 0||!t.commitSourceApplied?"none":n==="returned"?"committed":t.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:n,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,n){let t=this.#s("operation");if(t!==void 0)t.commitSourceApplied||=n.sourceApplied,t.commitFailurePhase=n.failurePhase;this.finishInterval(e,{result:n.result,fields:{intents:n.intents,...n.changedSources===void 0?{}:{changedSources:n.changedSources},...n.ownershipChanged===void 0?{}:{ownershipChanged:n.ownershipChanged},sourceApplied:n.sourceApplied,notificationsCompleted:n.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 n=e[0];if(n===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(n===1){let o=e[1]===0?"returned":"threw",r=this.#s("operation");if(r===void 0)return;let i=this.#s("commit");if(i!==void 0)this.#j(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(n===2){let o=this.#s("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#s("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#s("operation");if(t!==void 0)t.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.#s("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let r=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,n,t,o,r,i,a,s,c,b,x,k,I){let w=a===0?"prefix-revalidation":a===1?"new-edge-proof":"topology-delta-proof",h=this.beginInterval({type:"cycle-search",fields:{site:w,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-b,acceptedPrefixLength:s,parentWasCold:x}}),m={nodeVisits:0,dependentProbes:0,liveDependents:0,maxFrontier:0},S=a===1||a===2?Z(t,o,r,i,m,a===1?k?.reverseProofEnabled??!0:I?.reverseProofEnabled??!0,I?.transientDependents):void 0;if(S==="budget-exhausted"){if(a===1&&k!==void 0)k.reverseProofEnabled=!1;else if(I!==void 0)I.reverseProofEnabled=!1}let M=S==="proven-terminal"||S==="proven-reverse",O=0,N=0,l=0,T=0,P=0,C=0,v;if(!M){let f=k?.(),R=f?.beginSearch()??!1,y=[t],u=new Map([[t,_]]);l=1;while(y.length>0){let g=y.pop();if(O++,Object.is(g,o)){let p=[],E=g;while(E!==_)p.push(E),E=u.get(E);p.reverse(),v=Object.freeze(p);break}let V=i.getTransientDependencies(r,g);if(V){if(T++,V.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=V.length;for(let p of V){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length;continue}if(r.getSelectorDependencyNodes!==void 0){let p=r.getSelectorDependencyNodes(g);if(p===void 0){C++;continue}if(P++,p.length===0)continue;if(R){let E=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(E)continue}N+=p.length;for(let E of p){if(u.has(E))continue;u.set(E,g),y.push(E)}if(y.length>l)l=y.length;continue}let A=r.getSelectorRecord(g);if(!A){C++;continue}if(P++,A.dependencies.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=A.dependencies.length;for(let p of A.dependencies){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length}if(v===void 0)f?.completeNegative(u);else f?.completePositive()}return this.addWork({cycle:{searches:1,visits:O,maxVisits:O,found:v===void 0?0:1,site:w,host:e,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}}}}),this.finishInterval(h,{result:"returned",fields:{visits:O,edges:N,maxFrontier:l,transientExpansions:T,recordExpansions:P,terminalPrunes:C,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}},found:v!==void 0,...v===void 0?{}:{path:v.map((f)=>this.#h(f))}}}),v}span(e,n){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof n!=="function")throw TypeError("Inspection span callback must be a function");let t=this.beginInterval({type:"span",name:e}),o;try{o=n()}catch(i){throw this.finishInterval(t,{result:"threw"}),i}let r=Ee(o);if(r.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,he])}catch{}throw this.finishInterval(t,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(t,{result:"returned"}),o}export(){this.#O("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),n=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),t=U(e),o=U(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:5,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(n),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...t===void 0?{}:{summaries:t},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#O("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(n,t)=>e.capture(n,t),span:(n,t)=>e.span(n,t),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#d=`inspection-${Ie++}`,this.#o=new j(this.#r),this.#e=new j(this.#u),this.#i=1,this.#g=1,this.#v=1,this.#S=1,this.#P=1,this.#R=1,this.#E=1,this.#x=1,this.#T=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#b=this.#p()}#V(e){if(e==="span")return this.#g++;if(e==="operation")return this.#v++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#P++;if(e==="cycle-search")return this.#R++;return this.#x++}#y(){let e={};for(let n of this.#n){let{id:t,type:o}=n.token;if(n.links.sessionId!==void 0)e.sessionId=n.links.sessionId;if(o==="span")e.spanId=t;else if(o==="operation")e.operationId=t;else if(o==="commit")e.commitId=t;else if(o==="selector-evaluation")e.evaluationId=t;else if(o==="cycle-search")e.searchId=t}return e}#s(e){for(let n=this.#n.length-1;n>=0;n--){let t=this.#n[n];if(t.token.type===e)return t}return}#h(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):z(e,{remaining:1},new Set,0)}#A(e,n,t,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:n,startUs:e.startUs,durationUs:t,...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:W(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:W(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:W(e.totals)});let a=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,...a})}#O(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(n)=>this.#C.read(n);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#j(e){let n=e.counterStart;if(n===void 0)return;e.counterStart=void 0;let t=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=t.sourceEpoch!==n.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=t.transientSelectorHostsCreated-n.transientSelectorHostsCreated,o.propagationSettled+=t.propagationSettled-n.propagationSettled,o.notificationTargets+=t.notificationTargets-n.notificationTargets,o.subscriberCallbacks+=t.subscriberCallbacks-n.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let n=this.#i++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:n}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#M(e){return Math.max(0,Math.round((e-this.#b)*1000))}#I(){return this.#M(this.#p())}}var X=Object.freeze({id:0,kind:"store"}),Q=Object.freeze({id:0,type:"operation"}),xe=(e)=>{let n=(r,i,a,s)=>{if(e.hasActiveStoreOperation())return s();e.recordStoreEvent(0,r,i,i.name,a);try{let c=s();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof ne?1:0),c}},t=(r,i,a)=>{if(r===0){let s=i,c=a;e.registerStore(s,c);let b=s,x=s.set,k=s.update,I=s.reset,w=s.txn;b.set=(h,m)=>n(0,c,void 0,()=>x(h,m)),b.update=(h,m)=>n(1,c,void 0,()=>k(h,m)),b.reset=(h)=>n(2,c,void 0,()=>I(h)),b.txn=(h,m)=>{if(typeof h!=="function"||m!==void 0&&typeof m!=="string")return w(h,m);return n(3,c,m,()=>w(h,m))};return}if(r===1){e.beginDraftCommit(i,a);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(t,{evaluate:(r,i,a)=>{let s=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,b=e.reference(i,s==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),x=i.getSelectorGraphVersion(),k=a.getSelectorGraphPublicationCount(i),I=i.getSelectorRecord(r.node)?.dependencies,w=I?.length??0,h=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(a)},fields:{host:s,hostRef:b,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:x,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let m=ve((l)=>e.addWork({cycle:{newEdgeProofMemo:l}})),S=()=>{let l=m.finish();if(l===void 0)return;return se(l)},M=ge((l)=>e.addWork({cycle:{topologyDeltaReverseSnapshot:l}})),O=()=>{let l=M.finish();if(l===void 0)return;return ce(l)},N=(l,T,P,C,v,f,R,y)=>e.findDependencyPath(s,b,l,T,P,C,v,f,x,k,I===void 0,R,y);try{let l=ee(r,i,a,N,m.sink,M.sink),T=I===void 0||I.length!==l.dependencies.length||I.some((u,g)=>!Object.is(u.node,l.dependencies[g]?.node)),P=new Set(I?.map((u)=>u.node)),C=new Set(l.dependencies.map((u)=>u.node)),v=0,f=0;for(let u of C)if(!P.has(u))v++;for(let u of P)if(!C.has(u))f++;e.addWork(T?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let R=S(),y=O();return e.finishInterval(h,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:T,proposedEdgesAdded:v,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:R,topologyDeltaReverseSnapshot:y}}),l}catch(l){let T=S(),P=O();throw e.finishInterval(h,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:T,topologyDeltaReverseSnapshot:P}}),l}}}),Object.freeze(t)},le=(e={})=>{let n=te(),t=new de(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:xe(t)})};var Oe=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=le(e),r=pe(t,o);return Object.freeze({store:r,inspect:n})};export{Oe as createInspectableStore};
@@ -1,5 +1,5 @@
1
1
  import type { Store } from "./v1.js";
2
- import type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionNewEdgeProofMemoTotals, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionReverseProofOutcome, InspectionReverseProofTotals, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector } from "./v1-internal/inspection.js";
2
+ import type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionNewEdgeProofMemoTotals, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionReverseProofOutcome, InspectionReverseProofTotals, InspectionTopologyDeltaReverseSnapshotTotals, 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, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionNewEdgeProofMemoTotals, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionReverseProofOutcome, InspectionReverseProofTotals, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector, };
12
+ export type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionNewEdgeProofMemoTotals, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionReverseProofOutcome, InspectionReverseProofTotals, InspectionTopologyDeltaReverseSnapshotTotals, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector, };
@@ -1,6 +1,6 @@
1
1
  import { type InternalStoreTreeInstrumentation, type InternalStoreTreeTrace } from "./committed-store-tree/committed-store-tree.js";
2
2
  import type { CommittedStoreTree, State } from "./committed-store-tree/types.js";
3
- import type { SelectorCycleSearchSite, SelectorEvaluationHost, SelectorEvaluationSession, SelectorNewEdgeProofMemoProvider } from "./selector-evaluator/types.js";
3
+ import type { SelectorCycleSearchSite, SelectorEvaluationHost, SelectorEvaluationSession, SelectorNewEdgeProofMemoProvider, SelectorTopologyDeltaReverseProofContext, SelectorTopologyDeltaReverseSnapshotOutcome } from "./selector-evaluator/types.js";
4
4
  type StoreRecorderEvent = readonly [
5
5
  event: 0,
6
6
  operation: 0 | 1 | 2 | 3,
@@ -62,9 +62,28 @@ export type InspectionNewEdgeProofMemoTotals = Readonly<{
62
62
  }>;
63
63
  }> & InspectionJsonObject;
64
64
  export type InspectionReverseProofOutcome = "terminal" | "proven" | "path-possible" | "budget-exhausted" | "disabled" | "active-frames" | "unsupported";
65
- /** Bounded reverse-first work and outcomes for logical site-1 proofs. */
65
+ /** Construction outcomes and work for topology-delta reverse snapshots. */
66
+ export type InspectionTopologyDeltaReverseSnapshotTotals = Readonly<{
67
+ /** These three outcomes partition all nonempty exact-delta attempts. */
68
+ readonly attempts: number;
69
+ readonly completed: number;
70
+ readonly overflow: number;
71
+ readonly unavailable: number;
72
+ /** Session frames scanned by every attempt, including fail-closed attempts. */
73
+ readonly scannedActiveFrames: number;
74
+ /** Same-host prefix work scanned by every attempt. */
75
+ readonly scannedPrefixEdges: number;
76
+ readonly maxScannedActiveFrames: number;
77
+ readonly maxScannedPrefixEdges: number;
78
+ /** Effective snapshot size, counted only after complete construction. */
79
+ readonly capturedActiveFrames: number;
80
+ readonly capturedPrefixEdges: number;
81
+ readonly maxCapturedActiveFrames: number;
82
+ readonly maxCapturedPrefixEdges: number;
83
+ }> & InspectionJsonObject;
84
+ /** Bounded reverse-first work and outcomes for all site-1/site-2 proofs. */
66
85
  export type InspectionReverseProofTotals = Readonly<{
67
- /** These seven outcomes partition all new-edge proofs. */
86
+ /** These outcomes partition every site-1 and site-2 logical proof. */
68
87
  readonly terminal: number;
69
88
  readonly proven: number;
70
89
  readonly pathPossible: number;
@@ -78,6 +97,7 @@ export type InspectionReverseProofTotals = Readonly<{
78
97
  readonly liveDependents: number;
79
98
  readonly maxWork: number;
80
99
  readonly maxFrontier: number;
100
+ readonly topologyDeltaSnapshot: InspectionTopologyDeltaReverseSnapshotTotals;
81
101
  }> & InspectionJsonObject;
82
102
  export interface InspectionCycleTotals {
83
103
  readonly searches: number;
@@ -197,6 +217,7 @@ interface SelectorEvaluationInspectionBase extends InspectionDetailLinks {
197
217
  readonly graphVersionEnd: number;
198
218
  readonly previousDependencyCount: number;
199
219
  readonly newEdgeProofMemo?: InspectionNewEdgeProofMemoTotals;
220
+ readonly topologyDeltaReverseSnapshot?: InspectionTopologyDeltaReverseSnapshotTotals;
200
221
  }
201
222
  export type SelectorEvaluationInspectionDetail = SelectorEvaluationInspectionBase & (Readonly<{
202
223
  outcome: "value" | "error" | "control-error";
@@ -259,7 +280,7 @@ export interface InspectionRecorderFault {
259
280
  }
260
281
  export interface InspectionExport {
261
282
  readonly schema: "valdres.inspect";
262
- readonly schemaVersion: 4;
283
+ readonly schemaVersion: 5;
263
284
  readonly recordingId: string;
264
285
  readonly summaries: readonly InspectionSummary[];
265
286
  readonly details: readonly InspectionDetail[];
@@ -354,6 +375,12 @@ type ReverseProofWorkDelta = Readonly<{
354
375
  liveDependents: number;
355
376
  maxFrontier: number;
356
377
  }>;
378
+ type TopologyDeltaReverseSnapshotWorkDelta = Readonly<{
379
+ outcome: SelectorTopologyDeltaReverseSnapshotOutcome;
380
+ scannedFrames: number;
381
+ activeFrames: number;
382
+ prefixEdges: number;
383
+ }>;
357
384
  export interface InspectionWorkDelta {
358
385
  readonly selectorEvaluations?: number;
359
386
  readonly proposedTopologyChanges?: number;
@@ -371,12 +398,13 @@ export interface InspectionWorkDelta {
371
398
  host?: "committed" | "scratch" | "hydration";
372
399
  newEdgeProofMemo?: NewEdgeProofMemoWorkDelta;
373
400
  reverseProof?: ReverseProofWorkDelta;
401
+ topologyDeltaReverseSnapshot?: TopologyDeltaReverseSnapshotWorkDelta;
374
402
  }>;
375
403
  }
376
404
  export interface InternalInspectionRecorder {
377
405
  recordStoreEvent(...event: StoreRecorderEvent): void;
378
406
  hasActiveStoreOperation(): boolean;
379
- findDependencyPath<Node, Token extends object>(hostKind: "committed" | "scratch" | "hydration", hostRef: InspectionReference, start: Node, target: Node, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, site: SelectorCycleSearchSite, acceptedPrefixLength: number, evaluationGraphVersionStart: number, evaluationAttributedPublicationStart: number, parentWasCold: boolean, getNewEdgeProofMemo?: SelectorNewEdgeProofMemoProvider<Node>): readonly Node[] | undefined;
407
+ findDependencyPath<Node, Token extends object>(hostKind: "committed" | "scratch" | "hydration", hostRef: InspectionReference, start: Node, target: Node, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, site: SelectorCycleSearchSite, acceptedPrefixLength: number, evaluationGraphVersionStart: number, evaluationAttributedPublicationStart: number, parentWasCold: boolean, getNewEdgeProofMemo?: SelectorNewEdgeProofMemoProvider<Node>, topologyDeltaReverseProof?: SelectorTopologyDeltaReverseProofContext<Node>): readonly Node[] | undefined;
380
408
  reference(target: object, kind: InspectionReferenceKind, name?: string): InspectionReference;
381
409
  beginInterval(input: InternalInspectionIntervalInput): InternalInspectionIntervalToken;
382
410
  finishInterval(token: InternalInspectionIntervalToken, finish?: InternalInspectionIntervalFinish): void;
@@ -1,4 +1,4 @@
1
- import type { SelectorDefinition, SelectorNewEdgeProofDiagnostics, SelectorEvaluationHost, SelectorEvaluationProposal, SelectorEvaluationSession, SelectorCycleSearch } from "./types.js";
1
+ import type { SelectorDefinition, SelectorNewEdgeProofDiagnostics, SelectorEvaluationHost, SelectorEvaluationProposal, SelectorEvaluationSession, SelectorCycleSearch, SelectorTopologyDeltaReverseSnapshotDiagnostics } from "./types.js";
2
2
  export type SelectorReverseProofOutcome = "unsupported" | "ineligible-active-frames" | "proven-terminal" | "proven-reverse" | "path-possible" | "budget-exhausted" | "disabled";
3
3
  export interface SelectorReverseProofMeasurement {
4
4
  nodeVisits: number;
@@ -7,16 +7,17 @@ export interface SelectorReverseProofMeasurement {
7
7
  maxFrontier: number;
8
8
  }
9
9
  /**
10
- * Try the cheap direction first for a site-1 proof. The persistent host's
11
- * reverse index describes the effective graph exactly only while `target` is
12
- * its sole active frame: changing the target's own outgoing prefix cannot add
13
- * a path into the target. Any possible positive or bounded/ineligible case is
14
- * deliberately left to the canonical ordered forward DFS.
10
+ * Try the cheap direction first for a new-edge or topology-delta proof. Without
11
+ * an overlay, committed reverse adjacency describes the relevant effective
12
+ * graph only while `target` is the host's sole active frame. A topology-delta
13
+ * snapshot adds every active transient-prefix edge. Stale committed edges are
14
+ * retained deliberately: they can only cause conservative canonical fallback.
15
+ * Any positive, bounded, or ineligible case is left to the ordered forward DFS.
15
16
  */
16
- export declare const tryProveNoDependencyPathReverse: <Node, Token extends object>(start: Node, target: Node, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, measurement?: SelectorReverseProofMeasurement, allowTraversal?: boolean) => SelectorReverseProofOutcome;
17
+ export declare const tryProveNoDependencyPathReverse: <Node, Token extends object>(start: Node, target: Node, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, measurement?: SelectorReverseProofMeasurement, allowTraversal?: boolean, transientDependents?: ReadonlyMap<Node, readonly Node[]>) => SelectorReverseProofOutcome;
17
18
  /**
18
19
  * Evaluate exactly one selector body. This function never installs the active
19
20
  * selector record; persistent, scratch, and hydration hosts apply the returned
20
21
  * immutable proposal under their own publication policy.
21
22
  */
22
- export declare const evaluateSelector: <Node, Token extends object, Value>(definition: SelectorDefinition<Node, Value>, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, cycleSearch?: SelectorCycleSearch<Node, Token>, newEdgeProofDiagnostics?: SelectorNewEdgeProofDiagnostics) => SelectorEvaluationProposal<Node, Token, Value>;
23
+ export declare const evaluateSelector: <Node, Token extends object, Value>(definition: SelectorDefinition<Node, Value>, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, cycleSearch?: SelectorCycleSearch<Node, Token>, newEdgeProofDiagnostics?: SelectorNewEdgeProofDiagnostics, topologyDeltaReverseSnapshotDiagnostics?: SelectorTopologyDeltaReverseSnapshotDiagnostics) => SelectorEvaluationProposal<Node, Token, Value>;
@@ -44,6 +44,23 @@ export interface SelectorGraphEdgeAddition<Node> {
44
44
  readonly tail: Node;
45
45
  readonly head: Node;
46
46
  }
47
+ /** @internal Outcome of one bounded active-prefix reverse snapshot attempt. */
48
+ export type SelectorTopologyDeltaReverseSnapshotOutcome = "completed" | "overflow" | "unavailable";
49
+ /** @internal Inspection-only observation of reverse snapshot construction. */
50
+ export interface SelectorTopologyDeltaReverseSnapshotDiagnostics {
51
+ recordSnapshot(outcome: SelectorTopologyDeltaReverseSnapshotOutcome, scannedFrames: number, activeFrames: number, prefixEdges: number): void;
52
+ }
53
+ /**
54
+ * Evaluation-local reverse overlay for one exact topology-delta replay batch.
55
+ * The snapshot contributes active transient-prefix edges that are absent from
56
+ * committed reverse adjacency. Its mutable gate bounds repeated misses without
57
+ * retaining any evidence beyond the synchronous replay. An absent snapshot
58
+ * keeps only sole-active-target proofs eligible and otherwise fails closed.
59
+ */
60
+ export interface SelectorTopologyDeltaReverseProofContext<Node> {
61
+ readonly transientDependents: ReadonlyMap<Node, readonly Node[]> | undefined;
62
+ reverseProofEnabled: boolean;
63
+ }
47
64
  /**
48
65
  * Synchronous, bounded observation of exact selector-edge additions. An
49
66
  * undefined read means the host could not retain a complete interval and the
@@ -131,11 +148,12 @@ export interface SelectorNewEdgeProofMemoProvider<Node> {
131
148
  * supplied only at site 1 and is invoked only when a bounded host acceleration
132
149
  * cannot prove the negative first. Its evidence remains evaluation-local and
133
150
  * may cross a graph version only when one exact addition interval preserves a
134
- * fully exhausted, successor-closed negative proof.
151
+ * fully exhausted, successor-closed negative proof. The topology-delta reverse
152
+ * context is supplied only at site 2 and is shared by one exact replay batch.
135
153
  */
136
154
  export type SelectorCycleSearch<Node, Token extends object> = (start: Node, target: Node, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, site: SelectorCycleSearchSite,
137
155
  /** Length of the active selector prefix whose acyclicity this proves. */
138
- acceptedPrefixLength: number, getNewEdgeProofMemo?: SelectorNewEdgeProofMemoProvider<Node>) => readonly Node[] | undefined;
156
+ acceptedPrefixLength: number, getNewEdgeProofMemo?: SelectorNewEdgeProofMemoProvider<Node>, topologyDeltaReverseProof?: SelectorTopologyDeltaReverseProofContext<Node>) => readonly Node[] | undefined;
139
157
  export interface SelectorEvaluationStrategy {
140
158
  <Node, Token extends object, Value>(definition: SelectorDefinition<Node, Value>, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>): SelectorEvaluationProposal<Node, Token, Value>;
141
159
  }
@@ -220,6 +238,13 @@ export declare class SelectorEvaluationSession<Node> {
220
238
  getTransientDependencies(host: object, node: Node): readonly Readonly<{
221
239
  node: Node;
222
240
  }>[] | undefined;
241
+ /**
242
+ * Snapshot every active same-host transient prefix as reverse additions.
243
+ * Committed reverse edges are deliberately not subtracted: stale edges can
244
+ * only force canonical fallback from a negative-only reverse certificate.
245
+ * Any frame ambiguity, caller mismatch, or oversized snapshot fails closed.
246
+ */
247
+ captureTransientReverseDependents(host: object, selector: Node, acceptedPrefixLength: number, maxEntries: number, diagnostics?: SelectorTopologyDeltaReverseSnapshotDiagnostics): ReadonlyMap<Node, readonly Node[]> | undefined;
223
248
  /** @internal */
224
249
  latchCycle(host: object, selector: Node, error: unknown): void;
225
250
  /** @internal */
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.34",
4
+ "version": "1.0.0-beta.35",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Eigil Sagafos"
@@ -1,2 +0,0 @@
1
- class F extends Error{seal(){Object.freeze(this)}}class fe extends F{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 Ce extends F{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 ee extends F{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 _ extends F{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 Ee extends F{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class he extends F{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 De extends F{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var $e=Object.freeze({kind:"not-thenable"}),Dt=()=>{},Vt=Reflect.apply,Qe=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class Ve extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Pe 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 K extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class Y extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class X extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class Se extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class te extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ne extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class oe 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 xe extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class je extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ie extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class pe extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var E=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return $e;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):$e}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},D=(e)=>{try{Vt(e.then,e.target,[void 0,Dt])}catch{}},re=(e)=>{let t=E(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 D(t),Object.freeze({kind:"error",error:new ne})},Me=(e)=>{try{return re(e())}catch(t){let n=E(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 D(n),Object.freeze({kind:"error",error:new ne})}},ie=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},B=(e,t,n)=>{try{let o=ie(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}},Ze=(e,t,n)=>{try{let o=ie(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}},se=(e,t,n)=>ie(e,Object.freeze({kind:"selector",session:t}),n),Je=(e,t,n)=>ie(e,Object.freeze({kind:"transaction",transaction:t}),n),me=(e,t,n)=>{try{let o=ie(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}},V=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new Y(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new X;throw new K},ze=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new Y(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new X;throw new K},et=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new Y("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new X;throw new K},ye=(e,t,n)=>{if(!n)throw new Se;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new Y("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new K;throw new X},tt=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},U=(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,Qe);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Ve;throw tt(e,n).latchControlFault(r),r}}return"invalid"},j=(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=tt(e,n);if(o!==void 0&&"session"in o)try{let i=U(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 B(e,r,()=>U(e,t,r))},ae=(e,t)=>(Object.defineProperty(e,Qe,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),be=(e,t)=>Object.freeze(ae({kind:e},t));var nt=Object.freeze({kind:"not-thenable"}),Pt=()=>{},xt=Reflect.apply,ot=Symbol("selector dependency path root"),st=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return nt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):nt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},at=(e)=>{try{xt(e.then,e.target,[void 0,Pt])}catch{}},jt=(e)=>Object.freeze(e),It=(e)=>Object.freeze(e),R=(e,t,n,o)=>{let r=It(o);return Object.freeze({selector:e,token:t,outcome:jt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Mt:Object.freeze(r.map((i)=>i.node))})},Mt=Object.freeze([]),Ae=32,Q=8192,zt=2*Ae,dt=128;class ct{passiveSearches;searches=0;constructor(e,t){if(this.passiveSearches=e,t!==void 0)this.diagnostics=t}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let e=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(e)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(e&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(Q,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,t.has(e))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,n.has(e))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(e){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let n=e.size>=Ae&&e.size<=Q,o;if(this.searches===1&&n)this.first=e,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>Q){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=Ae&&e.size<=Q;if(this.first===void 0){if(t)this.first=e,this.firstIndependentlyClosed=!0;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,Ae),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=zt){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(e){if(!this.enabled||e===void 0)return this.reset(),!1;let t=this.firstIndependentlyClosed===!0?this.first:void 0,n=this.secondIndependentlyClosed===!0?this.second:void 0,o=t===void 0||n!==void 0&&n.size>t.size?n:t;if(o===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(Q,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>Q||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=e,this.firstIndependentlyClosed=t,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,this.secondIndependentlyClosed=t,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}hasWithinCrossVersionBudget(e,t){let n=this.passiveProbeBudget;if(n===void 0||n===0)return;let o=e.has(t);return this.passiveProbeBudget=n-1,o}completeDiagnostics(e,t){let n=this.diagnostics;if(n===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let o=this.mapProbes??0;n.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",e,t,o,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var Ft=(e,t)=>new ct(e,t),de=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=dt-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},_t=(e,t,n,o,r,i=!0)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let s=n.visitSelectorDependents;if(s===void 0)return"unsupported";if(!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let m=n.getSelectorDependencyNodes;if(m!==void 0){let h=m.call(n,e);if(h===void 0||h.length===0)return"proven-terminal"}}if(!i)return"disabled";let a={remaining:dt},d=[t],c=new Set(d),l=0,u=0,p=1;while(d.length>0){if(a.remaining===0)return de("budget-exhausted",a,l,u,p,r);a.remaining--,l++;let m=d.pop();if(Object.is(m,e))return de("path-possible",a,l,u,p,r);let h=!1,y=s.call(n,m,a,(M)=>{if(u++,Object.is(M,e))return h=!0,!1;if(!c.has(M)){if(c.add(M),d.push(M),d.length>p)p=d.length}return!0});if(h)return de("path-possible",a,l,u,p,r);if(!y)return de("budget-exhausted",a,l,u,p,r)}return de("proven-reverse",a,l,u,p,r)},Bt=(e,t,n,o,r,i,s)=>{if(r===1){let u=_t(e,t,n,o,void 0,s?.reverseProofEnabled??!0);if(u==="proven-terminal"||u==="proven-reverse")return;if(u==="budget-exhausted"&&s!==void 0)s.reverseProofEnabled=!1}let a=s?.(),d=a?.beginSearch()??!1,c=[e],l=new Map([[e,ot]]);while(c.length>0){let u=c.pop();if(Object.is(u,t)){let h=[],y=u;while(y!==ot)h.push(y),y=l.get(y);return h.reverse(),a?.completePositive(),Object.freeze(h)}let p=o.getTransientDependencies(n,u);if(p){if(p.length===0)continue;if(d){let h=a.hasProvenNoPath(u);if(!a.enabled)d=!1;if(h)continue}for(let h of p){if(l.has(h.node))continue;l.set(h.node,u),c.push(h.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let h=n.getSelectorDependencyNodes(u);if(h===void 0||h.length===0)continue;if(d){let y=a.hasProvenNoPath(u);if(!a.enabled)d=!1;if(y)continue}for(let y of h){if(l.has(y))continue;l.set(y,u),c.push(y)}continue}let m=n.getSelectorRecord(u);if(!m||m.dependencies.length===0)continue;if(d){let h=a.hasProvenNoPath(u);if(!a.enabled)d=!1;if(h)continue}for(let h of m.dependencies){if(l.has(h.node))continue;l.set(h.node,u),c.push(h.node)}}a?.completeNegative(l);return},rt=(e,t)=>{let n=st(e);if(n.kind==="thenable")return at(n),new _(t);if(n.kind==="inspection-error")return n.error;return e},it=(e,t)=>{let n=st(e);if(n.kind==="thenable")return at(n),Object.freeze({kind:"error",error:new _(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},lt=(e,t,n,o=Bt,r)=>{let{node:i}=e,s=[],a=t.getSelectorRecord(i),d=a?.dependencies,c=d===void 0?new Set:void 0,l,u=0,p=t.getComparisonBaseline(i),m=!0,h=()=>{let f=c;if(f!==void 0)return f;f=new Set;for(let S of s)f.add(S.node);return c=f,f};n.enter(t,i,s);let y=t.getSelectorGraphVersion(),M=n.getSelectorGraphPublicationCount(t),z=y,H=M,qe=y,Ue=M,ke,we=!1,Te=y,ce=0,G,Ke=y,le,Oe=(f,S)=>{if(f===Te)return;if(Te=f,G===void 0){ce=0;return}if(G.advanceGraphVersion(S))return;ce=0,r?.graphVersionReset()},Nt=(f)=>{if(f!==Te)Oe(f,void 0);if(ce++,(d?.length??0)===0&&ce<3){r?.admissionSkipped();return}if(G===void 0){let S=d!==void 0&&d.length>0&&d.length<3;G=Ft(S?3:0,r)}if(!G.enabled){r?.disabled();return}return G},Ct=(f)=>{if(we)return;let S=t.beginSelectorGraphObservation?.(f);if(S===void 0)return;we=!0,ke=S},Re=(f,S,g,v)=>g-f===v-S,Ye=(f=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t),g=Re(z,H,f,S))=>{if(f===z)return;if(!we&&t.beginSelectorGraphObservation!==void 0){Oe(f,void 0),z=f,H=S;return}let v=ke?.takeAddedEdges();if(Oe(f,v),g){z=f,H=S;return}if(v!==void 0){let k=!1;for(let O of v)if(o(O.head,O.tail,t,n,2,s.length)!==void 0){k=!0;break}if(!k){z=f,H=S;return}}for(let k=0;k<s.length;k++){let O=s[k],C=o(O.node,i,t,n,0,s.length);if(!C)continue;if(c!==void 0)for(let P=s.length-1;P>=k;P--)c.delete(s[P].node);if(s.length=k,u++,n.getControlFault().kind==="fault")return;let T=new ee(i,[i,...C]);n.latchCycle(t,i,T);return}z=f,H=S},Ne=()=>{let f=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t);qe=f,Ue=S;let g=Re(z,H,f,S);if(!g)n.revalidateAncestorPrefixes(t,i);Ye(f,S,g)};n.setPrefixRevalidator(t,i,Ye);let Et=(f)=>{if(!m)throw new De;let S=n.getControlFault();if(S.kind==="fault")throw S.error;let g=n.getCycle(t,i);if(g!==void 0)throw g;let v=n.activeCyclePath(t,f);if(v){let b=new ee(i,v);throw n.latchCycle(t,i,b),b}let k=s.length,O,C=!1;if(c===void 0){let b=d?.[k];if(b!==void 0&&Object.is(b.node,f))O=!1,C=!0;else O=h().has(f)}else O=c.has(f);if(!O&&!C&&d!==void 0&&d.length>0){let b=d[s.length];if(b!==void 0&&Object.is(b.node,f))C=!0;else{if(l===void 0){l=new Set;for(let q of d)l.add(q.node)}C=l.has(f)}}let L=u,T=t.serve(f,n);Ne();let P=n.getCycle(t,i);if(P!==void 0)throw P;let Z=c!==void 0?c.has(f):u===L&&s.length===k?!1:h().has(f),I=qe,W=Ue,x=Z||C&&I===y,ue=d===void 0&&Re(y,M,I,W);if(!x&&!ue){if(Ke=I,le===void 0)le=()=>Nt(Ke),le.reverseProofEnabled=!0;let b=o(f,i,t,n,1,s.length,le);if(b){let q=n.getControlFault();if(q.kind==="fault")throw q.error;let Xe=new ee(i,[i,...b]);throw n.latchCycle(t,i,Xe),Xe}}if(!Z){let b=a?.dependencies[s.length];c?.add(f),s.push(b!==void 0&&Object.is(b.node,f)&&Object.is(b.token,T.token)?b:Object.freeze({node:f,token:T.token})),Ct(f)}if(z=I,H=W,T.outcome.kind==="control-error"){n.latchControlFault(T.outcome.error);let b=n.getControlFault();if(b.kind==="fault")throw b.error;throw T.outcome.error}let J=n.getControlFault();if(J.kind==="fault")throw J.error;if(T.outcome.kind==="error")throw new Ce(f,T.outcome.error);return T.outcome.value};try{let f,S,g=!1;try{f=e.get(Et)}catch(P){g=!0,S=P}finally{m=!1}if(g)S=rt(S,"getter");let v=g?void 0:it(f,"getter");Ne();let k=n.getControlFault();if(k.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:k.error},s);let O=n.getCycle(t,i);if(O!==void 0)return R(i,t.createOutcomeToken(),{kind:"error",error:O},s);if(g)return R(i,t.createOutcomeToken(),{kind:"error",error:S instanceof _?S:new fe(i,S)},s);if(v===void 0)throw Error("Selector result classification was not completed");let C=n.getControlFault();if(C.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:C.error},s);if(v.kind==="error")return R(i,t.createOutcomeToken(),{kind:"error",error:v.error instanceof _?v.error:new fe(i,v.error)},s);let L=v.value,T;if(p){let P=e.equal??Object.is,Z,I,W=!1;try{Z=P(p.value,L)}catch(q){W=!0,I=rt(q,"comparator")}let x=W?void 0:it(Z,"comparator");Ne();let ue=n.getControlFault();if(ue.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:ue.error},s);let J=n.getCycle(t,i);if(J!==void 0)return R(i,t.createOutcomeToken(),{kind:"error",error:J},s);if(W)return R(i,t.createOutcomeToken(),{kind:"error",error:I instanceof _?I:new he(i,I)},s);if(x===void 0)throw Error("Selector comparator classification was not completed");let b=n.getControlFault();if(b.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:b.error},s);if(x.kind==="error")return R(i,t.createOutcomeToken(),{kind:"error",error:x.error instanceof _?x.error:new he(i,x.error)},s);if(x.value!==!0&&x.value!==!1)return R(i,t.createOutcomeToken(),{kind:"error",error:new Ee},s);if(x.value===!0)L=p.value,T=p.current?p.token:void 0}return R(i,T??t.createOutcomeToken(),{kind:"value",value:L},s)}finally{try{ke?.close()}finally{n.leave(t,i)}}};class A{#t=[];#n;#o=0;#i;#s=Ht;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))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#t){if(!Object.is(o.host,e))continue;if(n||!Object.is(o.selector,t))return!1;n=!0}return n}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 Ht=Object.freeze({kind:"none"});var ut=Symbol("no-committed-selector-baseline");class ve{#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 A,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 d=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,d),d}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)??ut,this.#i.set(e,t);return t===ut?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}}var ft=4096,Gt=Object.freeze([]);class St{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)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}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 ge{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=0;#d;#l=!1;#h;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#m(),this.#n=this.#m()}get status(){return this.#u}get facade(){if(this.#h===void 0)throw Error("Store scope facade is not installed");return this.#h}installFacade(e){if(this.#h!==void 0)throw Error("Store scope facade is already installed");this.#h=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="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.#m()};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,this.#a++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(U(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=se(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#b(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}visitSelectorDependents(e,t,n){return this.#s.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#a}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#c===0)this.#d=[],this.#l=!1;this.#c++;let t=this.#d?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#d;if(o===void 0)return;if(t===o.length)return Gt;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#c--,this.#c!==0)return;this.#d=void 0,this.#l=!1}})}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()}#b(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}),s=this.#y(e,o?.dependencies??ht,t.dependencies),a=s?this.#S(e,o?.dependencies??ht,t.dependencies):void 0;if(s)this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),a!==void 0)this.#p(a);if(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}#y(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.#m(),this.#s.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#c===0||this.#l)return;let o=this.#d;if(o===void 0){this.#e();return}let r=ft-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let d of t)if(i.has(d.node))s.add(d.node);let a=[];for(let d of n)if(i.has(d.node)&&!s.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#e();return}}return a}#p(e){if(e.length===0)return;let t=this.#d;if(t===void 0||t.length+e.length>ft){this.#e();return}t.push(...e)}#e(){if(this.#c===0)return;this.#d=[],this.#l=!0}#m(){return new St(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var ht=Object.freeze([]);class Fe{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#l;#h;#u;#b;#y;#S;#p;#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.#f(),n.set(e,i);i.set(t.atom,t),this.#m();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#f();i.set(this.#n,o);let s=this.#f();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#m();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#m();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#m();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#m();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#m();return}let s=this.#f();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#f(),s=this.#f();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.#f();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.#m()}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.#l,t))return this.#h;if(Object.is(this.#a,e))return this.#u?.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.#f(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#a,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#b=s,this.#u=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.#l=t,this.#h=n;return}if(Object.is(this.#l,t))return;let a=this.#f();a.set(this.#c,i),a.set(this.#l,s),a.set(t,n),this.#u=a}else{let s=this.#f(),a=this.#f();if(a.set(this.#c,i),this.#l!==void 0&&this.#h!==void 0)a.set(this.#l,this.#h);s.set(this.#a,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#l=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#y,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#y,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#y=e,this.#S=t;return}if(Object.is(this.#y,e)){this.#S=t;return}let o=this.#f();o.set(this.#y,this.#S),o.set(e,t),this.#p=o,this.#y=void 0,this.#S=void 0}forEachFallback(e){if(this.#y!==void 0&&this.#S!==void 0)e(this.#y,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#m(){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.#u?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.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.#l=void 0,this.#h=void 0,this.#u=void 0,this.#b=void 0,this.#y=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class pt{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]),ae(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var _e=(e,t,n)=>new pt(e,t,n),Be=(e)=>{let t=E(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw D(t),new te},mt=(e)=>{let t=E(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw D(t),new te};var Lt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},wt=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}),Wt=32,Tt=new WeakMap,pn=()=>{let e=new Uint32Array(Wt),t=Object.freeze({read(n){return e[wt[n]]??0}});return Tt.set(t,e),t},N=(e)=>Object.freeze({kind:"value",value:e}),qt=(e)=>Object.freeze({kind:"error",error:e}),yt=(e)=>e.kind==="value"?N(e.value):qt(e.error),bt=(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)},At=1,He=2,vt=4,Ut=(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}),Le=(e)=>(e.onAllocation?.(),new Map),Kt=(e)=>(e.onAllocation?.(),new Set),Ge=(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)},gt=(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=Le(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=Le(e),r.set(t,i);i.set(n,o)},Yt=(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=Kt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Xt=(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=Le(e),e.affected=o;o.set(t,n)};class Ot{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#l;#h;#u;#b=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:Tt.get(t),this.#f=n,this.evaluate=n?.evaluate??lt,this.#n=new ge(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#m!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#m;if(n===void 0)return;n[wt[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Fe(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new A,o=t,r=j(this.#e,o,n),i=ze(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":j(this.#e,o,r=new A);if(V(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 A);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#u;if(a===void 0){if(a=new Map,this.#u=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let d=a.get(e);if(d===void 0){if(d=new Map,a.set(e,d),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let c=d.get(o);if(c===void 0){if(c={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,c),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:c,previous:c.tail,next:void 0};if(c.tail===void 0)c.head=l;else c.tail.next=l;if(c.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return Lt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;et(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.#u,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.#u=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)j(this.#e,n,new A);if(V(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#P(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.#P(e,n)}dispose(e){if(V(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.#$(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(V(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=_e(this,o,e),i;try{i=Je(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new A;me(this.#e,s,()=>Be(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new A,o=t,r=j(this.#e,o,n);if(V(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.#v(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,d)=>{if(this.#t.has(a))return;this.#t.set(a,d),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new A,i=j(this.#e,o,r);if(ye(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.#v(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.#U(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new A;this.#R(e,t,r,i,"Transaction.set"),this.#j(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new A;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 A;this.#R(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new A;if(typeof n!=="string")j(this.#e,n,i);ye(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=_e(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let d;try{d=r(a)}catch(l){let u=new A;return me(this.#e,u,()=>mt(l))}let c=new A;return me(this.#e,c,()=>Be(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#U(e,t){return this.recordCounter("scratchHostAllocations"),new ve(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>se(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new ve(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>se(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(U(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})}#P(e,t){let n=new ge(this,e,t);this.recordCounter("scopeNodesCreated");let o=new We(this,n,this.#f);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 je;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 Ie;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new Se;throw new pe}throw new pe}#A(e){if(e.status!=="live")throw new xe}#X(e,t,n,o){let r=j(this.#e,t,n);V(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new A;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#j(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#M(a,e,i,s)}catch(d){throw a.close(),a.release(),d}a.close();try{this.#F(a)}finally{a.release()}}#$(e){let t=this.#u,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.#u=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=j(this.#e,n,o);ye(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`)}#j(e,t,n,o,r){let i=B(this.#e,r,()=>re(o));if(i.kind==="error")throw i.error;let s=this.#N(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.#N(e,t,n,r),a=e.hasIntents?this.#v(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let d=this.#J(o,a.value,r);this.#q(e,t,n,d,s,r)}#M(e,t,n,o){this.#N(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#z(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}))}#N(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=N(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,c=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}#v(e,t,n,o){return this.#z(e,t,n,o).outcome}#z(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:N(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:N(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#g(t);if(r.fallback.kind==="eager")return N(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=yt(B(this.#e,n,()=>Me(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#g(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#Z(r,t,n,o)?t:n}#Z(e,t,n,o){return B(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=E(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw D(a),new oe}let i=E(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw D(i),new oe;if(r!==!0&&r!==!1)throw new oe;return r})}#J(e,t,n){return B(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=E(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw D(s),new ne}let r=re(o);if(r.kind==="error")throw r.error;return r.value})}#F(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=Ut(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,d)=>{let c=this.#_(e,a,d,o);if(r===void 0){r=c;return}if(i===void 0)i=[];i.push(c)});if(r===void 0)return;if(this.#f?.(1,e,this.#e.atoms),this.#B(e,r),i!==void 0)for(let a of i)this.#B(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let d=this.#H(a);s||=d}if(this.#G(r),i!==void 0)for(let a of i)this.#G(a);this.#se();try{let a,d,c=o.affectedRecord,l=o.affectedBefore;if(c!==void 0&&l!==void 0)a=this.#E(o,c,l);let{secondAffectedRecord:u,secondAffectedBefore:p}=o;if(u!==void 0&&p!==void 0){let m=this.#E(o,u,p);if(m!==void 0)if(a===void 0)a=m;else d=[m]}if(o.affected!==void 0)for(let[m,h]of o.affected){let y=this.#E(o,m,h);if(y===void 0)continue;if(a===void 0)a=y;else{if(d===void 0)d=[];d.push(y)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(d?.length??0)),this.#ie(a,d)}catch(a){throw this.#k(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(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}#B(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")}#H(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}#G({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))}#E(e,t,n){let o=Ge(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),bt(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(!Yt(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(bt(i,s))continue;Xt(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),o.push(d)});for(let d=a,c=o.length-1;d<c;d++,c--){let l=o[d];o[d]=o[c],o[c]=l}}}#L(e,t,n,o){let r=Ge(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=Ge(o,n,i);if(c!==void 0){d=c;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"){d=N(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=N(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)gt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)gt(o,n,c,d),this.recordCounter("finalPreflightVisits");return d}#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.#g(t);if(r.fallback.kind==="eager")return N(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.#g(e);if(n.fallback.kind==="eager")return N(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,N(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,N(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.#g(e);if(o.fallback.kind==="eager")return N(o.fallback.value);let r=o.fallback.initialize,i=yt(B(this.#e,t,()=>Me(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#g(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.#k();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#l=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.#D(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.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#p=void 0,this.#y=this.#u===void 0?0:this.#b++}#k(){this.#y=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#y,o=this.#u?.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.#p===void 0)this.#p=[o];else this.#p.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#k(),e!==void 0)throw e;return}let n,o,r=(c)=>{let l=c.head;while(l!==void 0){let u=l.callback;if(u!==void 0)if(n===void 0)n=u;else if(o===void 0)o=[n,u];else o.push(u);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let c of i)r(c);if(this.#k(),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 d;for(let c of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new A,u=!1,p;try{Ze(this.#e,l,()=>{try{let m=c(),h=E(m);if(h.kind==="thenable")D(h);else if(h.kind==="inspection-error")u=!0,p=h.error}catch(m){u=!0,p=m;let h=E(m);if(h.kind==="thenable")D(h)}})}catch(m){u=!0,p=m}if(u){if(d===void 0)d=[];if(d.push(p),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Pe(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&At)!==0)return!0;return this.#w(e,t,At),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#D(e,t,n)}#D(e,t,n){if((this.#W(e,t)&(vt|He))!==0)return;this.#w(e,t,He);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.#D(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 A)}this.#w(e,t,vt)}finally{this.#w(e,t,0,He)}}#W(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#l?.get(e)?.get(t)??0}#w(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.#l;if(r===void 0)r=new Map,this.#l=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.#Q(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 We{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),ae(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var kt=(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}}},Rt=(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=(d,c={})=>{let l=new A,u=B(t,l,()=>re(d));if(u.kind==="error")throw u.error;let p=be("atom",t.ownerToken);return t.states.add(p),t.atoms.set(p,Object.freeze({fallback:Object.freeze({kind:"eager",value:u.value}),...kt(c)})),p},o=(d,c={})=>{if(typeof d!=="function")throw TypeError("atomLazy requires an initializer function");let l=be("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:d}),...kt(c)})),l},r=(d,c={})=>{if(typeof d!=="function")throw TypeError("selector requires a getter function");if(c.equal!==void 0&&typeof c.equal!=="function")throw TypeError("selector equal must be a function");let l=be("selector",t.ownerToken),u=Object.freeze({node:l,get:d,...c.name===void 0?{}:{name:c.name},...c.equal===void 0?{}:{equal:c.equal}});return t.states.add(l),t.selectors.set(l,u),l},i=(d)=>{let c=new A;if(j(t,d,c)==="invalid")return;return t.stores.get(d)},a=Object.freeze({assertStore:(d)=>{let c=i(d);if(V(t,"adapter assertStore"),c===void 0)throw TypeError("assertStore requires a valid Store")},read:(d,c)=>{if(i(d)===void 0)throw ze(t,"adapter read"),TypeError("read requires a valid Store");return d.get(c)},subscribe:(d,c,l)=>{if(i(d)===void 0)throw V(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return d.sub(c,l)},readHydrationSnapshot:(d,c)=>{let l=i(d);if(l===void 0)throw V(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,c)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(d=e,c)=>{V(t,"createStoreTree");let l=new Ot(t,d,c);return new We(l,l.rootScope,c)}})};var $t=Rt(),bn=(e,t)=>$t.createStoreTree(e,t);
2
- export{ee as a,_t as b,lt as c,Ve as d,Pe as e,K as f,Y as g,X as h,Se as i,te as j,ne as k,oe as l,xe as m,je as n,Ie as o,pe as p,pn as q,$t as r,bn as s};
@@ -1,2 +0,0 @@
1
- class F extends Error{seal(){Object.freeze(this)}}class fe extends F{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 Ce extends F{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 ee extends F{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 _ extends F{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 Ee extends F{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class he extends F{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 De extends F{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var $e=Object.freeze({kind:"not-thenable"}),Dt=()=>{},Vt=Reflect.apply,Qe=Symbol.for("valdres.runtime-owner/v1");class w extends Error{seal(){Object.freeze(this)}}class Ve extends w{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Pe 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 K extends w{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class Y extends w{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class X extends w{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class Se extends w{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class te extends w{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ne extends w{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class oe 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 xe extends w{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class je extends w{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ie extends w{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class pe extends w{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var E=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return $e;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):$e}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},D=(e)=>{try{Vt(e.then,e.target,[void 0,Dt])}catch{}},re=(e)=>{let t=E(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 D(t),Object.freeze({kind:"error",error:new ne})},Me=(e)=>{try{return re(e())}catch(t){let n=E(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 D(n),Object.freeze({kind:"error",error:new ne})}},ie=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},B=(e,t,n)=>{try{let o=ie(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}},Ze=(e,t,n)=>{try{let o=ie(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}},se=(e,t,n)=>ie(e,Object.freeze({kind:"selector",session:t}),n),Je=(e,t,n)=>ie(e,Object.freeze({kind:"transaction",transaction:t}),n),me=(e,t,n)=>{try{let o=ie(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}},V=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new Y(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new X;throw new K},ze=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new Y(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new X;throw new K},et=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new Y("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new X;throw new K},ye=(e,t,n)=>{if(!n)throw new Se;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new Y("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new K;throw new X},tt=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},U=(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,Qe);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Ve;throw tt(e,n).latchControlFault(r),r}}return"invalid"},j=(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=tt(e,n);if(o!==void 0&&"session"in o)try{let i=U(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 B(e,r,()=>U(e,t,r))},ae=(e,t)=>(Object.defineProperty(e,Qe,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),be=(e,t)=>Object.freeze(ae({kind:e},t));var nt=Object.freeze({kind:"not-thenable"}),Pt=()=>{},xt=Reflect.apply,ot=Symbol("selector dependency path root"),st=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return nt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):nt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},at=(e)=>{try{xt(e.then,e.target,[void 0,Pt])}catch{}},jt=(e)=>Object.freeze(e),It=(e)=>Object.freeze(e),R=(e,t,n,o)=>{let r=It(o);return Object.freeze({selector:e,token:t,outcome:jt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Mt:Object.freeze(r.map((i)=>i.node))})},Mt=Object.freeze([]),Ae=32,Q=8192,zt=2*Ae,dt=128;class ct{passiveSearches;searches=0;constructor(e,t){if(this.passiveSearches=e,t!==void 0)this.diagnostics=t}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let e=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(e)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(e&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(Q,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,t.has(e))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,n.has(e))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(e){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let n=e.size>=Ae&&e.size<=Q,o;if(this.searches===1&&n)this.first=e,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>Q){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=Ae&&e.size<=Q;if(this.first===void 0){if(t)this.first=e,this.firstIndependentlyClosed=!0;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,Ae),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=zt){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(e){if(!this.enabled||e===void 0)return this.reset(),!1;let t=this.firstIndependentlyClosed===!0?this.first:void 0,n=this.secondIndependentlyClosed===!0?this.second:void 0,o=t===void 0||n!==void 0&&n.size>t.size?n:t;if(o===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(Q,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>Q||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=e,this.firstIndependentlyClosed=t,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,this.secondIndependentlyClosed=t,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}hasWithinCrossVersionBudget(e,t){let n=this.passiveProbeBudget;if(n===void 0||n===0)return;let o=e.has(t);return this.passiveProbeBudget=n-1,o}completeDiagnostics(e,t){let n=this.diagnostics;if(n===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let o=this.mapProbes??0;n.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",e,t,o,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var Ft=(e,t)=>new ct(e,t),de=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=dt-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},_t=(e,t,n,o,r,i=!0)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let s=n.visitSelectorDependents;if(s===void 0)return"unsupported";if(!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let m=n.getSelectorDependencyNodes;if(m!==void 0){let h=m.call(n,e);if(h===void 0||h.length===0)return"proven-terminal"}}if(!i)return"disabled";let a={remaining:dt},d=[t],c=new Set(d),l=0,u=0,p=1;while(d.length>0){if(a.remaining===0)return de("budget-exhausted",a,l,u,p,r);a.remaining--,l++;let m=d.pop();if(Object.is(m,e))return de("path-possible",a,l,u,p,r);let h=!1,y=s.call(n,m,a,(M)=>{if(u++,Object.is(M,e))return h=!0,!1;if(!c.has(M)){if(c.add(M),d.push(M),d.length>p)p=d.length}return!0});if(h)return de("path-possible",a,l,u,p,r);if(!y)return de("budget-exhausted",a,l,u,p,r)}return de("proven-reverse",a,l,u,p,r)},Bt=(e,t,n,o,r,i,s)=>{if(r===1){let u=_t(e,t,n,o,void 0,s?.reverseProofEnabled??!0);if(u==="proven-terminal"||u==="proven-reverse")return;if(u==="budget-exhausted"&&s!==void 0)s.reverseProofEnabled=!1}let a=s?.(),d=a?.beginSearch()??!1,c=[e],l=new Map([[e,ot]]);while(c.length>0){let u=c.pop();if(Object.is(u,t)){let h=[],y=u;while(y!==ot)h.push(y),y=l.get(y);return h.reverse(),a?.completePositive(),Object.freeze(h)}let p=o.getTransientDependencies(n,u);if(p){if(p.length===0)continue;if(d){let h=a.hasProvenNoPath(u);if(!a.enabled)d=!1;if(h)continue}for(let h of p){if(l.has(h.node))continue;l.set(h.node,u),c.push(h.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let h=n.getSelectorDependencyNodes(u);if(h===void 0||h.length===0)continue;if(d){let y=a.hasProvenNoPath(u);if(!a.enabled)d=!1;if(y)continue}for(let y of h){if(l.has(y))continue;l.set(y,u),c.push(y)}continue}let m=n.getSelectorRecord(u);if(!m||m.dependencies.length===0)continue;if(d){let h=a.hasProvenNoPath(u);if(!a.enabled)d=!1;if(h)continue}for(let h of m.dependencies){if(l.has(h.node))continue;l.set(h.node,u),c.push(h.node)}}a?.completeNegative(l);return},rt=(e,t)=>{let n=st(e);if(n.kind==="thenable")return at(n),new _(t);if(n.kind==="inspection-error")return n.error;return e},it=(e,t)=>{let n=st(e);if(n.kind==="thenable")return at(n),Object.freeze({kind:"error",error:new _(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},lt=(e,t,n,o=Bt,r)=>{let{node:i}=e,s=[],a=t.getSelectorRecord(i),d=a?.dependencies,c=d===void 0?new Set:void 0,l,u=0,p=t.getComparisonBaseline(i),m=!0,h=()=>{let f=c;if(f!==void 0)return f;f=new Set;for(let S of s)f.add(S.node);return c=f,f};n.enter(t,i,s);let y=t.getSelectorGraphVersion(),M=n.getSelectorGraphPublicationCount(t),z=y,H=M,qe=y,Ue=M,ke,we=!1,Te=y,ce=0,G,Ke=y,le,Oe=(f,S)=>{if(f===Te)return;if(Te=f,G===void 0){ce=0;return}if(G.advanceGraphVersion(S))return;ce=0,r?.graphVersionReset()},Nt=(f)=>{if(f!==Te)Oe(f,void 0);if(ce++,(d?.length??0)===0&&ce<3){r?.admissionSkipped();return}if(G===void 0){let S=d!==void 0&&d.length>0&&d.length<3;G=Ft(S?3:0,r)}if(!G.enabled){r?.disabled();return}return G},Ct=(f)=>{if(we)return;let S=t.beginSelectorGraphObservation?.(f);if(S===void 0)return;we=!0,ke=S},Re=(f,S,g,v)=>g-f===v-S,Ye=(f=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t),g=Re(z,H,f,S))=>{if(f===z)return;if(!we&&t.beginSelectorGraphObservation!==void 0){Oe(f,void 0),z=f,H=S;return}let v=ke?.takeAddedEdges();if(Oe(f,v),g){z=f,H=S;return}if(v!==void 0){let k=!1;for(let O of v)if(o(O.head,O.tail,t,n,2,s.length)!==void 0){k=!0;break}if(!k){z=f,H=S;return}}for(let k=0;k<s.length;k++){let O=s[k],C=o(O.node,i,t,n,0,s.length);if(!C)continue;if(c!==void 0)for(let P=s.length-1;P>=k;P--)c.delete(s[P].node);if(s.length=k,u++,n.getControlFault().kind==="fault")return;let T=new ee(i,[i,...C]);n.latchCycle(t,i,T);return}z=f,H=S},Ne=()=>{let f=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t);qe=f,Ue=S;let g=Re(z,H,f,S);if(!g)n.revalidateAncestorPrefixes(t,i);Ye(f,S,g)};n.setPrefixRevalidator(t,i,Ye);let Et=(f)=>{if(!m)throw new De;let S=n.getControlFault();if(S.kind==="fault")throw S.error;let g=n.getCycle(t,i);if(g!==void 0)throw g;let v=n.activeCyclePath(t,f);if(v){let b=new ee(i,v);throw n.latchCycle(t,i,b),b}let k=s.length,O,C=!1;if(c===void 0){let b=d?.[k];if(b!==void 0&&Object.is(b.node,f))O=!1,C=!0;else O=h().has(f)}else O=c.has(f);if(!O&&!C&&d!==void 0&&d.length>0){let b=d[s.length];if(b!==void 0&&Object.is(b.node,f))C=!0;else{if(l===void 0){l=new Set;for(let q of d)l.add(q.node)}C=l.has(f)}}let L=u,T=t.serve(f,n);Ne();let P=n.getCycle(t,i);if(P!==void 0)throw P;let Z=c!==void 0?c.has(f):u===L&&s.length===k?!1:h().has(f),I=qe,W=Ue,x=Z||C&&I===y,ue=d===void 0&&Re(y,M,I,W);if(!x&&!ue){if(Ke=I,le===void 0)le=()=>Nt(Ke),le.reverseProofEnabled=!0;let b=o(f,i,t,n,1,s.length,le);if(b){let q=n.getControlFault();if(q.kind==="fault")throw q.error;let Xe=new ee(i,[i,...b]);throw n.latchCycle(t,i,Xe),Xe}}if(!Z){let b=a?.dependencies[s.length];c?.add(f),s.push(b!==void 0&&Object.is(b.node,f)&&Object.is(b.token,T.token)?b:Object.freeze({node:f,token:T.token})),Ct(f)}if(z=I,H=W,T.outcome.kind==="control-error"){n.latchControlFault(T.outcome.error);let b=n.getControlFault();if(b.kind==="fault")throw b.error;throw T.outcome.error}let J=n.getControlFault();if(J.kind==="fault")throw J.error;if(T.outcome.kind==="error")throw new Ce(f,T.outcome.error);return T.outcome.value};try{let f,S,g=!1;try{f=e.get(Et)}catch(P){g=!0,S=P}finally{m=!1}if(g)S=rt(S,"getter");let v=g?void 0:it(f,"getter");Ne();let k=n.getControlFault();if(k.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:k.error},s);let O=n.getCycle(t,i);if(O!==void 0)return R(i,t.createOutcomeToken(),{kind:"error",error:O},s);if(g)return R(i,t.createOutcomeToken(),{kind:"error",error:S instanceof _?S:new fe(i,S)},s);if(v===void 0)throw Error("Selector result classification was not completed");let C=n.getControlFault();if(C.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:C.error},s);if(v.kind==="error")return R(i,t.createOutcomeToken(),{kind:"error",error:v.error instanceof _?v.error:new fe(i,v.error)},s);let L=v.value,T;if(p){let P=e.equal??Object.is,Z,I,W=!1;try{Z=P(p.value,L)}catch(q){W=!0,I=rt(q,"comparator")}let x=W?void 0:it(Z,"comparator");Ne();let ue=n.getControlFault();if(ue.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:ue.error},s);let J=n.getCycle(t,i);if(J!==void 0)return R(i,t.createOutcomeToken(),{kind:"error",error:J},s);if(W)return R(i,t.createOutcomeToken(),{kind:"error",error:I instanceof _?I:new he(i,I)},s);if(x===void 0)throw Error("Selector comparator classification was not completed");let b=n.getControlFault();if(b.kind==="fault")return R(i,t.createOutcomeToken(),{kind:"control-error",error:b.error},s);if(x.kind==="error")return R(i,t.createOutcomeToken(),{kind:"error",error:x.error instanceof _?x.error:new he(i,x.error)},s);if(x.value!==!0&&x.value!==!1)return R(i,t.createOutcomeToken(),{kind:"error",error:new Ee},s);if(x.value===!0)L=p.value,T=p.current?p.token:void 0}return R(i,T??t.createOutcomeToken(),{kind:"value",value:L},s)}finally{try{ke?.close()}finally{n.leave(t,i)}}};class A{#t=[];#n;#o=0;#i;#s=Ht;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))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#t){if(!Object.is(o.host,e))continue;if(n||!Object.is(o.selector,t))return!1;n=!0}return n}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 Ht=Object.freeze({kind:"none"});var ut=Symbol("no-committed-selector-baseline");class ve{#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 A,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 d=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,d),d}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)??ut,this.#i.set(e,t);return t===ut?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}}var ft=4096,Gt=Object.freeze([]);class St{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)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}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 ge{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=0;#d;#l=!1;#h;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#m(),this.#n=this.#m()}get status(){return this.#u}get facade(){if(this.#h===void 0)throw Error("Store scope facade is not installed");return this.#h}installFacade(e){if(this.#h!==void 0)throw Error("Store scope facade is already installed");this.#h=e}markDisposing(){if(this.#u==="live")this.#u="disposing"}markDisposed(){this.#u="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.#m()};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,this.#a++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(U(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=se(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#b(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}visitSelectorDependents(e,t,n){return this.#s.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#a}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#c===0)this.#d=[],this.#l=!1;this.#c++;let t=this.#d?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#d;if(o===void 0)return;if(t===o.length)return Gt;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#c--,this.#c!==0)return;this.#d=void 0,this.#l=!1}})}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()}#b(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}),s=this.#y(e,o?.dependencies??ht,t.dependencies),a=s?this.#S(e,o?.dependencies??ht,t.dependencies):void 0;if(s)this.#i?.delete(e);if(this.#a++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),a!==void 0)this.#p(a);if(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}#y(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.#m(),this.#s.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#c===0||this.#l)return;let o=this.#d;if(o===void 0){this.#e();return}let r=ft-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let d of t)if(i.has(d.node))s.add(d.node);let a=[];for(let d of n)if(i.has(d.node)&&!s.has(d.node)){if(a.push(Object.freeze({tail:e,head:d.node})),a.length>r){this.#e();return}}return a}#p(e){if(e.length===0)return;let t=this.#d;if(t===void 0||t.length+e.length>ft){this.#e();return}t.push(...e)}#e(){if(this.#c===0)return;this.#d=[],this.#l=!0}#m(){return new St(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var ht=Object.freeze([]);class Fe{transaction=Object.freeze({});#t;#n;#o;#i;#s;#r;#a;#c;#d;#l;#h;#u;#b;#y;#S;#p;#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.#f(),n.set(e,i);i.set(t.atom,t),this.#m();return}let o=this.#s;if(o!==void 0){if(Object.is(this.#n,e))o.set(t.atom,t);else{let i=this.#f();i.set(this.#n,o);let s=this.#f();s.set(t.atom,t),i.set(e,s),this.#r=i,this.#s=void 0,this.#n=void 0}this.#m();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#m();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#m();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#m();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#m();return}let s=this.#f();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#s=s}else{let i=this.#f(),s=this.#f();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.#f();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.#m()}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.#l,t))return this.#h;if(Object.is(this.#a,e))return this.#u?.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.#f(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#a,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#a,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#b=s,this.#u=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.#l=t,this.#h=n;return}if(Object.is(this.#l,t))return;let a=this.#f();a.set(this.#c,i),a.set(this.#l,s),a.set(t,n),this.#u=a}else{let s=this.#f(),a=this.#f();if(a.set(this.#c,i),this.#l!==void 0&&this.#h!==void 0)a.set(this.#l,this.#h);s.set(this.#a,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#b=s,this.#a=void 0}this.#c=void 0,this.#d=void 0,this.#l=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#y,e))return this.#S;return this.#p?.get(e)}hasFallback(e){return Object.is(this.#y,e)||(this.#p?.has(e)??!1)}setFallback(e,t){let n=this.#p;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#y=e,this.#S=t;return}if(Object.is(this.#y,e)){this.#S=t;return}let o=this.#f();o.set(this.#y,this.#S),o.set(e,t),this.#p=o,this.#y=void 0,this.#S=void 0}forEachFallback(e){if(this.#y!==void 0&&this.#S!==void 0)e(this.#y,this.#S);if(this.#p!==void 0)for(let[t,n]of this.#p)e(t,n)}#m(){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.#u?.clear(),this.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.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.#l=void 0,this.#h=void 0,this.#u=void 0,this.#b=void 0,this.#y=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class pt{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]),ae(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var _e=(e,t,n)=>new pt(e,t,n),Be=(e)=>{let t=E(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw D(t),new te},mt=(e)=>{let t=E(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw D(t),new te};var Lt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},wt=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}),Wt=32,Tt=new WeakMap,pn=()=>{let e=new Uint32Array(Wt),t=Object.freeze({read(n){return e[wt[n]]??0}});return Tt.set(t,e),t},N=(e)=>Object.freeze({kind:"value",value:e}),qt=(e)=>Object.freeze({kind:"error",error:e}),yt=(e)=>e.kind==="value"?N(e.value):qt(e.error),bt=(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)},At=1,He=2,vt=4,Ut=(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}),Le=(e)=>(e.onAllocation?.(),new Map),Kt=(e)=>(e.onAllocation?.(),new Set),Ge=(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)},gt=(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=Le(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=Le(e),r.set(t,i);i.set(n,o)},Yt=(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=Kt(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Xt=(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=Le(e),e.affected=o;o.set(t,n)};class Ot{#t=new WeakMap;#n;#o=1;#i=0;#s=!1;#r;#a;#c;#d=0;#l;#h;#u;#b=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:Tt.get(t),this.#f=n,this.evaluate=n?.evaluate??lt,this.#n=new ge(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#s}get instrumented(){return this.#m!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#m;if(n===void 0)return;n[wt[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Fe(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new A,o=t,r=j(this.#e,o,n),i=ze(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":j(this.#e,o,r=new A);if(V(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 A);if(s.outcome.kind==="control-error")throw s.outcome.error;let a=this.#u;if(a===void 0){if(a=new Map,this.#u=a,this.instrumented)this.recordCounter("subscriptionIndexMapsCreated")}let d=a.get(e);if(d===void 0){if(d=new Map,a.set(e,d),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let c=d.get(o);if(c===void 0){if(c={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,c),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:c,previous:c.tail,next:void 0};if(c.tail===void 0)c.head=l;else c.tail.next=l;if(c.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return Lt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;et(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.#u,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.#u=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)j(this.#e,n,new A);if(V(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#P(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.#P(e,n)}dispose(e){if(V(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.#$(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(V(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=_e(this,o,e),i;try{i=Je(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new A;me(this.#e,s,()=>Be(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new A,o=t,r=j(this.#e,o,n);if(V(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.#v(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,d)=>{if(this.#t.has(a))return;this.#t.set(a,d),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new A,i=j(this.#e,o,r);if(ye(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.#v(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.#U(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new A;this.#R(e,t,r,i,"Transaction.set"),this.#j(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new A;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 A;this.#R(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new A;if(typeof n!=="string")j(this.#e,n,i);ye(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=_e(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let d;try{d=r(a)}catch(l){let u=new A;return me(this.#e,u,()=>mt(l))}let c=new A;return me(this.#e,c,()=>Be(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#U(e,t){return this.recordCounter("scratchHostAllocations"),new ve(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>se(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new ve(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>se(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(U(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})}#P(e,t){let n=new ge(this,e,t);this.recordCounter("scopeNodesCreated");let o=new We(this,n,this.#f);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 je;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 Ie;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new Se;throw new pe}throw new pe}#A(e){if(e.status!=="live")throw new xe}#X(e,t,n,o){let r=j(this.#e,t,n);V(this.#e,o),this.#A(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new A;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#j(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#M(a,e,i,s)}catch(d){throw a.close(),a.release(),d}a.close();try{this.#F(a)}finally{a.release()}}#$(e){let t=this.#u,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.#u=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=j(this.#e,n,o);ye(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`)}#j(e,t,n,o,r){let i=B(this.#e,r,()=>re(o));if(i.kind==="error")throw i.error;let s=this.#N(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.#N(e,t,n,r),a=e.hasIntents?this.#v(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let d=this.#J(o,a.value,r);this.#q(e,t,n,d,s,r)}#M(e,t,n,o){this.#N(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0}):this.#z(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}))}#N(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=N(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,c=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,c),c}#v(e,t,n,o){return this.#z(e,t,n,o).outcome}#z(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:N(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:N(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#C(e,n,o),reachesFallback:!0})}#C(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#g(t);if(r.fallback.kind==="eager")return N(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=yt(B(this.#e,n,()=>Me(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#g(e).equal;if(r===void 0)return Object.is(t,n)?t:n;return this.#Z(r,t,n,o)?t:n}#Z(e,t,n,o){return B(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=E(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw D(a),new oe}let i=E(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw D(i),new oe;if(r!==!0&&r!==!1)throw new oe;return r})}#J(e,t,n){return B(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=E(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw D(s),new ne}let r=re(o);if(r.kind==="error")throw r.error;return r.value})}#F(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=Ut(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,d)=>{let c=this.#_(e,a,d,o);if(r===void 0){r=c;return}if(i===void 0)i=[];i.push(c)});if(r===void 0)return;if(this.#f?.(1,e,this.#e.atoms),this.#B(e,r),i!==void 0)for(let a of i)this.#B(e,a);let s=this.#H(r);if(i!==void 0)for(let a of i){let d=this.#H(a);s||=d}if(this.#G(r),i!==void 0)for(let a of i)this.#G(a);this.#se();try{let a,d,c=o.affectedRecord,l=o.affectedBefore;if(c!==void 0&&l!==void 0)a=this.#E(o,c,l);let{secondAffectedRecord:u,secondAffectedBefore:p}=o;if(u!==void 0&&p!==void 0){let m=this.#E(o,u,p);if(m!==void 0)if(a===void 0)a=m;else d=[m]}if(o.affected!==void 0)for(let[m,h]of o.affected){let y=this.#E(o,m,h);if(y===void 0)continue;if(a===void 0)a=y;else{if(d===void 0)d=[];d.push(y)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(d?.length??0)),this.#ie(a,d)}catch(a){throw this.#k(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(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}#B(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")}#H(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}#G({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))}#E(e,t,n){let o=Ge(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),bt(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(!Yt(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(bt(i,s))continue;Xt(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),o.push(d)});for(let d=a,c=o.length-1;d<c;d++,c--){let l=o[d];o[d]=o[c],o[c]=l}}}#L(e,t,n,o){let r=Ge(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=Ge(o,n,i);if(c!==void 0){d=c;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"){d=N(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=N(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)gt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)gt(o,n,c,d),this.recordCounter("finalPreflightVisits");return d}#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.#g(t);if(r.fallback.kind==="eager")return N(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.#g(e);if(n.fallback.kind==="eager")return N(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,N(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,N(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.#g(e);if(o.fallback.kind==="eager")return N(o.fallback.value);let r=o.fallback.initialize,i=yt(B(this.#e,t,()=>Me(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#g(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.#k();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#a=void 0,this.#c=void 0,this.#d=0,this.#l=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.#D(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.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#p=void 0,this.#y=this.#u===void 0?0:this.#b++}#k(){this.#y=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#y,o=this.#u?.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.#p===void 0)this.#p=[o];else this.#p.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#k(),e!==void 0)throw e;return}let n,o,r=(c)=>{let l=c.head;while(l!==void 0){let u=l.callback;if(u!==void 0)if(n===void 0)n=u;else if(o===void 0)o=[n,u];else o.push(u);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let c of i)r(c);if(this.#k(),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 d;for(let c of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new A,u=!1,p;try{Ze(this.#e,l,()=>{try{let m=c(),h=E(m);if(h.kind==="thenable")D(h);else if(h.kind==="inspection-error")u=!0,p=h.error}catch(m){u=!0,p=m;let h=E(m);if(h.kind==="thenable")D(h)}})}catch(m){u=!0,p=m}if(u){if(d===void 0)d=[];if(d.push(p),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Pe(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&At)!==0)return!0;return this.#w(e,t,At),n.push(e,t),!0}prepareSelectorRead(e,t,n){if(this.#r===void 0)return;this.#D(e,t,n)}#D(e,t,n){if((this.#W(e,t)&(vt|He))!==0)return;this.#w(e,t,He);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.#D(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 A)}this.#w(e,t,vt)}finally{this.#w(e,t,0,He)}}#W(e,t){if(Object.is(this.#a,e)&&Object.is(this.#c,t))return this.#d;return this.#l?.get(e)?.get(t)??0}#w(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.#l;if(r===void 0)r=new Map,this.#l=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.#Q(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 We{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),ae(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var kt=(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}}},Rt=(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=(d,c={})=>{let l=new A,u=B(t,l,()=>re(d));if(u.kind==="error")throw u.error;let p=be("atom",t.ownerToken);return t.states.add(p),t.atoms.set(p,Object.freeze({fallback:Object.freeze({kind:"eager",value:u.value}),...kt(c)})),p},o=(d,c={})=>{if(typeof d!=="function")throw TypeError("atomLazy requires an initializer function");let l=be("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:d}),...kt(c)})),l},r=(d,c={})=>{if(typeof d!=="function")throw TypeError("selector requires a getter function");if(c.equal!==void 0&&typeof c.equal!=="function")throw TypeError("selector equal must be a function");let l=be("selector",t.ownerToken),u=Object.freeze({node:l,get:d,...c.name===void 0?{}:{name:c.name},...c.equal===void 0?{}:{equal:c.equal}});return t.states.add(l),t.selectors.set(l,u),l},i=(d)=>{let c=new A;if(j(t,d,c)==="invalid")return;return t.stores.get(d)},a=Object.freeze({assertStore:(d)=>{let c=i(d);if(V(t,"adapter assertStore"),c===void 0)throw TypeError("assertStore requires a valid Store")},read:(d,c)=>{if(i(d)===void 0)throw ze(t,"adapter read"),TypeError("read requires a valid Store");return d.get(c)},subscribe:(d,c,l)=>{if(i(d)===void 0)throw V(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return d.sub(c,l)},readHydrationSnapshot:(d,c)=>{let l=i(d);if(l===void 0)throw V(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,c)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(d=e,c)=>{V(t,"createStoreTree");let l=new Ot(t,d,c);return new We(l,l.rootScope,c)}})};var $t=Rt(),bn=(e,t)=>$t.createStoreTree(e,t);
2
- export{ee as a,_t as b,lt as c,Ve as d,Pe as e,K as f,Y as g,X as h,Se as i,te as j,ne as k,oe as l,xe as m,je as n,Ie as o,pe as p,pn as q,$t as r,bn as s};