@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.
- package/README.md +1096 -0
- package/dist/api/Raph.d.ts +59 -190
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +9 -4
- package/dist/api/types.d.ts +162 -17
- package/dist/core-CyilRD7s.js +1055 -0
- package/dist/core-ugchZNqC.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -366
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +306 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +149 -0
- package/dist/debug/api/errors.cjs +1 -1
- package/dist/debug/api/errors.js +10 -7
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +258 -207
- package/dist/debug/path/data-path.utils.cjs +1 -0
- package/dist/debug/path/data-path.utils.js +56 -0
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
- package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
- package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.types.js +1 -0
- package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +478 -306
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +280 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +798 -519
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
- package/dist/debug/runtime/errors.cjs +1 -1
- package/dist/debug/runtime/errors.js +6 -3
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +206 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +101 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +17 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -38
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +837 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
- package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
- package/dist/path/RaphKernel.d.ts +13 -10
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
- package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
- package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
- package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
- package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
- package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
- package/dist/path/path.types.d.ts +3 -2
- package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
- package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
- package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
- package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -1
- package/dist/path.js +16 -16
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +46 -38
- package/dist/reactivity/engine.d.ts +17 -3
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/types.d.ts +25 -0
- package/dist/reactivity.cjs +1 -1
- package/dist/reactivity.js +12 -12
- package/dist/runtime/RaphRuntime.d.ts +132 -192
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
- package/dist/runtime/ownership/RaphNode.d.ts +40 -0
- package/dist/runtime/ownership/RaphScope.d.ts +38 -0
- package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +92 -0
- package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
- package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
- package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +68 -35
- package/ReadMe.md +0 -153
- package/dist/api/public.d.ts +0 -22
- package/dist/debug/api/public.cjs +0 -1
- package/dist/debug/api/public.js +0 -40
- package/dist/debug/path/AdapterPathStore.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/public.cjs +0 -1
- package/dist/debug/path/public.js +0 -18
- package/dist/debug/runtime/PathHandle.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphNode.cjs +0 -1
- package/dist/debug/runtime/RaphNode.js +0 -143
- package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
- package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
- package/dist/debug/runtime/RaphScope.cjs +0 -1
- package/dist/debug/runtime/RaphScope.js +0 -64
- package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
- package/dist/debug/runtime/RuntimeReactivity.js +0 -154
- package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
- package/dist/debug/runtime/RuntimeWatch.js +0 -71
- package/dist/debug/runtime/public.cjs +0 -1
- package/dist/debug/runtime/public.js +0 -18
- package/dist/path/public.d.ts +0 -14
- package/dist/runtime/RaphDebug.d.ts +0 -32
- package/dist/runtime/RaphNode.d.ts +0 -68
- package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
- package/dist/runtime/RaphScope.d.ts +0 -50
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
- /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
- /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
- /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
- /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
- /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
- /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
- /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
- /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
- /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
- /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
- /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
- /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
- /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
- /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
- /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
- /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
- /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
- /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
- /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
- /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
- /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
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
|
-
|
|
12
|
-
|
|
10
|
+
o(this, "_canonical");
|
|
11
|
+
o(this, "_segments");
|
|
13
12
|
// Кешируют проверенные exact и mask представления.
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
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 =
|
|
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
|
-
),
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
const c = new
|
|
41
|
-
return
|
|
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(
|
|
48
|
-
return new
|
|
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:
|
|
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,
|
|
82
|
-
let
|
|
83
|
-
for (;
|
|
84
|
-
const c = r[
|
|
85
|
-
if (c.kind === "wildcard" && !c.indexed &&
|
|
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
|
|
88
|
-
if (a === void 0 || !
|
|
124
|
+
const a = s[i];
|
|
125
|
+
if (a === void 0 || !j(c, a))
|
|
89
126
|
return !1;
|
|
90
127
|
}
|
|
91
|
-
return
|
|
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
|
|
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 =
|
|
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
|
|
128
|
-
let
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (
|
|
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 <
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
175
|
+
for (; a < i.length; ) {
|
|
176
|
+
const x = i[a];
|
|
177
|
+
if (x === ".") {
|
|
204
178
|
if (l)
|
|
205
|
-
throw
|
|
179
|
+
throw d(n);
|
|
206
180
|
l = !0, a++;
|
|
207
181
|
continue;
|
|
208
182
|
}
|
|
209
|
-
if (
|
|
210
|
-
const
|
|
211
|
-
c.push(
|
|
212
|
-
|
|
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 =
|
|
190
|
+
)), a = _ + 1, l = !1;
|
|
217
191
|
continue;
|
|
218
192
|
}
|
|
219
193
|
if (!l)
|
|
220
|
-
throw
|
|
221
|
-
let
|
|
222
|
-
for (;
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
throw
|
|
227
|
-
if (
|
|
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
|
|
203
|
+
throw y(n);
|
|
230
204
|
c.push({ kind: "wildcard", indexed: !1 });
|
|
231
|
-
} else r &&
|
|
232
|
-
a =
|
|
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
|
|
236
|
-
return { canonical:
|
|
209
|
+
throw d(n);
|
|
210
|
+
return { canonical: w(c), segments: c };
|
|
237
211
|
}
|
|
238
|
-
function
|
|
212
|
+
function E(n, e) {
|
|
239
213
|
let t, r = 1;
|
|
240
|
-
for (let
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
|
|
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
|
-
|
|
221
|
+
i === t && (t = void 0);
|
|
248
222
|
continue;
|
|
249
223
|
}
|
|
250
|
-
if (
|
|
251
|
-
t =
|
|
224
|
+
if (i === '"' || i === "'") {
|
|
225
|
+
t = i;
|
|
252
226
|
continue;
|
|
253
227
|
}
|
|
254
|
-
if (
|
|
228
|
+
if (i === "[") {
|
|
255
229
|
r++;
|
|
256
230
|
continue;
|
|
257
231
|
}
|
|
258
|
-
if (
|
|
259
|
-
return
|
|
232
|
+
if (i === "]" && --r === 0)
|
|
233
|
+
return s;
|
|
260
234
|
}
|
|
261
|
-
throw
|
|
235
|
+
throw d(n);
|
|
262
236
|
}
|
|
263
|
-
function
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
237
|
+
function T(n, e, t, r) {
|
|
238
|
+
const s = n.trim();
|
|
239
|
+
if (s === "*") {
|
|
266
240
|
if (!t)
|
|
267
|
-
throw
|
|
241
|
+
throw y(`[${n}]`);
|
|
268
242
|
return { kind: "wildcard", indexed: !0 };
|
|
269
243
|
}
|
|
270
|
-
if (/^\d+$/.test(
|
|
271
|
-
return { kind: "index", index: Number(
|
|
272
|
-
if (/^\$[A-Z_$][\w$]*$/i.test(
|
|
273
|
-
if (r && !
|
|
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(
|
|
249
|
+
const l = p(s.slice(1), e);
|
|
276
250
|
if (!Number.isInteger(l) || l < 0)
|
|
277
|
-
throw new TypeError(`[Raph] Index variable "${
|
|
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
|
|
281
|
-
if (
|
|
282
|
-
throw
|
|
283
|
-
const c =
|
|
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
|
|
286
|
-
return r &&
|
|
259
|
+
throw d(`[${n}]`);
|
|
260
|
+
return r && I(a, e) ? { kind: "wildcard", indexed: !0 } : {
|
|
287
261
|
kind: "selector",
|
|
288
262
|
key: c,
|
|
289
|
-
value:
|
|
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
|
|
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
|
|
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
|
|
301
|
+
function P(n) {
|
|
328
302
|
const e = n[0];
|
|
329
303
|
if (n.length < 2 || n[n.length - 1] !== e)
|
|
330
|
-
throw
|
|
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
|
|
311
|
+
throw d(n);
|
|
338
312
|
}
|
|
339
313
|
let t = "";
|
|
340
314
|
for (let r = 1; r < n.length - 1; r++) {
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
315
|
+
const s = n[r];
|
|
316
|
+
if (s === "\\") {
|
|
343
317
|
if (r++, r >= n.length - 1)
|
|
344
|
-
throw
|
|
318
|
+
throw d(n);
|
|
345
319
|
t += n[r];
|
|
346
320
|
} else
|
|
347
|
-
t +=
|
|
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 (!
|
|
337
|
+
if (!g(n, e))
|
|
364
338
|
throw new TypeError(`[Raph] Missing path variable "${n}".`);
|
|
365
339
|
return e[n];
|
|
366
340
|
}
|
|
367
|
-
function
|
|
341
|
+
function g(n, e) {
|
|
368
342
|
return e !== void 0 && Object.hasOwn(e, n);
|
|
369
343
|
}
|
|
370
|
-
function
|
|
344
|
+
function I(n, e) {
|
|
371
345
|
for (const t of n.matchAll(/\$([A-Z_$][\w$]*)/gi))
|
|
372
|
-
if (!
|
|
346
|
+
if (!g(t[1], e))
|
|
373
347
|
return !0;
|
|
374
348
|
return !1;
|
|
375
349
|
}
|
|
376
|
-
function
|
|
350
|
+
function O(n) {
|
|
377
351
|
if (typeof n != "object" || n === null)
|
|
378
|
-
throw
|
|
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" &&
|
|
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
|
|
362
|
+
throw $();
|
|
389
363
|
}
|
|
390
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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}=${
|
|
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
|
|
380
|
+
function C(n) {
|
|
407
381
|
return typeof n == "string" ? JSON.stringify(n) : String(n);
|
|
408
382
|
}
|
|
409
|
-
function
|
|
383
|
+
function d(n) {
|
|
410
384
|
return new TypeError(`[Raph] Invalid data path "${n}".`);
|
|
411
385
|
}
|
|
412
|
-
function
|
|
386
|
+
function $() {
|
|
413
387
|
return new TypeError("[Raph] Invalid plain DataPath representation.");
|
|
414
388
|
}
|
|
415
|
-
function
|
|
389
|
+
function y(n) {
|
|
416
390
|
return new TypeError(`[Raph] Wildcard is only allowed in watch masks: "${n}".`);
|
|
417
391
|
}
|
|
418
392
|
export {
|
|
419
|
-
|
|
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 "./
|
|
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;
|