@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.20
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 +1096 -0
- package/dist/api/Raph.d.ts +59 -190
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +9 -4
- package/dist/api/types.d.ts +162 -17
- package/dist/core-CyilRD7s.js +1055 -0
- package/dist/core-ugchZNqC.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -366
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +306 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +149 -0
- package/dist/debug/api/errors.cjs +1 -1
- package/dist/debug/api/errors.js +10 -7
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +258 -207
- package/dist/debug/path/data-path.utils.cjs +1 -0
- package/dist/debug/path/data-path.utils.js +56 -0
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
- package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
- package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.types.js +1 -0
- package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +478 -306
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +280 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +798 -519
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
- package/dist/debug/runtime/errors.cjs +1 -1
- package/dist/debug/runtime/errors.js +6 -3
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +206 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +101 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +17 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -38
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +837 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
- package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
- package/dist/path/RaphKernel.d.ts +13 -10
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
- package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
- package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
- package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
- package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
- package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
- package/dist/path/path.types.d.ts +3 -2
- package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
- package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
- package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
- package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -1
- package/dist/path.js +16 -16
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +46 -38
- package/dist/reactivity/engine.d.ts +17 -3
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/types.d.ts +25 -0
- package/dist/reactivity.cjs +1 -1
- package/dist/reactivity.js +12 -12
- package/dist/runtime/RaphRuntime.d.ts +132 -192
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
- package/dist/runtime/ownership/RaphNode.d.ts +40 -0
- package/dist/runtime/ownership/RaphScope.d.ts +38 -0
- package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +92 -0
- package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
- package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
- package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +68 -35
- package/ReadMe.md +0 -153
- package/dist/api/public.d.ts +0 -22
- package/dist/debug/api/public.cjs +0 -1
- package/dist/debug/api/public.js +0 -40
- package/dist/debug/path/AdapterPathStore.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/public.cjs +0 -1
- package/dist/debug/path/public.js +0 -18
- package/dist/debug/runtime/PathHandle.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphNode.cjs +0 -1
- package/dist/debug/runtime/RaphNode.js +0 -143
- package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
- package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
- package/dist/debug/runtime/RaphScope.cjs +0 -1
- package/dist/debug/runtime/RaphScope.js +0 -64
- package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
- package/dist/debug/runtime/RuntimeReactivity.js +0 -154
- package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
- package/dist/debug/runtime/RuntimeWatch.js +0 -71
- package/dist/debug/runtime/public.cjs +0 -1
- package/dist/debug/runtime/public.js +0 -18
- package/dist/path/public.d.ts +0 -14
- package/dist/runtime/RaphDebug.d.ts +0 -32
- package/dist/runtime/RaphNode.d.ts +0 -68
- package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
- package/dist/runtime/RaphScope.d.ts +0 -50
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
- /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
- /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
- /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
- /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
- /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
- /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
- /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
- /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
- /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
- /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
- /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
- /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
- /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
- /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
- /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
- /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
- /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
- /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
- /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
- /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
- /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var f=Object.defineProperty;var l=(i,e,t)=>e in i?f(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>l(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../ownership/RaphNode.cjs"),p=Object.freeze(["action","machine","error"]),v=1024;class b{constructor(e){a(this,"_capacity",v);a(this,"_context","none");a(this,"_guards","failed");a(this,"_include",new Set(p));a(this,"_enabled",!1);a(this,"_events");a(this,"_eventStart",0);a(this,"_eventSize",0);a(this,"_sequence",0);a(this,"_operationSequence",0);a(this,"_machines");a(this,"trace");a(this,"machines");const t=e==null?void 0:e.trace;t!==void 0&&t!==!1&&(this._applyOptions(t),this._enabled=!0,this._ensureBuffer()),this.trace=Object.freeze({clear:()=>this.clear(),read:s=>this.read(s),start:s=>this.start(s),status:()=>this.status(),stop:()=>this.stop()}),this.machines=Object.freeze({list:()=>this.listMachines(),snapshot:s=>this.machineSnapshot(s)})}start(e){e!==void 0&&this._applyOptions(e),this._enabled=!0,this._ensureBuffer()}stop(){this._enabled=!1}clear(){var e;(e=this._events)==null||e.fill(void 0),this._eventStart=0,this._eventSize=0}read(e={}){const t=e.since??-1,s=e.limit??Number.POSITIVE_INFINITY;if(!Number.isFinite(s)&&s!==Number.POSITIVE_INFINITY)throw new TypeError("[Raph] Trace limit must be a positive integer.");if(s!==Number.POSITIVE_INFINITY&&(!Number.isInteger(s)||s<0))throw new TypeError("[Raph] Trace limit must be a positive integer.");const n=this._events;if(n===void 0||this._eventSize===0||s===0)return Object.freeze([]);const d=[];for(let r=0;r<this._eventSize;r++){const c=n[(this._eventStart+r)%this._capacity];if(!(c===void 0||c.sequence<=t)&&(d.push(c),d.length>=s))break}return Object.freeze(d)}status(){return Object.freeze({capacity:this._capacity,context:this._context,enabled:this._enabled,guards:this._guards,include:Object.freeze([...this._include]),size:this._eventSize})}nextOperationId(e){if(!(!this._enabled||!this._include.has(e)))return++this._operationSequence}traces(e){return this._enabled&&this._include.has(e)}record(e){if(!this._enabled||!this._include.has(e.kind)||e.guard!==void 0&&(this._guards==="none"||this._guards==="failed"&&e.guard!=="failed"))return;const t=Object.freeze({...e.causeId===void 0?{}:{causeId:e.causeId},...e.context===void 0||this._context==="none"?{}:{contextKeys:Object.freeze(Object.keys(e.context))},...e.details===void 0?{}:{details:Object.freeze({...e.details})},...e.guard===void 0?{}:{guard:e.guard},...e.operationId===void 0?{}:{operationId:e.operationId},...e.status===void 0?{}:{status:e.status},kind:e.kind,name:e.name,sequence:++this._sequence,timestamp:Date.now()}),s=this._ensureBuffer();if(this._eventSize<this._capacity){s[(this._eventStart+this._eventSize++)%this._capacity]=t;return}s[this._eventStart]=t,this._eventStart=(this._eventStart+1)%this._capacity}registerMachine(e){const t=this._machines??(this._machines=new Map);if(t.has(e.id))throw new Error(`[Raph] Machine diagnostic id "${e.id}" is already registered.`);return t.set(e.id,e),()=>{t.get(e.id)===e&&t.delete(e.id),t.size===0&&this._machines===t&&(this._machines=void 0)}}hasMachine(e){var t;return((t=this._machines)==null?void 0:t.has(e))??!1}listMachines(){var t;const e=[];for(const s of((t=this._machines)==null?void 0:t.values())??[]){const n=s.snapshot();e.push(Object.freeze({active:n.active,id:n.id,modelId:n.modelId,ownerId:n.ownerId,...n.parentId===void 0?{}:{parentId:n.parentId},revision:n.revision,status:n.status}))}return Object.freeze(e)}machineSnapshot(e){var t,s;return(s=(t=this._machines)==null?void 0:t.get(e))==null?void 0:s.snapshot()}get machineCount(){var e;return((e=this._machines)==null?void 0:e.size)??0}get traceSize(){return this._eventSize}get actorCount(){var t;let e=0;for(const s of((t=this._machines)==null?void 0:t.values())??[])e+=s.snapshot().actors.length;return e}machineTreeNodesByOwner(){var d;const e=[...((d=this._machines)==null?void 0:d.values())??[]],t=new Map(e.map(r=>[r.id,r])),s=new Map;for(const r of e){if(r.parentId===void 0||!t.has(r.parentId))continue;const c=s.get(r.parentId)??[];c.push(r),s.set(r.parentId,c)}const n=new Map;for(const r of e){if(r.parentId!==void 0&&t.has(r.parentId))continue;const c=n.get(r.ownerId)??[];c.push(_(r,s,!1)),n.set(r.ownerId,c)}return new Map([...n].map(([r,c])=>[r,Object.freeze(c)]))}_applyOptions(e){if(e.capacity!==void 0){if(!Number.isInteger(e.capacity)||e.capacity<=0)throw new TypeError("[Raph] Trace capacity must be a positive integer.");e.capacity!==this._capacity&&(this._capacity=e.capacity,this._events=void 0,this._eventStart=0,this._eventSize=0)}if(e.context!==void 0){if(e.context!=="none"&&e.context!=="keys")throw new TypeError('[Raph] Trace context must be "none" or "keys".');this._context=e.context}if(e.guards!==void 0){if(e.guards!=="none"&&e.guards!=="failed"&&e.guards!=="all")throw new TypeError('[Raph] Trace guards must be "none", "failed" or "all".');this._guards=e.guards}if(e.include!==void 0){const t=new Set;for(const s of e.include){if(s!=="action"&&s!=="machine"&&s!=="phase"&&s!=="error")throw new TypeError(`[Raph] Unsupported trace kind "${String(s)}".`);t.add(s)}this._include=t}}_ensureBuffer(){return this._events??(this._events=new Array(this._capacity))}}function o(i){const e=i instanceof h.RaphNode?i.children.map(o):[];return Object.freeze({children:Object.freeze(e),disposed:i.disposed,id:i.id,kind:i instanceof h.RaphNode?"node":"scope",resources:i._debugResourceCount(),sources:i._debugSourceCount()})}function u(i,e=new Map){const t=i instanceof h.RaphNode?i.children.map(n=>u(n,e)):[],s=i._debugResourceCount();return s!==0&&t.push(Object.freeze({children:Object.freeze([]),count:s,id:`${i.id}:resources`,kind:"resource"})),t.push(...e.get(i.id)??[]),Object.freeze({children:Object.freeze(t),disposed:i.disposed,id:i.id,kind:i instanceof h.RaphNode?"node":"scope"})}function _(i,e,t){const s=i.snapshot();return Object.freeze({children:Object.freeze((e.get(i.id)??[]).map(n=>_(n,e,!0))),id:s.id,kind:t?"actor":"machine",status:s.status})}exports.RaphDebugController=b;exports.createOwnerSnapshot=o;exports.createOwnerTree=u;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var f = (i, e, t) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var a = (i, e, t) => f(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { RaphNode as h } from "../ownership/RaphNode.js";
|
|
5
|
+
const _ = Object.freeze([
|
|
6
|
+
"action",
|
|
7
|
+
"machine",
|
|
8
|
+
"error"
|
|
9
|
+
]), l = 1024;
|
|
10
|
+
class I {
|
|
11
|
+
/**
|
|
12
|
+
* Создаёт controller; ring buffer появляется только при включённом trace.
|
|
13
|
+
*/
|
|
14
|
+
constructor(e) {
|
|
15
|
+
a(this, "_capacity", l);
|
|
16
|
+
a(this, "_context", "none");
|
|
17
|
+
a(this, "_guards", "failed");
|
|
18
|
+
a(this, "_include", new Set(_));
|
|
19
|
+
a(this, "_enabled", !1);
|
|
20
|
+
a(this, "_events");
|
|
21
|
+
a(this, "_eventStart", 0);
|
|
22
|
+
a(this, "_eventSize", 0);
|
|
23
|
+
a(this, "_sequence", 0);
|
|
24
|
+
a(this, "_operationSequence", 0);
|
|
25
|
+
a(this, "_machines");
|
|
26
|
+
a(this, "trace");
|
|
27
|
+
a(this, "machines");
|
|
28
|
+
const t = e == null ? void 0 : e.trace;
|
|
29
|
+
t !== void 0 && t !== !1 && (this._applyOptions(t), this._enabled = !0, this._ensureBuffer()), this.trace = Object.freeze({
|
|
30
|
+
clear: () => this.clear(),
|
|
31
|
+
read: (s) => this.read(s),
|
|
32
|
+
start: (s) => this.start(s),
|
|
33
|
+
status: () => this.status(),
|
|
34
|
+
stop: () => this.stop()
|
|
35
|
+
}), this.machines = Object.freeze({
|
|
36
|
+
list: () => this.listMachines(),
|
|
37
|
+
snapshot: (s) => this.machineSnapshot(s)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------
|
|
41
|
+
// PUBLIC API
|
|
42
|
+
// ---------------------------------------------
|
|
43
|
+
/**
|
|
44
|
+
* Включает trace с текущими или явно переданными настройками.
|
|
45
|
+
*/
|
|
46
|
+
start(e) {
|
|
47
|
+
e !== void 0 && this._applyOptions(e), this._enabled = !0, this._ensureBuffer();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Останавливает запись, сохраняя уже накопленные events.
|
|
51
|
+
*/
|
|
52
|
+
stop() {
|
|
53
|
+
this._enabled = !1;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Удаляет все накопленные events, не меняя status trace.
|
|
57
|
+
*/
|
|
58
|
+
clear() {
|
|
59
|
+
var e;
|
|
60
|
+
(e = this._events) == null || e.fill(void 0), this._eventStart = 0, this._eventSize = 0;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Формирует immutable chronological copy ring buffer.
|
|
64
|
+
*/
|
|
65
|
+
read(e = {}) {
|
|
66
|
+
const t = e.since ?? -1, s = e.limit ?? Number.POSITIVE_INFINITY;
|
|
67
|
+
if (!Number.isFinite(s) && s !== Number.POSITIVE_INFINITY)
|
|
68
|
+
throw new TypeError("[Raph] Trace limit must be a positive integer.");
|
|
69
|
+
if (s !== Number.POSITIVE_INFINITY && (!Number.isInteger(s) || s < 0))
|
|
70
|
+
throw new TypeError("[Raph] Trace limit must be a positive integer.");
|
|
71
|
+
const n = this._events;
|
|
72
|
+
if (n === void 0 || this._eventSize === 0 || s === 0)
|
|
73
|
+
return Object.freeze([]);
|
|
74
|
+
const d = [];
|
|
75
|
+
for (let r = 0; r < this._eventSize; r++) {
|
|
76
|
+
const c = n[(this._eventStart + r) % this._capacity];
|
|
77
|
+
if (!(c === void 0 || c.sequence <= t) && (d.push(c), d.length >= s))
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
return Object.freeze(d);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Возвращает текущую конфигурацию и заполнение buffer.
|
|
84
|
+
*/
|
|
85
|
+
status() {
|
|
86
|
+
return Object.freeze({
|
|
87
|
+
capacity: this._capacity,
|
|
88
|
+
context: this._context,
|
|
89
|
+
enabled: this._enabled,
|
|
90
|
+
guards: this._guards,
|
|
91
|
+
include: Object.freeze([...this._include]),
|
|
92
|
+
size: this._eventSize
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Выделяет operation ID только когда trace активен для этого kind.
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
nextOperationId(e) {
|
|
100
|
+
if (!(!this._enabled || !this._include.has(e)))
|
|
101
|
+
return ++this._operationSequence;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Проверяет active trace path без выделения operation ID.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
traces(e) {
|
|
109
|
+
return this._enabled && this._include.has(e);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Записывает одно событие без allocations/timestamp на disabled path.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
record(e) {
|
|
116
|
+
if (!this._enabled || !this._include.has(e.kind) || e.guard !== void 0 && (this._guards === "none" || this._guards === "failed" && e.guard !== "failed"))
|
|
117
|
+
return;
|
|
118
|
+
const t = Object.freeze({
|
|
119
|
+
...e.causeId === void 0 ? {} : { causeId: e.causeId },
|
|
120
|
+
...e.context === void 0 || this._context === "none" ? {} : { contextKeys: Object.freeze(Object.keys(e.context)) },
|
|
121
|
+
...e.details === void 0 ? {} : { details: Object.freeze({ ...e.details }) },
|
|
122
|
+
...e.guard === void 0 ? {} : { guard: e.guard },
|
|
123
|
+
...e.operationId === void 0 ? {} : { operationId: e.operationId },
|
|
124
|
+
...e.status === void 0 ? {} : { status: e.status },
|
|
125
|
+
kind: e.kind,
|
|
126
|
+
name: e.name,
|
|
127
|
+
sequence: ++this._sequence,
|
|
128
|
+
timestamp: Date.now()
|
|
129
|
+
}), s = this._ensureBuffer();
|
|
130
|
+
if (this._eventSize < this._capacity) {
|
|
131
|
+
s[(this._eventStart + this._eventSize++) % this._capacity] = t;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
s[this._eventStart] = t, this._eventStart = (this._eventStart + 1) % this._capacity;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Регистрирует read-only machine projection без импорта machine engine в Runtime.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
registerMachine(e) {
|
|
141
|
+
const t = this._machines ?? (this._machines = /* @__PURE__ */ new Map());
|
|
142
|
+
if (t.has(e.id))
|
|
143
|
+
throw new Error(`[Raph] Machine diagnostic id "${e.id}" is already registered.`);
|
|
144
|
+
return t.set(e.id, e), () => {
|
|
145
|
+
t.get(e.id) === e && t.delete(e.id), t.size === 0 && this._machines === t && (this._machines = void 0);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Проверяет diagnostic identity без создания public snapshot.
|
|
150
|
+
*
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
hasMachine(e) {
|
|
154
|
+
var t;
|
|
155
|
+
return ((t = this._machines) == null ? void 0 : t.has(e)) ?? !1;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Возвращает compact machine summaries без выполнения guards.
|
|
159
|
+
*/
|
|
160
|
+
listMachines() {
|
|
161
|
+
var t;
|
|
162
|
+
const e = [];
|
|
163
|
+
for (const s of ((t = this._machines) == null ? void 0 : t.values()) ?? []) {
|
|
164
|
+
const n = s.snapshot();
|
|
165
|
+
e.push(Object.freeze({
|
|
166
|
+
active: n.active,
|
|
167
|
+
id: n.id,
|
|
168
|
+
modelId: n.modelId,
|
|
169
|
+
ownerId: n.ownerId,
|
|
170
|
+
...n.parentId === void 0 ? {} : { parentId: n.parentId },
|
|
171
|
+
revision: n.revision,
|
|
172
|
+
status: n.status
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
return Object.freeze(e);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Читает готовый machine snapshot; transition selection и guards не вызываются.
|
|
179
|
+
*/
|
|
180
|
+
machineSnapshot(e) {
|
|
181
|
+
var t, s;
|
|
182
|
+
return (s = (t = this._machines) == null ? void 0 : t.get(e)) == null ? void 0 : s.snapshot();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Возвращает число зарегистрированных machines.
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
188
|
+
get machineCount() {
|
|
189
|
+
var e;
|
|
190
|
+
return ((e = this._machines) == null ? void 0 : e.size) ?? 0;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Возвращает число текущих trace events.
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
get traceSize() {
|
|
197
|
+
return this._eventSize;
|
|
198
|
+
}
|
|
199
|
+
/** Возвращает число child actors по уже готовым snapshots. @internal */
|
|
200
|
+
get actorCount() {
|
|
201
|
+
var t;
|
|
202
|
+
let e = 0;
|
|
203
|
+
for (const s of ((t = this._machines) == null ? void 0 : t.values()) ?? [])
|
|
204
|
+
e += s.snapshot().actors.length;
|
|
205
|
+
return e;
|
|
206
|
+
}
|
|
207
|
+
/** Группирует machine/actor ветви по фактическому lifecycle owner. @internal */
|
|
208
|
+
machineTreeNodesByOwner() {
|
|
209
|
+
var d;
|
|
210
|
+
const e = [...((d = this._machines) == null ? void 0 : d.values()) ?? []], t = new Map(e.map((r) => [r.id, r])), s = /* @__PURE__ */ new Map();
|
|
211
|
+
for (const r of e) {
|
|
212
|
+
if (r.parentId === void 0 || !t.has(r.parentId))
|
|
213
|
+
continue;
|
|
214
|
+
const c = s.get(r.parentId) ?? [];
|
|
215
|
+
c.push(r), s.set(r.parentId, c);
|
|
216
|
+
}
|
|
217
|
+
const n = /* @__PURE__ */ new Map();
|
|
218
|
+
for (const r of e) {
|
|
219
|
+
if (r.parentId !== void 0 && t.has(r.parentId))
|
|
220
|
+
continue;
|
|
221
|
+
const c = n.get(r.ownerId) ?? [];
|
|
222
|
+
c.push(o(r, s, !1)), n.set(r.ownerId, c);
|
|
223
|
+
}
|
|
224
|
+
return new Map([...n].map(([r, c]) => [r, Object.freeze(c)]));
|
|
225
|
+
}
|
|
226
|
+
// ---------------------------------------------
|
|
227
|
+
// PRIVATE
|
|
228
|
+
// ---------------------------------------------
|
|
229
|
+
_applyOptions(e) {
|
|
230
|
+
if (e.capacity !== void 0) {
|
|
231
|
+
if (!Number.isInteger(e.capacity) || e.capacity <= 0)
|
|
232
|
+
throw new TypeError("[Raph] Trace capacity must be a positive integer.");
|
|
233
|
+
e.capacity !== this._capacity && (this._capacity = e.capacity, this._events = void 0, this._eventStart = 0, this._eventSize = 0);
|
|
234
|
+
}
|
|
235
|
+
if (e.context !== void 0) {
|
|
236
|
+
if (e.context !== "none" && e.context !== "keys")
|
|
237
|
+
throw new TypeError('[Raph] Trace context must be "none" or "keys".');
|
|
238
|
+
this._context = e.context;
|
|
239
|
+
}
|
|
240
|
+
if (e.guards !== void 0) {
|
|
241
|
+
if (e.guards !== "none" && e.guards !== "failed" && e.guards !== "all")
|
|
242
|
+
throw new TypeError('[Raph] Trace guards must be "none", "failed" or "all".');
|
|
243
|
+
this._guards = e.guards;
|
|
244
|
+
}
|
|
245
|
+
if (e.include !== void 0) {
|
|
246
|
+
const t = /* @__PURE__ */ new Set();
|
|
247
|
+
for (const s of e.include) {
|
|
248
|
+
if (s !== "action" && s !== "machine" && s !== "phase" && s !== "error")
|
|
249
|
+
throw new TypeError(`[Raph] Unsupported trace kind "${String(s)}".`);
|
|
250
|
+
t.add(s);
|
|
251
|
+
}
|
|
252
|
+
this._include = t;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
_ensureBuffer() {
|
|
256
|
+
return this._events ?? (this._events = new Array(this._capacity));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function p(i) {
|
|
260
|
+
const e = i instanceof h ? i.children.map(p) : [];
|
|
261
|
+
return Object.freeze({
|
|
262
|
+
children: Object.freeze(e),
|
|
263
|
+
disposed: i.disposed,
|
|
264
|
+
id: i.id,
|
|
265
|
+
kind: i instanceof h ? "node" : "scope",
|
|
266
|
+
resources: i._debugResourceCount(),
|
|
267
|
+
sources: i._debugSourceCount()
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function v(i, e = /* @__PURE__ */ new Map()) {
|
|
271
|
+
const t = i instanceof h ? i.children.map((n) => v(n, e)) : [], s = i._debugResourceCount();
|
|
272
|
+
return s !== 0 && t.push(Object.freeze({
|
|
273
|
+
children: Object.freeze([]),
|
|
274
|
+
count: s,
|
|
275
|
+
id: `${i.id}:resources`,
|
|
276
|
+
kind: "resource"
|
|
277
|
+
})), t.push(...e.get(i.id) ?? []), Object.freeze({
|
|
278
|
+
children: Object.freeze(t),
|
|
279
|
+
disposed: i.disposed,
|
|
280
|
+
id: i.id,
|
|
281
|
+
kind: i instanceof h ? "node" : "scope"
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function o(i, e, t) {
|
|
285
|
+
const s = i.snapshot();
|
|
286
|
+
return Object.freeze({
|
|
287
|
+
children: Object.freeze((e.get(i.id) ?? []).map((n) => o(n, e, !0))),
|
|
288
|
+
id: s.id,
|
|
289
|
+
kind: t ? "actor" : "machine",
|
|
290
|
+
status: s.status
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
export {
|
|
294
|
+
I as RaphDebugController,
|
|
295
|
+
p as createOwnerSnapshot,
|
|
296
|
+
v as createOwnerTree
|
|
297
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../api/errors.cjs");class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../api/errors.cjs");class e extends r.RaphError{}class o extends r.RaphError{}class a extends r.RaphError{}class p extends r.RaphError{}exports.RaphActionError=e;exports.RaphCrossRuntimeError=a;exports.RaphDisposedError=o;exports.RaphPhaseProcessError=p;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { RaphError as r } from "../api/errors.js";
|
|
2
|
-
class
|
|
2
|
+
class o extends r {
|
|
3
3
|
}
|
|
4
4
|
class a extends r {
|
|
5
5
|
}
|
|
6
6
|
class p extends r {
|
|
7
7
|
}
|
|
8
|
+
class t extends r {
|
|
9
|
+
}
|
|
8
10
|
export {
|
|
9
|
-
|
|
11
|
+
o as RaphActionError,
|
|
10
12
|
p as RaphCrossRuntimeError,
|
|
11
|
-
a as RaphDisposedError
|
|
13
|
+
a as RaphDisposedError,
|
|
14
|
+
t as RaphPhaseProcessError
|
|
12
15
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var f=Object.defineProperty;var l=(i,e,s)=>e in i?f(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s;var o=(i,e,s)=>l(i,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("../errors.cjs");class d{constructor(e,s=null){o(this,"_registrations");o(this,"_children");o(this,"_selfPaused",!1);o(this,"_ancestorPauses",0);o(this,"_disposed",!1);o(this,"_releaseOwner");o(this,"_parent");if(this._owner=e,e._assertAlive(),(s==null?void 0:s.disposed)===!0)throw new _.RaphDisposedError("[Raph] Parent effect scope is disposed.");if(s!==null&&s._owner.runtime!==e.runtime)throw new TypeError("[Raph] Parent effect scope belongs to another runtime.");this._parent=s,s==null||s._addChild(this),this._ancestorPauses=(s==null?void 0:s.paused)===!0?1:0,this._releaseOwner=e.own(()=>this.dispose())}get paused(){return this._selfPaused||this._ancestorPauses!==0}get disposed(){return this._disposed}fork(e){return this._assertAlive(),new d(e,this)}effect(e,s,t){return this._assertAlive(),this._add(this._owner.runtime._effectRegistration(this._owner,e,s,t,this.paused))}watch(e,s,t,r){return this._assertAlive(),this._add(this._owner.runtime._watchRegistration(this._owner,e,s,t,r,this.paused))}pause(){this._assertAlive(),this._owner.runtime._runPhaseTransition(()=>this._pause())}resume(){this._assertAlive(),this._owner.runtime._runPhaseTransition(()=>this._resume())}_pause(){if(this._selfPaused)return;const e=this.paused;if(this._selfPaused=!0,e)return;const s=[];for(const t of this._registrations??[])try{t.registration.pause()}catch(r){s.push(r)}for(const t of this._children??[])try{t._changeAncestorPause(1)}catch(r){s.push(r)}n(s,"[Raph] Pausable effect scope pause failed.")}_resume(){if(!this._selfPaused||(this._selfPaused=!1,this.paused))return;const e=[];for(const s of this._registrations??[])try{s.registration.resume()}catch(t){e.push(t)}for(const s of this._children??[])try{s._changeAncestorPause(-1)}catch(t){e.push(t)}n(e,"[Raph] Pausable effect scope resume failed.")}dispose(){var t,r,a,u;if(this._disposed)return;this._disposed=!0;const e=this._owner.disposed,s=[];for(const h of[...this._children??[]])try{h.dispose()}catch(c){s.push(c)}(t=this._children)==null||t.clear(),this._children=void 0;for(const h of this._registrations??[])if(h.active=!1,!e)try{h.registration.dispose()}catch(c){s.push(c)}if((r=this._registrations)==null||r.clear(),this._registrations=void 0,(u=(a=this._parent)==null?void 0:a._children)==null||u.delete(this),!e)try{this._releaseOwner()}catch(h){s.push(h)}n(s,"[Raph] Pausable effect scope disposal failed.")}_add(e){if(this._disposed||this._owner.disposed)return e.dispose(),p;const s={active:!0,registration:e};return(this._registrations??(this._registrations=new Set)).add(s),()=>{var t;s.active&&(s.active=!1,(t=this._registrations)==null||t.delete(s),e.dispose())}}_assertAlive(){if(this._disposed||this._owner.disposed)throw new _.RaphDisposedError("[Raph] Pausable effect scope is disposed.")}_addChild(e){(this._children??(this._children=new Set)).add(e)}_changeAncestorPause(e){if(this._disposed)return;const s=this.paused;if(this._ancestorPauses+=e,this._ancestorPauses<0)throw this._ancestorPauses=0,new Error("[Raph] Effect scope ancestor pause state is unbalanced.");if(s===this.paused)return;const t=[];for(const r of this._registrations??[])try{this.paused?r.registration.pause():r.registration.resume()}catch(a){t.push(a)}for(const r of this._children??[])try{r._changeAncestorPause(e)}catch(a){t.push(a)}n(t,"[Raph] Pausable effect scope ancestor transition failed.")}}function n(i,e){if(i.length===1)throw i[0];if(i.length>1)throw new AggregateError(i,e)}function p(){}exports.RaphEffectScope=d;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var l = (r, e, s) => e in r ? f(r, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[e] = s;
|
|
3
|
+
var o = (r, e, s) => l(r, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { RaphDisposedError as u } from "../errors.js";
|
|
5
|
+
class _ {
|
|
6
|
+
constructor(e, s = null) {
|
|
7
|
+
o(this, "_registrations");
|
|
8
|
+
o(this, "_children");
|
|
9
|
+
o(this, "_selfPaused", !1);
|
|
10
|
+
o(this, "_ancestorPauses", 0);
|
|
11
|
+
o(this, "_disposed", !1);
|
|
12
|
+
o(this, "_releaseOwner");
|
|
13
|
+
o(this, "_parent");
|
|
14
|
+
if (this._owner = e, e._assertAlive(), (s == null ? void 0 : s.disposed) === !0)
|
|
15
|
+
throw new u("[Raph] Parent effect scope is disposed.");
|
|
16
|
+
if (s !== null && s._owner.runtime !== e.runtime)
|
|
17
|
+
throw new TypeError("[Raph] Parent effect scope belongs to another runtime.");
|
|
18
|
+
this._parent = s, s == null || s._addChild(this), this._ancestorPauses = (s == null ? void 0 : s.paused) === !0 ? 1 : 0, this._releaseOwner = e.own(() => this.dispose());
|
|
19
|
+
}
|
|
20
|
+
get paused() {
|
|
21
|
+
return this._selfPaused || this._ancestorPauses !== 0;
|
|
22
|
+
}
|
|
23
|
+
get disposed() {
|
|
24
|
+
return this._disposed;
|
|
25
|
+
}
|
|
26
|
+
fork(e) {
|
|
27
|
+
return this._assertAlive(), new _(e, this);
|
|
28
|
+
}
|
|
29
|
+
effect(e, s, t) {
|
|
30
|
+
return this._assertAlive(), this._add(this._owner.runtime._effectRegistration(
|
|
31
|
+
this._owner,
|
|
32
|
+
e,
|
|
33
|
+
s,
|
|
34
|
+
t,
|
|
35
|
+
this.paused
|
|
36
|
+
));
|
|
37
|
+
}
|
|
38
|
+
watch(e, s, t, i) {
|
|
39
|
+
return this._assertAlive(), this._add(this._owner.runtime._watchRegistration(
|
|
40
|
+
this._owner,
|
|
41
|
+
e,
|
|
42
|
+
s,
|
|
43
|
+
t,
|
|
44
|
+
i,
|
|
45
|
+
this.paused
|
|
46
|
+
));
|
|
47
|
+
}
|
|
48
|
+
pause() {
|
|
49
|
+
this._assertAlive(), this._owner.runtime._runPhaseTransition(() => this._pause());
|
|
50
|
+
}
|
|
51
|
+
resume() {
|
|
52
|
+
this._assertAlive(), this._owner.runtime._runPhaseTransition(() => this._resume());
|
|
53
|
+
}
|
|
54
|
+
_pause() {
|
|
55
|
+
if (this._selfPaused)
|
|
56
|
+
return;
|
|
57
|
+
const e = this.paused;
|
|
58
|
+
if (this._selfPaused = !0, e)
|
|
59
|
+
return;
|
|
60
|
+
const s = [];
|
|
61
|
+
for (const t of this._registrations ?? [])
|
|
62
|
+
try {
|
|
63
|
+
t.registration.pause();
|
|
64
|
+
} catch (i) {
|
|
65
|
+
s.push(i);
|
|
66
|
+
}
|
|
67
|
+
for (const t of this._children ?? [])
|
|
68
|
+
try {
|
|
69
|
+
t._changeAncestorPause(1);
|
|
70
|
+
} catch (i) {
|
|
71
|
+
s.push(i);
|
|
72
|
+
}
|
|
73
|
+
n(s, "[Raph] Pausable effect scope pause failed.");
|
|
74
|
+
}
|
|
75
|
+
_resume() {
|
|
76
|
+
if (!this._selfPaused || (this._selfPaused = !1, this.paused))
|
|
77
|
+
return;
|
|
78
|
+
const e = [];
|
|
79
|
+
for (const s of this._registrations ?? [])
|
|
80
|
+
try {
|
|
81
|
+
s.registration.resume();
|
|
82
|
+
} catch (t) {
|
|
83
|
+
e.push(t);
|
|
84
|
+
}
|
|
85
|
+
for (const s of this._children ?? [])
|
|
86
|
+
try {
|
|
87
|
+
s._changeAncestorPause(-1);
|
|
88
|
+
} catch (t) {
|
|
89
|
+
e.push(t);
|
|
90
|
+
}
|
|
91
|
+
n(e, "[Raph] Pausable effect scope resume failed.");
|
|
92
|
+
}
|
|
93
|
+
dispose() {
|
|
94
|
+
var t, i, h, d;
|
|
95
|
+
if (this._disposed)
|
|
96
|
+
return;
|
|
97
|
+
this._disposed = !0;
|
|
98
|
+
const e = this._owner.disposed, s = [];
|
|
99
|
+
for (const a of [...this._children ?? []])
|
|
100
|
+
try {
|
|
101
|
+
a.dispose();
|
|
102
|
+
} catch (c) {
|
|
103
|
+
s.push(c);
|
|
104
|
+
}
|
|
105
|
+
(t = this._children) == null || t.clear(), this._children = void 0;
|
|
106
|
+
for (const a of this._registrations ?? [])
|
|
107
|
+
if (a.active = !1, !e)
|
|
108
|
+
try {
|
|
109
|
+
a.registration.dispose();
|
|
110
|
+
} catch (c) {
|
|
111
|
+
s.push(c);
|
|
112
|
+
}
|
|
113
|
+
if ((i = this._registrations) == null || i.clear(), this._registrations = void 0, (d = (h = this._parent) == null ? void 0 : h._children) == null || d.delete(this), !e)
|
|
114
|
+
try {
|
|
115
|
+
this._releaseOwner();
|
|
116
|
+
} catch (a) {
|
|
117
|
+
s.push(a);
|
|
118
|
+
}
|
|
119
|
+
n(s, "[Raph] Pausable effect scope disposal failed.");
|
|
120
|
+
}
|
|
121
|
+
_add(e) {
|
|
122
|
+
if (this._disposed || this._owner.disposed)
|
|
123
|
+
return e.dispose(), p;
|
|
124
|
+
const s = { active: !0, registration: e };
|
|
125
|
+
return (this._registrations ?? (this._registrations = /* @__PURE__ */ new Set())).add(s), () => {
|
|
126
|
+
var t;
|
|
127
|
+
s.active && (s.active = !1, (t = this._registrations) == null || t.delete(s), e.dispose());
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
_assertAlive() {
|
|
131
|
+
if (this._disposed || this._owner.disposed)
|
|
132
|
+
throw new u("[Raph] Pausable effect scope is disposed.");
|
|
133
|
+
}
|
|
134
|
+
_addChild(e) {
|
|
135
|
+
(this._children ?? (this._children = /* @__PURE__ */ new Set())).add(e);
|
|
136
|
+
}
|
|
137
|
+
_changeAncestorPause(e) {
|
|
138
|
+
if (this._disposed)
|
|
139
|
+
return;
|
|
140
|
+
const s = this.paused;
|
|
141
|
+
if (this._ancestorPauses += e, this._ancestorPauses < 0)
|
|
142
|
+
throw this._ancestorPauses = 0, new Error("[Raph] Effect scope ancestor pause state is unbalanced.");
|
|
143
|
+
if (s === this.paused)
|
|
144
|
+
return;
|
|
145
|
+
const t = [];
|
|
146
|
+
for (const i of this._registrations ?? [])
|
|
147
|
+
try {
|
|
148
|
+
this.paused ? i.registration.pause() : i.registration.resume();
|
|
149
|
+
} catch (h) {
|
|
150
|
+
t.push(h);
|
|
151
|
+
}
|
|
152
|
+
for (const i of this._children ?? [])
|
|
153
|
+
try {
|
|
154
|
+
i._changeAncestorPause(e);
|
|
155
|
+
} catch (h) {
|
|
156
|
+
t.push(h);
|
|
157
|
+
}
|
|
158
|
+
n(t, "[Raph] Pausable effect scope ancestor transition failed.");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function n(r, e) {
|
|
162
|
+
if (r.length === 1)
|
|
163
|
+
throw r[0];
|
|
164
|
+
if (r.length > 1)
|
|
165
|
+
throw new AggregateError(r, e);
|
|
166
|
+
}
|
|
167
|
+
function p() {
|
|
168
|
+
}
|
|
169
|
+
export {
|
|
170
|
+
_ as RaphEffectScope
|
|
171
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var y=(o,h,e)=>h in o?b(o,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[h]=e;var l=(o,h,e)=>y(o,typeof h!="symbol"?h+"":h,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../errors.cjs"),w=require("./RaphScope.cjs"),v=require("./throwDisposalErrors.cjs");let g=0;const _=Symbol("RaphProvisionalNode");class c extends w.RaphScope{constructor(e,t={},r,i){const s=r??(e instanceof c?e.runtime:e??void 0);if(s===void 0)throw new Error("[RaphNode] A root node requires an explicit runtime.");const n=e instanceof c?e:(e==null?void 0:e.root)??null;if(n!==null&&n.runtime!==s)throw new a.RaphCrossRuntimeError("[Raph] Parent belongs to another runtime.");n==null||n._assertAlive();const d=t.priority??0;p(d);super(t.id??`node-${g++}`,s);l(this,"priority");l(this,"_parent");l(this,"_children",[]);l(this,"_published");l(this,"api");l(this,"meta");l(this,"type");l(this,"_subtreeSourceIdentity",Object.freeze({}));this.priority=d,this._parent=n,this.meta={...t.meta},this.type=t.type??"default",this.api=Object.freeze({});const f=i===_;if(this._published=n===null||!f&&n._published,n!==null){const m=n._children.length;if(n._children.push(this),!this._published)return;s._notifyNodeStructure(this,{node:this,newIndex:m,newParent:n},[],u(this)),this._assertAlive()}}get node(){return this}get parent(){return this._parent}get children(){return this._children}addChild(e){if(this._assertAlive(),e._assertAlive(),e.runtime!==this.runtime)throw new a.RaphCrossRuntimeError("[Raph] Child belongs to another runtime.");if(this===e)throw new Error("[Raph] A node cannot become its own ancestor.");if(!e._published||!this._published)throw new Error("[Raph] A provisional node cannot be reparented before setup commits.");for(let t=this;t!==null;t=t.parent)if(t===e)throw new Error("[Raph] A node cannot become its own ancestor.");return e.parent===this?!0:this.runtime._runNodeMutation(()=>{this.runtime._assertNodeReparentAllowed(e,this);const t=u(e),r=e._parent,i=r==null?void 0:r._children.indexOf(e);r!==null&&i!==void 0&&i>=0&&r._children.splice(i,1),e._parent=this;const s=this._children.length;return this._children.push(e),this.runtime._notifyNodeStructure(e,{node:e,...r===null?{}:{oldParent:r},...i===void 0||i<0?{}:{oldIndex:i},newParent:this,newIndex:s},t,u(e)),!0})}reorderChildren(e){if(this._assertAlive(),e.length!==this._children.length||new Set(e).size!==e.length)throw new Error("[Raph] Child order must contain every direct child exactly once.");for(const t of e)if(t._assertAlive(),t._parent!==this)throw new Error("[Raph] Child order can contain only direct children of the node.");this.runtime._runNodeMutation(()=>{const t=new Map(this._children.map((r,i)=>[r,i]));this._children.splice(0,this._children.length,...e);for(let r=0;r<e.length;r++){const i=e[r],s=t.get(i);if(s===r)continue;const n=u(i);this.runtime._notifyNodeStructure(i,{node:i,oldParent:this,newParent:this,oldIndex:s,newIndex:r},n,n)}})}options(e){this._assertAlive(),e.meta!==void 0&&(this.meta={...e.meta}),e.priority!==void 0&&(p(e.priority),this.priority=e.priority),e.type!==void 0&&(this.type=e.type),this.touch(Object.freeze({options:Object.freeze({...e})}))}touch(e){this._assertAlive(),this.runtime._runNodeMutation(()=>this.runtime._notifyNodeTouch(this,e))}remove(){this.dispose()}dispose(){if(this._disposed||this._disposing)return;this._disposing=!0,this.runtime._beginOwnerDisposal();const e=[];try{for(const s of[...this._children])try{s.dispose()}catch(n){e.push(n)}this._children.length=0;const t=this._parent,r=u(this),i=t==null?void 0:t._children.indexOf(this);if(t!==null&&i!==void 0&&i>=0&&t._children.splice(i,1),this._parent=null,this._published)try{this.runtime._notifyNodeStructure(this,{node:this,...t===null?{}:{oldParent:t},...i===void 0||i<0?{}:{oldIndex:i}},r,[])}catch(s){e.push(s)}try{super.dispose()}catch(s){e.push(s)}this._published=!1;try{this.runtime._releaseNode(this)}catch(s){e.push(s)}}finally{try{this.runtime._endOwnerDisposal()}catch(t){e.push(t)}}v.throwDisposalErrors(e,`[Raph] Node "${this.id}" disposal failed.`)}_setApi(e){const t=typeof e=="object"&&e!==null?Object.freeze(e):e;Object.defineProperty(this,"api",{configurable:!1,enumerable:!0,value:t,writable:!1})}_publishCreation(){if(this._published)return;const e=this._parent;if(e===null||!e._published)return;this._published=!0;const t=e._children.indexOf(this);try{this.runtime._notifyNodeStructure(this,{node:this,newIndex:t,newParent:e},[],u(this));for(const r of this._children)r._publishCreation()}catch(r){throw this._published=!1,r}}_isPublished(){return this._published}}function N(o,h,e){return new c(o,h,e,_)}function u(o){const h=[];for(let e=o;e!==null;e=e.parent)h.push(e);return h}function p(o){if(!Number.isFinite(o))throw new TypeError("[Raph] Node priority must be finite.")}exports.RaphNode=c;exports.createProvisionalNode=N;
|