@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.
- package/README.md +216 -0
- package/dist/FormulaPathBuilder-BUJRR0Am.d.cts +48 -0
- package/dist/FormulaPathBuilder-QR0htn-e.d.ts +48 -0
- package/dist/{chunk-VGADCIBG.cjs → chunk-2PIMJSWJ.cjs} +12 -8
- package/dist/chunk-3MJP73IJ.js +1 -0
- package/dist/{chunk-LLHQWDAR.js → chunk-4U2RZHMX.js} +19 -21
- package/dist/{chunk-Q2UOTIMG.js → chunk-5DUMJHCA.js} +0 -2
- package/dist/{chunk-V6JTSET2.cjs → chunk-7JWCZZPJ.cjs} +49 -51
- package/dist/{chunk-YFWOURZL.js → chunk-7PEC6ZYY.js} +0 -2
- package/dist/chunk-AV5EZUMZ.cjs +2 -0
- package/dist/{chunk-3JZKQWQH.js → chunk-AWFMSOHM.js} +5 -7
- package/dist/{chunk-X2VRR7V7.cjs → chunk-ERW5XVED.cjs} +0 -2
- package/dist/{chunk-XNFSFT7T.cjs → chunk-EVD5ZI55.cjs} +0 -2
- package/dist/{chunk-ZRNFSUOV.cjs → chunk-FL6PWPVJ.cjs} +0 -2
- package/dist/{chunk-55AMH44G.js → chunk-FTBRJODD.js} +28 -30
- package/dist/{chunk-R3MS2N4A.js → chunk-GJM63Q4K.js} +0 -2
- package/dist/{chunk-U5YDA3LA.js → chunk-HFMZITNE.js} +238 -31
- package/dist/{chunk-EGC32GPY.cjs → chunk-ITYABUR5.cjs} +19 -21
- package/dist/{chunk-R4CFU33U.js → chunk-IZMBM36H.js} +10 -9
- package/dist/chunk-J4RVO37K.cjs +2 -0
- package/dist/{chunk-QEV4Q4TR.js → chunk-JLXX3SGF.js} +30 -32
- package/dist/{chunk-MPF6VCB5.js → chunk-NO655UI5.js} +0 -2
- package/dist/chunk-OAUVP6CU.js +1 -0
- package/dist/{chunk-B3T6YB2D.cjs → chunk-ONW2OVNQ.cjs} +28 -30
- package/dist/{chunk-32FZHFIO.cjs → chunk-QKA7DJDN.cjs} +0 -2
- package/dist/{chunk-46ME2TAU.cjs → chunk-RCCBUOGY.cjs} +5 -7
- package/dist/{chunk-IPL2CGVA.cjs → chunk-RQBW7ATZ.cjs} +0 -2
- package/dist/{chunk-FZ2MS4Q5.cjs → chunk-S5SRXND6.cjs} +307 -97
- package/dist/{chunk-WSPFHUHU.cjs → chunk-T3QQSHAC.cjs} +0 -2
- package/dist/{chunk-J6SCHJKG.cjs → chunk-VMELKZXD.cjs} +0 -2
- package/dist/{chunk-5VDDLW7U.js → chunk-WE4OLW5U.js} +0 -2
- package/dist/{chunk-JUOGJFTL.js → chunk-XKWWCXGB.js} +0 -2
- package/dist/{chunk-ZBPUTF3Q.js → chunk-ZPRBA4AQ.js} +0 -2
- package/dist/consts/index.cjs +4 -6
- package/dist/consts/index.js +2 -4
- package/dist/core/index.cjs +65 -69
- package/dist/core/index.d.cts +6 -4
- package/dist/core/index.d.ts +6 -4
- package/dist/core/index.js +4 -8
- package/dist/formula/index.cjs +7 -9
- package/dist/formula/index.d.cts +1 -1
- package/dist/formula/index.d.ts +1 -1
- package/dist/formula/index.js +1 -3
- package/dist/index.cjs +269 -248
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +15 -18
- package/dist/{json-patch.types-DY7k9hxy.d.ts → json-patch.types-BpVnp08Z.d.ts} +1 -1
- package/dist/{json-patch.types-Cu0Medki.d.cts → json-patch.types-eM6pYC2P.d.cts} +1 -1
- package/dist/{json-string.store-C58zbl31.d.ts → json-string.store-DfdLcgnM.d.ts} +11 -11
- package/dist/{json-string.store-DuI--IL2.d.cts → json-string.store-cAOADo23.d.cts} +11 -11
- package/dist/lib/index.cjs +51 -54
- package/dist/lib/index.d.cts +3 -3
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +7 -10
- package/dist/mocks/index.cjs +30 -21
- package/dist/mocks/index.d.cts +22 -8
- package/dist/mocks/index.d.ts +22 -8
- package/dist/mocks/index.js +2 -5
- package/dist/model/index.cjs +85 -78
- package/dist/model/index.d.cts +171 -346
- package/dist/model/index.d.ts +171 -346
- package/dist/model/index.js +4 -9
- package/dist/plugins/index.cjs +20 -23
- package/dist/plugins/index.d.cts +10 -10
- package/dist/plugins/index.d.ts +10 -10
- package/dist/plugins/index.js +2 -5
- package/dist/{schema.types-B5OgKLpV.d.cts → schema.types-On_VGw2m.d.cts} +7 -6
- package/dist/{schema.types-B5OgKLpV.d.ts → schema.types-On_VGw2m.d.ts} +7 -6
- package/dist/typed-BRZhUqGG.d.ts +502 -0
- package/dist/typed-Cri0IYAn.d.cts +502 -0
- package/dist/types/index.cjs +6 -9
- package/dist/types/index.d.cts +7 -5
- package/dist/types/index.d.ts +7 -5
- package/dist/types/index.js +2 -5
- package/dist/{FormulaPathBuilder-DwlKOvVB.d.ts → types-BIvIURgy.d.cts} +37 -82
- package/dist/{FormulaPathBuilder-D9LkBcSv.d.cts → types-C_pTFtSY.d.ts} +37 -82
- package/dist/validation-schemas/index.cjs +18 -20
- package/dist/validation-schemas/index.js +1 -3
- package/package.json +1 -1
- package/dist/chunk-32FZHFIO.cjs.map +0 -1
- package/dist/chunk-3FJZMVWA.js +0 -3
- package/dist/chunk-3FJZMVWA.js.map +0 -1
- package/dist/chunk-3IKI64T2.js +0 -3
- package/dist/chunk-3IKI64T2.js.map +0 -1
- package/dist/chunk-3JZKQWQH.js.map +0 -1
- package/dist/chunk-46ME2TAU.cjs.map +0 -1
- package/dist/chunk-55AMH44G.js.map +0 -1
- package/dist/chunk-5VDDLW7U.js.map +0 -1
- package/dist/chunk-B3T6YB2D.cjs.map +0 -1
- package/dist/chunk-EGC32GPY.cjs.map +0 -1
- package/dist/chunk-FZ2MS4Q5.cjs.map +0 -1
- package/dist/chunk-G6ZKEVVU.cjs +0 -4
- package/dist/chunk-G6ZKEVVU.cjs.map +0 -1
- package/dist/chunk-IPL2CGVA.cjs.map +0 -1
- package/dist/chunk-J6SCHJKG.cjs.map +0 -1
- package/dist/chunk-JUOGJFTL.js.map +0 -1
- package/dist/chunk-L6HE7QPU.cjs +0 -4
- package/dist/chunk-L6HE7QPU.cjs.map +0 -1
- package/dist/chunk-LLHQWDAR.js.map +0 -1
- package/dist/chunk-MPF6VCB5.js.map +0 -1
- package/dist/chunk-NY3H6C7K.js +0 -3
- package/dist/chunk-NY3H6C7K.js.map +0 -1
- package/dist/chunk-Q2UOTIMG.js.map +0 -1
- package/dist/chunk-QEV4Q4TR.js.map +0 -1
- package/dist/chunk-R3MS2N4A.js.map +0 -1
- package/dist/chunk-R4CFU33U.js.map +0 -1
- package/dist/chunk-TBFTADML.cjs +0 -4
- package/dist/chunk-TBFTADML.cjs.map +0 -1
- package/dist/chunk-U5YDA3LA.js.map +0 -1
- package/dist/chunk-V6JTSET2.cjs.map +0 -1
- package/dist/chunk-VGADCIBG.cjs.map +0 -1
- package/dist/chunk-WSPFHUHU.cjs.map +0 -1
- package/dist/chunk-X2VRR7V7.cjs.map +0 -1
- package/dist/chunk-XNFSFT7T.cjs.map +0 -1
- package/dist/chunk-YFWOURZL.js.map +0 -1
- package/dist/chunk-ZBPUTF3Q.js.map +0 -1
- package/dist/chunk-ZRNFSUOV.cjs.map +0 -1
- package/dist/consts/index.cjs.map +0 -1
- package/dist/consts/index.js.map +0 -1
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/formula/index.cjs.map +0 -1
- package/dist/formula/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json-value-patch.types-CgiEpchp.d.ts +0 -24
- package/dist/json-value-patch.types-LEJxcIWR.d.cts +0 -24
- package/dist/lib/index.cjs.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/mocks/index.cjs.map +0 -1
- package/dist/mocks/index.js.map +0 -1
- package/dist/model/index.cjs.map +0 -1
- package/dist/model/index.js.map +0 -1
- package/dist/plugins/index.cjs.map +0 -1
- package/dist/plugins/index.js.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/validation-schemas/index.cjs.map +0 -1
- package/dist/validation-schemas/index.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { AbstractBasePath, EMPTY_PATH, FormulaError, ResolvedDependency, FormulaSerializer, createRefNode, createObjectNode, createArrayNode, createStringNode, createNumberNode, createBooleanNode, observable, makeObservable, makeAutoObservable, runInAction, PatchBuilder, SchemaSerializer, createSchemaTree, NULL_NODE, validateSchema, validateFormulas, reaction } from './chunk-
|
|
2
|
-
import { obj, ref } from './chunk-
|
|
1
|
+
import { AbstractBasePath, EMPTY_PATH, FormulaError, ResolvedDependency, FormulaSerializer, createRefNode, createObjectNode, createArrayNode, createStringNode, createNumberNode, createBooleanNode, observable, makeObservable, makeAutoObservable, runInAction, PatchBuilder, SchemaSerializer, createSchemaTree, NULL_NODE, validateSchema, validateFormulas, reaction } from './chunk-AWFMSOHM.js';
|
|
2
|
+
import { obj, ref } from './chunk-IZMBM36H.js';
|
|
3
3
|
import { nanoid } from 'nanoid';
|
|
4
4
|
import { parseFormula, parseExpression, evaluateWithContext } from '@revisium/formula';
|
|
5
|
+
import { EventEmitter } from 'eventemitter3';
|
|
5
6
|
|
|
6
7
|
var ARRAY_NOTATION_REGEX = /^([^[]+)\[(?:\d+|\*)?\]$/;
|
|
7
8
|
var FormulaPath = class {
|
|
@@ -343,15 +344,15 @@ var SchemaParser = class {
|
|
|
343
344
|
}
|
|
344
345
|
const schemaWithType = schema;
|
|
345
346
|
switch (schemaWithType.type) {
|
|
346
|
-
case "object"
|
|
347
|
+
case "object":
|
|
347
348
|
return this.parseObject(schemaWithType, name, parentRef);
|
|
348
|
-
case "array"
|
|
349
|
+
case "array":
|
|
349
350
|
return this.parseArray(schemaWithType, name, parentRef);
|
|
350
|
-
case "string"
|
|
351
|
+
case "string":
|
|
351
352
|
return this.parseString(schemaWithType, name, parentRef);
|
|
352
|
-
case "number"
|
|
353
|
+
case "number":
|
|
353
354
|
return this.parseNumber(schemaWithType, name, parentRef);
|
|
354
|
-
case "boolean"
|
|
355
|
+
case "boolean":
|
|
355
356
|
return this.parseBoolean(schemaWithType, name, parentRef);
|
|
356
357
|
default:
|
|
357
358
|
throw new Error(`Unknown schema type: ${schemaWithType.type}`);
|
|
@@ -462,10 +463,10 @@ function isRefSchema(schema) {
|
|
|
462
463
|
return "$ref" in schema;
|
|
463
464
|
}
|
|
464
465
|
function isObjectSchema(schema) {
|
|
465
|
-
return "type" in schema && schema.type === "object"
|
|
466
|
+
return "type" in schema && schema.type === "object";
|
|
466
467
|
}
|
|
467
468
|
function isArraySchema(schema) {
|
|
468
|
-
return "type" in schema && schema.type === "array"
|
|
469
|
+
return "type" in schema && schema.type === "array";
|
|
469
470
|
}
|
|
470
471
|
function hasDefaultValue(schema) {
|
|
471
472
|
return "default" in schema && schema.default !== void 0;
|
|
@@ -475,11 +476,11 @@ function generatePrimitiveDefault(schema) {
|
|
|
475
476
|
return void 0;
|
|
476
477
|
}
|
|
477
478
|
switch (schema.type) {
|
|
478
|
-
case "string"
|
|
479
|
+
case "string":
|
|
479
480
|
return DEFAULT_STRING;
|
|
480
|
-
case "number"
|
|
481
|
+
case "number":
|
|
481
482
|
return DEFAULT_NUMBER;
|
|
482
|
-
case "boolean"
|
|
483
|
+
case "boolean":
|
|
483
484
|
return DEFAULT_BOOLEAN;
|
|
484
485
|
default:
|
|
485
486
|
return void 0;
|
|
@@ -1598,8 +1599,6 @@ var FormulaEngine = class {
|
|
|
1598
1599
|
this.disposers = [];
|
|
1599
1600
|
}
|
|
1600
1601
|
};
|
|
1601
|
-
|
|
1602
|
-
// src/model/value-node/BaseValueNode.ts
|
|
1603
1602
|
var nodeIdCounter = 0;
|
|
1604
1603
|
function generateNodeId() {
|
|
1605
1604
|
return `node-${++nodeIdCounter}`;
|
|
@@ -1612,11 +1611,21 @@ var BaseValueNode = class {
|
|
|
1612
1611
|
schema;
|
|
1613
1612
|
_parent = null;
|
|
1614
1613
|
_name;
|
|
1614
|
+
_emitter = new EventEmitter();
|
|
1615
1615
|
constructor(id, name, schema) {
|
|
1616
1616
|
this.id = id ?? generateNodeId();
|
|
1617
1617
|
this._name = name;
|
|
1618
1618
|
this.schema = schema;
|
|
1619
1619
|
}
|
|
1620
|
+
on(event, listener) {
|
|
1621
|
+
this._emitter.on(event, listener);
|
|
1622
|
+
}
|
|
1623
|
+
off(event, listener) {
|
|
1624
|
+
this._emitter.off(event, listener);
|
|
1625
|
+
}
|
|
1626
|
+
emit(changeEvent) {
|
|
1627
|
+
this._emitter.emit("change", changeEvent);
|
|
1628
|
+
}
|
|
1620
1629
|
get parent() {
|
|
1621
1630
|
return this._parent;
|
|
1622
1631
|
}
|
|
@@ -1700,7 +1709,8 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1700
1709
|
commit: "action",
|
|
1701
1710
|
revert: "action",
|
|
1702
1711
|
pushValue: "action",
|
|
1703
|
-
insertValueAt: "action"
|
|
1712
|
+
insertValueAt: "action",
|
|
1713
|
+
setValue: "action"
|
|
1704
1714
|
});
|
|
1705
1715
|
}
|
|
1706
1716
|
get value() {
|
|
@@ -1721,6 +1731,7 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1721
1731
|
push(node) {
|
|
1722
1732
|
node.parent = this;
|
|
1723
1733
|
this._items.push(node);
|
|
1734
|
+
this.emit({ type: "arrayPush", array: this, item: node });
|
|
1724
1735
|
}
|
|
1725
1736
|
insertAt(index, node) {
|
|
1726
1737
|
if (index < 0 || index > this._items.length) {
|
|
@@ -1728,6 +1739,7 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1728
1739
|
}
|
|
1729
1740
|
node.parent = this;
|
|
1730
1741
|
this._items.splice(index, 0, node);
|
|
1742
|
+
this.emit({ type: "arrayInsert", array: this, index, item: node });
|
|
1731
1743
|
}
|
|
1732
1744
|
removeAt(index) {
|
|
1733
1745
|
if (index < 0 || index >= this._items.length) {
|
|
@@ -1737,6 +1749,7 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1737
1749
|
if (removed) {
|
|
1738
1750
|
removed.parent = null;
|
|
1739
1751
|
}
|
|
1752
|
+
this.emit({ type: "arrayRemove", array: this, index, item: removed });
|
|
1740
1753
|
}
|
|
1741
1754
|
move(fromIndex, toIndex) {
|
|
1742
1755
|
if (fromIndex < 0 || fromIndex >= this._items.length) {
|
|
@@ -1752,23 +1765,25 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1752
1765
|
if (item) {
|
|
1753
1766
|
this._items.splice(toIndex, 0, item);
|
|
1754
1767
|
}
|
|
1768
|
+
this.emit({ type: "arrayMove", array: this, fromIndex, toIndex });
|
|
1755
1769
|
}
|
|
1756
1770
|
replaceAt(index, node) {
|
|
1757
1771
|
if (index < 0 || index >= this._items.length) {
|
|
1758
1772
|
throw new Error(`Index out of bounds: ${index}`);
|
|
1759
1773
|
}
|
|
1760
1774
|
const oldNode = this._items[index];
|
|
1761
|
-
|
|
1762
|
-
oldNode.parent = null;
|
|
1763
|
-
}
|
|
1775
|
+
oldNode.parent = null;
|
|
1764
1776
|
node.parent = this;
|
|
1765
1777
|
this._items[index] = node;
|
|
1778
|
+
this.emit({ type: "arrayReplace", array: this, index, item: node, oldItem: oldNode });
|
|
1766
1779
|
}
|
|
1767
1780
|
clear() {
|
|
1768
|
-
|
|
1781
|
+
const removed = [...this._items];
|
|
1782
|
+
for (const item of removed) {
|
|
1769
1783
|
item.parent = null;
|
|
1770
1784
|
}
|
|
1771
1785
|
this._items.length = 0;
|
|
1786
|
+
this.emit({ type: "arrayClear", array: this, items: removed });
|
|
1772
1787
|
}
|
|
1773
1788
|
setNodeFactory(factory) {
|
|
1774
1789
|
this._nodeFactory = factory;
|
|
@@ -1781,6 +1796,32 @@ var ArrayValueNode = class extends BaseValueNode {
|
|
|
1781
1796
|
const node = this.createItemNode(index, value);
|
|
1782
1797
|
this.insertAt(index, node);
|
|
1783
1798
|
}
|
|
1799
|
+
setValue(value, options) {
|
|
1800
|
+
const commonLength = Math.min(this._items.length, value.length);
|
|
1801
|
+
for (let i = 0; i < commonLength; i++) {
|
|
1802
|
+
const item = this._items[i];
|
|
1803
|
+
if (!item) {
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
const itemValue = value[i];
|
|
1807
|
+
if (item.isObject()) {
|
|
1808
|
+
item.setValue(itemValue, options);
|
|
1809
|
+
} else if (item.isArray()) {
|
|
1810
|
+
item.setValue(itemValue, options);
|
|
1811
|
+
} else if (item.isPrimitive()) {
|
|
1812
|
+
item.setValue(itemValue, options);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (value.length > this._items.length) {
|
|
1816
|
+
for (let i = this._items.length; i < value.length; i++) {
|
|
1817
|
+
this.pushValue(value[i]);
|
|
1818
|
+
}
|
|
1819
|
+
} else if (value.length < this._items.length) {
|
|
1820
|
+
for (let i = this._items.length - 1; i >= value.length; i--) {
|
|
1821
|
+
this.removeAt(i);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1784
1825
|
createItemNode(index, value) {
|
|
1785
1826
|
if (!this._nodeFactory) {
|
|
1786
1827
|
throw new Error("NodeFactory not set");
|
|
@@ -1909,6 +1950,9 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
|
|
|
1909
1950
|
return this._baseValue;
|
|
1910
1951
|
}
|
|
1911
1952
|
get isDirty() {
|
|
1953
|
+
if (this.formula !== void 0) {
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1912
1956
|
return this._value !== this._baseValue;
|
|
1913
1957
|
}
|
|
1914
1958
|
get formula() {
|
|
@@ -1928,7 +1972,11 @@ var BasePrimitiveValueNode = class extends BaseValueNode {
|
|
|
1928
1972
|
if (this.isReadOnly && !options?.internal) {
|
|
1929
1973
|
throw new Error(`Cannot set value on read-only field: ${this.name}`);
|
|
1930
1974
|
}
|
|
1975
|
+
const oldValue = this._value;
|
|
1931
1976
|
this._value = this.coerceValue(value);
|
|
1977
|
+
if (!options?.internal) {
|
|
1978
|
+
this.emit({ type: "setValue", node: this, value: this._value, oldValue });
|
|
1979
|
+
}
|
|
1932
1980
|
}
|
|
1933
1981
|
setFormulaWarning(warning) {
|
|
1934
1982
|
this._formulaWarning = warning;
|
|
@@ -2184,7 +2232,7 @@ var NumberValueNode = class extends BasePrimitiveValueNode {
|
|
|
2184
2232
|
}
|
|
2185
2233
|
computeErrors() {
|
|
2186
2234
|
const errors = [];
|
|
2187
|
-
if (!("type" in this.schema) || this.schema.type !== "number"
|
|
2235
|
+
if (!("type" in this.schema) || this.schema.type !== "number") {
|
|
2188
2236
|
return errors;
|
|
2189
2237
|
}
|
|
2190
2238
|
const numberSchema = this.schema;
|
|
@@ -2248,6 +2296,7 @@ var ObjectValueNode = class extends BaseValueNode {
|
|
|
2248
2296
|
warnings: "computed",
|
|
2249
2297
|
addChild: "action",
|
|
2250
2298
|
removeChild: "action",
|
|
2299
|
+
setValue: "action",
|
|
2251
2300
|
commit: "action",
|
|
2252
2301
|
revert: "action"
|
|
2253
2302
|
});
|
|
@@ -2278,12 +2327,29 @@ var ObjectValueNode = class extends BaseValueNode {
|
|
|
2278
2327
|
}
|
|
2279
2328
|
node.parent = this;
|
|
2280
2329
|
this._children.set(node.name, node);
|
|
2330
|
+
this.emit({ type: "addChild", parent: this, child: node });
|
|
2281
2331
|
}
|
|
2282
2332
|
removeChild(name) {
|
|
2283
2333
|
const node = this._children.get(name);
|
|
2284
2334
|
if (node) {
|
|
2285
2335
|
node.parent = null;
|
|
2286
2336
|
this._children.delete(name);
|
|
2337
|
+
this.emit({ type: "removeChild", parent: this, childName: name, child: node });
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
setValue(value, options) {
|
|
2341
|
+
for (const [key, child] of this._children) {
|
|
2342
|
+
if (!(key in value)) {
|
|
2343
|
+
continue;
|
|
2344
|
+
}
|
|
2345
|
+
const childValue = value[key];
|
|
2346
|
+
if (child.isObject()) {
|
|
2347
|
+
child.setValue(childValue, options);
|
|
2348
|
+
} else if (child.isArray()) {
|
|
2349
|
+
child.setValue(childValue, options);
|
|
2350
|
+
} else if (child.isPrimitive()) {
|
|
2351
|
+
child.setValue(childValue, options);
|
|
2352
|
+
}
|
|
2287
2353
|
}
|
|
2288
2354
|
}
|
|
2289
2355
|
get isDirty() {
|
|
@@ -2794,16 +2860,22 @@ var ValueTree = class {
|
|
|
2794
2860
|
this._root = _root;
|
|
2795
2861
|
this.index = new TreeIndex(_root);
|
|
2796
2862
|
this.changeTracker = new ChangeTracker();
|
|
2863
|
+
this._nodeChangeListener = (event) => this.handleNodeChange(event);
|
|
2864
|
+
this.subscribe(this._root);
|
|
2797
2865
|
makeAutoObservable(this, {
|
|
2798
2866
|
_root: false,
|
|
2799
2867
|
index: false,
|
|
2800
2868
|
changeTracker: false,
|
|
2801
|
-
|
|
2869
|
+
_nodeChangeListener: false,
|
|
2870
|
+
_formulaEngine: false,
|
|
2871
|
+
_suppressEvents: false
|
|
2802
2872
|
});
|
|
2803
2873
|
}
|
|
2804
2874
|
index;
|
|
2805
2875
|
changeTracker;
|
|
2876
|
+
_nodeChangeListener;
|
|
2806
2877
|
_formulaEngine = null;
|
|
2878
|
+
_suppressEvents = false;
|
|
2807
2879
|
get root() {
|
|
2808
2880
|
return this._root;
|
|
2809
2881
|
}
|
|
@@ -2841,20 +2913,28 @@ var ValueTree = class {
|
|
|
2841
2913
|
const node = this.get(path);
|
|
2842
2914
|
return node?.getPlainValue();
|
|
2843
2915
|
}
|
|
2844
|
-
setValue(path, value) {
|
|
2916
|
+
setValue(path, value, options) {
|
|
2845
2917
|
const node = this.get(path);
|
|
2846
2918
|
if (!node) {
|
|
2847
2919
|
throw new Error(`Path not found: ${path}`);
|
|
2848
2920
|
}
|
|
2849
|
-
|
|
2850
|
-
|
|
2921
|
+
const oldValue = node.getPlainValue();
|
|
2922
|
+
this._suppressEvents = true;
|
|
2923
|
+
try {
|
|
2924
|
+
if (node.isPrimitive()) {
|
|
2925
|
+
node.setValue(value, options);
|
|
2926
|
+
} else if (node.isObject()) {
|
|
2927
|
+
node.setValue(value, options);
|
|
2928
|
+
} else if (node.isArray()) {
|
|
2929
|
+
node.setValue(value, options);
|
|
2930
|
+
}
|
|
2931
|
+
} finally {
|
|
2932
|
+
this._suppressEvents = false;
|
|
2851
2933
|
}
|
|
2852
|
-
const oldValue = node.value;
|
|
2853
|
-
node.setValue(value);
|
|
2854
2934
|
this.changeTracker.track({
|
|
2855
2935
|
type: "setValue",
|
|
2856
2936
|
path: this.index.pathOf(node),
|
|
2857
|
-
value,
|
|
2937
|
+
value: node.getPlainValue(),
|
|
2858
2938
|
oldValue
|
|
2859
2939
|
});
|
|
2860
2940
|
}
|
|
@@ -2888,11 +2968,13 @@ var ValueTree = class {
|
|
|
2888
2968
|
this.changeTracker.clear();
|
|
2889
2969
|
}
|
|
2890
2970
|
revert() {
|
|
2971
|
+
this.unsubscribe(this._root);
|
|
2891
2972
|
const root = this._root;
|
|
2892
2973
|
if ("revert" in root && typeof root.revert === "function") {
|
|
2893
2974
|
root.revert();
|
|
2894
2975
|
}
|
|
2895
2976
|
this.changeTracker.clear();
|
|
2977
|
+
this.subscribe(this._root);
|
|
2896
2978
|
}
|
|
2897
2979
|
rebuildIndex() {
|
|
2898
2980
|
this.index.rebuild();
|
|
@@ -2910,9 +2992,126 @@ var ValueTree = class {
|
|
|
2910
2992
|
return this._formulaEngine;
|
|
2911
2993
|
}
|
|
2912
2994
|
dispose() {
|
|
2995
|
+
this.unsubscribe(this._root);
|
|
2913
2996
|
this._formulaEngine?.dispose();
|
|
2914
2997
|
this._formulaEngine = null;
|
|
2915
2998
|
}
|
|
2999
|
+
handleNodeChange(event) {
|
|
3000
|
+
if (this._suppressEvents) {
|
|
3001
|
+
return;
|
|
3002
|
+
}
|
|
3003
|
+
switch (event.type) {
|
|
3004
|
+
case "setValue": {
|
|
3005
|
+
this.changeTracker.track({
|
|
3006
|
+
type: "setValue",
|
|
3007
|
+
path: this.index.pathOf(event.node),
|
|
3008
|
+
value: event.value,
|
|
3009
|
+
oldValue: event.oldValue
|
|
3010
|
+
});
|
|
3011
|
+
break;
|
|
3012
|
+
}
|
|
3013
|
+
case "addChild": {
|
|
3014
|
+
this.adoptNode(event.child);
|
|
3015
|
+
this.changeTracker.track({
|
|
3016
|
+
type: "addProperty",
|
|
3017
|
+
path: this.index.pathOf(event.parent).child(event.child.name),
|
|
3018
|
+
value: event.child.getPlainValue()
|
|
3019
|
+
});
|
|
3020
|
+
break;
|
|
3021
|
+
}
|
|
3022
|
+
case "removeChild": {
|
|
3023
|
+
this.unsubscribe(event.child);
|
|
3024
|
+
this.changeTracker.track({
|
|
3025
|
+
type: "removeProperty",
|
|
3026
|
+
path: this.index.pathOf(event.parent).child(event.childName)
|
|
3027
|
+
});
|
|
3028
|
+
break;
|
|
3029
|
+
}
|
|
3030
|
+
case "arrayPush":
|
|
3031
|
+
case "arrayInsert": {
|
|
3032
|
+
this.adoptNode(event.item);
|
|
3033
|
+
this.index.invalidatePathsUnder(event.array);
|
|
3034
|
+
this.changeTracker.track(
|
|
3035
|
+
this.toArrayItemChange(event)
|
|
3036
|
+
);
|
|
3037
|
+
break;
|
|
3038
|
+
}
|
|
3039
|
+
case "arrayReplace": {
|
|
3040
|
+
this.unsubscribe(event.oldItem);
|
|
3041
|
+
this.adoptNode(event.item);
|
|
3042
|
+
this.index.invalidatePathsUnder(event.array);
|
|
3043
|
+
this.changeTracker.track({
|
|
3044
|
+
type: "arrayReplace",
|
|
3045
|
+
path: this.index.pathOf(event.array),
|
|
3046
|
+
index: event.index,
|
|
3047
|
+
value: event.item.getPlainValue()
|
|
3048
|
+
});
|
|
3049
|
+
break;
|
|
3050
|
+
}
|
|
3051
|
+
case "arrayRemove": {
|
|
3052
|
+
this.unsubscribe(event.item);
|
|
3053
|
+
this.index.invalidatePathsUnder(event.array);
|
|
3054
|
+
this.changeTracker.track(
|
|
3055
|
+
this.toArrayStructureChange(event)
|
|
3056
|
+
);
|
|
3057
|
+
break;
|
|
3058
|
+
}
|
|
3059
|
+
case "arrayMove": {
|
|
3060
|
+
this.index.invalidatePathsUnder(event.array);
|
|
3061
|
+
this.changeTracker.track(
|
|
3062
|
+
this.toArrayStructureChange(event)
|
|
3063
|
+
);
|
|
3064
|
+
break;
|
|
3065
|
+
}
|
|
3066
|
+
case "arrayClear": {
|
|
3067
|
+
for (const item of event.items) {
|
|
3068
|
+
this.unsubscribe(item);
|
|
3069
|
+
}
|
|
3070
|
+
this.changeTracker.track({
|
|
3071
|
+
type: "arrayClear",
|
|
3072
|
+
path: this.index.pathOf(event.array)
|
|
3073
|
+
});
|
|
3074
|
+
break;
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
toArrayItemChange(event) {
|
|
3079
|
+
const path = this.index.pathOf(event.array);
|
|
3080
|
+
const value = event.item.getPlainValue();
|
|
3081
|
+
if (event.type === "arrayPush") {
|
|
3082
|
+
return { type: "arrayPush", path, value };
|
|
3083
|
+
}
|
|
3084
|
+
return { type: "arrayInsert", path, index: event.index, value };
|
|
3085
|
+
}
|
|
3086
|
+
toArrayStructureChange(event) {
|
|
3087
|
+
const path = this.index.pathOf(event.array);
|
|
3088
|
+
if (event.type === "arrayRemove") {
|
|
3089
|
+
return { type: "arrayRemove", path, index: event.index };
|
|
3090
|
+
}
|
|
3091
|
+
return { type: "arrayMove", path, fromIndex: event.fromIndex, toIndex: event.toIndex };
|
|
3092
|
+
}
|
|
3093
|
+
adoptNode(node) {
|
|
3094
|
+
this.subscribe(node);
|
|
3095
|
+
this.index.registerNode(node);
|
|
3096
|
+
}
|
|
3097
|
+
walkTree(node, visit) {
|
|
3098
|
+
visit(node);
|
|
3099
|
+
if (node.isObject()) {
|
|
3100
|
+
for (const child of node.children) {
|
|
3101
|
+
this.walkTree(child, visit);
|
|
3102
|
+
}
|
|
3103
|
+
} else if (node.isArray()) {
|
|
3104
|
+
for (const item of node.value) {
|
|
3105
|
+
this.walkTree(item, visit);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
subscribe(node) {
|
|
3110
|
+
this.walkTree(node, (n) => n.on("change", this._nodeChangeListener));
|
|
3111
|
+
}
|
|
3112
|
+
unsubscribe(node) {
|
|
3113
|
+
this.walkTree(node, (n) => n.off("change", this._nodeChangeListener));
|
|
3114
|
+
}
|
|
2916
3115
|
};
|
|
2917
3116
|
|
|
2918
3117
|
// src/model/table/row/RowModelImpl.ts
|
|
@@ -3443,7 +3642,7 @@ var ForeignKeyResolverImpl = class {
|
|
|
3443
3642
|
return foreignKeys;
|
|
3444
3643
|
}
|
|
3445
3644
|
getForeignKeyFromSchema(schema) {
|
|
3446
|
-
if ("type" in schema && schema.type === "string"
|
|
3645
|
+
if ("type" in schema && schema.type === "string") {
|
|
3447
3646
|
return schema.foreignKey;
|
|
3448
3647
|
}
|
|
3449
3648
|
return void 0;
|
|
@@ -3547,6 +3746,14 @@ function createDataModel(options) {
|
|
|
3547
3746
|
return new DataModelImpl(options);
|
|
3548
3747
|
}
|
|
3549
3748
|
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3749
|
+
// src/model/value-tree/typed.ts
|
|
3750
|
+
function typedNode(node) {
|
|
3751
|
+
return node;
|
|
3752
|
+
}
|
|
3753
|
+
function createTypedTree(schema, data, options) {
|
|
3754
|
+
const factory = createNodeFactory(options);
|
|
3755
|
+
const root = factory.createTree(schema, data);
|
|
3756
|
+
return new ValueTree(root);
|
|
3757
|
+
}
|
|
3758
|
+
|
|
3759
|
+
export { ArrayToItemsTypeTransformer, ArrayValueNode, BasePrimitiveValueNode, BaseValueNode, BooleanValueNode, DataModelImpl, DefaultTransformer, ForeignKeyNotFoundError, ForeignKeyResolverImpl, ForeignKeyResolverNotConfiguredError, ForeignKeyValueNodeImpl, FormulaChangeDetector, FormulaDependencyIndex, FormulaPath, NodeFactory, NodeFactory2, NodeFactoryRegistry, NumberValueNode, ObjectToArrayTransformer, ObjectValueNode, ParsedFormula, PrimitiveToArrayTransformer, RefTransformer, RowModelImpl, SchemaParser, StringValueNode, TableModelImpl, TypeTransformChain, ValueTree, ValueType, createDataModel, createDefaultRegistry, createForeignKeyResolver, createNodeFactory, createRowModel, createSchemaModel, createTableModel, createTypeTransformChain, createTypedTree, extractFormulaDefinition, generateDefaultValue, generateNodeId, isForeignKeyValueNode, resetNodeIdCounter, typedNode };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/plugins/row-id.schema.ts
|
|
4
4
|
var rowIdSchema = {
|
|
5
|
-
type: "string"
|
|
5
|
+
type: "string",
|
|
6
6
|
default: "",
|
|
7
7
|
readOnly: true
|
|
8
8
|
};
|
|
@@ -13,7 +13,7 @@ var ajvRowIdSchema = {
|
|
|
13
13
|
|
|
14
14
|
// src/plugins/row-version-id.schema.ts
|
|
15
15
|
var rowVersionIdSchema = {
|
|
16
|
-
type: "string"
|
|
16
|
+
type: "string",
|
|
17
17
|
default: "",
|
|
18
18
|
readOnly: true
|
|
19
19
|
};
|
|
@@ -24,7 +24,7 @@ var ajvRowVersionIdSchema = {
|
|
|
24
24
|
|
|
25
25
|
// src/plugins/row-created-id.schema.ts
|
|
26
26
|
var rowCreatedIdSchema = {
|
|
27
|
-
type: "string"
|
|
27
|
+
type: "string",
|
|
28
28
|
default: "",
|
|
29
29
|
readOnly: true
|
|
30
30
|
};
|
|
@@ -35,7 +35,7 @@ var ajvRowCreatedIdSchema = {
|
|
|
35
35
|
|
|
36
36
|
// src/plugins/row-created-at.schema.ts
|
|
37
37
|
var rowCreatedAtSchema = {
|
|
38
|
-
type: "string"
|
|
38
|
+
type: "string",
|
|
39
39
|
default: "",
|
|
40
40
|
readOnly: true
|
|
41
41
|
};
|
|
@@ -46,7 +46,7 @@ var ajvRowCreatedAtSchema = {
|
|
|
46
46
|
|
|
47
47
|
// src/plugins/row-published-at.schema.ts
|
|
48
48
|
var rowPublishedAtSchema = {
|
|
49
|
-
type: "string"
|
|
49
|
+
type: "string",
|
|
50
50
|
default: ""
|
|
51
51
|
};
|
|
52
52
|
var ajvRowPublishedAtSchema = {
|
|
@@ -56,7 +56,7 @@ var ajvRowPublishedAtSchema = {
|
|
|
56
56
|
|
|
57
57
|
// src/plugins/row-updated-at.schema.ts
|
|
58
58
|
var rowUpdatedAtSchema = {
|
|
59
|
-
type: "string"
|
|
59
|
+
type: "string",
|
|
60
60
|
default: "",
|
|
61
61
|
readOnly: true
|
|
62
62
|
};
|
|
@@ -67,7 +67,7 @@ var ajvRowUpdatedAtSchema = {
|
|
|
67
67
|
|
|
68
68
|
// src/plugins/row-hash.schema.ts
|
|
69
69
|
var rowHashSchema = {
|
|
70
|
-
type: "string"
|
|
70
|
+
type: "string",
|
|
71
71
|
default: "",
|
|
72
72
|
readOnly: true
|
|
73
73
|
};
|
|
@@ -78,7 +78,7 @@ var ajvRowHashSchema = {
|
|
|
78
78
|
|
|
79
79
|
// src/plugins/row-schema-hash.schema.ts
|
|
80
80
|
var rowSchemaHashSchema = {
|
|
81
|
-
type: "string"
|
|
81
|
+
type: "string",
|
|
82
82
|
default: "",
|
|
83
83
|
readOnly: true
|
|
84
84
|
};
|
|
@@ -89,39 +89,39 @@ var ajvRowSchemaHashSchema = {
|
|
|
89
89
|
|
|
90
90
|
// src/plugins/file-schema.ts
|
|
91
91
|
var fileSchema = {
|
|
92
|
-
type: "object"
|
|
92
|
+
type: "object",
|
|
93
93
|
properties: {
|
|
94
|
-
status: { type: "string"
|
|
95
|
-
fileId: { type: "string"
|
|
96
|
-
url: { type: "string"
|
|
97
|
-
fileName: { type: "string"
|
|
94
|
+
status: { type: "string", default: "", readOnly: true },
|
|
95
|
+
fileId: { type: "string", default: "", readOnly: true },
|
|
96
|
+
url: { type: "string", default: "", readOnly: true },
|
|
97
|
+
fileName: { type: "string", default: "" },
|
|
98
98
|
hash: {
|
|
99
|
-
type: "string"
|
|
99
|
+
type: "string",
|
|
100
100
|
default: "",
|
|
101
101
|
readOnly: true
|
|
102
102
|
},
|
|
103
103
|
extension: {
|
|
104
|
-
type: "string"
|
|
104
|
+
type: "string",
|
|
105
105
|
default: "",
|
|
106
106
|
readOnly: true
|
|
107
107
|
},
|
|
108
108
|
mimeType: {
|
|
109
|
-
type: "string"
|
|
109
|
+
type: "string",
|
|
110
110
|
default: "",
|
|
111
111
|
readOnly: true
|
|
112
112
|
},
|
|
113
113
|
size: {
|
|
114
|
-
type: "number"
|
|
114
|
+
type: "number",
|
|
115
115
|
default: 0,
|
|
116
116
|
readOnly: true
|
|
117
117
|
},
|
|
118
118
|
width: {
|
|
119
|
-
type: "number"
|
|
119
|
+
type: "number",
|
|
120
120
|
default: 0,
|
|
121
121
|
readOnly: true
|
|
122
122
|
},
|
|
123
123
|
height: {
|
|
124
|
-
type: "number"
|
|
124
|
+
type: "number",
|
|
125
125
|
default: 0,
|
|
126
126
|
readOnly: true
|
|
127
127
|
}
|
|
@@ -163,5 +163,3 @@ exports.rowPublishedAtSchema = rowPublishedAtSchema;
|
|
|
163
163
|
exports.rowSchemaHashSchema = rowSchemaHashSchema;
|
|
164
164
|
exports.rowUpdatedAtSchema = rowUpdatedAtSchema;
|
|
165
165
|
exports.rowVersionIdSchema = rowVersionIdSchema;
|
|
166
|
-
//# sourceMappingURL=chunk-EGC32GPY.cjs.map
|
|
167
|
-
//# sourceMappingURL=chunk-EGC32GPY.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/lib/schema-helpers.ts
|
|
2
2
|
var getReplacePatch = ({
|
|
3
3
|
path,
|
|
4
4
|
value
|
|
@@ -36,7 +36,7 @@ var buildFormula = (expression) => ({
|
|
|
36
36
|
var getStringSchema = (params = {}) => {
|
|
37
37
|
const { formula, ...rest } = params;
|
|
38
38
|
return {
|
|
39
|
-
type: "string"
|
|
39
|
+
type: "string",
|
|
40
40
|
...rest,
|
|
41
41
|
default: rest.default ?? "",
|
|
42
42
|
...formula && { "x-formula": buildFormula(formula) }
|
|
@@ -45,7 +45,7 @@ var getStringSchema = (params = {}) => {
|
|
|
45
45
|
var getNumberSchema = (params = {}) => {
|
|
46
46
|
const { formula, ...rest } = params;
|
|
47
47
|
return {
|
|
48
|
-
type: "number"
|
|
48
|
+
type: "number",
|
|
49
49
|
...rest,
|
|
50
50
|
default: rest.default ?? 0,
|
|
51
51
|
...formula && { "x-formula": buildFormula(formula) }
|
|
@@ -54,21 +54,21 @@ var getNumberSchema = (params = {}) => {
|
|
|
54
54
|
var getBooleanSchema = (params = {}) => {
|
|
55
55
|
const { formula, ...rest } = params;
|
|
56
56
|
return {
|
|
57
|
-
type: "boolean"
|
|
57
|
+
type: "boolean",
|
|
58
58
|
...rest,
|
|
59
59
|
default: rest.default ?? false,
|
|
60
60
|
...formula && { "x-formula": buildFormula(formula) }
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
var getObjectSchema = (properties, options = {}) => ({
|
|
64
|
-
type: "object"
|
|
64
|
+
type: "object",
|
|
65
65
|
additionalProperties: false,
|
|
66
66
|
required: Object.keys(properties).sort((a, b) => a.localeCompare(b)),
|
|
67
67
|
properties,
|
|
68
68
|
...options
|
|
69
69
|
});
|
|
70
70
|
var getArraySchema = (items, options = {}) => ({
|
|
71
|
-
type: "array"
|
|
71
|
+
type: "array",
|
|
72
72
|
items,
|
|
73
73
|
...options
|
|
74
74
|
});
|
|
@@ -79,10 +79,11 @@ var getRefSchema = ($ref, options = {}) => ({
|
|
|
79
79
|
var str = (params = {}) => getStringSchema(params);
|
|
80
80
|
var num = (params = {}) => getNumberSchema(params);
|
|
81
81
|
var bool = (params = {}) => getBooleanSchema(params);
|
|
82
|
+
var strFormula = (formula, params = {}) => getStringSchema({ ...params, formula, readOnly: true });
|
|
83
|
+
var numFormula = (formula, params = {}) => getNumberSchema({ ...params, formula, readOnly: true });
|
|
84
|
+
var boolFormula = (formula, params = {}) => getBooleanSchema({ ...params, formula, readOnly: true });
|
|
82
85
|
var obj = (properties, options) => getObjectSchema(properties, options);
|
|
83
86
|
var arr = (items, options) => getArraySchema(items, options);
|
|
84
87
|
var ref = ($ref, options) => getRefSchema($ref, options);
|
|
85
88
|
|
|
86
|
-
export { arr, bool, getAddPatch, getArraySchema, getBooleanSchema, getMovePatch, getNumberSchema, getObjectSchema, getRefSchema, getRemovePatch, getReplacePatch, getStringSchema, num, obj, ref, str };
|
|
87
|
-
//# sourceMappingURL=chunk-R4CFU33U.js.map
|
|
88
|
-
//# sourceMappingURL=chunk-R4CFU33U.js.map
|
|
89
|
+
export { arr, bool, boolFormula, getAddPatch, getArraySchema, getBooleanSchema, getMovePatch, getNumberSchema, getObjectSchema, getRefSchema, getRemovePatch, getReplacePatch, getStringSchema, num, numFormula, obj, ref, str, strFormula };
|