@raphy-js/raph 1.0.0-dev.2

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 (139) hide show
  1. package/LICENSE +202 -0
  2. package/ReadMe.md +153 -0
  3. package/dist/api/Raph.d.ts +228 -0
  4. package/dist/api/errors.d.ts +20 -0
  5. package/dist/api/public.d.ts +22 -0
  6. package/dist/api/types.d.ts +25 -0
  7. package/dist/debug/api/Raph.cjs +1 -0
  8. package/dist/debug/api/Raph.js +419 -0
  9. package/dist/debug/api/errors.cjs +1 -0
  10. package/dist/debug/api/errors.js +14 -0
  11. package/dist/debug/api/public.cjs +1 -0
  12. package/dist/debug/api/public.js +40 -0
  13. package/dist/debug/api/types.cjs +1 -0
  14. package/dist/debug/api/types.js +1 -0
  15. package/dist/debug/path/AdapterPathStore.cjs +1 -0
  16. package/dist/debug/path/AdapterPathStore.js +133 -0
  17. package/dist/debug/path/DerivedRegistry.cjs +1 -0
  18. package/dist/debug/path/DerivedRegistry.js +157 -0
  19. package/dist/debug/path/MetaController.cjs +1 -0
  20. package/dist/debug/path/MetaController.js +214 -0
  21. package/dist/debug/path/PathEventHub.cjs +1 -0
  22. package/dist/debug/path/PathEventHub.js +148 -0
  23. package/dist/debug/path/PathStore.cjs +1 -0
  24. package/dist/debug/path/PathStore.js +326 -0
  25. package/dist/debug/path/RaphDerivedHandle.cjs +1 -0
  26. package/dist/debug/path/RaphDerivedHandle.js +125 -0
  27. package/dist/debug/path/RaphKernel.cjs +1 -0
  28. package/dist/debug/path/RaphKernel.js +636 -0
  29. package/dist/debug/path/RaphMeta.cjs +1 -0
  30. package/dist/debug/path/RaphMeta.js +68 -0
  31. package/dist/debug/path/RaphMetaStore.cjs +1 -0
  32. package/dist/debug/path/RaphMetaStore.js +184 -0
  33. package/dist/debug/path/data-adapter.cjs +1 -0
  34. package/dist/debug/path/data-adapter.js +356 -0
  35. package/dist/debug/path/data-draft.cjs +1 -0
  36. package/dist/debug/path/data-draft.js +71 -0
  37. package/dist/debug/path/data-path.cjs +1 -0
  38. package/dist/debug/path/data-path.js +423 -0
  39. package/dist/debug/path/derived-collection.cjs +1 -0
  40. package/dist/debug/path/derived-collection.js +179 -0
  41. package/dist/debug/path/derived-strategies.cjs +1 -0
  42. package/dist/debug/path/derived-strategies.js +20 -0
  43. package/dist/debug/path/meta.types.cjs +1 -0
  44. package/dist/debug/path/meta.types.js +1 -0
  45. package/dist/debug/path/path-router.cjs +1 -0
  46. package/dist/debug/path/path-router.js +86 -0
  47. package/dist/debug/path/path.types.cjs +1 -0
  48. package/dist/debug/path/path.types.js +1 -0
  49. package/dist/debug/path/public.cjs +1 -0
  50. package/dist/debug/path/public.js +18 -0
  51. package/dist/debug/path/segment-key.cjs +1 -0
  52. package/dist/debug/path/segment-key.js +12 -0
  53. package/dist/debug/reactivity/engine.cjs +1 -0
  54. package/dist/debug/reactivity/engine.js +1133 -0
  55. package/dist/debug/reactivity/scope.cjs +1 -0
  56. package/dist/debug/reactivity/scope.js +274 -0
  57. package/dist/debug/reactivity/types.cjs +1 -0
  58. package/dist/debug/reactivity/types.js +1 -0
  59. package/dist/debug/reactivity/watch.cjs +1 -0
  60. package/dist/debug/reactivity/watch.js +64 -0
  61. package/dist/debug/runtime/PathHandle.cjs +1 -0
  62. package/dist/debug/runtime/PathHandle.js +139 -0
  63. package/dist/debug/runtime/RaphDebug.cjs +1 -0
  64. package/dist/debug/runtime/RaphDebug.js +15 -0
  65. package/dist/debug/runtime/RaphFrameLoop.cjs +1 -0
  66. package/dist/debug/runtime/RaphFrameLoop.js +106 -0
  67. package/dist/debug/runtime/RaphNode.cjs +1 -0
  68. package/dist/debug/runtime/RaphNode.js +143 -0
  69. package/dist/debug/runtime/RaphPhasePipeline.cjs +1 -0
  70. package/dist/debug/runtime/RaphPhasePipeline.js +526 -0
  71. package/dist/debug/runtime/RaphRuntime.cjs +1 -0
  72. package/dist/debug/runtime/RaphRuntime.js +700 -0
  73. package/dist/debug/runtime/RaphScope.cjs +1 -0
  74. package/dist/debug/runtime/RaphScope.js +64 -0
  75. package/dist/debug/runtime/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/RuntimeReactivity.js +154 -0
  77. package/dist/debug/runtime/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/RuntimeWatch.js +71 -0
  79. package/dist/debug/runtime/disposal.cjs +1 -0
  80. package/dist/debug/runtime/disposal.js +9 -0
  81. package/dist/debug/runtime/errors.cjs +1 -0
  82. package/dist/debug/runtime/errors.js +12 -0
  83. package/dist/debug/runtime/parent-graph.cjs +1 -0
  84. package/dist/debug/runtime/parent-graph.js +10 -0
  85. package/dist/debug/runtime/phase.types.cjs +1 -0
  86. package/dist/debug/runtime/phase.types.js +8 -0
  87. package/dist/debug/runtime/public.cjs +1 -0
  88. package/dist/debug/runtime/public.js +18 -0
  89. package/dist/debug/runtime/runtime-reactivity.types.cjs +1 -0
  90. package/dist/debug/runtime/runtime-reactivity.types.js +1 -0
  91. package/dist/index.cjs +1 -0
  92. package/dist/index.js +40 -0
  93. package/dist/path/AdapterPathStore.d.ts +45 -0
  94. package/dist/path/DerivedRegistry.d.ts +67 -0
  95. package/dist/path/MetaController.d.ts +85 -0
  96. package/dist/path/PathEventHub.d.ts +48 -0
  97. package/dist/path/PathStore.d.ts +51 -0
  98. package/dist/path/RaphDerivedHandle.d.ts +97 -0
  99. package/dist/path/RaphKernel.d.ts +166 -0
  100. package/dist/path/RaphMeta.d.ts +45 -0
  101. package/dist/path/RaphMetaStore.d.ts +45 -0
  102. package/dist/path/data-adapter.d.ts +78 -0
  103. package/dist/path/data-draft.d.ts +4 -0
  104. package/dist/path/data-path.d.ts +97 -0
  105. package/dist/path/derived-collection.d.ts +30 -0
  106. package/dist/path/derived-strategies.d.ts +15 -0
  107. package/dist/path/meta.types.d.ts +33 -0
  108. package/dist/path/path-router.d.ts +21 -0
  109. package/dist/path/path.types.d.ts +26 -0
  110. package/dist/path/public.d.ts +14 -0
  111. package/dist/path/segment-key.d.ts +2 -0
  112. package/dist/path.cjs +1 -0
  113. package/dist/path.js +18 -0
  114. package/dist/raph.cjs +1 -0
  115. package/dist/raph.js +40 -0
  116. package/dist/reactivity/engine.d.ts +379 -0
  117. package/dist/reactivity/scope.d.ts +146 -0
  118. package/dist/reactivity/types.d.ts +150 -0
  119. package/dist/reactivity/watch.d.ts +15 -0
  120. package/dist/reactivity.cjs +1 -0
  121. package/dist/reactivity.js +14 -0
  122. package/dist/runtime/PathHandle.d.ts +72 -0
  123. package/dist/runtime/RaphDebug.d.ts +32 -0
  124. package/dist/runtime/RaphFrameLoop.d.ts +51 -0
  125. package/dist/runtime/RaphNode.d.ts +68 -0
  126. package/dist/runtime/RaphPhasePipeline.d.ts +133 -0
  127. package/dist/runtime/RaphRuntime.d.ts +285 -0
  128. package/dist/runtime/RaphScope.d.ts +50 -0
  129. package/dist/runtime/RuntimeReactivity.d.ts +40 -0
  130. package/dist/runtime/RuntimeWatch.d.ts +28 -0
  131. package/dist/runtime/disposal.d.ts +1 -0
  132. package/dist/runtime/errors.d.ts +16 -0
  133. package/dist/runtime/parent-graph.d.ts +5 -0
  134. package/dist/runtime/phase.types.d.ts +49 -0
  135. package/dist/runtime/public.d.ts +13 -0
  136. package/dist/runtime/runtime-reactivity.types.d.ts +9 -0
  137. package/dist/runtime.cjs +1 -0
  138. package/dist/runtime.js +18 -0
  139. package/package.json +109 -0
@@ -0,0 +1,326 @@
1
+ var R = Object.defineProperty;
2
+ var m = (r, e, t) => e in r ? R(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var v = (r, e, t) => m(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { parseDataPath as l } from "./data-path.js";
5
+ import { PathEventHub as H } from "./PathEventHub.js";
6
+ const u = /* @__PURE__ */ new WeakMap();
7
+ class $ {
8
+ constructor() {
9
+ // Владеют path data и независимым event lifecycle этого store.
10
+ v(this, "_root");
11
+ v(this, "_eventHub", new H(
12
+ "[Raph] Path transaction and publication failed."
13
+ ));
14
+ }
15
+ /**
16
+ * Возвращает внутренний router для диагностического контракта Kernel.
17
+ * @internal
18
+ */
19
+ get _router() {
20
+ return this._eventHub.router;
21
+ }
22
+ get _events() {
23
+ return this._eventHub.events;
24
+ }
25
+ get _watcherCount() {
26
+ return this._eventHub.watcherCount;
27
+ }
28
+ /**
29
+ * Возвращает значение по пути без создания отсутствующих данных.
30
+ */
31
+ get(e, t) {
32
+ const n = l(e, t), o = this._root;
33
+ if (o !== void 0)
34
+ return a(o, n.segments).value;
35
+ }
36
+ /**
37
+ * Читает значение по пути без регистрации реактивной зависимости.
38
+ */
39
+ peek(e, t) {
40
+ return this.get(e, t);
41
+ }
42
+ /**
43
+ * Проверяет наличие значения по указанному пути.
44
+ */
45
+ has(e, t) {
46
+ const n = l(e, t), o = this._root;
47
+ return o !== void 0 && a(o, n.segments).exists;
48
+ }
49
+ /**
50
+ * Записывает значение и публикует соответствующее изменение.
51
+ */
52
+ set(e, t, n) {
53
+ const o = l(e, n);
54
+ if (o.segments.length === 0) {
55
+ this._setRoot(t);
56
+ return;
57
+ }
58
+ const s = this._eventHub.hasWatchers, i = s ? a(this._root, o.segments).value : void 0;
59
+ if (this._root ?? (this._root = /* @__PURE__ */ Object.create(null)), O(this._root, o, t), !s)
60
+ return;
61
+ const c = a(this._root, o.segments).value;
62
+ this._eventHub.record({
63
+ kind: "set",
64
+ path: o.canonical,
65
+ previous: i,
66
+ value: c
67
+ });
68
+ }
69
+ /**
70
+ * Объединяет значение по пути и публикует соответствующее изменение.
71
+ */
72
+ merge(e, t, n) {
73
+ const o = l(e, n);
74
+ if (o.segments.length === 0) {
75
+ this._mergeRoot(t);
76
+ return;
77
+ }
78
+ const s = this._eventHub.hasWatchers, i = a(this._root, o.segments).value, c = s && d(i) && d(t) ? A(i) : i;
79
+ if (d(i) && d(t)) {
80
+ g(this._root, o.segments);
81
+ for (const w of Object.keys(t))
82
+ h(i, w, t[w]);
83
+ } else
84
+ this._root ?? (this._root = /* @__PURE__ */ Object.create(null)), O(this._root, o, t);
85
+ if (!s)
86
+ return;
87
+ const f = a(this._root, o.segments).value;
88
+ this._eventHub.record({
89
+ kind: "merge",
90
+ path: o.canonical,
91
+ previous: c,
92
+ value: f
93
+ });
94
+ }
95
+ /**
96
+ * Удаляет значение по пути и публикует изменение при наличии данных.
97
+ */
98
+ delete(e, t) {
99
+ const n = l(e, t);
100
+ if (n.segments.length === 0) {
101
+ this._deleteRoot();
102
+ return;
103
+ }
104
+ const o = a(this._root, n.segments);
105
+ !o.exists || this._root === void 0 || (g(this._root, n.segments), E(this._root, n), this._eventHub.hasWatchers && this._eventHub.record({
106
+ kind: "delete",
107
+ path: n.canonical,
108
+ previous: o.value,
109
+ value: void 0
110
+ }));
111
+ }
112
+ /**
113
+ * Выполняет операцию в общей синхронной transaction boundary.
114
+ */
115
+ transaction(e) {
116
+ return this._eventHub.transaction(e);
117
+ }
118
+ /**
119
+ * Подписывает callback на подходящие изменения и возвращает disposer.
120
+ */
121
+ watch(e, t) {
122
+ return this._eventHub.watch(e, t);
123
+ }
124
+ _setRoot(e) {
125
+ const t = x(e), n = this._root;
126
+ this._root = t, this._recordRootEvent("set", n, t);
127
+ }
128
+ _mergeRoot(e) {
129
+ const t = this._root, n = this._eventHub.hasWatchers && d(t) && d(e) ? A(t) : t;
130
+ if (d(t) && d(e))
131
+ for (const o of Object.keys(e))
132
+ h(t, o, e[o]);
133
+ else
134
+ this._root = x(e);
135
+ this._recordRootEvent("merge", n, this._root);
136
+ }
137
+ _deleteRoot() {
138
+ const e = this._root;
139
+ e !== void 0 && (this._root = S(), this._recordRootEvent("delete", e, void 0));
140
+ }
141
+ _recordRootEvent(e, t, n) {
142
+ this._eventHub.record({ kind: e, path: "", previous: t, value: n });
143
+ }
144
+ }
145
+ function a(r, e) {
146
+ let t = r;
147
+ for (const n of e)
148
+ if (n.kind === "key") {
149
+ if (!k(t) || !Object.hasOwn(t, n.key))
150
+ return { exists: !1, value: void 0 };
151
+ t = t[n.key];
152
+ } else if (n.kind === "index") {
153
+ if (!Array.isArray(t) || !Object.hasOwn(t, n.index))
154
+ return { exists: !1, value: void 0 };
155
+ t = t[n.index];
156
+ } else {
157
+ if (!Array.isArray(t))
158
+ return { exists: !1, value: void 0 };
159
+ const o = _(t, n.key, n.value);
160
+ if (o === -1)
161
+ return { exists: !1, value: void 0 };
162
+ t = t[o];
163
+ }
164
+ return { exists: !0, value: t };
165
+ }
166
+ function g(r, e) {
167
+ let t = r;
168
+ for (const n of e) {
169
+ if (!k(t))
170
+ return;
171
+ const o = j(t, n);
172
+ Array.isArray(t) && u.delete(t), t = o;
173
+ }
174
+ }
175
+ function O(r, e, t) {
176
+ let n = r, o;
177
+ for (let i = 0; i < e.segments.length - 1; i++) {
178
+ const c = e.segments[i], f = e.segments[i + 1];
179
+ c.kind === "selector" && Array.isArray(n) && (o = n), c.kind === "index" && Array.isArray(n) && (o = n), n = P(n, c, f, e.canonical);
180
+ }
181
+ const s = e.segments[e.segments.length - 1];
182
+ if (C(n, s, t, e.canonical), s.kind === "key" && o !== void 0) {
183
+ const i = u.get(o);
184
+ i == null || i.delete(s.key), (i == null ? void 0 : i.size) === 0 && u.delete(o);
185
+ }
186
+ }
187
+ function E(r, e) {
188
+ let t = r;
189
+ for (let s = 0; s < e.segments.length - 1; s++) {
190
+ const i = e.segments[s], c = j(t, i);
191
+ if (!k(c))
192
+ return;
193
+ t = c;
194
+ }
195
+ const n = e.segments[e.segments.length - 1];
196
+ if (n.kind === "key") {
197
+ delete t[n.key];
198
+ return;
199
+ }
200
+ if (!Array.isArray(t))
201
+ return;
202
+ if (n.kind === "index") {
203
+ u.delete(t), delete t[n.index];
204
+ return;
205
+ }
206
+ const o = _(t, n.key, n.value);
207
+ o !== -1 && (u.delete(t), delete t[o]);
208
+ }
209
+ function j(r, e) {
210
+ if (e.kind === "key")
211
+ return Object.hasOwn(r, e.key) ? r[e.key] : void 0;
212
+ if (!Array.isArray(r))
213
+ return;
214
+ if (e.kind === "index")
215
+ return r[e.index];
216
+ const t = _(r, e.key, e.value);
217
+ return t === -1 ? void 0 : r[t];
218
+ }
219
+ function P(r, e, t, n) {
220
+ if (e.kind === "key") {
221
+ const s = r;
222
+ let i = s[e.key];
223
+ return (!Object.hasOwn(s, e.key) || i === void 0) && (i = p(t), h(s, e.key, i)), b(i, n);
224
+ }
225
+ if (e.kind === "index") {
226
+ if (!Array.isArray(r))
227
+ throw y(n);
228
+ let s = r[e.index];
229
+ return (!Object.hasOwn(r, e.index) || s === void 0) && (u.delete(r), s = p(t), r[e.index] = s), b(s, n);
230
+ }
231
+ if (!Array.isArray(r))
232
+ throw y(n);
233
+ let o = _(r, e.key, e.value);
234
+ if (o === -1) {
235
+ u.delete(r);
236
+ const s = /* @__PURE__ */ Object.create(null);
237
+ s[e.key] = e.value, r.push(s), o = r.length - 1;
238
+ }
239
+ return b(r[o], n);
240
+ }
241
+ function C(r, e, t, n) {
242
+ if (e.kind === "key") {
243
+ h(r, e.key, t);
244
+ return;
245
+ }
246
+ if (e.kind === "index") {
247
+ if (!Array.isArray(r))
248
+ throw y(n);
249
+ u.delete(r), r[e.index] = t;
250
+ return;
251
+ }
252
+ if (!Array.isArray(r))
253
+ throw y(n);
254
+ const o = _(r, e.key, e.value);
255
+ if (o !== -1) {
256
+ u.delete(r), r[o] = t;
257
+ return;
258
+ }
259
+ if (!d(t))
260
+ throw new TypeError(`[Raph] New selector target at "${n}" must be an object.`);
261
+ const s = t[e.key];
262
+ if (Object.hasOwn(t, e.key) && !Object.is(s, e.value))
263
+ throw new TypeError(`[Raph] Selector target at "${n}" has a conflicting key.`);
264
+ u.delete(r), r.push(Object.hasOwn(t, e.key) ? t : { ...t, [e.key]: e.value });
265
+ }
266
+ function p(r) {
267
+ return r.kind === "index" || r.kind === "selector" ? [] : /* @__PURE__ */ Object.create(null);
268
+ }
269
+ function S() {
270
+ return /* @__PURE__ */ Object.create(null);
271
+ }
272
+ function x(r) {
273
+ if (k(r))
274
+ return r;
275
+ throw new TypeError("[Raph] Root value must be an object or array.");
276
+ }
277
+ function b(r, e) {
278
+ if (k(r))
279
+ return r;
280
+ throw y(e);
281
+ }
282
+ function _(r, e, t) {
283
+ let n = u.get(r);
284
+ const o = n == null ? void 0 : n.get(e);
285
+ if (o)
286
+ return o.get(t) ?? -1;
287
+ const s = /* @__PURE__ */ new Map();
288
+ for (let i = 0; i < r.length; i++) {
289
+ const c = r[i];
290
+ if (d(c) && Object.hasOwn(c, e)) {
291
+ const f = c[e];
292
+ (f === null || typeof f == "string" || typeof f == "number" || typeof f == "boolean") && !s.has(f) && s.set(f, i);
293
+ }
294
+ }
295
+ return n || (n = /* @__PURE__ */ new Map(), u.set(r, n)), n.set(e, s), s.get(t) ?? -1;
296
+ }
297
+ function h(r, e, t) {
298
+ if (e === "__proto__") {
299
+ Object.defineProperty(r, e, {
300
+ configurable: !0,
301
+ enumerable: !0,
302
+ value: t,
303
+ writable: !0
304
+ });
305
+ return;
306
+ }
307
+ r[e] = t;
308
+ }
309
+ function A(r) {
310
+ const e = Object.create(Object.getPrototypeOf(r));
311
+ for (const t of Object.keys(r))
312
+ h(e, t, r[t]);
313
+ return e;
314
+ }
315
+ function d(r) {
316
+ return typeof r == "object" && r !== null && !Array.isArray(r);
317
+ }
318
+ function k(r) {
319
+ return Array.isArray(r) || d(r);
320
+ }
321
+ function y(r) {
322
+ return new TypeError(`[Raph] Cannot traverse non-container data at "${r}".`);
323
+ }
324
+ export {
325
+ $ as PathStore
326
+ };
@@ -0,0 +1 @@
1
+ "use strict";var o=Object.defineProperty;var d=(r,e,t)=>e in r?o(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var s=(r,e,t)=>d(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a extends Error{constructor(e){super(`[Raph] Derived target is read-only: "${e}".`),this.name="RaphDerivedTargetWriteError"}}class h{constructor(e,t,i){s(this,"id");s(this,"options");s(this,"_kernel");s(this,"_removeRoutes");s(this,"_paused",!1);s(this,"_disposed",!1);s(this,"_status","idle");s(this,"_lastError",null);this._kernel=e,this.id=t,this.options=i}get paused(){return this._paused}get disposed(){return this._disposed}get status(){return this._status}get lastError(){return this._lastError}_recordSuccess(){this._status="success",this._lastError=null}_recordFailure(e){this._status="error",this._lastError=e instanceof Error?e:new Error(String(e))}pause(){this._assertAlive(),this._paused=!0}resume(){this._assertAlive(),this._paused=!1,this.recompute()}recompute(){this._assertAlive(),this._kernel._recomputeDerived(this)}dispose(){this._disposed||(this._disposed=!0,this._kernel._removeDerived(this),this.options.disposeTarget==="delete"&&this._kernel.delete(this.options.to))}_attachRoutes(e){this._removeRoutes=e}_detachRoutes(){const e=this._removeRoutes;if(this._removeRoutes=void 0,e!==void 0)for(const t of e)t()}_disposeFromKernel(){this._disposed=!0,this._removeRoutes=void 0}_assertAlive(){if(this._disposed)throw new Error(`[Raph] Derived "${this.id}" is disposed.`)}}exports.RaphDerivedHandle=h;exports.RaphDerivedTargetWriteError=a;
@@ -0,0 +1,125 @@
1
+ var o = Object.defineProperty;
2
+ var d = (r, e, t) => e in r ? o(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var s = (r, e, t) => d(r, typeof e != "symbol" ? e + "" : e, t);
4
+ class h extends Error {
5
+ /**
6
+ * Создаёт ошибку с canonical path защищённого derived target.
7
+ */
8
+ constructor(e) {
9
+ super(`[Raph] Derived target is read-only: "${e}".`), this.name = "RaphDerivedTargetWriteError";
10
+ }
11
+ }
12
+ class u {
13
+ /**
14
+ * Создаёт internal handle, которым управляет owning Kernel.
15
+ * @internal
16
+ */
17
+ constructor(e, t, i) {
18
+ // Публикуют identity и immutable параметры materialized dependency.
19
+ s(this, "id");
20
+ s(this, "options");
21
+ // Связывают handle с owning Kernel и зарегистрированными source routes.
22
+ s(this, "_kernel");
23
+ s(this, "_removeRoutes");
24
+ // Хранят lifecycle и результат последнего вычисления.
25
+ s(this, "_paused", !1);
26
+ s(this, "_disposed", !1);
27
+ s(this, "_status", "idle");
28
+ s(this, "_lastError", null);
29
+ this._kernel = e, this.id = t, this.options = i;
30
+ }
31
+ /**
32
+ * Показывает, приостановлено ли derived-вычисление.
33
+ */
34
+ get paused() {
35
+ return this._paused;
36
+ }
37
+ /**
38
+ * Показывает, освобождён ли derived handle.
39
+ */
40
+ get disposed() {
41
+ return this._disposed;
42
+ }
43
+ /**
44
+ * Возвращает состояние последнего derived-пересчёта.
45
+ */
46
+ get status() {
47
+ return this._status;
48
+ }
49
+ /**
50
+ * Возвращает последнюю ошибку derived-пересчёта либо null.
51
+ */
52
+ get lastError() {
53
+ return this._lastError;
54
+ }
55
+ /**
56
+ * Фиксирует успешное завершение derived-пересчёта.
57
+ * @internal
58
+ */
59
+ _recordSuccess() {
60
+ this._status = "success", this._lastError = null;
61
+ }
62
+ /**
63
+ * Фиксирует ошибку derived-пересчёта без потери handle.
64
+ * @internal
65
+ */
66
+ _recordFailure(e) {
67
+ this._status = "error", this._lastError = e instanceof Error ? e : new Error(String(e));
68
+ }
69
+ /**
70
+ * Приостанавливает автоматические пересчёты без освобождения handle.
71
+ */
72
+ pause() {
73
+ this._assertAlive(), this._paused = !0;
74
+ }
75
+ /**
76
+ * Возобновляет пересчёты и синхронизирует устаревший target.
77
+ */
78
+ resume() {
79
+ this._assertAlive(), this._paused = !1, this.recompute();
80
+ }
81
+ /**
82
+ * Принудительно пересчитывает derived target.
83
+ */
84
+ recompute() {
85
+ this._assertAlive(), this._kernel._recomputeDerived(this);
86
+ }
87
+ /**
88
+ * Удаляет derived registration и применяет выбранную политику target cleanup.
89
+ */
90
+ dispose() {
91
+ this._disposed || (this._disposed = !0, this._kernel._removeDerived(this), this.options.disposeTarget === "delete" && this._kernel.delete(this.options.to));
92
+ }
93
+ /**
94
+ * Сохраняет disposers source routes текущей стратегии.
95
+ * @internal
96
+ */
97
+ _attachRoutes(e) {
98
+ this._removeRoutes = e;
99
+ }
100
+ /**
101
+ * Отсоединяет все source routes текущей стратегии.
102
+ * @internal
103
+ */
104
+ _detachRoutes() {
105
+ const e = this._removeRoutes;
106
+ if (this._removeRoutes = void 0, e !== void 0)
107
+ for (const t of e)
108
+ t();
109
+ }
110
+ /**
111
+ * Помечает handle освобождённым после cleanup owning Kernel.
112
+ * @internal
113
+ */
114
+ _disposeFromKernel() {
115
+ this._disposed = !0, this._removeRoutes = void 0;
116
+ }
117
+ _assertAlive() {
118
+ if (this._disposed)
119
+ throw new Error(`[Raph] Derived "${this.id}" is disposed.`);
120
+ }
121
+ }
122
+ export {
123
+ u as RaphDerivedHandle,
124
+ h as RaphDerivedTargetWriteError
125
+ };
@@ -0,0 +1 @@
1
+ "use strict";var z=Object.defineProperty;var A=(_,e,t)=>e in _?z(_,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):_[e]=t;var k=(_,e,t)=>A(_,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./AdapterPathStore.cjs"),I=require("./data-adapter.cjs"),w=require("./data-path.cjs"),f=require("./derived-collection.cjs"),E=require("./DerivedRegistry.cjs"),R=require("./MetaController.cjs"),T=require("./PathStore.cjs"),C=require("./RaphDerivedHandle.cjs"),x=class x{constructor(e={}){k(this,"id");k(this,"_paths");k(this,"_derivedController");k(this,"_runtimes");k(this,"_metaController");k(this,"_transactionDepth",0);k(this,"_stabilizing",!1);k(this,"_derivedWriteDepth",0);if(this.id=e.id??`kernel-${x._kernelCounter++}`,e.adapter!==void 0){if(e.initial!==void 0||e.adapterOptions!==void 0)throw new TypeError("[Raph] A custom adapter cannot be combined with initial or adapterOptions.");this._paths=new M.AdapterPathStore(e.adapter)}else if(e.adapterOptions!==void 0)this._paths=new M.AdapterPathStore(new I.DefaultDataAdapter(e.initial,e.adapterOptions));else{const t=this._paths=new T.PathStore;e.initial!==void 0&&t.set("",e.initial)}}get disposed(){return this._paths===void 0}getDerivedSnapshot(){var t;const e=this._derivedController;return{registrations:(e==null?void 0:e.size)??0,errors:[...(e==null?void 0:e.values())??[]].filter(r=>r.status==="error").length,pending:((t=e==null?void 0:e.pending)==null?void 0:t.size)??0,stabilizing:this._stabilizing}}get meta(){return this._metadata.facade}get(e,t){return this._store.get(e??"",t)}peek(e,t){return this._store.peek(e??"",t)}has(e,t){return this._store.has(e,t)}set(e,t,r){var s;this._assertWritablePath("set",e,t,r);const i=this._store;if((((s=this._metaController)==null?void 0:s.size)??0)===0){if(this._derivedController===void 0){i.set(e,t,r);return}this._mutateDerived(i,"set",e,t,r);return}this._mutateWithMetaLifecycle(()=>{this._derivedController===void 0?i.set(e,t,r):this._mutateDerived(i,"set",e,t,r),this._pruneMissingMetaOwners(e,"owner-replaced",r)})}merge(e,t,r){var s;this._assertWritablePath("merge",e,t,r);const i=this._store;if((((s=this._metaController)==null?void 0:s.size)??0)===0){if(this._derivedController===void 0){i.merge(e,t,r);return}this._mutateDerived(i,"merge",e,t,r);return}this._mutateWithMetaLifecycle(()=>{this._derivedController===void 0?i.merge(e,t,r):this._mutateDerived(i,"merge",e,t,r),this._pruneMissingMetaOwners(e,"owner-replaced",r)})}delete(e,t){var i;this._assertWritablePath("delete",e,void 0,t);const r=this._store;if((((i=this._metaController)==null?void 0:i.size)??0)===0){if(this._derivedController===void 0){r.delete(e,t);return}this._mutateDerived(r,"delete",e,void 0,t);return}r.has(e,t)&&this._mutateWithMetaLifecycle(()=>{this._derivedController===void 0?r.delete(e,t):this._mutateDerived(r,"delete",e,void 0,t);const s=this._metaPath(e,t);this._metaController.deleteSubtree(s,"owner-delete"),this._pruneMissingMetaOwners(s,"owner-delete")})}transaction(e){var c,d,v,g;const t=this._store;if(this._derivedController===void 0&&!((c=this._metaController)!=null&&c.hasWatchers))return t.transaction(e);const r=this._transactionDepth===0&&((d=this._metaController)!=null&&d.hasDeferredWatchers)&&this._runtimes!==void 0?[...this._runtimes]:void 0;if(r!==void 0)for(const o of r)(v=o._beginKernelTransaction)==null||v.call(o);let i,s,a=!1;try{i=t.transaction(()=>this._runDerivedTransaction(e))}catch(o){a=!0,s=o}const l=[];if(a&&l.push(s),r!==void 0)for(const o of r)try{(g=o._endKernelTransaction)==null||g.call(o)}catch(m){l.push(m)}if(l.length===1)throw l[0];if(l.length>1)throw new AggregateError(l,"[Raph] Kernel transaction execution failed.");return i}watch(e,t){return this._store.watch(e,t)}getMeta(e,t,r){var i;return this._store,t!==void 0&&this._assertMetaNamespace(t),(i=this._metaController)==null?void 0:i.get(this._metaPath(e,r),t)}hasMeta(e,t,r){var i;return this._store,t!==void 0&&this._assertMetaNamespace(t),((i=this._metaController)==null?void 0:i.has(this._metaPath(e,r),t))??!1}setMeta(e,t,r,i){this._assertMetaNamespace(t);const s=this._exactMetaPath(e,i);this._assertMetaOwner(s),this._metadata.set(s,t,r,i)}mergeMeta(e,t,r,i){this._assertMetaNamespace(t);const s=this._exactMetaPath(e,i);this._assertMetaOwner(s),this._metadata.merge(s,t,r,i)}deleteMeta(e,t,r){var s;t!==void 0&&this._assertMetaNamespace(t);const i=this._exactMetaPath(e,r);(s=this._metaController)==null||s.delete(i,t,r)}_watchMeta(e,t,r={},i){return this._store,r.namespace!==void 0&&this._assertMetaNamespace(r.namespace),this._metadata.watch(e,t,r,i)}derive(e){var d,v,g;if(this._store,e.strategy!==void 0&&e.strategy.kind!=="full"&&e.strategy.kind!=="collection-by-key"&&e.strategy.kind!=="filter-by-key")throw new Error(`[Raph] Unsupported derived strategy "${String(e.strategy.kind)}".`);if(e.id!==void 0&&((d=this._derivedController)!=null&&d.has(e.id)))throw new Error(`[Raph] Duplicate derived id "${e.id}".`);const t=w.parseDataPath(e.from),r=w.parseDataPath(e.to);if(P(t,r))throw new Error("[Raph] Derived source and target must not overlap.");const i=this._derivedController??new E.DerivedRegistry,s=e.id??i.nextId(),a={...e,from:t.canonical,to:r.canonical},l=new C.RaphDerivedHandle(this,s,a),c=((v=e.strategy)==null?void 0:v.kind)==="collection-by-key"||((g=e.strategy)==null?void 0:g.kind)==="filter-by-key"?e.strategy:void 0;this._derivedController=i,i.register(l,t,c);try{e.immediate!==!1&&l.recompute()}catch(o){throw this._removeDerived(l),l._disposeFromKernel(),o}return l}_attachRuntime(e){this._store,(this._runtimes??(this._runtimes=new Set)).add(e)}_detachRuntime(e){const t=this._runtimes;t!==void 0&&(t.delete(e),t.size===0&&(this._runtimes=void 0))}dispose(){var t,r;if(this._paths===void 0)return;const e=[];if(this._runtimes!==void 0)for(const i of[...this._runtimes])try{i.dispose()}catch(s){e.push(s)}if(this._runtimes=void 0,(t=this._derivedController)==null||t.dispose(),this._derivedController=void 0,(r=this._metaController)==null||r.dispose(),this._metaController=void 0,this._paths=void 0,e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,`[Raph] Kernel "${this.id}" disposal failed.`)}_recomputeDerived(e){if(!(e.paused||e.disposed))try{this._recomputeDerivedFull(e),e._recordSuccess()}catch(t){throw e._recordFailure(t),t}}_removeDerived(e){const t=this._derivedController;t!==void 0&&(t.remove(e),t.size===0&&(this._derivedController=void 0))}get _store(){const e=this._paths;if(e!==void 0)return e;throw new Error(`[Raph] Kernel "${this.id}" is disposed.`)}get _metadata(){return this._store,this._metaController??(this._metaController=new R.MetaController(this,e=>this.has(e),()=>this._transactionDepth!==0||this._stabilizing))}_assertWritablePath(e,t,r,i){const s=this._derivedController;if(s===void 0||this._derivedWriteDepth!==0)return;const a=w.parseDataPath(t,i);for(const l of s.values()){const c=w.parseDataPath(l.options.to);if(!P(a,c))continue;const d=a.segments.length<c.segments.length;if(!(e==="merge"&&d&&!S(r,c.segments[a.segments.length])))throw new C.RaphDerivedTargetWriteError(a.canonical)}}_writeDerivedTarget(e,t){this._derivedWriteDepth++;try{this.set(e,t)}finally{this._derivedWriteDepth--}}_mutateDerived(e,t,r,i,s){const a=w.parseDataPath(r,s);t==="delete"&&!e.has(r,s)||e.transaction(()=>{t==="set"?e.set(r,i,s):t==="merge"?e.merge(r,i,s):e.delete(r,s),this._queueDerived(a),this._transactionDepth===0&&!this._stabilizing&&this._stabilizeDerived()})}_runDerivedTransaction(e){var v;let t=!1,r,i=!1,s,a=!1,l,c;this._transactionDepth++;try{c=e()}catch(g){t=!0,r=g}finally{if(this._transactionDepth--,this._transactionDepth===0){if(!this._stabilizing)try{this._stabilizeDerived()}catch(g){i=!0,s=g}try{(v=this._metaController)==null||v.publish()}catch(g){a=!0,l=g}}}const d=[];if(t&&d.push(r),i&&d.push(s),a&&d.push(l),d.length>1)throw new AggregateError(d,"[Raph] Kernel transaction publication failed.");if(d.length===1)throw d[0];return c}_mutateWithMetaLifecycle(e){if(this._transactionDepth!==0||this._stabilizing){e();return}this.transaction(e)}_pruneMissingMetaOwners(e,t,r){var i;(i=this._metaController)==null||i.pruneMissing(this._metaPath(e,r),t)}_metaPath(e,t){return w.DataPath.from(e,t)}_exactMetaPath(e,t){const r=this._metaPath(e,t);if(r.segments().some(i=>i.kind==="wildcard"))throw new Error("[RaphMeta] wildcard paths are read-only observation masks.");return r}_assertMetaNamespace(e){if(this._store,!e.trim())throw new Error("[RaphMeta] namespace must not be empty.")}_assertMetaOwner(e){if(!this.has(e))throw new Error(`[RaphMeta] Owner data path does not exist: "${e}".`)}_queueDerived(e){var t;(t=this._derivedController)==null||t.queue(e)}_queueDerivedReplacement(e,t){var r;(r=this._derivedController)==null||r.queueReplacement(e,t)}_replaceDerivedTarget(e,t,r){const i=w.parseDataPath(e);this._store.set(i.canonical,t),this._queueDerivedReplacement(i,r)}_stabilizeDerived(){const e=this._derivedController,t=e==null?void 0:e.pending;if(t===void 0||t.size===0)return;this._stabilizing=!0;let r=0;try{for(;t.size!==0;){const i=t.values().next().value;if(t.delete(i),!(i.paused||i.disposed)){try{this._recomputePendingDerived(i),i._recordSuccess()}catch(s){throw i._recordFailure(s),s}if(++r>1e4)throw new Error("[Raph] Derived stabilization exceeded 10000 recomputations.")}}}catch(i){throw t.clear(),i}finally{this._stabilizing=!1,e==null||e.clearPendingIfEmpty()}}_recomputePendingDerived(e){var r;const t=(r=this._derivedController)==null?void 0:r.state(e);if(t===void 0||!t.initialized||t.full){this._recomputeDerivedFull(e);return}t.kind==="filter-by-key"?this._recomputeDerivedFilter(e,t):this._recomputeDerivedCollection(e,t)}_recomputeDerivedFull(e){var c;const t=(c=this._derivedController)==null?void 0:c.state(e);t!==void 0&&(t.full=!0);const r=this.get(e.options.from),i=e.options.compute(r);let s=i,a,l;t!==void 0&&(r===void 0&&(i===void 0||Array.isArray(i)&&i.length===0)?(a=new Map,l=new Map):(t.kind==="filter-by-key"?(f.validateFullFilter(e.id,t.key,r,i),s=f.cloneMaterializedValue(i)):f.validateFullCollection(e.id,t.key,r,i),a=f.collectionIndex(r,t.key,"source"),l=f.collectionIndex(s,t.key,"output"))),this._writeDerivedTarget(e.options.to,s),t!==void 0&&(t.sourceIndex=a,t.targetIndex=l,t.initialized=!0,t.full=!1,t.keys.clear())}_recomputeDerivedCollection(e,t){t.full=!0;const r=this.get(e.options.from),i=this.get(e.options.to);if(!Array.isArray(r)||!Array.isArray(i))throw f.collectionError(e.id,"requires array source and target");(t.sourceIndex===void 0||f.indexesAreStale(r,t.key,t.sourceIndex,t.keys))&&(t.sourceIndex=f.collectionIndex(r,t.key,"source"));const s=t.targetIndex;if(s===void 0)throw f.collectionError(e.id,"has no materialized target index");const a=[],l=[];for(const o of t.keys){const m=t.sourceIndex.get(o);m===void 0?l.push(o):a.push({key:o,index:m,item:r[m]})}a.sort((o,m)=>o.index-m.index);const c=a.map(o=>o.item),d=c.length===0?[]:e.options.compute(c);f.validateIncrementalCollection(e.id,t.key,a.map(o=>o.key),d);const v=d;if(l.length!==0||a.some(o=>!s.has(o.key))){const o=new Map;for(let u=0;u<a.length;u++)o.set(a[u].key,v[u]);const m=new Map;for(const[u,y]of s)m.set(u,i[y]);const n=f.collectionKeys(r,t.key,"source"),h=[];h.length=n.length;for(let u=0;u<n.length;u++){const y=n[u];if(y===void 0)continue;const D=o.has(y)?o.get(y):m.get(y);if(D===void 0)throw f.collectionError(e.id,`is missing target item for key "${String(y)}"`);h[u]=D}const p=f.collectionIndex(h,t.key,"target");this._replaceDerivedTarget(e.options.to,h,t.keys),t.targetIndex=p}else for(let o=0;o<a.length;o++)this._writeDerivedTarget(f.keyedPath(e.options.to,t.key,a[o].key),v[o]);t.keys.clear(),t.full=!1}_recomputeDerivedFilter(e,t){t.full=!0;const r=this.get(e.options.from),i=this.get(e.options.to);if(!Array.isArray(r)||!Array.isArray(i))throw f.filterError(e.id,"requires array source and target");(t.sourceIndex===void 0||f.indexesAreStale(r,t.key,t.sourceIndex,t.keys))&&(t.sourceIndex=f.collectionIndex(r,t.key,"source"));const s=t.targetIndex;if(s===void 0)throw f.filterError(e.id,"has no materialized target index");const a=[];for(const n of t.keys){const h=t.sourceIndex.get(n);h!==void 0&&a.push({key:n,index:h,item:r[h]})}a.sort((n,h)=>n.index-h.index);const l=a.map(n=>n.item),c=l.length===0?[]:e.options.compute(l);f.validateIncrementalFilter(e.id,t.key,a.map(n=>n.key),c);const d=new Map,v=c,g=f.collectionKeys(v,t.key,"output");for(let n=0;n<g.length;n++){const h=g[n];h!==void 0&&d.set(h,f.cloneMaterializedValue(v[n]))}const o=new Set;let m=!1;for(const n of t.keys){const h=s.has(n),p=d.has(n);!h&&!p||(o.add(n),h!==p&&(m=!0))}if(m&&t.keys.size===1&&i.length===s.size&&this._patchSingleFilterMembership(e,t,i,s,d,o)){t.keys.clear(),t.full=!1;return}if(m){const n=new Map;for(const[u,y]of s)n.set(u,i[y]);const h=[];for(const u of f.collectionKeys(r,t.key,"source"))if(u!==void 0){if(t.keys.has(u)){d.has(u)&&h.push(d.get(u));continue}n.has(u)&&h.push(n.get(u))}const p=f.collectionIndex(h,t.key,"target");this._replaceDerivedTarget(e.options.to,h,o),t.targetIndex=p}else for(const[n,h]of d)this._writeDerivedTarget(f.keyedPath(e.options.to,t.key,n),h);t.keys.clear(),t.full=!1}_patchSingleFilterMembership(e,t,r,i,s,a){const l=t.sourceIndex;if(l===void 0)return!1;const c=t.keys.values().next().value;if(c===void 0)return!1;const d=i.get(c),v=s.has(c);if(d!==void 0===v)return!1;const g=r.slice();let o;if(d!==void 0)o=d,g.splice(o,1);else{const m=l.get(c);if(m===void 0)return!1;let n=0,h=g.length;for(;n<h;){const p=n+h>>>1,u=g[p];if(typeof u!="object"||u===null||Array.isArray(u))return!1;const y=u[t.key];if(typeof y!="string"&&typeof y!="number")return!1;const D=l.get(y);if(D===void 0)return!1;D<m?n=p+1:h=p}o=n,g.splice(o,0,s.get(c))}if(this._replaceDerivedTarget(e.options.to,g,a),d!==void 0){i.delete(c);for(const[m,n]of i)n>o&&i.set(m,n-1)}else{for(const[m,n]of i)n>=o&&i.set(m,n+1);i.set(c,o)}return!0}};k(x,"_kernelCounter",0);let b=x;function P(_,e){const t=Math.min(_.segments.length,e.segments.length);for(let r=0;r<t;r++)if(!F(_.segments[r],e.segments[r]))return!1;return!0}function S(_,e){return typeof _!="object"||_===null||Array.isArray(_)||e.kind!=="key"?!0:Object.hasOwn(_,e.key)}function F(_,e){return _.kind!==e.kind?!1:_.kind==="key"&&e.kind==="key"?_.key===e.key:_.kind==="index"&&e.kind==="index"?_.index===e.index:_.kind==="selector"&&e.kind==="selector"&&_.key===e.key&&Object.is(_.value,e.value)}exports.RaphKernel=b;