@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +1096 -0
  2. package/dist/api/Raph.d.ts +59 -190
  3. package/dist/api/RaphFacadeSession.d.ts +90 -0
  4. package/dist/api/RaphReactivityInstance.d.ts +72 -0
  5. package/dist/api/errors.d.ts +9 -4
  6. package/dist/api/types.d.ts +162 -17
  7. package/dist/core-CyilRD7s.js +1055 -0
  8. package/dist/core-ugchZNqC.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -1
  10. package/dist/debug/api/Raph.js +368 -366
  11. package/dist/debug/api/RaphFacadeSession.cjs +1 -0
  12. package/dist/debug/api/RaphFacadeSession.js +306 -0
  13. package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
  14. package/dist/debug/api/RaphReactivityInstance.js +149 -0
  15. package/dist/debug/api/errors.cjs +1 -1
  16. package/dist/debug/api/errors.js +10 -7
  17. package/dist/debug/path/DataPath.cjs +1 -0
  18. package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
  19. package/dist/debug/path/PathRouter.cjs +1 -0
  20. package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
  21. package/dist/debug/path/RaphKernel.cjs +1 -1
  22. package/dist/debug/path/RaphKernel.js +258 -207
  23. package/dist/debug/path/data-path.utils.cjs +1 -0
  24. package/dist/debug/path/data-path.utils.js +56 -0
  25. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  26. package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
  27. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  28. package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
  29. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  30. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  31. package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
  32. package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
  33. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  34. package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
  35. package/dist/debug/path/meta/meta.types.cjs +1 -0
  36. package/dist/debug/path/meta/meta.types.js +1 -0
  37. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  38. package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
  39. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  40. package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
  41. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  42. package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
  43. package/dist/debug/path/storage/PathStore.cjs +1 -0
  44. package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
  45. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  46. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  47. package/dist/debug/reactivity/engine.cjs +1 -1
  48. package/dist/debug/reactivity/engine.js +478 -306
  49. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  50. package/dist/debug/reactivity/reactive-object.js +280 -0
  51. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  52. package/dist/debug/runtime/RaphRuntime.js +798 -519
  53. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  54. package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
  55. package/dist/debug/runtime/errors.cjs +1 -1
  56. package/dist/debug/runtime/errors.js +6 -3
  57. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  58. package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
  59. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  60. package/dist/debug/runtime/ownership/RaphNode.js +206 -0
  61. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  62. package/dist/debug/runtime/ownership/RaphScope.js +101 -0
  63. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  64. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  65. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  66. package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
  67. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  68. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  69. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  70. package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
  71. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  72. package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
  73. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  74. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
  75. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
  77. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
  79. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  80. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  81. package/dist/entrypoints/machine-testing.d.ts +2 -0
  82. package/dist/entrypoints/machine.d.ts +5 -0
  83. package/dist/entrypoints/path.d.ts +14 -0
  84. package/dist/entrypoints/reactivity.d.ts +1 -0
  85. package/dist/entrypoints/runtime.d.ts +17 -0
  86. package/dist/index.cjs +1 -1
  87. package/dist/index.js +46 -38
  88. package/dist/machine/compiler.d.ts +71 -0
  89. package/dist/machine/core.d.ts +50 -0
  90. package/dist/machine/persistence.d.ts +5 -0
  91. package/dist/machine/runtime.d.ts +4 -0
  92. package/dist/machine/testing.d.ts +43 -0
  93. package/dist/machine/types.d.ts +155 -0
  94. package/dist/machine-testing.cjs +1 -0
  95. package/dist/machine-testing.js +188 -0
  96. package/dist/machine.cjs +1 -0
  97. package/dist/machine.js +837 -0
  98. package/dist/main.d.ts +20 -0
  99. package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
  100. package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
  101. package/dist/path/RaphKernel.d.ts +13 -10
  102. package/dist/path/data-path.types.d.ts +34 -0
  103. package/dist/path/data-path.utils.d.ts +9 -0
  104. package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
  105. package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
  106. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  107. package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
  108. package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
  109. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  110. package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
  111. package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
  112. package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
  113. package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
  114. package/dist/path/path.types.d.ts +3 -2
  115. package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
  116. package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
  117. package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
  118. package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
  119. package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
  120. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  121. package/dist/path.cjs +1 -1
  122. package/dist/path.js +16 -16
  123. package/dist/raph.cjs +1 -1
  124. package/dist/raph.js +46 -38
  125. package/dist/reactivity/engine.d.ts +17 -3
  126. package/dist/reactivity/reactive-object.d.ts +36 -0
  127. package/dist/reactivity/types.d.ts +25 -0
  128. package/dist/reactivity.cjs +1 -1
  129. package/dist/reactivity.js +12 -12
  130. package/dist/runtime/RaphRuntime.d.ts +132 -192
  131. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  132. package/dist/runtime/errors.d.ts +5 -0
  133. package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
  134. package/dist/runtime/ownership/RaphNode.d.ts +40 -0
  135. package/dist/runtime/ownership/RaphScope.d.ts +38 -0
  136. package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
  137. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  138. package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
  139. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  140. package/dist/runtime/phases/phase.types.d.ts +92 -0
  141. package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
  142. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  143. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
  144. package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
  145. package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
  146. package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
  147. package/dist/runtime.cjs +1 -1
  148. package/dist/runtime.js +21 -16
  149. package/package.json +68 -35
  150. package/ReadMe.md +0 -153
  151. package/dist/api/public.d.ts +0 -22
  152. package/dist/debug/api/public.cjs +0 -1
  153. package/dist/debug/api/public.js +0 -40
  154. package/dist/debug/path/AdapterPathStore.cjs +0 -1
  155. package/dist/debug/path/DerivedRegistry.cjs +0 -1
  156. package/dist/debug/path/PathEventHub.cjs +0 -1
  157. package/dist/debug/path/PathStore.cjs +0 -1
  158. package/dist/debug/path/RaphMetaStore.cjs +0 -1
  159. package/dist/debug/path/data-adapter.cjs +0 -1
  160. package/dist/debug/path/data-path.cjs +0 -1
  161. package/dist/debug/path/derived-collection.cjs +0 -1
  162. package/dist/debug/path/path-router.cjs +0 -1
  163. package/dist/debug/path/public.cjs +0 -1
  164. package/dist/debug/path/public.js +0 -18
  165. package/dist/debug/runtime/PathHandle.cjs +0 -1
  166. package/dist/debug/runtime/RaphDebug.cjs +0 -1
  167. package/dist/debug/runtime/RaphDebug.js +0 -15
  168. package/dist/debug/runtime/RaphNode.cjs +0 -1
  169. package/dist/debug/runtime/RaphNode.js +0 -143
  170. package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
  171. package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
  172. package/dist/debug/runtime/RaphScope.cjs +0 -1
  173. package/dist/debug/runtime/RaphScope.js +0 -64
  174. package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
  175. package/dist/debug/runtime/RuntimeReactivity.js +0 -154
  176. package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
  177. package/dist/debug/runtime/RuntimeWatch.js +0 -71
  178. package/dist/debug/runtime/public.cjs +0 -1
  179. package/dist/debug/runtime/public.js +0 -18
  180. package/dist/path/public.d.ts +0 -14
  181. package/dist/runtime/RaphDebug.d.ts +0 -32
  182. package/dist/runtime/RaphNode.d.ts +0 -68
  183. package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
  184. package/dist/runtime/RaphScope.d.ts +0 -50
  185. package/dist/runtime/phase.types.d.ts +0 -49
  186. package/dist/runtime/public.d.ts +0 -13
  187. /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
  188. /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
  189. /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
  190. /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
  191. /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
  192. /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
  193. /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
  194. /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
  195. /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
  196. /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
  197. /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
  198. /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
  199. /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
  200. /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
  201. /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
  202. /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
  203. /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
  204. /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
  205. /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
  206. /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
  207. /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
  208. /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
  209. /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
  210. /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
  211. /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
@@ -1,18 +1,17 @@
1
- var S = Object.defineProperty;
2
- var A = (n, e, t) => e in n ? S(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var u = (n, e, t) => A(n, typeof e != "symbol" ? e + "" : e, t);
4
- let m, w;
5
- const o = class o {
1
+ var v = Object.defineProperty;
2
+ var S = (n, e, t) => e in n ? v(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var o = (n, e, t) => S(n, typeof e != "symbol" ? e + "" : e, t);
4
+ const u = class u {
6
5
  /**
7
6
  * Сохраняет уже разобранный immutable path value.
8
7
  */
9
8
  constructor(e, t) {
10
9
  // Хранят canonical value и разобранные сегменты пути.
11
- u(this, "_canonical");
12
- u(this, "_segments");
10
+ o(this, "_canonical");
11
+ o(this, "_segments");
13
12
  // Кешируют проверенные exact и mask представления.
14
- u(this, "_exact");
15
- u(this, "_mask");
13
+ o(this, "_exact");
14
+ o(this, "_mask");
16
15
  this._canonical = e, this._segments = Object.freeze(
17
16
  t.map((r) => Object.freeze({ ...r }))
18
17
  );
@@ -21,31 +20,69 @@ const o = class o {
21
20
  * Нормализует поддерживаемое определение пути в DataPath.
22
21
  */
23
22
  static from(e, t) {
24
- return e instanceof o ? e : typeof e == "string" ? this.fromString(e, t) : this.fromPlain(e);
23
+ return e instanceof u ? e : typeof e == "string" ? this.fromString(e, t) : this.fromPlain(e);
25
24
  }
26
25
  /**
27
26
  * Разбирает строковый path согласно строгой грамматике.
28
27
  */
29
28
  static fromString(e, t) {
30
- const r = x(
29
+ const r = m(
31
30
  e,
32
31
  t == null ? void 0 : t.vars,
33
32
  !0,
34
33
  (t == null ? void 0 : t.wildcardDynamic) === !0,
35
34
  !0
36
- ), i = this._cache ?? (this._cache = /* @__PURE__ */ new Map()), s = i.get(r.canonical);
37
- if (s !== void 0)
38
- return s;
39
- i.size >= 2e4 && i.clear();
40
- const c = new o(r.canonical, r.segments);
41
- return i.set(r.canonical, c), c;
35
+ ), s = this._cache ?? (this._cache = /* @__PURE__ */ new Map()), i = s.get(r.canonical);
36
+ if (i !== void 0)
37
+ return i;
38
+ s.size >= 2e4 && s.clear();
39
+ const c = new u(r.canonical, r.segments);
40
+ return s.set(r.canonical, c), c;
42
41
  }
43
42
  /**
44
43
  * Восстанавливает DataPath из сериализованного представления.
45
44
  */
46
45
  static fromPlain(e) {
47
- const r = (Array.isArray(e.segs) ? e.segs : []).map(j);
48
- return new o(_(r), r);
46
+ const r = (Array.isArray(e.segs) ? e.segs : []).map(O);
47
+ return new u(w(r), r);
48
+ }
49
+ /**
50
+ * Разбирает строку exact path без создания публичного value object.
51
+ * @internal
52
+ */
53
+ static _parseExactString(e, t) {
54
+ const r = m(e, t == null ? void 0 : t.vars, !1, !1, !0);
55
+ return {
56
+ canonical: r.canonical,
57
+ segments: r.segments
58
+ };
59
+ }
60
+ /**
61
+ * Разбирает строку path mask без создания публичного value object.
62
+ * @internal
63
+ */
64
+ static _parseMaskString(e) {
65
+ const t = m(e, void 0, !0, !1, !0);
66
+ for (let i = 0; i < t.segments.length - 1; i++) {
67
+ const c = t.segments[i];
68
+ if (c.kind === "wildcard" && !c.indexed)
69
+ throw new TypeError(
70
+ `[Raph] Dot wildcard must be the final mask segment: "${e}".`
71
+ );
72
+ }
73
+ const r = t.segments[t.segments.length - 1], s = (r == null ? void 0 : r.kind) === "wildcard" && !r.indexed;
74
+ return {
75
+ canonical: t.canonical,
76
+ deep: s,
77
+ segments: s ? t.segments.slice(0, -1) : t.segments
78
+ };
79
+ }
80
+ /**
81
+ * Формирует canonical path из уже проверенных сегментов.
82
+ * @internal
83
+ */
84
+ static _renderSegments(e) {
85
+ return w(e);
49
86
  }
50
87
  /**
51
88
  * Сериализует path в независимое plain-представление.
@@ -53,7 +90,7 @@ const o = class o {
53
90
  toPlain() {
54
91
  return {
55
92
  segs: this._segments.map((e) => e.kind === "key" ? { t: "key", k: e.key } : e.kind === "index" ? { t: "idx", i: e.index } : e.kind === "selector" ? { t: "param", pk: e.key, pv: e.value } : { t: "wc", indexed: e.indexed }),
56
- deepOnTail: v(this._segments)
93
+ deepOnTail: b(this._segments)
57
94
  };
58
95
  }
59
96
  /**
@@ -78,17 +115,17 @@ const o = class o {
78
115
  * Проверяет соответствие exact path указанной маске.
79
116
  */
80
117
  static match(e, t) {
81
- const r = this.from(e)._segments, i = this.from(t)._segments;
82
- let s = 0;
83
- for (; s < r.length; s++) {
84
- const c = r[s];
85
- if (c.kind === "wildcard" && !c.indexed && s === r.length - 1)
118
+ const r = this.from(e)._segments, s = this.from(t)._segments;
119
+ let i = 0;
120
+ for (; i < r.length; i++) {
121
+ const c = r[i];
122
+ if (c.kind === "wildcard" && !c.indexed && i === r.length - 1)
86
123
  return !0;
87
- const a = i[s];
88
- if (a === void 0 || !H(c, a))
124
+ const a = s[i];
125
+ if (a === void 0 || !j(c, a))
89
126
  return !1;
90
127
  }
91
- return s === i.length;
128
+ return i === s.length;
92
129
  }
93
130
  /**
94
131
  * Возвращает exact path либо отклоняет wildcard-сегменты.
@@ -97,7 +134,7 @@ const o = class o {
97
134
  _asExact() {
98
135
  for (const e of this._segments)
99
136
  if (e.kind === "wildcard")
100
- throw b(this._canonical);
137
+ throw y(this._canonical);
101
138
  return this._exact ?? (this._exact = {
102
139
  canonical: this._canonical,
103
140
  segments: this._segments
@@ -115,7 +152,7 @@ const o = class o {
115
152
  `[Raph] Dot wildcard must be the final mask segment: "${this._canonical}".`
116
153
  );
117
154
  }
118
- const e = v(this._segments);
155
+ const e = b(this._segments);
119
156
  return this._mask ?? (this._mask = {
120
157
  canonical: this._canonical,
121
158
  deep: e,
@@ -124,169 +161,106 @@ const o = class o {
124
161
  }
125
162
  };
126
163
  // Переиспользует immutable экземпляры для одинаковых canonical paths.
127
- u(o, "_cache");
128
- let h = o;
129
- function q(n, e) {
130
- if (!(e != null && e.vars)) {
131
- const i = m == null ? void 0 : m.get(n);
132
- if (i !== void 0)
133
- return i;
134
- }
135
- if (typeof n != "string")
136
- return M(n, e);
137
- const t = x(n, e == null ? void 0 : e.vars, !1, !1, !0), r = {
138
- canonical: t.canonical,
139
- segments: t.segments
140
- };
141
- if (!(e != null && e.vars)) {
142
- const i = m ?? (m = /* @__PURE__ */ new Map());
143
- i.size >= 2e4 && i.clear(), i.set(n, r);
144
- }
145
- return r;
146
- }
147
- function V(n) {
148
- const e = w == null ? void 0 : w.get(n);
149
- if (e !== void 0)
150
- return e;
151
- if (typeof n != "string")
152
- return P(n);
153
- const t = x(n, void 0, !0, !1, !0);
154
- for (let a = 0; a < t.segments.length - 1; a++) {
155
- const l = t.segments[a];
156
- if (l.kind === "wildcard" && !l.indexed)
157
- throw new TypeError(
158
- `[Raph] Dot wildcard must be the final mask segment: "${n}".`
159
- );
160
- }
161
- const r = t.segments[t.segments.length - 1], i = (r == null ? void 0 : r.kind) === "wildcard" && !r.indexed, s = {
162
- canonical: t.canonical,
163
- deep: i,
164
- segments: i ? t.segments.slice(0, -1) : t.segments
165
- }, c = w ?? (w = /* @__PURE__ */ new Map());
166
- return c.size >= 2e4 && c.clear(), c.set(n, s), s;
167
- }
168
- function M(n, e) {
169
- const t = h.from(n, e)._asExact();
170
- if (n instanceof h && !(e != null && e.vars)) {
171
- const r = m ?? (m = /* @__PURE__ */ new Map());
172
- r.size >= 2e4 && r.clear(), r.set(n, t);
173
- }
174
- return t;
175
- }
176
- function P(n) {
177
- const e = h.from(n)._asMask();
178
- if (n instanceof h) {
179
- const t = w ?? (w = /* @__PURE__ */ new Map());
180
- t.size >= 2e4 && t.clear(), t.set(n, e);
181
- }
182
- return e;
183
- }
184
- function F(n) {
185
- if (n.segments.length === 0)
186
- return ["*"];
187
- const e = [`${n.canonical}.*`];
188
- for (let t = 1; t < n.segments.length; t++)
189
- e.push(_(n.segments.slice(0, t)));
190
- return e;
191
- }
192
- function x(n, e, t, r = !1, i = !1) {
193
- const s = n.trim();
194
- if (s.length === 0) {
195
- if (i)
164
+ o(u, "_cache");
165
+ let k = u;
166
+ function m(n, e, t, r = !1, s = !1) {
167
+ const i = n.trim();
168
+ if (i.length === 0) {
169
+ if (s)
196
170
  return { canonical: "", segments: [] };
197
171
  throw new TypeError("[Raph] Data path must not be empty.");
198
172
  }
199
173
  const c = [];
200
174
  let a = 0, l = !0;
201
- for (; a < s.length; ) {
202
- const k = s[a];
203
- if (k === ".") {
175
+ for (; a < i.length; ) {
176
+ const x = i[a];
177
+ if (x === ".") {
204
178
  if (l)
205
- throw f(n);
179
+ throw d(n);
206
180
  l = !0, a++;
207
181
  continue;
208
182
  }
209
- if (k === "[") {
210
- const $ = T(s, a);
211
- c.push(I(
212
- s.slice(a + 1, $),
183
+ if (x === "[") {
184
+ const _ = E(i, a);
185
+ c.push(T(
186
+ i.slice(a + 1, _),
213
187
  e,
214
188
  t,
215
189
  r
216
- )), a = $ + 1, l = !1;
190
+ )), a = _ + 1, l = !1;
217
191
  continue;
218
192
  }
219
193
  if (!l)
220
- throw f(n);
221
- let d = a;
222
- for (; d < s.length && s[d] !== "." && s[d] !== "["; )
223
- d++;
224
- const g = s.slice(a, d).trim();
225
- if (g.length === 0)
226
- throw f(n);
227
- if (g === "*") {
194
+ throw d(n);
195
+ let f = a;
196
+ for (; f < i.length && i[f] !== "." && i[f] !== "["; )
197
+ f++;
198
+ const h = i.slice(a, f).trim();
199
+ if (h.length === 0)
200
+ throw d(n);
201
+ if (h === "*") {
228
202
  if (!t)
229
- throw b(n);
203
+ throw y(n);
230
204
  c.push({ kind: "wildcard", indexed: !1 });
231
- } else r && g.startsWith("$") && !y(g.slice(1), e) ? c.push({ kind: "wildcard", indexed: !1 }) : c.push({ kind: "key", key: N(g, e) });
232
- a = d, l = !1;
205
+ } else r && h.startsWith("$") && !g(h.slice(1), e) ? c.push({ kind: "wildcard", indexed: !1 }) : c.push({ kind: "key", key: N(h, e) });
206
+ a = f, l = !1;
233
207
  }
234
208
  if (l || c.length === 0)
235
- throw f(n);
236
- return { canonical: _(c), segments: c };
209
+ throw d(n);
210
+ return { canonical: w(c), segments: c };
237
211
  }
238
- function T(n, e) {
212
+ function E(n, e) {
239
213
  let t, r = 1;
240
- for (let i = e + 1; i < n.length; i++) {
241
- const s = n[i];
242
- if (s === "\\") {
243
- i++;
214
+ for (let s = e + 1; s < n.length; s++) {
215
+ const i = n[s];
216
+ if (i === "\\") {
217
+ s++;
244
218
  continue;
245
219
  }
246
220
  if (t !== void 0) {
247
- s === t && (t = void 0);
221
+ i === t && (t = void 0);
248
222
  continue;
249
223
  }
250
- if (s === '"' || s === "'") {
251
- t = s;
224
+ if (i === '"' || i === "'") {
225
+ t = i;
252
226
  continue;
253
227
  }
254
- if (s === "[") {
228
+ if (i === "[") {
255
229
  r++;
256
230
  continue;
257
231
  }
258
- if (s === "]" && --r === 0)
259
- return i;
232
+ if (i === "]" && --r === 0)
233
+ return s;
260
234
  }
261
- throw f(n);
235
+ throw d(n);
262
236
  }
263
- function I(n, e, t, r) {
264
- const i = n.trim();
265
- if (i === "*") {
237
+ function T(n, e, t, r) {
238
+ const s = n.trim();
239
+ if (s === "*") {
266
240
  if (!t)
267
- throw b(`[${n}]`);
241
+ throw y(`[${n}]`);
268
242
  return { kind: "wildcard", indexed: !0 };
269
243
  }
270
- if (/^\d+$/.test(i))
271
- return { kind: "index", index: Number(i) };
272
- if (/^\$[A-Z_$][\w$]*$/i.test(i)) {
273
- if (r && !y(i.slice(1), e))
244
+ if (/^\d+$/.test(s))
245
+ return { kind: "index", index: Number(s) };
246
+ if (/^\$[A-Z_$][\w$]*$/i.test(s)) {
247
+ if (r && !g(s.slice(1), e))
274
248
  return { kind: "wildcard", indexed: !0 };
275
- const l = p(i.slice(1), e);
249
+ const l = p(s.slice(1), e);
276
250
  if (!Number.isInteger(l) || l < 0)
277
- throw new TypeError(`[Raph] Index variable "${i}" must be a non-negative integer.`);
251
+ throw new TypeError(`[Raph] Index variable "${s}" must be a non-negative integer.`);
278
252
  return { kind: "index", index: l };
279
253
  }
280
- const s = R(i);
281
- if (s === -1)
282
- throw f(`[${n}]`);
283
- const c = i.slice(0, s).trim(), a = i.slice(s + 1).trim();
254
+ const i = R(s);
255
+ if (i === -1)
256
+ throw d(`[${n}]`);
257
+ const c = s.slice(0, i).trim(), a = s.slice(i + 1).trim();
284
258
  if (!c || !a)
285
- throw f(`[${n}]`);
286
- return r && Z(a, e) ? { kind: "wildcard", indexed: !0 } : {
259
+ throw d(`[${n}]`);
260
+ return r && I(a, e) ? { kind: "wildcard", indexed: !0 } : {
287
261
  kind: "selector",
288
262
  key: c,
289
- value: C(a, e)
263
+ value: A(a, e)
290
264
  };
291
265
  }
292
266
  function R(n) {
@@ -308,7 +282,7 @@ function R(n) {
308
282
  }
309
283
  return -1;
310
284
  }
311
- function C(n, e) {
285
+ function A(n, e) {
312
286
  if (/^\$[A-Z_$][\w$]*$/i.test(n)) {
313
287
  const t = p(n.slice(1), e);
314
288
  if (t === null || typeof t == "string" || typeof t == "boolean" || typeof t == "number" && Number.isFinite(t))
@@ -316,7 +290,7 @@ function C(n, e) {
316
290
  throw new TypeError(`[Raph] Selector variable "${n}" must be scalar.`);
317
291
  }
318
292
  if (n[0] === '"' || n[0] === "'")
319
- return O(n);
293
+ return P(n);
320
294
  if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(n)) {
321
295
  const t = Number(n);
322
296
  if (Number.isFinite(t))
@@ -324,27 +298,27 @@ function C(n, e) {
324
298
  }
325
299
  return n === "true" ? !0 : n === "false" ? !1 : n === "null" ? null : n;
326
300
  }
327
- function O(n) {
301
+ function P(n) {
328
302
  const e = n[0];
329
303
  if (n.length < 2 || n[n.length - 1] !== e)
330
- throw f(n);
304
+ throw d(n);
331
305
  if (e === '"')
332
306
  try {
333
307
  const r = JSON.parse(n);
334
308
  if (typeof r == "string")
335
309
  return r;
336
310
  } catch {
337
- throw f(n);
311
+ throw d(n);
338
312
  }
339
313
  let t = "";
340
314
  for (let r = 1; r < n.length - 1; r++) {
341
- const i = n[r];
342
- if (i === "\\") {
315
+ const s = n[r];
316
+ if (s === "\\") {
343
317
  if (r++, r >= n.length - 1)
344
- throw f(n);
318
+ throw d(n);
345
319
  t += n[r];
346
320
  } else
347
- t += i;
321
+ t += s;
348
322
  }
349
323
  return t;
350
324
  }
@@ -360,22 +334,22 @@ function N(n, e) {
360
334
  return r;
361
335
  }
362
336
  function p(n, e) {
363
- if (!y(n, e))
337
+ if (!g(n, e))
364
338
  throw new TypeError(`[Raph] Missing path variable "${n}".`);
365
339
  return e[n];
366
340
  }
367
- function y(n, e) {
341
+ function g(n, e) {
368
342
  return e !== void 0 && Object.hasOwn(e, n);
369
343
  }
370
- function Z(n, e) {
344
+ function I(n, e) {
371
345
  for (const t of n.matchAll(/\$([A-Z_$][\w$]*)/gi))
372
- if (!y(t[1], e))
346
+ if (!g(t[1], e))
373
347
  return !0;
374
348
  return !1;
375
349
  }
376
- function j(n) {
350
+ function O(n) {
377
351
  if (typeof n != "object" || n === null)
378
- throw E();
352
+ throw $();
379
353
  const e = n;
380
354
  if (e.t === "key" && typeof e.k == "string")
381
355
  return { kind: "key", key: e.k };
@@ -383,41 +357,38 @@ function j(n) {
383
357
  return { kind: "index", index: e.i };
384
358
  if (e.t === "wc")
385
359
  return { kind: "wildcard", indexed: e.indexed === !0 };
386
- if (e.t === "param" && typeof e.pk == "string" && z(e.pv))
360
+ if (e.t === "param" && typeof e.pk == "string" && M(e.pv))
387
361
  return { kind: "selector", key: e.pk, value: e.pv };
388
- throw E();
362
+ throw $();
389
363
  }
390
- function z(n) {
364
+ function M(n) {
391
365
  return n === null || typeof n == "string" || typeof n == "boolean" || typeof n == "number" && Number.isFinite(n);
392
366
  }
393
- function v(n) {
367
+ function b(n) {
394
368
  const e = n[n.length - 1];
395
369
  return (e == null ? void 0 : e.kind) === "wildcard" && !e.indexed;
396
370
  }
397
- function H(n, e) {
371
+ function j(n, e) {
398
372
  return n.kind === "wildcard" ? !n.indexed || e.kind === "index" || e.kind === "selector" : n.kind !== e.kind ? !1 : n.kind === "key" ? n.key === e.key : n.kind === "index" ? n.index === e.index : n.key === e.key && Object.is(n.value, e.value);
399
373
  }
400
- function _(n) {
374
+ function w(n) {
401
375
  let e = "";
402
376
  for (const t of n)
403
- t.kind === "key" ? e += e ? `.${t.key}` : t.key : t.kind === "index" ? e += `[${t.index}]` : t.kind === "selector" ? e += `[${t.key}=${X(t.value)}]` : e += t.indexed ? "[*]" : e ? ".*" : "*";
377
+ t.kind === "key" ? e += e ? `.${t.key}` : t.key : t.kind === "index" ? e += `[${t.index}]` : t.kind === "selector" ? e += `[${t.key}=${C(t.value)}]` : e += t.indexed ? "[*]" : e ? ".*" : "*";
404
378
  return e;
405
379
  }
406
- function X(n) {
380
+ function C(n) {
407
381
  return typeof n == "string" ? JSON.stringify(n) : String(n);
408
382
  }
409
- function f(n) {
383
+ function d(n) {
410
384
  return new TypeError(`[Raph] Invalid data path "${n}".`);
411
385
  }
412
- function E() {
386
+ function $() {
413
387
  return new TypeError("[Raph] Invalid plain DataPath representation.");
414
388
  }
415
- function b(n) {
389
+ function y(n) {
416
390
  return new TypeError(`[Raph] Wildcard is only allowed in watch masks: "${n}".`);
417
391
  }
418
392
  export {
419
- h as DataPath,
420
- q as parseDataPath,
421
- V as parsePathMask,
422
- F as pathRelationMasks
393
+ k as DataPath
423
394
  };
@@ -0,0 +1 @@
1
+ "use strict";var u=Object.defineProperty;var x=(n,t,i)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[t]=i;var p=(n,t,i)=>x(n,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./pathSegmentKey.cjs");class g{constructor(){p(this,"_root",{})}add(t,i){let e=this._root;const o=[];for(const c of t.segments)if(c.kind==="wildcard"){const d=e.indexedWildcard??(e.indexedWildcard={});o.push({child:d,parent:e,indexedWildcard:!0}),e=d}else{const d=h.pathSegmentKey(c),a=e.exact??(e.exact=new Map);let s=a.get(d);s===void 0&&(s={},a.set(d,s)),o.push({child:s,key:d,parent:e,indexedWildcard:!1}),e=s}const r=t.deep?e.deep??(e.deep=new Set):e.end??(e.end=new Set);r.add(i);let l=!0;return()=>{if(l){l=!1,r.delete(i),r.size===0&&(t.deep?e.deep=void 0:e.end=void 0);for(let c=o.length-1;c>=0;c--){const d=o[c];if(!v(d.child))break;d.indexedWildcard?d.parent.indexedWildcard=void 0:(d.parent.exact.delete(d.key),d.parent.exact.size===0&&(d.parent.exact=void 0))}}}}match(t){var o;let i=[this._root];const e=new Set;for(let r=0;r<=t.length;r++){const l=r===t.length,c=[];for(const d of i){if(f(e,d.deep),l){f(e,d.end);continue}const a=t[r],s=(o=d.exact)==null?void 0:o.get(h.pathSegmentKey(a));s!==void 0&&c.push(s),d.indexedWildcard!==void 0&&(a.kind==="index"||a.kind==="selector")&&c.push(d.indexedWildcard)}if(l||(i=c,i.length===0))break}return e}matchAll(){const t=new Set,i=[this._root];for(;i.length;){const e=i.pop();if(f(t,e.deep),f(t,e.end),e.indexedWildcard!==void 0&&i.push(e.indexedWildcard),e.exact!==void 0)for(const o of e.exact.values())i.push(o)}return t}}function f(n,t){if(t!==void 0)for(const i of t)n.add(i)}function v(n){return n.deep===void 0&&n.end===void 0&&n.exact===void 0&&n.indexedWildcard===void 0}exports.PathRouter=g;
@@ -1,7 +1,7 @@
1
1
  var h = Object.defineProperty;
2
2
  var u = (n, t, i) => t in n ? h(n, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[t] = i;
3
3
  var p = (n, t, i) => u(n, typeof t != "symbol" ? t + "" : t, i);
4
- import { pathSegmentKey as x } from "./segment-key.js";
4
+ import { pathSegmentKey as x } from "./pathSegmentKey.js";
5
5
  class m {
6
6
  constructor() {
7
7
  // Корень trie разделяет exact и indexed-wildcard transitions.
@@ -1 +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;
1
+ "use strict";var A=Object.defineProperty;var z=(m,e,t)=>e in m?A(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t;var p=(m,e,t)=>z(m,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./data-path.utils.cjs"),R=require("./DataPath.cjs"),f=require("./derived/derived-collection.utils.cjs"),I=require("./derived/DerivedRegistry.cjs"),M=require("./derived/RaphDerivedHandle.cjs"),E=require("./meta/MetaController.cjs"),C=require("./storage/AdapterPathStore.cjs"),S=require("./storage/DefaultDataAdapter.cjs"),F=require("./storage/PathStore.cjs"),b=class b{constructor(e={}){p(this,"id");p(this,"_paths");p(this,"_derivedController");p(this,"_runtimes");p(this,"_metaController");p(this,"_batchDepth",0);p(this,"_runtimeMutationDepth",0);p(this,"_stabilizing",!1);p(this,"_derivedWriteDepth",0);if(this.id=e.id??`kernel-${b._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 C.AdapterPathStore(e.adapter)}else if(e.adapterOptions!==void 0)this._paths=new C.AdapterPathStore(new S.DefaultDataAdapter(e.initial,e.adapterOptions));else{const t=this._paths=new F.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;if(this._runtimeMutationDepth===0&&this._runtimes!==void 0){this._withAttachedRuntimeBoundary(()=>this.set(e,t,r));return}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;if(this._runtimeMutationDepth===0&&this._runtimes!==void 0){this._withAttachedRuntimeBoundary(()=>this.merge(e,t,r));return}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;if(this._runtimeMutationDepth===0&&this._runtimes!==void 0){this._withAttachedRuntimeBoundary(()=>this.delete(e,t));return}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")})}batch(e){var o;if(this._runtimeMutationDepth===0&&this._runtimes!==void 0)return this._withAttachedRuntimeBoundary(()=>this.batch(e));const t=this._store;if(this._derivedController===void 0&&!((o=this._metaController)!=null&&o.hasWatchers))return t.batch(e);let r,i,s=!1;try{r=t.batch(()=>this._runDerivedBatch(e))}catch(l){s=!0,i=l}if(s)throw i;return r}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){if(this._runtimeMutationDepth===0&&this._runtimes!==void 0){this._withAttachedRuntimeBoundary(()=>this.setMeta(e,t,r,i));return}this._assertMetaNamespace(t);const s=this._exactMetaPath(e,i);this._assertMetaOwner(s),this._metadata.set(s,t,r,i)}mergeMeta(e,t,r,i){if(this._runtimeMutationDepth===0&&this._runtimes!==void 0){this._withAttachedRuntimeBoundary(()=>this.mergeMeta(e,t,r,i));return}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;if(this._runtimeMutationDepth===0&&this._runtimes!==void 0){this._withAttachedRuntimeBoundary(()=>this.deleteMeta(e,t,r));return}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,u,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=k.parseDataPath(e.from),r=k.parseDataPath(e.to);if(P(t,r))throw new Error("[Raph] Derived source and target must not overlap.");const i=this._derivedController??new I.DerivedRegistry,s=e.id??i.nextId(),o={...e,from:t.canonical,to:r.canonical},l=new M.RaphDerivedHandle(this,s,o),h=((u=e.strategy)==null?void 0:u.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,h);try{e.immediate!==!1&&l.recompute()}catch(a){throw this._removeDerived(l),l._disposeFromKernel(),a}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 E.MetaController(this,e=>this.has(e),()=>this._batchDepth!==0||this._stabilizing))}_withAttachedRuntimeBoundary(e){var l,h,d;const t=this._runtimes===void 0?[]:[...this._runtimes];if(t.length===0)return e();const r=[],i=[];let s,o=!1;this._runtimeMutationDepth++;try{for(const u of t)(l=u._beginKernelBatch)==null||l.call(u),r.push(u);try{s=e()}catch(u){o=!0,i.push(u)}}catch(u){o=!0,i.push(u)}finally{this._runtimeMutationDepth--;for(let u=r.length-1;u>=0;u--)try{(d=(h=r[u])._endKernelBatch)==null||d.call(h)}catch(g){i.push(g)}}if(i.length===1)throw i[0];if(i.length>1)throw new AggregateError(i,o?"[Raph] Kernel mutation and Runtime publication failed.":"[Raph] Runtime publication failed after a Kernel mutation.");return s}_assertWritablePath(e,t,r,i){const s=this._derivedController;if(s===void 0||this._derivedWriteDepth!==0)return;const o=k.parseDataPath(t,i);for(const l of s.values()){const h=k.parseDataPath(l.options.to);if(!P(o,h))continue;const d=o.segments.length<h.segments.length;if(!(e==="merge"&&d&&!q(r,h.segments[o.segments.length])))throw new M.RaphDerivedTargetWriteError(o.canonical)}}_writeDerivedTarget(e,t){this._derivedWriteDepth++;try{this.set(e,t)}finally{this._derivedWriteDepth--}}_mutateDerived(e,t,r,i,s){const o=k.parseDataPath(r,s);t==="delete"&&!e.has(r,s)||e.batch(()=>{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()})}_runDerivedBatch(e){var u;let t=!1,r,i=!1,s,o=!1,l,h;this._batchDepth++;try{h=e()}catch(g){t=!0,r=g}finally{if(this._batchDepth--,this._batchDepth===0){if(!this._stabilizing)try{this._stabilizeDerived()}catch(g){i=!0,s=g}try{(u=this._metaController)==null||u.publish()}catch(g){o=!0,l=g}}}const d=[];if(t&&d.push(r),i&&d.push(s),o&&d.push(l),d.length>1)throw new AggregateError(d,"[Raph] Kernel batch publication failed.");if(d.length===1)throw d[0];return h}_mutateWithMetaLifecycle(e){if(this._batchDepth!==0||this._stabilizing){e();return}this.batch(e)}_pruneMissingMetaOwners(e,t,r){var i;(i=this._metaController)==null||i.pruneMissing(this._metaPath(e,r),t)}_metaPath(e,t){return R.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=k.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 h;const t=(h=this._derivedController)==null?void 0:h.state(e);t!==void 0&&(t.full=!0);const r=this.get(e.options.from),i=e.options.compute(r);let s=i,o,l;t!==void 0&&(r===void 0&&(i===void 0||Array.isArray(i)&&i.length===0)?(o=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),o=f.collectionIndex(r,t.key,"source"),l=f.collectionIndex(s,t.key,"output"))),this._writeDerivedTarget(e.options.to,s),t!==void 0&&(t.sourceIndex=o,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 o=[],l=[];for(const a of t.keys){const v=t.sourceIndex.get(a);v===void 0?l.push(a):o.push({key:a,index:v,item:r[v]})}o.sort((a,v)=>a.index-v.index);const h=o.map(a=>a.item),d=h.length===0?[]:e.options.compute(h);f.validateIncrementalCollection(e.id,t.key,o.map(a=>a.key),d);const u=d;if(l.length!==0||o.some(a=>!s.has(a.key))){const a=new Map;for(let _=0;_<o.length;_++)a.set(o[_].key,u[_]);const v=new Map;for(const[_,y]of s)v.set(_,i[y]);const n=f.collectionKeys(r,t.key,"source"),c=[];c.length=n.length;for(let _=0;_<n.length;_++){const y=n[_];if(y===void 0)continue;const D=a.has(y)?a.get(y):v.get(y);if(D===void 0)throw f.collectionError(e.id,`is missing target item for key "${String(y)}"`);c[_]=D}const w=f.collectionIndex(c,t.key,"target");this._replaceDerivedTarget(e.options.to,c,t.keys),t.targetIndex=w}else for(let a=0;a<o.length;a++)this._writeDerivedTarget(f.keyedPath(e.options.to,t.key,o[a].key),u[a]);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 o=[];for(const n of t.keys){const c=t.sourceIndex.get(n);c!==void 0&&o.push({key:n,index:c,item:r[c]})}o.sort((n,c)=>n.index-c.index);const l=o.map(n=>n.item),h=l.length===0?[]:e.options.compute(l);f.validateIncrementalFilter(e.id,t.key,o.map(n=>n.key),h);const d=new Map,u=h,g=f.collectionKeys(u,t.key,"output");for(let n=0;n<g.length;n++){const c=g[n];c!==void 0&&d.set(c,f.cloneMaterializedValue(u[n]))}const a=new Set;let v=!1;for(const n of t.keys){const c=s.has(n),w=d.has(n);!c&&!w||(a.add(n),c!==w&&(v=!0))}if(v&&t.keys.size===1&&i.length===s.size&&this._patchSingleFilterMembership(e,t,i,s,d,a)){t.keys.clear(),t.full=!1;return}if(v){const n=new Map;for(const[_,y]of s)n.set(_,i[y]);const c=[];for(const _ of f.collectionKeys(r,t.key,"source"))if(_!==void 0){if(t.keys.has(_)){d.has(_)&&c.push(d.get(_));continue}n.has(_)&&c.push(n.get(_))}const w=f.collectionIndex(c,t.key,"target");this._replaceDerivedTarget(e.options.to,c,a),t.targetIndex=w}else for(const[n,c]of d)this._writeDerivedTarget(f.keyedPath(e.options.to,t.key,n),c);t.keys.clear(),t.full=!1}_patchSingleFilterMembership(e,t,r,i,s,o){const l=t.sourceIndex;if(l===void 0)return!1;const h=t.keys.values().next().value;if(h===void 0)return!1;const d=i.get(h),u=s.has(h);if(d!==void 0===u)return!1;const g=r.slice();let a;if(d!==void 0)a=d,g.splice(a,1);else{const v=l.get(h);if(v===void 0)return!1;let n=0,c=g.length;for(;n<c;){const w=n+c>>>1,_=g[w];if(typeof _!="object"||_===null||Array.isArray(_))return!1;const y=_[t.key];if(typeof y!="string"&&typeof y!="number")return!1;const D=l.get(y);if(D===void 0)return!1;D<v?n=w+1:c=w}a=n,g.splice(a,0,s.get(h))}if(this._replaceDerivedTarget(e.options.to,g,o),d!==void 0){i.delete(h);for(const[v,n]of i)n>a&&i.set(v,n-1)}else{for(const[v,n]of i)n>=a&&i.set(v,n+1);i.set(h,a)}return!0}};p(b,"_kernelCounter",0);let x=b;function P(m,e){const t=Math.min(m.segments.length,e.segments.length);for(let r=0;r<t;r++)if(!O(m.segments[r],e.segments[r]))return!1;return!0}function q(m,e){return typeof m!="object"||m===null||Array.isArray(m)||e.kind!=="key"?!0:Object.hasOwn(m,e.key)}function O(m,e){return m.kind!==e.kind?!1:m.kind==="key"&&e.kind==="key"?m.key===e.key:m.kind==="index"&&e.kind==="index"?m.index===e.index:m.kind==="selector"&&e.kind==="selector"&&m.key===e.key&&Object.is(m.value,e.value)}exports.RaphKernel=x;