@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.
Files changed (211) hide show
  1. package/README.md +1096 -0
  2. package/dist/api/Raph.d.ts +59 -190
  3. package/dist/api/RaphFacadeSession.d.ts +90 -0
  4. package/dist/api/RaphReactivityInstance.d.ts +72 -0
  5. package/dist/api/errors.d.ts +9 -4
  6. package/dist/api/types.d.ts +162 -17
  7. package/dist/core-CyilRD7s.js +1055 -0
  8. package/dist/core-ugchZNqC.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -1
  10. package/dist/debug/api/Raph.js +368 -366
  11. package/dist/debug/api/RaphFacadeSession.cjs +1 -0
  12. package/dist/debug/api/RaphFacadeSession.js +306 -0
  13. package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
  14. package/dist/debug/api/RaphReactivityInstance.js +149 -0
  15. package/dist/debug/api/errors.cjs +1 -1
  16. package/dist/debug/api/errors.js +10 -7
  17. package/dist/debug/path/DataPath.cjs +1 -0
  18. package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
  19. package/dist/debug/path/PathRouter.cjs +1 -0
  20. package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
  21. package/dist/debug/path/RaphKernel.cjs +1 -1
  22. package/dist/debug/path/RaphKernel.js +258 -207
  23. package/dist/debug/path/data-path.utils.cjs +1 -0
  24. package/dist/debug/path/data-path.utils.js +56 -0
  25. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  26. package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
  27. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  28. package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
  29. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  30. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  31. package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
  32. package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
  33. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  34. package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
  35. package/dist/debug/path/meta/meta.types.cjs +1 -0
  36. package/dist/debug/path/meta/meta.types.js +1 -0
  37. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  38. package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
  39. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  40. package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
  41. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  42. package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
  43. package/dist/debug/path/storage/PathStore.cjs +1 -0
  44. package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
  45. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  46. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  47. package/dist/debug/reactivity/engine.cjs +1 -1
  48. package/dist/debug/reactivity/engine.js +478 -306
  49. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  50. package/dist/debug/reactivity/reactive-object.js +280 -0
  51. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  52. package/dist/debug/runtime/RaphRuntime.js +798 -519
  53. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  54. package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
  55. package/dist/debug/runtime/errors.cjs +1 -1
  56. package/dist/debug/runtime/errors.js +6 -3
  57. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  58. package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
  59. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  60. package/dist/debug/runtime/ownership/RaphNode.js +206 -0
  61. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  62. package/dist/debug/runtime/ownership/RaphScope.js +101 -0
  63. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  64. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  65. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  66. package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
  67. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  68. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  69. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  70. package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
  71. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  72. package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
  73. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  74. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
  75. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
  77. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
  79. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  80. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  81. package/dist/entrypoints/machine-testing.d.ts +2 -0
  82. package/dist/entrypoints/machine.d.ts +5 -0
  83. package/dist/entrypoints/path.d.ts +14 -0
  84. package/dist/entrypoints/reactivity.d.ts +1 -0
  85. package/dist/entrypoints/runtime.d.ts +17 -0
  86. package/dist/index.cjs +1 -1
  87. package/dist/index.js +46 -38
  88. package/dist/machine/compiler.d.ts +71 -0
  89. package/dist/machine/core.d.ts +50 -0
  90. package/dist/machine/persistence.d.ts +5 -0
  91. package/dist/machine/runtime.d.ts +4 -0
  92. package/dist/machine/testing.d.ts +43 -0
  93. package/dist/machine/types.d.ts +155 -0
  94. package/dist/machine-testing.cjs +1 -0
  95. package/dist/machine-testing.js +188 -0
  96. package/dist/machine.cjs +1 -0
  97. package/dist/machine.js +837 -0
  98. package/dist/main.d.ts +20 -0
  99. package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
  100. package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
  101. package/dist/path/RaphKernel.d.ts +13 -10
  102. package/dist/path/data-path.types.d.ts +34 -0
  103. package/dist/path/data-path.utils.d.ts +9 -0
  104. package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
  105. package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
  106. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  107. package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
  108. package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
  109. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  110. package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
  111. package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
  112. package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
  113. package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
  114. package/dist/path/path.types.d.ts +3 -2
  115. package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
  116. package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
  117. package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
  118. package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
  119. package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
  120. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  121. package/dist/path.cjs +1 -1
  122. package/dist/path.js +16 -16
  123. package/dist/raph.cjs +1 -1
  124. package/dist/raph.js +46 -38
  125. package/dist/reactivity/engine.d.ts +17 -3
  126. package/dist/reactivity/reactive-object.d.ts +36 -0
  127. package/dist/reactivity/types.d.ts +25 -0
  128. package/dist/reactivity.cjs +1 -1
  129. package/dist/reactivity.js +12 -12
  130. package/dist/runtime/RaphRuntime.d.ts +132 -192
  131. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  132. package/dist/runtime/errors.d.ts +5 -0
  133. package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
  134. package/dist/runtime/ownership/RaphNode.d.ts +40 -0
  135. package/dist/runtime/ownership/RaphScope.d.ts +38 -0
  136. package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
  137. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  138. package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
  139. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  140. package/dist/runtime/phases/phase.types.d.ts +92 -0
  141. package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
  142. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  143. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
  144. package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
  145. package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
  146. package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
  147. package/dist/runtime.cjs +1 -1
  148. package/dist/runtime.js +21 -16
  149. package/package.json +68 -35
  150. package/ReadMe.md +0 -153
  151. package/dist/api/public.d.ts +0 -22
  152. package/dist/debug/api/public.cjs +0 -1
  153. package/dist/debug/api/public.js +0 -40
  154. package/dist/debug/path/AdapterPathStore.cjs +0 -1
  155. package/dist/debug/path/DerivedRegistry.cjs +0 -1
  156. package/dist/debug/path/PathEventHub.cjs +0 -1
  157. package/dist/debug/path/PathStore.cjs +0 -1
  158. package/dist/debug/path/RaphMetaStore.cjs +0 -1
  159. package/dist/debug/path/data-adapter.cjs +0 -1
  160. package/dist/debug/path/data-path.cjs +0 -1
  161. package/dist/debug/path/derived-collection.cjs +0 -1
  162. package/dist/debug/path/path-router.cjs +0 -1
  163. package/dist/debug/path/public.cjs +0 -1
  164. package/dist/debug/path/public.js +0 -18
  165. package/dist/debug/runtime/PathHandle.cjs +0 -1
  166. package/dist/debug/runtime/RaphDebug.cjs +0 -1
  167. package/dist/debug/runtime/RaphDebug.js +0 -15
  168. package/dist/debug/runtime/RaphNode.cjs +0 -1
  169. package/dist/debug/runtime/RaphNode.js +0 -143
  170. package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
  171. package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
  172. package/dist/debug/runtime/RaphScope.cjs +0 -1
  173. package/dist/debug/runtime/RaphScope.js +0 -64
  174. package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
  175. package/dist/debug/runtime/RuntimeReactivity.js +0 -154
  176. package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
  177. package/dist/debug/runtime/RuntimeWatch.js +0 -71
  178. package/dist/debug/runtime/public.cjs +0 -1
  179. package/dist/debug/runtime/public.js +0 -18
  180. package/dist/path/public.d.ts +0 -14
  181. package/dist/runtime/RaphDebug.d.ts +0 -32
  182. package/dist/runtime/RaphNode.d.ts +0 -68
  183. package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
  184. package/dist/runtime/RaphScope.d.ts +0 -50
  185. package/dist/runtime/phase.types.d.ts +0 -49
  186. package/dist/runtime/public.d.ts +0 -13
  187. /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
  188. /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
  189. /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
  190. /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
  191. /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
  192. /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
  193. /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
  194. /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
  195. /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
  196. /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
  197. /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
  198. /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
  199. /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
  200. /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
  201. /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
  202. /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
  203. /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
  204. /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
  205. /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
  206. /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
  207. /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
  208. /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
  209. /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
  210. /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
  211. /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
@@ -1,700 +1,979 @@
1
- var W = Object.defineProperty;
2
- var b = (a, t, e) => t in a ? W(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var h = (a, t, e) => b(a, typeof t != "symbol" ? t + "" : t, e);
4
- import { RaphDisposedError as R, RaphCrossRuntimeError as k, RaphActionError as T } from "./errors.js";
5
- import { parentGraph as x } from "./parent-graph.js";
6
- import { PathHandle as L } from "./PathHandle.js";
7
- import { RaphSchedulerType as d } from "./phase.types.js";
8
- import { RaphNode as m } from "./RaphNode.js";
9
- import { parseDataPath as q, DataPath as A } from "../path/data-path.js";
10
- import { RaphKernel as O } from "../path/RaphKernel.js";
11
- import { RaphMeta as M } from "../path/RaphMeta.js";
12
- import { watchWithReactivity as $ } from "../reactivity/watch.js";
13
- import { throwDisposalErrors as D } from "./disposal.js";
14
- import { createOwnerSnapshot as y } from "./RaphDebug.js";
15
- import { RaphFrameLoop as H } from "./RaphFrameLoop.js";
16
- import { RaphPhasePipeline as F } from "./RaphPhasePipeline.js";
17
- import { RaphScope as S } from "./RaphScope.js";
18
- import { RuntimeReactivity as U } from "./RuntimeReactivity.js";
19
- import { RuntimeWatch as g } from "./RuntimeWatch.js";
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";
20
23
  const v = class v {
21
- /**
22
- * Создаёт изолированный execution graph поверх собственного или shared Kernel.
23
- */
24
- constructor(t = {}) {
25
- // Публикуют immutable configuration и корневых lifecycle owners.
26
- h(this, "configuration");
27
- h(this, "rootScope");
28
- h(this, "root");
29
- // Владеют изолированным reactive graph и его runtime policy.
30
- h(this, "_reactivity");
31
- h(this, "_signalLifecycle");
32
- // Лениво создают adapters и diagnostics только по запросу consumer.
33
- h(this, "_pathHandles");
34
- h(this, "_meta");
35
- h(this, "_phases");
36
- h(this, "_frameLoop");
37
- h(this, "_frameRevision");
38
- h(this, "_frameRevisionValue", !1);
39
- h(this, "_debug");
40
- h(this, "_parentGraph");
41
- // Регистрируют всех lifecycle owners runtime.
42
- h(this, "_owners", /* @__PURE__ */ new Set());
43
- // Координируют вложенные write boundaries и execution requests.
44
- h(this, "_transactionDepth", 0);
45
- h(this, "_mutationDepth", 0);
46
- h(this, "_kernelTransactionDepth", 0);
47
- h(this, "_actionDepth", 0);
48
- h(this, "_executionRequested", !1);
49
- // Хранят окончательное состояние runtime и dispose listeners.
50
- h(this, "_disposed", !1);
51
- h(this, "_disposedListeners", /* @__PURE__ */ new Set());
52
- const e = t.id ?? `runtime-${v._runtimeCounter++}`, s = t.enforceActions ?? !1, i = t.scheduler ?? d.Sync;
53
- if (!I(i))
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))
54
56
  throw new Error(`[Raph] Unsupported scheduler "${String(i)}".`);
55
- const r = t.kernel ?? new O({ id: `${e}-kernel` });
56
- this.configuration = Object.freeze({ id: e, kernel: r, enforceActions: s, scheduler: i });
57
- const o = `[Raph] Runtime "${e}" is disposed.`;
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.`;
58
67
  this._signalLifecycle = {
59
68
  owner: this,
60
- runWrite: (n) => this._runWrite(n),
69
+ runWrite: (d) => this._runWrite(d),
70
+ assertDependencyAllowed: (d, l) => {
71
+ this._assertImplicitDependency(d, l);
72
+ },
61
73
  ...s ? { assertWriteAllowed: () => this._assertWriteAllowed() } : {},
62
74
  throwDisposed: () => {
63
- throw new R(o);
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);
64
86
  },
65
- throwCrossRuntime: (n) => this._throwCrossRuntime(n)
66
- }, this._reactivity = new U(this._signalLifecycle), r._attachRuntime(this), this.rootScope = new S(`${e}:root-scope`, this), this.root = new m(null, { id: `${e}:root` }, this);
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
+ });
67
111
  }
68
- /**
69
- * Возвращает внутренний runtime reactivity adapter.
70
- * @internal
71
- */
112
+ /** @internal */
72
113
  _getReactivity() {
73
114
  return this._reactivity;
74
115
  }
75
116
  /**
76
- * Возвращает стабильный идентификатор runtime.
117
+ * Возвращает внутренний WorkGraph для optional execution layers.
118
+ *
119
+ * @internal
77
120
  */
121
+ _getWorkGraph() {
122
+ return this._workGraph;
123
+ }
78
124
  get id() {
79
125
  return this.configuration.id;
80
126
  }
81
- /**
82
- * Возвращает data/meta Kernel этого runtime.
83
- */
84
127
  get kernel() {
85
128
  return this.configuration.kernel;
86
129
  }
87
- /**
88
- * Возвращает лениво созданный runtime-owned metadata facade.
89
- */
90
- get meta() {
91
- return this._assertAlive(), this._meta ?? (this._meta = new M(this.kernel, {
92
- assertReadable: () => this._assertAlive(),
93
- assertWritable: () => this._assertWriteAllowed(),
94
- runWrite: (t, e) => this._runWrite(t, e),
95
- watch: (t, e, s) => this._own(
96
- this._watchMeta(t, e, s),
97
- this.rootScope
98
- )
99
- }));
100
- }
101
- /**
102
- * Показывает, освобождён ли runtime.
103
- */
104
130
  get disposed() {
105
131
  return this._disposed;
106
132
  }
107
- /**
108
- * Возвращает лениво созданное read-only представление ownership graph.
109
- */
110
133
  get graph() {
111
- return this._parentGraph ?? (this._parentGraph = x());
134
+ return this._parentGraph ?? (this._parentGraph = F());
112
135
  }
113
- /**
114
- * Показывает, удерживается ли автоматический frame-loop.
115
- */
116
136
  get loopEnabled() {
117
- var t;
118
- return ((t = this._frameLoop) == null ? void 0 : t.running) ?? !1;
137
+ var e;
138
+ return ((e = this._frameLoop) == null ? void 0 : e.running) ?? !1;
119
139
  }
120
- /**
121
- * Возвращает последний frame context runtime pipeline.
122
- */
123
140
  get frame() {
124
- var t;
125
- return ((t = this._phases) == null ? void 0 : t.frame) ?? { now: 0, delta: 0, elapsed: 0, frame: 0 };
141
+ var e;
142
+ return ((e = this._phases) == null ? void 0 : e.frame) ?? { now: 0, delta: 0, elapsed: 0, frame: 0 };
126
143
  }
127
- /**
128
- * Возвращает текущее определение runtime phases.
129
- */
130
144
  get phases() {
131
- var t;
132
- return ((t = this._phases) == null ? void 0 : t.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
+ });
133
164
  }
134
- /**
135
- * Формирует диагностический снимок materialized derived registry.
136
- */
137
165
  getDerivedSnapshot() {
138
166
  return this.kernel.getDerivedSnapshot();
139
167
  }
140
- /**
141
- * Возвращает лениво созданную read-only диагностику runtime и ownership tree.
142
- */
143
168
  get debug() {
144
169
  return this._debug ?? (this._debug = Object.freeze({
145
170
  snapshot: () => this._createDebugSnapshot(),
146
- getTree: () => y(this.root)
171
+ getTree: () => this._createDebugTree(),
172
+ stats: () => this._createDebugStats(),
173
+ trace: this._debugController.trace,
174
+ machines: this._debugController.machines
147
175
  }));
148
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
+ }
149
186
  /**
150
- * Создаёт writable signal, принадлежащий указанному owner.
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.
151
190
  */
152
- signal(t, e = this.rootScope) {
153
- return this._assertOwnerRuntime(e), this._reactivity.signalForOwner(t, e);
191
+ reactive(e) {
192
+ return this._assertAlive(), this._reactivity.reactive(e);
154
193
  }
155
- computed(t, e = this.rootScope) {
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) {
156
214
  this._assertOwnerRuntime(e);
157
- const s = typeof t == "function" ? t : t.get, i = this._reactivity.computedForOwner(
158
- () => this._runTracked(s),
159
- 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
+ )
160
237
  );
161
- return typeof t == "function" ? i : this._attachWritableComputed(i, t.set, e);
162
- }
163
- effect(t, e, s = {}, i = this.rootScope) {
164
- const r = typeof t == "string" ? e : t, o = typeof t == "string" ? i : e ?? this.rootScope;
165
- if (this._assertOwnerRuntime(o), typeof t == "string") {
166
- const n = t.trim(), c = this._execution;
167
- c.requirePhase(n);
168
- const p = s.priority ?? 0, u = s.initial ?? "scheduled";
169
- if (!Number.isFinite(p))
170
- throw new TypeError("[Raph] Effect priority must be finite.");
171
- if (u !== "scheduled" && u !== "sync")
172
- throw new TypeError(`[Raph] Unsupported effect initial mode "${String(u)}".`);
173
- u === "sync" && c.lockConfiguration();
174
- const l = c.phaseMode(n) === "always" ? this._frameRevision ?? (this._frameRevision = this._reactivity.signal(!1)) : void 0, w = this._reactivity.withEffectBinding(
175
- (_) => c.bindEffect(
176
- n,
177
- p,
178
- _,
179
- o instanceof m ? o : void 0
180
- ),
181
- u,
182
- () => this._reactivity.effect(() => (l == null || l.get(), this._runTracked(r)))
183
- );
184
- return this._own(w, o);
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;
185
251
  }
186
- return this._own(
187
- this._reactivity._effectImmediate(() => this._runTracked(r)),
188
- o
189
- );
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
+ };
190
257
  }
191
- watch(t, e, s = {}, i = this.rootScope) {
192
- return this._assertOwnerRuntime(i), z(t) ? this._own(this._watchPath(t, e), i) : this._own(
193
- $(
194
- this._reactivity._effectImmediate,
195
- this._reactivity.untracked,
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(
196
282
  t,
197
- e,
198
- s,
199
- (r) => this._runTracked(r)
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
+ }
200
339
  ),
201
- i
340
+ () => s(!1)
202
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
+ }
203
356
  }
204
- /**
205
- * Возвращает кешируемый runtime-owned handle canonical path.
206
- */
207
- path(t, e = {}) {
357
+ path(e, t = {}) {
208
358
  this._assertAlive();
209
- const s = q(t, e), i = this._pathHandles ?? (this._pathHandles = /* @__PURE__ */ new Map()), r = i.get(s.canonical);
210
- if (r !== void 0)
211
- return r;
212
- const o = new L(
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(
213
363
  this.kernel,
214
- s,
215
- e,
216
- (n) => this._releasePathHandle(n),
364
+ r,
365
+ t,
366
+ (a) => this._releasePathHandle(a),
217
367
  this._reactivity,
218
368
  () => this._assertAlive(),
219
369
  () => this._assertTrackedRead(),
220
370
  this.configuration.enforceActions ? () => this._assertWriteAllowed() : void 0,
221
- (n) => this._runWrite(n)
371
+ (a) => this._runWrite(a),
372
+ { token: o, onDispose: c.onDispose },
373
+ ({ events: a }, h) => this._workGraph.notifyProducerEvents(o, a, !0, h)
222
374
  );
223
- return i.set(s.canonical, o), o;
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
+ }
224
389
  }
225
- get(t, e) {
390
+ get(e, t) {
226
391
  this._assertTrackedRead();
227
- const s = t ?? "";
228
- return this._reactivity._isTracking() ? this.path(s, e)._getTracked() : this.kernel.get(s, e);
392
+ const r = e ?? "";
393
+ return this._reactivity._isTracking() ? this.path(r, t)._getTracked() : this.kernel.get(r, t);
229
394
  }
230
- peek(t, e) {
231
- return this._assertAlive(), this.kernel.peek(t ?? "", e);
395
+ peek(e, t) {
396
+ return this._assertAlive(), this.kernel.peek(e ?? "", t);
232
397
  }
233
- /**
234
- * Проверяет наличие значения Kernel по пути.
235
- */
236
- has(t, e) {
237
- return this._assertAlive(), this.kernel.has(t, e);
398
+ has(e, t) {
399
+ return this._assertAlive(), this.kernel.has(e, t);
238
400
  }
239
- /**
240
- * Записывает значение Kernel внутри runtime write policy.
241
- */
242
- set(t, e, s) {
243
- this._assertWriteAllowed(), this._runWrite(() => this.kernel.set(t, e, s));
401
+ set(e, t, r) {
402
+ this._assertWriteAllowed(), this._runWrite(() => this.kernel.set(e, t, r));
244
403
  }
245
- /**
246
- * Объединяет значение Kernel внутри runtime write policy.
247
- */
248
- merge(t, e, s) {
249
- this._assertWriteAllowed(), this._runWrite(() => this.kernel.merge(t, e, s));
404
+ merge(e, t, r) {
405
+ this._assertWriteAllowed(), this._runWrite(() => this.kernel.merge(e, t, r));
250
406
  }
251
- /**
252
- * Удаляет значение Kernel внутри runtime write policy.
253
- */
254
- delete(t, e) {
255
- this._assertWriteAllowed(), this._runWrite(() => this.kernel.delete(t, e));
407
+ delete(e, t) {
408
+ this._assertWriteAllowed(), this._runWrite(() => this.kernel.delete(e, t));
256
409
  }
257
- /**
258
- * Выполняет операцию в общей синхронной transaction boundary.
259
- */
260
- transaction(t) {
261
- this._assertAlive(), this._transactionDepth++;
262
- try {
263
- return this._reactivity.batch(() => this.kernel.transaction(t));
264
- } finally {
265
- this._transactionDepth--, this._requestExecution();
266
- }
410
+ batch(e) {
411
+ return this._batch(e, !0);
267
412
  }
268
- /**
269
- * Создаёт именованную action boundary для разрешённых записей.
270
- */
271
- action(t, e, s = this.rootScope) {
272
- if (this._assertOwnerRuntime(s), !t.trim())
273
- throw new Error("[Raph] Action name must not be empty.");
274
- return (...i) => (s._assertAlive(), this.runInAction(t, () => e(...i)));
413
+ /** Batches an internal reactive-only commit without opening an unused Kernel boundary. @internal */
414
+ _batchReactive(e) {
415
+ return this._batch(e, !1);
275
416
  }
276
- /**
277
- * Выполняет операцию внутри action boundary.
278
- */
279
- runInAction(t, e) {
280
- this._assertAlive(), this._actionDepth++;
417
+ _batch(e, t) {
418
+ this._assertAlive(), this._batchDepth++;
419
+ let r, s, i = !1;
281
420
  try {
282
- return this.transaction(() => this._runUntracked(e));
283
- } finally {
284
- this._actionDepth--;
421
+ r = this._reactivity.batch(() => t ? this.kernel.batch(e) : e());
422
+ } catch (c) {
423
+ i = !0, s = c;
285
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
+ };
286
479
  }
287
- /**
288
- * Выполняет операцию без регистрации реактивных зависимостей.
289
- */
290
- untracked(t) {
291
- return this._assertAlive(), this._reactivity.untrackedWithOwner(t);
480
+ untracked(e) {
481
+ return this._assertAlive(), this._runUntracked(e);
292
482
  }
293
- /**
294
- * Создаёт дочерний lifecycle scope.
295
- */
296
- scope(t) {
297
- return this._assertAlive(), new S(t, this);
483
+ scope(e) {
484
+ return this._assertAlive(), new D(e, this);
298
485
  }
299
- /**
300
- * Создаёт дочерний execution node.
301
- */
302
- node(t, e) {
486
+ node(e, t) {
303
487
  this._assertAlive();
304
- const s = t.parent ?? this.root, i = new m(s, t, this);
305
- try {
306
- return i._setApi(e(i)), i;
307
- } catch (r) {
488
+ const r = this._runNodeMutation(() => {
489
+ const s = e.parent ?? this.root, i = q(s, e, this);
308
490
  try {
309
- i.dispose();
491
+ const o = t == null ? void 0 : t(i);
492
+ return i._assertAlive(), s._assertAlive(), i._setApi(o), i._publishCreation(), i;
310
493
  } catch (o) {
311
- throw new AggregateError(
312
- [r, o],
313
- `[Raph] Node "${i.id}" setup and cleanup failed.`
314
- );
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;
315
500
  }
316
- throw r;
317
- }
501
+ });
502
+ return r._assertAlive(), r;
318
503
  }
319
- /**
320
- * Находит принадлежащий runtime node по id для диагностики.
321
- */
322
- getNode(t) {
504
+ getNode(e) {
323
505
  this._assertAlive();
324
- const e = [this.root];
325
- for (; e.length !== 0; ) {
326
- const s = e.pop();
327
- if (s.id === t)
328
- return s;
329
- e.push(...s.children);
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);
330
512
  }
331
513
  }
332
- /**
333
- * Заменяет полное определение phase pipeline до его первого выполнения.
334
- */
335
- definePhases(t) {
336
- this._execution.definePhases(t);
514
+ definePhases(e) {
515
+ this._execution.definePhases(e);
337
516
  }
338
- /**
339
- * Добавляет phase до первого выполнения pipeline.
340
- */
341
- addPhase(t) {
342
- this._execution.addPhase(t);
517
+ addPhase(e) {
518
+ this._execution.addPhase(e);
343
519
  }
344
- /**
345
- * Удаляет пользовательские phases до первого выполнения pipeline.
346
- */
347
520
  clearPhases() {
348
- var t;
349
- this._assertAlive(), (t = this._phases) == null || t.clearPhases();
350
- }
351
- /**
352
- * Регистрирует path observer в phase pipeline.
353
- */
354
- observeData(t, e, s) {
355
- return this._assertOwnerRuntime(t), this._own(this._execution.observeData(t, e, s), t);
521
+ var e;
522
+ this._assertAlive(), (e = this._phases) == null || e.clearPhases();
356
523
  }
357
- /**
358
- * Регистрирует tracked executor указанной phase.
359
- */
360
- track(t, e, s = {}) {
361
- return this._assertOwnerRuntime(t), this._own(this._execution.track(t, e, s), t);
362
- }
363
- /**
364
- * Помечает node для выполнения в pipeline.
365
- */
366
- invalidateNode(t, e) {
367
- this._assertOwnerRuntime(t), this._execution.invalidate(t, e);
524
+ requestExecution() {
525
+ var e;
526
+ this._assertAlive(), (e = this._phases) == null || e.request();
368
527
  }
369
- /**
370
- * Синхронно выполняет все готовые очереди pipeline.
371
- */
372
528
  flush() {
373
- var t;
374
- this._assertAlive(), this._executionRequested = !1, (t = this._phases) == null || t.flush();
529
+ var e;
530
+ this._assertAlive(), this._executionRequested = !1, (e = this._phases) == null || e.flush();
375
531
  }
376
- /**
377
- * Получает lease автоматического frame-loop.
378
- */
379
- acquireLoop(t) {
380
- return this._assertAlive(), this._clock.acquire(t);
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);
381
538
  }
382
- /**
383
- * Запускает manual lease автоматического frame-loop.
384
- */
385
539
  startLoop() {
386
540
  this._assertAlive(), this._clock.start();
387
541
  }
388
- /**
389
- * Останавливает manual lease автоматического frame-loop.
390
- */
391
542
  stopLoop() {
392
- var t;
393
- (t = this._frameLoop) == null || t.stop();
543
+ var e;
544
+ (e = this._frameLoop) == null || e.stop();
394
545
  }
395
- /**
396
- * Создаёт управляемое derived-представление source path в target path.
397
- */
398
- derive(t) {
546
+ derive(e) {
399
547
  this._assertAlive();
400
- const e = t.compute, s = this.kernel.derive({
401
- ...t,
402
- compute: (i) => this._runUntracked(() => e(i))
548
+ const t = e.compute, r = this.kernel.derive({
549
+ ...e,
550
+ compute: (s) => this._runUntracked(() => t(s))
403
551
  });
404
- return this._own(() => s.dispose(), this.rootScope), s;
552
+ return this._own(() => r.dispose(), this.rootScope), r;
405
553
  }
406
- /**
407
- * Освобождает execution graph и отсоединяет runtime от shared Kernel.
408
- */
409
554
  dispose() {
410
- var r, o;
555
+ var c, n;
411
556
  if (this._disposed)
412
557
  return;
413
558
  this._disposed = !0, this._executionRequested = !1, this._signalLifecycle.owner = void 0;
414
- const t = [], e = [...this._owners];
559
+ const e = [], t = [...this._owners];
415
560
  try {
416
- (r = this._frameLoop) == null || r.dispose();
417
- } catch (n) {
418
- t.push(n);
561
+ (c = this._frameLoop) == null || c.dispose();
562
+ } catch (a) {
563
+ e.push(a);
419
564
  }
420
565
  this._frameLoop = void 0;
421
566
  try {
422
- (o = this._phases) == null || o.dispose();
423
- } catch (n) {
424
- t.push(n);
567
+ (n = this._phases) == null || n.dispose();
568
+ } catch (a) {
569
+ e.push(a);
425
570
  }
426
571
  this._phases = void 0;
427
572
  try {
428
573
  this.root.dispose();
429
- } catch (n) {
430
- t.push(n);
574
+ } catch (a) {
575
+ e.push(a);
431
576
  }
432
- for (const n of e.reverse())
433
- if (!(n === this.root || n === this.rootScope || n.disposed))
577
+ for (const a of t.reverse())
578
+ if (!(a === this.root || a === this.rootScope || a.disposed))
434
579
  try {
435
- n.dispose();
436
- } catch (c) {
437
- t.push(c);
580
+ a.dispose();
581
+ } catch (h) {
582
+ e.push(h);
438
583
  }
439
584
  try {
440
585
  this.rootScope.dispose();
441
- } catch (n) {
442
- t.push(n);
586
+ } catch (a) {
587
+ e.push(a);
443
588
  }
444
- this._owners.clear(), this._meta = void 0, this._frameRevision = void 0;
445
- const s = this._pathHandles;
446
- if (this._pathHandles = void 0, s !== void 0) {
447
- for (const n of s.values())
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())
448
605
  try {
449
- n.dispose();
450
- } catch (c) {
451
- t.push(c);
606
+ a.dispose();
607
+ } catch (h) {
608
+ e.push(h);
452
609
  }
453
- s.clear();
610
+ i.clear();
611
+ }
612
+ try {
613
+ this._workGraph.dispose();
614
+ } catch (a) {
615
+ e.push(a);
454
616
  }
455
617
  try {
456
618
  this.kernel._detachRuntime(this);
457
- } catch (n) {
458
- t.push(n);
619
+ } catch (a) {
620
+ e.push(a);
459
621
  }
460
- const i = [...this._disposedListeners];
622
+ const o = [...this._disposedListeners];
461
623
  this._disposedListeners.clear();
462
- for (const n of i)
624
+ for (const a of o)
463
625
  try {
464
- n();
465
- } catch (c) {
466
- t.push(c);
626
+ a();
627
+ } catch (h) {
628
+ e.push(h);
467
629
  }
468
- D(t, `[Raph] Runtime "${this.id}" disposal failed.`);
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);
469
702
  }
470
703
  /**
471
- * Регистрирует listener освобождения runtime.
704
+ * Проверяет optional diagnostic identity без создания public facade.
705
+ *
472
706
  * @internal
473
707
  */
474
- _onDisposed(t) {
475
- return this._disposed ? (t(), () => {
476
- }) : (this._disposedListeners.add(t), () => {
477
- this._disposedListeners.delete(t);
478
- });
708
+ _hasMachineDebug(e) {
709
+ return this._debugController.hasMachine(e);
479
710
  }
480
- _watchPath(t, e) {
481
- const s = new g((r) => this._runUntracked(r)), i = this.kernel.watch(t, (r) => {
482
- s.deliver(() => e(r));
483
- });
484
- return () => s.stop(i);
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;
485
762
  }
486
763
  _createDebugSnapshot() {
487
- var s, i, r;
488
- const t = ((s = this._frameLoop) == null ? void 0 : s._debugState()) ?? { running: !1, manual: !1, leases: 0 }, e = [...this._owners].filter((o) => o !== this.rootScope && !(o instanceof m)).map(y);
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);
489
766
  return Object.freeze({
490
767
  id: this.id,
491
768
  disposed: this._disposed,
492
- pending: !this._disposed && (this._executionRequested || (((i = this._phases) == null ? void 0 : i._debugPending()) ?? !1)),
493
- transactionDepth: this._transactionDepth,
494
- kernelTransactionDepth: this._kernelTransactionDepth,
769
+ pending: !this._disposed && (this._executionRequested || (((s = this._phases) == null ? void 0 : s._debugPending()) ?? !1)),
770
+ batchDepth: this._batchDepth,
771
+ kernelBatchDepth: this._kernelBatchDepth,
495
772
  owners: this._owners.size,
496
- pathHandles: ((r = this._pathHandles) == null ? void 0 : r.size) ?? 0,
497
- rootScope: y(this.rootScope),
498
- scopes: Object.freeze(e),
499
- root: y(this.root),
500
- frameLoop: Object.freeze(t)
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
501
781
  });
502
782
  }
503
- _watchMeta(t, e, s) {
504
- if (s.phase !== void 0)
505
- return this._watchMetaInPhase(t, e, s);
506
- if (s.priority !== void 0)
507
- throw new TypeError("[RaphMeta] watch priority requires a phase.");
508
- const i = new g((o) => this._runUntracked(o)), r = this.kernel._watchMeta(t, (o) => {
509
- i.deliver(() => e(o));
510
- }, s);
511
- return () => i.stop(r);
512
- }
513
- _watchMetaInPhase(t, e, s) {
514
- const i = s.phase.trim(), r = this._execution;
515
- r.requirePhase(i);
516
- const o = s.priority ?? 0;
517
- if (!Number.isFinite(o))
518
- throw new TypeError("[RaphMeta] watch priority must be finite.");
519
- const n = r.retainPhase(i), c = new g((_) => this._runUntracked(_));
520
- let p = [], u;
521
- const l = () => {
522
- u = void 0;
523
- const _ = p;
524
- p = [], c.deliver(() => e({ events: _ }));
525
- };
526
- let w;
527
- try {
528
- w = this.kernel._watchMeta(t, ({ events: _ }) => {
529
- c.stopped || (p.push(..._), u === void 0 && (u = r.queueEffect(i, o, l, !1)));
530
- }, s, (_) => {
531
- !c.stopped && _ && u !== void 0 && r.request();
532
- });
533
- } catch (_) {
534
- throw n(), _;
535
- }
536
- return () => {
537
- if (c.stopped)
538
- return;
539
- const _ = [];
540
- try {
541
- c.stop(w);
542
- } catch (f) {
543
- _.push(f);
544
- }
545
- try {
546
- u == null || u();
547
- } catch (f) {
548
- _.push(f);
549
- }
550
- try {
551
- n();
552
- } catch (f) {
553
- _.push(f);
554
- }
555
- u = void 0, p = [], D(_, "[RaphMeta] Phase watch disposal failed.");
556
- };
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
+ });
557
795
  }
558
- _releasePathHandle(t) {
559
- const e = this._pathHandles;
560
- (e == null ? void 0 : e.get(t.path)) === t && (e.delete(t.path), e.size === 0 && (this._pathHandles = void 0));
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));
561
817
  }
562
818
  get _execution() {
563
- return this._assertAlive(), this._phases ?? (this._phases = new F(
564
- this.kernel,
565
- this.root,
819
+ return this._assertAlive(), this._phases ?? (this._phases = new H(
566
820
  this.configuration.scheduler,
567
- (t) => this._runUntracked(t),
821
+ (e) => this._runUntracked(e),
822
+ (e) => this._workGraph.causeForToken(e),
568
823
  () => {
569
- const t = this._mutationDepth !== 0 || this._transactionDepth !== 0 || this._kernelTransactionDepth !== 0 || this._reactivity._isFlushingEffects();
570
- return t && this.configuration.scheduler === d.Sync && (this._executionRequested = !0), t;
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
+ });
571
838
  }
572
839
  ));
573
840
  }
574
841
  get _clock() {
575
- return this._frameLoop ?? (this._frameLoop = new H(() => this._tickFrameLoop()));
842
+ return this._frameLoop ?? (this._frameLoop = new I(() => this._tickFrameLoop()));
576
843
  }
577
844
  _tickFrameLoop() {
578
- var t;
579
- this._disposed || (this._frameRevision !== void 0 && (this._frameRevisionValue = !this._frameRevisionValue, this._frameRevision.set(this._frameRevisionValue)), (t = this._phases) == null || t.requestAlwaysPhases(), this._requestExecution());
845
+ this._disposed || this._setFrameTick(this._frameTickWritable.peek() + 1);
580
846
  }
581
- _attachWritableComputed(t, e, s) {
582
- let i = e;
847
+ _attachWritableComputed(e, t, r) {
848
+ let s = t;
583
849
  this._own(() => {
584
- i = void 0;
585
- }, s);
586
- const r = t;
587
- return r.set = (o) => {
588
- s._assertAlive(), this._assertWriteAllowed(), i(o);
589
- }, r;
590
- }
591
- _own(t, e) {
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) {
592
858
  try {
593
- return e._adoptResource(t);
594
- } catch (s) {
859
+ return t._adoptResource(e);
860
+ } catch (r) {
595
861
  try {
596
- t();
597
- } catch (i) {
598
- throw new AggregateError(
599
- [s, i],
600
- "[Raph] Resource registration and cleanup failed."
601
- );
862
+ e();
863
+ } catch (s) {
864
+ throw new AggregateError([r, s], "[Raph] Resource registration and cleanup failed.");
602
865
  }
603
- throw s;
866
+ throw r;
604
867
  }
605
868
  }
606
- /**
607
- * Регистрирует lifecycle owner в runtime registry.
608
- * @internal
609
- */
610
- _registerOwner(t) {
611
- this._assertAlive(), this._owners.add(t);
612
- }
613
- /**
614
- * Удаляет lifecycle owner из runtime registry.
615
- * @internal
616
- */
617
- _unregisterOwner(t) {
618
- this._owners.delete(t);
619
- }
620
- /**
621
- * Проверяет, что owner принадлежит этому живому runtime.
622
- * @internal
623
- */
624
- _assertOwnerRuntime(t) {
625
- if (this._assertAlive(), t.runtime !== this)
626
- throw new k("[Raph] Owner belongs to another runtime.");
627
- t._assertAlive();
869
+ _runTracked(e, t) {
870
+ return this._reactivity.runWithOwner(this._signalLifecycle, e, t);
628
871
  }
629
- _runTracked(t) {
630
- return this._reactivity.runWithOwner(this._signalLifecycle, t);
872
+ _runUntracked(e) {
873
+ return this._reactivity.untrackedWithOwner(e);
631
874
  }
632
- _runUntracked(t) {
633
- return this._reactivity.untrackedWithOwner(t);
634
- }
635
- _runWrite(t, e = !0) {
636
- e && this.configuration.scheduler === d.Sync && (this._executionRequested = !0), this._mutationDepth++;
875
+ _runWrite(e, t = !0) {
876
+ t && this.configuration.scheduler === w.Sync && (this._executionRequested = !0), this._mutationDepth++;
877
+ let r, s, i = !1;
637
878
  try {
638
- return t();
639
- } finally {
640
- this._mutationDepth--, this._requestExecution();
879
+ r = e();
880
+ } catch (c) {
881
+ i = !0, s = c;
641
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();
642
908
  }
643
909
  _requestExecution() {
644
- var t;
645
- this.configuration.scheduler !== d.Sync || this._mutationDepth !== 0 || this._transactionDepth !== 0 || this._kernelTransactionDepth !== 0 || this._reactivity._isFlushingEffects() || this._executionRequested && (this._executionRequested = !1, (t = this._phases) == null || t.flush());
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());
646
912
  }
647
- /**
648
- * Открывает shared Kernel transaction для runtime.
649
- * @internal
650
- */
651
- _beginKernelTransaction() {
652
- this._disposed || this._kernelTransactionDepth++;
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);
653
919
  }
654
920
  /**
655
- * Закрывает shared Kernel transaction и запускает отложенное выполнение.
921
+ * Проверяет tracked read из optional owned source.
922
+ *
656
923
  * @internal
657
924
  */
658
- _endKernelTransaction() {
659
- this._kernelTransactionDepth !== 0 && (this._kernelTransactionDepth--, this._disposed || this._requestExecution());
660
- }
661
- _assertTrackedRead() {
925
+ _assertSourceReadable(e) {
662
926
  this._assertAlive();
663
927
  const t = this._reactivity.getActiveOwner();
664
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
+ }
665
945
  }
666
946
  _assertWriteAllowed() {
667
- if (this._assertAlive(), this.configuration.enforceActions && this._actionDepth === 0 && this._transactionDepth === 0)
668
- throw new T(
669
- "[Raph] Writes are allowed only inside action() or transaction()."
670
- );
947
+ if (this._assertAlive(), this.configuration.enforceActions && this._batchDepth === 0)
948
+ throw new B("[Raph] Writes are allowed only inside action() or batch().");
671
949
  }
672
- _throwCrossRuntime(t) {
950
+ _throwCrossRuntime(e) {
673
951
  throw new k(
674
- `[Raph] Runtime "${this.id}" cannot be tracked by runtime "${t.id}".`
952
+ `[Raph] Runtime "${this.id}" cannot be tracked by runtime "${e.id}".`
675
953
  );
676
954
  }
677
- _throwDisposed() {
678
- throw new R(`[Raph] Runtime "${this.id}" is disposed.`);
679
- }
680
955
  _assertAlive() {
681
- this._disposed && this._throwDisposed();
956
+ if (this._disposed)
957
+ throw new A(`[Raph] Runtime "${this.id}" is disposed.`);
682
958
  }
683
959
  };
684
- // Формирует локальный id для runtime без явно заданного имени.
685
- h(v, "_runtimeCounter", 0);
686
- let P = v;
687
- function z(a) {
688
- return typeof a == "string" || a instanceof A || E(a) ? !0 : Array.isArray(a) && a.every(
689
- (t) => typeof t == "string" || t instanceof A || E(t)
690
- );
960
+ u(v, "_runtimeCounter", 0);
961
+ let S = v;
962
+ function K(p) {
963
+ return p === w.Sync || p === w.Microtask || p === w.AnimationFrame;
691
964
  }
692
- function E(a) {
693
- return typeof a == "object" && a !== null && "segs" in a && a.segs !== void 0 && Array.isArray(a.segs);
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();
694
973
  }
695
- function I(a) {
696
- return a === d.Sync || a === d.Microtask || a === d.AnimationFrame;
974
+ function C(p) {
975
+ return p instanceof Error ? p.message : String(p);
697
976
  }
698
977
  export {
699
- P as RaphRuntime
978
+ S as RaphRuntime
700
979
  };