@raphy-js/raph 1.0.0-dev.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE +202 -0
  2. package/dist/api/Raph.d.ts +97 -0
  3. package/dist/api/RaphFacadeSession.d.ts +90 -0
  4. package/dist/api/RaphReactivityInstance.d.ts +72 -0
  5. package/dist/api/errors.d.ts +25 -0
  6. package/dist/api/types.d.ts +170 -0
  7. package/dist/core-CyilRD7s.js +1055 -0
  8. package/dist/core-ugchZNqC.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -0
  10. package/dist/debug/api/Raph.js +421 -0
  11. package/dist/debug/api/RaphFacadeSession.cjs +1 -0
  12. package/dist/debug/api/RaphFacadeSession.js +306 -0
  13. package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
  14. package/dist/debug/api/RaphReactivityInstance.js +149 -0
  15. package/dist/debug/api/errors.cjs +1 -0
  16. package/dist/debug/api/errors.js +17 -0
  17. package/dist/debug/api/types.cjs +1 -0
  18. package/dist/debug/api/types.js +1 -0
  19. package/dist/debug/path/DataPath.cjs +1 -0
  20. package/dist/debug/path/DataPath.js +394 -0
  21. package/dist/debug/path/PathRouter.cjs +1 -0
  22. package/dist/debug/path/PathRouter.js +86 -0
  23. package/dist/debug/path/RaphKernel.cjs +1 -0
  24. package/dist/debug/path/RaphKernel.js +687 -0
  25. package/dist/debug/path/data-path.types.cjs +1 -0
  26. package/dist/debug/path/data-path.types.js +1 -0
  27. package/dist/debug/path/data-path.utils.cjs +1 -0
  28. package/dist/debug/path/data-path.utils.js +56 -0
  29. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  30. package/dist/debug/path/derived/DerivedRegistry.js +157 -0
  31. package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
  32. package/dist/debug/path/derived/RaphDerivedHandle.js +125 -0
  33. package/dist/debug/path/derived/derived-collection.types.cjs +1 -0
  34. package/dist/debug/path/derived/derived-collection.types.js +1 -0
  35. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  36. package/dist/debug/path/derived/derived-collection.utils.js +179 -0
  37. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  38. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  39. package/dist/debug/path/derived/derived-strategy.utils.cjs +1 -0
  40. package/dist/debug/path/derived/derived-strategy.utils.js +20 -0
  41. package/dist/debug/path/meta/MetaController.cjs +1 -0
  42. package/dist/debug/path/meta/MetaController.js +214 -0
  43. package/dist/debug/path/meta/RaphMeta.cjs +1 -0
  44. package/dist/debug/path/meta/RaphMeta.js +68 -0
  45. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  46. package/dist/debug/path/meta/RaphMetaStore.js +184 -0
  47. package/dist/debug/path/meta/meta.types.cjs +1 -0
  48. package/dist/debug/path/meta/meta.types.js +1 -0
  49. package/dist/debug/path/path.types.cjs +1 -0
  50. package/dist/debug/path/path.types.js +1 -0
  51. package/dist/debug/path/pathSegmentKey.cjs +1 -0
  52. package/dist/debug/path/pathSegmentKey.js +12 -0
  53. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  54. package/dist/debug/path/storage/AdapterPathStore.js +133 -0
  55. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  56. package/dist/debug/path/storage/DefaultDataAdapter.js +356 -0
  57. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  58. package/dist/debug/path/storage/PathEventHub.js +148 -0
  59. package/dist/debug/path/storage/PathStore.cjs +1 -0
  60. package/dist/debug/path/storage/PathStore.js +326 -0
  61. package/dist/debug/path/storage/createDataDraft.cjs +1 -0
  62. package/dist/debug/path/storage/createDataDraft.js +71 -0
  63. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  64. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  65. package/dist/debug/reactivity/engine.cjs +1 -0
  66. package/dist/debug/reactivity/engine.js +1305 -0
  67. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  68. package/dist/debug/reactivity/reactive-object.js +280 -0
  69. package/dist/debug/reactivity/scope.cjs +1 -0
  70. package/dist/debug/reactivity/scope.js +274 -0
  71. package/dist/debug/reactivity/types.cjs +1 -0
  72. package/dist/debug/reactivity/types.js +1 -0
  73. package/dist/debug/reactivity/watch.cjs +1 -0
  74. package/dist/debug/reactivity/watch.js +64 -0
  75. package/dist/debug/runtime/RaphRuntime.cjs +1 -0
  76. package/dist/debug/runtime/RaphRuntime.js +979 -0
  77. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  78. package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
  79. package/dist/debug/runtime/errors.cjs +1 -0
  80. package/dist/debug/runtime/errors.js +15 -0
  81. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  82. package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
  83. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  84. package/dist/debug/runtime/ownership/RaphNode.js +206 -0
  85. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  86. package/dist/debug/runtime/ownership/RaphScope.js +101 -0
  87. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  88. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  89. package/dist/debug/runtime/ownership/parentGraph.cjs +1 -0
  90. package/dist/debug/runtime/ownership/parentGraph.js +10 -0
  91. package/dist/debug/runtime/ownership/throwDisposalErrors.cjs +1 -0
  92. package/dist/debug/runtime/ownership/throwDisposalErrors.js +9 -0
  93. package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
  94. package/dist/debug/runtime/phases/RaphFrameLoop.js +106 -0
  95. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  96. package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
  97. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  98. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  99. package/dist/debug/runtime/phases/phase.types.cjs +1 -0
  100. package/dist/debug/runtime/phases/phase.types.js +8 -0
  101. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  102. package/dist/debug/runtime/reactivity/PathHandle.js +175 -0
  103. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  104. package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
  105. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  106. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
  107. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  108. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
  109. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  110. package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
  111. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  112. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  113. package/dist/entrypoints/machine-testing.d.ts +2 -0
  114. package/dist/entrypoints/machine.d.ts +5 -0
  115. package/dist/entrypoints/path.d.ts +14 -0
  116. package/dist/entrypoints/reactivity.d.ts +1 -0
  117. package/dist/entrypoints/runtime.d.ts +17 -0
  118. package/dist/index.cjs +1 -0
  119. package/dist/index.js +48 -0
  120. package/dist/machine/compiler.d.ts +71 -0
  121. package/dist/machine/core.d.ts +50 -0
  122. package/dist/machine/persistence.d.ts +5 -0
  123. package/dist/machine/runtime.d.ts +4 -0
  124. package/dist/machine/testing.d.ts +43 -0
  125. package/dist/machine/types.d.ts +155 -0
  126. package/dist/machine-testing.cjs +1 -0
  127. package/dist/machine-testing.js +188 -0
  128. package/dist/machine.cjs +1 -0
  129. package/dist/machine.js +837 -0
  130. package/dist/main.d.ts +20 -0
  131. package/dist/path/DataPath.d.ts +73 -0
  132. package/dist/path/PathRouter.d.ts +21 -0
  133. package/dist/path/RaphKernel.d.ts +169 -0
  134. package/dist/path/data-path.types.d.ts +34 -0
  135. package/dist/path/data-path.utils.d.ts +9 -0
  136. package/dist/path/derived/DerivedRegistry.d.ts +67 -0
  137. package/dist/path/derived/RaphDerivedHandle.d.ts +97 -0
  138. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  139. package/dist/path/derived/derived-collection.utils.d.ts +20 -0
  140. package/dist/path/derived/derived-strategy.types.d.ts +12 -0
  141. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  142. package/dist/path/meta/MetaController.d.ts +85 -0
  143. package/dist/path/meta/RaphMeta.d.ts +45 -0
  144. package/dist/path/meta/RaphMetaStore.d.ts +45 -0
  145. package/dist/path/meta/meta.types.d.ts +31 -0
  146. package/dist/path/path.types.d.ts +27 -0
  147. package/dist/path/pathSegmentKey.d.ts +2 -0
  148. package/dist/path/storage/AdapterPathStore.d.ts +45 -0
  149. package/dist/path/storage/DefaultDataAdapter.d.ts +63 -0
  150. package/dist/path/storage/PathEventHub.d.ts +48 -0
  151. package/dist/path/storage/PathStore.d.ts +51 -0
  152. package/dist/path/storage/createDataDraft.d.ts +4 -0
  153. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  154. package/dist/path.cjs +1 -0
  155. package/dist/path.js +18 -0
  156. package/dist/raph.cjs +1 -0
  157. package/dist/raph.js +48 -0
  158. package/dist/reactivity/engine.d.ts +393 -0
  159. package/dist/reactivity/reactive-object.d.ts +36 -0
  160. package/dist/reactivity/scope.d.ts +146 -0
  161. package/dist/reactivity/types.d.ts +175 -0
  162. package/dist/reactivity/watch.d.ts +15 -0
  163. package/dist/reactivity.cjs +1 -0
  164. package/dist/reactivity.js +14 -0
  165. package/dist/runtime/RaphRuntime.d.ts +225 -0
  166. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  167. package/dist/runtime/errors.d.ts +21 -0
  168. package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
  169. package/dist/runtime/ownership/RaphNode.d.ts +40 -0
  170. package/dist/runtime/ownership/RaphScope.d.ts +38 -0
  171. package/dist/runtime/ownership/parent-graph.types.d.ts +4 -0
  172. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  173. package/dist/runtime/ownership/throwDisposalErrors.d.ts +1 -0
  174. package/dist/runtime/phases/RaphFrameLoop.d.ts +51 -0
  175. package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
  176. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  177. package/dist/runtime/phases/phase.types.d.ts +92 -0
  178. package/dist/runtime/reactivity/PathHandle.d.ts +80 -0
  179. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  180. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
  181. package/dist/runtime/reactivity/RuntimeReactivity.d.ts +45 -0
  182. package/dist/runtime/reactivity/RuntimeWatch.d.ts +34 -0
  183. package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +11 -0
  184. package/dist/runtime.cjs +1 -0
  185. package/dist/runtime.js +23 -0
  186. package/package.json +141 -0
@@ -0,0 +1,394 @@
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 {
5
+ /**
6
+ * Сохраняет уже разобранный immutable path value.
7
+ */
8
+ constructor(e, t) {
9
+ // Хранят canonical value и разобранные сегменты пути.
10
+ o(this, "_canonical");
11
+ o(this, "_segments");
12
+ // Кешируют проверенные exact и mask представления.
13
+ o(this, "_exact");
14
+ o(this, "_mask");
15
+ this._canonical = e, this._segments = Object.freeze(
16
+ t.map((r) => Object.freeze({ ...r }))
17
+ );
18
+ }
19
+ /**
20
+ * Нормализует поддерживаемое определение пути в DataPath.
21
+ */
22
+ static from(e, t) {
23
+ return e instanceof u ? e : typeof e == "string" ? this.fromString(e, t) : this.fromPlain(e);
24
+ }
25
+ /**
26
+ * Разбирает строковый path согласно строгой грамматике.
27
+ */
28
+ static fromString(e, t) {
29
+ const r = m(
30
+ e,
31
+ t == null ? void 0 : t.vars,
32
+ !0,
33
+ (t == null ? void 0 : t.wildcardDynamic) === !0,
34
+ !0
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;
41
+ }
42
+ /**
43
+ * Восстанавливает DataPath из сериализованного представления.
44
+ */
45
+ static fromPlain(e) {
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);
86
+ }
87
+ /**
88
+ * Сериализует path в независимое plain-представление.
89
+ */
90
+ toPlain() {
91
+ return {
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 }),
93
+ deepOnTail: b(this._segments)
94
+ };
95
+ }
96
+ /**
97
+ * Возвращает canonical строковое представление пути.
98
+ */
99
+ toStringPath() {
100
+ return this._canonical;
101
+ }
102
+ /**
103
+ * Возвращает canonical строковое представление пути.
104
+ */
105
+ toString() {
106
+ return this._canonical;
107
+ }
108
+ /**
109
+ * Возвращает immutable список сегментов пути.
110
+ */
111
+ segments() {
112
+ return this._segments;
113
+ }
114
+ /**
115
+ * Проверяет соответствие exact path указанной маске.
116
+ */
117
+ static match(e, t) {
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)
123
+ return !0;
124
+ const a = s[i];
125
+ if (a === void 0 || !j(c, a))
126
+ return !1;
127
+ }
128
+ return i === s.length;
129
+ }
130
+ /**
131
+ * Возвращает exact path либо отклоняет wildcard-сегменты.
132
+ * @internal
133
+ */
134
+ _asExact() {
135
+ for (const e of this._segments)
136
+ if (e.kind === "wildcard")
137
+ throw y(this._canonical);
138
+ return this._exact ?? (this._exact = {
139
+ canonical: this._canonical,
140
+ segments: this._segments
141
+ });
142
+ }
143
+ /**
144
+ * Возвращает path mask с проверкой позиции wildcard.
145
+ * @internal
146
+ */
147
+ _asMask() {
148
+ for (let t = 0; t < this._segments.length - 1; t++) {
149
+ const r = this._segments[t];
150
+ if (r.kind === "wildcard" && !r.indexed)
151
+ throw new TypeError(
152
+ `[Raph] Dot wildcard must be the final mask segment: "${this._canonical}".`
153
+ );
154
+ }
155
+ const e = b(this._segments);
156
+ return this._mask ?? (this._mask = {
157
+ canonical: this._canonical,
158
+ deep: e,
159
+ segments: e ? this._segments.slice(0, -1) : this._segments
160
+ });
161
+ }
162
+ };
163
+ // Переиспользует immutable экземпляры для одинаковых canonical paths.
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)
170
+ return { canonical: "", segments: [] };
171
+ throw new TypeError("[Raph] Data path must not be empty.");
172
+ }
173
+ const c = [];
174
+ let a = 0, l = !0;
175
+ for (; a < i.length; ) {
176
+ const x = i[a];
177
+ if (x === ".") {
178
+ if (l)
179
+ throw d(n);
180
+ l = !0, a++;
181
+ continue;
182
+ }
183
+ if (x === "[") {
184
+ const _ = E(i, a);
185
+ c.push(T(
186
+ i.slice(a + 1, _),
187
+ e,
188
+ t,
189
+ r
190
+ )), a = _ + 1, l = !1;
191
+ continue;
192
+ }
193
+ if (!l)
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 === "*") {
202
+ if (!t)
203
+ throw y(n);
204
+ c.push({ kind: "wildcard", indexed: !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;
207
+ }
208
+ if (l || c.length === 0)
209
+ throw d(n);
210
+ return { canonical: w(c), segments: c };
211
+ }
212
+ function E(n, e) {
213
+ let t, r = 1;
214
+ for (let s = e + 1; s < n.length; s++) {
215
+ const i = n[s];
216
+ if (i === "\\") {
217
+ s++;
218
+ continue;
219
+ }
220
+ if (t !== void 0) {
221
+ i === t && (t = void 0);
222
+ continue;
223
+ }
224
+ if (i === '"' || i === "'") {
225
+ t = i;
226
+ continue;
227
+ }
228
+ if (i === "[") {
229
+ r++;
230
+ continue;
231
+ }
232
+ if (i === "]" && --r === 0)
233
+ return s;
234
+ }
235
+ throw d(n);
236
+ }
237
+ function T(n, e, t, r) {
238
+ const s = n.trim();
239
+ if (s === "*") {
240
+ if (!t)
241
+ throw y(`[${n}]`);
242
+ return { kind: "wildcard", indexed: !0 };
243
+ }
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))
248
+ return { kind: "wildcard", indexed: !0 };
249
+ const l = p(s.slice(1), e);
250
+ if (!Number.isInteger(l) || l < 0)
251
+ throw new TypeError(`[Raph] Index variable "${s}" must be a non-negative integer.`);
252
+ return { kind: "index", index: l };
253
+ }
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();
258
+ if (!c || !a)
259
+ throw d(`[${n}]`);
260
+ return r && I(a, e) ? { kind: "wildcard", indexed: !0 } : {
261
+ kind: "selector",
262
+ key: c,
263
+ value: A(a, e)
264
+ };
265
+ }
266
+ function R(n) {
267
+ let e;
268
+ for (let t = 0; t < n.length; t++) {
269
+ const r = n[t];
270
+ if (r === "\\") {
271
+ t++;
272
+ continue;
273
+ }
274
+ if (e !== void 0) {
275
+ r === e && (e = void 0);
276
+ continue;
277
+ }
278
+ if (r === '"' || r === "'")
279
+ e = r;
280
+ else if (r === "=")
281
+ return t;
282
+ }
283
+ return -1;
284
+ }
285
+ function A(n, e) {
286
+ if (/^\$[A-Z_$][\w$]*$/i.test(n)) {
287
+ const t = p(n.slice(1), e);
288
+ if (t === null || typeof t == "string" || typeof t == "boolean" || typeof t == "number" && Number.isFinite(t))
289
+ return t;
290
+ throw new TypeError(`[Raph] Selector variable "${n}" must be scalar.`);
291
+ }
292
+ if (n[0] === '"' || n[0] === "'")
293
+ return P(n);
294
+ if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(n)) {
295
+ const t = Number(n);
296
+ if (Number.isFinite(t))
297
+ return t;
298
+ }
299
+ return n === "true" ? !0 : n === "false" ? !1 : n === "null" ? null : n;
300
+ }
301
+ function P(n) {
302
+ const e = n[0];
303
+ if (n.length < 2 || n[n.length - 1] !== e)
304
+ throw d(n);
305
+ if (e === '"')
306
+ try {
307
+ const r = JSON.parse(n);
308
+ if (typeof r == "string")
309
+ return r;
310
+ } catch {
311
+ throw d(n);
312
+ }
313
+ let t = "";
314
+ for (let r = 1; r < n.length - 1; r++) {
315
+ const s = n[r];
316
+ if (s === "\\") {
317
+ if (r++, r >= n.length - 1)
318
+ throw d(n);
319
+ t += n[r];
320
+ } else
321
+ t += s;
322
+ }
323
+ return t;
324
+ }
325
+ function N(n, e) {
326
+ if (!n.startsWith("$"))
327
+ return n;
328
+ const t = p(n.slice(1), e);
329
+ if (typeof t != "string" && typeof t != "number")
330
+ throw new TypeError(`[Raph] Key variable "${n}" must be a string or number.`);
331
+ const r = String(t);
332
+ if (!r || r.includes(".") || r.includes("[") || r.includes("]"))
333
+ throw new TypeError(`[Raph] Key variable "${n}" contains path syntax.`);
334
+ return r;
335
+ }
336
+ function p(n, e) {
337
+ if (!g(n, e))
338
+ throw new TypeError(`[Raph] Missing path variable "${n}".`);
339
+ return e[n];
340
+ }
341
+ function g(n, e) {
342
+ return e !== void 0 && Object.hasOwn(e, n);
343
+ }
344
+ function I(n, e) {
345
+ for (const t of n.matchAll(/\$([A-Z_$][\w$]*)/gi))
346
+ if (!g(t[1], e))
347
+ return !0;
348
+ return !1;
349
+ }
350
+ function O(n) {
351
+ if (typeof n != "object" || n === null)
352
+ throw $();
353
+ const e = n;
354
+ if (e.t === "key" && typeof e.k == "string")
355
+ return { kind: "key", key: e.k };
356
+ if (e.t === "idx" && typeof e.i == "number" && Number.isInteger(e.i) && e.i >= 0)
357
+ return { kind: "index", index: e.i };
358
+ if (e.t === "wc")
359
+ return { kind: "wildcard", indexed: e.indexed === !0 };
360
+ if (e.t === "param" && typeof e.pk == "string" && M(e.pv))
361
+ return { kind: "selector", key: e.pk, value: e.pv };
362
+ throw $();
363
+ }
364
+ function M(n) {
365
+ return n === null || typeof n == "string" || typeof n == "boolean" || typeof n == "number" && Number.isFinite(n);
366
+ }
367
+ function b(n) {
368
+ const e = n[n.length - 1];
369
+ return (e == null ? void 0 : e.kind) === "wildcard" && !e.indexed;
370
+ }
371
+ function j(n, e) {
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);
373
+ }
374
+ function w(n) {
375
+ let e = "";
376
+ for (const t of n)
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 ? ".*" : "*";
378
+ return e;
379
+ }
380
+ function C(n) {
381
+ return typeof n == "string" ? JSON.stringify(n) : String(n);
382
+ }
383
+ function d(n) {
384
+ return new TypeError(`[Raph] Invalid data path "${n}".`);
385
+ }
386
+ function $() {
387
+ return new TypeError("[Raph] Invalid plain DataPath representation.");
388
+ }
389
+ function y(n) {
390
+ return new TypeError(`[Raph] Wildcard is only allowed in watch masks: "${n}".`);
391
+ }
392
+ export {
393
+ k as DataPath
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;
@@ -0,0 +1,86 @@
1
+ var h = Object.defineProperty;
2
+ var u = (n, t, i) => t in n ? h(n, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[t] = i;
3
+ var p = (n, t, i) => u(n, typeof t != "symbol" ? t + "" : t, i);
4
+ import { pathSegmentKey as x } from "./pathSegmentKey.js";
5
+ class m {
6
+ constructor() {
7
+ // Корень trie разделяет exact и indexed-wildcard transitions.
8
+ p(this, "_root", {});
9
+ }
10
+ /**
11
+ * Регистрирует route mask и возвращает функцию удаления.
12
+ */
13
+ add(t, i) {
14
+ let e = this._root;
15
+ const o = [];
16
+ for (const c of t.segments)
17
+ if (c.kind === "wildcard") {
18
+ const d = e.indexedWildcard ?? (e.indexedWildcard = {});
19
+ o.push({ child: d, parent: e, indexedWildcard: !0 }), e = d;
20
+ } else {
21
+ const d = x(c), a = e.exact ?? (e.exact = /* @__PURE__ */ new Map());
22
+ let s = a.get(d);
23
+ s === void 0 && (s = {}, a.set(d, s)), o.push({ child: s, key: d, parent: e, indexedWildcard: !1 }), e = s;
24
+ }
25
+ const r = t.deep ? e.deep ?? (e.deep = /* @__PURE__ */ new Set()) : e.end ?? (e.end = /* @__PURE__ */ new Set());
26
+ r.add(i);
27
+ let l = !0;
28
+ return () => {
29
+ if (l) {
30
+ l = !1, r.delete(i), r.size === 0 && (t.deep ? e.deep = void 0 : e.end = void 0);
31
+ for (let c = o.length - 1; c >= 0; c--) {
32
+ const d = o[c];
33
+ if (!v(d.child))
34
+ break;
35
+ d.indexedWildcard ? d.parent.indexedWildcard = void 0 : (d.parent.exact.delete(d.key), d.parent.exact.size === 0 && (d.parent.exact = void 0));
36
+ }
37
+ }
38
+ };
39
+ }
40
+ /**
41
+ * Возвращает routes, чьи masks соответствуют указанному событию.
42
+ */
43
+ match(t) {
44
+ var o;
45
+ let i = [this._root];
46
+ const e = /* @__PURE__ */ new Set();
47
+ for (let r = 0; r <= t.length; r++) {
48
+ const l = r === t.length, c = [];
49
+ for (const d of i) {
50
+ if (f(e, d.deep), l) {
51
+ f(e, d.end);
52
+ continue;
53
+ }
54
+ const a = t[r], s = (o = d.exact) == null ? void 0 : o.get(x(a));
55
+ s !== void 0 && c.push(s), d.indexedWildcard !== void 0 && (a.kind === "index" || a.kind === "selector") && c.push(d.indexedWildcard);
56
+ }
57
+ if (l || (i = c, i.length === 0))
58
+ break;
59
+ }
60
+ return e;
61
+ }
62
+ /**
63
+ * При замене root возвращает все зарегистрированные path masks.
64
+ */
65
+ matchAll() {
66
+ const t = /* @__PURE__ */ new Set(), i = [this._root];
67
+ for (; i.length; ) {
68
+ const e = i.pop();
69
+ if (f(t, e.deep), f(t, e.end), e.indexedWildcard !== void 0 && i.push(e.indexedWildcard), e.exact !== void 0)
70
+ for (const o of e.exact.values())
71
+ i.push(o);
72
+ }
73
+ return t;
74
+ }
75
+ }
76
+ function f(n, t) {
77
+ if (t !== void 0)
78
+ for (const i of t)
79
+ n.add(i);
80
+ }
81
+ function v(n) {
82
+ return n.deep === void 0 && n.end === void 0 && n.exact === void 0 && n.indexedWildcard === void 0;
83
+ }
84
+ export {
85
+ m as PathRouter
86
+ };
@@ -0,0 +1 @@
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;