@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 @@
1
+ "use strict";var p=Object.defineProperty;var _=(n,e,t)=>e in n?p(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>_(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./segment-key.cjs");function d(){return{children:new Map,namespaces:new Map,path:void 0}}class g{constructor(){a(this,"_root",d());a(this,"size",0)}get(e,t){const r=this._find(e);if(r!==void 0)return t===void 0?Object.fromEntries(r.namespaces):r.namespaces.get(t)}has(e,t){const r=this._find(e);return r===void 0?!1:t===void 0?r.namespaces.size!==0:r.namespaces.has(t)}set(e,t,r){const s=this._ensure(e);s.namespaces.has(t)||this.size++,s.namespaces.set(t,r),s.path=e}merge(e,t,r){const s=this.get(e,t);if(l(s)&&l(r)){for(const i of Object.keys(r))y(s,i,r[i]);return}this.set(e,t,r)}delete(e,t){var i;const r=this._findStack(e),s=(i=r.at(-1))==null?void 0:i.node;if(s===void 0)return!1;if(t===void 0){if(s.namespaces.size===0)return!1;this.size-=s.namespaces.size,s.namespaces.clear()}else{if(!s.namespaces.delete(t))return!1;this.size--}return this._pruneEmpty(r),!0}deleteSubtree(e){const t=o(e);if(t.length===0)return this.clear();let r=this._root;for(let c=0;c<t.length-1;c++){const u=r.children.get(t[c]);if(u===void 0)return[];r=u}const s=r.children.get(t.at(-1));if(s===void 0)return[];const i=h(s);return this.size-=f(s),r.children.delete(t.at(-1)),i}pruneMissing(e,t){const r=this._find(e);if(r===void 0)return[];const s=[];return this._pruneMissingNode(r,t,s),s}clear(){const e=h(this._root);return this._root.children.clear(),this._root.namespaces.clear(),this._root.path=void 0,this.size=0,e}_find(e){let t=this._root;for(const r of o(e)){const s=t.children.get(r);if(s===void 0)return;t=s}return t}_ensure(e){let t=this._root;for(const r of o(e)){let s=t.children.get(r);s===void 0&&(s=d(),t.children.set(r,s)),t=s}return t}_findStack(e){const t=[{key:void 0,node:this._root}];let r=this._root;for(const s of o(e)){const i=r.children.get(s);if(i===void 0)return[];t.push({key:s,node:i}),r=i}return t}_pruneEmpty(e){for(let t=e.length-1;t>0;t--){const r=e[t];if(r.node.namespaces.size!==0||r.node.children.size!==0)return;e[t-1].node.children.delete(r.key)}}_pruneMissingNode(e,t,r){for(const[s,i]of[...e.children])this._pruneMissingNode(i,t,r)&&e.children.delete(s);return e.path!==void 0&&e.namespaces.size!==0&&!t(e.path)&&(this.size-=e.namespaces.size,e.namespaces.clear(),r.push(e.path)),e!==this._root&&e.namespaces.size===0&&e.children.size===0}}function o(n){return n.segments().map(m.pathSegmentKey)}function h(n){const e=n.path!==void 0&&n.namespaces.size!==0?[n.path]:[];for(const t of n.children.values())e.push(...h(t));return e}function f(n){let e=n.namespaces.size;for(const t of n.children.values())e+=f(t);return e}function l(n){if(typeof n!="object"||n===null||Array.isArray(n))return!1;const e=Object.getPrototypeOf(n);return e===Object.prototype||e===null}function y(n,e,t){if(e!=="__proto__"){n[e]=t;return}Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0})}exports.RaphMetaStore=g;
@@ -0,0 +1,184 @@
1
+ var p = Object.defineProperty;
2
+ var _ = (n, e, t) => e in n ? p(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var h = (n, e, t) => _(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { pathSegmentKey as m } from "./segment-key.js";
5
+ function f() {
6
+ return { children: /* @__PURE__ */ new Map(), namespaces: /* @__PURE__ */ new Map(), path: void 0 };
7
+ }
8
+ class v {
9
+ constructor() {
10
+ // Хранят metadata tree и точное число записанных namespaces.
11
+ h(this, "_root", f());
12
+ h(this, "size", 0);
13
+ }
14
+ /**
15
+ * Возвращает значение по пути без создания отсутствующих данных.
16
+ */
17
+ get(e, t) {
18
+ const r = this._find(e);
19
+ if (r !== void 0)
20
+ return t === void 0 ? Object.fromEntries(r.namespaces) : r.namespaces.get(t);
21
+ }
22
+ /**
23
+ * Проверяет наличие значения по указанному пути.
24
+ */
25
+ has(e, t) {
26
+ const r = this._find(e);
27
+ return r === void 0 ? !1 : t === void 0 ? r.namespaces.size !== 0 : r.namespaces.has(t);
28
+ }
29
+ /**
30
+ * Записывает значение namespace в metadata tree.
31
+ */
32
+ set(e, t, r) {
33
+ const s = this._ensure(e);
34
+ s.namespaces.has(t) || this.size++, s.namespaces.set(t, r), s.path = e;
35
+ }
36
+ /**
37
+ * Объединяет object metadata либо заменяет значение namespace.
38
+ */
39
+ merge(e, t, r) {
40
+ const s = this.get(e, t);
41
+ if (l(s) && l(r)) {
42
+ for (const i of Object.keys(r))
43
+ g(s, i, r[i]);
44
+ return;
45
+ }
46
+ this.set(e, t, r);
47
+ }
48
+ /**
49
+ * Удаляет namespace либо все metadata указанного owner.
50
+ */
51
+ delete(e, t) {
52
+ var i;
53
+ const r = this._findStack(e), s = (i = r.at(-1)) == null ? void 0 : i.node;
54
+ if (s === void 0)
55
+ return !1;
56
+ if (t === void 0) {
57
+ if (s.namespaces.size === 0)
58
+ return !1;
59
+ this.size -= s.namespaces.size, s.namespaces.clear();
60
+ } else {
61
+ if (!s.namespaces.delete(t))
62
+ return !1;
63
+ this.size--;
64
+ }
65
+ return this._pruneEmpty(r), !0;
66
+ }
67
+ /**
68
+ * Удаляет metadata всего поддерева указанного data-owner.
69
+ */
70
+ deleteSubtree(e) {
71
+ const t = o(e);
72
+ if (t.length === 0)
73
+ return this.clear();
74
+ let r = this._root;
75
+ for (let c = 0; c < t.length - 1; c++) {
76
+ const d = r.children.get(t[c]);
77
+ if (d === void 0)
78
+ return [];
79
+ r = d;
80
+ }
81
+ const s = r.children.get(t.at(-1));
82
+ if (s === void 0)
83
+ return [];
84
+ const i = a(s);
85
+ return this.size -= u(s), r.children.delete(t.at(-1)), i;
86
+ }
87
+ /**
88
+ * Удаляет metadata, владельцы которой отсутствуют в data tree.
89
+ */
90
+ pruneMissing(e, t) {
91
+ const r = this._find(e);
92
+ if (r === void 0)
93
+ return [];
94
+ const s = [];
95
+ return this._pruneMissingNode(r, t, s), s;
96
+ }
97
+ /**
98
+ * Полностью очищает metadata storage.
99
+ */
100
+ clear() {
101
+ const e = a(this._root);
102
+ return this._root.children.clear(), this._root.namespaces.clear(), this._root.path = void 0, this.size = 0, e;
103
+ }
104
+ _find(e) {
105
+ let t = this._root;
106
+ for (const r of o(e)) {
107
+ const s = t.children.get(r);
108
+ if (s === void 0)
109
+ return;
110
+ t = s;
111
+ }
112
+ return t;
113
+ }
114
+ _ensure(e) {
115
+ let t = this._root;
116
+ for (const r of o(e)) {
117
+ let s = t.children.get(r);
118
+ s === void 0 && (s = f(), t.children.set(r, s)), t = s;
119
+ }
120
+ return t;
121
+ }
122
+ _findStack(e) {
123
+ const t = [
124
+ { key: void 0, node: this._root }
125
+ ];
126
+ let r = this._root;
127
+ for (const s of o(e)) {
128
+ const i = r.children.get(s);
129
+ if (i === void 0)
130
+ return [];
131
+ t.push({ key: s, node: i }), r = i;
132
+ }
133
+ return t;
134
+ }
135
+ _pruneEmpty(e) {
136
+ for (let t = e.length - 1; t > 0; t--) {
137
+ const r = e[t];
138
+ if (r.node.namespaces.size !== 0 || r.node.children.size !== 0)
139
+ return;
140
+ e[t - 1].node.children.delete(r.key);
141
+ }
142
+ }
143
+ _pruneMissingNode(e, t, r) {
144
+ for (const [s, i] of [...e.children])
145
+ this._pruneMissingNode(i, t, r) && e.children.delete(s);
146
+ return e.path !== void 0 && e.namespaces.size !== 0 && !t(e.path) && (this.size -= e.namespaces.size, e.namespaces.clear(), r.push(e.path)), e !== this._root && e.namespaces.size === 0 && e.children.size === 0;
147
+ }
148
+ }
149
+ function o(n) {
150
+ return n.segments().map(m);
151
+ }
152
+ function a(n) {
153
+ const e = n.path !== void 0 && n.namespaces.size !== 0 ? [n.path] : [];
154
+ for (const t of n.children.values())
155
+ e.push(...a(t));
156
+ return e;
157
+ }
158
+ function u(n) {
159
+ let e = n.namespaces.size;
160
+ for (const t of n.children.values())
161
+ e += u(t);
162
+ return e;
163
+ }
164
+ function l(n) {
165
+ if (typeof n != "object" || n === null || Array.isArray(n))
166
+ return !1;
167
+ const e = Object.getPrototypeOf(n);
168
+ return e === Object.prototype || e === null;
169
+ }
170
+ function g(n, e, t) {
171
+ if (e !== "__proto__") {
172
+ n[e] = t;
173
+ return;
174
+ }
175
+ Object.defineProperty(n, e, {
176
+ configurable: !0,
177
+ enumerable: !0,
178
+ value: t,
179
+ writable: !0
180
+ });
181
+ }
182
+ export {
183
+ v as RaphMetaStore
184
+ };
@@ -0,0 +1 @@
1
+ "use strict";var j=Object.defineProperty;var S=(o,e,t)=>e in o?j(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var y=(o,e,t)=>S(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./data-draft.cjs"),h=require("./data-path.cjs");class g{constructor(e=p(),t={}){y(this,"_root");y(this,"_options");y(this,"_indexes");this._root=x(e),this._options={arrayDelete:t.arrayDelete??"unset",autoCreate:t.autoCreate??!0,indexEnabled:t.indexEnabled??!0,indexStrategy:t.indexStrategy??"eager-all-keys"}}root(){return this._root}fork(){const e=new g({},this._options);return e._root=C.createDataDraft(this._root,t=>{var r;return(r=e._indexes)==null?void 0:r.delete(t)}).root,e}replaceRoot(e){this._root=x(e),this._indexes=void 0}options(e){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}get(e,t){return this._read(h.parseDataPath(e,t)).value}has(e,t){return this._read(h.parseDataPath(e,t)).exists}set(e,t,r){const i=h.parseDataPath(e,r);if(i.segments.length===0){this.replaceRoot(x(t));return}let s=this._root,n;for(let a=0;a<i.segments.length-1;a++){const d=i.segments[a],c=i.segments[a+1],l=this._readOrCreateChild(s,d,c,i.canonical);s=l.value,n=l.indexedParent}this._writeSegment(s,i.segments[i.segments.length-1],t,i.canonical,n)}merge(e,t,r){const i=this.get(e,r);if(f(i)&&f(t)){for(const s of Object.keys(t))b(i,s,t[s]);this._indexes=void 0;return}this.set(e,t,r)}delete(e,t){const r=h.parseDataPath(e,t);if(r.segments.length===0){this._root=p(),this._indexes=void 0;return}let i=this._root;for(let n=0;n<r.segments.length-1;n++){if(!u(i))return;i=this._readSegment(i,r.segments[n])}if(!u(i))return;const s=r.segments[r.segments.length-1];if(s.kind==="key")delete i[s.key];else if(s.kind==="index"){if(!Array.isArray(i))return;this._options.arrayDelete==="splice"?i.splice(s.index,1):delete i[s.index]}else{if(!Array.isArray(i))return;const n=this._findSelector(i,s.key,s.value);if(n===-1)return;this._options.arrayDelete==="splice"?i.splice(n,1):delete i[n]}this._indexes=void 0}indexOf(e,t){const r=h.parseDataPath(e,t);let i=this._root;for(let s=0;s<r.segments.length;s++){const n=r.segments[s],a=s===r.segments.length-1;if(n.kind==="key"){if(!u(i)||!Object.hasOwn(i,n.key))return-1;i=i[n.key];continue}if(!Array.isArray(i))return-1;if(n.kind==="index"){if(!Object.hasOwn(i,n.index))return-1;if(a)return n.index;i=i[n.index];continue}const d=this._findSelector(i,n.key,n.value);if(d===-1)return-1;if(a)return d;i=i[d]}return-1}_read(e){let t=this._root;for(const r of e.segments)if(r.kind==="key"){if(!u(t)||!Object.hasOwn(t,r.key))return{exists:!1,value:void 0};t=t[r.key]}else if(r.kind==="index"){if(!Array.isArray(t)||!Object.hasOwn(t,r.index))return{exists:!1,value:void 0};t=t[r.index]}else{if(!Array.isArray(t))return{exists:!1,value:void 0};const i=this._findSelector(t,r.key,r.value);if(i===-1)return{exists:!1,value:void 0};t=t[i]}return{exists:!0,value:t}}_readSegment(e,t){if(t.kind==="key")return Object.hasOwn(e,t.key)?e[t.key]:void 0;if(!Array.isArray(e))return;if(t.kind==="index")return e[t.index];const r=this._findSelector(e,t.key,t.value);return r===-1?void 0:e[r]}_readOrCreateChild(e,t,r,i){if(t.kind==="key"){let n=e[t.key];if(!Object.hasOwn(e,t.key)||n===void 0){if(!this._options.autoCreate)throw _(i);n=v(r),b(e,t.key,n)}return{value:k(n,i)}}if(!Array.isArray(e))throw w(i);if(t.kind==="index"){let n=e[t.index];if(!Object.hasOwn(e,t.index)||n===void 0){if(!this._options.autoCreate)throw _(i);n=v(r),e[t.index]=n}return{value:k(n,i),indexedParent:{array:e,index:t.index}}}let s=this._findSelector(e,t.key,t.value);if(s===-1){if(!this._options.autoCreate)throw _(i);const n=Object.create(null);n[t.key]=t.value,e.push(n),s=e.length-1,this._invalidateArray(e)}return{value:k(e[s],i),indexedParent:{array:e,index:s}}}_writeSegment(e,t,r,i,s){if(t.kind==="key"){b(e,t.key,r),s!==void 0&&s.array[s.index]===e&&this._invalidateIndexKey(s.array,t.key);return}if(!Array.isArray(e))throw w(i);if(t.kind==="index"){e[t.index]=r,this._invalidateArray(e);return}if(!f(r))throw new TypeError(`[Raph] New selector target at "${i}" must be an object.`);if(Object.hasOwn(r,t.key)&&!Object.is(r[t.key],t.value))throw new TypeError(`[Raph] Selector target at "${i}" has a conflicting key.`);const n=this._findSelector(e,t.key,t.value);if(n===-1&&!this._options.autoCreate)throw _(i);const a=Object.hasOwn(r,t.key)?r:{...r,[t.key]:t.value};n===-1?e.push(a):e[n]=a,this._invalidateArray(e)}_invalidateArray(e){var t;(t=this._indexes)==null||t.delete(e)}_invalidateIndexKey(e,t){var i;const r=(i=this._indexes)==null?void 0:i.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._indexes.delete(e))}_findSelector(e,t,r){var d;if(!this._options.indexEnabled)return O(e,t,r);const i=(d=this._indexes)==null?void 0:d.get(e);let s=i==null?void 0:i.get(t);s===void 0&&(s=this._createIndex(e,t));const n=s.get(r);if(n!==void 0&&f(e[n])&&Object.is(e[n][t],r))return n;const a=O(e,t,r);return a===-1?s.delete(r):s.set(r,a),a}_createIndex(e,t){const r=this._indexes??(this._indexes=new WeakMap);let i=r.get(e);if(i===void 0&&(i=new Map,r.set(e,i)),this._options.indexStrategy==="eager-all-keys")for(let n=0;n<e.length;n++){const a=e[n];if(f(a))for(const d of Object.keys(a)){const c=a[d];if(!A(c))continue;let l=i.get(d);l===void 0&&(l=new Map,i.set(d,l)),l.has(c)||l.set(c,n)}}let s=i.get(t);if(s!==void 0)return s;s=new Map;for(let n=0;n<e.length;n++){const a=e[n];if(!f(a))continue;const d=a[t];A(d)&&!s.has(d)&&s.set(d,n)}return i.set(t,s),s}}function O(o,e,t){for(let r=0;r<o.length;r++){const i=o[r];if(f(i)&&Object.hasOwn(i,e)&&Object.is(i[e],t))return r}return-1}function v(o){return o.kind==="index"||o.kind==="selector"?[]:p()}function p(){return Object.create(null)}function x(o){if(u(o))return o;throw new TypeError("[Raph] Root value must be an object or array.")}function k(o,e){if(u(o))return o;throw w(e)}function f(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function u(o){return Array.isArray(o)||f(o)}function A(o){return o===null||typeof o=="string"||typeof o=="number"||typeof o=="boolean"}function b(o,e,t){if(e==="__proto__"){Object.defineProperty(o,e,{configurable:!0,enumerable:!0,value:t,writable:!0});return}o[e]=t}function w(o){return new TypeError(`[Raph] Cannot traverse non-container data at "${o}".`)}function _(o){return new Error(`[Raph] Cannot create missing container at "${o}" (autoCreate=false).`)}exports.DefaultDataAdapter=g;
@@ -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 { createDataDraft as S } from "./data-draft.js";
5
+ import { parseDataPath as h } from "./data-path.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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(S,x){const m=new WeakMap,v=new WeakMap,b=(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)b(c,r,s)}},w=(n,u,s)=>{if(!n||typeof n!="object")return n;const c=Object.getPrototypeOf(n);let l=v.get(n)??m.get(n);if(!l){const r=n,g=Array.isArray(r),d=g?[]:Object.create(c);g&&(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)),i=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)=>w(i(e),t,e),has:(a,e)=>O(e),set:(a,e,f)=>{if(g&&e==="length"){const o=Number(f);if(!Number.isInteger(o)||o<0||o>4294967295)throw new RangeError("Invalid array length");for(let h=o;h<Number(i("length"));h++)t.removed.add(String(h)),t.values.delete(String(h));d.length=o}else if(g&&typeof e=="string"&&/^(?:0|[1-9]\d*)$/.test(e)){const o=Number(e);o<4294967295&&o>=Number(i("length"))&&(t.values.set("length",o+1),d.length=o+1)}return t.values.set(e,f),t.removed.delete(e),b(t,e),!0},deleteProperty:(a,e)=>g&&e==="length"?!1:(t.values.delete(e),t.removed.add(e),b(t,e),!0),ownKeys:()=>[...new Set([...Reflect.ownKeys(r),...t.values.keys()])].filter(a=>!t.removed.has(a)),getOwnPropertyDescriptor:(a,e)=>{if(g&&e==="length")return{value:i(e),writable:!0,enumerable:!1,configurable:!1};const f=Object.getOwnPropertyDescriptor(r,e);if(!(t.removed.has(e)||!f&&!t.values.has(e)))return{value:w(i(e),t,e),writable:!0,enumerable:(f==null?void 0:f.enumerable)??!0,configurable:!0}}}),m.set(r,t),v.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:w(S),unchangedArray(n,u){const s=v.get(n);if(!s)return null;for(const c of s.changed){if(s.values.has(c)||s.removed.has(c))return null;const l=m.get(s.source[c]);if(l!=null&&l.changed.has(u))return null}return s.source}}}exports.createDataDraft=y;
@@ -0,0 +1,71 @@
1
+ function k(x, S) {
2
+ const m = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), w = (n, u, a = /* @__PURE__ */ new Set()) => {
3
+ if (!a.has(n)) {
4
+ a.add(n), n.changed.add(u), Array.isArray(n.source) && S(n.proxy);
5
+ for (const [c, l] of n.parents)
6
+ for (const r of l)
7
+ w(c, r, a);
8
+ }
9
+ }, b = (n, u, a) => {
10
+ if (!n || typeof n != "object")
11
+ return n;
12
+ const c = Object.getPrototypeOf(n);
13
+ let l = v.get(n) ?? m.get(n);
14
+ if (!l) {
15
+ const r = n, g = Array.isArray(r), i = g ? [] : Object.create(c);
16
+ g && (i.length = r.length), l = { source: r, proxy: null, values: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Set(), changed: /* @__PURE__ */ new Set(), parents: /* @__PURE__ */ new Map() };
17
+ const t = l, O = (s) => !t.removed.has(s) && (t.values.has(s) || Reflect.has(r, s)), d = (s) => t.removed.has(s) ? void 0 : t.values.has(s) ? t.values.get(s) : Reflect.get(r, s);
18
+ t.proxy = new Proxy(i, {
19
+ get: (s, e) => b(d(e), t, e),
20
+ has: (s, e) => O(e),
21
+ set: (s, e, f) => {
22
+ if (g && e === "length") {
23
+ const o = Number(f);
24
+ if (!Number.isInteger(o) || o < 0 || o > 4294967295)
25
+ throw new RangeError("Invalid array length");
26
+ for (let h = o; h < Number(d("length")); h++)
27
+ t.removed.add(String(h)), t.values.delete(String(h));
28
+ i.length = o;
29
+ } else if (g && typeof e == "string" && /^(?:0|[1-9]\d*)$/.test(e)) {
30
+ const o = Number(e);
31
+ o < 4294967295 && o >= Number(d("length")) && (t.values.set("length", o + 1), i.length = o + 1);
32
+ }
33
+ return t.values.set(e, f), t.removed.delete(e), w(t, e), !0;
34
+ },
35
+ deleteProperty: (s, e) => g && e === "length" ? !1 : (t.values.delete(e), t.removed.add(e), w(t, e), !0),
36
+ ownKeys: () => [.../* @__PURE__ */ new Set([...Reflect.ownKeys(r), ...t.values.keys()])].filter((s) => !t.removed.has(s)),
37
+ getOwnPropertyDescriptor: (s, e) => {
38
+ if (g && e === "length")
39
+ return { value: d(e), writable: !0, enumerable: !1, configurable: !1 };
40
+ const f = Object.getOwnPropertyDescriptor(r, e);
41
+ if (!(t.removed.has(e) || !f && !t.values.has(e)))
42
+ return { value: b(d(e), t, e), writable: !0, enumerable: (f == null ? void 0 : f.enumerable) ?? !0, configurable: !0 };
43
+ }
44
+ }), m.set(r, t), v.set(t.proxy, t);
45
+ }
46
+ if (u && a !== void 0) {
47
+ let r = l.parents.get(u);
48
+ r || (r = /* @__PURE__ */ new Set(), l.parents.set(u, r)), r.add(a);
49
+ }
50
+ return l.proxy;
51
+ };
52
+ return {
53
+ root: b(x),
54
+ unchangedArray(n, u) {
55
+ const a = v.get(n);
56
+ if (!a)
57
+ return null;
58
+ for (const c of a.changed) {
59
+ if (a.values.has(c) || a.removed.has(c))
60
+ return null;
61
+ const l = m.get(a.source[c]);
62
+ if (l != null && l.changed.has(u))
63
+ return null;
64
+ }
65
+ return a.source;
66
+ }
67
+ };
68
+ }
69
+ export {
70
+ k as createDataDraft
71
+ };
@@ -0,0 +1 @@
1
+ "use strict";var E=Object.defineProperty;var M=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var o=(t,e,n)=>M(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=2e4;let m,w;const h=class h{constructor(e,n){o(this,"_canonical");o(this,"_segments");o(this,"_exact");o(this,"_mask");this._canonical=e,this._segments=Object.freeze(n.map(r=>Object.freeze({...r})))}static from(e,n){return e instanceof h?e:typeof e=="string"?this.fromString(e,n):this.fromPlain(e)}static fromString(e,n){const r=p(e,n==null?void 0:n.vars,!0,(n==null?void 0:n.wildcardDynamic)===!0,!0),i=this._cache??(this._cache=new Map),s=i.get(r.canonical);if(s!==void 0)return s;i.size>=y&&i.clear();const c=new h(r.canonical,r.segments);return i.set(r.canonical,c),c}static fromPlain(e){const r=(Array.isArray(e.segs)?e.segs:[]).map(F);return new h(k(r),r)}toPlain(){return{segs:this._segments.map(e=>e.kind==="key"?{t:"key",k:e.key}:e.kind==="index"?{t:"idx",i:e.index}:e.kind==="selector"?{t:"param",pk:e.key,pv:e.value}:{t:"wc",indexed:e.indexed}),deepOnTail:S(this._segments)}}toStringPath(){return this._canonical}toString(){return this._canonical}segments(){return this._segments}static match(e,n){const r=this.from(e)._segments,i=this.from(n)._segments;let s=0;for(;s<r.length;s++){const c=r[s];if(c.kind==="wildcard"&&!c.indexed&&s===r.length-1)return!0;const a=i[s];if(a===void 0||!W(c,a))return!1}return s===i.length}_asExact(){for(const e of this._segments)if(e.kind==="wildcard")throw $(this._canonical);return this._exact??(this._exact={canonical:this._canonical,segments:this._segments})}_asMask(){for(let n=0;n<this._segments.length-1;n++){const r=this._segments[n];if(r.kind==="wildcard"&&!r.indexed)throw new TypeError(`[Raph] Dot wildcard must be the final mask segment: "${this._canonical}".`)}const e=S(this._segments);return this._mask??(this._mask={canonical:this._canonical,deep:e,segments:e?this._segments.slice(0,-1):this._segments})}};o(h,"_cache");let d=h;function T(t,e){if(!(e!=null&&e.vars)){const i=m==null?void 0:m.get(t);if(i!==void 0)return i}if(typeof t!="string")return O(t,e);const n=p(t,e==null?void 0:e.vars,!1,!1,!0),r={canonical:n.canonical,segments:n.segments};if(!(e!=null&&e.vars)){const i=m??(m=new Map);i.size>=y&&i.clear(),i.set(t,r)}return r}function R(t){const e=w==null?void 0:w.get(t);if(e!==void 0)return e;if(typeof t!="string")return N(t);const n=p(t,void 0,!0,!1,!0);for(let a=0;a<n.segments.length-1;a++){const l=n.segments[a];if(l.kind==="wildcard"&&!l.indexed)throw new TypeError(`[Raph] Dot wildcard must be the final mask segment: "${t}".`)}const r=n.segments[n.segments.length-1],i=(r==null?void 0:r.kind)==="wildcard"&&!r.indexed,s={canonical:n.canonical,deep:i,segments:i?n.segments.slice(0,-1):n.segments},c=w??(w=new Map);return c.size>=y&&c.clear(),c.set(t,s),s}function O(t,e){const n=d.from(t,e)._asExact();if(t instanceof d&&!(e!=null&&e.vars)){const r=m??(m=new Map);r.size>=y&&r.clear(),r.set(t,n)}return n}function N(t){const e=d.from(t)._asMask();if(t instanceof d){const n=w??(w=new Map);n.size>=y&&n.clear(),n.set(t,e)}return e}function j(t){if(t.segments.length===0)return["*"];const e=[`${t.canonical}.*`];for(let n=1;n<t.segments.length;n++)e.push(k(t.segments.slice(0,n)));return e}function p(t,e,n,r=!1,i=!1){const s=t.trim();if(s.length===0){if(i)return{canonical:"",segments:[]};throw new TypeError("[Raph] Data path must not be empty.")}const c=[];let a=0,l=!0;for(;a<s.length;){const _=s[a];if(_==="."){if(l)throw f(t);l=!0,a++;continue}if(_==="["){const v=A(s,a);c.push(z(s.slice(a+1,v),e,n,r)),a=v+1,l=!1;continue}if(!l)throw f(t);let u=a;for(;u<s.length&&s[u]!=="."&&s[u]!=="[";)u++;const g=s.slice(a,u).trim();if(g.length===0)throw f(t);if(g==="*"){if(!n)throw $(t);c.push({kind:"wildcard",indexed:!1})}else r&&g.startsWith("$")&&!x(g.slice(1),e)?c.push({kind:"wildcard",indexed:!1}):c.push({kind:"key",key:V(g,e)});a=u,l=!1}if(l||c.length===0)throw f(t);return{canonical:k(c),segments:c}}function A(t,e){let n,r=1;for(let i=e+1;i<t.length;i++){const s=t[i];if(s==="\\"){i++;continue}if(n!==void 0){s===n&&(n=void 0);continue}if(s==='"'||s==="'"){n=s;continue}if(s==="["){r++;continue}if(s==="]"&&--r===0)return i}throw f(t)}function z(t,e,n,r){const i=t.trim();if(i==="*"){if(!n)throw $(`[${t}]`);return{kind:"wildcard",indexed:!0}}if(/^\d+$/.test(i))return{kind:"index",index:Number(i)};if(/^\$[A-Z_$][\w$]*$/i.test(i)){if(r&&!x(i.slice(1),e))return{kind:"wildcard",indexed:!0};const l=b(i.slice(1),e);if(!Number.isInteger(l)||l<0)throw new TypeError(`[Raph] Index variable "${i}" must be a non-negative integer.`);return{kind:"index",index:l}}const s=D(i);if(s===-1)throw f(`[${t}]`);const c=i.slice(0,s).trim(),a=i.slice(s+1).trim();if(!c||!a)throw f(`[${t}]`);return r&&Z(a,e)?{kind:"wildcard",indexed:!0}:{kind:"selector",key:c,value:I(a,e)}}function D(t){let e;for(let n=0;n<t.length;n++){const r=t[n];if(r==="\\"){n++;continue}if(e!==void 0){r===e&&(e=void 0);continue}if(r==='"'||r==="'")e=r;else if(r==="=")return n}return-1}function I(t,e){if(/^\$[A-Z_$][\w$]*$/i.test(t)){const n=b(t.slice(1),e);if(n===null||typeof n=="string"||typeof n=="boolean"||typeof n=="number"&&Number.isFinite(n))return n;throw new TypeError(`[Raph] Selector variable "${t}" must be scalar.`)}if(t[0]==='"'||t[0]==="'")return q(t);if(/^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(t)){const n=Number(t);if(Number.isFinite(n))return n}return t==="true"?!0:t==="false"?!1:t==="null"?null:t}function q(t){const e=t[0];if(t.length<2||t[t.length-1]!==e)throw f(t);if(e==='"')try{const r=JSON.parse(t);if(typeof r=="string")return r}catch{throw f(t)}let n="";for(let r=1;r<t.length-1;r++){const i=t[r];if(i==="\\"){if(r++,r>=t.length-1)throw f(t);n+=t[r]}else n+=i}return n}function V(t,e){if(!t.startsWith("$"))return t;const n=b(t.slice(1),e);if(typeof n!="string"&&typeof n!="number")throw new TypeError(`[Raph] Key variable "${t}" must be a string or number.`);const r=String(n);if(!r||r.includes(".")||r.includes("[")||r.includes("]"))throw new TypeError(`[Raph] Key variable "${t}" contains path syntax.`);return r}function b(t,e){if(!x(t,e))throw new TypeError(`[Raph] Missing path variable "${t}".`);return e[t]}function x(t,e){return e!==void 0&&Object.hasOwn(e,t)}function Z(t,e){for(const n of t.matchAll(/\$([A-Z_$][\w$]*)/gi))if(!x(n[1],e))return!0;return!1}function F(t){if(typeof t!="object"||t===null)throw P();const e=t;if(e.t==="key"&&typeof e.k=="string")return{kind:"key",key:e.k};if(e.t==="idx"&&typeof e.i=="number"&&Number.isInteger(e.i)&&e.i>=0)return{kind:"index",index:e.i};if(e.t==="wc")return{kind:"wildcard",indexed:e.indexed===!0};if(e.t==="param"&&typeof e.pk=="string"&&K(e.pv))return{kind:"selector",key:e.pk,value:e.pv};throw P()}function K(t){return t===null||typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function S(t){const e=t[t.length-1];return(e==null?void 0:e.kind)==="wildcard"&&!e.indexed}function W(t,e){return t.kind==="wildcard"?!t.indexed||e.kind==="index"||e.kind==="selector":t.kind!==e.kind?!1:t.kind==="key"?t.key===e.key:t.kind==="index"?t.index===e.index:t.key===e.key&&Object.is(t.value,e.value)}function k(t){let e="";for(const n of t)n.kind==="key"?e+=e?`.${n.key}`:n.key:n.kind==="index"?e+=`[${n.index}]`:n.kind==="selector"?e+=`[${n.key}=${B(n.value)}]`:e+=n.indexed?"[*]":e?".*":"*";return e}function B(t){return typeof t=="string"?JSON.stringify(t):String(t)}function f(t){return new TypeError(`[Raph] Invalid data path "${t}".`)}function P(){return new TypeError("[Raph] Invalid plain DataPath representation.")}function $(t){return new TypeError(`[Raph] Wildcard is only allowed in watch masks: "${t}".`)}exports.DataPath=d;exports.parseDataPath=T;exports.parsePathMask=R;exports.pathRelationMasks=j;