@raphy-js/raph 1.0.0-dev.18

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