@raphy-js/raph 1.0.1-dev.26 → 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 e=require("./RaphRuntimeBase.cjs");class u extends e.RaphRuntimeBase{constructor(t={}){super(e.resolveRuntimeConfiguration(t))}}exports.RaphCompactExecutionRuntime=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./RaphRuntimeBase.cjs"),u=require("./reactivity/RuntimeObjectSupport.cjs"),i=require("./reactivity/RuntimeSelectorSupport.cjs");class r extends e.RaphRuntimeBase{constructor(t={}){super(e.resolveRuntimeConfiguration(t),void 0,u.RUNTIME_OBJECT_SUPPORT,i.RUNTIME_SELECTOR_SUPPORT)}}exports.RaphExecutionRuntime=r;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RaphRuntimeBase as r, resolveRuntimeConfiguration as t } from "./RaphRuntimeBase.js";
|
|
2
|
+
import { RUNTIME_OBJECT_SUPPORT as e } from "./reactivity/RuntimeObjectSupport.js";
|
|
3
|
+
import { RUNTIME_SELECTOR_SUPPORT as i } from "./reactivity/RuntimeSelectorSupport.js";
|
|
4
|
+
class s extends r {
|
|
5
|
+
constructor(o = {}) {
|
|
6
|
+
super(t(o), void 0, e, i);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
s as RaphExecutionRuntime
|
|
11
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../path/data-path.utils.cjs"),P=require("../path/DataPath.cjs"),N=require("../path/meta/RaphMeta.cjs"),q=require("../path/RaphKernel.cjs"),O=require("../reactivity/reactive-object.cjs"),R=require("./diagnostics/RaphDebug.cjs"),v=require("./errors.cjs"),I=require("./ownership/parentGraph.cjs"),m=require("./ownership/RaphNode.cjs"),E=require("./ownership/RaphScope.cjs"),b=require("./ownership/throwDisposalErrors.cjs"),w=require("./phases/phase.types.cjs"),G=require("./phases/RaphFrameLoop.cjs"),B=require("./phases/RaphPhasePipeline.cjs"),f=require("./phases/RaphPhaseTaskRecord.cjs"),W=require("./phases/RaphPhaseWatch.cjs"),k=require("./reactivity/disposal-sweep.utils.cjs"),M=require("./reactivity/PathHandle.cjs"),L=require("./reactivity/RaphMetaSource.cjs"),F=require("./reactivity/RaphWorkGraph.cjs"),$=require("./reactivity/RuntimeReactivity.cjs"),S=Object.freeze({}),x=2**32-1-f.GROUP_NODES;class A{static _runtimeCounter=0;mode="runtime";configuration;rootScope;root;frameTick;_reactivity;_signalLifecycle;_workGraph;_frameTickSignal;_pathHandles;_meta;_phases;_frameLoop;_debug;_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;constructor(e={}){const t=e.id??`runtime-${A._runtimeCounter++}`,s=e.adaptiveDependencyIndex??!1,r=e.enforceActions??!1,i=e.scheduler??w.RaphSchedulerType.Sync;if(!K(i))throw new Error(`[Raph] Unsupported scheduler "${String(i)}".`);const o=e.kernel??new q.RaphKernel({id:`${t}-kernel`});this.configuration=Object.freeze({adaptiveDependencyIndex:s,...e.debug===void 0?{}:{debug:e.debug},id:t,kernel:o,enforceActions:r,scheduler:i}),this._debugController=new R.RaphDebugController(e.debug);const a=`[Raph] Runtime "${t}" is disposed.`;this._signalLifecycle={owner:this,assertDependencyAllowed:(h,u)=>{this._assertImplicitDependency(h,u)},...r?{assertWriteAllowed:()=>this._assertWriteAllowed()}:{},throwDisposed:()=>{throw new v.RaphDisposedError(a)},throwCrossRuntime:h=>this._throwCrossRuntime(h)},this._reactivity=new $.RuntimeReactivity(this._signalLifecycle,{adaptiveDependencyIndex:s}),this._workGraph=new F.RaphWorkGraph(this),o._attachRuntime(this),this.rootScope=new E.RaphScope(`${t}:root-scope`,this),this.root=new m.RaphNode(null,{id:`${t}:root`},this),O.configureReactiveObjectPolicy(this._reactivity,{owner:this,assertRead:()=>{this._assertAlive();const h=this._reactivity.getActiveOwner();h!==void 0&&h!==this&&this._throwCrossRuntime(h);const u=this._reactivity.getActiveConsumerOwner();u!==void 0&&this._assertImplicitDependency(this.rootScope,u)},assertWrite:()=>this._assertWriteAllowed(),runWrite:h=>this._runWrite(h),throwForeign:h=>{throw h instanceof A&&this._throwCrossRuntime(h),new v.RaphCrossRuntimeError("[Raph] Reactive object belongs to another reactivity engine.")}});const n=this._reactivity.signalForOwner(0,this.rootScope,"frame",!1);this._frameTickSignal=n,this.frameTick=this._workGraph.attachProducer(n,{get:()=>n.get(),peek:()=>n.peek()})}_getReactivity(){return this._reactivity}_getWorkGraph(){return this._workGraph}get id(){return this.configuration.id}get kernel(){return this.configuration.kernel}get disposed(){return this._disposed}get graph(){return this._parentGraph??=I.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??[]}get meta(){if(this._assertAlive(),this._meta!==void 0)return this._meta;const e=new N.RaphMeta(this.kernel,{assertReadable:()=>this._assertAlive(),assertWritable:()=>this._assertWriteAllowed(),runWrite:(t,s)=>this._runWrite(t,s)});return this._meta=Object.freeze({delete:e.delete.bind(e),get:e.get.bind(e),has:e.has.bind(e),merge:e.merge.bind(e),set:e.set.bind(e)})}getDerivedSnapshot(){return this.kernel.getDerivedSnapshot()}get debug(){return this._debug??=Object.freeze({snapshot:()=>this._createDebugSnapshot(),getTree:()=>this._createDebugTree(),stats:()=>this._createDebugStats(),trace:this._debugController.trace,machines:this._debugController.machines})}signal(e,t=this.rootScope){return this._assertOwnerRuntime(t),this._reactivity.signalForOwner(e,t)}reactive(e){return this._assertAlive(),this._reactivity.reactive(e)}computed(e,t=this.rootScope){this._assertOwnerRuntime(t);const s=this._workGraph.createProducer(t),r=typeof e=="function"?e:e.get,i=this._reactivity.computedForOwner(()=>this._runTracked(t,r),t,this._workGraph.producerHooks(s));if(this._workGraph.setProducerActivation(s,()=>{i.peek()}),typeof e=="function")return this._workGraph.attachProducer(s,i);const o=this._attachWritableComputed(i,e.set,t);return this._workGraph.attachProducer(s,o)}effect(e,t,s,r=S){return H(this._effectRegistration(e,t,s,r))}_effectRegistration(e,t,s,r=S,i=!1,o=!1,a,n){this._assertOwnerRuntime(e);const h=this._execution,u=this._validatePhaseBinding(h,t,s,r),c=h.bindTask(u,e,s,r.priority??0);o&&(c.state=f.TASK_ACTIVE|f.TASK_TASKLESS);const d=this._reactivity,_=r.initial==="sync",l=_&&this.configuration.scheduler!==w.RaphSchedulerType.Sync;let y="Effect registration and cleanup failed.",g=!1;try{i&&c.pause();const D=d._allocateTaskEffect(d._phaseBody,c);if(c.node=D,l&&h._queue(c,!1),g=!0,d._requestTaskEffect(D,!l),n?.())return c.dispose(),c;g=!1,y="[Raph] Resource registration and cleanup failed.",(c.state&f.TASK_ACTIVE)!==0&&c.node!==void 0?e._adoptRecord(c):(e._assertAlive(),c.dispose()),y="[Raph] Phase effect registration and rollback failed.",g=!0,_?this.flush():this._requestExecution(),n?.()&&c.dispose()}catch(D){this._rollbackRegistration(c,D,y,g?a:void 0)}return c}_effectGroupRegistration(e,t,s,r,i,o=S,a=!1){this._assertOwnerRuntime(e);const n=this._execution,h=r,u=this._validatePhaseBinding(n,t,h,o);if(!Number.isInteger(s)||s<1)throw new RangeError("[Raph] Effect group slot count must be a positive integer.");if(s>x)throw new RangeError(`[Raph] Effect group slot count must not exceed ${x}.`);const c=n.bindGroup(u,e,h,i,s,o.priority??0);try{a&&c.pause();const d=c.group,_=this._reactivity,l=_._phaseBody,y=f.GROUP_NODES+s;for(let g=f.GROUP_NODES;g<y;g++)d[g]=_._allocateTaskEffect(l,c);e._adoptRecord(c)}catch(d){this._rollbackRegistration(c,d,"[Raph] Resource registration and cleanup failed.")}return c}_startGroupSlot(e,t,s,r){const i=e.group;if(i===void 0){e.consumerOwner._assertAlive();return}const o=t>=0?i[f.GROUP_NODES+t]:void 0;if(o===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(o===null||o.firstDep!==null)return;const a=e.phaseState.pipeline,n=s==="sync",h=n&&this.configuration.scheduler!==w.RaphSchedulerType.Sync;let u=!1;try{u=!0,this._reactivity._requestTaskEffect(o,!1),h?e.state&f.TASK_PENDING||a._queue(e,!1):e.schedule(),u=!1,e.state&(f.TASK_PENDING|f.TASK_REQUESTED)||e.consumerOwner._assertAlive(),n?a._running?this._executionRequested=!1:(u=!0,this.flush(),u=!1,e.state&f.TASK_ACTIVE||e.consumerOwner._assertAlive()):(u=!0,this._requestExecution())}catch(c){let d=c;try{this._reactivity._disposeTaskEffect(o)}catch(_){d=new AggregateError([c,_],"[Raph] Phase effect registration and rollback failed.")}throw u&&r!==void 0&&r(d),d}}watch(e,t,s,r,i=S){const o=this._watchRegistration(e,t,s,r,i).watch;return o===void 0?U:z(o)}_watchRegistration(e,t,s,r,i=S,o=!1,a,n){this._assertOwnerRuntime(e);const h=this._execution,u=this._validatePhaseBinding(h,s,r,i,!0);this._workGraph.assertSubscriptionAllowed(e,t);const c=h.bindTask(u,e,r,i.priority??0),d=W.createPhaseWatch(l=>this._runUntracked(l),c);c.watch=d,o&&c.pause();try{if(d.source=this._workGraph.subscribe(t,i.include,(l,y,g)=>d.record?.enqueue(l,y,g)),n?.())return c.dispose(),c}catch(l){throw c.dispose(),l}try{e._adoptRecord(c)}catch(l){this._rollbackRegistration(c,l,"[Raph] Resource registration and cleanup failed.")}const _=i.initial??"scheduled";try{_!=="none"&&c.schedule(),_==="sync"&&this.flush(),n?.()&&c.dispose()}catch(l){this._rollbackRegistration(c,l,"[Raph] Phase watch registration and rollback failed.",a)}return c}aggregate(e,t){return this._assertOwnerRuntime(e),this._workGraph.createAggregate(e,t)}metaSource(e,t={}){this._assertAlive(),V(e,t);const s=this._workGraph.createProducer(this.rootScope,"path"),r=this._workGraph.producerHooks(s).onDispose,i=L.RaphMetaSource._create(this.rootScope,e,t,()=>this.kernel._watchMeta(i.masks,({events:o})=>this._workGraph.notifyProducerEvents(s,o,!1),i.options,o=>{o&&this._execution.request()}),()=>r(!1));i._bindOwner(this.rootScope._adoptResource(()=>i._disposeOwned()));try{return this._workGraph.setProducerActivation(s,()=>i._activate(),!0),this._workGraph.attachProducer(s,i),i}catch(o){try{i.dispose()}catch(a){throw new AggregateError([o,a],"[Raph] Meta source activation and rollback failed.")}throw o}}path(e,t={}){this._assertAlive();const s=C.parseDataPath(e,t),r=this._pathHandles??=new Map,i=r.get(s.canonical);if(i!==void 0)return i;const o=this._workGraph.createProducer(this.rootScope,"path"),a=this._workGraph.producerHooks(o),n=new M.PathHandle(this.kernel,s,t,h=>this._releasePathHandle(h),this._reactivity,()=>this._assertAlive(),()=>this._assertTrackedRead(),this.configuration.enforceActions?()=>this._assertWriteAllowed():void 0,h=>this._runWrite(h),{token:o,onDispose:a.onDispose},({events:h},u)=>this._workGraph.notifyProducerEvents(o,h,!0,u));try{return this._workGraph.setProducerActivation(o,()=>n._activate(),!0),this._workGraph.attachProducer(o,n),r.set(s.canonical,n),n}catch(h){let u,c=!1;try{n.dispose()}catch(d){c=!0,u=d}throw r.size===0&&this._pathHandles===r&&(this._pathHandles=void 0),c?new AggregateError([h,u],"[Raph] Path source activation and rollback failed."):h}}get(e,t){this._assertTrackedRead();const s=e??"";return this._reactivity._isTracking()?this.path(s,t)._getTracked():this.kernel.get(s,t)}peek(e,t){return this._assertAlive(),this.kernel.peek(e??"",t)}has(e,t){return this._assertAlive(),this.kernel.has(e,t)}set(e,t,s){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.set(e,t,s))}merge(e,t,s){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.merge(e,t,s))}delete(e,t){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.delete(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,r,i=!1;try{s=this._reactivity.batch(()=>t?this.kernel.batch(e):e())}catch(o){i=!0,r=o}return this._closeBatch(i,r),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){this._assertAlive();const s=this.kernel,r=s._openSoleRuntimeBatch(this);if(r===void 0)return this._batch(()=>this._runUntracked(()=>e(...t)),!0);const i=this._reactivity;this._batchDepth++,i._startBatch();let o,a,n=!1;try{o=i._applyUntrackedWithOwner(e,t)}catch(h){n=!0,a=h}try{s._closeSoleRuntimeBatch(this,r,n,a)}catch(h){n=!0,a=h}try{i._endBatch()}catch(h){a=n?new AggregateError([a,h],"Batch operation and effect queue processing failed."):h,n=!0}return this._closeBatch(n,a),o}action(e,t,s){const r=typeof e=="function"?e:t,i=typeof e=="function"?t instanceof E.RaphScope?t:this.rootScope:s??this.rootScope,o=typeof e=="string"?e:`action#${++this._actionCounter}`;if(this._assertOwnerRuntime(i),typeof r!="function")throw new TypeError("[Raph] Action operation must be a function.");if(!o.trim())throw new Error("[Raph] Action name must not be empty.");return(...a)=>{i._assertAlive();const n=this._debugController,h=this._traceCauseStack,u=n.nextOperationId("action"),d=(h.length===0?void 0:h[h.length-1])??u;n.traces("action")&&n.record({...d===void 0?{}:{causeId:d},kind:"action",name:o,...u===void 0?{}:{operationId:u},status:"start"}),d!==void 0&&h.push(d),this._actionDepth++;try{const _=this._applyBatch(r,a);return n.traces("action")&&n.record({...d===void 0?{}:{causeId:d},kind:"action",name:o,...u===void 0?{}:{operationId:u},status:"end"}),_}catch(_){throw this._debugController.record({...d===void 0?{}:{causeId:d},details:{message:T(_)},kind:"action",name:o,...u===void 0?{}:{operationId:u},status:"error"}),this._debugController.record({...d===void 0?{}:{causeId:d},details:{message:T(_)},kind:"error",name:`action:${o}`,...u===void 0?{}:{operationId:u},status:"error"}),_}finally{this._actionDepth--,d!==void 0&&h.pop()}}}untracked(e){return this._assertAlive(),this._runUntracked(e)}scope(e){return this._assertAlive(),new E.RaphScope(e,this)}node(e,t){this._assertAlive(),this._enterWrite();let s;try{s=this._createCommittedNode(e,t)}catch(r){throw this._failWrite(r)}return this._exitWrite(),s._assertAlive(),s}_createCommittedNode(e,t){const s=e.parent??this.root,r=m.createProvisionalNode(s,e,this);try{const i=t?.(r);return r._assertAlive(),s._assertAlive(),r._setApi(i),r._publishCreation(),r}catch(i){try{r.dispose()}catch(o){throw new AggregateError([i,o],`[Raph] Node "${r.id}" setup and cleanup failed.`)}throw i}}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()}derive(e){this._assertAlive();const t=e.compute,s=this.kernel.derive({...e,compute:r=>this._runUntracked(()=>t(r))});return this._own(()=>s.dispose(),this.rootScope),s}dispose(){if(this._disposed)return;this._disposed=!0,this._executionRequested=!1,this._signalLifecycle.owner=void 0;const e=[];try{this._frameLoop?.dispose()}catch(a){e.push(a)}this._frameLoop=void 0;try{this._phases?.dispose()}catch(a){e.push(a)}this._phases=void 0;try{this.root.dispose()}catch(a){e.push(a)}const t=this._collectOwners().sort(j);for(const a of t)if(!(a===this.root||a===this.rootScope||a.disposed))try{a.dispose()}catch(n){e.push(n)}try{this.rootScope.dispose()}catch(a){e.push(a)}const s=`[Raph] Runtime "${this.id}" is disposed.`,r=()=>{throw new v.RaphDisposedError(s)};try{O.disposeReactiveObjectContext(this._reactivity,{assertRead:r,assertWrite:r,throwForeign:r})}catch(a){e.push(a)}this._topOwners.clear(),this._ownersReleased=!0,this._meta=void 0;const i=this._pathHandles;if(this._pathHandles=void 0,i!==void 0){for(const a of i.values())try{a.dispose()}catch(n){e.push(n)}i.clear()}try{this._workGraph.dispose()}catch(a){e.push(a)}try{this.kernel._detachRuntime(this)}catch(a){e.push(a)}const o=[...this._disposedListeners];this._disposedListeners.clear();for(const a of o)try{a()}catch(n){e.push(n)}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,r){if(!this._workGraph._hasStructuralDemand(e)){this._touchMutationBoundary();return}this._runNodeMutation(()=>{this._workGraph.notifyNode(e,"structure",{structure:t,oldAncestors:s,newAncestors:r})})}_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}k.enqueueSweeper(s,e,t),this._nextDisposalSweep=s[0]._sweepDue}_removeDisposalSweeper(e){const t=this._disposalSweepers;t===void 0||!k.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],r=s._afterOwnerDisposals(t);r>t?(s._sweepDue=r,this._nextDisposalSweep=r):(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 r=s._afterOwnerDisposals(t);if(r>t)k.postponeFirstSweeper(e,r);else if(k.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 v.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)}_hasMachineDebug(e){return this._debugController.hasMachine(e)}_traces(e){return this._debugController.traces(e)}_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,r,i=!1){if(typeof s!="function")throw new TypeError("[Raph] Phase callback must be a function.");const o=e.resolvePhase(t),a=r.priority??0;if(!Number.isFinite(a))throw new TypeError("[Raph] Effect priority must be finite.");const n=r.initial??"scheduled";if(n!=="scheduled"&&n!=="sync"&&!(i&&n==="none"))throw new TypeError(`[Raph] Unsupported effect initial mode "${String(n)}".`);return o}_rollbackRegistration(e,t,s,r){let i=t;try{e.dispose()}catch(o){i=new AggregateError([t,o],s)}throw r!==void 0&&r(i),i}_createDebugSnapshot(){const e=this._frameLoop?._debugState()??{running:!1,manual:!1,leases:0},t=[...this._topOwners].filter(s=>s!==this.rootScope&&!(s instanceof m.RaphNode)).map(R.createOwnerSnapshot);return Object.freeze({id:this.id,disposed:this._disposed,pending:!this._disposed&&(this._executionRequested||(this._phases?._debugPending()??!1)),batchDepth:this._batchDepth,kernelBatchDepth:this._kernelBatchDepth,owners:this._liveOwnerCount(),pathHandles:this._pathHandles?.size??0,rootScope:R.createOwnerSnapshot(this.rootScope),scopes:Object.freeze(t),root:R.createOwnerSnapshot(this.root),frameLoop:Object.freeze(e),actionDepth:this._actionDepth,machines:this._debugController.machineCount,traceEvents:this._debugController.traceSize})}_createDebugTree(){const e=this._debugController.machineTreeNodesByOwner(),t=[R.createOwnerTree(this.rootScope,e),R.createOwnerTree(this.root,e),...[...this._topOwners].filter(s=>s!==this.rootScope&&s!==this.root&&!(s instanceof m.RaphNode)).map(s=>R.createOwnerTree(s,e))];return Object.freeze({children:Object.freeze(t),disposed:this._disposed,id:this.id,kind:"runtime"})}_createDebugStats(){const e=this._liveOwnerCount();let t=0;const s={resources:0,sources:0};if(!this._ownersReleased){const r=this._topOwners;for(const a of r)a._isNode?a._countSubtree(s):(t++,s.resources+=a._debugResourceCount(),s.sources+=a._debugSourceCount());const i=this._disposingNodes,o=this._ownerDisposalDepth;for(let a=0;a<o;a++){const n=i[a];n===void 0||n._isLinked()||r.has(n)||n._countSubtree(s)}}return Object.freeze({actors:this._debugController.actorCount,machines:this._debugController.machineCount,nodes:e-t,owners:e,pathHandles:this._pathHandles?.size??0,pending:!this._disposed&&(this._executionRequested||(this._phases?._debugPending()??!1)),resources:s.resources,scopes:t,sources:s.sources,traceEvents:this._debugController.traceSize})}_liveOwnerCount(){return this._ownersReleased?0:this._ownerRegistrations-this._ownerDisposals}_collectOwners(){const e=[];if(this._ownersReleased)return e;const t=this._topOwners;for(const i of t)e.push(i),i._isNode&&i._collectDescendants(e);const s=this._disposingNodes,r=this._ownerDisposalDepth;for(let i=0;i<r;i++){const o=s[i];o===void 0||o._isLinked()||t.has(o)||(e.push(o),o._collectDescendants(e))}return e}_releasePathHandle(e){const t=this._pathHandles;t?.get(e.path)===e&&(t.delete(e.path),t.size===0&&(this._pathHandles=void 0))}get _execution(){return this._assertAlive(),this._phases??=new B.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},(e,t,s)=>{if(this._phaseTraceOperations===void 0&&!this._debugController.traces("phase"))return;let r;t==="start"?(r=this._debugController.nextOperationId("phase"),r!==void 0&&(this._phaseTraceOperations??=new Map).set(e,r)):(r=this._phaseTraceOperations?.get(e),this._phaseTraceOperations?.delete(e),this._phaseTraceOperations?.size===0&&(this._phaseTraceOperations=void 0)),this._debugController.record({...r===void 0?{}:{causeId:r},...s===void 0?{}:{details:{message:T(s)}},kind:"phase",name:e,...r===void 0?{}:{operationId:r},status:t})})}get _clock(){return this._frameLoop??=new G.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 r=t;this._own(()=>{r=void 0},s);const i=e;return i.set=o=>{s._assertAlive(),this._assertWriteAllowed(),this._runWrite(()=>r(o))},i}_own(e,t){try{return t._adoptResource(e)}catch(s){try{e()}catch(r){throw new AggregateError([s,r],"[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,r,i=!1;try{s=e()}catch(a){i=!0,r=a}if(this._mutationDepth--,this._executionBoundaryOpen()){if(i)throw r;return s}const o=this._finishExecutionBoundary();if(i)throw o!==void 0?new AggregateError([r,...o],"[Raph] Mutation and scheduled phase execution failed."):r;return o!==void 0&&b.throwDisposalErrors(o,"[Raph] Mutation phase execution failed."),s}_enterWrite(){this.configuration.scheduler===w.RaphSchedulerType.Sync&&(this._executionRequested=!0),this._mutationDepth++}_exitWrite(){if(this._mutationDepth--,this._executionBoundaryOpen())return;const e=this._finishExecutionBoundary();e!==void 0&&b.throwDisposalErrors(e,"[Raph] Mutation phase execution failed.")}_failWrite(e){if(this._mutationDepth--,this._executionBoundaryOpen())return e;const t=this._finishExecutionBoundary();return t===void 0?e:new AggregateError([e,...t],"[Raph] Mutation and scheduled phase execution failed.")}_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())}_assertTrackedRead(){this._assertAlive();const e=this._reactivity.getActiveOwner();e!==void 0&&e!==this&&this._throwCrossRuntime(e);const t=this._reactivity.getActiveConsumerOwner();t!==void 0&&this._assertImplicitDependency(this.rootScope,t)}_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 v.RaphCrossRuntimeError("[Raph] Implicit dependency crosses runtime boundaries.");if(!(e===this.rootScope||e===t)){if(e instanceof m.RaphNode&&t instanceof m.RaphNode){for(let s=t.parent;s!==null;s=s.parent)if(s===e)return}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 v.RaphActionError("[Raph] Writes are allowed only inside action() or batch().")}_throwCrossRuntime(e){throw new v.RaphCrossRuntimeError(`[Raph] Runtime "${this.id}" cannot be tracked by runtime "${e.id}".`)}_assertAlive(){if(this._disposed)throw new v.RaphDisposedError(`[Raph] Runtime "${this.id}" is disposed.`)}}function H(p){let e=p;return()=>{const t=e;t!==void 0&&(e=void 0,t.dispose())}}function z(p){return()=>{p.record?.dispose()}}function U(){}function j(p,e){return e._order-p._order}function K(p){return p===w.RaphSchedulerType.Sync||p===w.RaphSchedulerType.Microtask||p===w.RaphSchedulerType.AnimationFrame}function V(p,e){const t=Array.isArray(p)?p:[p];if(t.length===0)throw new TypeError("[RaphMeta] watch requires at least one mask.");if(e.namespace!==void 0&&!e.namespace.trim())throw new Error("[RaphMeta] namespace must not be empty.");for(const s of t)P.DataPath.from(s,e)._asMask()}function T(p){return p instanceof Error?p.message:String(p)}exports.RaphRuntime=A;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../path/data-path.utils.cjs"),f=require("../path/DataPath.cjs"),m=require("../path/meta/RaphMeta.cjs"),w=require("../path/RaphKernel.cjs"),u=require("./diagnostics/RaphDebug.cjs"),_=require("./ownership/RaphNode.cjs"),p=require("./RaphRuntimeBase.cjs"),k=require("./reactivity/PathHandle.cjs"),v=require("./reactivity/RaphMetaSource.cjs"),R=require("./reactivity/RuntimeObjectSupport.cjs"),S=require("./reactivity/RuntimeSelectorSupport.cjs");class y extends p.RaphRuntimeBase{constructor(e={}){const t=p.resolveRuntimeConfiguration(e),r=e.kernel??new w.RaphKernel({id:`${t.id}-kernel`}),s=Object.freeze({...t,...e.debug===void 0?{}:{debug:e.debug},kernel:r});super(s,void 0,R.RUNTIME_OBJECT_SUPPORT,S.RUNTIME_SELECTOR_SUPPORT),this._debugController=new u.RaphDebugController(e.debug,this,this._syncPhaseTrace),r._attachRuntime(this)}_pathHandles;_meta;_debug;get kernel(){return this.configuration.kernel}get meta(){if(this._assertAlive(),this._meta!==void 0)return this._meta;const e=new m.RaphMeta(this.kernel,{assertReadable:()=>this._assertAlive(),assertWritable:()=>this._assertWriteAllowed(),runWrite:(t,r)=>this._runWrite(t,r)});return this._meta=Object.freeze({delete:e.delete.bind(e),get:e.get.bind(e),has:e.has.bind(e),merge:e.merge.bind(e),set:e.set.bind(e)})}getDerivedSnapshot(){return this.kernel.getDerivedSnapshot()}get debug(){return this._debug??=Object.freeze({snapshot:()=>this._createDebugSnapshot(),getTree:()=>this._createDebugTree(),stats:()=>this._createDebugStats(),trace:this._debugController.trace,machines:this._debugController.machines})}metaSource(e,t={}){this._assertAlive(),O(e,t);const r=this._workGraph.createProducer(this.rootScope,"path"),s=this._workGraph.producerHooks(r).onDispose,o=v.RaphMetaSource._create(this.rootScope,e,t,()=>this.kernel._watchMeta(o.masks,({events:a})=>this._workGraph.notifyProducerEvents(r,a,!1),o.options,a=>{a&&this._execution.request()}),()=>s(!1));o._bindOwner(this.rootScope._adoptResource(()=>o._disposeOwned()));try{return this._workGraph.setProducerActivation(r,()=>o._activate(),!0),this._workGraph.attachProducer(r,o),o}catch(a){try{o.dispose()}catch(n){throw new AggregateError([a,n],"[Raph] Meta source activation and rollback failed.")}throw a}}path(e,t={}){this._assertAlive();const r=b.parseDataPath(e,t),s=this._pathHandles??=new Map,o=s.get(r.canonical);if(o!==void 0)return o;const a=this._workGraph.createProducer(this.rootScope,"path"),n=this._workGraph.producerHooks(a),i=new k.PathHandle(this.kernel,r,t,h=>this._releasePathHandle(h),this._reactivity,()=>this._assertAlive(),()=>this._assertTrackedRead(),this.configuration.enforceActions?()=>this._assertWriteAllowed():void 0,h=>this._runWrite(h),{token:a,onDispose:n.onDispose},({events:h},c)=>this._workGraph.notifyProducerEvents(a,h,!0,c));try{return this._workGraph.setProducerActivation(a,()=>i._activate(),!0),this._workGraph.attachProducer(a,i),s.set(r.canonical,i),i}catch(h){let c,l=!1;try{i.dispose()}catch(g){l=!0,c=g}throw s.size===0&&this._pathHandles===s&&(this._pathHandles=void 0),l?new AggregateError([h,c],"[Raph] Path source activation and rollback failed."):h}}get(e,t){this._assertTrackedRead();const r=e??"";return this._reactivity._isTracking()?this.path(r,t)._getTracked():this.kernel.get(r,t)}peek(e,t){return this._assertAlive(),this.kernel.peek(e??"",t)}has(e,t){return this._assertAlive(),this.kernel.has(e,t)}set(e,t,r){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.set(e,t,r))}merge(e,t,r){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.merge(e,t,r))}delete(e,t){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.delete(e,t))}derive(e){this._assertAlive();const t=e.compute,r=this.kernel.derive({...e,compute:s=>this._runUntracked(()=>t(s))});return this._own(()=>r.dispose(),this.rootScope),r}_createDebugSnapshot(){const e=this._frameLoop?._debugState()??{running:!1,manual:!1,leases:0},t=[...this._topOwners].filter(r=>r!==this.rootScope&&!(r instanceof _.RaphNode)).map(u.createOwnerSnapshot);return Object.freeze({id:this.id,disposed:this._disposed,pending:!this._disposed&&(this._executionRequested||(this._phases?._debugPending()??!1)),batchDepth:this._batchDepth,kernelBatchDepth:this._kernelBatchDepth,owners:this._liveOwnerCount(),pathHandles:this._pathHandles?.size??0,rootScope:u.createOwnerSnapshot(this.rootScope),scopes:Object.freeze(t),root:u.createOwnerSnapshot(this.root),frameLoop:Object.freeze(e),actionDepth:this._actionDepth,machines:this._debugController.machineCount,traceEvents:this._debugController.traceSize})}_createDebugTree(){const e=this._debugController.machineTreeNodesByOwner(),t=[u.createOwnerTree(this.rootScope,e),u.createOwnerTree(this.root,e),...[...this._topOwners].filter(r=>r!==this.rootScope&&r!==this.root&&!(r instanceof _.RaphNode)).map(r=>u.createOwnerTree(r,e))];return Object.freeze({children:Object.freeze(t),disposed:this._disposed,id:this.id,kind:"runtime"})}_createDebugStats(){const e=this._liveOwnerCount();let t=0;const r={resources:0,sources:0};if(!this._ownersReleased){const s=this._topOwners;for(const n of s)n._isNode?n._countSubtree(r):(t++,r.resources+=n._debugResourceCount(),r.sources+=n._debugSourceCount());const o=this._disposingNodes,a=this._ownerDisposalDepth;for(let n=0;n<a;n++){const i=o[n];i===void 0||i._isLinked()||s.has(i)||i._countSubtree(r)}}return Object.freeze({actors:this._debugController.actorCount,machines:this._debugController.machineCount,nodes:e-t,owners:e,pathHandles:this._pathHandles?.size??0,pending:!this._disposed&&(this._executionRequested||(this._phases?._debugPending()??!1)),resources:r.resources,scopes:t,sources:r.sources,traceEvents:this._debugController.traceSize})}_releasePathHandle(e){const t=this._pathHandles;t?.get(e.path)===e&&(t.delete(e.path),t.size===0&&(this._pathHandles=void 0))}_applyBatch(e,t,r){this._assertAlive();const s=this.kernel,o=s._openSoleRuntimeBatch(this);if(o===void 0)return this._batch(()=>this._runUntracked(()=>Reflect.apply(e,r,t)),!0);const a=this._reactivity;this._batchDepth++,a._startBatch();let n,i,h=!1;try{n=a._applyUntrackedWithOwner(e,t,r)}catch(c){h=!0,i=c}try{s._closeSoleRuntimeBatch(this,o,h,i)}catch(c){h=!0,i=c}try{a._endBatch()}catch(c){i=h?new AggregateError([i,c],"Batch operation and effect queue processing failed."):c,h=!0}return this._closeBatch(h,i),n}_runDataBatch(e){return this.kernel.batch(e)}_disposeDataSources(e){this._meta=void 0;const t=this._pathHandles;if(this._pathHandles=void 0,t!==void 0){for(const r of t.values())try{r.dispose()}catch(s){e.push(s)}t.clear()}}_detachDataPlane(e){try{this.kernel._detachRuntime(this)}catch(t){e.push(t)}}}function O(d,e){const t=Array.isArray(d)?d:[d];if(t.length===0)throw new TypeError("[RaphMeta] watch requires at least one mask.");if(e.namespace!==void 0&&!e.namespace.trim())throw new Error("[RaphMeta] namespace must not be empty.");for(const r of t)f.DataPath.from(r,e)._asMask()}exports.RaphRuntime=y;
|