@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
@@ -0,0 +1,995 @@
1
+ var $ = Object.defineProperty;
2
+ var U = (u, e, t) => e in u ? $(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
3
+ var d = (u, e, t) => U(u, typeof e != "symbol" ? e + "" : e, t);
4
+ import { RaphDisposedError as A, RaphCrossRuntimeError as H } from "../errors.js";
5
+ import { throwDisposalErrors as v } from "../ownership/throwDisposalErrors.js";
6
+ const G = Symbol("RaphProducerRecord"), m = /* @__PURE__ */ new WeakMap(), M = Object.freeze([]), C = Object.freeze([]);
7
+ class b {
8
+ /** @internal */
9
+ constructor(e, t) {
10
+ d(this, "_sources");
11
+ d(this, "_disposed", !1);
12
+ d(this, "_releaseOwner");
13
+ d(this, "_memberReleases");
14
+ d(this, "_firstSubscription");
15
+ d(this, "_lastSubscription");
16
+ d(this, "_firstDependent");
17
+ d(this, "_lastDependent");
18
+ d(this, "_revision", 0);
19
+ d(this, "_finalCause");
20
+ this.owner = e, this._sources = F(t);
21
+ }
22
+ /** @internal */
23
+ static _create(e, t) {
24
+ return new b(e, t);
25
+ }
26
+ get runtime() {
27
+ return this.owner.runtime;
28
+ }
29
+ get disposed() {
30
+ return this._disposed;
31
+ }
32
+ get sources() {
33
+ return this._sources;
34
+ }
35
+ dispose() {
36
+ if (this._disposed)
37
+ return;
38
+ const e = this.runtime, t = !e._ownerDisposalActive();
39
+ t && e._beginOwnerDisposal();
40
+ const s = [];
41
+ try {
42
+ const i = this._releaseOwner;
43
+ i !== void 0 ? (this._releaseOwner = void 0, i()) : this._disposeOwned();
44
+ } catch (i) {
45
+ s.push(i);
46
+ } finally {
47
+ if (t)
48
+ try {
49
+ e._endOwnerDisposal();
50
+ } catch (i) {
51
+ s.push(i);
52
+ }
53
+ }
54
+ v(s, "[Raph] Aggregate disposal failed.");
55
+ }
56
+ /** @internal */
57
+ _assertAlive() {
58
+ if (this._disposed || this.owner.disposed)
59
+ throw new A("[Raph] Aggregate is disposed.");
60
+ }
61
+ /** @internal */
62
+ _bindOwner(e) {
63
+ this._releaseOwner = e;
64
+ }
65
+ /** @internal */
66
+ _bindMembers(e) {
67
+ this._memberReleases = e.length === 0 ? void 0 : e;
68
+ }
69
+ /** @internal */
70
+ _removeMember(e) {
71
+ if (this._disposed)
72
+ return;
73
+ const t = this._sources.filter((s) => L(s) !== e);
74
+ t.length !== this._sources.length && (this._sources = t.length === 0 ? M : Object.freeze(t));
75
+ }
76
+ /** @internal */
77
+ _disposeOwned() {
78
+ if (this._disposed)
79
+ return;
80
+ this._disposed = !0, this._releaseOwner = void 0;
81
+ const e = f(this.owner) && !this.owner._isPublished() ? void 0 : this._disposalCause(), t = [];
82
+ let s = this._firstSubscription;
83
+ for (this._firstSubscription = this._lastSubscription = void 0; s !== void 0; ) {
84
+ const o = s.next, r = s.dispose;
85
+ s.aggregate = void 0, s.dispose = void 0, s.previous = s.next = void 0;
86
+ try {
87
+ r == null || r(e);
88
+ } catch (c) {
89
+ t.push(c);
90
+ }
91
+ s = o;
92
+ }
93
+ const i = this._memberReleases;
94
+ if (this._memberReleases = void 0, i !== void 0)
95
+ for (let o = i.length - 1; o >= 0; o--)
96
+ try {
97
+ i[o]();
98
+ } catch (r) {
99
+ t.push(r);
100
+ }
101
+ this._sources = M;
102
+ let n = this._firstDependent;
103
+ for (this._firstDependent = this._lastDependent = void 0; n !== void 0; ) {
104
+ const o = n.next, r = n.cleanup;
105
+ n.source = void 0, n.cleanup = void 0, n.previous = n.next = void 0;
106
+ try {
107
+ r == null || r();
108
+ } catch (c) {
109
+ t.push(c);
110
+ }
111
+ n = o;
112
+ }
113
+ v(t, "[Raph] Aggregate owned cleanup failed.");
114
+ }
115
+ /** @internal */
116
+ _linkSubscription(e) {
117
+ this._assertAlive();
118
+ const t = {
119
+ aggregate: this,
120
+ dispose: e,
121
+ previous: this._lastSubscription
122
+ };
123
+ return this._lastSubscription === void 0 ? this._firstSubscription = t : this._lastSubscription.next = t, this._lastSubscription = t, () => Y(t);
124
+ }
125
+ /** @internal */
126
+ _linkDependent(e) {
127
+ e.previous = this._lastDependent, this._lastDependent === void 0 ? this._firstDependent = e : this._lastDependent.next = e, this._lastDependent = e;
128
+ }
129
+ /** @internal */
130
+ _detachDependent(e) {
131
+ e.previous === void 0 ? this._firstDependent = e.next : e.previous.next = e.next, e.next === void 0 ? this._lastDependent = e.previous : e.next.previous = e.previous, e.previous = e.next = void 0;
132
+ }
133
+ /** @internal */
134
+ _disposalCause() {
135
+ return this._finalCause ?? (this._finalCause = Object.freeze({
136
+ kind: "structure",
137
+ source: this,
138
+ sourceOwner: this.owner,
139
+ revision: ++this._revision,
140
+ metadata: Object.freeze({ disposed: !0 })
141
+ }));
142
+ }
143
+ /** @internal */
144
+ _detachSubscription(e) {
145
+ if (e.aggregate === void 0)
146
+ return;
147
+ const t = e.dispose;
148
+ e.aggregate = void 0, e.dispose = void 0, e.previous === void 0 ? this._firstSubscription = e.next : e.previous.next = e.next, e.next === void 0 ? this._lastSubscription = e.previous : e.next.previous = e.previous, e.previous = e.next = void 0, t == null || t();
149
+ }
150
+ }
151
+ class V {
152
+ constructor(e) {
153
+ d(this, "_selfSubscribers");
154
+ d(this, "_subtreeSubscribers");
155
+ d(this, "_runtimeSubscribers");
156
+ d(this, "_runtimeSubscriberCount", 0);
157
+ d(this, "_runtimeActivationProducers");
158
+ d(this, "_nodeMemberships");
159
+ d(this, "_nodeRevisions");
160
+ d(this, "_nodeTouchKeys");
161
+ d(this, "_implicitProducers");
162
+ d(this, "_transientProducers");
163
+ d(this, "_dispatchDepth", 0);
164
+ d(this, "_detachedEdges");
165
+ d(this, "_disposed", !1);
166
+ this._runtime = e;
167
+ }
168
+ createProducer(e, t = "producer", s = {}) {
169
+ return this._assertAlive(), {
170
+ [G]: !0,
171
+ runtime: this._runtime,
172
+ owner: e,
173
+ kind: t,
174
+ includeRuntime: s.includeRuntime ?? !0,
175
+ revision: 0,
176
+ disposed: !1
177
+ };
178
+ }
179
+ attachProducer(e, t) {
180
+ return e.alias !== void 0 && m.delete(e.alias), e.source = t, e.alias = t, m.set(t, e), t;
181
+ }
182
+ setProducerActivation(e, t, s = !1) {
183
+ if (e.disposed)
184
+ throw new A("[Raph] Producer is disposed.");
185
+ if (e.activate = t, !s)
186
+ return;
187
+ const i = this._runtimeActivationProducers ?? (this._runtimeActivationProducers = /* @__PURE__ */ new Set());
188
+ if (i.add(e), this._runtimeSubscriberCount !== 0)
189
+ try {
190
+ e.runtimeActivation = D(t());
191
+ } catch (n) {
192
+ throw i.delete(e), i.size === 0 && (this._runtimeActivationProducers = void 0), n;
193
+ }
194
+ }
195
+ producerHooks(e) {
196
+ return {
197
+ token: e,
198
+ dependencyOwner: e.owner,
199
+ onDependency: (t) => this._linkImplicitDependency(e, t),
200
+ onChange: (t, s, i) => {
201
+ this.notifyProducer(e, t, s, void 0, !0, i, !0);
202
+ },
203
+ onInvalidate: (t) => this.notifyProducer(
204
+ e,
205
+ void 0,
206
+ void 0,
207
+ void 0,
208
+ !0,
209
+ t,
210
+ !1
211
+ ),
212
+ onDispose: (t) => this._disposeProducer(e, t)
213
+ };
214
+ }
215
+ causeForToken(e) {
216
+ if (!(!E(e) || e.runtime !== this._runtime))
217
+ return e.lastCause;
218
+ }
219
+ /** Clears mutation-local payloads after engine propagation consumed them. */
220
+ clearTransientCauses() {
221
+ let e = this._transientProducers;
222
+ for (this._transientProducers = void 0; e !== void 0; ) {
223
+ const t = e.transientNext;
224
+ e.transientNext = void 0, e.lastCause = void 0, e = t;
225
+ }
226
+ }
227
+ notifyProducer(e, t, s, i, n = !0, o = !1, r = !1) {
228
+ var a, h;
229
+ if (this._disposed || e.disposed || e.source === void 0 || f(e.owner) && !e.owner._isPublished() || !r && i === void 0 && e.lastCause !== void 0)
230
+ return;
231
+ if (!o && ((a = e.subscribers) == null ? void 0 : a.first) === void 0 && (!e.includeRuntime || ((h = this._runtimeSubscribers) == null ? void 0 : h.first) === void 0)) {
232
+ this._dispatchProducerLazily(e, t, s, i, n, r);
233
+ return;
234
+ }
235
+ const c = Object.freeze({
236
+ kind: e.kind,
237
+ source: e.source,
238
+ sourceOwner: e.owner,
239
+ revision: ++e.revision,
240
+ ...r ? { previous: t, value: s } : {},
241
+ ...i === void 0 ? {} : { events: Object.freeze([...i]) }
242
+ });
243
+ this._setTransientCause(e, c), this._dispatchProducer(e, c, n);
244
+ }
245
+ notifyProducerEvents(e, t, s = !0, i = !1) {
246
+ var o, r;
247
+ if (this._disposed || e.disposed || e.source === void 0 || f(e.owner) && !e.owner._isPublished())
248
+ return;
249
+ if (!i && ((o = e.subscribers) == null ? void 0 : o.first) === void 0 && (!e.includeRuntime || ((r = this._runtimeSubscribers) == null ? void 0 : r.first) === void 0)) {
250
+ this._dispatchProducerLazily(e, void 0, void 0, t, s, !1);
251
+ return;
252
+ }
253
+ const n = Object.freeze({
254
+ kind: e.kind,
255
+ source: e.source,
256
+ sourceOwner: e.owner,
257
+ revision: ++e.revision,
258
+ events: Object.freeze([...t])
259
+ });
260
+ this._setTransientCause(e, n), this._dispatchProducer(e, n, s);
261
+ }
262
+ notifyNode(e, t, s = {}) {
263
+ var l, _, p, O, g, z;
264
+ if (this._disposed || !e._isPublished() || ((l = this._runtimeSubscribers) == null ? void 0 : l.first) === void 0 && ((p = (_ = this._selfSubscribers) == null ? void 0 : _.get(e)) == null ? void 0 : p.first) === void 0 && this._subtreeSubscribers === void 0)
265
+ return;
266
+ const i = s.oldAncestors === void 0 && s.newAncestors === void 0 ? this._subtreeSubscribers === void 0 ? C : k(e) : void 0, n = s.oldAncestors ?? i ?? C, o = s.newAncestors ?? i ?? C;
267
+ if (!this._nodeHasDemand(e, n, o))
268
+ return;
269
+ const r = this._nodeRevisions ?? (this._nodeRevisions = /* @__PURE__ */ new WeakMap()), c = (r.get(e) ?? 0) + 1;
270
+ r.set(e, c);
271
+ const a = Object.freeze({
272
+ kind: t,
273
+ source: e,
274
+ sourceOwner: e,
275
+ revision: c,
276
+ ...s.metadata === void 0 ? {} : { metadata: s.metadata },
277
+ ...s.structure === void 0 ? {} : { structure: Object.freeze({ ...s.structure }) }
278
+ }), h = t === "structure" ? e : this._nodeTouchKey(e);
279
+ if (this._dispatch((O = this._selfSubscribers) == null ? void 0 : O.get(e), a, h), i !== void 0)
280
+ for (const R of i)
281
+ this._dispatch((g = this._subtreeSubscribers) == null ? void 0 : g.get(R), a, h);
282
+ else {
283
+ const R = /* @__PURE__ */ new Set();
284
+ for (const y of n)
285
+ R.add(y);
286
+ for (const y of o)
287
+ R.add(y);
288
+ for (const y of R)
289
+ this._dispatch((z = this._subtreeSubscribers) == null ? void 0 : z.get(y), a, h);
290
+ }
291
+ this._dispatch(this._runtimeSubscribers, a, h);
292
+ }
293
+ createAggregate(e, t) {
294
+ if (this._assertOwner(e), t.length === 0)
295
+ throw new TypeError("[Raph] Aggregate requires at least one source.");
296
+ this._validateAggregateSources(t, /* @__PURE__ */ new Set());
297
+ for (const o of t)
298
+ this._assertSourceVisibleTo(e, o, /* @__PURE__ */ new Set());
299
+ const s = b._create(e, t), i = [], n = /* @__PURE__ */ new Set();
300
+ try {
301
+ for (const o of s.sources) {
302
+ const r = L(o);
303
+ if (r === void 0 || n.has(r))
304
+ continue;
305
+ n.add(r);
306
+ const c = this._linkSourceCleanup(o, () => s._removeMember(r));
307
+ c !== void 0 && i.push(c);
308
+ }
309
+ return s._bindMembers(i), s._bindOwner(e._adoptResource(() => s._disposeOwned())), s;
310
+ } catch (o) {
311
+ const r = [];
312
+ for (let c = i.length - 1; c >= 0; c--)
313
+ try {
314
+ i[c]();
315
+ } catch (a) {
316
+ r.push(a);
317
+ }
318
+ throw r.length !== 0 ? new AggregateError(
319
+ [o, ...r],
320
+ "[Raph] Aggregate registration and rollback failed."
321
+ ) : o;
322
+ }
323
+ }
324
+ subscribe(e, t, s) {
325
+ this._assertAlive();
326
+ const i = [], n = /* @__PURE__ */ new WeakMap();
327
+ try {
328
+ this._subscribeOne(e, t, s, i, n, /* @__PURE__ */ new Set());
329
+ } catch (r) {
330
+ const c = [];
331
+ for (let a = i.length - 1; a >= 0; a--)
332
+ try {
333
+ i[a]();
334
+ } catch (h) {
335
+ c.push(h);
336
+ }
337
+ throw c.length !== 0 ? new AggregateError(
338
+ [r, ...c],
339
+ "[Raph] Granular subscription registration and rollback failed."
340
+ ) : r;
341
+ }
342
+ let o = !0;
343
+ return () => {
344
+ if (!o)
345
+ return;
346
+ o = !1;
347
+ const r = [];
348
+ for (let c = i.length - 1; c >= 0; c--)
349
+ try {
350
+ i[c]();
351
+ } catch (a) {
352
+ r.push(a);
353
+ }
354
+ v(r, "[Raph] Granular subscription disposal failed.");
355
+ };
356
+ }
357
+ assertSubscriptionAllowed(e, t) {
358
+ this._assertOwner(e), this._assertSourceVisibleTo(e, t, /* @__PURE__ */ new Set());
359
+ }
360
+ /** Rejects a move that would make an existing implicit reactive edge illegal. */
361
+ assertReparentAllowed(e, t) {
362
+ const s = this._implicitProducers;
363
+ if (s !== void 0)
364
+ for (const i of s) {
365
+ const n = i.owner;
366
+ if (!f(n))
367
+ continue;
368
+ const o = i.implicitConsumers;
369
+ if (o !== void 0) {
370
+ for (const r of o.keys())
371
+ if (j(r, e) && !j(n, e) && !K(n, t))
372
+ throw new Error(
373
+ `[Raph] Cannot reparent "${e.id}": implicit dependency from "${r.id}" to "${n.id}" would become invalid; use watch().`
374
+ );
375
+ }
376
+ }
377
+ }
378
+ releaseNode(e) {
379
+ var s, i;
380
+ this._releaseGranule(this._selfSubscribers, e), this._releaseGranule(this._subtreeSubscribers, e);
381
+ const t = (s = this._nodeMemberships) == null ? void 0 : s.get(e);
382
+ if (t !== void 0) {
383
+ this._nodeMemberships.delete(e);
384
+ try {
385
+ this._releaseCleanupList(t);
386
+ } finally {
387
+ ((i = this._nodeMemberships) == null ? void 0 : i.size) === 0 && (this._nodeMemberships = void 0);
388
+ }
389
+ }
390
+ }
391
+ dispose() {
392
+ var t;
393
+ if (this._disposed)
394
+ return;
395
+ this._disposed = !0;
396
+ const e = [];
397
+ if (this.clearTransientCauses(), this._implicitProducers !== void 0) {
398
+ for (const s of this._implicitProducers)
399
+ s.implicitConsumers = void 0;
400
+ this._implicitProducers.clear(), this._implicitProducers = void 0;
401
+ }
402
+ try {
403
+ this._releaseRuntimeActivations();
404
+ } catch (s) {
405
+ e.push(s);
406
+ }
407
+ if ((t = this._runtimeActivationProducers) == null || t.clear(), this._runtimeActivationProducers = void 0, this._runtimeSubscriberCount = 0, this._selfSubscribers !== void 0)
408
+ for (const s of [...this._selfSubscribers.keys()])
409
+ this._releaseGranule(this._selfSubscribers, s);
410
+ if (this._subtreeSubscribers !== void 0)
411
+ for (const s of [...this._subtreeSubscribers.keys()])
412
+ this._releaseGranule(this._subtreeSubscribers, s);
413
+ if (this._nodeMemberships !== void 0) {
414
+ for (const s of this._nodeMemberships.values())
415
+ this._releaseCleanupList(s, !1);
416
+ this._nodeMemberships.clear(), this._nodeMemberships = void 0;
417
+ }
418
+ if (this._runtimeSubscribers !== void 0) {
419
+ try {
420
+ this._releaseWorkList(this._runtimeSubscribers);
421
+ } catch (s) {
422
+ e.push(s);
423
+ }
424
+ this._runtimeSubscribers = void 0;
425
+ }
426
+ v(e, "[Raph] Work graph disposal failed.");
427
+ }
428
+ _disposeProducer(e, t = !1) {
429
+ var r, c;
430
+ if (e.disposed)
431
+ return;
432
+ const s = e.source, i = !f(e.owner) || e.owner._isPublished();
433
+ let n;
434
+ if (s !== void 0 && i && (t || this._producerHasDemand(e))) {
435
+ const a = Object.freeze({
436
+ kind: "structure",
437
+ source: s,
438
+ sourceOwner: e.owner,
439
+ revision: ++e.revision,
440
+ metadata: Object.freeze({ disposed: !0 })
441
+ });
442
+ this._setTransientCause(e, a);
443
+ try {
444
+ this._dispatchProducer(e, a, !0, s);
445
+ } catch (h) {
446
+ (n ?? (n = [])).push(h);
447
+ }
448
+ }
449
+ e.disposed = !0;
450
+ const o = e.runtimeActivation;
451
+ e.runtimeActivation = void 0, (r = this._runtimeActivationProducers) == null || r.delete(e), ((c = this._runtimeActivationProducers) == null ? void 0 : c.size) === 0 && (this._runtimeActivationProducers = void 0);
452
+ try {
453
+ o == null || o();
454
+ } catch (a) {
455
+ (n ?? (n = [])).push(a);
456
+ }
457
+ if (e.memberships !== void 0) {
458
+ try {
459
+ this._releaseCleanupList(e.memberships);
460
+ } catch (a) {
461
+ (n ?? (n = [])).push(a);
462
+ }
463
+ e.memberships = void 0;
464
+ }
465
+ if (e.alias !== void 0 && m.delete(e.alias), e.alias = void 0, e.subscribers !== void 0)
466
+ try {
467
+ this._releaseWorkList(e.subscribers);
468
+ } catch (a) {
469
+ (n ?? (n = [])).push(a);
470
+ } finally {
471
+ e.subscribers = void 0;
472
+ }
473
+ e.activate = void 0, e.source = void 0, n !== void 0 && v(n, "[Raph] Runtime producer disposal failed.");
474
+ }
475
+ _dispatchProducer(e, t, s = !0, i = e) {
476
+ var o, r;
477
+ this._dispatch(e.subscribers, t, i, s);
478
+ const n = e.owner;
479
+ if (f(n)) {
480
+ this._dispatch((o = this._selfSubscribers) == null ? void 0 : o.get(n), t, i, s);
481
+ for (const c of k(n))
482
+ this._dispatch((r = this._subtreeSubscribers) == null ? void 0 : r.get(c), t, i, s);
483
+ }
484
+ e.includeRuntime && this._dispatch(this._runtimeSubscribers, t, i, s);
485
+ }
486
+ _dispatchProducerLazily(e, t, s, i, n, o) {
487
+ var h;
488
+ const r = e.owner;
489
+ let c;
490
+ if (f(r)) {
491
+ const l = (h = this._selfSubscribers) == null ? void 0 : h.get(r);
492
+ (l == null ? void 0 : l.first) !== void 0 && (c = this._createProducerCause(e, t, s, i, o), this._dispatch(l, c, e, n));
493
+ const _ = this._subtreeSubscribers;
494
+ if (_ !== void 0)
495
+ for (let p = r; p !== null; ) {
496
+ const O = p.parent, g = _.get(p);
497
+ (g == null ? void 0 : g.first) !== void 0 && (c ?? (c = this._createProducerCause(e, t, s, i, o)), this._dispatch(g, c, e, n)), p = O;
498
+ }
499
+ }
500
+ const a = e.includeRuntime ? this._runtimeSubscribers : void 0;
501
+ (a == null ? void 0 : a.first) !== void 0 && (c ?? (c = this._createProducerCause(e, t, s, i, o)), this._dispatch(a, c, e, n));
502
+ }
503
+ _createProducerCause(e, t, s, i, n) {
504
+ const o = ++e.revision, r = Object.freeze(n ? i === void 0 ? {
505
+ kind: e.kind,
506
+ source: e.source,
507
+ sourceOwner: e.owner,
508
+ revision: o,
509
+ previous: t,
510
+ value: s
511
+ } : {
512
+ kind: e.kind,
513
+ source: e.source,
514
+ sourceOwner: e.owner,
515
+ revision: o,
516
+ previous: t,
517
+ value: s,
518
+ events: Object.freeze([...i])
519
+ } : i === void 0 ? {
520
+ kind: e.kind,
521
+ source: e.source,
522
+ sourceOwner: e.owner,
523
+ revision: o
524
+ } : {
525
+ kind: e.kind,
526
+ source: e.source,
527
+ sourceOwner: e.owner,
528
+ revision: o,
529
+ events: Object.freeze([...i])
530
+ });
531
+ return this._setTransientCause(e, r), r;
532
+ }
533
+ _retainRuntimeSubscriber() {
534
+ var s;
535
+ if (this._runtimeSubscriberCount++, this._runtimeSubscriberCount !== 1)
536
+ return;
537
+ const e = [], t = [];
538
+ try {
539
+ for (const i of this._runtimeActivationProducers ?? [])
540
+ i.disposed || i.runtimeActivation !== void 0 || (i.runtimeActivation = D((s = i.activate) == null ? void 0 : s.call(i)), e.push(i));
541
+ return;
542
+ } catch (i) {
543
+ t.push(i);
544
+ }
545
+ this._runtimeSubscriberCount = 0;
546
+ for (let i = e.length - 1; i >= 0; i--) {
547
+ const n = e[i], o = n.runtimeActivation;
548
+ n.runtimeActivation = void 0;
549
+ try {
550
+ o == null || o();
551
+ } catch (r) {
552
+ t.push(r);
553
+ }
554
+ }
555
+ throw t.length === 1 ? t[0] : new AggregateError(t, "[Raph] Runtime granule activation failed and rollback was incomplete.");
556
+ }
557
+ _releaseRuntimeSubscriber() {
558
+ this._runtimeSubscriberCount !== 0 && (this._runtimeSubscriberCount--, this._runtimeSubscriberCount === 0 && this._releaseRuntimeActivations());
559
+ }
560
+ _releaseRuntimeActivations() {
561
+ const e = [];
562
+ for (const t of this._runtimeActivationProducers ?? []) {
563
+ const s = t.runtimeActivation;
564
+ t.runtimeActivation = void 0;
565
+ try {
566
+ s == null || s();
567
+ } catch (i) {
568
+ e.push(i);
569
+ }
570
+ }
571
+ v(e, "[Raph] Runtime granule activation cleanup failed.");
572
+ }
573
+ _linkImplicitDependency(e, t) {
574
+ const s = e.owner, i = t;
575
+ if (e.disposed || i.runtime !== this._runtime || !f(s) || !f(i) || s === i)
576
+ return;
577
+ const n = e.implicitConsumers ?? (e.implicitConsumers = /* @__PURE__ */ new Map());
578
+ n.set(i, (n.get(i) ?? 0) + 1), (this._implicitProducers ?? (this._implicitProducers = /* @__PURE__ */ new Set())).add(e);
579
+ let r = !0;
580
+ return () => {
581
+ var a, h, l;
582
+ if (!r)
583
+ return;
584
+ r = !1;
585
+ const c = (a = e.implicitConsumers) == null ? void 0 : a.get(i);
586
+ if (c !== void 0) {
587
+ if (c > 1) {
588
+ e.implicitConsumers.set(i, c - 1);
589
+ return;
590
+ }
591
+ e.implicitConsumers.delete(i), e.implicitConsumers.size === 0 && (e.implicitConsumers = void 0, (h = this._implicitProducers) == null || h.delete(e), ((l = this._implicitProducers) == null ? void 0 : l.size) === 0 && (this._implicitProducers = void 0));
592
+ }
593
+ };
594
+ }
595
+ _subscribeOne(e, t, s, i, n, o) {
596
+ if (t !== void 0 && !f(e))
597
+ throw new TypeError("[Raph] watch include applies only to a bare RaphNode source.");
598
+ if (e instanceof b) {
599
+ if (e._assertAlive(), this._assertRuntime(e.runtime), o.has(e))
600
+ throw new TypeError("[Raph] Aggregate sources cannot contain a cycle.");
601
+ o.add(e);
602
+ const r = [];
603
+ try {
604
+ for (const c of e.sources)
605
+ this._subscribeOne(c, void 0, s, r, n, o);
606
+ i.push(e._linkSubscription((c) => {
607
+ const a = [];
608
+ if (c !== void 0)
609
+ try {
610
+ s(c, e, !0);
611
+ } catch (h) {
612
+ a.push(h);
613
+ }
614
+ for (let h = r.length - 1; h >= 0; h--)
615
+ try {
616
+ r[h]();
617
+ } catch (l) {
618
+ a.push(l);
619
+ }
620
+ v(a, "[Raph] Aggregate member subscription disposal failed.");
621
+ }));
622
+ } catch (c) {
623
+ const a = [];
624
+ for (let h = r.length - 1; h >= 0; h--)
625
+ try {
626
+ r[h]();
627
+ } catch (l) {
628
+ a.push(l);
629
+ }
630
+ throw o.delete(e), a.length !== 0 ? new AggregateError(
631
+ [c, ...a],
632
+ "[Raph] Aggregate subscription registration and rollback failed."
633
+ ) : c;
634
+ }
635
+ o.delete(e);
636
+ return;
637
+ }
638
+ if (S(e)) {
639
+ this._subscribeNode(e.source, e.include, s, i, n);
640
+ return;
641
+ }
642
+ if (f(e)) {
643
+ this._subscribeNode(e, t ?? "self", s, i, n);
644
+ return;
645
+ }
646
+ if (P(e)) {
647
+ this._assertRuntime(e), i.push(x(n, e, () => {
648
+ const r = this._runtimeSubscribers ?? (this._runtimeSubscribers = {}), c = { kind: "runtime", sink: s, source: e };
649
+ this._appendWorkEdge(r, c);
650
+ try {
651
+ this._retainRuntimeSubscriber();
652
+ } catch (a) {
653
+ throw c.source = void 0, this._detachWorkEdge(r, c), r.first === void 0 && (this._runtimeSubscribers = void 0), a;
654
+ }
655
+ return () => {
656
+ var a;
657
+ c.source !== void 0 && (c.source = void 0, this._detachWorkEdge(this._runtimeSubscribers, c), ((a = this._runtimeSubscribers) == null ? void 0 : a.first) === void 0 && (this._runtimeSubscribers = void 0), this._releaseRuntimeSubscriber());
658
+ };
659
+ }));
660
+ return;
661
+ }
662
+ if (w(e)) {
663
+ const r = m.get(e);
664
+ if (r !== void 0) {
665
+ if (this._assertRuntime(r.runtime), r.disposed)
666
+ throw new A("[Raph] Producer is disposed.");
667
+ i.push(x(n, r, () => {
668
+ var h;
669
+ const c = r.subscribers ?? (r.subscribers = {}), a = { kind: "producer", sink: s, source: r };
670
+ this._appendWorkEdge(c, a);
671
+ try {
672
+ a.activationRelease = D((h = r.activate) == null ? void 0 : h.call(r));
673
+ } catch (l) {
674
+ throw a.source = void 0, this._detachWorkEdge(c, a), c.first === void 0 && (r.subscribers = void 0), l;
675
+ }
676
+ return () => {
677
+ var p;
678
+ const l = a.activationRelease;
679
+ a.activationRelease = void 0;
680
+ const _ = a.source;
681
+ E(_) && (a.source = void 0, this._detachWorkEdge(_.subscribers, a), ((p = _.subscribers) == null ? void 0 : p.first) === void 0 && (_.subscribers = void 0)), l == null || l();
682
+ };
683
+ }));
684
+ return;
685
+ }
686
+ }
687
+ throw new TypeError("[Raph] Unsupported or ownerless granular watch source.");
688
+ }
689
+ _subscribeNode(e, t, s, i, n) {
690
+ if (this._assertRuntime(e.runtime), e._assertAlive(), t !== "self" && t !== "subtree")
691
+ throw new TypeError(`[Raph] Unsupported node include mode "${String(t)}".`);
692
+ const o = t === "self" ? e : e._subtreeSourceIdentity;
693
+ i.push(x(n, o, () => {
694
+ const r = t === "self" ? this._selfSubscribers ?? (this._selfSubscribers = /* @__PURE__ */ new Map()) : this._subtreeSubscribers ?? (this._subtreeSubscribers = /* @__PURE__ */ new Map());
695
+ let c = r.get(e);
696
+ c === void 0 && (c = {}, r.set(e, c));
697
+ const a = { kind: t, sink: s, source: e };
698
+ return this._appendWorkEdge(c, a), this._createNodeEdgeRelease(a);
699
+ }));
700
+ }
701
+ _createNodeEdgeRelease(e) {
702
+ return () => {
703
+ const t = e.source;
704
+ if (!f(t))
705
+ return;
706
+ e.source = void 0;
707
+ const s = e.kind === "self" ? this._selfSubscribers : this._subtreeSubscribers, i = s == null ? void 0 : s.get(t);
708
+ this._detachWorkEdge(i, e), (i == null ? void 0 : i.first) === void 0 && (s == null || s.delete(t), (s == null ? void 0 : s.size) === 0 && (e.kind === "self" ? this._selfSubscribers = void 0 : this._subtreeSubscribers = void 0));
709
+ };
710
+ }
711
+ _linkSourceCleanup(e, t) {
712
+ const s = I(e);
713
+ if (s === void 0)
714
+ return;
715
+ const i = { cleanup: t, source: s };
716
+ if (E(s)) {
717
+ const n = s.memberships ?? (s.memberships = {});
718
+ W(n, i);
719
+ } else if (s instanceof b)
720
+ s._linkDependent(i);
721
+ else {
722
+ const n = this._nodeMemberships ?? (this._nodeMemberships = /* @__PURE__ */ new Map());
723
+ let o = n.get(s);
724
+ o === void 0 && (o = {}, n.set(s, o)), W(o, i);
725
+ }
726
+ return () => this._detachCleanupEdge(i);
727
+ }
728
+ _detachCleanupEdge(e) {
729
+ var i, n, o, r;
730
+ const t = e.source;
731
+ if (t === void 0)
732
+ return;
733
+ if (e.source = void 0, e.cleanup = void 0, E(t)) {
734
+ N(t.memberships, e), ((i = t.memberships) == null ? void 0 : i.first) === void 0 && (t.memberships = void 0);
735
+ return;
736
+ }
737
+ if (t instanceof b) {
738
+ t._detachDependent(e);
739
+ return;
740
+ }
741
+ const s = (n = this._nodeMemberships) == null ? void 0 : n.get(t);
742
+ N(s, e), (s == null ? void 0 : s.first) === void 0 && ((o = this._nodeMemberships) == null || o.delete(t), ((r = this._nodeMemberships) == null ? void 0 : r.size) === 0 && (this._nodeMemberships = void 0));
743
+ }
744
+ _releaseCleanupList(e, t = !0) {
745
+ let s = e.first;
746
+ e.first = e.last = void 0;
747
+ const i = [];
748
+ for (; s !== void 0; ) {
749
+ const n = s.next, o = s.cleanup;
750
+ if (s.source = void 0, s.cleanup = void 0, s.previous = s.next = void 0, t)
751
+ try {
752
+ o == null || o();
753
+ } catch (r) {
754
+ i.push(r);
755
+ }
756
+ s = n;
757
+ }
758
+ v(i, "[Raph] Aggregate membership cleanup failed.");
759
+ }
760
+ _validateAggregateSources(e, t) {
761
+ for (const s of e) {
762
+ if (Array.isArray(s))
763
+ throw new TypeError("[Raph] Nested source arrays are not supported; create a named aggregate.");
764
+ if (s instanceof b) {
765
+ if (s._assertAlive(), this._assertRuntime(s.runtime), t.has(s))
766
+ throw new TypeError("[Raph] Aggregate sources cannot contain a cycle.");
767
+ t.add(s), this._validateAggregateSources(s.sources, t), t.delete(s);
768
+ } else if (S(s)) {
769
+ if (this._assertRuntime(s.source.runtime), s.source._assertAlive(), s.include !== "self" && s.include !== "subtree")
770
+ throw new TypeError(`[Raph] Unsupported node include mode "${String(s.include)}".`);
771
+ } else if (f(s))
772
+ this._assertRuntime(s.runtime), s._assertAlive();
773
+ else if (P(s))
774
+ this._assertRuntime(s);
775
+ else if (w(s)) {
776
+ const i = m.get(s);
777
+ if (i === void 0 || i.disposed)
778
+ throw new A("[Raph] Aggregate producer is disposed or ownerless.");
779
+ this._assertRuntime(i.runtime);
780
+ } else
781
+ throw new TypeError("[Raph] Unsupported aggregate source.");
782
+ }
783
+ }
784
+ _assertSourceVisibleTo(e, t, s) {
785
+ if (t instanceof b) {
786
+ if (this._assertProvisionalOwnerAccess(e, t.owner), s.has(t))
787
+ return;
788
+ s.add(t);
789
+ for (const n of t.sources)
790
+ this._assertSourceVisibleTo(e, n, s);
791
+ s.delete(t);
792
+ return;
793
+ }
794
+ if (S(t)) {
795
+ this._assertProvisionalOwnerAccess(e, t.source);
796
+ return;
797
+ }
798
+ if (f(t)) {
799
+ this._assertProvisionalOwnerAccess(e, t);
800
+ return;
801
+ }
802
+ if (P(t) || !w(t))
803
+ return;
804
+ const i = m.get(t);
805
+ i !== void 0 && this._assertProvisionalOwnerAccess(e, i.owner);
806
+ }
807
+ _assertProvisionalOwnerAccess(e, t) {
808
+ if (!(!f(t) || t._isPublished()) && !(f(e) && !e._isPublished() && T(e) === T(t)))
809
+ throw new Error(
810
+ `[Raph] Owner "${e.id}" cannot subscribe to provisional source owner "${t.id}".`
811
+ );
812
+ }
813
+ _dispatch(e, t, s, i = !0) {
814
+ let n = e == null ? void 0 : e.first;
815
+ if (n === void 0)
816
+ return;
817
+ const o = e.last;
818
+ this._dispatchDepth++;
819
+ try {
820
+ for (; n !== void 0; ) {
821
+ const r = n.next;
822
+ if (n.source !== void 0 && n.sink(t, s, i), n === o)
823
+ break;
824
+ n = r;
825
+ }
826
+ } finally {
827
+ if (--this._dispatchDepth === 0 && this._detachedEdges !== void 0) {
828
+ for (const r of this._detachedEdges)
829
+ r.previous = r.next = void 0;
830
+ this._detachedEdges = void 0;
831
+ }
832
+ }
833
+ }
834
+ _appendWorkEdge(e, t) {
835
+ t.previous = e.last, e.last === void 0 ? e.first = t : e.last.next = t, e.last = t;
836
+ }
837
+ _detachWorkEdge(e, t) {
838
+ e !== void 0 && (t.previous === void 0 ? e.first = t.next : t.previous.next = t.next, t.next === void 0 ? e.last = t.previous : t.next.previous = t.previous, this._dispatchDepth === 0 ? t.previous = t.next = void 0 : (this._detachedEdges ?? (this._detachedEdges = [])).push(t));
839
+ }
840
+ _releaseWorkList(e) {
841
+ let t = e.first;
842
+ const s = [];
843
+ for (; t !== void 0; ) {
844
+ const i = t.next, n = t.activationRelease;
845
+ t.activationRelease = void 0, t.source = void 0, this._detachWorkEdge(e, t);
846
+ try {
847
+ n == null || n();
848
+ } catch (o) {
849
+ s.push(o);
850
+ }
851
+ t = i;
852
+ }
853
+ v(s, "[Raph] Granular source activation cleanup failed.");
854
+ }
855
+ _releaseGranule(e, t) {
856
+ const s = e == null ? void 0 : e.get(t);
857
+ s !== void 0 && (e.delete(t), this._releaseWorkList(s), e.size === 0 && (e === this._selfSubscribers && (this._selfSubscribers = void 0), e === this._subtreeSubscribers && (this._subtreeSubscribers = void 0)));
858
+ }
859
+ _setTransientCause(e, t) {
860
+ e.lastCause === void 0 && (e.transientNext = this._transientProducers, this._transientProducers = e), e.lastCause = t;
861
+ }
862
+ _producerHasDemand(e) {
863
+ var s, i, n, o, r;
864
+ if (f(e.owner) && !e.owner._isPublished())
865
+ return !1;
866
+ if (((s = e.subscribers) == null ? void 0 : s.first) !== void 0 || e.includeRuntime && ((i = this._runtimeSubscribers) == null ? void 0 : i.first) !== void 0)
867
+ return !0;
868
+ const t = e.owner;
869
+ if (!f(t))
870
+ return !1;
871
+ if (((o = (n = this._selfSubscribers) == null ? void 0 : n.get(t)) == null ? void 0 : o.first) !== void 0)
872
+ return !0;
873
+ if (this._subtreeSubscribers === void 0)
874
+ return !1;
875
+ for (const c of k(t))
876
+ if (((r = this._subtreeSubscribers.get(c)) == null ? void 0 : r.first) !== void 0)
877
+ return !0;
878
+ return !1;
879
+ }
880
+ _nodeTouchKey(e) {
881
+ const t = this._nodeTouchKeys ?? (this._nodeTouchKeys = /* @__PURE__ */ new WeakMap());
882
+ let s = t.get(e);
883
+ return s === void 0 && (s = Object.freeze({}), t.set(e, s)), s;
884
+ }
885
+ _nodeHasDemand(e, t, s) {
886
+ var i, n, o, r, c;
887
+ if (((i = this._runtimeSubscribers) == null ? void 0 : i.first) !== void 0 || ((o = (n = this._selfSubscribers) == null ? void 0 : n.get(e)) == null ? void 0 : o.first) !== void 0)
888
+ return !0;
889
+ if (this._subtreeSubscribers === void 0)
890
+ return !1;
891
+ for (const a of t)
892
+ if (((r = this._subtreeSubscribers.get(a)) == null ? void 0 : r.first) !== void 0)
893
+ return !0;
894
+ for (const a of s)
895
+ if (((c = this._subtreeSubscribers.get(a)) == null ? void 0 : c.first) !== void 0)
896
+ return !0;
897
+ return !1;
898
+ }
899
+ _assertOwner(e) {
900
+ this._assertRuntime(e.runtime), e._assertAlive();
901
+ }
902
+ _assertRuntime(e) {
903
+ if (e !== this._runtime)
904
+ throw new H("[Raph] Granular source belongs to another runtime.");
905
+ }
906
+ _assertAlive() {
907
+ if (this._disposed)
908
+ throw new A("[Raph] Work graph is disposed.");
909
+ }
910
+ }
911
+ function T(u) {
912
+ let e = u;
913
+ for (; e.parent !== null && !e.parent._isPublished(); )
914
+ e = e.parent;
915
+ return e;
916
+ }
917
+ function k(u) {
918
+ const e = [];
919
+ for (let t = u; t !== null; t = t.parent)
920
+ e.push(t);
921
+ return e;
922
+ }
923
+ function j(u, e) {
924
+ for (let t = u; t !== null; t = t.parent)
925
+ if (t === e)
926
+ return !0;
927
+ return !1;
928
+ }
929
+ function K(u, e) {
930
+ for (let t = e; t !== null; t = t.parent)
931
+ if (t === u)
932
+ return !0;
933
+ return !1;
934
+ }
935
+ function F(u) {
936
+ return Object.freeze(u.map((e) => S(e) ? Object.freeze({ source: e.source, include: e.include }) : e));
937
+ }
938
+ function L(u) {
939
+ return u instanceof b ? u : S(u) ? u.source : f(u) || P(u) ? u : w(u) ? m.get(u) : void 0;
940
+ }
941
+ function I(u) {
942
+ if (u instanceof b)
943
+ return u;
944
+ if (S(u))
945
+ return u.source;
946
+ if (f(u))
947
+ return u;
948
+ if (!P(u))
949
+ return w(u) ? m.get(u) : void 0;
950
+ }
951
+ function W(u, e) {
952
+ e.previous = u.last, u.last === void 0 ? u.first = e : u.last.next = e, u.last = e;
953
+ }
954
+ function Y(u) {
955
+ var e;
956
+ (e = u.aggregate) == null || e._detachSubscription(u);
957
+ }
958
+ function N(u, e) {
959
+ u !== void 0 && (e.previous === void 0 ? u.first = e.next : e.previous.next = e.next, e.next === void 0 ? u.last = e.previous : e.next.previous = e.previous, e.previous = e.next = void 0);
960
+ }
961
+ function x(u, e, t) {
962
+ let s = u.get(e);
963
+ s === void 0 && (s = { count: 0, dispose: t() }, u.set(e, s)), s.count++;
964
+ let i = !0;
965
+ return () => {
966
+ if (!i || (i = !1, --s.count !== 0))
967
+ return;
968
+ const n = s.dispose;
969
+ s.dispose = q, n();
970
+ };
971
+ }
972
+ function q() {
973
+ }
974
+ function D(u) {
975
+ return typeof u == "function" ? u : void 0;
976
+ }
977
+ function E(u) {
978
+ return typeof u == "object" && u !== null && u[G] === !0;
979
+ }
980
+ function S(u) {
981
+ return w(u) && "source" in u && f(u.source) && "include" in u;
982
+ }
983
+ function f(u) {
984
+ return w(u) && "_subtreeSourceIdentity" in u && "runtime" in u && "children" in u;
985
+ }
986
+ function P(u) {
987
+ return w(u) && "rootScope" in u && "definePhases" in u && "configuration" in u;
988
+ }
989
+ function w(u) {
990
+ return typeof u == "object" && u !== null;
991
+ }
992
+ export {
993
+ b as RaphAggregate,
994
+ V as RaphWorkGraph
995
+ };