@revisium/schema-toolkit 0.16.4 → 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.
- package/dist/{chunk-PGR2S2BR.js → chunk-7XIWS4W6.js} +54 -42
- package/dist/chunk-7XIWS4W6.js.map +1 -0
- package/dist/{chunk-VGB4YCGF.cjs → chunk-HLGT7PCU.cjs} +54 -42
- package/dist/chunk-HLGT7PCU.cjs.map +1 -0
- package/dist/{chunk-MAEGAVK4.cjs → chunk-I6ZH7HZ7.cjs} +83 -67
- package/dist/chunk-I6ZH7HZ7.cjs.map +1 -0
- package/dist/{chunk-YCJJVI3Z.js → chunk-JHMO5NLL.js} +39 -23
- package/dist/chunk-JHMO5NLL.js.map +1 -0
- package/dist/core/index.cjs +57 -57
- package/dist/core/index.d.cts +13 -2
- package/dist/core/index.d.ts +13 -2
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +95 -95
- package/dist/index.js +2 -2
- package/dist/model/index.cjs +39 -39
- package/dist/model/index.d.cts +2 -1
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-MAEGAVK4.cjs.map +0 -1
- package/dist/chunk-PGR2S2BR.js.map +0 -1
- package/dist/chunk-VGB4YCGF.cjs.map +0 -1
- package/dist/chunk-YCJJVI3Z.js.map +0 -1
|
@@ -181,13 +181,15 @@ function createMobxProvider(mobx) {
|
|
|
181
181
|
|
|
182
182
|
// src/core/schema-node/BaseNode.ts
|
|
183
183
|
var BaseNode = class {
|
|
184
|
-
constructor(_id, name, metadata = EMPTY_METADATA) {
|
|
184
|
+
constructor(_id, name, metadata = EMPTY_METADATA, ref) {
|
|
185
185
|
this._id = _id;
|
|
186
186
|
this._name = name;
|
|
187
187
|
this._metadata = metadata;
|
|
188
|
+
this._ref = ref;
|
|
188
189
|
}
|
|
189
190
|
_name;
|
|
190
191
|
_metadata;
|
|
192
|
+
_ref;
|
|
191
193
|
initBaseObservable() {
|
|
192
194
|
makeObservable(this, {
|
|
193
195
|
_name: "observable",
|
|
@@ -215,7 +217,7 @@ var BaseNode = class {
|
|
|
215
217
|
return false;
|
|
216
218
|
}
|
|
217
219
|
isRef() {
|
|
218
|
-
return
|
|
220
|
+
return this._ref !== void 0;
|
|
219
221
|
}
|
|
220
222
|
isNull() {
|
|
221
223
|
return false;
|
|
@@ -230,7 +232,7 @@ var BaseNode = class {
|
|
|
230
232
|
return NULL_NODE;
|
|
231
233
|
}
|
|
232
234
|
ref() {
|
|
233
|
-
return
|
|
235
|
+
return this._ref;
|
|
234
236
|
}
|
|
235
237
|
formula() {
|
|
236
238
|
return void 0;
|
|
@@ -273,11 +275,26 @@ var BaseNode = class {
|
|
|
273
275
|
}
|
|
274
276
|
};
|
|
275
277
|
|
|
278
|
+
// src/core/schema-node/utils.ts
|
|
279
|
+
function isNodeMetadata(value) {
|
|
280
|
+
if ("ref" in value || "metadata" in value) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return "title" in value || "description" in value || "deprecated" in value;
|
|
284
|
+
}
|
|
285
|
+
function normalizeNodeOptions(options) {
|
|
286
|
+
if (isNodeMetadata(options)) {
|
|
287
|
+
return { metadata: options };
|
|
288
|
+
}
|
|
289
|
+
return options;
|
|
290
|
+
}
|
|
291
|
+
|
|
276
292
|
// src/core/schema-node/ObjectNode.ts
|
|
277
293
|
var ObjectNode = class _ObjectNode extends BaseNode {
|
|
278
294
|
_children;
|
|
279
|
-
constructor(id, name, children = [],
|
|
280
|
-
|
|
295
|
+
constructor(id, name, children = [], optionsOrMetadata = {}) {
|
|
296
|
+
const options = normalizeNodeOptions(optionsOrMetadata);
|
|
297
|
+
super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
|
|
281
298
|
this._children = [...children];
|
|
282
299
|
this.initBaseObservable();
|
|
283
300
|
makeObservable(this, {
|
|
@@ -304,7 +321,7 @@ var ObjectNode = class _ObjectNode extends BaseNode {
|
|
|
304
321
|
this.id(),
|
|
305
322
|
this.name(),
|
|
306
323
|
this._children.map((child) => child.clone()),
|
|
307
|
-
this.metadata()
|
|
324
|
+
{ metadata: this.metadata(), ref: this._ref }
|
|
308
325
|
);
|
|
309
326
|
}
|
|
310
327
|
addChild(node) {
|
|
@@ -327,15 +344,16 @@ var ObjectNode = class _ObjectNode extends BaseNode {
|
|
|
327
344
|
return true;
|
|
328
345
|
}
|
|
329
346
|
};
|
|
330
|
-
function createObjectNode(id, name, children = [],
|
|
331
|
-
return new ObjectNode(id, name, children,
|
|
347
|
+
function createObjectNode(id, name, children = [], options = {}) {
|
|
348
|
+
return new ObjectNode(id, name, children, options);
|
|
332
349
|
}
|
|
333
350
|
|
|
334
351
|
// src/core/schema-node/ArrayNode.ts
|
|
335
352
|
var ArrayNode = class _ArrayNode extends BaseNode {
|
|
336
353
|
_items;
|
|
337
|
-
constructor(id, name, items,
|
|
338
|
-
|
|
354
|
+
constructor(id, name, items, optionsOrMetadata = {}) {
|
|
355
|
+
const options = normalizeNodeOptions(optionsOrMetadata);
|
|
356
|
+
super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
|
|
339
357
|
this._items = items;
|
|
340
358
|
this.initBaseObservable();
|
|
341
359
|
makeObservable(this, {
|
|
@@ -356,19 +374,17 @@ var ArrayNode = class _ArrayNode extends BaseNode {
|
|
|
356
374
|
return this._items;
|
|
357
375
|
}
|
|
358
376
|
clone() {
|
|
359
|
-
return new _ArrayNode(
|
|
360
|
-
this.
|
|
361
|
-
this.
|
|
362
|
-
|
|
363
|
-
this.metadata()
|
|
364
|
-
);
|
|
377
|
+
return new _ArrayNode(this.id(), this.name(), this._items.clone(), {
|
|
378
|
+
metadata: this.metadata(),
|
|
379
|
+
ref: this._ref
|
|
380
|
+
});
|
|
365
381
|
}
|
|
366
382
|
setItems(node) {
|
|
367
383
|
this._items = node;
|
|
368
384
|
}
|
|
369
385
|
};
|
|
370
|
-
function createArrayNode(id, name, items,
|
|
371
|
-
return new ArrayNode(id, name, items,
|
|
386
|
+
function createArrayNode(id, name, items, options = {}) {
|
|
387
|
+
return new ArrayNode(id, name, items, options);
|
|
372
388
|
}
|
|
373
389
|
|
|
374
390
|
// src/core/schema-node/PrimitiveNode.ts
|
|
@@ -377,7 +393,7 @@ var PrimitiveNode = class extends BaseNode {
|
|
|
377
393
|
_foreignKey;
|
|
378
394
|
_formula;
|
|
379
395
|
constructor(id, name, options = {}) {
|
|
380
|
-
super(id, name, options.metadata ?? EMPTY_METADATA);
|
|
396
|
+
super(id, name, options.metadata ?? EMPTY_METADATA, options.ref);
|
|
381
397
|
this._defaultValue = options.defaultValue;
|
|
382
398
|
this._foreignKey = options.foreignKey;
|
|
383
399
|
this._formula = options.formula;
|
|
@@ -452,7 +468,8 @@ var StringNode = class _StringNode extends PrimitiveNode {
|
|
|
452
468
|
foreignKey: this._foreignKey,
|
|
453
469
|
formula: this._formula,
|
|
454
470
|
metadata: this._metadata,
|
|
455
|
-
contentMediaType: this._contentMediaType
|
|
471
|
+
contentMediaType: this._contentMediaType,
|
|
472
|
+
ref: this._ref
|
|
456
473
|
};
|
|
457
474
|
}
|
|
458
475
|
};
|
|
@@ -476,7 +493,8 @@ var NumberNode = class _NumberNode extends PrimitiveNode {
|
|
|
476
493
|
return {
|
|
477
494
|
defaultValue: this._defaultValue,
|
|
478
495
|
formula: this._formula,
|
|
479
|
-
metadata: this._metadata
|
|
496
|
+
metadata: this._metadata,
|
|
497
|
+
ref: this._ref
|
|
480
498
|
};
|
|
481
499
|
}
|
|
482
500
|
};
|
|
@@ -500,7 +518,8 @@ var BooleanNode = class _BooleanNode extends PrimitiveNode {
|
|
|
500
518
|
return {
|
|
501
519
|
defaultValue: this._defaultValue,
|
|
502
520
|
formula: this._formula,
|
|
503
|
-
metadata: this._metadata
|
|
521
|
+
metadata: this._metadata,
|
|
522
|
+
ref: this._ref
|
|
504
523
|
};
|
|
505
524
|
}
|
|
506
525
|
};
|
|
@@ -510,26 +529,22 @@ function createBooleanNode(id, name, options = {}) {
|
|
|
510
529
|
|
|
511
530
|
// src/core/schema-node/RefNode.ts
|
|
512
531
|
var RefNode = class _RefNode extends BaseNode {
|
|
513
|
-
_ref;
|
|
514
532
|
constructor(id, name, ref, metadata = EMPTY_METADATA) {
|
|
515
|
-
super(id, name, metadata);
|
|
533
|
+
super(id, name, metadata, ref);
|
|
516
534
|
if (!ref) {
|
|
517
535
|
throw new Error("RefNode requires a non-empty ref");
|
|
518
536
|
}
|
|
519
|
-
this._ref = ref;
|
|
520
537
|
this.initBaseObservable();
|
|
521
538
|
}
|
|
522
539
|
nodeType() {
|
|
523
540
|
return "ref";
|
|
524
541
|
}
|
|
525
|
-
isRef() {
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
ref() {
|
|
529
|
-
return this._ref;
|
|
530
|
-
}
|
|
531
542
|
clone() {
|
|
532
|
-
|
|
543
|
+
const ref = this.ref();
|
|
544
|
+
if (!ref) {
|
|
545
|
+
throw new Error("RefNode must have a ref value");
|
|
546
|
+
}
|
|
547
|
+
return new _RefNode(this.id(), this.name(), ref, this.metadata());
|
|
533
548
|
}
|
|
534
549
|
};
|
|
535
550
|
function createRefNode(id, name, ref, metadata = EMPTY_METADATA) {
|
|
@@ -1749,15 +1764,16 @@ var SchemaSerializer = class {
|
|
|
1749
1764
|
if (node.isNull()) {
|
|
1750
1765
|
throw new Error("Cannot serialize null node");
|
|
1751
1766
|
}
|
|
1767
|
+
const ref = node.ref();
|
|
1768
|
+
if (ref) {
|
|
1769
|
+
return this.serializeRef(node, ref);
|
|
1770
|
+
}
|
|
1752
1771
|
if (node.isObject()) {
|
|
1753
1772
|
return this.serializeObject(node);
|
|
1754
1773
|
}
|
|
1755
1774
|
if (node.isArray()) {
|
|
1756
1775
|
return this.serializeArray(node);
|
|
1757
1776
|
}
|
|
1758
|
-
if (node.isRef()) {
|
|
1759
|
-
return this.serializeRef(node);
|
|
1760
|
-
}
|
|
1761
1777
|
return this.serializePrimitive(node);
|
|
1762
1778
|
}
|
|
1763
1779
|
serializeObject(node) {
|
|
@@ -1789,11 +1805,7 @@ var SchemaSerializer = class {
|
|
|
1789
1805
|
};
|
|
1790
1806
|
return this.addMetadata(result, node);
|
|
1791
1807
|
}
|
|
1792
|
-
serializeRef(node) {
|
|
1793
|
-
const ref = node.ref();
|
|
1794
|
-
if (!ref) {
|
|
1795
|
-
throw new Error("Ref node must have a ref value");
|
|
1796
|
-
}
|
|
1808
|
+
serializeRef(node, ref) {
|
|
1797
1809
|
const result = {
|
|
1798
1810
|
$ref: ref
|
|
1799
1811
|
};
|
|
@@ -2953,5 +2965,5 @@ exports.runInAction = runInAction;
|
|
|
2953
2965
|
exports.setReactivityProvider = setReactivityProvider;
|
|
2954
2966
|
exports.validateFormulas = validateFormulas;
|
|
2955
2967
|
exports.validateSchema = validateSchema;
|
|
2956
|
-
//# sourceMappingURL=chunk-
|
|
2957
|
-
//# sourceMappingURL=chunk-
|
|
2968
|
+
//# sourceMappingURL=chunk-HLGT7PCU.cjs.map
|
|
2969
|
+
//# sourceMappingURL=chunk-HLGT7PCU.cjs.map
|