@revisium/schema-toolkit 0.19.1 → 0.19.3

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 (33) hide show
  1. package/dist/{types-EHdxfQpd.d.cts → FormulaPathBuilder-8gmUFlgu.d.cts} +27 -2
  2. package/dist/{types-Dw9ba_YE.d.ts → FormulaPathBuilder-B6RyUFN7.d.ts} +27 -2
  3. package/dist/chunk-3FJZMVWA.js +3 -0
  4. package/dist/{chunk-Y2GYABV7.js.map → chunk-3FJZMVWA.js.map} +1 -1
  5. package/dist/{chunk-MKDGOOBV.cjs → chunk-CN74KAMA.cjs} +373 -66
  6. package/dist/chunk-CN74KAMA.cjs.map +1 -0
  7. package/dist/{chunk-R6VYCHY2.js → chunk-K7XZT2M4.js} +49 -310
  8. package/dist/chunk-K7XZT2M4.js.map +1 -0
  9. package/dist/chunk-L6HE7QPU.cjs +4 -0
  10. package/dist/{chunk-MLNKM67U.cjs.map → chunk-L6HE7QPU.cjs.map} +1 -1
  11. package/dist/{chunk-45UZ3CJN.js → chunk-T2JUOWMX.js} +313 -10
  12. package/dist/chunk-T2JUOWMX.js.map +1 -0
  13. package/dist/{chunk-U7N3EEQX.cjs → chunk-X2KLCGJ6.cjs} +51 -315
  14. package/dist/chunk-X2KLCGJ6.cjs.map +1 -0
  15. package/dist/core/index.cjs +70 -58
  16. package/dist/core/index.d.cts +2 -2
  17. package/dist/core/index.d.ts +2 -2
  18. package/dist/core/index.js +2 -2
  19. package/dist/index.cjs +115 -115
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +3 -3
  23. package/dist/model/index.cjs +58 -58
  24. package/dist/model/index.d.cts +4 -28
  25. package/dist/model/index.d.ts +4 -28
  26. package/dist/model/index.js +2 -2
  27. package/package.json +1 -1
  28. package/dist/chunk-45UZ3CJN.js.map +0 -1
  29. package/dist/chunk-MKDGOOBV.cjs.map +0 -1
  30. package/dist/chunk-MLNKM67U.cjs +0 -4
  31. package/dist/chunk-R6VYCHY2.js.map +0 -1
  32. package/dist/chunk-U7N3EEQX.cjs.map +0 -1
  33. package/dist/chunk-Y2GYABV7.js +0 -3
@@ -1,9 +1,308 @@
1
1
  'use strict';
2
2
 
3
- var chunkU7N3EEQX_cjs = require('./chunk-U7N3EEQX.cjs');
3
+ var chunkX2KLCGJ6_cjs = require('./chunk-X2KLCGJ6.cjs');
4
4
  var chunkVGADCIBG_cjs = require('./chunk-VGADCIBG.cjs');
5
5
  var nanoid = require('nanoid');
6
+ var formula = require('@revisium/formula');
6
7
 
8
+ var ARRAY_NOTATION_REGEX = /^([^[]+)\[(?:\d+|\*)?\]$/;
9
+ var FormulaPath = class {
10
+ constructor(basePath, relativePath) {
11
+ this.basePath = basePath;
12
+ this.relativePath = relativePath;
13
+ }
14
+ resolve() {
15
+ let ast;
16
+ try {
17
+ const parseResult = formula.parseFormula(this.relativePath);
18
+ ast = parseResult.ast;
19
+ } catch {
20
+ return null;
21
+ }
22
+ return this.astToPath(ast, this.basePath);
23
+ }
24
+ astToPath(ast, base) {
25
+ switch (ast.type) {
26
+ case "Identifier":
27
+ return base.child(ast.name);
28
+ case "MemberExpression": {
29
+ const objectPath = this.astToPath(ast.object, base);
30
+ if (!objectPath) {
31
+ return null;
32
+ }
33
+ return objectPath.child(ast.property);
34
+ }
35
+ case "IndexExpression":
36
+ case "WildcardExpression": {
37
+ const objectPath = this.astToPath(ast.object, base);
38
+ if (!objectPath) {
39
+ return null;
40
+ }
41
+ return objectPath.childItems();
42
+ }
43
+ case "RelativePath":
44
+ return this.resolveRelativePathString(base, ast.path);
45
+ case "RootPath":
46
+ return this.resolveRootPath(ast.path);
47
+ default:
48
+ return null;
49
+ }
50
+ }
51
+ resolveRelativePathString(base, path) {
52
+ const parts = path.split("/");
53
+ let result = base;
54
+ for (const part of parts) {
55
+ if (part === "..") {
56
+ if (result.isEmpty()) {
57
+ return null;
58
+ }
59
+ result = result.parent();
60
+ } else if (part === ".") {
61
+ continue;
62
+ } else if (part) {
63
+ result = result.child(part);
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+ resolveRootPath(rootPath) {
69
+ const path = rootPath.startsWith("/") ? rootPath.slice(1) : rootPath;
70
+ if (!path) {
71
+ return chunkX2KLCGJ6_cjs.EMPTY_PATH;
72
+ }
73
+ try {
74
+ return this.parseFormulaPath(path);
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+ parseFormulaPath(formulaPath) {
80
+ const parts = formulaPath.split(".");
81
+ let result = chunkX2KLCGJ6_cjs.EMPTY_PATH;
82
+ for (const part of parts) {
83
+ if (!part) {
84
+ throw new Error(`Invalid path: empty segment`);
85
+ }
86
+ const match = ARRAY_NOTATION_REGEX.exec(part);
87
+ if (match?.[1]) {
88
+ result = result.child(match[1]).childItems();
89
+ } else {
90
+ result = result.child(part);
91
+ }
92
+ }
93
+ return result;
94
+ }
95
+ };
96
+
97
+ // src/model/schema-formula/parsing/ParsedFormula.ts
98
+ var ParsedFormula = class {
99
+ _expression;
100
+ astNode;
101
+ deps;
102
+ astPathToNodeId;
103
+ constructor(tree, formulaNodeId, expression) {
104
+ this._expression = expression;
105
+ const parseResult = formula.parseFormula(expression);
106
+ this.astNode = parseResult.ast;
107
+ const formulaPath = tree.pathOf(formulaNodeId);
108
+ if (formulaPath.isEmpty() && tree.root().id() !== formulaNodeId) {
109
+ throw new chunkX2KLCGJ6_cjs.FormulaError("Formula node not found in tree", formulaNodeId);
110
+ }
111
+ const deps = [];
112
+ const astPathToNodeId = /* @__PURE__ */ new Map();
113
+ for (const depPath of parseResult.dependencies) {
114
+ const targetNodeId = this.resolveDependencyPath(
115
+ tree,
116
+ formulaPath,
117
+ depPath
118
+ );
119
+ if (!targetNodeId) {
120
+ throw new chunkX2KLCGJ6_cjs.FormulaError(
121
+ `Cannot resolve formula dependency: ${depPath}`,
122
+ formulaNodeId,
123
+ "Path not found in schema"
124
+ );
125
+ }
126
+ if (targetNodeId === formulaNodeId) {
127
+ throw new chunkX2KLCGJ6_cjs.FormulaError(
128
+ "Formula cannot reference itself",
129
+ formulaNodeId,
130
+ "Self-reference detected"
131
+ );
132
+ }
133
+ deps.push(new chunkX2KLCGJ6_cjs.ResolvedDependency(targetNodeId));
134
+ astPathToNodeId.set(depPath, targetNodeId);
135
+ }
136
+ this.deps = deps;
137
+ this.astPathToNodeId = astPathToNodeId;
138
+ }
139
+ version() {
140
+ return 1;
141
+ }
142
+ expression() {
143
+ return this._expression;
144
+ }
145
+ ast() {
146
+ return this.astNode;
147
+ }
148
+ dependencies() {
149
+ return this.deps;
150
+ }
151
+ getNodeIdForAstPath(astPath) {
152
+ return this.astPathToNodeId.get(astPath) ?? null;
153
+ }
154
+ astPaths() {
155
+ return Array.from(this.astPathToNodeId.keys());
156
+ }
157
+ resolveDependencyPath(tree, formulaNodePath, depPath) {
158
+ const basePath = this.getFormulaBasePath(formulaNodePath);
159
+ const depFormulaPath = new FormulaPath(basePath, depPath);
160
+ const targetPath = depFormulaPath.resolve();
161
+ if (!targetPath) {
162
+ return null;
163
+ }
164
+ const targetNode = tree.nodeAt(targetPath);
165
+ if (targetNode.isNull()) {
166
+ return null;
167
+ }
168
+ return targetNode.id();
169
+ }
170
+ getFormulaBasePath(formulaPath) {
171
+ let basePath = formulaPath;
172
+ while (!basePath.isEmpty()) {
173
+ const segs = basePath.segments();
174
+ const lastSeg = segs[segs.length - 1];
175
+ basePath = basePath.parent();
176
+ if (!lastSeg?.isItems()) {
177
+ break;
178
+ }
179
+ }
180
+ return basePath;
181
+ }
182
+ };
183
+
184
+ // src/model/schema-formula/store/FormulaDependencyIndex.ts
185
+ var FormulaDependencyIndex = class {
186
+ dependentsMap = /* @__PURE__ */ new Map();
187
+ formulasByNodeId = /* @__PURE__ */ new Map();
188
+ registerFormula(formulaNodeId, formula) {
189
+ this.unregisterFormula(formulaNodeId);
190
+ this.formulasByNodeId.set(formulaNodeId, formula);
191
+ for (const dep of formula.dependencies()) {
192
+ const targetId = dep.targetNodeId();
193
+ let dependents = this.dependentsMap.get(targetId);
194
+ if (!dependents) {
195
+ dependents = /* @__PURE__ */ new Set();
196
+ this.dependentsMap.set(targetId, dependents);
197
+ }
198
+ dependents.add(formulaNodeId);
199
+ }
200
+ }
201
+ unregisterFormula(formulaNodeId) {
202
+ this.formulasByNodeId.delete(formulaNodeId);
203
+ for (const [targetId, dependents] of this.dependentsMap) {
204
+ dependents.delete(formulaNodeId);
205
+ if (dependents.size === 0) {
206
+ this.dependentsMap.delete(targetId);
207
+ }
208
+ }
209
+ }
210
+ getDependents(nodeId) {
211
+ const dependents = this.dependentsMap.get(nodeId);
212
+ return dependents ? Array.from(dependents) : [];
213
+ }
214
+ hasDependents(nodeId) {
215
+ const dependents = this.dependentsMap.get(nodeId);
216
+ return dependents !== void 0 && dependents.size > 0;
217
+ }
218
+ getFormula(nodeId) {
219
+ return this.formulasByNodeId.get(nodeId) ?? null;
220
+ }
221
+ hasFormula(nodeId) {
222
+ return this.formulasByNodeId.has(nodeId);
223
+ }
224
+ clear() {
225
+ this.dependentsMap.clear();
226
+ this.formulasByNodeId.clear();
227
+ }
228
+ forEachFormula(callback) {
229
+ for (const [nodeId, formula] of this.formulasByNodeId) {
230
+ callback(nodeId, formula);
231
+ }
232
+ }
233
+ size() {
234
+ return this.formulasByNodeId.size;
235
+ }
236
+ };
237
+
238
+ // src/model/schema-formula/changes/FormulaChangeDetector.ts
239
+ var FormulaChangeDetector = class {
240
+ constructor(index, currentTree, baseTree) {
241
+ this.index = index;
242
+ this.currentTree = currentTree;
243
+ this.baseTree = baseTree;
244
+ }
245
+ detectIndirectChanges(changedNodeIds) {
246
+ const result = [];
247
+ const visited = /* @__PURE__ */ new Set();
248
+ for (const changedId of changedNodeIds) {
249
+ this.collectDependentChanges(changedId, result, visited, changedNodeIds);
250
+ }
251
+ return result;
252
+ }
253
+ collectDependentChanges(nodeId, result, visited, directlyChanged) {
254
+ const dependents = this.index.getDependents(nodeId);
255
+ for (const dependentId of dependents) {
256
+ if (visited.has(dependentId)) {
257
+ continue;
258
+ }
259
+ visited.add(dependentId);
260
+ if (directlyChanged.has(dependentId)) {
261
+ continue;
262
+ }
263
+ const change = this.detectFormulaChange(dependentId);
264
+ if (change) {
265
+ result.push(change);
266
+ }
267
+ this.collectDependentChanges(dependentId, result, visited, directlyChanged);
268
+ }
269
+ }
270
+ detectFormulaChange(nodeId) {
271
+ const currentNode = this.currentTree.nodeById(nodeId);
272
+ const baseNode = this.baseTree.nodeById(nodeId);
273
+ if (currentNode.isNull() || baseNode.isNull()) {
274
+ return null;
275
+ }
276
+ const currentFormula = currentNode.formula();
277
+ const baseFormula = baseNode.formula();
278
+ if (!currentFormula || !baseFormula) {
279
+ return null;
280
+ }
281
+ const fromExpression = this.getSerializedExpression(baseFormula, this.baseTree, nodeId);
282
+ const toExpression = this.getSerializedExpression(currentFormula, this.currentTree, nodeId);
283
+ if (fromExpression === null || toExpression === null) {
284
+ return null;
285
+ }
286
+ if (fromExpression === toExpression) {
287
+ return null;
288
+ }
289
+ return {
290
+ nodeId,
291
+ fromExpression,
292
+ toExpression
293
+ };
294
+ }
295
+ getSerializedExpression(formula, tree, nodeId) {
296
+ try {
297
+ const xFormula = chunkX2KLCGJ6_cjs.FormulaSerializer.toXFormula(tree, nodeId, formula);
298
+ return xFormula.expression;
299
+ } catch {
300
+ return null;
301
+ }
302
+ }
303
+ };
304
+
305
+ // src/model/schema-model/SchemaParser.ts
7
306
  var SchemaParser = class {
8
307
  pendingFormulas = [];
9
308
  _parseErrors = [];
@@ -21,7 +320,7 @@ var SchemaParser = class {
21
320
  continue;
22
321
  }
23
322
  try {
24
- const formula = new chunkU7N3EEQX_cjs.ParsedFormula(tree, pending.nodeId, pending.expression);
323
+ const formula = new ParsedFormula(tree, pending.nodeId, pending.expression);
25
324
  node.setFormula(formula);
26
325
  } catch (error) {
27
326
  this._parseErrors.push({
@@ -42,7 +341,7 @@ var SchemaParser = class {
42
341
  if (resolvedSchema) {
43
342
  return this.parseNode(resolvedSchema, name, refValue);
44
343
  }
45
- return chunkU7N3EEQX_cjs.createRefNode(nanoid.nanoid(), name, refValue, this.extractMetadata(schema));
344
+ return chunkX2KLCGJ6_cjs.createRefNode(nanoid.nanoid(), name, refValue, this.extractMetadata(schema));
46
345
  }
47
346
  const schemaWithType = schema;
48
347
  switch (schemaWithType.type) {
@@ -68,14 +367,14 @@ var SchemaParser = class {
68
367
  children.push(this.parseNode(propSchema, propName));
69
368
  }
70
369
  }
71
- return chunkU7N3EEQX_cjs.createObjectNode(nanoid.nanoid(), name, children, {
370
+ return chunkX2KLCGJ6_cjs.createObjectNode(nanoid.nanoid(), name, children, {
72
371
  metadata: this.extractMetadata(schema),
73
372
  ref: ref2
74
373
  });
75
374
  }
76
375
  parseArray(schema, name, ref2) {
77
376
  const items = this.parseNode(schema.items, "items");
78
- return chunkU7N3EEQX_cjs.createArrayNode(nanoid.nanoid(), name, items, {
377
+ return chunkX2KLCGJ6_cjs.createArrayNode(nanoid.nanoid(), name, items, {
79
378
  metadata: this.extractMetadata(schema),
80
379
  ref: ref2
81
380
  });
@@ -83,7 +382,7 @@ var SchemaParser = class {
83
382
  parseString(schema, name, ref2) {
84
383
  const nodeId = nanoid.nanoid();
85
384
  this.collectFormula(nodeId, schema["x-formula"]);
86
- return chunkU7N3EEQX_cjs.createStringNode(nodeId, name, {
385
+ return chunkX2KLCGJ6_cjs.createStringNode(nodeId, name, {
87
386
  defaultValue: schema.default,
88
387
  foreignKey: schema.foreignKey,
89
388
  metadata: this.extractMetadata(schema),
@@ -93,7 +392,7 @@ var SchemaParser = class {
93
392
  parseNumber(schema, name, ref2) {
94
393
  const nodeId = nanoid.nanoid();
95
394
  this.collectFormula(nodeId, schema["x-formula"]);
96
- return chunkU7N3EEQX_cjs.createNumberNode(nodeId, name, {
395
+ return chunkX2KLCGJ6_cjs.createNumberNode(nodeId, name, {
97
396
  defaultValue: schema.default,
98
397
  metadata: this.extractMetadata(schema),
99
398
  ref: ref2
@@ -102,7 +401,7 @@ var SchemaParser = class {
102
401
  parseBoolean(schema, name, ref2) {
103
402
  const nodeId = nanoid.nanoid();
104
403
  this.collectFormula(nodeId, schema["x-formula"]);
105
- return chunkU7N3EEQX_cjs.createBooleanNode(nodeId, name, {
404
+ return chunkX2KLCGJ6_cjs.createBooleanNode(nodeId, name, {
106
405
  defaultValue: schema.default,
107
406
  metadata: this.extractMetadata(schema),
108
407
  ref: ref2
@@ -135,13 +434,13 @@ var NodeFactory = class {
135
434
  createNode(name, type) {
136
435
  switch (type) {
137
436
  case "string":
138
- return chunkU7N3EEQX_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
437
+ return chunkX2KLCGJ6_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
139
438
  case "number":
140
- return chunkU7N3EEQX_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
439
+ return chunkX2KLCGJ6_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
141
440
  case "boolean":
142
- return chunkU7N3EEQX_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
441
+ return chunkX2KLCGJ6_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
143
442
  case "object":
144
- return chunkU7N3EEQX_cjs.createObjectNode(nanoid.nanoid(), name, []);
443
+ return chunkX2KLCGJ6_cjs.createObjectNode(nanoid.nanoid(), name, []);
145
444
  case "array":
146
445
  return this.createArrayNodeInternal(name);
147
446
  default:
@@ -149,11 +448,11 @@ var NodeFactory = class {
149
448
  }
150
449
  }
151
450
  createArrayNodeInternal(name) {
152
- const items = chunkU7N3EEQX_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
153
- return chunkU7N3EEQX_cjs.createArrayNode(nanoid.nanoid(), name, items);
451
+ const items = chunkX2KLCGJ6_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
452
+ return chunkX2KLCGJ6_cjs.createArrayNode(nanoid.nanoid(), name, items);
154
453
  }
155
454
  createArrayNodeWithItems(name, items) {
156
- return chunkU7N3EEQX_cjs.createArrayNode(nanoid.nanoid(), name, items);
455
+ return chunkX2KLCGJ6_cjs.createArrayNode(nanoid.nanoid(), name, items);
157
456
  }
158
457
  };
159
458
 
@@ -252,7 +551,7 @@ var PrimitiveToArrayTransformer = class {
252
551
  const { sourceNode } = ctx;
253
552
  const itemsNode = sourceNode.cloneWithId(nanoid.nanoid());
254
553
  itemsNode.setName("items");
255
- const arrayNode = chunkU7N3EEQX_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
554
+ const arrayNode = chunkX2KLCGJ6_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
256
555
  return { node: arrayNode };
257
556
  }
258
557
  };
@@ -265,7 +564,7 @@ var ObjectToArrayTransformer = class {
265
564
  const { sourceNode } = ctx;
266
565
  const itemsNode = sourceNode.cloneWithId(nanoid.nanoid());
267
566
  itemsNode.setName("items");
268
- const arrayNode = chunkU7N3EEQX_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
567
+ const arrayNode = chunkX2KLCGJ6_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
269
568
  return { node: arrayNode };
270
569
  }
271
570
  };
@@ -315,7 +614,7 @@ var RefTransformer = class {
315
614
  return { node: newNode };
316
615
  }
317
616
  const metadata = this.extractMetadata(targetSpec);
318
- const node = chunkU7N3EEQX_cjs.createRefNode(sourceNode.id(), sourceNode.name(), refUri, metadata);
617
+ const node = chunkX2KLCGJ6_cjs.createRefNode(sourceNode.id(), sourceNode.name(), refUri, metadata);
319
618
  return { node };
320
619
  }
321
620
  extractMetadata(spec) {
@@ -350,23 +649,23 @@ var DefaultTransformer = class {
350
649
  createNode(id, name, type, spec, metadata) {
351
650
  switch (type) {
352
651
  case "string":
353
- return chunkU7N3EEQX_cjs.createStringNode(id, name, {
652
+ return chunkX2KLCGJ6_cjs.createStringNode(id, name, {
354
653
  defaultValue: spec.default ?? "",
355
654
  foreignKey: spec.foreignKey,
356
655
  metadata
357
656
  });
358
657
  case "number":
359
- return chunkU7N3EEQX_cjs.createNumberNode(id, name, {
658
+ return chunkX2KLCGJ6_cjs.createNumberNode(id, name, {
360
659
  defaultValue: spec.default ?? 0,
361
660
  metadata
362
661
  });
363
662
  case "boolean":
364
- return chunkU7N3EEQX_cjs.createBooleanNode(id, name, {
663
+ return chunkX2KLCGJ6_cjs.createBooleanNode(id, name, {
365
664
  defaultValue: spec.default ?? false,
366
665
  metadata
367
666
  });
368
667
  case "object":
369
- return chunkU7N3EEQX_cjs.createObjectNode(id, name, [], { metadata });
668
+ return chunkX2KLCGJ6_cjs.createObjectNode(id, name, [], { metadata });
370
669
  case "array":
371
670
  return this.createArrayNode(id, name, metadata);
372
671
  default:
@@ -374,8 +673,8 @@ var DefaultTransformer = class {
374
673
  }
375
674
  }
376
675
  createArrayNode(id, name, metadata) {
377
- const items = chunkU7N3EEQX_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
378
- return chunkU7N3EEQX_cjs.createArrayNode(id, name, items, { metadata });
676
+ const items = chunkX2KLCGJ6_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
677
+ return chunkX2KLCGJ6_cjs.createArrayNode(id, name, items, { metadata });
379
678
  }
380
679
  extractMetadata(spec) {
381
680
  const meta = {};
@@ -439,10 +738,10 @@ function createTypeTransformChain(options) {
439
738
  var SchemaModelImpl = class {
440
739
  _baseTree;
441
740
  _currentTree;
442
- _patchBuilder = new chunkU7N3EEQX_cjs.PatchBuilder();
443
- _serializer = new chunkU7N3EEQX_cjs.SchemaSerializer();
741
+ _patchBuilder = new chunkX2KLCGJ6_cjs.PatchBuilder();
742
+ _serializer = new chunkX2KLCGJ6_cjs.SchemaSerializer();
444
743
  _nodeFactory = new NodeFactory();
445
- _formulaIndex = new chunkU7N3EEQX_cjs.FormulaDependencyIndex();
744
+ _formulaIndex = new FormulaDependencyIndex();
446
745
  _transformChain;
447
746
  _formulaParseErrors = [];
448
747
  _refSchemas;
@@ -454,12 +753,12 @@ var SchemaModelImpl = class {
454
753
  });
455
754
  const parser = new SchemaParser();
456
755
  const rootNode = parser.parse(schema, this._refSchemas);
457
- this._currentTree = chunkU7N3EEQX_cjs.createSchemaTree(rootNode);
756
+ this._currentTree = chunkX2KLCGJ6_cjs.createSchemaTree(rootNode);
458
757
  parser.parseFormulas(this._currentTree);
459
758
  this._formulaParseErrors = parser.parseErrors;
460
759
  this._buildFormulaIndex();
461
760
  this._baseTree = this._currentTree.clone();
462
- chunkU7N3EEQX_cjs.makeAutoObservable(this, {
761
+ chunkX2KLCGJ6_cjs.makeAutoObservable(this, {
463
762
  _patchBuilder: false,
464
763
  _serializer: false,
465
764
  _nodeFactory: false,
@@ -488,10 +787,10 @@ var SchemaModelImpl = class {
488
787
  insertFieldAt(parentId, index, name, type) {
489
788
  const parent = this._currentTree.nodeById(parentId);
490
789
  if (parent.isNull() || !parent.isObject()) {
491
- return chunkU7N3EEQX_cjs.NULL_NODE;
790
+ return chunkX2KLCGJ6_cjs.NULL_NODE;
492
791
  }
493
792
  if (index < 0 || index > parent.properties().length) {
494
- return chunkU7N3EEQX_cjs.NULL_NODE;
793
+ return chunkX2KLCGJ6_cjs.NULL_NODE;
495
794
  }
496
795
  const node = this._nodeFactory.createNode(name, type);
497
796
  this._currentTree.insertChildAt(parentId, index, node);
@@ -547,7 +846,7 @@ var SchemaModelImpl = class {
547
846
  this._formulaIndex.unregisterFormula(nodeId);
548
847
  } else {
549
848
  try {
550
- const formula = new chunkU7N3EEQX_cjs.ParsedFormula(this._currentTree, nodeId, expression);
849
+ const formula = new ParsedFormula(this._currentTree, nodeId, expression);
551
850
  node.setFormula(formula);
552
851
  this._formulaIndex.registerFormula(nodeId, formula);
553
852
  } catch (error) {
@@ -715,18 +1014,22 @@ var SchemaModelImpl = class {
715
1014
  if (!formula) {
716
1015
  return "";
717
1016
  }
718
- return chunkU7N3EEQX_cjs.FormulaSerializer.serializeExpression(
719
- this._currentTree,
720
- nodeId,
721
- formula,
722
- { strict: false }
723
- );
1017
+ try {
1018
+ return chunkX2KLCGJ6_cjs.FormulaSerializer.serializeExpression(
1019
+ this._currentTree,
1020
+ nodeId,
1021
+ formula,
1022
+ { strict: false }
1023
+ );
1024
+ } catch {
1025
+ return "";
1026
+ }
724
1027
  }
725
1028
  get validationErrors() {
726
- return chunkU7N3EEQX_cjs.validateSchema(this._currentTree.root());
1029
+ return chunkX2KLCGJ6_cjs.validateSchema(this._currentTree.root());
727
1030
  }
728
1031
  get formulaErrors() {
729
- return [...this._formulaParseErrors, ...chunkU7N3EEQX_cjs.validateFormulas(this._currentTree)];
1032
+ return [...this._formulaParseErrors, ...chunkX2KLCGJ6_cjs.validateFormulas(this._currentTree)];
730
1033
  }
731
1034
  get isDirty() {
732
1035
  return this.patches.length > 0;
@@ -782,7 +1085,7 @@ var RowModelImpl = class {
782
1085
  constructor(_rowId, _tree) {
783
1086
  this._rowId = _rowId;
784
1087
  this._tree = _tree;
785
- chunkU7N3EEQX_cjs.makeAutoObservable(this, {
1088
+ chunkX2KLCGJ6_cjs.makeAutoObservable(this, {
786
1089
  _rowId: false,
787
1090
  _tree: false,
788
1091
  _tableModel: "observable.ref"
@@ -934,7 +1237,7 @@ var ArrayValueNode = class extends BaseValueNode {
934
1237
  _nodeFactory = null;
935
1238
  constructor(id, name, schema, items) {
936
1239
  super(id, name, schema);
937
- this._items = chunkU7N3EEQX_cjs.observable.array();
1240
+ this._items = chunkX2KLCGJ6_cjs.observable.array();
938
1241
  this._baseItems = [];
939
1242
  if (items) {
940
1243
  for (const item of items) {
@@ -943,7 +1246,7 @@ var ArrayValueNode = class extends BaseValueNode {
943
1246
  }
944
1247
  }
945
1248
  this._baseItems = [...this._items];
946
- chunkU7N3EEQX_cjs.makeObservable(this, {
1249
+ chunkX2KLCGJ6_cjs.makeObservable(this, {
947
1250
  _items: "observable",
948
1251
  _baseItems: "observable",
949
1252
  value: "computed",
@@ -1098,7 +1401,7 @@ var ArrayValueNode = class extends BaseValueNode {
1098
1401
  for (const item of this._items) {
1099
1402
  item.parent = null;
1100
1403
  }
1101
- this._items = chunkU7N3EEQX_cjs.observable.array();
1404
+ this._items = chunkX2KLCGJ6_cjs.observable.array();
1102
1405
  for (const baseItem of this._baseItems) {
1103
1406
  this._items.push(baseItem);
1104
1407
  }
@@ -1141,7 +1444,7 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
1141
1444
  this._baseValue = initialValue;
1142
1445
  }
1143
1446
  initObservable() {
1144
- chunkU7N3EEQX_cjs.makeObservable(this, {
1447
+ chunkX2KLCGJ6_cjs.makeObservable(this, {
1145
1448
  _value: "observable",
1146
1449
  _baseValue: "observable",
1147
1450
  _formulaWarning: "observable",
@@ -1489,7 +1792,7 @@ var ObjectValueNode = class extends BaseValueNode {
1489
1792
  _baseChildren;
1490
1793
  constructor(id, name, schema, children) {
1491
1794
  super(id, name, schema);
1492
- this._children = chunkU7N3EEQX_cjs.observable.map();
1795
+ this._children = chunkX2KLCGJ6_cjs.observable.map();
1493
1796
  this._baseChildren = /* @__PURE__ */ new Map();
1494
1797
  if (children) {
1495
1798
  for (const child of children) {
@@ -1498,7 +1801,7 @@ var ObjectValueNode = class extends BaseValueNode {
1498
1801
  }
1499
1802
  }
1500
1803
  this._baseChildren = new Map(this._children);
1501
- chunkU7N3EEQX_cjs.makeObservable(this, {
1804
+ chunkX2KLCGJ6_cjs.makeObservable(this, {
1502
1805
  _children: "observable",
1503
1806
  _baseChildren: "observable",
1504
1807
  value: "computed",
@@ -1574,7 +1877,7 @@ var ObjectValueNode = class extends BaseValueNode {
1574
1877
  for (const child of this._children.values()) {
1575
1878
  child.parent = null;
1576
1879
  }
1577
- this._children = chunkU7N3EEQX_cjs.observable.map();
1880
+ this._children = chunkX2KLCGJ6_cjs.observable.map();
1578
1881
  for (const [key, value] of this._baseChildren) {
1579
1882
  this._children.set(key, value);
1580
1883
  }
@@ -1788,7 +2091,7 @@ var IndexSegment = class {
1788
2091
  };
1789
2092
 
1790
2093
  // src/core/value-path/ValuePath.ts
1791
- var ValuePathImpl = class _ValuePathImpl extends chunkU7N3EEQX_cjs.AbstractBasePath {
2094
+ var ValuePathImpl = class _ValuePathImpl extends chunkX2KLCGJ6_cjs.AbstractBasePath {
1792
2095
  asString() {
1793
2096
  const parts = [];
1794
2097
  for (const seg of this.segs) {
@@ -1876,7 +2179,7 @@ function parseValuePath(path) {
1876
2179
  var ValueTree = class {
1877
2180
  constructor(_root) {
1878
2181
  this._root = _root;
1879
- chunkU7N3EEQX_cjs.makeAutoObservable(this, {
2182
+ chunkX2KLCGJ6_cjs.makeAutoObservable(this, {
1880
2183
  _root: false
1881
2184
  });
1882
2185
  }
@@ -1966,13 +2269,13 @@ var TableModelImpl = class {
1966
2269
  this._schema = createSchemaModel(options.schema, { refSchemas: options.refSchemas });
1967
2270
  this._fkResolver = options.fkResolver;
1968
2271
  this._refSchemas = options.refSchemas;
1969
- this._rows = chunkU7N3EEQX_cjs.observable.array();
2272
+ this._rows = chunkX2KLCGJ6_cjs.observable.array();
1970
2273
  if (options.rows) {
1971
2274
  for (const row of options.rows) {
1972
2275
  this._rows.push(this.createRowModel(row.rowId, row.data));
1973
2276
  }
1974
2277
  }
1975
- chunkU7N3EEQX_cjs.makeAutoObservable(this, {
2278
+ chunkX2KLCGJ6_cjs.makeAutoObservable(this, {
1976
2279
  _schema: false,
1977
2280
  _rows: false,
1978
2281
  _jsonSchema: false,
@@ -2093,13 +2396,13 @@ var ForeignKeyResolverImpl = class {
2093
2396
  constructor(options) {
2094
2397
  this.loader = options?.loader;
2095
2398
  this._prefetchEnabled = options?.prefetch ?? false;
2096
- this._schemaCache = chunkU7N3EEQX_cjs.observable.map();
2097
- this._tableCache = chunkU7N3EEQX_cjs.observable.map();
2399
+ this._schemaCache = chunkX2KLCGJ6_cjs.observable.map();
2400
+ this._tableCache = chunkX2KLCGJ6_cjs.observable.map();
2098
2401
  this._loadingTables = /* @__PURE__ */ new Set();
2099
2402
  this._loadingRows = /* @__PURE__ */ new Map();
2100
2403
  this._pendingTableLoads = /* @__PURE__ */ new Map();
2101
2404
  this._pendingRowLoads = /* @__PURE__ */ new Map();
2102
- chunkU7N3EEQX_cjs.makeAutoObservable(this, {
2405
+ chunkX2KLCGJ6_cjs.makeAutoObservable(this, {
2103
2406
  _schemaCache: false,
2104
2407
  _tableCache: false,
2105
2408
  _loadingTables: false,
@@ -2137,7 +2440,7 @@ var ForeignKeyResolverImpl = class {
2137
2440
  if (this._disposed) {
2138
2441
  return;
2139
2442
  }
2140
- chunkU7N3EEQX_cjs.runInAction(() => {
2443
+ chunkX2KLCGJ6_cjs.runInAction(() => {
2141
2444
  this._schemaCache.set(tableId, schema);
2142
2445
  });
2143
2446
  }
@@ -2145,12 +2448,12 @@ var ForeignKeyResolverImpl = class {
2145
2448
  if (this._disposed) {
2146
2449
  return;
2147
2450
  }
2148
- const rowMap = chunkU7N3EEQX_cjs.observable.map();
2451
+ const rowMap = chunkX2KLCGJ6_cjs.observable.map();
2149
2452
  for (const row of rows) {
2150
2453
  rowMap.set(row.rowId, row);
2151
2454
  }
2152
2455
  const cache = { schema, rows: rowMap };
2153
- chunkU7N3EEQX_cjs.runInAction(() => {
2456
+ chunkX2KLCGJ6_cjs.runInAction(() => {
2154
2457
  this._tableCache.set(tableId, cache);
2155
2458
  this._schemaCache.set(tableId, schema);
2156
2459
  });
@@ -2165,7 +2468,7 @@ var ForeignKeyResolverImpl = class {
2165
2468
  const table = this._tableCache.get(tableId);
2166
2469
  if (table) {
2167
2470
  const rowData = { rowId, data };
2168
- chunkU7N3EEQX_cjs.runInAction(() => {
2471
+ chunkX2KLCGJ6_cjs.runInAction(() => {
2169
2472
  table.rows.set(rowId, rowData);
2170
2473
  });
2171
2474
  if (this._prefetchEnabled) {
@@ -2179,7 +2482,7 @@ var ForeignKeyResolverImpl = class {
2179
2482
  }
2180
2483
  const schema = this._schemaCache.get(oldTableId);
2181
2484
  const tableCache = this._tableCache.get(oldTableId);
2182
- chunkU7N3EEQX_cjs.runInAction(() => {
2485
+ chunkX2KLCGJ6_cjs.runInAction(() => {
2183
2486
  if (schema) {
2184
2487
  this._schemaCache.delete(oldTableId);
2185
2488
  this._schemaCache.set(newTableId, schema);
@@ -2281,9 +2584,9 @@ var ForeignKeyResolverImpl = class {
2281
2584
  }
2282
2585
  ensureTableCache(tableId, schema) {
2283
2586
  if (!this._tableCache.has(tableId)) {
2284
- const rowMap = chunkU7N3EEQX_cjs.observable.map();
2587
+ const rowMap = chunkX2KLCGJ6_cjs.observable.map();
2285
2588
  const cache = { schema, rows: rowMap };
2286
- chunkU7N3EEQX_cjs.runInAction(() => {
2589
+ chunkX2KLCGJ6_cjs.runInAction(() => {
2287
2590
  this._tableCache.set(tableId, cache);
2288
2591
  });
2289
2592
  }
@@ -2383,7 +2686,7 @@ var DataModelImpl = class {
2383
2686
  _fk;
2384
2687
  _ownsFkResolver;
2385
2688
  constructor(options) {
2386
- this._tables = chunkU7N3EEQX_cjs.observable.map();
2689
+ this._tables = chunkX2KLCGJ6_cjs.observable.map();
2387
2690
  if (options?.fkResolver) {
2388
2691
  this._fk = options.fkResolver;
2389
2692
  this._ownsFkResolver = false;
@@ -2391,7 +2694,7 @@ var DataModelImpl = class {
2391
2694
  this._fk = createForeignKeyResolver();
2392
2695
  this._ownsFkResolver = true;
2393
2696
  }
2394
- chunkU7N3EEQX_cjs.makeAutoObservable(this, {
2697
+ chunkX2KLCGJ6_cjs.makeAutoObservable(this, {
2395
2698
  _tables: false,
2396
2699
  _fk: false,
2397
2700
  _ownsFkResolver: false
@@ -2482,12 +2785,16 @@ exports.ForeignKeyNotFoundError = ForeignKeyNotFoundError;
2482
2785
  exports.ForeignKeyResolverImpl = ForeignKeyResolverImpl;
2483
2786
  exports.ForeignKeyResolverNotConfiguredError = ForeignKeyResolverNotConfiguredError;
2484
2787
  exports.ForeignKeyValueNodeImpl = ForeignKeyValueNodeImpl;
2788
+ exports.FormulaChangeDetector = FormulaChangeDetector;
2789
+ exports.FormulaDependencyIndex = FormulaDependencyIndex;
2790
+ exports.FormulaPath = FormulaPath;
2485
2791
  exports.NodeFactory = NodeFactory;
2486
2792
  exports.NodeFactory2 = NodeFactory2;
2487
2793
  exports.NodeFactoryRegistry = NodeFactoryRegistry;
2488
2794
  exports.NumberValueNode = NumberValueNode;
2489
2795
  exports.ObjectToArrayTransformer = ObjectToArrayTransformer;
2490
2796
  exports.ObjectValueNode = ObjectValueNode;
2797
+ exports.ParsedFormula = ParsedFormula;
2491
2798
  exports.PrimitiveToArrayTransformer = PrimitiveToArrayTransformer;
2492
2799
  exports.RefTransformer = RefTransformer;
2493
2800
  exports.RowModelImpl = RowModelImpl;
@@ -2508,5 +2815,5 @@ exports.generateDefaultValue = generateDefaultValue;
2508
2815
  exports.generateNodeId = generateNodeId;
2509
2816
  exports.isForeignKeyValueNode = isForeignKeyValueNode;
2510
2817
  exports.resetNodeIdCounter = resetNodeIdCounter;
2511
- //# sourceMappingURL=chunk-MKDGOOBV.cjs.map
2512
- //# sourceMappingURL=chunk-MKDGOOBV.cjs.map
2818
+ //# sourceMappingURL=chunk-CN74KAMA.cjs.map
2819
+ //# sourceMappingURL=chunk-CN74KAMA.cjs.map