@raphy-js/raph 1.0.1-dev.20 → 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/dist/{core-CyilRD7s.js → core-CClhT8WR.js} +389 -400
- package/dist/core-cPQWYD4K.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +46 -47
- package/dist/debug/api/RaphFacadeSession.cjs +1 -1
- package/dist/debug/api/RaphFacadeSession.js +85 -89
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -1
- package/dist/debug/api/RaphReactivityInstance.js +27 -30
- package/dist/debug/path/DataPath.cjs +1 -1
- package/dist/debug/path/DataPath.js +198 -202
- package/dist/debug/path/PathRouter.cjs +1 -1
- package/dist/debug/path/PathRouter.js +44 -50
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +257 -228
- package/dist/debug/path/data-path.utils.cjs +1 -1
- package/dist/debug/path/data-path.utils.js +41 -41
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -1
- package/dist/debug/path/derived/DerivedRegistry.js +52 -66
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -1
- package/dist/debug/path/derived/RaphDerivedHandle.js +19 -22
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -1
- package/dist/debug/path/derived/derived-collection.utils.js +70 -70
- package/dist/debug/path/meta/MetaController.cjs +1 -1
- package/dist/debug/path/meta/MetaController.js +57 -65
- package/dist/debug/path/meta/RaphMeta.cjs +1 -1
- package/dist/debug/path/meta/RaphMeta.js +26 -32
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -1
- package/dist/debug/path/meta/RaphMetaStore.js +24 -30
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -1
- package/dist/debug/path/storage/AdapterPathStore.js +49 -54
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -1
- package/dist/debug/path/storage/DefaultDataAdapter.js +46 -56
- package/dist/debug/path/storage/PathEventHub.cjs +1 -1
- package/dist/debug/path/storage/PathEventHub.js +74 -61
- package/dist/debug/path/storage/PathStore.cjs +1 -1
- package/dist/debug/path/storage/PathStore.js +89 -99
- package/dist/debug/path/storage/createDataDraft.cjs +1 -1
- package/dist/debug/path/storage/createDataDraft.js +24 -28
- 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 +787 -392
- package/dist/debug/reactivity/reactive-object.cjs +1 -1
- package/dist/debug/reactivity/reactive-object.js +81 -96
- 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 +764 -411
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
- package/dist/debug/runtime/diagnostics/RaphDebug.js +90 -100
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphEffectScope.js +215 -82
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphNode.js +595 -136
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphScope.js +203 -68
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -1
- package/dist/debug/runtime/phases/RaphFrameLoop.js +13 -17
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +618 -357
- 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/reactivity/PathHandle.cjs +1 -1
- package/dist/debug/runtime/reactivity/PathHandle.js +50 -60
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -1
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +28 -32
- 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 -1
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +541 -379
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +484 -90
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +33 -44
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
- package/dist/entrypoints/runtime.d.ts +2 -1
- package/dist/machine-testing.cjs +1 -1
- package/dist/machine-testing.js +1 -1
- package/dist/machine.cjs +1 -1
- package/dist/machine.js +216 -231
- package/dist/path/RaphKernel.d.ts +24 -0
- package/dist/path/storage/PathEventHub.d.ts +14 -0
- package/dist/path/storage/PathStore.d.ts +4 -4
- package/dist/reactivity/disposal.d.ts +14 -0
- package/dist/reactivity/engine.d.ts +177 -4
- package/dist/reactivity/scope.d.ts +108 -30
- package/dist/runtime/RaphRuntime.d.ts +236 -17
- package/dist/runtime/ownership/RaphEffectScope.d.ts +70 -1
- package/dist/runtime/ownership/RaphNode.d.ts +276 -6
- package/dist/runtime/ownership/RaphScope.d.ts +144 -14
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +202 -28
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
- package/dist/runtime/phases/phase.types.d.ts +83 -4
- package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +163 -25
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +258 -10
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +8 -8
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +48 -3
- package/package.json +9 -1
- package/dist/core-ugchZNqC.cjs +0 -1
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { parsePathMask as _, parseDataPath as g } from "../data-path.utils.js";
|
|
5
|
-
import { PathRouter as b } from "../PathRouter.js";
|
|
6
|
-
class y {
|
|
1
|
+
import { parsePathMask as l, parseDataPath as p } from "../data-path.utils.js";
|
|
2
|
+
import { PathRouter as _ } from "../PathRouter.js";
|
|
3
|
+
class v {
|
|
7
4
|
/**
|
|
8
5
|
* Создаёт общий batch и publication boundary для path store.
|
|
9
6
|
*/
|
|
10
7
|
constructor(t) {
|
|
11
|
-
// Хранят ленивый routing и текущий batch path events.
|
|
12
|
-
c(this, "_router");
|
|
13
|
-
c(this, "_events");
|
|
14
|
-
// Защищают границы batch, reentrant publication и snapshot requirements.
|
|
15
|
-
c(this, "_batchDepth", 0);
|
|
16
|
-
c(this, "_watcherCount", 0);
|
|
17
|
-
c(this, "_publishing", !1);
|
|
18
8
|
this._batchErrorMessage = t;
|
|
19
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;
|
|
20
17
|
/**
|
|
21
18
|
* Показывает, есть ли watchers, ради которых нужно сохранять значения событий.
|
|
22
19
|
*/
|
|
@@ -48,55 +45,71 @@ class y {
|
|
|
48
45
|
* Добавляет событие в текущую batch либо публикует его сразу.
|
|
49
46
|
*/
|
|
50
47
|
record(t) {
|
|
51
|
-
this._watcherCount !== 0 && ((this._events
|
|
48
|
+
this._watcherCount !== 0 && ((this._events ??= []).push(t), this._batchDepth === 0 && !this._publishing && this._publish());
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
51
|
* Выполняет операцию в общей синхронной batch boundary.
|
|
55
52
|
*/
|
|
56
53
|
batch(t) {
|
|
57
|
-
|
|
58
|
-
let e = !1, a, o = !1, i, s;
|
|
54
|
+
let e = !1, s, r;
|
|
59
55
|
this._batchDepth++;
|
|
60
56
|
try {
|
|
61
|
-
|
|
62
|
-
} catch (
|
|
63
|
-
e = !0,
|
|
64
|
-
} finally {
|
|
65
|
-
if (this._batchDepth--, this._batchDepth === 0 && ((h = this._events) != null && h.length))
|
|
66
|
-
try {
|
|
67
|
-
this._publish();
|
|
68
|
-
} catch (r) {
|
|
69
|
-
o = !0, i = r;
|
|
70
|
-
}
|
|
57
|
+
r = t();
|
|
58
|
+
} catch (h) {
|
|
59
|
+
e = !0, s = h;
|
|
71
60
|
}
|
|
72
|
-
|
|
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)
|
|
73
87
|
throw new AggregateError(
|
|
74
|
-
[
|
|
88
|
+
[e, r],
|
|
75
89
|
this._batchErrorMessage
|
|
76
90
|
);
|
|
77
|
-
if (
|
|
78
|
-
throw
|
|
79
|
-
if (
|
|
80
|
-
throw
|
|
81
|
-
return s;
|
|
91
|
+
if (t)
|
|
92
|
+
throw e;
|
|
93
|
+
if (s)
|
|
94
|
+
throw r;
|
|
82
95
|
}
|
|
83
96
|
/**
|
|
84
97
|
* Подписывает callback на подходящие изменения и возвращает disposer.
|
|
85
98
|
*/
|
|
86
99
|
watch(t, e) {
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
100
|
+
const s = Array.isArray(t) ? t : [t];
|
|
101
|
+
if (s.length === 0)
|
|
89
102
|
throw new TypeError("[Raph] Path watch requires at least one mask.");
|
|
90
|
-
const
|
|
91
|
-
for (const
|
|
92
|
-
const
|
|
93
|
-
|
|
103
|
+
const r = /* @__PURE__ */ new Map();
|
|
104
|
+
for (const o of s) {
|
|
105
|
+
const a = l(o);
|
|
106
|
+
r.set(a.canonical, a);
|
|
94
107
|
}
|
|
95
|
-
const
|
|
96
|
-
return this._watcherCount++,
|
|
97
|
-
|
|
98
|
-
for (const
|
|
99
|
-
|
|
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();
|
|
100
113
|
this._watcherCount--, this._watcherCount === 0 && (this._router = void 0);
|
|
101
114
|
});
|
|
102
115
|
}
|
|
@@ -108,23 +121,23 @@ class y {
|
|
|
108
121
|
this._publishing = !0;
|
|
109
122
|
try {
|
|
110
123
|
for (; t.length !== 0; ) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
124
|
+
const s = t.splice(0), r = this._router;
|
|
125
|
+
if (r === void 0)
|
|
113
126
|
continue;
|
|
114
|
-
const
|
|
115
|
-
for (const
|
|
116
|
-
const
|
|
117
|
-
for (const
|
|
118
|
-
const
|
|
119
|
-
|
|
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);
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
|
-
for (const [
|
|
123
|
-
if (!(!
|
|
135
|
+
for (const [i, n] of h)
|
|
136
|
+
if (!(!i.active || i.callback === void 0))
|
|
124
137
|
try {
|
|
125
|
-
|
|
126
|
-
} catch (
|
|
127
|
-
e.push(
|
|
138
|
+
i.callback({ events: n });
|
|
139
|
+
} catch (o) {
|
|
140
|
+
e.push(o);
|
|
128
141
|
}
|
|
129
142
|
}
|
|
130
143
|
} finally {
|
|
@@ -136,13 +149,13 @@ class y {
|
|
|
136
149
|
throw new AggregateError(e, "[Raph] Multiple path watchers failed.");
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
|
-
function
|
|
140
|
-
let t =
|
|
152
|
+
function f(c) {
|
|
153
|
+
let t = c;
|
|
141
154
|
return () => {
|
|
142
155
|
const e = t;
|
|
143
|
-
t = void 0, e
|
|
156
|
+
t = void 0, e?.();
|
|
144
157
|
};
|
|
145
158
|
}
|
|
146
159
|
export {
|
|
147
|
-
|
|
160
|
+
v as PathEventHub
|
|
148
161
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
k(this, "_root");
|
|
11
|
-
k(this, "_eventHub", new H(
|
|
12
|
-
"[Raph] Path batch and publication failed."
|
|
13
|
-
));
|
|
14
|
-
}
|
|
1
|
+
import { parseDataPath as a } from "../data-path.utils.js";
|
|
2
|
+
import { PathEventHub as j } from "./PathEventHub.js";
|
|
3
|
+
const d = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
class S {
|
|
5
|
+
// Владеют path data и независимым event lifecycle этого store.
|
|
6
|
+
_root;
|
|
7
|
+
_eventHub = new j(
|
|
8
|
+
"[Raph] Path batch and publication failed."
|
|
9
|
+
);
|
|
15
10
|
/**
|
|
16
|
-
* Возвращает
|
|
11
|
+
* Возвращает владельца batch boundary этого store: Kernel открывает и
|
|
12
|
+
* закрывает её без closure операции.
|
|
17
13
|
* @internal
|
|
18
14
|
*/
|
|
19
|
-
get
|
|
20
|
-
return this._eventHub
|
|
21
|
-
}
|
|
22
|
-
get _events() {
|
|
23
|
-
return this._eventHub.events;
|
|
24
|
-
}
|
|
25
|
-
get _watcherCount() {
|
|
26
|
-
return this._eventHub.watcherCount;
|
|
15
|
+
get _batchHub() {
|
|
16
|
+
return this._eventHub;
|
|
27
17
|
}
|
|
28
18
|
/**
|
|
29
19
|
* Возвращает значение по пути без создания отсутствующих данных.
|
|
30
20
|
*/
|
|
31
21
|
get(e, t) {
|
|
32
|
-
const n =
|
|
22
|
+
const n = a(e, t), o = this._root;
|
|
33
23
|
if (o !== void 0)
|
|
34
|
-
return
|
|
24
|
+
return l(o, n.segments).value;
|
|
35
25
|
}
|
|
36
26
|
/**
|
|
37
27
|
* Читает значение по пути без регистрации реактивной зависимости.
|
|
@@ -43,22 +33,22 @@ class $ {
|
|
|
43
33
|
* Проверяет наличие значения по указанному пути.
|
|
44
34
|
*/
|
|
45
35
|
has(e, t) {
|
|
46
|
-
const n =
|
|
47
|
-
return o !== void 0 &&
|
|
36
|
+
const n = a(e, t), o = this._root;
|
|
37
|
+
return o !== void 0 && l(o, n.segments).exists;
|
|
48
38
|
}
|
|
49
39
|
/**
|
|
50
40
|
* Записывает значение и публикует соответствующее изменение.
|
|
51
41
|
*/
|
|
52
42
|
set(e, t, n) {
|
|
53
|
-
const o =
|
|
43
|
+
const o = a(e, n);
|
|
54
44
|
if (o.segments.length === 0) {
|
|
55
45
|
this._setRoot(t);
|
|
56
46
|
return;
|
|
57
47
|
}
|
|
58
|
-
const s = this._eventHub.hasWatchers, i = s ?
|
|
59
|
-
if (this._root
|
|
48
|
+
const s = this._eventHub.hasWatchers, i = s ? l(this._root, o.segments).value : void 0;
|
|
49
|
+
if (this._root ??= /* @__PURE__ */ Object.create(null), w(this._root, o, t), !s)
|
|
60
50
|
return;
|
|
61
|
-
const c =
|
|
51
|
+
const c = l(this._root, o.segments).value;
|
|
62
52
|
this._eventHub.record({
|
|
63
53
|
kind: "set",
|
|
64
54
|
path: o.canonical,
|
|
@@ -70,21 +60,21 @@ class $ {
|
|
|
70
60
|
* Объединяет значение по пути и публикует соответствующее изменение.
|
|
71
61
|
*/
|
|
72
62
|
merge(e, t, n) {
|
|
73
|
-
const o =
|
|
63
|
+
const o = a(e, n);
|
|
74
64
|
if (o.segments.length === 0) {
|
|
75
65
|
this._mergeRoot(t);
|
|
76
66
|
return;
|
|
77
67
|
}
|
|
78
|
-
const s = this._eventHub.hasWatchers, i =
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
for (const
|
|
82
|
-
|
|
68
|
+
const s = this._eventHub.hasWatchers, i = l(this._root, o.segments).value, c = s && u(i) && u(t) ? p(i) : i;
|
|
69
|
+
if (u(i) && u(t)) {
|
|
70
|
+
x(this._root, o.segments);
|
|
71
|
+
for (const v of Object.keys(t))
|
|
72
|
+
h(i, v, t[v]);
|
|
83
73
|
} else
|
|
84
|
-
this._root
|
|
74
|
+
this._root ??= /* @__PURE__ */ Object.create(null), w(this._root, o, t);
|
|
85
75
|
if (!s)
|
|
86
76
|
return;
|
|
87
|
-
const f =
|
|
77
|
+
const f = l(this._root, o.segments).value;
|
|
88
78
|
this._eventHub.record({
|
|
89
79
|
kind: "merge",
|
|
90
80
|
path: o.canonical,
|
|
@@ -96,13 +86,13 @@ class $ {
|
|
|
96
86
|
* Удаляет значение по пути и публикует изменение при наличии данных.
|
|
97
87
|
*/
|
|
98
88
|
delete(e, t) {
|
|
99
|
-
const n =
|
|
89
|
+
const n = a(e, t);
|
|
100
90
|
if (n.segments.length === 0) {
|
|
101
91
|
this._deleteRoot();
|
|
102
92
|
return;
|
|
103
93
|
}
|
|
104
|
-
const o =
|
|
105
|
-
!o.exists || this._root === void 0 || (
|
|
94
|
+
const o = l(this._root, n.segments);
|
|
95
|
+
!o.exists || this._root === void 0 || (x(this._root, n.segments), R(this._root, n), this._eventHub.hasWatchers && this._eventHub.record({
|
|
106
96
|
kind: "delete",
|
|
107
97
|
path: n.canonical,
|
|
108
98
|
previous: o.value,
|
|
@@ -122,31 +112,31 @@ class $ {
|
|
|
122
112
|
return this._eventHub.watch(e, t);
|
|
123
113
|
}
|
|
124
114
|
_setRoot(e) {
|
|
125
|
-
const t =
|
|
115
|
+
const t = g(e), n = this._root;
|
|
126
116
|
this._root = t, this._recordRootEvent("set", n, t);
|
|
127
117
|
}
|
|
128
118
|
_mergeRoot(e) {
|
|
129
|
-
const t = this._root, n = this._eventHub.hasWatchers &&
|
|
130
|
-
if (
|
|
119
|
+
const t = this._root, n = this._eventHub.hasWatchers && u(t) && u(e) ? p(t) : t;
|
|
120
|
+
if (u(t) && u(e))
|
|
131
121
|
for (const o of Object.keys(e))
|
|
132
|
-
|
|
122
|
+
h(t, o, e[o]);
|
|
133
123
|
else
|
|
134
|
-
this._root =
|
|
124
|
+
this._root = g(e);
|
|
135
125
|
this._recordRootEvent("merge", n, this._root);
|
|
136
126
|
}
|
|
137
127
|
_deleteRoot() {
|
|
138
128
|
const e = this._root;
|
|
139
|
-
e !== void 0 && (this._root =
|
|
129
|
+
e !== void 0 && (this._root = E(), this._recordRootEvent("delete", e, void 0));
|
|
140
130
|
}
|
|
141
131
|
_recordRootEvent(e, t, n) {
|
|
142
132
|
this._eventHub.record({ kind: e, path: "", previous: t, value: n });
|
|
143
133
|
}
|
|
144
134
|
}
|
|
145
|
-
function
|
|
135
|
+
function l(r, e) {
|
|
146
136
|
let t = r;
|
|
147
137
|
for (const n of e)
|
|
148
138
|
if (n.kind === "key") {
|
|
149
|
-
if (!
|
|
139
|
+
if (!_(t) || !Object.hasOwn(t, n.key))
|
|
150
140
|
return { exists: !1, value: void 0 };
|
|
151
141
|
t = t[n.key];
|
|
152
142
|
} else if (n.kind === "index") {
|
|
@@ -156,39 +146,39 @@ function a(r, e) {
|
|
|
156
146
|
} else {
|
|
157
147
|
if (!Array.isArray(t))
|
|
158
148
|
return { exists: !1, value: void 0 };
|
|
159
|
-
const o =
|
|
149
|
+
const o = b(t, n.key, n.value);
|
|
160
150
|
if (o === -1)
|
|
161
151
|
return { exists: !1, value: void 0 };
|
|
162
152
|
t = t[o];
|
|
163
153
|
}
|
|
164
154
|
return { exists: !0, value: t };
|
|
165
155
|
}
|
|
166
|
-
function
|
|
156
|
+
function x(r, e) {
|
|
167
157
|
let t = r;
|
|
168
158
|
for (const n of e) {
|
|
169
|
-
if (!
|
|
159
|
+
if (!_(t))
|
|
170
160
|
return;
|
|
171
|
-
const o =
|
|
172
|
-
Array.isArray(t) &&
|
|
161
|
+
const o = A(t, n);
|
|
162
|
+
Array.isArray(t) && d.delete(t), t = o;
|
|
173
163
|
}
|
|
174
164
|
}
|
|
175
|
-
function
|
|
165
|
+
function w(r, e, t) {
|
|
176
166
|
let n = r, o;
|
|
177
167
|
for (let i = 0; i < e.segments.length - 1; i++) {
|
|
178
168
|
const c = e.segments[i], f = e.segments[i + 1];
|
|
179
|
-
c.kind === "selector" && Array.isArray(n) && (o = n), c.kind === "index" && Array.isArray(n) && (o = n), n =
|
|
169
|
+
c.kind === "selector" && Array.isArray(n) && (o = n), c.kind === "index" && Array.isArray(n) && (o = n), n = m(n, c, f, e.canonical);
|
|
180
170
|
}
|
|
181
171
|
const s = e.segments[e.segments.length - 1];
|
|
182
|
-
if (
|
|
183
|
-
const i =
|
|
184
|
-
i
|
|
172
|
+
if (H(n, s, t, e.canonical), s.kind === "key" && o !== void 0) {
|
|
173
|
+
const i = d.get(o);
|
|
174
|
+
i?.delete(s.key), i?.size === 0 && d.delete(o);
|
|
185
175
|
}
|
|
186
176
|
}
|
|
187
|
-
function
|
|
177
|
+
function R(r, e) {
|
|
188
178
|
let t = r;
|
|
189
179
|
for (let s = 0; s < e.segments.length - 1; s++) {
|
|
190
|
-
const i = e.segments[s], c =
|
|
191
|
-
if (!
|
|
180
|
+
const i = e.segments[s], c = A(t, i);
|
|
181
|
+
if (!_(c))
|
|
192
182
|
return;
|
|
193
183
|
t = c;
|
|
194
184
|
}
|
|
@@ -200,101 +190,101 @@ function E(r, e) {
|
|
|
200
190
|
if (!Array.isArray(t))
|
|
201
191
|
return;
|
|
202
192
|
if (n.kind === "index") {
|
|
203
|
-
|
|
193
|
+
d.delete(t), delete t[n.index];
|
|
204
194
|
return;
|
|
205
195
|
}
|
|
206
|
-
const o =
|
|
207
|
-
o !== -1 && (
|
|
196
|
+
const o = b(t, n.key, n.value);
|
|
197
|
+
o !== -1 && (d.delete(t), delete t[o]);
|
|
208
198
|
}
|
|
209
|
-
function
|
|
199
|
+
function A(r, e) {
|
|
210
200
|
if (e.kind === "key")
|
|
211
201
|
return Object.hasOwn(r, e.key) ? r[e.key] : void 0;
|
|
212
202
|
if (!Array.isArray(r))
|
|
213
203
|
return;
|
|
214
204
|
if (e.kind === "index")
|
|
215
205
|
return r[e.index];
|
|
216
|
-
const t =
|
|
206
|
+
const t = b(r, e.key, e.value);
|
|
217
207
|
return t === -1 ? void 0 : r[t];
|
|
218
208
|
}
|
|
219
|
-
function
|
|
209
|
+
function m(r, e, t, n) {
|
|
220
210
|
if (e.kind === "key") {
|
|
221
211
|
const s = r;
|
|
222
212
|
let i = s[e.key];
|
|
223
|
-
return (!Object.hasOwn(s, e.key) || i === void 0) && (i =
|
|
213
|
+
return (!Object.hasOwn(s, e.key) || i === void 0) && (i = O(t), h(s, e.key, i)), k(i, n);
|
|
224
214
|
}
|
|
225
215
|
if (e.kind === "index") {
|
|
226
216
|
if (!Array.isArray(r))
|
|
227
217
|
throw y(n);
|
|
228
218
|
let s = r[e.index];
|
|
229
|
-
return (!Object.hasOwn(r, e.index) || s === void 0) && (
|
|
219
|
+
return (!Object.hasOwn(r, e.index) || s === void 0) && (d.delete(r), s = O(t), r[e.index] = s), k(s, n);
|
|
230
220
|
}
|
|
231
221
|
if (!Array.isArray(r))
|
|
232
222
|
throw y(n);
|
|
233
|
-
let o =
|
|
223
|
+
let o = b(r, e.key, e.value);
|
|
234
224
|
if (o === -1) {
|
|
235
|
-
|
|
225
|
+
d.delete(r);
|
|
236
226
|
const s = /* @__PURE__ */ Object.create(null);
|
|
237
227
|
s[e.key] = e.value, r.push(s), o = r.length - 1;
|
|
238
228
|
}
|
|
239
|
-
return
|
|
229
|
+
return k(r[o], n);
|
|
240
230
|
}
|
|
241
|
-
function
|
|
231
|
+
function H(r, e, t, n) {
|
|
242
232
|
if (e.kind === "key") {
|
|
243
|
-
|
|
233
|
+
h(r, e.key, t);
|
|
244
234
|
return;
|
|
245
235
|
}
|
|
246
236
|
if (e.kind === "index") {
|
|
247
237
|
if (!Array.isArray(r))
|
|
248
238
|
throw y(n);
|
|
249
|
-
|
|
239
|
+
d.delete(r), r[e.index] = t;
|
|
250
240
|
return;
|
|
251
241
|
}
|
|
252
242
|
if (!Array.isArray(r))
|
|
253
243
|
throw y(n);
|
|
254
|
-
const o =
|
|
244
|
+
const o = b(r, e.key, e.value);
|
|
255
245
|
if (o !== -1) {
|
|
256
|
-
|
|
246
|
+
d.delete(r), r[o] = t;
|
|
257
247
|
return;
|
|
258
248
|
}
|
|
259
|
-
if (!
|
|
249
|
+
if (!u(t))
|
|
260
250
|
throw new TypeError(`[Raph] New selector target at "${n}" must be an object.`);
|
|
261
251
|
const s = t[e.key];
|
|
262
252
|
if (Object.hasOwn(t, e.key) && !Object.is(s, e.value))
|
|
263
253
|
throw new TypeError(`[Raph] Selector target at "${n}" has a conflicting key.`);
|
|
264
|
-
|
|
254
|
+
d.delete(r), r.push(Object.hasOwn(t, e.key) ? t : { ...t, [e.key]: e.value });
|
|
265
255
|
}
|
|
266
|
-
function
|
|
256
|
+
function O(r) {
|
|
267
257
|
return r.kind === "index" || r.kind === "selector" ? [] : /* @__PURE__ */ Object.create(null);
|
|
268
258
|
}
|
|
269
|
-
function
|
|
259
|
+
function E() {
|
|
270
260
|
return /* @__PURE__ */ Object.create(null);
|
|
271
261
|
}
|
|
272
|
-
function
|
|
273
|
-
if (
|
|
262
|
+
function g(r) {
|
|
263
|
+
if (_(r))
|
|
274
264
|
return r;
|
|
275
265
|
throw new TypeError("[Raph] Root value must be an object or array.");
|
|
276
266
|
}
|
|
277
|
-
function
|
|
278
|
-
if (
|
|
267
|
+
function k(r, e) {
|
|
268
|
+
if (_(r))
|
|
279
269
|
return r;
|
|
280
270
|
throw y(e);
|
|
281
271
|
}
|
|
282
|
-
function
|
|
283
|
-
let n =
|
|
284
|
-
const o = n
|
|
272
|
+
function b(r, e, t) {
|
|
273
|
+
let n = d.get(r);
|
|
274
|
+
const o = n?.get(e);
|
|
285
275
|
if (o)
|
|
286
276
|
return o.get(t) ?? -1;
|
|
287
277
|
const s = /* @__PURE__ */ new Map();
|
|
288
278
|
for (let i = 0; i < r.length; i++) {
|
|
289
279
|
const c = r[i];
|
|
290
|
-
if (
|
|
280
|
+
if (u(c) && Object.hasOwn(c, e)) {
|
|
291
281
|
const f = c[e];
|
|
292
282
|
(f === null || typeof f == "string" || typeof f == "number" || typeof f == "boolean") && !s.has(f) && s.set(f, i);
|
|
293
283
|
}
|
|
294
284
|
}
|
|
295
|
-
return n || (n = /* @__PURE__ */ new Map(),
|
|
285
|
+
return n || (n = /* @__PURE__ */ new Map(), d.set(r, n)), n.set(e, s), s.get(t) ?? -1;
|
|
296
286
|
}
|
|
297
|
-
function
|
|
287
|
+
function h(r, e, t) {
|
|
298
288
|
if (e === "__proto__") {
|
|
299
289
|
Object.defineProperty(r, e, {
|
|
300
290
|
configurable: !0,
|
|
@@ -306,21 +296,21 @@ function l(r, e, t) {
|
|
|
306
296
|
}
|
|
307
297
|
r[e] = t;
|
|
308
298
|
}
|
|
309
|
-
function
|
|
299
|
+
function p(r) {
|
|
310
300
|
const e = Object.create(Object.getPrototypeOf(r));
|
|
311
301
|
for (const t of Object.keys(r))
|
|
312
|
-
|
|
302
|
+
h(e, t, r[t]);
|
|
313
303
|
return e;
|
|
314
304
|
}
|
|
315
|
-
function
|
|
305
|
+
function u(r) {
|
|
316
306
|
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
317
307
|
}
|
|
318
|
-
function
|
|
319
|
-
return Array.isArray(r) ||
|
|
308
|
+
function _(r) {
|
|
309
|
+
return Array.isArray(r) || u(r);
|
|
320
310
|
}
|
|
321
311
|
function y(r) {
|
|
322
312
|
return new TypeError(`[Raph] Cannot traverse non-container data at "${r}".`);
|
|
323
313
|
}
|
|
324
314
|
export {
|
|
325
|
-
|
|
315
|
+
S as PathStore
|
|
326
316
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(S,x){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(S,x){const w=new WeakMap,m=new WeakMap,v=(n,u,s=new Set)=>{if(!s.has(n)){s.add(n),n.changed.add(u),Array.isArray(n.source)&&x(n.proxy);for(const[c,l]of n.parents)for(const r of l)v(c,r,s)}},b=(n,u,s)=>{if(!n||typeof n!="object")return n;const c=Object.getPrototypeOf(n);let l=m.get(n)??w.get(n);if(!l){const r=n,f=Array.isArray(r),d=f?[]:Object.create(c);f&&(d.length=r.length),l={source:r,proxy:null,values:new Map,removed:new Set,changed:new Set,parents:new Map};const t=l,O=a=>!t.removed.has(a)&&(t.values.has(a)||Reflect.has(r,a)),g=a=>t.removed.has(a)?void 0:t.values.has(a)?t.values.get(a):Reflect.get(r,a);t.proxy=new Proxy(d,{get:(a,e)=>b(g(e),t,e),has:(a,e)=>O(e),set:(a,e,i)=>{if(f&&e==="length"){const o=Number(i);if(!Number.isInteger(o)||o<0||o>4294967295)throw new RangeError("Invalid array length");for(let h=o;h<Number(g("length"));h++)t.removed.add(String(h)),t.values.delete(String(h));d.length=o}else if(f&&typeof e=="string"&&/^(?:0|[1-9]\d*)$/.test(e)){const o=Number(e);o<4294967295&&o>=Number(g("length"))&&(t.values.set("length",o+1),d.length=o+1)}return t.values.set(e,i),t.removed.delete(e),v(t,e),!0},deleteProperty:(a,e)=>f&&e==="length"?!1:(t.values.delete(e),t.removed.add(e),v(t,e),!0),ownKeys:()=>[...new Set([...Reflect.ownKeys(r),...t.values.keys()])].filter(a=>!t.removed.has(a)),getOwnPropertyDescriptor:(a,e)=>{if(f&&e==="length")return{value:g(e),writable:!0,enumerable:!1,configurable:!1};const i=Object.getOwnPropertyDescriptor(r,e);if(!(t.removed.has(e)||!i&&!t.values.has(e)))return{value:b(g(e),t,e),writable:!0,enumerable:i?.enumerable??!0,configurable:!0}}}),w.set(r,t),m.set(t.proxy,t)}if(u&&s!==void 0){let r=l.parents.get(u);r||(r=new Set,l.parents.set(u,r)),r.add(s)}return l.proxy};return{root:b(S),unchangedArray(n,u){const s=m.get(n);if(!s)return null;for(const c of s.changed)if(s.values.has(c)||s.removed.has(c)||w.get(s.source[c])?.changed.has(u))return null;return s.source}}}exports.createDataDraft=y;
|