@revisium/schema-toolkit 0.19.0 → 0.19.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 (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-OZ4ZCJXY.js → chunk-3V7AYFDS.js} +331 -25
  6. package/dist/chunk-3V7AYFDS.js.map +1 -0
  7. package/dist/{chunk-WJXVLFZN.cjs → chunk-HDZCCAWA.cjs} +125 -323
  8. package/dist/chunk-HDZCCAWA.cjs.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-HLHODANT.cjs → chunk-OMSE2HGD.cjs} +383 -73
  12. package/dist/chunk-OMSE2HGD.cjs.map +1 -0
  13. package/dist/{chunk-EPFW6FVB.js → chunk-XL4R6PSM.js} +123 -318
  14. package/dist/chunk-XL4R6PSM.js.map +1 -0
  15. package/dist/core/index.cjs +70 -58
  16. package/dist/core/index.d.cts +8 -2
  17. package/dist/core/index.d.ts +8 -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-EPFW6FVB.js.map +0 -1
  29. package/dist/chunk-HLHODANT.cjs.map +0 -1
  30. package/dist/chunk-MLNKM67U.cjs +0 -4
  31. package/dist/chunk-OZ4ZCJXY.js.map +0 -1
  32. package/dist/chunk-WJXVLFZN.cjs.map +0 -1
  33. package/dist/chunk-Y2GYABV7.js +0 -3
@@ -1,9 +1,308 @@
1
1
  'use strict';
2
2
 
3
- var chunkWJXVLFZN_cjs = require('./chunk-WJXVLFZN.cjs');
3
+ var chunkHDZCCAWA_cjs = require('./chunk-HDZCCAWA.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 chunkHDZCCAWA_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 = chunkHDZCCAWA_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 chunkHDZCCAWA_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 chunkHDZCCAWA_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 chunkHDZCCAWA_cjs.FormulaError(
128
+ "Formula cannot reference itself",
129
+ formulaNodeId,
130
+ "Self-reference detected"
131
+ );
132
+ }
133
+ deps.push(new chunkHDZCCAWA_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 = chunkHDZCCAWA_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 chunkWJXVLFZN_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 chunkWJXVLFZN_cjs.createRefNode(nanoid.nanoid(), name, refValue, this.extractMetadata(schema));
344
+ return chunkHDZCCAWA_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 chunkWJXVLFZN_cjs.createObjectNode(nanoid.nanoid(), name, children, {
370
+ return chunkHDZCCAWA_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 chunkWJXVLFZN_cjs.createArrayNode(nanoid.nanoid(), name, items, {
377
+ return chunkHDZCCAWA_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 chunkWJXVLFZN_cjs.createStringNode(nodeId, name, {
385
+ return chunkHDZCCAWA_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 chunkWJXVLFZN_cjs.createNumberNode(nodeId, name, {
395
+ return chunkHDZCCAWA_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 chunkWJXVLFZN_cjs.createBooleanNode(nodeId, name, {
404
+ return chunkHDZCCAWA_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 chunkWJXVLFZN_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
437
+ return chunkHDZCCAWA_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
139
438
  case "number":
140
- return chunkWJXVLFZN_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
439
+ return chunkHDZCCAWA_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
141
440
  case "boolean":
142
- return chunkWJXVLFZN_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
441
+ return chunkHDZCCAWA_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
143
442
  case "object":
144
- return chunkWJXVLFZN_cjs.createObjectNode(nanoid.nanoid(), name, []);
443
+ return chunkHDZCCAWA_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 = chunkWJXVLFZN_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
153
- return chunkWJXVLFZN_cjs.createArrayNode(nanoid.nanoid(), name, items);
451
+ const items = chunkHDZCCAWA_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
452
+ return chunkHDZCCAWA_cjs.createArrayNode(nanoid.nanoid(), name, items);
154
453
  }
155
454
  createArrayNodeWithItems(name, items) {
156
- return chunkWJXVLFZN_cjs.createArrayNode(nanoid.nanoid(), name, items);
455
+ return chunkHDZCCAWA_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 = chunkWJXVLFZN_cjs.createArrayNode(nanoid.nanoid(), sourceNode.name(), itemsNode);
554
+ const arrayNode = chunkHDZCCAWA_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
256
555
  return { node: arrayNode };
257
556
  }
258
557
  };
@@ -265,10 +564,12 @@ var ObjectToArrayTransformer = class {
265
564
  const { sourceNode } = ctx;
266
565
  const itemsNode = sourceNode.cloneWithId(nanoid.nanoid());
267
566
  itemsNode.setName("items");
268
- const arrayNode = chunkWJXVLFZN_cjs.createArrayNode(nanoid.nanoid(), sourceNode.name(), itemsNode);
567
+ const arrayNode = chunkHDZCCAWA_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
269
568
  return { node: arrayNode };
270
569
  }
271
570
  };
571
+
572
+ // src/model/type-transformer/transformers/ArrayToItemsTypeTransformer.ts
272
573
  var ArrayToItemsTypeTransformer = class {
273
574
  canTransform(ctx) {
274
575
  const { sourceNode, targetSpec } = ctx;
@@ -285,7 +586,7 @@ var ArrayToItemsTypeTransformer = class {
285
586
  transform(ctx) {
286
587
  const { sourceNode } = ctx;
287
588
  const items = sourceNode.items();
288
- const newNode = items.cloneWithId(nanoid.nanoid());
589
+ const newNode = items.cloneWithId(sourceNode.id());
289
590
  newNode.setName(sourceNode.name());
290
591
  return { node: newNode };
291
592
  }
@@ -293,6 +594,8 @@ var ArrayToItemsTypeTransformer = class {
293
594
  return type === "string" || type === "number" || type === "boolean";
294
595
  }
295
596
  };
597
+
598
+ // src/model/type-transformer/transformers/RefTransformer.ts
296
599
  var RefTransformer = class {
297
600
  canTransform(ctx) {
298
601
  return ctx.targetSpec.$ref !== void 0;
@@ -306,12 +609,12 @@ var RefTransformer = class {
306
609
  const wrapperSchema = chunkVGADCIBG_cjs.obj({ temp: chunkVGADCIBG_cjs.ref(refUri) });
307
610
  const resolvedNode = parser.parse(wrapperSchema, refSchemas);
308
611
  const tempNode = resolvedNode.property("temp");
309
- const newNode = tempNode.cloneWithId(nanoid.nanoid());
612
+ const newNode = tempNode.cloneWithId(sourceNode.id());
310
613
  newNode.setName(sourceNode.name());
311
614
  return { node: newNode };
312
615
  }
313
616
  const metadata = this.extractMetadata(targetSpec);
314
- const node = chunkWJXVLFZN_cjs.createRefNode(nanoid.nanoid(), sourceNode.name(), refUri, metadata);
617
+ const node = chunkHDZCCAWA_cjs.createRefNode(sourceNode.id(), sourceNode.name(), refUri, metadata);
315
618
  return { node };
316
619
  }
317
620
  extractMetadata(spec) {
@@ -340,38 +643,38 @@ var DefaultTransformer = class {
340
643
  const { sourceNode, targetSpec } = ctx;
341
644
  const type = targetSpec.type;
342
645
  const metadata = this.extractMetadata(targetSpec);
343
- const node = this.createNode(sourceNode.name(), type, targetSpec, metadata);
646
+ const node = this.createNode(sourceNode.id(), sourceNode.name(), type, targetSpec, metadata);
344
647
  return { node };
345
648
  }
346
- createNode(name, type, spec, metadata) {
649
+ createNode(id, name, type, spec, metadata) {
347
650
  switch (type) {
348
651
  case "string":
349
- return chunkWJXVLFZN_cjs.createStringNode(nanoid.nanoid(), name, {
652
+ return chunkHDZCCAWA_cjs.createStringNode(id, name, {
350
653
  defaultValue: spec.default ?? "",
351
654
  foreignKey: spec.foreignKey,
352
655
  metadata
353
656
  });
354
657
  case "number":
355
- return chunkWJXVLFZN_cjs.createNumberNode(nanoid.nanoid(), name, {
658
+ return chunkHDZCCAWA_cjs.createNumberNode(id, name, {
356
659
  defaultValue: spec.default ?? 0,
357
660
  metadata
358
661
  });
359
662
  case "boolean":
360
- return chunkWJXVLFZN_cjs.createBooleanNode(nanoid.nanoid(), name, {
663
+ return chunkHDZCCAWA_cjs.createBooleanNode(id, name, {
361
664
  defaultValue: spec.default ?? false,
362
665
  metadata
363
666
  });
364
667
  case "object":
365
- return chunkWJXVLFZN_cjs.createObjectNode(nanoid.nanoid(), name, [], { metadata });
668
+ return chunkHDZCCAWA_cjs.createObjectNode(id, name, [], { metadata });
366
669
  case "array":
367
- return this.createArrayNode(name, metadata);
670
+ return this.createArrayNode(id, name, metadata);
368
671
  default:
369
672
  throw new Error(`Unknown field type: ${type}`);
370
673
  }
371
674
  }
372
- createArrayNode(name, metadata) {
373
- const items = chunkWJXVLFZN_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
374
- return chunkWJXVLFZN_cjs.createArrayNode(nanoid.nanoid(), name, items, { metadata });
675
+ createArrayNode(id, name, metadata) {
676
+ const items = chunkHDZCCAWA_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
677
+ return chunkHDZCCAWA_cjs.createArrayNode(id, name, items, { metadata });
375
678
  }
376
679
  extractMetadata(spec) {
377
680
  const meta = {};
@@ -435,10 +738,10 @@ function createTypeTransformChain(options) {
435
738
  var SchemaModelImpl = class {
436
739
  _baseTree;
437
740
  _currentTree;
438
- _patchBuilder = new chunkWJXVLFZN_cjs.PatchBuilder();
439
- _serializer = new chunkWJXVLFZN_cjs.SchemaSerializer();
741
+ _patchBuilder = new chunkHDZCCAWA_cjs.PatchBuilder();
742
+ _serializer = new chunkHDZCCAWA_cjs.SchemaSerializer();
440
743
  _nodeFactory = new NodeFactory();
441
- _formulaIndex = new chunkWJXVLFZN_cjs.FormulaDependencyIndex();
744
+ _formulaIndex = new FormulaDependencyIndex();
442
745
  _transformChain;
443
746
  _formulaParseErrors = [];
444
747
  _refSchemas;
@@ -450,12 +753,12 @@ var SchemaModelImpl = class {
450
753
  });
451
754
  const parser = new SchemaParser();
452
755
  const rootNode = parser.parse(schema, this._refSchemas);
453
- this._currentTree = chunkWJXVLFZN_cjs.createSchemaTree(rootNode);
756
+ this._currentTree = chunkHDZCCAWA_cjs.createSchemaTree(rootNode);
454
757
  parser.parseFormulas(this._currentTree);
455
758
  this._formulaParseErrors = parser.parseErrors;
456
759
  this._buildFormulaIndex();
457
760
  this._baseTree = this._currentTree.clone();
458
- chunkWJXVLFZN_cjs.makeAutoObservable(this, {
761
+ chunkHDZCCAWA_cjs.makeAutoObservable(this, {
459
762
  _patchBuilder: false,
460
763
  _serializer: false,
461
764
  _nodeFactory: false,
@@ -484,10 +787,10 @@ var SchemaModelImpl = class {
484
787
  insertFieldAt(parentId, index, name, type) {
485
788
  const parent = this._currentTree.nodeById(parentId);
486
789
  if (parent.isNull() || !parent.isObject()) {
487
- return chunkWJXVLFZN_cjs.NULL_NODE;
790
+ return chunkHDZCCAWA_cjs.NULL_NODE;
488
791
  }
489
792
  if (index < 0 || index > parent.properties().length) {
490
- return chunkWJXVLFZN_cjs.NULL_NODE;
793
+ return chunkHDZCCAWA_cjs.NULL_NODE;
491
794
  }
492
795
  const node = this._nodeFactory.createNode(name, type);
493
796
  this._currentTree.insertChildAt(parentId, index, node);
@@ -518,7 +821,6 @@ var SchemaModelImpl = class {
518
821
  }
519
822
  const result = this._transformChain.transform(node, newType);
520
823
  this._currentTree.setNodeAt(path, result.node);
521
- this._currentTree.trackReplacement(nodeId, result.node.id());
522
824
  return result.node;
523
825
  }
524
826
  updateMetadata(nodeId, meta) {
@@ -544,7 +846,7 @@ var SchemaModelImpl = class {
544
846
  this._formulaIndex.unregisterFormula(nodeId);
545
847
  } else {
546
848
  try {
547
- const formula = new chunkWJXVLFZN_cjs.ParsedFormula(this._currentTree, nodeId, expression);
849
+ const formula = new ParsedFormula(this._currentTree, nodeId, expression);
548
850
  node.setFormula(formula);
549
851
  this._formulaIndex.registerFormula(nodeId, formula);
550
852
  } catch (error) {
@@ -712,18 +1014,22 @@ var SchemaModelImpl = class {
712
1014
  if (!formula) {
713
1015
  return "";
714
1016
  }
715
- return chunkWJXVLFZN_cjs.FormulaSerializer.serializeExpression(
716
- this._currentTree,
717
- nodeId,
718
- formula,
719
- { strict: false }
720
- );
1017
+ try {
1018
+ return chunkHDZCCAWA_cjs.FormulaSerializer.serializeExpression(
1019
+ this._currentTree,
1020
+ nodeId,
1021
+ formula,
1022
+ { strict: false }
1023
+ );
1024
+ } catch {
1025
+ return "";
1026
+ }
721
1027
  }
722
1028
  get validationErrors() {
723
- return chunkWJXVLFZN_cjs.validateSchema(this._currentTree.root());
1029
+ return chunkHDZCCAWA_cjs.validateSchema(this._currentTree.root());
724
1030
  }
725
1031
  get formulaErrors() {
726
- return [...this._formulaParseErrors, ...chunkWJXVLFZN_cjs.validateFormulas(this._currentTree)];
1032
+ return [...this._formulaParseErrors, ...chunkHDZCCAWA_cjs.validateFormulas(this._currentTree)];
727
1033
  }
728
1034
  get isDirty() {
729
1035
  return this.patches.length > 0;
@@ -779,7 +1085,7 @@ var RowModelImpl = class {
779
1085
  constructor(_rowId, _tree) {
780
1086
  this._rowId = _rowId;
781
1087
  this._tree = _tree;
782
- chunkWJXVLFZN_cjs.makeAutoObservable(this, {
1088
+ chunkHDZCCAWA_cjs.makeAutoObservable(this, {
783
1089
  _rowId: false,
784
1090
  _tree: false,
785
1091
  _tableModel: "observable.ref"
@@ -931,7 +1237,7 @@ var ArrayValueNode = class extends BaseValueNode {
931
1237
  _nodeFactory = null;
932
1238
  constructor(id, name, schema, items) {
933
1239
  super(id, name, schema);
934
- this._items = chunkWJXVLFZN_cjs.observable.array();
1240
+ this._items = chunkHDZCCAWA_cjs.observable.array();
935
1241
  this._baseItems = [];
936
1242
  if (items) {
937
1243
  for (const item of items) {
@@ -940,7 +1246,7 @@ var ArrayValueNode = class extends BaseValueNode {
940
1246
  }
941
1247
  }
942
1248
  this._baseItems = [...this._items];
943
- chunkWJXVLFZN_cjs.makeObservable(this, {
1249
+ chunkHDZCCAWA_cjs.makeObservable(this, {
944
1250
  _items: "observable",
945
1251
  _baseItems: "observable",
946
1252
  value: "computed",
@@ -1095,7 +1401,7 @@ var ArrayValueNode = class extends BaseValueNode {
1095
1401
  for (const item of this._items) {
1096
1402
  item.parent = null;
1097
1403
  }
1098
- this._items = chunkWJXVLFZN_cjs.observable.array();
1404
+ this._items = chunkHDZCCAWA_cjs.observable.array();
1099
1405
  for (const baseItem of this._baseItems) {
1100
1406
  this._items.push(baseItem);
1101
1407
  }
@@ -1138,7 +1444,7 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
1138
1444
  this._baseValue = initialValue;
1139
1445
  }
1140
1446
  initObservable() {
1141
- chunkWJXVLFZN_cjs.makeObservable(this, {
1447
+ chunkHDZCCAWA_cjs.makeObservable(this, {
1142
1448
  _value: "observable",
1143
1449
  _baseValue: "observable",
1144
1450
  _formulaWarning: "observable",
@@ -1486,7 +1792,7 @@ var ObjectValueNode = class extends BaseValueNode {
1486
1792
  _baseChildren;
1487
1793
  constructor(id, name, schema, children) {
1488
1794
  super(id, name, schema);
1489
- this._children = chunkWJXVLFZN_cjs.observable.map();
1795
+ this._children = chunkHDZCCAWA_cjs.observable.map();
1490
1796
  this._baseChildren = /* @__PURE__ */ new Map();
1491
1797
  if (children) {
1492
1798
  for (const child of children) {
@@ -1495,7 +1801,7 @@ var ObjectValueNode = class extends BaseValueNode {
1495
1801
  }
1496
1802
  }
1497
1803
  this._baseChildren = new Map(this._children);
1498
- chunkWJXVLFZN_cjs.makeObservable(this, {
1804
+ chunkHDZCCAWA_cjs.makeObservable(this, {
1499
1805
  _children: "observable",
1500
1806
  _baseChildren: "observable",
1501
1807
  value: "computed",
@@ -1571,7 +1877,7 @@ var ObjectValueNode = class extends BaseValueNode {
1571
1877
  for (const child of this._children.values()) {
1572
1878
  child.parent = null;
1573
1879
  }
1574
- this._children = chunkWJXVLFZN_cjs.observable.map();
1880
+ this._children = chunkHDZCCAWA_cjs.observable.map();
1575
1881
  for (const [key, value] of this._baseChildren) {
1576
1882
  this._children.set(key, value);
1577
1883
  }
@@ -1785,7 +2091,7 @@ var IndexSegment = class {
1785
2091
  };
1786
2092
 
1787
2093
  // src/core/value-path/ValuePath.ts
1788
- var ValuePathImpl = class _ValuePathImpl extends chunkWJXVLFZN_cjs.AbstractBasePath {
2094
+ var ValuePathImpl = class _ValuePathImpl extends chunkHDZCCAWA_cjs.AbstractBasePath {
1789
2095
  asString() {
1790
2096
  const parts = [];
1791
2097
  for (const seg of this.segs) {
@@ -1873,7 +2179,7 @@ function parseValuePath(path) {
1873
2179
  var ValueTree = class {
1874
2180
  constructor(_root) {
1875
2181
  this._root = _root;
1876
- chunkWJXVLFZN_cjs.makeAutoObservable(this, {
2182
+ chunkHDZCCAWA_cjs.makeAutoObservable(this, {
1877
2183
  _root: false
1878
2184
  });
1879
2185
  }
@@ -1963,13 +2269,13 @@ var TableModelImpl = class {
1963
2269
  this._schema = createSchemaModel(options.schema, { refSchemas: options.refSchemas });
1964
2270
  this._fkResolver = options.fkResolver;
1965
2271
  this._refSchemas = options.refSchemas;
1966
- this._rows = chunkWJXVLFZN_cjs.observable.array();
2272
+ this._rows = chunkHDZCCAWA_cjs.observable.array();
1967
2273
  if (options.rows) {
1968
2274
  for (const row of options.rows) {
1969
2275
  this._rows.push(this.createRowModel(row.rowId, row.data));
1970
2276
  }
1971
2277
  }
1972
- chunkWJXVLFZN_cjs.makeAutoObservable(this, {
2278
+ chunkHDZCCAWA_cjs.makeAutoObservable(this, {
1973
2279
  _schema: false,
1974
2280
  _rows: false,
1975
2281
  _jsonSchema: false,
@@ -2090,13 +2396,13 @@ var ForeignKeyResolverImpl = class {
2090
2396
  constructor(options) {
2091
2397
  this.loader = options?.loader;
2092
2398
  this._prefetchEnabled = options?.prefetch ?? false;
2093
- this._schemaCache = chunkWJXVLFZN_cjs.observable.map();
2094
- this._tableCache = chunkWJXVLFZN_cjs.observable.map();
2399
+ this._schemaCache = chunkHDZCCAWA_cjs.observable.map();
2400
+ this._tableCache = chunkHDZCCAWA_cjs.observable.map();
2095
2401
  this._loadingTables = /* @__PURE__ */ new Set();
2096
2402
  this._loadingRows = /* @__PURE__ */ new Map();
2097
2403
  this._pendingTableLoads = /* @__PURE__ */ new Map();
2098
2404
  this._pendingRowLoads = /* @__PURE__ */ new Map();
2099
- chunkWJXVLFZN_cjs.makeAutoObservable(this, {
2405
+ chunkHDZCCAWA_cjs.makeAutoObservable(this, {
2100
2406
  _schemaCache: false,
2101
2407
  _tableCache: false,
2102
2408
  _loadingTables: false,
@@ -2134,7 +2440,7 @@ var ForeignKeyResolverImpl = class {
2134
2440
  if (this._disposed) {
2135
2441
  return;
2136
2442
  }
2137
- chunkWJXVLFZN_cjs.runInAction(() => {
2443
+ chunkHDZCCAWA_cjs.runInAction(() => {
2138
2444
  this._schemaCache.set(tableId, schema);
2139
2445
  });
2140
2446
  }
@@ -2142,12 +2448,12 @@ var ForeignKeyResolverImpl = class {
2142
2448
  if (this._disposed) {
2143
2449
  return;
2144
2450
  }
2145
- const rowMap = chunkWJXVLFZN_cjs.observable.map();
2451
+ const rowMap = chunkHDZCCAWA_cjs.observable.map();
2146
2452
  for (const row of rows) {
2147
2453
  rowMap.set(row.rowId, row);
2148
2454
  }
2149
2455
  const cache = { schema, rows: rowMap };
2150
- chunkWJXVLFZN_cjs.runInAction(() => {
2456
+ chunkHDZCCAWA_cjs.runInAction(() => {
2151
2457
  this._tableCache.set(tableId, cache);
2152
2458
  this._schemaCache.set(tableId, schema);
2153
2459
  });
@@ -2162,7 +2468,7 @@ var ForeignKeyResolverImpl = class {
2162
2468
  const table = this._tableCache.get(tableId);
2163
2469
  if (table) {
2164
2470
  const rowData = { rowId, data };
2165
- chunkWJXVLFZN_cjs.runInAction(() => {
2471
+ chunkHDZCCAWA_cjs.runInAction(() => {
2166
2472
  table.rows.set(rowId, rowData);
2167
2473
  });
2168
2474
  if (this._prefetchEnabled) {
@@ -2176,7 +2482,7 @@ var ForeignKeyResolverImpl = class {
2176
2482
  }
2177
2483
  const schema = this._schemaCache.get(oldTableId);
2178
2484
  const tableCache = this._tableCache.get(oldTableId);
2179
- chunkWJXVLFZN_cjs.runInAction(() => {
2485
+ chunkHDZCCAWA_cjs.runInAction(() => {
2180
2486
  if (schema) {
2181
2487
  this._schemaCache.delete(oldTableId);
2182
2488
  this._schemaCache.set(newTableId, schema);
@@ -2278,9 +2584,9 @@ var ForeignKeyResolverImpl = class {
2278
2584
  }
2279
2585
  ensureTableCache(tableId, schema) {
2280
2586
  if (!this._tableCache.has(tableId)) {
2281
- const rowMap = chunkWJXVLFZN_cjs.observable.map();
2587
+ const rowMap = chunkHDZCCAWA_cjs.observable.map();
2282
2588
  const cache = { schema, rows: rowMap };
2283
- chunkWJXVLFZN_cjs.runInAction(() => {
2589
+ chunkHDZCCAWA_cjs.runInAction(() => {
2284
2590
  this._tableCache.set(tableId, cache);
2285
2591
  });
2286
2592
  }
@@ -2380,7 +2686,7 @@ var DataModelImpl = class {
2380
2686
  _fk;
2381
2687
  _ownsFkResolver;
2382
2688
  constructor(options) {
2383
- this._tables = chunkWJXVLFZN_cjs.observable.map();
2689
+ this._tables = chunkHDZCCAWA_cjs.observable.map();
2384
2690
  if (options?.fkResolver) {
2385
2691
  this._fk = options.fkResolver;
2386
2692
  this._ownsFkResolver = false;
@@ -2388,7 +2694,7 @@ var DataModelImpl = class {
2388
2694
  this._fk = createForeignKeyResolver();
2389
2695
  this._ownsFkResolver = true;
2390
2696
  }
2391
- chunkWJXVLFZN_cjs.makeAutoObservable(this, {
2697
+ chunkHDZCCAWA_cjs.makeAutoObservable(this, {
2392
2698
  _tables: false,
2393
2699
  _fk: false,
2394
2700
  _ownsFkResolver: false
@@ -2479,12 +2785,16 @@ exports.ForeignKeyNotFoundError = ForeignKeyNotFoundError;
2479
2785
  exports.ForeignKeyResolverImpl = ForeignKeyResolverImpl;
2480
2786
  exports.ForeignKeyResolverNotConfiguredError = ForeignKeyResolverNotConfiguredError;
2481
2787
  exports.ForeignKeyValueNodeImpl = ForeignKeyValueNodeImpl;
2788
+ exports.FormulaChangeDetector = FormulaChangeDetector;
2789
+ exports.FormulaDependencyIndex = FormulaDependencyIndex;
2790
+ exports.FormulaPath = FormulaPath;
2482
2791
  exports.NodeFactory = NodeFactory;
2483
2792
  exports.NodeFactory2 = NodeFactory2;
2484
2793
  exports.NodeFactoryRegistry = NodeFactoryRegistry;
2485
2794
  exports.NumberValueNode = NumberValueNode;
2486
2795
  exports.ObjectToArrayTransformer = ObjectToArrayTransformer;
2487
2796
  exports.ObjectValueNode = ObjectValueNode;
2797
+ exports.ParsedFormula = ParsedFormula;
2488
2798
  exports.PrimitiveToArrayTransformer = PrimitiveToArrayTransformer;
2489
2799
  exports.RefTransformer = RefTransformer;
2490
2800
  exports.RowModelImpl = RowModelImpl;
@@ -2505,5 +2815,5 @@ exports.generateDefaultValue = generateDefaultValue;
2505
2815
  exports.generateNodeId = generateNodeId;
2506
2816
  exports.isForeignKeyValueNode = isForeignKeyValueNode;
2507
2817
  exports.resetNodeIdCounter = resetNodeIdCounter;
2508
- //# sourceMappingURL=chunk-HLHODANT.cjs.map
2509
- //# sourceMappingURL=chunk-HLHODANT.cjs.map
2818
+ //# sourceMappingURL=chunk-OMSE2HGD.cjs.map
2819
+ //# sourceMappingURL=chunk-OMSE2HGD.cjs.map