@revisium/schema-toolkit 0.16.3 → 0.16.5

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.
@@ -179,13 +179,15 @@ function createMobxProvider(mobx) {
179
179
 
180
180
  // src/core/schema-node/BaseNode.ts
181
181
  var BaseNode = class {
182
- constructor(_id, name, metadata = EMPTY_METADATA) {
182
+ constructor(_id, name, metadata = EMPTY_METADATA, ref) {
183
183
  this._id = _id;
184
184
  this._name = name;
185
185
  this._metadata = metadata;
186
+ this._ref = ref;
186
187
  }
187
188
  _name;
188
189
  _metadata;
190
+ _ref;
189
191
  initBaseObservable() {
190
192
  makeObservable(this, {
191
193
  _name: "observable",
@@ -213,7 +215,7 @@ var BaseNode = class {
213
215
  return false;
214
216
  }
215
217
  isRef() {
216
- return false;
218
+ return this._ref !== void 0;
217
219
  }
218
220
  isNull() {
219
221
  return false;
@@ -228,7 +230,7 @@ var BaseNode = class {
228
230
  return NULL_NODE;
229
231
  }
230
232
  ref() {
231
- return void 0;
233
+ return this._ref;
232
234
  }
233
235
  formula() {
234
236
  return void 0;
@@ -271,11 +273,26 @@ var BaseNode = class {
271
273
  }
272
274
  };
273
275
 
276
+ // src/core/schema-node/utils.ts
277
+ function isNodeMetadata(value) {
278
+ if ("ref" in value || "metadata" in value) {
279
+ return false;
280
+ }
281
+ return "title" in value || "description" in value || "deprecated" in value;
282
+ }
283
+ function normalizeNodeOptions(options) {
284
+ if (isNodeMetadata(options)) {
285
+ return { metadata: options };
286
+ }
287
+ return options;
288
+ }
289
+
274
290
  // src/core/schema-node/ObjectNode.ts
275
291
  var ObjectNode = class _ObjectNode extends BaseNode {
276
292
  _children;
277
- constructor(id, name, children = [], metadata = EMPTY_METADATA) {
278
- super(id, name, metadata);
293
+ constructor(id, name, children = [], optionsOrMetadata = {}) {
294
+ const options = normalizeNodeOptions(optionsOrMetadata);
295
+ super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
279
296
  this._children = [...children];
280
297
  this.initBaseObservable();
281
298
  makeObservable(this, {
@@ -302,7 +319,7 @@ var ObjectNode = class _ObjectNode extends BaseNode {
302
319
  this.id(),
303
320
  this.name(),
304
321
  this._children.map((child) => child.clone()),
305
- this.metadata()
322
+ { metadata: this.metadata(), ref: this._ref }
306
323
  );
307
324
  }
308
325
  addChild(node) {
@@ -325,15 +342,16 @@ var ObjectNode = class _ObjectNode extends BaseNode {
325
342
  return true;
326
343
  }
327
344
  };
328
- function createObjectNode(id, name, children = [], metadata = EMPTY_METADATA) {
329
- return new ObjectNode(id, name, children, metadata);
345
+ function createObjectNode(id, name, children = [], options = {}) {
346
+ return new ObjectNode(id, name, children, options);
330
347
  }
331
348
 
332
349
  // src/core/schema-node/ArrayNode.ts
333
350
  var ArrayNode = class _ArrayNode extends BaseNode {
334
351
  _items;
335
- constructor(id, name, items, metadata = EMPTY_METADATA) {
336
- super(id, name, metadata);
352
+ constructor(id, name, items, optionsOrMetadata = {}) {
353
+ const options = normalizeNodeOptions(optionsOrMetadata);
354
+ super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
337
355
  this._items = items;
338
356
  this.initBaseObservable();
339
357
  makeObservable(this, {
@@ -354,19 +372,17 @@ var ArrayNode = class _ArrayNode extends BaseNode {
354
372
  return this._items;
355
373
  }
356
374
  clone() {
357
- return new _ArrayNode(
358
- this.id(),
359
- this.name(),
360
- this._items.clone(),
361
- this.metadata()
362
- );
375
+ return new _ArrayNode(this.id(), this.name(), this._items.clone(), {
376
+ metadata: this.metadata(),
377
+ ref: this._ref
378
+ });
363
379
  }
364
380
  setItems(node) {
365
381
  this._items = node;
366
382
  }
367
383
  };
368
- function createArrayNode(id, name, items, metadata = EMPTY_METADATA) {
369
- return new ArrayNode(id, name, items, metadata);
384
+ function createArrayNode(id, name, items, options = {}) {
385
+ return new ArrayNode(id, name, items, options);
370
386
  }
371
387
 
372
388
  // src/core/schema-node/PrimitiveNode.ts
@@ -375,7 +391,7 @@ var PrimitiveNode = class extends BaseNode {
375
391
  _foreignKey;
376
392
  _formula;
377
393
  constructor(id, name, options = {}) {
378
- super(id, name, options.metadata ?? EMPTY_METADATA);
394
+ super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
379
395
  this._defaultValue = options.defaultValue;
380
396
  this._foreignKey = options.foreignKey;
381
397
  this._formula = options.formula;
@@ -450,7 +466,8 @@ var StringNode = class _StringNode extends PrimitiveNode {
450
466
  foreignKey: this._foreignKey,
451
467
  formula: this._formula,
452
468
  metadata: this._metadata,
453
- contentMediaType: this._contentMediaType
469
+ contentMediaType: this._contentMediaType,
470
+ ref: this._ref
454
471
  };
455
472
  }
456
473
  };
@@ -474,7 +491,8 @@ var NumberNode = class _NumberNode extends PrimitiveNode {
474
491
  return {
475
492
  defaultValue: this._defaultValue,
476
493
  formula: this._formula,
477
- metadata: this._metadata
494
+ metadata: this._metadata,
495
+ ref: this._ref
478
496
  };
479
497
  }
480
498
  };
@@ -498,7 +516,8 @@ var BooleanNode = class _BooleanNode extends PrimitiveNode {
498
516
  return {
499
517
  defaultValue: this._defaultValue,
500
518
  formula: this._formula,
501
- metadata: this._metadata
519
+ metadata: this._metadata,
520
+ ref: this._ref
502
521
  };
503
522
  }
504
523
  };
@@ -508,26 +527,22 @@ function createBooleanNode(id, name, options = {}) {
508
527
 
509
528
  // src/core/schema-node/RefNode.ts
510
529
  var RefNode = class _RefNode extends BaseNode {
511
- _ref;
512
530
  constructor(id, name, ref, metadata = EMPTY_METADATA) {
513
- super(id, name, metadata);
531
+ super(id, name, metadata, ref);
514
532
  if (!ref) {
515
533
  throw new Error("RefNode requires a non-empty ref");
516
534
  }
517
- this._ref = ref;
518
535
  this.initBaseObservable();
519
536
  }
520
537
  nodeType() {
521
538
  return "ref";
522
539
  }
523
- isRef() {
524
- return true;
525
- }
526
- ref() {
527
- return this._ref;
528
- }
529
540
  clone() {
530
- return new _RefNode(this.id(), this.name(), this._ref, this.metadata());
541
+ const ref = this.ref();
542
+ if (!ref) {
543
+ throw new Error("RefNode must have a ref value");
544
+ }
545
+ return new _RefNode(this.id(), this.name(), ref, this.metadata());
531
546
  }
532
547
  };
533
548
  function createRefNode(id, name, ref, metadata = EMPTY_METADATA) {
@@ -1747,15 +1762,16 @@ var SchemaSerializer = class {
1747
1762
  if (node.isNull()) {
1748
1763
  throw new Error("Cannot serialize null node");
1749
1764
  }
1765
+ const ref = node.ref();
1766
+ if (ref) {
1767
+ return this.serializeRef(node, ref);
1768
+ }
1750
1769
  if (node.isObject()) {
1751
1770
  return this.serializeObject(node);
1752
1771
  }
1753
1772
  if (node.isArray()) {
1754
1773
  return this.serializeArray(node);
1755
1774
  }
1756
- if (node.isRef()) {
1757
- return this.serializeRef(node);
1758
- }
1759
1775
  return this.serializePrimitive(node);
1760
1776
  }
1761
1777
  serializeObject(node) {
@@ -1787,11 +1803,7 @@ var SchemaSerializer = class {
1787
1803
  };
1788
1804
  return this.addMetadata(result, node);
1789
1805
  }
1790
- serializeRef(node) {
1791
- const ref = node.ref();
1792
- if (!ref) {
1793
- throw new Error("Ref node must have a ref value");
1794
- }
1806
+ serializeRef(node, ref) {
1795
1807
  const result = {
1796
1808
  $ref: ref
1797
1809
  };
@@ -2888,5 +2900,5 @@ function buildArrayItemsPath(parentPath) {
2888
2900
  }
2889
2901
 
2890
2902
  export { AbstractBasePath, ChangeCoalescer, ChangeCollector, CompositeRule, EMPTY_METADATA, EMPTY_PATH, EnumValidator, FIELD_NAME_ERROR_MESSAGE, ForeignKeyValidator, FormulaChangeDetector, FormulaDependencyIndex, FormulaPath, FormulaPathBuilder, FormulaSerializer, ItemsSegment, MaxLengthValidator, MaximumValidator, MinLengthValidator, MinimumValidator, NULL_NODE, NodePathIndex, ParsedFormula, PatchBuilder, PatchEnricher, PatchGenerator, PatternValidator, PropertySegment, RequiredValidator, ResolvedDependency, SchemaDiff, SchemaPropertyRule, SchemaSerializer, SchemaTruthyRule, ValidationEngine, ValidatorRegistry, ValidatorResolver, areNodesContentEqual, areNodesEqual, coalesceChanges, collectChanges, createArrayNode, createBooleanNode, createDefaultValidatorRegistry, createMobxProvider, createNumberNode, createObjectNode, createPath, createRefNode, createSchemaTree, createStringNode, createValidationEngine, isValidFieldName, jsonPointerToPath, jsonPointerToSegments, jsonPointerToSimplePath, makeAutoObservable, makeObservable, observable, reaction, resetReactivityProvider, runInAction, setReactivityProvider, validateFormulas, validateSchema };
2891
- //# sourceMappingURL=chunk-PGR2S2BR.js.map
2892
- //# sourceMappingURL=chunk-PGR2S2BR.js.map
2903
+ //# sourceMappingURL=chunk-7XIWS4W6.js.map
2904
+ //# sourceMappingURL=chunk-7XIWS4W6.js.map