@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
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { parseDataPath as h } from "../data-path.utils.js";
|
|
2
|
+
import { createDataDraft as A } from "./createDataDraft.js";
|
|
3
|
+
class v {
|
|
4
|
+
// Хранят root, нормализованные опции и ленивые selector indexes.
|
|
5
|
+
_root;
|
|
6
|
+
_options;
|
|
7
|
+
_indexes;
|
|
7
8
|
/**
|
|
8
9
|
* Создаёт in-memory adapter с заданным начальным root и опциями.
|
|
9
10
|
*/
|
|
10
|
-
constructor(e =
|
|
11
|
-
|
|
12
|
-
y(this, "_root");
|
|
13
|
-
y(this, "_options");
|
|
14
|
-
y(this, "_indexes");
|
|
15
|
-
this._root = _(e), this._options = {
|
|
11
|
+
constructor(e = b(), t = {}) {
|
|
12
|
+
this._root = x(e), this._options = {
|
|
16
13
|
arrayDelete: t.arrayDelete ?? "unset",
|
|
17
14
|
autoCreate: t.autoCreate ?? !0,
|
|
18
15
|
indexEnabled: t.indexEnabled ?? !0,
|
|
@@ -29,17 +26,14 @@ class A {
|
|
|
29
26
|
* Создаёт изолированную copy-on-write проекцию для синхронной проверки mutation.
|
|
30
27
|
*/
|
|
31
28
|
fork() {
|
|
32
|
-
const e = new
|
|
33
|
-
return e._root =
|
|
34
|
-
var r;
|
|
35
|
-
return (r = e._indexes) == null ? void 0 : r.delete(t);
|
|
36
|
-
}).root, e;
|
|
29
|
+
const e = new v({}, this._options);
|
|
30
|
+
return e._root = A(this._root, (t) => e._indexes?.delete(t)).root, e;
|
|
37
31
|
}
|
|
38
32
|
/**
|
|
39
33
|
* Заменяет корневой объект без path-level публикации.
|
|
40
34
|
*/
|
|
41
35
|
replaceRoot(e) {
|
|
42
|
-
this._root =
|
|
36
|
+
this._root = x(e), this._indexes = void 0;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* Обновляет изменяемые опции adapter и сбрасывает построенные indexes.
|
|
@@ -65,7 +59,7 @@ class A {
|
|
|
65
59
|
set(e, t, r) {
|
|
66
60
|
const i = h(e, r);
|
|
67
61
|
if (i.segments.length === 0) {
|
|
68
|
-
this.replaceRoot(
|
|
62
|
+
this.replaceRoot(x(t));
|
|
69
63
|
return;
|
|
70
64
|
}
|
|
71
65
|
let s = this._root, n;
|
|
@@ -88,7 +82,7 @@ class A {
|
|
|
88
82
|
const i = this.get(e, r);
|
|
89
83
|
if (f(i) && f(t)) {
|
|
90
84
|
for (const s of Object.keys(t))
|
|
91
|
-
|
|
85
|
+
k(i, s, t[s]);
|
|
92
86
|
this._indexes = void 0;
|
|
93
87
|
return;
|
|
94
88
|
}
|
|
@@ -100,7 +94,7 @@ class A {
|
|
|
100
94
|
delete(e, t) {
|
|
101
95
|
const r = h(e, t);
|
|
102
96
|
if (r.segments.length === 0) {
|
|
103
|
-
this._root =
|
|
97
|
+
this._root = b(), this._indexes = void 0;
|
|
104
98
|
return;
|
|
105
99
|
}
|
|
106
100
|
let i = this._root;
|
|
@@ -197,44 +191,44 @@ class A {
|
|
|
197
191
|
let n = e[t.key];
|
|
198
192
|
if (!Object.hasOwn(e, t.key) || n === void 0) {
|
|
199
193
|
if (!this._options.autoCreate)
|
|
200
|
-
throw
|
|
201
|
-
n =
|
|
194
|
+
throw y(i);
|
|
195
|
+
n = p(r), k(e, t.key, n);
|
|
202
196
|
}
|
|
203
|
-
return { value:
|
|
197
|
+
return { value: _(n, i) };
|
|
204
198
|
}
|
|
205
199
|
if (!Array.isArray(e))
|
|
206
|
-
throw
|
|
200
|
+
throw w(i);
|
|
207
201
|
if (t.kind === "index") {
|
|
208
202
|
let n = e[t.index];
|
|
209
203
|
if (!Object.hasOwn(e, t.index) || n === void 0) {
|
|
210
204
|
if (!this._options.autoCreate)
|
|
211
|
-
throw
|
|
212
|
-
n =
|
|
205
|
+
throw y(i);
|
|
206
|
+
n = p(r), e[t.index] = n;
|
|
213
207
|
}
|
|
214
208
|
return {
|
|
215
|
-
value:
|
|
209
|
+
value: _(n, i),
|
|
216
210
|
indexedParent: { array: e, index: t.index }
|
|
217
211
|
};
|
|
218
212
|
}
|
|
219
213
|
let s = this._findSelector(e, t.key, t.value);
|
|
220
214
|
if (s === -1) {
|
|
221
215
|
if (!this._options.autoCreate)
|
|
222
|
-
throw
|
|
216
|
+
throw y(i);
|
|
223
217
|
const n = /* @__PURE__ */ Object.create(null);
|
|
224
218
|
n[t.key] = t.value, e.push(n), s = e.length - 1, this._invalidateArray(e);
|
|
225
219
|
}
|
|
226
220
|
return {
|
|
227
|
-
value:
|
|
221
|
+
value: _(e[s], i),
|
|
228
222
|
indexedParent: { array: e, index: s }
|
|
229
223
|
};
|
|
230
224
|
}
|
|
231
225
|
_writeSegment(e, t, r, i, s) {
|
|
232
226
|
if (t.kind === "key") {
|
|
233
|
-
|
|
227
|
+
k(e, t.key, r), s !== void 0 && s.array[s.index] === e && this._invalidateIndexKey(s.array, t.key);
|
|
234
228
|
return;
|
|
235
229
|
}
|
|
236
230
|
if (!Array.isArray(e))
|
|
237
|
-
throw
|
|
231
|
+
throw w(i);
|
|
238
232
|
if (t.kind === "index") {
|
|
239
233
|
e[t.index] = r, this._invalidateArray(e);
|
|
240
234
|
return;
|
|
@@ -245,34 +239,30 @@ class A {
|
|
|
245
239
|
throw new TypeError(`[Raph] Selector target at "${i}" has a conflicting key.`);
|
|
246
240
|
const n = this._findSelector(e, t.key, t.value);
|
|
247
241
|
if (n === -1 && !this._options.autoCreate)
|
|
248
|
-
throw
|
|
242
|
+
throw y(i);
|
|
249
243
|
const d = Object.hasOwn(r, t.key) ? r : { ...r, [t.key]: t.value };
|
|
250
244
|
n === -1 ? e.push(d) : e[n] = d, this._invalidateArray(e);
|
|
251
245
|
}
|
|
252
246
|
_invalidateArray(e) {
|
|
253
|
-
|
|
254
|
-
(t = this._indexes) == null || t.delete(e);
|
|
247
|
+
this._indexes?.delete(e);
|
|
255
248
|
}
|
|
256
249
|
_invalidateIndexKey(e, t) {
|
|
257
|
-
|
|
258
|
-
const r = (i = this._indexes) == null ? void 0 : i.get(e);
|
|
250
|
+
const r = this._indexes?.get(e);
|
|
259
251
|
r !== void 0 && (r.delete(t), r.size === 0 && this._indexes.delete(e));
|
|
260
252
|
}
|
|
261
253
|
_findSelector(e, t, r) {
|
|
262
|
-
var a;
|
|
263
254
|
if (!this._options.indexEnabled)
|
|
264
|
-
return
|
|
265
|
-
|
|
266
|
-
let s = i == null ? void 0 : i.get(t);
|
|
255
|
+
return O(e, t, r);
|
|
256
|
+
let s = this._indexes?.get(e)?.get(t);
|
|
267
257
|
s === void 0 && (s = this._createIndex(e, t));
|
|
268
258
|
const n = s.get(r);
|
|
269
259
|
if (n !== void 0 && f(e[n]) && Object.is(e[n][t], r))
|
|
270
260
|
return n;
|
|
271
|
-
const d =
|
|
261
|
+
const d = O(e, t, r);
|
|
272
262
|
return d === -1 ? s.delete(r) : s.set(r, d), d;
|
|
273
263
|
}
|
|
274
264
|
_createIndex(e, t) {
|
|
275
|
-
const r = this._indexes
|
|
265
|
+
const r = this._indexes ??= /* @__PURE__ */ new WeakMap();
|
|
276
266
|
let i = r.get(e);
|
|
277
267
|
if (i === void 0 && (i = /* @__PURE__ */ new Map(), r.set(e, i)), this._options.indexStrategy === "eager-all-keys")
|
|
278
268
|
for (let n = 0; n < e.length; n++) {
|
|
@@ -280,7 +270,7 @@ class A {
|
|
|
280
270
|
if (f(d))
|
|
281
271
|
for (const a of Object.keys(d)) {
|
|
282
272
|
const c = d[a];
|
|
283
|
-
if (!
|
|
273
|
+
if (!g(c))
|
|
284
274
|
continue;
|
|
285
275
|
let l = i.get(a);
|
|
286
276
|
l === void 0 && (l = /* @__PURE__ */ new Map(), i.set(a, l)), l.has(c) || l.set(c, n);
|
|
@@ -295,12 +285,12 @@ class A {
|
|
|
295
285
|
if (!f(d))
|
|
296
286
|
continue;
|
|
297
287
|
const a = d[t];
|
|
298
|
-
|
|
288
|
+
g(a) && !s.has(a) && s.set(a, n);
|
|
299
289
|
}
|
|
300
290
|
return i.set(t, s), s;
|
|
301
291
|
}
|
|
302
292
|
}
|
|
303
|
-
function
|
|
293
|
+
function O(o, e, t) {
|
|
304
294
|
for (let r = 0; r < o.length; r++) {
|
|
305
295
|
const i = o[r];
|
|
306
296
|
if (f(i) && Object.hasOwn(i, e) && Object.is(i[e], t))
|
|
@@ -308,21 +298,21 @@ function p(o, e, t) {
|
|
|
308
298
|
}
|
|
309
299
|
return -1;
|
|
310
300
|
}
|
|
311
|
-
function
|
|
312
|
-
return o.kind === "index" || o.kind === "selector" ? [] :
|
|
301
|
+
function p(o) {
|
|
302
|
+
return o.kind === "index" || o.kind === "selector" ? [] : b();
|
|
313
303
|
}
|
|
314
|
-
function
|
|
304
|
+
function b() {
|
|
315
305
|
return /* @__PURE__ */ Object.create(null);
|
|
316
306
|
}
|
|
317
|
-
function
|
|
307
|
+
function x(o) {
|
|
318
308
|
if (u(o))
|
|
319
309
|
return o;
|
|
320
310
|
throw new TypeError("[Raph] Root value must be an object or array.");
|
|
321
311
|
}
|
|
322
|
-
function
|
|
312
|
+
function _(o, e) {
|
|
323
313
|
if (u(o))
|
|
324
314
|
return o;
|
|
325
|
-
throw
|
|
315
|
+
throw w(e);
|
|
326
316
|
}
|
|
327
317
|
function f(o) {
|
|
328
318
|
return typeof o == "object" && o !== null && !Array.isArray(o);
|
|
@@ -330,10 +320,10 @@ function f(o) {
|
|
|
330
320
|
function u(o) {
|
|
331
321
|
return Array.isArray(o) || f(o);
|
|
332
322
|
}
|
|
333
|
-
function
|
|
323
|
+
function g(o) {
|
|
334
324
|
return o === null || typeof o == "string" || typeof o == "number" || typeof o == "boolean";
|
|
335
325
|
}
|
|
336
|
-
function
|
|
326
|
+
function k(o, e, t) {
|
|
337
327
|
if (e === "__proto__") {
|
|
338
328
|
Object.defineProperty(o, e, {
|
|
339
329
|
configurable: !0,
|
|
@@ -345,12 +335,12 @@ function b(o, e, t) {
|
|
|
345
335
|
}
|
|
346
336
|
o[e] = t;
|
|
347
337
|
}
|
|
348
|
-
function
|
|
338
|
+
function w(o) {
|
|
349
339
|
return new TypeError(`[Raph] Cannot traverse non-container data at "${o}".`);
|
|
350
340
|
}
|
|
351
|
-
function
|
|
341
|
+
function y(o) {
|
|
352
342
|
return new Error(`[Raph] Cannot create missing container at "${o}" (autoCreate=false).`);
|
|
353
343
|
}
|
|
354
344
|
export {
|
|
355
|
-
|
|
345
|
+
v as DefaultDataAdapter
|
|
356
346
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../data-path.utils.cjs"),p=require("../PathRouter.cjs");class _{constructor(t){this._batchErrorMessage=t}_router;_events;_batchDepth=0;_watcherCount=0;_publishing=!1;get hasWatchers(){return this._watcherCount!==0}get events(){return this._events}get router(){return this._router}get watcherCount(){return this._watcherCount}record(t){this._watcherCount!==0&&((this._events??=[]).push(t),this._batchDepth===0&&!this._publishing&&this._publish())}batch(t){let e=!1,s,r;this._batchDepth++;try{r=t()}catch(h){e=!0,s=h}return this._closeBatch(e,s),r}_openBatch(){this._batchDepth++}_closeBatch(t,e){let s=!1,r;if(this._batchDepth--,this._batchDepth===0&&this._events?.length)try{this._publish()}catch(h){s=!0,r=h}if(t&&s)throw new AggregateError([e,r],this._batchErrorMessage);if(t)throw e;if(s)throw r}watch(t,e){const s=Array.isArray(t)?t:[t];if(s.length===0)throw new TypeError("[Raph] Path watch requires at least one mask.");const r=new Map;for(const o of s){const a=l.parsePathMask(o);r.set(a.canonical,a)}const h={active:!0,callback:e},i=this._router??=new p.PathRouter,n=[...r.values()].map(o=>i.add(o,h));return this._watcherCount++,f(()=>{h.active=!1,h.callback=void 0;for(const o of n)o();this._watcherCount--,this._watcherCount===0&&(this._router=void 0)})}_publish(){const t=this._events;if(t===void 0||t.length===0||this._publishing)return;const e=[];this._publishing=!0;try{for(;t.length!==0;){const s=t.splice(0),r=this._router;if(r===void 0)continue;const h=new Map;for(const i of s){const n=l.parseDataPath(i.path),o=n.segments.length===0?r.matchAll():r.match(n.segments);for(const a of o){const u=h.get(a);u===void 0?h.set(a,[i]):u.push(i)}}for(const[i,n]of h)if(!(!i.active||i.callback===void 0))try{i.callback({events:n})}catch(o){e.push(o)}}}finally{this._publishing=!1}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"[Raph] Multiple path watchers failed.")}}function f(c){let t=c;return()=>{const e=t;t=void 0,e?.()}}exports.PathEventHub=_;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { parsePathMask as l, parseDataPath as p } from "../data-path.utils.js";
|
|
2
|
+
import { PathRouter as _ } from "../PathRouter.js";
|
|
3
|
+
class v {
|
|
4
|
+
/**
|
|
5
|
+
* Создаёт общий batch и publication boundary для path store.
|
|
6
|
+
*/
|
|
7
|
+
constructor(t) {
|
|
8
|
+
this._batchErrorMessage = t;
|
|
9
|
+
}
|
|
10
|
+
// Хранят ленивый routing и текущий batch path events.
|
|
11
|
+
_router;
|
|
12
|
+
_events;
|
|
13
|
+
// Защищают границы batch, reentrant publication и snapshot requirements.
|
|
14
|
+
_batchDepth = 0;
|
|
15
|
+
_watcherCount = 0;
|
|
16
|
+
_publishing = !1;
|
|
17
|
+
/**
|
|
18
|
+
* Показывает, есть ли watchers, ради которых нужно сохранять значения событий.
|
|
19
|
+
*/
|
|
20
|
+
get hasWatchers() {
|
|
21
|
+
return this._watcherCount !== 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Возвращает накопленные события текущей batch.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
get events() {
|
|
28
|
+
return this._events;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Возвращает внутренний path router для диагностики store.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
get router() {
|
|
35
|
+
return this._router;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Возвращает число активных watchers.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
get watcherCount() {
|
|
42
|
+
return this._watcherCount;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Добавляет событие в текущую batch либо публикует его сразу.
|
|
46
|
+
*/
|
|
47
|
+
record(t) {
|
|
48
|
+
this._watcherCount !== 0 && ((this._events ??= []).push(t), this._batchDepth === 0 && !this._publishing && this._publish());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Выполняет операцию в общей синхронной batch boundary.
|
|
52
|
+
*/
|
|
53
|
+
batch(t) {
|
|
54
|
+
let e = !1, s, r;
|
|
55
|
+
this._batchDepth++;
|
|
56
|
+
try {
|
|
57
|
+
r = t();
|
|
58
|
+
} catch (h) {
|
|
59
|
+
e = !0, s = h;
|
|
60
|
+
}
|
|
61
|
+
return this._closeBatch(e, s), r;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Открывает batch boundary без closure операции: вызывающий сам исполняет
|
|
65
|
+
* операцию и закрывает boundary через `_closeBatch()`.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
_openBatch() {
|
|
69
|
+
this._batchDepth++;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Закрывает один уровень batch boundary: на внешнем уровне публикует
|
|
73
|
+
* накопленные события. Бросает то же, что `batch()`: ошибку операции, ошибку
|
|
74
|
+
* публикации либо обе в AggregateError; после успешной операции и публикации
|
|
75
|
+
* возвращает управление.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
_closeBatch(t, e) {
|
|
79
|
+
let s = !1, r;
|
|
80
|
+
if (this._batchDepth--, this._batchDepth === 0 && this._events?.length)
|
|
81
|
+
try {
|
|
82
|
+
this._publish();
|
|
83
|
+
} catch (h) {
|
|
84
|
+
s = !0, r = h;
|
|
85
|
+
}
|
|
86
|
+
if (t && s)
|
|
87
|
+
throw new AggregateError(
|
|
88
|
+
[e, r],
|
|
89
|
+
this._batchErrorMessage
|
|
90
|
+
);
|
|
91
|
+
if (t)
|
|
92
|
+
throw e;
|
|
93
|
+
if (s)
|
|
94
|
+
throw r;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Подписывает callback на подходящие изменения и возвращает disposer.
|
|
98
|
+
*/
|
|
99
|
+
watch(t, e) {
|
|
100
|
+
const s = Array.isArray(t) ? t : [t];
|
|
101
|
+
if (s.length === 0)
|
|
102
|
+
throw new TypeError("[Raph] Path watch requires at least one mask.");
|
|
103
|
+
const r = /* @__PURE__ */ new Map();
|
|
104
|
+
for (const o of s) {
|
|
105
|
+
const a = l(o);
|
|
106
|
+
r.set(a.canonical, a);
|
|
107
|
+
}
|
|
108
|
+
const h = { active: !0, callback: e }, i = this._router ??= new _(), n = [...r.values()].map((o) => i.add(o, h));
|
|
109
|
+
return this._watcherCount++, f(() => {
|
|
110
|
+
h.active = !1, h.callback = void 0;
|
|
111
|
+
for (const o of n)
|
|
112
|
+
o();
|
|
113
|
+
this._watcherCount--, this._watcherCount === 0 && (this._router = void 0);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
_publish() {
|
|
117
|
+
const t = this._events;
|
|
118
|
+
if (t === void 0 || t.length === 0 || this._publishing)
|
|
119
|
+
return;
|
|
120
|
+
const e = [];
|
|
121
|
+
this._publishing = !0;
|
|
122
|
+
try {
|
|
123
|
+
for (; t.length !== 0; ) {
|
|
124
|
+
const s = t.splice(0), r = this._router;
|
|
125
|
+
if (r === void 0)
|
|
126
|
+
continue;
|
|
127
|
+
const h = /* @__PURE__ */ new Map();
|
|
128
|
+
for (const i of s) {
|
|
129
|
+
const n = p(i.path), o = n.segments.length === 0 ? r.matchAll() : r.match(n.segments);
|
|
130
|
+
for (const a of o) {
|
|
131
|
+
const u = h.get(a);
|
|
132
|
+
u === void 0 ? h.set(a, [i]) : u.push(i);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const [i, n] of h)
|
|
136
|
+
if (!(!i.active || i.callback === void 0))
|
|
137
|
+
try {
|
|
138
|
+
i.callback({ events: n });
|
|
139
|
+
} catch (o) {
|
|
140
|
+
e.push(o);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} finally {
|
|
144
|
+
this._publishing = !1;
|
|
145
|
+
}
|
|
146
|
+
if (e.length === 1)
|
|
147
|
+
throw e[0];
|
|
148
|
+
if (e.length > 1)
|
|
149
|
+
throw new AggregateError(e, "[Raph] Multiple path watchers failed.");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function f(c) {
|
|
153
|
+
let t = c;
|
|
154
|
+
return () => {
|
|
155
|
+
const e = t;
|
|
156
|
+
t = void 0, e?.();
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
v as PathEventHub
|
|
161
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../data-path.utils.cjs"),j=require("./PathEventHub.cjs"),d=new WeakMap;class R{_root;_eventHub=new j.PathEventHub("[Raph] Path batch and publication failed.");get _batchHub(){return this._eventHub}get(e,t){const n=f.parseDataPath(e,t),s=this._root;if(s!==void 0)return h(s,n.segments).value}peek(e,t){return this.get(e,t)}has(e,t){const n=f.parseDataPath(e,t),s=this._root;return s!==void 0&&h(s,n.segments).exists}set(e,t,n){const s=f.parseDataPath(e,n);if(s.segments.length===0){this._setRoot(t);return}const o=this._eventHub.hasWatchers,i=o?h(this._root,s.segments).value:void 0;if(this._root??=Object.create(null),p(this._root,s,t),!o)return;const c=h(this._root,s.segments).value;this._eventHub.record({kind:"set",path:s.canonical,previous:i,value:c})}merge(e,t,n){const s=f.parseDataPath(e,n);if(s.segments.length===0){this._mergeRoot(t);return}const o=this._eventHub.hasWatchers,i=h(this._root,s.segments).value,c=o&&u(i)&&u(t)?O(i):i;if(u(i)&&u(t)){g(this._root,s.segments);for(const v of Object.keys(t))l(i,v,t[v])}else this._root??=Object.create(null),p(this._root,s,t);if(!o)return;const a=h(this._root,s.segments).value;this._eventHub.record({kind:"merge",path:s.canonical,previous:c,value:a})}delete(e,t){const n=f.parseDataPath(e,t);if(n.segments.length===0){this._deleteRoot();return}const s=h(this._root,n.segments);!s.exists||this._root===void 0||(g(this._root,n.segments),P(this._root,n),this._eventHub.hasWatchers&&this._eventHub.record({kind:"delete",path:n.canonical,previous:s.value,value:void 0}))}batch(e){return this._eventHub.batch(e)}watch(e,t){return this._eventHub.watch(e,t)}_setRoot(e){const t=w(e),n=this._root;this._root=t,this._recordRootEvent("set",n,t)}_mergeRoot(e){const t=this._root,n=this._eventHub.hasWatchers&&u(t)&&u(e)?O(t):t;if(u(t)&&u(e))for(const s of Object.keys(e))l(t,s,e[s]);else this._root=w(e);this._recordRootEvent("merge",n,this._root)}_deleteRoot(){const e=this._root;e!==void 0&&(this._root=E(),this._recordRootEvent("delete",e,void 0))}_recordRootEvent(e,t,n){this._eventHub.record({kind:e,path:"",previous:t,value:n})}}function h(r,e){let t=r;for(const n of e)if(n.kind==="key"){if(!_(t)||!Object.hasOwn(t,n.key))return{exists:!1,value:void 0};t=t[n.key]}else if(n.kind==="index"){if(!Array.isArray(t)||!Object.hasOwn(t,n.index))return{exists:!1,value:void 0};t=t[n.index]}else{if(!Array.isArray(t))return{exists:!1,value:void 0};const s=b(t,n.key,n.value);if(s===-1)return{exists:!1,value:void 0};t=t[s]}return{exists:!0,value:t}}function g(r,e){let t=r;for(const n of e){if(!_(t))return;const s=A(t,n);Array.isArray(t)&&d.delete(t),t=s}}function p(r,e,t){let n=r,s;for(let i=0;i<e.segments.length-1;i++){const c=e.segments[i],a=e.segments[i+1];c.kind==="selector"&&Array.isArray(n)&&(s=n),c.kind==="index"&&Array.isArray(n)&&(s=n),n=H(n,c,a,e.canonical)}const o=e.segments[e.segments.length-1];if(m(n,o,t,e.canonical),o.kind==="key"&&s!==void 0){const i=d.get(s);i?.delete(o.key),i?.size===0&&d.delete(s)}}function P(r,e){let t=r;for(let o=0;o<e.segments.length-1;o++){const i=e.segments[o],c=A(t,i);if(!_(c))return;t=c}const n=e.segments[e.segments.length-1];if(n.kind==="key"){delete t[n.key];return}if(!Array.isArray(t))return;if(n.kind==="index"){d.delete(t),delete t[n.index];return}const s=b(t,n.key,n.value);s!==-1&&(d.delete(t),delete t[s])}function A(r,e){if(e.kind==="key")return Object.hasOwn(r,e.key)?r[e.key]:void 0;if(!Array.isArray(r))return;if(e.kind==="index")return r[e.index];const t=b(r,e.key,e.value);return t===-1?void 0:r[t]}function H(r,e,t,n){if(e.kind==="key"){const o=r;let i=o[e.key];return(!Object.hasOwn(o,e.key)||i===void 0)&&(i=x(t),l(o,e.key,i)),k(i,n)}if(e.kind==="index"){if(!Array.isArray(r))throw y(n);let o=r[e.index];return(!Object.hasOwn(r,e.index)||o===void 0)&&(d.delete(r),o=x(t),r[e.index]=o),k(o,n)}if(!Array.isArray(r))throw y(n);let s=b(r,e.key,e.value);if(s===-1){d.delete(r);const o=Object.create(null);o[e.key]=e.value,r.push(o),s=r.length-1}return k(r[s],n)}function m(r,e,t,n){if(e.kind==="key"){l(r,e.key,t);return}if(e.kind==="index"){if(!Array.isArray(r))throw y(n);d.delete(r),r[e.index]=t;return}if(!Array.isArray(r))throw y(n);const s=b(r,e.key,e.value);if(s!==-1){d.delete(r),r[s]=t;return}if(!u(t))throw new TypeError(`[Raph] New selector target at "${n}" must be an object.`);const o=t[e.key];if(Object.hasOwn(t,e.key)&&!Object.is(o,e.value))throw new TypeError(`[Raph] Selector target at "${n}" has a conflicting key.`);d.delete(r),r.push(Object.hasOwn(t,e.key)?t:{...t,[e.key]:e.value})}function x(r){return r.kind==="index"||r.kind==="selector"?[]:Object.create(null)}function E(){return Object.create(null)}function w(r){if(_(r))return r;throw new TypeError("[Raph] Root value must be an object or array.")}function k(r,e){if(_(r))return r;throw y(e)}function b(r,e,t){let n=d.get(r);const s=n?.get(e);if(s)return s.get(t)??-1;const o=new Map;for(let i=0;i<r.length;i++){const c=r[i];if(u(c)&&Object.hasOwn(c,e)){const a=c[e];(a===null||typeof a=="string"||typeof a=="number"||typeof a=="boolean")&&!o.has(a)&&o.set(a,i)}}return n||(n=new Map,d.set(r,n)),n.set(e,o),o.get(t)??-1}function l(r,e,t){if(e==="__proto__"){Object.defineProperty(r,e,{configurable:!0,enumerable:!0,value:t,writable:!0});return}r[e]=t}function O(r){const e=Object.create(Object.getPrototypeOf(r));for(const t of Object.keys(r))l(e,t,r[t]);return e}function u(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function _(r){return Array.isArray(r)||u(r)}function y(r){return new TypeError(`[Raph] Cannot traverse non-container data at "${r}".`)}exports.PathStore=R;
|