valdres 1.0.0-beta.35 → 1.0.0-beta.36
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 +30 -0
- package/dist/adapter-internals/v1.js +1 -1
- package/dist/chunk-kve4rdec.js +2 -0
- package/dist/development/adapter-internals/v1.js +1 -1
- package/dist/development/chunk-kve4rdec.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/index.d.ts +2 -0
- package/dist/types/v1-internal/committed-store-tree/committed-store-tree.d.ts +11 -1
- package/dist/types/v1-internal/committed-store-tree/runtime-domain.d.ts +23 -4
- package/dist/types/v1-internal/committed-store-tree/scope-node.d.ts +6 -2
- package/dist/types/v1-internal/family.d.ts +38 -0
- package/dist/types/v1-internal/selector-evaluator/types.d.ts +6 -0
- package/dist/types/v1.d.ts +16 -0
- package/package.json +1 -1
- package/dist/chunk-y5ja7h9m.js +0 -2
- package/dist/development/chunk-y5ja7h9m.js +0 -2
package/README.md
CHANGED
|
@@ -32,6 +32,36 @@ A store also exposes `sub`, `reset`, `txn`, `scope`, and `dispose`. Store operat
|
|
|
32
32
|
|
|
33
33
|
`atom(initial, options)` and `atom.lazy(initialize, options)` create writable state. `selector(read, options)` creates synchronous derived state. Atom and selector options accept an inert diagnostic `name` and an `equal(previous, next)` comparator.
|
|
34
34
|
|
|
35
|
+
## Parameterized State identity
|
|
36
|
+
|
|
37
|
+
`family(factory)` memoizes one Atom or Selector per non-empty ordered tuple of primitive keys (`string`, `number`, `bigint`, `boolean`, `symbol`, `null`, or `undefined`). Keys use SameValueZero, so `NaN` matches `NaN` and `0` matches `-0`; tuple arity and order still matter.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { atom, family } from "valdres"
|
|
41
|
+
|
|
42
|
+
const cellValue = family((sheetId: string, row: number) => atom(""))
|
|
43
|
+
cellValue("budget", 4) === cellValue("budget", 4) // true
|
|
44
|
+
|
|
45
|
+
type Step = { readonly id: string; readonly title: string }
|
|
46
|
+
|
|
47
|
+
const stepProgress = family((step: Step) => atom(0), {
|
|
48
|
+
encodeKey: step => step.id,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
stepProgress({ id: "step-1", title: "Draft" }) ===
|
|
52
|
+
stepProgress({ id: "step-1", title: "Review" }) // true
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Structured arguments require a synchronous `encodeKey` that returns one canonical primitive key. The factory must construct and return its Atom or Selector during that member's construction, or return any member already published by a family. Returning an arbitrary pre-existing State is rejected.
|
|
56
|
+
|
|
57
|
+
The exported `FamilyKey` type names the primitive-key union for reusable APIs.
|
|
58
|
+
|
|
59
|
+
Factories and encoders are synchronous definition callbacks, not Store work. Neither may perform Store, scope, transaction, or subscription operations or borrow an active selector's `get`. Encoders also cannot construct State definitions or call a family; factories may do both. A violation throws without caching a member.
|
|
60
|
+
|
|
61
|
+
The family cache is weak. A live reference, a committed Store override for a family Atom, an active subscription, or a retained selector dependency keeps that member alive. Reset or disposal releases Store ownership, and unsubscription releases subscription ownership. After the last owner disappears, a later lookup may run the factory again.
|
|
62
|
+
|
|
63
|
+
A family is only a callable identity cache. It has no membership or enumeration API and no `delete`, `release`, `index`, Store, or collection surface.
|
|
64
|
+
|
|
35
65
|
## Opt-in structural equality
|
|
36
66
|
|
|
37
67
|
`Object.is` remains the default comparator. Import `deepEqual` from the separate equality entry only where structurally equal replacements should retain the previous reference and stop notifications or downstream propagation:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{v as e}from"../chunk-kve4rdec.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 L extends Error{seal(){Object.freeze(this)}}class me extends L{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 xe extends L{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 re extends L{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 W extends L{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 je extends L{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ye extends L{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 Ie extends L{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var C=Symbol(),U=Symbol(),be=Symbol(),tt=Object.freeze({kind:"not-thenable"}),Mt=()=>{},Ft=Reflect.apply,nt=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}class Me extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Fe extends T{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 G extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class Z extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class J extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class Ae extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class ie extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class se extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ae extends T{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class ze extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class _e extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Be extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class ve extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var x=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return tt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):tt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},j=(e)=>{try{Ft(e.then,e.target,[void 0,Mt])}catch{}},de=(e)=>{let t=x(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 j(t),Object.freeze({kind:"error",error:new se})},Ge=(e)=>{try{return de(e())}catch(t){let n=x(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 j(n),Object.freeze({kind:"error",error:new se})}},ce=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},H=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,i=r===void 0?Object.freeze({kind:"guarded-callback",session:t}):Object.freeze({kind:"guarded-callback",session:t,selectorActivity:r});try{let s=ce(e,i,n),a=t.getControlFault();if(a.kind==="fault")throw a.error;return s}catch(s){let a=t.getControlFault();if(a.kind==="fault")throw a.error;throw s}},ot=(e,t,n)=>{try{let o=ce(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}},le=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,i=Object.is(r?.session,t)?r?.parentSelectorActivity:r,s=i===void 0?Object.freeze({kind:"selector",session:t}):Object.freeze({kind:"selector",session:t,parentSelectorActivity:i});return ce(e,s,n)},rt=(e,t,n)=>ce(e,Object.freeze({kind:"transaction",transaction:t}),n),ge=(e,t,n)=>{try{let o=ce(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}},I=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new Z(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new J;throw new G},He=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new Z(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new J;throw new G},it=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new G;throw e.latchControlFault(r),t.latchControlFault(r),r},st=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new Z("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new J;throw new G},ke=(e,t,n)=>{if(!n)throw new Ae;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new Z("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new G;throw new J},at=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},Q=(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,nt);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Me;throw at(e,n).latchControlFault(r),r}}return"invalid"},M=(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=at(e,n);if(o!==void 0&&"session"in o)try{let i=Q(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 H(e,r,()=>Q(e,t,r))},ue=(e,t)=>(Object.defineProperty(e,nt,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),we=(e,t)=>Object.freeze(ue({kind:e},t));var dt=Object.freeze({kind:"not-thenable"}),zt=()=>{},_t=Reflect.apply,ct=Symbol("selector dependency path root"),ft=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return dt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):dt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},ht=(e)=>{try{_t(e.then,e.target,[void 0,zt])}catch{}},Bt=(e)=>Object.freeze(e),Gt=(e)=>Object.freeze(e),E=(e,t,n,o)=>{let r=Gt(o);return Object.freeze({selector:e,token:t,outcome:Bt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Ht:Object.freeze(r.map((i)=>i.node))})},Ht=Object.freeze([]),Re=32,ee=8192,Lt=2*Re,St=128,Wt=4096;class pt{passiveSearches;searches=0;constructor(e,t){if(this.passiveSearches=e,t!==void 0)this.diagnostics=t}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let e=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(e)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(e&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(ee,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,t.has(e))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,n.has(e))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(e){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let n=e.size>=Re&&e.size<=ee,o;if(this.searches===1&&n)this.first=e,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>ee){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=Re&&e.size<=ee;if(this.first===void 0){if(t)this.first=e,this.firstIndependentlyClosed=!0;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,Re),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Lt){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(e){if(!this.enabled||e===void 0)return this.reset(),!1;let t=this.firstIndependentlyClosed===!0?this.first:void 0,n=this.secondIndependentlyClosed===!0?this.second:void 0,o=t===void 0||n!==void 0&&n.size>t.size?n:t;if(o===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(ee,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>ee||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=e,this.firstIndependentlyClosed=t,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,this.secondIndependentlyClosed=t,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}hasWithinCrossVersionBudget(e,t){let n=this.passiveProbeBudget;if(n===void 0||n===0)return;let o=e.has(t);return this.passiveProbeBudget=n-1,o}completeDiagnostics(e,t){let n=this.diagnostics;if(n===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let o=this.mapProbes??0;n.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",e,t,o,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var Ut=(e,t)=>new pt(e,t),q=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=St-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},qt=(e,t,n,o,r,i=!0,s)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let a=n.visitSelectorDependents;if(a===void 0)return"unsupported";if(s===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let m=s===void 0?void 0:o.getTransientDependencies(n,e);if(m!==void 0){if(m.length===0)return"proven-terminal"}else{let p=n.getSelectorDependencyNodes;if(p!==void 0){let A=p.call(n,e);if(A===void 0||A.length===0)return"proven-terminal"}}}if(!i)return"disabled";let d={remaining:St},u=[t],l=new Set(u),f=0,c=0,h=1;while(u.length>0){if(d.remaining===0)return q("budget-exhausted",d,f,c,h,r);d.remaining--,f++;let m=u.pop();if(Object.is(m,e))return q("path-possible",d,f,c,h,r);let p=!1,A=(k)=>{if(c++,Object.is(k,e))return p=!0,!1;if(!l.has(k)){if(l.add(k),u.push(k),u.length>h)h=u.length}return!0},te=a.call(n,m,d,A);if(p)return q("path-possible",d,f,c,h,r);if(!te)return q("budget-exhausted",d,f,c,h,r);let V=s?.get(m);if(V!==void 0)for(let k of V){if(d.remaining===0)return q("budget-exhausted",d,f,c,h,r);if(d.remaining--,!A(k))return q("path-possible",d,f,c,h,r)}}return q("proven-reverse",d,f,c,h,r)},Yt=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let c=qt(e,t,n,o,void 0,r===1?s?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(c==="proven-terminal"||c==="proven-reverse")return;if(c==="budget-exhausted"){if(r===1&&s!==void 0)s.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=s?.(),u=d?.beginSearch()??!1,l=[e],f=new Map([[e,ct]]);while(l.length>0){let c=l.pop();if(Object.is(c,t)){let p=[],A=c;while(A!==ct)p.push(A),A=f.get(A);return p.reverse(),d?.completePositive(),Object.freeze(p)}let h=o.getTransientDependencies(n,c);if(h){if(h.length===0)continue;if(u){let p=d.hasProvenNoPath(c);if(!d.enabled)u=!1;if(p)continue}for(let p of h){if(f.has(p.node))continue;f.set(p.node,c),l.push(p.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let p=n.getSelectorDependencyNodes(c);if(p===void 0||p.length===0)continue;if(u){let A=d.hasProvenNoPath(c);if(!d.enabled)u=!1;if(A)continue}for(let A of p){if(f.has(A))continue;f.set(A,c),l.push(A)}continue}let m=n.getSelectorRecord(c);if(!m||m.dependencies.length===0)continue;if(u){let p=d.hasProvenNoPath(c);if(!d.enabled)u=!1;if(p)continue}for(let p of m.dependencies){if(f.has(p.node))continue;f.set(p.node,c),l.push(p.node)}}d?.completeNegative(f);return},lt=(e,t)=>{let n=ft(e);if(n.kind==="thenable")return ht(n),new W(t);if(n.kind==="inspection-error")return n.error;return e},ut=(e,t)=>{let n=ft(e);if(n.kind==="thenable")return ht(n),Object.freeze({kind:"error",error:new W(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},mt=(e,t,n,o=Yt,r,i)=>{let{node:s}=e,a=[],d=t.getSelectorRecord(s),u=d?.dependencies,l=u===void 0?new Set:void 0,f,c=0,h=t.getComparisonBaseline(s),m=!0,p=()=>{let S=l;if(S!==void 0)return S;S=new Set;for(let y of a)S.add(y.node);return l=S,S};n.enter(t,s,a);let A=t.getSelectorGraphVersion(),te=n.getSelectorGraphPublicationCount(t),V=A,k=te,Qe=A,$e=te,Ne,Ce=!1,Ee=A,he=0,Y,Ze=A,Se,De=(S,y)=>{if(S===Ee)return;if(Ee=S,Y===void 0){he=0;return}if(Y.advanceGraphVersion(y))return;he=0,r?.graphVersionReset()},xt=(S)=>{if(S!==Ee)De(S,void 0);if(he++,(u?.length??0)===0&&he<3){r?.admissionSkipped();return}if(Y===void 0){let y=u!==void 0&&u.length>0&&u.length<3;Y=Ut(y?3:0,r)}if(!Y.enabled){r?.disabled();return}return Y},jt=(S)=>{if(Ce)return;let y=t.beginSelectorGraphObservation?.(S);if(y===void 0)return;Ce=!0,Ne=y},Ve=(S,y,w,g)=>w-S===g-y,Je=(S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t),w=Ve(V,k,S,y))=>{if(S===V)return;if(!Ce&&t.beginSelectorGraphObservation!==void 0){De(S,void 0),V=S,k=y;return}let g=Ne?.takeAddedEdges();if(De(S,g),w){V=S,k=y;return}if(g!==void 0){let O=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,Wt,i),P=g.length===0?void 0:{transientDependents:O,reverseProofEnabled:!0},R=!1;for(let _ of g)if(o(_.head,_.tail,t,n,2,a.length,void 0,P)!==void 0){R=!0;break}if(!R){V=S,k=y;return}}for(let O=0;O<a.length;O++){let P=a[O],R=o(P.node,s,t,n,0,a.length);if(!R)continue;if(l!==void 0)for(let F=a.length-1;F>=O;F--)l.delete(a[F].node);if(a.length=O,c++,n.getControlFault().kind==="fault")return;let N=new re(s,[s,...R]);n.latchCycle(t,s,N);return}V=S,k=y},Pe=()=>{let S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t);Qe=S,$e=y;let w=Ve(V,k,S,y);if(!w)n.revalidateAncestorPrefixes(t,s);Je(S,y,w)};n.setPrefixRevalidator(t,s,Je);let It=(S)=>{if(!m)throw new Ie;let y=n.getControlFaultForSuppliedRead();if(y.kind==="fault")throw y.error;let w=n.getCycle(t,s);if(w!==void 0)throw w;let g=n.activeCyclePath(t,S);if(g){let v=new re(s,g);throw n.latchCycle(t,s,v),v}let O=a.length,P,R=!1;if(l===void 0){let v=u?.[O];if(v!==void 0&&Object.is(v.node,S))P=!1,R=!0;else P=p().has(S)}else P=l.has(S);if(!P&&!R&&u!==void 0&&u.length>0){let v=u[a.length];if(v!==void 0&&Object.is(v.node,S))R=!0;else{if(f===void 0){f=new Set;for(let X of u)f.add(X.node)}R=f.has(S)}}let _=c,N=t.serve(S,n);Pe();let F=n.getCycle(t,s);if(F!==void 0)throw F;let ne=l!==void 0?l.has(S):c===_&&a.length===O?!1:p().has(S),B=Qe,K=$e,z=ne||R&&B===A,pe=u===void 0&&Ve(A,te,B,K);if(!z&&!pe){if(Ze=B,Se===void 0)Se=()=>xt(Ze),Se.reverseProofEnabled=!0;let v=o(S,s,t,n,1,a.length,Se);if(v){let X=n.getControlFault();if(X.kind==="fault")throw X.error;let et=new re(s,[s,...v]);throw n.latchCycle(t,s,et),et}}if(!ne){let v=d?.dependencies[a.length];l?.add(S),a.push(v!==void 0&&Object.is(v.node,S)&&Object.is(v.token,N.token)?v:Object.freeze({node:S,token:N.token})),jt(S)}if(V=B,k=K,N.outcome.kind==="control-error"){n.latchControlFault(N.outcome.error);let v=n.getControlFault();if(v.kind==="fault")throw v.error;throw N.outcome.error}let oe=n.getControlFault();if(oe.kind==="fault")throw oe.error;if(N.outcome.kind==="error")throw new xe(S,N.outcome.error);return N.outcome.value};try{let S,y,w=!1;try{S=e.get(It)}catch(F){w=!0,y=F}finally{m=!1}if(w)y=lt(y,"getter");let g=w?void 0:ut(S,"getter");Pe();let O=n.getControlFault();if(O.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:O.error},a);let P=n.getCycle(t,s);if(P!==void 0)return E(s,t.createOutcomeToken(),{kind:"error",error:P},a);if(w)return E(s,t.createOutcomeToken(),{kind:"error",error:y instanceof W?y:new me(s,y)},a);if(g===void 0)throw Error("Selector result classification was not completed");let R=n.getControlFault();if(R.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:R.error},a);if(g.kind==="error")return E(s,t.createOutcomeToken(),{kind:"error",error:g.error instanceof W?g.error:new me(s,g.error)},a);let _=g.value,N;if(h){let F=e.equal??Object.is,ne,B,K=!1;try{ne=F(h.value,_)}catch(X){K=!0,B=lt(X,"comparator")}let z=K?void 0:ut(ne,"comparator");Pe();let pe=n.getControlFault();if(pe.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:pe.error},a);let oe=n.getCycle(t,s);if(oe!==void 0)return E(s,t.createOutcomeToken(),{kind:"error",error:oe},a);if(K)return E(s,t.createOutcomeToken(),{kind:"error",error:B instanceof W?B:new ye(s,B)},a);if(z===void 0)throw Error("Selector comparator classification was not completed");let v=n.getControlFault();if(v.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:v.error},a);if(z.kind==="error")return E(s,t.createOutcomeToken(),{kind:"error",error:z.error instanceof W?z.error:new ye(s,z.error)},a);if(z.value!==!0&&z.value!==!1)return E(s,t.createOutcomeToken(),{kind:"error",error:new je},a);if(z.value===!0)_=h.value,N=h.current?h.token:void 0}return E(s,N??t.createOutcomeToken(),{kind:"value",value:_},a)}finally{try{Ne?.close()}finally{n.leave(t,s)}}};class b{#t=[];#n;#o=0;#s;#a=Kt;#r;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}setSuppliedReadGuard(e){let t=this.#r;return this.#r=e,t}getControlFaultForSuppliedRead(){return this.#r?.(),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.#s??(this.#s=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#s?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#t){if(!Object.is(o.host,e))continue;if(n||!Object.is(o.selector,t))return!1;n=!0}return n}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#i(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#i(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}captureTransientReverseDependents(e,t,n,o,r){let i=new Set,s=new Map,a=!1,d=0,u=0,l=0;for(let c of this.#t){if(d++,d>o){r?.recordSnapshot("overflow",d,u,l);return}if(!Object.is(c.host,e))continue;if(u++,c.revalidatePrefix===void 0||i.has(c.selector)){r?.recordSnapshot("unavailable",d,u,l);return}if(i.add(c.selector),Object.is(c.selector,t)){if(a||c.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,u,l);return}a=!0}for(let h of c.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,u,l);return}let m=s.get(h.node);if(m===void 0)s.set(h.node,[c.selector]);else m.push(c.selector)}}if(!a){r?.recordSnapshot("unavailable",d,u,l);return}let f=new Map;for(let[c,h]of s)f.set(c,Object.freeze(h));return r?.recordSnapshot("completed",d,u,l),f}latchCycle(e,t,n){let o=this.#d(e,t);o.cycleError??=n}getCycle(e,t){return this.#i(e,t).cycleError}#i(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}#d(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var Kt=Object.freeze({kind:"none"});var yt=Symbol("no-committed-selector-baseline");class Te{#t;#n=new Map;#o=new Map;#s=new Map;#a;#r=1;#i=0;#d;constructor(e,t,n){this.#t=e,this.#a=t,this.#d=n}readSelector(e){let t=new b,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.#s.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 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.#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.#i++,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.#i}getComparisonBaseline(e){let t=this.#s.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??yt,this.#s.set(e,t);return t===yt?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 bt=4096,Xt=Object.freeze([]);class vt{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Oe{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;[C]=void 0;#t=new WeakMap;#n;#o=new WeakMap;#s;#a=new WeakMap;#r=new WeakSet;#i=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.#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((t)=>{this.detachAtomView(t),t.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap;let e=this[C]?.size??0;if(e>0)this.coordinator.recordCounter("familyOwnerReleases",e);this[C]=void 0,this.#t=new WeakMap,this.#o=new WeakMap,this.#s=void 0,this.#a=new WeakMap,this.#r=new WeakSet,this.#i++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(Q(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=le(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#b(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#s?.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.#s;if(i===void 0)i=new WeakMap,this.#s=i;i.set(n,o)}return o}visitSelectorDependents(e,t,n){return this.#a.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#i}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 Xt;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()}#b(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess}),s=this.#y(e,o?.dependencies??At,t.dependencies),a=s?this.#S(e,o?.dependencies??At,t.dependencies):void 0;if(s)this.#s?.delete(e);if(this.#i++,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.#d===0||this.#l)return;let o=this.#c;if(o===void 0){this.#e();return}let r=bt-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.#c;if(t===void 0||t.length+e.length>bt){this.#e();return}t.push(...e)}#e(){if(this.#d===0)return;this.#c=[],this.#l=!0}#m(){return new vt(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var At=Object.freeze([]);class Le{transaction=Object.freeze({});#t;#n;#o;#s;#a;#r;#i;#d;#c;#l;#h;#u;#b;#y;#S;#p;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#s!==void 0||this.#a!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#s===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.#s;if(i===void 0){this.#s=t,this.#m();return}if(Object.is(i.atom,t.atom)){this.#s=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.#s!==void 0)s.set(this.#s.atom,this.#s);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.#s=void 0,this.#m()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#s!==void 0)e(this.#n,this.#s);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.#s;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.#i,e)&&Object.is(this.#d,t))return this.#c;if(this.#h!==void 0&&Object.is(this.#i,e)&&Object.is(this.#l,t))return this.#h;if(Object.is(this.#i,e))return this.#u?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#f(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#i,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#i,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#b=s,this.#u=void 0,this.#i=void 0}return}let i=this.#c;if(i===void 0){this.#i=e,this.#d=t,this.#c=n;return}if(Object.is(this.#i,e)&&Object.is(this.#d,t))return;if(Object.is(this.#i,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.#i,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#b=s,this.#i=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.#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.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#s=void 0,this.#a=void 0,this.#r=void 0,this.#i=void 0,this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#h=void 0,this.#u=void 0,this.#b=void 0,this.#y=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class gt{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]),ue(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var We=(e,t,n)=>new gt(e,t,n),Ue=(e)=>{let t=x(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw j(t),new ie},kt=(e)=>{let t=x(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw j(t),new ie};var Qt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},fe=Symbol("definition domain records"),kn=(e,t,n,o,r)=>{let i=e[fe],s=new b,a=i.activity,d=a?.kind==="selector"?a:a?.kind==="guarded-callback"?a.selectorActivity:void 0,u=[];while(d!==void 0){let c=d.session;if(!u.includes(c))u.push(c);d=d.parentSelectorActivity}let l=i[U];i[U]={session:s,definitions:new WeakSet,allowDefinitions:t==="factory"};let f=u.map((c)=>Object.freeze({selectorSession:c,previous:c.setSuppliedReadGuard(()=>{let h=i.activity;return it(h?.kind==="guarded-callback"?h.session:s,c)})}));try{return H(i,s,()=>{let c=Reflect.apply(n,void 0,o);return r===void 0?c:r(c)})}finally{for(let c=f.length-1;c>=0;c--){let h=f[c];h.selectorSession.setSuppliedReadGuard(h.previous)}if(l===void 0)delete i[U];else i[U]=l}},wn=(e)=>{let t=e[fe][U];if(t===void 0||t.allowDefinitions)return;let n=new G;throw t.session.latchControlFault(n),n},Rn=(e,t)=>{let n=e[fe];if((typeof t==="object"||typeof t==="function")&&t!==null&&n.states.has(t)){if(n[U]?.definitions.has(t)||n[be]?.has(t))return t;return}M(n,t,new b);return},Tn=(e,t)=>{let n=e[fe];if((n[be]??(n[be]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[C]??(n[C]=new WeakSet)).add(t)},Et=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,familyOwnerRetentionSetsCreated:32,familyOwnerRetains:33,familyOwnerReleases:34}),$t=35,Dt=new WeakMap,On=()=>{let e=new Uint32Array($t),t=Object.freeze({read(n){return e[Et[n]]??0}});return Dt.set(t,e),t},D=(e)=>Object.freeze({kind:"value",value:e}),Zt=(e)=>Object.freeze({kind:"error",error:e}),wt=(e)=>e.kind==="value"?D(e.value):Zt(e.error),Rt=(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)},Tt=1,qe=2,Ot=4,Jt=(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}),Ke=(e)=>(e.onAllocation?.(),new Map),en=(e)=>(e.onAllocation?.(),new Set),Ye=(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)},Nt=(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=Ke(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=Ke(e),r.set(t,i);i.set(n,o)},tn=(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=en(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},nn=(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=Ke(e),e.affected=o;o.set(t,n)};class Vt{#t=new WeakMap;#n;#o=1;#s=0;#a=!1;#r;#i;#d;#c=0;#l;#h;#u;#b=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:Dt.get(t),this.#f=n,this.evaluate=n?.evaluate??mt,this.#n=new Oe(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[Et[e]]+=t}#R(){return this.recordCounter("draftCreations"),new Le(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new b,o=t,r=M(this.#e,o,n),i=He(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":M(this.#e,o,r=new b);if(I(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new b);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 u=d.get(o);if(u===void 0){if(u={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,u),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:u,previous:u.tail,next:void 0};if(u.tail===void 0)u.head=l;else u.tail.next=l;if(u.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return Qt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;st(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.#T(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#T(e,t,"StoreTree.update","update",n)}reset(e,t){this.#T(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)M(this.#e,n,new b);if(I(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#P(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#P(e,n)}dispose(e){if(I(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#Q(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(I(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#R(),r=We(this,o,e),i;try{i=rt(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new b;ge(this.#e,s,()=>Ue(i)),this.#z(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new b,o=t,r=M(this.#e,o,n);if(I(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#R(),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.#Y(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 b,i=M(this.#e,o,r);if(ke(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#v(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new b;this.#O(e,t,r,i,"Transaction.set"),this.#j(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new b;this.#O(e,t,r,i,"Transaction.update"),this.#I(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new b;this.#O(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new b;if(typeof n!=="string")M(this.#e,n,i);ke(this.#e,e.transaction,e.active),this.#A(t);let s=this.#K(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=We(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 f=new b;return ge(this.#e,f,()=>kt(l))}let u=new b;return ge(this.#e,u,()=>Ue(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new Te(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)=>le(this.#e,n,o)}),e.generation,this.evaluate)}#Y(e,t){return this.recordCounter("scratchHostAllocations"),new Te(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>le(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(Q(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#P(e,t){let n=new Oe(this,e,t);this.recordCounter("scopeNodesCreated");let o=new Xe(this,n,this.#f);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#K(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new _e;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new Be;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new Ae;throw new ve}throw new ve}#A(e){if(e.status!=="live")throw new ze}#X(e,t,n,o){let r=M(this.#e,t,n);I(this.#e,o),this.#A(e),this.#x(t,r,o)}#T(e,t,n,o,r){let i=t,s=new b;this.#X(e,i,s,n);let a=this.#R();try{if(o==="set")this.#j(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#M(a,e,i,s)}catch(d){throw a.close(),a.release(),d}a.close();try{this.#z(a)}finally{a.release()}}#Q(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)}#O(e,t,n,o,r){let i=M(this.#e,n,o);ke(this.#e,e.transaction,e.active),this.#A(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#j(e,t,n,o,r){let i=H(this.#e,r,()=>de(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.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#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=D(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,u=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,u),u}#v(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:D(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:D(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 D(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=wt(H(this.#e,n,()=>Ge(i)));return e.setFallback(t,a),a}#$(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 H(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=x(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw j(a),new ae}let i=x(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw j(i),new ae;if(r!==!0&&r!==!1)throw new ae;return r})}#J(e,t,n){return H(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=x(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw j(s),new se}let r=de(o);if(r.kind==="error")throw r.error;return r.value})}#z(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=Jt(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 u=this.#_(e,a,d,o);if(r===void 0){r=u;return}if(i===void 0)i=[];i.push(u)});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.#G(r);if(i!==void 0)for(let a of i){let d=this.#G(a);s||=d}if(this.#H(r),i!==void 0)for(let a of i)this.#H(a);this.#se();try{let a,d,u=o.affectedRecord,l=o.affectedBefore;if(u!==void 0&&l!==void 0)a=this.#E(o,u,l);let{secondAffectedRecord:f,secondAffectedBefore:c}=o;if(f!==void 0&&c!==void 0){let h=this.#E(o,f,c);if(h!==void 0)if(a===void 0)a=h;else d=[h]}if(o.affected!==void 0)for(let[h,m]of o.affected){let p=this.#E(o,h,m);if(p===void 0)continue;if(a===void 0)a=p;else{if(d===void 0)d=[];d.push(p)}}if(s)this.#s+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(d?.length??0)),this.#ie(a,d)}catch(a){throw this.#k(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#B(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#G(e){let{intent:t,scope:n}=e;if(t.kind==="set"){if(n.atomOverrides.set(t.atom,t.value),this.#e[C]?.has(t.atom)){let o=n[C];if(o===void 0)o=new Set,n[C]=o,this.recordCounter("familyOwnerRetentionSetsCreated");let r=o.size;if(o.add(t.atom),o.size!==r)this.recordCounter("familyOwnerRetains")}}else{n.atomOverrides.delete(t.atom);let o=n[C];if(o?.delete(t.atom))this.recordCounter("familyOwnerReleases");if(o?.size===0)n[C]=void 0}return e.ownershipChanged}#H({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=Ye(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),Rt(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(!tn(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(Rt(i,s))continue;nn(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),o.push(d)});for(let d=a,u=o.length-1;d<u;d++,u--){let l=o[d];o[d]=o[u],o[u]=l}}}#L(e,t,n,o){let r=Ye(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let u=Ye(o,n,i);if(u!==void 0){d=u;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=D(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=D(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)Nt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let u of a)Nt(o,n,u,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 D(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 D(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,D(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,D(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 D(o.fallback.value);let r=o.fallback.initialize,i=wt(H(this.#e,t,()=>Ge(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.#i=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.#i=void 0,this.#d=void 0,this.#c=0,this.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#p=void 0,this.#y=this.#u===void 0?0:this.#b++}#k(){this.#y=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#y,o=this.#u?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#p===void 0)this.#p=[o];else this.#p.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#k(),e!==void 0)throw e;return}let n,o,r=(u)=>{let l=u.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let u of i)r(u);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 u of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new b,f=!1,c;try{ot(this.#e,l,()=>{try{let h=u(),m=x(h);if(m.kind==="thenable")j(m);else if(m.kind==="inspection-error")f=!0,c=m.error}catch(h){f=!0,c=h;let m=x(h);if(m.kind==="thenable")j(m)}})}catch(h){f=!0,c=h}if(f){if(d===void 0)d=[];if(d.push(c),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Fe(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&Tt)!==0)return!0;return this.#w(e,t,Tt),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)&(Ot|qe))!==0)return;this.#w(e,t,qe);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 b)}this.#w(e,t,Ot)}finally{this.#w(e,t,0,qe)}}#W(e,t){if(Object.is(this.#i,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.#i===void 0){this.#i=e,this.#d=t,this.#c=n&~o;return}if(Object.is(this.#i,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.#$(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class Xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t,n){this.get=(o)=>e.get(t,o),this.sub=(o,r)=>e.sub(t,o,r),this.set=(o,r)=>e.set(t,o,r),this.update=(o,r)=>e.update(t,o,r),this.reset=(o)=>e.reset(t,o),this.txn=(o,r)=>e.txn(t,o,r),this.scope=function(o){return e.scope(t,arguments.length,o)},this.dispose=()=>e.dispose(t),t.installFacade(this),ue(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var Ct=(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}}},Pt=(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=(l)=>{let f=t[U];if(f===void 0)return;if(!f.allowDefinitions){let c=new G;throw f.session.latchControlFault(c),c}f.definitions.add(l)},o=(l,f={})=>{let c=new b,h=H(t,c,()=>de(l));if(h.kind==="error")throw h.error;let m=we("atom",t.ownerToken);return n(m),t.states.add(m),t.atoms.set(m,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...Ct(f)})),m},r=(l,f={})=>{if(typeof l!=="function")throw TypeError("atomLazy requires an initializer function");let c=we("atom",t.ownerToken);return n(c),t.states.add(c),t.atoms.set(c,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:l}),...Ct(f)})),c},i=(l,f={})=>{if(typeof l!=="function")throw TypeError("selector requires a getter function");if(f.equal!==void 0&&typeof f.equal!=="function")throw TypeError("selector equal must be a function");let c=we("selector",t.ownerToken);n(c);let h=Object.freeze({node:c,get:l,...f.name===void 0?{}:{name:f.name},...f.equal===void 0?{}:{equal:f.equal}});return t.states.add(c),t.selectors.set(c,h),c},s=(l)=>{let f=new b;if(M(t,l,f)==="invalid")return;return t.stores.get(l)},d=Object.freeze({assertStore:(l)=>{let f=s(l);if(I(t,"adapter assertStore"),f===void 0)throw TypeError("assertStore requires a valid Store")},read:(l,f)=>{if(s(l)===void 0)throw He(t,"adapter read"),TypeError("read requires a valid Store");return l.get(f)},subscribe:(l,f,c)=>{if(s(l)===void 0)throw I(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return l.sub(f,c)},readHydrationSnapshot:(l,f)=>{let c=s(l);if(c===void 0)throw I(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return c.coordinator.readHydrationSnapshot(c,f)}});return Object.freeze({[fe]:t,atom:o,atomLazy:r,selector:i,adapter:d,createStoreTree:(l=e,f)=>{I(t,"createStoreTree");let c=new Vt(t,l,f);return new Xe(c,c.rootScope,f)}})};var on=Pt(),En=(e,t)=>on.createStoreTree(e,t);
|
|
2
|
+
export{re as a,qt as b,mt as c,Me as d,Fe as e,G as f,Z as g,J as h,Ae as i,ie as j,se as k,ae as l,ze as m,_e as n,Be as o,ve as p,kn as q,wn as r,Rn as s,Tn as t,On as u,on as v,En as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{v as e}from"../chunk-kve4rdec.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 L extends Error{seal(){Object.freeze(this)}}class me extends L{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 xe extends L{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 re extends L{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 W extends L{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 je extends L{code="VALDRES_INVALID_SELECTOR_COMPARATOR_RESULT";constructor(){super("Selector comparator must return exactly true or false");this.name="InvalidSelectorComparatorResultError",this.seal()}}class ye extends L{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 Ie extends L{code="VALDRES_SELECTOR_READ_REVOKED";constructor(){super("Selector supplied get is no longer active");this.name="SelectorReadRevokedError",this.seal()}}var C=Symbol(),U=Symbol(),be=Symbol(),tt=Object.freeze({kind:"not-thenable"}),Mt=()=>{},Ft=Reflect.apply,nt=Symbol.for("valdres.runtime-owner/v1");class T extends Error{seal(){Object.freeze(this)}}class Me extends T{code="VALDRES_RUNTIME_MISMATCH";constructor(){super("Valdres handles belong to a different runtime domain");this.name="RuntimeMismatchError",this.seal()}}class Fe extends T{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 G extends T{code="VALDRES_CALLBACK_CAPABILITY";constructor(){super("This callback cannot use captured Valdres runtime capabilities");this.name="CallbackCapabilityError",this.seal()}}class Z extends T{code="VALDRES_SELECTOR_CAPABILITY_ERROR";constructor(e){super(`A selector callback cannot call ${e} directly`);this.name="SelectorCapabilityError",this.seal()}}class J extends T{code="VALDRES_TRANSACTION_PHASE";constructor(){super("Captured StoreTree work is forbidden during a transaction");this.name="TransactionPhaseError",this.seal()}}class Ae extends T{code="VALDRES_TRANSACTION_CLOSED";constructor(){super("The Transaction cursor is no longer active");this.name="TransactionClosedError",this.seal()}}class ie extends T{code="VALDRES_INVALID_TRANSACTION_CALLBACK_RESULT";constructor(){super("Transaction callbacks must return synchronously");this.name="InvalidTransactionCallbackResultError",this.seal()}}class se extends T{code="VALDRES_INVALID_SYNCHRONOUS_ATOM_VALUE";constructor(){super("Atom values and lazy initializers must be synchronous");this.name="InvalidSynchronousAtomValueError",this.seal()}}class ae extends T{code="VALDRES_INVALID_ATOM_COMPARATOR_RESULT";constructor(){super("Atom comparators must return exactly true or false synchronously");this.name="InvalidAtomComparatorResultError",this.seal()}}class ze extends T{code="VALDRES_STORE_DISPOSED";constructor(){super("This Store has been disposed");this.name="StoreDisposedError",this.seal()}}class _e extends T{code="VALDRES_SCOPE_NOT_FOUND";constructor(){super("The named child Store does not exist");this.name="ScopeNotFoundError",this.seal()}}class Be extends T{code="VALDRES_STORE_TREE_MISMATCH";constructor(){super("The Store belongs to a different StoreTree");this.name="StoreTreeMismatchError",this.seal()}}class ve extends T{code="VALDRES_INVALID_TRANSACTION_TARGET";constructor(){super("Transaction.scope requires a Store or named child");this.name="InvalidTransactionTargetError",this.seal()}}var x=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return tt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):tt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},j=(e)=>{try{Ft(e.then,e.target,[void 0,Mt])}catch{}},de=(e)=>{let t=x(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 j(t),Object.freeze({kind:"error",error:new se})},Ge=(e)=>{try{return de(e())}catch(t){let n=x(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 j(n),Object.freeze({kind:"error",error:new se})}},ce=(e,t,n)=>{let o=e.activity;e.activity=t;try{return n()}finally{e.activity=o}},H=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,i=r===void 0?Object.freeze({kind:"guarded-callback",session:t}):Object.freeze({kind:"guarded-callback",session:t,selectorActivity:r});try{let s=ce(e,i,n),a=t.getControlFault();if(a.kind==="fault")throw a.error;return s}catch(s){let a=t.getControlFault();if(a.kind==="fault")throw a.error;throw s}},ot=(e,t,n)=>{try{let o=ce(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}},le=(e,t,n)=>{let o=e.activity,r=o?.kind==="selector"?o:o?.kind==="guarded-callback"?o.selectorActivity:void 0,i=Object.is(r?.session,t)?r?.parentSelectorActivity:r,s=i===void 0?Object.freeze({kind:"selector",session:t}):Object.freeze({kind:"selector",session:t,parentSelectorActivity:i});return ce(e,s,n)},rt=(e,t,n)=>ce(e,Object.freeze({kind:"transaction",transaction:t}),n),ge=(e,t,n)=>{try{let o=ce(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}},I=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="selector")throw new Z(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new J;throw new G},He=(e,t)=>{let n=e.activity;if(n===void 0)return;if(n.kind==="subscriber")return n.session;if(n.kind==="selector")throw new Z(t);if(n.kind==="transaction"||n.kind==="transaction-result")throw new J;throw new G},it=(e,t)=>{let n=t.getControlFault(),o=e.getControlFault(),r=n.kind==="fault"?n.error:o.kind==="fault"?o.error:new G;throw e.latchControlFault(r),t.latchControlFault(r),r},st=(e)=>{let t=e.activity;if(t===void 0||t.kind==="subscriber")return;if(t.kind==="selector")throw new Z("Store unsubscribe");if(t.kind==="transaction"||t.kind==="transaction-result")throw new J;throw new G},ke=(e,t,n)=>{if(!n)throw new Ae;let o=e.activity;if(o?.kind==="transaction"&&Object.is(o.transaction,t))return;if(o?.kind==="selector")throw new Z("Transaction cursor operation");if(o?.kind==="guarded-callback")throw new G;throw new J},at=(e,t)=>{let n=e.activity;return n!==void 0&&"session"in n?n.session:t},Q=(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,nt);if(o!==void 0&&"value"in o&&!Object.is(o.value,e.ownerToken)){let r=new Me;throw at(e,n).latchControlFault(r),r}}return"invalid"},M=(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=at(e,n);if(o!==void 0&&"session"in o)try{let i=Q(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 H(e,r,()=>Q(e,t,r))},ue=(e,t)=>(Object.defineProperty(e,nt,{value:t,enumerable:!1,writable:!1,configurable:!1}),e),we=(e,t)=>Object.freeze(ue({kind:e},t));var dt=Object.freeze({kind:"not-thenable"}),zt=()=>{},_t=Reflect.apply,ct=Symbol("selector dependency path root"),ft=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return dt;try{let t=e.then;return typeof t==="function"?Object.freeze({kind:"thenable",target:e,then:t}):dt}catch(t){return Object.freeze({kind:"inspection-error",error:t})}},ht=(e)=>{try{_t(e.then,e.target,[void 0,zt])}catch{}},Bt=(e)=>Object.freeze(e),Gt=(e)=>Object.freeze(e),E=(e,t,n,o)=>{let r=Gt(o);return Object.freeze({selector:e,token:t,outcome:Bt(n),dependencies:r,attemptedPrefix:n.kind==="value"?Ht:Object.freeze(r.map((i)=>i.node))})},Ht=Object.freeze([]),Re=32,ee=8192,Lt=2*Re,St=128,Wt=4096;class pt{passiveSearches;searches=0;constructor(e,t){if(this.passiveSearches=e,t!==void 0)this.diagnostics=t}get enabled(){return this.disabled!==!0}beginSearch(){if(this.searches++,this.diagnostics!==void 0)this.diagnosticsCompleted=!1,this.mapProbes=0,this.prunedNodes=0;let e=this.enabled&&this.searches>this.passiveSearches&&this.first!==void 0;if(e)this.consultCurrentSearch=!0,this.hits=0;else if(this.consultCurrentSearch===!0)this.consultCurrentSearch=void 0;if(e&&this.passiveOrigin===!0&&this.searches===this.passiveSearches+1&&this.passiveProbeBudget===void 0)this.passiveProbeBudget=Math.min(ee,2*this.first.size);return e}hasProvenNoPath(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(t.has(e))return this.hits=(this.hits??0)|1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(n.has(e))return this.hits=(this.hits??0)|2,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}hasProvenNoPathMeasured(e){if(!this.enabled)return!1;let t=this.first;if(t!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,t.has(e))return this.hits=(this.hits??0)|1,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}let n=this.second;if(n!==void 0){let o=this.passiveProbeBudget;if(o===0)return this.disable("passive-probe-budget"),!1;if(this.mapProbes=(this.mapProbes??0)+1,n.has(e))return this.hits=(this.hits??0)|2,this.prunedNodes=(this.prunedNodes??0)+1,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,!0;if(o!==void 0){if(this.passiveProbeBudget=o-1,o===1)return this.disable("passive-probe-budget"),!1}}return!1}completeNegative(e){if(!this.enabled)return;if(this.searches<=this.passiveSearches){let n=e.size>=Re&&e.size<=ee,o;if(this.searches===1&&n)this.first=e,this.firstIndependentlyClosed=!0,this.passiveOrigin=!0,o="initial";else if(this.searches===this.passiveSearches&&n)o=this.first===void 0?"initial":"activation-replacement",this.first=e,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0;this.completeDiagnostics(o);return}if((this.hits??0)!==0){if(e.size>ee){this.disable("over-cap-hit");return}let n=this.first,o=this.second,r=this.firstIndependentlyClosed===!0,i=this.secondIndependentlyClosed===!0;this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.retain(n,r),this.retain(o,i);let s=this.retain(e,!1);this.locked=!0,this.missWork=0,this.completeDiagnostics(s?"hit-derived":void 0);return}if(e.size===1){this.completeDiagnostics();return}let t=e.size>=Re&&e.size<=ee;if(this.first===void 0){if(t)this.first=e,this.firstIndependentlyClosed=!0;this.completeDiagnostics(t?"initial":void 0);return}if(this.missWork=(this.missWork??0)+Math.min(e.size,Re),this.locked!==!0&&this.second===void 0&&t){this.second=e,this.secondIndependentlyClosed=!0,this.completeDiagnostics("secondary");return}if((this.missWork??0)>=Lt){this.disable("miss-budget");return}this.completeDiagnostics()}completePositive(){this.completeDiagnostics()}advanceGraphVersion(e){if(!this.enabled||e===void 0)return this.reset(),!1;let t=this.firstIndependentlyClosed===!0?this.first:void 0,n=this.secondIndependentlyClosed===!0?this.second:void 0,o=t===void 0||n!==void 0&&n.size>t.size?n:t;if(o===void 0)return this.reset(),!1;if(this.passiveProbeBudget===void 0)this.passiveOrigin=!0,this.passiveProbeBudget=Math.min(ee,2*o.size);let r=0;for(let i of e){let s=this.hasWithinCrossVersionBudget(o,i.tail);if(s===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!s)continue;let a=this.hasWithinCrossVersionBudget(o,i.head);if(a===void 0)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1;if(r++,!a)return this.diagnostics?.recordMapProbes?.(r),this.reset(),!1}if(this.diagnostics?.recordMapProbes?.(r),this.passiveProbeBudget===0)return this.reset(),!1;return this.first=o,this.firstIndependentlyClosed=!0,this.second=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.consultCurrentSearch=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0,!0}reset(){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.hits=void 0,this.missWork=void 0,this.locked=void 0,this.disabled=void 0,this.searches=0,this.consultCurrentSearch=void 0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.diagnosticsCompleted=void 0,this.mapProbes=void 0,this.prunedNodes=void 0}retain(e,t=!1){if(e===void 0||e.size>ee||e===this.first)return!1;if(this.first===void 0||e.size>this.first.size)return this.second=this.first,this.secondIndependentlyClosed=this.firstIndependentlyClosed,this.first=e,this.firstIndependentlyClosed=t,!0;if(this.second===void 0||e.size>this.second.size)return this.second=e,this.secondIndependentlyClosed=t,!0;return!1}disable(e){this.first=void 0,this.second=void 0,this.firstIndependentlyClosed=void 0,this.secondIndependentlyClosed=void 0,this.missWork=void 0,this.disabled=!0,this.passiveOrigin=void 0,this.passiveProbeBudget=void 0,this.completeDiagnostics(void 0,e)}hasWithinCrossVersionBudget(e,t){let n=this.passiveProbeBudget;if(n===void 0||n===0)return;let o=e.has(t);return this.passiveProbeBudget=n-1,o}completeDiagnostics(e,t){let n=this.diagnostics;if(n===void 0||this.diagnosticsCompleted===!0)return;this.diagnosticsCompleted=!0;let o=this.mapProbes??0;n.completeSearch(this.consultCurrentSearch===!0?(this.hits??0)!==0?"consulted-pruned":"consulted-no-prune":"observing",e,t,o,this.prunedNodes??0,(this.first?.size??0)+(this.second?.size??0))}}var Ut=(e,t)=>new pt(e,t),q=(e,t,n,o,r,i)=>{if(i!==void 0)i.nodeVisits=n,i.dependentProbes=St-t.remaining-n,i.liveDependents=o,i.maxFrontier=r;return e},qt=(e,t,n,o,r,i=!0,s)=>{if(r!==void 0)r.nodeVisits=0,r.dependentProbes=0,r.liveDependents=0,r.maxFrontier=0;let a=n.visitSelectorDependents;if(a===void 0)return"unsupported";if(s===void 0&&!o.isSoleActiveSelector(n,t))return"ineligible-active-frames";if(!Object.is(e,t)){let m=s===void 0?void 0:o.getTransientDependencies(n,e);if(m!==void 0){if(m.length===0)return"proven-terminal"}else{let p=n.getSelectorDependencyNodes;if(p!==void 0){let A=p.call(n,e);if(A===void 0||A.length===0)return"proven-terminal"}}}if(!i)return"disabled";let d={remaining:St},u=[t],l=new Set(u),f=0,c=0,h=1;while(u.length>0){if(d.remaining===0)return q("budget-exhausted",d,f,c,h,r);d.remaining--,f++;let m=u.pop();if(Object.is(m,e))return q("path-possible",d,f,c,h,r);let p=!1,A=(k)=>{if(c++,Object.is(k,e))return p=!0,!1;if(!l.has(k)){if(l.add(k),u.push(k),u.length>h)h=u.length}return!0},te=a.call(n,m,d,A);if(p)return q("path-possible",d,f,c,h,r);if(!te)return q("budget-exhausted",d,f,c,h,r);let V=s?.get(m);if(V!==void 0)for(let k of V){if(d.remaining===0)return q("budget-exhausted",d,f,c,h,r);if(d.remaining--,!A(k))return q("path-possible",d,f,c,h,r)}}return q("proven-reverse",d,f,c,h,r)},Yt=(e,t,n,o,r,i,s,a)=>{if(r===1||r===2){let c=qt(e,t,n,o,void 0,r===1?s?.reverseProofEnabled??!0:a?.reverseProofEnabled??!0,a?.transientDependents);if(c==="proven-terminal"||c==="proven-reverse")return;if(c==="budget-exhausted"){if(r===1&&s!==void 0)s.reverseProofEnabled=!1;else if(a!==void 0)a.reverseProofEnabled=!1}}let d=s?.(),u=d?.beginSearch()??!1,l=[e],f=new Map([[e,ct]]);while(l.length>0){let c=l.pop();if(Object.is(c,t)){let p=[],A=c;while(A!==ct)p.push(A),A=f.get(A);return p.reverse(),d?.completePositive(),Object.freeze(p)}let h=o.getTransientDependencies(n,c);if(h){if(h.length===0)continue;if(u){let p=d.hasProvenNoPath(c);if(!d.enabled)u=!1;if(p)continue}for(let p of h){if(f.has(p.node))continue;f.set(p.node,c),l.push(p.node)}continue}if(n.getSelectorDependencyNodes!==void 0){let p=n.getSelectorDependencyNodes(c);if(p===void 0||p.length===0)continue;if(u){let A=d.hasProvenNoPath(c);if(!d.enabled)u=!1;if(A)continue}for(let A of p){if(f.has(A))continue;f.set(A,c),l.push(A)}continue}let m=n.getSelectorRecord(c);if(!m||m.dependencies.length===0)continue;if(u){let p=d.hasProvenNoPath(c);if(!d.enabled)u=!1;if(p)continue}for(let p of m.dependencies){if(f.has(p.node))continue;f.set(p.node,c),l.push(p.node)}}d?.completeNegative(f);return},lt=(e,t)=>{let n=ft(e);if(n.kind==="thenable")return ht(n),new W(t);if(n.kind==="inspection-error")return n.error;return e},ut=(e,t)=>{let n=ft(e);if(n.kind==="thenable")return ht(n),Object.freeze({kind:"error",error:new W(t)});if(n.kind==="inspection-error")return Object.freeze({kind:"error",error:n.error});return Object.freeze({kind:"value",value:e})},mt=(e,t,n,o=Yt,r,i)=>{let{node:s}=e,a=[],d=t.getSelectorRecord(s),u=d?.dependencies,l=u===void 0?new Set:void 0,f,c=0,h=t.getComparisonBaseline(s),m=!0,p=()=>{let S=l;if(S!==void 0)return S;S=new Set;for(let y of a)S.add(y.node);return l=S,S};n.enter(t,s,a);let A=t.getSelectorGraphVersion(),te=n.getSelectorGraphPublicationCount(t),V=A,k=te,Qe=A,$e=te,Ne,Ce=!1,Ee=A,he=0,Y,Ze=A,Se,De=(S,y)=>{if(S===Ee)return;if(Ee=S,Y===void 0){he=0;return}if(Y.advanceGraphVersion(y))return;he=0,r?.graphVersionReset()},xt=(S)=>{if(S!==Ee)De(S,void 0);if(he++,(u?.length??0)===0&&he<3){r?.admissionSkipped();return}if(Y===void 0){let y=u!==void 0&&u.length>0&&u.length<3;Y=Ut(y?3:0,r)}if(!Y.enabled){r?.disabled();return}return Y},jt=(S)=>{if(Ce)return;let y=t.beginSelectorGraphObservation?.(S);if(y===void 0)return;Ce=!0,Ne=y},Ve=(S,y,w,g)=>w-S===g-y,Je=(S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t),w=Ve(V,k,S,y))=>{if(S===V)return;if(!Ce&&t.beginSelectorGraphObservation!==void 0){De(S,void 0),V=S,k=y;return}let g=Ne?.takeAddedEdges();if(De(S,g),w){V=S,k=y;return}if(g!==void 0){let O=g.length===0||t.visitSelectorDependents===void 0?void 0:n.captureTransientReverseDependents(t,s,a.length,Wt,i),P=g.length===0?void 0:{transientDependents:O,reverseProofEnabled:!0},R=!1;for(let _ of g)if(o(_.head,_.tail,t,n,2,a.length,void 0,P)!==void 0){R=!0;break}if(!R){V=S,k=y;return}}for(let O=0;O<a.length;O++){let P=a[O],R=o(P.node,s,t,n,0,a.length);if(!R)continue;if(l!==void 0)for(let F=a.length-1;F>=O;F--)l.delete(a[F].node);if(a.length=O,c++,n.getControlFault().kind==="fault")return;let N=new re(s,[s,...R]);n.latchCycle(t,s,N);return}V=S,k=y},Pe=()=>{let S=t.getSelectorGraphVersion(),y=n.getSelectorGraphPublicationCount(t);Qe=S,$e=y;let w=Ve(V,k,S,y);if(!w)n.revalidateAncestorPrefixes(t,s);Je(S,y,w)};n.setPrefixRevalidator(t,s,Je);let It=(S)=>{if(!m)throw new Ie;let y=n.getControlFaultForSuppliedRead();if(y.kind==="fault")throw y.error;let w=n.getCycle(t,s);if(w!==void 0)throw w;let g=n.activeCyclePath(t,S);if(g){let v=new re(s,g);throw n.latchCycle(t,s,v),v}let O=a.length,P,R=!1;if(l===void 0){let v=u?.[O];if(v!==void 0&&Object.is(v.node,S))P=!1,R=!0;else P=p().has(S)}else P=l.has(S);if(!P&&!R&&u!==void 0&&u.length>0){let v=u[a.length];if(v!==void 0&&Object.is(v.node,S))R=!0;else{if(f===void 0){f=new Set;for(let X of u)f.add(X.node)}R=f.has(S)}}let _=c,N=t.serve(S,n);Pe();let F=n.getCycle(t,s);if(F!==void 0)throw F;let ne=l!==void 0?l.has(S):c===_&&a.length===O?!1:p().has(S),B=Qe,K=$e,z=ne||R&&B===A,pe=u===void 0&&Ve(A,te,B,K);if(!z&&!pe){if(Ze=B,Se===void 0)Se=()=>xt(Ze),Se.reverseProofEnabled=!0;let v=o(S,s,t,n,1,a.length,Se);if(v){let X=n.getControlFault();if(X.kind==="fault")throw X.error;let et=new re(s,[s,...v]);throw n.latchCycle(t,s,et),et}}if(!ne){let v=d?.dependencies[a.length];l?.add(S),a.push(v!==void 0&&Object.is(v.node,S)&&Object.is(v.token,N.token)?v:Object.freeze({node:S,token:N.token})),jt(S)}if(V=B,k=K,N.outcome.kind==="control-error"){n.latchControlFault(N.outcome.error);let v=n.getControlFault();if(v.kind==="fault")throw v.error;throw N.outcome.error}let oe=n.getControlFault();if(oe.kind==="fault")throw oe.error;if(N.outcome.kind==="error")throw new xe(S,N.outcome.error);return N.outcome.value};try{let S,y,w=!1;try{S=e.get(It)}catch(F){w=!0,y=F}finally{m=!1}if(w)y=lt(y,"getter");let g=w?void 0:ut(S,"getter");Pe();let O=n.getControlFault();if(O.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:O.error},a);let P=n.getCycle(t,s);if(P!==void 0)return E(s,t.createOutcomeToken(),{kind:"error",error:P},a);if(w)return E(s,t.createOutcomeToken(),{kind:"error",error:y instanceof W?y:new me(s,y)},a);if(g===void 0)throw Error("Selector result classification was not completed");let R=n.getControlFault();if(R.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:R.error},a);if(g.kind==="error")return E(s,t.createOutcomeToken(),{kind:"error",error:g.error instanceof W?g.error:new me(s,g.error)},a);let _=g.value,N;if(h){let F=e.equal??Object.is,ne,B,K=!1;try{ne=F(h.value,_)}catch(X){K=!0,B=lt(X,"comparator")}let z=K?void 0:ut(ne,"comparator");Pe();let pe=n.getControlFault();if(pe.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:pe.error},a);let oe=n.getCycle(t,s);if(oe!==void 0)return E(s,t.createOutcomeToken(),{kind:"error",error:oe},a);if(K)return E(s,t.createOutcomeToken(),{kind:"error",error:B instanceof W?B:new ye(s,B)},a);if(z===void 0)throw Error("Selector comparator classification was not completed");let v=n.getControlFault();if(v.kind==="fault")return E(s,t.createOutcomeToken(),{kind:"control-error",error:v.error},a);if(z.kind==="error")return E(s,t.createOutcomeToken(),{kind:"error",error:z.error instanceof W?z.error:new ye(s,z.error)},a);if(z.value!==!0&&z.value!==!1)return E(s,t.createOutcomeToken(),{kind:"error",error:new je},a);if(z.value===!0)_=h.value,N=h.current?h.token:void 0}return E(s,N??t.createOutcomeToken(),{kind:"value",value:_},a)}finally{try{Ne?.close()}finally{n.leave(t,s)}}};class b{#t=[];#n;#o=0;#s;#a=Kt;#r;latchControlFault(e){if(this.#a.kind==="fault")return;this.#a=Object.freeze({kind:"fault",error:e})}getControlFault(){return this.#a}setSuppliedReadGuard(e){let t=this.#r;return this.#r=e,t}getControlFaultForSuppliedRead(){return this.#r?.(),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.#s??(this.#s=new WeakMap);n.set(e,(n.get(e)??0)+1)}getSelectorGraphPublicationCount(e){return Object.is(this.#n,e)?this.#o:this.#s?.get(e)??0}enter(e,t,n){this.#t.push({host:e,selector:t,dependencyPrefix:n,revalidatePrefix:void 0,cycleError:void 0})}leave(e,t){let n=this.#t.pop();if(!n||!Object.is(n.host,e)||!Object.is(n.selector,t))throw Error("Selector evaluation frame corruption")}isActive(e,t){return this.#t.some((n)=>Object.is(n.host,e)&&Object.is(n.selector,t))}isSoleActiveSelector(e,t){let n=!1;for(let o of this.#t){if(!Object.is(o.host,e))continue;if(n||!Object.is(o.selector,t))return!1;n=!0}return n}activeCyclePath(e,t){let n=this.#t.findIndex((o)=>Object.is(o.host,e)&&Object.is(o.selector,t));if(n===-1)return;return Object.freeze([...this.#t.slice(n).filter((o)=>Object.is(o.host,e)).map((o)=>o.selector),t])}setPrefixRevalidator(e,t,n){let o=this.#i(e,t);if(o.revalidatePrefix!==void 0)throw Error("Selector prefix revalidator is already installed");o.revalidatePrefix=n}revalidateAncestorPrefixes(e,t){this.#i(e,t);for(let n=0;n<this.#t.length-1;n++){let o=this.#t[n];if(!Object.is(o.host,e))continue;let r=o.revalidatePrefix;if(r===void 0)throw Error("Selector prefix revalidator is not installed");r()}}getTransientDependencies(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o.dependencyPrefix}return}captureTransientReverseDependents(e,t,n,o,r){let i=new Set,s=new Map,a=!1,d=0,u=0,l=0;for(let c of this.#t){if(d++,d>o){r?.recordSnapshot("overflow",d,u,l);return}if(!Object.is(c.host,e))continue;if(u++,c.revalidatePrefix===void 0||i.has(c.selector)){r?.recordSnapshot("unavailable",d,u,l);return}if(i.add(c.selector),Object.is(c.selector,t)){if(a||c.dependencyPrefix.length!==n){r?.recordSnapshot("unavailable",d,u,l);return}a=!0}for(let h of c.dependencyPrefix){if(l++,l>o){r?.recordSnapshot("overflow",d,u,l);return}let m=s.get(h.node);if(m===void 0)s.set(h.node,[c.selector]);else m.push(c.selector)}}if(!a){r?.recordSnapshot("unavailable",d,u,l);return}let f=new Map;for(let[c,h]of s)f.set(c,Object.freeze(h));return r?.recordSnapshot("completed",d,u,l),f}latchCycle(e,t,n){let o=this.#d(e,t);o.cycleError??=n}getCycle(e,t){return this.#i(e,t).cycleError}#i(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}#d(e,t){for(let n=this.#t.length-1;n>=0;n--){let o=this.#t[n];if(Object.is(o.host,e)&&Object.is(o.selector,t))return o}throw Error("Selector evaluation frame is not active")}}var Kt=Object.freeze({kind:"none"});var yt=Symbol("no-committed-selector-baseline");class Te{#t;#n=new Map;#o=new Map;#s=new Map;#a;#r=1;#i=0;#d;constructor(e,t,n){this.#t=e,this.#a=t,this.#d=n}readSelector(e){let t=new b,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.#s.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 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.#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.#i++,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.#i}getComparisonBaseline(e){let t=this.#s.get(e);if(t===void 0)t=this.#c().captureCommittedSelectorSuccess(e)??yt,this.#s.set(e,t);return t===yt?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 bt=4096,Xt=Object.freeze([]);class vt{onDeadReference;onEmptinessProbe;#t=new WeakMap;#n=new Set;constructor(e,t){this.onDeadReference=e;this.onEmptinessProbe=t}add(e){if(this.#t.has(e))return;let t=new WeakRef(e);this.#t.set(e,t),this.#n.add(t)}delete(e){let t=this.#t.get(e);if(t===void 0)return;this.#t.delete(e),this.#n.delete(t)}forEach(e){for(let t of this.#n){let n=t.deref();if(n===void 0){this.#n.delete(t),this.onDeadReference?.();continue}e(n)}}visitWithin(e,t){for(let n of this.#n){if(e.remaining===0)return!1;e.remaining--;let o=n.deref();if(o===void 0){this.#n.delete(n),this.onDeadReference?.();continue}if(!t(o))return!1}return!0}isEmpty(){for(let e of this.#n){if(this.onEmptinessProbe?.(),e.deref()!==void 0)return!1;this.#n.delete(e),this.onDeadReference?.()}return!0}clear(){this.#n.clear(),this.#t=new WeakMap}}class Oe{coordinator;parent;name;children;namedChildren=new Map;atomOverrides=new WeakMap;[C]=void 0;#t=new WeakMap;#n;#o=new WeakMap;#s;#a=new WeakMap;#r=new WeakSet;#i=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.#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((t)=>{this.detachAtomView(t),t.inheritingChildren.clear()}),this.#n.clear(),this.atomOverrides=new WeakMap;let e=this[C]?.size??0;if(e>0)this.coordinator.recordCounter("familyOwnerReleases",e);this[C]=void 0,this.#t=new WeakMap,this.#o=new WeakMap,this.#s=void 0,this.#a=new WeakMap,this.#r=new WeakSet,this.#i++,this.#e()}serve(e,t){let n=this.coordinator.runtimeDomain;if(Q(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=le(n,t,()=>this.coordinator.evaluate(o,this,t));if(s.outcome.kind==="control-error"&&!this.coordinator.postSourceApply)throw s.outcome.error;return this.#b(r,s,t)}getSelectorRecord(e){let t=this.#o.get(e);return t===void 0?void 0:Object.freeze({dependencies:t.dependencies})}getSelectorDependencyNodes(e){let t=this.#o.get(e);if(t===void 0)return;let n=e,o=this.#s?.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.#s;if(i===void 0)i=new WeakMap,this.#s=i;i.set(n,o)}return o}visitSelectorDependents(e,t,n){return this.#a.get(e)?.visitWithin(t,n)??!0}getSelectorGraphVersion(){return this.#i}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 Xt;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()}#b(e,t,n){let o=this.#o.get(e),r=Object.freeze({token:t.token,outcome:t.outcome}),i=Object.freeze({served:r,dependencies:t.dependencies,lastSuccess:t.outcome.kind==="value"?Object.freeze({value:t.outcome.value,token:t.token}):o?.lastSuccess}),s=this.#y(e,o?.dependencies??At,t.dependencies),a=s?this.#S(e,o?.dependencies??At,t.dependencies):void 0;if(s)this.#s?.delete(e);if(this.#i++,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.#d===0||this.#l)return;let o=this.#c;if(o===void 0){this.#e();return}let r=bt-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.#c;if(t===void 0||t.length+e.length>bt){this.#e();return}t.push(...e)}#e(){if(this.#d===0)return;this.#c=[],this.#l=!0}#m(){return new vt(this.coordinator.instrumented?()=>this.coordinator.recordCounter("deadRouteCompactions"):void 0)}}var At=Object.freeze([]);class Le{transaction=Object.freeze({});#t;#n;#o;#s;#a;#r;#i;#d;#c;#l;#h;#u;#b;#y;#S;#p;#e;generation=0;active=!0;constructor(e){this.#t=e}get hasIntents(){return this.#o!==void 0||this.#s!==void 0||this.#a!==void 0||this.#r!==void 0}get singleIntentScope(){return this.#n}get singleIntent(){return this.#s===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.#s;if(i===void 0){this.#s=t,this.#m();return}if(Object.is(i.atom,t.atom)){this.#s=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.#s!==void 0)s.set(this.#s.atom,this.#s);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.#s=void 0,this.#m()}forEachIntent(e){let t=this.#o;if(t!==void 0){if(e(this.#n,t),this.#s!==void 0)e(this.#n,this.#s);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.#s;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.#i,e)&&Object.is(this.#d,t))return this.#c;if(this.#h!==void 0&&Object.is(this.#i,e)&&Object.is(this.#l,t))return this.#h;if(Object.is(this.#i,e))return this.#u?.get(t);return this.#b?.get(e)?.get(t)}setAtomBaseline(e,t,n){let o=this.#b;if(o!==void 0){let s=o.get(e);if(s===void 0)s=this.#f(),o.set(e,s);if(!s.has(t))s.set(t,n);return}let r=this.#u;if(r!==void 0){if(Object.is(this.#i,e)){if(!r.has(t))r.set(t,n)}else{let s=this.#f();s.set(this.#i,r);let a=this.#f();a.set(t,n),s.set(e,a),this.#b=s,this.#u=void 0,this.#i=void 0}return}let i=this.#c;if(i===void 0){this.#i=e,this.#d=t,this.#c=n;return}if(Object.is(this.#i,e)&&Object.is(this.#d,t))return;if(Object.is(this.#i,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.#i,a);let d=this.#f();d.set(t,n),s.set(e,d),this.#b=s,this.#i=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.#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.#b!==void 0){for(let e of this.#b.values())e.clear();this.#b.clear()}this.#p?.clear(),this.#n=void 0,this.#o=void 0,this.#s=void 0,this.#a=void 0,this.#r=void 0,this.#i=void 0,this.#d=void 0,this.#c=void 0,this.#l=void 0,this.#h=void 0,this.#u=void 0,this.#b=void 0,this.#y=void 0,this.#S=void 0,this.#p=void 0,this.#e?.clear(),this.#e=void 0}#f(){return this.#t?.(),new Map}}class gt{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]),ue(this,e.runtimeDomain.ownerToken),e.runtimeDomain.transactionCursors.set(this,t),Object.freeze(this)}}var We=(e,t,n)=>new gt(e,t,n),Ue=(e)=>{let t=x(e);if(t.kind==="not-thenable")return;if(t.kind==="inspection-error")throw t.error;throw j(t),new ie},kt=(e)=>{let t=x(e);if(t.kind==="not-thenable")throw e;if(t.kind==="inspection-error")throw t.error;throw j(t),new ie};var Qt=(e)=>function(){let n=e.target;if(n===void 0)return;n.host.removeSubscription(e)},fe=Symbol("definition domain records"),kn=(e,t,n,o,r)=>{let i=e[fe],s=new b,a=i.activity,d=a?.kind==="selector"?a:a?.kind==="guarded-callback"?a.selectorActivity:void 0,u=[];while(d!==void 0){let c=d.session;if(!u.includes(c))u.push(c);d=d.parentSelectorActivity}let l=i[U];i[U]={session:s,definitions:new WeakSet,allowDefinitions:t==="factory"};let f=u.map((c)=>Object.freeze({selectorSession:c,previous:c.setSuppliedReadGuard(()=>{let h=i.activity;return it(h?.kind==="guarded-callback"?h.session:s,c)})}));try{return H(i,s,()=>{let c=Reflect.apply(n,void 0,o);return r===void 0?c:r(c)})}finally{for(let c=f.length-1;c>=0;c--){let h=f[c];h.selectorSession.setSuppliedReadGuard(h.previous)}if(l===void 0)delete i[U];else i[U]=l}},wn=(e)=>{let t=e[fe][U];if(t===void 0||t.allowDefinitions)return;let n=new G;throw t.session.latchControlFault(n),n},Rn=(e,t)=>{let n=e[fe];if((typeof t==="object"||typeof t==="function")&&t!==null&&n.states.has(t)){if(n[U]?.definitions.has(t)||n[be]?.has(t))return t;return}M(n,t,new b);return},Tn=(e,t)=>{let n=e[fe];if((n[be]??(n[be]=new WeakSet)).add(t),!n.atoms.has(t))return;(n[C]??(n[C]=new WeakSet)).add(t)},Et=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,familyOwnerRetentionSetsCreated:32,familyOwnerRetains:33,familyOwnerReleases:34}),$t=35,Dt=new WeakMap,On=()=>{let e=new Uint32Array($t),t=Object.freeze({read(n){return e[Et[n]]??0}});return Dt.set(t,e),t},D=(e)=>Object.freeze({kind:"value",value:e}),Zt=(e)=>Object.freeze({kind:"error",error:e}),wt=(e)=>e.kind==="value"?D(e.value):Zt(e.error),Rt=(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)},Tt=1,qe=2,Ot=4,Jt=(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}),Ke=(e)=>(e.onAllocation?.(),new Map),en=(e)=>(e.onAllocation?.(),new Set),Ye=(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)},Nt=(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=Ke(e),e.preflight=r;let i=r.get(t);if(i===void 0)i=Ke(e),r.set(t,i);i.set(n,o)},tn=(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=en(e),e.considered=n;if(n.has(t))return!1;return n.add(t),!0},nn=(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=Ke(e),e.affected=o;o.set(t,n)};class Vt{#t=new WeakMap;#n;#o=1;#s=0;#a=!1;#r;#i;#d;#c=0;#l;#h;#u;#b=1;#y=0;#S;#p;#e;#m;#f;evaluate;constructor(e,t,n){this.#e=e,this.#m=t===void 0?void 0:Dt.get(t),this.#f=n,this.evaluate=n?.evaluate??mt,this.#n=new Oe(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[Et[e]]+=t}#R(){return this.recordCounter("draftCreations"),new Le(this.instrumented?()=>this.recordCounter("draftStorageAllocations"):void 0)}get(e,t){let n=new b,o=t,r=M(this.#e,o,n),i=He(this.#e,"StoreTree.get");if(this.#A(e),r==="invalid")throw TypeError("StoreTree.get requires a valid State");if(i===void 0){let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value")throw s.outcome.error;return s.outcome.value}try{let s=e.serveKnownLocal(o,n);if(s.outcome.kind!=="value"){if(s.outcome.kind==="control-error")i.latchControlFault(s.outcome.error);throw s.outcome.error}return s.outcome.value}catch(s){let a=n.getControlFault();if(a.kind==="fault")i.latchControlFault(a.error);throw s}}sub(e,t,n){let o=t,r,i=this.#e.states.has(o)?"local":M(this.#e,o,r=new b);if(I(this.#e,"StoreTree.sub"),this.#A(e),i==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("StoreTree.sub requires a valid State");if(typeof n!=="function")throw TypeError("StoreTree.sub requires a callback function");let s=e.getMaterializedServedOutcome(o)??e.serveKnownLocal(o,r??new b);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 u=d.get(o);if(u===void 0){if(u={host:this,scope:e,state:o,head:void 0,tail:void 0,reachedEpoch:0},d.set(o,u),this.instrumented)this.recordCounter("subscriptionTargetsCreated"),this.recordCounter("activeSubscriptionTargets")}let l={callback:n,target:u,previous:u.tail,next:void 0};if(u.tail===void 0)u.head=l;else u.tail.next=l;if(u.tail=l,this.instrumented)this.recordCounter("subscriptionRegistrations"),this.recordCounter("activeSubscriptions"),this.recordCounter("unsubscribeClosuresCreated");return Qt(l)}removeSubscription(e){let t=e.target;if(t===void 0)return;st(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.#T(e,t,"StoreTree.set","set",n)}update(e,t,n){this.#T(e,t,"StoreTree.update","update",n)}reset(e,t){this.#T(e,t,"StoreTree.reset","reset")}scope(e,t,n){if(t!==0&&(typeof n==="object"||typeof n==="function")&&n!==null)M(this.#e,n,new b);if(I(this.#e,"StoreTree.scope"),this.#A(e),t===0)return this.#P(e);if(t!==1||typeof n!=="string")throw TypeError("StoreTree.scope requires a string name");let o=e.namedChildren.get(n);if(o!==void 0)return this.recordCounter("namedScopeHits"),o.facade;return this.recordCounter("namedScopeMisses"),this.#P(e,n)}dispose(e){if(I(this.#e,"StoreTree.dispose"),e.status!=="live")return;let t=[],n=[Object.freeze({node:e,expanded:!1})];while(n.length>0){let{node:o,expanded:r}=n.pop();if(r){t.push(o);continue}o.markDisposing(),n.push(Object.freeze({node:o,expanded:!0}));let i=[];o.children.forEach((s)=>i.push(s));for(let s=i.length-1;s>=0;s--)n.push(Object.freeze({node:i[s],expanded:!1}))}for(let o of t){this.recordCounter("disposalVisits");let r=o.parent;if(r!==void 0){if(o.name!==void 0&&Object.is(r.namedChildren.get(o.name),o))r.namedChildren.delete(o.name);r.children.delete(o)}this.#Q(o),o.dropRecords(),o.namedChildren.clear(),o.children.clear(),o.markDisposed()}if(Object.is(e,this.#n))this.#t=new WeakMap}txn(e,t,n){if(I(this.#e,"StoreTree.txn"),this.#A(e),typeof t!=="function"||n!==void 0&&typeof n!=="string")throw TypeError("StoreTree.txn requires a callback");let o=this.#R(),r=We(this,o,e),i;try{i=rt(this.#e,o.transaction,()=>t(r))}catch(s){throw o.close(),o.release(),s}o.close();try{let s=new b;ge(this.#e,s,()=>Ue(i)),this.#z(o)}finally{o.release()}return i}readHydrationSnapshot(e,t){let n=new b,o=t,r=M(this.#e,o,n);if(I(this.#e,"adapter readHydrationSnapshot"),this.#A(e),r==="invalid"||!this.#e.atoms.has(o)&&!this.#e.selectors.has(o))throw TypeError("readHydrationSnapshot requires a valid State");let i=this.#R(),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.#Y(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 b,i=M(this.#e,o,r);if(ke(this.#e,e.transaction,e.active),this.#A(t),i==="invalid")throw TypeError("Transaction.get requires a valid State");if(this.#e.atoms.has(o)){let a=this.#v(e,t,o,r);if(a.kind!=="value")throw a.error;return a.value}if(!this.#e.selectors.has(o))throw TypeError("Transaction.get requires a readable State");let s=e.getScratchHost(t);if(s===void 0){if(s=this.#q(e,t),e.installScratchHost(t,s))this.recordCounter("scratchMapAllocations")}return s.readSelector(o)}transactionSet(e,t,n,o){let r=n,i=new b;this.#O(e,t,r,i,"Transaction.set"),this.#j(e,t,r,o,i)}transactionUpdate(e,t,n,o){let r=n,i=new b;this.#O(e,t,r,i,"Transaction.update"),this.#I(e,t,r,o,i,"Transaction.update")}transactionReset(e,t,n){let o=n,r=new b;this.#O(e,t,o,r,"Transaction.reset"),this.#M(e,t,o,r)}transactionScope(e,t,n,o,r){let i=new b;if(typeof n!=="string")M(this.#e,n,i);ke(this.#e,e.transaction,e.active),this.#A(t);let s=this.#K(t,n);if(o!==1&&o!==2)throw TypeError("Transaction.scope requires a target and optional callback");let a=We(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 f=new b;return ge(this.#e,f,()=>kt(l))}let u=new b;return ge(this.#e,u,()=>Ue(d)),d}createOutcomeToken(){return Object.freeze({id:this.#o++})}#q(e,t){return this.recordCounter("scratchHostAllocations"),new Te(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)=>le(this.#e,n,o)}),e.generation,this.evaluate)}#Y(e,t){return this.recordCounter("scratchHostAllocations"),new Te(Object.freeze({resolveState:(n,o)=>this.#V(n,o),readDraftAtomOutcome:(n,o)=>this.#v(e,t,n,o),captureCommittedSelectorSuccess:()=>{return},runSelectorActivity:(n,o)=>le(this.#e,n,o)}),e.generation,this.evaluate)}#V(e,t){if(Q(this.#e,e,t)==="invalid")throw TypeError("Selector get requires a valid State");if(this.#e.atoms.has(e))return Object.freeze({kind:"atom"});let n=this.#e.selectors.get(e);if(n===void 0)throw TypeError("Unknown scratch StoreTree State");return Object.freeze({kind:"selector",definition:n})}#P(e,t){let n=new Oe(this,e,t);this.recordCounter("scopeNodesCreated");let o=new Xe(this,n,this.#f);if(e.children.add(n),t!==void 0)e.namedChildren.set(t,n);return o}#K(e,t){if(typeof t==="string"){let i=e.namedChildren.get(t);if(i===void 0)throw new _e;return this.#A(i),i}let n=t,o=this.#e.stores.get(n);if(o!==void 0){let i=o;if(this.#A(i),!Object.is(i.coordinator,this))throw new Be;return i}let r=this.#e.transactionCursors.get(n);if(r!==void 0){if(!r.active)throw new Ae;throw new ve}throw new ve}#A(e){if(e.status!=="live")throw new ze}#X(e,t,n,o){let r=M(this.#e,t,n);I(this.#e,o),this.#A(e),this.#x(t,r,o)}#T(e,t,n,o,r){let i=t,s=new b;this.#X(e,i,s,n);let a=this.#R();try{if(o==="set")this.#j(a,e,i,r,s);else if(o==="update")this.#I(a,e,i,r,s,n);else this.#M(a,e,i,s)}catch(d){throw a.close(),a.release(),d}a.close();try{this.#z(a)}finally{a.release()}}#Q(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)}#O(e,t,n,o,r){let i=M(this.#e,n,o);ke(this.#e,e.transaction,e.active),this.#A(t),this.#x(n,i,r)}#x(e,t,n){if(t==="invalid"||!this.#e.atoms.has(e))throw TypeError(`${n} requires a valid Atom`)}#j(e,t,n,o,r){let i=H(this.#e,r,()=>de(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.#F(e,t.parent,n,o);if(r.outcome.kind!=="value")throw r.outcome.error;let i=r.reachesFallback&&e.hasFallback(n);e.stage(t,Object.freeze({kind:"reset",atom:n,publishDraftFallback:i}))}#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=D(s.atomOverrides.get(n));break}s=s.parent}let d=a===void 0,u=Object.freeze({owned:i,outcome:a??this.#C(e,n,o),reachesFallback:d});return e.setAtomBaseline(t,n,u),u}#v(e,t,n,o){return this.#F(e,t,n,o).outcome}#F(e,t,n,o){let r=t;while(r!==void 0){let i=e.getIntent(r,n);if(i?.kind==="set")return Object.freeze({outcome:D(i.value),reachesFallback:!1});if(i===void 0&&r.atomOverrides.has(n))return Object.freeze({outcome:D(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 D(r.fallback.value);let i=r.fallback.initialize,s=e.getFallback(t);if(s!==void 0)return s;let a=wt(H(this.#e,n,()=>Ge(i)));return e.setFallback(t,a),a}#$(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 H(this.#e,o,()=>{let r;try{r=e(t,n)}catch(s){let a=x(s);if(a.kind==="not-thenable")throw s;if(a.kind==="inspection-error")throw a.error;throw j(a),new ae}let i=x(r);if(i.kind==="inspection-error")throw i.error;if(i.kind==="thenable")throw j(i),new ae;if(r!==!0&&r!==!1)throw new ae;return r})}#J(e,t,n){return H(this.#e,n,()=>{let o;try{o=e(t)}catch(i){let s=x(i);if(s.kind==="not-thenable")throw i;if(s.kind==="inspection-error")throw s.error;throw j(s),new se}let r=de(o);if(r.kind==="error")throw r.error;return r.value})}#z(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=Jt(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 u=this.#_(e,a,d,o);if(r===void 0){r=u;return}if(i===void 0)i=[];i.push(u)});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.#G(r);if(i!==void 0)for(let a of i){let d=this.#G(a);s||=d}if(this.#H(r),i!==void 0)for(let a of i)this.#H(a);this.#se();try{let a,d,u=o.affectedRecord,l=o.affectedBefore;if(u!==void 0&&l!==void 0)a=this.#E(o,u,l);let{secondAffectedRecord:f,secondAffectedBefore:c}=o;if(f!==void 0&&c!==void 0){let h=this.#E(o,f,c);if(h!==void 0)if(a===void 0)a=h;else d=[h]}if(o.affected!==void 0)for(let[h,m]of o.affected){let p=this.#E(o,h,m);if(p===void 0)continue;if(a===void 0)a=p;else{if(d===void 0)d=[];d.push(p)}}if(s)this.#s+=1,this.recordCounter("sourceEpoch");this.#f?.(2,a===void 0?0:1+(d?.length??0)),this.#ie(a,d)}catch(a){throw this.#k(),a}}#_(e,t,n,o){let r=e.getAtomBaseline(t,n.atom);if(r===void 0)throw Error("TreeDraft atom baseline is missing");this.#L(e,t,n.atom,o);let i=Object.freeze({scope:t,intent:n,ownershipChanged:n.kind==="set"?!r.owned||!Object.is(t.atomOverrides.get(n.atom),n.value):r.owned}),s=t.getAtomView(n.atom);if(s!==void 0)this.#ee(e,s,o);return i}#B(e,t){if(!t.intent.publishDraftFallback)return;let n=e.getFallback(t.intent.atom);if(n!==void 0&&!this.#t.has(t.intent.atom))this.#t.set(t.intent.atom,n),this.recordCounter("fallbackPublications")}#G(e){let{intent:t,scope:n}=e;if(t.kind==="set"){if(n.atomOverrides.set(t.atom,t.value),this.#e[C]?.has(t.atom)){let o=n[C];if(o===void 0)o=new Set,n[C]=o,this.recordCounter("familyOwnerRetentionSetsCreated");let r=o.size;if(o.add(t.atom),o.size!==r)this.recordCounter("familyOwnerRetains")}}else{n.atomOverrides.delete(t.atom);let o=n[C];if(o?.delete(t.atom))this.recordCounter("familyOwnerReleases");if(o?.size===0)n[C]=void 0}return e.ownershipChanged}#H({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=Ye(e,t.atom,t.scope);if(o===void 0)throw Error("Affected AtomView final outcome is missing");if(this.recordCounter("finalResolutionVisits"),Rt(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(!tn(n,r))continue;let i=r.served.outcome,s=this.#L(e,r.scope,r.atom,n);if(Rt(i,s))continue;nn(n,r,i);let a=o.length;r.inheritingChildren.forEach((d)=>{this.recordCounter("routeVisits"),o.push(d)});for(let d=a,u=o.length-1;d<u;d++,u--){let l=o[d];o[d]=o[u],o[u]=l}}}#L(e,t,n,o){let r=Ye(o,n,t);if(r!==void 0)return r;let i=t,s,a,d;while(i!==void 0){let u=Ye(o,n,i);if(u!==void 0){d=u;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=D(l.value);break}if(l===void 0&&i.atomOverrides.has(n)){d=D(i.atomOverrides.get(n));break}i=i.parent}if(d??=this.#te(e,n),s!==void 0)Nt(o,n,s,d),this.recordCounter("finalPreflightVisits");if(a!==void 0)for(let u of a)Nt(o,n,u,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 D(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 D(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,D(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,D(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 D(o.fallback.value);let r=o.fallback.initialize,i=wt(H(this.#e,t,()=>Ge(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.#i=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.#i=void 0,this.#d=void 0,this.#c=0,this.#l=void 0}this.#ae(n)}#se(){this.#S=void 0,this.#p=void 0,this.#y=this.#u===void 0?0:this.#b++}#k(){this.#y=0,this.#S=void 0,this.#p=void 0}reachSubscriptionTarget(e,t){let n=this.#y,o=this.#u?.get(e)?.get(t);if(n===0||o===void 0||o.reachedEpoch===n)return;if(o.reachedEpoch=n,this.instrumented)this.recordCounter("notificationTargetsReached");if(this.#S===void 0){this.#S=o;return}if(this.#p===void 0)this.#p=[o];else this.#p.push(o)}#ae(e){let t=this.#S;if(t===void 0){if(this.#k(),e!==void 0)throw e;return}let n,o,r=(u)=>{let l=u.head;while(l!==void 0){let f=l.callback;if(f!==void 0)if(n===void 0)n=f;else if(o===void 0)o=[n,f];else o.push(f);l=l.next}};r(t);let i=this.#p;if(i!==void 0)for(let u of i)r(u);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 u of s){if(a)this.recordCounter("subscriberCallbacksAttempted");let l=new b,f=!1,c;try{ot(this.#e,l,()=>{try{let h=u(),m=x(h);if(m.kind==="thenable")j(m);else if(m.kind==="inspection-error")f=!0,c=m.error}catch(h){f=!0,c=h;let m=x(h);if(m.kind==="thenable")j(m)}})}catch(h){f=!0,c=h}if(f){if(d===void 0)d=[];if(d.push(c),a)this.recordCounter("subscriberErrors")}}if(d===void 0){if(e!==void 0)throw e;return}throw new Fe(e===void 0?d:[e,...d])}enqueueSelector(e,t){let n=this.#r;if(n===void 0)return!1;if((this.#W(e,t)&Tt)!==0)return!0;return this.#w(e,t,Tt),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)&(Ot|qe))!==0)return;this.#w(e,t,qe);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 b)}this.#w(e,t,Ot)}finally{this.#w(e,t,0,qe)}}#W(e,t){if(Object.is(this.#i,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.#i===void 0){this.#i=e,this.#d=t,this.#c=n&~o;return}if(Object.is(this.#i,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.#$(n,r.outcome.value,o,i):o;e.stage(t,Object.freeze({kind:"set",atom:n,value:s,publishDraftFallback:r.reachesFallback&&e.hasFallback(n)}))}}class Xe{get;sub;set;update;reset;txn;scope;dispose;constructor(e,t,n){this.get=(o)=>e.get(t,o),this.sub=(o,r)=>e.sub(t,o,r),this.set=(o,r)=>e.set(t,o,r),this.update=(o,r)=>e.update(t,o,r),this.reset=(o)=>e.reset(t,o),this.txn=(o,r)=>e.txn(t,o,r),this.scope=function(o){return e.scope(t,arguments.length,o)},this.dispose=()=>e.dispose(t),t.installFacade(this),ue(this,e.runtimeDomain.ownerToken),e.runtimeDomain.stores.set(this,t),e.recordCounter("storeFacadesCreated"),n?.(0,this,t),Object.freeze(this)}}var Ct=(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}}},Pt=(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=(l)=>{let f=t[U];if(f===void 0)return;if(!f.allowDefinitions){let c=new G;throw f.session.latchControlFault(c),c}f.definitions.add(l)},o=(l,f={})=>{let c=new b,h=H(t,c,()=>de(l));if(h.kind==="error")throw h.error;let m=we("atom",t.ownerToken);return n(m),t.states.add(m),t.atoms.set(m,Object.freeze({fallback:Object.freeze({kind:"eager",value:h.value}),...Ct(f)})),m},r=(l,f={})=>{if(typeof l!=="function")throw TypeError("atomLazy requires an initializer function");let c=we("atom",t.ownerToken);return n(c),t.states.add(c),t.atoms.set(c,Object.freeze({fallback:Object.freeze({kind:"lazy",initialize:l}),...Ct(f)})),c},i=(l,f={})=>{if(typeof l!=="function")throw TypeError("selector requires a getter function");if(f.equal!==void 0&&typeof f.equal!=="function")throw TypeError("selector equal must be a function");let c=we("selector",t.ownerToken);n(c);let h=Object.freeze({node:c,get:l,...f.name===void 0?{}:{name:f.name},...f.equal===void 0?{}:{equal:f.equal}});return t.states.add(c),t.selectors.set(c,h),c},s=(l)=>{let f=new b;if(M(t,l,f)==="invalid")return;return t.stores.get(l)},d=Object.freeze({assertStore:(l)=>{let f=s(l);if(I(t,"adapter assertStore"),f===void 0)throw TypeError("assertStore requires a valid Store")},read:(l,f)=>{if(s(l)===void 0)throw He(t,"adapter read"),TypeError("read requires a valid Store");return l.get(f)},subscribe:(l,f,c)=>{if(s(l)===void 0)throw I(t,"adapter subscribe"),TypeError("subscribe requires a valid Store");return l.sub(f,c)},readHydrationSnapshot:(l,f)=>{let c=s(l);if(c===void 0)throw I(t,"adapter readHydrationSnapshot"),TypeError("readHydrationSnapshot requires a valid Store");return c.coordinator.readHydrationSnapshot(c,f)}});return Object.freeze({[fe]:t,atom:o,atomLazy:r,selector:i,adapter:d,createStoreTree:(l=e,f)=>{I(t,"createStoreTree");let c=new Vt(t,l,f);return new Xe(c,c.rootScope,f)}})};var on=Pt(),En=(e,t)=>on.createStoreTree(e,t);
|
|
2
|
+
export{re as a,qt as b,mt as c,Me as d,Fe as e,G as f,Z as g,J as h,Ae as i,ie as j,se as k,ae as l,ze as m,_e as n,Be as o,ve as p,kn as q,wn as r,Rn as s,Tn as t,On as u,on as v,En as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as E,d as b,e as h,f as v,g as F,h as V,i as T,j as g,k,l as x,m as S,n as R,o as w,p as C,q as z,r as P,s as M,t as L,v as u}from"./chunk-kve4rdec.js";var _={ref:(e)=>new WeakRef(e),registry:(e)=>{let r=new FinalizationRegistry(e);return Object.freeze({register:(t,n,o)=>r.register(t,n,o),unregister:(t)=>r.unregister(t)})}},A={kind:"not-thenable"},J=()=>{},I=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return A;try{let r=e.then;return typeof r==="function"?Object.freeze({kind:"thenable",target:e,then:r}):A}catch(r){return Object.freeze({kind:"inspection-error",error:r})}},K=(e)=>{try{Reflect.apply(e.then,e.target,[void 0,J])}catch{}throw TypeError("Definition callbacks must complete synchronously")},j=(e,r,t,n,o)=>e(r,(...a)=>{let c;try{c=Reflect.apply(t,void 0,a)}catch(d){let y=I(d);if(y.kind==="not-thenable")throw d;if(y.kind==="inspection-error")throw y.error;return K(y)}let l=I(c);if(l.kind==="not-thenable")return c;if(l.kind==="inspection-error")throw l.error;return K(l)},n,o),Q=()=>TypeError("family cannot recursively construct the same member");class N{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#r;#t;#n;constructor(e,r=_,t){this.#t=e,this.#n=t,this.#r=r.registry((n)=>{let o=n.route;if(o.entry!==n)return;o.entry=void 0,this.#l(o)}),this.#o=(n)=>r.ref(n)}#o;getOrCreateOne(e,r){return this.#i(this.#a(this.#e,e),r)}getOrCreateTuple(e,r){let t=this.#e;for(let n=0;n<e.length;n++)t=this.#a(t,e[n]);return this.#i(t,r)}get routeCount(){let e=0,r=(t)=>{if(t.children===void 0)return;for(let n of t.children.values())e++,r(n)};return r(this.#e),e}hasRoute(e){let r=this.#e;for(let t=0;t<e.length;t++){let n=r.children?.get(e[t]);if(n===void 0)return!1;r=n}return!0}#a(e,r){let t=e.children??(e.children=new Map),n=t.get(r);if(n!==void 0)return n;return n={parent:e,parentKey:r,children:void 0,entry:void 0},t.set(r,n),n}#i(e,r){let t=e.entry;if(t?.kind==="ready"){let o=t.reference.deref();if(o!==void 0)return o;if(this.#r.unregister(t),e.entry===t)e.entry=void 0}else if(t?.kind==="building"){let o=t.fault??Q();throw t.fault=o,o}let n={kind:"building",route:e,fault:void 0};e.entry=n;try{let o=this.#t(r);if(n.fault!==void 0)throw n.fault;this.#n?.(o);let a={kind:"ready",route:e,reference:this.#o(o)};return e.entry=a,this.#r.register(o,a,a),o}catch(o){if(e.entry===n)e.entry=void 0;throw this.#l(e),n.fault??o}}#l(e){let r=e;while(r.parent!==void 0&&r.entry===void 0&&(r.children===void 0||r.children.size===0)){let t=r.parent,n=t.children;if(n?.get(r.parentKey)!==r)return;if(n.delete(r.parentKey),n.size===0)t.children=void 0;r=t}}}var m=(e)=>e===null||e===void 0||typeof e!=="object"&&typeof e!=="function",O=()=>TypeError("family keys must be primitive; use encodeKey for structured arguments"),X=()=>TypeError("family encodeKey must return one primitive FamilyKey"),Y=()=>TypeError("family members require at least one key"),D=(e,r,t,n,o,a)=>{let c,l=new N((y)=>j(t,"factory",e,y,n),void 0,o),d={family(y){let s=arguments,p=c;if(p!==void 0){let i=p.fault??TypeError("family encodeKey cannot call its own family");throw p.fault=i,i}if(a(),s.length===0)throw Y();if(r!==void 0){let i={fault:void 0};c=i;let f;try{f=j(t,"encoder",r,s)}catch(G){throw i.fault??G}finally{c=void 0}if(i.fault!==void 0)throw i.fault;if(!m(f))throw X();return l.getOrCreateOne(f,s)}if(s.length===1){if(!m(y))throw O();return l.getOrCreateOne(y,s)}for(let i=0;i<s.length;i++)if(!m(s[i]))throw O();return l.getOrCreateTuple(s,s)}}.family;return Object.freeze(d)};var Z=(e,r={})=>u.atomLazy(e,r),q=(e,r={})=>u.atom(e,r);Object.defineProperty(q,"lazy",{configurable:!1,enumerable:!0,value:Z,writable:!1});var H=Object.freeze(q),W=(e,r={})=>u.selector(e,r),ee=(...e)=>{if(e.length===0||e.length>2)throw TypeError("family requires a State factory and options");let[r,t]=e;if(typeof r!=="function")throw TypeError("family requires a State factory function");if(t!==void 0&&(typeof t!=="object"||t===null))throw TypeError("family options must be an object");let n=t?.encodeKey;if(n!==void 0&&typeof n!=="function")throw TypeError("family encodeKey must be a function");return D(r,n,(o,a,c,l)=>z(u,o,a,c,l),(o)=>{let a=M(u,o);if(a===void 0)throw TypeError("family factories must construct or return a family State");return a},(o)=>L(u,o),()=>P(u))},B=ee;function U(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return u.createStoreTree()}var ce=H,ye=B,se=W,ue=U,de=v,pe=x,fe=k,me=g,Ee=C,be=b,he=R,ve=F,Fe=E,Ve=S,Te=w,ge=h,ke=T,xe=V;export{de as CallbackCapabilityError,pe as InvalidAtomComparatorResultError,fe as InvalidSynchronousAtomValueError,me as InvalidTransactionCallbackResultError,Ee as InvalidTransactionTargetError,be as RuntimeMismatchError,he as ScopeNotFoundError,ve as SelectorCapabilityError,Fe as SelectorCircularDependencyError,Ve as StoreDisposedError,Te as StoreTreeMismatchError,ge as SubscriberNotificationError,ke as TransactionClosedError,xe as TransactionPhaseError,ce as atom,ye as family,se as selector,ue as store};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as Z,c as ee,e as ne,q as te,s as pe}from"./chunk-y5ja7h9m.js";var ue=2048,me=1e5,q=256,H=1024,B=1e4,fe=32,be=20000,F=new Set(["span","operation","commit"]),ye=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),oe=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),he=()=>{},_=Symbol("inspection dependency path root"),L=(e)=>e==="proven-terminal"?"terminal":e==="proven-reverse"?"proven":e==="ineligible-active-frames"?"active-frames":e,Ie=1;class j{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var U=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??r??0),t=Math.max(t,o.seqEnd??r??0)}return Object.freeze({firstSequence:n,lastSequence:t})},G=(e,n,t,o)=>{let r=e??n;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},Y=(e)=>e.length<=q?e:e.slice(0,q),D=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({admissionSkipped:0,observing:0,consultedNoPrune:0,consultedPruned:0,disabled:0,mapProbes:0,prunedNodes:0,graphVersionResets:0,initialSeeds:0,activationReplacementSeeds:0,secondarySeeds:0,hitDerivedSeeds:0,missBudgetDisables:0,oversizedHitApproachDisables:0,passiveProbeBudgetDisables:0,maxRetainedEntries:0}),se=(e)=>Object.freeze({admissionSkipped:e.admissionSkipped,observing:e.observing,consultedNoPrune:e.consultedNoPrune,consultedPruned:e.consultedPruned,disabled:e.disabled,mapProbes:e.mapProbes,prunedNodes:e.prunedNodes,resets:Object.freeze({graphVersion:e.graphVersionResets}),seeds:Object.freeze({initial:e.initialSeeds,activationReplacement:e.activationReplacementSeeds,secondary:e.secondarySeeds,hitDerived:e.hitDerivedSeeds}),disables:Object.freeze({missBudget:e.missBudgetDisables,oversizedHitApproach:e.oversizedHitApproachDisables,passiveProbeBudget:e.passiveProbeBudgetDisables}),retained:Object.freeze({maxEntries:e.maxRetainedEntries})}),ie=()=>({attempts:0,completed:0,overflow:0,unavailable:0,scannedActiveFrames:0,scannedPrefixEdges:0,maxScannedActiveFrames:0,maxScannedPrefixEdges:0,capturedActiveFrames:0,capturedPrefixEdges:0,maxCapturedActiveFrames:0,maxCapturedPrefixEdges:0}),ae=(e,n)=>{if(e.attempts++,n.outcome==="completed")e.completed++;else if(n.outcome==="overflow")e.overflow++;else e.unavailable++;if(e.scannedActiveFrames=d(e.scannedActiveFrames,n.scannedFrames),e.scannedPrefixEdges=d(e.scannedPrefixEdges,n.prefixEdges),e.maxScannedActiveFrames=Math.max(e.maxScannedActiveFrames,n.scannedFrames),e.maxScannedPrefixEdges=Math.max(e.maxScannedPrefixEdges,n.prefixEdges),n.outcome!=="completed")return;e.capturedActiveFrames=d(e.capturedActiveFrames,n.activeFrames),e.capturedPrefixEdges=d(e.capturedPrefixEdges,n.prefixEdges),e.maxCapturedActiveFrames=Math.max(e.maxCapturedActiveFrames,n.activeFrames),e.maxCapturedPrefixEdges=Math.max(e.maxCapturedPrefixEdges,n.prefixEdges)},ce=(e)=>Object.freeze({...e}),ge=(e)=>{let n=ie();return Object.freeze({sink:Object.freeze({recordSnapshot(o,r,i,a){let s={outcome:o,scannedFrames:r,activeFrames:i,prefixEdges:a};ae(n,s),e(s)}}),finish:()=>n.attempts===0?void 0:n})},ve=(e)=>{let n=re(),t=!1;return Object.freeze({sink:Object.freeze({admissionSkipped(){t=!0,n.admissionSkipped++,e({admissionSkipped:1})},disabled(){t=!0,n.disabled++,e({disabled:1})},graphVersionReset(){t=!0,n.graphVersionResets++,e({graphVersionResets:1})},recordMapProbes(r){if(r===0)return;t=!0,n.mapProbes+=r,e({mapProbes:r})},completeSearch(r,i,a,s=0,c=0,b=0){if(t=!0,r==="observing")n.observing++;else if(r==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=s,n.prunedNodes+=c,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,b),i==="initial")n.initialSeeds++;else if(i==="activation-replacement")n.activationReplacementSeeds++;else if(i==="secondary")n.secondarySeeds++;else if(i==="hit-derived")n.hitDerivedSeeds++;if(a==="miss-budget")n.missBudgetDisables++;else if(a==="over-cap-hit")n.oversizedHitApproachDisables++;else if(a==="passive-probe-budget")n.passiveProbeBudgetDisables++;e({...r==="observing"?{observing:1}:r==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:s,prunedNodes:c,maxRetainedEntries:b,...i==="initial"?{initialSeeds:1}:i==="activation-replacement"?{activationReplacementSeeds:1}:i==="secondary"?{secondarySeeds:1}:i==="hit-derived"?{hitDerivedSeeds:1}:{},...a==="miss-budget"?{missBudgetDisables:1}:a==="over-cap-hit"?{oversizedHitApproachDisables:1}:a==="passive-probe-budget"?{passiveProbeBudgetDisables:1}:{}})}}),finish:()=>t?n:void 0})},Se=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,topologyDeltaProof:0,committed:0,scratch:0,hydration:0,newEdgeProofMemo:re(),reverseProof:{terminal:0,proven:0,pathPossible:0,budgetExhausted:0,disabled:0,activeFrames:0,unsupported:0,nodeVisits:0,dependentProbes:0,liveDependents:0,maxWork:0,maxFrontier:0,topologyDeltaSnapshot:ie()},lanes:{committed:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},scratch:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},hydration:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()}}}}),W=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof,topologyDeltaProof:e.cycle.topologyDeltaProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),newEdgeProofMemo:se(e.cycle.newEdgeProofMemo),reverseProof:Object.freeze({...e.cycle.reverseProof,topologyDeltaSnapshot:ce(e.cycle.reverseProof.topologyDeltaSnapshot)}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.committed.topologyDeltaProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.scratch.topologyDeltaProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.hydration.topologyDeltaProof})})})})}),z=(e,n,t,o)=>{if(n.remaining--<=0||o>fe)return null;if(e===null)return null;if(typeof e==="string")return e.length<=H?e:e.slice(0,H);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){let a=[],s=Math.min(e.length,B);for(let c=0;c<s;c++)a.push(z(e[c],n,t,o+1));return Object.freeze(a)}let r={},i=Object.keys(e).slice(0,B);for(let a of i){if(oe.has(a))continue;let s=Reflect.get(e,a);if(s===void 0)continue;r[a]=z(s,n,t,o+1)}return Object.freeze(r)}finally{t.delete(e)}},J=(e)=>{if(e===void 0)return Pe;let n={},t={remaining:be};for(let o of Object.keys(e).slice(0,B)){if(ye.has(o)||oe.has(o))continue;let r=e[o];if(r===void 0)continue;n[o]=z(r,t,new Set,0)}return Object.freeze(n)},Pe=Object.freeze({}),Re=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...J(n)})},d=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,Ee=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return K;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:K}catch(n){return{kind:"inspection-error",error:n}}},K=Object.freeze({kind:"not-thenable"});class de{#o;#e;#r;#u;#d="";#i=1;#g=1;#v=1;#S=1;#P=1;#R=1;#E=1;#x=1;#T=1;#n=[];#m=new WeakMap;#D=new WeakMap;#k=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#b;#C;constructor(e,n){this.#C=n,this.#r=G(e.capacity?.summaries,ue,"Inspection summary",!1),this.#u=G(e.capacity?.details,me,"Inspection detail",!0),this.#o=new j(this.#r),this.#e=new j(this.#u),this.#b=this.#p(),this.#w()}get recordingId(){return this.#d}registerStore(e,n){this.#k.set(e,n)}capture(e,n){let t=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=t===void 0?void 0:this.#k.get(t);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(n!==void 0){let a=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,s=o.coordinator.runtimeDomain;if(a===void 0||!s.states.has(a))throw TypeError("Inspection capture requires a valid State");let c=s.atoms.get(a),b=s.selectors.get(a);if(c===void 0&&b===void 0)throw TypeError("Inspection capture requires a valid State");let x=c?.name??b?.name;r=this.reference(a,c===void 0?"selector":"atom",typeof x==="string"?x:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#y()})}reference(e,n,t){if(this.#t!==void 0)return X;try{let o=this.#m.get(e);if(o===void 0)o=this.#T++,this.#m.set(e,o);let r=this.#D.get(e);if(r===void 0&&t!==void 0)r=Y(t),this.#D.set(e,r);return Object.freeze({id:o,kind:n,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),X}}sessionId(e){let n=this.#f.get(e);if(n!==void 0)return n;let t=this.#E++;return this.#f.set(e,t),t}beginInterval(e){if(this.#t!==void 0)return Q;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#y(),...e.links}),r={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:Y(e.name),seqStart:this.#i++,startUs:this.#I(),fields:J(e.fields),totals:F.has(e.type)?Se():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:F.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#s("operation");if(i!==void 0)i.commitId=n}return this.#n.push(r),t}catch{return this.#c("begin-interval"),Q}}finishInterval(e,n={}){if(e.id===0||this.#t!==void 0)return;try{let t=this.#n.pop();if(t===void 0||!Object.is(t.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#j(t);let o=this.#i++,r=Math.max(0,this.#I()-t.startUs),i=Re(t.fields,n.fields),a=this.#A(t,o,r,i,n.result);if(F.has(t.token.type)){if(this.#o.add(a))this.#l++}else if(this.#e.add(a))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let n=this.#i++,t=Object.freeze({...J(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#y(),...e.links});if(this.#e.add(t))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let n of this.#n){let t=n.totals;if(t===void 0)continue;t.selectorEvaluations=d(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=d(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=d(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=d(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=d(t.propagationSettled,e.propagationSettled),t.notificationTargets=d(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=d(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=d(t.cycle.searches,o.searches),t.cycle.visits=d(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=d(t.cycle.found,o.found);let r=o.newEdgeProofMemo;if(r!==void 0){let s=t.cycle.newEdgeProofMemo;s.admissionSkipped=d(s.admissionSkipped,r.admissionSkipped),s.observing=d(s.observing,r.observing),s.consultedNoPrune=d(s.consultedNoPrune,r.consultedNoPrune),s.consultedPruned=d(s.consultedPruned,r.consultedPruned),s.disabled=d(s.disabled,r.disabled),s.mapProbes=d(s.mapProbes,r.mapProbes),s.prunedNodes=d(s.prunedNodes,r.prunedNodes),s.graphVersionResets=d(s.graphVersionResets,r.graphVersionResets),s.initialSeeds=d(s.initialSeeds,r.initialSeeds),s.activationReplacementSeeds=d(s.activationReplacementSeeds,r.activationReplacementSeeds),s.secondarySeeds=d(s.secondarySeeds,r.secondarySeeds),s.hitDerivedSeeds=d(s.hitDerivedSeeds,r.hitDerivedSeeds),s.missBudgetDisables=d(s.missBudgetDisables,r.missBudgetDisables),s.oversizedHitApproachDisables=d(s.oversizedHitApproachDisables,r.oversizedHitApproachDisables),s.passiveProbeBudgetDisables=d(s.passiveProbeBudgetDisables,r.passiveProbeBudgetDisables),s.maxRetainedEntries=Math.max(s.maxRetainedEntries,r.maxRetainedEntries??0)}let i=o.topologyDeltaReverseSnapshot;if(i!==void 0)ae(t.cycle.reverseProof.topologyDeltaSnapshot,i);let a=o.reverseProof;if(a!==void 0){let s=t.cycle.reverseProof;if(a.outcome==="terminal")s.terminal++;else if(a.outcome==="proven")s.proven++;else if(a.outcome==="path-possible")s.pathPossible++;else if(a.outcome==="budget-exhausted")s.budgetExhausted++;else if(a.outcome==="disabled")s.disabled++;else if(a.outcome==="active-frames")s.activeFrames++;else s.unsupported++;s.nodeVisits=d(s.nodeVisits,a.nodeVisits),s.dependentProbes=d(s.dependentProbes,a.dependentProbes),s.liveDependents=d(s.liveDependents,a.liveDependents),s.maxWork=Math.max(s.maxWork,a.nodeVisits+a.dependentProbes),s.maxFrontier=Math.max(s.maxFrontier,a.maxFrontier)}if(o.site==="prefix-revalidation")t.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")t.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")t.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)t.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let s=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",c=t.cycle.lanes[o.host][s];c.searches=d(c.searches,o.searches),c.visits=d(c.visits,o.visits),c.maxVisits=Math.max(c.maxVisits,o.maxVisits??0),c.found=d(c.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,n){let t=this.#s("operation"),o=t===void 0||!Object.is(t.token,e)||t.commitId===void 0||!t.commitSourceApplied?"none":n==="returned"?"committed":t.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:n,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,n){let t=this.#s("operation");if(t!==void 0)t.commitSourceApplied||=n.sourceApplied,t.commitFailurePhase=n.failurePhase;this.finishInterval(e,{result:n.result,fields:{intents:n.intents,...n.changedSources===void 0?{}:{changedSources:n.changedSources},...n.ownershipChanged===void 0?{}:{ownershipChanged:n.ownershipChanged},sourceApplied:n.sourceApplied,notificationsCompleted:n.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let n=e[0];if(n===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(n===1){let o=e[1]===0?"returned":"threw",r=this.#s("operation");if(r===void 0)return;let i=this.#s("commit");if(i!==void 0)this.#j(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(n===2){let o=this.#s("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#s("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#s("operation");if(t!==void 0)t.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#s("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let r=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,n,t,o,r,i,a,s,c,b,x,k,I){let w=a===0?"prefix-revalidation":a===1?"new-edge-proof":"topology-delta-proof",h=this.beginInterval({type:"cycle-search",fields:{site:w,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-b,acceptedPrefixLength:s,parentWasCold:x}}),m={nodeVisits:0,dependentProbes:0,liveDependents:0,maxFrontier:0},S=a===1||a===2?Z(t,o,r,i,m,a===1?k?.reverseProofEnabled??!0:I?.reverseProofEnabled??!0,I?.transientDependents):void 0;if(S==="budget-exhausted"){if(a===1&&k!==void 0)k.reverseProofEnabled=!1;else if(I!==void 0)I.reverseProofEnabled=!1}let M=S==="proven-terminal"||S==="proven-reverse",O=0,N=0,l=0,T=0,P=0,C=0,v;if(!M){let f=k?.(),R=f?.beginSearch()??!1,y=[t],u=new Map([[t,_]]);l=1;while(y.length>0){let g=y.pop();if(O++,Object.is(g,o)){let p=[],E=g;while(E!==_)p.push(E),E=u.get(E);p.reverse(),v=Object.freeze(p);break}let V=i.getTransientDependencies(r,g);if(V){if(T++,V.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=V.length;for(let p of V){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length;continue}if(r.getSelectorDependencyNodes!==void 0){let p=r.getSelectorDependencyNodes(g);if(p===void 0){C++;continue}if(P++,p.length===0)continue;if(R){let E=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(E)continue}N+=p.length;for(let E of p){if(u.has(E))continue;u.set(E,g),y.push(E)}if(y.length>l)l=y.length;continue}let A=r.getSelectorRecord(g);if(!A){C++;continue}if(P++,A.dependencies.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=A.dependencies.length;for(let p of A.dependencies){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length}if(v===void 0)f?.completeNegative(u);else f?.completePositive()}return this.addWork({cycle:{searches:1,visits:O,maxVisits:O,found:v===void 0?0:1,site:w,host:e,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}}}}),this.finishInterval(h,{result:"returned",fields:{visits:O,edges:N,maxFrontier:l,transientExpansions:T,recordExpansions:P,terminalPrunes:C,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}},found:v!==void 0,...v===void 0?{}:{path:v.map((f)=>this.#h(f))}}}),v}span(e,n){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof n!=="function")throw TypeError("Inspection span callback must be a function");let t=this.beginInterval({type:"span",name:e}),o;try{o=n()}catch(i){throw this.finishInterval(t,{result:"threw"}),i}let r=Ee(o);if(r.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,he])}catch{}throw this.finishInterval(t,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(t,{result:"returned"}),o}export(){this.#O("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),n=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),t=U(e),o=U(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:5,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(n),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...t===void 0?{}:{summaries:t},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#O("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(n,t)=>e.capture(n,t),span:(n,t)=>e.span(n,t),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#d=`inspection-${Ie++}`,this.#o=new j(this.#r),this.#e=new j(this.#u),this.#i=1,this.#g=1,this.#v=1,this.#S=1,this.#P=1,this.#R=1,this.#E=1,this.#x=1,this.#T=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#b=this.#p()}#V(e){if(e==="span")return this.#g++;if(e==="operation")return this.#v++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#P++;if(e==="cycle-search")return this.#R++;return this.#x++}#y(){let e={};for(let n of this.#n){let{id:t,type:o}=n.token;if(n.links.sessionId!==void 0)e.sessionId=n.links.sessionId;if(o==="span")e.spanId=t;else if(o==="operation")e.operationId=t;else if(o==="commit")e.commitId=t;else if(o==="selector-evaluation")e.evaluationId=t;else if(o==="cycle-search")e.searchId=t}return e}#s(e){for(let n=this.#n.length-1;n>=0;n--){let t=this.#n[n];if(t.token.type===e)return t}return}#h(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):z(e,{remaining:1},new Set,0)}#A(e,n,t,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:n,startUs:e.startUs,durationUs:t,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:W(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:W(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:W(e.totals)});let a=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...a})}#O(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(n)=>this.#C.read(n);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#j(e){let n=e.counterStart;if(n===void 0)return;e.counterStart=void 0;let t=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=t.sourceEpoch!==n.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=t.transientSelectorHostsCreated-n.transientSelectorHostsCreated,o.propagationSettled+=t.propagationSettled-n.propagationSettled,o.notificationTargets+=t.notificationTargets-n.notificationTargets,o.subscriberCallbacks+=t.subscriberCallbacks-n.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let n=this.#i++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:n}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#M(e){return Math.max(0,Math.round((e-this.#b)*1000))}#I(){return this.#M(this.#p())}}var X=Object.freeze({id:0,kind:"store"}),Q=Object.freeze({id:0,type:"operation"}),xe=(e)=>{let n=(r,i,a,s)=>{if(e.hasActiveStoreOperation())return s();e.recordStoreEvent(0,r,i,i.name,a);try{let c=s();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof ne?1:0),c}},t=(r,i,a)=>{if(r===0){let s=i,c=a;e.registerStore(s,c);let b=s,x=s.set,k=s.update,I=s.reset,w=s.txn;b.set=(h,m)=>n(0,c,void 0,()=>x(h,m)),b.update=(h,m)=>n(1,c,void 0,()=>k(h,m)),b.reset=(h)=>n(2,c,void 0,()=>I(h)),b.txn=(h,m)=>{if(typeof h!=="function"||m!==void 0&&typeof m!=="string")return w(h,m);return n(3,c,m,()=>w(h,m))};return}if(r===1){e.beginDraftCommit(i,a);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(t,{evaluate:(r,i,a)=>{let s=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,b=e.reference(i,s==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),x=i.getSelectorGraphVersion(),k=a.getSelectorGraphPublicationCount(i),I=i.getSelectorRecord(r.node)?.dependencies,w=I?.length??0,h=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(a)},fields:{host:s,hostRef:b,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:x,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let m=ve((l)=>e.addWork({cycle:{newEdgeProofMemo:l}})),S=()=>{let l=m.finish();if(l===void 0)return;return se(l)},M=ge((l)=>e.addWork({cycle:{topologyDeltaReverseSnapshot:l}})),O=()=>{let l=M.finish();if(l===void 0)return;return ce(l)},N=(l,T,P,C,v,f,R,y)=>e.findDependencyPath(s,b,l,T,P,C,v,f,x,k,I===void 0,R,y);try{let l=ee(r,i,a,N,m.sink,M.sink),T=I===void 0||I.length!==l.dependencies.length||I.some((u,g)=>!Object.is(u.node,l.dependencies[g]?.node)),P=new Set(I?.map((u)=>u.node)),C=new Set(l.dependencies.map((u)=>u.node)),v=0,f=0;for(let u of C)if(!P.has(u))v++;for(let u of P)if(!C.has(u))f++;e.addWork(T?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let R=S(),y=O();return e.finishInterval(h,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:T,proposedEdgesAdded:v,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:R,topologyDeltaReverseSnapshot:y}}),l}catch(l){let T=S(),P=O();throw e.finishInterval(h,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:T,topologyDeltaReverseSnapshot:P}}),l}}}),Object.freeze(t)},le=(e={})=>{let n=te(),t=new de(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:xe(t)})};var Oe=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=le(e),r=pe(t,o);return Object.freeze({store:r,inspect:n})};export{Oe as createInspectableStore};
|
|
1
|
+
import{b as Z,c as ee,e as ne,u as te,w as pe}from"./chunk-kve4rdec.js";var ue=2048,me=1e5,q=256,H=1024,B=1e4,fe=32,be=20000,F=new Set(["span","operation","commit"]),ye=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),oe=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),he=()=>{},_=Symbol("inspection dependency path root"),L=(e)=>e==="proven-terminal"?"terminal":e==="proven-reverse"?"proven":e==="ineligible-active-frames"?"active-frames":e,Ie=1;class j{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var U=(e)=>{if(e.length===0)return;let n=Number.POSITIVE_INFINITY,t=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;n=Math.min(n,o.seqStart??r??0),t=Math.max(t,o.seqEnd??r??0)}return Object.freeze({firstSequence:n,lastSequence:t})},G=(e,n,t,o)=>{let r=e??n;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${t} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},Y=(e)=>e.length<=q?e:e.slice(0,q),D=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({admissionSkipped:0,observing:0,consultedNoPrune:0,consultedPruned:0,disabled:0,mapProbes:0,prunedNodes:0,graphVersionResets:0,initialSeeds:0,activationReplacementSeeds:0,secondarySeeds:0,hitDerivedSeeds:0,missBudgetDisables:0,oversizedHitApproachDisables:0,passiveProbeBudgetDisables:0,maxRetainedEntries:0}),se=(e)=>Object.freeze({admissionSkipped:e.admissionSkipped,observing:e.observing,consultedNoPrune:e.consultedNoPrune,consultedPruned:e.consultedPruned,disabled:e.disabled,mapProbes:e.mapProbes,prunedNodes:e.prunedNodes,resets:Object.freeze({graphVersion:e.graphVersionResets}),seeds:Object.freeze({initial:e.initialSeeds,activationReplacement:e.activationReplacementSeeds,secondary:e.secondarySeeds,hitDerived:e.hitDerivedSeeds}),disables:Object.freeze({missBudget:e.missBudgetDisables,oversizedHitApproach:e.oversizedHitApproachDisables,passiveProbeBudget:e.passiveProbeBudgetDisables}),retained:Object.freeze({maxEntries:e.maxRetainedEntries})}),ie=()=>({attempts:0,completed:0,overflow:0,unavailable:0,scannedActiveFrames:0,scannedPrefixEdges:0,maxScannedActiveFrames:0,maxScannedPrefixEdges:0,capturedActiveFrames:0,capturedPrefixEdges:0,maxCapturedActiveFrames:0,maxCapturedPrefixEdges:0}),ae=(e,n)=>{if(e.attempts++,n.outcome==="completed")e.completed++;else if(n.outcome==="overflow")e.overflow++;else e.unavailable++;if(e.scannedActiveFrames=d(e.scannedActiveFrames,n.scannedFrames),e.scannedPrefixEdges=d(e.scannedPrefixEdges,n.prefixEdges),e.maxScannedActiveFrames=Math.max(e.maxScannedActiveFrames,n.scannedFrames),e.maxScannedPrefixEdges=Math.max(e.maxScannedPrefixEdges,n.prefixEdges),n.outcome!=="completed")return;e.capturedActiveFrames=d(e.capturedActiveFrames,n.activeFrames),e.capturedPrefixEdges=d(e.capturedPrefixEdges,n.prefixEdges),e.maxCapturedActiveFrames=Math.max(e.maxCapturedActiveFrames,n.activeFrames),e.maxCapturedPrefixEdges=Math.max(e.maxCapturedPrefixEdges,n.prefixEdges)},ce=(e)=>Object.freeze({...e}),ge=(e)=>{let n=ie();return Object.freeze({sink:Object.freeze({recordSnapshot(o,r,i,a){let s={outcome:o,scannedFrames:r,activeFrames:i,prefixEdges:a};ae(n,s),e(s)}}),finish:()=>n.attempts===0?void 0:n})},ve=(e)=>{let n=re(),t=!1;return Object.freeze({sink:Object.freeze({admissionSkipped(){t=!0,n.admissionSkipped++,e({admissionSkipped:1})},disabled(){t=!0,n.disabled++,e({disabled:1})},graphVersionReset(){t=!0,n.graphVersionResets++,e({graphVersionResets:1})},recordMapProbes(r){if(r===0)return;t=!0,n.mapProbes+=r,e({mapProbes:r})},completeSearch(r,i,a,s=0,c=0,b=0){if(t=!0,r==="observing")n.observing++;else if(r==="consulted-no-prune")n.consultedNoPrune++;else n.consultedPruned++;if(n.mapProbes+=s,n.prunedNodes+=c,n.maxRetainedEntries=Math.max(n.maxRetainedEntries,b),i==="initial")n.initialSeeds++;else if(i==="activation-replacement")n.activationReplacementSeeds++;else if(i==="secondary")n.secondarySeeds++;else if(i==="hit-derived")n.hitDerivedSeeds++;if(a==="miss-budget")n.missBudgetDisables++;else if(a==="over-cap-hit")n.oversizedHitApproachDisables++;else if(a==="passive-probe-budget")n.passiveProbeBudgetDisables++;e({...r==="observing"?{observing:1}:r==="consulted-no-prune"?{consultedNoPrune:1}:{consultedPruned:1},mapProbes:s,prunedNodes:c,maxRetainedEntries:b,...i==="initial"?{initialSeeds:1}:i==="activation-replacement"?{activationReplacementSeeds:1}:i==="secondary"?{secondarySeeds:1}:i==="hit-derived"?{hitDerivedSeeds:1}:{},...a==="miss-budget"?{missBudgetDisables:1}:a==="over-cap-hit"?{oversizedHitApproachDisables:1}:a==="passive-probe-budget"?{passiveProbeBudgetDisables:1}:{}})}}),finish:()=>t?n:void 0})},Se=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,topologyDeltaProof:0,committed:0,scratch:0,hydration:0,newEdgeProofMemo:re(),reverseProof:{terminal:0,proven:0,pathPossible:0,budgetExhausted:0,disabled:0,activeFrames:0,unsupported:0,nodeVisits:0,dependentProbes:0,liveDependents:0,maxWork:0,maxFrontier:0,topologyDeltaSnapshot:ie()},lanes:{committed:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},scratch:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()},hydration:{prefixRevalidation:D(),newEdgeProof:D(),topologyDeltaProof:D()}}}}),W=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof,topologyDeltaProof:e.cycle.topologyDeltaProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),newEdgeProofMemo:se(e.cycle.newEdgeProofMemo),reverseProof:Object.freeze({...e.cycle.reverseProof,topologyDeltaSnapshot:ce(e.cycle.reverseProof.topologyDeltaSnapshot)}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.committed.topologyDeltaProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.scratch.topologyDeltaProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof}),topologyDeltaProof:Object.freeze({...e.cycle.lanes.hydration.topologyDeltaProof})})})})}),z=(e,n,t,o)=>{if(n.remaining--<=0||o>fe)return null;if(e===null)return null;if(typeof e==="string")return e.length<=H?e:e.slice(0,H);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(t.has(e))return null;t.add(e);try{if(Array.isArray(e)){let a=[],s=Math.min(e.length,B);for(let c=0;c<s;c++)a.push(z(e[c],n,t,o+1));return Object.freeze(a)}let r={},i=Object.keys(e).slice(0,B);for(let a of i){if(oe.has(a))continue;let s=Reflect.get(e,a);if(s===void 0)continue;r[a]=z(s,n,t,o+1)}return Object.freeze(r)}finally{t.delete(e)}},J=(e)=>{if(e===void 0)return Pe;let n={},t={remaining:be};for(let o of Object.keys(e).slice(0,B)){if(ye.has(o)||oe.has(o))continue;let r=e[o];if(r===void 0)continue;n[o]=z(r,t,new Set,0)}return Object.freeze(n)},Pe=Object.freeze({}),Re=(e,n)=>{if(n===void 0)return e;return Object.freeze({...e,...J(n)})},d=(e,n)=>n===void 0||!Number.isFinite(n)||n<=0?e:e+n,Ee=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return K;try{let n=e.then;return typeof n==="function"?{kind:"thenable",target:e,then:n}:K}catch(n){return{kind:"inspection-error",error:n}}},K=Object.freeze({kind:"not-thenable"});class de{#o;#e;#r;#u;#d="";#i=1;#g=1;#v=1;#S=1;#P=1;#R=1;#E=1;#x=1;#T=1;#n=[];#m=new WeakMap;#D=new WeakMap;#k=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#b;#C;constructor(e,n){this.#C=n,this.#r=G(e.capacity?.summaries,ue,"Inspection summary",!1),this.#u=G(e.capacity?.details,me,"Inspection detail",!0),this.#o=new j(this.#r),this.#e=new j(this.#u),this.#b=this.#p(),this.#w()}get recordingId(){return this.#d}registerStore(e,n){this.#k.set(e,n)}capture(e,n){let t=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=t===void 0?void 0:this.#k.get(t);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(n!==void 0){let a=typeof n==="object"&&n!==null||typeof n==="function"?n:void 0,s=o.coordinator.runtimeDomain;if(a===void 0||!s.states.has(a))throw TypeError("Inspection capture requires a valid State");let c=s.atoms.get(a),b=s.selectors.get(a);if(c===void 0&&b===void 0)throw TypeError("Inspection capture requires a valid State");let x=c?.name??b?.name;r=this.reference(a,c===void 0?"selector":"atom",typeof x==="string"?x:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#M(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#y()})}reference(e,n,t){if(this.#t!==void 0)return X;try{let o=this.#m.get(e);if(o===void 0)o=this.#T++,this.#m.set(e,o);let r=this.#D.get(e);if(r===void 0&&t!==void 0)r=Y(t),this.#D.set(e,r);return Object.freeze({id:o,kind:n,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),X}}sessionId(e){let n=this.#f.get(e);if(n!==void 0)return n;let t=this.#E++;return this.#f.set(e,t),t}beginInterval(e){if(this.#t!==void 0)return Q;try{let n=this.#V(e.type),t=Object.freeze({id:n,type:e.type}),o=Object.freeze({...this.#y(),...e.links}),r={token:t,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:Y(e.name),seqStart:this.#i++,startUs:this.#I(),fields:J(e.fields),totals:F.has(e.type)?Se():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:F.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#s("operation");if(i!==void 0)i.commitId=n}return this.#n.push(r),t}catch{return this.#c("begin-interval"),Q}}finishInterval(e,n={}){if(e.id===0||this.#t!==void 0)return;try{let t=this.#n.pop();if(t===void 0||!Object.is(t.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#j(t);let o=this.#i++,r=Math.max(0,this.#I()-t.startUs),i=Re(t.fields,n.fields),a=this.#A(t,o,r,i,n.result);if(F.has(t.token.type)){if(this.#o.add(a))this.#l++}else if(this.#e.add(a))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let n=this.#i++,t=Object.freeze({...J(e.fields),type:e.type,sequence:n,timeUs:this.#I(),...this.#y(),...e.links});if(this.#e.add(t))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let n of this.#n){let t=n.totals;if(t===void 0)continue;t.selectorEvaluations=d(t.selectorEvaluations,e.selectorEvaluations),t.proposedTopologyChanges=d(t.proposedTopologyChanges,e.proposedTopologyChanges),t.proposedTopologyIdentical=d(t.proposedTopologyIdentical,e.proposedTopologyIdentical),t.transientSelectorHostsCreated=d(t.transientSelectorHostsCreated,e.transientSelectorHostsCreated),t.propagationSettled=d(t.propagationSettled,e.propagationSettled),t.notificationTargets=d(t.notificationTargets,e.notificationTargets),t.subscriberCallbacks=d(t.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;t.cycle.searches=d(t.cycle.searches,o.searches),t.cycle.visits=d(t.cycle.visits,o.visits),t.cycle.maxVisits=Math.max(t.cycle.maxVisits,o.maxVisits??0),t.cycle.found=d(t.cycle.found,o.found);let r=o.newEdgeProofMemo;if(r!==void 0){let s=t.cycle.newEdgeProofMemo;s.admissionSkipped=d(s.admissionSkipped,r.admissionSkipped),s.observing=d(s.observing,r.observing),s.consultedNoPrune=d(s.consultedNoPrune,r.consultedNoPrune),s.consultedPruned=d(s.consultedPruned,r.consultedPruned),s.disabled=d(s.disabled,r.disabled),s.mapProbes=d(s.mapProbes,r.mapProbes),s.prunedNodes=d(s.prunedNodes,r.prunedNodes),s.graphVersionResets=d(s.graphVersionResets,r.graphVersionResets),s.initialSeeds=d(s.initialSeeds,r.initialSeeds),s.activationReplacementSeeds=d(s.activationReplacementSeeds,r.activationReplacementSeeds),s.secondarySeeds=d(s.secondarySeeds,r.secondarySeeds),s.hitDerivedSeeds=d(s.hitDerivedSeeds,r.hitDerivedSeeds),s.missBudgetDisables=d(s.missBudgetDisables,r.missBudgetDisables),s.oversizedHitApproachDisables=d(s.oversizedHitApproachDisables,r.oversizedHitApproachDisables),s.passiveProbeBudgetDisables=d(s.passiveProbeBudgetDisables,r.passiveProbeBudgetDisables),s.maxRetainedEntries=Math.max(s.maxRetainedEntries,r.maxRetainedEntries??0)}let i=o.topologyDeltaReverseSnapshot;if(i!==void 0)ae(t.cycle.reverseProof.topologyDeltaSnapshot,i);let a=o.reverseProof;if(a!==void 0){let s=t.cycle.reverseProof;if(a.outcome==="terminal")s.terminal++;else if(a.outcome==="proven")s.proven++;else if(a.outcome==="path-possible")s.pathPossible++;else if(a.outcome==="budget-exhausted")s.budgetExhausted++;else if(a.outcome==="disabled")s.disabled++;else if(a.outcome==="active-frames")s.activeFrames++;else s.unsupported++;s.nodeVisits=d(s.nodeVisits,a.nodeVisits),s.dependentProbes=d(s.dependentProbes,a.dependentProbes),s.liveDependents=d(s.liveDependents,a.liveDependents),s.maxWork=Math.max(s.maxWork,a.nodeVisits+a.dependentProbes),s.maxFrontier=Math.max(s.maxFrontier,a.maxFrontier)}if(o.site==="prefix-revalidation")t.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")t.cycle.newEdgeProof+=o.searches??1;else if(o.site==="topology-delta-proof")t.cycle.topologyDeltaProof+=o.searches??1;if(o.host!==void 0)t.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let s=o.site==="prefix-revalidation"?"prefixRevalidation":o.site==="new-edge-proof"?"newEdgeProof":"topologyDeltaProof",c=t.cycle.lanes[o.host][s];c.searches=d(c.searches,o.searches),c.visits=d(c.visits,o.visits),c.maxVisits=Math.max(c.maxVisits,o.maxVisits??0),c.found=d(c.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,n){let t=this.#s("operation"),o=t===void 0||!Object.is(t.token,e)||t.commitId===void 0||!t.commitSourceApplied?"none":n==="returned"?"committed":t.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:n,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,n){let t=this.#s("operation");if(t!==void 0)t.commitSourceApplied||=n.sourceApplied,t.commitFailurePhase=n.failurePhase;this.finishInterval(e,{result:n.result,fields:{intents:n.intents,...n.changedSources===void 0?{}:{changedSources:n.changedSources},...n.ownershipChanged===void 0?{}:{ownershipChanged:n.ownershipChanged},sourceApplied:n.sourceApplied,notificationsCompleted:n.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let n=e[0];if(n===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(n===1){let o=e[1]===0?"returned":"threw",r=this.#s("operation");if(r===void 0)return;let i=this.#s("commit");if(i!==void 0)this.#j(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(n===2){let o=this.#s("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(n===3){let o=this.#s("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let t=this.#s("operation");if(t!==void 0)t.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#s("operation")!==void 0}beginDraftCommit(e,n){this.recordStoreEvent(2),e.forEachIntent((t,o)=>{let r=n.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,t,t.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,n,t,o,r,i,a,s,c,b,x,k,I){let w=a===0?"prefix-revalidation":a===1?"new-edge-proof":"topology-delta-proof",h=this.beginInterval({type:"cycle-search",fields:{site:w,host:e,hostRef:n,start:this.#h(t),target:this.#h(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-b,acceptedPrefixLength:s,parentWasCold:x}}),m={nodeVisits:0,dependentProbes:0,liveDependents:0,maxFrontier:0},S=a===1||a===2?Z(t,o,r,i,m,a===1?k?.reverseProofEnabled??!0:I?.reverseProofEnabled??!0,I?.transientDependents):void 0;if(S==="budget-exhausted"){if(a===1&&k!==void 0)k.reverseProofEnabled=!1;else if(I!==void 0)I.reverseProofEnabled=!1}let M=S==="proven-terminal"||S==="proven-reverse",O=0,N=0,l=0,T=0,P=0,C=0,v;if(!M){let f=k?.(),R=f?.beginSearch()??!1,y=[t],u=new Map([[t,_]]);l=1;while(y.length>0){let g=y.pop();if(O++,Object.is(g,o)){let p=[],E=g;while(E!==_)p.push(E),E=u.get(E);p.reverse(),v=Object.freeze(p);break}let V=i.getTransientDependencies(r,g);if(V){if(T++,V.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=V.length;for(let p of V){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length;continue}if(r.getSelectorDependencyNodes!==void 0){let p=r.getSelectorDependencyNodes(g);if(p===void 0){C++;continue}if(P++,p.length===0)continue;if(R){let E=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(E)continue}N+=p.length;for(let E of p){if(u.has(E))continue;u.set(E,g),y.push(E)}if(y.length>l)l=y.length;continue}let A=r.getSelectorRecord(g);if(!A){C++;continue}if(P++,A.dependencies.length===0)continue;if(R){let p=f.hasProvenNoPathMeasured(g);if(!f.enabled)R=!1;if(p)continue}N+=A.dependencies.length;for(let p of A.dependencies){if(u.has(p.node))continue;u.set(p.node,g),y.push(p.node)}if(y.length>l)l=y.length}if(v===void 0)f?.completeNegative(u);else f?.completePositive()}return this.addWork({cycle:{searches:1,visits:O,maxVisits:O,found:v===void 0?0:1,site:w,host:e,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}}}}),this.finishInterval(h,{result:"returned",fields:{visits:O,edges:N,maxFrontier:l,transientExpansions:T,recordExpansions:P,terminalPrunes:C,...S===void 0?{}:{reverseProof:{outcome:L(S),...m}},found:v!==void 0,...v===void 0?{}:{path:v.map((f)=>this.#h(f))}}}),v}span(e,n){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof n!=="function")throw TypeError("Inspection span callback must be a function");let t=this.beginInterval({type:"span",name:e}),o;try{o=n()}catch(i){throw this.finishInterval(t,{result:"threw"}),i}let r=Ee(o);if(r.kind==="inspection-error")throw this.finishInterval(t,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,he])}catch{}throw this.finishInterval(t,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(t,{result:"returned"}),o}export(){this.#O("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),n=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),t=U(e),o=U(n);return Object.freeze({schema:"valdres.inspect",schemaVersion:5,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(n),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...t===void 0?{}:{summaries:t},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#O("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(n,t)=>e.capture(n,t),span:(n,t)=>e.span(n,t),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#d=`inspection-${Ie++}`,this.#o=new j(this.#r),this.#e=new j(this.#u),this.#i=1,this.#g=1,this.#v=1,this.#S=1,this.#P=1,this.#R=1,this.#E=1,this.#x=1,this.#T=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#b=this.#p()}#V(e){if(e==="span")return this.#g++;if(e==="operation")return this.#v++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#P++;if(e==="cycle-search")return this.#R++;return this.#x++}#y(){let e={};for(let n of this.#n){let{id:t,type:o}=n.token;if(n.links.sessionId!==void 0)e.sessionId=n.links.sessionId;if(o==="span")e.spanId=t;else if(o==="operation")e.operationId=t;else if(o==="commit")e.commitId=t;else if(o==="selector-evaluation")e.evaluationId=t;else if(o==="cycle-search")e.searchId=t}return e}#s(e){for(let n=this.#n.length-1;n>=0;n--){let t=this.#n[n];if(t.token.type===e)return t}return}#h(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):z(e,{remaining:1},new Set,0)}#A(e,n,t,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:n,startUs:e.startUs,durationUs:t,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:W(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:W(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:W(e.totals)});let a=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...a})}#O(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(n)=>this.#C.read(n);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#j(e){let n=e.counterStart;if(n===void 0)return;e.counterStart=void 0;let t=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=t.sourceEpoch!==n.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=t.transientSelectorHostsCreated-n.transientSelectorHostsCreated,o.propagationSettled+=t.propagationSettled-n.propagationSettled,o.notificationTargets+=t.notificationTargets-n.notificationTargets,o.subscriberCallbacks+=t.subscriberCallbacks-n.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let n=this.#i++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:n}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#M(e){return Math.max(0,Math.round((e-this.#b)*1000))}#I(){return this.#M(this.#p())}}var X=Object.freeze({id:0,kind:"store"}),Q=Object.freeze({id:0,type:"operation"}),xe=(e)=>{let n=(r,i,a,s)=>{if(e.hasActiveStoreOperation())return s();e.recordStoreEvent(0,r,i,i.name,a);try{let c=s();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof ne?1:0),c}},t=(r,i,a)=>{if(r===0){let s=i,c=a;e.registerStore(s,c);let b=s,x=s.set,k=s.update,I=s.reset,w=s.txn;b.set=(h,m)=>n(0,c,void 0,()=>x(h,m)),b.update=(h,m)=>n(1,c,void 0,()=>k(h,m)),b.reset=(h)=>n(2,c,void 0,()=>I(h)),b.txn=(h,m)=>{if(typeof h!=="function"||m!==void 0&&typeof m!=="string")return w(h,m);return n(3,c,m,()=>w(h,m))};return}if(r===1){e.beginDraftCommit(i,a);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(t,{evaluate:(r,i,a)=>{let s=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,b=e.reference(i,s==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),x=i.getSelectorGraphVersion(),k=a.getSelectorGraphPublicationCount(i),I=i.getSelectorRecord(r.node)?.dependencies,w=I?.length??0,h=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(a)},fields:{host:s,hostRef:b,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:x,previousDependencyCount:w}});e.addWork({selectorEvaluations:1});let m=ve((l)=>e.addWork({cycle:{newEdgeProofMemo:l}})),S=()=>{let l=m.finish();if(l===void 0)return;return se(l)},M=ge((l)=>e.addWork({cycle:{topologyDeltaReverseSnapshot:l}})),O=()=>{let l=M.finish();if(l===void 0)return;return ce(l)},N=(l,T,P,C,v,f,R,y)=>e.findDependencyPath(s,b,l,T,P,C,v,f,x,k,I===void 0,R,y);try{let l=ee(r,i,a,N,m.sink,M.sink),T=I===void 0||I.length!==l.dependencies.length||I.some((u,g)=>!Object.is(u.node,l.dependencies[g]?.node)),P=new Set(I?.map((u)=>u.node)),C=new Set(l.dependencies.map((u)=>u.node)),v=0,f=0;for(let u of C)if(!P.has(u))v++;for(let u of P)if(!C.has(u))f++;e.addWork(T?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1});let R=S(),y=O();return e.finishInterval(h,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:T,proposedEdgesAdded:v,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:R,topologyDeltaReverseSnapshot:y}}),l}catch(l){let T=S(),P=O();throw e.finishInterval(h,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion(),newEdgeProofMemo:T,topologyDeltaReverseSnapshot:P}}),l}}}),Object.freeze(t)},le=(e={})=>{let n=te(),t=new de(e,n);return Object.freeze({recorder:t,inspect:t.createInspector(),instrumentation:n,trace:xe(t)})};var Oe=(e={})=>{let{inspect:n,instrumentation:t,trace:o}=le(e),r=pe(t,o);return Object.freeze({store:r,inspect:n})};export{Oe as createInspectableStore};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as E,d as b,e as h,f as v,g as F,h as V,i as T,j as g,k,l as x,m as S,n as R,o as w,p as C,q as z,r as P,s as M,t as L,v as u}from"./chunk-kve4rdec.js";var _={ref:(e)=>new WeakRef(e),registry:(e)=>{let r=new FinalizationRegistry(e);return Object.freeze({register:(t,n,o)=>r.register(t,n,o),unregister:(t)=>r.unregister(t)})}},A={kind:"not-thenable"},J=()=>{},I=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return A;try{let r=e.then;return typeof r==="function"?Object.freeze({kind:"thenable",target:e,then:r}):A}catch(r){return Object.freeze({kind:"inspection-error",error:r})}},K=(e)=>{try{Reflect.apply(e.then,e.target,[void 0,J])}catch{}throw TypeError("Definition callbacks must complete synchronously")},j=(e,r,t,n,o)=>e(r,(...a)=>{let c;try{c=Reflect.apply(t,void 0,a)}catch(d){let y=I(d);if(y.kind==="not-thenable")throw d;if(y.kind==="inspection-error")throw y.error;return K(y)}let l=I(c);if(l.kind==="not-thenable")return c;if(l.kind==="inspection-error")throw l.error;return K(l)},n,o),Q=()=>TypeError("family cannot recursively construct the same member");class N{#e={parent:void 0,parentKey:void 0,children:void 0,entry:void 0};#r;#t;#n;constructor(e,r=_,t){this.#t=e,this.#n=t,this.#r=r.registry((n)=>{let o=n.route;if(o.entry!==n)return;o.entry=void 0,this.#l(o)}),this.#o=(n)=>r.ref(n)}#o;getOrCreateOne(e,r){return this.#i(this.#a(this.#e,e),r)}getOrCreateTuple(e,r){let t=this.#e;for(let n=0;n<e.length;n++)t=this.#a(t,e[n]);return this.#i(t,r)}get routeCount(){let e=0,r=(t)=>{if(t.children===void 0)return;for(let n of t.children.values())e++,r(n)};return r(this.#e),e}hasRoute(e){let r=this.#e;for(let t=0;t<e.length;t++){let n=r.children?.get(e[t]);if(n===void 0)return!1;r=n}return!0}#a(e,r){let t=e.children??(e.children=new Map),n=t.get(r);if(n!==void 0)return n;return n={parent:e,parentKey:r,children:void 0,entry:void 0},t.set(r,n),n}#i(e,r){let t=e.entry;if(t?.kind==="ready"){let o=t.reference.deref();if(o!==void 0)return o;if(this.#r.unregister(t),e.entry===t)e.entry=void 0}else if(t?.kind==="building"){let o=t.fault??Q();throw t.fault=o,o}let n={kind:"building",route:e,fault:void 0};e.entry=n;try{let o=this.#t(r);if(n.fault!==void 0)throw n.fault;this.#n?.(o);let a={kind:"ready",route:e,reference:this.#o(o)};return e.entry=a,this.#r.register(o,a,a),o}catch(o){if(e.entry===n)e.entry=void 0;throw this.#l(e),n.fault??o}}#l(e){let r=e;while(r.parent!==void 0&&r.entry===void 0&&(r.children===void 0||r.children.size===0)){let t=r.parent,n=t.children;if(n?.get(r.parentKey)!==r)return;if(n.delete(r.parentKey),n.size===0)t.children=void 0;r=t}}}var m=(e)=>e===null||e===void 0||typeof e!=="object"&&typeof e!=="function",O=()=>TypeError("family keys must be primitive; use encodeKey for structured arguments"),X=()=>TypeError("family encodeKey must return one primitive FamilyKey"),Y=()=>TypeError("family members require at least one key"),D=(e,r,t,n,o,a)=>{let c,l=new N((y)=>j(t,"factory",e,y,n),void 0,o),d={family(y){let s=arguments,p=c;if(p!==void 0){let i=p.fault??TypeError("family encodeKey cannot call its own family");throw p.fault=i,i}if(a(),s.length===0)throw Y();if(r!==void 0){let i={fault:void 0};c=i;let f;try{f=j(t,"encoder",r,s)}catch(G){throw i.fault??G}finally{c=void 0}if(i.fault!==void 0)throw i.fault;if(!m(f))throw X();return l.getOrCreateOne(f,s)}if(s.length===1){if(!m(y))throw O();return l.getOrCreateOne(y,s)}for(let i=0;i<s.length;i++)if(!m(s[i]))throw O();return l.getOrCreateTuple(s,s)}}.family;return Object.freeze(d)};var Z=(e,r={})=>u.atomLazy(e,r),q=(e,r={})=>u.atom(e,r);Object.defineProperty(q,"lazy",{configurable:!1,enumerable:!0,value:Z,writable:!1});var H=Object.freeze(q),W=(e,r={})=>u.selector(e,r),ee=(...e)=>{if(e.length===0||e.length>2)throw TypeError("family requires a State factory and options");let[r,t]=e;if(typeof r!=="function")throw TypeError("family requires a State factory function");if(t!==void 0&&(typeof t!=="object"||t===null))throw TypeError("family options must be an object");let n=t?.encodeKey;if(n!==void 0&&typeof n!=="function")throw TypeError("family encodeKey must be a function");return D(r,n,(o,a,c,l)=>z(u,o,a,c,l),(o)=>{let a=M(u,o);if(a===void 0)throw TypeError("family factories must construct or return a family State");return a},(o)=>L(u,o),()=>P(u))},B=ee;function U(){if(arguments.length!==0)throw TypeError("store() accepts no arguments");return u.createStoreTree()}var ce=H,ye=B,se=W,ue=U,de=v,pe=x,fe=k,me=g,Ee=C,be=b,he=R,ve=F,Fe=E,Ve=S,Te=w,ge=h,ke=T,xe=V;export{de as CallbackCapabilityError,pe as InvalidAtomComparatorResultError,fe as InvalidSynchronousAtomValueError,me as InvalidTransactionCallbackResultError,Ee as InvalidTransactionTargetError,be as RuntimeMismatchError,he as ScopeNotFoundError,ve as SelectorCapabilityError,Fe as SelectorCircularDependencyError,Ve as StoreDisposedError,Te as StoreTreeMismatchError,ge as SubscriberNotificationError,ke as TransactionClosedError,xe as TransactionPhaseError,ce as atom,ye as family,se as selector,ue as store};
|