valdres 1.0.0-beta.31 → 1.0.0-beta.32
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 +1 -1
- package/dist/adapter-internals/v1.js +1 -1
- package/dist/chunk-k8zy7f8n.js +2 -0
- package/dist/development/adapter-internals/v1.js +1 -1
- package/dist/development/chunk-k8zy7f8n.js +2 -0
- package/dist/development/index.js +1 -1
- package/dist/development/inspect.js +1 -1
- package/dist/index.js +1 -1
- package/dist/inspect.js +1 -1
- package/dist/types/inspect.d.ts +2 -2
- package/dist/types/v1-internal/inspection.d.ts +49 -1
- package/dist/types/v1-internal/selector-evaluator/evaluate.d.ts +2 -2
- package/dist/types/v1-internal/selector-evaluator/types.d.ts +24 -0
- package/package.json +1 -1
- package/dist/chunk-g4tkm20t.js +0 -2
- package/dist/development/chunk-g4tkm20t.js +0 -2
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, cycle-search visits by host and call site, 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.
|
|
69
|
+
The report correlates human labels with opaque operation, commit, evaluation, session, and search IDs. It includes selector work, proposed topology changes, cycle-search visits by host and call site, 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 3.
|
|
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{q as e}from"../chunk-
|
|
1
|
+
import{q as e}from"../chunk-k8zy7f8n.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 z extends Error{seal(){Object.freeze(this)}}class de extends z{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 Te extends z{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 Z extends z{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 F extends z{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 Oe extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ce extends z{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 Re extends z{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"}),Ot=()=>{},Rt=Reflect.apply,Ke=Symbol.for("valdres.runtime-owner/v1");class k extends Error{seal(){Object.freeze(this)}}class Ne extends k{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ce extends k{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 q extends k{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class K extends k{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class Y extends k{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class le extends k{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends k{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ee extends k{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class te extends k{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class Ee extends k{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class De extends k{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ve extends k{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class ue extends k{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var C=(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})}},E=(e)=>{try{Rt(e.then,e.target,[void 0,Ot])}catch{}},ne=(e)=>{let t=C(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 E(t),Object.freeze({kind:"error",error:new ee})},je=(e)=>{try{return ne(e())}catch(t){let n=C(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 E(n),Object.freeze({kind:"error",error:new ee})}},oe=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},_=(e,t,n)=>{try{let o=oe(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}},Ye=(e,t,n)=>{try{let o=oe(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}},re=(e,t,n)=>oe(e,Object.freeze({kind:"selector",session:t}),n),Xe=(e,t,n)=>oe(e,Object.freeze({kind:"transaction",transaction:t}),n),fe=(e,t,n)=>{try{let o=oe(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}},D=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new K(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Y;throw new q},xe=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new K(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Y;throw new q},$e=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new K("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new Y;throw new q},he=(e,t,n)=>{if(!n)throw new le;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new K("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new q;throw new Y},Qe=(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,Ke);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Ne;throw Qe(e,n).latchControlFault(r),r}}return"invalid"},x=(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=Qe(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 _(e,r,()=>U(e,t,r))},ie=(e,t)=>(Object.defineProperty(e,Ke,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),Se=(e,t)=>Object.freeze(ie({kind:e},t));var Ze=Object.freeze({kind:"not-thenable"}),Nt=()=>{},Ct=Reflect.apply,Je=Symbol("selector dependency path root"),nt=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ze;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ze}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},ot=(e)=>{try{Ct(e.then,e.target,[void 0,Nt])}catch{}},Et=(e)=>Object.freeze(e),Dt=(e)=>Object.freeze(e),O=(e,t,n,o)=>{let r=Dt(o);return Object.freeze({selector:e,token:t,outcome:Et(n),dependencies:r,attemptedPrefix:n.kind==="value"?Vt:Object.freeze(r.map((i)=>i.node))})},Vt=Object.freeze([]),pe=32,se=8192,jt=2*pe;class rt{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=Math.min(se,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;let o=this.passiveProbeBudget;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){if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;let o=this.passiveProbeBudget;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){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;let o=this.passiveProbeBudget;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){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;let o=this.passiveProbeBudget;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>=pe&&e.size<=se,o;if(this.searches===1&&n)this.first=e,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>se){this.disable("over-cap-hit");return}let n=this.first,o=this.second;this.first=void 0,this.second=void 0,this.retain(n),this.retain(o);let r=this.retain(e);this.locked=!0,this.missWork=0,this.completeDiagnostics(r?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=pe&&e.size<=se;if(this.first===void 0){if(t)this.first=e;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,pe),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=jt){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}reset(){this.first=void 0,this.second=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){if(e===void 0||e.size>se||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.first=e,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}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 xt=(e,t)=>new rt(e,t),Pt=(e,t,n,o,r,i,s)=>{let a=s?.beginSearch()??!1,d=[e],c=new Map([[e,Je]]);while(d.length>0){let l=d.pop();if(Object.is(l,t)){let f=[],p=l;while(p!==Je)f.push(p),p=c.get(p);return f.reverse(),s?.completePositive(),Object.freeze(f)}let h=o.getTransientDependencies(n,l);if(h){if(h.length===0)continue;if(a){let f=s.hasProvenNoPath(l);if(!s.enabled)a=!1;if(f)continue}for(let f of h){if(c.has(f.node))continue;c.set(f.node,l),d.push(f.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let f=n.getSelectorDependencyNodes(l);if(f===void 0||f.length===0)continue;if(a){let p=s.hasProvenNoPath(l);if(!s.enabled)a=!1;if(p)continue}for(let p of f){if(c.has(p))continue;c.set(p,l),d.push(p)}continue}let A=n.getSelectorRecord(l);if(!A||A.dependencies.length===0)continue;if(a){let f=s.hasProvenNoPath(l);if(!s.enabled)a=!1;if(f)continue}for(let f of A.dependencies){if(c.has(f.node))continue;c.set(f.node,l),d.push(f.node)}}s?.completeNegative(c);return},et=(e,t)=>{let n=nt(e);if(n.kind==="thenable")return ot(n),new F(t);if(n.kind==="inspection-error")return n.error;return e},tt=(e,t)=>{let n=nt(e);if(n.kind==="thenable")return ot(n),Object.freeze({kind:"error",error:new F(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},it=(e,t,n,o=Pt,r)=>{let{node:i}=e,s=[],a=t.getSelectorRecord(i),d=a?.dependencies,c=d===void 0?new Set:void 0,l,h=0,A=t.getComparisonBaseline(i),f=!0,p=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let S of s)u.add(S.node);return c=u,u};n.enter(t,i,s);let P=t.getSelectorGraphVersion(),Ae=n.getSelectorGraphPublicationCount(t),M=P,B=Ae,He=P,Le=Ae,be,ve=!1,Ge=P,ge=0,H,kt=(u)=>{if(u!==Ge){if(Ge=u,ge=0,H!==void 0)H.reset(),r?.graphVersionReset()}if(ge++,(d?.length??0)===0&&ge<3){r?.admissionSkipped();return}if(H===void 0){let S=d!==void 0&&d.length>0&&d.length<3;H=xt(S?3:0,r)}if(!H.enabled){r?.disabled();return}return H},wt=(u)=>{if(ve)return;let S=t.beginSelectorGraphObservation?.(u);if(S===void 0)return;ve=!0,be=S},ke=(u,S,b,v)=>b-u===v-S,We=(u=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t),b=ke(M,B,u,S))=>{if(u===M)return;if(!ve&&t.beginSelectorGraphObservation!==void 0){M=u,B=S;return}let v=be?.takeAddedEdges();if(b){M=u,B=S;return}if(v!==void 0){let g=!1;for(let T of v)if(o(T.head,T.tail,t,n,2,s.length)!==void 0){g=!0;break}if(!g){M=u,B=S;return}}for(let g=0;g<s.length;g++){let T=s[g],N=o(T.node,i,t,n,0,s.length);if(!N)continue;if(c!==void 0)for(let V=s.length-1;V>=g;V--)c.delete(s[V].node);if(s.length=g,h++,n.getControlFault().kind==="fault")return;let w=new Z(i,[i,...N]);n.latchCycle(t,i,w);return}M=u,B=S},we=()=>{let u=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t);He=u,Le=S;let b=ke(M,B,u,S);if(!b)n.revalidateAncestorPrefixes(t,i);We(u,S,b)};n.setPrefixRevalidator(t,i,We);let Tt=(u)=>{if(!f)throw new Re;let S=n.getControlFault();if(S.kind==="fault")throw S.error;let b=n.getCycle(t,i);if(b!==void 0)throw b;let v=n.activeCyclePath(t,u);if(v){let m=new Z(i,v);throw n.latchCycle(t,i,m),m}let g=s.length,T,N=!1;if(c===void 0){let m=d?.[g];if(m!==void 0&&Object.is(m.node,u))T=!1,N=!0;else T=p().has(u)}else T=c.has(u);if(!T&&!N&&d!==void 0&&d.length>0){let m=d[s.length];if(m!==void 0&&Object.is(m.node,u))N=!0;else{if(l===void 0){l=new Set;for(let W of d)l.add(W.node)}N=l.has(u)}}let L=h,w=t.serve(u,n);we();let V=n.getCycle(t,i);if(V!==void 0)throw V;let X=c!==void 0?c.has(u):h===L&&s.length===g?!1:p().has(u),I=He,G=Le,j=X||N&&I===P,ae=d===void 0&&ke(P,Ae,I,G);if(!j&&!ae){let m=o(u,i,t,n,1,s.length,kt(I));if(m){let W=n.getControlFault();if(W.kind==="fault")throw W.error;let Ue=new Z(i,[i,...m]);throw n.latchCycle(t,i,Ue),Ue}}if(!X){let m=a?.dependencies[s.length];c?.add(u),s.push(m!==void 0&&Object.is(m.node,u)&&Object.is(m.token,w.token)?m:Object.freeze({node:u,token:w.token})),wt(u)}if(M=I,B=G,w.outcome.kind==="control-error"){n.latchControlFault(w.outcome.error);let m=n.getControlFault();if(m.kind==="fault")throw m.error;throw w.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(w.outcome.kind==="error")throw new Te(u,w.outcome.error);return w.outcome.value};try{let u,S,b=!1;try{u=e.get(Tt)}catch(V){b=!0,S=V}finally{f=!1}if(b)S=et(S,"getter");let v=b?void 0:tt(u,"getter");we();let g=n.getControlFault();if(g.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:g.error},s);let T=n.getCycle(t,i);if(T!==void 0)return O(i,t.createOutcomeToken(),{kind:"error",error:T},s);if(b)return O(i,t.createOutcomeToken(),{kind:"error",error:S instanceof F?S:new de(i,S)},s);if(v===void 0)throw Error("Selector result classification was not completed");let N=n.getControlFault();if(N.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:N.error},s);if(v.kind==="error")return O(i,t.createOutcomeToken(),{kind:"error",error:v.error instanceof F?v.error:new de(i,v.error)},s);let L=v.value,w;if(A){let V=e.equal??Object.is,X,I,G=!1;try{X=V(A.value,L)}catch(W){G=!0,I=et(W,"comparator")}let j=G?void 0:tt(X,"comparator");we();let ae=n.getControlFault();if(ae.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:ae.error},s);let Q=n.getCycle(t,i);if(Q!==void 0)return O(i,t.createOutcomeToken(),{kind:"error",error:Q},s);if(G)return O(i,t.createOutcomeToken(),{kind:"error",error:I instanceof F?I:new ce(i,I)},s);if(j===void 0)throw Error("Selector comparator classification was not completed");let m=n.getControlFault();if(m.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:m.error},s);if(j.kind==="error")return O(i,t.createOutcomeToken(),{kind:"error",error:j.error instanceof F?j.error:new ce(i,j.error)},s);if(j.value!==!0&&j.value!==!1)return O(i,t.createOutcomeToken(),{kind:"error",error:new Oe},s);if(j.value===!0)L=A.value,w=A.current?A.token:void 0}return O(i,w??t.createOutcomeToken(),{kind:"value",value:L},s)}finally{try{be?.close()}finally{n.leave(t,i)}}};class y{#t=[];#n;#o=0;#i;#a=It;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#s(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}#s(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 It=Object.freeze({kind:"none"});var st=Symbol("no-committed-selector-baseline");class me{#t;#n=new Map;#o=new Map;#i=new Map;#a;#r=1;#s=0;#c;constructor(e,t,n){this.#t=e,this.#a=t,this.#c=n}readSelector(e){let t=new y,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#a+1)throw Error("Scratch selector generation is not contiguous");this.#a=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.#s++,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.#s}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#d().captureCommittedSelectorSuccess(e)??st,this.#i.set(e,t);return t===st?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 at=4096,Mt=Object.freeze([]);class ct{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class ye{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#a=new WeakMap;#r=new WeakSet;#s=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.#a.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.#a=new WeakMap,this.#r=new WeakSet,this.#s++,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=re(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#A(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#s}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 Mt;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()}#A(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??dt,t.dependencies),a=s?this.#S(e,o?.dependencies??dt,t.dependencies):void 0;if(s)this.#i?.delete(e);if(this.#s++,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.#a.get(o.node);if(r?.delete(e),r?.isEmpty())this.#a.delete(o.node)}for(let o of n){let r=this.#a.get(o.node);if(r===void 0)r=this.#m(),this.#a.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=at-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>at){this.#e();return}t.push(...e)}#e(){if(this.#c===0)return;this.#d=[],this.#l=!0}#m(){return new ct(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var dt=Object.freeze([]);class Pe{transaction=Object.freeze({});#t;#n;#o;#i;#a;#r;#s;#c;#d;#l;#h;#u;#A;#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.#a!==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.#a;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.#a=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.#a=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.#a;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.#a?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#d!==void 0&&Object.is(this.#s,e)&&Object.is(this.#c,t))return this.#d;if(this.#h!==void 0&&Object.is(this.#s,e)&&Object.is(this.#l,t))return this.#h;if(Object.is(this.#s,e))return this.#u?.get(t);return this.#A?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#A;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.#s,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#s,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#A=s,this.#u=void 0,this.#s=void 0}return}let i=this.#d;if(i===void 0){this.#s=e,this.#c=t,this.#d=n;return}if(Object.is(this.#s,e)&&Object.is(this.#c,t))return;if(Object.is(this.#s,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.#s,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#A=s,this.#s=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.#a?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#u?.clear(),this.#A!==void 0){for(let e of this.#A.values())e.clear();this.#A.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#a=void 0,this.#r=void 0,this.#s=void 0,this.#c=void 0,this.#d=void 0,this.#l=void 0,this.#h=void 0,this.#u=void 0,this.#A=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 lt{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]),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ie=(e,t,n)=>new lt(e,t,n),Me=(e)=>{let t=C(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw E(t),new J},ut=(e)=>{let t=C(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw E(t),new J};var zt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},At=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31}),Ft=32,bt=new WeakMap,cn=()=>{let e=new Uint32Array(Ft),t=Object.freeze({read(n){return e[At[n]]??0}});return bt.set(t,e),t},R=(e)=>Object.freeze({kind:"value",value:e}),_t=(e)=>Object.freeze({kind:"error",error:e}),ft=(e)=>e.kind==="value"?R(e.value):_t(e.error),ht=(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)},St=1,ze=2,pt=4,Bt=(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}),_e=(e)=>(e.onAllocation?.(),new Map),Ht=(e)=>(e.onAllocation?.(),new Set),Fe=(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)},mt=(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=_e(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=_e(e),r.set(t,i);i.set(n,o)},Lt=(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=Ht(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Gt=(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=_e(e),e.affected=o;o.set(t,n)};class vt{#t=new WeakMap;#n;#o=1;#i=0;#a=!1;#r;#s;#c;#d=0;#l;#h;#u;#A=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:bt.get(t),this.#f=n,this.evaluate=n?.evaluate??it,this.#n=new ye(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#a}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[At[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Pe(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new y,o=t,r=x(this.#e,o,n),i=xe(this.#e,"StoreTree.get");if(this.#b(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":x(this.#e,o,r=new y);if(D(this.#e,"StoreTree.sub"),this.#b(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 y);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 zt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;$e(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)x(this.#e,n,new y);if(D(this.#e,"StoreTree.scope"),this.#b(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(D(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(D(this.#e,"StoreTree.txn"),this.#b(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Ie(this,o,e),i;try{i=Xe(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new y;fe(this.#e,s,()=>Me(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new y,o=t,r=x(this.#e,o,n);if(D(this.#e,"adapter readHydrationSnapshot"),this.#b(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 y,i=x(this.#e,o,r);if(he(this.#e,e.transaction,e.active),this.#b(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.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new y;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new y;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 y;this.#R(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new y;if(typeof n!=="string")x(this.#e,n,i);he(this.#e,e.transaction,e.active),this.#b(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ie(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 y;return fe(this.#e,h,()=>ut(l))}let c=new y;return fe(this.#e,c,()=>Me(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new me(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)=>re(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new me(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>re(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})}#j(e,t){let n=new ye(this,e,t);this.recordCounter("scopeNodesCreated");let o=new Be(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 De;return this.#b(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#b(i),!Object.is(i.coordinator,this))throw new Ve;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new le;throw new ue}throw new ue}#b(e){if(e.status!=="live")throw new Ee}#X(e,t,n,o){let r=x(this.#e,t,n);D(this.#e,o),this.#b(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new y;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#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=x(this.#e,n,o);he(this.#e,e.transaction,e.active),this.#b(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=_(this.#e,r,()=>ne(o));if(i.kind==="error")throw i.error;let s=this.#N(e,t,n,r);this.#U(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.#U(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=R(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:R(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:R(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 R(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=ft(_(this.#e,n,()=>je(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 _(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=C(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw E(a),new te}let i=C(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw E(i),new te;if(r!==!0&&r!==!1)throw new te;return r})}#J(e,t,n){return _(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=C(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw E(s),new ee}let r=ne(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=Bt(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.#L(r),i!==void 0)for(let a of i)this.#L(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:A}=o;if(h!==void 0&&A!==void 0){let f=this.#E(o,h,A);if(f!==void 0)if(a===void 0)a=f;else d=[f]}if(o.affected!==void 0)for(let[f,p]of o.affected){let P=this.#E(o,f,p);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.#G(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}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#E(e,t,n){let o=Fe(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),ht(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(!Lt(n,r))continue;let i=r.served.outcome,s=this.#G(e,r.scope,r.atom,n);if(ht(i,s))continue;Gt(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}}}#G(e,t,n,o){let r=Fe(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=Fe(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=R(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=R(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)mt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)mt(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 R(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 R(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,R(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,R(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 R(o.fallback.value);let r=o.fallback.initialize,i=ft(_(this.#e,t,()=>je(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.#s=void 0,this.#c=void 0,this.#d=0,this.#l=void 0,this.#h=void 0,this.#a=!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.#a=!1,this.#r=void 0,this.#s=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.#A++}#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 y,h=!1,A;try{Ye(this.#e,l,()=>{try{let f=c(),p=C(f);if(p.kind==="thenable")E(p);else if(p.kind==="inspection-error")h=!0,A=p.error}catch(f){h=!0,A=f;let p=C(f);if(p.kind==="thenable")E(p)}})}catch(f){h=!0,A=f}if(h){if(d===void 0)d=[];if(d.push(A),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Ce(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&St)!==0)return!0;return this.#w(e,t,St),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)&(pt|ze))!==0)return;this.#w(e,t,ze);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 y)}this.#w(e,t,pt)}finally{this.#w(e,t,0,ze)}}#W(e,t){if(Object.is(this.#s,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.#s===void 0){this.#s=e,this.#c=t,this.#d=n&~o;return}if(Object.is(this.#s,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}#U(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 Be{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),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var yt=(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}}},gt=(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 y,h=_(t,l,()=>ne(d));if(h.kind==="error")throw h.error;let A=Se("atom",t.ownerToken);return t.states.add(A),t.atoms.set(A,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...yt(c)})),A},o=(d,c={})=>{if(typeof d!=="function")throw TypeError("atomLazy requires an initializer function");let l=Se("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:d}),...yt(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=Se("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 y;if(x(t,d,c)==="invalid")return;return t.stores.get(d)},a=Object.freeze({assertStore:(d)=>{let c=i(d);if(D(t,"adapter assertStore"),c===void 0)throw TypeError("assertStore requires a valid Store")},read:(d,c)=>{if(i(d)===void 0)throw xe(t,"adapter read"),TypeError("read requires a valid Store");return d.get(c)},subscribe:(d,c,l)=>{if(i(d)===void 0)throw D(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 D(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)=>{D(t,"createStoreTree");let l=new vt(t,d,c);return new Be(l,l.rootScope,c)}})};var Wt=gt(),fn=(e,t)=>Wt.createStoreTree(e,t);
|
|
2
|
+
export{Z as a,it as b,Ne as c,Ce as d,q as e,K as f,Y as g,le as h,J as i,ee as j,te as k,Ee as l,De as m,Ve as n,ue as o,cn as p,Wt as q,fn as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{q as e}from"../chunk-
|
|
1
|
+
import{q as e}from"../chunk-k8zy7f8n.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 z extends Error{seal(){Object.freeze(this)}}class de extends z{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 Te extends z{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 Z extends z{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 F extends z{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 Oe extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ce extends z{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 Re extends z{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"}),Ot=()=>{},Rt=Reflect.apply,Ke=Symbol.for("valdres.runtime-owner/v1");class k extends Error{seal(){Object.freeze(this)}}class Ne extends k{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Ce extends k{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 q extends k{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class K extends k{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class Y extends k{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class le extends k{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends k{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ee extends k{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class te extends k{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class Ee extends k{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class De extends k{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ve extends k{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class ue extends k{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var C=(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})}},E=(e)=>{try{Rt(e.then,e.target,[void 0,Ot])}catch{}},ne=(e)=>{let t=C(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 E(t),Object.freeze({kind:"error",error:new ee})},je=(e)=>{try{return ne(e())}catch(t){let n=C(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 E(n),Object.freeze({kind:"error",error:new ee})}},oe=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},_=(e,t,n)=>{try{let o=oe(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}},Ye=(e,t,n)=>{try{let o=oe(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}},re=(e,t,n)=>oe(e,Object.freeze({kind:"selector",session:t}),n),Xe=(e,t,n)=>oe(e,Object.freeze({kind:"transaction",transaction:t}),n),fe=(e,t,n)=>{try{let o=oe(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}},D=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new K(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Y;throw new q},xe=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new K(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new Y;throw new q},$e=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new K("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new Y;throw new q},he=(e,t,n)=>{if(!n)throw new le;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new K("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new q;throw new Y},Qe=(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,Ke);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Ne;throw Qe(e,n).latchControlFault(r),r}}return"invalid"},x=(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=Qe(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 _(e,r,()=>U(e,t,r))},ie=(e,t)=>(Object.defineProperty(e,Ke,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),Se=(e,t)=>Object.freeze(ie({kind:e},t));var Ze=Object.freeze({kind:"not-thenable"}),Nt=()=>{},Ct=Reflect.apply,Je=Symbol("selector dependency path root"),nt=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ze;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ze}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},ot=(e)=>{try{Ct(e.then,e.target,[void 0,Nt])}catch{}},Et=(e)=>Object.freeze(e),Dt=(e)=>Object.freeze(e),O=(e,t,n,o)=>{let r=Dt(o);return Object.freeze({selector:e,token:t,outcome:Et(n),dependencies:r,attemptedPrefix:n.kind==="value"?Vt:Object.freeze(r.map((i)=>i.node))})},Vt=Object.freeze([]),pe=32,se=8192,jt=2*pe;class rt{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=Math.min(se,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;let o=this.passiveProbeBudget;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){if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;let o=this.passiveProbeBudget;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){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;let o=this.passiveProbeBudget;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){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;let o=this.passiveProbeBudget;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>=pe&&e.size<=se,o;if(this.searches===1&&n)this.first=e,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>se){this.disable("over-cap-hit");return}let n=this.first,o=this.second;this.first=void 0,this.second=void 0,this.retain(n),this.retain(o);let r=this.retain(e);this.locked=!0,this.missWork=0,this.completeDiagnostics(r?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=pe&&e.size<=se;if(this.first===void 0){if(t)this.first=e;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,pe),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=jt){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}reset(){this.first=void 0,this.second=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){if(e===void 0||e.size>se||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.first=e,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}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 xt=(e,t)=>new rt(e,t),Pt=(e,t,n,o,r,i,s)=>{let a=s?.beginSearch()??!1,d=[e],c=new Map([[e,Je]]);while(d.length>0){let l=d.pop();if(Object.is(l,t)){let f=[],p=l;while(p!==Je)f.push(p),p=c.get(p);return f.reverse(),s?.completePositive(),Object.freeze(f)}let h=o.getTransientDependencies(n,l);if(h){if(h.length===0)continue;if(a){let f=s.hasProvenNoPath(l);if(!s.enabled)a=!1;if(f)continue}for(let f of h){if(c.has(f.node))continue;c.set(f.node,l),d.push(f.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let f=n.getSelectorDependencyNodes(l);if(f===void 0||f.length===0)continue;if(a){let p=s.hasProvenNoPath(l);if(!s.enabled)a=!1;if(p)continue}for(let p of f){if(c.has(p))continue;c.set(p,l),d.push(p)}continue}let A=n.getSelectorRecord(l);if(!A||A.dependencies.length===0)continue;if(a){let f=s.hasProvenNoPath(l);if(!s.enabled)a=!1;if(f)continue}for(let f of A.dependencies){if(c.has(f.node))continue;c.set(f.node,l),d.push(f.node)}}s?.completeNegative(c);return},et=(e,t)=>{let n=nt(e);if(n.kind==="thenable")return ot(n),new F(t);if(n.kind==="inspection-error")return n.error;return e},tt=(e,t)=>{let n=nt(e);if(n.kind==="thenable")return ot(n),Object.freeze({kind:"error",error:new F(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},it=(e,t,n,o=Pt,r)=>{let{node:i}=e,s=[],a=t.getSelectorRecord(i),d=a?.dependencies,c=d===void 0?new Set:void 0,l,h=0,A=t.getComparisonBaseline(i),f=!0,p=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let S of s)u.add(S.node);return c=u,u};n.enter(t,i,s);let P=t.getSelectorGraphVersion(),Ae=n.getSelectorGraphPublicationCount(t),M=P,B=Ae,He=P,Le=Ae,be,ve=!1,Ge=P,ge=0,H,kt=(u)=>{if(u!==Ge){if(Ge=u,ge=0,H!==void 0)H.reset(),r?.graphVersionReset()}if(ge++,(d?.length??0)===0&&ge<3){r?.admissionSkipped();return}if(H===void 0){let S=d!==void 0&&d.length>0&&d.length<3;H=xt(S?3:0,r)}if(!H.enabled){r?.disabled();return}return H},wt=(u)=>{if(ve)return;let S=t.beginSelectorGraphObservation?.(u);if(S===void 0)return;ve=!0,be=S},ke=(u,S,b,v)=>b-u===v-S,We=(u=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t),b=ke(M,B,u,S))=>{if(u===M)return;if(!ve&&t.beginSelectorGraphObservation!==void 0){M=u,B=S;return}let v=be?.takeAddedEdges();if(b){M=u,B=S;return}if(v!==void 0){let g=!1;for(let T of v)if(o(T.head,T.tail,t,n,2,s.length)!==void 0){g=!0;break}if(!g){M=u,B=S;return}}for(let g=0;g<s.length;g++){let T=s[g],N=o(T.node,i,t,n,0,s.length);if(!N)continue;if(c!==void 0)for(let V=s.length-1;V>=g;V--)c.delete(s[V].node);if(s.length=g,h++,n.getControlFault().kind==="fault")return;let w=new Z(i,[i,...N]);n.latchCycle(t,i,w);return}M=u,B=S},we=()=>{let u=t.getSelectorGraphVersion(),S=n.getSelectorGraphPublicationCount(t);He=u,Le=S;let b=ke(M,B,u,S);if(!b)n.revalidateAncestorPrefixes(t,i);We(u,S,b)};n.setPrefixRevalidator(t,i,We);let Tt=(u)=>{if(!f)throw new Re;let S=n.getControlFault();if(S.kind==="fault")throw S.error;let b=n.getCycle(t,i);if(b!==void 0)throw b;let v=n.activeCyclePath(t,u);if(v){let m=new Z(i,v);throw n.latchCycle(t,i,m),m}let g=s.length,T,N=!1;if(c===void 0){let m=d?.[g];if(m!==void 0&&Object.is(m.node,u))T=!1,N=!0;else T=p().has(u)}else T=c.has(u);if(!T&&!N&&d!==void 0&&d.length>0){let m=d[s.length];if(m!==void 0&&Object.is(m.node,u))N=!0;else{if(l===void 0){l=new Set;for(let W of d)l.add(W.node)}N=l.has(u)}}let L=h,w=t.serve(u,n);we();let V=n.getCycle(t,i);if(V!==void 0)throw V;let X=c!==void 0?c.has(u):h===L&&s.length===g?!1:p().has(u),I=He,G=Le,j=X||N&&I===P,ae=d===void 0&&ke(P,Ae,I,G);if(!j&&!ae){let m=o(u,i,t,n,1,s.length,kt(I));if(m){let W=n.getControlFault();if(W.kind==="fault")throw W.error;let Ue=new Z(i,[i,...m]);throw n.latchCycle(t,i,Ue),Ue}}if(!X){let m=a?.dependencies[s.length];c?.add(u),s.push(m!==void 0&&Object.is(m.node,u)&&Object.is(m.token,w.token)?m:Object.freeze({node:u,token:w.token})),wt(u)}if(M=I,B=G,w.outcome.kind==="control-error"){n.latchControlFault(w.outcome.error);let m=n.getControlFault();if(m.kind==="fault")throw m.error;throw w.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(w.outcome.kind==="error")throw new Te(u,w.outcome.error);return w.outcome.value};try{let u,S,b=!1;try{u=e.get(Tt)}catch(V){b=!0,S=V}finally{f=!1}if(b)S=et(S,"getter");let v=b?void 0:tt(u,"getter");we();let g=n.getControlFault();if(g.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:g.error},s);let T=n.getCycle(t,i);if(T!==void 0)return O(i,t.createOutcomeToken(),{kind:"error",error:T},s);if(b)return O(i,t.createOutcomeToken(),{kind:"error",error:S instanceof F?S:new de(i,S)},s);if(v===void 0)throw Error("Selector result classification was not completed");let N=n.getControlFault();if(N.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:N.error},s);if(v.kind==="error")return O(i,t.createOutcomeToken(),{kind:"error",error:v.error instanceof F?v.error:new de(i,v.error)},s);let L=v.value,w;if(A){let V=e.equal??Object.is,X,I,G=!1;try{X=V(A.value,L)}catch(W){G=!0,I=et(W,"comparator")}let j=G?void 0:tt(X,"comparator");we();let ae=n.getControlFault();if(ae.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:ae.error},s);let Q=n.getCycle(t,i);if(Q!==void 0)return O(i,t.createOutcomeToken(),{kind:"error",error:Q},s);if(G)return O(i,t.createOutcomeToken(),{kind:"error",error:I instanceof F?I:new ce(i,I)},s);if(j===void 0)throw Error("Selector comparator classification was not completed");let m=n.getControlFault();if(m.kind==="fault")return O(i,t.createOutcomeToken(),{kind:"control-error",error:m.error},s);if(j.kind==="error")return O(i,t.createOutcomeToken(),{kind:"error",error:j.error instanceof F?j.error:new ce(i,j.error)},s);if(j.value!==!0&&j.value!==!1)return O(i,t.createOutcomeToken(),{kind:"error",error:new Oe},s);if(j.value===!0)L=A.value,w=A.current?A.token:void 0}return O(i,w??t.createOutcomeToken(),{kind:"value",value:L},s)}finally{try{be?.close()}finally{n.leave(t,i)}}};class y{#t=[];#n;#o=0;#i;#a=It;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#s(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}#s(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 It=Object.freeze({kind:"none"});var st=Symbol("no-committed-selector-baseline");class me{#t;#n=new Map;#o=new Map;#i=new Map;#a;#r=1;#s=0;#c;constructor(e,t,n){this.#t=e,this.#a=t,this.#c=n}readSelector(e){let t=new y,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#a+1)throw Error("Scratch selector generation is not contiguous");this.#a=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.#s++,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.#s}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#d().captureCommittedSelectorSuccess(e)??st,this.#i.set(e,t);return t===st?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 at=4096,Mt=Object.freeze([]);class ct{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class ye{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#a=new WeakMap;#r=new WeakSet;#s=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.#a.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.#a=new WeakMap,this.#r=new WeakSet,this.#s++,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=re(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#A(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#s}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 Mt;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()}#A(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??dt,t.dependencies),a=s?this.#S(e,o?.dependencies??dt,t.dependencies):void 0;if(s)this.#i?.delete(e);if(this.#s++,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.#a.get(o.node);if(r?.delete(e),r?.isEmpty())this.#a.delete(o.node)}for(let o of n){let r=this.#a.get(o.node);if(r===void 0)r=this.#m(),this.#a.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=at-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>at){this.#e();return}t.push(...e)}#e(){if(this.#c===0)return;this.#d=[],this.#l=!0}#m(){return new ct(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var dt=Object.freeze([]);class Pe{transaction=Object.freeze({});#t;#n;#o;#i;#a;#r;#s;#c;#d;#l;#h;#u;#A;#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.#a!==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.#a;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.#a=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.#a=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.#a;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.#a?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#d!==void 0&&Object.is(this.#s,e)&&Object.is(this.#c,t))return this.#d;if(this.#h!==void 0&&Object.is(this.#s,e)&&Object.is(this.#l,t))return this.#h;if(Object.is(this.#s,e))return this.#u?.get(t);return this.#A?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#A;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.#s,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#s,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#A=s,this.#u=void 0,this.#s=void 0}return}let i=this.#d;if(i===void 0){this.#s=e,this.#c=t,this.#d=n;return}if(Object.is(this.#s,e)&&Object.is(this.#c,t))return;if(Object.is(this.#s,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.#s,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#A=s,this.#s=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.#a?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#u?.clear(),this.#A!==void 0){for(let e of this.#A.values())e.clear();this.#A.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#a=void 0,this.#r=void 0,this.#s=void 0,this.#c=void 0,this.#d=void 0,this.#l=void 0,this.#h=void 0,this.#u=void 0,this.#A=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 lt{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]),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Ie=(e,t,n)=>new lt(e,t,n),Me=(e)=>{let t=C(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw E(t),new J},ut=(e)=>{let t=C(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw E(t),new J};var zt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},At=Object.freeze({sourceEpoch:0,routeVisits:1,deadRouteCompactions:2,scratchHostAllocations:3,propagationSettlements:4,disposalVisits:5,warmParentHops:6,scopeNodesCreated:7,storeFacadesCreated:8,namedScopeHits:9,namedScopeMisses:10,routeAdds:11,routeRemoves:12,fallbackPublications:13,draftCreations:14,scratchMapAllocations:15,finalResolutionVisits:16,finalPreflightVisits:17,draftStorageAllocations:18,commitWorksetAllocations:19,subscriptionIndexMapsCreated:20,subscriptionTargetsCreated:21,subscriptionRegistrations:22,subscriptionRemovals:23,unsubscribeClosuresCreated:24,activeSubscriptionScopes:25,activeSubscriptionTargets:26,activeSubscriptions:27,notificationTargetsReached:28,notificationSnapshots:29,subscriberCallbacksAttempted:30,subscriberErrors:31}),Ft=32,bt=new WeakMap,cn=()=>{let e=new Uint32Array(Ft),t=Object.freeze({read(n){return e[At[n]]??0}});return bt.set(t,e),t},R=(e)=>Object.freeze({kind:"value",value:e}),_t=(e)=>Object.freeze({kind:"error",error:e}),ft=(e)=>e.kind==="value"?R(e.value):_t(e.error),ht=(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)},St=1,ze=2,pt=4,Bt=(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}),_e=(e)=>(e.onAllocation?.(),new Map),Ht=(e)=>(e.onAllocation?.(),new Set),Fe=(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)},mt=(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=_e(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=_e(e),r.set(t,i);i.set(n,o)},Lt=(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=Ht(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Gt=(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=_e(e),e.affected=o;o.set(t,n)};class vt{#t=new WeakMap;#n;#o=1;#i=0;#a=!1;#r;#s;#c;#d=0;#l;#h;#u;#A=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:bt.get(t),this.#f=n,this.evaluate=n?.evaluate??it,this.#n=new ye(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#a}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[At[e]]+=t}#T(){return this.recordCounter("draftCreations"),new Pe(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new y,o=t,r=x(this.#e,o,n),i=xe(this.#e,"StoreTree.get");if(this.#b(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":x(this.#e,o,r=new y);if(D(this.#e,"StoreTree.sub"),this.#b(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 y);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 zt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;$e(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)x(this.#e,n,new y);if(D(this.#e,"StoreTree.scope"),this.#b(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(D(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(D(this.#e,"StoreTree.txn"),this.#b(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Ie(this,o,e),i;try{i=Xe(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new y;fe(this.#e,s,()=>Me(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new y,o=t,r=x(this.#e,o,n);if(D(this.#e,"adapter readHydrationSnapshot"),this.#b(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 y,i=x(this.#e,o,r);if(he(this.#e,e.transaction,e.active),this.#b(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.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new y;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new y;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 y;this.#R(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new y;if(typeof n!=="string")x(this.#e,n,i);he(this.#e,e.transaction,e.active),this.#b(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Ie(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 y;return fe(this.#e,h,()=>ut(l))}let c=new y;return fe(this.#e,c,()=>Me(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new me(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)=>re(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new me(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>re(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})}#j(e,t){let n=new ye(this,e,t);this.recordCounter("scopeNodesCreated");let o=new Be(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 De;return this.#b(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#b(i),!Object.is(i.coordinator,this))throw new Ve;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new le;throw new ue}throw new ue}#b(e){if(e.status!=="live")throw new Ee}#X(e,t,n,o){let r=x(this.#e,t,n);D(this.#e,o),this.#b(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new y;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#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=x(this.#e,n,o);he(this.#e,e.transaction,e.active),this.#b(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=_(this.#e,r,()=>ne(o));if(i.kind==="error")throw i.error;let s=this.#N(e,t,n,r);this.#U(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.#U(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=R(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:R(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:R(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 R(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=ft(_(this.#e,n,()=>je(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 _(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=C(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw E(a),new te}let i=C(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw E(i),new te;if(r!==!0&&r!==!1)throw new te;return r})}#J(e,t,n){return _(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=C(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw E(s),new ee}let r=ne(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=Bt(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.#L(r),i!==void 0)for(let a of i)this.#L(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:A}=o;if(h!==void 0&&A!==void 0){let f=this.#E(o,h,A);if(f!==void 0)if(a===void 0)a=f;else d=[f]}if(o.affected!==void 0)for(let[f,p]of o.affected){let P=this.#E(o,f,p);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.#G(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}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#E(e,t,n){let o=Fe(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),ht(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(!Lt(n,r))continue;let i=r.served.outcome,s=this.#G(e,r.scope,r.atom,n);if(ht(i,s))continue;Gt(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}}}#G(e,t,n,o){let r=Fe(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let c=Fe(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=R(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=R(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)mt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let c of a)mt(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 R(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 R(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,R(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,R(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 R(o.fallback.value);let r=o.fallback.initialize,i=ft(_(this.#e,t,()=>je(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.#s=void 0,this.#c=void 0,this.#d=0,this.#l=void 0,this.#h=void 0,this.#a=!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.#a=!1,this.#r=void 0,this.#s=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.#A++}#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 y,h=!1,A;try{Ye(this.#e,l,()=>{try{let f=c(),p=C(f);if(p.kind==="thenable")E(p);else if(p.kind==="inspection-error")h=!0,A=p.error}catch(f){h=!0,A=f;let p=C(f);if(p.kind==="thenable")E(p)}})}catch(f){h=!0,A=f}if(h){if(d===void 0)d=[];if(d.push(A),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Ce(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&St)!==0)return!0;return this.#w(e,t,St),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)&(pt|ze))!==0)return;this.#w(e,t,ze);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 y)}this.#w(e,t,pt)}finally{this.#w(e,t,0,ze)}}#W(e,t){if(Object.is(this.#s,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.#s===void 0){this.#s=e,this.#c=t,this.#d=n&~o;return}if(Object.is(this.#s,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}#U(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 Be{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),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var yt=(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}}},gt=(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 y,h=_(t,l,()=>ne(d));if(h.kind==="error")throw h.error;let A=Se("atom",t.ownerToken);return t.states.add(A),t.atoms.set(A,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...yt(c)})),A},o=(d,c={})=>{if(typeof d!=="function")throw TypeError("atomLazy requires an initializer function");let l=Se("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:d}),...yt(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=Se("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 y;if(x(t,d,c)==="invalid")return;return t.stores.get(d)},a=Object.freeze({assertStore:(d)=>{let c=i(d);if(D(t,"adapter assertStore"),c===void 0)throw TypeError("assertStore requires a valid Store")},read:(d,c)=>{if(i(d)===void 0)throw xe(t,"adapter read"),TypeError("read requires a valid Store");return d.get(c)},subscribe:(d,c,l)=>{if(i(d)===void 0)throw D(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 D(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)=>{D(t,"createStoreTree");let l=new vt(t,d,c);return new Be(l,l.rootScope,c)}})};var Wt=gt(),fn=(e,t)=>Wt.createStoreTree(e,t);
|
|
2
|
+
export{Z as a,it as b,Ne as c,Ce as d,q as e,K as f,Y as g,le as h,J as i,ee as j,te as k,Ee as l,De as m,Ve as n,ue as o,cn as p,Wt as q,fn as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-
|
|
1
|
+
import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-k8zy7f8n.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 U,d as G,p as Y,r as Z}from"./chunk-g4tkm20t.js";var ee=2048,ne=1e5,M=256,q=1024,A=1e4,te=32,oe=20000,P=new Set(["span","operation","commit"]),re=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),K=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),ie=()=>{},J=Symbol("inspection dependency path root"),se=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 _=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},L=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},W=(e)=>e.length<=M?e:e.slice(0,M),T=()=>({searches:0,visits:0,maxVisits:0,found:0}),ae=()=>({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,lanes:{committed:{prefixRevalidation:T(),newEdgeProof:T(),topologyDeltaProof:T()},scratch:{prefixRevalidation:T(),newEdgeProof:T(),topologyDeltaProof:T()},hydration:{prefixRevalidation:T(),newEdgeProof:T(),topologyDeltaProof:T()}}}}),V=(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}),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})})})})}),N=(e,t,n,o)=>{if(t.remaining--<=0||o>te)return null;if(e===null)return null;if(typeof e==="string")return e.length<=q?e:e.slice(0,q);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,A);for(let c=0;c<a;c++)s.push(N(e[c],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,A);for(let s of i){if(K.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=N(a,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},z=(e)=>{if(e===void 0)return ce;let t={},n={remaining:oe};for(let o of Object.keys(e).slice(0,A)){if(re.has(o)||K.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=N(r,n,new Set,0)}return Object.freeze(t)},ce=Object.freeze({}),de=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...z(t)})},y=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,le=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return F;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:F}catch(t){return{kind:"inspection-error",error:t}}},F=Object.freeze({kind:"not-thenable"});class X{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#C=1;#T=1;#R=1;#E=1;#n=[];#f=new WeakMap;#x=new WeakMap;#w=new WeakMap;#m=new WeakMap;#l=0;#a=0;#t;#y;#O;constructor(e,t){this.#O=t,this.#r=L(e.capacity?.summaries,ee,"Inspection summary",!1),this.#u=L(e.capacity?.details,ne,"Inspection detail",!0),this.#o=new O(this.#r),this.#e=new O(this.#u),this.#y=this.#p(),this.#j()}get recordingId(){return this.#d}registerStore(e,t){this.#w.set(e,t)}capture(e,t){let n=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=n===void 0?void 0:this.#w.get(n);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(t!==void 0){let s=typeof t==="object"&&t!==null||typeof t==="function"?t:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let c=a.atoms.get(s),h=a.selectors.get(s);if(c===void 0&&h===void 0)throw TypeError("Inspection capture requires a valid State");let g=c?.name??h?.name;r=this.reference(s,c===void 0?"selector":"atom",typeof g==="string"?g:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#V(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#h()})}reference(e,t,n){if(this.#t!==void 0)return H;try{let o=this.#f.get(e);if(o===void 0)o=this.#E++,this.#f.set(e,o);let r=this.#x.get(e);if(r===void 0&&n!==void 0)r=W(n),this.#x.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),H}}sessionId(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#T++;return this.#m.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return B;try{let t=this.#A(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#h(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:W(e.name),seqStart:this.#s++,startUs:this.#b(),fields:z(e.fields),totals:P.has(e.type)?ae():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:P.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),B}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#P(n);let o=this.#s++,r=Math.max(0,this.#b()-n.startUs),i=de(n.fields,t.fields),s=this.#z(n,o,r,i,t.result);if(P.has(n.token.type)){if(this.#o.add(s))this.#l++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...z(e.fields),type:e.type,sequence:t,timeUs:this.#b(),...this.#h(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=y(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=y(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=y(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=y(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=y(n.propagationSettled,e.propagationSettled),n.notificationTargets=y(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=y(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=y(n.cycle.searches,o.searches),n.cycle.visits=y(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=y(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")n.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",i=n.cycle.lanes[o.host][r];i.searches=y(i.searches,o.searches),i.visits=y(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=y(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#P(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,a,c,h,g,S){let b=s===0?"prefix-revalidation":s===1?"new-edge-proof":"topology-delta-proof",w=this.beginInterval({type:"cycle-search",fields:{site:b,host:e,hostRef:t,start:this.#I(n),target:this.#I(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-h,acceptedPrefixLength:a,parentWasCold:g}}),p=S?.beginSearch()??!1,d=[n],l=new Map([[n,J]]),v=0,k=0,I=1,x=0,R=0,f=0,C;while(d.length>0){let m=d.pop();if(v++,Object.is(m,o)){let u=[],E=m;while(E!==J)u.push(E),E=l.get(E);u.reverse(),C=Object.freeze(u);break}let j=i.getTransientDependencies(r,m);if(j){if(x++,j.length===0)continue;if(p&&S.hasProvenNoPath(m))continue;k+=j.length;for(let u of j){if(l.has(u.node))continue;l.set(u.node,m),d.push(u.node)}if(d.length>I)I=d.length;continue}if(r.getSelectorDependencyNodes!==void 0){let u=r.getSelectorDependencyNodes(m);if(u===void 0){f++;continue}if(R++,u.length===0)continue;if(p&&S.hasProvenNoPath(m))continue;k+=u.length;for(let E of u){if(l.has(E))continue;l.set(E,m),d.push(E)}if(d.length>I)I=d.length;continue}let D=r.getSelectorRecord(m);if(!D){f++;continue}if(R++,D.dependencies.length===0)continue;if(p&&S.hasProvenNoPath(m))continue;k+=D.dependencies.length;for(let u of D.dependencies){if(l.has(u.node))continue;l.set(u.node,m),d.push(u.node)}if(d.length>I)I=d.length}if(C===void 0)S?.completeNegative(l);return this.addWork({cycle:{searches:1,visits:v,maxVisits:v,found:C===void 0?0:1,site:b,host:e}}),this.finishInterval(w,{result:"returned",fields:{visits:v,edges:k,maxFrontier:I,transientExpansions:x,recordExpansions:R,terminalPrunes:f,found:C!==void 0,...C===void 0?{}:{path:C.map((m)=>this.#I(m))}}}),C}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=le(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,ie])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#D("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=_(e),o=_(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:2,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#D("reset"),this.#j()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(t,n)=>e.capture(t,n),span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#j(){this.#d=`inspection-${se++}`,this.#o=new O(this.#r),this.#e=new O(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#C=1,this.#T=1,this.#R=1,this.#E=1,this.#n=[],this.#f=new WeakMap,this.#m=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#A(e){if(e==="span")return this.#g++;if(e==="operation")return this.#S++;if(e==="commit")return this.#v++;if(e==="selector-evaluation")return this.#k++;if(e==="cycle-search")return this.#C++;return this.#R++}#h(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#I(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):N(e,{remaining:1},new Set,0)}#z(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:V(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:V(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:V(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})}#D(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(t)=>this.#O.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#P(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#V(e){return Math.max(0,Math.round((e-this.#y)*1000))}#b(){return this.#V(this.#p())}}var H=Object.freeze({id:0,kind:"store"}),B=Object.freeze({id:0,type:"operation"}),pe=(e)=>{let t=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let c=a();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof G?1:0),c}},n=(r,i,s)=>{if(r===0){let a=i,c=s;e.registerStore(a,c);let h=a,g=a.set,S=a.update,b=a.reset,w=a.txn;h.set=(p,d)=>t(0,c,void 0,()=>g(p,d)),h.update=(p,d)=>t(1,c,void 0,()=>S(p,d)),h.reset=(p)=>t(2,c,void 0,()=>b(p)),h.txn=(p,d)=>{if(typeof p!=="function"||d!==void 0&&typeof d!=="string")return w(p,d);return t(3,c,d,()=>w(p,d))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,h=e.reference(i,a==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),g=i.getSelectorGraphVersion(),S=s.getSelectorGraphPublicationCount(i),b=i.getSelectorRecord(r.node)?.dependencies,w=b?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:h,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:g,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let d=(l,v,k,I,x,R,f)=>e.findDependencyPath(a,h,l,v,k,I,x,R,g,S,b===void 0,f);try{let l=U(r,i,s,d),v=b===void 0||b.length!==l.dependencies.length||b.some((f,C)=>!Object.is(f.node,l.dependencies[C]?.node)),k=new Set(b?.map((f)=>f.node)),I=new Set(l.dependencies.map((f)=>f.node)),x=0,R=0;for(let f of I)if(!k.has(f))x++;for(let f of k)if(!I.has(f))R++;return e.addWork(v?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:v,proposedEdgesAdded:x,proposedEdgesRemoved:R,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Q=(e={})=>{let t=Y(),n=new X(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:pe(n)})};var Ie=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Q(e),r=Z(n,o);return Object.freeze({store:r,inspect:t})};export{Ie as createInspectableStore};
|
|
1
|
+
import{b as U,d as G,p as Y,r as ne}from"./chunk-k8zy7f8n.js";var te=2048,oe=1e5,A=256,B=1024,V=1e4,re=32,ie=20000,j=new Set(["span","operation","commit"]),se=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),K=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),ae=()=>{},q=Symbol("inspection dependency path root"),ce=1;class N{#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 H=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let i="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??i??0),t=Math.max(t,o.seqEnd??i??0)}return Object.freeze({firstSequence:n,lastSequence:t})},J=(e,n,t,o)=>{let i=e??n;if(!Number.isSafeInteger(i)||i<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return i},W=(e)=>e.length<=A?e:e.slice(0,A),E=()=>({searches:0,visits:0,maxVisits:0,found:0}),X=()=>({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}),Q=(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})}),de=(e)=>{let n=X(),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})},completeSearch(i,r,s,c=0,d=0,y=0){if(t=!0,i==="observing")n.observing++;else if(i==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=c,n.prunedNodes+=d,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,y),r==="initial")n.initialSeeds++;else if(r==="activation-replacement")n.activationReplacementSeeds++;else if(r==="secondary")n.secondarySeeds++;else if(r==="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({...i==="observing"?{observing:1}:i==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:c,prunedNodes:d,maxRetainedEntries:y,...r==="initial"?{initialSeeds:1}:r==="activation-replacement"?{activationReplacementSeeds:1}:r==="secondary"?{secondarySeeds:1}:r==="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})},le=()=>({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:X(),lanes:{committed:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},scratch:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},hydration:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()}}}}),M=(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:Q(e.cycle.newEdgeProofMemo),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})})})})}),O=(e,n,t,o)=>{if(n.remaining--<=0||o>re)return null;if(e===null)return null;if(typeof e==="string")return e.length<=B?e:e.slice(0,B);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=[],c=Math.min(e.length,V);for(let d=0;d<c;d++)s.push(O(e[d],n,t,o+1));return Object.freeze(s)}let i={},r=Object.keys(e).slice(0,V);for(let s of r){if(K.has(s))continue;let c=Reflect.get(e,s);if(c===void 0)continue;i[s]=O(c,n,t,o+1)}return Object.freeze(i)}finally{t.delete(e)}},z=(e)=>{if(e===void 0)return pe;let n={},t={remaining:ie};for(let o of Object.keys(e).slice(0,V)){if(se.has(o)||K.has(o))continue;let i=e[o];if(i===void 0)continue;n[o]=O(i,t,new Set,0)}return Object.freeze(n)},pe=Object.freeze({}),ue=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...z(n)})},a=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,me=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return _;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:_}catch(n){return{kind:"inspection-error",error:n}}},_=Object.freeze({kind:"not-thenable"});class Z{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#R=1;#E=1;#T=1;#P=1;#n=[];#m=new WeakMap;#C=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#y;#x;constructor(e,n){this.#x=n,this.#r=J(e.capacity?.summaries,te,"Inspection summary",!1),this.#u=J(e.capacity?.details,oe,"Inspection detail",!0),this.#o=new N(this.#r),this.#e=new N(this.#u),this.#y=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 i;if(n!==void 0){let s=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,c=o.coordinator.runtimeDomain;if(s===void 0||!c.states.has(s))throw TypeError("Inspection capture requires a valid State");let d=c.atoms.get(s),y=c.selectors.get(s);if(d===void 0&&y===void 0)throw TypeError("Inspection capture requires a valid State");let R=d?.name??y?.name;i=this.reference(s,d===void 0?"selector":"atom",typeof R==="string"?R:void 0)}let r=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(r),monotonicTimeMs:r,store:this.reference(o,"scope",o.name),...i===void 0?{}:{state:i},...this.#b()})}reference(e,n,t){if(this.#t!==void 0)return L;try{let o=this.#m.get(e);if(o===void 0)o=this.#P++,this.#m.set(e,o);let i=this.#C.get(e);if(i===void 0&&t!==void 0)i=W(t),this.#C.set(e,i);return Object.freeze({id:o,kind:n,...i===void 0?{}:{name:i}})}catch{return this.#c("reference"),L}}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 F;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#b(),...e.links}),i={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:W(e.name),seqStart:this.#s++,startUs:this.#I(),fields:z(e.fields),totals:j.has(e.type)?le():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#O():void 0};if(e.type==="commit"){let r=this.#i("operation");if(r!==void 0)r.commitId=n}return this.#n.push(i),t}catch{return this.#c("begin-interval"),F}}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.#s++,i=Math.max(0,this.#I()-t.startUs),r=ue(t.fields,n.fields),s=this.#z(t,o,i,r,n.result);if(j.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.#s++,t=Object.freeze({...z(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#b(),...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=a(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=a(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=a(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=a(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=a(t.propagationSettled,e.propagationSettled),t.notificationTargets=a(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=a(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=a(t.cycle.searches,o.searches),t.cycle.visits=a(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=a(t.cycle.found,o.found);let i=o.newEdgeProofMemo;if(i!==void 0){let r=t.cycle.newEdgeProofMemo;r.admissionSkipped=a(r.admissionSkipped,i.admissionSkipped),r.observing=a(r.observing,i.observing),r.consultedNoPrune=a(r.consultedNoPrune,i.consultedNoPrune),r.consultedPruned=a(r.consultedPruned,i.consultedPruned),r.disabled=a(r.disabled,i.disabled),r.mapProbes=a(r.mapProbes,i.mapProbes),r.prunedNodes=a(r.prunedNodes,i.prunedNodes),r.graphVersionResets=a(r.graphVersionResets,i.graphVersionResets),r.initialSeeds=a(r.initialSeeds,i.initialSeeds),r.activationReplacementSeeds=a(r.activationReplacementSeeds,i.activationReplacementSeeds),r.secondarySeeds=a(r.secondarySeeds,i.secondarySeeds),r.hitDerivedSeeds=a(r.hitDerivedSeeds,i.hitDerivedSeeds),r.missBudgetDisables=a(r.missBudgetDisables,i.missBudgetDisables),r.oversizedHitApproachDisables=a(r.oversizedHitApproachDisables,i.oversizedHitApproachDisables),r.passiveProbeBudgetDisables=a(r.passiveProbeBudgetDisables,i.passiveProbeBudgetDisables),r.maxRetainedEntries=Math.max(r.maxRetainedEntries,i.maxRetainedEntries??0)}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 r=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",s=t.cycle.lanes[o.host][r];s.searches=a(s.searches,o.searches),s.visits=a(s.visits,o.visits),s.maxVisits=Math.max(s.maxVisits,o.maxVisits??0),s.found=a(s.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.#i("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.#i("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",i=this.#i("operation");if(i===void 0)return;let r=this.#i("commit");if(r!==void 0)this.#j(r),this.finishStoreCommit(r.token,{result:o,intents:i.operationIntents,...r.commitChangedSources===void 0?{}:{changedSources:r.commitChangedSources},...r.commitOwnershipChanged===void 0?{}:{ownershipChanged:r.commitOwnershipChanged},sourceApplied:r.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(i.token,o);return}if(n===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#i("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.#i("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let i=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof i==="string"?i:void 0)})}findDependencyPath(e,n,t,o,i,r,s,c,d,y,R,I){let S=s===0?"prefix-revalidation":s===1?"new-edge-proof":"topology-delta-proof",w=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:i.getSelectorGraphVersion(),attributedSessionPublications:r.getSelectorGraphPublicationCount(i),evaluationGraphVersionDelta:i.getSelectorGraphVersion()-d,evaluationAttributedPublicationDelta:r.getSelectorGraphPublicationCount(i)-y,acceptedPrefixLength:c,parentWasCold:R}}),m=I?.beginSearch()??!1,l=[t],v=new Map([[t,q]]),x=0,p=0,b=1,C=0,T=0,P=0,g;while(l.length>0){let f=l.pop();if(x++,Object.is(f,o)){let u=[],k=f;while(k!==q)u.push(k),k=v.get(k);u.reverse(),g=Object.freeze(u);break}let h=r.getTransientDependencies(i,f);if(h){if(C++,h.length===0)continue;if(m){let u=I.hasProvenNoPathMeasured(f);if(!I.enabled)m=!1;if(u)continue}p+=h.length;for(let u of h){if(v.has(u.node))continue;v.set(u.node,f),l.push(u.node)}if(l.length>b)b=l.length;continue}if(i.getSelectorDependencyNodes!==void 0){let u=i.getSelectorDependencyNodes(f);if(u===void 0){P++;continue}if(T++,u.length===0)continue;if(m){let k=I.hasProvenNoPathMeasured(f);if(!I.enabled)m=!1;if(k)continue}p+=u.length;for(let k of u){if(v.has(k))continue;v.set(k,f),l.push(k)}if(l.length>b)b=l.length;continue}let D=i.getSelectorRecord(f);if(!D){P++;continue}if(T++,D.dependencies.length===0)continue;if(m){let u=I.hasProvenNoPathMeasured(f);if(!I.enabled)m=!1;if(u)continue}p+=D.dependencies.length;for(let u of D.dependencies){if(v.has(u.node))continue;v.set(u.node,f),l.push(u.node)}if(l.length>b)b=l.length}if(g===void 0)I?.completeNegative(v);else I?.completePositive();return this.addWork({cycle:{searches:1,visits:x,maxVisits:x,found:g===void 0?0:1,site:S,host:e}}),this.finishInterval(w,{result:"returned",fields:{visits:x,edges:p,maxFrontier:b,transientExpansions:C,recordExpansions:T,terminalPrunes:P,found:g!==void 0,...g===void 0?{}:{path:g.map((f)=>this.#h(f))}}}),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(r){throw this.finishInterval(t,{result:"threw"}),r}let i=me(o);if(i.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),i.error;if(i.kind==="thenable"){try{Reflect.apply(i.then,i.target,[void 0,ae])}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((i,r)=>i.seqStart-r.seqStart),n=[...this.#e.snapshot()].sort((i,r)=>(i.seqStart??i.sequence??0)-(r.seqStart??r.sequence??0)),t=H(e),o=H(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:3,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-${ce++}`,this.#o=new N(this.#r),this.#e=new N(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#R=1,this.#E=1,this.#T=1,this.#P=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#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.#k++;if(e==="cycle-search")return this.#R++;return this.#T++}#b(){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}#i(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"):O(e,{remaining:1},new Set,0)}#z(e,n,t,o,i){let r={...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({...r,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:i??"returned",totals:M(e.totals)});if(e.token.type==="operation")return Object.freeze({...r,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:i==="threw"||i==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:M(e.totals)});if(e.token.type==="commit")return Object.freeze({...r,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:M(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({...r,...s})}#N(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#O(){let e=(n)=>this.#x.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.#s++;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.#y)*1000))}#I(){return this.#M(this.#p())}}var L=Object.freeze({id:0,kind:"store"}),F=Object.freeze({id:0,type:"operation"}),fe=(e)=>{let n=(i,r,s,c)=>{if(e.hasActiveStoreOperation())return c();e.recordStoreEvent(0,i,r,r.name,s);try{let d=c();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof G?1:0),d}},t=(i,r,s)=>{if(i===0){let c=r,d=s;e.registerStore(c,d);let y=c,R=c.set,I=c.update,S=c.reset,w=c.txn;y.set=(m,l)=>n(0,d,void 0,()=>R(m,l)),y.update=(m,l)=>n(1,d,void 0,()=>I(m,l)),y.reset=(m)=>n(2,d,void 0,()=>S(m)),y.txn=(m,l)=>{if(typeof m!=="function"||l!==void 0&&typeof l!=="string")return w(m,l);return n(3,d,l,()=>w(m,l))};return}if(i===1){e.beginDraftCommit(r,s);return}if(i===2)e.recordStoreEvent(3,r)};return Object.assign(t,{evaluate:(i,r,s)=>{let c=r.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=r.name,y=e.reference(r,c==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),R=r.getSelectorGraphVersion(),I=s.getSelectorGraphPublicationCount(r),S=r.getSelectorRecord(i.node)?.dependencies,w=S?.length??0,m=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:c,hostRef:y,selector:e.reference(i.node,"selector",typeof i.name==="string"?i.name:void 0),graphVersionStart:R,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let l=de((p)=>e.addWork({cycle:{newEdgeProofMemo:p}})),v=()=>{let p=l.finish();if(p===void 0)return;return Q(p)},x=(p,b,C,T,P,g,f)=>e.findDependencyPath(c,y,p,b,C,T,P,g,R,I,S===void 0,f);try{let p=U(i,r,s,x,l.sink),b=S===void 0||S.length!==p.dependencies.length||S.some((h,D)=>!Object.is(h.node,p.dependencies[D]?.node)),C=new Set(S?.map((h)=>h.node)),T=new Set(p.dependencies.map((h)=>h.node)),P=0,g=0;for(let h of T)if(!C.has(h))P++;for(let h of C)if(!T.has(h))g++;e.addWork(b?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let f=v();return e.finishInterval(m,{result:"returned",fields:{outcome:p.outcome.kind,dependencyCount:p.dependencies.length,proposedTopologyChanged:b,proposedEdgesAdded:P,proposedEdgesRemoved:g,graphVersionEnd:r.getSelectorGraphVersion(),newEdgeProofMemo:f}}),p}catch(p){let b=v();throw e.finishInterval(m,{result:"threw",fields:{outcome:"threw",graphVersionEnd:r.getSelectorGraphVersion(),newEdgeProofMemo:b}}),p}}}),Object.freeze(t)},ee=(e={})=>{let n=Y(),t=new Z(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:fe(t)})};var Se=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=ee(e),i=ne(t,o);return Object.freeze({store:i,inspect:n})};export{Se as createInspectableStore};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-
|
|
1
|
+
import{a as o,c as a,d as n,e as l,f as p,g as c,h as i,i as s,j as u,k as y,l as v,m as E,n as m,o as S,q as t}from"./chunk-k8zy7f8n.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 U,d as G,p as Y,r as Z}from"./chunk-g4tkm20t.js";var ee=2048,ne=1e5,M=256,q=1024,A=1e4,te=32,oe=20000,P=new Set(["span","operation","commit"]),re=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),K=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),ie=()=>{},J=Symbol("inspection dependency path root"),se=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 _=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},L=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},W=(e)=>e.length<=M?e:e.slice(0,M),T=()=>({searches:0,visits:0,maxVisits:0,found:0}),ae=()=>({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,lanes:{committed:{prefixRevalidation:T(),newEdgeProof:T(),topologyDeltaProof:T()},scratch:{prefixRevalidation:T(),newEdgeProof:T(),topologyDeltaProof:T()},hydration:{prefixRevalidation:T(),newEdgeProof:T(),topologyDeltaProof:T()}}}}),V=(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}),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})})})})}),N=(e,t,n,o)=>{if(t.remaining--<=0||o>te)return null;if(e===null)return null;if(typeof e==="string")return e.length<=q?e:e.slice(0,q);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,A);for(let c=0;c<a;c++)s.push(N(e[c],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,A);for(let s of i){if(K.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=N(a,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},z=(e)=>{if(e===void 0)return ce;let t={},n={remaining:oe};for(let o of Object.keys(e).slice(0,A)){if(re.has(o)||K.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=N(r,n,new Set,0)}return Object.freeze(t)},ce=Object.freeze({}),de=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...z(t)})},y=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,le=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return F;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:F}catch(t){return{kind:"inspection-error",error:t}}},F=Object.freeze({kind:"not-thenable"});class X{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#C=1;#T=1;#R=1;#E=1;#n=[];#f=new WeakMap;#x=new WeakMap;#w=new WeakMap;#m=new WeakMap;#l=0;#a=0;#t;#y;#O;constructor(e,t){this.#O=t,this.#r=L(e.capacity?.summaries,ee,"Inspection summary",!1),this.#u=L(e.capacity?.details,ne,"Inspection detail",!0),this.#o=new O(this.#r),this.#e=new O(this.#u),this.#y=this.#p(),this.#j()}get recordingId(){return this.#d}registerStore(e,t){this.#w.set(e,t)}capture(e,t){let n=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=n===void 0?void 0:this.#w.get(n);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(t!==void 0){let s=typeof t==="object"&&t!==null||typeof t==="function"?t:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let c=a.atoms.get(s),h=a.selectors.get(s);if(c===void 0&&h===void 0)throw TypeError("Inspection capture requires a valid State");let g=c?.name??h?.name;r=this.reference(s,c===void 0?"selector":"atom",typeof g==="string"?g:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#V(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#h()})}reference(e,t,n){if(this.#t!==void 0)return H;try{let o=this.#f.get(e);if(o===void 0)o=this.#E++,this.#f.set(e,o);let r=this.#x.get(e);if(r===void 0&&n!==void 0)r=W(n),this.#x.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),H}}sessionId(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#T++;return this.#m.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return B;try{let t=this.#A(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#h(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:W(e.name),seqStart:this.#s++,startUs:this.#b(),fields:z(e.fields),totals:P.has(e.type)?ae():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:P.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),B}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#P(n);let o=this.#s++,r=Math.max(0,this.#b()-n.startUs),i=de(n.fields,t.fields),s=this.#z(n,o,r,i,t.result);if(P.has(n.token.type)){if(this.#o.add(s))this.#l++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...z(e.fields),type:e.type,sequence:t,timeUs:this.#b(),...this.#h(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=y(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=y(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=y(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=y(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=y(n.propagationSettled,e.propagationSettled),n.notificationTargets=y(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=y(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=y(n.cycle.searches,o.searches),n.cycle.visits=y(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=y(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")n.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",i=n.cycle.lanes[o.host][r];i.searches=y(i.searches,o.searches),i.visits=y(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=y(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#P(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,a,c,h,g,S){let b=s===0?"prefix-revalidation":s===1?"new-edge-proof":"topology-delta-proof",w=this.beginInterval({type:"cycle-search",fields:{site:b,host:e,hostRef:t,start:this.#I(n),target:this.#I(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-h,acceptedPrefixLength:a,parentWasCold:g}}),p=S?.beginSearch()??!1,d=[n],l=new Map([[n,J]]),v=0,k=0,I=1,x=0,R=0,f=0,C;while(d.length>0){let m=d.pop();if(v++,Object.is(m,o)){let u=[],E=m;while(E!==J)u.push(E),E=l.get(E);u.reverse(),C=Object.freeze(u);break}let j=i.getTransientDependencies(r,m);if(j){if(x++,j.length===0)continue;if(p&&S.hasProvenNoPath(m))continue;k+=j.length;for(let u of j){if(l.has(u.node))continue;l.set(u.node,m),d.push(u.node)}if(d.length>I)I=d.length;continue}if(r.getSelectorDependencyNodes!==void 0){let u=r.getSelectorDependencyNodes(m);if(u===void 0){f++;continue}if(R++,u.length===0)continue;if(p&&S.hasProvenNoPath(m))continue;k+=u.length;for(let E of u){if(l.has(E))continue;l.set(E,m),d.push(E)}if(d.length>I)I=d.length;continue}let D=r.getSelectorRecord(m);if(!D){f++;continue}if(R++,D.dependencies.length===0)continue;if(p&&S.hasProvenNoPath(m))continue;k+=D.dependencies.length;for(let u of D.dependencies){if(l.has(u.node))continue;l.set(u.node,m),d.push(u.node)}if(d.length>I)I=d.length}if(C===void 0)S?.completeNegative(l);return this.addWork({cycle:{searches:1,visits:v,maxVisits:v,found:C===void 0?0:1,site:b,host:e}}),this.finishInterval(w,{result:"returned",fields:{visits:v,edges:k,maxFrontier:I,transientExpansions:x,recordExpansions:R,terminalPrunes:f,found:C!==void 0,...C===void 0?{}:{path:C.map((m)=>this.#I(m))}}}),C}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=le(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,ie])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#D("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=_(e),o=_(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:2,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#D("reset"),this.#j()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(t,n)=>e.capture(t,n),span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#j(){this.#d=`inspection-${se++}`,this.#o=new O(this.#r),this.#e=new O(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#C=1,this.#T=1,this.#R=1,this.#E=1,this.#n=[],this.#f=new WeakMap,this.#m=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#A(e){if(e==="span")return this.#g++;if(e==="operation")return this.#S++;if(e==="commit")return this.#v++;if(e==="selector-evaluation")return this.#k++;if(e==="cycle-search")return this.#C++;return this.#R++}#h(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#I(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):N(e,{remaining:1},new Set,0)}#z(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:V(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:V(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:V(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})}#D(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(t)=>this.#O.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#P(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#V(e){return Math.max(0,Math.round((e-this.#y)*1000))}#b(){return this.#V(this.#p())}}var H=Object.freeze({id:0,kind:"store"}),B=Object.freeze({id:0,type:"operation"}),pe=(e)=>{let t=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let c=a();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof G?1:0),c}},n=(r,i,s)=>{if(r===0){let a=i,c=s;e.registerStore(a,c);let h=a,g=a.set,S=a.update,b=a.reset,w=a.txn;h.set=(p,d)=>t(0,c,void 0,()=>g(p,d)),h.update=(p,d)=>t(1,c,void 0,()=>S(p,d)),h.reset=(p)=>t(2,c,void 0,()=>b(p)),h.txn=(p,d)=>{if(typeof p!=="function"||d!==void 0&&typeof d!=="string")return w(p,d);return t(3,c,d,()=>w(p,d))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,h=e.reference(i,a==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),g=i.getSelectorGraphVersion(),S=s.getSelectorGraphPublicationCount(i),b=i.getSelectorRecord(r.node)?.dependencies,w=b?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:h,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:g,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let d=(l,v,k,I,x,R,f)=>e.findDependencyPath(a,h,l,v,k,I,x,R,g,S,b===void 0,f);try{let l=U(r,i,s,d),v=b===void 0||b.length!==l.dependencies.length||b.some((f,C)=>!Object.is(f.node,l.dependencies[C]?.node)),k=new Set(b?.map((f)=>f.node)),I=new Set(l.dependencies.map((f)=>f.node)),x=0,R=0;for(let f of I)if(!k.has(f))x++;for(let f of k)if(!I.has(f))R++;return e.addWork(v?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:v,proposedEdgesAdded:x,proposedEdgesRemoved:R,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Q=(e={})=>{let t=Y(),n=new X(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:pe(n)})};var Ie=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Q(e),r=Z(n,o);return Object.freeze({store:r,inspect:t})};export{Ie as createInspectableStore};
|
|
1
|
+
import{b as U,d as G,p as Y,r as ne}from"./chunk-k8zy7f8n.js";var te=2048,oe=1e5,A=256,B=1024,V=1e4,re=32,ie=20000,j=new Set(["span","operation","commit"]),se=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),K=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),ae=()=>{},q=Symbol("inspection dependency path root"),ce=1;class N{#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 H=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let i="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??i??0),t=Math.max(t,o.seqEnd??i??0)}return Object.freeze({firstSequence:n,lastSequence:t})},J=(e,n,t,o)=>{let i=e??n;if(!Number.isSafeInteger(i)||i<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return i},W=(e)=>e.length<=A?e:e.slice(0,A),E=()=>({searches:0,visits:0,maxVisits:0,found:0}),X=()=>({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}),Q=(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})}),de=(e)=>{let n=X(),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})},completeSearch(i,r,s,c=0,d=0,y=0){if(t=!0,i==="observing")n.observing++;else if(i==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=c,n.prunedNodes+=d,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,y),r==="initial")n.initialSeeds++;else if(r==="activation-replacement")n.activationReplacementSeeds++;else if(r==="secondary")n.secondarySeeds++;else if(r==="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({...i==="observing"?{observing:1}:i==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:c,prunedNodes:d,maxRetainedEntries:y,...r==="initial"?{initialSeeds:1}:r==="activation-replacement"?{activationReplacementSeeds:1}:r==="secondary"?{secondarySeeds:1}:r==="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})},le=()=>({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:X(),lanes:{committed:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},scratch:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()},hydration:{prefixRevalidation:E(),newEdgeProof:E(),topologyDeltaProof:E()}}}}),M=(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:Q(e.cycle.newEdgeProofMemo),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})})})})}),O=(e,n,t,o)=>{if(n.remaining--<=0||o>re)return null;if(e===null)return null;if(typeof e==="string")return e.length<=B?e:e.slice(0,B);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=[],c=Math.min(e.length,V);for(let d=0;d<c;d++)s.push(O(e[d],n,t,o+1));return Object.freeze(s)}let i={},r=Object.keys(e).slice(0,V);for(let s of r){if(K.has(s))continue;let c=Reflect.get(e,s);if(c===void 0)continue;i[s]=O(c,n,t,o+1)}return Object.freeze(i)}finally{t.delete(e)}},z=(e)=>{if(e===void 0)return pe;let n={},t={remaining:ie};for(let o of Object.keys(e).slice(0,V)){if(se.has(o)||K.has(o))continue;let i=e[o];if(i===void 0)continue;n[o]=O(i,t,new Set,0)}return Object.freeze(n)},pe=Object.freeze({}),ue=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...z(n)})},a=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,me=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return _;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:_}catch(n){return{kind:"inspection-error",error:n}}},_=Object.freeze({kind:"not-thenable"});class Z{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#R=1;#E=1;#T=1;#P=1;#n=[];#m=new WeakMap;#C=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#y;#x;constructor(e,n){this.#x=n,this.#r=J(e.capacity?.summaries,te,"Inspection summary",!1),this.#u=J(e.capacity?.details,oe,"Inspection detail",!0),this.#o=new N(this.#r),this.#e=new N(this.#u),this.#y=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 i;if(n!==void 0){let s=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,c=o.coordinator.runtimeDomain;if(s===void 0||!c.states.has(s))throw TypeError("Inspection capture requires a valid State");let d=c.atoms.get(s),y=c.selectors.get(s);if(d===void 0&&y===void 0)throw TypeError("Inspection capture requires a valid State");let R=d?.name??y?.name;i=this.reference(s,d===void 0?"selector":"atom",typeof R==="string"?R:void 0)}let r=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(r),monotonicTimeMs:r,store:this.reference(o,"scope",o.name),...i===void 0?{}:{state:i},...this.#b()})}reference(e,n,t){if(this.#t!==void 0)return L;try{let o=this.#m.get(e);if(o===void 0)o=this.#P++,this.#m.set(e,o);let i=this.#C.get(e);if(i===void 0&&t!==void 0)i=W(t),this.#C.set(e,i);return Object.freeze({id:o,kind:n,...i===void 0?{}:{name:i}})}catch{return this.#c("reference"),L}}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 F;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#b(),...e.links}),i={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:W(e.name),seqStart:this.#s++,startUs:this.#I(),fields:z(e.fields),totals:j.has(e.type)?le():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#O():void 0};if(e.type==="commit"){let r=this.#i("operation");if(r!==void 0)r.commitId=n}return this.#n.push(i),t}catch{return this.#c("begin-interval"),F}}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.#s++,i=Math.max(0,this.#I()-t.startUs),r=ue(t.fields,n.fields),s=this.#z(t,o,i,r,n.result);if(j.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.#s++,t=Object.freeze({...z(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#b(),...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=a(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=a(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=a(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=a(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=a(t.propagationSettled,e.propagationSettled),t.notificationTargets=a(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=a(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=a(t.cycle.searches,o.searches),t.cycle.visits=a(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=a(t.cycle.found,o.found);let i=o.newEdgeProofMemo;if(i!==void 0){let r=t.cycle.newEdgeProofMemo;r.admissionSkipped=a(r.admissionSkipped,i.admissionSkipped),r.observing=a(r.observing,i.observing),r.consultedNoPrune=a(r.consultedNoPrune,i.consultedNoPrune),r.consultedPruned=a(r.consultedPruned,i.consultedPruned),r.disabled=a(r.disabled,i.disabled),r.mapProbes=a(r.mapProbes,i.mapProbes),r.prunedNodes=a(r.prunedNodes,i.prunedNodes),r.graphVersionResets=a(r.graphVersionResets,i.graphVersionResets),r.initialSeeds=a(r.initialSeeds,i.initialSeeds),r.activationReplacementSeeds=a(r.activationReplacementSeeds,i.activationReplacementSeeds),r.secondarySeeds=a(r.secondarySeeds,i.secondarySeeds),r.hitDerivedSeeds=a(r.hitDerivedSeeds,i.hitDerivedSeeds),r.missBudgetDisables=a(r.missBudgetDisables,i.missBudgetDisables),r.oversizedHitApproachDisables=a(r.oversizedHitApproachDisables,i.oversizedHitApproachDisables),r.passiveProbeBudgetDisables=a(r.passiveProbeBudgetDisables,i.passiveProbeBudgetDisables),r.maxRetainedEntries=Math.max(r.maxRetainedEntries,i.maxRetainedEntries??0)}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 r=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",s=t.cycle.lanes[o.host][r];s.searches=a(s.searches,o.searches),s.visits=a(s.visits,o.visits),s.maxVisits=Math.max(s.maxVisits,o.maxVisits??0),s.found=a(s.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.#i("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.#i("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",i=this.#i("operation");if(i===void 0)return;let r=this.#i("commit");if(r!==void 0)this.#j(r),this.finishStoreCommit(r.token,{result:o,intents:i.operationIntents,...r.commitChangedSources===void 0?{}:{changedSources:r.commitChangedSources},...r.commitOwnershipChanged===void 0?{}:{ownershipChanged:r.commitOwnershipChanged},sourceApplied:r.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(i.token,o);return}if(n===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#i("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.#i("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let i=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof i==="string"?i:void 0)})}findDependencyPath(e,n,t,o,i,r,s,c,d,y,R,I){let S=s===0?"prefix-revalidation":s===1?"new-edge-proof":"topology-delta-proof",w=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:i.getSelectorGraphVersion(),attributedSessionPublications:r.getSelectorGraphPublicationCount(i),evaluationGraphVersionDelta:i.getSelectorGraphVersion()-d,evaluationAttributedPublicationDelta:r.getSelectorGraphPublicationCount(i)-y,acceptedPrefixLength:c,parentWasCold:R}}),m=I?.beginSearch()??!1,l=[t],v=new Map([[t,q]]),x=0,p=0,b=1,C=0,T=0,P=0,g;while(l.length>0){let f=l.pop();if(x++,Object.is(f,o)){let u=[],k=f;while(k!==q)u.push(k),k=v.get(k);u.reverse(),g=Object.freeze(u);break}let h=r.getTransientDependencies(i,f);if(h){if(C++,h.length===0)continue;if(m){let u=I.hasProvenNoPathMeasured(f);if(!I.enabled)m=!1;if(u)continue}p+=h.length;for(let u of h){if(v.has(u.node))continue;v.set(u.node,f),l.push(u.node)}if(l.length>b)b=l.length;continue}if(i.getSelectorDependencyNodes!==void 0){let u=i.getSelectorDependencyNodes(f);if(u===void 0){P++;continue}if(T++,u.length===0)continue;if(m){let k=I.hasProvenNoPathMeasured(f);if(!I.enabled)m=!1;if(k)continue}p+=u.length;for(let k of u){if(v.has(k))continue;v.set(k,f),l.push(k)}if(l.length>b)b=l.length;continue}let D=i.getSelectorRecord(f);if(!D){P++;continue}if(T++,D.dependencies.length===0)continue;if(m){let u=I.hasProvenNoPathMeasured(f);if(!I.enabled)m=!1;if(u)continue}p+=D.dependencies.length;for(let u of D.dependencies){if(v.has(u.node))continue;v.set(u.node,f),l.push(u.node)}if(l.length>b)b=l.length}if(g===void 0)I?.completeNegative(v);else I?.completePositive();return this.addWork({cycle:{searches:1,visits:x,maxVisits:x,found:g===void 0?0:1,site:S,host:e}}),this.finishInterval(w,{result:"returned",fields:{visits:x,edges:p,maxFrontier:b,transientExpansions:C,recordExpansions:T,terminalPrunes:P,found:g!==void 0,...g===void 0?{}:{path:g.map((f)=>this.#h(f))}}}),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(r){throw this.finishInterval(t,{result:"threw"}),r}let i=me(o);if(i.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),i.error;if(i.kind==="thenable"){try{Reflect.apply(i.then,i.target,[void 0,ae])}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((i,r)=>i.seqStart-r.seqStart),n=[...this.#e.snapshot()].sort((i,r)=>(i.seqStart??i.sequence??0)-(r.seqStart??r.sequence??0)),t=H(e),o=H(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:3,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-${ce++}`,this.#o=new N(this.#r),this.#e=new N(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#R=1,this.#E=1,this.#T=1,this.#P=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#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.#k++;if(e==="cycle-search")return this.#R++;return this.#T++}#b(){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}#i(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"):O(e,{remaining:1},new Set,0)}#z(e,n,t,o,i){let r={...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({...r,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:i??"returned",totals:M(e.totals)});if(e.token.type==="operation")return Object.freeze({...r,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:i==="threw"||i==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:M(e.totals)});if(e.token.type==="commit")return Object.freeze({...r,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:M(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({...r,...s})}#N(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#O(){let e=(n)=>this.#x.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.#s++;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.#y)*1000))}#I(){return this.#M(this.#p())}}var L=Object.freeze({id:0,kind:"store"}),F=Object.freeze({id:0,type:"operation"}),fe=(e)=>{let n=(i,r,s,c)=>{if(e.hasActiveStoreOperation())return c();e.recordStoreEvent(0,i,r,r.name,s);try{let d=c();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof G?1:0),d}},t=(i,r,s)=>{if(i===0){let c=r,d=s;e.registerStore(c,d);let y=c,R=c.set,I=c.update,S=c.reset,w=c.txn;y.set=(m,l)=>n(0,d,void 0,()=>R(m,l)),y.update=(m,l)=>n(1,d,void 0,()=>I(m,l)),y.reset=(m)=>n(2,d,void 0,()=>S(m)),y.txn=(m,l)=>{if(typeof m!=="function"||l!==void 0&&typeof l!=="string")return w(m,l);return n(3,d,l,()=>w(m,l))};return}if(i===1){e.beginDraftCommit(r,s);return}if(i===2)e.recordStoreEvent(3,r)};return Object.assign(t,{evaluate:(i,r,s)=>{let c=r.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=r.name,y=e.reference(r,c==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),R=r.getSelectorGraphVersion(),I=s.getSelectorGraphPublicationCount(r),S=r.getSelectorRecord(i.node)?.dependencies,w=S?.length??0,m=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:c,hostRef:y,selector:e.reference(i.node,"selector",typeof i.name==="string"?i.name:void 0),graphVersionStart:R,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let l=de((p)=>e.addWork({cycle:{newEdgeProofMemo:p}})),v=()=>{let p=l.finish();if(p===void 0)return;return Q(p)},x=(p,b,C,T,P,g,f)=>e.findDependencyPath(c,y,p,b,C,T,P,g,R,I,S===void 0,f);try{let p=U(i,r,s,x,l.sink),b=S===void 0||S.length!==p.dependencies.length||S.some((h,D)=>!Object.is(h.node,p.dependencies[D]?.node)),C=new Set(S?.map((h)=>h.node)),T=new Set(p.dependencies.map((h)=>h.node)),P=0,g=0;for(let h of T)if(!C.has(h))P++;for(let h of C)if(!T.has(h))g++;e.addWork(b?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let f=v();return e.finishInterval(m,{result:"returned",fields:{outcome:p.outcome.kind,dependencyCount:p.dependencies.length,proposedTopologyChanged:b,proposedEdgesAdded:P,proposedEdgesRemoved:g,graphVersionEnd:r.getSelectorGraphVersion(),newEdgeProofMemo:f}}),p}catch(p){let b=v();throw e.finishInterval(m,{result:"threw",fields:{outcome:"threw",graphVersionEnd:r.getSelectorGraphVersion(),newEdgeProofMemo:b}}),p}}}),Object.freeze(t)},ee=(e={})=>{let n=Y(),t=new Z(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:fe(t)})};var Se=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=ee(e),i=ne(t,o);return Object.freeze({store:i,inspect:n})};export{Se as createInspectableStore};
|
package/dist/types/inspect.d.ts
CHANGED
|
@@ -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, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, 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, 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, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, 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, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector, };
|
|
@@ -34,6 +34,32 @@ export interface InspectionCycleBucket {
|
|
|
34
34
|
* delta signal and its canonical prefix fallback may both contribute. */
|
|
35
35
|
readonly found: number;
|
|
36
36
|
}
|
|
37
|
+
export type InspectionNewEdgeProofMemoTotals = Readonly<{
|
|
38
|
+
readonly admissionSkipped: number;
|
|
39
|
+
readonly observing: number;
|
|
40
|
+
readonly consultedNoPrune: number;
|
|
41
|
+
readonly consultedPruned: number;
|
|
42
|
+
readonly disabled: number;
|
|
43
|
+
readonly mapProbes: number;
|
|
44
|
+
readonly prunedNodes: number;
|
|
45
|
+
readonly resets: Readonly<{
|
|
46
|
+
graphVersion: number;
|
|
47
|
+
}>;
|
|
48
|
+
readonly seeds: Readonly<{
|
|
49
|
+
initial: number;
|
|
50
|
+
activationReplacement: number;
|
|
51
|
+
secondary: number;
|
|
52
|
+
hitDerived: number;
|
|
53
|
+
}>;
|
|
54
|
+
readonly disables: Readonly<{
|
|
55
|
+
missBudget: number;
|
|
56
|
+
oversizedHitApproach: number;
|
|
57
|
+
passiveProbeBudget: number;
|
|
58
|
+
}>;
|
|
59
|
+
readonly retained: Readonly<{
|
|
60
|
+
maxEntries: number;
|
|
61
|
+
}>;
|
|
62
|
+
}> & InspectionJsonObject;
|
|
37
63
|
export interface InspectionCycleTotals {
|
|
38
64
|
readonly searches: number;
|
|
39
65
|
readonly visits: number;
|
|
@@ -49,6 +75,8 @@ export interface InspectionCycleTotals {
|
|
|
49
75
|
scratch: number;
|
|
50
76
|
hydration: number;
|
|
51
77
|
}>;
|
|
78
|
+
/** Aggregate site-1 proof-sharing decisions; no per-node events. */
|
|
79
|
+
readonly newEdgeProofMemo: InspectionNewEdgeProofMemoTotals;
|
|
52
80
|
readonly byLane: Readonly<{
|
|
53
81
|
committed: Readonly<{
|
|
54
82
|
prefixRevalidation: InspectionCycleBucket;
|
|
@@ -147,6 +175,7 @@ interface SelectorEvaluationInspectionBase extends InspectionDetailLinks {
|
|
|
147
175
|
readonly graphVersionStart: number;
|
|
148
176
|
readonly graphVersionEnd: number;
|
|
149
177
|
readonly previousDependencyCount: number;
|
|
178
|
+
readonly newEdgeProofMemo?: InspectionNewEdgeProofMemoTotals;
|
|
150
179
|
}
|
|
151
180
|
export type SelectorEvaluationInspectionDetail = SelectorEvaluationInspectionBase & (Readonly<{
|
|
152
181
|
outcome: "value" | "error" | "control-error";
|
|
@@ -202,7 +231,7 @@ export interface InspectionRecorderFault {
|
|
|
202
231
|
}
|
|
203
232
|
export interface InspectionExport {
|
|
204
233
|
readonly schema: "valdres.inspect";
|
|
205
|
-
readonly schemaVersion:
|
|
234
|
+
readonly schemaVersion: 3;
|
|
206
235
|
readonly recordingId: string;
|
|
207
236
|
readonly summaries: readonly InspectionSummary[];
|
|
208
237
|
readonly details: readonly InspectionDetail[];
|
|
@@ -272,6 +301,24 @@ export interface InternalInspectionIntervalToken {
|
|
|
272
301
|
readonly id: number;
|
|
273
302
|
readonly type: InternalInspectionIntervalType;
|
|
274
303
|
}
|
|
304
|
+
type NewEdgeProofMemoWorkDelta = Readonly<{
|
|
305
|
+
admissionSkipped?: number;
|
|
306
|
+
observing?: number;
|
|
307
|
+
consultedNoPrune?: number;
|
|
308
|
+
consultedPruned?: number;
|
|
309
|
+
disabled?: number;
|
|
310
|
+
mapProbes?: number;
|
|
311
|
+
prunedNodes?: number;
|
|
312
|
+
graphVersionResets?: number;
|
|
313
|
+
initialSeeds?: number;
|
|
314
|
+
activationReplacementSeeds?: number;
|
|
315
|
+
secondarySeeds?: number;
|
|
316
|
+
hitDerivedSeeds?: number;
|
|
317
|
+
missBudgetDisables?: number;
|
|
318
|
+
oversizedHitApproachDisables?: number;
|
|
319
|
+
passiveProbeBudgetDisables?: number;
|
|
320
|
+
maxRetainedEntries?: number;
|
|
321
|
+
}>;
|
|
275
322
|
export interface InspectionWorkDelta {
|
|
276
323
|
readonly selectorEvaluations?: number;
|
|
277
324
|
readonly proposedTopologyChanges?: number;
|
|
@@ -287,6 +334,7 @@ export interface InspectionWorkDelta {
|
|
|
287
334
|
found?: number;
|
|
288
335
|
site?: "prefix-revalidation" | "new-edge-proof" | "topology-delta-proof";
|
|
289
336
|
host?: "committed" | "scratch" | "hydration";
|
|
337
|
+
newEdgeProofMemo?: NewEdgeProofMemoWorkDelta;
|
|
290
338
|
}>;
|
|
291
339
|
}
|
|
292
340
|
export interface InternalInspectionRecorder {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SelectorDefinition, SelectorEvaluationHost, SelectorEvaluationProposal, SelectorEvaluationSession, SelectorCycleSearch } from "./types.js";
|
|
1
|
+
import type { SelectorDefinition, SelectorNewEdgeProofDiagnostics, SelectorEvaluationHost, SelectorEvaluationProposal, SelectorEvaluationSession, SelectorCycleSearch } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Evaluate exactly one selector body. This function never installs the active
|
|
4
4
|
* selector record; persistent, scratch, and hydration hosts apply the returned
|
|
5
5
|
* immutable proposal under their own publication policy.
|
|
6
6
|
*/
|
|
7
|
-
export declare const evaluateSelector: <Node, Token extends object, Value>(definition: SelectorDefinition<Node, Value>, host: SelectorEvaluationHost<Node, Token>, session: SelectorEvaluationSession<Node>, cycleSearch?: SelectorCycleSearch<Node, Token
|
|
7
|
+
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>;
|
|
@@ -64,6 +64,22 @@ export interface SelectorEvaluationProposal<Node, Token extends object, Value =
|
|
|
64
64
|
readonly attemptedPrefix: readonly Node[];
|
|
65
65
|
}
|
|
66
66
|
export type SelectorCycleSearchSite = 0 | 1 | 2;
|
|
67
|
+
/** @internal Inspection-only aggregate classification for one site-1 proof. */
|
|
68
|
+
export type SelectorNewEdgeProofMemoSearchClassification = "observing" | "consulted-no-prune" | "consulted-pruned";
|
|
69
|
+
/** @internal A bounded negative closure retained by one site-1 proof. */
|
|
70
|
+
export type SelectorNewEdgeProofMemoSeedReason = "initial" | "activation-replacement" | "secondary" | "hit-derived";
|
|
71
|
+
/** @internal A site-1 proof-sharing coordinator stopped for this version. */
|
|
72
|
+
export type SelectorNewEdgeProofMemoDisableReason = "miss-budget" | "over-cap-hit" | "passive-probe-budget";
|
|
73
|
+
/**
|
|
74
|
+
* Optional evaluation-local diagnostics sink. Ordinary evaluation omits it;
|
|
75
|
+
* inspectable evaluation aggregates into its enclosing summaries.
|
|
76
|
+
*/
|
|
77
|
+
export interface SelectorNewEdgeProofDiagnostics {
|
|
78
|
+
admissionSkipped(): void;
|
|
79
|
+
disabled(): void;
|
|
80
|
+
graphVersionReset(): void;
|
|
81
|
+
completeSearch(classification: SelectorNewEdgeProofMemoSearchClassification, seed?: SelectorNewEdgeProofMemoSeedReason, disable?: SelectorNewEdgeProofMemoDisableReason, mapProbes?: number, prunedNodes?: number, retainedNodes?: number): void;
|
|
82
|
+
}
|
|
67
83
|
/**
|
|
68
84
|
* Evaluation-local coordinator for fully exhausted negative site-1 proofs.
|
|
69
85
|
*
|
|
@@ -79,8 +95,16 @@ export interface SelectorNewEdgeProofMemo<Node> {
|
|
|
79
95
|
beginSearch(): boolean;
|
|
80
96
|
/** Prunes a node covered by a retained fully-negative closure. */
|
|
81
97
|
hasProvenNoPath(node: Node): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Inspection-only equivalent that also updates aggregate probe counters.
|
|
100
|
+
* The ordinary evaluator deliberately uses the unmeasured method so its
|
|
101
|
+
* DFS inner loop does not pay a diagnostics branch.
|
|
102
|
+
*/
|
|
103
|
+
hasProvenNoPathMeasured(node: Node): boolean;
|
|
82
104
|
/** Publishes a closure only after complete negative exhaustion. */
|
|
83
105
|
completeNegative(closure: ReadonlyMap<Node, unknown>): void;
|
|
106
|
+
/** Completes a physical search that found its target and retained nothing. */
|
|
107
|
+
completePositive(): void;
|
|
84
108
|
}
|
|
85
109
|
/**
|
|
86
110
|
* Optional inspectable-Store strategy. Live nodes are valid only for the
|
package/package.json
CHANGED
package/dist/chunk-g4tkm20t.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
class z extends Error{seal(){Object.freeze(this)}}class ae extends z{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 ve extends z{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 Z extends z{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 M extends z{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 ge extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ce extends z{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 we extends z{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Ue=Object.freeze({kind:"not-thenable"}),wt=()=>{},Tt=Reflect.apply,qe=Symbol.for("valdres.runtime-owner/v1");class g extends Error{seal(){Object.freeze(this)}}class Te extends g{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Oe extends g{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 U extends g{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class q extends g{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class K extends g{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class de extends g{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends g{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ee extends g{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class te extends g{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class Re extends g{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class Ce extends g{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ne extends g{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class le extends g{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var N=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},E=(e)=>{try{Tt(e.then,e.target,[void 0,wt])}catch{}},ne=(e)=>{let t=N(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 E(t),Object.freeze({kind:"error",error:new ee})},Ee=(e)=>{try{return ne(e())}catch(t){let n=N(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 E(n),Object.freeze({kind:"error",error:new ee})}},oe=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},F=(e,t,n)=>{try{let o=oe(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}},Ke=(e,t,n)=>{try{let o=oe(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}},re=(e,t,n)=>oe(e,Object.freeze({kind:"selector",session:t}),n),Ye=(e,t,n)=>oe(e,Object.freeze({kind:"transaction",transaction:t}),n),ue=(e,t,n)=>{try{let o=oe(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}},D=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new q(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new K;throw new U},De=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new q(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new K;throw new U},Xe=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new q("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new K;throw new U},fe=(e,t,n)=>{if(!n)throw new de;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new q("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new U;throw new K},$e=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},W=(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 Te;throw $e(e,n).latchControlFault(r),r}}return"invalid"},x=(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=$e(e,n);if(o!==void 0&&"session"in o)try{let i=W(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 F(e,r,()=>W(e,t,r))},ie=(e,t)=>(Object.defineProperty(e,qe,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),he=(e,t)=>Object.freeze(ie({kind:e},t));var Qe=Object.freeze({kind:"not-thenable"}),Ot=()=>{},Rt=Reflect.apply,Ze=Symbol("selector dependency path root"),tt=(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})}},nt=(e)=>{try{Rt(e.then,e.target,[void 0,Ot])}catch{}},Ct=(e)=>Object.freeze(e),Nt=(e)=>Object.freeze(e),O=(e,t,n,o)=>{let r=Nt(o);return Object.freeze({selector:e,token:t,outcome:Ct(n),dependencies:r,attemptedPrefix:n.kind==="value"?Et:Object.freeze(r.map((i)=>i.node))})},Et=Object.freeze([]),je=32,Ve=8192,Dt=2*je,Vt=()=>{let e,t,n=0,o=0,r=!1,i=!0,s=()=>{e=void 0,t=void 0,o=0,i=!1};return{get enabled(){return i},beginSearch(){return n=0,i&&e!==void 0},hasProvenNoPath(c){if(e?.has(c))return n|=1,!0;if(t?.has(c))return n|=2,!0;return!1},completeNegative(c){if(!i)return;if(n!==0){if(c.size>Ve){s();return}let h=e,A=t;e=void 0,t=void 0;let f=(S)=>{if(S===void 0||S.size>Ve||S===e)return;if(e===void 0||S.size>e.size)t=e,e=S;else if(t===void 0||S.size>t.size)t=S};f(h),f(A),f(c),r=!0,o=0;return}if(c.size===1)return;let d=c.size>=je&&c.size<=Ve;if(e===void 0){if(d)e=c;return}let l=Math.min(c.size,je);if(o+=l,!r&&t===void 0&&d){t=c;return}if(o>=Dt)s()},reset:()=>{e=void 0,t=void 0,n=0,o=0,r=!1,i=!0}}},jt=(e,t,n,o,r,i,s)=>{let a=s?.beginSearch()??!1,c=[e],d=new Map([[e,Ze]]);while(c.length>0){let l=c.pop();if(Object.is(l,t)){let f=[],S=l;while(S!==Ze)f.push(S),S=d.get(S);return f.reverse(),Object.freeze(f)}let h=o.getTransientDependencies(n,l);if(h){if(h.length===0)continue;if(a&&s.hasProvenNoPath(l))continue;for(let f of h){if(d.has(f.node))continue;d.set(f.node,l),c.push(f.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let f=n.getSelectorDependencyNodes(l);if(f===void 0||f.length===0)continue;if(a&&s.hasProvenNoPath(l))continue;for(let S of f){if(d.has(S))continue;d.set(S,l),c.push(S)}continue}let A=n.getSelectorRecord(l);if(!A||A.dependencies.length===0)continue;if(a&&s.hasProvenNoPath(l))continue;for(let f of A.dependencies){if(d.has(f.node))continue;d.set(f.node,l),c.push(f.node)}}s?.completeNegative(d);return},Je=(e,t)=>{let n=tt(e);if(n.kind==="thenable")return nt(n),new M(t);if(n.kind==="inspection-error")return n.error;return e},et=(e,t)=>{let n=tt(e);if(n.kind==="thenable")return nt(n),Object.freeze({kind:"error",error:new M(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},ot=(e,t,n,o=jt)=>{let{node:r}=e,i=[],s=t.getSelectorRecord(r),a=s?.dependencies,c=a===void 0?new Set:void 0,d,l=0,h=t.getComparisonBaseline(r),A=!0,f=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let m of i)u.add(m.node);return c=u,u};n.enter(t,r,i);let S=t.getSelectorGraphVersion(),_=n.getSelectorGraphPublicationCount(t),I=S,H=_,He=S,Be=_,pe,ye=!1,Le=S,Ae=0,Y,kt=(u)=>{if(u!==Le)Le=u,Ae=0,Y?.reset();if(Ae++,(a?.length??0)<3&&Ae<3)return;if(Y===void 0)Y=Vt();return Y.enabled?Y:void 0},vt=(u)=>{if(ye)return;let m=t.beginSelectorGraphObservation?.(u);if(m===void 0)return;ye=!0,pe=m},be=(u,m,b,k)=>b-u===k-m,Ge=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),b=be(I,H,u,m))=>{if(u===I)return;if(!ye&&t.beginSelectorGraphObservation!==void 0){I=u,H=m;return}let k=pe?.takeAddedEdges();if(b){I=u,H=m;return}if(k!==void 0){let v=!1;for(let T of k)if(o(T.head,T.tail,t,n,2,i.length)!==void 0){v=!0;break}if(!v){I=u,H=m;return}}for(let v=0;v<i.length;v++){let T=i[v],C=o(T.node,r,t,n,0,i.length);if(!C)continue;if(c!==void 0)for(let V=i.length-1;V>=v;V--)c.delete(i[V].node);if(i.length=v,l++,n.getControlFault().kind==="fault")return;let w=new Z(r,[r,...C]);n.latchCycle(t,r,w);return}I=u,H=m},ke=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);He=u,Be=m;let b=be(I,H,u,m);if(!b)n.revalidateAncestorPrefixes(t,r);Ge(u,m,b)};n.setPrefixRevalidator(t,r,Ge);let gt=(u)=>{if(!A)throw new we;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let b=n.getCycle(t,r);if(b!==void 0)throw b;let k=n.activeCyclePath(t,u);if(k){let p=new Z(r,k);throw n.latchCycle(t,r,p),p}let v=i.length,T,C=!1;if(c===void 0){let p=a?.[v];if(p!==void 0&&Object.is(p.node,u))T=!1,C=!0;else T=f().has(u)}else T=c.has(u);if(!T&&!C&&a!==void 0&&a.length>0){let p=a[i.length];if(p!==void 0&&Object.is(p.node,u))C=!0;else{if(d===void 0){d=new Set;for(let G of a)d.add(G.node)}C=d.has(u)}}let B=l,w=t.serve(u,n);ke();let V=n.getCycle(t,r);if(V!==void 0)throw V;let X=c!==void 0?c.has(u):l===B&&i.length===v?!1:f().has(u),P=He,L=Be,j=X||C&&P===S,se=a===void 0&&be(S,_,P,L);if(!j&&!se){let p=o(u,r,t,n,1,i.length,kt(P));if(p){let G=n.getControlFault();if(G.kind==="fault")throw G.error;let We=new Z(r,[r,...p]);throw n.latchCycle(t,r,We),We}}if(!X){let p=s?.dependencies[i.length];c?.add(u),i.push(p!==void 0&&Object.is(p.node,u)&&Object.is(p.token,w.token)?p:Object.freeze({node:u,token:w.token})),vt(u)}if(I=P,H=L,w.outcome.kind==="control-error"){n.latchControlFault(w.outcome.error);let p=n.getControlFault();if(p.kind==="fault")throw p.error;throw w.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(w.outcome.kind==="error")throw new ve(u,w.outcome.error);return w.outcome.value};try{let u,m,b=!1;try{u=e.get(gt)}catch(V){b=!0,m=V}finally{A=!1}if(b)m=Je(m,"getter");let k=b?void 0:et(u,"getter");ke();let v=n.getControlFault();if(v.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:v.error},i);let T=n.getCycle(t,r);if(T!==void 0)return O(r,t.createOutcomeToken(),{kind:"error",error:T},i);if(b)return O(r,t.createOutcomeToken(),{kind:"error",error:m instanceof M?m:new ae(r,m)},i);if(k===void 0)throw Error("Selector result classification was not completed");let C=n.getControlFault();if(C.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:C.error},i);if(k.kind==="error")return O(r,t.createOutcomeToken(),{kind:"error",error:k.error instanceof M?k.error:new ae(r,k.error)},i);let B=k.value,w;if(h){let V=e.equal??Object.is,X,P,L=!1;try{X=V(h.value,B)}catch(G){L=!0,P=Je(G,"comparator")}let j=L?void 0:et(X,"comparator");ke();let se=n.getControlFault();if(se.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:se.error},i);let Q=n.getCycle(t,r);if(Q!==void 0)return O(r,t.createOutcomeToken(),{kind:"error",error:Q},i);if(L)return O(r,t.createOutcomeToken(),{kind:"error",error:P instanceof M?P:new ce(r,P)},i);if(j===void 0)throw Error("Selector comparator classification was not completed");let p=n.getControlFault();if(p.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:p.error},i);if(j.kind==="error")return O(r,t.createOutcomeToken(),{kind:"error",error:j.error instanceof M?j.error:new ce(r,j.error)},i);if(j.value!==!0&&j.value!==!1)return O(r,t.createOutcomeToken(),{kind:"error",error:new ge},i);if(j.value===!0)B=h.value,w=h.current?h.token:void 0}return O(r,w??t.createOutcomeToken(),{kind:"value",value:B},i)}finally{try{pe?.close()}finally{n.leave(t,r)}}};class y{#t=[];#n;#o=0;#i;#a=xt;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#s(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}#s(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 xt=Object.freeze({kind:"none"});var rt=Symbol("no-committed-selector-baseline");class Se{#t;#n=new Map;#o=new Map;#i=new Map;#a;#r=1;#s=0;#d;constructor(e,t,n){this.#t=e,this.#a=t,this.#d=n}readSelector(e){let t=new y,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#a+1)throw Error("Scratch selector generation is not contiguous");this.#a=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.#c(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>this.#d(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.#s++,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.#s}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??rt,this.#i.set(e,t);return t===rt?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}var it=4096,Pt=Object.freeze([]);class at{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class me{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#a=new WeakMap;#r=new WeakSet;#s=0;#d=0;#c;#l=!1;#h;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#p(),this.#n=this.#p()}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.#p()};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.#a.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.#a=new WeakMap,this.#r=new WeakSet,this.#s++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(W(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=re(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#A(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#s}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#d===0)this.#c=[],this.#l=!1;this.#d++;let t=this.#c?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#c;if(o===void 0)return;if(t===o.length)return Pt;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#d--,this.#d!==0)return;this.#c=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()}#A(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.#s++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),a!==void 0)this.#m(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.#a.get(o.node);if(r?.delete(e),r?.isEmpty())this.#a.delete(o.node)}for(let o of n){let r=this.#a.get(o.node);if(r===void 0)r=this.#p(),this.#a.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#d===0||this.#l)return;let o=this.#c;if(o===void 0){this.#e();return}let r=it-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let c of t)if(i.has(c.node))s.add(c.node);let a=[];for(let c of n)if(i.has(c.node)&&!s.has(c.node)){if(a.push(Object.freeze({tail:e,head:c.node})),a.length>r){this.#e();return}}return a}#m(e){if(e.length===0)return;let t=this.#c;if(t===void 0||t.length+e.length>it){this.#e();return}t.push(...e)}#e(){if(this.#d===0)return;this.#c=[],this.#l=!0}#p(){return new at(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var st=Object.freeze([]);class xe{transaction=Object.freeze({});#t;#n;#o;#i;#a;#r;#s;#d;#c;#l;#h;#u;#A;#y;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#a!==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.#p();return}let o=this.#a;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.#a=void 0,this.#n=void 0}this.#p();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#p();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#p();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#p();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#p();return}let s=this.#f();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#a=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.#p()}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.#a;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.#a?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#c!==void 0&&Object.is(this.#s,e)&&Object.is(this.#d,t))return this.#c;if(this.#h!==void 0&&Object.is(this.#s,e)&&Object.is(this.#l,t))return this.#h;if(Object.is(this.#s,e))return this.#u?.get(t);return this.#A?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#A;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.#s,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#s,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#A=s,this.#u=void 0,this.#s=void 0}return}let i=this.#c;if(i===void 0){this.#s=e,this.#d=t,this.#c=n;return}if(Object.is(this.#s,e)&&Object.is(this.#d,t))return;if(Object.is(this.#s,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.#d,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.#d,i),this.#l!==void 0&&this.#h!==void 0)a.set(this.#l,this.#h);s.set(this.#s,a);let c=this.#f();c.set(t,n),s.set(e,c),this.#A=s,this.#s=void 0}this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#y,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#y,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#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.#m=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.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#p(){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.#a?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#u?.clear(),this.#A!==void 0){for(let e of this.#A.values())e.clear();this.#A.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#a=void 0,this.#r=void 0,this.#s=void 0,this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#h=void 0,this.#u=void 0,this.#A=void 0,this.#y=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class ct{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]),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Pe=(e,t,n)=>new ct(e,t,n),Ie=(e)=>{let t=N(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw E(t),new J},dt=(e)=>{let t=N(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw E(t),new J};var It=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},pt=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}),zt=32,yt=new WeakMap,an=()=>{let e=new Uint32Array(zt),t=Object.freeze({read(n){return e[pt[n]]??0}});return yt.set(t,e),t},R=(e)=>Object.freeze({kind:"value",value:e}),Mt=(e)=>Object.freeze({kind:"error",error:e}),lt=(e)=>e.kind==="value"?R(e.value):Mt(e.error),ut=(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)},ft=1,ze=2,ht=4,Ft=(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}),Fe=(e)=>(e.onAllocation?.(),new Map),_t=(e)=>(e.onAllocation?.(),new Set),Me=(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)},St=(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=Fe(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=Fe(e),r.set(t,i);i.set(n,o)},Ht=(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=_t(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Bt=(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=Fe(e),e.affected=o;o.set(t,n)};class At{#t=new WeakMap;#n;#o=1;#i=0;#a=!1;#r;#s;#d;#c=0;#l;#h;#u;#A=1;#y=0;#S;#m;#e;#p;#f;evaluate;constructor(e,t,n){this.#e=e,this.#p=t===void 0?void 0:yt.get(t),this.#f=n,this.evaluate=n?.evaluate??ot,this.#n=new me(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#a}get instrumented(){return this.#p!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#p;if(n===void 0)return;n[pt[e]]+=t}#T(){return this.recordCounter("draftCreations"),new xe(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new y,o=t,r=x(this.#e,o,n),i=De(this.#e,"StoreTree.get");if(this.#b(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":x(this.#e,o,r=new y);if(D(this.#e,"StoreTree.sub"),this.#b(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 y);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 c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return It(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Xe(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)x(this.#e,n,new y);if(D(this.#e,"StoreTree.scope"),this.#b(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(D(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(D(this.#e,"StoreTree.txn"),this.#b(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Pe(this,o,e),i;try{i=Ye(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new y;ue(this.#e,s,()=>Ie(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new y,o=t,r=x(this.#e,o,n);if(D(this.#e,"adapter readHydrationSnapshot"),this.#b(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#T(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#K(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new y,i=x(this.#e,o,r);if(fe(this.#e,e.transaction,e.active),this.#b(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new y;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new y;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 y;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new y;if(typeof n!=="string")x(this.#e,n,i);fe(this.#e,e.transaction,e.active),this.#b(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Pe(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let h=new y;return ue(this.#e,h,()=>dt(l))}let d=new y;return ue(this.#e,d,()=>Ie(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new Se(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>re(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new Se(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>re(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(W(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#j(e,t){let n=new me(this,e,t);this.recordCounter("scopeNodesCreated");let o=new _e(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 Ce;return this.#b(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#b(i),!Object.is(i.coordinator,this))throw new Ne;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new de;throw new le}throw new le}#b(e){if(e.status!=="live")throw new Re}#X(e,t,n,o){let r=x(this.#e,t,n);D(this.#e,o),this.#b(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new y;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#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=x(this.#e,n,o);fe(this.#e,e.transaction,e.active),this.#b(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=F(this.#e,r,()=>ne(o));if(i.kind==="error")throw i.error;let s=this.#C(e,t,n,r);this.#U(e,t,n,i.value,s,r)}#I(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#C(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#J(o,a.value,r);this.#U(e,t,n,c,s,r)}#z(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0}):this.#M(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=R(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#N(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#M(e,t,n,o).outcome}#M(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:R(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:R(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0})}#N(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return R(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=lt(F(this.#e,n,()=>Ee(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#v(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 F(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=N(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw E(a),new te}let i=N(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw E(i),new te;if(r!==!0&&r!==!1)throw new te;return r})}#J(e,t,n){return F(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=N(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw E(s),new ee}let r=ne(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=Ft(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#_(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#_(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#f?.(1,e,this.#e.atoms),this.#H(e,r),i!==void 0)for(let a of i)this.#H(e,a);let s=this.#B(r);if(i!==void 0)for(let a of i){let c=this.#B(a);s||=c}if(this.#L(r),i!==void 0)for(let a of i)this.#L(a);this.#se();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#E(o,d,l);let{secondAffectedRecord:h,secondAffectedBefore:A}=o;if(h!==void 0&&A!==void 0){let f=this.#E(o,h,A);if(f!==void 0)if(a===void 0)a=f;else c=[f]}if(o.affected!==void 0)for(let[f,S]of o.affected){let _=this.#E(o,f,S);if(_===void 0)continue;if(a===void 0)a=_;else{if(c===void 0)c=[];c.push(_)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(c?.length??0)),this.#ie(a,c)}catch(a){throw this.#g(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#G(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#H(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#B(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#E(e,t,n){let o=Me(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),ut(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(!Ht(n,r))continue;let i=r.served.outcome,s=this.#G(e,r.scope,r.atom,n);if(ut(i,s))continue;Bt(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#G(e,t,n,o){let r=Me(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=Me(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=R(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=R(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#te(e,n),s!==void 0)St(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)St(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#te(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return R(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ne(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#v(e);if(n.fallback.kind==="eager")return R(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,R(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,R(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#re(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#re(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#v(e);if(o.fallback.kind==="eager")return R(o.fallback.value);let r=o.fallback.initialize,i=lt(F(this.#e,t,()=>Ee(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#v(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#ie(e,t){if(e===void 0){this.#g();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#s=void 0,this.#d=void 0,this.#c=0,this.#l=void 0,this.#h=void 0,this.#a=!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.#a=!1,this.#r=void 0,this.#s=void 0,this.#d=void 0,this.#c=0,this.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#m=void 0,this.#y=this.#u===void 0?0:this.#A++}#g(){this.#y=0,this.#S=void 0,this.#m=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.#m===void 0)this.#m=[o];else this.#m.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#g(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.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.#m;if(i!==void 0)for(let d of i)r(d);if(this.#g(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new y,h=!1,A;try{Ke(this.#e,l,()=>{try{let f=d(),S=N(f);if(S.kind==="thenable")E(S);else if(S.kind==="inspection-error")h=!0,A=S.error}catch(f){h=!0,A=f;let S=N(f);if(S.kind==="thenable")E(S)}})}catch(f){h=!0,A=f}if(h){if(c===void 0)c=[];if(c.push(A),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new Oe(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&ft)!==0)return!0;return this.#w(e,t,ft),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)&(ht|ze))!==0)return;this.#w(e,t,ze);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 y)}this.#w(e,t,ht)}finally{this.#w(e,t,0,ze)}}#W(e,t){if(Object.is(this.#s,e)&&Object.is(this.#d,t))return this.#c;return this.#l?.get(e)?.get(t)??0}#w(e,t,n,o=0){if(this.#s===void 0){this.#s=e,this.#d=t,this.#c=n&~o;return}if(Object.is(this.#s,e)&&Object.is(this.#d,t)){this.#c=(this.#c|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}#U(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 _e{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),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var mt=(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}}},bt=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new y,h=F(t,l,()=>ne(c));if(h.kind==="error")throw h.error;let A=he("atom",t.ownerToken);return t.states.add(A),t.atoms.set(A,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...mt(d)})),A},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=he("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...mt(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=he("selector",t.ownerToken),h=Object.freeze({node:l,get:c,...d.name===void 0?{}:{name:d.name},...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,h),l},i=(c)=>{let d=new y;if(x(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(D(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw De(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw D(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw D(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,d)=>{D(t,"createStoreTree");let l=new At(t,c,d);return new _e(l,l.rootScope,d)}})};var Lt=bt(),ln=(e,t)=>Lt.createStoreTree(e,t);
|
|
2
|
-
export{Z as a,ot as b,Te as c,Oe as d,U as e,q as f,K as g,de as h,J as i,ee as j,te as k,Re as l,Ce as m,Ne as n,le as o,an as p,Lt as q,ln as r};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
class z extends Error{seal(){Object.freeze(this)}}class ae extends z{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 ve extends z{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 Z extends z{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 M extends z{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 ge extends z{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ce extends z{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 we extends z{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var Ue=Object.freeze({kind:"not-thenable"}),wt=()=>{},Tt=Reflect.apply,qe=Symbol.for("valdres.runtime-owner/v1");class g extends Error{seal(){Object.freeze(this)}}class Te extends g{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Oe extends g{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 U extends g{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class q extends g{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class K extends g{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class de extends g{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class J extends g{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class ee extends g{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class te extends g{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class Re extends g{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class Ce extends g{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Ne extends g{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class le extends g{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var N=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return Ue;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):Ue}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},E=(e)=>{try{Tt(e.then,e.target,[void 0,wt])}catch{}},ne=(e)=>{let t=N(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 E(t),Object.freeze({kind:"error",error:new ee})},Ee=(e)=>{try{return ne(e())}catch(t){let n=N(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 E(n),Object.freeze({kind:"error",error:new ee})}},oe=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},F=(e,t,n)=>{try{let o=oe(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}},Ke=(e,t,n)=>{try{let o=oe(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}},re=(e,t,n)=>oe(e,Object.freeze({kind:"selector",session:t}),n),Ye=(e,t,n)=>oe(e,Object.freeze({kind:"transaction",transaction:t}),n),ue=(e,t,n)=>{try{let o=oe(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}},D=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new q(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new K;throw new U},De=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new q(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new K;throw new U},Xe=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new q("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new K;throw new U},fe=(e,t,n)=>{if(!n)throw new de;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new q("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new U;throw new K},$e=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},W=(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 Te;throw $e(e,n).latchControlFault(r),r}}return"invalid"},x=(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=$e(e,n);if(o!==void 0&&"session"in o)try{let i=W(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 F(e,r,()=>W(e,t,r))},ie=(e,t)=>(Object.defineProperty(e,qe,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),he=(e,t)=>Object.freeze(ie({kind:e},t));var Qe=Object.freeze({kind:"not-thenable"}),Ot=()=>{},Rt=Reflect.apply,Ze=Symbol("selector dependency path root"),tt=(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})}},nt=(e)=>{try{Rt(e.then,e.target,[void 0,Ot])}catch{}},Ct=(e)=>Object.freeze(e),Nt=(e)=>Object.freeze(e),O=(e,t,n,o)=>{let r=Nt(o);return Object.freeze({selector:e,token:t,outcome:Ct(n),dependencies:r,attemptedPrefix:n.kind==="value"?Et:Object.freeze(r.map((i)=>i.node))})},Et=Object.freeze([]),je=32,Ve=8192,Dt=2*je,Vt=()=>{let e,t,n=0,o=0,r=!1,i=!0,s=()=>{e=void 0,t=void 0,o=0,i=!1};return{get enabled(){return i},beginSearch(){return n=0,i&&e!==void 0},hasProvenNoPath(c){if(e?.has(c))return n|=1,!0;if(t?.has(c))return n|=2,!0;return!1},completeNegative(c){if(!i)return;if(n!==0){if(c.size>Ve){s();return}let h=e,A=t;e=void 0,t=void 0;let f=(S)=>{if(S===void 0||S.size>Ve||S===e)return;if(e===void 0||S.size>e.size)t=e,e=S;else if(t===void 0||S.size>t.size)t=S};f(h),f(A),f(c),r=!0,o=0;return}if(c.size===1)return;let d=c.size>=je&&c.size<=Ve;if(e===void 0){if(d)e=c;return}let l=Math.min(c.size,je);if(o+=l,!r&&t===void 0&&d){t=c;return}if(o>=Dt)s()},reset:()=>{e=void 0,t=void 0,n=0,o=0,r=!1,i=!0}}},jt=(e,t,n,o,r,i,s)=>{let a=s?.beginSearch()??!1,c=[e],d=new Map([[e,Ze]]);while(c.length>0){let l=c.pop();if(Object.is(l,t)){let f=[],S=l;while(S!==Ze)f.push(S),S=d.get(S);return f.reverse(),Object.freeze(f)}let h=o.getTransientDependencies(n,l);if(h){if(h.length===0)continue;if(a&&s.hasProvenNoPath(l))continue;for(let f of h){if(d.has(f.node))continue;d.set(f.node,l),c.push(f.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let f=n.getSelectorDependencyNodes(l);if(f===void 0||f.length===0)continue;if(a&&s.hasProvenNoPath(l))continue;for(let S of f){if(d.has(S))continue;d.set(S,l),c.push(S)}continue}let A=n.getSelectorRecord(l);if(!A||A.dependencies.length===0)continue;if(a&&s.hasProvenNoPath(l))continue;for(let f of A.dependencies){if(d.has(f.node))continue;d.set(f.node,l),c.push(f.node)}}s?.completeNegative(d);return},Je=(e,t)=>{let n=tt(e);if(n.kind==="thenable")return nt(n),new M(t);if(n.kind==="inspection-error")return n.error;return e},et=(e,t)=>{let n=tt(e);if(n.kind==="thenable")return nt(n),Object.freeze({kind:"error",error:new M(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},ot=(e,t,n,o=jt)=>{let{node:r}=e,i=[],s=t.getSelectorRecord(r),a=s?.dependencies,c=a===void 0?new Set:void 0,d,l=0,h=t.getComparisonBaseline(r),A=!0,f=()=>{let u=c;if(u!==void 0)return u;u=new Set;for(let m of i)u.add(m.node);return c=u,u};n.enter(t,r,i);let S=t.getSelectorGraphVersion(),_=n.getSelectorGraphPublicationCount(t),I=S,H=_,He=S,Be=_,pe,ye=!1,Le=S,Ae=0,Y,kt=(u)=>{if(u!==Le)Le=u,Ae=0,Y?.reset();if(Ae++,(a?.length??0)<3&&Ae<3)return;if(Y===void 0)Y=Vt();return Y.enabled?Y:void 0},vt=(u)=>{if(ye)return;let m=t.beginSelectorGraphObservation?.(u);if(m===void 0)return;ye=!0,pe=m},be=(u,m,b,k)=>b-u===k-m,Ge=(u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t),b=be(I,H,u,m))=>{if(u===I)return;if(!ye&&t.beginSelectorGraphObservation!==void 0){I=u,H=m;return}let k=pe?.takeAddedEdges();if(b){I=u,H=m;return}if(k!==void 0){let v=!1;for(let T of k)if(o(T.head,T.tail,t,n,2,i.length)!==void 0){v=!0;break}if(!v){I=u,H=m;return}}for(let v=0;v<i.length;v++){let T=i[v],C=o(T.node,r,t,n,0,i.length);if(!C)continue;if(c!==void 0)for(let V=i.length-1;V>=v;V--)c.delete(i[V].node);if(i.length=v,l++,n.getControlFault().kind==="fault")return;let w=new Z(r,[r,...C]);n.latchCycle(t,r,w);return}I=u,H=m},ke=()=>{let u=t.getSelectorGraphVersion(),m=n.getSelectorGraphPublicationCount(t);He=u,Be=m;let b=be(I,H,u,m);if(!b)n.revalidateAncestorPrefixes(t,r);Ge(u,m,b)};n.setPrefixRevalidator(t,r,Ge);let gt=(u)=>{if(!A)throw new we;let m=n.getControlFault();if(m.kind==="fault")throw m.error;let b=n.getCycle(t,r);if(b!==void 0)throw b;let k=n.activeCyclePath(t,u);if(k){let p=new Z(r,k);throw n.latchCycle(t,r,p),p}let v=i.length,T,C=!1;if(c===void 0){let p=a?.[v];if(p!==void 0&&Object.is(p.node,u))T=!1,C=!0;else T=f().has(u)}else T=c.has(u);if(!T&&!C&&a!==void 0&&a.length>0){let p=a[i.length];if(p!==void 0&&Object.is(p.node,u))C=!0;else{if(d===void 0){d=new Set;for(let G of a)d.add(G.node)}C=d.has(u)}}let B=l,w=t.serve(u,n);ke();let V=n.getCycle(t,r);if(V!==void 0)throw V;let X=c!==void 0?c.has(u):l===B&&i.length===v?!1:f().has(u),P=He,L=Be,j=X||C&&P===S,se=a===void 0&&be(S,_,P,L);if(!j&&!se){let p=o(u,r,t,n,1,i.length,kt(P));if(p){let G=n.getControlFault();if(G.kind==="fault")throw G.error;let We=new Z(r,[r,...p]);throw n.latchCycle(t,r,We),We}}if(!X){let p=s?.dependencies[i.length];c?.add(u),i.push(p!==void 0&&Object.is(p.node,u)&&Object.is(p.token,w.token)?p:Object.freeze({node:u,token:w.token})),vt(u)}if(I=P,H=L,w.outcome.kind==="control-error"){n.latchControlFault(w.outcome.error);let p=n.getControlFault();if(p.kind==="fault")throw p.error;throw w.outcome.error}let Q=n.getControlFault();if(Q.kind==="fault")throw Q.error;if(w.outcome.kind==="error")throw new ve(u,w.outcome.error);return w.outcome.value};try{let u,m,b=!1;try{u=e.get(gt)}catch(V){b=!0,m=V}finally{A=!1}if(b)m=Je(m,"getter");let k=b?void 0:et(u,"getter");ke();let v=n.getControlFault();if(v.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:v.error},i);let T=n.getCycle(t,r);if(T!==void 0)return O(r,t.createOutcomeToken(),{kind:"error",error:T},i);if(b)return O(r,t.createOutcomeToken(),{kind:"error",error:m instanceof M?m:new ae(r,m)},i);if(k===void 0)throw Error("Selector result classification was not completed");let C=n.getControlFault();if(C.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:C.error},i);if(k.kind==="error")return O(r,t.createOutcomeToken(),{kind:"error",error:k.error instanceof M?k.error:new ae(r,k.error)},i);let B=k.value,w;if(h){let V=e.equal??Object.is,X,P,L=!1;try{X=V(h.value,B)}catch(G){L=!0,P=Je(G,"comparator")}let j=L?void 0:et(X,"comparator");ke();let se=n.getControlFault();if(se.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:se.error},i);let Q=n.getCycle(t,r);if(Q!==void 0)return O(r,t.createOutcomeToken(),{kind:"error",error:Q},i);if(L)return O(r,t.createOutcomeToken(),{kind:"error",error:P instanceof M?P:new ce(r,P)},i);if(j===void 0)throw Error("Selector comparator classification was not completed");let p=n.getControlFault();if(p.kind==="fault")return O(r,t.createOutcomeToken(),{kind:"control-error",error:p.error},i);if(j.kind==="error")return O(r,t.createOutcomeToken(),{kind:"error",error:j.error instanceof M?j.error:new ce(r,j.error)},i);if(j.value!==!0&&j.value!==!1)return O(r,t.createOutcomeToken(),{kind:"error",error:new ge},i);if(j.value===!0)B=h.value,w=h.current?h.token:void 0}return O(r,w??t.createOutcomeToken(),{kind:"value",value:B},i)}finally{try{pe?.close()}finally{n.leave(t,r)}}};class y{#t=[];#n;#o=0;#i;#a=xt;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}noteSelectorGraphPublication(e){let t=this.#n;if(t===void 0){this.#n=e,this.#o=1;return}if(Object.is(t,e)){this.#o++;return}let n=this.#i??(this.#i=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#i?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#r(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#r(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}latchCycle(e,t,n){let o=this.#s(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}#s(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 xt=Object.freeze({kind:"none"});var rt=Symbol("no-committed-selector-baseline");class Se{#t;#n=new Map;#o=new Map;#i=new Map;#a;#r=1;#s=0;#d;constructor(e,t,n){this.#t=e,this.#a=t,this.#d=n}readSelector(e){let t=new y,n=this.serve(e,t);if(n.outcome.kind!=="value")throw n.outcome.error;return n.outcome.value}advanceGeneration(e){if(e!==this.#a+1)throw Error("Scratch selector generation is not contiguous");this.#a=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.#c(),o=n.resolveState(e,t);if(o.kind==="atom"){let a=this.#o.get(e);if(a!==void 0)return a;let c=Object.freeze({token:this.createOutcomeToken(),outcome:n.readDraftAtomOutcome(e,t)});return this.#o.set(e,c),c}let r=this.#n.get(e);if(r!==void 0)return r.served;let i=n.runSelectorActivity(t,()=>this.#d(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.#s++,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.#s}getComparisonBaseline(e){let t=this.#i.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??rt,this.#i.set(e,t);return t===rt?void 0:Object.freeze({current:!1,value:t.value})}createOutcomeToken(){return Object.freeze({id:this.#r++})}#c(){if(this.#t===void 0)throw Error("Scratch selector host is revoked");return this.#t}}var it=4096,Pt=Object.freeze([]);class at{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class me{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;#t=new WeakMap;#n;#o=new WeakMap;#i;#a=new WeakMap;#r=new WeakSet;#s=0;#d=0;#c;#l=!1;#h;#u="live";constructor(e,t,n){this.coordinator=e,this.parent=t,this.name=n,this.children=this.#p(),this.#n=this.#p()}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.#p()};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.#a.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.#a=new WeakMap,this.#r=new WeakSet,this.#s++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(W(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=re(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#A(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#i?.get(n);if(o===void 0){let r=[];for(let s of t.dependencies)if(this.coordinator.runtimeDomain.selectors.has(s.node))r.push(s.node);o=Object.freeze(r);let i=this.#i;if(i===void 0)i=new WeakMap,this.#i=i;i.set(n,o)}return o}getSelectorGraphVersion(){return this.#s}beginSelectorGraphObservation(e){if(!this.coordinator.runtimeDomain.selectors.has(e))return;if(this.#d===0)this.#c=[],this.#l=!1;this.#d++;let t=this.#c?.length??0,n=!1;return Object.freeze({takeAddedEdges:()=>{if(n||this.#l)return;let o=this.#c;if(o===void 0)return;if(t===o.length)return Pt;let r=Object.freeze(o.slice(t));return t=o.length,r},close:()=>{if(n)return;if(n=!0,this.#d--,this.#d!==0)return;this.#c=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()}#A(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.#s++,n.noteSelectorGraphPublication(this),this.#o.set(e,i),this.#r.delete(e),a!==void 0)this.#m(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.#a.get(o.node);if(r?.delete(e),r?.isEmpty())this.#a.delete(o.node)}for(let o of n){let r=this.#a.get(o.node);if(r===void 0)r=this.#p(),this.#a.set(o.node,r);r.add(e)}return!0}#S(e,t,n){if(this.#d===0||this.#l)return;let o=this.#c;if(o===void 0){this.#e();return}let r=it-o.length,i=this.coordinator.runtimeDomain.selectors,s=new Set;for(let c of t)if(i.has(c.node))s.add(c.node);let a=[];for(let c of n)if(i.has(c.node)&&!s.has(c.node)){if(a.push(Object.freeze({tail:e,head:c.node})),a.length>r){this.#e();return}}return a}#m(e){if(e.length===0)return;let t=this.#c;if(t===void 0||t.length+e.length>it){this.#e();return}t.push(...e)}#e(){if(this.#d===0)return;this.#c=[],this.#l=!0}#p(){return new at(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var st=Object.freeze([]);class xe{transaction=Object.freeze({});#t;#n;#o;#i;#a;#r;#s;#d;#c;#l;#h;#u;#A;#y;#S;#m;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#i!==void 0||this.#a!==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.#p();return}let o=this.#a;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.#a=void 0,this.#n=void 0}this.#p();return}let r=this.#o;if(r===void 0){this.#n=e,this.#o=t,this.#p();return}if(Object.is(this.#n,e)&&Object.is(r.atom,t.atom)){this.#o=t,this.#p();return}if(Object.is(this.#n,e)){let i=this.#i;if(i===void 0){this.#i=t,this.#p();return}if(Object.is(i.atom,t.atom)){this.#i=t,this.#p();return}let s=this.#f();s.set(r.atom,r),s.set(i.atom,i),s.set(t.atom,t),this.#a=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.#p()}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.#a;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.#a?.get(t);return this.#r?.get(e)?.get(t)}getAtomBaseline(e,t){if(this.#c!==void 0&&Object.is(this.#s,e)&&Object.is(this.#d,t))return this.#c;if(this.#h!==void 0&&Object.is(this.#s,e)&&Object.is(this.#l,t))return this.#h;if(Object.is(this.#s,e))return this.#u?.get(t);return this.#A?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#A;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.#s,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#s,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#A=s,this.#u=void 0,this.#s=void 0}return}let i=this.#c;if(i===void 0){this.#s=e,this.#d=t,this.#c=n;return}if(Object.is(this.#s,e)&&Object.is(this.#d,t))return;if(Object.is(this.#s,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.#d,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.#d,i),this.#l!==void 0&&this.#h!==void 0)a.set(this.#l,this.#h);s.set(this.#s,a);let c=this.#f();c.set(t,n),s.set(e,c),this.#A=s,this.#s=void 0}this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#h=void 0}getFallback(e){if(Object.is(this.#y,e))return this.#S;return this.#m?.get(e)}hasFallback(e){return Object.is(this.#y,e)||(this.#m?.has(e)??!1)}setFallback(e,t){let n=this.#m;if(n!==void 0){n.set(e,t);return}if(this.#S===void 0){this.#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.#m=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.#m!==void 0)for(let[t,n]of this.#m)e(t,n)}#p(){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.#a?.clear(),this.#r!==void 0){for(let e of this.#r.values())e.clear();this.#r.clear()}if(this.#u?.clear(),this.#A!==void 0){for(let e of this.#A.values())e.clear();this.#A.clear()}this.#m?.clear(),this.#n=void 0,this.#o=void 0,this.#i=void 0,this.#a=void 0,this.#r=void 0,this.#s=void 0,this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#h=void 0,this.#u=void 0,this.#A=void 0,this.#y=void 0,this.#S=void 0,this.#m=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class ct{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]),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var Pe=(e,t,n)=>new ct(e,t,n),Ie=(e)=>{let t=N(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw E(t),new J},dt=(e)=>{let t=N(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw E(t),new J};var It=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},pt=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}),zt=32,yt=new WeakMap,an=()=>{let e=new Uint32Array(zt),t=Object.freeze({read(n){return e[pt[n]]??0}});return yt.set(t,e),t},R=(e)=>Object.freeze({kind:"value",value:e}),Mt=(e)=>Object.freeze({kind:"error",error:e}),lt=(e)=>e.kind==="value"?R(e.value):Mt(e.error),ut=(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)},ft=1,ze=2,ht=4,Ft=(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}),Fe=(e)=>(e.onAllocation?.(),new Map),_t=(e)=>(e.onAllocation?.(),new Set),Me=(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)},St=(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=Fe(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=Fe(e),r.set(t,i);i.set(n,o)},Ht=(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=_t(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},Bt=(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=Fe(e),e.affected=o;o.set(t,n)};class At{#t=new WeakMap;#n;#o=1;#i=0;#a=!1;#r;#s;#d;#c=0;#l;#h;#u;#A=1;#y=0;#S;#m;#e;#p;#f;evaluate;constructor(e,t,n){this.#e=e,this.#p=t===void 0?void 0:yt.get(t),this.#f=n,this.evaluate=n?.evaluate??ot,this.#n=new me(this),this.recordCounter("scopeNodesCreated")}get runtimeDomain(){return this.#e}get postSourceApply(){return this.#a}get instrumented(){return this.#p!==void 0}get rootScope(){return this.#n}recordCounter(e,t=1){let n=this.#p;if(n===void 0)return;n[pt[e]]+=t}#T(){return this.recordCounter("draftCreations"),new xe(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new y,o=t,r=x(this.#e,o,n),i=De(this.#e,"StoreTree.get");if(this.#b(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":x(this.#e,o,r=new y);if(D(this.#e,"StoreTree.sub"),this.#b(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 y);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 c=a.get(e);if(c===void 0){if(c=new Map,a.set(e,c),this.instrumented)this.recordCounter("subscriptionIndexMapsCreated"),this.recordCounter("activeSubscriptionScopes")}let d=c.get(o);if(d===void 0){if(d={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},c.set(o,d),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:d,previous:d.tail,next:void 0};if(d.tail===void 0)d.head=l;else d.tail.next=l;if(d.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return It(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;Xe(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)x(this.#e,n,new y);if(D(this.#e,"StoreTree.scope"),this.#b(e),t===0)return this.#j(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#j(e,n)}dispose(e){if(D(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(D(this.#e,"StoreTree.txn"),this.#b(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#T(),r=Pe(this,o,e),i;try{i=Ye(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new y;ue(this.#e,s,()=>Ie(i)),this.#F(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new y,o=t,r=x(this.#e,o,n);if(D(this.#e,"adapter readHydrationSnapshot"),this.#b(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#T(),s;try{if(this.#e.atoms.has(o)){let a=this.#k(i,e,o,n);if(a.kind!=="value")throw a.error;return a.value}return s=this.#K(i,e),s.readSelector(o)}finally{s?.revoke(),i.close(),i.forEachFallback((a,c)=>{if(this.#t.has(a))return;this.#t.set(a,c),this.recordCounter("fallbackPublications")}),i.release()}}transactionGet(e,t,n){let o=n,r=new y,i=x(this.#e,o,r);if(fe(this.#e,e.transaction,e.active),this.#b(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#k(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new y;this.#R(e,t,r,i,"Transaction.set"),this.#P(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new y;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 y;this.#R(e,t,o,r,"Transaction.reset"),this.#z(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new y;if(typeof n!=="string")x(this.#e,n,i);fe(this.#e,e.transaction,e.active),this.#b(t);let s=this.#Y(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=Pe(this,e,s);if(o===1)return a;if(typeof r!=="function")throw TypeError("Transaction.scope requires a callback function");let c;try{c=r(a)}catch(l){let h=new y;return ue(this.#e,h,()=>dt(l))}let d=new y;return ue(this.#e,d,()=>Ie(c)),c}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new Se(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:(n)=>t.captureCommittedSelectorSuccess(n),runSelectorActivity:(n,o)=>re(this.#e,n,o)}),e.generation,this.evaluate)}#K(e,t){return this.recordCounter("scratchHostAllocations"),new Se(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#k(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>re(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(W(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#j(e,t){let n=new me(this,e,t);this.recordCounter("scopeNodesCreated");let o=new _e(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 Ce;return this.#b(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#b(i),!Object.is(i.coordinator,this))throw new Ne;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new de;throw new le}throw new le}#b(e){if(e.status!=="live")throw new Re}#X(e,t,n,o){let r=x(this.#e,t,n);D(this.#e,o),this.#b(e),this.#x(t,r,o)}#O(e,t,n,o,r){let i=t,s=new y;this.#X(e,i,s,n);let a=this.#T();try{if(o==="set")this.#P(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#z(a,e,i,s)}catch(c){throw a.close(),a.release(),c}a.close();try{this.#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=x(this.#e,n,o);fe(this.#e,e.transaction,e.active),this.#b(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#P(e,t,n,o,r){let i=F(this.#e,r,()=>ne(o));if(i.kind==="error")throw i.error;let s=this.#C(e,t,n,r);this.#U(e,t,n,i.value,s,r)}#I(e,t,n,o,r,i){if(typeof o!=="function")throw TypeError(`${i} requires an updater function`);let s=this.#C(e,t,n,r),a=e.hasIntents?this.#k(e,t,n,r):s.outcome;if(a.kind!=="value")throw a.error;let c=this.#J(o,a.value,r);this.#U(e,t,n,c,s,r)}#z(e,t,n,o){this.#C(e,t,n,o);let r=t.parent===void 0?Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0}):this.#M(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#C(e,t,n,o){let r=e.getAtomBaseline(t,n);if(r!==void 0)return r;let i=t.atomOverrides.has(n),s=t,a;while(s!==void 0){if(s.atomOverrides.has(n)){a=R(s.atomOverrides.get(n));break}s=s.parent}let c=a===void 0,d=Object.freeze({owned:i,outcome:a??this.#N(e,n,o),reachesFallback:c});return e.setAtomBaseline(t,n,d),d}#k(e,t,n,o){return this.#M(e,t,n,o).outcome}#M(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:R(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:R(r.atomOverrides.get(n)),reachesFallback:!1});r=r.parent}return Object.freeze({outcome:this.#N(e,n,o),reachesFallback:!0})}#N(e,t,n){let o=this.#t.get(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return R(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=lt(F(this.#e,n,()=>Ee(i)));return e.setFallback(t,a),a}#Q(e,t,n,o){let r=this.#v(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 F(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=N(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw E(a),new te}let i=N(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw E(i),new te;if(r!==!0&&r!==!1)throw new te;return r})}#J(e,t,n){return F(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=N(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw E(s),new ee}let r=ne(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=Ft(this.instrumented?()=>this.recordCounter("commitWorksetAllocations"):void 0),r,i;if(t!==void 0&&n!==void 0)r=this.#_(e,n,t,o);else e.forEachIntent((a,c)=>{let d=this.#_(e,a,c,o);if(r===void 0){r=d;return}if(i===void 0)i=[];i.push(d)});if(r===void 0)return;if(this.#f?.(1,e,this.#e.atoms),this.#H(e,r),i!==void 0)for(let a of i)this.#H(e,a);let s=this.#B(r);if(i!==void 0)for(let a of i){let c=this.#B(a);s||=c}if(this.#L(r),i!==void 0)for(let a of i)this.#L(a);this.#se();try{let a,c,d=o.affectedRecord,l=o.affectedBefore;if(d!==void 0&&l!==void 0)a=this.#E(o,d,l);let{secondAffectedRecord:h,secondAffectedBefore:A}=o;if(h!==void 0&&A!==void 0){let f=this.#E(o,h,A);if(f!==void 0)if(a===void 0)a=f;else c=[f]}if(o.affected!==void 0)for(let[f,S]of o.affected){let _=this.#E(o,f,S);if(_===void 0)continue;if(a===void 0)a=_;else{if(c===void 0)c=[];c.push(_)}}if(s)this.#i+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(c?.length??0)),this.#ie(a,c)}catch(a){throw this.#g(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#G(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#H(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#B(e){let{intent:t,scope:n}=e;if(t.kind==="set")n.atomOverrides.set(t.atom,t.value);else n.atomOverrides.delete(t.atom);return e.ownershipChanged}#L({scope:e,intent:t}){let n=e.getAtomView(t.atom);if(n===void 0)return;if(t.kind==="set"||e.parent===void 0)e.detachAtomView(n);else e.attachAtomView(n,this.#oe(e.parent,t.atom))}#E(e,t,n){let o=Me(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),ut(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(!Ht(n,r))continue;let i=r.served.outcome,s=this.#G(e,r.scope,r.atom,n);if(ut(i,s))continue;Bt(n,r,i);let a=o.length;r.inheritingChildren.forEach((c)=>{this.recordCounter("routeVisits"),o.push(c)});for(let c=a,d=o.length-1;c<d;c++,d--){let l=o[c];o[c]=o[d],o[d]=l}}}#G(e,t,n,o){let r=Me(o,n,t);if(r!==void 0)return r;let i=t,s,a,c;while(i!==void 0){let d=Me(o,n,i);if(d!==void 0){c=d;break}if(s===void 0)s=i;else{if(a===void 0)a=[];a.push(i)}let l=e.getIntent(i,n);if(l?.kind==="set"){c=R(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){c=R(i.atomOverrides.get(n));break}i=i.parent}if(c??=this.#te(e,n),s!==void 0)St(o,n,s,c),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let d of a)St(o,n,d,c),this.recordCounter("finalPreflightVisits");return c}#te(e,t){let n=this.#t.get(t);if(n!==void 0)return n;let o=e.getFallback(t);if(o!==void 0)return o;let r=this.#v(t);if(r.fallback.kind==="eager")return R(r.fallback.value);throw Error("Final Atom fallback was not resolved during staging")}#ne(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=this.#v(e);if(n.fallback.kind==="eager")return R(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,R(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,R(o.atomOverrides.get(t)));break}if(o.parent===void 0){i=o.createAtomView(t,this.#re(t,n));break}this.recordCounter("warmParentHops"),r.push(o),o=o.parent}for(let s=r.length-1;s>=0;s--)i=r[s].createAtomView(t,i.served.outcome,i);return i.served}#re(e,t){let n=this.#t.get(e);if(n!==void 0)return n;let o=this.#v(e);if(o.fallback.kind==="eager")return R(o.fallback.value);let r=o.fallback.initialize,i=lt(F(this.#e,t,()=>Ee(r)));return this.#t.set(e,i),this.recordCounter("fallbackPublications"),i}#v(e){let t=this.#e.atoms.get(e);if(t===void 0)throw TypeError("Unknown committed StoreTree Atom");return t}#ie(e,t){if(e===void 0){this.#g();return}this.recordCounter("propagationSettlements"),this.#r=[],this.#s=void 0,this.#d=void 0,this.#c=0,this.#l=void 0,this.#h=void 0,this.#a=!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.#a=!1,this.#r=void 0,this.#s=void 0,this.#d=void 0,this.#c=0,this.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#m=void 0,this.#y=this.#u===void 0?0:this.#A++}#g(){this.#y=0,this.#S=void 0,this.#m=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.#m===void 0)this.#m=[o];else this.#m.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#g(),e!==void 0)throw e;return}let n,o,r=(d)=>{let l=d.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.#m;if(i!==void 0)for(let d of i)r(d);if(this.#g(),n===void 0){if(e!==void 0)throw e;return}let s=Object.freeze(o??[n]),a=this.instrumented;if(a)this.recordCounter("notificationSnapshots");let c;for(let d of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new y,h=!1,A;try{Ke(this.#e,l,()=>{try{let f=d(),S=N(f);if(S.kind==="thenable")E(S);else if(S.kind==="inspection-error")h=!0,A=S.error}catch(f){h=!0,A=f;let S=N(f);if(S.kind==="thenable")E(S)}})}catch(f){h=!0,A=f}if(h){if(c===void 0)c=[];if(c.push(A),a)this.recordCounter("subscriberErrors")}}if(c===void 0){if(e!==void 0)throw e;return}throw new Oe(e===void 0?c:[e,...c])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&ft)!==0)return!0;return this.#w(e,t,ft),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)&(ht|ze))!==0)return;this.#w(e,t,ze);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 y)}this.#w(e,t,ht)}finally{this.#w(e,t,0,ze)}}#W(e,t){if(Object.is(this.#s,e)&&Object.is(this.#d,t))return this.#c;return this.#l?.get(e)?.get(t)??0}#w(e,t,n,o=0){if(this.#s===void 0){this.#s=e,this.#d=t,this.#c=n&~o;return}if(Object.is(this.#s,e)&&Object.is(this.#d,t)){this.#c=(this.#c|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}#U(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 _e{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),ie(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var mt=(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}}},bt=(e)=>{let t={states:new WeakSet,atoms:new WeakMap,selectors:new WeakMap,stores:new WeakMap,transactionCursors:new WeakMap,ownerToken:Object.freeze({}),activity:void 0},n=(c,d={})=>{let l=new y,h=F(t,l,()=>ne(c));if(h.kind==="error")throw h.error;let A=he("atom",t.ownerToken);return t.states.add(A),t.atoms.set(A,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...mt(d)})),A},o=(c,d={})=>{if(typeof c!=="function")throw TypeError("atomLazy requires an initializer function");let l=he("atom",t.ownerToken);return t.states.add(l),t.atoms.set(l,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:c}),...mt(d)})),l},r=(c,d={})=>{if(typeof c!=="function")throw TypeError("selector requires a getter function");if(d.equal!==void 0&&typeof d.equal!=="function")throw TypeError("selector equal must be a function");let l=he("selector",t.ownerToken),h=Object.freeze({node:l,get:c,...d.name===void 0?{}:{name:d.name},...d.equal===void 0?{}:{equal:d.equal}});return t.states.add(l),t.selectors.set(l,h),l},i=(c)=>{let d=new y;if(x(t,c,d)==="invalid")return;return t.stores.get(c)},a=Object.freeze({assertStore:(c)=>{let d=i(c);if(D(t,"adapter assertStore"),d===void 0)throw TypeError("assertStore requires a valid Store")},read:(c,d)=>{if(i(c)===void 0)throw De(t,"adapter read"),TypeError("read requires a valid Store");return c.get(d)},subscribe:(c,d,l)=>{if(i(c)===void 0)throw D(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return c.sub(d,l)},readHydrationSnapshot:(c,d)=>{let l=i(c);if(l===void 0)throw D(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return l.coordinator.readHydrationSnapshot(l,d)}});return Object.freeze({atom:n,atomLazy:o,selector:r,adapter:a,createStoreTree:(c=e,d)=>{D(t,"createStoreTree");let l=new At(t,c,d);return new _e(l,l.rootScope,d)}})};var Lt=bt(),ln=(e,t)=>Lt.createStoreTree(e,t);
|
|
2
|
-
export{Z as a,ot as b,Te as c,Oe as d,U as e,q as f,K as g,de as h,J as i,ee as j,te as k,Re as l,Ce as m,Ne as n,le as o,an as p,Lt as q,ln as r};
|