@raphy-js/raph 1.0.0-dev.18
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/LICENSE +202 -0
- package/dist/api/Raph.d.ts +97 -0
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +25 -0
- package/dist/api/types.d.ts +170 -0
- package/dist/core-CyilRD7s.js +1055 -0
- package/dist/core-ugchZNqC.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -0
- package/dist/debug/api/Raph.js +421 -0
- 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 -0
- package/dist/debug/api/errors.js +17 -0
- package/dist/debug/api/types.cjs +1 -0
- package/dist/debug/api/types.js +1 -0
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/DataPath.js +394 -0
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/PathRouter.js +86 -0
- package/dist/debug/path/RaphKernel.cjs +1 -0
- package/dist/debug/path/RaphKernel.js +687 -0
- package/dist/debug/path/data-path.types.cjs +1 -0
- package/dist/debug/path/data-path.types.js +1 -0
- 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/derived/DerivedRegistry.js +157 -0
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
- package/dist/debug/path/derived/RaphDerivedHandle.js +125 -0
- package/dist/debug/path/derived/derived-collection.types.cjs +1 -0
- package/dist/debug/path/derived/derived-collection.types.js +1 -0
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/derived/derived-collection.utils.js +179 -0
- 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/derived/derived-strategy.utils.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.utils.js +20 -0
- package/dist/debug/path/meta/MetaController.cjs +1 -0
- package/dist/debug/path/meta/MetaController.js +214 -0
- package/dist/debug/path/meta/RaphMeta.cjs +1 -0
- package/dist/debug/path/meta/RaphMeta.js +68 -0
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/meta/RaphMetaStore.js +184 -0
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/path.types.cjs +1 -0
- package/dist/debug/path/path.types.js +1 -0
- package/dist/debug/path/pathSegmentKey.cjs +1 -0
- package/dist/debug/path/pathSegmentKey.js +12 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/storage/AdapterPathStore.js +133 -0
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/storage/DefaultDataAdapter.js +356 -0
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/storage/PathEventHub.js +148 -0
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/storage/PathStore.js +326 -0
- package/dist/debug/path/storage/createDataDraft.cjs +1 -0
- package/dist/debug/path/storage/createDataDraft.js +71 -0
- 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 -0
- package/dist/debug/reactivity/engine.js +1305 -0
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +280 -0
- package/dist/debug/reactivity/scope.cjs +1 -0
- package/dist/debug/reactivity/scope.js +274 -0
- package/dist/debug/reactivity/types.cjs +1 -0
- package/dist/debug/reactivity/types.js +1 -0
- package/dist/debug/reactivity/watch.cjs +1 -0
- package/dist/debug/reactivity/watch.js +64 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphRuntime.js +979 -0
- 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 -0
- package/dist/debug/runtime/errors.js +15 -0
- 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/ownership/parentGraph.cjs +1 -0
- package/dist/debug/runtime/ownership/parentGraph.js +10 -0
- package/dist/debug/runtime/ownership/throwDisposalErrors.cjs +1 -0
- package/dist/debug/runtime/ownership/throwDisposalErrors.js +9 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.js +106 -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/phases/phase.types.cjs +1 -0
- package/dist/debug/runtime/phases/phase.types.js +8 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/reactivity/PathHandle.js +175 -0
- 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 -0
- package/dist/index.js +48 -0
- 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/DataPath.d.ts +73 -0
- package/dist/path/PathRouter.d.ts +21 -0
- package/dist/path/RaphKernel.d.ts +169 -0
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/derived/DerivedRegistry.d.ts +67 -0
- package/dist/path/derived/RaphDerivedHandle.d.ts +97 -0
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/derived/derived-collection.utils.d.ts +20 -0
- package/dist/path/derived/derived-strategy.types.d.ts +12 -0
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/meta/MetaController.d.ts +85 -0
- package/dist/path/meta/RaphMeta.d.ts +45 -0
- package/dist/path/meta/RaphMetaStore.d.ts +45 -0
- package/dist/path/meta/meta.types.d.ts +31 -0
- package/dist/path/path.types.d.ts +27 -0
- package/dist/path/pathSegmentKey.d.ts +2 -0
- package/dist/path/storage/AdapterPathStore.d.ts +45 -0
- package/dist/path/storage/DefaultDataAdapter.d.ts +63 -0
- package/dist/path/storage/PathEventHub.d.ts +48 -0
- package/dist/path/storage/PathStore.d.ts +51 -0
- package/dist/path/storage/createDataDraft.d.ts +4 -0
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -0
- package/dist/path.js +18 -0
- package/dist/raph.cjs +1 -0
- package/dist/raph.js +48 -0
- package/dist/reactivity/engine.d.ts +393 -0
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/scope.d.ts +146 -0
- package/dist/reactivity/types.d.ts +175 -0
- package/dist/reactivity/watch.d.ts +15 -0
- package/dist/reactivity.cjs +1 -0
- package/dist/reactivity.js +14 -0
- package/dist/runtime/RaphRuntime.d.ts +225 -0
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +21 -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/ownership/parent-graph.types.d.ts +4 -0
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/ownership/throwDisposalErrors.d.ts +1 -0
- package/dist/runtime/phases/RaphFrameLoop.d.ts +51 -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/reactivity/PathHandle.d.ts +80 -0
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +45 -0
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +34 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +11 -0
- package/dist/runtime.cjs +1 -0
- package/dist/runtime.js +23 -0
- package/package.json +141 -0
|
@@ -0,0 +1,979 @@
|
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var T = (p, e, t) => e in p ? E(p, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[e] = t;
|
|
3
|
+
var u = (p, e, t) => T(p, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { parseDataPath as P } from "../path/data-path.utils.js";
|
|
5
|
+
import { DataPath as x } from "../path/DataPath.js";
|
|
6
|
+
import { RaphMeta as W } from "../path/meta/RaphMeta.js";
|
|
7
|
+
import { RaphKernel as G } from "../path/RaphKernel.js";
|
|
8
|
+
import { configureReactiveObjectPolicy as O, disposeReactiveObjectContext as L } from "../reactivity/reactive-object.js";
|
|
9
|
+
import { RaphDebugController as M, createOwnerSnapshot as b, createOwnerTree as R } from "./diagnostics/RaphDebug.js";
|
|
10
|
+
import { RaphDisposedError as A, RaphCrossRuntimeError as k, RaphActionError as B } from "./errors.js";
|
|
11
|
+
import { parentGraph as F } from "./ownership/parentGraph.js";
|
|
12
|
+
import { RaphNode as g, createProvisionalNode as q } from "./ownership/RaphNode.js";
|
|
13
|
+
import { RaphScope as D } from "./ownership/RaphScope.js";
|
|
14
|
+
import { throwDisposalErrors as y } from "./ownership/throwDisposalErrors.js";
|
|
15
|
+
import { RaphSchedulerType as w } from "./phases/phase.types.js";
|
|
16
|
+
import { RaphFrameLoop as I } from "./phases/RaphFrameLoop.js";
|
|
17
|
+
import { RaphPhasePipeline as H } from "./phases/RaphPhasePipeline.js";
|
|
18
|
+
import { PathHandle as z } from "./reactivity/PathHandle.js";
|
|
19
|
+
import { RaphMetaSource as N } from "./reactivity/RaphMetaSource.js";
|
|
20
|
+
import { RaphWorkGraph as $ } from "./reactivity/RaphWorkGraph.js";
|
|
21
|
+
import { RuntimeReactivity as j } from "./reactivity/RuntimeReactivity.js";
|
|
22
|
+
import { RuntimeWatch as U } from "./reactivity/RuntimeWatch.js";
|
|
23
|
+
const v = class v {
|
|
24
|
+
constructor(e = {}) {
|
|
25
|
+
u(this, "mode", "runtime");
|
|
26
|
+
u(this, "configuration");
|
|
27
|
+
u(this, "rootScope");
|
|
28
|
+
u(this, "root");
|
|
29
|
+
u(this, "frameTick");
|
|
30
|
+
u(this, "_reactivity");
|
|
31
|
+
u(this, "_signalLifecycle");
|
|
32
|
+
u(this, "_workGraph");
|
|
33
|
+
u(this, "_frameTickWritable");
|
|
34
|
+
u(this, "_setFrameTick");
|
|
35
|
+
u(this, "_pathHandles");
|
|
36
|
+
u(this, "_meta");
|
|
37
|
+
u(this, "_phases");
|
|
38
|
+
u(this, "_frameLoop");
|
|
39
|
+
u(this, "_debug");
|
|
40
|
+
u(this, "_debugController");
|
|
41
|
+
u(this, "_parentGraph");
|
|
42
|
+
u(this, "_owners", /* @__PURE__ */ new Set());
|
|
43
|
+
u(this, "_batchDepth", 0);
|
|
44
|
+
u(this, "_mutationDepth", 0);
|
|
45
|
+
u(this, "_kernelBatchDepth", 0);
|
|
46
|
+
u(this, "_ownerDisposalDepth", 0);
|
|
47
|
+
u(this, "_actionDepth", 0);
|
|
48
|
+
u(this, "_actionCounter", 0);
|
|
49
|
+
u(this, "_traceCauseStack", []);
|
|
50
|
+
u(this, "_phaseTraceOperations");
|
|
51
|
+
u(this, "_executionRequested", !1);
|
|
52
|
+
u(this, "_disposed", !1);
|
|
53
|
+
u(this, "_disposedListeners", /* @__PURE__ */ new Set());
|
|
54
|
+
const t = e.id ?? `runtime-${v._runtimeCounter++}`, r = e.adaptiveDependencyIndex ?? !1, s = e.enforceActions ?? !1, i = e.scheduler ?? w.Sync;
|
|
55
|
+
if (!K(i))
|
|
56
|
+
throw new Error(`[Raph] Unsupported scheduler "${String(i)}".`);
|
|
57
|
+
const o = e.kernel ?? new G({ id: `${t}-kernel` });
|
|
58
|
+
this.configuration = Object.freeze({
|
|
59
|
+
adaptiveDependencyIndex: r,
|
|
60
|
+
...e.debug === void 0 ? {} : { debug: e.debug },
|
|
61
|
+
id: t,
|
|
62
|
+
kernel: o,
|
|
63
|
+
enforceActions: s,
|
|
64
|
+
scheduler: i
|
|
65
|
+
}), this._debugController = new M(e.debug);
|
|
66
|
+
const c = `[Raph] Runtime "${t}" is disposed.`;
|
|
67
|
+
this._signalLifecycle = {
|
|
68
|
+
owner: this,
|
|
69
|
+
runWrite: (d) => this._runWrite(d),
|
|
70
|
+
assertDependencyAllowed: (d, l) => {
|
|
71
|
+
this._assertImplicitDependency(d, l);
|
|
72
|
+
},
|
|
73
|
+
...s ? { assertWriteAllowed: () => this._assertWriteAllowed() } : {},
|
|
74
|
+
throwDisposed: () => {
|
|
75
|
+
throw new A(c);
|
|
76
|
+
},
|
|
77
|
+
throwCrossRuntime: (d) => this._throwCrossRuntime(d)
|
|
78
|
+
}, this._reactivity = new j(this._signalLifecycle, { adaptiveDependencyIndex: r }), this._workGraph = new $(this), o._attachRuntime(this), this.rootScope = new D(`${t}:root-scope`, this), this.root = new g(null, { id: `${t}:root` }, this), O(this._reactivity, {
|
|
79
|
+
owner: this,
|
|
80
|
+
assertRead: () => {
|
|
81
|
+
this._assertAlive();
|
|
82
|
+
const d = this._reactivity.getActiveOwner();
|
|
83
|
+
d !== void 0 && d !== this && this._throwCrossRuntime(d);
|
|
84
|
+
const l = this._reactivity.getActiveConsumerOwner();
|
|
85
|
+
l !== void 0 && this._assertImplicitDependency(this.rootScope, l);
|
|
86
|
+
},
|
|
87
|
+
assertWrite: () => this._assertWriteAllowed(),
|
|
88
|
+
runWrite: (d) => this._runWrite(d),
|
|
89
|
+
throwForeign: (d) => {
|
|
90
|
+
throw d instanceof v && this._throwCrossRuntime(d), new k(
|
|
91
|
+
"[Raph] Reactive object belongs to another reactivity engine."
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const n = this._workGraph.createProducer(this.rootScope, "frame", {
|
|
96
|
+
includeRuntime: !1
|
|
97
|
+
});
|
|
98
|
+
let a;
|
|
99
|
+
const h = this._reactivity.signalForOwner(
|
|
100
|
+
0,
|
|
101
|
+
this.rootScope,
|
|
102
|
+
this._workGraph.producerHooks(n),
|
|
103
|
+
(d) => {
|
|
104
|
+
a = d;
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
this._setFrameTick = (d) => this._runWrite(() => a(d)), this._frameTickWritable = h, this.frameTick = this._workGraph.attachProducer(n, {
|
|
108
|
+
get: h.get,
|
|
109
|
+
peek: h.peek
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/** @internal */
|
|
113
|
+
_getReactivity() {
|
|
114
|
+
return this._reactivity;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Возвращает внутренний WorkGraph для optional execution layers.
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
_getWorkGraph() {
|
|
122
|
+
return this._workGraph;
|
|
123
|
+
}
|
|
124
|
+
get id() {
|
|
125
|
+
return this.configuration.id;
|
|
126
|
+
}
|
|
127
|
+
get kernel() {
|
|
128
|
+
return this.configuration.kernel;
|
|
129
|
+
}
|
|
130
|
+
get disposed() {
|
|
131
|
+
return this._disposed;
|
|
132
|
+
}
|
|
133
|
+
get graph() {
|
|
134
|
+
return this._parentGraph ?? (this._parentGraph = F());
|
|
135
|
+
}
|
|
136
|
+
get loopEnabled() {
|
|
137
|
+
var e;
|
|
138
|
+
return ((e = this._frameLoop) == null ? void 0 : e.running) ?? !1;
|
|
139
|
+
}
|
|
140
|
+
get frame() {
|
|
141
|
+
var e;
|
|
142
|
+
return ((e = this._phases) == null ? void 0 : e.frame) ?? { now: 0, delta: 0, elapsed: 0, frame: 0 };
|
|
143
|
+
}
|
|
144
|
+
get phases() {
|
|
145
|
+
var e;
|
|
146
|
+
return ((e = this._phases) == null ? void 0 : e.phases) ?? [];
|
|
147
|
+
}
|
|
148
|
+
/** Runtime metadata facade intentionally excludes unphased watch(). */
|
|
149
|
+
get meta() {
|
|
150
|
+
if (this._assertAlive(), this._meta !== void 0)
|
|
151
|
+
return this._meta;
|
|
152
|
+
const e = new W(this.kernel, {
|
|
153
|
+
assertReadable: () => this._assertAlive(),
|
|
154
|
+
assertWritable: () => this._assertWriteAllowed(),
|
|
155
|
+
runWrite: (t, r) => this._runWrite(t, r)
|
|
156
|
+
});
|
|
157
|
+
return this._meta = Object.freeze({
|
|
158
|
+
delete: e.delete.bind(e),
|
|
159
|
+
get: e.get.bind(e),
|
|
160
|
+
has: e.has.bind(e),
|
|
161
|
+
merge: e.merge.bind(e),
|
|
162
|
+
set: e.set.bind(e)
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
getDerivedSnapshot() {
|
|
166
|
+
return this.kernel.getDerivedSnapshot();
|
|
167
|
+
}
|
|
168
|
+
get debug() {
|
|
169
|
+
return this._debug ?? (this._debug = Object.freeze({
|
|
170
|
+
snapshot: () => this._createDebugSnapshot(),
|
|
171
|
+
getTree: () => this._createDebugTree(),
|
|
172
|
+
stats: () => this._createDebugStats(),
|
|
173
|
+
trace: this._debugController.trace,
|
|
174
|
+
machines: this._debugController.machines
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
signal(e, t = this.rootScope) {
|
|
178
|
+
this._assertOwnerRuntime(t);
|
|
179
|
+
const r = this._workGraph.createProducer(t), s = this._reactivity.signalForOwner(
|
|
180
|
+
e,
|
|
181
|
+
t,
|
|
182
|
+
this._workGraph.producerHooks(r)
|
|
183
|
+
);
|
|
184
|
+
return this._workGraph.attachProducer(r, s);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Creates a deep reactive Proxy owned by this Runtime root scope.
|
|
188
|
+
* Property dependencies use the intrusive graph directly and intentionally
|
|
189
|
+
* do not create per-property WorkGraph producers or phase causes.
|
|
190
|
+
*/
|
|
191
|
+
reactive(e) {
|
|
192
|
+
return this._assertAlive(), this._reactivity.reactive(e);
|
|
193
|
+
}
|
|
194
|
+
computed(e, t = this.rootScope) {
|
|
195
|
+
this._assertOwnerRuntime(t);
|
|
196
|
+
const r = this._workGraph.createProducer(t), s = typeof e == "function" ? e : e.get, i = this._reactivity.computedForOwner(
|
|
197
|
+
() => this._runTracked(t, s),
|
|
198
|
+
t,
|
|
199
|
+
this._workGraph.producerHooks(r)
|
|
200
|
+
);
|
|
201
|
+
if (this._workGraph.setProducerActivation(r, () => {
|
|
202
|
+
i.peek();
|
|
203
|
+
}), typeof e == "function")
|
|
204
|
+
return this._workGraph.attachProducer(r, i);
|
|
205
|
+
const o = this._attachWritableComputed(i, e.set, t);
|
|
206
|
+
return this._workGraph.attachProducer(r, o);
|
|
207
|
+
}
|
|
208
|
+
/** Low-level adapter form. Prefer consumer.effect(). */
|
|
209
|
+
effect(e, t, r, s = {}) {
|
|
210
|
+
return this._effectRegistration(e, t, r, s).dispose;
|
|
211
|
+
}
|
|
212
|
+
/** @internal */
|
|
213
|
+
_effectRegistration(e, t, r, s = {}, i = !1) {
|
|
214
|
+
this._assertOwnerRuntime(e);
|
|
215
|
+
const o = this._validatePhaseBinding(t, r, s), c = this._execution, n = s.initial ?? "scheduled";
|
|
216
|
+
let a, h, d = !1;
|
|
217
|
+
const l = this._reactivity.withEffectBinding(
|
|
218
|
+
(f) => {
|
|
219
|
+
const _ = c.bindTask(
|
|
220
|
+
o,
|
|
221
|
+
e,
|
|
222
|
+
r,
|
|
223
|
+
s.priority ?? 0,
|
|
224
|
+
f
|
|
225
|
+
);
|
|
226
|
+
return i && _.pause(), a = _;
|
|
227
|
+
},
|
|
228
|
+
() => this._reactivity.effect(
|
|
229
|
+
() => this._runTracked(e, () => {
|
|
230
|
+
const f = r(a.task);
|
|
231
|
+
return typeof f == "function" ? () => this._runUntracked(f) : f;
|
|
232
|
+
}),
|
|
233
|
+
() => {
|
|
234
|
+
h === void 0 ? d = !0 : h();
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
);
|
|
238
|
+
h = this._own(l, e), d && h(), a.abort = () => h == null ? void 0 : h();
|
|
239
|
+
try {
|
|
240
|
+
n === "sync" ? this.flush() : this._requestExecution();
|
|
241
|
+
} catch (f) {
|
|
242
|
+
try {
|
|
243
|
+
h();
|
|
244
|
+
} catch (_) {
|
|
245
|
+
throw new AggregateError(
|
|
246
|
+
[f, _],
|
|
247
|
+
"[Raph] Phase effect registration and rollback failed."
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
throw f;
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
dispose: () => h == null ? void 0 : h(),
|
|
254
|
+
pause: () => a == null ? void 0 : a.pause(),
|
|
255
|
+
resume: () => a == null ? void 0 : a.resume()
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/** Low-level adapter form. Prefer consumer.watch(). */
|
|
259
|
+
watch(e, t, r, s, i = {}) {
|
|
260
|
+
return this._watchRegistration(e, t, r, s, i).dispose;
|
|
261
|
+
}
|
|
262
|
+
/** @internal */
|
|
263
|
+
_watchRegistration(e, t, r, s, i = {}, o = !1) {
|
|
264
|
+
this._assertOwnerRuntime(e);
|
|
265
|
+
const c = this._validatePhaseBinding(r, s, i, !0);
|
|
266
|
+
this._workGraph.assertSubscriptionAllowed(e, t);
|
|
267
|
+
let n;
|
|
268
|
+
const a = new U(
|
|
269
|
+
(_) => this._runUntracked(_),
|
|
270
|
+
() => s(n.task)
|
|
271
|
+
);
|
|
272
|
+
n = this._execution.bindTask(
|
|
273
|
+
c,
|
|
274
|
+
e,
|
|
275
|
+
s,
|
|
276
|
+
i.priority ?? 0,
|
|
277
|
+
a.deliver
|
|
278
|
+
), o && n.pause();
|
|
279
|
+
let h;
|
|
280
|
+
try {
|
|
281
|
+
h = this._workGraph.subscribe(
|
|
282
|
+
t,
|
|
283
|
+
i.include,
|
|
284
|
+
n.enqueue
|
|
285
|
+
);
|
|
286
|
+
} catch (_) {
|
|
287
|
+
throw n.dispose(), _;
|
|
288
|
+
}
|
|
289
|
+
const d = () => a.stop(() => {
|
|
290
|
+
const _ = [];
|
|
291
|
+
try {
|
|
292
|
+
h();
|
|
293
|
+
} catch (m) {
|
|
294
|
+
_.push(m);
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
n.dispose();
|
|
298
|
+
} catch (m) {
|
|
299
|
+
_.push(m);
|
|
300
|
+
}
|
|
301
|
+
y(_, "[Raph] Phase watch disposal failed.");
|
|
302
|
+
}), l = this._own(d, e), f = i.initial ?? "scheduled";
|
|
303
|
+
try {
|
|
304
|
+
f !== "none" && n.schedule(), f === "sync" && this.flush();
|
|
305
|
+
} catch (_) {
|
|
306
|
+
try {
|
|
307
|
+
l();
|
|
308
|
+
} catch (m) {
|
|
309
|
+
throw new AggregateError(
|
|
310
|
+
[_, m],
|
|
311
|
+
"[Raph] Phase watch registration and rollback failed."
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
throw _;
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
dispose: l,
|
|
318
|
+
pause: n.pause,
|
|
319
|
+
resume: n.resume
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
aggregate(e, t) {
|
|
323
|
+
return this._assertOwnerRuntime(e), this._workGraph.createAggregate(e, t);
|
|
324
|
+
}
|
|
325
|
+
/** Creates a lazy root-owned metadata event source for phase watches. */
|
|
326
|
+
metaSource(e, t = {}) {
|
|
327
|
+
this._assertAlive(), J(e, t);
|
|
328
|
+
const r = this._workGraph.createProducer(this.rootScope, "path"), s = this._workGraph.producerHooks(r).onDispose, i = N._create(
|
|
329
|
+
this.rootScope,
|
|
330
|
+
e,
|
|
331
|
+
t,
|
|
332
|
+
() => this.kernel._watchMeta(
|
|
333
|
+
i.masks,
|
|
334
|
+
({ events: o }) => this._workGraph.notifyProducerEvents(r, o, !1),
|
|
335
|
+
i.options,
|
|
336
|
+
(o) => {
|
|
337
|
+
o && this._execution.request();
|
|
338
|
+
}
|
|
339
|
+
),
|
|
340
|
+
() => s(!1)
|
|
341
|
+
);
|
|
342
|
+
i._bindOwner(this.rootScope._adoptResource(() => i._disposeOwned()));
|
|
343
|
+
try {
|
|
344
|
+
return this._workGraph.setProducerActivation(r, () => i._activate(), !0), this._workGraph.attachProducer(r, i), i;
|
|
345
|
+
} catch (o) {
|
|
346
|
+
try {
|
|
347
|
+
i.dispose();
|
|
348
|
+
} catch (c) {
|
|
349
|
+
throw new AggregateError(
|
|
350
|
+
[o, c],
|
|
351
|
+
"[Raph] Meta source activation and rollback failed."
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
throw o;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
path(e, t = {}) {
|
|
358
|
+
this._assertAlive();
|
|
359
|
+
const r = P(e, t), s = this._pathHandles ?? (this._pathHandles = /* @__PURE__ */ new Map()), i = s.get(r.canonical);
|
|
360
|
+
if (i !== void 0)
|
|
361
|
+
return i;
|
|
362
|
+
const o = this._workGraph.createProducer(this.rootScope, "path"), c = this._workGraph.producerHooks(o), n = new z(
|
|
363
|
+
this.kernel,
|
|
364
|
+
r,
|
|
365
|
+
t,
|
|
366
|
+
(a) => this._releasePathHandle(a),
|
|
367
|
+
this._reactivity,
|
|
368
|
+
() => this._assertAlive(),
|
|
369
|
+
() => this._assertTrackedRead(),
|
|
370
|
+
this.configuration.enforceActions ? () => this._assertWriteAllowed() : void 0,
|
|
371
|
+
(a) => this._runWrite(a),
|
|
372
|
+
{ token: o, onDispose: c.onDispose },
|
|
373
|
+
({ events: a }, h) => this._workGraph.notifyProducerEvents(o, a, !0, h)
|
|
374
|
+
);
|
|
375
|
+
try {
|
|
376
|
+
return this._workGraph.setProducerActivation(o, () => n._activate(), !0), this._workGraph.attachProducer(o, n), s.set(r.canonical, n), n;
|
|
377
|
+
} catch (a) {
|
|
378
|
+
let h, d = !1;
|
|
379
|
+
try {
|
|
380
|
+
n.dispose();
|
|
381
|
+
} catch (l) {
|
|
382
|
+
d = !0, h = l;
|
|
383
|
+
}
|
|
384
|
+
throw s.size === 0 && this._pathHandles === s && (this._pathHandles = void 0), d ? new AggregateError(
|
|
385
|
+
[a, h],
|
|
386
|
+
"[Raph] Path source activation and rollback failed."
|
|
387
|
+
) : a;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
get(e, t) {
|
|
391
|
+
this._assertTrackedRead();
|
|
392
|
+
const r = e ?? "";
|
|
393
|
+
return this._reactivity._isTracking() ? this.path(r, t)._getTracked() : this.kernel.get(r, t);
|
|
394
|
+
}
|
|
395
|
+
peek(e, t) {
|
|
396
|
+
return this._assertAlive(), this.kernel.peek(e ?? "", t);
|
|
397
|
+
}
|
|
398
|
+
has(e, t) {
|
|
399
|
+
return this._assertAlive(), this.kernel.has(e, t);
|
|
400
|
+
}
|
|
401
|
+
set(e, t, r) {
|
|
402
|
+
this._assertWriteAllowed(), this._runWrite(() => this.kernel.set(e, t, r));
|
|
403
|
+
}
|
|
404
|
+
merge(e, t, r) {
|
|
405
|
+
this._assertWriteAllowed(), this._runWrite(() => this.kernel.merge(e, t, r));
|
|
406
|
+
}
|
|
407
|
+
delete(e, t) {
|
|
408
|
+
this._assertWriteAllowed(), this._runWrite(() => this.kernel.delete(e, t));
|
|
409
|
+
}
|
|
410
|
+
batch(e) {
|
|
411
|
+
return this._batch(e, !0);
|
|
412
|
+
}
|
|
413
|
+
/** Batches an internal reactive-only commit without opening an unused Kernel boundary. @internal */
|
|
414
|
+
_batchReactive(e) {
|
|
415
|
+
return this._batch(e, !1);
|
|
416
|
+
}
|
|
417
|
+
_batch(e, t) {
|
|
418
|
+
this._assertAlive(), this._batchDepth++;
|
|
419
|
+
let r, s, i = !1;
|
|
420
|
+
try {
|
|
421
|
+
r = this._reactivity.batch(() => t ? this.kernel.batch(e) : e());
|
|
422
|
+
} catch (c) {
|
|
423
|
+
i = !0, s = c;
|
|
424
|
+
}
|
|
425
|
+
this._batchDepth--;
|
|
426
|
+
const o = this._finishExecutionBoundary();
|
|
427
|
+
if (i)
|
|
428
|
+
throw o.length !== 0 ? new AggregateError(
|
|
429
|
+
[s, ...o],
|
|
430
|
+
"[Raph] Batch and scheduled phase execution failed."
|
|
431
|
+
) : s;
|
|
432
|
+
return y(o, "[Raph] Batch phase execution failed."), r;
|
|
433
|
+
}
|
|
434
|
+
action(e, t, r) {
|
|
435
|
+
const s = typeof e == "function" ? e : t, i = typeof e == "function" ? t instanceof D ? t : this.rootScope : r ?? this.rootScope, o = typeof e == "string" ? e : `action#${++this._actionCounter}`;
|
|
436
|
+
if (this._assertOwnerRuntime(i), typeof s != "function")
|
|
437
|
+
throw new TypeError("[Raph] Action operation must be a function.");
|
|
438
|
+
if (!o.trim())
|
|
439
|
+
throw new Error("[Raph] Action name must not be empty.");
|
|
440
|
+
return (...c) => {
|
|
441
|
+
i._assertAlive();
|
|
442
|
+
const n = this._debugController.nextOperationId("action"), h = this._traceCauseStack.at(-1) ?? n;
|
|
443
|
+
this._debugController.record({
|
|
444
|
+
...h === void 0 ? {} : { causeId: h },
|
|
445
|
+
kind: "action",
|
|
446
|
+
name: o,
|
|
447
|
+
...n === void 0 ? {} : { operationId: n },
|
|
448
|
+
status: "start"
|
|
449
|
+
}), h !== void 0 && this._traceCauseStack.push(h), this._actionDepth++;
|
|
450
|
+
try {
|
|
451
|
+
const d = this.batch(() => this._runUntracked(() => s(...c)));
|
|
452
|
+
return this._debugController.record({
|
|
453
|
+
...h === void 0 ? {} : { causeId: h },
|
|
454
|
+
kind: "action",
|
|
455
|
+
name: o,
|
|
456
|
+
...n === void 0 ? {} : { operationId: n },
|
|
457
|
+
status: "end"
|
|
458
|
+
}), d;
|
|
459
|
+
} catch (d) {
|
|
460
|
+
throw this._debugController.record({
|
|
461
|
+
...h === void 0 ? {} : { causeId: h },
|
|
462
|
+
details: { message: C(d) },
|
|
463
|
+
kind: "action",
|
|
464
|
+
name: o,
|
|
465
|
+
...n === void 0 ? {} : { operationId: n },
|
|
466
|
+
status: "error"
|
|
467
|
+
}), this._debugController.record({
|
|
468
|
+
...h === void 0 ? {} : { causeId: h },
|
|
469
|
+
details: { message: C(d) },
|
|
470
|
+
kind: "error",
|
|
471
|
+
name: `action:${o}`,
|
|
472
|
+
...n === void 0 ? {} : { operationId: n },
|
|
473
|
+
status: "error"
|
|
474
|
+
}), d;
|
|
475
|
+
} finally {
|
|
476
|
+
this._actionDepth--, h !== void 0 && this._traceCauseStack.pop();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
untracked(e) {
|
|
481
|
+
return this._assertAlive(), this._runUntracked(e);
|
|
482
|
+
}
|
|
483
|
+
scope(e) {
|
|
484
|
+
return this._assertAlive(), new D(e, this);
|
|
485
|
+
}
|
|
486
|
+
node(e, t) {
|
|
487
|
+
this._assertAlive();
|
|
488
|
+
const r = this._runNodeMutation(() => {
|
|
489
|
+
const s = e.parent ?? this.root, i = q(s, e, this);
|
|
490
|
+
try {
|
|
491
|
+
const o = t == null ? void 0 : t(i);
|
|
492
|
+
return i._assertAlive(), s._assertAlive(), i._setApi(o), i._publishCreation(), i;
|
|
493
|
+
} catch (o) {
|
|
494
|
+
try {
|
|
495
|
+
i.dispose();
|
|
496
|
+
} catch (c) {
|
|
497
|
+
throw new AggregateError([o, c], `[Raph] Node "${i.id}" setup and cleanup failed.`);
|
|
498
|
+
}
|
|
499
|
+
throw o;
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
return r._assertAlive(), r;
|
|
503
|
+
}
|
|
504
|
+
getNode(e) {
|
|
505
|
+
this._assertAlive();
|
|
506
|
+
const t = [this.root];
|
|
507
|
+
for (; t.length !== 0; ) {
|
|
508
|
+
const r = t.pop();
|
|
509
|
+
if (r.id === e)
|
|
510
|
+
return r;
|
|
511
|
+
t.push(...r.children);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
definePhases(e) {
|
|
515
|
+
this._execution.definePhases(e);
|
|
516
|
+
}
|
|
517
|
+
addPhase(e) {
|
|
518
|
+
this._execution.addPhase(e);
|
|
519
|
+
}
|
|
520
|
+
clearPhases() {
|
|
521
|
+
var e;
|
|
522
|
+
this._assertAlive(), (e = this._phases) == null || e.clearPhases();
|
|
523
|
+
}
|
|
524
|
+
requestExecution() {
|
|
525
|
+
var e;
|
|
526
|
+
this._assertAlive(), (e = this._phases) == null || e.request();
|
|
527
|
+
}
|
|
528
|
+
flush() {
|
|
529
|
+
var e;
|
|
530
|
+
this._assertAlive(), this._executionRequested = !1, (e = this._phases) == null || e.flush();
|
|
531
|
+
}
|
|
532
|
+
afterFlush() {
|
|
533
|
+
var e;
|
|
534
|
+
return this._assertAlive(), ((e = this._phases) == null ? void 0 : e.afterFlush()) ?? Promise.resolve();
|
|
535
|
+
}
|
|
536
|
+
acquireLoop(e) {
|
|
537
|
+
return this._assertAlive(), this._clock.acquire(e);
|
|
538
|
+
}
|
|
539
|
+
startLoop() {
|
|
540
|
+
this._assertAlive(), this._clock.start();
|
|
541
|
+
}
|
|
542
|
+
stopLoop() {
|
|
543
|
+
var e;
|
|
544
|
+
(e = this._frameLoop) == null || e.stop();
|
|
545
|
+
}
|
|
546
|
+
derive(e) {
|
|
547
|
+
this._assertAlive();
|
|
548
|
+
const t = e.compute, r = this.kernel.derive({
|
|
549
|
+
...e,
|
|
550
|
+
compute: (s) => this._runUntracked(() => t(s))
|
|
551
|
+
});
|
|
552
|
+
return this._own(() => r.dispose(), this.rootScope), r;
|
|
553
|
+
}
|
|
554
|
+
dispose() {
|
|
555
|
+
var c, n;
|
|
556
|
+
if (this._disposed)
|
|
557
|
+
return;
|
|
558
|
+
this._disposed = !0, this._executionRequested = !1, this._signalLifecycle.owner = void 0;
|
|
559
|
+
const e = [], t = [...this._owners];
|
|
560
|
+
try {
|
|
561
|
+
(c = this._frameLoop) == null || c.dispose();
|
|
562
|
+
} catch (a) {
|
|
563
|
+
e.push(a);
|
|
564
|
+
}
|
|
565
|
+
this._frameLoop = void 0;
|
|
566
|
+
try {
|
|
567
|
+
(n = this._phases) == null || n.dispose();
|
|
568
|
+
} catch (a) {
|
|
569
|
+
e.push(a);
|
|
570
|
+
}
|
|
571
|
+
this._phases = void 0;
|
|
572
|
+
try {
|
|
573
|
+
this.root.dispose();
|
|
574
|
+
} catch (a) {
|
|
575
|
+
e.push(a);
|
|
576
|
+
}
|
|
577
|
+
for (const a of t.reverse())
|
|
578
|
+
if (!(a === this.root || a === this.rootScope || a.disposed))
|
|
579
|
+
try {
|
|
580
|
+
a.dispose();
|
|
581
|
+
} catch (h) {
|
|
582
|
+
e.push(h);
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
this.rootScope.dispose();
|
|
586
|
+
} catch (a) {
|
|
587
|
+
e.push(a);
|
|
588
|
+
}
|
|
589
|
+
const r = `[Raph] Runtime "${this.id}" is disposed.`, s = () => {
|
|
590
|
+
throw new A(r);
|
|
591
|
+
};
|
|
592
|
+
try {
|
|
593
|
+
L(this._reactivity, {
|
|
594
|
+
assertRead: s,
|
|
595
|
+
assertWrite: s,
|
|
596
|
+
throwForeign: s
|
|
597
|
+
});
|
|
598
|
+
} catch (a) {
|
|
599
|
+
e.push(a);
|
|
600
|
+
}
|
|
601
|
+
this._owners.clear(), this._meta = void 0;
|
|
602
|
+
const i = this._pathHandles;
|
|
603
|
+
if (this._pathHandles = void 0, i !== void 0) {
|
|
604
|
+
for (const a of i.values())
|
|
605
|
+
try {
|
|
606
|
+
a.dispose();
|
|
607
|
+
} catch (h) {
|
|
608
|
+
e.push(h);
|
|
609
|
+
}
|
|
610
|
+
i.clear();
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
this._workGraph.dispose();
|
|
614
|
+
} catch (a) {
|
|
615
|
+
e.push(a);
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
this.kernel._detachRuntime(this);
|
|
619
|
+
} catch (a) {
|
|
620
|
+
e.push(a);
|
|
621
|
+
}
|
|
622
|
+
const o = [...this._disposedListeners];
|
|
623
|
+
this._disposedListeners.clear();
|
|
624
|
+
for (const a of o)
|
|
625
|
+
try {
|
|
626
|
+
a();
|
|
627
|
+
} catch (h) {
|
|
628
|
+
e.push(h);
|
|
629
|
+
}
|
|
630
|
+
y(e, `[Raph] Runtime "${this.id}" disposal failed.`);
|
|
631
|
+
}
|
|
632
|
+
/** @internal */
|
|
633
|
+
_onDisposed(e) {
|
|
634
|
+
return this._disposed ? (e(), () => {
|
|
635
|
+
}) : (this._disposedListeners.add(e), () => {
|
|
636
|
+
this._disposedListeners.delete(e);
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
/** @internal */
|
|
640
|
+
_notifyNodeStructure(e, t, r, s) {
|
|
641
|
+
this._runNodeMutation(() => {
|
|
642
|
+
this._workGraph.notifyNode(e, "structure", { structure: t, oldAncestors: r, newAncestors: s });
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
/** @internal */
|
|
646
|
+
_notifyNodeTouch(e, t) {
|
|
647
|
+
this._runNodeMutation(() => this._workGraph.notifyNode(e, "touch", { metadata: t }));
|
|
648
|
+
}
|
|
649
|
+
/** @internal */
|
|
650
|
+
_assertNodeReparentAllowed(e, t) {
|
|
651
|
+
this._workGraph.assertReparentAllowed(e, t);
|
|
652
|
+
}
|
|
653
|
+
/** @internal */
|
|
654
|
+
_releaseNode(e) {
|
|
655
|
+
this._workGraph.releaseNode(e);
|
|
656
|
+
}
|
|
657
|
+
/** @internal */
|
|
658
|
+
_runNodeMutation(e) {
|
|
659
|
+
return this._runWrite(e);
|
|
660
|
+
}
|
|
661
|
+
/** @internal */
|
|
662
|
+
_runPhaseTransition(e) {
|
|
663
|
+
return this._runWrite(e, !1);
|
|
664
|
+
}
|
|
665
|
+
/** @internal */
|
|
666
|
+
_beginOwnerDisposal() {
|
|
667
|
+
this._ownerDisposalDepth++;
|
|
668
|
+
}
|
|
669
|
+
/** @internal */
|
|
670
|
+
_endOwnerDisposal() {
|
|
671
|
+
this._ownerDisposalDepth !== 0 && (this._ownerDisposalDepth--, this._clearTransientCausesIfSettled(), this._disposed || this._requestExecution());
|
|
672
|
+
}
|
|
673
|
+
/** @internal */
|
|
674
|
+
_ownerDisposalActive() {
|
|
675
|
+
return this._ownerDisposalDepth !== 0;
|
|
676
|
+
}
|
|
677
|
+
/** @internal */
|
|
678
|
+
_registerOwner(e) {
|
|
679
|
+
this._assertAlive(), this._owners.add(e);
|
|
680
|
+
}
|
|
681
|
+
/** @internal */
|
|
682
|
+
_unregisterOwner(e) {
|
|
683
|
+
this._owners.delete(e);
|
|
684
|
+
}
|
|
685
|
+
/** @internal */
|
|
686
|
+
_assertOwnerRuntime(e) {
|
|
687
|
+
if (this._assertAlive(), e.runtime !== this)
|
|
688
|
+
throw new k("[Raph] Owner belongs to another runtime.");
|
|
689
|
+
e._assertAlive();
|
|
690
|
+
}
|
|
691
|
+
/** @internal */
|
|
692
|
+
_beginKernelBatch() {
|
|
693
|
+
this._disposed || this._kernelBatchDepth++;
|
|
694
|
+
}
|
|
695
|
+
/** @internal */
|
|
696
|
+
_endKernelBatch() {
|
|
697
|
+
this._kernelBatchDepth !== 0 && (this._kernelBatchDepth--, this._clearTransientCausesIfSettled(), this._disposed || this._requestExecution());
|
|
698
|
+
}
|
|
699
|
+
/** Регистрирует read-only diagnostics projection optional Machine. @internal */
|
|
700
|
+
_registerMachineDebug(e) {
|
|
701
|
+
return this._assertAlive(), this._debugController.registerMachine(e);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Проверяет optional diagnostic identity без создания public facade.
|
|
705
|
+
*
|
|
706
|
+
* @internal
|
|
707
|
+
*/
|
|
708
|
+
_hasMachineDebug(e) {
|
|
709
|
+
return this._debugController.hasMachine(e);
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Проверяет optional trace path без выделения operation ID.
|
|
713
|
+
*
|
|
714
|
+
* @internal
|
|
715
|
+
*/
|
|
716
|
+
_traces(e) {
|
|
717
|
+
return this._debugController.traces(e);
|
|
718
|
+
}
|
|
719
|
+
/** Возвращает наследуемый cause для optional execution layers. @internal */
|
|
720
|
+
_currentTraceCauseId() {
|
|
721
|
+
return this._traceCauseStack.at(-1);
|
|
722
|
+
}
|
|
723
|
+
/** Выдаёт operation id только на активном trace path. @internal */
|
|
724
|
+
_nextTraceOperation(e) {
|
|
725
|
+
return this._debugController.nextOperationId(e);
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Проверяет, должен ли untracked work изолировать reactive или Runtime owner context.
|
|
729
|
+
*
|
|
730
|
+
* @internal
|
|
731
|
+
*/
|
|
732
|
+
_hasActiveReactiveContext() {
|
|
733
|
+
return this._assertAlive(), this._reactivity.hasActiveContext();
|
|
734
|
+
}
|
|
735
|
+
/** Записывает optional trace event без machine dependency. @internal */
|
|
736
|
+
_recordTrace(e) {
|
|
737
|
+
this._debugController.record(e);
|
|
738
|
+
}
|
|
739
|
+
/** Наследует cause через outputs/tasks optional execution layers. @internal */
|
|
740
|
+
_runWithTraceCause(e, t) {
|
|
741
|
+
if (e === void 0)
|
|
742
|
+
return t();
|
|
743
|
+
this._traceCauseStack.push(e);
|
|
744
|
+
try {
|
|
745
|
+
return t();
|
|
746
|
+
} finally {
|
|
747
|
+
this._traceCauseStack.pop();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
_validatePhaseBinding(e, t, r, s = !1) {
|
|
751
|
+
if (typeof t != "function")
|
|
752
|
+
throw new TypeError("[Raph] Phase callback must be a function.");
|
|
753
|
+
const i = e.trim();
|
|
754
|
+
this._execution.requirePhase(i);
|
|
755
|
+
const o = r.priority ?? 0;
|
|
756
|
+
if (!Number.isFinite(o))
|
|
757
|
+
throw new TypeError("[Raph] Effect priority must be finite.");
|
|
758
|
+
const c = r.initial ?? "scheduled";
|
|
759
|
+
if (c !== "scheduled" && c !== "sync" && !(s && c === "none"))
|
|
760
|
+
throw new TypeError(`[Raph] Unsupported effect initial mode "${String(c)}".`);
|
|
761
|
+
return i;
|
|
762
|
+
}
|
|
763
|
+
_createDebugSnapshot() {
|
|
764
|
+
var r, s, i;
|
|
765
|
+
const e = ((r = this._frameLoop) == null ? void 0 : r._debugState()) ?? { running: !1, manual: !1, leases: 0 }, t = [...this._owners].filter((o) => o !== this.rootScope && !(o instanceof g)).map(b);
|
|
766
|
+
return Object.freeze({
|
|
767
|
+
id: this.id,
|
|
768
|
+
disposed: this._disposed,
|
|
769
|
+
pending: !this._disposed && (this._executionRequested || (((s = this._phases) == null ? void 0 : s._debugPending()) ?? !1)),
|
|
770
|
+
batchDepth: this._batchDepth,
|
|
771
|
+
kernelBatchDepth: this._kernelBatchDepth,
|
|
772
|
+
owners: this._owners.size,
|
|
773
|
+
pathHandles: ((i = this._pathHandles) == null ? void 0 : i.size) ?? 0,
|
|
774
|
+
rootScope: b(this.rootScope),
|
|
775
|
+
scopes: Object.freeze(t),
|
|
776
|
+
root: b(this.root),
|
|
777
|
+
frameLoop: Object.freeze(e),
|
|
778
|
+
actionDepth: this._actionDepth,
|
|
779
|
+
machines: this._debugController.machineCount,
|
|
780
|
+
traceEvents: this._debugController.traceSize
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
_createDebugTree() {
|
|
784
|
+
const e = this._debugController.machineTreeNodesByOwner(), t = [
|
|
785
|
+
R(this.rootScope, e),
|
|
786
|
+
R(this.root, e),
|
|
787
|
+
...[...this._owners].filter((r) => r !== this.rootScope && r !== this.root && !(r instanceof g)).map((r) => R(r, e))
|
|
788
|
+
];
|
|
789
|
+
return Object.freeze({
|
|
790
|
+
children: Object.freeze(t),
|
|
791
|
+
disposed: this._disposed,
|
|
792
|
+
id: this.id,
|
|
793
|
+
kind: "runtime"
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
_createDebugStats() {
|
|
797
|
+
var i, o;
|
|
798
|
+
let e = 0, t = 0, r = 0, s = 0;
|
|
799
|
+
for (const c of this._owners)
|
|
800
|
+
c instanceof g ? e++ : t++, r += c._debugResourceCount(), s += c._debugSourceCount();
|
|
801
|
+
return Object.freeze({
|
|
802
|
+
actors: this._debugController.actorCount,
|
|
803
|
+
machines: this._debugController.machineCount,
|
|
804
|
+
nodes: e,
|
|
805
|
+
owners: this._owners.size,
|
|
806
|
+
pathHandles: ((i = this._pathHandles) == null ? void 0 : i.size) ?? 0,
|
|
807
|
+
pending: !this._disposed && (this._executionRequested || (((o = this._phases) == null ? void 0 : o._debugPending()) ?? !1)),
|
|
808
|
+
resources: r,
|
|
809
|
+
scopes: t,
|
|
810
|
+
sources: s,
|
|
811
|
+
traceEvents: this._debugController.traceSize
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
_releasePathHandle(e) {
|
|
815
|
+
const t = this._pathHandles;
|
|
816
|
+
(t == null ? void 0 : t.get(e.path)) === e && (t.delete(e.path), t.size === 0 && (this._pathHandles = void 0));
|
|
817
|
+
}
|
|
818
|
+
get _execution() {
|
|
819
|
+
return this._assertAlive(), this._phases ?? (this._phases = new H(
|
|
820
|
+
this.configuration.scheduler,
|
|
821
|
+
(e) => this._runUntracked(e),
|
|
822
|
+
(e) => this._workGraph.causeForToken(e),
|
|
823
|
+
() => {
|
|
824
|
+
const e = this._mutationDepth !== 0 || this._batchDepth !== 0 || this._kernelBatchDepth !== 0 || this._ownerDisposalDepth !== 0 || this._reactivity._isFlushingEffects();
|
|
825
|
+
return e && this.configuration.scheduler === w.Sync && (this._executionRequested = !0), e;
|
|
826
|
+
},
|
|
827
|
+
(e, t, r) => {
|
|
828
|
+
var i, o, c;
|
|
829
|
+
let s;
|
|
830
|
+
t === "start" ? (s = this._debugController.nextOperationId("phase"), s !== void 0 && (this._phaseTraceOperations ?? (this._phaseTraceOperations = /* @__PURE__ */ new Map())).set(e, s)) : (s = (i = this._phaseTraceOperations) == null ? void 0 : i.get(e), (o = this._phaseTraceOperations) == null || o.delete(e), ((c = this._phaseTraceOperations) == null ? void 0 : c.size) === 0 && (this._phaseTraceOperations = void 0)), this._debugController.record({
|
|
831
|
+
...s === void 0 ? {} : { causeId: s },
|
|
832
|
+
...r === void 0 ? {} : { details: { message: C(r) } },
|
|
833
|
+
kind: "phase",
|
|
834
|
+
name: e,
|
|
835
|
+
...s === void 0 ? {} : { operationId: s },
|
|
836
|
+
status: t
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
));
|
|
840
|
+
}
|
|
841
|
+
get _clock() {
|
|
842
|
+
return this._frameLoop ?? (this._frameLoop = new I(() => this._tickFrameLoop()));
|
|
843
|
+
}
|
|
844
|
+
_tickFrameLoop() {
|
|
845
|
+
this._disposed || this._setFrameTick(this._frameTickWritable.peek() + 1);
|
|
846
|
+
}
|
|
847
|
+
_attachWritableComputed(e, t, r) {
|
|
848
|
+
let s = t;
|
|
849
|
+
this._own(() => {
|
|
850
|
+
s = void 0;
|
|
851
|
+
}, r);
|
|
852
|
+
const i = e;
|
|
853
|
+
return i.set = (o) => {
|
|
854
|
+
r._assertAlive(), this._assertWriteAllowed(), this._runWrite(() => s(o));
|
|
855
|
+
}, i;
|
|
856
|
+
}
|
|
857
|
+
_own(e, t) {
|
|
858
|
+
try {
|
|
859
|
+
return t._adoptResource(e);
|
|
860
|
+
} catch (r) {
|
|
861
|
+
try {
|
|
862
|
+
e();
|
|
863
|
+
} catch (s) {
|
|
864
|
+
throw new AggregateError([r, s], "[Raph] Resource registration and cleanup failed.");
|
|
865
|
+
}
|
|
866
|
+
throw r;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
_runTracked(e, t) {
|
|
870
|
+
return this._reactivity.runWithOwner(this._signalLifecycle, e, t);
|
|
871
|
+
}
|
|
872
|
+
_runUntracked(e) {
|
|
873
|
+
return this._reactivity.untrackedWithOwner(e);
|
|
874
|
+
}
|
|
875
|
+
_runWrite(e, t = !0) {
|
|
876
|
+
t && this.configuration.scheduler === w.Sync && (this._executionRequested = !0), this._mutationDepth++;
|
|
877
|
+
let r, s, i = !1;
|
|
878
|
+
try {
|
|
879
|
+
r = e();
|
|
880
|
+
} catch (c) {
|
|
881
|
+
i = !0, s = c;
|
|
882
|
+
}
|
|
883
|
+
this._mutationDepth--;
|
|
884
|
+
const o = this._finishExecutionBoundary();
|
|
885
|
+
if (i)
|
|
886
|
+
throw o.length !== 0 ? new AggregateError(
|
|
887
|
+
[s, ...o],
|
|
888
|
+
"[Raph] Mutation and scheduled phase execution failed."
|
|
889
|
+
) : s;
|
|
890
|
+
return y(o, "[Raph] Mutation phase execution failed."), r;
|
|
891
|
+
}
|
|
892
|
+
_finishExecutionBoundary() {
|
|
893
|
+
const e = [];
|
|
894
|
+
try {
|
|
895
|
+
this._clearTransientCausesIfSettled();
|
|
896
|
+
} catch (t) {
|
|
897
|
+
e.push(t);
|
|
898
|
+
}
|
|
899
|
+
try {
|
|
900
|
+
this._requestExecution();
|
|
901
|
+
} catch (t) {
|
|
902
|
+
e.push(t);
|
|
903
|
+
}
|
|
904
|
+
return e;
|
|
905
|
+
}
|
|
906
|
+
_clearTransientCausesIfSettled() {
|
|
907
|
+
this._mutationDepth === 0 && this._batchDepth === 0 && this._kernelBatchDepth === 0 && this._ownerDisposalDepth === 0 && !this._reactivity._isFlushingEffects() && this._workGraph.clearTransientCauses();
|
|
908
|
+
}
|
|
909
|
+
_requestExecution() {
|
|
910
|
+
var e;
|
|
911
|
+
this._disposed || this.configuration.scheduler !== w.Sync || this._mutationDepth !== 0 || this._batchDepth !== 0 || this._kernelBatchDepth !== 0 || this._ownerDisposalDepth !== 0 || this._reactivity._isFlushingEffects() || this._executionRequested && (this._executionRequested = !1, (e = this._phases) == null || e.flush());
|
|
912
|
+
}
|
|
913
|
+
_assertTrackedRead() {
|
|
914
|
+
this._assertAlive();
|
|
915
|
+
const e = this._reactivity.getActiveOwner();
|
|
916
|
+
e !== void 0 && e !== this && this._throwCrossRuntime(e);
|
|
917
|
+
const t = this._reactivity.getActiveConsumerOwner();
|
|
918
|
+
t !== void 0 && this._assertImplicitDependency(this.rootScope, t);
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Проверяет tracked read из optional owned source.
|
|
922
|
+
*
|
|
923
|
+
* @internal
|
|
924
|
+
*/
|
|
925
|
+
_assertSourceReadable(e) {
|
|
926
|
+
this._assertAlive();
|
|
927
|
+
const t = this._reactivity.getActiveOwner();
|
|
928
|
+
t !== void 0 && t !== this && this._throwCrossRuntime(t);
|
|
929
|
+
const r = this._reactivity.getActiveConsumerOwner();
|
|
930
|
+
r !== void 0 && this._assertImplicitDependency(e, r), e._assertAlive();
|
|
931
|
+
}
|
|
932
|
+
_assertImplicitDependency(e, t) {
|
|
933
|
+
if (e.runtime !== this || t.runtime !== this)
|
|
934
|
+
throw new k("[Raph] Implicit dependency crosses runtime boundaries.");
|
|
935
|
+
if (!(e === this.rootScope || e === t)) {
|
|
936
|
+
if (e instanceof g && t instanceof g) {
|
|
937
|
+
for (let r = t.parent; r !== null; r = r.parent)
|
|
938
|
+
if (r === e)
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
throw new Error(
|
|
942
|
+
`[Raph] Implicit dependency from "${t.id}" to "${e.id}" is not allowed; use watch().`
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
_assertWriteAllowed() {
|
|
947
|
+
if (this._assertAlive(), this.configuration.enforceActions && this._batchDepth === 0)
|
|
948
|
+
throw new B("[Raph] Writes are allowed only inside action() or batch().");
|
|
949
|
+
}
|
|
950
|
+
_throwCrossRuntime(e) {
|
|
951
|
+
throw new k(
|
|
952
|
+
`[Raph] Runtime "${this.id}" cannot be tracked by runtime "${e.id}".`
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
_assertAlive() {
|
|
956
|
+
if (this._disposed)
|
|
957
|
+
throw new A(`[Raph] Runtime "${this.id}" is disposed.`);
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
u(v, "_runtimeCounter", 0);
|
|
961
|
+
let S = v;
|
|
962
|
+
function K(p) {
|
|
963
|
+
return p === w.Sync || p === w.Microtask || p === w.AnimationFrame;
|
|
964
|
+
}
|
|
965
|
+
function J(p, e) {
|
|
966
|
+
const t = Array.isArray(p) ? p : [p];
|
|
967
|
+
if (t.length === 0)
|
|
968
|
+
throw new TypeError("[RaphMeta] watch requires at least one mask.");
|
|
969
|
+
if (e.namespace !== void 0 && !e.namespace.trim())
|
|
970
|
+
throw new Error("[RaphMeta] namespace must not be empty.");
|
|
971
|
+
for (const r of t)
|
|
972
|
+
x.from(r, e)._asMask();
|
|
973
|
+
}
|
|
974
|
+
function C(p) {
|
|
975
|
+
return p instanceof Error ? p.message : String(p);
|
|
976
|
+
}
|
|
977
|
+
export {
|
|
978
|
+
S as RaphRuntime
|
|
979
|
+
};
|