@raphy-js/raph 1.0.0-dev.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE +202 -0
  2. package/dist/api/Raph.d.ts +97 -0
  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 +25 -0
  6. package/dist/api/types.d.ts +170 -0
  7. package/dist/core-CyilRD7s.js +1055 -0
  8. package/dist/core-ugchZNqC.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -0
  10. package/dist/debug/api/Raph.js +421 -0
  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 -0
  16. package/dist/debug/api/errors.js +17 -0
  17. package/dist/debug/api/types.cjs +1 -0
  18. package/dist/debug/api/types.js +1 -0
  19. package/dist/debug/path/DataPath.cjs +1 -0
  20. package/dist/debug/path/DataPath.js +394 -0
  21. package/dist/debug/path/PathRouter.cjs +1 -0
  22. package/dist/debug/path/PathRouter.js +86 -0
  23. package/dist/debug/path/RaphKernel.cjs +1 -0
  24. package/dist/debug/path/RaphKernel.js +687 -0
  25. package/dist/debug/path/data-path.types.cjs +1 -0
  26. package/dist/debug/path/data-path.types.js +1 -0
  27. package/dist/debug/path/data-path.utils.cjs +1 -0
  28. package/dist/debug/path/data-path.utils.js +56 -0
  29. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  30. package/dist/debug/path/derived/DerivedRegistry.js +157 -0
  31. package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
  32. package/dist/debug/path/derived/RaphDerivedHandle.js +125 -0
  33. package/dist/debug/path/derived/derived-collection.types.cjs +1 -0
  34. package/dist/debug/path/derived/derived-collection.types.js +1 -0
  35. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  36. package/dist/debug/path/derived/derived-collection.utils.js +179 -0
  37. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  38. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  39. package/dist/debug/path/derived/derived-strategy.utils.cjs +1 -0
  40. package/dist/debug/path/derived/derived-strategy.utils.js +20 -0
  41. package/dist/debug/path/meta/MetaController.cjs +1 -0
  42. package/dist/debug/path/meta/MetaController.js +214 -0
  43. package/dist/debug/path/meta/RaphMeta.cjs +1 -0
  44. package/dist/debug/path/meta/RaphMeta.js +68 -0
  45. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  46. package/dist/debug/path/meta/RaphMetaStore.js +184 -0
  47. package/dist/debug/path/meta/meta.types.cjs +1 -0
  48. package/dist/debug/path/meta/meta.types.js +1 -0
  49. package/dist/debug/path/path.types.cjs +1 -0
  50. package/dist/debug/path/path.types.js +1 -0
  51. package/dist/debug/path/pathSegmentKey.cjs +1 -0
  52. package/dist/debug/path/pathSegmentKey.js +12 -0
  53. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  54. package/dist/debug/path/storage/AdapterPathStore.js +133 -0
  55. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  56. package/dist/debug/path/storage/DefaultDataAdapter.js +356 -0
  57. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  58. package/dist/debug/path/storage/PathEventHub.js +148 -0
  59. package/dist/debug/path/storage/PathStore.cjs +1 -0
  60. package/dist/debug/path/storage/PathStore.js +326 -0
  61. package/dist/debug/path/storage/createDataDraft.cjs +1 -0
  62. package/dist/debug/path/storage/createDataDraft.js +71 -0
  63. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  64. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  65. package/dist/debug/reactivity/engine.cjs +1 -0
  66. package/dist/debug/reactivity/engine.js +1305 -0
  67. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  68. package/dist/debug/reactivity/reactive-object.js +280 -0
  69. package/dist/debug/reactivity/scope.cjs +1 -0
  70. package/dist/debug/reactivity/scope.js +274 -0
  71. package/dist/debug/reactivity/types.cjs +1 -0
  72. package/dist/debug/reactivity/types.js +1 -0
  73. package/dist/debug/reactivity/watch.cjs +1 -0
  74. package/dist/debug/reactivity/watch.js +64 -0
  75. package/dist/debug/runtime/RaphRuntime.cjs +1 -0
  76. package/dist/debug/runtime/RaphRuntime.js +979 -0
  77. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  78. package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
  79. package/dist/debug/runtime/errors.cjs +1 -0
  80. package/dist/debug/runtime/errors.js +15 -0
  81. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  82. package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
  83. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  84. package/dist/debug/runtime/ownership/RaphNode.js +206 -0
  85. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  86. package/dist/debug/runtime/ownership/RaphScope.js +101 -0
  87. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  88. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  89. package/dist/debug/runtime/ownership/parentGraph.cjs +1 -0
  90. package/dist/debug/runtime/ownership/parentGraph.js +10 -0
  91. package/dist/debug/runtime/ownership/throwDisposalErrors.cjs +1 -0
  92. package/dist/debug/runtime/ownership/throwDisposalErrors.js +9 -0
  93. package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
  94. package/dist/debug/runtime/phases/RaphFrameLoop.js +106 -0
  95. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  96. package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
  97. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  98. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  99. package/dist/debug/runtime/phases/phase.types.cjs +1 -0
  100. package/dist/debug/runtime/phases/phase.types.js +8 -0
  101. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  102. package/dist/debug/runtime/reactivity/PathHandle.js +175 -0
  103. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  104. package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
  105. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  106. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
  107. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  108. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
  109. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  110. package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
  111. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  112. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  113. package/dist/entrypoints/machine-testing.d.ts +2 -0
  114. package/dist/entrypoints/machine.d.ts +5 -0
  115. package/dist/entrypoints/path.d.ts +14 -0
  116. package/dist/entrypoints/reactivity.d.ts +1 -0
  117. package/dist/entrypoints/runtime.d.ts +17 -0
  118. package/dist/index.cjs +1 -0
  119. package/dist/index.js +48 -0
  120. package/dist/machine/compiler.d.ts +71 -0
  121. package/dist/machine/core.d.ts +50 -0
  122. package/dist/machine/persistence.d.ts +5 -0
  123. package/dist/machine/runtime.d.ts +4 -0
  124. package/dist/machine/testing.d.ts +43 -0
  125. package/dist/machine/types.d.ts +155 -0
  126. package/dist/machine-testing.cjs +1 -0
  127. package/dist/machine-testing.js +188 -0
  128. package/dist/machine.cjs +1 -0
  129. package/dist/machine.js +837 -0
  130. package/dist/main.d.ts +20 -0
  131. package/dist/path/DataPath.d.ts +73 -0
  132. package/dist/path/PathRouter.d.ts +21 -0
  133. package/dist/path/RaphKernel.d.ts +169 -0
  134. package/dist/path/data-path.types.d.ts +34 -0
  135. package/dist/path/data-path.utils.d.ts +9 -0
  136. package/dist/path/derived/DerivedRegistry.d.ts +67 -0
  137. package/dist/path/derived/RaphDerivedHandle.d.ts +97 -0
  138. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  139. package/dist/path/derived/derived-collection.utils.d.ts +20 -0
  140. package/dist/path/derived/derived-strategy.types.d.ts +12 -0
  141. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  142. package/dist/path/meta/MetaController.d.ts +85 -0
  143. package/dist/path/meta/RaphMeta.d.ts +45 -0
  144. package/dist/path/meta/RaphMetaStore.d.ts +45 -0
  145. package/dist/path/meta/meta.types.d.ts +31 -0
  146. package/dist/path/path.types.d.ts +27 -0
  147. package/dist/path/pathSegmentKey.d.ts +2 -0
  148. package/dist/path/storage/AdapterPathStore.d.ts +45 -0
  149. package/dist/path/storage/DefaultDataAdapter.d.ts +63 -0
  150. package/dist/path/storage/PathEventHub.d.ts +48 -0
  151. package/dist/path/storage/PathStore.d.ts +51 -0
  152. package/dist/path/storage/createDataDraft.d.ts +4 -0
  153. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  154. package/dist/path.cjs +1 -0
  155. package/dist/path.js +18 -0
  156. package/dist/raph.cjs +1 -0
  157. package/dist/raph.js +48 -0
  158. package/dist/reactivity/engine.d.ts +393 -0
  159. package/dist/reactivity/reactive-object.d.ts +36 -0
  160. package/dist/reactivity/scope.d.ts +146 -0
  161. package/dist/reactivity/types.d.ts +175 -0
  162. package/dist/reactivity/watch.d.ts +15 -0
  163. package/dist/reactivity.cjs +1 -0
  164. package/dist/reactivity.js +14 -0
  165. package/dist/runtime/RaphRuntime.d.ts +225 -0
  166. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  167. package/dist/runtime/errors.d.ts +21 -0
  168. package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
  169. package/dist/runtime/ownership/RaphNode.d.ts +40 -0
  170. package/dist/runtime/ownership/RaphScope.d.ts +38 -0
  171. package/dist/runtime/ownership/parent-graph.types.d.ts +4 -0
  172. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  173. package/dist/runtime/ownership/throwDisposalErrors.d.ts +1 -0
  174. package/dist/runtime/phases/RaphFrameLoop.d.ts +51 -0
  175. package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
  176. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  177. package/dist/runtime/phases/phase.types.d.ts +92 -0
  178. package/dist/runtime/reactivity/PathHandle.d.ts +80 -0
  179. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  180. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
  181. package/dist/runtime/reactivity/RuntimeReactivity.d.ts +45 -0
  182. package/dist/runtime/reactivity/RuntimeWatch.d.ts +34 -0
  183. package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +11 -0
  184. package/dist/runtime.cjs +1 -0
  185. package/dist/runtime.js +23 -0
  186. package/package.json +141 -0
@@ -0,0 +1,175 @@
1
+ var p = Object.defineProperty;
2
+ var u = (o, s, t) => s in o ? p(o, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[s] = t;
3
+ var i = (o, s, t) => u(o, typeof s != "symbol" ? s + "" : s, t);
4
+ import { pathRelationMasks as f } from "../../path/data-path.utils.js";
5
+ import { RaphDisposedError as k } from "../errors.js";
6
+ import { throwDisposalErrors as w } from "../ownership/throwDisposalErrors.js";
7
+ class T {
8
+ /**
9
+ * Создаёт internal path handle и связывает его с runtime lifecycle.
10
+ * @internal
11
+ */
12
+ constructor(s, t, h, r, e, a, n, d, v, c, l) {
13
+ // Публикуют canonical path и нормализованные параметры handle.
14
+ i(this, "path");
15
+ i(this, "options");
16
+ // Связывают path revision с runtime reactivity и owning Kernel.
17
+ i(this, "_revision");
18
+ i(this, "_disposeRevision");
19
+ i(this, "_isTracking");
20
+ i(this, "_store");
21
+ i(this, "_release");
22
+ i(this, "_masks");
23
+ // Применяют runtime lifecycle и write policy к операциям handle.
24
+ i(this, "_assertOwnerAlive");
25
+ i(this, "_assertTrackedRead");
26
+ i(this, "_assertWriteAllowed");
27
+ i(this, "_runWrite");
28
+ i(this, "_notifyEvents");
29
+ i(this, "_hasRevisionSubscribers");
30
+ // Хранят активную Kernel subscription и окончательное состояние handle.
31
+ i(this, "_stop");
32
+ i(this, "_activationLeases", 0);
33
+ i(this, "_trackedActivation", !1);
34
+ i(this, "_disposed", !1);
35
+ const _ = e._ownedSignal(0, c);
36
+ this._store = s, this._revision = _.source, this._disposeRevision = _.dispose, this._isTracking = e._isTracking, this.path = t.canonical, this.options = h, this._release = r, this._masks = f(t), this._assertOwnerAlive = a, this._assertTrackedRead = n, this._assertWriteAllowed = d, this._runWrite = v, this._notifyEvents = l, this._hasRevisionSubscribers = _.hasSubscribers;
37
+ }
38
+ /**
39
+ * Показывает, освобождён ли path handle.
40
+ */
41
+ get disposed() {
42
+ return this._disposed;
43
+ }
44
+ /**
45
+ * Читает path с регистрацией реактивной зависимости.
46
+ */
47
+ get() {
48
+ var s;
49
+ return this._assertAlive(), (s = this._assertTrackedRead) == null || s.call(this), this._isTracking() ? this._readTracked() : this._store.peek(this.path);
50
+ }
51
+ /**
52
+ * Читает path без регистрации реактивной зависимости.
53
+ */
54
+ peek() {
55
+ return this._assertAlive(), this._store.peek(this.path);
56
+ }
57
+ /**
58
+ * Записывает значение path через runtime write policy.
59
+ */
60
+ set(s) {
61
+ var t;
62
+ this._assertAlive(), (t = this._assertWriteAllowed) == null || t.call(this), this._write(() => this._store.set(this.path, s));
63
+ }
64
+ /**
65
+ * Объединяет значение path через runtime write policy.
66
+ */
67
+ merge(s) {
68
+ var t;
69
+ this._assertAlive(), (t = this._assertWriteAllowed) == null || t.call(this), this._write(() => this._store.merge(this.path, s));
70
+ }
71
+ /**
72
+ * Удаляет значение path через runtime write policy.
73
+ */
74
+ delete() {
75
+ var s;
76
+ this._assertAlive(), (s = this._assertWriteAllowed) == null || s.call(this), this._write(() => this._store.delete(this.path));
77
+ }
78
+ /**
79
+ * Проверяет наличие значения path.
80
+ */
81
+ has() {
82
+ return this._assertAlive(), this._store.has(this.path);
83
+ }
84
+ /**
85
+ * Отсоединяет Kernel subscription и освобождает reactive revision handle.
86
+ */
87
+ dispose() {
88
+ if (this._disposed)
89
+ return;
90
+ const s = this._runWrite;
91
+ s === void 0 ? this._disposeNow() : s(() => this._disposeNow());
92
+ }
93
+ _disposeNow() {
94
+ if (this._disposed)
95
+ return;
96
+ this._disposed = !0;
97
+ const s = [], t = this._stop;
98
+ this._stop = void 0;
99
+ const h = this._disposeRevision;
100
+ this._disposeRevision = void 0;
101
+ const r = this._release;
102
+ this._release = void 0, this._revision = void 0, this._isTracking = void 0, this._store = void 0, this._assertOwnerAlive = void 0, this._assertTrackedRead = void 0, this._assertWriteAllowed = void 0, this._runWrite = void 0, this._notifyEvents = void 0, this._hasRevisionSubscribers = void 0, this._activationLeases = 0, this._trackedActivation = !1;
103
+ try {
104
+ t == null || t();
105
+ } catch (e) {
106
+ s.push(e);
107
+ }
108
+ try {
109
+ h == null || h();
110
+ } catch (e) {
111
+ s.push(e);
112
+ }
113
+ try {
114
+ r == null || r(this);
115
+ } catch (e) {
116
+ s.push(e);
117
+ }
118
+ w(s, `[Raph] Path handle "${this.path}" disposal failed.`);
119
+ }
120
+ /**
121
+ * Читает path с регистрацией runtime reactive dependency.
122
+ * @internal
123
+ */
124
+ _getTracked() {
125
+ var s;
126
+ return this._assertAlive(), (s = this._assertTrackedRead) == null || s.call(this), this._readTracked();
127
+ }
128
+ /** Activates the lazy Kernel observer for an explicit granular watch. @internal */
129
+ _activate() {
130
+ this._assertAlive(), this._activationLeases++;
131
+ try {
132
+ this._observe();
133
+ } catch (t) {
134
+ throw this._activationLeases--, t;
135
+ }
136
+ let s = !0;
137
+ return () => {
138
+ s && (s = !1, this._activationLeases !== 0 && this._activationLeases--, this._releaseObserverIfIdle());
139
+ };
140
+ }
141
+ _readTracked() {
142
+ return this._trackedActivation = !0, this._observe(), this._revision.get(), this._store.get(this.path);
143
+ }
144
+ _observe() {
145
+ this._stop ?? (this._stop = this._store.watch(this._masks, (s) => {
146
+ const t = () => {
147
+ var e, a;
148
+ if (this._disposed)
149
+ return;
150
+ const r = this._revision;
151
+ r !== void 0 && ((a = this._notifyEvents) == null || a.call(this, s, ((e = this._hasRevisionSubscribers) == null ? void 0 : e.call(this)) ?? !1), !(this._disposed || this._revision !== r) && r.set(r.peek() + 1));
152
+ }, h = this._runWrite;
153
+ h === void 0 ? t() : h(t);
154
+ }));
155
+ }
156
+ _releaseObserverIfIdle() {
157
+ if (this._disposed || this._trackedActivation || this._activationLeases !== 0)
158
+ return;
159
+ const s = this._stop;
160
+ this._stop = void 0, s == null || s();
161
+ }
162
+ _write(s) {
163
+ const t = this._runWrite;
164
+ t === void 0 ? s() : t(s);
165
+ }
166
+ _assertAlive() {
167
+ var s;
168
+ if (this._disposed)
169
+ throw new k(`[Raph] Path handle "${this.path}" is disposed.`);
170
+ (s = this._assertOwnerAlive) == null || s.call(this);
171
+ }
172
+ }
173
+ export {
174
+ T as PathHandle
175
+ };
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var u=(o,e,t)=>e in o?p(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var i=(o,e,t)=>u(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../path/DataPath.cjs"),l=require("../errors.cjs");class h{constructor(e,t,s,r,a){i(this,"masks");i(this,"options");i(this,"_stop");i(this,"_activationLeases",0);i(this,"_disposed",!1);i(this,"_releaseOwner");this.owner=e,this._start=r,this._release=a;const n=Object.freeze({...s,...s.vars===void 0?{}:{vars:Object.freeze({...s.vars})}});this.options=n,this.masks=Array.isArray(t)?Object.freeze(t.map(_=>c.DataPath.from(_,n))):c.DataPath.from(t,n)}static _create(e,t,s,r,a){return new h(e,t,s,r,a)}get runtime(){return this.owner.runtime}get disposed(){return this._disposed}dispose(){if(this._disposed)return;const e=this.runtime,t=!e._ownerDisposalActive();t&&e._beginOwnerDisposal();const s=[];try{const r=this._releaseOwner;r!==void 0?(this._releaseOwner=void 0,r()):this._disposeOwned()}catch(r){s.push(r)}finally{if(t)try{e._endOwnerDisposal()}catch(r){s.push(r)}}if(s.length===1)throw s[0];if(s.length>1)throw new AggregateError(s,"[Raph] Meta source disposal failed.")}_bindOwner(e){this._releaseOwner=e}_disposeOwned(){var t;if(this._disposed)return;this._disposed=!0,this._releaseOwner=void 0;const e=[];try{(t=this._stop)==null||t.call(this)}catch(s){e.push(s)}this._stop=void 0,this._activationLeases=0;try{this._release()}catch(s){e.push(s)}if(this._start=f,this._release=d,e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"[Raph] Meta source disposal failed.")}_activate(){this._assertAlive(),this._activationLeases++;try{this._stop??(this._stop=this._start())}catch(t){throw this._activationLeases--,t}let e=!0;return()=>{if(!e||(e=!1,this._activationLeases!==0&&this._activationLeases--,this._disposed||this._activationLeases!==0))return;const t=this._stop;this._stop=void 0,t==null||t()}}_assertAlive(){if(this._disposed||this.owner.disposed)throw new l.RaphDisposedError("[Raph] Meta source is disposed.")}}function d(){}function f(){return d}exports.RaphMetaSource=h;
@@ -0,0 +1,112 @@
1
+ var _ = Object.defineProperty;
2
+ var l = (o, e, s) => e in o ? _(o, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[e] = s;
3
+ var i = (o, e, s) => l(o, typeof e != "symbol" ? e + "" : e, s);
4
+ import { DataPath as h } from "../../path/DataPath.js";
5
+ import { RaphDisposedError as f } from "../errors.js";
6
+ class c {
7
+ /** @internal */
8
+ constructor(e, s, t, r, a) {
9
+ i(this, "masks");
10
+ i(this, "options");
11
+ i(this, "_stop");
12
+ i(this, "_activationLeases", 0);
13
+ i(this, "_disposed", !1);
14
+ i(this, "_releaseOwner");
15
+ this.owner = e, this._start = r, this._release = a;
16
+ const n = Object.freeze({
17
+ ...t,
18
+ ...t.vars === void 0 ? {} : { vars: Object.freeze({ ...t.vars }) }
19
+ });
20
+ this.options = n, this.masks = Array.isArray(s) ? Object.freeze(s.map((p) => h.from(p, n))) : h.from(s, n);
21
+ }
22
+ /** @internal */
23
+ static _create(e, s, t, r, a) {
24
+ return new c(e, s, t, r, a);
25
+ }
26
+ get runtime() {
27
+ return this.owner.runtime;
28
+ }
29
+ get disposed() {
30
+ return this._disposed;
31
+ }
32
+ dispose() {
33
+ if (this._disposed)
34
+ return;
35
+ const e = this.runtime, s = !e._ownerDisposalActive();
36
+ s && e._beginOwnerDisposal();
37
+ const t = [];
38
+ try {
39
+ const r = this._releaseOwner;
40
+ r !== void 0 ? (this._releaseOwner = void 0, r()) : this._disposeOwned();
41
+ } catch (r) {
42
+ t.push(r);
43
+ } finally {
44
+ if (s)
45
+ try {
46
+ e._endOwnerDisposal();
47
+ } catch (r) {
48
+ t.push(r);
49
+ }
50
+ }
51
+ if (t.length === 1)
52
+ throw t[0];
53
+ if (t.length > 1)
54
+ throw new AggregateError(t, "[Raph] Meta source disposal failed.");
55
+ }
56
+ /** @internal */
57
+ _bindOwner(e) {
58
+ this._releaseOwner = e;
59
+ }
60
+ /** @internal */
61
+ _disposeOwned() {
62
+ var s;
63
+ if (this._disposed)
64
+ return;
65
+ this._disposed = !0, this._releaseOwner = void 0;
66
+ const e = [];
67
+ try {
68
+ (s = this._stop) == null || s.call(this);
69
+ } catch (t) {
70
+ e.push(t);
71
+ }
72
+ this._stop = void 0, this._activationLeases = 0;
73
+ try {
74
+ this._release();
75
+ } catch (t) {
76
+ e.push(t);
77
+ }
78
+ if (this._start = u, this._release = d, e.length === 1)
79
+ throw e[0];
80
+ if (e.length > 1)
81
+ throw new AggregateError(e, "[Raph] Meta source disposal failed.");
82
+ }
83
+ /** @internal */
84
+ _activate() {
85
+ this._assertAlive(), this._activationLeases++;
86
+ try {
87
+ this._stop ?? (this._stop = this._start());
88
+ } catch (s) {
89
+ throw this._activationLeases--, s;
90
+ }
91
+ let e = !0;
92
+ return () => {
93
+ if (!e || (e = !1, this._activationLeases !== 0 && this._activationLeases--, this._disposed || this._activationLeases !== 0))
94
+ return;
95
+ const s = this._stop;
96
+ this._stop = void 0, s == null || s();
97
+ };
98
+ }
99
+ /** @internal */
100
+ _assertAlive() {
101
+ if (this._disposed || this.owner.disposed)
102
+ throw new f("[Raph] Meta source is disposed.");
103
+ }
104
+ }
105
+ function d() {
106
+ }
107
+ function u() {
108
+ return d;
109
+ }
110
+ export {
111
+ c as RaphMetaSource
112
+ };
@@ -0,0 +1 @@
1
+ "use strict";var $=Object.defineProperty;var U=(u,e,s)=>e in u?$(u,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):u[e]=s;var d=(u,e,s)=>U(u,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../errors.cjs"),v=require("../ownership/throwDisposalErrors.cjs"),G=Symbol("RaphProducerRecord"),m=new WeakMap,M=Object.freeze([]),C=Object.freeze([]);class p{constructor(e,s){d(this,"_sources");d(this,"_disposed",!1);d(this,"_releaseOwner");d(this,"_memberReleases");d(this,"_firstSubscription");d(this,"_lastSubscription");d(this,"_firstDependent");d(this,"_lastDependent");d(this,"_revision",0);d(this,"_finalCause");this.owner=e,this._sources=q(s)}static _create(e,s){return new p(e,s)}get runtime(){return this.owner.runtime}get disposed(){return this._disposed}get sources(){return this._sources}dispose(){if(this._disposed)return;const e=this.runtime,s=!e._ownerDisposalActive();s&&e._beginOwnerDisposal();const t=[];try{const i=this._releaseOwner;i!==void 0?(this._releaseOwner=void 0,i()):this._disposeOwned()}catch(i){t.push(i)}finally{if(s)try{e._endOwnerDisposal()}catch(i){t.push(i)}}v.throwDisposalErrors(t,"[Raph] Aggregate disposal failed.")}_assertAlive(){if(this._disposed||this.owner.disposed)throw new S.RaphDisposedError("[Raph] Aggregate is disposed.")}_bindOwner(e){this._releaseOwner=e}_bindMembers(e){this._memberReleases=e.length===0?void 0:e}_removeMember(e){if(this._disposed)return;const s=this._sources.filter(t=>L(t)!==e);s.length!==this._sources.length&&(this._sources=s.length===0?M:Object.freeze(s))}_disposeOwned(){if(this._disposed)return;this._disposed=!0,this._releaseOwner=void 0;const e=f(this.owner)&&!this.owner._isPublished()?void 0:this._disposalCause(),s=[];let t=this._firstSubscription;for(this._firstSubscription=this._lastSubscription=void 0;t!==void 0;){const o=t.next,r=t.dispose;t.aggregate=void 0,t.dispose=void 0,t.previous=t.next=void 0;try{r==null||r(e)}catch(a){s.push(a)}t=o}const i=this._memberReleases;if(this._memberReleases=void 0,i!==void 0)for(let o=i.length-1;o>=0;o--)try{i[o]()}catch(r){s.push(r)}this._sources=M;let n=this._firstDependent;for(this._firstDependent=this._lastDependent=void 0;n!==void 0;){const o=n.next,r=n.cleanup;n.source=void 0,n.cleanup=void 0,n.previous=n.next=void 0;try{r==null||r()}catch(a){s.push(a)}n=o}v.throwDisposalErrors(s,"[Raph] Aggregate owned cleanup failed.")}_linkSubscription(e){this._assertAlive();const s={aggregate:this,dispose:e,previous:this._lastSubscription};return this._lastSubscription===void 0?this._firstSubscription=s:this._lastSubscription.next=s,this._lastSubscription=s,()=>I(s)}_linkDependent(e){e.previous=this._lastDependent,this._lastDependent===void 0?this._firstDependent=e:this._lastDependent.next=e,this._lastDependent=e}_detachDependent(e){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}_disposalCause(){return this._finalCause??(this._finalCause=Object.freeze({kind:"structure",source:this,sourceOwner:this.owner,revision:++this._revision,metadata:Object.freeze({disposed:!0})}))}_detachSubscription(e){if(e.aggregate===void 0)return;const s=e.dispose;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,s==null||s()}}class H{constructor(e){d(this,"_selfSubscribers");d(this,"_subtreeSubscribers");d(this,"_runtimeSubscribers");d(this,"_runtimeSubscriberCount",0);d(this,"_runtimeActivationProducers");d(this,"_nodeMemberships");d(this,"_nodeRevisions");d(this,"_nodeTouchKeys");d(this,"_implicitProducers");d(this,"_transientProducers");d(this,"_dispatchDepth",0);d(this,"_detachedEdges");d(this,"_disposed",!1);this._runtime=e}createProducer(e,s="producer",t={}){return this._assertAlive(),{[G]:!0,runtime:this._runtime,owner:e,kind:s,includeRuntime:t.includeRuntime??!0,revision:0,disposed:!1}}attachProducer(e,s){return e.alias!==void 0&&m.delete(e.alias),e.source=s,e.alias=s,m.set(s,e),s}setProducerActivation(e,s,t=!1){if(e.disposed)throw new S.RaphDisposedError("[Raph] Producer is disposed.");if(e.activate=s,!t)return;const i=this._runtimeActivationProducers??(this._runtimeActivationProducers=new Set);if(i.add(e),this._runtimeSubscriberCount!==0)try{e.runtimeActivation=x(s())}catch(n){throw i.delete(e),i.size===0&&(this._runtimeActivationProducers=void 0),n}}producerHooks(e){return{token:e,dependencyOwner:e.owner,onDependency:s=>this._linkImplicitDependency(e,s),onChange:(s,t,i)=>{this.notifyProducer(e,s,t,void 0,!0,i,!0)},onInvalidate:s=>this.notifyProducer(e,void 0,void 0,void 0,!0,s,!1),onDispose:s=>this._disposeProducer(e,s)}}causeForToken(e){if(!(!O(e)||e.runtime!==this._runtime))return e.lastCause}clearTransientCauses(){let e=this._transientProducers;for(this._transientProducers=void 0;e!==void 0;){const s=e.transientNext;e.transientNext=void 0,e.lastCause=void 0,e=s}}notifyProducer(e,s,t,i,n=!0,o=!1,r=!1){var c,h;if(this._disposed||e.disposed||e.source===void 0||f(e.owner)&&!e.owner._isPublished()||!r&&i===void 0&&e.lastCause!==void 0)return;if(!o&&((c=e.subscribers)==null?void 0:c.first)===void 0&&(!e.includeRuntime||((h=this._runtimeSubscribers)==null?void 0:h.first)===void 0)){this._dispatchProducerLazily(e,s,t,i,n,r);return}const a=Object.freeze({kind:e.kind,source:e.source,sourceOwner:e.owner,revision:++e.revision,...r?{previous:s,value:t}:{},...i===void 0?{}:{events:Object.freeze([...i])}});this._setTransientCause(e,a),this._dispatchProducer(e,a,n)}notifyProducerEvents(e,s,t=!0,i=!1){var o,r;if(this._disposed||e.disposed||e.source===void 0||f(e.owner)&&!e.owner._isPublished())return;if(!i&&((o=e.subscribers)==null?void 0:o.first)===void 0&&(!e.includeRuntime||((r=this._runtimeSubscribers)==null?void 0:r.first)===void 0)){this._dispatchProducerLazily(e,void 0,void 0,s,t,!1);return}const n=Object.freeze({kind:e.kind,source:e.source,sourceOwner:e.owner,revision:++e.revision,events:Object.freeze([...s])});this._setTransientCause(e,n),this._dispatchProducer(e,n,t)}notifyNode(e,s,t={}){var l,_,b,E,g,z;if(this._disposed||!e._isPublished()||((l=this._runtimeSubscribers)==null?void 0:l.first)===void 0&&((b=(_=this._selfSubscribers)==null?void 0:_.get(e))==null?void 0:b.first)===void 0&&this._subtreeSubscribers===void 0)return;const i=t.oldAncestors===void 0&&t.newAncestors===void 0?this._subtreeSubscribers===void 0?C:D(e):void 0,n=t.oldAncestors??i??C,o=t.newAncestors??i??C;if(!this._nodeHasDemand(e,n,o))return;const r=this._nodeRevisions??(this._nodeRevisions=new WeakMap),a=(r.get(e)??0)+1;r.set(e,a);const c=Object.freeze({kind:s,source:e,sourceOwner:e,revision:a,...t.metadata===void 0?{}:{metadata:t.metadata},...t.structure===void 0?{}:{structure:Object.freeze({...t.structure})}}),h=s==="structure"?e:this._nodeTouchKey(e);if(this._dispatch((E=this._selfSubscribers)==null?void 0:E.get(e),c,h),i!==void 0)for(const y of i)this._dispatch((g=this._subtreeSubscribers)==null?void 0:g.get(y),c,h);else{const y=new Set;for(const A of n)y.add(A);for(const A of o)y.add(A);for(const A of y)this._dispatch((z=this._subtreeSubscribers)==null?void 0:z.get(A),c,h)}this._dispatch(this._runtimeSubscribers,c,h)}createAggregate(e,s){if(this._assertOwner(e),s.length===0)throw new TypeError("[Raph] Aggregate requires at least one source.");this._validateAggregateSources(s,new Set);for(const o of s)this._assertSourceVisibleTo(e,o,new Set);const t=p._create(e,s),i=[],n=new Set;try{for(const o of t.sources){const r=L(o);if(r===void 0||n.has(r))continue;n.add(r);const a=this._linkSourceCleanup(o,()=>t._removeMember(r));a!==void 0&&i.push(a)}return t._bindMembers(i),t._bindOwner(e._adoptResource(()=>t._disposeOwned())),t}catch(o){const r=[];for(let a=i.length-1;a>=0;a--)try{i[a]()}catch(c){r.push(c)}throw r.length!==0?new AggregateError([o,...r],"[Raph] Aggregate registration and rollback failed."):o}}subscribe(e,s,t){this._assertAlive();const i=[],n=new WeakMap;try{this._subscribeOne(e,s,t,i,n,new Set)}catch(r){const a=[];for(let c=i.length-1;c>=0;c--)try{i[c]()}catch(h){a.push(h)}throw a.length!==0?new AggregateError([r,...a],"[Raph] Granular subscription registration and rollback failed."):r}let o=!0;return()=>{if(!o)return;o=!1;const r=[];for(let a=i.length-1;a>=0;a--)try{i[a]()}catch(c){r.push(c)}v.throwDisposalErrors(r,"[Raph] Granular subscription disposal failed.")}}assertSubscriptionAllowed(e,s){this._assertOwner(e),this._assertSourceVisibleTo(e,s,new Set)}assertReparentAllowed(e,s){const t=this._implicitProducers;if(t!==void 0)for(const i of t){const n=i.owner;if(!f(n))continue;const o=i.implicitConsumers;if(o!==void 0){for(const r of o.keys())if(j(r,e)&&!j(n,e)&&!K(n,s))throw new Error(`[Raph] Cannot reparent "${e.id}": implicit dependency from "${r.id}" to "${n.id}" would become invalid; use watch().`)}}}releaseNode(e){var t,i;this._releaseGranule(this._selfSubscribers,e),this._releaseGranule(this._subtreeSubscribers,e);const s=(t=this._nodeMemberships)==null?void 0:t.get(e);if(s!==void 0){this._nodeMemberships.delete(e);try{this._releaseCleanupList(s)}finally{((i=this._nodeMemberships)==null?void 0:i.size)===0&&(this._nodeMemberships=void 0)}}}dispose(){var s;if(this._disposed)return;this._disposed=!0;const e=[];if(this.clearTransientCauses(),this._implicitProducers!==void 0){for(const t of this._implicitProducers)t.implicitConsumers=void 0;this._implicitProducers.clear(),this._implicitProducers=void 0}try{this._releaseRuntimeActivations()}catch(t){e.push(t)}if((s=this._runtimeActivationProducers)==null||s.clear(),this._runtimeActivationProducers=void 0,this._runtimeSubscriberCount=0,this._selfSubscribers!==void 0)for(const t of[...this._selfSubscribers.keys()])this._releaseGranule(this._selfSubscribers,t);if(this._subtreeSubscribers!==void 0)for(const t of[...this._subtreeSubscribers.keys()])this._releaseGranule(this._subtreeSubscribers,t);if(this._nodeMemberships!==void 0){for(const t of this._nodeMemberships.values())this._releaseCleanupList(t,!1);this._nodeMemberships.clear(),this._nodeMemberships=void 0}if(this._runtimeSubscribers!==void 0){try{this._releaseWorkList(this._runtimeSubscribers)}catch(t){e.push(t)}this._runtimeSubscribers=void 0}v.throwDisposalErrors(e,"[Raph] Work graph disposal failed.")}_disposeProducer(e,s=!1){var r,a;if(e.disposed)return;const t=e.source,i=!f(e.owner)||e.owner._isPublished();let n;if(t!==void 0&&i&&(s||this._producerHasDemand(e))){const c=Object.freeze({kind:"structure",source:t,sourceOwner:e.owner,revision:++e.revision,metadata:Object.freeze({disposed:!0})});this._setTransientCause(e,c);try{this._dispatchProducer(e,c,!0,t)}catch(h){(n??(n=[])).push(h)}}e.disposed=!0;const o=e.runtimeActivation;e.runtimeActivation=void 0,(r=this._runtimeActivationProducers)==null||r.delete(e),((a=this._runtimeActivationProducers)==null?void 0:a.size)===0&&(this._runtimeActivationProducers=void 0);try{o==null||o()}catch(c){(n??(n=[])).push(c)}if(e.memberships!==void 0){try{this._releaseCleanupList(e.memberships)}catch(c){(n??(n=[])).push(c)}e.memberships=void 0}if(e.alias!==void 0&&m.delete(e.alias),e.alias=void 0,e.subscribers!==void 0)try{this._releaseWorkList(e.subscribers)}catch(c){(n??(n=[])).push(c)}finally{e.subscribers=void 0}e.activate=void 0,e.source=void 0,n!==void 0&&v.throwDisposalErrors(n,"[Raph] Runtime producer disposal failed.")}_dispatchProducer(e,s,t=!0,i=e){var o,r;this._dispatch(e.subscribers,s,i,t);const n=e.owner;if(f(n)){this._dispatch((o=this._selfSubscribers)==null?void 0:o.get(n),s,i,t);for(const a of D(n))this._dispatch((r=this._subtreeSubscribers)==null?void 0:r.get(a),s,i,t)}e.includeRuntime&&this._dispatch(this._runtimeSubscribers,s,i,t)}_dispatchProducerLazily(e,s,t,i,n,o){var h;const r=e.owner;let a;if(f(r)){const l=(h=this._selfSubscribers)==null?void 0:h.get(r);(l==null?void 0:l.first)!==void 0&&(a=this._createProducerCause(e,s,t,i,o),this._dispatch(l,a,e,n));const _=this._subtreeSubscribers;if(_!==void 0)for(let b=r;b!==null;){const E=b.parent,g=_.get(b);(g==null?void 0:g.first)!==void 0&&(a??(a=this._createProducerCause(e,s,t,i,o)),this._dispatch(g,a,e,n)),b=E}}const c=e.includeRuntime?this._runtimeSubscribers:void 0;(c==null?void 0:c.first)!==void 0&&(a??(a=this._createProducerCause(e,s,t,i,o)),this._dispatch(c,a,e,n))}_createProducerCause(e,s,t,i,n){const o=++e.revision,r=Object.freeze(n?i===void 0?{kind:e.kind,source:e.source,sourceOwner:e.owner,revision:o,previous:s,value:t}:{kind:e.kind,source:e.source,sourceOwner:e.owner,revision:o,previous:s,value:t,events:Object.freeze([...i])}:i===void 0?{kind:e.kind,source:e.source,sourceOwner:e.owner,revision:o}:{kind:e.kind,source:e.source,sourceOwner:e.owner,revision:o,events:Object.freeze([...i])});return this._setTransientCause(e,r),r}_retainRuntimeSubscriber(){var t;if(this._runtimeSubscriberCount++,this._runtimeSubscriberCount!==1)return;const e=[],s=[];try{for(const i of this._runtimeActivationProducers??[])i.disposed||i.runtimeActivation!==void 0||(i.runtimeActivation=x((t=i.activate)==null?void 0:t.call(i)),e.push(i));return}catch(i){s.push(i)}this._runtimeSubscriberCount=0;for(let i=e.length-1;i>=0;i--){const n=e[i],o=n.runtimeActivation;n.runtimeActivation=void 0;try{o==null||o()}catch(r){s.push(r)}}throw s.length===1?s[0]:new AggregateError(s,"[Raph] Runtime granule activation failed and rollback was incomplete.")}_releaseRuntimeSubscriber(){this._runtimeSubscriberCount!==0&&(this._runtimeSubscriberCount--,this._runtimeSubscriberCount===0&&this._releaseRuntimeActivations())}_releaseRuntimeActivations(){const e=[];for(const s of this._runtimeActivationProducers??[]){const t=s.runtimeActivation;s.runtimeActivation=void 0;try{t==null||t()}catch(i){e.push(i)}}v.throwDisposalErrors(e,"[Raph] Runtime granule activation cleanup failed.")}_linkImplicitDependency(e,s){const t=e.owner,i=s;if(e.disposed||i.runtime!==this._runtime||!f(t)||!f(i)||t===i)return;const n=e.implicitConsumers??(e.implicitConsumers=new Map);n.set(i,(n.get(i)??0)+1),(this._implicitProducers??(this._implicitProducers=new Set)).add(e);let r=!0;return()=>{var c,h,l;if(!r)return;r=!1;const a=(c=e.implicitConsumers)==null?void 0:c.get(i);if(a!==void 0){if(a>1){e.implicitConsumers.set(i,a-1);return}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))}}}_subscribeOne(e,s,t,i,n,o){if(s!==void 0&&!f(e))throw new TypeError("[Raph] watch include applies only to a bare RaphNode source.");if(e instanceof p){if(e._assertAlive(),this._assertRuntime(e.runtime),o.has(e))throw new TypeError("[Raph] Aggregate sources cannot contain a cycle.");o.add(e);const r=[];try{for(const a of e.sources)this._subscribeOne(a,void 0,t,r,n,o);i.push(e._linkSubscription(a=>{const c=[];if(a!==void 0)try{t(a,e,!0)}catch(h){c.push(h)}for(let h=r.length-1;h>=0;h--)try{r[h]()}catch(l){c.push(l)}v.throwDisposalErrors(c,"[Raph] Aggregate member subscription disposal failed.")}))}catch(a){const c=[];for(let h=r.length-1;h>=0;h--)try{r[h]()}catch(l){c.push(l)}throw o.delete(e),c.length!==0?new AggregateError([a,...c],"[Raph] Aggregate subscription registration and rollback failed."):a}o.delete(e);return}if(R(e)){this._subscribeNode(e.source,e.include,t,i,n);return}if(f(e)){this._subscribeNode(e,s??"self",t,i,n);return}if(P(e)){this._assertRuntime(e),i.push(k(n,e,()=>{const r=this._runtimeSubscribers??(this._runtimeSubscribers={}),a={kind:"runtime",sink:t,source:e};this._appendWorkEdge(r,a);try{this._retainRuntimeSubscriber()}catch(c){throw a.source=void 0,this._detachWorkEdge(r,a),r.first===void 0&&(this._runtimeSubscribers=void 0),c}return()=>{var c;a.source!==void 0&&(a.source=void 0,this._detachWorkEdge(this._runtimeSubscribers,a),((c=this._runtimeSubscribers)==null?void 0:c.first)===void 0&&(this._runtimeSubscribers=void 0),this._releaseRuntimeSubscriber())}}));return}if(w(e)){const r=m.get(e);if(r!==void 0){if(this._assertRuntime(r.runtime),r.disposed)throw new S.RaphDisposedError("[Raph] Producer is disposed.");i.push(k(n,r,()=>{var h;const a=r.subscribers??(r.subscribers={}),c={kind:"producer",sink:t,source:r};this._appendWorkEdge(a,c);try{c.activationRelease=x((h=r.activate)==null?void 0:h.call(r))}catch(l){throw c.source=void 0,this._detachWorkEdge(a,c),a.first===void 0&&(r.subscribers=void 0),l}return()=>{var b;const l=c.activationRelease;c.activationRelease=void 0;const _=c.source;O(_)&&(c.source=void 0,this._detachWorkEdge(_.subscribers,c),((b=_.subscribers)==null?void 0:b.first)===void 0&&(_.subscribers=void 0)),l==null||l()}}));return}}throw new TypeError("[Raph] Unsupported or ownerless granular watch source.")}_subscribeNode(e,s,t,i,n){if(this._assertRuntime(e.runtime),e._assertAlive(),s!=="self"&&s!=="subtree")throw new TypeError(`[Raph] Unsupported node include mode "${String(s)}".`);const o=s==="self"?e:e._subtreeSourceIdentity;i.push(k(n,o,()=>{const r=s==="self"?this._selfSubscribers??(this._selfSubscribers=new Map):this._subtreeSubscribers??(this._subtreeSubscribers=new Map);let a=r.get(e);a===void 0&&(a={},r.set(e,a));const c={kind:s,sink:t,source:e};return this._appendWorkEdge(a,c),this._createNodeEdgeRelease(c)}))}_createNodeEdgeRelease(e){return()=>{const s=e.source;if(!f(s))return;e.source=void 0;const t=e.kind==="self"?this._selfSubscribers:this._subtreeSubscribers,i=t==null?void 0:t.get(s);this._detachWorkEdge(i,e),(i==null?void 0:i.first)===void 0&&(t==null||t.delete(s),(t==null?void 0:t.size)===0&&(e.kind==="self"?this._selfSubscribers=void 0:this._subtreeSubscribers=void 0))}}_linkSourceCleanup(e,s){const t=F(e);if(t===void 0)return;const i={cleanup:s,source:t};if(O(t)){const n=t.memberships??(t.memberships={});W(n,i)}else if(t instanceof p)t._linkDependent(i);else{const n=this._nodeMemberships??(this._nodeMemberships=new Map);let o=n.get(t);o===void 0&&(o={},n.set(t,o)),W(o,i)}return()=>this._detachCleanupEdge(i)}_detachCleanupEdge(e){var i,n,o,r;const s=e.source;if(s===void 0)return;if(e.source=void 0,e.cleanup=void 0,O(s)){N(s.memberships,e),((i=s.memberships)==null?void 0:i.first)===void 0&&(s.memberships=void 0);return}if(s instanceof p){s._detachDependent(e);return}const t=(n=this._nodeMemberships)==null?void 0:n.get(s);N(t,e),(t==null?void 0:t.first)===void 0&&((o=this._nodeMemberships)==null||o.delete(s),((r=this._nodeMemberships)==null?void 0:r.size)===0&&(this._nodeMemberships=void 0))}_releaseCleanupList(e,s=!0){let t=e.first;e.first=e.last=void 0;const i=[];for(;t!==void 0;){const n=t.next,o=t.cleanup;if(t.source=void 0,t.cleanup=void 0,t.previous=t.next=void 0,s)try{o==null||o()}catch(r){i.push(r)}t=n}v.throwDisposalErrors(i,"[Raph] Aggregate membership cleanup failed.")}_validateAggregateSources(e,s){for(const t of e){if(Array.isArray(t))throw new TypeError("[Raph] Nested source arrays are not supported; create a named aggregate.");if(t instanceof p){if(t._assertAlive(),this._assertRuntime(t.runtime),s.has(t))throw new TypeError("[Raph] Aggregate sources cannot contain a cycle.");s.add(t),this._validateAggregateSources(t.sources,s),s.delete(t)}else if(R(t)){if(this._assertRuntime(t.source.runtime),t.source._assertAlive(),t.include!=="self"&&t.include!=="subtree")throw new TypeError(`[Raph] Unsupported node include mode "${String(t.include)}".`)}else if(f(t))this._assertRuntime(t.runtime),t._assertAlive();else if(P(t))this._assertRuntime(t);else if(w(t)){const i=m.get(t);if(i===void 0||i.disposed)throw new S.RaphDisposedError("[Raph] Aggregate producer is disposed or ownerless.");this._assertRuntime(i.runtime)}else throw new TypeError("[Raph] Unsupported aggregate source.")}}_assertSourceVisibleTo(e,s,t){if(s instanceof p){if(this._assertProvisionalOwnerAccess(e,s.owner),t.has(s))return;t.add(s);for(const n of s.sources)this._assertSourceVisibleTo(e,n,t);t.delete(s);return}if(R(s)){this._assertProvisionalOwnerAccess(e,s.source);return}if(f(s)){this._assertProvisionalOwnerAccess(e,s);return}if(P(s)||!w(s))return;const i=m.get(s);i!==void 0&&this._assertProvisionalOwnerAccess(e,i.owner)}_assertProvisionalOwnerAccess(e,s){if(!(!f(s)||s._isPublished())&&!(f(e)&&!e._isPublished()&&T(e)===T(s)))throw new Error(`[Raph] Owner "${e.id}" cannot subscribe to provisional source owner "${s.id}".`)}_dispatch(e,s,t,i=!0){let n=e==null?void 0:e.first;if(n===void 0)return;const o=e.last;this._dispatchDepth++;try{for(;n!==void 0;){const r=n.next;if(n.source!==void 0&&n.sink(s,t,i),n===o)break;n=r}}finally{if(--this._dispatchDepth===0&&this._detachedEdges!==void 0){for(const r of this._detachedEdges)r.previous=r.next=void 0;this._detachedEdges=void 0}}}_appendWorkEdge(e,s){s.previous=e.last,e.last===void 0?e.first=s:e.last.next=s,e.last=s}_detachWorkEdge(e,s){e!==void 0&&(s.previous===void 0?e.first=s.next:s.previous.next=s.next,s.next===void 0?e.last=s.previous:s.next.previous=s.previous,this._dispatchDepth===0?s.previous=s.next=void 0:(this._detachedEdges??(this._detachedEdges=[])).push(s))}_releaseWorkList(e){let s=e.first;const t=[];for(;s!==void 0;){const i=s.next,n=s.activationRelease;s.activationRelease=void 0,s.source=void 0,this._detachWorkEdge(e,s);try{n==null||n()}catch(o){t.push(o)}s=i}v.throwDisposalErrors(t,"[Raph] Granular source activation cleanup failed.")}_releaseGranule(e,s){const t=e==null?void 0:e.get(s);t!==void 0&&(e.delete(s),this._releaseWorkList(t),e.size===0&&(e===this._selfSubscribers&&(this._selfSubscribers=void 0),e===this._subtreeSubscribers&&(this._subtreeSubscribers=void 0)))}_setTransientCause(e,s){e.lastCause===void 0&&(e.transientNext=this._transientProducers,this._transientProducers=e),e.lastCause=s}_producerHasDemand(e){var t,i,n,o,r;if(f(e.owner)&&!e.owner._isPublished())return!1;if(((t=e.subscribers)==null?void 0:t.first)!==void 0||e.includeRuntime&&((i=this._runtimeSubscribers)==null?void 0:i.first)!==void 0)return!0;const s=e.owner;if(!f(s))return!1;if(((o=(n=this._selfSubscribers)==null?void 0:n.get(s))==null?void 0:o.first)!==void 0)return!0;if(this._subtreeSubscribers===void 0)return!1;for(const a of D(s))if(((r=this._subtreeSubscribers.get(a))==null?void 0:r.first)!==void 0)return!0;return!1}_nodeTouchKey(e){const s=this._nodeTouchKeys??(this._nodeTouchKeys=new WeakMap);let t=s.get(e);return t===void 0&&(t=Object.freeze({}),s.set(e,t)),t}_nodeHasDemand(e,s,t){var i,n,o,r,a;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)return!0;if(this._subtreeSubscribers===void 0)return!1;for(const c of s)if(((r=this._subtreeSubscribers.get(c))==null?void 0:r.first)!==void 0)return!0;for(const c of t)if(((a=this._subtreeSubscribers.get(c))==null?void 0:a.first)!==void 0)return!0;return!1}_assertOwner(e){this._assertRuntime(e.runtime),e._assertAlive()}_assertRuntime(e){if(e!==this._runtime)throw new S.RaphCrossRuntimeError("[Raph] Granular source belongs to another runtime.")}_assertAlive(){if(this._disposed)throw new S.RaphDisposedError("[Raph] Work graph is disposed.")}}function T(u){let e=u;for(;e.parent!==null&&!e.parent._isPublished();)e=e.parent;return e}function D(u){const e=[];for(let s=u;s!==null;s=s.parent)e.push(s);return e}function j(u,e){for(let s=u;s!==null;s=s.parent)if(s===e)return!0;return!1}function K(u,e){for(let s=e;s!==null;s=s.parent)if(s===u)return!0;return!1}function q(u){return Object.freeze(u.map(e=>R(e)?Object.freeze({source:e.source,include:e.include}):e))}function L(u){return u instanceof p?u:R(u)?u.source:f(u)||P(u)?u:w(u)?m.get(u):void 0}function F(u){if(u instanceof p)return u;if(R(u))return u.source;if(f(u))return u;if(!P(u))return w(u)?m.get(u):void 0}function W(u,e){e.previous=u.last,u.last===void 0?u.first=e:u.last.next=e,u.last=e}function I(u){var e;(e=u.aggregate)==null||e._detachSubscription(u)}function N(u,e){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)}function k(u,e,s){let t=u.get(e);t===void 0&&(t={count:0,dispose:s()},u.set(e,t)),t.count++;let i=!0;return()=>{if(!i||(i=!1,--t.count!==0))return;const n=t.dispose;t.dispose=Y,n()}}function Y(){}function x(u){return typeof u=="function"?u:void 0}function O(u){return typeof u=="object"&&u!==null&&u[G]===!0}function R(u){return w(u)&&"source"in u&&f(u.source)&&"include"in u}function f(u){return w(u)&&"_subtreeSourceIdentity"in u&&"runtime"in u&&"children"in u}function P(u){return w(u)&&"rootScope"in u&&"definePhases"in u&&"configuration"in u}function w(u){return typeof u=="object"&&u!==null}exports.RaphAggregate=p;exports.RaphWorkGraph=H;