tinybase 9.4.0 → 9.5.0-beta.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/@types/_internal/store/with-schemas/index.d.ts +43 -8
- package/@types/mergeable-store/with-schemas/index.d.ts +30 -11
- package/@types/queries/index.d.ts +11 -11
- package/@types/queries/with-schemas/index.d.ts +17 -3
- package/@types/schematizers/index.d.ts +6 -4
- package/@types/schematizers/schematizer-arktype/index.d.ts +6 -6
- package/@types/schematizers/schematizer-arktype/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-effect/index.d.ts +9 -11
- package/@types/schematizers/schematizer-effect/with-schemas/index.d.ts +114 -1
- package/@types/schematizers/schematizer-typebox/index.d.ts +7 -7
- package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +114 -1
- package/@types/schematizers/schematizer-valibot/index.d.ts +6 -6
- package/@types/schematizers/schematizer-valibot/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
- package/@types/schematizers/schematizer-yup/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/schematizer-zod/index.d.ts +6 -6
- package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +112 -1
- package/@types/schematizers/with-schemas/index.d.ts +113 -4
- package/@types/store/index.d.ts +175 -16
- package/@types/store/with-schemas/index.d.ts +238 -55
- package/@types/synchronizers/with-schemas/index.d.ts +12 -2
- package/@types/ui-react/with-schemas/index.d.ts +576 -7
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +94 -10
- package/@types/ui-react-dom-charts/index.d.ts +7 -7
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
- package/@types/ui-react-inspector/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-solid/with-schemas/index.d.ts +340 -7
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +94 -10
- package/@types/ui-solid-inspector/index.d.ts +1 -1
- package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-svelte/with-schemas/index.d.ts +30 -0
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +94 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/agents.md +4 -0
- package/index.js +76 -22
- package/mergeable-store/index.js +76 -22
- package/mergeable-store/with-schemas/index.js +76 -22
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/schematizers/index.js +1 -1
- package/min/schematizers/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/index.js +1 -1
- package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/index.js +1 -1
- package/min/schematizers/schematizer-effect/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/index.js +1 -1
- package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/index.js +1 -1
- package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/index.js +1 -1
- package/min/schematizers/schematizer-yup/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/index.js +1 -1
- package/min/schematizers/schematizer-zod/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
- package/min/schematizers/with-schemas/index.js +1 -1
- package/min/schematizers/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-solid-inspector/index.js +1 -1
- package/min/ui-solid-inspector/index.js.gz +0 -0
- package/min/ui-solid-inspector/with-schemas/index.js +1 -1
- package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-svelte-inspector/index.js +1 -1
- package/min/ui-svelte-inspector/index.js.gz +0 -0
- package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
- package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +76 -22
- package/omni/with-schemas/index.js +76 -22
- package/package.json +2 -2
- package/readme.md +14 -14
- package/releases.md +95 -65
- package/schematizers/index.js +54 -6
- package/schematizers/schematizer-arktype/index.js +99 -19
- package/schematizers/schematizer-arktype/with-schemas/index.js +99 -19
- package/schematizers/schematizer-effect/index.js +101 -11
- package/schematizers/schematizer-effect/with-schemas/index.js +101 -11
- package/schematizers/schematizer-typebox/index.js +87 -11
- package/schematizers/schematizer-typebox/with-schemas/index.js +87 -11
- package/schematizers/schematizer-valibot/index.js +125 -21
- package/schematizers/schematizer-valibot/with-schemas/index.js +125 -21
- package/schematizers/schematizer-yup/index.js +58 -14
- package/schematizers/schematizer-yup/with-schemas/index.js +58 -14
- package/schematizers/schematizer-zod/index.js +131 -12
- package/schematizers/schematizer-zod/with-schemas/index.js +131 -12
- package/schematizers/with-schemas/index.js +54 -6
- package/store/index.js +76 -22
- package/store/with-schemas/index.js +76 -22
- package/ui-react-inspector/index.js +76 -22
- package/ui-react-inspector/with-schemas/index.js +76 -22
- package/ui-solid-inspector/index.js +76 -22
- package/ui-solid-inspector/with-schemas/index.js +76 -22
- package/ui-svelte-inspector/index.js +76 -22
- package/ui-svelte-inspector/with-schemas/index.js +76 -22
- package/with-schemas/index.js +76 -22
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
8
8
|
const OBJECT = 'object';
|
|
9
9
|
const ARRAY = 'array';
|
|
10
10
|
const TYPE = 'type';
|
|
11
|
+
const ENUM = 'enum';
|
|
11
12
|
const DEFAULT = 'default';
|
|
12
13
|
const ALLOW_NULL = 'allowNull';
|
|
13
14
|
const NULL = 'null';
|
|
@@ -226,6 +227,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
226
227
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
227
228
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
228
229
|
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
230
|
+
const isCellOrValueSchemaType = (type) =>
|
|
231
|
+
isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
|
|
232
|
+
const isCellOrValueSchemaTypes = (types) =>
|
|
233
|
+
isArray(types)
|
|
234
|
+
? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
|
|
235
|
+
: isCellOrValueSchemaType(types);
|
|
236
|
+
const cellOrValueSchemaTypeIncludes = (types, type) =>
|
|
237
|
+
isArray(types) ? arrayHas(types, type) : types == type;
|
|
229
238
|
const encodeIfJson = (value) =>
|
|
230
239
|
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
231
240
|
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
@@ -1512,13 +1521,29 @@ const createStore = () => {
|
|
|
1512
1521
|
const validateCellOrValueSchema = (schema) => {
|
|
1513
1522
|
if (
|
|
1514
1523
|
!objValidate(schema, (_child, id2) =>
|
|
1515
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1524
|
+
arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1516
1525
|
)
|
|
1517
1526
|
) {
|
|
1518
1527
|
return false;
|
|
1519
1528
|
}
|
|
1520
1529
|
const type = schema[TYPE];
|
|
1521
|
-
|
|
1530
|
+
const enumValues = schema[ENUM];
|
|
1531
|
+
if (
|
|
1532
|
+
isUndefined(enumValues)
|
|
1533
|
+
? !isCellOrValueSchemaTypes(type)
|
|
1534
|
+
: !isUndefined(type) ||
|
|
1535
|
+
!isArray(enumValues) ||
|
|
1536
|
+
isUndefined(enumValues[0]) ||
|
|
1537
|
+
!arrayEvery(enumValues, (enumValue) => {
|
|
1538
|
+
const enumType = getCellOrValueType(enumValue);
|
|
1539
|
+
return (
|
|
1540
|
+
!isNull(enumValue) &&
|
|
1541
|
+
!isUndefined(enumType) &&
|
|
1542
|
+
!isJsonType(enumType) &&
|
|
1543
|
+
!isReservedString(enumValue)
|
|
1544
|
+
);
|
|
1545
|
+
})
|
|
1546
|
+
) {
|
|
1522
1547
|
return false;
|
|
1523
1548
|
}
|
|
1524
1549
|
const defaultValue = schema[DEFAULT];
|
|
@@ -1527,7 +1552,12 @@ const createStore = () => {
|
|
|
1527
1552
|
}
|
|
1528
1553
|
if (!isNull(defaultValue)) {
|
|
1529
1554
|
if (
|
|
1530
|
-
|
|
1555
|
+
(isUndefined(enumValues)
|
|
1556
|
+
? !cellOrValueSchemaTypeIncludes(
|
|
1557
|
+
type,
|
|
1558
|
+
getCellOrValueType(defaultValue),
|
|
1559
|
+
)
|
|
1560
|
+
: !arrayHas(enumValues, defaultValue)) ||
|
|
1531
1561
|
isReservedString(defaultValue)
|
|
1532
1562
|
) {
|
|
1533
1563
|
objDel(schema, DEFAULT);
|
|
@@ -1554,13 +1584,15 @@ const createStore = () => {
|
|
|
1554
1584
|
isObject(tables) ? objMap(tables, cloneTable) : tables;
|
|
1555
1585
|
const cloneValues = (values) =>
|
|
1556
1586
|
isObject(values) ? objMap(values, getArg) : values;
|
|
1557
|
-
const isValidEncodedJson = (cellOrValue,
|
|
1587
|
+
const isValidEncodedJson = (cellOrValue, types) =>
|
|
1558
1588
|
acceptingEncodedData == 1 &&
|
|
1559
1589
|
isEncodedJson(cellOrValue) &&
|
|
1560
1590
|
tryReturn(() => {
|
|
1561
1591
|
const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
|
|
1562
1592
|
return (
|
|
1563
|
-
isJsonType(encodedType) &&
|
|
1593
|
+
isJsonType(encodedType) &&
|
|
1594
|
+
(isUndefined(types) ||
|
|
1595
|
+
cellOrValueSchemaTypeIncludes(types, encodedType))
|
|
1564
1596
|
);
|
|
1565
1597
|
}, false) == true;
|
|
1566
1598
|
const validateContent = isArray;
|
|
@@ -1613,7 +1645,8 @@ const createStore = () => {
|
|
|
1613
1645
|
: isReservedString(cell, acceptingEncodedData)
|
|
1614
1646
|
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
1615
1647
|
: isEncodedJson(cell)
|
|
1616
|
-
?
|
|
1648
|
+
? isUndefined(cellSchema[ENUM]) &&
|
|
1649
|
+
isValidEncodedJson(cell, cellSchema[TYPE])
|
|
1617
1650
|
? cell
|
|
1618
1651
|
: cellInvalid(
|
|
1619
1652
|
tableId,
|
|
@@ -1622,23 +1655,36 @@ const createStore = () => {
|
|
|
1622
1655
|
cell,
|
|
1623
1656
|
cellSchema[DEFAULT],
|
|
1624
1657
|
)
|
|
1625
|
-
:
|
|
1626
|
-
?
|
|
1627
|
-
|
|
1658
|
+
: isUndefined(cellSchema[ENUM])
|
|
1659
|
+
? cellOrValueSchemaTypeIncludes(
|
|
1660
|
+
cellSchema[TYPE],
|
|
1661
|
+
getCellOrValueType(cell),
|
|
1662
|
+
)
|
|
1663
|
+
? encodeValid(cell, () =>
|
|
1664
|
+
cellInvalid(
|
|
1665
|
+
tableId,
|
|
1666
|
+
rowId,
|
|
1667
|
+
cellId,
|
|
1668
|
+
cell,
|
|
1669
|
+
cellSchema[DEFAULT],
|
|
1670
|
+
),
|
|
1671
|
+
)
|
|
1672
|
+
: cellInvalid(
|
|
1673
|
+
tableId,
|
|
1674
|
+
rowId,
|
|
1675
|
+
cellId,
|
|
1676
|
+
cell,
|
|
1677
|
+
cellSchema[DEFAULT],
|
|
1678
|
+
)
|
|
1679
|
+
: arrayHas(cellSchema[ENUM], cell)
|
|
1680
|
+
? cell
|
|
1681
|
+
: cellInvalid(
|
|
1628
1682
|
tableId,
|
|
1629
1683
|
rowId,
|
|
1630
1684
|
cellId,
|
|
1631
1685
|
cell,
|
|
1632
1686
|
cellSchema[DEFAULT],
|
|
1633
1687
|
),
|
|
1634
|
-
)
|
|
1635
|
-
: cellInvalid(
|
|
1636
|
-
tableId,
|
|
1637
|
-
rowId,
|
|
1638
|
-
cellId,
|
|
1639
|
-
cell,
|
|
1640
|
-
cellSchema[DEFAULT],
|
|
1641
|
-
),
|
|
1642
1688
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
1643
1689
|
)
|
|
1644
1690
|
: isUndefined(getCellOrValueType(cell)) ||
|
|
@@ -1683,14 +1729,22 @@ const createStore = () => {
|
|
|
1683
1729
|
: isReservedString(value, acceptingEncodedData)
|
|
1684
1730
|
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1685
1731
|
: isEncodedJson(value)
|
|
1686
|
-
?
|
|
1732
|
+
? isUndefined(valueSchema[ENUM]) &&
|
|
1733
|
+
isValidEncodedJson(value, valueSchema[TYPE])
|
|
1687
1734
|
? value
|
|
1688
1735
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1689
|
-
:
|
|
1690
|
-
?
|
|
1691
|
-
|
|
1736
|
+
: isUndefined(valueSchema[ENUM])
|
|
1737
|
+
? cellOrValueSchemaTypeIncludes(
|
|
1738
|
+
valueSchema[TYPE],
|
|
1739
|
+
getCellOrValueType(value),
|
|
1692
1740
|
)
|
|
1693
|
-
|
|
1741
|
+
? encodeValid(value, () =>
|
|
1742
|
+
valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
1743
|
+
)
|
|
1744
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
1745
|
+
: arrayHas(valueSchema[ENUM], value)
|
|
1746
|
+
? value
|
|
1747
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
1694
1748
|
() => valueInvalid(valueId, value),
|
|
1695
1749
|
)
|
|
1696
1750
|
: isUndefined(getCellOrValueType(value)) ||
|
package/mergeable-store/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
8
8
|
const OBJECT = 'object';
|
|
9
9
|
const ARRAY = 'array';
|
|
10
10
|
const TYPE = 'type';
|
|
11
|
+
const ENUM = 'enum';
|
|
11
12
|
const DEFAULT = 'default';
|
|
12
13
|
const ALLOW_NULL = 'allowNull';
|
|
13
14
|
const NULL = 'null';
|
|
@@ -199,6 +200,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
199
200
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
200
201
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
201
202
|
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
203
|
+
const isCellOrValueSchemaType = (type) =>
|
|
204
|
+
isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
|
|
205
|
+
const isCellOrValueSchemaTypes = (types) =>
|
|
206
|
+
isArray(types)
|
|
207
|
+
? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
|
|
208
|
+
: isCellOrValueSchemaType(types);
|
|
209
|
+
const cellOrValueSchemaTypeIncludes = (types, type) =>
|
|
210
|
+
isArray(types) ? arrayHas(types, type) : types == type;
|
|
202
211
|
const encodeIfJson = (value) =>
|
|
203
212
|
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
204
213
|
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
@@ -756,13 +765,29 @@ const createStore = () => {
|
|
|
756
765
|
const validateCellOrValueSchema = (schema) => {
|
|
757
766
|
if (
|
|
758
767
|
!objValidate(schema, (_child, id2) =>
|
|
759
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
768
|
+
arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
760
769
|
)
|
|
761
770
|
) {
|
|
762
771
|
return false;
|
|
763
772
|
}
|
|
764
773
|
const type = schema[TYPE];
|
|
765
|
-
|
|
774
|
+
const enumValues = schema[ENUM];
|
|
775
|
+
if (
|
|
776
|
+
isUndefined(enumValues)
|
|
777
|
+
? !isCellOrValueSchemaTypes(type)
|
|
778
|
+
: !isUndefined(type) ||
|
|
779
|
+
!isArray(enumValues) ||
|
|
780
|
+
isUndefined(enumValues[0]) ||
|
|
781
|
+
!arrayEvery(enumValues, (enumValue) => {
|
|
782
|
+
const enumType = getCellOrValueType(enumValue);
|
|
783
|
+
return (
|
|
784
|
+
!isNull(enumValue) &&
|
|
785
|
+
!isUndefined(enumType) &&
|
|
786
|
+
!isJsonType(enumType) &&
|
|
787
|
+
!isReservedString(enumValue)
|
|
788
|
+
);
|
|
789
|
+
})
|
|
790
|
+
) {
|
|
766
791
|
return false;
|
|
767
792
|
}
|
|
768
793
|
const defaultValue = schema[DEFAULT];
|
|
@@ -771,7 +796,12 @@ const createStore = () => {
|
|
|
771
796
|
}
|
|
772
797
|
if (!isNull(defaultValue)) {
|
|
773
798
|
if (
|
|
774
|
-
|
|
799
|
+
(isUndefined(enumValues)
|
|
800
|
+
? !cellOrValueSchemaTypeIncludes(
|
|
801
|
+
type,
|
|
802
|
+
getCellOrValueType(defaultValue),
|
|
803
|
+
)
|
|
804
|
+
: !arrayHas(enumValues, defaultValue)) ||
|
|
775
805
|
isReservedString(defaultValue)
|
|
776
806
|
) {
|
|
777
807
|
objDel(schema, DEFAULT);
|
|
@@ -798,13 +828,15 @@ const createStore = () => {
|
|
|
798
828
|
isObject(tables) ? objMap(tables, cloneTable) : tables;
|
|
799
829
|
const cloneValues = (values) =>
|
|
800
830
|
isObject(values) ? objMap(values, getArg) : values;
|
|
801
|
-
const isValidEncodedJson = (cellOrValue,
|
|
831
|
+
const isValidEncodedJson = (cellOrValue, types) =>
|
|
802
832
|
acceptingEncodedData == 1 &&
|
|
803
833
|
isEncodedJson(cellOrValue) &&
|
|
804
834
|
tryReturn(() => {
|
|
805
835
|
const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
|
|
806
836
|
return (
|
|
807
|
-
isJsonType(encodedType) &&
|
|
837
|
+
isJsonType(encodedType) &&
|
|
838
|
+
(isUndefined(types) ||
|
|
839
|
+
cellOrValueSchemaTypeIncludes(types, encodedType))
|
|
808
840
|
);
|
|
809
841
|
}, false) == true;
|
|
810
842
|
const validateContent = isArray;
|
|
@@ -857,7 +889,8 @@ const createStore = () => {
|
|
|
857
889
|
: isReservedString(cell, acceptingEncodedData)
|
|
858
890
|
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
859
891
|
: isEncodedJson(cell)
|
|
860
|
-
?
|
|
892
|
+
? isUndefined(cellSchema[ENUM]) &&
|
|
893
|
+
isValidEncodedJson(cell, cellSchema[TYPE])
|
|
861
894
|
? cell
|
|
862
895
|
: cellInvalid(
|
|
863
896
|
tableId,
|
|
@@ -866,23 +899,36 @@ const createStore = () => {
|
|
|
866
899
|
cell,
|
|
867
900
|
cellSchema[DEFAULT],
|
|
868
901
|
)
|
|
869
|
-
:
|
|
870
|
-
?
|
|
871
|
-
|
|
902
|
+
: isUndefined(cellSchema[ENUM])
|
|
903
|
+
? cellOrValueSchemaTypeIncludes(
|
|
904
|
+
cellSchema[TYPE],
|
|
905
|
+
getCellOrValueType(cell),
|
|
906
|
+
)
|
|
907
|
+
? encodeValid(cell, () =>
|
|
908
|
+
cellInvalid(
|
|
909
|
+
tableId,
|
|
910
|
+
rowId,
|
|
911
|
+
cellId,
|
|
912
|
+
cell,
|
|
913
|
+
cellSchema[DEFAULT],
|
|
914
|
+
),
|
|
915
|
+
)
|
|
916
|
+
: cellInvalid(
|
|
917
|
+
tableId,
|
|
918
|
+
rowId,
|
|
919
|
+
cellId,
|
|
920
|
+
cell,
|
|
921
|
+
cellSchema[DEFAULT],
|
|
922
|
+
)
|
|
923
|
+
: arrayHas(cellSchema[ENUM], cell)
|
|
924
|
+
? cell
|
|
925
|
+
: cellInvalid(
|
|
872
926
|
tableId,
|
|
873
927
|
rowId,
|
|
874
928
|
cellId,
|
|
875
929
|
cell,
|
|
876
930
|
cellSchema[DEFAULT],
|
|
877
931
|
),
|
|
878
|
-
)
|
|
879
|
-
: cellInvalid(
|
|
880
|
-
tableId,
|
|
881
|
-
rowId,
|
|
882
|
-
cellId,
|
|
883
|
-
cell,
|
|
884
|
-
cellSchema[DEFAULT],
|
|
885
|
-
),
|
|
886
932
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
887
933
|
)
|
|
888
934
|
: isUndefined(getCellOrValueType(cell)) ||
|
|
@@ -927,14 +973,22 @@ const createStore = () => {
|
|
|
927
973
|
: isReservedString(value, acceptingEncodedData)
|
|
928
974
|
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
929
975
|
: isEncodedJson(value)
|
|
930
|
-
?
|
|
976
|
+
? isUndefined(valueSchema[ENUM]) &&
|
|
977
|
+
isValidEncodedJson(value, valueSchema[TYPE])
|
|
931
978
|
? value
|
|
932
979
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
933
|
-
:
|
|
934
|
-
?
|
|
935
|
-
|
|
980
|
+
: isUndefined(valueSchema[ENUM])
|
|
981
|
+
? cellOrValueSchemaTypeIncludes(
|
|
982
|
+
valueSchema[TYPE],
|
|
983
|
+
getCellOrValueType(value),
|
|
936
984
|
)
|
|
937
|
-
|
|
985
|
+
? encodeValid(value, () =>
|
|
986
|
+
valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
987
|
+
)
|
|
988
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
989
|
+
: arrayHas(valueSchema[ENUM], value)
|
|
990
|
+
? value
|
|
991
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
938
992
|
() => valueInvalid(valueId, value),
|
|
939
993
|
)
|
|
940
994
|
: isUndefined(getCellOrValueType(value)) ||
|
|
@@ -8,6 +8,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
8
8
|
const OBJECT = 'object';
|
|
9
9
|
const ARRAY = 'array';
|
|
10
10
|
const TYPE = 'type';
|
|
11
|
+
const ENUM = 'enum';
|
|
11
12
|
const DEFAULT = 'default';
|
|
12
13
|
const ALLOW_NULL = 'allowNull';
|
|
13
14
|
const NULL = 'null';
|
|
@@ -199,6 +200,14 @@ const getCellOrValueType = (cellOrValue) => {
|
|
|
199
200
|
const isCellOrValueOrUndefined = (cellOrValue) =>
|
|
200
201
|
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
|
|
201
202
|
const isJsonType = (type) => type == OBJECT || type == ARRAY;
|
|
203
|
+
const isCellOrValueSchemaType = (type) =>
|
|
204
|
+
isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
|
|
205
|
+
const isCellOrValueSchemaTypes = (types) =>
|
|
206
|
+
isArray(types)
|
|
207
|
+
? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
|
|
208
|
+
: isCellOrValueSchemaType(types);
|
|
209
|
+
const cellOrValueSchemaTypeIncludes = (types, type) =>
|
|
210
|
+
isArray(types) ? arrayHas(types, type) : types == type;
|
|
202
211
|
const encodeIfJson = (value) =>
|
|
203
212
|
isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
|
|
204
213
|
const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
|
|
@@ -756,13 +765,29 @@ const createStore = () => {
|
|
|
756
765
|
const validateCellOrValueSchema = (schema) => {
|
|
757
766
|
if (
|
|
758
767
|
!objValidate(schema, (_child, id2) =>
|
|
759
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
768
|
+
arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
760
769
|
)
|
|
761
770
|
) {
|
|
762
771
|
return false;
|
|
763
772
|
}
|
|
764
773
|
const type = schema[TYPE];
|
|
765
|
-
|
|
774
|
+
const enumValues = schema[ENUM];
|
|
775
|
+
if (
|
|
776
|
+
isUndefined(enumValues)
|
|
777
|
+
? !isCellOrValueSchemaTypes(type)
|
|
778
|
+
: !isUndefined(type) ||
|
|
779
|
+
!isArray(enumValues) ||
|
|
780
|
+
isUndefined(enumValues[0]) ||
|
|
781
|
+
!arrayEvery(enumValues, (enumValue) => {
|
|
782
|
+
const enumType = getCellOrValueType(enumValue);
|
|
783
|
+
return (
|
|
784
|
+
!isNull(enumValue) &&
|
|
785
|
+
!isUndefined(enumType) &&
|
|
786
|
+
!isJsonType(enumType) &&
|
|
787
|
+
!isReservedString(enumValue)
|
|
788
|
+
);
|
|
789
|
+
})
|
|
790
|
+
) {
|
|
766
791
|
return false;
|
|
767
792
|
}
|
|
768
793
|
const defaultValue = schema[DEFAULT];
|
|
@@ -771,7 +796,12 @@ const createStore = () => {
|
|
|
771
796
|
}
|
|
772
797
|
if (!isNull(defaultValue)) {
|
|
773
798
|
if (
|
|
774
|
-
|
|
799
|
+
(isUndefined(enumValues)
|
|
800
|
+
? !cellOrValueSchemaTypeIncludes(
|
|
801
|
+
type,
|
|
802
|
+
getCellOrValueType(defaultValue),
|
|
803
|
+
)
|
|
804
|
+
: !arrayHas(enumValues, defaultValue)) ||
|
|
775
805
|
isReservedString(defaultValue)
|
|
776
806
|
) {
|
|
777
807
|
objDel(schema, DEFAULT);
|
|
@@ -798,13 +828,15 @@ const createStore = () => {
|
|
|
798
828
|
isObject(tables) ? objMap(tables, cloneTable) : tables;
|
|
799
829
|
const cloneValues = (values) =>
|
|
800
830
|
isObject(values) ? objMap(values, getArg) : values;
|
|
801
|
-
const isValidEncodedJson = (cellOrValue,
|
|
831
|
+
const isValidEncodedJson = (cellOrValue, types) =>
|
|
802
832
|
acceptingEncodedData == 1 &&
|
|
803
833
|
isEncodedJson(cellOrValue) &&
|
|
804
834
|
tryReturn(() => {
|
|
805
835
|
const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
|
|
806
836
|
return (
|
|
807
|
-
isJsonType(encodedType) &&
|
|
837
|
+
isJsonType(encodedType) &&
|
|
838
|
+
(isUndefined(types) ||
|
|
839
|
+
cellOrValueSchemaTypeIncludes(types, encodedType))
|
|
808
840
|
);
|
|
809
841
|
}, false) == true;
|
|
810
842
|
const validateContent = isArray;
|
|
@@ -857,7 +889,8 @@ const createStore = () => {
|
|
|
857
889
|
: isReservedString(cell, acceptingEncodedData)
|
|
858
890
|
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
|
859
891
|
: isEncodedJson(cell)
|
|
860
|
-
?
|
|
892
|
+
? isUndefined(cellSchema[ENUM]) &&
|
|
893
|
+
isValidEncodedJson(cell, cellSchema[TYPE])
|
|
861
894
|
? cell
|
|
862
895
|
: cellInvalid(
|
|
863
896
|
tableId,
|
|
@@ -866,23 +899,36 @@ const createStore = () => {
|
|
|
866
899
|
cell,
|
|
867
900
|
cellSchema[DEFAULT],
|
|
868
901
|
)
|
|
869
|
-
:
|
|
870
|
-
?
|
|
871
|
-
|
|
902
|
+
: isUndefined(cellSchema[ENUM])
|
|
903
|
+
? cellOrValueSchemaTypeIncludes(
|
|
904
|
+
cellSchema[TYPE],
|
|
905
|
+
getCellOrValueType(cell),
|
|
906
|
+
)
|
|
907
|
+
? encodeValid(cell, () =>
|
|
908
|
+
cellInvalid(
|
|
909
|
+
tableId,
|
|
910
|
+
rowId,
|
|
911
|
+
cellId,
|
|
912
|
+
cell,
|
|
913
|
+
cellSchema[DEFAULT],
|
|
914
|
+
),
|
|
915
|
+
)
|
|
916
|
+
: cellInvalid(
|
|
917
|
+
tableId,
|
|
918
|
+
rowId,
|
|
919
|
+
cellId,
|
|
920
|
+
cell,
|
|
921
|
+
cellSchema[DEFAULT],
|
|
922
|
+
)
|
|
923
|
+
: arrayHas(cellSchema[ENUM], cell)
|
|
924
|
+
? cell
|
|
925
|
+
: cellInvalid(
|
|
872
926
|
tableId,
|
|
873
927
|
rowId,
|
|
874
928
|
cellId,
|
|
875
929
|
cell,
|
|
876
930
|
cellSchema[DEFAULT],
|
|
877
931
|
),
|
|
878
|
-
)
|
|
879
|
-
: cellInvalid(
|
|
880
|
-
tableId,
|
|
881
|
-
rowId,
|
|
882
|
-
cellId,
|
|
883
|
-
cell,
|
|
884
|
-
cellSchema[DEFAULT],
|
|
885
|
-
),
|
|
886
932
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
887
933
|
)
|
|
888
934
|
: isUndefined(getCellOrValueType(cell)) ||
|
|
@@ -927,14 +973,22 @@ const createStore = () => {
|
|
|
927
973
|
: isReservedString(value, acceptingEncodedData)
|
|
928
974
|
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
929
975
|
: isEncodedJson(value)
|
|
930
|
-
?
|
|
976
|
+
? isUndefined(valueSchema[ENUM]) &&
|
|
977
|
+
isValidEncodedJson(value, valueSchema[TYPE])
|
|
931
978
|
? value
|
|
932
979
|
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
933
|
-
:
|
|
934
|
-
?
|
|
935
|
-
|
|
980
|
+
: isUndefined(valueSchema[ENUM])
|
|
981
|
+
? cellOrValueSchemaTypeIncludes(
|
|
982
|
+
valueSchema[TYPE],
|
|
983
|
+
getCellOrValueType(value),
|
|
936
984
|
)
|
|
937
|
-
|
|
985
|
+
? encodeValid(value, () =>
|
|
986
|
+
valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
987
|
+
)
|
|
988
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
|
|
989
|
+
: arrayHas(valueSchema[ENUM], value)
|
|
990
|
+
? value
|
|
991
|
+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
|
|
938
992
|
() => valueInvalid(valueId, value),
|
|
939
993
|
)
|
|
940
994
|
: isUndefined(getCellOrValueType(value)) ||
|