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