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
@@ -6,21 +6,31 @@ const NUMBER = getTypeOf(0);
6
6
  const OBJECT = 'object';
7
7
  const ARRAY = 'array';
8
8
  const TYPE = 'type';
9
+ const ENUM = 'enum';
9
10
  const DEFAULT = 'default';
10
11
  const ALLOW_NULL = 'allowNull';
12
+ const NULL = 'null';
11
13
  const REQUIRED = 'required';
14
+ const UNDEFINED = '\uFFFC';
15
+ const JSON_PREFIX = '\uFFFD';
12
16
 
13
17
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
14
18
  predicate(value)
15
19
  ? /* istanbul ignore next */
16
20
  otherwise?.()
17
21
  : then(value);
22
+ const isFiniteNumber = isFinite;
18
23
  const isNullish = (thing) => thing == null;
19
24
  const isUndefined = (thing) => thing === void 0;
25
+ const isNull = (thing) => thing === null;
20
26
  const ifNotNullish = getIfNotFunction(isNullish);
21
27
  const ifNotUndefined = getIfNotFunction(isUndefined);
28
+ const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
29
+ const isString = (thing) => getTypeOf(thing) == STRING;
30
+ const isArray = (thing) => Array.isArray(thing);
22
31
  const size = (thing) => thing.length;
23
32
 
33
+ const arrayEvery = (array, cb) => array.every(cb);
24
34
  const arrayForEach = (array, cb) => array.forEach(cb);
25
35
 
26
36
  const object = Object;
@@ -57,6 +67,33 @@ const objForEach = (obj, cb) =>
57
67
  const objSize = (obj) => size(objIds(obj));
58
68
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
59
69
 
70
+ const getCellOrValueType = (cellOrValue) => {
71
+ if (isNull(cellOrValue)) {
72
+ return NULL;
73
+ }
74
+ if (isArray(cellOrValue)) {
75
+ return ARRAY;
76
+ }
77
+ if (isObject(cellOrValue)) {
78
+ return OBJECT;
79
+ }
80
+ const type = getTypeOf(cellOrValue);
81
+ return isTypeStringOrBoolean(type) ||
82
+ (type == NUMBER && isFiniteNumber(cellOrValue))
83
+ ? type
84
+ : void 0;
85
+ };
86
+ const isJsonType = (type) => type == OBJECT || type == ARRAY;
87
+ const isCellOrValueSchemaType = (type) =>
88
+ isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
89
+ const isCellOrValueSchemaTypes = (types) =>
90
+ isArray(types)
91
+ ? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
92
+ : isCellOrValueSchemaType(types);
93
+ const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
94
+ const isReservedString = (value, encoded = 0) =>
95
+ value === UNDEFINED || (!encoded && isEncodedJson(value));
96
+
60
97
  const createCustomSchematizer = (
61
98
  unwrapSchema,
62
99
  getProperties,
@@ -66,16 +103,27 @@ const createCustomSchematizer = (
66
103
  const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
67
104
  unwrapSchema(schema, void 0, void 0, required);
68
105
  const type = unwrapped?.type;
106
+ const enumValues = unwrapped?.[ENUM];
107
+ const isEnum =
108
+ isUndefined(type) &&
109
+ isArray(enumValues) &&
110
+ !isUndefined(enumValues[0]) &&
111
+ arrayEvery(enumValues, (enumValue) => {
112
+ const enumType = getCellOrValueType(enumValue);
113
+ return (
114
+ !isNull(enumValue) &&
115
+ !isUndefined(enumType) &&
116
+ !isJsonType(enumType) &&
117
+ !isReservedString(enumValue)
118
+ );
119
+ });
69
120
  if (
70
- type !== STRING &&
71
- type !== NUMBER &&
72
- type !== BOOLEAN &&
73
- type !== OBJECT &&
74
- type !== ARRAY
121
+ !isEnum &&
122
+ (!isUndefined(enumValues) || !isCellOrValueSchemaTypes(type))
75
123
  ) {
76
124
  return void 0;
77
125
  }
78
- const cellOrValueSchema = {[TYPE]: type};
126
+ const cellOrValueSchema = isEnum ? {[ENUM]: enumValues} : {[TYPE]: type};
79
127
  ifNotUndefined(defaultValue, (defaultValue2) => {
80
128
  cellOrValueSchema[DEFAULT] = defaultValue2;
81
129
  });
package/store/index.js CHANGED
@@ -7,6 +7,7 @@ const FUNCTION = getTypeOf(getTypeOf);
7
7
  const OBJECT = 'object';
8
8
  const ARRAY = 'array';
9
9
  const TYPE = 'type';
10
+ const ENUM = 'enum';
10
11
  const DEFAULT = 'default';
11
12
  const ALLOW_NULL = 'allowNull';
12
13
  const NULL = 'null';
@@ -173,6 +174,14 @@ const getCellOrValueType = (cellOrValue) => {
173
174
  : void 0;
174
175
  };
175
176
  const isJsonType = (type) => type == OBJECT || type == ARRAY;
177
+ const isCellOrValueSchemaType = (type) =>
178
+ isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
179
+ const isCellOrValueSchemaTypes = (types) =>
180
+ isArray(types)
181
+ ? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
182
+ : isCellOrValueSchemaType(types);
183
+ const cellOrValueSchemaTypeIncludes = (types, type) =>
184
+ isArray(types) ? arrayHas(types, type) : types == type;
176
185
  const encodeIfJson = (value) =>
177
186
  isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
178
187
  const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
@@ -560,13 +569,29 @@ const createStore = () => {
560
569
  const validateCellOrValueSchema = (schema) => {
561
570
  if (
562
571
  !objValidate(schema, (_child, id2) =>
563
- arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
572
+ arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
564
573
  )
565
574
  ) {
566
575
  return false;
567
576
  }
568
577
  const type = schema[TYPE];
569
- if (!isTypeStringOrBoolean(type) && type != NUMBER && !isJsonType(type)) {
578
+ const enumValues = schema[ENUM];
579
+ if (
580
+ isUndefined(enumValues)
581
+ ? !isCellOrValueSchemaTypes(type)
582
+ : !isUndefined(type) ||
583
+ !isArray(enumValues) ||
584
+ isUndefined(enumValues[0]) ||
585
+ !arrayEvery(enumValues, (enumValue) => {
586
+ const enumType = getCellOrValueType(enumValue);
587
+ return (
588
+ !isNull(enumValue) &&
589
+ !isUndefined(enumType) &&
590
+ !isJsonType(enumType) &&
591
+ !isReservedString(enumValue)
592
+ );
593
+ })
594
+ ) {
570
595
  return false;
571
596
  }
572
597
  const defaultValue = schema[DEFAULT];
@@ -575,7 +600,12 @@ const createStore = () => {
575
600
  }
576
601
  if (!isNull(defaultValue)) {
577
602
  if (
578
- getCellOrValueType(defaultValue) != type ||
603
+ (isUndefined(enumValues)
604
+ ? !cellOrValueSchemaTypeIncludes(
605
+ type,
606
+ getCellOrValueType(defaultValue),
607
+ )
608
+ : !arrayHas(enumValues, defaultValue)) ||
579
609
  isReservedString(defaultValue)
580
610
  ) {
581
611
  objDel(schema, DEFAULT);
@@ -602,13 +632,15 @@ const createStore = () => {
602
632
  isObject(tables) ? objMap(tables, cloneTable) : tables;
603
633
  const cloneValues = (values) =>
604
634
  isObject(values) ? objMap(values, getArg) : values;
605
- const isValidEncodedJson = (cellOrValue, type) =>
635
+ const isValidEncodedJson = (cellOrValue, types) =>
606
636
  acceptingEncodedData == 1 &&
607
637
  isEncodedJson(cellOrValue) &&
608
638
  tryReturn(() => {
609
639
  const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
610
640
  return (
611
- isJsonType(encodedType) && (isUndefined(type) || type == encodedType)
641
+ isJsonType(encodedType) &&
642
+ (isUndefined(types) ||
643
+ cellOrValueSchemaTypeIncludes(types, encodedType))
612
644
  );
613
645
  }, false) == true;
614
646
  const validateContent = isArray;
@@ -661,7 +693,8 @@ const createStore = () => {
661
693
  : isReservedString(cell, acceptingEncodedData)
662
694
  ? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
663
695
  : isEncodedJson(cell)
664
- ? isValidEncodedJson(cell, cellSchema[TYPE])
696
+ ? isUndefined(cellSchema[ENUM]) &&
697
+ isValidEncodedJson(cell, cellSchema[TYPE])
665
698
  ? cell
666
699
  : cellInvalid(
667
700
  tableId,
@@ -670,23 +703,36 @@ const createStore = () => {
670
703
  cell,
671
704
  cellSchema[DEFAULT],
672
705
  )
673
- : getCellOrValueType(cell) === cellSchema[TYPE]
674
- ? encodeValid(cell, () =>
675
- cellInvalid(
706
+ : isUndefined(cellSchema[ENUM])
707
+ ? cellOrValueSchemaTypeIncludes(
708
+ cellSchema[TYPE],
709
+ getCellOrValueType(cell),
710
+ )
711
+ ? encodeValid(cell, () =>
712
+ cellInvalid(
713
+ tableId,
714
+ rowId,
715
+ cellId,
716
+ cell,
717
+ cellSchema[DEFAULT],
718
+ ),
719
+ )
720
+ : cellInvalid(
721
+ tableId,
722
+ rowId,
723
+ cellId,
724
+ cell,
725
+ cellSchema[DEFAULT],
726
+ )
727
+ : arrayHas(cellSchema[ENUM], cell)
728
+ ? cell
729
+ : cellInvalid(
676
730
  tableId,
677
731
  rowId,
678
732
  cellId,
679
733
  cell,
680
734
  cellSchema[DEFAULT],
681
735
  ),
682
- )
683
- : cellInvalid(
684
- tableId,
685
- rowId,
686
- cellId,
687
- cell,
688
- cellSchema[DEFAULT],
689
- ),
690
736
  () => cellInvalid(tableId, rowId, cellId, cell),
691
737
  )
692
738
  : isUndefined(getCellOrValueType(cell)) ||
@@ -731,14 +777,22 @@ const createStore = () => {
731
777
  : isReservedString(value, acceptingEncodedData)
732
778
  ? valueInvalid(valueId, value, valueSchema[DEFAULT])
733
779
  : isEncodedJson(value)
734
- ? isValidEncodedJson(value, valueSchema[TYPE])
780
+ ? isUndefined(valueSchema[ENUM]) &&
781
+ isValidEncodedJson(value, valueSchema[TYPE])
735
782
  ? value
736
783
  : valueInvalid(valueId, value, valueSchema[DEFAULT])
737
- : getCellOrValueType(value) === valueSchema[TYPE]
738
- ? encodeValid(value, () =>
739
- valueInvalid(valueId, value, valueSchema[DEFAULT]),
784
+ : isUndefined(valueSchema[ENUM])
785
+ ? cellOrValueSchemaTypeIncludes(
786
+ valueSchema[TYPE],
787
+ getCellOrValueType(value),
740
788
  )
741
- : valueInvalid(valueId, value, valueSchema[DEFAULT]),
789
+ ? encodeValid(value, () =>
790
+ valueInvalid(valueId, value, valueSchema[DEFAULT]),
791
+ )
792
+ : valueInvalid(valueId, value, valueSchema[DEFAULT])
793
+ : arrayHas(valueSchema[ENUM], value)
794
+ ? value
795
+ : valueInvalid(valueId, value, valueSchema[DEFAULT]),
742
796
  () => valueInvalid(valueId, value),
743
797
  )
744
798
  : isUndefined(getCellOrValueType(value)) ||
@@ -7,6 +7,7 @@ const FUNCTION = getTypeOf(getTypeOf);
7
7
  const OBJECT = 'object';
8
8
  const ARRAY = 'array';
9
9
  const TYPE = 'type';
10
+ const ENUM = 'enum';
10
11
  const DEFAULT = 'default';
11
12
  const ALLOW_NULL = 'allowNull';
12
13
  const NULL = 'null';
@@ -173,6 +174,14 @@ const getCellOrValueType = (cellOrValue) => {
173
174
  : void 0;
174
175
  };
175
176
  const isJsonType = (type) => type == OBJECT || type == ARRAY;
177
+ const isCellOrValueSchemaType = (type) =>
178
+ isTypeStringOrBoolean(type) || type == NUMBER || isJsonType(type);
179
+ const isCellOrValueSchemaTypes = (types) =>
180
+ isArray(types)
181
+ ? !isUndefined(types[0]) && arrayEvery(types, isCellOrValueSchemaType)
182
+ : isCellOrValueSchemaType(types);
183
+ const cellOrValueSchemaTypeIncludes = (types, type) =>
184
+ isArray(types) ? arrayHas(types, type) : types == type;
176
185
  const encodeIfJson = (value) =>
177
186
  isObject(value) || isArray(value) ? JSON_PREFIX + jsonString(value) : value;
178
187
  const isEncodedJson = (value) => isString(value) && value[0] == JSON_PREFIX;
@@ -560,13 +569,29 @@ const createStore = () => {
560
569
  const validateCellOrValueSchema = (schema) => {
561
570
  if (
562
571
  !objValidate(schema, (_child, id2) =>
563
- arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
572
+ arrayHas([TYPE, ENUM, DEFAULT, ALLOW_NULL, REQUIRED], id2),
564
573
  )
565
574
  ) {
566
575
  return false;
567
576
  }
568
577
  const type = schema[TYPE];
569
- if (!isTypeStringOrBoolean(type) && type != NUMBER && !isJsonType(type)) {
578
+ const enumValues = schema[ENUM];
579
+ if (
580
+ isUndefined(enumValues)
581
+ ? !isCellOrValueSchemaTypes(type)
582
+ : !isUndefined(type) ||
583
+ !isArray(enumValues) ||
584
+ isUndefined(enumValues[0]) ||
585
+ !arrayEvery(enumValues, (enumValue) => {
586
+ const enumType = getCellOrValueType(enumValue);
587
+ return (
588
+ !isNull(enumValue) &&
589
+ !isUndefined(enumType) &&
590
+ !isJsonType(enumType) &&
591
+ !isReservedString(enumValue)
592
+ );
593
+ })
594
+ ) {
570
595
  return false;
571
596
  }
572
597
  const defaultValue = schema[DEFAULT];
@@ -575,7 +600,12 @@ const createStore = () => {
575
600
  }
576
601
  if (!isNull(defaultValue)) {
577
602
  if (
578
- getCellOrValueType(defaultValue) != type ||
603
+ (isUndefined(enumValues)
604
+ ? !cellOrValueSchemaTypeIncludes(
605
+ type,
606
+ getCellOrValueType(defaultValue),
607
+ )
608
+ : !arrayHas(enumValues, defaultValue)) ||
579
609
  isReservedString(defaultValue)
580
610
  ) {
581
611
  objDel(schema, DEFAULT);
@@ -602,13 +632,15 @@ const createStore = () => {
602
632
  isObject(tables) ? objMap(tables, cloneTable) : tables;
603
633
  const cloneValues = (values) =>
604
634
  isObject(values) ? objMap(values, getArg) : values;
605
- const isValidEncodedJson = (cellOrValue, type) =>
635
+ const isValidEncodedJson = (cellOrValue, types) =>
606
636
  acceptingEncodedData == 1 &&
607
637
  isEncodedJson(cellOrValue) &&
608
638
  tryReturn(() => {
609
639
  const encodedType = getCellOrValueType(decodeIfJson(cellOrValue));
610
640
  return (
611
- isJsonType(encodedType) && (isUndefined(type) || type == encodedType)
641
+ isJsonType(encodedType) &&
642
+ (isUndefined(types) ||
643
+ cellOrValueSchemaTypeIncludes(types, encodedType))
612
644
  );
613
645
  }, false) == true;
614
646
  const validateContent = isArray;
@@ -661,7 +693,8 @@ const createStore = () => {
661
693
  : isReservedString(cell, acceptingEncodedData)
662
694
  ? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
663
695
  : isEncodedJson(cell)
664
- ? isValidEncodedJson(cell, cellSchema[TYPE])
696
+ ? isUndefined(cellSchema[ENUM]) &&
697
+ isValidEncodedJson(cell, cellSchema[TYPE])
665
698
  ? cell
666
699
  : cellInvalid(
667
700
  tableId,
@@ -670,23 +703,36 @@ const createStore = () => {
670
703
  cell,
671
704
  cellSchema[DEFAULT],
672
705
  )
673
- : getCellOrValueType(cell) === cellSchema[TYPE]
674
- ? encodeValid(cell, () =>
675
- cellInvalid(
706
+ : isUndefined(cellSchema[ENUM])
707
+ ? cellOrValueSchemaTypeIncludes(
708
+ cellSchema[TYPE],
709
+ getCellOrValueType(cell),
710
+ )
711
+ ? encodeValid(cell, () =>
712
+ cellInvalid(
713
+ tableId,
714
+ rowId,
715
+ cellId,
716
+ cell,
717
+ cellSchema[DEFAULT],
718
+ ),
719
+ )
720
+ : cellInvalid(
721
+ tableId,
722
+ rowId,
723
+ cellId,
724
+ cell,
725
+ cellSchema[DEFAULT],
726
+ )
727
+ : arrayHas(cellSchema[ENUM], cell)
728
+ ? cell
729
+ : cellInvalid(
676
730
  tableId,
677
731
  rowId,
678
732
  cellId,
679
733
  cell,
680
734
  cellSchema[DEFAULT],
681
735
  ),
682
- )
683
- : cellInvalid(
684
- tableId,
685
- rowId,
686
- cellId,
687
- cell,
688
- cellSchema[DEFAULT],
689
- ),
690
736
  () => cellInvalid(tableId, rowId, cellId, cell),
691
737
  )
692
738
  : isUndefined(getCellOrValueType(cell)) ||
@@ -731,14 +777,22 @@ const createStore = () => {
731
777
  : isReservedString(value, acceptingEncodedData)
732
778
  ? valueInvalid(valueId, value, valueSchema[DEFAULT])
733
779
  : isEncodedJson(value)
734
- ? isValidEncodedJson(value, valueSchema[TYPE])
780
+ ? isUndefined(valueSchema[ENUM]) &&
781
+ isValidEncodedJson(value, valueSchema[TYPE])
735
782
  ? value
736
783
  : valueInvalid(valueId, value, valueSchema[DEFAULT])
737
- : getCellOrValueType(value) === valueSchema[TYPE]
738
- ? encodeValid(value, () =>
739
- valueInvalid(valueId, value, valueSchema[DEFAULT]),
784
+ : isUndefined(valueSchema[ENUM])
785
+ ? cellOrValueSchemaTypeIncludes(
786
+ valueSchema[TYPE],
787
+ getCellOrValueType(value),
740
788
  )
741
- : valueInvalid(valueId, value, valueSchema[DEFAULT]),
789
+ ? encodeValid(value, () =>
790
+ valueInvalid(valueId, value, valueSchema[DEFAULT]),
791
+ )
792
+ : valueInvalid(valueId, value, valueSchema[DEFAULT])
793
+ : arrayHas(valueSchema[ENUM], value)
794
+ ? value
795
+ : valueInvalid(valueId, value, valueSchema[DEFAULT]),
742
796
  () => valueInvalid(valueId, value),
743
797
  )
744
798
  : isUndefined(getCellOrValueType(value)) ||
@@ -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)) ||