valdres 1.0.0-beta.26 → 1.0.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,6 +74,6 @@ The versioned `valdres/adapter-internals/v1` entry is for framework bindings. It
74
74
 
75
75
  ## Beta compatibility
76
76
 
77
- `valdres@1.0.0-beta.24` and later v1 betas intentionally replace the legacy beta API. `valdres-react@1.0.0-beta.5` is certified with core versions accepted by its `^1.0.0-beta.24` peer range. Deferred framework adapters and plugins remain unsupported even when their published semver ranges allow npm to resolve this core; do not mix them with the new beta until they are migrated.
77
+ `valdres@1.0.0-beta.24` and later v1 betas intentionally replace the legacy beta API. `valdres-react@1.0.0-beta.6` is certified with `valdres@1.0.0-beta.27` and later v1 betas accepted by its `^1.0.0-beta.27` peer range. Deferred framework adapters and plugins remain unsupported even when their published semver ranges allow npm to resolve this core; do not mix them with the new beta until they are migrated.
78
78
 
79
79
  <!-- DOCS:END -->
@@ -1 +1 @@
1
- import{b as F,d as H,p as B,r as K}from"./chunk-wzf3zmr8.js";var X=2048,Q=1e5,V=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},J=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},_=(e)=>e.length<=V?e:e.slice(0,V),C=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:C(),newEdgeProof:C()},scratch:{prefixRevalidation:C(),newEdgeProof:C()},hydration:{prefixRevalidation:C(),newEdgeProof:C()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],c=Math.min(e.length,D);for(let d=0;d<c;d++)s.push(O(e[d],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let c=Reflect.get(e,s);if(c===void 0)continue;r[s]=O(c,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},P=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...P(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return q;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:q}catch(t){return{kind:"inspection-error",error:t}}},q=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#l;#p="";#s=1;#b=1;#g=1;#S=1;#v=1;#k=1;#T=1;#R=1;#C=1;#n=[];#u=new WeakMap;#E=new WeakMap;#m=new WeakMap;#d=0;#a=0;#t;#f;#x;constructor(e,t){this.#x=t,this.#r=J(e.capacity?.summaries,X,"Inspection summary",!1),this.#l=J(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#l),this.#f=this.#h(),this.#w()}get recordingId(){return this.#p}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#u.get(e);if(o===void 0)o=this.#C++,this.#u.set(e,o);let r=this.#E.get(e);if(r===void 0&&n!==void 0)r=_(n),this.#E.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#T++;return this.#m.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#P(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#O(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:_(e.name),seqStart:this.#s++,startUs:this.#I(),fields:P(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#D(n);let o=this.#s++,r=Math.max(0,this.#I()-n.startUs),i=se(n.fields,t.fields),s=this.#V(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#d++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...P(e.fields),type:e.type,sequence:t,timeUs:this.#I(),...this.#O(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#D(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,c,d,g){let T=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:T,host:e,hostRef:t,start:this.#y(n),target:this.#y(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-d,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:g}}),a=[n],I=new Map([[n,z]]),p=0,u=0,l=1,R=0,S=0,v=0,b;while(a.length>0){let f=a.pop();if(p++,Object.is(f,o)){let m=[],k=f;while(k!==z)m.push(k),k=I.get(k);m.reverse(),b=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){R++,u+=y.length;for(let m of y){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){v++;continue}S++,u+=m.length;for(let k of m){if(I.has(k))continue;I.set(k,f),a.push(k)}if(a.length>l)l=a.length;continue}let x=r.getSelectorRecord(f);if(!x){v++;continue}S++,u+=x.dependencies.length;for(let m of x.dependencies){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:b===void 0?0:1,site:T,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:R,recordExpansions:S,terminalPrunes:v,found:b!==void 0,...b===void 0?{}:{path:b.map((f)=>this.#y(f))}}}),b}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#j("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#p,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#d===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#d,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#j("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#p=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#l),this.#s=1,this.#b=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#R=1,this.#C=1,this.#n=[],this.#u=new WeakMap,this.#m=new WeakMap,this.#d=0,this.#a=0,this.#t=void 0,this.#f=this.#h()}#P(e){if(e==="span")return this.#b++;if(e==="operation")return this.#g++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#v++;if(e==="cycle-search")return this.#k++;return this.#R++}#O(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#y(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#V(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#j(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(t)=>this.#x.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#D(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#h(){return globalThis.performance?.now()??Date.now()}#I(){return Math.max(0,Math.round((this.#h()-this.#f)*1000))}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,c)=>{if(e.hasActiveStoreOperation())return c();e.recordStoreEvent(0,r,i,i.name,s);try{let d=c();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof H?1:0),d}},n=(r,i,s)=>{if(r===0){let c=i,d=s,g=c,T=c.set,E=c.update,a=c.reset,I=c.txn;g.set=(p,u)=>t(0,d,void 0,()=>T(p,u)),g.update=(p,u)=>t(1,d,void 0,()=>E(p,u)),g.reset=(p)=>t(2,d,void 0,()=>a(p)),g.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return I(p,u);return t(3,d,u,()=>I(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let c=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=i.name,g=e.reference(i,c==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),T=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),a=i.getSelectorRecord(r.node)?.dependencies,I=a?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:c,hostRef:g,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:T,previousDependencyCount:I}});e.addWork({selectorEvaluations:1});let u=(l,R,S,v,b)=>e.findDependencyPath(c,g,l,R,S,v,b,T,E,a===void 0);try{let l=F(r,i,s,u),R=a===void 0||a.length!==l.dependencies.length||a.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),S=new Set(a?.map((y)=>y.node)),v=new Set(l.dependencies.map((y)=>y.node)),b=0,f=0;for(let y of v)if(!S.has(y))b++;for(let y of S)if(!v.has(y))f++;return e.addWork(R?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:R,proposedEdgesAdded:b,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
1
+ import{b as F,d as H,p as B,r as K}from"./chunk-wzf3zmr8.js";var X=2048,Q=1e5,P=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},q=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},J=(e)=>e.length<=P?e:e.slice(0,P),R=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:R(),newEdgeProof:R()},scratch:{prefixRevalidation:R(),newEdgeProof:R()},hydration:{prefixRevalidation:R(),newEdgeProof:R()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,D);for(let c=0;c<a;c++)s.push(O(e[c],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=O(a,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},V=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...V(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return _;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:_}catch(t){return{kind:"inspection-error",error:t}}},_=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#T=1;#C=1;#R=1;#E=1;#n=[];#m=new WeakMap;#x=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#y;#O;constructor(e,t){this.#O=t,this.#r=q(e.capacity?.summaries,X,"Inspection summary",!1),this.#u=q(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#u),this.#y=this.#p(),this.#j()}get recordingId(){return this.#d}registerStore(e,t){this.#w.set(e,t)}capture(e,t){let n=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=n===void 0?void 0:this.#w.get(n);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(t!==void 0){let s=typeof t==="object"&&t!==null||typeof t==="function"?t:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let c=a.atoms.get(s),I=a.selectors.get(s);if(c===void 0&&I===void 0)throw TypeError("Inspection capture requires a valid State");let S=c?.name??I?.name;r=this.reference(s,c===void 0?"selector":"atom",typeof S==="string"?S:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#P(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#h()})}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#m.get(e);if(o===void 0)o=this.#E++,this.#m.set(e,o);let r=this.#x.get(e);if(r===void 0&&n!==void 0)r=J(n),this.#x.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#f.get(e);if(t!==void 0)return t;let n=this.#C++;return this.#f.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#A(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#h(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:J(e.name),seqStart:this.#s++,startUs:this.#b(),fields:V(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#D():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#V(n);let o=this.#s++,r=Math.max(0,this.#b()-n.startUs),i=se(n.fields,t.fields),s=this.#z(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#l++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...V(e.fields),type:e.type,sequence:t,timeUs:this.#b(),...this.#h(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#V(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,a,c,I){let S=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:t,start:this.#I(n),target:this.#I(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-a,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-c,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:I}}),d=[n],b=new Map([[n,z]]),p=0,u=0,l=1,C=0,v=0,k=0,g;while(d.length>0){let f=d.pop();if(p++,Object.is(f,o)){let m=[],T=f;while(T!==z)m.push(T),T=b.get(T);m.reverse(),g=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){C++,u+=y.length;for(let m of y){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){k++;continue}v++,u+=m.length;for(let T of m){if(b.has(T))continue;b.set(T,f),d.push(T)}if(d.length>l)l=d.length;continue}let x=r.getSelectorRecord(f);if(!x){k++;continue}v++,u+=x.dependencies.length;for(let m of x.dependencies){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:g===void 0?0:1,site:S,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:C,recordExpansions:v,terminalPrunes:k,found:g!==void 0,...g===void 0?{}:{path:g.map((f)=>this.#I(f))}}}),g}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#N("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#N("reset"),this.#j()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(t,n)=>e.capture(t,n),span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#j(){this.#d=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#C=1,this.#R=1,this.#E=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#A(e){if(e==="span")return this.#g++;if(e==="operation")return this.#S++;if(e==="commit")return this.#v++;if(e==="selector-evaluation")return this.#k++;if(e==="cycle-search")return this.#T++;return this.#R++}#h(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#I(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#z(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#N(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#D(){let e=(t)=>this.#O.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#V(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#D();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#P(e){return Math.max(0,Math.round((e-this.#y)*1000))}#b(){return this.#P(this.#p())}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let c=a();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof H?1:0),c}},n=(r,i,s)=>{if(r===0){let a=i,c=s;e.registerStore(a,c);let I=a,S=a.set,E=a.update,d=a.reset,b=a.txn;I.set=(p,u)=>t(0,c,void 0,()=>S(p,u)),I.update=(p,u)=>t(1,c,void 0,()=>E(p,u)),I.reset=(p)=>t(2,c,void 0,()=>d(p)),I.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return b(p,u);return t(3,c,u,()=>b(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,I=e.reference(i,a==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),S=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),d=i.getSelectorRecord(r.node)?.dependencies,b=d?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:I,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:S,previousDependencyCount:b}});e.addWork({selectorEvaluations:1});let u=(l,C,v,k,g)=>e.findDependencyPath(a,I,l,C,v,k,g,S,E,d===void 0);try{let l=F(r,i,s,u),C=d===void 0||d.length!==l.dependencies.length||d.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),v=new Set(d?.map((y)=>y.node)),k=new Set(l.dependencies.map((y)=>y.node)),g=0,f=0;for(let y of k)if(!v.has(y))g++;for(let y of v)if(!k.has(y))f++;return e.addWork(C?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:C,proposedEdgesAdded:g,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
package/dist/inspect.js CHANGED
@@ -1 +1 @@
1
- import{b as F,d as H,p as B,r as K}from"./chunk-wzf3zmr8.js";var X=2048,Q=1e5,V=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},J=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},_=(e)=>e.length<=V?e:e.slice(0,V),C=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:C(),newEdgeProof:C()},scratch:{prefixRevalidation:C(),newEdgeProof:C()},hydration:{prefixRevalidation:C(),newEdgeProof:C()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],c=Math.min(e.length,D);for(let d=0;d<c;d++)s.push(O(e[d],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let c=Reflect.get(e,s);if(c===void 0)continue;r[s]=O(c,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},P=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...P(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return q;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:q}catch(t){return{kind:"inspection-error",error:t}}},q=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#l;#p="";#s=1;#b=1;#g=1;#S=1;#v=1;#k=1;#T=1;#R=1;#C=1;#n=[];#u=new WeakMap;#E=new WeakMap;#m=new WeakMap;#d=0;#a=0;#t;#f;#x;constructor(e,t){this.#x=t,this.#r=J(e.capacity?.summaries,X,"Inspection summary",!1),this.#l=J(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#l),this.#f=this.#h(),this.#w()}get recordingId(){return this.#p}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#u.get(e);if(o===void 0)o=this.#C++,this.#u.set(e,o);let r=this.#E.get(e);if(r===void 0&&n!==void 0)r=_(n),this.#E.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#T++;return this.#m.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#P(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#O(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:_(e.name),seqStart:this.#s++,startUs:this.#I(),fields:P(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#N():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#D(n);let o=this.#s++,r=Math.max(0,this.#I()-n.startUs),i=se(n.fields,t.fields),s=this.#V(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#d++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...P(e.fields),type:e.type,sequence:t,timeUs:this.#I(),...this.#O(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#D(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,c,d,g){let T=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:T,host:e,hostRef:t,start:this.#y(n),target:this.#y(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-c,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-d,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:g}}),a=[n],I=new Map([[n,z]]),p=0,u=0,l=1,R=0,S=0,v=0,b;while(a.length>0){let f=a.pop();if(p++,Object.is(f,o)){let m=[],k=f;while(k!==z)m.push(k),k=I.get(k);m.reverse(),b=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){R++,u+=y.length;for(let m of y){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){v++;continue}S++,u+=m.length;for(let k of m){if(I.has(k))continue;I.set(k,f),a.push(k)}if(a.length>l)l=a.length;continue}let x=r.getSelectorRecord(f);if(!x){v++;continue}S++,u+=x.dependencies.length;for(let m of x.dependencies){if(I.has(m.node))continue;I.set(m.node,f),a.push(m.node)}if(a.length>l)l=a.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:b===void 0?0:1,site:T,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:R,recordExpansions:S,terminalPrunes:v,found:b!==void 0,...b===void 0?{}:{path:b.map((f)=>this.#y(f))}}}),b}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#j("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#p,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#d===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#d,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#j("reset"),this.#w()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#w(){this.#p=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#l),this.#s=1,this.#b=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#R=1,this.#C=1,this.#n=[],this.#u=new WeakMap,this.#m=new WeakMap,this.#d=0,this.#a=0,this.#t=void 0,this.#f=this.#h()}#P(e){if(e==="span")return this.#b++;if(e==="operation")return this.#g++;if(e==="commit")return this.#S++;if(e==="selector-evaluation")return this.#v++;if(e==="cycle-search")return this.#k++;return this.#R++}#O(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#y(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#V(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#j(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#N(){let e=(t)=>this.#x.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#D(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#N();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#h(){return globalThis.performance?.now()??Date.now()}#I(){return Math.max(0,Math.round((this.#h()-this.#f)*1000))}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,c)=>{if(e.hasActiveStoreOperation())return c();e.recordStoreEvent(0,r,i,i.name,s);try{let d=c();return e.recordStoreEvent(1,0),d}catch(d){throw e.recordStoreEvent(1,1,d instanceof H?1:0),d}},n=(r,i,s)=>{if(r===0){let c=i,d=s,g=c,T=c.set,E=c.update,a=c.reset,I=c.txn;g.set=(p,u)=>t(0,d,void 0,()=>T(p,u)),g.update=(p,u)=>t(1,d,void 0,()=>E(p,u)),g.reset=(p)=>t(2,d,void 0,()=>a(p)),g.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return I(p,u);return t(3,d,u,()=>I(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let c=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",d=i.name,g=e.reference(i,c==="committed"?"scope":"scratch-host",typeof d==="string"?d:void 0),T=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),a=i.getSelectorRecord(r.node)?.dependencies,I=a?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:c,hostRef:g,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:T,previousDependencyCount:I}});e.addWork({selectorEvaluations:1});let u=(l,R,S,v,b)=>e.findDependencyPath(c,g,l,R,S,v,b,T,E,a===void 0);try{let l=F(r,i,s,u),R=a===void 0||a.length!==l.dependencies.length||a.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),S=new Set(a?.map((y)=>y.node)),v=new Set(l.dependencies.map((y)=>y.node)),b=0,f=0;for(let y of v)if(!S.has(y))b++;for(let y of S)if(!v.has(y))f++;return e.addWork(R?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:R,proposedEdgesAdded:b,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
1
+ import{b as F,d as H,p as B,r as K}from"./chunk-wzf3zmr8.js";var X=2048,Q=1e5,P=256,A=1024,D=1e4,Z=32,ee=20000,j=new Set(["span","operation","commit"]),ne=new Set(["type","id","sequence","seqStart","seqEnd","startUs","durationUs","spanId","parentSpanId","operationId","commitId","evaluationId","searchId","name","result","totals"]),U=new Set(["value","previousValue","nextValue","resultValue","error","callback","updater"]),te=()=>{},z=Symbol("inspection dependency path root"),oe=1;class w{#o;#e=[];#r=0;constructor(e){this.#o=e}add(e){if(this.#o===0)return!0;if(this.#e.length<this.#o)return this.#e.push(e),!1;return this.#e[this.#r]=e,this.#r=(this.#r+1)%this.#o,!0}snapshot(){if(this.#e.length<this.#o||this.#r===0)return Object.freeze([...this.#e]);return Object.freeze([...this.#e.slice(this.#r),...this.#e.slice(0,this.#r)])}}var M=(e)=>{if(e.length===0)return;let t=Number.POSITIVE_INFINITY,n=0;for(let o of e){let r="sequence"in o?o.sequence:void 0;t=Math.min(t,o.seqStart??r??0),n=Math.max(n,o.seqEnd??r??0)}return Object.freeze({firstSequence:t,lastSequence:n})},q=(e,t,n,o)=>{let r=e??t;if(!Number.isSafeInteger(r)||r<(o?0:1))throw TypeError(`${n} capacity must be ${o?"a non-negative":"a positive"} safe integer`);return r},J=(e)=>e.length<=P?e:e.slice(0,P),R=()=>({searches:0,visits:0,maxVisits:0,found:0}),re=()=>({selectorEvaluations:0,proposedTopologyChanges:0,proposedTopologyIdentical:0,transientSelectorHostsCreated:0,propagationSettled:0,notificationTargets:0,subscriberCallbacks:0,cycle:{searches:0,visits:0,maxVisits:0,found:0,prefixRevalidation:0,newEdgeProof:0,committed:0,scratch:0,hydration:0,lanes:{committed:{prefixRevalidation:R(),newEdgeProof:R()},scratch:{prefixRevalidation:R(),newEdgeProof:R()},hydration:{prefixRevalidation:R(),newEdgeProof:R()}}}}),N=(e)=>Object.freeze({selectorEvaluations:e.selectorEvaluations,proposedTopologyChanges:e.proposedTopologyChanges,proposedTopologyIdentical:e.proposedTopologyIdentical,transientSelectorHostsCreated:e.transientSelectorHostsCreated,propagationSettled:e.propagationSettled,notificationTargets:e.notificationTargets,subscriberCallbacks:e.subscriberCallbacks,cycle:Object.freeze({searches:e.cycle.searches,visits:e.cycle.visits,maxVisits:e.cycle.maxVisits,found:e.cycle.found,bySite:Object.freeze({prefixRevalidation:e.cycle.prefixRevalidation,newEdgeProof:e.cycle.newEdgeProof}),byHost:Object.freeze({committed:e.cycle.committed,scratch:e.cycle.scratch,hydration:e.cycle.hydration}),byLane:Object.freeze({committed:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.committed.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.committed.newEdgeProof})}),scratch:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.scratch.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.scratch.newEdgeProof})}),hydration:Object.freeze({prefixRevalidation:Object.freeze({...e.cycle.lanes.hydration.prefixRevalidation}),newEdgeProof:Object.freeze({...e.cycle.lanes.hydration.newEdgeProof})})})})}),O=(e,t,n,o)=>{if(t.remaining--<=0||o>Z)return null;if(e===null)return null;if(typeof e==="string")return e.length<=A?e:e.slice(0,A);if(typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:null;if(typeof e!=="object")return null;if(n.has(e))return null;n.add(e);try{if(Array.isArray(e)){let s=[],a=Math.min(e.length,D);for(let c=0;c<a;c++)s.push(O(e[c],t,n,o+1));return Object.freeze(s)}let r={},i=Object.keys(e).slice(0,D);for(let s of i){if(U.has(s))continue;let a=Reflect.get(e,s);if(a===void 0)continue;r[s]=O(a,t,n,o+1)}return Object.freeze(r)}finally{n.delete(e)}},V=(e)=>{if(e===void 0)return ie;let t={},n={remaining:ee};for(let o of Object.keys(e).slice(0,D)){if(ne.has(o)||U.has(o))continue;let r=e[o];if(r===void 0)continue;t[o]=O(r,n,new Set,0)}return Object.freeze(t)},ie=Object.freeze({}),se=(e,t)=>{if(t===void 0)return e;return Object.freeze({...e,...V(t)})},h=(e,t)=>t===void 0||!Number.isFinite(t)||t<=0?e:e+t,ae=(e)=>{if((typeof e!=="object"||e===null)&&typeof e!=="function")return _;try{let t=e.then;return typeof t==="function"?{kind:"thenable",target:e,then:t}:_}catch(t){return{kind:"inspection-error",error:t}}},_=Object.freeze({kind:"not-thenable"});class G{#o;#e;#r;#u;#d="";#s=1;#g=1;#S=1;#v=1;#k=1;#T=1;#C=1;#R=1;#E=1;#n=[];#m=new WeakMap;#x=new WeakMap;#w=new WeakMap;#f=new WeakMap;#l=0;#a=0;#t;#y;#O;constructor(e,t){this.#O=t,this.#r=q(e.capacity?.summaries,X,"Inspection summary",!1),this.#u=q(e.capacity?.details,Q,"Inspection detail",!0),this.#o=new w(this.#r),this.#e=new w(this.#u),this.#y=this.#p(),this.#j()}get recordingId(){return this.#d}registerStore(e,t){this.#w.set(e,t)}capture(e,t){let n=typeof e==="object"&&e!==null||typeof e==="function"?e:void 0,o=n===void 0?void 0:this.#w.get(n);if(o===void 0)throw TypeError("Inspection capture requires a Store owned by this inspector");let r;if(t!==void 0){let s=typeof t==="object"&&t!==null||typeof t==="function"?t:void 0,a=o.coordinator.runtimeDomain;if(s===void 0||!a.states.has(s))throw TypeError("Inspection capture requires a valid State");let c=a.atoms.get(s),I=a.selectors.get(s);if(c===void 0&&I===void 0)throw TypeError("Inspection capture requires a valid State");let S=c?.name??I?.name;r=this.reference(s,c===void 0?"selector":"atom",typeof S==="string"?S:void 0)}let i=this.#p();return Object.freeze({recordingId:this.#d,timeUs:this.#P(i),monotonicTimeMs:i,store:this.reference(o,"scope",o.name),...r===void 0?{}:{state:r},...this.#h()})}reference(e,t,n){if(this.#t!==void 0)return L;try{let o=this.#m.get(e);if(o===void 0)o=this.#E++,this.#m.set(e,o);let r=this.#x.get(e);if(r===void 0&&n!==void 0)r=J(n),this.#x.set(e,r);return Object.freeze({id:o,kind:t,...r===void 0?{}:{name:r}})}catch{return this.#c("reference"),L}}sessionId(e){let t=this.#f.get(e);if(t!==void 0)return t;let n=this.#C++;return this.#f.set(e,n),n}beginInterval(e){if(this.#t!==void 0)return W;try{let t=this.#A(e.type),n=Object.freeze({id:t,type:e.type}),o=Object.freeze({...this.#h(),...e.links}),r={token:n,parentId:this.#n[this.#n.length-1]?.token.id,links:o,name:e.name===void 0?void 0:J(e.name),seqStart:this.#s++,startUs:this.#b(),fields:V(e.fields),totals:j.has(e.type)?re():void 0,commitId:void 0,commitSourceApplied:!1,commitChangedSources:void 0,commitOwnershipChanged:void 0,commitFailurePhase:void 0,operationIntents:0,counterStart:j.has(e.type)?this.#D():void 0};if(e.type==="commit"){let i=this.#i("operation");if(i!==void 0)i.commitId=t}return this.#n.push(r),n}catch{return this.#c("begin-interval"),W}}finishInterval(e,t={}){if(e.id===0||this.#t!==void 0)return;try{let n=this.#n.pop();if(n===void 0||!Object.is(n.token,e))throw Error("Inspection intervals must finish in LIFO order");this.#V(n);let o=this.#s++,r=Math.max(0,this.#b()-n.startUs),i=se(n.fields,t.fields),s=this.#z(n,o,r,i,t.result);if(j.has(n.token.type)){if(this.#o.add(s))this.#l++}else if(this.#e.add(s))this.#a++}catch{this.#c("finish-interval")}}record(e){if(this.#t!==void 0)return;try{let t=this.#s++,n=Object.freeze({...V(e.fields),type:e.type,sequence:t,timeUs:this.#b(),...this.#h(),...e.links});if(this.#e.add(n))this.#a++}catch{this.#c("record-detail")}}addWork(e){if(this.#t!==void 0)return;try{for(let t of this.#n){let n=t.totals;if(n===void 0)continue;n.selectorEvaluations=h(n.selectorEvaluations,e.selectorEvaluations),n.proposedTopologyChanges=h(n.proposedTopologyChanges,e.proposedTopologyChanges),n.proposedTopologyIdentical=h(n.proposedTopologyIdentical,e.proposedTopologyIdentical),n.transientSelectorHostsCreated=h(n.transientSelectorHostsCreated,e.transientSelectorHostsCreated),n.propagationSettled=h(n.propagationSettled,e.propagationSettled),n.notificationTargets=h(n.notificationTargets,e.notificationTargets),n.subscriberCallbacks=h(n.subscriberCallbacks,e.subscriberCallbacks);let o=e.cycle;if(o===void 0)continue;if(n.cycle.searches=h(n.cycle.searches,o.searches),n.cycle.visits=h(n.cycle.visits,o.visits),n.cycle.maxVisits=Math.max(n.cycle.maxVisits,o.maxVisits??0),n.cycle.found=h(n.cycle.found,o.found),o.site==="prefix-revalidation")n.cycle.prefixRevalidation+=o.searches??1;else if(o.site==="new-edge-proof")n.cycle.newEdgeProof+=o.searches??1;if(o.host!==void 0)n.cycle[o.host]+=o.searches??1;if(o.host!==void 0&&o.site!==void 0){let r=o.site==="prefix-revalidation"?"prefixRevalidation":"newEdgeProof",i=n.cycle.lanes[o.host][r];i.searches=h(i.searches,o.searches),i.visits=h(i.visits,o.visits),i.maxVisits=Math.max(i.maxVisits,o.maxVisits??0),i.found=h(i.found,o.found)}}}catch{this.#c("add-work")}}beginStoreOperation(e){return this.beginInterval({type:"operation",...e.name===void 0?{}:{name:e.name},fields:{operation:e.operation,scope:this.reference(e.scope,"scope",e.scopeName)}})}finishStoreOperation(e,t){let n=this.#i("operation"),o=n===void 0||!Object.is(n.token,e)||n.commitId===void 0||!n.commitSourceApplied?"none":t==="returned"?"committed":n.commitFailurePhase==="notify"?"committed-with-notification-error":"committed-with-propagation-error";this.finishInterval(e,{result:t,fields:{effect:o}})}beginStoreCommit(e){return this.beginInterval({type:"commit",links:{operationId:e.id}})}finishStoreCommit(e,t){let n=this.#i("operation");if(n!==void 0)n.commitSourceApplied||=t.sourceApplied,n.commitFailurePhase=t.failurePhase;this.finishInterval(e,{result:t.result,fields:{intents:t.intents,...t.changedSources===void 0?{}:{changedSources:t.changedSources},...t.ownershipChanged===void 0?{}:{ownershipChanged:t.ownershipChanged},sourceApplied:t.sourceApplied,notificationsCompleted:t.notificationsCompleted}})}recordStoreIntent(e){this.record({type:"intent",fields:{intent:e.intent,scope:this.reference(e.scope,"scope",e.scopeName),atom:this.reference(e.atom,"atom",e.atomName)}})}recordStoreEvent(...e){let t=e[0];if(t===0){let o=["set","update","reset","transaction"][e[1]];this.beginStoreOperation({operation:o,scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},...e[4]===void 0?{}:{name:e[4]}});return}if(t===1){let o=e[1]===0?"returned":"threw",r=this.#i("operation");if(r===void 0)return;let i=this.#i("commit");if(i!==void 0)this.#V(i),this.finishStoreCommit(i.token,{result:o,intents:r.operationIntents,...i.commitChangedSources===void 0?{}:{changedSources:i.commitChangedSources},...i.commitOwnershipChanged===void 0?{}:{ownershipChanged:i.commitOwnershipChanged},sourceApplied:i.commitSourceApplied,notificationsCompleted:o==="returned",...e[2]===void 0?{}:{failurePhase:e[2]===1?"notify":"propagate"}});this.finishStoreOperation(r.token,o);return}if(t===2){let o=this.#i("operation");if(o!==void 0)this.beginStoreCommit(o.token);return}if(t===3){let o=this.#i("commit");if(o!==void 0)o.commitSourceApplied=!0,o.commitChangedSources=e[1];return}let n=this.#i("operation");if(n!==void 0)n.operationIntents++;this.recordStoreIntent({intent:e[1]===0?"set":"reset",scope:e[2],...e[3]===void 0?{}:{scopeName:e[3]},atom:e[4],...e[5]===void 0?{}:{atomName:e[5]}})}hasActiveStoreOperation(){return this.#i("operation")!==void 0}beginDraftCommit(e,t){this.recordStoreEvent(2),e.forEachIntent((n,o)=>{let r=t.get(o.atom)?.name;this.recordStoreEvent(5,o.kind==="set"?0:2,n,n.name,o.atom,typeof r==="string"?r:void 0)})}findDependencyPath(e,t,n,o,r,i,s,a,c,I){let S=s===0?"prefix-revalidation":"new-edge-proof",E=this.beginInterval({type:"cycle-search",fields:{site:S,host:e,hostRef:t,start:this.#I(n),target:this.#I(o),graphVersion:r.getSelectorGraphVersion(),attributedSessionPublications:i.getSelectorGraphPublicationCount(r),evaluationGraphVersionDelta:r.getSelectorGraphVersion()-a,evaluationAttributedPublicationDelta:i.getSelectorGraphPublicationCount(r)-c,acceptedPrefixLength:i.getTransientDependencies(r,o)?.length??0,parentWasCold:I}}),d=[n],b=new Map([[n,z]]),p=0,u=0,l=1,C=0,v=0,k=0,g;while(d.length>0){let f=d.pop();if(p++,Object.is(f,o)){let m=[],T=f;while(T!==z)m.push(T),T=b.get(T);m.reverse(),g=Object.freeze(m);break}let y=i.getTransientDependencies(r,f);if(y){C++,u+=y.length;for(let m of y){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length;continue}if(r.getSelectorDependencyNodes!==void 0){let m=r.getSelectorDependencyNodes(f);if(m===void 0){k++;continue}v++,u+=m.length;for(let T of m){if(b.has(T))continue;b.set(T,f),d.push(T)}if(d.length>l)l=d.length;continue}let x=r.getSelectorRecord(f);if(!x){k++;continue}v++,u+=x.dependencies.length;for(let m of x.dependencies){if(b.has(m.node))continue;b.set(m.node,f),d.push(m.node)}if(d.length>l)l=d.length}return this.addWork({cycle:{searches:1,visits:p,maxVisits:p,found:g===void 0?0:1,site:S,host:e}}),this.finishInterval(E,{result:"returned",fields:{visits:p,edges:u,maxFrontier:l,transientExpansions:C,recordExpansions:v,terminalPrunes:k,found:g!==void 0,...g===void 0?{}:{path:g.map((f)=>this.#I(f))}}}),g}span(e,t){if(typeof e!=="string")throw TypeError("Inspection span name must be a string");if(typeof t!=="function")throw TypeError("Inspection span callback must be a function");let n=this.beginInterval({type:"span",name:e}),o;try{o=t()}catch(i){throw this.finishInterval(n,{result:"threw"}),i}let r=ae(o);if(r.kind==="inspection-error")throw this.finishInterval(n,{result:"threw"}),r.error;if(r.kind==="thenable"){try{Reflect.apply(r.then,r.target,[void 0,te])}catch{}throw this.finishInterval(n,{result:"async-rejected"}),TypeError("Inspection spans must be synchronous")}return this.finishInterval(n,{result:"returned"}),o}export(){this.#N("export");let e=[...this.#o.snapshot()].sort((r,i)=>r.seqStart-i.seqStart),t=[...this.#e.snapshot()].sort((r,i)=>(r.seqStart??r.sequence??0)-(i.seqStart??i.sequence??0)),n=M(e),o=M(t);return Object.freeze({schema:"valdres.inspect",schemaVersion:1,recordingId:this.#d,summaries:Object.freeze(e),details:Object.freeze(t),complete:this.#l===0&&this.#a===0&&this.#t===void 0,overflow:Object.freeze({summaries:this.#l,details:this.#a,retained:Object.freeze({...n===void 0?{}:{summaries:n},...o===void 0?{}:{details:o}})}),...this.#t===void 0?{}:{fault:this.#t}})}reset(){this.#N("reset"),this.#j()}createInspector(){let e=this;return Object.freeze({get recordingId(){return e.recordingId},capture:(t,n)=>e.capture(t,n),span:(t,n)=>e.span(t,n),export:()=>e.export(),reset:()=>e.reset()})}#j(){this.#d=`inspection-${oe++}`,this.#o=new w(this.#r),this.#e=new w(this.#u),this.#s=1,this.#g=1,this.#S=1,this.#v=1,this.#k=1,this.#T=1,this.#C=1,this.#R=1,this.#E=1,this.#n=[],this.#m=new WeakMap,this.#f=new WeakMap,this.#l=0,this.#a=0,this.#t=void 0,this.#y=this.#p()}#A(e){if(e==="span")return this.#g++;if(e==="operation")return this.#S++;if(e==="commit")return this.#v++;if(e==="selector-evaluation")return this.#k++;if(e==="cycle-search")return this.#T++;return this.#R++}#h(){let e={};for(let t of this.#n){let{id:n,type:o}=t.token;if(t.links.sessionId!==void 0)e.sessionId=t.links.sessionId;if(o==="span")e.spanId=n;else if(o==="operation")e.operationId=n;else if(o==="commit")e.commitId=n;else if(o==="selector-evaluation")e.evaluationId=n;else if(o==="cycle-search")e.searchId=n}return e}#i(e){for(let t=this.#n.length-1;t>=0;t--){let n=this.#n[t];if(n.token.type===e)return n}return}#I(e){return typeof e==="object"&&e!==null||typeof e==="function"?this.reference(e,"state"):O(e,{remaining:1},new Set,0)}#z(e,t,n,o,r){let i={...o,type:e.token.type,seqStart:e.seqStart,seqEnd:t,startUs:e.startUs,durationUs:n,...e.links};if(e.token.type==="span")return Object.freeze({...i,type:"span",spanId:e.token.id,...e.links.spanId===void 0?{}:{parentSpanId:e.links.spanId},name:e.name??"",result:r??"returned",totals:N(e.totals)});if(e.token.type==="operation")return Object.freeze({...i,type:"operation",operationId:e.token.id,...e.name===void 0?{}:{name:e.name},...e.commitId===void 0?{}:{commitId:e.commitId},result:r==="threw"||r==="async-rejected"?"threw":"returned",effect:o.effect??(e.commitId===void 0?"none":"committed"),totals:N(e.totals)});if(e.token.type==="commit")return Object.freeze({...i,type:"commit",commitId:e.token.id,operationId:e.links.operationId??0,intents:o.intents??0,changedSources:o.changedSources??0,ownershipChanged:o.ownershipChanged??!1,sourceApplied:o.sourceApplied??!0,notificationsCompleted:o.notificationsCompleted??!0,totals:N(e.totals)});let s=e.token.type==="selector-evaluation"?{evaluationId:e.token.id}:e.token.type==="cycle-search"?{searchId:e.token.id}:{id:e.token.id};return Object.freeze({...i,...s})}#N(e){if(this.#n.length!==0)throw Error(`Inspection ${e} requires an idle Store`)}#D(){let e=(t)=>this.#O.read(t);return{sourceEpoch:e("sourceEpoch"),transientSelectorHostsCreated:e("scratchHostAllocations"),propagationSettled:e("propagationSettlements"),notificationTargets:e("notificationTargetsReached"),subscriberCallbacks:e("subscriberCallbacksAttempted")}}#V(e){let t=e.counterStart;if(t===void 0)return;e.counterStart=void 0;let n=this.#D();if(e.token.type==="commit")e.commitOwnershipChanged=n.sourceEpoch!==t.sourceEpoch;let o=e.totals;if(o===void 0)return;o.transientSelectorHostsCreated+=n.transientSelectorHostsCreated-t.transientSelectorHostsCreated,o.propagationSettled+=n.propagationSettled-t.propagationSettled,o.notificationTargets+=n.notificationTargets-t.notificationTargets,o.subscriberCallbacks+=n.subscriberCallbacks-t.subscriberCallbacks}#c(e){if(this.#t!==void 0)return;let t=this.#s++;this.#t=Object.freeze({type:"recorder-fault",phase:e,sequence:t}),this.#n=[]}#p(){return globalThis.performance?.now()??Date.now()}#P(e){return Math.max(0,Math.round((e-this.#y)*1000))}#b(){return this.#P(this.#p())}}var L=Object.freeze({id:0,kind:"store"}),W=Object.freeze({id:0,type:"operation"}),ce=(e)=>{let t=(r,i,s,a)=>{if(e.hasActiveStoreOperation())return a();e.recordStoreEvent(0,r,i,i.name,s);try{let c=a();return e.recordStoreEvent(1,0),c}catch(c){throw e.recordStoreEvent(1,1,c instanceof H?1:0),c}},n=(r,i,s)=>{if(r===0){let a=i,c=s;e.registerStore(a,c);let I=a,S=a.set,E=a.update,d=a.reset,b=a.txn;I.set=(p,u)=>t(0,c,void 0,()=>S(p,u)),I.update=(p,u)=>t(1,c,void 0,()=>E(p,u)),I.reset=(p)=>t(2,c,void 0,()=>d(p)),I.txn=(p,u)=>{if(typeof p!=="function"||u!==void 0&&typeof u!=="string")return b(p,u);return t(3,c,u,()=>b(p,u))};return}if(r===1){e.beginDraftCommit(i,s);return}if(r===2)e.recordStoreEvent(3,i)};return Object.assign(n,{evaluate:(r,i,s)=>{let a=i.getSelectorDependencyNodes!==void 0?"committed":e.hasActiveStoreOperation()?"scratch":"hydration",c=i.name,I=e.reference(i,a==="committed"?"scope":"scratch-host",typeof c==="string"?c:void 0),S=i.getSelectorGraphVersion(),E=s.getSelectorGraphPublicationCount(i),d=i.getSelectorRecord(r.node)?.dependencies,b=d?.length??0,p=e.beginInterval({type:"selector-evaluation",links:{sessionId:e.sessionId(s)},fields:{host:a,hostRef:I,selector:e.reference(r.node,"selector",typeof r.name==="string"?r.name:void 0),graphVersionStart:S,previousDependencyCount:b}});e.addWork({selectorEvaluations:1});let u=(l,C,v,k,g)=>e.findDependencyPath(a,I,l,C,v,k,g,S,E,d===void 0);try{let l=F(r,i,s,u),C=d===void 0||d.length!==l.dependencies.length||d.some((y,x)=>!Object.is(y.node,l.dependencies[x]?.node)),v=new Set(d?.map((y)=>y.node)),k=new Set(l.dependencies.map((y)=>y.node)),g=0,f=0;for(let y of k)if(!v.has(y))g++;for(let y of v)if(!k.has(y))f++;return e.addWork(C?{proposedTopologyChanges:1}:{proposedTopologyIdentical:1}),e.finishInterval(p,{result:"returned",fields:{outcome:l.outcome.kind,dependencyCount:l.dependencies.length,proposedTopologyChanged:C,proposedEdgesAdded:g,proposedEdgesRemoved:f,graphVersionEnd:i.getSelectorGraphVersion()}}),l}catch(l){throw e.finishInterval(p,{result:"threw",fields:{outcome:"threw",graphVersionEnd:i.getSelectorGraphVersion()}}),l}}}),Object.freeze(n)},Y=(e={})=>{let t=B(),n=new G(e,t);return Object.freeze({recorder:n,inspect:n.createInspector(),instrumentation:t,trace:ce(n)})};var fe=(e={})=>{let{inspect:t,instrumentation:n,trace:o}=Y(e),r=K(n,o);return Object.freeze({store:r,inspect:t})};export{fe as createInspectableStore};
@@ -1,5 +1,5 @@
1
1
  import type { Store } from "./v1.js";
2
- import type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StoreInspector } from "./v1-internal/inspection.js";
2
+ import type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector } from "./v1-internal/inspection.js";
3
3
  export interface InspectableStoreResult {
4
4
  readonly store: Store;
5
5
  readonly inspect: StoreInspector;
@@ -9,4 +9,4 @@ export interface InspectableStoreResult {
9
9
  * State values, callbacks, and Store internals never enter the recording.
10
10
  */
11
11
  export declare const createInspectableStore: (options?: InspectableStoreOptions) => InspectableStoreResult;
12
- export type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StoreInspector, };
12
+ export type { CommitInspection, CycleSearchInspectionDetail, InspectableStoreOptions, InspectionCycleBucket, InspectionCycleTotals, InspectionCapture, InspectionDetail, InspectionDetailType, InspectionExport, InspectionJsonObject, InspectionJsonPrimitive, InspectionJsonValue, InspectionOverflow, InspectionRecorderFault, InspectionReference, InspectionReferenceKind, InspectionSummary, InspectionWorkTotals, OperationInspection, IntentInspectionDetail, SelectorEvaluationInspectionDetail, SpanInspection, StateInspectionCapture, StoreInspector, };
@@ -1,4 +1,5 @@
1
1
  import { type InternalStoreTreeInstrumentation, type InternalStoreTreeTrace } from "./committed-store-tree/committed-store-tree.js";
2
+ import type { CommittedStoreTree, State } from "./committed-store-tree/types.js";
2
3
  import type { SelectorCycleSearchSite, SelectorEvaluationHost, SelectorEvaluationSession } from "./selector-evaluator/types.js";
3
4
  type StoreRecorderEvent = readonly [
4
5
  event: 0,
@@ -211,9 +212,28 @@ export interface InspectableStoreOptions {
211
212
  details?: number;
212
213
  }>;
213
214
  }
215
+ /** A point-in-time, value-free correlation token for companion adapters. */
216
+ export interface InspectionCapture {
217
+ readonly recordingId: string;
218
+ readonly timeUs: number;
219
+ readonly monotonicTimeMs: number;
220
+ readonly store: InspectionReference;
221
+ readonly state?: InspectionReference;
222
+ readonly spanId?: number;
223
+ readonly operationId?: number;
224
+ readonly commitId?: number;
225
+ readonly sessionId?: number;
226
+ readonly evaluationId?: number;
227
+ readonly searchId?: number;
228
+ }
229
+ export interface StateInspectionCapture extends InspectionCapture {
230
+ readonly state: InspectionReference;
231
+ }
214
232
  type SynchronousInspectionResult<Result> = Result extends PromiseLike<unknown> ? never : Result;
215
233
  export interface StoreInspector {
216
234
  readonly recordingId: string;
235
+ capture(store: CommittedStoreTree): InspectionCapture;
236
+ capture<Value>(store: CommittedStoreTree, state: State<Value>): StateInspectionCapture;
217
237
  span<Result>(name: string, callback: () => SynchronousInspectionResult<Result>): Result;
218
238
  export(): InspectionExport;
219
239
  reset(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valdres",
3
3
  "description": "Fast atom-based state management for JavaScript. Inspired by Recoil and Jotai.",
4
- "version": "1.0.0-beta.26",
4
+ "version": "1.0.0-beta.27",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Eigil Sagafos"