@raphy-js/raph 1.0.1-dev.20 → 1.0.1-dev.26

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 (107) hide show
  1. package/dist/{core-CyilRD7s.js → core-CClhT8WR.js} +389 -400
  2. package/dist/core-cPQWYD4K.cjs +1 -0
  3. package/dist/debug/api/Raph.cjs +1 -1
  4. package/dist/debug/api/Raph.js +46 -47
  5. package/dist/debug/api/RaphFacadeSession.cjs +1 -1
  6. package/dist/debug/api/RaphFacadeSession.js +85 -89
  7. package/dist/debug/api/RaphReactivityInstance.cjs +1 -1
  8. package/dist/debug/api/RaphReactivityInstance.js +27 -30
  9. package/dist/debug/path/DataPath.cjs +1 -1
  10. package/dist/debug/path/DataPath.js +198 -202
  11. package/dist/debug/path/PathRouter.cjs +1 -1
  12. package/dist/debug/path/PathRouter.js +44 -50
  13. package/dist/debug/path/RaphKernel.cjs +1 -1
  14. package/dist/debug/path/RaphKernel.js +257 -228
  15. package/dist/debug/path/data-path.utils.cjs +1 -1
  16. package/dist/debug/path/data-path.utils.js +41 -41
  17. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -1
  18. package/dist/debug/path/derived/DerivedRegistry.js +52 -66
  19. package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -1
  20. package/dist/debug/path/derived/RaphDerivedHandle.js +19 -22
  21. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -1
  22. package/dist/debug/path/derived/derived-collection.utils.js +70 -70
  23. package/dist/debug/path/meta/MetaController.cjs +1 -1
  24. package/dist/debug/path/meta/MetaController.js +57 -65
  25. package/dist/debug/path/meta/RaphMeta.cjs +1 -1
  26. package/dist/debug/path/meta/RaphMeta.js +26 -32
  27. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -1
  28. package/dist/debug/path/meta/RaphMetaStore.js +24 -30
  29. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -1
  30. package/dist/debug/path/storage/AdapterPathStore.js +49 -54
  31. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -1
  32. package/dist/debug/path/storage/DefaultDataAdapter.js +46 -56
  33. package/dist/debug/path/storage/PathEventHub.cjs +1 -1
  34. package/dist/debug/path/storage/PathEventHub.js +74 -61
  35. package/dist/debug/path/storage/PathStore.cjs +1 -1
  36. package/dist/debug/path/storage/PathStore.js +89 -99
  37. package/dist/debug/path/storage/createDataDraft.cjs +1 -1
  38. package/dist/debug/path/storage/createDataDraft.js +24 -28
  39. package/dist/debug/reactivity/disposal.cjs +1 -0
  40. package/dist/debug/reactivity/disposal.js +32 -0
  41. package/dist/debug/reactivity/engine.cjs +1 -1
  42. package/dist/debug/reactivity/engine.js +787 -392
  43. package/dist/debug/reactivity/reactive-object.cjs +1 -1
  44. package/dist/debug/reactivity/reactive-object.js +81 -96
  45. package/dist/debug/reactivity/scope.cjs +1 -1
  46. package/dist/debug/reactivity/scope.js +221 -117
  47. package/dist/debug/reactivity/watch.cjs +1 -1
  48. package/dist/debug/reactivity/watch.js +1 -1
  49. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  50. package/dist/debug/runtime/RaphRuntime.js +764 -411
  51. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
  52. package/dist/debug/runtime/diagnostics/RaphDebug.js +90 -100
  53. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -1
  54. package/dist/debug/runtime/ownership/RaphEffectScope.js +215 -82
  55. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
  56. package/dist/debug/runtime/ownership/RaphNode.js +595 -136
  57. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
  58. package/dist/debug/runtime/ownership/RaphScope.js +203 -68
  59. package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -1
  60. package/dist/debug/runtime/phases/RaphFrameLoop.js +13 -17
  61. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
  62. package/dist/debug/runtime/phases/RaphPhasePipeline.js +618 -357
  63. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
  64. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
  65. package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
  66. package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -0
  67. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -1
  68. package/dist/debug/runtime/reactivity/PathHandle.js +50 -60
  69. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -1
  70. package/dist/debug/runtime/reactivity/RaphMetaSource.js +28 -32
  71. package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
  72. package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
  73. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -1
  74. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +541 -379
  75. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
  76. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +484 -90
  77. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -1
  78. package/dist/debug/runtime/reactivity/RuntimeWatch.js +33 -44
  79. package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
  80. package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
  81. package/dist/entrypoints/runtime.d.ts +2 -1
  82. package/dist/machine-testing.cjs +1 -1
  83. package/dist/machine-testing.js +1 -1
  84. package/dist/machine.cjs +1 -1
  85. package/dist/machine.js +216 -231
  86. package/dist/path/RaphKernel.d.ts +24 -0
  87. package/dist/path/storage/PathEventHub.d.ts +14 -0
  88. package/dist/path/storage/PathStore.d.ts +4 -4
  89. package/dist/reactivity/disposal.d.ts +14 -0
  90. package/dist/reactivity/engine.d.ts +177 -4
  91. package/dist/reactivity/scope.d.ts +108 -30
  92. package/dist/runtime/RaphRuntime.d.ts +236 -17
  93. package/dist/runtime/ownership/RaphEffectScope.d.ts +70 -1
  94. package/dist/runtime/ownership/RaphNode.d.ts +276 -6
  95. package/dist/runtime/ownership/RaphScope.d.ts +144 -14
  96. package/dist/runtime/phases/RaphPhasePipeline.d.ts +202 -28
  97. package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
  98. package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
  99. package/dist/runtime/phases/phase.types.d.ts +83 -4
  100. package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
  101. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +163 -25
  102. package/dist/runtime/reactivity/RuntimeReactivity.d.ts +258 -10
  103. package/dist/runtime/reactivity/RuntimeWatch.d.ts +8 -8
  104. package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
  105. package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +48 -3
  106. package/package.json +10 -2
  107. package/dist/core-ugchZNqC.cjs +0 -1
@@ -1,44 +1,48 @@
1
- var F = Object.defineProperty;
2
- var O = (_, e, t) => e in _ ? F(_, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : _[e] = t;
3
- var y = (_, e, t) => O(_, typeof e != "symbol" ? e + "" : e, t);
4
- import { parseDataPath as w } from "./data-path.utils.js";
5
- import { DataPath as T } from "./DataPath.js";
6
- import { validateFullFilter as S, cloneMaterializedValue as C, validateFullCollection as W, collectionIndex as k, collectionError as b, indexesAreStale as z, validateIncrementalCollection as B, collectionKeys as x, keyedPath as A, filterError as P, validateIncrementalFilter as K } from "./derived/derived-collection.utils.js";
7
- import { DerivedRegistry as q } from "./derived/DerivedRegistry.js";
8
- import { RaphDerivedHandle as N, RaphDerivedTargetWriteError as $ } from "./derived/RaphDerivedHandle.js";
9
- import { MetaController as j } from "./meta/MetaController.js";
10
- import { AdapterPathStore as R } from "./storage/AdapterPathStore.js";
11
- import { DefaultDataAdapter as L } from "./storage/DefaultDataAdapter.js";
12
- import { PathStore as H } from "./storage/PathStore.js";
13
- const M = class M {
1
+ import { parseDataPath as p } from "./data-path.utils.js";
2
+ import { DataPath as B } from "./DataPath.js";
3
+ import { validateFullFilter as I, cloneMaterializedValue as M, validateFullCollection as E, collectionIndex as w, collectionError as D, indexesAreStale as x, validateIncrementalCollection as F, collectionKeys as b, keyedPath as C, filterError as R, validateIncrementalFilter as K } from "./derived/derived-collection.utils.js";
4
+ import { DerivedRegistry as O } from "./derived/DerivedRegistry.js";
5
+ import { RaphDerivedHandle as S, RaphDerivedTargetWriteError as T } from "./derived/RaphDerivedHandle.js";
6
+ import { MetaController as W } from "./meta/MetaController.js";
7
+ import { AdapterPathStore as z } from "./storage/AdapterPathStore.js";
8
+ import { DefaultDataAdapter as q } from "./storage/DefaultDataAdapter.js";
9
+ import { PathStore as N } from "./storage/PathStore.js";
10
+ class P {
11
+ // Формирует локальный id для Kernel без явно заданного имени.
12
+ static _kernelCounter = 0;
13
+ // Публикует стабильную identity data/meta owner.
14
+ id;
15
+ // Лениво создают независимые data, derived, runtime и metadata controllers.
16
+ _paths;
17
+ _derivedController;
18
+ _runtimes;
19
+ _metaController;
20
+ // Что читает `_openSoleRuntimeBatch()`: единственный присоединённый Runtime
21
+ // и владелец batch boundary встроенного store. Первое пусто, пока Runtime
22
+ // нет либо их несколько; второе — у store над adapter и после dispose.
23
+ _soleRuntime;
24
+ _pathBatch;
25
+ // Защищают batch stabilization и записи в derived targets.
26
+ _batchDepth = 0;
27
+ _runtimeMutationDepth = 0;
28
+ _stabilizing = !1;
29
+ _derivedWriteDepth = 0;
14
30
  /**
15
31
  * Создаёт data/meta owner с независимым lifecycle и derived registry.
16
32
  */
17
33
  constructor(e = {}) {
18
- // Публикует стабильную identity data/meta owner.
19
- y(this, "id");
20
- // Лениво создают независимые data, derived, runtime и metadata controllers.
21
- y(this, "_paths");
22
- y(this, "_derivedController");
23
- y(this, "_runtimes");
24
- y(this, "_metaController");
25
- // Защищают batch stabilization и записи в derived targets.
26
- y(this, "_batchDepth", 0);
27
- y(this, "_runtimeMutationDepth", 0);
28
- y(this, "_stabilizing", !1);
29
- y(this, "_derivedWriteDepth", 0);
30
- if (this.id = e.id ?? `kernel-${M._kernelCounter++}`, e.adapter !== void 0) {
34
+ if (this.id = e.id ?? `kernel-${P._kernelCounter++}`, e.adapter !== void 0) {
31
35
  if (e.initial !== void 0 || e.adapterOptions !== void 0)
32
36
  throw new TypeError("[Raph] A custom adapter cannot be combined with initial or adapterOptions.");
33
- this._paths = new R(e.adapter);
37
+ this._paths = new z(e.adapter);
34
38
  } else if (e.adapterOptions !== void 0)
35
- this._paths = new R(new L(
39
+ this._paths = new z(new q(
36
40
  e.initial,
37
41
  e.adapterOptions
38
42
  ));
39
43
  else {
40
- const t = this._paths = new H();
41
- e.initial !== void 0 && t.set("", e.initial);
44
+ const t = this._paths = new N();
45
+ this._pathBatch = t._batchHub, e.initial !== void 0 && t.set("", e.initial);
42
46
  }
43
47
  }
44
48
  /**
@@ -51,12 +55,11 @@ const M = class M {
51
55
  * Формирует диагностический снимок materialized derived registry.
52
56
  */
53
57
  getDerivedSnapshot() {
54
- var t;
55
58
  const e = this._derivedController;
56
59
  return {
57
- registrations: (e == null ? void 0 : e.size) ?? 0,
58
- errors: [...(e == null ? void 0 : e.values()) ?? []].filter((r) => r.status === "error").length,
59
- pending: ((t = e == null ? void 0 : e.pending) == null ? void 0 : t.size) ?? 0,
60
+ registrations: e?.size ?? 0,
61
+ errors: [...e?.values() ?? []].filter((t) => t.status === "error").length,
62
+ pending: e?.pending?.size ?? 0,
60
63
  stabilizing: this._stabilizing
61
64
  };
62
65
  }
@@ -82,14 +85,13 @@ const M = class M {
82
85
  * Записывает значение и публикует соответствующее изменение.
83
86
  */
84
87
  set(e, t, r) {
85
- var s;
86
88
  if (this._runtimeMutationDepth === 0 && this._runtimes !== void 0) {
87
89
  this._withAttachedRuntimeBoundary(() => this.set(e, t, r));
88
90
  return;
89
91
  }
90
92
  this._assertWritablePath("set", e, t, r);
91
93
  const i = this._store;
92
- if ((((s = this._metaController) == null ? void 0 : s.size) ?? 0) === 0) {
94
+ if ((this._metaController?.size ?? 0) === 0) {
93
95
  if (this._derivedController === void 0) {
94
96
  i.set(e, t, r);
95
97
  return;
@@ -105,14 +107,13 @@ const M = class M {
105
107
  * Объединяет значение по пути и публикует соответствующее изменение.
106
108
  */
107
109
  merge(e, t, r) {
108
- var s;
109
110
  if (this._runtimeMutationDepth === 0 && this._runtimes !== void 0) {
110
111
  this._withAttachedRuntimeBoundary(() => this.merge(e, t, r));
111
112
  return;
112
113
  }
113
114
  this._assertWritablePath("merge", e, t, r);
114
115
  const i = this._store;
115
- if ((((s = this._metaController) == null ? void 0 : s.size) ?? 0) === 0) {
116
+ if ((this._metaController?.size ?? 0) === 0) {
116
117
  if (this._derivedController === void 0) {
117
118
  i.merge(e, t, r);
118
119
  return;
@@ -128,14 +129,13 @@ const M = class M {
128
129
  * Удаляет значение по пути и публикует изменение при наличии данных.
129
130
  */
130
131
  delete(e, t) {
131
- var i;
132
132
  if (this._runtimeMutationDepth === 0 && this._runtimes !== void 0) {
133
133
  this._withAttachedRuntimeBoundary(() => this.delete(e, t));
134
134
  return;
135
135
  }
136
136
  this._assertWritablePath("delete", e, void 0, t);
137
137
  const r = this._store;
138
- if ((((i = this._metaController) == null ? void 0 : i.size) ?? 0) === 0) {
138
+ if ((this._metaController?.size ?? 0) === 0) {
139
139
  if (this._derivedController === void 0) {
140
140
  r.delete(e, t);
141
141
  return;
@@ -145,30 +145,72 @@ const M = class M {
145
145
  }
146
146
  r.has(e, t) && this._mutateWithMetaLifecycle(() => {
147
147
  this._derivedController === void 0 ? r.delete(e, t) : this._mutateDerived(r, "delete", e, void 0, t);
148
- const s = this._metaPath(e, t);
149
- this._metaController.deleteSubtree(s, "owner-delete"), this._pruneMissingMetaOwners(s, "owner-delete");
148
+ const i = this._metaPath(e, t);
149
+ this._metaController.deleteSubtree(i, "owner-delete"), this._pruneMissingMetaOwners(i, "owner-delete");
150
150
  });
151
151
  }
152
152
  /**
153
153
  * Выполняет операцию в общей синхронной batch boundary.
154
154
  */
155
155
  batch(e) {
156
- var o;
157
156
  if (this._runtimeMutationDepth === 0 && this._runtimes !== void 0)
158
157
  return this._withAttachedRuntimeBoundary(() => this.batch(e));
159
158
  const t = this._store;
160
- if (this._derivedController === void 0 && !((o = this._metaController) != null && o.hasWatchers))
159
+ if (this._derivedController === void 0 && !this._metaController?.hasWatchers)
161
160
  return t.batch(e);
162
161
  let r, i, s = !1;
163
162
  try {
164
163
  r = t.batch(() => this._runDerivedBatch(e));
165
- } catch (h) {
166
- s = !0, i = h;
164
+ } catch (o) {
165
+ s = !0, i = o;
167
166
  }
168
167
  if (s)
169
168
  throw i;
170
169
  return r;
171
170
  }
171
+ /**
172
+ * Открывает то же, что `batch()`, для единственного присоединённого Runtime
173
+ * без closure операции и без массивов: границу этого Runtime и path batch.
174
+ * Возвращает владельца path batch, которого вызывающий передаёт в
175
+ * `_closeSoleRuntimeBatch()` после операции.
176
+ *
177
+ * Возвращает `undefined` и ничего не открывает в любом другом состоянии:
178
+ * Kernel разделяют несколько Runtime, граница Runtime уже открыта, есть
179
+ * derived handles либо metadata watchers, store построен над adapter. Тогда
180
+ * вызывающий исполняет `batch()`. Состояние читается при входе, как в
181
+ * `batch()`: то, что появилось во время операции, выход не меняет.
182
+ * @internal
183
+ */
184
+ _openSoleRuntimeBatch(e) {
185
+ const t = this._pathBatch;
186
+ if (!(this._soleRuntime !== e || t === void 0 || this._runtimeMutationDepth !== 0 || this._derivedController !== void 0 || this._metaController?.hasWatchers === !0))
187
+ return this._runtimeMutationDepth++, e._beginKernelBatch?.(), t._openBatch(), t;
188
+ }
189
+ /**
190
+ * Закрывает границу, открытую `_openSoleRuntimeBatch()`, в порядке `batch()`:
191
+ * публикация path events, затем граница Runtime. Бросает то же, что бросил бы
192
+ * `batch()` с этой операцией; после успешного выхода возвращает управление.
193
+ * @internal
194
+ */
195
+ _closeSoleRuntimeBatch(e, t, r, i) {
196
+ let s = r, o = i;
197
+ try {
198
+ t._closeBatch(r, i);
199
+ } catch (n) {
200
+ s = !0, o = n;
201
+ }
202
+ this._runtimeMutationDepth--;
203
+ try {
204
+ e._endKernelBatch?.();
205
+ } catch (n) {
206
+ throw s ? new AggregateError(
207
+ [o, n],
208
+ "[Raph] Kernel mutation and Runtime publication failed."
209
+ ) : n;
210
+ }
211
+ if (s)
212
+ throw o;
213
+ }
172
214
  /**
173
215
  * Подписывает callback на подходящие изменения и возвращает disposer.
174
216
  */
@@ -179,15 +221,13 @@ const M = class M {
179
221
  * Возвращает metadata указанного data-owner.
180
222
  */
181
223
  getMeta(e, t, r) {
182
- var i;
183
- return this._store, t !== void 0 && this._assertMetaNamespace(t), (i = this._metaController) == null ? void 0 : i.get(this._metaPath(e, r), t);
224
+ return this._store, t !== void 0 && this._assertMetaNamespace(t), this._metaController?.get(this._metaPath(e, r), t);
184
225
  }
185
226
  /**
186
227
  * Проверяет наличие metadata у указанного data-owner.
187
228
  */
188
229
  hasMeta(e, t, r) {
189
- var i;
190
- return this._store, t !== void 0 && this._assertMetaNamespace(t), ((i = this._metaController) == null ? void 0 : i.has(this._metaPath(e, r), t)) ?? !1;
230
+ return this._store, t !== void 0 && this._assertMetaNamespace(t), this._metaController?.has(this._metaPath(e, r), t) ?? !1;
191
231
  }
192
232
  /**
193
233
  * Записывает metadata указанного data-owner.
@@ -217,14 +257,13 @@ const M = class M {
217
257
  * Удаляет metadata указанного data-owner.
218
258
  */
219
259
  deleteMeta(e, t, r) {
220
- var s;
221
260
  if (this._runtimeMutationDepth === 0 && this._runtimes !== void 0) {
222
261
  this._withAttachedRuntimeBoundary(() => this.deleteMeta(e, t, r));
223
262
  return;
224
263
  }
225
264
  t !== void 0 && this._assertMetaNamespace(t);
226
265
  const i = this._exactMetaPath(e, r);
227
- (s = this._metaController) == null || s.delete(i, t, r);
266
+ this._metaController?.delete(i, t, r);
228
267
  }
229
268
  /**
230
269
  * Подписывает runtime adapter на metadata-события Kernel.
@@ -237,33 +276,34 @@ const M = class M {
237
276
  * Создаёт управляемое derived-представление source path в target path.
238
277
  */
239
278
  derive(e) {
240
- var d, u, m;
241
279
  if (this._store, e.strategy !== void 0 && e.strategy.kind !== "full" && e.strategy.kind !== "collection-by-key" && e.strategy.kind !== "filter-by-key")
242
280
  throw new Error(`[Raph] Unsupported derived strategy "${String(e.strategy.kind)}".`);
243
- if (e.id !== void 0 && ((d = this._derivedController) != null && d.has(e.id)))
281
+ if (e.id !== void 0 && this._derivedController?.has(e.id))
244
282
  throw new Error(`[Raph] Duplicate derived id "${e.id}".`);
245
- const t = w(e.from), r = w(e.to);
246
- if (E(t, r))
283
+ const t = p(e.from), r = p(e.to);
284
+ if (A(t, r))
247
285
  throw new Error("[Raph] Derived source and target must not overlap.");
248
- const i = this._derivedController ?? new q(), s = e.id ?? i.nextId(), o = {
286
+ const i = this._derivedController ?? new O(), s = e.id ?? i.nextId(), o = {
249
287
  ...e,
250
288
  from: t.canonical,
251
289
  to: r.canonical
252
- }, h = new N(this, s, o), l = ((u = e.strategy) == null ? void 0 : u.kind) === "collection-by-key" || ((m = e.strategy) == null ? void 0 : m.kind) === "filter-by-key" ? e.strategy : void 0;
253
- this._derivedController = i, i.register(h, t, l);
290
+ }, n = new S(this, s, o), c = e.strategy?.kind === "collection-by-key" || e.strategy?.kind === "filter-by-key" ? e.strategy : void 0;
291
+ this._derivedController = i, i.register(n, t, c);
254
292
  try {
255
- e.immediate !== !1 && h.recompute();
256
- } catch (a) {
257
- throw this._removeDerived(h), h._disposeFromKernel(), a;
293
+ e.immediate !== !1 && n.recompute();
294
+ } catch (l) {
295
+ throw this._removeDerived(n), n._disposeFromKernel(), l;
258
296
  }
259
- return h;
297
+ return n;
260
298
  }
261
299
  /**
262
300
  * Регистрирует runtime, разделяющий этот Kernel.
263
301
  * @internal
264
302
  */
265
303
  _attachRuntime(e) {
266
- this._store, (this._runtimes ?? (this._runtimes = /* @__PURE__ */ new Set())).add(e);
304
+ this._store;
305
+ const t = this._runtimes ??= /* @__PURE__ */ new Set();
306
+ t.add(e), this._soleRuntime = t.size === 1 ? e : void 0;
267
307
  }
268
308
  /**
269
309
  * Удаляет runtime из shared Kernel registry.
@@ -271,24 +311,23 @@ const M = class M {
271
311
  */
272
312
  _detachRuntime(e) {
273
313
  const t = this._runtimes;
274
- t !== void 0 && (t.delete(e), t.size === 0 && (this._runtimes = void 0));
314
+ t !== void 0 && (t.delete(e), t.size === 0 && (this._runtimes = void 0), this._soleRuntime = t.size === 1 ? t.values().next().value : void 0);
275
315
  }
276
316
  /**
277
317
  * Освобождает shared runtimes, derived handles и data/meta state Kernel.
278
318
  */
279
319
  dispose() {
280
- var t, r;
281
320
  if (this._paths === void 0)
282
321
  return;
283
322
  const e = [];
284
323
  if (this._runtimes !== void 0)
285
- for (const i of [...this._runtimes])
324
+ for (const t of [...this._runtimes])
286
325
  try {
287
- i.dispose();
288
- } catch (s) {
289
- e.push(s);
326
+ t.dispose();
327
+ } catch (r) {
328
+ e.push(r);
290
329
  }
291
- 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)
330
+ if (this._runtimes = void 0, this._soleRuntime = void 0, this._derivedController?.dispose(), this._derivedController = void 0, this._metaController?.dispose(), this._metaController = void 0, this._paths = void 0, this._pathBatch = void 0, e.length === 1)
292
331
  throw e[0];
293
332
  if (e.length > 1)
294
333
  throw new AggregateError(e, `[Raph] Kernel "${this.id}" disposal failed.`);
@@ -320,15 +359,14 @@ const M = class M {
320
359
  throw new Error(`[Raph] Kernel "${this.id}" is disposed.`);
321
360
  }
322
361
  get _metadata() {
323
- return this._store, this._metaController ?? (this._metaController = new j(
362
+ return this._store, this._metaController ??= new W(
324
363
  this,
325
364
  (e) => this.has(e),
326
365
  () => this._batchDepth !== 0 || this._stabilizing
327
- ));
366
+ );
328
367
  }
329
368
  /** Keeps every attached Runtime quiescent until one Kernel publication completes. */
330
369
  _withAttachedRuntimeBoundary(e) {
331
- var h, l, d;
332
370
  const t = this._runtimes === void 0 ? [] : [...this._runtimes];
333
371
  if (t.length === 0)
334
372
  return e();
@@ -336,22 +374,22 @@ const M = class M {
336
374
  let s, o = !1;
337
375
  this._runtimeMutationDepth++;
338
376
  try {
339
- for (const u of t)
340
- (h = u._beginKernelBatch) == null || h.call(u), r.push(u);
377
+ for (const n of t)
378
+ n._beginKernelBatch?.(), r.push(n);
341
379
  try {
342
380
  s = e();
343
- } catch (u) {
344
- o = !0, i.push(u);
381
+ } catch (n) {
382
+ o = !0, i.push(n);
345
383
  }
346
- } catch (u) {
347
- o = !0, i.push(u);
384
+ } catch (n) {
385
+ o = !0, i.push(n);
348
386
  } finally {
349
387
  this._runtimeMutationDepth--;
350
- for (let u = r.length - 1; u >= 0; u--)
388
+ for (let n = r.length - 1; n >= 0; n--)
351
389
  try {
352
- (d = (l = r[u])._endKernelBatch) == null || d.call(l);
353
- } catch (m) {
354
- i.push(m);
390
+ r[n]._endKernelBatch?.();
391
+ } catch (c) {
392
+ i.push(c);
355
393
  }
356
394
  }
357
395
  if (i.length === 1)
@@ -367,14 +405,14 @@ const M = class M {
367
405
  const s = this._derivedController;
368
406
  if (s === void 0 || this._derivedWriteDepth !== 0)
369
407
  return;
370
- const o = w(t, i);
371
- for (const h of s.values()) {
372
- const l = w(h.options.to);
373
- if (!E(o, l))
408
+ const o = p(t, i);
409
+ for (const n of s.values()) {
410
+ const c = p(n.options.to);
411
+ if (!A(o, c))
374
412
  continue;
375
- const d = o.segments.length < l.segments.length;
376
- if (!(e === "merge" && d && !U(r, l.segments[o.segments.length])))
377
- throw new $(o.canonical);
413
+ const l = o.segments.length < c.segments.length;
414
+ if (!(e === "merge" && l && !$(r, c.segments[o.segments.length])))
415
+ throw new T(o.canonical);
378
416
  }
379
417
  }
380
418
  _writeDerivedTarget(e, t) {
@@ -386,17 +424,16 @@ const M = class M {
386
424
  }
387
425
  }
388
426
  _mutateDerived(e, t, r, i, s) {
389
- const o = w(r, s);
427
+ const o = p(r, s);
390
428
  t === "delete" && !e.has(r, s) || e.batch(() => {
391
429
  t === "set" ? e.set(r, i, s) : t === "merge" ? e.merge(r, i, s) : e.delete(r, s), this._queueDerived(o), this._batchDepth === 0 && !this._stabilizing && this._stabilizeDerived();
392
430
  });
393
431
  }
394
432
  _runDerivedBatch(e) {
395
- var u;
396
- let t = !1, r, i = !1, s, o = !1, h, l;
433
+ let t = !1, r, i = !1, s, o = !1, n, c;
397
434
  this._batchDepth++;
398
435
  try {
399
- l = e();
436
+ c = e();
400
437
  } catch (m) {
401
438
  t = !0, r = m;
402
439
  } finally {
@@ -408,21 +445,21 @@ const M = class M {
408
445
  i = !0, s = m;
409
446
  }
410
447
  try {
411
- (u = this._metaController) == null || u.publish();
448
+ this._metaController?.publish();
412
449
  } catch (m) {
413
- o = !0, h = m;
450
+ o = !0, n = m;
414
451
  }
415
452
  }
416
453
  }
417
- const d = [];
418
- if (t && d.push(r), i && d.push(s), o && d.push(h), d.length > 1)
454
+ const l = [];
455
+ if (t && l.push(r), i && l.push(s), o && l.push(n), l.length > 1)
419
456
  throw new AggregateError(
420
- d,
457
+ l,
421
458
  "[Raph] Kernel batch publication failed."
422
459
  );
423
- if (d.length === 1)
424
- throw d[0];
425
- return l;
460
+ if (l.length === 1)
461
+ throw l[0];
462
+ return c;
426
463
  }
427
464
  _mutateWithMetaLifecycle(e) {
428
465
  if (this._batchDepth !== 0 || this._stabilizing) {
@@ -432,11 +469,10 @@ const M = class M {
432
469
  this.batch(e);
433
470
  }
434
471
  _pruneMissingMetaOwners(e, t, r) {
435
- var i;
436
- (i = this._metaController) == null || i.pruneMissing(this._metaPath(e, r), t);
472
+ this._metaController?.pruneMissing(this._metaPath(e, r), t);
437
473
  }
438
474
  _metaPath(e, t) {
439
- return T.from(e, t);
475
+ return B.from(e, t);
440
476
  }
441
477
  _exactMetaPath(e, t) {
442
478
  const r = this._metaPath(e, t);
@@ -453,19 +489,17 @@ const M = class M {
453
489
  throw new Error(`[RaphMeta] Owner data path does not exist: "${e}".`);
454
490
  }
455
491
  _queueDerived(e) {
456
- var t;
457
- (t = this._derivedController) == null || t.queue(e);
492
+ this._derivedController?.queue(e);
458
493
  }
459
494
  _queueDerivedReplacement(e, t) {
460
- var r;
461
- (r = this._derivedController) == null || r.queueReplacement(e, t);
495
+ this._derivedController?.queueReplacement(e, t);
462
496
  }
463
497
  _replaceDerivedTarget(e, t, r) {
464
- const i = w(e);
498
+ const i = p(e);
465
499
  this._store.set(i.canonical, t), this._queueDerivedReplacement(i, r);
466
500
  }
467
501
  _stabilizeDerived() {
468
- const e = this._derivedController, t = e == null ? void 0 : e.pending;
502
+ const e = this._derivedController, t = e?.pending;
469
503
  if (t === void 0 || t.size === 0)
470
504
  return;
471
505
  this._stabilizing = !0;
@@ -486,12 +520,11 @@ const M = class M {
486
520
  } catch (i) {
487
521
  throw t.clear(), i;
488
522
  } finally {
489
- this._stabilizing = !1, e == null || e.clearPendingIfEmpty();
523
+ this._stabilizing = !1, e?.clearPendingIfEmpty();
490
524
  }
491
525
  }
492
526
  _recomputePendingDerived(e) {
493
- var r;
494
- const t = (r = this._derivedController) == null ? void 0 : r.state(e);
527
+ const t = this._derivedController?.state(e);
495
528
  if (t === void 0 || !t.initialized || t.full) {
496
529
  this._recomputeDerivedFull(e);
497
530
  return;
@@ -499,61 +532,60 @@ const M = class M {
499
532
  t.kind === "filter-by-key" ? this._recomputeDerivedFilter(e, t) : this._recomputeDerivedCollection(e, t);
500
533
  }
501
534
  _recomputeDerivedFull(e) {
502
- var l;
503
- const t = (l = this._derivedController) == null ? void 0 : l.state(e);
535
+ const t = this._derivedController?.state(e);
504
536
  t !== void 0 && (t.full = !0);
505
537
  const r = this.get(e.options.from), i = e.options.compute(r);
506
- let s = i, o, h;
507
- t !== void 0 && (r === void 0 && (i === void 0 || Array.isArray(i) && i.length === 0) ? (o = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map()) : (t.kind === "filter-by-key" ? (S(e.id, t.key, r, i), s = C(i)) : W(e.id, t.key, r, i), o = k(r, t.key, "source"), h = k(s, t.key, "output"))), this._writeDerivedTarget(e.options.to, s), t !== void 0 && (t.sourceIndex = o, t.targetIndex = h, t.initialized = !0, t.full = !1, t.keys.clear());
538
+ let s = i, o, n;
539
+ t !== void 0 && (r === void 0 && (i === void 0 || Array.isArray(i) && i.length === 0) ? (o = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map()) : (t.kind === "filter-by-key" ? (I(e.id, t.key, r, i), s = M(i)) : E(e.id, t.key, r, i), o = w(r, t.key, "source"), n = w(s, t.key, "output"))), this._writeDerivedTarget(e.options.to, s), t !== void 0 && (t.sourceIndex = o, t.targetIndex = n, t.initialized = !0, t.full = !1, t.keys.clear());
508
540
  }
509
541
  _recomputeDerivedCollection(e, t) {
510
542
  t.full = !0;
511
543
  const r = this.get(e.options.from), i = this.get(e.options.to);
512
544
  if (!Array.isArray(r) || !Array.isArray(i))
513
- throw b(e.id, "requires array source and target");
514
- (t.sourceIndex === void 0 || z(r, t.key, t.sourceIndex, t.keys)) && (t.sourceIndex = k(r, t.key, "source"));
545
+ throw D(e.id, "requires array source and target");
546
+ (t.sourceIndex === void 0 || x(r, t.key, t.sourceIndex, t.keys)) && (t.sourceIndex = w(r, t.key, "source"));
515
547
  const s = t.targetIndex;
516
548
  if (s === void 0)
517
- throw b(e.id, "has no materialized target index");
518
- const o = [], h = [];
519
- for (const a of t.keys) {
520
- const g = t.sourceIndex.get(a);
521
- g === void 0 ? h.push(a) : o.push({ key: a, index: g, item: r[g] });
549
+ throw D(e.id, "has no materialized target index");
550
+ const o = [], n = [];
551
+ for (const h of t.keys) {
552
+ const _ = t.sourceIndex.get(h);
553
+ _ === void 0 ? n.push(h) : o.push({ key: h, index: _, item: r[_] });
522
554
  }
523
- o.sort((a, g) => a.index - g.index);
524
- const l = o.map((a) => a.item), d = l.length === 0 ? [] : e.options.compute(l);
525
- B(
555
+ o.sort((h, _) => h.index - _.index);
556
+ const c = o.map((h) => h.item), l = c.length === 0 ? [] : e.options.compute(c);
557
+ F(
526
558
  e.id,
527
559
  t.key,
528
- o.map((a) => a.key),
529
- d
560
+ o.map((h) => h.key),
561
+ l
530
562
  );
531
- const u = d;
532
- if (h.length !== 0 || o.some((a) => !s.has(a.key))) {
533
- const a = /* @__PURE__ */ new Map();
534
- for (let f = 0; f < o.length; f++)
535
- a.set(o[f].key, u[f]);
536
- const g = /* @__PURE__ */ new Map();
537
- for (const [f, v] of s)
538
- g.set(f, i[v]);
539
- const n = x(r, t.key, "source"), c = [];
540
- c.length = n.length;
541
- for (let f = 0; f < n.length; f++) {
542
- const v = n[f];
563
+ const m = l;
564
+ if (n.length !== 0 || o.some((h) => !s.has(h.key))) {
565
+ const h = /* @__PURE__ */ new Map();
566
+ for (let u = 0; u < o.length; u++)
567
+ h.set(o[u].key, m[u]);
568
+ const _ = /* @__PURE__ */ new Map();
569
+ for (const [u, v] of s)
570
+ _.set(u, i[v]);
571
+ const a = b(r, t.key, "source"), d = [];
572
+ d.length = a.length;
573
+ for (let u = 0; u < a.length; u++) {
574
+ const v = a[u];
543
575
  if (v === void 0)
544
576
  continue;
545
- const D = a.has(v) ? a.get(v) : g.get(v);
546
- if (D === void 0)
547
- throw b(e.id, `is missing target item for key "${String(v)}"`);
548
- c[f] = D;
577
+ const k = h.has(v) ? h.get(v) : _.get(v);
578
+ if (k === void 0)
579
+ throw D(e.id, `is missing target item for key "${String(v)}"`);
580
+ d[u] = k;
549
581
  }
550
- const p = k(c, t.key, "target");
551
- this._replaceDerivedTarget(e.options.to, c, t.keys), t.targetIndex = p;
582
+ const g = w(d, t.key, "target");
583
+ this._replaceDerivedTarget(e.options.to, d, t.keys), t.targetIndex = g;
552
584
  } else
553
- for (let a = 0; a < o.length; a++)
585
+ for (let h = 0; h < o.length; h++)
554
586
  this._writeDerivedTarget(
555
- A(e.options.to, t.key, o[a].key),
556
- u[a]
587
+ C(e.options.to, t.key, o[h].key),
588
+ m[h]
557
589
  );
558
590
  t.keys.clear(), t.full = !1;
559
591
  }
@@ -561,127 +593,124 @@ const M = class M {
561
593
  t.full = !0;
562
594
  const r = this.get(e.options.from), i = this.get(e.options.to);
563
595
  if (!Array.isArray(r) || !Array.isArray(i))
564
- throw P(e.id, "requires array source and target");
565
- (t.sourceIndex === void 0 || z(r, t.key, t.sourceIndex, t.keys)) && (t.sourceIndex = k(r, t.key, "source"));
596
+ throw R(e.id, "requires array source and target");
597
+ (t.sourceIndex === void 0 || x(r, t.key, t.sourceIndex, t.keys)) && (t.sourceIndex = w(r, t.key, "source"));
566
598
  const s = t.targetIndex;
567
599
  if (s === void 0)
568
- throw P(e.id, "has no materialized target index");
600
+ throw R(e.id, "has no materialized target index");
569
601
  const o = [];
570
- for (const n of t.keys) {
571
- const c = t.sourceIndex.get(n);
572
- c !== void 0 && o.push({ key: n, index: c, item: r[c] });
602
+ for (const a of t.keys) {
603
+ const d = t.sourceIndex.get(a);
604
+ d !== void 0 && o.push({ key: a, index: d, item: r[d] });
573
605
  }
574
- o.sort((n, c) => n.index - c.index);
575
- const h = o.map((n) => n.item), l = h.length === 0 ? [] : e.options.compute(h);
606
+ o.sort((a, d) => a.index - d.index);
607
+ const n = o.map((a) => a.item), c = n.length === 0 ? [] : e.options.compute(n);
576
608
  K(
577
609
  e.id,
578
610
  t.key,
579
- o.map((n) => n.key),
580
- l
611
+ o.map((a) => a.key),
612
+ c
581
613
  );
582
- const d = /* @__PURE__ */ new Map(), u = l, m = x(u, t.key, "output");
583
- for (let n = 0; n < m.length; n++) {
584
- const c = m[n];
585
- c !== void 0 && d.set(c, C(u[n]));
614
+ const l = /* @__PURE__ */ new Map(), m = c, y = b(m, t.key, "output");
615
+ for (let a = 0; a < y.length; a++) {
616
+ const d = y[a];
617
+ d !== void 0 && l.set(d, M(m[a]));
586
618
  }
587
- const a = /* @__PURE__ */ new Set();
588
- let g = !1;
589
- for (const n of t.keys) {
590
- const c = s.has(n), p = d.has(n);
591
- !c && !p || (a.add(n), c !== p && (g = !0));
619
+ const h = /* @__PURE__ */ new Set();
620
+ let _ = !1;
621
+ for (const a of t.keys) {
622
+ const d = s.has(a), g = l.has(a);
623
+ !d && !g || (h.add(a), d !== g && (_ = !0));
592
624
  }
593
- if (g && t.keys.size === 1 && i.length === s.size && this._patchSingleFilterMembership(
625
+ if (_ && t.keys.size === 1 && i.length === s.size && this._patchSingleFilterMembership(
594
626
  e,
595
627
  t,
596
628
  i,
597
629
  s,
598
- d,
599
- a
630
+ l,
631
+ h
600
632
  )) {
601
633
  t.keys.clear(), t.full = !1;
602
634
  return;
603
635
  }
604
- if (g) {
605
- const n = /* @__PURE__ */ new Map();
606
- for (const [f, v] of s)
607
- n.set(f, i[v]);
608
- const c = [];
609
- for (const f of x(r, t.key, "source"))
610
- if (f !== void 0) {
611
- if (t.keys.has(f)) {
612
- d.has(f) && c.push(d.get(f));
636
+ if (_) {
637
+ const a = /* @__PURE__ */ new Map();
638
+ for (const [u, v] of s)
639
+ a.set(u, i[v]);
640
+ const d = [];
641
+ for (const u of b(r, t.key, "source"))
642
+ if (u !== void 0) {
643
+ if (t.keys.has(u)) {
644
+ l.has(u) && d.push(l.get(u));
613
645
  continue;
614
646
  }
615
- n.has(f) && c.push(n.get(f));
647
+ a.has(u) && d.push(a.get(u));
616
648
  }
617
- const p = k(c, t.key, "target");
618
- this._replaceDerivedTarget(e.options.to, c, a), t.targetIndex = p;
649
+ const g = w(d, t.key, "target");
650
+ this._replaceDerivedTarget(e.options.to, d, h), t.targetIndex = g;
619
651
  } else
620
- for (const [n, c] of d)
621
- this._writeDerivedTarget(A(e.options.to, t.key, n), c);
652
+ for (const [a, d] of l)
653
+ this._writeDerivedTarget(C(e.options.to, t.key, a), d);
622
654
  t.keys.clear(), t.full = !1;
623
655
  }
624
656
  _patchSingleFilterMembership(e, t, r, i, s, o) {
625
- const h = t.sourceIndex;
626
- if (h === void 0)
657
+ const n = t.sourceIndex;
658
+ if (n === void 0)
627
659
  return !1;
628
- const l = t.keys.values().next().value;
629
- if (l === void 0)
660
+ const c = t.keys.values().next().value;
661
+ if (c === void 0)
630
662
  return !1;
631
- const d = i.get(l), u = s.has(l);
632
- if (d !== void 0 === u)
663
+ const l = i.get(c), m = s.has(c);
664
+ if (l !== void 0 === m)
633
665
  return !1;
634
- const m = r.slice();
635
- let a;
636
- if (d !== void 0)
637
- a = d, m.splice(a, 1);
666
+ const y = r.slice();
667
+ let h;
668
+ if (l !== void 0)
669
+ h = l, y.splice(h, 1);
638
670
  else {
639
- const g = h.get(l);
640
- if (g === void 0)
671
+ const _ = n.get(c);
672
+ if (_ === void 0)
641
673
  return !1;
642
- let n = 0, c = m.length;
643
- for (; n < c; ) {
644
- const p = n + c >>> 1, f = m[p];
645
- if (typeof f != "object" || f === null || Array.isArray(f))
674
+ let a = 0, d = y.length;
675
+ for (; a < d; ) {
676
+ const g = a + d >>> 1, u = y[g];
677
+ if (typeof u != "object" || u === null || Array.isArray(u))
646
678
  return !1;
647
- const v = f[t.key];
679
+ const v = u[t.key];
648
680
  if (typeof v != "string" && typeof v != "number")
649
681
  return !1;
650
- const D = h.get(v);
651
- if (D === void 0)
682
+ const k = n.get(v);
683
+ if (k === void 0)
652
684
  return !1;
653
- D < g ? n = p + 1 : c = p;
685
+ k < _ ? a = g + 1 : d = g;
654
686
  }
655
- a = n, m.splice(a, 0, s.get(l));
687
+ h = a, y.splice(h, 0, s.get(c));
656
688
  }
657
- if (this._replaceDerivedTarget(e.options.to, m, o), d !== void 0) {
658
- i.delete(l);
659
- for (const [g, n] of i)
660
- n > a && i.set(g, n - 1);
689
+ if (this._replaceDerivedTarget(e.options.to, y, o), l !== void 0) {
690
+ i.delete(c);
691
+ for (const [_, a] of i)
692
+ a > h && i.set(_, a - 1);
661
693
  } else {
662
- for (const [g, n] of i)
663
- n >= a && i.set(g, n + 1);
664
- i.set(l, a);
694
+ for (const [_, a] of i)
695
+ a >= h && i.set(_, a + 1);
696
+ i.set(c, h);
665
697
  }
666
698
  return !0;
667
699
  }
668
- };
669
- // Формирует локальный id для Kernel без явно заданного имени.
670
- y(M, "_kernelCounter", 0);
671
- let I = M;
672
- function E(_, e) {
673
- const t = Math.min(_.segments.length, e.segments.length);
700
+ }
701
+ function A(f, e) {
702
+ const t = Math.min(f.segments.length, e.segments.length);
674
703
  for (let r = 0; r < t; r++)
675
- if (!V(_.segments[r], e.segments[r]))
704
+ if (!j(f.segments[r], e.segments[r]))
676
705
  return !1;
677
706
  return !0;
678
707
  }
679
- function U(_, e) {
680
- return typeof _ != "object" || _ === null || Array.isArray(_) || e.kind !== "key" ? !0 : Object.hasOwn(_, e.key);
708
+ function $(f, e) {
709
+ return typeof f != "object" || f === null || Array.isArray(f) || e.kind !== "key" ? !0 : Object.hasOwn(f, e.key);
681
710
  }
682
- function V(_, e) {
683
- 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);
711
+ function j(f, e) {
712
+ return f.kind !== e.kind ? !1 : f.kind === "key" && e.kind === "key" ? f.key === e.key : f.kind === "index" && e.kind === "index" ? f.index === e.index : f.kind === "selector" && e.kind === "selector" && f.key === e.key && Object.is(f.value, e.value);
684
713
  }
685
714
  export {
686
- I as RaphKernel
715
+ P as RaphKernel
687
716
  };