@revisium/schema-toolkit 0.15.0 → 0.16.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.
- package/dist/FormulaValidator-CKE2kT4C.d.cts +10 -0
- package/dist/FormulaValidator-DGGmwqDQ.d.ts +10 -0
- package/dist/{chunk-A4E524UU.cjs → chunk-IWRV6QAD.cjs} +455 -13
- package/dist/chunk-IWRV6QAD.cjs.map +1 -0
- package/dist/{chunk-OP35BPMU.js → chunk-LF6CGXRQ.js} +115 -4
- package/dist/chunk-LF6CGXRQ.js.map +1 -0
- package/dist/{chunk-5WZ4YPH5.cjs → chunk-OR2I3XOQ.cjs} +134 -23
- package/dist/chunk-OR2I3XOQ.cjs.map +1 -0
- package/dist/{chunk-F4UBBZAL.js → chunk-S7GEDTSL.js} +436 -14
- package/dist/chunk-S7GEDTSL.js.map +1 -0
- package/dist/core/index.cjs +109 -352
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +3 -2
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +2 -309
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +48 -32
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/model/index.cjs +32 -32
- package/dist/model/index.d.cts +16 -2
- package/dist/model/index.d.ts +16 -2
- package/dist/model/index.js +2 -2
- package/dist/{types-XDWz0V1v.d.ts → types-Cnfj5nLO.d.ts} +16 -1
- package/dist/{types-CwJ2OWO_.d.cts → types-DMzUCve0.d.cts} +16 -1
- package/package.json +1 -1
- package/dist/chunk-5WZ4YPH5.cjs.map +0 -1
- package/dist/chunk-A4E524UU.cjs.map +0 -1
- package/dist/chunk-F4UBBZAL.js.map +0 -1
- package/dist/chunk-OP35BPMU.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkIWRV6QAD_cjs = require('./chunk-IWRV6QAD.cjs');
|
|
4
4
|
var nanoid = require('nanoid');
|
|
5
5
|
|
|
6
6
|
var SchemaParser = class {
|
|
@@ -15,14 +15,14 @@ var SchemaParser = class {
|
|
|
15
15
|
if (node.isNull()) {
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
|
-
const formula = new
|
|
18
|
+
const formula = new chunkIWRV6QAD_cjs.ParsedFormula(tree, pending.nodeId, pending.expression);
|
|
19
19
|
node.setFormula(formula);
|
|
20
20
|
}
|
|
21
21
|
this.pendingFormulas = [];
|
|
22
22
|
}
|
|
23
23
|
parseNode(schema, name) {
|
|
24
24
|
if ("$ref" in schema) {
|
|
25
|
-
return
|
|
25
|
+
return chunkIWRV6QAD_cjs.createRefNode(
|
|
26
26
|
nanoid.nanoid(),
|
|
27
27
|
name,
|
|
28
28
|
schema.$ref,
|
|
@@ -53,7 +53,7 @@ var SchemaParser = class {
|
|
|
53
53
|
children.push(this.parseNode(propSchema, propName));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
return
|
|
56
|
+
return chunkIWRV6QAD_cjs.createObjectNode(
|
|
57
57
|
nanoid.nanoid(),
|
|
58
58
|
name,
|
|
59
59
|
children,
|
|
@@ -62,7 +62,7 @@ var SchemaParser = class {
|
|
|
62
62
|
}
|
|
63
63
|
parseArray(schema, name) {
|
|
64
64
|
const items = this.parseNode(schema.items, "items");
|
|
65
|
-
return
|
|
65
|
+
return chunkIWRV6QAD_cjs.createArrayNode(
|
|
66
66
|
nanoid.nanoid(),
|
|
67
67
|
name,
|
|
68
68
|
items,
|
|
@@ -72,7 +72,7 @@ var SchemaParser = class {
|
|
|
72
72
|
parseString(schema, name) {
|
|
73
73
|
const nodeId = nanoid.nanoid();
|
|
74
74
|
this.collectFormula(nodeId, schema["x-formula"]);
|
|
75
|
-
return
|
|
75
|
+
return chunkIWRV6QAD_cjs.createStringNode(nodeId, name, {
|
|
76
76
|
defaultValue: schema.default,
|
|
77
77
|
foreignKey: schema.foreignKey,
|
|
78
78
|
metadata: this.extractMetadata(schema)
|
|
@@ -81,7 +81,7 @@ var SchemaParser = class {
|
|
|
81
81
|
parseNumber(schema, name) {
|
|
82
82
|
const nodeId = nanoid.nanoid();
|
|
83
83
|
this.collectFormula(nodeId, schema["x-formula"]);
|
|
84
|
-
return
|
|
84
|
+
return chunkIWRV6QAD_cjs.createNumberNode(nodeId, name, {
|
|
85
85
|
defaultValue: schema.default,
|
|
86
86
|
metadata: this.extractMetadata(schema)
|
|
87
87
|
});
|
|
@@ -89,7 +89,7 @@ var SchemaParser = class {
|
|
|
89
89
|
parseBoolean(schema, name) {
|
|
90
90
|
const nodeId = nanoid.nanoid();
|
|
91
91
|
this.collectFormula(nodeId, schema["x-formula"]);
|
|
92
|
-
return
|
|
92
|
+
return chunkIWRV6QAD_cjs.createBooleanNode(nodeId, name, {
|
|
93
93
|
defaultValue: schema.default,
|
|
94
94
|
metadata: this.extractMetadata(schema)
|
|
95
95
|
});
|
|
@@ -121,13 +121,13 @@ var NodeFactory = class {
|
|
|
121
121
|
createNode(name, type) {
|
|
122
122
|
switch (type) {
|
|
123
123
|
case "string":
|
|
124
|
-
return
|
|
124
|
+
return chunkIWRV6QAD_cjs.createStringNode(nanoid.nanoid(), name, { defaultValue: "" });
|
|
125
125
|
case "number":
|
|
126
|
-
return
|
|
126
|
+
return chunkIWRV6QAD_cjs.createNumberNode(nanoid.nanoid(), name, { defaultValue: 0 });
|
|
127
127
|
case "boolean":
|
|
128
|
-
return
|
|
128
|
+
return chunkIWRV6QAD_cjs.createBooleanNode(nanoid.nanoid(), name, { defaultValue: false });
|
|
129
129
|
case "object":
|
|
130
|
-
return
|
|
130
|
+
return chunkIWRV6QAD_cjs.createObjectNode(nanoid.nanoid(), name, []);
|
|
131
131
|
case "array":
|
|
132
132
|
return this.createArrayNode(name);
|
|
133
133
|
default:
|
|
@@ -135,8 +135,11 @@ var NodeFactory = class {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
createArrayNode(name) {
|
|
138
|
-
const items =
|
|
139
|
-
return
|
|
138
|
+
const items = chunkIWRV6QAD_cjs.createStringNode(nanoid.nanoid(), "items", { defaultValue: "" });
|
|
139
|
+
return chunkIWRV6QAD_cjs.createArrayNode(nanoid.nanoid(), name, items);
|
|
140
|
+
}
|
|
141
|
+
createArrayNodeWithItems(name, items) {
|
|
142
|
+
return chunkIWRV6QAD_cjs.createArrayNode(nanoid.nanoid(), name, items);
|
|
140
143
|
}
|
|
141
144
|
};
|
|
142
145
|
|
|
@@ -232,14 +235,14 @@ var SchemaModelImpl = class {
|
|
|
232
235
|
_baseTree;
|
|
233
236
|
_currentTree;
|
|
234
237
|
_reactivity;
|
|
235
|
-
_patchBuilder = new
|
|
236
|
-
_serializer = new
|
|
238
|
+
_patchBuilder = new chunkIWRV6QAD_cjs.PatchBuilder();
|
|
239
|
+
_serializer = new chunkIWRV6QAD_cjs.SchemaSerializer();
|
|
237
240
|
_nodeFactory = new NodeFactory();
|
|
238
|
-
_formulaIndex = new
|
|
241
|
+
_formulaIndex = new chunkIWRV6QAD_cjs.FormulaDependencyIndex();
|
|
239
242
|
constructor(schema, options) {
|
|
240
243
|
const parser = new SchemaParser();
|
|
241
244
|
const rootNode = parser.parse(schema);
|
|
242
|
-
this._currentTree =
|
|
245
|
+
this._currentTree = chunkIWRV6QAD_cjs.createSchemaTree(rootNode);
|
|
243
246
|
parser.parseFormulas(this._currentTree);
|
|
244
247
|
this._buildFormulaIndex();
|
|
245
248
|
this._baseTree = this._currentTree.clone();
|
|
@@ -261,6 +264,9 @@ var SchemaModelImpl = class {
|
|
|
261
264
|
updateFormula: "action",
|
|
262
265
|
updateForeignKey: "action",
|
|
263
266
|
updateDefaultValue: "action",
|
|
267
|
+
wrapInArray: "action",
|
|
268
|
+
wrapRootInArray: "action",
|
|
269
|
+
replaceRoot: "action",
|
|
264
270
|
markAsSaved: "action",
|
|
265
271
|
revert: "action"
|
|
266
272
|
});
|
|
@@ -329,7 +335,7 @@ var SchemaModelImpl = class {
|
|
|
329
335
|
node.setFormula(void 0);
|
|
330
336
|
this._formulaIndex.unregisterFormula(nodeId);
|
|
331
337
|
} else {
|
|
332
|
-
const formula = new
|
|
338
|
+
const formula = new chunkIWRV6QAD_cjs.ParsedFormula(this._currentTree, nodeId, expression);
|
|
333
339
|
node.setFormula(formula);
|
|
334
340
|
this._formulaIndex.registerFormula(nodeId, formula);
|
|
335
341
|
}
|
|
@@ -348,11 +354,116 @@ var SchemaModelImpl = class {
|
|
|
348
354
|
}
|
|
349
355
|
node.setDefaultValue(value);
|
|
350
356
|
}
|
|
357
|
+
wrapInArray(nodeId) {
|
|
358
|
+
const node = this._currentTree.nodeById(nodeId);
|
|
359
|
+
if (node.isNull() || node.isArray()) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
const path = this._currentTree.pathOf(nodeId);
|
|
363
|
+
if (path.isEmpty()) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
const name = node.name();
|
|
367
|
+
const arrayNode = this._nodeFactory.createArrayNodeWithItems(name, node);
|
|
368
|
+
this._currentTree.setNodeAt(path, arrayNode);
|
|
369
|
+
node.setName("");
|
|
370
|
+
this._currentTree.trackReplacement(nodeId, arrayNode.id());
|
|
371
|
+
return {
|
|
372
|
+
replacedNodeId: nodeId,
|
|
373
|
+
newNodeId: arrayNode.id()
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
wrapRootInArray() {
|
|
377
|
+
const currentRoot = this._currentTree.root();
|
|
378
|
+
if (currentRoot.isArray()) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
const oldId = currentRoot.id();
|
|
382
|
+
const name = currentRoot.name();
|
|
383
|
+
currentRoot.setName("");
|
|
384
|
+
const arrayNode = this._nodeFactory.createArrayNodeWithItems(name, currentRoot);
|
|
385
|
+
this._currentTree.replaceRoot(arrayNode);
|
|
386
|
+
this._currentTree.trackReplacement(oldId, arrayNode.id());
|
|
387
|
+
return {
|
|
388
|
+
replacedNodeId: oldId,
|
|
389
|
+
newNodeId: arrayNode.id()
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
replaceRoot(newType) {
|
|
393
|
+
const currentRoot = this._currentTree.root();
|
|
394
|
+
const oldId = currentRoot.id();
|
|
395
|
+
const name = currentRoot.name();
|
|
396
|
+
const newRoot = this._nodeFactory.createNode(name, newType);
|
|
397
|
+
this._currentTree.replaceRoot(newRoot);
|
|
398
|
+
this._currentTree.trackReplacement(oldId, newRoot.id());
|
|
399
|
+
this._buildFormulaIndex();
|
|
400
|
+
return {
|
|
401
|
+
replacedNodeId: oldId,
|
|
402
|
+
newNodeId: newRoot.id()
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
canMoveNode(nodeId, targetParentId) {
|
|
406
|
+
if (nodeId === targetParentId) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
const node = this._currentTree.nodeById(nodeId);
|
|
410
|
+
if (node.isNull()) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
const target = this._currentTree.nodeById(targetParentId);
|
|
414
|
+
if (target.isNull()) {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
if (!target.isObject()) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
const nodePath = this._currentTree.pathOf(nodeId);
|
|
421
|
+
if (nodePath.isEmpty()) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
const targetPath = this._currentTree.pathOf(targetParentId);
|
|
425
|
+
if (targetPath.equals(nodePath) || targetPath.isChildOf(nodePath)) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
const nodeParentPath = nodePath.parent();
|
|
429
|
+
if (targetPath.equals(nodeParentPath)) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
hasValidDropTarget(nodeId) {
|
|
435
|
+
const node = this._currentTree.nodeById(nodeId);
|
|
436
|
+
if (node.isNull()) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
const nodePath = this._currentTree.pathOf(nodeId);
|
|
440
|
+
if (nodePath.isEmpty()) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
for (const candidateId of this._currentTree.nodeIds()) {
|
|
444
|
+
if (this.canMoveNode(nodeId, candidateId)) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
getFormulaDependents(nodeId) {
|
|
451
|
+
return this._formulaIndex.getDependents(nodeId);
|
|
452
|
+
}
|
|
453
|
+
hasFormulaDependents(nodeId) {
|
|
454
|
+
return this._formulaIndex.hasDependents(nodeId);
|
|
455
|
+
}
|
|
456
|
+
getValidationErrors() {
|
|
457
|
+
return chunkIWRV6QAD_cjs.validateSchema(this._currentTree.root());
|
|
458
|
+
}
|
|
459
|
+
getFormulaErrors() {
|
|
460
|
+
return chunkIWRV6QAD_cjs.validateFormulas(this._currentTree);
|
|
461
|
+
}
|
|
351
462
|
isDirty() {
|
|
352
463
|
return this.getPatches().length > 0;
|
|
353
464
|
}
|
|
354
465
|
isValid() {
|
|
355
|
-
return this._currentTree.root().isObject();
|
|
466
|
+
return this._currentTree.root().isObject() && this.getValidationErrors().length === 0 && this.getFormulaErrors().length === 0;
|
|
356
467
|
}
|
|
357
468
|
getPatches() {
|
|
358
469
|
return this._patchBuilder.build(this._currentTree, this._baseTree);
|
|
@@ -1429,7 +1540,7 @@ var IndexSegment = class {
|
|
|
1429
1540
|
};
|
|
1430
1541
|
|
|
1431
1542
|
// src/core/value-path/ValuePath.ts
|
|
1432
|
-
var ValuePathImpl = class _ValuePathImpl extends
|
|
1543
|
+
var ValuePathImpl = class _ValuePathImpl extends chunkIWRV6QAD_cjs.AbstractBasePath {
|
|
1433
1544
|
asString() {
|
|
1434
1545
|
const parts = [];
|
|
1435
1546
|
for (const seg of this.segs) {
|
|
@@ -2205,5 +2316,5 @@ exports.generateDefaultValue = generateDefaultValue;
|
|
|
2205
2316
|
exports.generateNodeId = generateNodeId;
|
|
2206
2317
|
exports.isForeignKeyValueNode = isForeignKeyValueNode;
|
|
2207
2318
|
exports.resetNodeIdCounter = resetNodeIdCounter;
|
|
2208
|
-
//# sourceMappingURL=chunk-
|
|
2209
|
-
//# sourceMappingURL=chunk-
|
|
2319
|
+
//# sourceMappingURL=chunk-OR2I3XOQ.cjs.map
|
|
2320
|
+
//# sourceMappingURL=chunk-OR2I3XOQ.cjs.map
|