tinybase 9.5.0-beta.0 → 9.5.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.
Files changed (130) hide show
  1. package/@types/_internal/store/with-schemas/index.d.ts +43 -8
  2. package/@types/mergeable-store/with-schemas/index.d.ts +30 -11
  3. package/@types/queries/index.d.ts +11 -11
  4. package/@types/queries/with-schemas/index.d.ts +17 -3
  5. package/@types/schematizers/index.d.ts +6 -4
  6. package/@types/schematizers/schematizer-arktype/index.d.ts +6 -6
  7. package/@types/schematizers/schematizer-arktype/with-schemas/index.d.ts +112 -1
  8. package/@types/schematizers/schematizer-effect/index.d.ts +9 -11
  9. package/@types/schematizers/schematizer-effect/with-schemas/index.d.ts +114 -1
  10. package/@types/schematizers/schematizer-typebox/index.d.ts +7 -7
  11. package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +114 -1
  12. package/@types/schematizers/schematizer-valibot/index.d.ts +6 -6
  13. package/@types/schematizers/schematizer-valibot/with-schemas/index.d.ts +112 -1
  14. package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
  15. package/@types/schematizers/schematizer-yup/with-schemas/index.d.ts +112 -1
  16. package/@types/schematizers/schematizer-zod/index.d.ts +6 -6
  17. package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +112 -1
  18. package/@types/schematizers/with-schemas/index.d.ts +113 -4
  19. package/@types/store/index.d.ts +175 -16
  20. package/@types/store/with-schemas/index.d.ts +238 -55
  21. package/@types/synchronizers/with-schemas/index.d.ts +12 -2
  22. package/@types/ui-react/with-schemas/index.d.ts +576 -7
  23. package/@types/ui-react-dom/index.d.ts +10 -10
  24. package/@types/ui-react-dom/with-schemas/index.d.ts +94 -10
  25. package/@types/ui-react-dom-charts/index.d.ts +7 -7
  26. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
  27. package/@types/ui-react-inspector/index.d.ts +1 -1
  28. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
  29. package/@types/ui-solid/with-schemas/index.d.ts +340 -7
  30. package/@types/ui-solid-dom/index.d.ts +10 -10
  31. package/@types/ui-solid-dom/with-schemas/index.d.ts +94 -10
  32. package/@types/ui-solid-inspector/index.d.ts +1 -1
  33. package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
  34. package/@types/ui-svelte/with-schemas/index.d.ts +30 -0
  35. package/@types/ui-svelte-dom/index.d.ts +10 -10
  36. package/@types/ui-svelte-dom/with-schemas/index.d.ts +94 -10
  37. package/@types/ui-svelte-inspector/index.d.ts +1 -1
  38. package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
  39. package/agents.md +4 -0
  40. package/index.js +76 -22
  41. package/mergeable-store/index.js +76 -22
  42. package/mergeable-store/with-schemas/index.js +76 -22
  43. package/min/index.js +1 -1
  44. package/min/index.js.gz +0 -0
  45. package/min/mergeable-store/index.js +1 -1
  46. package/min/mergeable-store/index.js.gz +0 -0
  47. package/min/mergeable-store/with-schemas/index.js +1 -1
  48. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  49. package/min/omni/index.js +1 -1
  50. package/min/omni/index.js.gz +0 -0
  51. package/min/omni/with-schemas/index.js +1 -1
  52. package/min/omni/with-schemas/index.js.gz +0 -0
  53. package/min/schematizers/index.js +1 -1
  54. package/min/schematizers/index.js.gz +0 -0
  55. package/min/schematizers/schematizer-arktype/index.js +1 -1
  56. package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
  57. package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
  58. package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
  59. package/min/schematizers/schematizer-effect/index.js +1 -1
  60. package/min/schematizers/schematizer-effect/index.js.gz +0 -0
  61. package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
  62. package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
  63. package/min/schematizers/schematizer-typebox/index.js +1 -1
  64. package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
  65. package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
  66. package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
  67. package/min/schematizers/schematizer-valibot/index.js +1 -1
  68. package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
  69. package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
  70. package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
  71. package/min/schematizers/schematizer-yup/index.js +1 -1
  72. package/min/schematizers/schematizer-yup/index.js.gz +0 -0
  73. package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
  74. package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
  75. package/min/schematizers/schematizer-zod/index.js +1 -1
  76. package/min/schematizers/schematizer-zod/index.js.gz +0 -0
  77. package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
  78. package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
  79. package/min/schematizers/with-schemas/index.js +1 -1
  80. package/min/schematizers/with-schemas/index.js.gz +0 -0
  81. package/min/store/index.js +1 -1
  82. package/min/store/index.js.gz +0 -0
  83. package/min/store/with-schemas/index.js +1 -1
  84. package/min/store/with-schemas/index.js.gz +0 -0
  85. package/min/ui-react-inspector/index.js +1 -1
  86. package/min/ui-react-inspector/index.js.gz +0 -0
  87. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  88. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  89. package/min/ui-solid-inspector/index.js +1 -1
  90. package/min/ui-solid-inspector/index.js.gz +0 -0
  91. package/min/ui-solid-inspector/with-schemas/index.js +1 -1
  92. package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
  93. package/min/ui-svelte-inspector/index.js +1 -1
  94. package/min/ui-svelte-inspector/index.js.gz +0 -0
  95. package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
  96. package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
  97. package/min/with-schemas/index.js +1 -1
  98. package/min/with-schemas/index.js.gz +0 -0
  99. package/omni/index.js +76 -22
  100. package/omni/with-schemas/index.js +76 -22
  101. package/package.json +5 -5
  102. package/readme.md +3 -3
  103. package/releases.md +32 -2
  104. package/schematizers/index.js +54 -6
  105. package/schematizers/schematizer-arktype/index.js +99 -19
  106. package/schematizers/schematizer-arktype/with-schemas/index.js +99 -19
  107. package/schematizers/schematizer-effect/index.js +101 -11
  108. package/schematizers/schematizer-effect/with-schemas/index.js +101 -11
  109. package/schematizers/schematizer-typebox/index.js +87 -11
  110. package/schematizers/schematizer-typebox/with-schemas/index.js +87 -11
  111. package/schematizers/schematizer-valibot/index.js +125 -21
  112. package/schematizers/schematizer-valibot/with-schemas/index.js +125 -21
  113. package/schematizers/schematizer-yup/index.js +58 -14
  114. package/schematizers/schematizer-yup/with-schemas/index.js +58 -14
  115. package/schematizers/schematizer-zod/index.js +131 -12
  116. package/schematizers/schematizer-zod/with-schemas/index.js +131 -12
  117. package/schematizers/with-schemas/index.js +54 -6
  118. package/store/index.js +76 -22
  119. package/store/with-schemas/index.js +76 -22
  120. package/ui-react-inspector/index.js +76 -22
  121. package/ui-react-inspector/with-schemas/index.js +76 -22
  122. package/ui-solid-inspector/index.js +76 -22
  123. package/ui-solid-inspector/with-schemas/index.js +76 -22
  124. package/ui-svelte/index.js +1 -1
  125. package/ui-svelte/with-schemas/index.js +1 -1
  126. package/ui-svelte-dom/index.js +2 -2
  127. package/ui-svelte-dom/with-schemas/index.js +2 -2
  128. package/ui-svelte-inspector/index.js +78 -24
  129. package/ui-svelte-inspector/with-schemas/index.js +78 -24
  130. package/with-schemas/index.js +76 -22
@@ -44,6 +44,7 @@ const FUNCTION = getTypeOf(getTypeOf);
44
44
  const OBJECT = 'object';
45
45
  const ARRAY = 'array';
46
46
  const TYPE = 'type';
47
+ const ENUM = 'enum';
47
48
  const DEFAULT = 'default';
48
49
  const ALLOW_NULL = 'allowNull';
49
50
  const NULL = 'null';
@@ -1475,6 +1476,14 @@ const getCellOrValueType = (cellOrValue) => {
1475
1476
  : void 0;
1476
1477
  };
1477
1478
  const isJsonType = (type) => type == OBJECT || type == ARRAY;
1479
+ const isCellOrValueSchemaType = (type) =>
1480
+ isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
1481
+ const isCellOrValueSchemaTypes = (types) =>
1482
+ isArray(types)
1483
+ ? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
1484
+ : isCellOrValueSchemaType(types);
1485
+ const cellOrValueSchemaTypeIncludes = (types, type) =>
1486
+ isArray(types) ? arrayHas(types, type) : types == type;
1478
1487
  const encodeIfJson = (value) =>
1479
1488
  isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
1480
1489
  const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
@@ -1630,13 +1639,29 @@ const createStore = () => {
1630
1639
  const validateCellOrValueSchema = (schema) => {
1631
1640
  if (
1632
1641
  !objValidate(schema, (_child, id2) =>
1633
- arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1642
+ arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1634
1643
  )
1635
1644
  ) {
1636
1645
  return false;
1637
1646
  }
1638
1647
  const type = schema[TYPE];
1639
- if (!isTypeStringOrBoolean(type) && type != NUMBER && !isJsonType(type)) {
1648
+ const enumValues = schema[ENUM];
1649
+ if (
1650
+ isUndefined(enumValues)
1651
+ ? !isCellOrValueSchemaTypes(type)
1652
+ : !isUndefined(type) ||
1653
+ !isArray(enumValues) ||
1654
+ isUndefined(enumValues[0]) ||
1655
+ !arrayEvery(enumValues, (enumValue) => {
1656
+ const enumType = getCellOrValueType(enumValue);
1657
+ return (
1658
+ !isNull(enumValue) &&
1659
+ !isUndefined(enumType) &&
1660
+ !isJsonType(enumType) &&
1661
+ !isReservedString(enumValue)
1662
+ );
1663
+ })
1664
+ ) {
1640
1665
  return false;
1641
1666
  }
1642
1667
  const defaultValue = schema[DEFAULT];
@@ -1645,7 +1670,12 @@ const createStore = () => {
1645
1670
  }
1646
1671
  if (!isNull(defaultValue)) {
1647
1672
  if (
1648
- getCellOrValueType(defaultValue) != type ||
1673
+ (isUndefined(enumValues)
1674
+ ? !cellOrValueSchemaTypeIncludes(
1675
+ type,
1676
+ getCellOrValueType(defaultValue),
1677
+ )
1678
+ : !arrayHas(enumValues, defaultValue)) ||
1649
1679
  isReservedString(defaultValue)
1650
1680
  ) {
1651
1681
  objDel(schema, DEFAULT);
@@ -1672,13 +1702,15 @@ const createStore = () => {
1672
1702
  isObject(tables) ? objMap(tables, cloneTable) : tables;
1673
1703
  const cloneValues = (values) =>
1674
1704
  isObject(values) ? objMap(values, getArg) : values;
1675
- const isValidEncodedJson = (cellOrValue, type) =>
1705
+ const isValidEncodedJson = (cellOrValue, types) =>
1676
1706
  acceptingEncodedData == 1 &&
1677
1707
  isEncodedJson(cellOrValue) &&
1678
1708
  tryReturn(() => {
1679
1709
  const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
1680
1710
  return (
1681
- isJsonType(encodedType) && (isUndefined(type) || type == encodedType)
1711
+ isJsonType(encodedType) &&
1712
+ (isUndefined(types) ||
1713
+ cellOrValueSchemaTypeIncludes(types, encodedType))
1682
1714
  );
1683
1715
  }, false) == true;
1684
1716
  const validateContent = isArray;
@@ -1731,7 +1763,8 @@ const createStore = () => {
1731
1763
  : isReservedString(cell, acceptingEncodedData)
1732
1764
  ? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
1733
1765
  : isEncodedJson(cell)
1734
- ? isValidEncodedJson(cell, cellSchema[TYPE])
1766
+ ? isUndefined(cellSchema[ENUM]) &&
1767
+ isValidEncodedJson(cell, cellSchema[TYPE])
1735
1768
  ? cell
1736
1769
  : cellInvalid(
1737
1770
  tableId,
@@ -1740,23 +1773,36 @@ const createStore = () => {
1740
1773
  cell,
1741
1774
  cellSchema[DEFAULT],
1742
1775
  )
1743
- : getCellOrValueType(cell) === cellSchema[TYPE]
1744
- ? encodeValid(cell, () =>
1745
- cellInvalid(
1776
+ : isUndefined(cellSchema[ENUM])
1777
+ ? cellOrValueSchemaTypeIncludes(
1778
+ cellSchema[TYPE],
1779
+ getCellOrValueType(cell),
1780
+ )
1781
+ ? encodeValid(cell, () =>
1782
+ cellInvalid(
1783
+ tableId,
1784
+ rowId,
1785
+ cellId,
1786
+ cell,
1787
+ cellSchema[DEFAULT],
1788
+ ),
1789
+ )
1790
+ : cellInvalid(
1791
+ tableId,
1792
+ rowId,
1793
+ cellId,
1794
+ cell,
1795
+ cellSchema[DEFAULT],
1796
+ )
1797
+ : arrayHas(cellSchema[ENUM], cell)
1798
+ ? cell
1799
+ : cellInvalid(
1746
1800
  tableId,
1747
1801
  rowId,
1748
1802
  cellId,
1749
1803
  cell,
1750
1804
  cellSchema[DEFAULT],
1751
1805
  ),
1752
- )
1753
- : cellInvalid(
1754
- tableId,
1755
- rowId,
1756
- cellId,
1757
- cell,
1758
- cellSchema[DEFAULT],
1759
- ),
1760
1806
  () => cellInvalid(tableId, rowId, cellId, cell),
1761
1807
  )
1762
1808
  : isUndefined(getCellOrValueType(cell)) ||
@@ -1801,14 +1847,22 @@ const createStore = () => {
1801
1847
  : isReservedString(value, acceptingEncodedData)
1802
1848
  ? valueInvalid(valueId, value, valueSchema[DEFAULT])
1803
1849
  : isEncodedJson(value)
1804
- ? isValidEncodedJson(value, valueSchema[TYPE])
1850
+ ? isUndefined(valueSchema[ENUM]) &&
1851
+ isValidEncodedJson(value, valueSchema[TYPE])
1805
1852
  ? value
1806
1853
  : valueInvalid(valueId, value, valueSchema[DEFAULT])
1807
- : getCellOrValueType(value) === valueSchema[TYPE]
1808
- ? encodeValid(value, () =>
1809
- valueInvalid(valueId, value, valueSchema[DEFAULT]),
1854
+ : isUndefined(valueSchema[ENUM])
1855
+ ? cellOrValueSchemaTypeIncludes(
1856
+ valueSchema[TYPE],
1857
+ getCellOrValueType(value),
1810
1858
  )
1811
- : valueInvalid(valueId, value, valueSchema[DEFAULT]),
1859
+ ? encodeValid(value, () =>
1860
+ valueInvalid(valueId, value, valueSchema[DEFAULT]),
1861
+ )
1862
+ : valueInvalid(valueId, value, valueSchema[DEFAULT])
1863
+ : arrayHas(valueSchema[ENUM], value)
1864
+ ? value
1865
+ : valueInvalid(valueId, value, valueSchema[DEFAULT]),
1812
1866
  () => valueInvalid(valueId, value),
1813
1867
  )
1814
1868
  : isUndefined(getCellOrValueType(value)) ||
@@ -80,6 +80,7 @@ const FUNCTION = getTypeOf(getTypeOf);
80
80
  const OBJECT = 'object';
81
81
  const ARRAY = 'array';
82
82
  const TYPE = 'type';
83
+ const ENUM = 'enum';
83
84
  const DEFAULT = 'default';
84
85
  const ALLOW_NULL = 'allowNull';
85
86
  const NULL = 'null';
@@ -1537,6 +1538,14 @@ const getCellOrValueType = (cellOrValue) => {
1537
1538
  : void 0;
1538
1539
  };
1539
1540
  const isJsonType = (type) => type == OBJECT || type == ARRAY;
1541
+ const isCellOrValueSchemaType = (type) =>
1542
+ isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
1543
+ const isCellOrValueSchemaTypes = (types) =>
1544
+ isArray(types)
1545
+ ? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
1546
+ : isCellOrValueSchemaType(types);
1547
+ const cellOrValueSchemaTypeIncludes = (types, type) =>
1548
+ isArray(types) ? arrayHas(types, type) : types == type;
1540
1549
  const encodeIfJson = (value) =>
1541
1550
  isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
1542
1551
  const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
@@ -1692,13 +1701,29 @@ const createStore = () => {
1692
1701
  const validateCellOrValueSchema = (schema) => {
1693
1702
  if (
1694
1703
  !objValidate(schema, (_child, id2) =>
1695
- arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1704
+ arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1696
1705
  )
1697
1706
  ) {
1698
1707
  return false;
1699
1708
  }
1700
1709
  const type = schema[TYPE];
1701
- if (!isTypeStringOrBoolean(type) && type != NUMBER && !isJsonType(type)) {
1710
+ const enumValues = schema[ENUM];
1711
+ if (
1712
+ isUndefined(enumValues)
1713
+ ? !isCellOrValueSchemaTypes(type)
1714
+ : !isUndefined(type) ||
1715
+ !isArray(enumValues) ||
1716
+ isUndefined(enumValues[0]) ||
1717
+ !arrayEvery(enumValues, (enumValue) => {
1718
+ const enumType = getCellOrValueType(enumValue);
1719
+ return (
1720
+ !isNull(enumValue) &&
1721
+ !isUndefined(enumType) &&
1722
+ !isJsonType(enumType) &&
1723
+ !isReservedString(enumValue)
1724
+ );
1725
+ })
1726
+ ) {
1702
1727
  return false;
1703
1728
  }
1704
1729
  const defaultValue = schema[DEFAULT];
@@ -1707,7 +1732,12 @@ const createStore = () => {
1707
1732
  }
1708
1733
  if (!isNull(defaultValue)) {
1709
1734
  if (
1710
- getCellOrValueType(defaultValue) != type ||
1735
+ (isUndefined(enumValues)
1736
+ ? !cellOrValueSchemaTypeIncludes(
1737
+ type,
1738
+ getCellOrValueType(defaultValue),
1739
+ )
1740
+ : !arrayHas(enumValues, defaultValue)) ||
1711
1741
  isReservedString(defaultValue)
1712
1742
  ) {
1713
1743
  objDel(schema, DEFAULT);
@@ -1734,13 +1764,15 @@ const createStore = () => {
1734
1764
  isObject(tables) ? objMap(tables, cloneTable) : tables;
1735
1765
  const cloneValues = (values) =>
1736
1766
  isObject(values) ? objMap(values, getArg) : values;
1737
- const isValidEncodedJson = (cellOrValue, type) =>
1767
+ const isValidEncodedJson = (cellOrValue, types) =>
1738
1768
  acceptingEncodedData == 1 &&
1739
1769
  isEncodedJson(cellOrValue) &&
1740
1770
  tryReturn(() => {
1741
1771
  const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
1742
1772
  return (
1743
- isJsonType(encodedType) && (isUndefined(type) || type == encodedType)
1773
+ isJsonType(encodedType) &&
1774
+ (isUndefined(types) ||
1775
+ cellOrValueSchemaTypeIncludes(types, encodedType))
1744
1776
  );
1745
1777
  }, false) == true;
1746
1778
  const validateContent = isArray;
@@ -1793,7 +1825,8 @@ const createStore = () => {
1793
1825
  : isReservedString(cell, acceptingEncodedData)
1794
1826
  ? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
1795
1827
  : isEncodedJson(cell)
1796
- ? isValidEncodedJson(cell, cellSchema[TYPE])
1828
+ ? isUndefined(cellSchema[ENUM]) &&
1829
+ isValidEncodedJson(cell, cellSchema[TYPE])
1797
1830
  ? cell
1798
1831
  : cellInvalid(
1799
1832
  tableId,
@@ -1802,23 +1835,36 @@ const createStore = () => {
1802
1835
  cell,
1803
1836
  cellSchema[DEFAULT],
1804
1837
  )
1805
- : getCellOrValueType(cell) === cellSchema[TYPE]
1806
- ? encodeValid(cell, () =>
1807
- cellInvalid(
1838
+ : isUndefined(cellSchema[ENUM])
1839
+ ? cellOrValueSchemaTypeIncludes(
1840
+ cellSchema[TYPE],
1841
+ getCellOrValueType(cell),
1842
+ )
1843
+ ? encodeValid(cell, () =>
1844
+ cellInvalid(
1845
+ tableId,
1846
+ rowId,
1847
+ cellId,
1848
+ cell,
1849
+ cellSchema[DEFAULT],
1850
+ ),
1851
+ )
1852
+ : cellInvalid(
1853
+ tableId,
1854
+ rowId,
1855
+ cellId,
1856
+ cell,
1857
+ cellSchema[DEFAULT],
1858
+ )
1859
+ : arrayHas(cellSchema[ENUM], cell)
1860
+ ? cell
1861
+ : cellInvalid(
1808
1862
  tableId,
1809
1863
  rowId,
1810
1864
  cellId,
1811
1865
  cell,
1812
1866
  cellSchema[DEFAULT],
1813
1867
  ),
1814
- )
1815
- : cellInvalid(
1816
- tableId,
1817
- rowId,
1818
- cellId,
1819
- cell,
1820
- cellSchema[DEFAULT],
1821
- ),
1822
1868
  () => cellInvalid(tableId, rowId, cellId, cell),
1823
1869
  )
1824
1870
  : isUndefined(getCellOrValueType(cell)) ||
@@ -1863,14 +1909,22 @@ const createStore = () => {
1863
1909
  : isReservedString(value, acceptingEncodedData)
1864
1910
  ? valueInvalid(valueId, value, valueSchema[DEFAULT])
1865
1911
  : isEncodedJson(value)
1866
- ? isValidEncodedJson(value, valueSchema[TYPE])
1912
+ ? isUndefined(valueSchema[ENUM]) &&
1913
+ isValidEncodedJson(value, valueSchema[TYPE])
1867
1914
  ? value
1868
1915
  : valueInvalid(valueId, value, valueSchema[DEFAULT])
1869
- : getCellOrValueType(value) === valueSchema[TYPE]
1870
- ? encodeValid(value, () =>
1871
- valueInvalid(valueId, value, valueSchema[DEFAULT]),
1916
+ : isUndefined(valueSchema[ENUM])
1917
+ ? cellOrValueSchemaTypeIncludes(
1918
+ valueSchema[TYPE],
1919
+ getCellOrValueType(value),
1872
1920
  )
1873
- : valueInvalid(valueId, value, valueSchema[DEFAULT]),
1921
+ ? encodeValid(value, () =>
1922
+ valueInvalid(valueId, value, valueSchema[DEFAULT]),
1923
+ )
1924
+ : valueInvalid(valueId, value, valueSchema[DEFAULT])
1925
+ : arrayHas(valueSchema[ENUM], value)
1926
+ ? value
1927
+ : valueInvalid(valueId, value, valueSchema[DEFAULT]),
1874
1928
  () => valueInvalid(valueId, value),
1875
1929
  )
1876
1930
  : isUndefined(getCellOrValueType(value)) ||
@@ -80,6 +80,7 @@ const FUNCTION = getTypeOf(getTypeOf);
80
80
  const OBJECT = 'object';
81
81
  const ARRAY = 'array';
82
82
  const TYPE = 'type';
83
+ const ENUM = 'enum';
83
84
  const DEFAULT = 'default';
84
85
  const ALLOW_NULL = 'allowNull';
85
86
  const NULL = 'null';
@@ -1537,6 +1538,14 @@ const getCellOrValueType = (cellOrValue) => {
1537
1538
  : void 0;
1538
1539
  };
1539
1540
  const isJsonType = (type) => type == OBJECT || type == ARRAY;
1541
+ const isCellOrValueSchemaType = (type) =>
1542
+ isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
1543
+ const isCellOrValueSchemaTypes = (types) =>
1544
+ isArray(types)
1545
+ ? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
1546
+ : isCellOrValueSchemaType(types);
1547
+ const cellOrValueSchemaTypeIncludes = (types, type) =>
1548
+ isArray(types) ? arrayHas(types, type) : types == type;
1540
1549
  const encodeIfJson = (value) =>
1541
1550
  isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
1542
1551
  const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
@@ -1692,13 +1701,29 @@ const createStore = () => {
1692
1701
  const validateCellOrValueSchema = (schema) => {
1693
1702
  if (
1694
1703
  !objValidate(schema, (_child, id2) =>
1695
- arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1704
+ arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1696
1705
  )
1697
1706
  ) {
1698
1707
  return false;
1699
1708
  }
1700
1709
  const type = schema[TYPE];
1701
- if (!isTypeStringOrBoolean(type) && type != NUMBER && !isJsonType(type)) {
1710
+ const enumValues = schema[ENUM];
1711
+ if (
1712
+ isUndefined(enumValues)
1713
+ ? !isCellOrValueSchemaTypes(type)
1714
+ : !isUndefined(type) ||
1715
+ !isArray(enumValues) ||
1716
+ isUndefined(enumValues[0]) ||
1717
+ !arrayEvery(enumValues, (enumValue) => {
1718
+ const enumType = getCellOrValueType(enumValue);
1719
+ return (
1720
+ !isNull(enumValue) &&
1721
+ !isUndefined(enumType) &&
1722
+ !isJsonType(enumType) &&
1723
+ !isReservedString(enumValue)
1724
+ );
1725
+ })
1726
+ ) {
1702
1727
  return false;
1703
1728
  }
1704
1729
  const defaultValue = schema[DEFAULT];
@@ -1707,7 +1732,12 @@ const createStore = () => {
1707
1732
  }
1708
1733
  if (!isNull(defaultValue)) {
1709
1734
  if (
1710
- getCellOrValueType(defaultValue) != type ||
1735
+ (isUndefined(enumValues)
1736
+ ? !cellOrValueSchemaTypeIncludes(
1737
+ type,
1738
+ getCellOrValueType(defaultValue),
1739
+ )
1740
+ : !arrayHas(enumValues, defaultValue)) ||
1711
1741
  isReservedString(defaultValue)
1712
1742
  ) {
1713
1743
  objDel(schema, DEFAULT);
@@ -1734,13 +1764,15 @@ const createStore = () => {
1734
1764
  isObject(tables) ? objMap(tables, cloneTable) : tables;
1735
1765
  const cloneValues = (values) =>
1736
1766
  isObject(values) ? objMap(values, getArg) : values;
1737
- const isValidEncodedJson = (cellOrValue, type) =>
1767
+ const isValidEncodedJson = (cellOrValue, types) =>
1738
1768
  acceptingEncodedData == 1 &&
1739
1769
  isEncodedJson(cellOrValue) &&
1740
1770
  tryReturn(() => {
1741
1771
  const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
1742
1772
  return (
1743
- isJsonType(encodedType) && (isUndefined(type) || type == encodedType)
1773
+ isJsonType(encodedType) &&
1774
+ (isUndefined(types) ||
1775
+ cellOrValueSchemaTypeIncludes(types, encodedType))
1744
1776
  );
1745
1777
  }, false) == true;
1746
1778
  const validateContent = isArray;
@@ -1793,7 +1825,8 @@ const createStore = () => {
1793
1825
  : isReservedString(cell, acceptingEncodedData)
1794
1826
  ? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
1795
1827
  : isEncodedJson(cell)
1796
- ? isValidEncodedJson(cell, cellSchema[TYPE])
1828
+ ? isUndefined(cellSchema[ENUM]) &&
1829
+ isValidEncodedJson(cell, cellSchema[TYPE])
1797
1830
  ? cell
1798
1831
  : cellInvalid(
1799
1832
  tableId,
@@ -1802,23 +1835,36 @@ const createStore = () => {
1802
1835
  cell,
1803
1836
  cellSchema[DEFAULT],
1804
1837
  )
1805
- : getCellOrValueType(cell) === cellSchema[TYPE]
1806
- ? encodeValid(cell, () =>
1807
- cellInvalid(
1838
+ : isUndefined(cellSchema[ENUM])
1839
+ ? cellOrValueSchemaTypeIncludes(
1840
+ cellSchema[TYPE],
1841
+ getCellOrValueType(cell),
1842
+ )
1843
+ ? encodeValid(cell, () =>
1844
+ cellInvalid(
1845
+ tableId,
1846
+ rowId,
1847
+ cellId,
1848
+ cell,
1849
+ cellSchema[DEFAULT],
1850
+ ),
1851
+ )
1852
+ : cellInvalid(
1853
+ tableId,
1854
+ rowId,
1855
+ cellId,
1856
+ cell,
1857
+ cellSchema[DEFAULT],
1858
+ )
1859
+ : arrayHas(cellSchema[ENUM], cell)
1860
+ ? cell
1861
+ : cellInvalid(
1808
1862
  tableId,
1809
1863
  rowId,
1810
1864
  cellId,
1811
1865
  cell,
1812
1866
  cellSchema[DEFAULT],
1813
1867
  ),
1814
- )
1815
- : cellInvalid(
1816
- tableId,
1817
- rowId,
1818
- cellId,
1819
- cell,
1820
- cellSchema[DEFAULT],
1821
- ),
1822
1868
  () => cellInvalid(tableId, rowId, cellId, cell),
1823
1869
  )
1824
1870
  : isUndefined(getCellOrValueType(cell)) ||
@@ -1863,14 +1909,22 @@ const createStore = () => {
1863
1909
  : isReservedString(value, acceptingEncodedData)
1864
1910
  ? valueInvalid(valueId, value, valueSchema[DEFAULT])
1865
1911
  : isEncodedJson(value)
1866
- ? isValidEncodedJson(value, valueSchema[TYPE])
1912
+ ? isUndefined(valueSchema[ENUM]) &&
1913
+ isValidEncodedJson(value, valueSchema[TYPE])
1867
1914
  ? value
1868
1915
  : valueInvalid(valueId, value, valueSchema[DEFAULT])
1869
- : getCellOrValueType(value) === valueSchema[TYPE]
1870
- ? encodeValid(value, () =>
1871
- valueInvalid(valueId, value, valueSchema[DEFAULT]),
1916
+ : isUndefined(valueSchema[ENUM])
1917
+ ? cellOrValueSchemaTypeIncludes(
1918
+ valueSchema[TYPE],
1919
+ getCellOrValueType(value),
1872
1920
  )
1873
- : valueInvalid(valueId, value, valueSchema[DEFAULT]),
1921
+ ? encodeValid(value, () =>
1922
+ valueInvalid(valueId, value, valueSchema[DEFAULT]),
1923
+ )
1924
+ : valueInvalid(valueId, value, valueSchema[DEFAULT])
1925
+ : arrayHas(valueSchema[ENUM], value)
1926
+ ? value
1927
+ : valueInvalid(valueId, value, valueSchema[DEFAULT]),
1874
1928
  () => valueInvalid(valueId, value),
1875
1929
  )
1876
1930
  : isUndefined(getCellOrValueType(value)) ||
@@ -88,7 +88,7 @@ const objDel = (obj, id) => {
88
88
 
89
89
  const TINYBASE_CONTEXT_KEY = TINYBASE + '_uisc';
90
90
 
91
- /* functions.svelte.ts generated by Svelte v5.56.8 */
91
+ /* functions.svelte.ts generated by Svelte v5.56.9 */
92
92
 
93
93
  class ReactiveHandle {
94
94
  #get;
@@ -88,7 +88,7 @@ const objDel = (obj, id) => {
88
88
 
89
89
  const TINYBASE_CONTEXT_KEY = TINYBASE + '_uisc';
90
90
 
91
- /* functions.svelte.ts generated by Svelte v5.56.8 */
91
+ /* functions.svelte.ts generated by Svelte v5.56.9 */
92
92
 
93
93
  class ReactiveHandle {
94
94
  #get;
@@ -107,7 +107,7 @@ const objMap = (obj, cb) => {
107
107
 
108
108
  const TINYBASE_CONTEXT_KEY = TINYBASE + '_uisc';
109
109
 
110
- /* functions.svelte.ts generated by Svelte v5.56.8 */
110
+ /* functions.svelte.ts generated by Svelte v5.56.9 */
111
111
 
112
112
  class ReactiveHandle {
113
113
  #get;
@@ -1750,7 +1750,7 @@ function SortedTablePaginator($$anchor, $$props) {
1750
1750
 
1751
1751
  $.delegate(['click']);
1752
1752
 
1753
- /* sortingAndPagination.svelte.ts generated by Svelte v5.56.8 */
1753
+ /* sortingAndPagination.svelte.ts generated by Svelte v5.56.9 */
1754
1754
 
1755
1755
  const createSortingAndPagination = (
1756
1756
  getCellId,
@@ -107,7 +107,7 @@ const objMap = (obj, cb) => {
107
107
 
108
108
  const TINYBASE_CONTEXT_KEY = TINYBASE + '_uisc';
109
109
 
110
- /* functions.svelte.ts generated by Svelte v5.56.8 */
110
+ /* functions.svelte.ts generated by Svelte v5.56.9 */
111
111
 
112
112
  class ReactiveHandle {
113
113
  #get;
@@ -1750,7 +1750,7 @@ function SortedTablePaginator($$anchor, $$props) {
1750
1750
 
1751
1751
  $.delegate(['click']);
1752
1752
 
1753
- /* sortingAndPagination.svelte.ts generated by Svelte v5.56.8 */
1753
+ /* sortingAndPagination.svelte.ts generated by Svelte v5.56.9 */
1754
1754
 
1755
1755
  const createSortingAndPagination = (
1756
1756
  getCellId,