@raphy-js/raph 1.0.1-dev.25 → 1.0.1-dev.54
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 +100 -0
- package/dist/api/Raph.d.ts +15 -15
- package/dist/api/RaphFacadeSession.d.ts +4 -4
- package/dist/api/RaphReactivityInstance.d.ts +4 -4
- package/dist/api/types.d.ts +11 -11
- package/dist/compact.cjs +1 -0
- package/dist/compact.js +4 -0
- package/dist/debug/reactivity/engine-core.cjs +1 -0
- package/dist/debug/reactivity/engine-core.js +1760 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +25 -1689
- package/dist/debug/reactivity/reactive-object.cjs +1 -1
- package/dist/debug/reactivity/reactive-object.js +604 -167
- package/dist/debug/runtime/RaphCompactExecutionRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphCompactExecutionRuntime.js +9 -0
- package/dist/debug/runtime/RaphExecutionRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphExecutionRuntime.js +11 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +115 -1176
- package/dist/debug/runtime/RaphRuntimeBase.cjs +1 -0
- package/dist/debug/runtime/RaphRuntimeBase.js +941 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
- package/dist/debug/runtime/diagnostics/RaphDebug.js +72 -66
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphNode.js +11 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphScope.js +12 -12
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +361 -242
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +23 -22
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -1
- package/dist/debug/runtime/reactivity/RaphSelector.js +111 -90
- package/dist/debug/runtime/reactivity/RuntimeObjectSupport.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeObjectSupport.js +11 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +118 -103
- package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.js +12 -0
- package/dist/entrypoints/compact.d.ts +2 -0
- package/dist/entrypoints/execution.d.ts +2 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -2
- package/dist/entrypoints/machine.d.ts +5 -5
- package/dist/entrypoints/observable.d.ts +4 -0
- package/dist/entrypoints/path.d.ts +14 -14
- package/dist/entrypoints/reactivity.d.ts +1 -1
- package/dist/entrypoints/runtime.d.ts +19 -18
- package/dist/execution.cjs +1 -0
- package/dist/execution.js +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +23 -21
- package/dist/machine/compiler.d.ts +1 -1
- package/dist/machine/core.d.ts +2 -2
- package/dist/machine/persistence.d.ts +1 -1
- package/dist/machine/runtime.d.ts +3 -3
- package/dist/machine/testing.d.ts +1 -1
- package/dist/machine/types.d.ts +3 -3
- package/dist/main.d.ts +19 -19
- package/dist/observable/buffer.d.ts +6 -0
- package/dist/observable/class-admin.d.ts +63 -0
- package/dist/observable/class-plan.d.ts +46 -0
- package/dist/observable/classes.d.ts +10 -0
- package/dist/observable/context.d.ts +73 -0
- package/dist/observable/native.d.ts +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/types.d.ts +60 -0
- package/dist/observable.cjs +1 -0
- package/dist/observable.js +1187 -0
- package/dist/path/DataPath.d.ts +2 -2
- package/dist/path/PathRouter.d.ts +1 -1
- package/dist/path/RaphKernel.d.ts +6 -6
- package/dist/path/data-path.types.d.ts +1 -1
- package/dist/path/data-path.utils.d.ts +2 -2
- package/dist/path/derived/DerivedRegistry.d.ts +3 -3
- package/dist/path/derived/RaphDerivedHandle.d.ts +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +1 -1
- package/dist/path/derived/derived-collection.utils.d.ts +3 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +1 -1
- package/dist/path/meta/MetaController.d.ts +5 -5
- package/dist/path/meta/RaphMeta.d.ts +3 -3
- package/dist/path/meta/RaphMetaStore.d.ts +1 -1
- package/dist/path/meta/meta.types.d.ts +2 -2
- package/dist/path/path.types.d.ts +2 -2
- package/dist/path/pathSegmentKey.d.ts +1 -1
- package/dist/path/storage/AdapterPathStore.d.ts +2 -2
- package/dist/path/storage/DefaultDataAdapter.d.ts +2 -2
- package/dist/path/storage/PathEventHub.d.ts +1 -1
- package/dist/path/storage/PathStore.d.ts +2 -2
- package/dist/path/storage/data-adapter.types.d.ts +1 -1
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +23 -21
- package/dist/reactivity/engine-core.d.ts +600 -0
- package/dist/reactivity/engine.d.ts +6 -550
- package/dist/reactivity/reactive-object.d.ts +143 -2
- package/dist/reactivity/scope.d.ts +7 -6
- package/dist/reactivity/types.d.ts +9 -12
- package/dist/reactivity/watch.d.ts +1 -1
- package/dist/runtime/RaphCompactExecutionRuntime.d.ts +7 -0
- package/dist/runtime/RaphExecutionRuntime.d.ts +6 -0
- package/dist/runtime/RaphRuntime.d.ts +19 -403
- package/dist/runtime/RaphRuntimeBase.d.ts +194 -0
- package/dist/runtime/diagnostics/RaphDebug.d.ts +8 -5
- package/dist/runtime/errors.d.ts +1 -1
- package/dist/runtime/ownership/RaphEffectScope.d.ts +13 -12
- package/dist/runtime/ownership/RaphNode.d.ts +28 -21
- package/dist/runtime/ownership/RaphScope.d.ts +32 -19
- package/dist/runtime/ownership/parent-graph.types.d.ts +1 -1
- package/dist/runtime/ownership/parentGraph.d.ts +2 -2
- package/dist/runtime/phases/RaphFrameLoop.d.ts +1 -1
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +80 -29
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +21 -21
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +3 -3
- package/dist/runtime/phases/orderPhaseTasks.d.ts +4 -2
- package/dist/runtime/phases/phase.types.d.ts +36 -35
- package/dist/runtime/reactivity/PathHandle.d.ts +5 -5
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +7 -7
- package/dist/runtime/reactivity/RaphSelector.d.ts +27 -6
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +40 -39
- package/dist/runtime/reactivity/RuntimeObjectSupport.d.ts +9 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +27 -19
- package/dist/runtime/reactivity/RuntimeSelectorSupport.d.ts +10 -0
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +1 -1
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +1 -1
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +3 -3
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +13 -11
- package/package.json +22 -62
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./errors.cjs"),G=require("./ownership/parentGraph.cjs"),C=require("./ownership/RaphNode.cjs"),O=require("./ownership/RaphScope.cjs"),b=require("./ownership/throwDisposalErrors.cjs"),w=require("./phases/phase.types.cjs"),W=require("./phases/RaphFrameLoop.cjs"),L=require("./phases/RaphPhasePipeline.cjs"),f=require("./phases/RaphPhaseTaskRecord.cjs"),j=require("./phases/RaphPhaseWatch.cjs"),S=require("./reactivity/disposal-sweep.utils.cjs"),F=require("./reactivity/RaphWorkGraph.cjs"),M=require("./reactivity/RuntimeReactivity.cjs");let $=0;function U(d){const e=d.id??`runtime-${$++}`,t=d.adaptiveDependencyIndex??!1,s=d.enforceActions??!1,i=d.scheduler??w.RaphSchedulerType.Sync;if(!Y(i))throw new Error(`[Raph] Unsupported scheduler "${String(i)}".`);return Object.freeze({id:e,adaptiveDependencyIndex:t,enforceActions:s,scheduler:i})}const m=Object.freeze({}),N=2**32-1-f.GROUP_NODES,k=new Set;let x=!1;function I(){let d=0,e;for(const s of k){const i=s.deref();if(i===void 0||i.disposed){k.delete(s);continue}d++,e=i}const t=d>1;if(t!==x){if(!t&&e!==void 0){const s=e._getReactivity();if(s.getActiveOwner()!==void 0||s.getActiveConsumerOwner()!==void 0)return}x=t;for(const s of k)s.deref()?._applyObjectReadPolicy(t)}}class P{reactiveObjects;selectors;_reactiveObjects;mode="runtime";configuration;rootScope;root;frameTick;_reactivity;_signalLifecycle;_workGraph;_frameTickSignal;_phases;_frameLoop;_debugController;_parentGraph;_topOwners=new Set;_ownerRegistrations=0;_ownersReleased=!1;_batchDepth=0;_mutationDepth=0;_kernelBatchDepth=0;_ownerDisposalDepth=0;_disposingNodes=[];_ownerDisposals=0;_disposalSweepers;_nextDisposalSweep=Number.POSITIVE_INFINITY;_actionDepth=0;_actionCounter=0;_traceCauseStack=[];_phaseTraceOperations;_executionRequested=!1;_disposed=!1;_disposedListeners=new Set;_checkedObjectPolicy;_fastObjectPolicy;constructor(e,t,s,i){const{id:o,adaptiveDependencyIndex:r,enforceActions:c}=e;this.configuration=e,this.reactiveObjects=s!==void 0,this.selectors=i!==void 0,this._reactiveObjects=s,this._debugController=t;const n=`[Raph] Runtime "${o}" is disposed.`;if(this._signalLifecycle={owner:this,assertDependencyAllowed:(h,a)=>{this._assertImplicitDependency(h,a)},...c?{assertWriteAllowed:()=>this._assertWriteAllowed()}:{},throwDisposed:()=>{throw new g.RaphDisposedError(n)},throwCrossRuntime:h=>this._throwCrossRuntime(h)},this._reactivity=new M.RuntimeReactivity(this._signalLifecycle,{adaptiveDependencyIndex:r},i),this._workGraph=new F.RaphWorkGraph(this),this.rootScope=new O.RaphScope(`${o}:root-scope`,this),this.root=new C.RaphNode(null,{id:`${o}:root`},this),s!==void 0){const h=()=>this._assertWriteAllowed(),a=l=>this._runWrite(l),p=l=>{throw l instanceof P&&this._throwCrossRuntime(l),new g.RaphCrossRuntimeError("[Raph] Reactive object belongs to another reactivity engine.")};this._checkedObjectPolicy=Object.freeze({owner:this,assertRead:()=>this._assertTrackedRead(),assertWrite:h,runWrite:a,writeBoundary:this,throwForeign:p}),this._fastObjectPolicy=Object.freeze({owner:this,assertRead:void 0,assertWrite:h,runWrite:a,writeBoundary:this,throwForeign:p})}k.add(new WeakRef(this)),I(),this._applyObjectReadPolicy(x);const _=this._reactivity.signalForOwner(0,this.rootScope,"frame",!1);this._frameTickSignal=_,this.frameTick=this._workGraph.attachProducer(_,{get:()=>_.get(),peek:()=>_.peek()})}_getReactivity(){return this._reactivity}_getWorkGraph(){return this._workGraph}get id(){return this.configuration.id}get disposed(){return this._disposed}get graph(){return this._parentGraph??=G.parentGraph()}get loopEnabled(){return this._frameLoop?.running??!1}get frame(){return this._phases?.frame??{now:0,delta:0,elapsed:0,frame:0}}get phases(){return this._phases?.phases??[]}signal(e,t=this.rootScope){return this._assertOwnerRuntime(t),this._reactivity.signalForOwner(e,t)}reactive(e){if(this._assertAlive(),this._reactiveObjects===void 0)throw new TypeError("[Raph] Reactive objects require the full execution profile.");return this._reactiveObjects.reactive(this._reactivity,e)}computed(e,t=this.rootScope){this._assertOwnerRuntime(t);const s=this._workGraph.createProducer(t),i=typeof e=="function"?e:e.get,o=this._reactivity.computedForOwner(()=>this._runTracked(t,i),t,this._workGraph.producerHooks(s));if(this._workGraph.setProducerActivation(s,()=>{o.peek()}),typeof e=="function")return this._workGraph.attachProducer(s,o);const r=this._attachWritableComputed(o,e.set,t);return this._workGraph.attachProducer(s,r)}effect(e,t,s,i=m){return K(this._effectRegistration(e,t,s,i))}_effectRegistration(e,t,s,i=m,o=!1,r=!1,c,n){this._disposed||e.runtime!==this?this._assertOwnerRuntime(e):e._assertAlive();const _=this._phases??this._execution;if(typeof s!="function")throw new TypeError("[Raph] Phase callback must be a function.");const h=_._resolvedState,a=h!==void 0&&t===_._resolvedInput?h:_.resolvePhase(t),p=i.priority??0;if(!Number.isFinite(p))throw new TypeError("[Raph] Effect priority must be finite.");const l=i.initial??"scheduled";if(l!=="scheduled"&&l!=="sync")throw new TypeError(`[Raph] Unsupported effect initial mode "${String(l)}".`);a.bindings++;const u=new f.RaphPhaseTaskRecord(a,i.priority??0,e,s);r&&(u.state=f.TASK_ACTIVE|f.TASK_TASKLESS);const y=this._reactivity,v=i.initial==="sync",T=v&&this.configuration.scheduler!==w.RaphSchedulerType.Sync;let E="Effect registration and cleanup failed.",D=!1;try{o&&u.pause();const R=y._allocateTaskEffect(y._phaseBody,u);if(u.node=R,T&&_._queue(u,!1),D=!0,!T&&!o&&!y._isBatching()&&_._canDeliverFirst(u)){y._requestTaskEffect(R,!1);try{_._deliverFirst(u)}catch(B){y._failTaskEffectSchedule(R,B)}}else y._requestTaskEffect(R,!T);if(n?.())return u.dispose(),u;D=!1,E="[Raph] Resource registration and cleanup failed.",(u.state&f.TASK_ACTIVE)!==0&&u.node!==void 0?e._adoptRecord(u):(e._assertAlive(),u.dispose()),E="[Raph] Phase effect registration and rollback failed.",D=!0,v?_._running?this._executionRequested=!1:(this._disposed&&this._assertAlive(),this._executionRequested=!1,_.flush()):this._requestExecution(),n?.()&&u.dispose()}catch(R){this._rollbackRegistration(u,R,E,D?c:void 0)}return u}_effectGroupRegistration(e,t,s,i,o,r=m,c=!1){this._assertOwnerRuntime(e);const n=this._execution,_=i,h=this._validatePhaseBinding(n,t,_,r);if(!Number.isInteger(s)||s<1)throw new RangeError("[Raph] Effect group slot count must be a positive integer.");if(s>N)throw new RangeError(`[Raph] Effect group slot count must not exceed ${N}.`);const a=n.bindGroup(h,e,_,o,s,r.priority??0);try{c&&a.pause();const p=a.group,l=this._reactivity,u=l._phaseBody,y=f.GROUP_NODES+s;for(let v=f.GROUP_NODES;v<y;v++)p[v]=l._allocateTaskEffect(u,a);e._adoptRecord(a)}catch(p){this._rollbackRegistration(a,p,"[Raph] Resource registration and cleanup failed.")}return a}_startGroupSlot(e,t,s,i){const o=e.group;if(o===void 0){e.consumerOwner._assertAlive();return}const r=t>=0?o[f.GROUP_NODES+t]:void 0;if(r===void 0)throw new RangeError(`[Raph] Effect group has no slot ${String(t)}.`);if(s!=="scheduled"&&s!=="sync")throw new TypeError(`[Raph] Unsupported effect initial mode "${String(s)}".`);if(r===null||r.firstDep!==null)return;const c=e.phaseState.pipeline,n=s==="sync",_=n&&this.configuration.scheduler!==w.RaphSchedulerType.Sync;let h=!1;try{h=!0,this._reactivity._requestTaskEffect(r,!1),_?e.state&f.TASK_PENDING||c._queue(e,!1):e.schedule(),h=!1,e.state&(f.TASK_PENDING|f.TASK_REQUESTED)||e.consumerOwner._assertAlive(),n?c._running?this._executionRequested=!1:(h=!0,this.flush(),h=!1,e.state&f.TASK_ACTIVE||e.consumerOwner._assertAlive()):(h=!0,this._requestExecution())}catch(a){let p=a;try{this._reactivity._disposeTaskEffect(r)}catch(l){p=new AggregateError([a,l],"[Raph] Phase effect registration and rollback failed.")}throw h&&i!==void 0&&i(p),p}}watch(e,t,s,i,o=m){const r=this._watchRegistration(e,t,s,i,o).watch;return r===void 0?q:V(r)}_watchRegistration(e,t,s,i,o=m,r=!1,c,n){this._assertOwnerRuntime(e);const _=this._execution,h=this._validatePhaseBinding(_,s,i,o,!0);this._workGraph.assertSubscriptionAllowed(e,t);const a=_.bindTask(h,e,i,o.priority??0),p=j.createPhaseWatch(u=>this._runUntracked(u),a);a.watch=p,r&&a.pause();try{if(p.source=this._workGraph.subscribe(t,o.include,(u,y,v)=>p.record?.enqueue(u,y,v)),n?.())return a.dispose(),a}catch(u){throw a.dispose(),u}try{e._adoptRecord(a)}catch(u){this._rollbackRegistration(a,u,"[Raph] Resource registration and cleanup failed.")}const l=o.initial??"scheduled";try{l!=="none"&&a.schedule(),l==="sync"&&this.flush(),n?.()&&a.dispose()}catch(u){this._rollbackRegistration(a,u,"[Raph] Phase watch registration and rollback failed.",c)}return a}aggregate(e,t){return this._assertOwnerRuntime(e),this._workGraph.createAggregate(e,t)}batch(e){return this._batch(e,!0)}_batchReactive(e){return this._batch(e,!1)}_batch(e,t){this._assertAlive(),this._batchDepth++;let s,i,o=!1;try{s=this._reactivity.batch(()=>t?this._runDataBatch(e):e())}catch(r){o=!0,i=r}return this._closeBatch(o,i),s}_closeBatch(e,t){if(this._batchDepth--,this._executionBoundaryOpen()){if(e)throw t;return}const s=this._finishExecutionBoundary();if(e)throw s!==void 0?new AggregateError([t,...s],"[Raph] Batch and scheduled phase execution failed."):t;s!==void 0&&b.throwDisposalErrors(s,"[Raph] Batch phase execution failed.")}_applyBatch(e,t,s){this._assertAlive();const i=this._reactivity;this._batchDepth++,i._startBatch();let o,r,c=!1;try{o=i._applyUntrackedWithOwner(e,t,s)}catch(n){c=!0,r=n}try{i._endBatch()}catch(n){r=c?new AggregateError([r,n],"Batch operation and effect queue processing failed."):n,c=!0}return this._closeBatch(c,r),o}action(e,t,s){const i=typeof e=="function"?e:t,o=typeof e=="function"?t instanceof O.RaphScope?t:this.rootScope:s??this.rootScope,r=typeof e=="string"?e:`action#${++this._actionCounter}`;if(this._assertOwnerRuntime(o),typeof i!="function")throw new TypeError("[Raph] Action operation must be a function.");if(!r.trim())throw new Error("[Raph] Action name must not be empty.");return(...c)=>this._invokeAction(r,o,i,c)}_invokeAction(e,t,s,i,o){t._assertAlive();const r=this._debugController,c=this._traceCauseStack,n=r?.nextOperationId("action"),h=(c.length===0?void 0:c[c.length-1])??n;n!==void 0&&r?.record({...h===void 0?{}:{causeId:h},kind:"action",name:e,...n===void 0?{}:{operationId:n},status:"start"}),h!==void 0&&c.push(h),this._actionDepth++;try{const a=this._applyBatch(s,i,o);return r?.traces("action")&&r?.record({...h===void 0?{}:{causeId:h},kind:"action",name:e,...n===void 0?{}:{operationId:n},status:"end"}),a}catch(a){throw this._debugController?.record({...h===void 0?{}:{causeId:h},details:{message:A(a)},kind:"action",name:e,...n===void 0?{}:{operationId:n},status:"error"}),this._debugController?.record({...h===void 0?{}:{causeId:h},details:{message:A(a)},kind:"error",name:`action:${e}`,...n===void 0?{}:{operationId:n},status:"error"}),a}finally{this._actionDepth--,h!==void 0&&c.pop()}}untracked(e){return this._assertAlive(),this._runUntracked(e)}_probeReads(e){return this._assertAlive(),this._reactivity._probeReadsWithOwner(e)}scope(e){return this._assertAlive(),new O.RaphScope(e,this)}node(e,t){this._assertAlive(),this._enterWrite();let s;try{s=this._createCommittedNode(e,t)}catch(i){throw this._failWrite(i)}return this._exitWrite(),s._assertAlive(),s}_createCommittedNode(e,t){const s=e.parent??this.root,i=C.createProvisionalNode(s,e,this);try{const o=t?.(i);return i._assertAlive(),s._assertAlive(),i._setApi(o),i._publishCreation(),i}catch(o){try{i.dispose()}catch(r){throw new AggregateError([o,r],`[Raph] Node "${i.id}" setup and cleanup failed.`)}throw o}}getNode(e){return this._assertAlive(),this.root._findNode(e)}definePhases(e){this._execution.definePhases(e)}addPhase(e){this._execution.addPhase(e)}clearPhases(){this._assertAlive(),this._phases?.clearPhases()}requestExecution(){this._assertAlive(),this._phases?.request()}flush(){this._assertAlive(),this._executionRequested=!1,this._phases?.flush()}afterFlush(){return this._assertAlive(),this._phases?.afterFlush()??Promise.resolve()}acquireLoop(e){return this._assertAlive(),this._clock.acquire(e)}startLoop(){this._assertAlive(),this._clock.start()}stopLoop(){this._frameLoop?.stop()}dispose(){if(this._disposed)return;this._disposed=!0,this._checkedObjectPolicy!==void 0&&this._reactiveObjects?.configure(this._reactivity,this._checkedObjectPolicy),I(),this._executionRequested=!1,this._signalLifecycle.owner=void 0;const e=[];try{this._frameLoop?.dispose()}catch(r){e.push(r)}this._frameLoop=void 0;try{this._phases?.dispose()}catch(r){e.push(r)}this._phases=void 0;try{this.root.dispose()}catch(r){e.push(r)}const t=this._collectOwners().sort(z);for(const r of t)if(!(r===this.root||r===this.rootScope||r.disposed))try{r.dispose()}catch(c){e.push(c)}try{this.rootScope.dispose()}catch(r){e.push(r)}const s=`[Raph] Runtime "${this.id}" is disposed.`,i=()=>{throw new g.RaphDisposedError(s)};try{this._reactiveObjects?.dispose(this._reactivity,{assertRead:i,assertWrite:i,throwForeign:i})}catch(r){e.push(r)}this._topOwners.clear(),this._ownersReleased=!0,this._disposeDataSources(e);try{this._workGraph.dispose()}catch(r){e.push(r)}this._detachDataPlane(e);const o=[...this._disposedListeners];this._disposedListeners.clear();for(const r of o)try{r()}catch(c){e.push(c)}b.throwDisposalErrors(e,`[Raph] Runtime "${this.id}" disposal failed.`)}_onDisposed(e){return this._disposed?(e(),()=>{}):(this._disposedListeners.add(e),()=>{this._disposedListeners.delete(e)})}_notifyNodeStructure(e,t,s,i){if(!this._workGraph._hasStructuralDemand(e)){this._touchMutationBoundary();return}this._runNodeMutation(()=>{this._workGraph.notifyNode(e,"structure",{structure:t,oldAncestors:s,newAncestors:i})})}_hasNodeStructureDemand(e){return this._workGraph._hasStructuralDemand(e)}_hasNodeSubscribers(){return this._workGraph._hasNodeSubscribers()}_notifyNodeTouch(e,t){this._runNodeMutation(()=>this._workGraph.notifyNode(e,"touch",{metadata:t}))}_assertNodeReparentAllowed(e,t){this._workGraph.assertReparentAllowed(e,t)}_releaseNode(e){this._workGraph.releaseNode(e)}_runNodeMutation(e){return this._runWrite(e)}_touchMutationBoundary(){if(this.configuration.scheduler===w.RaphSchedulerType.Sync&&(this._executionRequested=!0),this._executionBoundaryOpen())return;const e=this._finishExecutionBoundary();e!==void 0&&b.throwDisposalErrors(e,"[Raph] Mutation phase execution failed.")}_runPhaseTransition(e){return this._runWrite(e,!1)}_beginOwnerDisposal(e){this._disposingNodes[this._ownerDisposalDepth++]=e}_endOwnerDisposal(){const e=this._ownerDisposalDepth;e!==0&&(this._ownerDisposalDepth=e-1,this._disposingNodes[e-1]=void 0,this._ownerDisposals>=this._nextDisposalSweep&&e===1&&this._sweepAfterDisposals(),this._clearTransientCausesIfSettled(),this._disposed||this._requestExecution())}_ownerDisposalCount(){return this._ownerDisposals}_addDisposalSweeper(e,t){const s=this._disposalSweepers;if(s===void 0){e._sweepSlot=0,e._sweepDue=t,this._disposalSweepers=[e],this._nextDisposalSweep=t;return}S.enqueueSweeper(s,e,t),this._nextDisposalSweep=s[0]._sweepDue}_removeDisposalSweeper(e){const t=this._disposalSweepers;t===void 0||!S.dequeueSweeper(t,e)||(t.length===0?(this._disposalSweepers=void 0,this._nextDisposalSweep=Number.POSITIVE_INFINITY):this._nextDisposalSweep=t[0]._sweepDue)}_sweepAfterDisposals(){const e=this._disposalSweepers;if(e===void 0)return;const t=this._ownerDisposals;if(e.length===1){const s=e[0],i=s._afterOwnerDisposals(t);i>t?(s._sweepDue=i,this._nextDisposalSweep=i):(s._sweepSlot=-1,this._disposalSweepers=void 0,this._nextDisposalSweep=Number.POSITIVE_INFINITY);return}for(let s=e[0];s._sweepDue<=t;s=e[0]){const i=s._afterOwnerDisposals(t);if(i>t)S.postponeFirstSweeper(e,i);else if(S.dequeueSweeper(e,s),e.length===0){this._disposalSweepers=void 0,this._nextDisposalSweep=Number.POSITIVE_INFINITY;return}}this._nextDisposalSweep=e[0]._sweepDue}_ownerDisposalActive(){return this._ownerDisposalDepth!==0}_registerOwner(e){return this._assertAlive(),e._isNode||this._topOwners.add(e),++this._ownerRegistrations}_unregisterOwner(e){e._isNode||this._topOwners.delete(e),this._ownerDisposals++}_addTopOwner(e){this._topOwners.add(e)}_removeTopOwner(e){this._topOwners.delete(e)}_assertOwnerRuntime(e){if(this._assertAlive(),e.runtime!==this)throw new g.RaphCrossRuntimeError("[Raph] Owner belongs to another runtime.");e._assertAlive()}_beginKernelBatch(){this._disposed||this._kernelBatchDepth++}_endKernelBatch(){this._kernelBatchDepth!==0&&(this._kernelBatchDepth--,this._clearTransientCausesIfSettled(),this._disposed||this._requestExecution())}_registerMachineDebug(e){return this._assertAlive(),this._debugController?.registerMachine(e)??q}_hasMachineDebug(e){return this._debugController?.hasMachine(e)??!1}_traces(e){return this._debugController?.traces(e)??!1}_currentTraceCauseId(){return this._traceCauseStack.at(-1)}_nextTraceOperation(e){return this._debugController?.nextOperationId(e)}_hasActiveReactiveContext(){return this._assertAlive(),this._reactivity.hasActiveContext()}_recordTrace(e){this._debugController?.record(e)}_runWithTraceCause(e,t){if(e===void 0)return t();this._traceCauseStack.push(e);try{return t()}finally{this._traceCauseStack.pop()}}_validatePhaseBinding(e,t,s,i,o=!1){if(typeof s!="function")throw new TypeError("[Raph] Phase callback must be a function.");const r=e.resolvePhase(t),c=i.priority??0;if(!Number.isFinite(c))throw new TypeError("[Raph] Effect priority must be finite.");const n=i.initial??"scheduled";if(n!=="scheduled"&&n!=="sync"&&!(o&&n==="none"))throw new TypeError(`[Raph] Unsupported effect initial mode "${String(n)}".`);return r}_rollbackRegistration(e,t,s,i){let o=t;try{e.dispose()}catch(r){o=new AggregateError([t,r],s)}throw i!==void 0&&i(o),o}_liveOwnerCount(){return this._ownersReleased?0:this._ownerRegistrations-this._ownerDisposals}_collectOwners(){const e=[];if(this._ownersReleased)return e;const t=this._topOwners;for(const o of t)e.push(o),o._isNode&&o._collectDescendants(e);const s=this._disposingNodes,i=this._ownerDisposalDepth;for(let o=0;o<i;o++){const r=s[o];r===void 0||r._isLinked()||t.has(r)||(e.push(r),r._collectDescendants(e))}return e}get _execution(){return this._assertAlive(),this._phases!==void 0?this._phases:(this._phases=new L.RaphPhasePipeline(this.configuration.scheduler,this._reactivity,e=>this._workGraph.causeForToken(e),()=>{const e=this._mutationDepth!==0||this._batchDepth!==0||this._kernelBatchDepth!==0||this._ownerDisposalDepth!==0||this._reactivity._isFlushingEffects();return e&&this.configuration.scheduler===w.RaphSchedulerType.Sync&&(this._executionRequested=!0),e}),this._syncPhaseTrace(),this._phases)}_phaseTraceListener;_syncPhaseTrace(){if(this._phases===void 0)return;const t=this._phaseTraceOperations!==void 0||this._debugController?.traces("phase")?this._phaseTraceListener??=this._tracePhase.bind(this):void 0;this._phases._setPhaseTrace(t)}_tracePhase(e,t,s){if(this._phaseTraceOperations===void 0&&!this._debugController?.traces("phase"))return;let i;t==="start"?(i=this._debugController?.nextOperationId("phase"),i!==void 0&&(this._phaseTraceOperations??=new Map).set(e,i)):(i=this._phaseTraceOperations?.get(e),this._phaseTraceOperations?.delete(e),this._phaseTraceOperations?.size===0&&(this._phaseTraceOperations=void 0)),this._debugController?.record({...i===void 0?{}:{causeId:i},...s===void 0?{}:{details:{message:A(s)}},kind:"phase",name:e,...i===void 0?{}:{operationId:i},status:t}),this._phaseTraceOperations===void 0&&!this._debugController?.traces("phase")&&this._phases?._setPhaseTrace(void 0)}get _clock(){return this._frameLoop??=new W.RaphFrameLoop(()=>this._tickFrameLoop())}_tickFrameLoop(){this._disposed||this._setFrameTick(this._frameTickSignal.peek()+1)}_setFrameTick(e){this._enterWrite();try{this._frameTickSignal._writeInBoundary(e)}catch(t){throw this._failWrite(t)}this._exitWrite()}_attachWritableComputed(e,t,s){let i=t;this._own(()=>{i=void 0},s);const o=e;return o.set=r=>{s._assertAlive(),this._assertWriteAllowed(),this._runWrite(()=>i(r))},o}_own(e,t){try{return t._adoptResource(e)}catch(s){try{e()}catch(i){throw new AggregateError([s,i],"[Raph] Resource registration and cleanup failed.")}throw s}}_runTracked(e,t){return this._reactivity.runWithOwner(this._signalLifecycle,e,t)}_runUntracked(e){return this._reactivity.untrackedWithOwner(e)}_runWrite(e,t=!0){t&&this.configuration.scheduler===w.RaphSchedulerType.Sync&&(this._executionRequested=!0),this._mutationDepth++;let s,i,o=!1;try{s=e()}catch(c){o=!0,i=c}if(this._mutationDepth--,this._executionBoundaryOpen()){if(o)throw i;return s}const r=this._finishExecutionBoundary();if(o)throw r!==void 0?new AggregateError([i,...r],"[Raph] Mutation and scheduled phase execution failed."):i;return r!==void 0&&b.throwDisposalErrors(r,"[Raph] Mutation phase execution failed."),s}_isWriteBatchOpen(){return this._batchDepth!==0&&this._reactivity._isBatching()}_enterWrite(){this._mutationDepth++}_exitWrite(){if(this._mutationDepth--,this._requestPendingExecution(),this._executionBoundaryOpen())return;const e=this._finishExecutionBoundary();e!==void 0&&b.throwDisposalErrors(e,"[Raph] Mutation phase execution failed.")}_failWrite(e){if(this._mutationDepth--,this._requestPendingExecution(),this._executionBoundaryOpen())return e;const t=this._finishExecutionBoundary();return t===void 0?e:new AggregateError([e,...t],"[Raph] Mutation and scheduled phase execution failed.")}_requestPendingExecution(){!this._executionRequested&&this.configuration.scheduler===w.RaphSchedulerType.Sync&&this._phases?._hasPendingWork()===!0&&(this._executionRequested=!0)}_executionBoundaryOpen(){return this._mutationDepth!==0||this._batchDepth!==0||this._kernelBatchDepth!==0||this._ownerDisposalDepth!==0}_finishExecutionBoundary(){let e;try{this._clearTransientCausesIfSettled()}catch(t){e=[t]}try{this._requestExecution()}catch(t){e===void 0?e=[t]:e.push(t)}return e}_clearTransientCausesIfSettled(){this._mutationDepth===0&&this._batchDepth===0&&this._kernelBatchDepth===0&&this._ownerDisposalDepth===0&&!this._reactivity._isFlushingEffects()&&this._workGraph.clearTransientCauses()}_requestExecution(){this._disposed||this.configuration.scheduler!==w.RaphSchedulerType.Sync||this._mutationDepth!==0||this._batchDepth!==0||this._kernelBatchDepth!==0||this._ownerDisposalDepth!==0||this._reactivity._isFlushingEffects()||this._executionRequested&&(this._executionRequested=!1,this._phases?.flush())}_applyObjectReadPolicy(e){this._disposed||this._checkedObjectPolicy===void 0||this._reactiveObjects?.configure(this._reactivity,e?this._checkedObjectPolicy:this._fastObjectPolicy)}_assertTrackedRead(){this._assertAlive();const e=this._reactivity.getActiveOwner();if(e!==void 0&&e!==this&&this._throwCrossRuntime(e),e===void 0){const t=this._reactivity.getActiveConsumerOwner();if(t!==void 0&&t.runtime!==this)throw new g.RaphCrossRuntimeError("[Raph] Implicit dependency crosses runtime boundaries.")}}_assertSourceReadable(e){this._assertAlive();const t=this._reactivity.getActiveOwner();t!==void 0&&t!==this&&this._throwCrossRuntime(t);const s=this._reactivity.getActiveConsumerOwner();s!==void 0&&this._assertImplicitDependency(e,s),e._assertAlive()}_assertImplicitDependency(e,t){if(e.runtime!==this||t.runtime!==this)throw new g.RaphCrossRuntimeError("[Raph] Implicit dependency crosses runtime boundaries.");if(!(e===this.rootScope||e===t)&&!(e._isNode&&t._isNode&&t._hasAncestor(e)))throw new Error(`[Raph] Implicit dependency from "${t.id}" to "${e.id}" is not allowed; use watch().`)}_assertWriteAllowed(){if(this._assertAlive(),this.configuration.enforceActions&&this._batchDepth===0)throw new g.RaphActionError("[Raph] Writes are allowed only inside action() or batch().")}_throwCrossRuntime(e){throw new g.RaphCrossRuntimeError(`[Raph] Runtime "${this.id}" cannot be tracked by runtime "${e.id}".`)}_assertAlive(){if(this._disposed)throw new g.RaphDisposedError(`[Raph] Runtime "${this.id}" is disposed.`)}_runDataBatch(e){return e()}_disposeDataSources(e){}_detachDataPlane(e){}}function K(d){let e=d;return()=>{const t=e;t!==void 0&&(e=void 0,t.dispose())}}function V(d){return()=>{d.record?.dispose()}}function q(){}function z(d,e){return e._order-d._order}function Y(d){return d===w.RaphSchedulerType.Sync||d===w.RaphSchedulerType.Microtask||d===w.RaphSchedulerType.AnimationFrame}function A(d){return d instanceof Error?d.message:String(d)}exports.RaphRuntimeBase=P;exports.resolveRuntimeConfiguration=U;
|