@revisium/schema-toolkit 0.16.4 → 0.17.0

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 (37) hide show
  1. package/dist/{chunk-YCJJVI3Z.js → chunk-6EAIJMZV.js} +238 -28
  2. package/dist/chunk-6EAIJMZV.js.map +1 -0
  3. package/dist/chunk-G6ZKEVVU.cjs +4 -0
  4. package/dist/chunk-G6ZKEVVU.cjs.map +1 -0
  5. package/dist/chunk-NY3H6C7K.js +3 -0
  6. package/dist/chunk-NY3H6C7K.js.map +1 -0
  7. package/dist/{chunk-YGTMLR3D.js → chunk-R4CFU33U.js} +2 -2
  8. package/dist/{chunk-YGTMLR3D.js.map → chunk-R4CFU33U.js.map} +1 -1
  9. package/dist/{chunk-PGR2S2BR.js → chunk-RTBMPBPC.js} +87 -42
  10. package/dist/chunk-RTBMPBPC.js.map +1 -0
  11. package/dist/{chunk-JJ2KGTZX.cjs → chunk-VGADCIBG.cjs} +2 -2
  12. package/dist/{chunk-JJ2KGTZX.cjs.map → chunk-VGADCIBG.cjs.map} +1 -1
  13. package/dist/{chunk-MAEGAVK4.cjs → chunk-YRKXZTRZ.cjs} +288 -71
  14. package/dist/chunk-YRKXZTRZ.cjs.map +1 -0
  15. package/dist/{chunk-VGB4YCGF.cjs → chunk-ZG7QX4I3.cjs} +87 -42
  16. package/dist/chunk-ZG7QX4I3.cjs.map +1 -0
  17. package/dist/core/index.cjs +57 -57
  18. package/dist/core/index.d.cts +15 -4
  19. package/dist/core/index.d.ts +15 -4
  20. package/dist/core/index.js +1 -1
  21. package/dist/index.cjs +189 -160
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +4 -3
  25. package/dist/mocks/index.cjs +18 -17
  26. package/dist/mocks/index.js +2 -1
  27. package/dist/model/index.cjs +68 -39
  28. package/dist/model/index.d.cts +80 -5
  29. package/dist/model/index.d.ts +80 -5
  30. package/dist/model/index.js +3 -2
  31. package/dist/{types-bBnnfNxC.d.ts → types-6S07rMdY.d.ts} +1 -0
  32. package/dist/{types-BUiNI0oL.d.cts → types-DHlnrQKG.d.cts} +1 -0
  33. package/package.json +1 -1
  34. package/dist/chunk-MAEGAVK4.cjs.map +0 -1
  35. package/dist/chunk-PGR2S2BR.js.map +0 -1
  36. package/dist/chunk-VGB4YCGF.cjs.map +0 -1
  37. package/dist/chunk-YCJJVI3Z.js.map +0 -1
@@ -61,6 +61,9 @@ var NullNodeImpl = class {
61
61
  clone() {
62
62
  return this;
63
63
  }
64
+ cloneWithId(_newId) {
65
+ return this;
66
+ }
64
67
  setName(_name) {
65
68
  }
66
69
  setMetadata(_metadata) {
@@ -181,13 +184,15 @@ function createMobxProvider(mobx) {
181
184
 
182
185
  // src/core/schema-node/BaseNode.ts
183
186
  var BaseNode = class {
184
- constructor(_id, name, metadata = EMPTY_METADATA) {
187
+ constructor(_id, name, metadata = EMPTY_METADATA, ref) {
185
188
  this._id = _id;
186
189
  this._name = name;
187
190
  this._metadata = metadata;
191
+ this._ref = ref;
188
192
  }
189
193
  _name;
190
194
  _metadata;
195
+ _ref;
191
196
  initBaseObservable() {
192
197
  makeObservable(this, {
193
198
  _name: "observable",
@@ -215,7 +220,7 @@ var BaseNode = class {
215
220
  return false;
216
221
  }
217
222
  isRef() {
218
- return false;
223
+ return this._ref !== void 0;
219
224
  }
220
225
  isNull() {
221
226
  return false;
@@ -230,7 +235,7 @@ var BaseNode = class {
230
235
  return NULL_NODE;
231
236
  }
232
237
  ref() {
233
- return void 0;
238
+ return this._ref;
234
239
  }
235
240
  formula() {
236
241
  return void 0;
@@ -273,11 +278,26 @@ var BaseNode = class {
273
278
  }
274
279
  };
275
280
 
281
+ // src/core/schema-node/utils.ts
282
+ function isNodeMetadata(value) {
283
+ if ("ref" in value || "metadata" in value) {
284
+ return false;
285
+ }
286
+ return "title" in value || "description" in value || "deprecated" in value;
287
+ }
288
+ function normalizeNodeOptions(options) {
289
+ if (isNodeMetadata(options)) {
290
+ return { metadata: options };
291
+ }
292
+ return options;
293
+ }
294
+
276
295
  // src/core/schema-node/ObjectNode.ts
277
296
  var ObjectNode = class _ObjectNode extends BaseNode {
278
297
  _children;
279
- constructor(id, name, children = [], metadata = EMPTY_METADATA) {
280
- super(id, name, metadata);
298
+ constructor(id, name, children = [], optionsOrMetadata = {}) {
299
+ const options = normalizeNodeOptions(optionsOrMetadata);
300
+ super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
281
301
  this._children = [...children];
282
302
  this.initBaseObservable();
283
303
  makeObservable(this, {
@@ -304,7 +324,15 @@ var ObjectNode = class _ObjectNode extends BaseNode {
304
324
  this.id(),
305
325
  this.name(),
306
326
  this._children.map((child) => child.clone()),
307
- this.metadata()
327
+ { metadata: this.metadata(), ref: this._ref }
328
+ );
329
+ }
330
+ cloneWithId(newId) {
331
+ return new _ObjectNode(
332
+ newId,
333
+ this.name(),
334
+ this._children.map((child) => child.clone()),
335
+ { metadata: this.metadata(), ref: this._ref }
308
336
  );
309
337
  }
310
338
  addChild(node) {
@@ -327,15 +355,16 @@ var ObjectNode = class _ObjectNode extends BaseNode {
327
355
  return true;
328
356
  }
329
357
  };
330
- function createObjectNode(id, name, children = [], metadata = EMPTY_METADATA) {
331
- return new ObjectNode(id, name, children, metadata);
358
+ function createObjectNode(id, name, children = [], options = {}) {
359
+ return new ObjectNode(id, name, children, options);
332
360
  }
333
361
 
334
362
  // src/core/schema-node/ArrayNode.ts
335
363
  var ArrayNode = class _ArrayNode extends BaseNode {
336
364
  _items;
337
- constructor(id, name, items, metadata = EMPTY_METADATA) {
338
- super(id, name, metadata);
365
+ constructor(id, name, items, optionsOrMetadata = {}) {
366
+ const options = normalizeNodeOptions(optionsOrMetadata);
367
+ super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
339
368
  this._items = items;
340
369
  this.initBaseObservable();
341
370
  makeObservable(this, {
@@ -356,19 +385,23 @@ var ArrayNode = class _ArrayNode extends BaseNode {
356
385
  return this._items;
357
386
  }
358
387
  clone() {
359
- return new _ArrayNode(
360
- this.id(),
361
- this.name(),
362
- this._items.clone(),
363
- this.metadata()
364
- );
388
+ return new _ArrayNode(this.id(), this.name(), this._items.clone(), {
389
+ metadata: this.metadata(),
390
+ ref: this._ref
391
+ });
392
+ }
393
+ cloneWithId(newId) {
394
+ return new _ArrayNode(newId, this.name(), this._items.clone(), {
395
+ metadata: this.metadata(),
396
+ ref: this._ref
397
+ });
365
398
  }
366
399
  setItems(node) {
367
400
  this._items = node;
368
401
  }
369
402
  };
370
- function createArrayNode(id, name, items, metadata = EMPTY_METADATA) {
371
- return new ArrayNode(id, name, items, metadata);
403
+ function createArrayNode(id, name, items, options = {}) {
404
+ return new ArrayNode(id, name, items, options);
372
405
  }
373
406
 
374
407
  // src/core/schema-node/PrimitiveNode.ts
@@ -377,7 +410,7 @@ var PrimitiveNode = class extends BaseNode {
377
410
  _foreignKey;
378
411
  _formula;
379
412
  constructor(id, name, options = {}) {
380
- super(id, name, options.metadata ?? EMPTY_METADATA);
413
+ super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
381
414
  this._defaultValue = options.defaultValue;
382
415
  this._foreignKey = options.foreignKey;
383
416
  this._formula = options.formula;
@@ -446,13 +479,17 @@ var StringNode = class _StringNode extends PrimitiveNode {
446
479
  clone() {
447
480
  return new _StringNode(this.id(), this.name(), this.cloneOptions());
448
481
  }
482
+ cloneWithId(newId) {
483
+ return new _StringNode(newId, this.name(), this.cloneOptions());
484
+ }
449
485
  cloneOptions() {
450
486
  return {
451
487
  defaultValue: this._defaultValue,
452
488
  foreignKey: this._foreignKey,
453
489
  formula: this._formula,
454
490
  metadata: this._metadata,
455
- contentMediaType: this._contentMediaType
491
+ contentMediaType: this._contentMediaType,
492
+ ref: this._ref
456
493
  };
457
494
  }
458
495
  };
@@ -472,11 +509,15 @@ var NumberNode = class _NumberNode extends PrimitiveNode {
472
509
  clone() {
473
510
  return new _NumberNode(this.id(), this.name(), this.cloneOptions());
474
511
  }
512
+ cloneWithId(newId) {
513
+ return new _NumberNode(newId, this.name(), this.cloneOptions());
514
+ }
475
515
  cloneOptions() {
476
516
  return {
477
517
  defaultValue: this._defaultValue,
478
518
  formula: this._formula,
479
- metadata: this._metadata
519
+ metadata: this._metadata,
520
+ ref: this._ref
480
521
  };
481
522
  }
482
523
  };
@@ -496,11 +537,15 @@ var BooleanNode = class _BooleanNode extends PrimitiveNode {
496
537
  clone() {
497
538
  return new _BooleanNode(this.id(), this.name(), this.cloneOptions());
498
539
  }
540
+ cloneWithId(newId) {
541
+ return new _BooleanNode(newId, this.name(), this.cloneOptions());
542
+ }
499
543
  cloneOptions() {
500
544
  return {
501
545
  defaultValue: this._defaultValue,
502
546
  formula: this._formula,
503
- metadata: this._metadata
547
+ metadata: this._metadata,
548
+ ref: this._ref
504
549
  };
505
550
  }
506
551
  };
@@ -510,26 +555,29 @@ function createBooleanNode(id, name, options = {}) {
510
555
 
511
556
  // src/core/schema-node/RefNode.ts
512
557
  var RefNode = class _RefNode extends BaseNode {
513
- _ref;
514
558
  constructor(id, name, ref, metadata = EMPTY_METADATA) {
515
- super(id, name, metadata);
559
+ super(id, name, metadata, ref);
516
560
  if (!ref) {
517
561
  throw new Error("RefNode requires a non-empty ref");
518
562
  }
519
- this._ref = ref;
520
563
  this.initBaseObservable();
521
564
  }
522
565
  nodeType() {
523
566
  return "ref";
524
567
  }
525
- isRef() {
526
- return true;
527
- }
528
- ref() {
529
- return this._ref;
530
- }
531
568
  clone() {
532
- return new _RefNode(this.id(), this.name(), this._ref, this.metadata());
569
+ const ref = this.ref();
570
+ if (!ref) {
571
+ throw new Error("RefNode must have a ref value");
572
+ }
573
+ return new _RefNode(this.id(), this.name(), ref, this.metadata());
574
+ }
575
+ cloneWithId(newId) {
576
+ const ref = this.ref();
577
+ if (!ref) {
578
+ throw new Error("RefNode must have a ref value");
579
+ }
580
+ return new _RefNode(newId, this.name(), ref, this.metadata());
533
581
  }
534
582
  };
535
583
  function createRefNode(id, name, ref, metadata = EMPTY_METADATA) {
@@ -1749,15 +1797,16 @@ var SchemaSerializer = class {
1749
1797
  if (node.isNull()) {
1750
1798
  throw new Error("Cannot serialize null node");
1751
1799
  }
1800
+ const ref = node.ref();
1801
+ if (ref) {
1802
+ return this.serializeRef(node, ref);
1803
+ }
1752
1804
  if (node.isObject()) {
1753
1805
  return this.serializeObject(node);
1754
1806
  }
1755
1807
  if (node.isArray()) {
1756
1808
  return this.serializeArray(node);
1757
1809
  }
1758
- if (node.isRef()) {
1759
- return this.serializeRef(node);
1760
- }
1761
1810
  return this.serializePrimitive(node);
1762
1811
  }
1763
1812
  serializeObject(node) {
@@ -1789,11 +1838,7 @@ var SchemaSerializer = class {
1789
1838
  };
1790
1839
  return this.addMetadata(result, node);
1791
1840
  }
1792
- serializeRef(node) {
1793
- const ref = node.ref();
1794
- if (!ref) {
1795
- throw new Error("Ref node must have a ref value");
1796
- }
1841
+ serializeRef(node, ref) {
1797
1842
  const result = {
1798
1843
  $ref: ref
1799
1844
  };
@@ -2953,5 +2998,5 @@ exports.runInAction = runInAction;
2953
2998
  exports.setReactivityProvider = setReactivityProvider;
2954
2999
  exports.validateFormulas = validateFormulas;
2955
3000
  exports.validateSchema = validateSchema;
2956
- //# sourceMappingURL=chunk-VGB4YCGF.cjs.map
2957
- //# sourceMappingURL=chunk-VGB4YCGF.cjs.map
3001
+ //# sourceMappingURL=chunk-ZG7QX4I3.cjs.map
3002
+ //# sourceMappingURL=chunk-ZG7QX4I3.cjs.map