tinybase 9.1.0-beta.1 → 9.1.0-beta.2

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 (80) hide show
  1. package/@types/_internal/store/with-schemas/index.d.ts +133 -2
  2. package/@types/indexes/index.d.ts +97 -0
  3. package/@types/indexes/with-schemas/index.d.ts +137 -0
  4. package/@types/store/index.d.ts +96 -18
  5. package/@types/store/with-schemas/index.d.ts +107 -44
  6. package/@types/ui-react/index.d.ts +42 -0
  7. package/@types/ui-react/with-schemas/index.d.ts +101 -32
  8. package/@types/ui-solid/index.d.ts +42 -0
  9. package/@types/ui-solid/with-schemas/index.d.ts +101 -32
  10. package/@types/ui-svelte/index.d.ts +34 -0
  11. package/@types/ui-svelte/with-schemas/index.d.ts +34 -0
  12. package/index.js +121 -32
  13. package/indexes/index.js +39 -0
  14. package/indexes/with-schemas/index.js +39 -0
  15. package/mergeable-store/index.js +82 -32
  16. package/mergeable-store/with-schemas/index.js +82 -32
  17. package/min/index.js +1 -1
  18. package/min/index.js.gz +0 -0
  19. package/min/indexes/index.js +1 -1
  20. package/min/indexes/index.js.gz +0 -0
  21. package/min/indexes/with-schemas/index.js +1 -1
  22. package/min/indexes/with-schemas/index.js.gz +0 -0
  23. package/min/mergeable-store/index.js +1 -1
  24. package/min/mergeable-store/index.js.gz +0 -0
  25. package/min/mergeable-store/with-schemas/index.js +1 -1
  26. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  27. package/min/omni/index.js +1 -1
  28. package/min/omni/index.js.gz +0 -0
  29. package/min/omni/with-schemas/index.js +1 -1
  30. package/min/omni/with-schemas/index.js.gz +0 -0
  31. package/min/store/index.js +1 -1
  32. package/min/store/index.js.gz +0 -0
  33. package/min/store/with-schemas/index.js +1 -1
  34. package/min/store/with-schemas/index.js.gz +0 -0
  35. package/min/ui-react/index.js +1 -1
  36. package/min/ui-react/index.js.gz +0 -0
  37. package/min/ui-react/with-schemas/index.js +1 -1
  38. package/min/ui-react/with-schemas/index.js.gz +0 -0
  39. package/min/ui-react-inspector/index.js +1 -1
  40. package/min/ui-react-inspector/index.js.gz +0 -0
  41. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  42. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  43. package/min/ui-solid/index.js +1 -1
  44. package/min/ui-solid/index.js.gz +0 -0
  45. package/min/ui-solid/with-schemas/index.js +1 -1
  46. package/min/ui-solid/with-schemas/index.js.gz +0 -0
  47. package/min/ui-solid-inspector/index.js +1 -1
  48. package/min/ui-solid-inspector/index.js.gz +0 -0
  49. package/min/ui-solid-inspector/with-schemas/index.js +1 -1
  50. package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
  51. package/min/ui-svelte/index.js +1 -1
  52. package/min/ui-svelte/index.js.gz +0 -0
  53. package/min/ui-svelte/with-schemas/index.js +1 -1
  54. package/min/ui-svelte/with-schemas/index.js.gz +0 -0
  55. package/min/ui-svelte-inspector/index.js +1 -1
  56. package/min/ui-svelte-inspector/index.js.gz +0 -0
  57. package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
  58. package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
  59. package/min/with-schemas/index.js +1 -1
  60. package/min/with-schemas/index.js.gz +0 -0
  61. package/omni/index.js +121 -32
  62. package/omni/with-schemas/index.js +121 -32
  63. package/package.json +2 -2
  64. package/readme.md +14 -14
  65. package/releases.md +101 -60
  66. package/store/index.js +82 -32
  67. package/store/with-schemas/index.js +82 -32
  68. package/ui-react/index.js +16 -0
  69. package/ui-react/with-schemas/index.js +16 -0
  70. package/ui-react-inspector/index.js +82 -32
  71. package/ui-react-inspector/with-schemas/index.js +82 -32
  72. package/ui-solid/index.js +16 -0
  73. package/ui-solid/with-schemas/index.js +16 -0
  74. package/ui-solid-inspector/index.js +82 -32
  75. package/ui-solid-inspector/with-schemas/index.js +82 -32
  76. package/ui-svelte/index.js +18 -0
  77. package/ui-svelte/with-schemas/index.js +18 -0
  78. package/ui-svelte-inspector/index.js +82 -32
  79. package/ui-svelte-inspector/with-schemas/index.js +82 -32
  80. package/with-schemas/index.js +121 -32
package/store/index.js CHANGED
@@ -25,6 +25,7 @@ const CELL_IDS = CELL + IDS;
25
25
  const VALUE = 'Value';
26
26
  const VALUES = VALUE + 's';
27
27
  const VALUE_IDS = VALUE + IDS;
28
+ const REQUIRED = 'required';
28
29
  const JSON_PREFIX = '\uFFFD';
29
30
  const id = (key) => EMPTY_STRING + key;
30
31
 
@@ -397,6 +398,7 @@ const createStore = () => {
397
398
  const valuesSchemaMap = mapNew();
398
399
  const valuesDefaulted = mapNew();
399
400
  const valuesNonDefaulted = setNew();
401
+ const valuesRequiredNonDefaulted = setNew();
400
402
  const tablePoolFunctions = mapNew();
401
403
  const tableCellIds = mapNew();
402
404
  const tablesMap = mapNew();
@@ -449,7 +451,7 @@ const createStore = () => {
449
451
  const validateCellOrValueSchema = (schema) => {
450
452
  if (
451
453
  !objValidate(schema, (_child, id2) =>
452
- arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
454
+ arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
453
455
  )
454
456
  ) {
455
457
  return false;
@@ -484,20 +486,32 @@ const createStore = () => {
484
486
  (row, rowId) => validateRow(tableId, rowId, row),
485
487
  () => cellInvalid(tableId),
486
488
  );
487
- const validateRow = (tableId, rowId, row, skipDefaults) =>
488
- objValidate(
489
- skipDefaults ? row : addDefaultsToRow(row, tableId, rowId),
490
- (cell, cellId) =>
491
- ifNotUndefined(
492
- getValidatedCell(tableId, rowId, cellId, cell),
493
- (validCell) => {
494
- row[cellId] = validCell;
495
- return true;
496
- },
497
- () => false,
498
- ),
499
- () => cellInvalid(tableId, rowId),
489
+ const validateRow = (tableId, rowId, row, skipDefaults) => {
490
+ const rowWithDefaults = skipDefaults
491
+ ? row
492
+ : addDefaultsToRow(row, tableId, rowId);
493
+ return (
494
+ objValidate(
495
+ rowWithDefaults,
496
+ (cell, cellId) =>
497
+ ifNotUndefined(
498
+ getValidatedCell(tableId, rowId, cellId, cell),
499
+ (validCell) => {
500
+ row[cellId] = validCell;
501
+ return true;
502
+ },
503
+ () => false,
504
+ ),
505
+ () => cellInvalid(tableId, rowId),
506
+ ) &&
507
+ (skipDefaults
508
+ ? true
509
+ : arrayEvery(
510
+ collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
511
+ (cellId) => objHas(rowWithDefaults, cellId),
512
+ ))
500
513
  );
514
+ };
501
515
  const getValidatedCell = (tableId, rowId, cellId, cell) =>
502
516
  hasTablesSchema
503
517
  ? ifNotUndefined(
@@ -523,20 +537,31 @@ const createStore = () => {
523
537
  : isUndefined(getCellOrValueType(cell))
524
538
  ? cellInvalid(tableId, rowId, cellId, cell)
525
539
  : encodeIfJson(cell);
526
- const validateValues = (values, skipDefaults) =>
527
- objValidate(
528
- skipDefaults ? values : addDefaultsToValues(values),
529
- (value, valueId) =>
530
- ifNotUndefined(
531
- getValidatedValue(valueId, value),
532
- (validValue) => {
533
- values[valueId] = validValue;
534
- return true;
535
- },
536
- () => false,
537
- ),
538
- () => valueInvalid(),
540
+ const validateValues = (values, skipDefaults) => {
541
+ const valuesWithDefaults = skipDefaults
542
+ ? values
543
+ : addDefaultsToValues(values);
544
+ return (
545
+ objValidate(
546
+ valuesWithDefaults,
547
+ (value, valueId) =>
548
+ ifNotUndefined(
549
+ getValidatedValue(valueId, value),
550
+ (validValue) => {
551
+ values[valueId] = validValue;
552
+ return true;
553
+ },
554
+ () => false,
555
+ ),
556
+ () => valueInvalid(),
557
+ ) &&
558
+ (skipDefaults
559
+ ? true
560
+ : arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
561
+ objHas(valuesWithDefaults, valueId),
562
+ ))
539
563
  );
564
+ };
540
565
  const getValidatedValue = (valueId, value) =>
541
566
  hasValuesSchema
542
567
  ? ifNotUndefined(
@@ -607,6 +632,7 @@ const createStore = () => {
607
632
  (_tablesSchema, tableId, tableSchema) => {
608
633
  const rowDefaulted = mapNew();
609
634
  const rowNonDefaulted = setNew();
635
+ const rowRequiredNonDefaulted = setNew();
610
636
  mapMatch(
611
637
  mapEnsure(tablesSchemaMap, tableId, mapNew),
612
638
  tableSchema,
@@ -614,12 +640,23 @@ const createStore = () => {
614
640
  mapSet(tableSchemaMap, cellId, cellSchema);
615
641
  ifNotUndefined(
616
642
  cellSchema[DEFAULT],
617
- (def) => mapSet(rowDefaulted, cellId, def),
618
- () => setAdd(rowNonDefaulted, cellId),
643
+ (defaultCell) => {
644
+ mapSet(rowDefaulted, cellId, defaultCell);
645
+ },
646
+ () => {
647
+ setAdd(rowNonDefaulted, cellId);
648
+ if (cellSchema[REQUIRED] === true) {
649
+ setAdd(rowRequiredNonDefaulted, cellId);
650
+ }
651
+ },
619
652
  );
620
653
  },
621
654
  );
622
- mapSet(tablesSchemaRowCache, tableId, [rowDefaulted, rowNonDefaulted]);
655
+ mapSet(tablesSchemaRowCache, tableId, [
656
+ rowDefaulted,
657
+ rowNonDefaulted,
658
+ rowRequiredNonDefaulted,
659
+ ]);
623
660
  },
624
661
  (_tablesSchema, tableId) => {
625
662
  mapSet(tablesSchemaMap, tableId);
@@ -634,14 +671,27 @@ const createStore = () => {
634
671
  mapSet(valuesSchemaMap, valueId, valueSchema);
635
672
  ifNotUndefined(
636
673
  valueSchema[DEFAULT],
637
- (def) => mapSet(valuesDefaulted, valueId, def),
638
- () => setAdd(valuesNonDefaulted, valueId),
674
+ (defaultValue) => {
675
+ mapSet(valuesDefaulted, valueId, defaultValue);
676
+ collDel(valuesNonDefaulted, valueId);
677
+ collDel(valuesRequiredNonDefaulted, valueId);
678
+ },
679
+ () => {
680
+ mapSet(valuesDefaulted, valueId);
681
+ setAdd(valuesNonDefaulted, valueId);
682
+ if (valueSchema[REQUIRED] === true) {
683
+ setAdd(valuesRequiredNonDefaulted, valueId);
684
+ } else {
685
+ collDel(valuesRequiredNonDefaulted, valueId);
686
+ }
687
+ },
639
688
  );
640
689
  },
641
690
  (_valuesSchema, valueId) => {
642
691
  mapSet(valuesSchemaMap, valueId);
643
692
  mapSet(valuesDefaulted, valueId);
644
693
  collDel(valuesNonDefaulted, valueId);
694
+ collDel(valuesRequiredNonDefaulted, valueId);
645
695
  },
646
696
  );
647
697
  const setOrDelTables = (tables) =>
@@ -25,6 +25,7 @@ const CELL_IDS = CELL + IDS;
25
25
  const VALUE = 'Value';
26
26
  const VALUES = VALUE + 's';
27
27
  const VALUE_IDS = VALUE + IDS;
28
+ const REQUIRED = 'required';
28
29
  const JSON_PREFIX = '\uFFFD';
29
30
  const id = (key) => EMPTY_STRING + key;
30
31
 
@@ -397,6 +398,7 @@ const createStore = () => {
397
398
  const valuesSchemaMap = mapNew();
398
399
  const valuesDefaulted = mapNew();
399
400
  const valuesNonDefaulted = setNew();
401
+ const valuesRequiredNonDefaulted = setNew();
400
402
  const tablePoolFunctions = mapNew();
401
403
  const tableCellIds = mapNew();
402
404
  const tablesMap = mapNew();
@@ -449,7 +451,7 @@ const createStore = () => {
449
451
  const validateCellOrValueSchema = (schema) => {
450
452
  if (
451
453
  !objValidate(schema, (_child, id2) =>
452
- arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
454
+ arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
453
455
  )
454
456
  ) {
455
457
  return false;
@@ -484,20 +486,32 @@ const createStore = () => {
484
486
  (row, rowId) => validateRow(tableId, rowId, row),
485
487
  () => cellInvalid(tableId),
486
488
  );
487
- const validateRow = (tableId, rowId, row, skipDefaults) =>
488
- objValidate(
489
- skipDefaults ? row : addDefaultsToRow(row, tableId, rowId),
490
- (cell, cellId) =>
491
- ifNotUndefined(
492
- getValidatedCell(tableId, rowId, cellId, cell),
493
- (validCell) => {
494
- row[cellId] = validCell;
495
- return true;
496
- },
497
- () => false,
498
- ),
499
- () => cellInvalid(tableId, rowId),
489
+ const validateRow = (tableId, rowId, row, skipDefaults) => {
490
+ const rowWithDefaults = skipDefaults
491
+ ? row
492
+ : addDefaultsToRow(row, tableId, rowId);
493
+ return (
494
+ objValidate(
495
+ rowWithDefaults,
496
+ (cell, cellId) =>
497
+ ifNotUndefined(
498
+ getValidatedCell(tableId, rowId, cellId, cell),
499
+ (validCell) => {
500
+ row[cellId] = validCell;
501
+ return true;
502
+ },
503
+ () => false,
504
+ ),
505
+ () => cellInvalid(tableId, rowId),
506
+ ) &&
507
+ (skipDefaults
508
+ ? true
509
+ : arrayEvery(
510
+ collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
511
+ (cellId) => objHas(rowWithDefaults, cellId),
512
+ ))
500
513
  );
514
+ };
501
515
  const getValidatedCell = (tableId, rowId, cellId, cell) =>
502
516
  hasTablesSchema
503
517
  ? ifNotUndefined(
@@ -523,20 +537,31 @@ const createStore = () => {
523
537
  : isUndefined(getCellOrValueType(cell))
524
538
  ? cellInvalid(tableId, rowId, cellId, cell)
525
539
  : encodeIfJson(cell);
526
- const validateValues = (values, skipDefaults) =>
527
- objValidate(
528
- skipDefaults ? values : addDefaultsToValues(values),
529
- (value, valueId) =>
530
- ifNotUndefined(
531
- getValidatedValue(valueId, value),
532
- (validValue) => {
533
- values[valueId] = validValue;
534
- return true;
535
- },
536
- () => false,
537
- ),
538
- () => valueInvalid(),
540
+ const validateValues = (values, skipDefaults) => {
541
+ const valuesWithDefaults = skipDefaults
542
+ ? values
543
+ : addDefaultsToValues(values);
544
+ return (
545
+ objValidate(
546
+ valuesWithDefaults,
547
+ (value, valueId) =>
548
+ ifNotUndefined(
549
+ getValidatedValue(valueId, value),
550
+ (validValue) => {
551
+ values[valueId] = validValue;
552
+ return true;
553
+ },
554
+ () => false,
555
+ ),
556
+ () => valueInvalid(),
557
+ ) &&
558
+ (skipDefaults
559
+ ? true
560
+ : arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
561
+ objHas(valuesWithDefaults, valueId),
562
+ ))
539
563
  );
564
+ };
540
565
  const getValidatedValue = (valueId, value) =>
541
566
  hasValuesSchema
542
567
  ? ifNotUndefined(
@@ -607,6 +632,7 @@ const createStore = () => {
607
632
  (_tablesSchema, tableId, tableSchema) => {
608
633
  const rowDefaulted = mapNew();
609
634
  const rowNonDefaulted = setNew();
635
+ const rowRequiredNonDefaulted = setNew();
610
636
  mapMatch(
611
637
  mapEnsure(tablesSchemaMap, tableId, mapNew),
612
638
  tableSchema,
@@ -614,12 +640,23 @@ const createStore = () => {
614
640
  mapSet(tableSchemaMap, cellId, cellSchema);
615
641
  ifNotUndefined(
616
642
  cellSchema[DEFAULT],
617
- (def) => mapSet(rowDefaulted, cellId, def),
618
- () => setAdd(rowNonDefaulted, cellId),
643
+ (defaultCell) => {
644
+ mapSet(rowDefaulted, cellId, defaultCell);
645
+ },
646
+ () => {
647
+ setAdd(rowNonDefaulted, cellId);
648
+ if (cellSchema[REQUIRED] === true) {
649
+ setAdd(rowRequiredNonDefaulted, cellId);
650
+ }
651
+ },
619
652
  );
620
653
  },
621
654
  );
622
- mapSet(tablesSchemaRowCache, tableId, [rowDefaulted, rowNonDefaulted]);
655
+ mapSet(tablesSchemaRowCache, tableId, [
656
+ rowDefaulted,
657
+ rowNonDefaulted,
658
+ rowRequiredNonDefaulted,
659
+ ]);
623
660
  },
624
661
  (_tablesSchema, tableId) => {
625
662
  mapSet(tablesSchemaMap, tableId);
@@ -634,14 +671,27 @@ const createStore = () => {
634
671
  mapSet(valuesSchemaMap, valueId, valueSchema);
635
672
  ifNotUndefined(
636
673
  valueSchema[DEFAULT],
637
- (def) => mapSet(valuesDefaulted, valueId, def),
638
- () => setAdd(valuesNonDefaulted, valueId),
674
+ (defaultValue) => {
675
+ mapSet(valuesDefaulted, valueId, defaultValue);
676
+ collDel(valuesNonDefaulted, valueId);
677
+ collDel(valuesRequiredNonDefaulted, valueId);
678
+ },
679
+ () => {
680
+ mapSet(valuesDefaulted, valueId);
681
+ setAdd(valuesNonDefaulted, valueId);
682
+ if (valueSchema[REQUIRED] === true) {
683
+ setAdd(valuesRequiredNonDefaulted, valueId);
684
+ } else {
685
+ collDel(valuesRequiredNonDefaulted, valueId);
686
+ }
687
+ },
639
688
  );
640
689
  },
641
690
  (_valuesSchema, valueId) => {
642
691
  mapSet(valuesSchemaMap, valueId);
643
692
  mapSet(valuesDefaulted, valueId);
644
693
  collDel(valuesNonDefaulted, valueId);
694
+ collDel(valuesRequiredNonDefaulted, valueId);
645
695
  },
646
696
  );
647
697
  const setOrDelTables = (tables) =>
package/ui-react/index.js CHANGED
@@ -1332,6 +1332,13 @@ const useIndexIds = (indexesOrIndexesId) =>
1332
1332
  useIndexesOrIndexesById(indexesOrIndexesId),
1333
1333
  1 /* Array */,
1334
1334
  );
1335
+ const useHasIndex = (indexId, indexesOrIndexesId) =>
1336
+ useListenable(
1337
+ INDEX,
1338
+ useIndexesOrIndexesById(indexesOrIndexesId),
1339
+ 6 /* Boolean */,
1340
+ [indexId],
1341
+ );
1335
1342
  const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
1336
1343
  useListenable(
1337
1344
  SLICE + ROW_IDS,
@@ -1339,6 +1346,13 @@ const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
1339
1346
  1 /* Array */,
1340
1347
  [indexId, sliceId],
1341
1348
  );
1349
+ const useHasSlice = (indexId, sliceId, indexesOrIndexesId) =>
1350
+ useListenable(
1351
+ SLICE,
1352
+ useIndexesOrIndexesById(indexesOrIndexesId),
1353
+ 6 /* Boolean */,
1354
+ [indexId, sliceId],
1355
+ );
1342
1356
  const useSliceIdsListener = (
1343
1357
  indexId,
1344
1358
  listener,
@@ -2461,8 +2475,10 @@ export {
2461
2475
  useGoToCallback,
2462
2476
  useHasCell,
2463
2477
  useHasCellListener,
2478
+ useHasIndex,
2464
2479
  useHasRow,
2465
2480
  useHasRowListener,
2481
+ useHasSlice,
2466
2482
  useHasTable,
2467
2483
  useHasTableCell,
2468
2484
  useHasTableCellListener,
@@ -1332,6 +1332,13 @@ const useIndexIds = (indexesOrIndexesId) =>
1332
1332
  useIndexesOrIndexesById(indexesOrIndexesId),
1333
1333
  1 /* Array */,
1334
1334
  );
1335
+ const useHasIndex = (indexId, indexesOrIndexesId) =>
1336
+ useListenable(
1337
+ INDEX,
1338
+ useIndexesOrIndexesById(indexesOrIndexesId),
1339
+ 6 /* Boolean */,
1340
+ [indexId],
1341
+ );
1335
1342
  const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
1336
1343
  useListenable(
1337
1344
  SLICE + ROW_IDS,
@@ -1339,6 +1346,13 @@ const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
1339
1346
  1 /* Array */,
1340
1347
  [indexId, sliceId],
1341
1348
  );
1349
+ const useHasSlice = (indexId, sliceId, indexesOrIndexesId) =>
1350
+ useListenable(
1351
+ SLICE,
1352
+ useIndexesOrIndexesById(indexesOrIndexesId),
1353
+ 6 /* Boolean */,
1354
+ [indexId, sliceId],
1355
+ );
1342
1356
  const useSliceIdsListener = (
1343
1357
  indexId,
1344
1358
  listener,
@@ -2461,8 +2475,10 @@ export {
2461
2475
  useGoToCallback,
2462
2476
  useHasCell,
2463
2477
  useHasCellListener,
2478
+ useHasIndex,
2464
2479
  useHasRow,
2465
2480
  useHasRowListener,
2481
+ useHasSlice,
2466
2482
  useHasTable,
2467
2483
  useHasTableCell,
2468
2484
  useHasTableCellListener,
@@ -73,6 +73,7 @@ const REMOTE_ROW_ID = 'Remote' + ROW + 'Id';
73
73
  const CURRENT_TARGET = 'currentTarget';
74
74
  const _VALUE = 'value';
75
75
  const EXTRA = 'extra';
76
+ const REQUIRED = 'required';
76
77
  const UNDEFINED = '\uFFFC';
77
78
  const JSON_PREFIX = '\uFFFD';
78
79
  const id = (key) => EMPTY_STRING + key;
@@ -1200,6 +1201,7 @@ const createStore = () => {
1200
1201
  const valuesSchemaMap = mapNew();
1201
1202
  const valuesDefaulted = mapNew();
1202
1203
  const valuesNonDefaulted = setNew();
1204
+ const valuesRequiredNonDefaulted = setNew();
1203
1205
  const tablePoolFunctions = mapNew();
1204
1206
  const tableCellIds = mapNew();
1205
1207
  const tablesMap = mapNew();
@@ -1252,7 +1254,7 @@ const createStore = () => {
1252
1254
  const validateCellOrValueSchema = (schema) => {
1253
1255
  if (
1254
1256
  !objValidate(schema, (_child, id2) =>
1255
- arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
1257
+ arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
1256
1258
  )
1257
1259
  ) {
1258
1260
  return false;
@@ -1287,20 +1289,32 @@ const createStore = () => {
1287
1289
  (row, rowId) => validateRow(tableId, rowId, row),
1288
1290
  () => cellInvalid(tableId),
1289
1291
  );
1290
- const validateRow = (tableId, rowId, row, skipDefaults) =>
1291
- objValidate(
1292
- skipDefaults ? row : addDefaultsToRow(row, tableId, rowId),
1293
- (cell, cellId) =>
1294
- ifNotUndefined(
1295
- getValidatedCell(tableId, rowId, cellId, cell),
1296
- (validCell) => {
1297
- row[cellId] = validCell;
1298
- return true;
1299
- },
1300
- () => false,
1301
- ),
1302
- () => cellInvalid(tableId, rowId),
1292
+ const validateRow = (tableId, rowId, row, skipDefaults) => {
1293
+ const rowWithDefaults = skipDefaults
1294
+ ? row
1295
+ : addDefaultsToRow(row, tableId, rowId);
1296
+ return (
1297
+ objValidate(
1298
+ rowWithDefaults,
1299
+ (cell, cellId) =>
1300
+ ifNotUndefined(
1301
+ getValidatedCell(tableId, rowId, cellId, cell),
1302
+ (validCell) => {
1303
+ row[cellId] = validCell;
1304
+ return true;
1305
+ },
1306
+ () => false,
1307
+ ),
1308
+ () => cellInvalid(tableId, rowId),
1309
+ ) &&
1310
+ (skipDefaults
1311
+ ? true
1312
+ : arrayEvery(
1313
+ collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
1314
+ (cellId) => objHas(rowWithDefaults, cellId),
1315
+ ))
1303
1316
  );
1317
+ };
1304
1318
  const getValidatedCell = (tableId, rowId, cellId, cell) =>
1305
1319
  hasTablesSchema
1306
1320
  ? ifNotUndefined(
@@ -1326,20 +1340,31 @@ const createStore = () => {
1326
1340
  : isUndefined(getCellOrValueType(cell))
1327
1341
  ? cellInvalid(tableId, rowId, cellId, cell)
1328
1342
  : encodeIfJson(cell);
1329
- const validateValues = (values, skipDefaults) =>
1330
- objValidate(
1331
- skipDefaults ? values : addDefaultsToValues(values),
1332
- (value, valueId) =>
1333
- ifNotUndefined(
1334
- getValidatedValue(valueId, value),
1335
- (validValue) => {
1336
- values[valueId] = validValue;
1337
- return true;
1338
- },
1339
- () => false,
1340
- ),
1341
- () => valueInvalid(),
1343
+ const validateValues = (values, skipDefaults) => {
1344
+ const valuesWithDefaults = skipDefaults
1345
+ ? values
1346
+ : addDefaultsToValues(values);
1347
+ return (
1348
+ objValidate(
1349
+ valuesWithDefaults,
1350
+ (value, valueId) =>
1351
+ ifNotUndefined(
1352
+ getValidatedValue(valueId, value),
1353
+ (validValue) => {
1354
+ values[valueId] = validValue;
1355
+ return true;
1356
+ },
1357
+ () => false,
1358
+ ),
1359
+ () => valueInvalid(),
1360
+ ) &&
1361
+ (skipDefaults
1362
+ ? true
1363
+ : arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
1364
+ objHas(valuesWithDefaults, valueId),
1365
+ ))
1342
1366
  );
1367
+ };
1343
1368
  const getValidatedValue = (valueId, value) =>
1344
1369
  hasValuesSchema
1345
1370
  ? ifNotUndefined(
@@ -1410,6 +1435,7 @@ const createStore = () => {
1410
1435
  (_tablesSchema, tableId, tableSchema) => {
1411
1436
  const rowDefaulted = mapNew();
1412
1437
  const rowNonDefaulted = setNew();
1438
+ const rowRequiredNonDefaulted = setNew();
1413
1439
  mapMatch(
1414
1440
  mapEnsure(tablesSchemaMap, tableId, mapNew),
1415
1441
  tableSchema,
@@ -1417,12 +1443,23 @@ const createStore = () => {
1417
1443
  mapSet(tableSchemaMap, cellId, cellSchema);
1418
1444
  ifNotUndefined(
1419
1445
  cellSchema[DEFAULT],
1420
- (def) => mapSet(rowDefaulted, cellId, def),
1421
- () => setAdd(rowNonDefaulted, cellId),
1446
+ (defaultCell) => {
1447
+ mapSet(rowDefaulted, cellId, defaultCell);
1448
+ },
1449
+ () => {
1450
+ setAdd(rowNonDefaulted, cellId);
1451
+ if (cellSchema[REQUIRED] === true) {
1452
+ setAdd(rowRequiredNonDefaulted, cellId);
1453
+ }
1454
+ },
1422
1455
  );
1423
1456
  },
1424
1457
  );
1425
- mapSet(tablesSchemaRowCache, tableId, [rowDefaulted, rowNonDefaulted]);
1458
+ mapSet(tablesSchemaRowCache, tableId, [
1459
+ rowDefaulted,
1460
+ rowNonDefaulted,
1461
+ rowRequiredNonDefaulted,
1462
+ ]);
1426
1463
  },
1427
1464
  (_tablesSchema, tableId) => {
1428
1465
  mapSet(tablesSchemaMap, tableId);
@@ -1437,14 +1474,27 @@ const createStore = () => {
1437
1474
  mapSet(valuesSchemaMap, valueId, valueSchema);
1438
1475
  ifNotUndefined(
1439
1476
  valueSchema[DEFAULT],
1440
- (def) => mapSet(valuesDefaulted, valueId, def),
1441
- () => setAdd(valuesNonDefaulted, valueId),
1477
+ (defaultValue) => {
1478
+ mapSet(valuesDefaulted, valueId, defaultValue);
1479
+ collDel(valuesNonDefaulted, valueId);
1480
+ collDel(valuesRequiredNonDefaulted, valueId);
1481
+ },
1482
+ () => {
1483
+ mapSet(valuesDefaulted, valueId);
1484
+ setAdd(valuesNonDefaulted, valueId);
1485
+ if (valueSchema[REQUIRED] === true) {
1486
+ setAdd(valuesRequiredNonDefaulted, valueId);
1487
+ } else {
1488
+ collDel(valuesRequiredNonDefaulted, valueId);
1489
+ }
1490
+ },
1442
1491
  );
1443
1492
  },
1444
1493
  (_valuesSchema, valueId) => {
1445
1494
  mapSet(valuesSchemaMap, valueId);
1446
1495
  mapSet(valuesDefaulted, valueId);
1447
1496
  collDel(valuesNonDefaulted, valueId);
1497
+ collDel(valuesRequiredNonDefaulted, valueId);
1448
1498
  },
1449
1499
  );
1450
1500
  const setOrDelTables = (tables) =>