tinybase 9.1.0-beta.1 → 9.1.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.
- package/@types/_internal/store/with-schemas/index.d.ts +133 -2
- package/@types/indexes/index.d.ts +97 -0
- package/@types/indexes/with-schemas/index.d.ts +137 -0
- package/@types/store/index.d.ts +96 -18
- package/@types/store/with-schemas/index.d.ts +107 -44
- package/@types/ui-react/index.d.ts +42 -0
- package/@types/ui-react/with-schemas/index.d.ts +101 -32
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +10 -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/index.d.ts +42 -0
- package/@types/ui-solid/with-schemas/index.d.ts +101 -32
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +10 -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/index.d.ts +34 -0
- package/@types/ui-svelte/with-schemas/index.d.ts +34 -0
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/index.js +121 -32
- package/indexes/index.js +39 -0
- package/indexes/with-schemas/index.js +39 -0
- package/mergeable-store/index.js +82 -32
- package/mergeable-store/with-schemas/index.js +82 -32
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/indexes/index.js +1 -1
- package/min/indexes/index.js.gz +0 -0
- package/min/indexes/with-schemas/index.js +1 -1
- package/min/indexes/with-schemas/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/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/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/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/index.js +1 -1
- package/min/ui-solid/index.js.gz +0 -0
- package/min/ui-solid/with-schemas/index.js +1 -1
- package/min/ui-solid/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/index.js +1 -1
- package/min/ui-svelte/index.js.gz +0 -0
- package/min/ui-svelte/with-schemas/index.js +1 -1
- package/min/ui-svelte/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 +121 -32
- package/omni/with-schemas/index.js +121 -32
- package/package.json +5 -5
- package/readme.md +14 -14
- package/releases.md +101 -60
- package/store/index.js +82 -32
- package/store/with-schemas/index.js +82 -32
- package/ui-react/index.js +16 -0
- package/ui-react/with-schemas/index.js +16 -0
- package/ui-react-inspector/index.js +82 -32
- package/ui-react-inspector/with-schemas/index.js +82 -32
- package/ui-solid/index.js +16 -0
- package/ui-solid/with-schemas/index.js +16 -0
- package/ui-solid-inspector/index.js +82 -32
- package/ui-solid-inspector/with-schemas/index.js +82 -32
- package/ui-svelte/index.js +18 -0
- package/ui-svelte/with-schemas/index.js +18 -0
- package/ui-svelte-inspector/index.js +82 -32
- package/ui-svelte-inspector/with-schemas/index.js +82 -32
- package/with-schemas/index.js +121 -32
package/index.js
CHANGED
|
@@ -35,6 +35,7 @@ const VALUE = 'Value';
|
|
|
35
35
|
const VALUES = VALUE + 's';
|
|
36
36
|
const VALUE_IDS = VALUE + IDS;
|
|
37
37
|
const TRANSACTION = 'Transaction';
|
|
38
|
+
const REQUIRED = 'required';
|
|
38
39
|
const JSON_PREFIX = '\uFFFD';
|
|
39
40
|
const id = (key) => EMPTY_STRING + key;
|
|
40
41
|
const strStartsWith = (str, prefix) => str.startsWith(prefix);
|
|
@@ -929,7 +930,9 @@ const defaultSorter = (sortKey1, sortKey2) =>
|
|
|
929
930
|
(sortKey1 ?? 0) < (sortKey2 ?? 0) ? -1 : 1;
|
|
930
931
|
|
|
931
932
|
const createIndexes = getCreateFunction((store) => {
|
|
933
|
+
const hasIndexListeners = mapNew();
|
|
932
934
|
const sliceIdsListeners = mapNew();
|
|
935
|
+
const hasSliceListeners = mapNew();
|
|
933
936
|
const sliceRowIdsListeners = mapNew();
|
|
934
937
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
935
938
|
() => indexes,
|
|
@@ -968,6 +971,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
968
971
|
sliceIdSorter,
|
|
969
972
|
rowIdSorter = defaultSorter,
|
|
970
973
|
) => {
|
|
974
|
+
const hadIndex = hasIndex(indexId);
|
|
971
975
|
const sliceIdArraySorter = isUndefined(sliceIdSorter)
|
|
972
976
|
? void 0
|
|
973
977
|
: ([id1], [id2]) => sliceIdSorter(id1, id2);
|
|
@@ -984,8 +988,14 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
984
988
|
) => {
|
|
985
989
|
let sliceIdsChanged = 0;
|
|
986
990
|
const changedSlices = setNew();
|
|
991
|
+
const hadSlices = mapNew();
|
|
987
992
|
const unsortedSlices = setNew();
|
|
988
993
|
const index = getIndex(indexId);
|
|
994
|
+
const setHadSlice = (sliceId) => {
|
|
995
|
+
if (!collHas(hadSlices, sliceId)) {
|
|
996
|
+
mapSet(hadSlices, sliceId, collHas(index, sliceId));
|
|
997
|
+
}
|
|
998
|
+
};
|
|
989
999
|
collForEach(
|
|
990
1000
|
changedSliceIds,
|
|
991
1001
|
([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
|
|
@@ -997,6 +1007,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
997
1007
|
: 0,
|
|
998
1008
|
);
|
|
999
1009
|
collForEach(oldSliceIds, (oldSliceId) => {
|
|
1010
|
+
setHadSlice(oldSliceId);
|
|
1000
1011
|
setAdd(changedSlices, oldSliceId);
|
|
1001
1012
|
ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
|
|
1002
1013
|
collDel(oldSlice, rowId);
|
|
@@ -1007,6 +1018,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1007
1018
|
});
|
|
1008
1019
|
});
|
|
1009
1020
|
collForEach(newSliceIds, (newSliceId) => {
|
|
1021
|
+
setHadSlice(newSliceId);
|
|
1010
1022
|
setAdd(changedSlices, newSliceId);
|
|
1011
1023
|
if (!collHas(index, newSliceId)) {
|
|
1012
1024
|
mapSet(index, newSliceId, setNew());
|
|
@@ -1068,6 +1080,12 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1068
1080
|
if (sliceIdsChanged) {
|
|
1069
1081
|
callListeners(sliceIdsListeners, [indexId]);
|
|
1070
1082
|
}
|
|
1083
|
+
mapForEach(hadSlices, (sliceId, hadSlice) => {
|
|
1084
|
+
const hasSliceNow = collHas(index, sliceId);
|
|
1085
|
+
if (hadSlice != hasSliceNow) {
|
|
1086
|
+
callListeners(hasSliceListeners, [indexId, sliceId], hasSliceNow);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1071
1089
|
collForEach(changedSlices, (sliceId) =>
|
|
1072
1090
|
callListeners(sliceRowIdsListeners, [indexId, sliceId]),
|
|
1073
1091
|
);
|
|
@@ -1075,6 +1093,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1075
1093
|
getRowCellFunction(getSliceIdOrIds),
|
|
1076
1094
|
ifNotUndefined(getSortKey, getRowCellFunction),
|
|
1077
1095
|
);
|
|
1096
|
+
if (!hadIndex) {
|
|
1097
|
+
callListeners(hasIndexListeners, [indexId], true);
|
|
1098
|
+
}
|
|
1078
1099
|
return indexes;
|
|
1079
1100
|
};
|
|
1080
1101
|
const forEachIndex = (indexCallback) =>
|
|
@@ -1098,7 +1119,20 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1098
1119
|
);
|
|
1099
1120
|
};
|
|
1100
1121
|
const delIndexDefinition = (indexId) => {
|
|
1122
|
+
const index = getIndex(indexId);
|
|
1123
|
+
const hadIndex = hasIndex(indexId);
|
|
1124
|
+
const sliceIds = hadIndex ? mapKeys(index) : [];
|
|
1101
1125
|
delDefinition(indexId);
|
|
1126
|
+
if (hadIndex) {
|
|
1127
|
+
callListeners(hasIndexListeners, [indexId], false);
|
|
1128
|
+
if (sliceIds.length > 0) {
|
|
1129
|
+
callListeners(sliceIdsListeners, [indexId]);
|
|
1130
|
+
arrayForEach(sliceIds, (sliceId) => {
|
|
1131
|
+
callListeners(hasSliceListeners, [indexId, sliceId], false);
|
|
1132
|
+
callListeners(sliceRowIdsListeners, [indexId, sliceId]);
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1102
1136
|
return indexes;
|
|
1103
1137
|
};
|
|
1104
1138
|
const getSliceIds = (indexId) => mapKeys(getIndex(indexId));
|
|
@@ -1106,6 +1140,10 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1106
1140
|
collValues(mapGet(getIndex(indexId), sliceId));
|
|
1107
1141
|
const addSliceIdsListener = (indexId, listener) =>
|
|
1108
1142
|
addListener(listener, sliceIdsListeners, [indexId]);
|
|
1143
|
+
const addHasIndexListener = (indexId, listener) =>
|
|
1144
|
+
addListener(listener, hasIndexListeners, [indexId]);
|
|
1145
|
+
const addHasSliceListener = (indexId, sliceId, listener) =>
|
|
1146
|
+
addListener(listener, hasSliceListeners, [indexId, sliceId]);
|
|
1109
1147
|
const addSliceRowIdsListener = (indexId, sliceId, listener) =>
|
|
1110
1148
|
addListener(listener, sliceRowIdsListeners, [indexId, sliceId]);
|
|
1111
1149
|
const delListener = (listenerId) => {
|
|
@@ -1129,7 +1167,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1129
1167
|
getSliceIds,
|
|
1130
1168
|
getSliceRowIds,
|
|
1131
1169
|
addIndexIdsListener,
|
|
1170
|
+
addHasIndexListener,
|
|
1132
1171
|
addSliceIdsListener,
|
|
1172
|
+
addHasSliceListener,
|
|
1133
1173
|
addSliceRowIdsListener,
|
|
1134
1174
|
delListener,
|
|
1135
1175
|
destroy,
|
|
@@ -1236,6 +1276,7 @@ const createStore = () => {
|
|
|
1236
1276
|
const valuesSchemaMap = mapNew();
|
|
1237
1277
|
const valuesDefaulted = mapNew();
|
|
1238
1278
|
const valuesNonDefaulted = setNew();
|
|
1279
|
+
const valuesRequiredNonDefaulted = setNew();
|
|
1239
1280
|
const tablePoolFunctions = mapNew();
|
|
1240
1281
|
const tableCellIds = mapNew();
|
|
1241
1282
|
const tablesMap = mapNew();
|
|
@@ -1288,7 +1329,7 @@ const createStore = () => {
|
|
|
1288
1329
|
const validateCellOrValueSchema = (schema) => {
|
|
1289
1330
|
if (
|
|
1290
1331
|
!objValidate(schema, (_child, id2) =>
|
|
1291
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
|
|
1332
|
+
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1292
1333
|
)
|
|
1293
1334
|
) {
|
|
1294
1335
|
return false;
|
|
@@ -1323,20 +1364,32 @@ const createStore = () => {
|
|
|
1323
1364
|
(row, rowId) => validateRow(tableId, rowId, row),
|
|
1324
1365
|
() => cellInvalid(tableId),
|
|
1325
1366
|
);
|
|
1326
|
-
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
(
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1367
|
+
const validateRow = (tableId, rowId, row, skipDefaults) => {
|
|
1368
|
+
const rowWithDefaults = skipDefaults
|
|
1369
|
+
? row
|
|
1370
|
+
: addDefaultsToRow(row, tableId, rowId);
|
|
1371
|
+
return (
|
|
1372
|
+
objValidate(
|
|
1373
|
+
rowWithDefaults,
|
|
1374
|
+
(cell, cellId) =>
|
|
1375
|
+
ifNotUndefined(
|
|
1376
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1377
|
+
(validCell) => {
|
|
1378
|
+
row[cellId] = validCell;
|
|
1379
|
+
return true;
|
|
1380
|
+
},
|
|
1381
|
+
() => false,
|
|
1382
|
+
),
|
|
1383
|
+
() => cellInvalid(tableId, rowId),
|
|
1384
|
+
) &&
|
|
1385
|
+
(skipDefaults
|
|
1386
|
+
? true
|
|
1387
|
+
: arrayEvery(
|
|
1388
|
+
collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
|
|
1389
|
+
(cellId) => objHas(rowWithDefaults, cellId),
|
|
1390
|
+
))
|
|
1339
1391
|
);
|
|
1392
|
+
};
|
|
1340
1393
|
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
|
1341
1394
|
hasTablesSchema
|
|
1342
1395
|
? ifNotUndefined(
|
|
@@ -1362,20 +1415,31 @@ const createStore = () => {
|
|
|
1362
1415
|
: isUndefined(getCellOrValueType(cell))
|
|
1363
1416
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1364
1417
|
: encodeIfJson(cell);
|
|
1365
|
-
const validateValues = (values, skipDefaults) =>
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
(
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1418
|
+
const validateValues = (values, skipDefaults) => {
|
|
1419
|
+
const valuesWithDefaults = skipDefaults
|
|
1420
|
+
? values
|
|
1421
|
+
: addDefaultsToValues(values);
|
|
1422
|
+
return (
|
|
1423
|
+
objValidate(
|
|
1424
|
+
valuesWithDefaults,
|
|
1425
|
+
(value, valueId) =>
|
|
1426
|
+
ifNotUndefined(
|
|
1427
|
+
getValidatedValue(valueId, value),
|
|
1428
|
+
(validValue) => {
|
|
1429
|
+
values[valueId] = validValue;
|
|
1430
|
+
return true;
|
|
1431
|
+
},
|
|
1432
|
+
() => false,
|
|
1433
|
+
),
|
|
1434
|
+
() => valueInvalid(),
|
|
1435
|
+
) &&
|
|
1436
|
+
(skipDefaults
|
|
1437
|
+
? true
|
|
1438
|
+
: arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
|
|
1439
|
+
objHas(valuesWithDefaults, valueId),
|
|
1440
|
+
))
|
|
1378
1441
|
);
|
|
1442
|
+
};
|
|
1379
1443
|
const getValidatedValue = (valueId, value) =>
|
|
1380
1444
|
hasValuesSchema
|
|
1381
1445
|
? ifNotUndefined(
|
|
@@ -1446,6 +1510,7 @@ const createStore = () => {
|
|
|
1446
1510
|
(_tablesSchema, tableId, tableSchema) => {
|
|
1447
1511
|
const rowDefaulted = mapNew();
|
|
1448
1512
|
const rowNonDefaulted = setNew();
|
|
1513
|
+
const rowRequiredNonDefaulted = setNew();
|
|
1449
1514
|
mapMatch(
|
|
1450
1515
|
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
|
1451
1516
|
tableSchema,
|
|
@@ -1453,12 +1518,23 @@ const createStore = () => {
|
|
|
1453
1518
|
mapSet(tableSchemaMap, cellId, cellSchema);
|
|
1454
1519
|
ifNotUndefined(
|
|
1455
1520
|
cellSchema[DEFAULT],
|
|
1456
|
-
(
|
|
1457
|
-
|
|
1521
|
+
(defaultCell) => {
|
|
1522
|
+
mapSet(rowDefaulted, cellId, defaultCell);
|
|
1523
|
+
},
|
|
1524
|
+
() => {
|
|
1525
|
+
setAdd(rowNonDefaulted, cellId);
|
|
1526
|
+
if (cellSchema[REQUIRED] === true) {
|
|
1527
|
+
setAdd(rowRequiredNonDefaulted, cellId);
|
|
1528
|
+
}
|
|
1529
|
+
},
|
|
1458
1530
|
);
|
|
1459
1531
|
},
|
|
1460
1532
|
);
|
|
1461
|
-
mapSet(tablesSchemaRowCache, tableId, [
|
|
1533
|
+
mapSet(tablesSchemaRowCache, tableId, [
|
|
1534
|
+
rowDefaulted,
|
|
1535
|
+
rowNonDefaulted,
|
|
1536
|
+
rowRequiredNonDefaulted,
|
|
1537
|
+
]);
|
|
1462
1538
|
},
|
|
1463
1539
|
(_tablesSchema, tableId) => {
|
|
1464
1540
|
mapSet(tablesSchemaMap, tableId);
|
|
@@ -1473,14 +1549,27 @@ const createStore = () => {
|
|
|
1473
1549
|
mapSet(valuesSchemaMap, valueId, valueSchema);
|
|
1474
1550
|
ifNotUndefined(
|
|
1475
1551
|
valueSchema[DEFAULT],
|
|
1476
|
-
(
|
|
1477
|
-
|
|
1552
|
+
(defaultValue) => {
|
|
1553
|
+
mapSet(valuesDefaulted, valueId, defaultValue);
|
|
1554
|
+
collDel(valuesNonDefaulted, valueId);
|
|
1555
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1556
|
+
},
|
|
1557
|
+
() => {
|
|
1558
|
+
mapSet(valuesDefaulted, valueId);
|
|
1559
|
+
setAdd(valuesNonDefaulted, valueId);
|
|
1560
|
+
if (valueSchema[REQUIRED] === true) {
|
|
1561
|
+
setAdd(valuesRequiredNonDefaulted, valueId);
|
|
1562
|
+
} else {
|
|
1563
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1564
|
+
}
|
|
1565
|
+
},
|
|
1478
1566
|
);
|
|
1479
1567
|
},
|
|
1480
1568
|
(_valuesSchema, valueId) => {
|
|
1481
1569
|
mapSet(valuesSchemaMap, valueId);
|
|
1482
1570
|
mapSet(valuesDefaulted, valueId);
|
|
1483
1571
|
collDel(valuesNonDefaulted, valueId);
|
|
1572
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1484
1573
|
},
|
|
1485
1574
|
);
|
|
1486
1575
|
const setOrDelTables = (tables) =>
|
package/indexes/index.js
CHANGED
|
@@ -339,7 +339,9 @@ const getListenerFunctions = (getThing) => {
|
|
|
339
339
|
};
|
|
340
340
|
|
|
341
341
|
const createIndexes = getCreateFunction((store) => {
|
|
342
|
+
const hasIndexListeners = mapNew();
|
|
342
343
|
const sliceIdsListeners = mapNew();
|
|
344
|
+
const hasSliceListeners = mapNew();
|
|
343
345
|
const sliceRowIdsListeners = mapNew();
|
|
344
346
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
345
347
|
() => indexes,
|
|
@@ -378,6 +380,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
378
380
|
sliceIdSorter,
|
|
379
381
|
rowIdSorter = defaultSorter,
|
|
380
382
|
) => {
|
|
383
|
+
const hadIndex = hasIndex(indexId);
|
|
381
384
|
const sliceIdArraySorter = isUndefined(sliceIdSorter)
|
|
382
385
|
? void 0
|
|
383
386
|
: ([id1], [id2]) => sliceIdSorter(id1, id2);
|
|
@@ -394,8 +397,14 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
394
397
|
) => {
|
|
395
398
|
let sliceIdsChanged = 0;
|
|
396
399
|
const changedSlices = setNew();
|
|
400
|
+
const hadSlices = mapNew();
|
|
397
401
|
const unsortedSlices = setNew();
|
|
398
402
|
const index = getIndex(indexId);
|
|
403
|
+
const setHadSlice = (sliceId) => {
|
|
404
|
+
if (!collHas(hadSlices, sliceId)) {
|
|
405
|
+
mapSet(hadSlices, sliceId, collHas(index, sliceId));
|
|
406
|
+
}
|
|
407
|
+
};
|
|
399
408
|
collForEach(
|
|
400
409
|
changedSliceIds,
|
|
401
410
|
([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
|
|
@@ -407,6 +416,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
407
416
|
: 0,
|
|
408
417
|
);
|
|
409
418
|
collForEach(oldSliceIds, (oldSliceId) => {
|
|
419
|
+
setHadSlice(oldSliceId);
|
|
410
420
|
setAdd(changedSlices, oldSliceId);
|
|
411
421
|
ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
|
|
412
422
|
collDel(oldSlice, rowId);
|
|
@@ -417,6 +427,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
417
427
|
});
|
|
418
428
|
});
|
|
419
429
|
collForEach(newSliceIds, (newSliceId) => {
|
|
430
|
+
setHadSlice(newSliceId);
|
|
420
431
|
setAdd(changedSlices, newSliceId);
|
|
421
432
|
if (!collHas(index, newSliceId)) {
|
|
422
433
|
mapSet(index, newSliceId, setNew());
|
|
@@ -478,6 +489,12 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
478
489
|
if (sliceIdsChanged) {
|
|
479
490
|
callListeners(sliceIdsListeners, [indexId]);
|
|
480
491
|
}
|
|
492
|
+
mapForEach(hadSlices, (sliceId, hadSlice) => {
|
|
493
|
+
const hasSliceNow = collHas(index, sliceId);
|
|
494
|
+
if (hadSlice != hasSliceNow) {
|
|
495
|
+
callListeners(hasSliceListeners, [indexId, sliceId], hasSliceNow);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
481
498
|
collForEach(changedSlices, (sliceId) =>
|
|
482
499
|
callListeners(sliceRowIdsListeners, [indexId, sliceId]),
|
|
483
500
|
);
|
|
@@ -485,6 +502,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
485
502
|
getRowCellFunction(getSliceIdOrIds),
|
|
486
503
|
ifNotUndefined(getSortKey, getRowCellFunction),
|
|
487
504
|
);
|
|
505
|
+
if (!hadIndex) {
|
|
506
|
+
callListeners(hasIndexListeners, [indexId], true);
|
|
507
|
+
}
|
|
488
508
|
return indexes;
|
|
489
509
|
};
|
|
490
510
|
const forEachIndex = (indexCallback) =>
|
|
@@ -508,7 +528,20 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
508
528
|
);
|
|
509
529
|
};
|
|
510
530
|
const delIndexDefinition = (indexId) => {
|
|
531
|
+
const index = getIndex(indexId);
|
|
532
|
+
const hadIndex = hasIndex(indexId);
|
|
533
|
+
const sliceIds = hadIndex ? mapKeys(index) : [];
|
|
511
534
|
delDefinition(indexId);
|
|
535
|
+
if (hadIndex) {
|
|
536
|
+
callListeners(hasIndexListeners, [indexId], false);
|
|
537
|
+
if (sliceIds.length > 0) {
|
|
538
|
+
callListeners(sliceIdsListeners, [indexId]);
|
|
539
|
+
arrayForEach(sliceIds, (sliceId) => {
|
|
540
|
+
callListeners(hasSliceListeners, [indexId, sliceId], false);
|
|
541
|
+
callListeners(sliceRowIdsListeners, [indexId, sliceId]);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}
|
|
512
545
|
return indexes;
|
|
513
546
|
};
|
|
514
547
|
const getSliceIds = (indexId) => mapKeys(getIndex(indexId));
|
|
@@ -516,6 +549,10 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
516
549
|
collValues(mapGet(getIndex(indexId), sliceId));
|
|
517
550
|
const addSliceIdsListener = (indexId, listener) =>
|
|
518
551
|
addListener(listener, sliceIdsListeners, [indexId]);
|
|
552
|
+
const addHasIndexListener = (indexId, listener) =>
|
|
553
|
+
addListener(listener, hasIndexListeners, [indexId]);
|
|
554
|
+
const addHasSliceListener = (indexId, sliceId, listener) =>
|
|
555
|
+
addListener(listener, hasSliceListeners, [indexId, sliceId]);
|
|
519
556
|
const addSliceRowIdsListener = (indexId, sliceId, listener) =>
|
|
520
557
|
addListener(listener, sliceRowIdsListeners, [indexId, sliceId]);
|
|
521
558
|
const delListener = (listenerId) => {
|
|
@@ -539,7 +576,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
539
576
|
getSliceIds,
|
|
540
577
|
getSliceRowIds,
|
|
541
578
|
addIndexIdsListener,
|
|
579
|
+
addHasIndexListener,
|
|
542
580
|
addSliceIdsListener,
|
|
581
|
+
addHasSliceListener,
|
|
543
582
|
addSliceRowIdsListener,
|
|
544
583
|
delListener,
|
|
545
584
|
destroy,
|
|
@@ -339,7 +339,9 @@ const getListenerFunctions = (getThing) => {
|
|
|
339
339
|
};
|
|
340
340
|
|
|
341
341
|
const createIndexes = getCreateFunction((store) => {
|
|
342
|
+
const hasIndexListeners = mapNew();
|
|
342
343
|
const sliceIdsListeners = mapNew();
|
|
344
|
+
const hasSliceListeners = mapNew();
|
|
343
345
|
const sliceRowIdsListeners = mapNew();
|
|
344
346
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
345
347
|
() => indexes,
|
|
@@ -378,6 +380,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
378
380
|
sliceIdSorter,
|
|
379
381
|
rowIdSorter = defaultSorter,
|
|
380
382
|
) => {
|
|
383
|
+
const hadIndex = hasIndex(indexId);
|
|
381
384
|
const sliceIdArraySorter = isUndefined(sliceIdSorter)
|
|
382
385
|
? void 0
|
|
383
386
|
: ([id1], [id2]) => sliceIdSorter(id1, id2);
|
|
@@ -394,8 +397,14 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
394
397
|
) => {
|
|
395
398
|
let sliceIdsChanged = 0;
|
|
396
399
|
const changedSlices = setNew();
|
|
400
|
+
const hadSlices = mapNew();
|
|
397
401
|
const unsortedSlices = setNew();
|
|
398
402
|
const index = getIndex(indexId);
|
|
403
|
+
const setHadSlice = (sliceId) => {
|
|
404
|
+
if (!collHas(hadSlices, sliceId)) {
|
|
405
|
+
mapSet(hadSlices, sliceId, collHas(index, sliceId));
|
|
406
|
+
}
|
|
407
|
+
};
|
|
399
408
|
collForEach(
|
|
400
409
|
changedSliceIds,
|
|
401
410
|
([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
|
|
@@ -407,6 +416,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
407
416
|
: 0,
|
|
408
417
|
);
|
|
409
418
|
collForEach(oldSliceIds, (oldSliceId) => {
|
|
419
|
+
setHadSlice(oldSliceId);
|
|
410
420
|
setAdd(changedSlices, oldSliceId);
|
|
411
421
|
ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
|
|
412
422
|
collDel(oldSlice, rowId);
|
|
@@ -417,6 +427,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
417
427
|
});
|
|
418
428
|
});
|
|
419
429
|
collForEach(newSliceIds, (newSliceId) => {
|
|
430
|
+
setHadSlice(newSliceId);
|
|
420
431
|
setAdd(changedSlices, newSliceId);
|
|
421
432
|
if (!collHas(index, newSliceId)) {
|
|
422
433
|
mapSet(index, newSliceId, setNew());
|
|
@@ -478,6 +489,12 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
478
489
|
if (sliceIdsChanged) {
|
|
479
490
|
callListeners(sliceIdsListeners, [indexId]);
|
|
480
491
|
}
|
|
492
|
+
mapForEach(hadSlices, (sliceId, hadSlice) => {
|
|
493
|
+
const hasSliceNow = collHas(index, sliceId);
|
|
494
|
+
if (hadSlice != hasSliceNow) {
|
|
495
|
+
callListeners(hasSliceListeners, [indexId, sliceId], hasSliceNow);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
481
498
|
collForEach(changedSlices, (sliceId) =>
|
|
482
499
|
callListeners(sliceRowIdsListeners, [indexId, sliceId]),
|
|
483
500
|
);
|
|
@@ -485,6 +502,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
485
502
|
getRowCellFunction(getSliceIdOrIds),
|
|
486
503
|
ifNotUndefined(getSortKey, getRowCellFunction),
|
|
487
504
|
);
|
|
505
|
+
if (!hadIndex) {
|
|
506
|
+
callListeners(hasIndexListeners, [indexId], true);
|
|
507
|
+
}
|
|
488
508
|
return indexes;
|
|
489
509
|
};
|
|
490
510
|
const forEachIndex = (indexCallback) =>
|
|
@@ -508,7 +528,20 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
508
528
|
);
|
|
509
529
|
};
|
|
510
530
|
const delIndexDefinition = (indexId) => {
|
|
531
|
+
const index = getIndex(indexId);
|
|
532
|
+
const hadIndex = hasIndex(indexId);
|
|
533
|
+
const sliceIds = hadIndex ? mapKeys(index) : [];
|
|
511
534
|
delDefinition(indexId);
|
|
535
|
+
if (hadIndex) {
|
|
536
|
+
callListeners(hasIndexListeners, [indexId], false);
|
|
537
|
+
if (sliceIds.length > 0) {
|
|
538
|
+
callListeners(sliceIdsListeners, [indexId]);
|
|
539
|
+
arrayForEach(sliceIds, (sliceId) => {
|
|
540
|
+
callListeners(hasSliceListeners, [indexId, sliceId], false);
|
|
541
|
+
callListeners(sliceRowIdsListeners, [indexId, sliceId]);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}
|
|
512
545
|
return indexes;
|
|
513
546
|
};
|
|
514
547
|
const getSliceIds = (indexId) => mapKeys(getIndex(indexId));
|
|
@@ -516,6 +549,10 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
516
549
|
collValues(mapGet(getIndex(indexId), sliceId));
|
|
517
550
|
const addSliceIdsListener = (indexId, listener) =>
|
|
518
551
|
addListener(listener, sliceIdsListeners, [indexId]);
|
|
552
|
+
const addHasIndexListener = (indexId, listener) =>
|
|
553
|
+
addListener(listener, hasIndexListeners, [indexId]);
|
|
554
|
+
const addHasSliceListener = (indexId, sliceId, listener) =>
|
|
555
|
+
addListener(listener, hasSliceListeners, [indexId, sliceId]);
|
|
519
556
|
const addSliceRowIdsListener = (indexId, sliceId, listener) =>
|
|
520
557
|
addListener(listener, sliceRowIdsListeners, [indexId, sliceId]);
|
|
521
558
|
const delListener = (listenerId) => {
|
|
@@ -539,7 +576,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
539
576
|
getSliceIds,
|
|
540
577
|
getSliceRowIds,
|
|
541
578
|
addIndexIdsListener,
|
|
579
|
+
addHasIndexListener,
|
|
542
580
|
addSliceIdsListener,
|
|
581
|
+
addHasSliceListener,
|
|
543
582
|
addSliceRowIdsListener,
|
|
544
583
|
delListener,
|
|
545
584
|
destroy,
|
package/mergeable-store/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const VALUE = 'Value';
|
|
|
28
28
|
const VALUES = VALUE + 's';
|
|
29
29
|
const VALUE_IDS = VALUE + IDS;
|
|
30
30
|
const TRANSACTION = 'Transaction';
|
|
31
|
+
const REQUIRED = 'required';
|
|
31
32
|
const JSON_PREFIX = '\uFFFD';
|
|
32
33
|
const id = (key) => EMPTY_STRING + key;
|
|
33
34
|
const strStartsWith = (str, prefix) => str.startsWith(prefix);
|
|
@@ -568,6 +569,7 @@ const createStore = () => {
|
|
|
568
569
|
const valuesSchemaMap = mapNew();
|
|
569
570
|
const valuesDefaulted = mapNew();
|
|
570
571
|
const valuesNonDefaulted = setNew();
|
|
572
|
+
const valuesRequiredNonDefaulted = setNew();
|
|
571
573
|
const tablePoolFunctions = mapNew();
|
|
572
574
|
const tableCellIds = mapNew();
|
|
573
575
|
const tablesMap = mapNew();
|
|
@@ -620,7 +622,7 @@ const createStore = () => {
|
|
|
620
622
|
const validateCellOrValueSchema = (schema) => {
|
|
621
623
|
if (
|
|
622
624
|
!objValidate(schema, (_child, id2) =>
|
|
623
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
|
|
625
|
+
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
624
626
|
)
|
|
625
627
|
) {
|
|
626
628
|
return false;
|
|
@@ -655,20 +657,32 @@ const createStore = () => {
|
|
|
655
657
|
(row, rowId) => validateRow(tableId, rowId, row),
|
|
656
658
|
() => cellInvalid(tableId),
|
|
657
659
|
);
|
|
658
|
-
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
(
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
660
|
+
const validateRow = (tableId, rowId, row, skipDefaults) => {
|
|
661
|
+
const rowWithDefaults = skipDefaults
|
|
662
|
+
? row
|
|
663
|
+
: addDefaultsToRow(row, tableId, rowId);
|
|
664
|
+
return (
|
|
665
|
+
objValidate(
|
|
666
|
+
rowWithDefaults,
|
|
667
|
+
(cell, cellId) =>
|
|
668
|
+
ifNotUndefined(
|
|
669
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
670
|
+
(validCell) => {
|
|
671
|
+
row[cellId] = validCell;
|
|
672
|
+
return true;
|
|
673
|
+
},
|
|
674
|
+
() => false,
|
|
675
|
+
),
|
|
676
|
+
() => cellInvalid(tableId, rowId),
|
|
677
|
+
) &&
|
|
678
|
+
(skipDefaults
|
|
679
|
+
? true
|
|
680
|
+
: arrayEvery(
|
|
681
|
+
collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
|
|
682
|
+
(cellId) => objHas(rowWithDefaults, cellId),
|
|
683
|
+
))
|
|
671
684
|
);
|
|
685
|
+
};
|
|
672
686
|
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
|
673
687
|
hasTablesSchema
|
|
674
688
|
? ifNotUndefined(
|
|
@@ -694,20 +708,31 @@ const createStore = () => {
|
|
|
694
708
|
: isUndefined(getCellOrValueType(cell))
|
|
695
709
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
696
710
|
: encodeIfJson(cell);
|
|
697
|
-
const validateValues = (values, skipDefaults) =>
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
711
|
+
const validateValues = (values, skipDefaults) => {
|
|
712
|
+
const valuesWithDefaults = skipDefaults
|
|
713
|
+
? values
|
|
714
|
+
: addDefaultsToValues(values);
|
|
715
|
+
return (
|
|
716
|
+
objValidate(
|
|
717
|
+
valuesWithDefaults,
|
|
718
|
+
(value, valueId) =>
|
|
719
|
+
ifNotUndefined(
|
|
720
|
+
getValidatedValue(valueId, value),
|
|
721
|
+
(validValue) => {
|
|
722
|
+
values[valueId] = validValue;
|
|
723
|
+
return true;
|
|
724
|
+
},
|
|
725
|
+
() => false,
|
|
726
|
+
),
|
|
727
|
+
() => valueInvalid(),
|
|
728
|
+
) &&
|
|
729
|
+
(skipDefaults
|
|
730
|
+
? true
|
|
731
|
+
: arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
|
|
732
|
+
objHas(valuesWithDefaults, valueId),
|
|
733
|
+
))
|
|
710
734
|
);
|
|
735
|
+
};
|
|
711
736
|
const getValidatedValue = (valueId, value) =>
|
|
712
737
|
hasValuesSchema
|
|
713
738
|
? ifNotUndefined(
|
|
@@ -778,6 +803,7 @@ const createStore = () => {
|
|
|
778
803
|
(_tablesSchema, tableId, tableSchema) => {
|
|
779
804
|
const rowDefaulted = mapNew();
|
|
780
805
|
const rowNonDefaulted = setNew();
|
|
806
|
+
const rowRequiredNonDefaulted = setNew();
|
|
781
807
|
mapMatch(
|
|
782
808
|
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
|
783
809
|
tableSchema,
|
|
@@ -785,12 +811,23 @@ const createStore = () => {
|
|
|
785
811
|
mapSet(tableSchemaMap, cellId, cellSchema);
|
|
786
812
|
ifNotUndefined(
|
|
787
813
|
cellSchema[DEFAULT],
|
|
788
|
-
(
|
|
789
|
-
|
|
814
|
+
(defaultCell) => {
|
|
815
|
+
mapSet(rowDefaulted, cellId, defaultCell);
|
|
816
|
+
},
|
|
817
|
+
() => {
|
|
818
|
+
setAdd(rowNonDefaulted, cellId);
|
|
819
|
+
if (cellSchema[REQUIRED] === true) {
|
|
820
|
+
setAdd(rowRequiredNonDefaulted, cellId);
|
|
821
|
+
}
|
|
822
|
+
},
|
|
790
823
|
);
|
|
791
824
|
},
|
|
792
825
|
);
|
|
793
|
-
mapSet(tablesSchemaRowCache, tableId, [
|
|
826
|
+
mapSet(tablesSchemaRowCache, tableId, [
|
|
827
|
+
rowDefaulted,
|
|
828
|
+
rowNonDefaulted,
|
|
829
|
+
rowRequiredNonDefaulted,
|
|
830
|
+
]);
|
|
794
831
|
},
|
|
795
832
|
(_tablesSchema, tableId) => {
|
|
796
833
|
mapSet(tablesSchemaMap, tableId);
|
|
@@ -805,14 +842,27 @@ const createStore = () => {
|
|
|
805
842
|
mapSet(valuesSchemaMap, valueId, valueSchema);
|
|
806
843
|
ifNotUndefined(
|
|
807
844
|
valueSchema[DEFAULT],
|
|
808
|
-
(
|
|
809
|
-
|
|
845
|
+
(defaultValue) => {
|
|
846
|
+
mapSet(valuesDefaulted, valueId, defaultValue);
|
|
847
|
+
collDel(valuesNonDefaulted, valueId);
|
|
848
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
849
|
+
},
|
|
850
|
+
() => {
|
|
851
|
+
mapSet(valuesDefaulted, valueId);
|
|
852
|
+
setAdd(valuesNonDefaulted, valueId);
|
|
853
|
+
if (valueSchema[REQUIRED] === true) {
|
|
854
|
+
setAdd(valuesRequiredNonDefaulted, valueId);
|
|
855
|
+
} else {
|
|
856
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
857
|
+
}
|
|
858
|
+
},
|
|
810
859
|
);
|
|
811
860
|
},
|
|
812
861
|
(_valuesSchema, valueId) => {
|
|
813
862
|
mapSet(valuesSchemaMap, valueId);
|
|
814
863
|
mapSet(valuesDefaulted, valueId);
|
|
815
864
|
collDel(valuesNonDefaulted, valueId);
|
|
865
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
816
866
|
},
|
|
817
867
|
);
|
|
818
868
|
const setOrDelTables = (tables) =>
|