@raphy-js/raph 1.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/LICENSE +202 -0
  2. package/ReadMe.md +153 -0
  3. package/dist/api/Raph.d.ts +228 -0
  4. package/dist/api/errors.d.ts +20 -0
  5. package/dist/api/public.d.ts +22 -0
  6. package/dist/api/types.d.ts +25 -0
  7. package/dist/debug/api/Raph.cjs +1 -0
  8. package/dist/debug/api/Raph.js +419 -0
  9. package/dist/debug/api/errors.cjs +1 -0
  10. package/dist/debug/api/errors.js +14 -0
  11. package/dist/debug/api/public.cjs +1 -0
  12. package/dist/debug/api/public.js +40 -0
  13. package/dist/debug/api/types.cjs +1 -0
  14. package/dist/debug/api/types.js +1 -0
  15. package/dist/debug/path/AdapterPathStore.cjs +1 -0
  16. package/dist/debug/path/AdapterPathStore.js +133 -0
  17. package/dist/debug/path/DerivedRegistry.cjs +1 -0
  18. package/dist/debug/path/DerivedRegistry.js +157 -0
  19. package/dist/debug/path/MetaController.cjs +1 -0
  20. package/dist/debug/path/MetaController.js +214 -0
  21. package/dist/debug/path/PathEventHub.cjs +1 -0
  22. package/dist/debug/path/PathEventHub.js +148 -0
  23. package/dist/debug/path/PathStore.cjs +1 -0
  24. package/dist/debug/path/PathStore.js +326 -0
  25. package/dist/debug/path/RaphDerivedHandle.cjs +1 -0
  26. package/dist/debug/path/RaphDerivedHandle.js +125 -0
  27. package/dist/debug/path/RaphKernel.cjs +1 -0
  28. package/dist/debug/path/RaphKernel.js +636 -0
  29. package/dist/debug/path/RaphMeta.cjs +1 -0
  30. package/dist/debug/path/RaphMeta.js +68 -0
  31. package/dist/debug/path/RaphMetaStore.cjs +1 -0
  32. package/dist/debug/path/RaphMetaStore.js +184 -0
  33. package/dist/debug/path/data-adapter.cjs +1 -0
  34. package/dist/debug/path/data-adapter.js +356 -0
  35. package/dist/debug/path/data-draft.cjs +1 -0
  36. package/dist/debug/path/data-draft.js +71 -0
  37. package/dist/debug/path/data-path.cjs +1 -0
  38. package/dist/debug/path/data-path.js +423 -0
  39. package/dist/debug/path/derived-collection.cjs +1 -0
  40. package/dist/debug/path/derived-collection.js +179 -0
  41. package/dist/debug/path/derived-strategies.cjs +1 -0
  42. package/dist/debug/path/derived-strategies.js +20 -0
  43. package/dist/debug/path/meta.types.cjs +1 -0
  44. package/dist/debug/path/meta.types.js +1 -0
  45. package/dist/debug/path/path-router.cjs +1 -0
  46. package/dist/debug/path/path-router.js +86 -0
  47. package/dist/debug/path/path.types.cjs +1 -0
  48. package/dist/debug/path/path.types.js +1 -0
  49. package/dist/debug/path/public.cjs +1 -0
  50. package/dist/debug/path/public.js +18 -0
  51. package/dist/debug/path/segment-key.cjs +1 -0
  52. package/dist/debug/path/segment-key.js +12 -0
  53. package/dist/debug/reactivity/engine.cjs +1 -0
  54. package/dist/debug/reactivity/engine.js +1133 -0
  55. package/dist/debug/reactivity/scope.cjs +1 -0
  56. package/dist/debug/reactivity/scope.js +274 -0
  57. package/dist/debug/reactivity/types.cjs +1 -0
  58. package/dist/debug/reactivity/types.js +1 -0
  59. package/dist/debug/reactivity/watch.cjs +1 -0
  60. package/dist/debug/reactivity/watch.js +64 -0
  61. package/dist/debug/runtime/PathHandle.cjs +1 -0
  62. package/dist/debug/runtime/PathHandle.js +139 -0
  63. package/dist/debug/runtime/RaphDebug.cjs +1 -0
  64. package/dist/debug/runtime/RaphDebug.js +15 -0
  65. package/dist/debug/runtime/RaphFrameLoop.cjs +1 -0
  66. package/dist/debug/runtime/RaphFrameLoop.js +106 -0
  67. package/dist/debug/runtime/RaphNode.cjs +1 -0
  68. package/dist/debug/runtime/RaphNode.js +143 -0
  69. package/dist/debug/runtime/RaphPhasePipeline.cjs +1 -0
  70. package/dist/debug/runtime/RaphPhasePipeline.js +526 -0
  71. package/dist/debug/runtime/RaphRuntime.cjs +1 -0
  72. package/dist/debug/runtime/RaphRuntime.js +700 -0
  73. package/dist/debug/runtime/RaphScope.cjs +1 -0
  74. package/dist/debug/runtime/RaphScope.js +64 -0
  75. package/dist/debug/runtime/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/RuntimeReactivity.js +154 -0
  77. package/dist/debug/runtime/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/RuntimeWatch.js +71 -0
  79. package/dist/debug/runtime/disposal.cjs +1 -0
  80. package/dist/debug/runtime/disposal.js +9 -0
  81. package/dist/debug/runtime/errors.cjs +1 -0
  82. package/dist/debug/runtime/errors.js +12 -0
  83. package/dist/debug/runtime/parent-graph.cjs +1 -0
  84. package/dist/debug/runtime/parent-graph.js +10 -0
  85. package/dist/debug/runtime/phase.types.cjs +1 -0
  86. package/dist/debug/runtime/phase.types.js +8 -0
  87. package/dist/debug/runtime/public.cjs +1 -0
  88. package/dist/debug/runtime/public.js +18 -0
  89. package/dist/debug/runtime/runtime-reactivity.types.cjs +1 -0
  90. package/dist/debug/runtime/runtime-reactivity.types.js +1 -0
  91. package/dist/index.cjs +1 -0
  92. package/dist/index.js +40 -0
  93. package/dist/path/AdapterPathStore.d.ts +45 -0
  94. package/dist/path/DerivedRegistry.d.ts +67 -0
  95. package/dist/path/MetaController.d.ts +85 -0
  96. package/dist/path/PathEventHub.d.ts +48 -0
  97. package/dist/path/PathStore.d.ts +51 -0
  98. package/dist/path/RaphDerivedHandle.d.ts +97 -0
  99. package/dist/path/RaphKernel.d.ts +166 -0
  100. package/dist/path/RaphMeta.d.ts +45 -0
  101. package/dist/path/RaphMetaStore.d.ts +45 -0
  102. package/dist/path/data-adapter.d.ts +78 -0
  103. package/dist/path/data-draft.d.ts +4 -0
  104. package/dist/path/data-path.d.ts +97 -0
  105. package/dist/path/derived-collection.d.ts +30 -0
  106. package/dist/path/derived-strategies.d.ts +15 -0
  107. package/dist/path/meta.types.d.ts +33 -0
  108. package/dist/path/path-router.d.ts +21 -0
  109. package/dist/path/path.types.d.ts +26 -0
  110. package/dist/path/public.d.ts +14 -0
  111. package/dist/path/segment-key.d.ts +2 -0
  112. package/dist/path.cjs +1 -0
  113. package/dist/path.js +18 -0
  114. package/dist/raph.cjs +1 -0
  115. package/dist/raph.js +40 -0
  116. package/dist/reactivity/engine.d.ts +379 -0
  117. package/dist/reactivity/scope.d.ts +146 -0
  118. package/dist/reactivity/types.d.ts +150 -0
  119. package/dist/reactivity/watch.d.ts +15 -0
  120. package/dist/reactivity.cjs +1 -0
  121. package/dist/reactivity.js +14 -0
  122. package/dist/runtime/PathHandle.d.ts +72 -0
  123. package/dist/runtime/RaphDebug.d.ts +32 -0
  124. package/dist/runtime/RaphFrameLoop.d.ts +51 -0
  125. package/dist/runtime/RaphNode.d.ts +68 -0
  126. package/dist/runtime/RaphPhasePipeline.d.ts +133 -0
  127. package/dist/runtime/RaphRuntime.d.ts +285 -0
  128. package/dist/runtime/RaphScope.d.ts +50 -0
  129. package/dist/runtime/RuntimeReactivity.d.ts +40 -0
  130. package/dist/runtime/RuntimeWatch.d.ts +28 -0
  131. package/dist/runtime/disposal.d.ts +1 -0
  132. package/dist/runtime/errors.d.ts +16 -0
  133. package/dist/runtime/parent-graph.d.ts +5 -0
  134. package/dist/runtime/phase.types.d.ts +49 -0
  135. package/dist/runtime/public.d.ts +13 -0
  136. package/dist/runtime/runtime-reactivity.types.d.ts +9 -0
  137. package/dist/runtime.cjs +1 -0
  138. package/dist/runtime.js +18 -0
  139. package/package.json +109 -0
@@ -0,0 +1,157 @@
1
+ var a = Object.defineProperty;
2
+ var h = (l, e, t) => e in l ? a(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
+ var d = (l, e, t) => h(l, typeof e != "symbol" ? e + "" : e, t);
4
+ import { pathRelationMasks as _, parsePathMask as u } from "./data-path.js";
5
+ import { collectionMutationImpact as f } from "./derived-collection.js";
6
+ import { PathRouter as m } from "./path-router.js";
7
+ const g = 2e4;
8
+ class z {
9
+ constructor() {
10
+ // Хранят routes, handles и инкрементальное состояние materialized derived.
11
+ d(this, "_router");
12
+ d(this, "_handles");
13
+ d(this, "_matches");
14
+ d(this, "_pending");
15
+ d(this, "_collections");
16
+ // Формирует локальные идентификаторы derived без глобального shared state.
17
+ d(this, "_counter", 0);
18
+ }
19
+ /**
20
+ * Возвращает число зарегистрированных записей.
21
+ */
22
+ get size() {
23
+ var e;
24
+ return ((e = this._handles) == null ? void 0 : e.size) ?? 0;
25
+ }
26
+ /**
27
+ * Возвращает очередь derived-вычислений, ожидающих стабилизации.
28
+ */
29
+ get pending() {
30
+ return this._pending;
31
+ }
32
+ /**
33
+ * Выделяет следующий стабильный идентификатор registry.
34
+ */
35
+ nextId() {
36
+ return `derived-${this._counter++}`;
37
+ }
38
+ /**
39
+ * Проверяет наличие derived handle с указанным id.
40
+ */
41
+ has(e) {
42
+ var t;
43
+ return ((t = this._handles) == null ? void 0 : t.has(e)) ?? !1;
44
+ }
45
+ /**
46
+ * Возвращает зарегистрированные derived handles.
47
+ */
48
+ values() {
49
+ var e;
50
+ return ((e = this._handles) == null ? void 0 : e.values()) ?? [][Symbol.iterator]();
51
+ }
52
+ /**
53
+ * Возвращает внутреннее состояние зарегистрированного handle.
54
+ */
55
+ state(e) {
56
+ var t;
57
+ return (t = this._collections) == null ? void 0 : t.get(e);
58
+ }
59
+ /**
60
+ * Регистрирует derived handle и его зависимости.
61
+ */
62
+ register(e, t, i) {
63
+ (this._handles ?? (this._handles = /* @__PURE__ */ new Map())).set(e.id, e), i !== void 0 && (this._collections ?? (this._collections = /* @__PURE__ */ new Map())).set(e, {
64
+ from: t,
65
+ kind: i.kind,
66
+ key: i.key,
67
+ initialized: !1,
68
+ full: !0,
69
+ keys: /* @__PURE__ */ new Set(),
70
+ sourceIndex: void 0,
71
+ targetIndex: void 0
72
+ });
73
+ const n = this._router ?? (this._router = new m());
74
+ this._matches = void 0, e._attachRoutes(_(t).map(
75
+ (s) => n.add(u(s), e)
76
+ ));
77
+ }
78
+ /**
79
+ * Удаляет регистрацию и связанные pending-записи.
80
+ */
81
+ remove(e) {
82
+ var i, o, n;
83
+ const t = this._handles;
84
+ (t == null ? void 0 : t.get(e.id)) === e && (t.delete(e.id), e._detachRoutes(), this._matches = void 0, (i = this._pending) == null || i.delete(e), (o = this._collections) == null || o.delete(e), ((n = this._collections) == null ? void 0 : n.size) === 0 && (this._collections = void 0), t.size === 0 && (this._handles = void 0, this._router = void 0, this._pending = void 0));
85
+ }
86
+ /**
87
+ * Добавляет derived handle в очередь пересчёта.
88
+ */
89
+ queue(e) {
90
+ var o;
91
+ const t = this._matching(e);
92
+ if (t.length === 0)
93
+ return;
94
+ const i = this._pending ?? (this._pending = /* @__PURE__ */ new Set());
95
+ for (const n of t) {
96
+ if (n.paused || n.disposed)
97
+ continue;
98
+ const s = (o = this._collections) == null ? void 0 : o.get(n);
99
+ if (s !== void 0 && s.initialized && !s.full) {
100
+ const c = f(s.from, s.key, e);
101
+ c.kind === "full" ? (s.full = !0, s.keys.clear()) : s.keys.add(c.key);
102
+ }
103
+ i.add(n);
104
+ }
105
+ }
106
+ /**
107
+ * Запоминает полную замену, которую нужно применить при стабилизации.
108
+ */
109
+ queueReplacement(e, t) {
110
+ var n;
111
+ const i = this._matching(e);
112
+ if (i.length === 0)
113
+ return;
114
+ const o = this._pending ?? (this._pending = /* @__PURE__ */ new Set());
115
+ for (const s of i) {
116
+ if (s.paused || s.disposed)
117
+ continue;
118
+ const c = (n = this._collections) == null ? void 0 : n.get(s);
119
+ if (c !== void 0 && c.initialized && !c.full && c.from.canonical === e.canonical)
120
+ for (const r of t)
121
+ c.keys.add(r);
122
+ else c !== void 0 && (c.full = !0, c.keys.clear());
123
+ o.add(s);
124
+ }
125
+ }
126
+ /**
127
+ * Сбрасывает pending-состояние после опустошения очереди.
128
+ */
129
+ clearPendingIfEmpty() {
130
+ var e;
131
+ ((e = this._pending) == null ? void 0 : e.size) === 0 && (this._pending = void 0);
132
+ }
133
+ /**
134
+ * Освобождает все handles и очищает derived registry.
135
+ */
136
+ dispose() {
137
+ if (this._handles !== void 0)
138
+ for (const e of this._handles.values())
139
+ e._disposeFromKernel();
140
+ this._handles = void 0, this._router = void 0, this._matches = void 0, this._pending = void 0, this._collections = void 0;
141
+ }
142
+ _matching(e) {
143
+ var n;
144
+ const t = this._router;
145
+ if (t === void 0)
146
+ return [];
147
+ let i = (n = this._matches) == null ? void 0 : n.get(e.canonical);
148
+ if (i !== void 0)
149
+ return i;
150
+ i = [...e.segments.length === 0 ? t.matchAll() : t.match(e.segments)];
151
+ const o = this._matches ?? (this._matches = /* @__PURE__ */ new Map());
152
+ return o.size >= g && o.clear(), o.set(e.canonical, i), i;
153
+ }
154
+ }
155
+ export {
156
+ z as DerivedRegistry
157
+ };
@@ -0,0 +1 @@
1
+ "use strict";var v=Object.defineProperty;var p=(d,e,t)=>e in d?v(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var l=(d,e,t)=>p(d,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./data-path.cjs"),g=require("./path-router.cjs"),m=require("./RaphMeta.cjs"),_=require("./RaphMetaStore.cjs");class b{constructor(e,t,r){l(this,"_facade");l(this,"_store");l(this,"_router");l(this,"_pending");l(this,"_publishing",!1);l(this,"_watcherCount",0);l(this,"_deferredWatcherCount",0);this._kernel=e,this._ownerExists=t,this._publicationDeferred=r}get facade(){return this._facade??(this._facade=new m.RaphMeta(this._kernel))}get size(){var e;return((e=this._store)==null?void 0:e.size)??0}get hasWatchers(){return this._router!==void 0}get hasDeferredWatchers(){return this._deferredWatcherCount!==0}get(e,t){var r;return(r=this._store)==null?void 0:r.get(e,t)}has(e,t){var r;return((r=this._store)==null?void 0:r.has(e,t))??!1}set(e,t,r,i){(this._store??(this._store=new _.RaphMetaStore)).set(e,t,r),this.record("set",e,t,"explicit",i)}merge(e,t,r,i){(this._store??(this._store=new _.RaphMetaStore)).merge(e,t,r),this.record("merge",e,t,"explicit",i)}delete(e,t,r){var i;return(i=this._store)!=null&&i.delete(e,t)?(this.record("delete",e,t??null,"explicit",r),!0):!1}deleteSubtree(e,t){const r=this._store;if(r!==void 0)for(const i of r.deleteSubtree(e))this.record("delete",i,null,t)}pruneMissing(e,t){const r=this._store;if(r===void 0||r.size===0)return;const n=e.segments().findIndex(s=>s.kind==="index"||s.kind==="selector"),c=n===-1?e:f.DataPath.fromPlain({segs:e.toPlain().segs.slice(0,n)});for(const s of r.pruneMissing(c,o=>this._ownerExists(o)))this.record("delete",s,null,t)}watch(e,t,r={},i){const n=Array.isArray(e)?e:[e];if(n.length===0)throw new TypeError("[RaphMeta] watch requires at least one mask.");const c=new Map;for(const a of n){const u=f.DataPath.from(a,r)._asMask();c.set(u.canonical,u)}const s={active:!0,callback:t,afterPublish:i,...r.namespace===void 0?{}:{namespace:r.namespace}},o=this._router??(this._router=new g.PathRouter),h=[...c.values()].map(a=>o.add(a,s));return this._watcherCount++,i!==void 0&&this._deferredWatcherCount++,w(()=>{s.active=!1,s.callback=void 0,s.afterPublish=void 0;for(const a of h)a();this._watcherCount--,i!==void 0&&this._deferredWatcherCount--,this._watcherCount===0&&(this._router=void 0)})}record(e,t,r,i,n){(this._pending??(this._pending=[])).push({event:{kind:e,path:t,namespace:r,cause:i},invalidate:(n==null?void 0:n.invalidate)??!0}),!this._publicationDeferred()&&!this._publishing&&this.publish()}publish(){const e=this._pending;if(e===void 0||e.length===0||this._publishing)return;const t=[],r=new Map;this._publishing=!0;try{for(;e.length!==0;){const i=e.splice(0),n=this._router;if(n===void 0)continue;const c=new Map;for(const s of i){const o=s.event;for(const h of n.match(o.path._asExact().segments)){if(h.namespace!==void 0&&o.namespace!==null&&h.namespace!==o.namespace)continue;const a=c.get(h);a===void 0?c.set(h,{events:[o],invalidate:s.invalidate}):(a.events.push(o),s.invalidate&&(a.invalidate=!0))}}for(const[s,o]of c){if(!s.active||s.callback===void 0)continue;const h=s.afterPublish;h!==void 0&&r.set(h,(r.get(h)??!1)||o.invalidate);try{s.callback({events:o.events})}catch(a){t.push(a)}}}}finally{this._publishing=!1}for(const[i,n]of r)try{i(n)}catch(c){t.push(c)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"[RaphMeta] Multiple watchers failed.")}dispose(){var e;(e=this._store)==null||e.clear(),this._store=void 0,this._facade=void 0,this._router=void 0,this._pending=void 0,this._watcherCount=0,this._deferredWatcherCount=0}}function w(d){let e=d;return()=>{const t=e;e=void 0,t==null||t()}}exports.MetaController=b;
@@ -0,0 +1,214 @@
1
+ var v = Object.defineProperty;
2
+ var p = (d, e, t) => e in d ? v(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t;
3
+ var l = (d, e, t) => p(d, typeof e != "symbol" ? e + "" : e, t);
4
+ import { DataPath as f } from "./data-path.js";
5
+ import { PathRouter as g } from "./path-router.js";
6
+ import { RaphMeta as m } from "./RaphMeta.js";
7
+ import { RaphMetaStore as _ } from "./RaphMetaStore.js";
8
+ class k {
9
+ /**
10
+ * Создаёт lifecycle-контроллер metadata для одного Kernel.
11
+ */
12
+ constructor(e, t, r) {
13
+ // Лениво создают metadata facade, storage и routing только при первом использовании.
14
+ l(this, "_facade");
15
+ l(this, "_store");
16
+ l(this, "_router");
17
+ l(this, "_pending");
18
+ // Управляют reentrant publication и режимами активных watchers.
19
+ l(this, "_publishing", !1);
20
+ l(this, "_watcherCount", 0);
21
+ l(this, "_deferredWatcherCount", 0);
22
+ this._kernel = e, this._ownerExists = t, this._publicationDeferred = r;
23
+ }
24
+ /**
25
+ * Возвращает metadata facade, принадлежащий контроллеру.
26
+ */
27
+ get facade() {
28
+ return this._facade ?? (this._facade = new m(this._kernel));
29
+ }
30
+ /**
31
+ * Возвращает число зарегистрированных записей.
32
+ */
33
+ get size() {
34
+ var e;
35
+ return ((e = this._store) == null ? void 0 : e.size) ?? 0;
36
+ }
37
+ /**
38
+ * Показывает, есть ли активные синхронные metadata/path watchers.
39
+ */
40
+ get hasWatchers() {
41
+ return this._router !== void 0;
42
+ }
43
+ /**
44
+ * Показывает, есть ли watchers с отложенной публикацией.
45
+ */
46
+ get hasDeferredWatchers() {
47
+ return this._deferredWatcherCount !== 0;
48
+ }
49
+ /**
50
+ * Возвращает значение по пути без создания отсутствующих данных.
51
+ */
52
+ get(e, t) {
53
+ var r;
54
+ return (r = this._store) == null ? void 0 : r.get(e, t);
55
+ }
56
+ /**
57
+ * Проверяет наличие значения по указанному пути.
58
+ */
59
+ has(e, t) {
60
+ var r;
61
+ return ((r = this._store) == null ? void 0 : r.has(e, t)) ?? !1;
62
+ }
63
+ /**
64
+ * Записывает значение и публикует соответствующее изменение.
65
+ */
66
+ set(e, t, r, i) {
67
+ (this._store ?? (this._store = new _())).set(e, t, r), this.record("set", e, t, "explicit", i);
68
+ }
69
+ /**
70
+ * Объединяет значение по пути и публикует соответствующее изменение.
71
+ */
72
+ merge(e, t, r, i) {
73
+ (this._store ?? (this._store = new _())).merge(e, t, r), this.record("merge", e, t, "explicit", i);
74
+ }
75
+ /**
76
+ * Удаляет значение по пути и публикует изменение при наличии данных.
77
+ */
78
+ delete(e, t, r) {
79
+ var i;
80
+ return (i = this._store) != null && i.delete(e, t) ? (this.record("delete", e, t ?? null, "explicit", r), !0) : !1;
81
+ }
82
+ /**
83
+ * Удаляет metadata всего поддерева указанного data-owner.
84
+ */
85
+ deleteSubtree(e, t) {
86
+ const r = this._store;
87
+ if (r !== void 0)
88
+ for (const i of r.deleteSubtree(e))
89
+ this.record("delete", i, null, t);
90
+ }
91
+ /**
92
+ * Удаляет metadata, владельцы которой отсутствуют в data tree.
93
+ */
94
+ pruneMissing(e, t) {
95
+ const r = this._store;
96
+ if (r === void 0 || r.size === 0)
97
+ return;
98
+ const o = e.segments().findIndex(
99
+ (s) => s.kind === "index" || s.kind === "selector"
100
+ ), c = o === -1 ? e : f.fromPlain({ segs: e.toPlain().segs.slice(0, o) });
101
+ for (const s of r.pruneMissing(
102
+ c,
103
+ (n) => this._ownerExists(n)
104
+ ))
105
+ this.record("delete", s, null, t);
106
+ }
107
+ /**
108
+ * Подписывает callback на подходящие изменения и возвращает disposer.
109
+ */
110
+ watch(e, t, r = {}, i) {
111
+ const o = Array.isArray(e) ? e : [e];
112
+ if (o.length === 0)
113
+ throw new TypeError("[RaphMeta] watch requires at least one mask.");
114
+ const c = /* @__PURE__ */ new Map();
115
+ for (const a of o) {
116
+ const u = f.from(a, r)._asMask();
117
+ c.set(u.canonical, u);
118
+ }
119
+ const s = {
120
+ active: !0,
121
+ callback: t,
122
+ afterPublish: i,
123
+ ...r.namespace === void 0 ? {} : { namespace: r.namespace }
124
+ }, n = this._router ?? (this._router = new g()), h = [...c.values()].map((a) => n.add(a, s));
125
+ return this._watcherCount++, i !== void 0 && this._deferredWatcherCount++, w(() => {
126
+ s.active = !1, s.callback = void 0, s.afterPublish = void 0;
127
+ for (const a of h)
128
+ a();
129
+ this._watcherCount--, i !== void 0 && this._deferredWatcherCount--, this._watcherCount === 0 && (this._router = void 0);
130
+ });
131
+ }
132
+ /**
133
+ * Добавляет событие в текущую transaction либо публикует его сразу.
134
+ */
135
+ record(e, t, r, i, o) {
136
+ (this._pending ?? (this._pending = [])).push({
137
+ event: { kind: e, path: t, namespace: r, cause: i },
138
+ invalidate: (o == null ? void 0 : o.invalidate) ?? !0
139
+ }), !this._publicationDeferred() && !this._publishing && this.publish();
140
+ }
141
+ /**
142
+ * Публикует накопленные metadata-события с учётом watcher mode.
143
+ */
144
+ publish() {
145
+ const e = this._pending;
146
+ if (e === void 0 || e.length === 0 || this._publishing)
147
+ return;
148
+ const t = [], r = /* @__PURE__ */ new Map();
149
+ this._publishing = !0;
150
+ try {
151
+ for (; e.length !== 0; ) {
152
+ const i = e.splice(0), o = this._router;
153
+ if (o === void 0)
154
+ continue;
155
+ const c = /* @__PURE__ */ new Map();
156
+ for (const s of i) {
157
+ const n = s.event;
158
+ for (const h of o.match(n.path._asExact().segments)) {
159
+ if (h.namespace !== void 0 && n.namespace !== null && h.namespace !== n.namespace)
160
+ continue;
161
+ const a = c.get(h);
162
+ a === void 0 ? c.set(h, {
163
+ events: [n],
164
+ invalidate: s.invalidate
165
+ }) : (a.events.push(n), s.invalidate && (a.invalidate = !0));
166
+ }
167
+ }
168
+ for (const [s, n] of c) {
169
+ if (!s.active || s.callback === void 0)
170
+ continue;
171
+ const h = s.afterPublish;
172
+ h !== void 0 && r.set(
173
+ h,
174
+ (r.get(h) ?? !1) || n.invalidate
175
+ );
176
+ try {
177
+ s.callback({ events: n.events });
178
+ } catch (a) {
179
+ t.push(a);
180
+ }
181
+ }
182
+ }
183
+ } finally {
184
+ this._publishing = !1;
185
+ }
186
+ for (const [i, o] of r)
187
+ try {
188
+ i(o);
189
+ } catch (c) {
190
+ t.push(c);
191
+ }
192
+ if (t.length === 1)
193
+ throw t[0];
194
+ if (t.length > 1)
195
+ throw new AggregateError(t, "[RaphMeta] Multiple watchers failed.");
196
+ }
197
+ /**
198
+ * Очищает metadata storage, subscriptions и pending publication state.
199
+ */
200
+ dispose() {
201
+ var e;
202
+ (e = this._store) == null || e.clear(), this._store = void 0, this._facade = void 0, this._router = void 0, this._pending = void 0, this._watcherCount = 0, this._deferredWatcherCount = 0;
203
+ }
204
+ }
205
+ function w(d) {
206
+ let e = d;
207
+ return () => {
208
+ const t = e;
209
+ e = void 0, t == null || t();
210
+ };
211
+ }
212
+ export {
213
+ k as MetaController
214
+ };
@@ -0,0 +1 @@
1
+ "use strict";var _=Object.defineProperty;var f=(a,t,e)=>t in a?_(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var c=(a,t,e)=>f(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./data-path.cjs"),g=require("./path-router.cjs");class v{constructor(t){c(this,"_router");c(this,"_events");c(this,"_transactionDepth",0);c(this,"_watcherCount",0);c(this,"_publishing",!1);this._transactionErrorMessage=t}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??(this._events=[])).push(t),this._transactionDepth===0&&!this._publishing&&this._publish())}transaction(t){var o;let e=!1,h,n=!1,i,s;this._transactionDepth++;try{s=t()}catch(r){e=!0,h=r}finally{if(this._transactionDepth--,this._transactionDepth===0&&((o=this._events)!=null&&o.length))try{this._publish()}catch(r){n=!0,i=r}}if(e&&n)throw new AggregateError([h,i],this._transactionErrorMessage);if(e)throw h;if(n)throw i;return s}watch(t,e){const h=Array.isArray(t)?t:[t];if(h.length===0)throw new TypeError("[Raph] Path watch requires at least one mask.");const n=new Map;for(const r of h){const u=p.parsePathMask(r);n.set(u.canonical,u)}const i={active:!0,callback:e},s=this._router??(this._router=new g.PathRouter),o=[...n.values()].map(r=>s.add(r,i));return this._watcherCount++,d(()=>{i.active=!1,i.callback=void 0;for(const r of o)r();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 h=t.splice(0),n=this._router;if(n===void 0)continue;const i=new Map;for(const s of h){const o=p.parseDataPath(s.path),r=o.segments.length===0?n.matchAll():n.match(o.segments);for(const u of r){const l=i.get(u);l===void 0?i.set(u,[s]):l.push(s)}}for(const[s,o]of i)if(!(!s.active||s.callback===void 0))try{s.callback({events:o})}catch(r){e.push(r)}}}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 d(a){let t=a;return()=>{const e=t;t=void 0,e==null||e()}}exports.PathEventHub=v;
@@ -0,0 +1,148 @@
1
+ var p = Object.defineProperty;
2
+ var f = (a, t, e) => t in a ? p(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
+ var c = (a, t, e) => f(a, typeof t != "symbol" ? t + "" : t, e);
4
+ import { parsePathMask as _, parseDataPath as g } from "./data-path.js";
5
+ import { PathRouter as v } from "./path-router.js";
6
+ class y {
7
+ /**
8
+ * Создаёт общий transaction и publication boundary для path store.
9
+ */
10
+ constructor(t) {
11
+ // Хранят ленивый routing и текущий batch path events.
12
+ c(this, "_router");
13
+ c(this, "_events");
14
+ // Защищают границы transaction, reentrant publication и snapshot requirements.
15
+ c(this, "_transactionDepth", 0);
16
+ c(this, "_watcherCount", 0);
17
+ c(this, "_publishing", !1);
18
+ this._transactionErrorMessage = t;
19
+ }
20
+ /**
21
+ * Показывает, есть ли watchers, ради которых нужно сохранять значения событий.
22
+ */
23
+ get hasWatchers() {
24
+ return this._watcherCount !== 0;
25
+ }
26
+ /**
27
+ * Возвращает накопленные события текущей transaction.
28
+ * @internal
29
+ */
30
+ get events() {
31
+ return this._events;
32
+ }
33
+ /**
34
+ * Возвращает внутренний path router для диагностики store.
35
+ * @internal
36
+ */
37
+ get router() {
38
+ return this._router;
39
+ }
40
+ /**
41
+ * Возвращает число активных watchers.
42
+ * @internal
43
+ */
44
+ get watcherCount() {
45
+ return this._watcherCount;
46
+ }
47
+ /**
48
+ * Добавляет событие в текущую transaction либо публикует его сразу.
49
+ */
50
+ record(t) {
51
+ this._watcherCount !== 0 && ((this._events ?? (this._events = [])).push(t), this._transactionDepth === 0 && !this._publishing && this._publish());
52
+ }
53
+ /**
54
+ * Выполняет операцию в общей синхронной transaction boundary.
55
+ */
56
+ transaction(t) {
57
+ var n;
58
+ let e = !1, h, o = !1, i, s;
59
+ this._transactionDepth++;
60
+ try {
61
+ s = t();
62
+ } catch (r) {
63
+ e = !0, h = r;
64
+ } finally {
65
+ if (this._transactionDepth--, this._transactionDepth === 0 && ((n = this._events) != null && n.length))
66
+ try {
67
+ this._publish();
68
+ } catch (r) {
69
+ o = !0, i = r;
70
+ }
71
+ }
72
+ if (e && o)
73
+ throw new AggregateError(
74
+ [h, i],
75
+ this._transactionErrorMessage
76
+ );
77
+ if (e)
78
+ throw h;
79
+ if (o)
80
+ throw i;
81
+ return s;
82
+ }
83
+ /**
84
+ * Подписывает callback на подходящие изменения и возвращает disposer.
85
+ */
86
+ watch(t, e) {
87
+ const h = Array.isArray(t) ? t : [t];
88
+ if (h.length === 0)
89
+ throw new TypeError("[Raph] Path watch requires at least one mask.");
90
+ const o = /* @__PURE__ */ new Map();
91
+ for (const r of h) {
92
+ const u = _(r);
93
+ o.set(u.canonical, u);
94
+ }
95
+ const i = { active: !0, callback: e }, s = this._router ?? (this._router = new v()), n = [...o.values()].map((r) => s.add(r, i));
96
+ return this._watcherCount++, w(() => {
97
+ i.active = !1, i.callback = void 0;
98
+ for (const r of n)
99
+ r();
100
+ this._watcherCount--, this._watcherCount === 0 && (this._router = void 0);
101
+ });
102
+ }
103
+ _publish() {
104
+ const t = this._events;
105
+ if (t === void 0 || t.length === 0 || this._publishing)
106
+ return;
107
+ const e = [];
108
+ this._publishing = !0;
109
+ try {
110
+ for (; t.length !== 0; ) {
111
+ const h = t.splice(0), o = this._router;
112
+ if (o === void 0)
113
+ continue;
114
+ const i = /* @__PURE__ */ new Map();
115
+ for (const s of h) {
116
+ const n = g(s.path), r = n.segments.length === 0 ? o.matchAll() : o.match(n.segments);
117
+ for (const u of r) {
118
+ const l = i.get(u);
119
+ l === void 0 ? i.set(u, [s]) : l.push(s);
120
+ }
121
+ }
122
+ for (const [s, n] of i)
123
+ if (!(!s.active || s.callback === void 0))
124
+ try {
125
+ s.callback({ events: n });
126
+ } catch (r) {
127
+ e.push(r);
128
+ }
129
+ }
130
+ } finally {
131
+ this._publishing = !1;
132
+ }
133
+ if (e.length === 1)
134
+ throw e[0];
135
+ if (e.length > 1)
136
+ throw new AggregateError(e, "[Raph] Multiple path watchers failed.");
137
+ }
138
+ }
139
+ function w(a) {
140
+ let t = a;
141
+ return () => {
142
+ const e = t;
143
+ t = void 0, e == null || e();
144
+ };
145
+ }
146
+ export {
147
+ y as PathEventHub
148
+ };
@@ -0,0 +1 @@
1
+ "use strict";var R=Object.defineProperty;var P=(r,e,t)=>e in r?R(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var v=(r,e,t)=>P(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./data-path.cjs"),H=require("./PathEventHub.cjs"),u=new WeakMap;class m{constructor(){v(this,"_root");v(this,"_eventHub",new H.PathEventHub("[Raph] Path transaction and publication failed."))}get _router(){return this._eventHub.router}get _events(){return this._eventHub.events}get _watcherCount(){return this._eventHub.watcherCount}get(e,t){const n=f.parseDataPath(e,t),o=this._root;if(o!==void 0)return h(o,n.segments).value}peek(e,t){return this.get(e,t)}has(e,t){const n=f.parseDataPath(e,t),o=this._root;return o!==void 0&&h(o,n.segments).exists}set(e,t,n){const o=f.parseDataPath(e,n);if(o.segments.length===0){this._setRoot(t);return}const s=this._eventHub.hasWatchers,i=s?h(this._root,o.segments).value:void 0;if(this._root??(this._root=Object.create(null)),w(this._root,o,t),!s)return;const c=h(this._root,o.segments).value;this._eventHub.record({kind:"set",path:o.canonical,previous:i,value:c})}merge(e,t,n){const o=f.parseDataPath(e,n);if(o.segments.length===0){this._mergeRoot(t);return}const s=this._eventHub.hasWatchers,i=h(this._root,o.segments).value,c=s&&a(i)&&a(t)?A(i):i;if(a(i)&&a(t)){p(this._root,o.segments);for(const g of Object.keys(t))l(i,g,t[g])}else this._root??(this._root=Object.create(null)),w(this._root,o,t);if(!s)return;const d=h(this._root,o.segments).value;this._eventHub.record({kind:"merge",path:o.canonical,previous:c,value:d})}delete(e,t){const n=f.parseDataPath(e,t);if(n.segments.length===0){this._deleteRoot();return}const o=h(this._root,n.segments);!o.exists||this._root===void 0||(p(this._root,n.segments),E(this._root,n),this._eventHub.hasWatchers&&this._eventHub.record({kind:"delete",path:n.canonical,previous:o.value,value:void 0}))}transaction(e){return this._eventHub.transaction(e)}watch(e,t){return this._eventHub.watch(e,t)}_setRoot(e){const t=x(e),n=this._root;this._root=t,this._recordRootEvent("set",n,t)}_mergeRoot(e){const t=this._root,n=this._eventHub.hasWatchers&&a(t)&&a(e)?A(t):t;if(a(t)&&a(e))for(const o of Object.keys(e))l(t,o,e[o]);else this._root=x(e);this._recordRootEvent("merge",n,this._root)}_deleteRoot(){const e=this._root;e!==void 0&&(this._root=D(),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(!b(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 o=_(t,n.key,n.value);if(o===-1)return{exists:!1,value:void 0};t=t[o]}return{exists:!0,value:t}}function p(r,e){let t=r;for(const n of e){if(!b(t))return;const o=j(t,n);Array.isArray(t)&&u.delete(t),t=o}}function w(r,e,t){let n=r,o;for(let i=0;i<e.segments.length-1;i++){const c=e.segments[i],d=e.segments[i+1];c.kind==="selector"&&Array.isArray(n)&&(o=n),c.kind==="index"&&Array.isArray(n)&&(o=n),n=C(n,c,d,e.canonical)}const s=e.segments[e.segments.length-1];if(S(n,s,t,e.canonical),s.kind==="key"&&o!==void 0){const i=u.get(o);i==null||i.delete(s.key),(i==null?void 0:i.size)===0&&u.delete(o)}}function E(r,e){let t=r;for(let s=0;s<e.segments.length-1;s++){const i=e.segments[s],c=j(t,i);if(!b(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"){u.delete(t),delete t[n.index];return}const o=_(t,n.key,n.value);o!==-1&&(u.delete(t),delete t[o])}function j(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=_(r,e.key,e.value);return t===-1?void 0:r[t]}function C(r,e,t,n){if(e.kind==="key"){const s=r;let i=s[e.key];return(!Object.hasOwn(s,e.key)||i===void 0)&&(i=O(t),l(s,e.key,i)),k(i,n)}if(e.kind==="index"){if(!Array.isArray(r))throw y(n);let s=r[e.index];return(!Object.hasOwn(r,e.index)||s===void 0)&&(u.delete(r),s=O(t),r[e.index]=s),k(s,n)}if(!Array.isArray(r))throw y(n);let o=_(r,e.key,e.value);if(o===-1){u.delete(r);const s=Object.create(null);s[e.key]=e.value,r.push(s),o=r.length-1}return k(r[o],n)}function S(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);u.delete(r),r[e.index]=t;return}if(!Array.isArray(r))throw y(n);const o=_(r,e.key,e.value);if(o!==-1){u.delete(r),r[o]=t;return}if(!a(t))throw new TypeError(`[Raph] New selector target at "${n}" must be an object.`);const s=t[e.key];if(Object.hasOwn(t,e.key)&&!Object.is(s,e.value))throw new TypeError(`[Raph] Selector target at "${n}" has a conflicting key.`);u.delete(r),r.push(Object.hasOwn(t,e.key)?t:{...t,[e.key]:e.value})}function O(r){return r.kind==="index"||r.kind==="selector"?[]:Object.create(null)}function D(){return Object.create(null)}function x(r){if(b(r))return r;throw new TypeError("[Raph] Root value must be an object or array.")}function k(r,e){if(b(r))return r;throw y(e)}function _(r,e,t){let n=u.get(r);const o=n==null?void 0:n.get(e);if(o)return o.get(t)??-1;const s=new Map;for(let i=0;i<r.length;i++){const c=r[i];if(a(c)&&Object.hasOwn(c,e)){const d=c[e];(d===null||typeof d=="string"||typeof d=="number"||typeof d=="boolean")&&!s.has(d)&&s.set(d,i)}}return n||(n=new Map,u.set(r,n)),n.set(e,s),s.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 A(r){const e=Object.create(Object.getPrototypeOf(r));for(const t of Object.keys(r))l(e,t,r[t]);return e}function a(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function b(r){return Array.isArray(r)||a(r)}function y(r){return new TypeError(`[Raph] Cannot traverse non-container data at "${r}".`)}exports.PathStore=m;