@revisium/schema-toolkit 0.20.2 → 0.21.1

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 (140) hide show
  1. package/README.md +216 -0
  2. package/dist/FormulaPathBuilder-BUJRR0Am.d.cts +48 -0
  3. package/dist/FormulaPathBuilder-QR0htn-e.d.ts +48 -0
  4. package/dist/{chunk-VGADCIBG.cjs → chunk-2PIMJSWJ.cjs} +12 -8
  5. package/dist/chunk-3MJP73IJ.js +1 -0
  6. package/dist/{chunk-LLHQWDAR.js → chunk-4U2RZHMX.js} +19 -21
  7. package/dist/{chunk-Q2UOTIMG.js → chunk-5DUMJHCA.js} +0 -2
  8. package/dist/{chunk-V6JTSET2.cjs → chunk-7JWCZZPJ.cjs} +49 -51
  9. package/dist/{chunk-YFWOURZL.js → chunk-7PEC6ZYY.js} +0 -2
  10. package/dist/chunk-AV5EZUMZ.cjs +2 -0
  11. package/dist/{chunk-3JZKQWQH.js → chunk-AWFMSOHM.js} +5 -7
  12. package/dist/{chunk-X2VRR7V7.cjs → chunk-ERW5XVED.cjs} +0 -2
  13. package/dist/{chunk-XNFSFT7T.cjs → chunk-EVD5ZI55.cjs} +0 -2
  14. package/dist/{chunk-ZRNFSUOV.cjs → chunk-FL6PWPVJ.cjs} +0 -2
  15. package/dist/{chunk-55AMH44G.js → chunk-FTBRJODD.js} +28 -30
  16. package/dist/{chunk-R3MS2N4A.js → chunk-GJM63Q4K.js} +0 -2
  17. package/dist/{chunk-U5YDA3LA.js → chunk-HFMZITNE.js} +238 -31
  18. package/dist/{chunk-EGC32GPY.cjs → chunk-ITYABUR5.cjs} +19 -21
  19. package/dist/{chunk-R4CFU33U.js → chunk-IZMBM36H.js} +10 -9
  20. package/dist/chunk-J4RVO37K.cjs +2 -0
  21. package/dist/{chunk-QEV4Q4TR.js → chunk-JLXX3SGF.js} +30 -32
  22. package/dist/{chunk-MPF6VCB5.js → chunk-NO655UI5.js} +0 -2
  23. package/dist/chunk-OAUVP6CU.js +1 -0
  24. package/dist/{chunk-B3T6YB2D.cjs → chunk-ONW2OVNQ.cjs} +28 -30
  25. package/dist/{chunk-32FZHFIO.cjs → chunk-QKA7DJDN.cjs} +0 -2
  26. package/dist/{chunk-46ME2TAU.cjs → chunk-RCCBUOGY.cjs} +5 -7
  27. package/dist/{chunk-IPL2CGVA.cjs → chunk-RQBW7ATZ.cjs} +0 -2
  28. package/dist/{chunk-FZ2MS4Q5.cjs → chunk-S5SRXND6.cjs} +307 -97
  29. package/dist/{chunk-WSPFHUHU.cjs → chunk-T3QQSHAC.cjs} +0 -2
  30. package/dist/{chunk-J6SCHJKG.cjs → chunk-VMELKZXD.cjs} +0 -2
  31. package/dist/{chunk-5VDDLW7U.js → chunk-WE4OLW5U.js} +0 -2
  32. package/dist/{chunk-JUOGJFTL.js → chunk-XKWWCXGB.js} +0 -2
  33. package/dist/{chunk-ZBPUTF3Q.js → chunk-ZPRBA4AQ.js} +0 -2
  34. package/dist/consts/index.cjs +4 -6
  35. package/dist/consts/index.js +2 -4
  36. package/dist/core/index.cjs +65 -69
  37. package/dist/core/index.d.cts +6 -4
  38. package/dist/core/index.d.ts +6 -4
  39. package/dist/core/index.js +4 -8
  40. package/dist/formula/index.cjs +7 -9
  41. package/dist/formula/index.d.cts +1 -1
  42. package/dist/formula/index.d.ts +1 -1
  43. package/dist/formula/index.js +1 -3
  44. package/dist/index.cjs +269 -248
  45. package/dist/index.d.cts +8 -7
  46. package/dist/index.d.ts +8 -7
  47. package/dist/index.js +15 -18
  48. package/dist/{json-patch.types-DY7k9hxy.d.ts → json-patch.types-BpVnp08Z.d.ts} +1 -1
  49. package/dist/{json-patch.types-Cu0Medki.d.cts → json-patch.types-eM6pYC2P.d.cts} +1 -1
  50. package/dist/{json-string.store-C58zbl31.d.ts → json-string.store-DfdLcgnM.d.ts} +11 -11
  51. package/dist/{json-string.store-DuI--IL2.d.cts → json-string.store-cAOADo23.d.cts} +11 -11
  52. package/dist/lib/index.cjs +51 -54
  53. package/dist/lib/index.d.cts +3 -3
  54. package/dist/lib/index.d.ts +3 -3
  55. package/dist/lib/index.js +7 -10
  56. package/dist/mocks/index.cjs +30 -21
  57. package/dist/mocks/index.d.cts +22 -8
  58. package/dist/mocks/index.d.ts +22 -8
  59. package/dist/mocks/index.js +2 -5
  60. package/dist/model/index.cjs +85 -78
  61. package/dist/model/index.d.cts +171 -346
  62. package/dist/model/index.d.ts +171 -346
  63. package/dist/model/index.js +4 -9
  64. package/dist/plugins/index.cjs +20 -23
  65. package/dist/plugins/index.d.cts +10 -10
  66. package/dist/plugins/index.d.ts +10 -10
  67. package/dist/plugins/index.js +2 -5
  68. package/dist/{schema.types-B5OgKLpV.d.cts → schema.types-On_VGw2m.d.cts} +7 -6
  69. package/dist/{schema.types-B5OgKLpV.d.ts → schema.types-On_VGw2m.d.ts} +7 -6
  70. package/dist/typed-BRZhUqGG.d.ts +502 -0
  71. package/dist/typed-Cri0IYAn.d.cts +502 -0
  72. package/dist/types/index.cjs +6 -9
  73. package/dist/types/index.d.cts +7 -5
  74. package/dist/types/index.d.ts +7 -5
  75. package/dist/types/index.js +2 -5
  76. package/dist/{FormulaPathBuilder-DwlKOvVB.d.ts → types-BIvIURgy.d.cts} +37 -82
  77. package/dist/{FormulaPathBuilder-D9LkBcSv.d.cts → types-C_pTFtSY.d.ts} +37 -82
  78. package/dist/validation-schemas/index.cjs +18 -20
  79. package/dist/validation-schemas/index.js +1 -3
  80. package/package.json +1 -1
  81. package/dist/chunk-32FZHFIO.cjs.map +0 -1
  82. package/dist/chunk-3FJZMVWA.js +0 -3
  83. package/dist/chunk-3FJZMVWA.js.map +0 -1
  84. package/dist/chunk-3IKI64T2.js +0 -3
  85. package/dist/chunk-3IKI64T2.js.map +0 -1
  86. package/dist/chunk-3JZKQWQH.js.map +0 -1
  87. package/dist/chunk-46ME2TAU.cjs.map +0 -1
  88. package/dist/chunk-55AMH44G.js.map +0 -1
  89. package/dist/chunk-5VDDLW7U.js.map +0 -1
  90. package/dist/chunk-B3T6YB2D.cjs.map +0 -1
  91. package/dist/chunk-EGC32GPY.cjs.map +0 -1
  92. package/dist/chunk-FZ2MS4Q5.cjs.map +0 -1
  93. package/dist/chunk-G6ZKEVVU.cjs +0 -4
  94. package/dist/chunk-G6ZKEVVU.cjs.map +0 -1
  95. package/dist/chunk-IPL2CGVA.cjs.map +0 -1
  96. package/dist/chunk-J6SCHJKG.cjs.map +0 -1
  97. package/dist/chunk-JUOGJFTL.js.map +0 -1
  98. package/dist/chunk-L6HE7QPU.cjs +0 -4
  99. package/dist/chunk-L6HE7QPU.cjs.map +0 -1
  100. package/dist/chunk-LLHQWDAR.js.map +0 -1
  101. package/dist/chunk-MPF6VCB5.js.map +0 -1
  102. package/dist/chunk-NY3H6C7K.js +0 -3
  103. package/dist/chunk-NY3H6C7K.js.map +0 -1
  104. package/dist/chunk-Q2UOTIMG.js.map +0 -1
  105. package/dist/chunk-QEV4Q4TR.js.map +0 -1
  106. package/dist/chunk-R3MS2N4A.js.map +0 -1
  107. package/dist/chunk-R4CFU33U.js.map +0 -1
  108. package/dist/chunk-TBFTADML.cjs +0 -4
  109. package/dist/chunk-TBFTADML.cjs.map +0 -1
  110. package/dist/chunk-U5YDA3LA.js.map +0 -1
  111. package/dist/chunk-V6JTSET2.cjs.map +0 -1
  112. package/dist/chunk-VGADCIBG.cjs.map +0 -1
  113. package/dist/chunk-WSPFHUHU.cjs.map +0 -1
  114. package/dist/chunk-X2VRR7V7.cjs.map +0 -1
  115. package/dist/chunk-XNFSFT7T.cjs.map +0 -1
  116. package/dist/chunk-YFWOURZL.js.map +0 -1
  117. package/dist/chunk-ZBPUTF3Q.js.map +0 -1
  118. package/dist/chunk-ZRNFSUOV.cjs.map +0 -1
  119. package/dist/consts/index.cjs.map +0 -1
  120. package/dist/consts/index.js.map +0 -1
  121. package/dist/core/index.cjs.map +0 -1
  122. package/dist/core/index.js.map +0 -1
  123. package/dist/formula/index.cjs.map +0 -1
  124. package/dist/formula/index.js.map +0 -1
  125. package/dist/index.cjs.map +0 -1
  126. package/dist/index.js.map +0 -1
  127. package/dist/json-value-patch.types-CgiEpchp.d.ts +0 -24
  128. package/dist/json-value-patch.types-LEJxcIWR.d.cts +0 -24
  129. package/dist/lib/index.cjs.map +0 -1
  130. package/dist/lib/index.js.map +0 -1
  131. package/dist/mocks/index.cjs.map +0 -1
  132. package/dist/mocks/index.js.map +0 -1
  133. package/dist/model/index.cjs.map +0 -1
  134. package/dist/model/index.js.map +0 -1
  135. package/dist/plugins/index.cjs.map +0 -1
  136. package/dist/plugins/index.js.map +0 -1
  137. package/dist/types/index.cjs.map +0 -1
  138. package/dist/types/index.js.map +0 -1
  139. package/dist/validation-schemas/index.cjs.map +0 -1
  140. package/dist/validation-schemas/index.js.map +0 -1
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunk46ME2TAU_cjs = require('./chunk-46ME2TAU.cjs');
4
- var chunkVGADCIBG_cjs = require('./chunk-VGADCIBG.cjs');
3
+ var chunkRCCBUOGY_cjs = require('./chunk-RCCBUOGY.cjs');
4
+ var chunk2PIMJSWJ_cjs = require('./chunk-2PIMJSWJ.cjs');
5
5
  var nanoid = require('nanoid');
6
6
  var formula = require('@revisium/formula');
7
+ var eventemitter3 = require('eventemitter3');
7
8
 
8
9
  var ARRAY_NOTATION_REGEX = /^([^[]+)\[(?:\d+|\*)?\]$/;
9
10
  var FormulaPath = class {
@@ -68,7 +69,7 @@ var FormulaPath = class {
68
69
  resolveRootPath(rootPath) {
69
70
  const path = rootPath.startsWith("/") ? rootPath.slice(1) : rootPath;
70
71
  if (!path) {
71
- return chunk46ME2TAU_cjs.EMPTY_PATH;
72
+ return chunkRCCBUOGY_cjs.EMPTY_PATH;
72
73
  }
73
74
  try {
74
75
  return this.parseFormulaPath(path);
@@ -78,7 +79,7 @@ var FormulaPath = class {
78
79
  }
79
80
  parseFormulaPath(formulaPath) {
80
81
  const parts = formulaPath.split(".");
81
- let result = chunk46ME2TAU_cjs.EMPTY_PATH;
82
+ let result = chunkRCCBUOGY_cjs.EMPTY_PATH;
82
83
  for (const part of parts) {
83
84
  if (!part) {
84
85
  throw new Error(`Invalid path: empty segment`);
@@ -106,7 +107,7 @@ var ParsedFormula = class {
106
107
  this.astNode = parseResult.ast;
107
108
  const formulaPath = tree.pathOf(formulaNodeId);
108
109
  if (formulaPath.isEmpty() && tree.root().id() !== formulaNodeId) {
109
- throw new chunk46ME2TAU_cjs.FormulaError("Formula node not found in tree", formulaNodeId);
110
+ throw new chunkRCCBUOGY_cjs.FormulaError("Formula node not found in tree", formulaNodeId);
110
111
  }
111
112
  const deps = [];
112
113
  const astPathToNodeId = /* @__PURE__ */ new Map();
@@ -117,20 +118,20 @@ var ParsedFormula = class {
117
118
  depPath
118
119
  );
119
120
  if (!targetNodeId) {
120
- throw new chunk46ME2TAU_cjs.FormulaError(
121
+ throw new chunkRCCBUOGY_cjs.FormulaError(
121
122
  `Cannot resolve formula dependency: ${depPath}`,
122
123
  formulaNodeId,
123
124
  "Path not found in schema"
124
125
  );
125
126
  }
126
127
  if (targetNodeId === formulaNodeId) {
127
- throw new chunk46ME2TAU_cjs.FormulaError(
128
+ throw new chunkRCCBUOGY_cjs.FormulaError(
128
129
  "Formula cannot reference itself",
129
130
  formulaNodeId,
130
131
  "Self-reference detected"
131
132
  );
132
133
  }
133
- deps.push(new chunk46ME2TAU_cjs.ResolvedDependency(targetNodeId));
134
+ deps.push(new chunkRCCBUOGY_cjs.ResolvedDependency(targetNodeId));
134
135
  astPathToNodeId.set(depPath, targetNodeId);
135
136
  }
136
137
  this.deps = deps;
@@ -294,7 +295,7 @@ var FormulaChangeDetector = class {
294
295
  }
295
296
  getSerializedExpression(formula, tree, nodeId) {
296
297
  try {
297
- const xFormula = chunk46ME2TAU_cjs.FormulaSerializer.toXFormula(tree, nodeId, formula);
298
+ const xFormula = chunkRCCBUOGY_cjs.FormulaSerializer.toXFormula(tree, nodeId, formula);
298
299
  return xFormula.expression;
299
300
  } catch {
300
301
  return null;
@@ -341,19 +342,19 @@ var SchemaParser = class {
341
342
  if (resolvedSchema) {
342
343
  return this.parseNode(resolvedSchema, name, refValue);
343
344
  }
344
- return chunk46ME2TAU_cjs.createRefNode(nanoid.nanoid(), name, refValue, this.extractMetadata(schema));
345
+ return chunkRCCBUOGY_cjs.createRefNode(nanoid.nanoid(), name, refValue, this.extractMetadata(schema));
345
346
  }
346
347
  const schemaWithType = schema;
347
348
  switch (schemaWithType.type) {
348
- case "object" /* Object */:
349
+ case "object":
349
350
  return this.parseObject(schemaWithType, name, parentRef);
350
- case "array" /* Array */:
351
+ case "array":
351
352
  return this.parseArray(schemaWithType, name, parentRef);
352
- case "string" /* String */:
353
+ case "string":
353
354
  return this.parseString(schemaWithType, name, parentRef);
354
- case "number" /* Number */:
355
+ case "number":
355
356
  return this.parseNumber(schemaWithType, name, parentRef);
356
- case "boolean" /* Boolean */:
357
+ case "boolean":
357
358
  return this.parseBoolean(schemaWithType, name, parentRef);
358
359
  default:
359
360
  throw new Error(`Unknown schema type: ${schemaWithType.type}`);
@@ -367,14 +368,14 @@ var SchemaParser = class {
367
368
  children.push(this.parseNode(propSchema, propName));
368
369
  }
369
370
  }
370
- return chunk46ME2TAU_cjs.createObjectNode(nanoid.nanoid(), name, children, {
371
+ return chunkRCCBUOGY_cjs.createObjectNode(nanoid.nanoid(), name, children, {
371
372
  metadata: this.extractMetadata(schema),
372
373
  ref: ref2
373
374
  });
374
375
  }
375
376
  parseArray(schema, name, ref2) {
376
377
  const items = this.parseNode(schema.items, "items");
377
- return chunk46ME2TAU_cjs.createArrayNode(nanoid.nanoid(), name, items, {
378
+ return chunkRCCBUOGY_cjs.createArrayNode(nanoid.nanoid(), name, items, {
378
379
  metadata: this.extractMetadata(schema),
379
380
  ref: ref2
380
381
  });
@@ -382,7 +383,7 @@ var SchemaParser = class {
382
383
  parseString(schema, name, ref2) {
383
384
  const nodeId = nanoid.nanoid();
384
385
  this.collectFormula(nodeId, schema["x-formula"]);
385
- return chunk46ME2TAU_cjs.createStringNode(nodeId, name, {
386
+ return chunkRCCBUOGY_cjs.createStringNode(nodeId, name, {
386
387
  defaultValue: schema.default,
387
388
  foreignKey: schema.foreignKey,
388
389
  metadata: this.extractMetadata(schema),
@@ -392,7 +393,7 @@ var SchemaParser = class {
392
393
  parseNumber(schema, name, ref2) {
393
394
  const nodeId = nanoid.nanoid();
394
395
  this.collectFormula(nodeId, schema["x-formula"]);
395
- return chunk46ME2TAU_cjs.createNumberNode(nodeId, name, {
396
+ return chunkRCCBUOGY_cjs.createNumberNode(nodeId, name, {
396
397
  defaultValue: schema.default,
397
398
  metadata: this.extractMetadata(schema),
398
399
  ref: ref2
@@ -401,7 +402,7 @@ var SchemaParser = class {
401
402
  parseBoolean(schema, name, ref2) {
402
403
  const nodeId = nanoid.nanoid();
403
404
  this.collectFormula(nodeId, schema["x-formula"]);
404
- return chunk46ME2TAU_cjs.createBooleanNode(nodeId, name, {
405
+ return chunkRCCBUOGY_cjs.createBooleanNode(nodeId, name, {
405
406
  defaultValue: schema.default,
406
407
  metadata: this.extractMetadata(schema),
407
408
  ref: ref2
@@ -434,13 +435,13 @@ var NodeFactory = class {
434
435
  createNode(name, type) {
435
436
  switch (type) {
436
437
  case "string":
437
- return chunk46ME2TAU_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
438
+ return chunkRCCBUOGY_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
438
439
  case "number":
439
- return chunk46ME2TAU_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
440
+ return chunkRCCBUOGY_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
440
441
  case "boolean":
441
- return chunk46ME2TAU_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
442
+ return chunkRCCBUOGY_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
442
443
  case "object":
443
- return chunk46ME2TAU_cjs.createObjectNode(nanoid.nanoid(), name, []);
444
+ return chunkRCCBUOGY_cjs.createObjectNode(nanoid.nanoid(), name, []);
444
445
  case "array":
445
446
  return this.createArrayNodeInternal(name);
446
447
  default:
@@ -448,11 +449,11 @@ var NodeFactory = class {
448
449
  }
449
450
  }
450
451
  createArrayNodeInternal(name) {
451
- const items = chunk46ME2TAU_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
452
- return chunk46ME2TAU_cjs.createArrayNode(nanoid.nanoid(), name, items);
452
+ const items = chunkRCCBUOGY_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
453
+ return chunkRCCBUOGY_cjs.createArrayNode(nanoid.nanoid(), name, items);
453
454
  }
454
455
  createArrayNodeWithItems(name, items) {
455
- return chunk46ME2TAU_cjs.createArrayNode(nanoid.nanoid(), name, items);
456
+ return chunkRCCBUOGY_cjs.createArrayNode(nanoid.nanoid(), name, items);
456
457
  }
457
458
  };
458
459
 
@@ -464,10 +465,10 @@ function isRefSchema(schema) {
464
465
  return "$ref" in schema;
465
466
  }
466
467
  function isObjectSchema(schema) {
467
- return "type" in schema && schema.type === "object" /* Object */;
468
+ return "type" in schema && schema.type === "object";
468
469
  }
469
470
  function isArraySchema(schema) {
470
- return "type" in schema && schema.type === "array" /* Array */;
471
+ return "type" in schema && schema.type === "array";
471
472
  }
472
473
  function hasDefaultValue(schema) {
473
474
  return "default" in schema && schema.default !== void 0;
@@ -477,11 +478,11 @@ function generatePrimitiveDefault(schema) {
477
478
  return void 0;
478
479
  }
479
480
  switch (schema.type) {
480
- case "string" /* String */:
481
+ case "string":
481
482
  return DEFAULT_STRING;
482
- case "number" /* Number */:
483
+ case "number":
483
484
  return DEFAULT_NUMBER;
484
- case "boolean" /* Boolean */:
485
+ case "boolean":
485
486
  return DEFAULT_BOOLEAN;
486
487
  default:
487
488
  return void 0;
@@ -551,7 +552,7 @@ var PrimitiveToArrayTransformer = class {
551
552
  const { sourceNode } = ctx;
552
553
  const itemsNode = sourceNode.cloneWithId(nanoid.nanoid());
553
554
  itemsNode.setName("items");
554
- const arrayNode = chunk46ME2TAU_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
555
+ const arrayNode = chunkRCCBUOGY_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
555
556
  return { node: arrayNode };
556
557
  }
557
558
  };
@@ -564,7 +565,7 @@ var ObjectToArrayTransformer = class {
564
565
  const { sourceNode } = ctx;
565
566
  const itemsNode = sourceNode.cloneWithId(nanoid.nanoid());
566
567
  itemsNode.setName("items");
567
- const arrayNode = chunk46ME2TAU_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
568
+ const arrayNode = chunkRCCBUOGY_cjs.createArrayNode(sourceNode.id(), sourceNode.name(), itemsNode);
568
569
  return { node: arrayNode };
569
570
  }
570
571
  };
@@ -606,7 +607,7 @@ var RefTransformer = class {
606
607
  const resolvedSchema = refSchemas?.[refUri];
607
608
  if (resolvedSchema) {
608
609
  const parser = new SchemaParser();
609
- const wrapperSchema = chunkVGADCIBG_cjs.obj({ temp: chunkVGADCIBG_cjs.ref(refUri) });
610
+ const wrapperSchema = chunk2PIMJSWJ_cjs.obj({ temp: chunk2PIMJSWJ_cjs.ref(refUri) });
610
611
  const resolvedNode = parser.parse(wrapperSchema, refSchemas);
611
612
  const tempNode = resolvedNode.property("temp");
612
613
  const newNode = tempNode.cloneWithId(sourceNode.id());
@@ -614,7 +615,7 @@ var RefTransformer = class {
614
615
  return { node: newNode };
615
616
  }
616
617
  const metadata = this.extractMetadata(targetSpec);
617
- const node = chunk46ME2TAU_cjs.createRefNode(sourceNode.id(), sourceNode.name(), refUri, metadata);
618
+ const node = chunkRCCBUOGY_cjs.createRefNode(sourceNode.id(), sourceNode.name(), refUri, metadata);
618
619
  return { node };
619
620
  }
620
621
  extractMetadata(spec) {
@@ -649,23 +650,23 @@ var DefaultTransformer = class {
649
650
  createNode(id, name, type, spec, metadata) {
650
651
  switch (type) {
651
652
  case "string":
652
- return chunk46ME2TAU_cjs.createStringNode(id, name, {
653
+ return chunkRCCBUOGY_cjs.createStringNode(id, name, {
653
654
  defaultValue: spec.default ?? "",
654
655
  foreignKey: spec.foreignKey,
655
656
  metadata
656
657
  });
657
658
  case "number":
658
- return chunk46ME2TAU_cjs.createNumberNode(id, name, {
659
+ return chunkRCCBUOGY_cjs.createNumberNode(id, name, {
659
660
  defaultValue: spec.default ?? 0,
660
661
  metadata
661
662
  });
662
663
  case "boolean":
663
- return chunk46ME2TAU_cjs.createBooleanNode(id, name, {
664
+ return chunkRCCBUOGY_cjs.createBooleanNode(id, name, {
664
665
  defaultValue: spec.default ?? false,
665
666
  metadata
666
667
  });
667
668
  case "object":
668
- return chunk46ME2TAU_cjs.createObjectNode(id, name, [], { metadata });
669
+ return chunkRCCBUOGY_cjs.createObjectNode(id, name, [], { metadata });
669
670
  case "array":
670
671
  return this.createArrayNode(id, name, metadata);
671
672
  default:
@@ -673,8 +674,8 @@ var DefaultTransformer = class {
673
674
  }
674
675
  }
675
676
  createArrayNode(id, name, metadata) {
676
- const items = chunk46ME2TAU_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
677
- return chunk46ME2TAU_cjs.createArrayNode(id, name, items, { metadata });
677
+ const items = chunkRCCBUOGY_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
678
+ return chunkRCCBUOGY_cjs.createArrayNode(id, name, items, { metadata });
678
679
  }
679
680
  extractMetadata(spec) {
680
681
  const meta = {};
@@ -738,8 +739,8 @@ function createTypeTransformChain(options) {
738
739
  var SchemaModelImpl = class {
739
740
  _baseTree;
740
741
  _currentTree;
741
- _patchBuilder = new chunk46ME2TAU_cjs.PatchBuilder();
742
- _serializer = new chunk46ME2TAU_cjs.SchemaSerializer();
742
+ _patchBuilder = new chunkRCCBUOGY_cjs.PatchBuilder();
743
+ _serializer = new chunkRCCBUOGY_cjs.SchemaSerializer();
743
744
  _nodeFactory = new NodeFactory();
744
745
  _formulaIndex = new FormulaDependencyIndex();
745
746
  _transformChain;
@@ -753,12 +754,12 @@ var SchemaModelImpl = class {
753
754
  });
754
755
  const parser = new SchemaParser();
755
756
  const rootNode = parser.parse(schema, this._refSchemas);
756
- this._currentTree = chunk46ME2TAU_cjs.createSchemaTree(rootNode);
757
+ this._currentTree = chunkRCCBUOGY_cjs.createSchemaTree(rootNode);
757
758
  parser.parseFormulas(this._currentTree);
758
759
  this._formulaParseErrors = parser.parseErrors;
759
760
  this._buildFormulaIndex();
760
761
  this._baseTree = this._currentTree.clone();
761
- chunk46ME2TAU_cjs.makeAutoObservable(this, {
762
+ chunkRCCBUOGY_cjs.makeAutoObservable(this, {
762
763
  _patchBuilder: false,
763
764
  _serializer: false,
764
765
  _nodeFactory: false,
@@ -787,10 +788,10 @@ var SchemaModelImpl = class {
787
788
  insertFieldAt(parentId, index, name, type) {
788
789
  const parent = this._currentTree.nodeById(parentId);
789
790
  if (parent.isNull() || !parent.isObject()) {
790
- return chunk46ME2TAU_cjs.NULL_NODE;
791
+ return chunkRCCBUOGY_cjs.NULL_NODE;
791
792
  }
792
793
  if (index < 0 || index > parent.properties().length) {
793
- return chunk46ME2TAU_cjs.NULL_NODE;
794
+ return chunkRCCBUOGY_cjs.NULL_NODE;
794
795
  }
795
796
  const node = this._nodeFactory.createNode(name, type);
796
797
  this._currentTree.insertChildAt(parentId, index, node);
@@ -1015,7 +1016,7 @@ var SchemaModelImpl = class {
1015
1016
  return "";
1016
1017
  }
1017
1018
  try {
1018
- return chunk46ME2TAU_cjs.FormulaSerializer.serializeExpression(
1019
+ return chunkRCCBUOGY_cjs.FormulaSerializer.serializeExpression(
1019
1020
  this._currentTree,
1020
1021
  nodeId,
1021
1022
  formula,
@@ -1026,10 +1027,10 @@ var SchemaModelImpl = class {
1026
1027
  }
1027
1028
  }
1028
1029
  get validationErrors() {
1029
- return chunk46ME2TAU_cjs.validateSchema(this._currentTree.root());
1030
+ return chunkRCCBUOGY_cjs.validateSchema(this._currentTree.root());
1030
1031
  }
1031
1032
  get formulaErrors() {
1032
- return [...this._formulaParseErrors, ...chunk46ME2TAU_cjs.validateFormulas(this._currentTree)];
1033
+ return [...this._formulaParseErrors, ...chunkRCCBUOGY_cjs.validateFormulas(this._currentTree)];
1033
1034
  }
1034
1035
  get isDirty() {
1035
1036
  return this.patches.length > 0;
@@ -1541,7 +1542,7 @@ var FormulaEngine = class {
1541
1542
  this.setupReactions();
1542
1543
  }
1543
1544
  evaluateAll() {
1544
- chunk46ME2TAU_cjs.runInAction(() => {
1545
+ chunkRCCBUOGY_cjs.runInAction(() => {
1545
1546
  for (const field of this.evaluationOrder) {
1546
1547
  this.evaluator.evaluate(field);
1547
1548
  }
@@ -1554,7 +1555,7 @@ var FormulaEngine = class {
1554
1555
  continue;
1555
1556
  }
1556
1557
  watchedNodes.add(depNode);
1557
- const disposer = chunk46ME2TAU_cjs.reaction(
1558
+ const disposer = chunkRCCBUOGY_cjs.reaction(
1558
1559
  () => depNode.value,
1559
1560
  () => this.handleDependencyChange(depNode)
1560
1561
  );
@@ -1564,7 +1565,7 @@ var FormulaEngine = class {
1564
1565
  }
1565
1566
  setupArrayReactions(node) {
1566
1567
  if (node.isArray()) {
1567
- const disposer = chunk46ME2TAU_cjs.reaction(
1568
+ const disposer = chunkRCCBUOGY_cjs.reaction(
1568
1569
  () => node.length,
1569
1570
  () => this.handleStructureChange()
1570
1571
  );
@@ -1584,7 +1585,7 @@ var FormulaEngine = class {
1584
1585
  this.dependencyMap,
1585
1586
  this.evaluationOrder
1586
1587
  );
1587
- chunk46ME2TAU_cjs.runInAction(() => {
1588
+ chunkRCCBUOGY_cjs.runInAction(() => {
1588
1589
  for (const field of affected) {
1589
1590
  this.evaluator.evaluate(field);
1590
1591
  }
@@ -1600,8 +1601,6 @@ var FormulaEngine = class {
1600
1601
  this.disposers = [];
1601
1602
  }
1602
1603
  };
1603
-
1604
- // src/model/value-node/BaseValueNode.ts
1605
1604
  var nodeIdCounter = 0;
1606
1605
  function generateNodeId() {
1607
1606
  return `node-${++nodeIdCounter}`;
@@ -1614,11 +1613,21 @@ var BaseValueNode = class {
1614
1613
  schema;
1615
1614
  _parent = null;
1616
1615
  _name;
1616
+ _emitter = new eventemitter3.EventEmitter();
1617
1617
  constructor(id, name, schema) {
1618
1618
  this.id = id ?? generateNodeId();
1619
1619
  this._name = name;
1620
1620
  this.schema = schema;
1621
1621
  }
1622
+ on(event, listener) {
1623
+ this._emitter.on(event, listener);
1624
+ }
1625
+ off(event, listener) {
1626
+ this._emitter.off(event, listener);
1627
+ }
1628
+ emit(changeEvent) {
1629
+ this._emitter.emit("change", changeEvent);
1630
+ }
1622
1631
  get parent() {
1623
1632
  return this._parent;
1624
1633
  }
@@ -1676,7 +1685,7 @@ var ArrayValueNode = class extends BaseValueNode {
1676
1685
  _nodeFactory = null;
1677
1686
  constructor(id, name, schema, items) {
1678
1687
  super(id, name, schema);
1679
- this._items = chunk46ME2TAU_cjs.observable.array();
1688
+ this._items = chunkRCCBUOGY_cjs.observable.array();
1680
1689
  this._baseItems = [];
1681
1690
  if (items) {
1682
1691
  for (const item of items) {
@@ -1685,7 +1694,7 @@ var ArrayValueNode = class extends BaseValueNode {
1685
1694
  }
1686
1695
  }
1687
1696
  this._baseItems = [...this._items];
1688
- chunk46ME2TAU_cjs.makeObservable(this, {
1697
+ chunkRCCBUOGY_cjs.makeObservable(this, {
1689
1698
  _items: "observable",
1690
1699
  _baseItems: "observable",
1691
1700
  value: "computed",
@@ -1702,7 +1711,8 @@ var ArrayValueNode = class extends BaseValueNode {
1702
1711
  commit: "action",
1703
1712
  revert: "action",
1704
1713
  pushValue: "action",
1705
- insertValueAt: "action"
1714
+ insertValueAt: "action",
1715
+ setValue: "action"
1706
1716
  });
1707
1717
  }
1708
1718
  get value() {
@@ -1723,6 +1733,7 @@ var ArrayValueNode = class extends BaseValueNode {
1723
1733
  push(node) {
1724
1734
  node.parent = this;
1725
1735
  this._items.push(node);
1736
+ this.emit({ type: "arrayPush", array: this, item: node });
1726
1737
  }
1727
1738
  insertAt(index, node) {
1728
1739
  if (index < 0 || index > this._items.length) {
@@ -1730,6 +1741,7 @@ var ArrayValueNode = class extends BaseValueNode {
1730
1741
  }
1731
1742
  node.parent = this;
1732
1743
  this._items.splice(index, 0, node);
1744
+ this.emit({ type: "arrayInsert", array: this, index, item: node });
1733
1745
  }
1734
1746
  removeAt(index) {
1735
1747
  if (index < 0 || index >= this._items.length) {
@@ -1739,6 +1751,7 @@ var ArrayValueNode = class extends BaseValueNode {
1739
1751
  if (removed) {
1740
1752
  removed.parent = null;
1741
1753
  }
1754
+ this.emit({ type: "arrayRemove", array: this, index, item: removed });
1742
1755
  }
1743
1756
  move(fromIndex, toIndex) {
1744
1757
  if (fromIndex < 0 || fromIndex >= this._items.length) {
@@ -1754,23 +1767,25 @@ var ArrayValueNode = class extends BaseValueNode {
1754
1767
  if (item) {
1755
1768
  this._items.splice(toIndex, 0, item);
1756
1769
  }
1770
+ this.emit({ type: "arrayMove", array: this, fromIndex, toIndex });
1757
1771
  }
1758
1772
  replaceAt(index, node) {
1759
1773
  if (index < 0 || index >= this._items.length) {
1760
1774
  throw new Error(`Index out of bounds: ${index}`);
1761
1775
  }
1762
1776
  const oldNode = this._items[index];
1763
- if (oldNode) {
1764
- oldNode.parent = null;
1765
- }
1777
+ oldNode.parent = null;
1766
1778
  node.parent = this;
1767
1779
  this._items[index] = node;
1780
+ this.emit({ type: "arrayReplace", array: this, index, item: node, oldItem: oldNode });
1768
1781
  }
1769
1782
  clear() {
1770
- for (const item of this._items) {
1783
+ const removed = [...this._items];
1784
+ for (const item of removed) {
1771
1785
  item.parent = null;
1772
1786
  }
1773
1787
  this._items.length = 0;
1788
+ this.emit({ type: "arrayClear", array: this, items: removed });
1774
1789
  }
1775
1790
  setNodeFactory(factory) {
1776
1791
  this._nodeFactory = factory;
@@ -1783,6 +1798,32 @@ var ArrayValueNode = class extends BaseValueNode {
1783
1798
  const node = this.createItemNode(index, value);
1784
1799
  this.insertAt(index, node);
1785
1800
  }
1801
+ setValue(value, options) {
1802
+ const commonLength = Math.min(this._items.length, value.length);
1803
+ for (let i = 0; i < commonLength; i++) {
1804
+ const item = this._items[i];
1805
+ if (!item) {
1806
+ continue;
1807
+ }
1808
+ const itemValue = value[i];
1809
+ if (item.isObject()) {
1810
+ item.setValue(itemValue, options);
1811
+ } else if (item.isArray()) {
1812
+ item.setValue(itemValue, options);
1813
+ } else if (item.isPrimitive()) {
1814
+ item.setValue(itemValue, options);
1815
+ }
1816
+ }
1817
+ if (value.length > this._items.length) {
1818
+ for (let i = this._items.length; i < value.length; i++) {
1819
+ this.pushValue(value[i]);
1820
+ }
1821
+ } else if (value.length < this._items.length) {
1822
+ for (let i = this._items.length - 1; i >= value.length; i--) {
1823
+ this.removeAt(i);
1824
+ }
1825
+ }
1826
+ }
1786
1827
  createItemNode(index, value) {
1787
1828
  if (!this._nodeFactory) {
1788
1829
  throw new Error("NodeFactory not set");
@@ -1840,7 +1881,7 @@ var ArrayValueNode = class extends BaseValueNode {
1840
1881
  for (const item of this._items) {
1841
1882
  item.parent = null;
1842
1883
  }
1843
- this._items = chunk46ME2TAU_cjs.observable.array();
1884
+ this._items = chunkRCCBUOGY_cjs.observable.array();
1844
1885
  for (const baseItem of this._baseItems) {
1845
1886
  this._items.push(baseItem);
1846
1887
  }
@@ -1883,7 +1924,7 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
1883
1924
  this._baseValue = initialValue;
1884
1925
  }
1885
1926
  initObservable() {
1886
- chunk46ME2TAU_cjs.makeObservable(this, {
1927
+ chunkRCCBUOGY_cjs.makeObservable(this, {
1887
1928
  _value: "observable",
1888
1929
  _baseValue: "observable",
1889
1930
  _formulaWarning: "observable",
@@ -1911,6 +1952,9 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
1911
1952
  return this._baseValue;
1912
1953
  }
1913
1954
  get isDirty() {
1955
+ if (this.formula !== void 0) {
1956
+ return false;
1957
+ }
1914
1958
  return this._value !== this._baseValue;
1915
1959
  }
1916
1960
  get formula() {
@@ -1930,7 +1974,11 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
1930
1974
  if (this.isReadOnly && !options?.internal) {
1931
1975
  throw new Error(`Cannot set value on read-only field: ${this.name}`);
1932
1976
  }
1977
+ const oldValue = this._value;
1933
1978
  this._value = this.coerceValue(value);
1979
+ if (!options?.internal) {
1980
+ this.emit({ type: "setValue", node: this, value: this._value, oldValue });
1981
+ }
1934
1982
  }
1935
1983
  setFormulaWarning(warning) {
1936
1984
  this._formulaWarning = warning;
@@ -2186,7 +2234,7 @@ var NumberValueNode = class extends BasePrimitiveValueNode {
2186
2234
  }
2187
2235
  computeErrors() {
2188
2236
  const errors = [];
2189
- if (!("type" in this.schema) || this.schema.type !== "number" /* Number */) {
2237
+ if (!("type" in this.schema) || this.schema.type !== "number") {
2190
2238
  return errors;
2191
2239
  }
2192
2240
  const numberSchema = this.schema;
@@ -2231,7 +2279,7 @@ var ObjectValueNode = class extends BaseValueNode {
2231
2279
  _baseChildren;
2232
2280
  constructor(id, name, schema, children) {
2233
2281
  super(id, name, schema);
2234
- this._children = chunk46ME2TAU_cjs.observable.map();
2282
+ this._children = chunkRCCBUOGY_cjs.observable.map();
2235
2283
  this._baseChildren = /* @__PURE__ */ new Map();
2236
2284
  if (children) {
2237
2285
  for (const child of children) {
@@ -2240,7 +2288,7 @@ var ObjectValueNode = class extends BaseValueNode {
2240
2288
  }
2241
2289
  }
2242
2290
  this._baseChildren = new Map(this._children);
2243
- chunk46ME2TAU_cjs.makeObservable(this, {
2291
+ chunkRCCBUOGY_cjs.makeObservable(this, {
2244
2292
  _children: "observable",
2245
2293
  _baseChildren: "observable",
2246
2294
  value: "computed",
@@ -2250,6 +2298,7 @@ var ObjectValueNode = class extends BaseValueNode {
2250
2298
  warnings: "computed",
2251
2299
  addChild: "action",
2252
2300
  removeChild: "action",
2301
+ setValue: "action",
2253
2302
  commit: "action",
2254
2303
  revert: "action"
2255
2304
  });
@@ -2280,12 +2329,29 @@ var ObjectValueNode = class extends BaseValueNode {
2280
2329
  }
2281
2330
  node.parent = this;
2282
2331
  this._children.set(node.name, node);
2332
+ this.emit({ type: "addChild", parent: this, child: node });
2283
2333
  }
2284
2334
  removeChild(name) {
2285
2335
  const node = this._children.get(name);
2286
2336
  if (node) {
2287
2337
  node.parent = null;
2288
2338
  this._children.delete(name);
2339
+ this.emit({ type: "removeChild", parent: this, childName: name, child: node });
2340
+ }
2341
+ }
2342
+ setValue(value, options) {
2343
+ for (const [key, child] of this._children) {
2344
+ if (!(key in value)) {
2345
+ continue;
2346
+ }
2347
+ const childValue = value[key];
2348
+ if (child.isObject()) {
2349
+ child.setValue(childValue, options);
2350
+ } else if (child.isArray()) {
2351
+ child.setValue(childValue, options);
2352
+ } else if (child.isPrimitive()) {
2353
+ child.setValue(childValue, options);
2354
+ }
2289
2355
  }
2290
2356
  }
2291
2357
  get isDirty() {
@@ -2316,7 +2382,7 @@ var ObjectValueNode = class extends BaseValueNode {
2316
2382
  for (const child of this._children.values()) {
2317
2383
  child.parent = null;
2318
2384
  }
2319
- this._children = chunk46ME2TAU_cjs.observable.map();
2385
+ this._children = chunkRCCBUOGY_cjs.observable.map();
2320
2386
  for (const [key, value] of this._baseChildren) {
2321
2387
  this._children.set(key, value);
2322
2388
  }
@@ -2530,7 +2596,7 @@ var IndexSegment = class {
2530
2596
  };
2531
2597
 
2532
2598
  // src/core/value-path/ValuePath.ts
2533
- var ValuePathImpl = class _ValuePathImpl extends chunk46ME2TAU_cjs.AbstractBasePath {
2599
+ var ValuePathImpl = class _ValuePathImpl extends chunkRCCBUOGY_cjs.AbstractBasePath {
2534
2600
  asString() {
2535
2601
  const parts = [];
2536
2602
  for (const seg of this.segs) {
@@ -2796,16 +2862,22 @@ var ValueTree = class {
2796
2862
  this._root = _root;
2797
2863
  this.index = new TreeIndex(_root);
2798
2864
  this.changeTracker = new ChangeTracker();
2799
- chunk46ME2TAU_cjs.makeAutoObservable(this, {
2865
+ this._nodeChangeListener = (event) => this.handleNodeChange(event);
2866
+ this.subscribe(this._root);
2867
+ chunkRCCBUOGY_cjs.makeAutoObservable(this, {
2800
2868
  _root: false,
2801
2869
  index: false,
2802
2870
  changeTracker: false,
2803
- _formulaEngine: false
2871
+ _nodeChangeListener: false,
2872
+ _formulaEngine: false,
2873
+ _suppressEvents: false
2804
2874
  });
2805
2875
  }
2806
2876
  index;
2807
2877
  changeTracker;
2878
+ _nodeChangeListener;
2808
2879
  _formulaEngine = null;
2880
+ _suppressEvents = false;
2809
2881
  get root() {
2810
2882
  return this._root;
2811
2883
  }
@@ -2843,20 +2915,28 @@ var ValueTree = class {
2843
2915
  const node = this.get(path);
2844
2916
  return node?.getPlainValue();
2845
2917
  }
2846
- setValue(path, value) {
2918
+ setValue(path, value, options) {
2847
2919
  const node = this.get(path);
2848
2920
  if (!node) {
2849
2921
  throw new Error(`Path not found: ${path}`);
2850
2922
  }
2851
- if (!node.isPrimitive()) {
2852
- throw new Error(`Cannot set value on non-primitive node: ${path}`);
2923
+ const oldValue = node.getPlainValue();
2924
+ this._suppressEvents = true;
2925
+ try {
2926
+ if (node.isPrimitive()) {
2927
+ node.setValue(value, options);
2928
+ } else if (node.isObject()) {
2929
+ node.setValue(value, options);
2930
+ } else if (node.isArray()) {
2931
+ node.setValue(value, options);
2932
+ }
2933
+ } finally {
2934
+ this._suppressEvents = false;
2853
2935
  }
2854
- const oldValue = node.value;
2855
- node.setValue(value);
2856
2936
  this.changeTracker.track({
2857
2937
  type: "setValue",
2858
2938
  path: this.index.pathOf(node),
2859
- value,
2939
+ value: node.getPlainValue(),
2860
2940
  oldValue
2861
2941
  });
2862
2942
  }
@@ -2890,11 +2970,13 @@ var ValueTree = class {
2890
2970
  this.changeTracker.clear();
2891
2971
  }
2892
2972
  revert() {
2973
+ this.unsubscribe(this._root);
2893
2974
  const root = this._root;
2894
2975
  if ("revert" in root && typeof root.revert === "function") {
2895
2976
  root.revert();
2896
2977
  }
2897
2978
  this.changeTracker.clear();
2979
+ this.subscribe(this._root);
2898
2980
  }
2899
2981
  rebuildIndex() {
2900
2982
  this.index.rebuild();
@@ -2912,9 +2994,126 @@ var ValueTree = class {
2912
2994
  return this._formulaEngine;
2913
2995
  }
2914
2996
  dispose() {
2997
+ this.unsubscribe(this._root);
2915
2998
  this._formulaEngine?.dispose();
2916
2999
  this._formulaEngine = null;
2917
3000
  }
3001
+ handleNodeChange(event) {
3002
+ if (this._suppressEvents) {
3003
+ return;
3004
+ }
3005
+ switch (event.type) {
3006
+ case "setValue": {
3007
+ this.changeTracker.track({
3008
+ type: "setValue",
3009
+ path: this.index.pathOf(event.node),
3010
+ value: event.value,
3011
+ oldValue: event.oldValue
3012
+ });
3013
+ break;
3014
+ }
3015
+ case "addChild": {
3016
+ this.adoptNode(event.child);
3017
+ this.changeTracker.track({
3018
+ type: "addProperty",
3019
+ path: this.index.pathOf(event.parent).child(event.child.name),
3020
+ value: event.child.getPlainValue()
3021
+ });
3022
+ break;
3023
+ }
3024
+ case "removeChild": {
3025
+ this.unsubscribe(event.child);
3026
+ this.changeTracker.track({
3027
+ type: "removeProperty",
3028
+ path: this.index.pathOf(event.parent).child(event.childName)
3029
+ });
3030
+ break;
3031
+ }
3032
+ case "arrayPush":
3033
+ case "arrayInsert": {
3034
+ this.adoptNode(event.item);
3035
+ this.index.invalidatePathsUnder(event.array);
3036
+ this.changeTracker.track(
3037
+ this.toArrayItemChange(event)
3038
+ );
3039
+ break;
3040
+ }
3041
+ case "arrayReplace": {
3042
+ this.unsubscribe(event.oldItem);
3043
+ this.adoptNode(event.item);
3044
+ this.index.invalidatePathsUnder(event.array);
3045
+ this.changeTracker.track({
3046
+ type: "arrayReplace",
3047
+ path: this.index.pathOf(event.array),
3048
+ index: event.index,
3049
+ value: event.item.getPlainValue()
3050
+ });
3051
+ break;
3052
+ }
3053
+ case "arrayRemove": {
3054
+ this.unsubscribe(event.item);
3055
+ this.index.invalidatePathsUnder(event.array);
3056
+ this.changeTracker.track(
3057
+ this.toArrayStructureChange(event)
3058
+ );
3059
+ break;
3060
+ }
3061
+ case "arrayMove": {
3062
+ this.index.invalidatePathsUnder(event.array);
3063
+ this.changeTracker.track(
3064
+ this.toArrayStructureChange(event)
3065
+ );
3066
+ break;
3067
+ }
3068
+ case "arrayClear": {
3069
+ for (const item of event.items) {
3070
+ this.unsubscribe(item);
3071
+ }
3072
+ this.changeTracker.track({
3073
+ type: "arrayClear",
3074
+ path: this.index.pathOf(event.array)
3075
+ });
3076
+ break;
3077
+ }
3078
+ }
3079
+ }
3080
+ toArrayItemChange(event) {
3081
+ const path = this.index.pathOf(event.array);
3082
+ const value = event.item.getPlainValue();
3083
+ if (event.type === "arrayPush") {
3084
+ return { type: "arrayPush", path, value };
3085
+ }
3086
+ return { type: "arrayInsert", path, index: event.index, value };
3087
+ }
3088
+ toArrayStructureChange(event) {
3089
+ const path = this.index.pathOf(event.array);
3090
+ if (event.type === "arrayRemove") {
3091
+ return { type: "arrayRemove", path, index: event.index };
3092
+ }
3093
+ return { type: "arrayMove", path, fromIndex: event.fromIndex, toIndex: event.toIndex };
3094
+ }
3095
+ adoptNode(node) {
3096
+ this.subscribe(node);
3097
+ this.index.registerNode(node);
3098
+ }
3099
+ walkTree(node, visit) {
3100
+ visit(node);
3101
+ if (node.isObject()) {
3102
+ for (const child of node.children) {
3103
+ this.walkTree(child, visit);
3104
+ }
3105
+ } else if (node.isArray()) {
3106
+ for (const item of node.value) {
3107
+ this.walkTree(item, visit);
3108
+ }
3109
+ }
3110
+ }
3111
+ subscribe(node) {
3112
+ this.walkTree(node, (n) => n.on("change", this._nodeChangeListener));
3113
+ }
3114
+ unsubscribe(node) {
3115
+ this.walkTree(node, (n) => n.off("change", this._nodeChangeListener));
3116
+ }
2918
3117
  };
2919
3118
 
2920
3119
  // src/model/table/row/RowModelImpl.ts
@@ -2923,7 +3122,7 @@ var RowModelImpl = class {
2923
3122
  constructor(_rowId, _tree) {
2924
3123
  this._rowId = _rowId;
2925
3124
  this._tree = _tree;
2926
- chunk46ME2TAU_cjs.makeAutoObservable(this, {
3125
+ chunkRCCBUOGY_cjs.makeAutoObservable(this, {
2927
3126
  _rowId: false,
2928
3127
  _tree: false,
2929
3128
  _tableModel: "observable.ref"
@@ -3034,13 +3233,13 @@ var TableModelImpl = class {
3034
3233
  this._schema = createSchemaModel(options.schema, { refSchemas: options.refSchemas });
3035
3234
  this._fkResolver = options.fkResolver;
3036
3235
  this._refSchemas = options.refSchemas;
3037
- this._rows = chunk46ME2TAU_cjs.observable.array();
3236
+ this._rows = chunkRCCBUOGY_cjs.observable.array();
3038
3237
  if (options.rows) {
3039
3238
  for (const row of options.rows) {
3040
3239
  this._rows.push(this.createRow(row.rowId, row.data));
3041
3240
  }
3042
3241
  }
3043
- chunk46ME2TAU_cjs.makeAutoObservable(this, {
3242
+ chunkRCCBUOGY_cjs.makeAutoObservable(this, {
3044
3243
  _schema: false,
3045
3244
  _rows: false,
3046
3245
  _jsonSchema: false,
@@ -3171,13 +3370,13 @@ var ForeignKeyResolverImpl = class {
3171
3370
  constructor(options) {
3172
3371
  this.loader = options?.loader;
3173
3372
  this._prefetchEnabled = options?.prefetch ?? false;
3174
- this._schemaCache = chunk46ME2TAU_cjs.observable.map();
3175
- this._tableCache = chunk46ME2TAU_cjs.observable.map();
3373
+ this._schemaCache = chunkRCCBUOGY_cjs.observable.map();
3374
+ this._tableCache = chunkRCCBUOGY_cjs.observable.map();
3176
3375
  this._loadingTables = /* @__PURE__ */ new Set();
3177
3376
  this._loadingRows = /* @__PURE__ */ new Map();
3178
3377
  this._pendingTableLoads = /* @__PURE__ */ new Map();
3179
3378
  this._pendingRowLoads = /* @__PURE__ */ new Map();
3180
- chunk46ME2TAU_cjs.makeAutoObservable(this, {
3379
+ chunkRCCBUOGY_cjs.makeAutoObservable(this, {
3181
3380
  _schemaCache: false,
3182
3381
  _tableCache: false,
3183
3382
  _loadingTables: false,
@@ -3215,7 +3414,7 @@ var ForeignKeyResolverImpl = class {
3215
3414
  if (this._disposed) {
3216
3415
  return;
3217
3416
  }
3218
- chunk46ME2TAU_cjs.runInAction(() => {
3417
+ chunkRCCBUOGY_cjs.runInAction(() => {
3219
3418
  this._schemaCache.set(tableId, schema);
3220
3419
  });
3221
3420
  }
@@ -3223,12 +3422,12 @@ var ForeignKeyResolverImpl = class {
3223
3422
  if (this._disposed) {
3224
3423
  return;
3225
3424
  }
3226
- const rowMap = chunk46ME2TAU_cjs.observable.map();
3425
+ const rowMap = chunkRCCBUOGY_cjs.observable.map();
3227
3426
  for (const row of rows) {
3228
3427
  rowMap.set(row.rowId, row);
3229
3428
  }
3230
3429
  const cache = { schema, rows: rowMap };
3231
- chunk46ME2TAU_cjs.runInAction(() => {
3430
+ chunkRCCBUOGY_cjs.runInAction(() => {
3232
3431
  this._tableCache.set(tableId, cache);
3233
3432
  this._schemaCache.set(tableId, schema);
3234
3433
  });
@@ -3243,7 +3442,7 @@ var ForeignKeyResolverImpl = class {
3243
3442
  const table = this._tableCache.get(tableId);
3244
3443
  if (table) {
3245
3444
  const rowData = { rowId, data };
3246
- chunk46ME2TAU_cjs.runInAction(() => {
3445
+ chunkRCCBUOGY_cjs.runInAction(() => {
3247
3446
  table.rows.set(rowId, rowData);
3248
3447
  });
3249
3448
  if (this._prefetchEnabled) {
@@ -3257,7 +3456,7 @@ var ForeignKeyResolverImpl = class {
3257
3456
  }
3258
3457
  const schema = this._schemaCache.get(oldTableId);
3259
3458
  const tableCache = this._tableCache.get(oldTableId);
3260
- chunk46ME2TAU_cjs.runInAction(() => {
3459
+ chunkRCCBUOGY_cjs.runInAction(() => {
3261
3460
  if (schema) {
3262
3461
  this._schemaCache.delete(oldTableId);
3263
3462
  this._schemaCache.set(newTableId, schema);
@@ -3359,9 +3558,9 @@ var ForeignKeyResolverImpl = class {
3359
3558
  }
3360
3559
  ensureTableCache(tableId, schema) {
3361
3560
  if (!this._tableCache.has(tableId)) {
3362
- const rowMap = chunk46ME2TAU_cjs.observable.map();
3561
+ const rowMap = chunkRCCBUOGY_cjs.observable.map();
3363
3562
  const cache = { schema, rows: rowMap };
3364
- chunk46ME2TAU_cjs.runInAction(() => {
3563
+ chunkRCCBUOGY_cjs.runInAction(() => {
3365
3564
  this._tableCache.set(tableId, cache);
3366
3565
  });
3367
3566
  }
@@ -3445,7 +3644,7 @@ var ForeignKeyResolverImpl = class {
3445
3644
  return foreignKeys;
3446
3645
  }
3447
3646
  getForeignKeyFromSchema(schema) {
3448
- if ("type" in schema && schema.type === "string" /* String */) {
3647
+ if ("type" in schema && schema.type === "string") {
3449
3648
  return schema.foreignKey;
3450
3649
  }
3451
3650
  return void 0;
@@ -3461,7 +3660,7 @@ var DataModelImpl = class {
3461
3660
  _fk;
3462
3661
  _ownsFkResolver;
3463
3662
  constructor(options) {
3464
- this._tables = chunk46ME2TAU_cjs.observable.map();
3663
+ this._tables = chunkRCCBUOGY_cjs.observable.map();
3465
3664
  if (options?.fkResolver) {
3466
3665
  this._fk = options.fkResolver;
3467
3666
  this._ownsFkResolver = false;
@@ -3469,7 +3668,7 @@ var DataModelImpl = class {
3469
3668
  this._fk = createForeignKeyResolver();
3470
3669
  this._ownsFkResolver = true;
3471
3670
  }
3472
- chunk46ME2TAU_cjs.makeAutoObservable(this, {
3671
+ chunkRCCBUOGY_cjs.makeAutoObservable(this, {
3473
3672
  _tables: false,
3474
3673
  _fk: false,
3475
3674
  _ownsFkResolver: false
@@ -3549,6 +3748,16 @@ function createDataModel(options) {
3549
3748
  return new DataModelImpl(options);
3550
3749
  }
3551
3750
 
3751
+ // src/model/value-tree/typed.ts
3752
+ function typedNode(node) {
3753
+ return node;
3754
+ }
3755
+ function createTypedTree(schema, data, options) {
3756
+ const factory = createNodeFactory(options);
3757
+ const root = factory.createTree(schema, data);
3758
+ return new ValueTree(root);
3759
+ }
3760
+
3552
3761
  exports.ArrayToItemsTypeTransformer = ArrayToItemsTypeTransformer;
3553
3762
  exports.ArrayValueNode = ArrayValueNode;
3554
3763
  exports.BasePrimitiveValueNode = BasePrimitiveValueNode;
@@ -3577,6 +3786,7 @@ exports.SchemaParser = SchemaParser;
3577
3786
  exports.StringValueNode = StringValueNode;
3578
3787
  exports.TableModelImpl = TableModelImpl;
3579
3788
  exports.TypeTransformChain = TypeTransformChain;
3789
+ exports.ValueTree = ValueTree;
3580
3790
  exports.ValueType = ValueType;
3581
3791
  exports.createDataModel = createDataModel;
3582
3792
  exports.createDefaultRegistry = createDefaultRegistry;
@@ -3586,10 +3796,10 @@ exports.createRowModel = createRowModel;
3586
3796
  exports.createSchemaModel = createSchemaModel;
3587
3797
  exports.createTableModel = createTableModel;
3588
3798
  exports.createTypeTransformChain = createTypeTransformChain;
3799
+ exports.createTypedTree = createTypedTree;
3589
3800
  exports.extractFormulaDefinition = extractFormulaDefinition;
3590
3801
  exports.generateDefaultValue = generateDefaultValue;
3591
3802
  exports.generateNodeId = generateNodeId;
3592
3803
  exports.isForeignKeyValueNode = isForeignKeyValueNode;
3593
3804
  exports.resetNodeIdCounter = resetNodeIdCounter;
3594
- //# sourceMappingURL=chunk-FZ2MS4Q5.cjs.map
3595
- //# sourceMappingURL=chunk-FZ2MS4Q5.cjs.map
3805
+ exports.typedNode = typedNode;