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/omni/index.js
CHANGED
|
@@ -49,6 +49,7 @@ const TRANSACTION = 'Transaction';
|
|
|
49
49
|
const OPEN = 'open';
|
|
50
50
|
const MESSAGE = 'message';
|
|
51
51
|
const ERROR = 'error';
|
|
52
|
+
const REQUIRED = 'required';
|
|
52
53
|
const T = 't';
|
|
53
54
|
const V = 'v';
|
|
54
55
|
const UNDEFINED = '\uFFFC';
|
|
@@ -982,7 +983,9 @@ const defaultSorter = (sortKey1, sortKey2) =>
|
|
|
982
983
|
(sortKey1 ?? 0) < (sortKey2 ?? 0) ? -1 : 1;
|
|
983
984
|
|
|
984
985
|
const createIndexes = getCreateFunction((store) => {
|
|
986
|
+
const hasIndexListeners = mapNew();
|
|
985
987
|
const sliceIdsListeners = mapNew();
|
|
988
|
+
const hasSliceListeners = mapNew();
|
|
986
989
|
const sliceRowIdsListeners = mapNew();
|
|
987
990
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
988
991
|
() => indexes,
|
|
@@ -1021,6 +1024,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1021
1024
|
sliceIdSorter,
|
|
1022
1025
|
rowIdSorter = defaultSorter,
|
|
1023
1026
|
) => {
|
|
1027
|
+
const hadIndex = hasIndex(indexId);
|
|
1024
1028
|
const sliceIdArraySorter = isUndefined(sliceIdSorter)
|
|
1025
1029
|
? void 0
|
|
1026
1030
|
: ([id1], [id2]) => sliceIdSorter(id1, id2);
|
|
@@ -1037,8 +1041,14 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1037
1041
|
) => {
|
|
1038
1042
|
let sliceIdsChanged = 0;
|
|
1039
1043
|
const changedSlices = setNew();
|
|
1044
|
+
const hadSlices = mapNew();
|
|
1040
1045
|
const unsortedSlices = setNew();
|
|
1041
1046
|
const index = getIndex(indexId);
|
|
1047
|
+
const setHadSlice = (sliceId) => {
|
|
1048
|
+
if (!collHas(hadSlices, sliceId)) {
|
|
1049
|
+
mapSet(hadSlices, sliceId, collHas(index, sliceId));
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1042
1052
|
collForEach(
|
|
1043
1053
|
changedSliceIds,
|
|
1044
1054
|
([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
|
|
@@ -1050,6 +1060,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1050
1060
|
: 0,
|
|
1051
1061
|
);
|
|
1052
1062
|
collForEach(oldSliceIds, (oldSliceId) => {
|
|
1063
|
+
setHadSlice(oldSliceId);
|
|
1053
1064
|
setAdd(changedSlices, oldSliceId);
|
|
1054
1065
|
ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
|
|
1055
1066
|
collDel(oldSlice, rowId);
|
|
@@ -1060,6 +1071,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1060
1071
|
});
|
|
1061
1072
|
});
|
|
1062
1073
|
collForEach(newSliceIds, (newSliceId) => {
|
|
1074
|
+
setHadSlice(newSliceId);
|
|
1063
1075
|
setAdd(changedSlices, newSliceId);
|
|
1064
1076
|
if (!collHas(index, newSliceId)) {
|
|
1065
1077
|
mapSet(index, newSliceId, setNew());
|
|
@@ -1121,6 +1133,12 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1121
1133
|
if (sliceIdsChanged) {
|
|
1122
1134
|
callListeners(sliceIdsListeners, [indexId]);
|
|
1123
1135
|
}
|
|
1136
|
+
mapForEach(hadSlices, (sliceId, hadSlice) => {
|
|
1137
|
+
const hasSliceNow = collHas(index, sliceId);
|
|
1138
|
+
if (hadSlice != hasSliceNow) {
|
|
1139
|
+
callListeners(hasSliceListeners, [indexId, sliceId], hasSliceNow);
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1124
1142
|
collForEach(changedSlices, (sliceId) =>
|
|
1125
1143
|
callListeners(sliceRowIdsListeners, [indexId, sliceId]),
|
|
1126
1144
|
);
|
|
@@ -1128,6 +1146,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1128
1146
|
getRowCellFunction(getSliceIdOrIds),
|
|
1129
1147
|
ifNotUndefined(getSortKey, getRowCellFunction),
|
|
1130
1148
|
);
|
|
1149
|
+
if (!hadIndex) {
|
|
1150
|
+
callListeners(hasIndexListeners, [indexId], true);
|
|
1151
|
+
}
|
|
1131
1152
|
return indexes;
|
|
1132
1153
|
};
|
|
1133
1154
|
const forEachIndex = (indexCallback) =>
|
|
@@ -1151,7 +1172,20 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1151
1172
|
);
|
|
1152
1173
|
};
|
|
1153
1174
|
const delIndexDefinition = (indexId) => {
|
|
1175
|
+
const index = getIndex(indexId);
|
|
1176
|
+
const hadIndex = hasIndex(indexId);
|
|
1177
|
+
const sliceIds = hadIndex ? mapKeys(index) : [];
|
|
1154
1178
|
delDefinition(indexId);
|
|
1179
|
+
if (hadIndex) {
|
|
1180
|
+
callListeners(hasIndexListeners, [indexId], false);
|
|
1181
|
+
if (sliceIds.length > 0) {
|
|
1182
|
+
callListeners(sliceIdsListeners, [indexId]);
|
|
1183
|
+
arrayForEach(sliceIds, (sliceId) => {
|
|
1184
|
+
callListeners(hasSliceListeners, [indexId, sliceId], false);
|
|
1185
|
+
callListeners(sliceRowIdsListeners, [indexId, sliceId]);
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1155
1189
|
return indexes;
|
|
1156
1190
|
};
|
|
1157
1191
|
const getSliceIds = (indexId) => mapKeys(getIndex(indexId));
|
|
@@ -1159,6 +1193,10 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1159
1193
|
collValues(mapGet(getIndex(indexId), sliceId));
|
|
1160
1194
|
const addSliceIdsListener = (indexId, listener) =>
|
|
1161
1195
|
addListener(listener, sliceIdsListeners, [indexId]);
|
|
1196
|
+
const addHasIndexListener = (indexId, listener) =>
|
|
1197
|
+
addListener(listener, hasIndexListeners, [indexId]);
|
|
1198
|
+
const addHasSliceListener = (indexId, sliceId, listener) =>
|
|
1199
|
+
addListener(listener, hasSliceListeners, [indexId, sliceId]);
|
|
1162
1200
|
const addSliceRowIdsListener = (indexId, sliceId, listener) =>
|
|
1163
1201
|
addListener(listener, sliceRowIdsListeners, [indexId, sliceId]);
|
|
1164
1202
|
const delListener = (listenerId) => {
|
|
@@ -1182,7 +1220,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1182
1220
|
getSliceIds,
|
|
1183
1221
|
getSliceRowIds,
|
|
1184
1222
|
addIndexIdsListener,
|
|
1223
|
+
addHasIndexListener,
|
|
1185
1224
|
addSliceIdsListener,
|
|
1225
|
+
addHasSliceListener,
|
|
1186
1226
|
addSliceRowIdsListener,
|
|
1187
1227
|
delListener,
|
|
1188
1228
|
destroy,
|
|
@@ -1289,6 +1329,7 @@ const createStore = () => {
|
|
|
1289
1329
|
const valuesSchemaMap = mapNew();
|
|
1290
1330
|
const valuesDefaulted = mapNew();
|
|
1291
1331
|
const valuesNonDefaulted = setNew();
|
|
1332
|
+
const valuesRequiredNonDefaulted = setNew();
|
|
1292
1333
|
const tablePoolFunctions = mapNew();
|
|
1293
1334
|
const tableCellIds = mapNew();
|
|
1294
1335
|
const tablesMap = mapNew();
|
|
@@ -1341,7 +1382,7 @@ const createStore = () => {
|
|
|
1341
1382
|
const validateCellOrValueSchema = (schema) => {
|
|
1342
1383
|
if (
|
|
1343
1384
|
!objValidate(schema, (_child, id2) =>
|
|
1344
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
|
|
1385
|
+
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1345
1386
|
)
|
|
1346
1387
|
) {
|
|
1347
1388
|
return false;
|
|
@@ -1376,20 +1417,32 @@ const createStore = () => {
|
|
|
1376
1417
|
(row, rowId) => validateRow(tableId, rowId, row),
|
|
1377
1418
|
() => cellInvalid(tableId),
|
|
1378
1419
|
);
|
|
1379
|
-
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
(
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1420
|
+
const validateRow = (tableId, rowId, row, skipDefaults) => {
|
|
1421
|
+
const rowWithDefaults = skipDefaults
|
|
1422
|
+
? row
|
|
1423
|
+
: addDefaultsToRow(row, tableId, rowId);
|
|
1424
|
+
return (
|
|
1425
|
+
objValidate(
|
|
1426
|
+
rowWithDefaults,
|
|
1427
|
+
(cell, cellId) =>
|
|
1428
|
+
ifNotUndefined(
|
|
1429
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1430
|
+
(validCell) => {
|
|
1431
|
+
row[cellId] = validCell;
|
|
1432
|
+
return true;
|
|
1433
|
+
},
|
|
1434
|
+
() => false,
|
|
1435
|
+
),
|
|
1436
|
+
() => cellInvalid(tableId, rowId),
|
|
1437
|
+
) &&
|
|
1438
|
+
(skipDefaults
|
|
1439
|
+
? true
|
|
1440
|
+
: arrayEvery(
|
|
1441
|
+
collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
|
|
1442
|
+
(cellId) => objHas(rowWithDefaults, cellId),
|
|
1443
|
+
))
|
|
1392
1444
|
);
|
|
1445
|
+
};
|
|
1393
1446
|
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
|
1394
1447
|
hasTablesSchema
|
|
1395
1448
|
? ifNotUndefined(
|
|
@@ -1415,20 +1468,31 @@ const createStore = () => {
|
|
|
1415
1468
|
: isUndefined(getCellOrValueType(cell))
|
|
1416
1469
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1417
1470
|
: encodeIfJson(cell);
|
|
1418
|
-
const validateValues = (values, skipDefaults) =>
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
(
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1471
|
+
const validateValues = (values, skipDefaults) => {
|
|
1472
|
+
const valuesWithDefaults = skipDefaults
|
|
1473
|
+
? values
|
|
1474
|
+
: addDefaultsToValues(values);
|
|
1475
|
+
return (
|
|
1476
|
+
objValidate(
|
|
1477
|
+
valuesWithDefaults,
|
|
1478
|
+
(value, valueId) =>
|
|
1479
|
+
ifNotUndefined(
|
|
1480
|
+
getValidatedValue(valueId, value),
|
|
1481
|
+
(validValue) => {
|
|
1482
|
+
values[valueId] = validValue;
|
|
1483
|
+
return true;
|
|
1484
|
+
},
|
|
1485
|
+
() => false,
|
|
1486
|
+
),
|
|
1487
|
+
() => valueInvalid(),
|
|
1488
|
+
) &&
|
|
1489
|
+
(skipDefaults
|
|
1490
|
+
? true
|
|
1491
|
+
: arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
|
|
1492
|
+
objHas(valuesWithDefaults, valueId),
|
|
1493
|
+
))
|
|
1431
1494
|
);
|
|
1495
|
+
};
|
|
1432
1496
|
const getValidatedValue = (valueId, value) =>
|
|
1433
1497
|
hasValuesSchema
|
|
1434
1498
|
? ifNotUndefined(
|
|
@@ -1499,6 +1563,7 @@ const createStore = () => {
|
|
|
1499
1563
|
(_tablesSchema, tableId, tableSchema) => {
|
|
1500
1564
|
const rowDefaulted = mapNew();
|
|
1501
1565
|
const rowNonDefaulted = setNew();
|
|
1566
|
+
const rowRequiredNonDefaulted = setNew();
|
|
1502
1567
|
mapMatch(
|
|
1503
1568
|
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
|
1504
1569
|
tableSchema,
|
|
@@ -1506,12 +1571,23 @@ const createStore = () => {
|
|
|
1506
1571
|
mapSet(tableSchemaMap, cellId, cellSchema);
|
|
1507
1572
|
ifNotUndefined(
|
|
1508
1573
|
cellSchema[DEFAULT],
|
|
1509
|
-
(
|
|
1510
|
-
|
|
1574
|
+
(defaultCell) => {
|
|
1575
|
+
mapSet(rowDefaulted, cellId, defaultCell);
|
|
1576
|
+
},
|
|
1577
|
+
() => {
|
|
1578
|
+
setAdd(rowNonDefaulted, cellId);
|
|
1579
|
+
if (cellSchema[REQUIRED] === true) {
|
|
1580
|
+
setAdd(rowRequiredNonDefaulted, cellId);
|
|
1581
|
+
}
|
|
1582
|
+
},
|
|
1511
1583
|
);
|
|
1512
1584
|
},
|
|
1513
1585
|
);
|
|
1514
|
-
mapSet(tablesSchemaRowCache, tableId, [
|
|
1586
|
+
mapSet(tablesSchemaRowCache, tableId, [
|
|
1587
|
+
rowDefaulted,
|
|
1588
|
+
rowNonDefaulted,
|
|
1589
|
+
rowRequiredNonDefaulted,
|
|
1590
|
+
]);
|
|
1515
1591
|
},
|
|
1516
1592
|
(_tablesSchema, tableId) => {
|
|
1517
1593
|
mapSet(tablesSchemaMap, tableId);
|
|
@@ -1526,14 +1602,27 @@ const createStore = () => {
|
|
|
1526
1602
|
mapSet(valuesSchemaMap, valueId, valueSchema);
|
|
1527
1603
|
ifNotUndefined(
|
|
1528
1604
|
valueSchema[DEFAULT],
|
|
1529
|
-
(
|
|
1530
|
-
|
|
1605
|
+
(defaultValue) => {
|
|
1606
|
+
mapSet(valuesDefaulted, valueId, defaultValue);
|
|
1607
|
+
collDel(valuesNonDefaulted, valueId);
|
|
1608
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1609
|
+
},
|
|
1610
|
+
() => {
|
|
1611
|
+
mapSet(valuesDefaulted, valueId);
|
|
1612
|
+
setAdd(valuesNonDefaulted, valueId);
|
|
1613
|
+
if (valueSchema[REQUIRED] === true) {
|
|
1614
|
+
setAdd(valuesRequiredNonDefaulted, valueId);
|
|
1615
|
+
} else {
|
|
1616
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1617
|
+
}
|
|
1618
|
+
},
|
|
1531
1619
|
);
|
|
1532
1620
|
},
|
|
1533
1621
|
(_valuesSchema, valueId) => {
|
|
1534
1622
|
mapSet(valuesSchemaMap, valueId);
|
|
1535
1623
|
mapSet(valuesDefaulted, valueId);
|
|
1536
1624
|
collDel(valuesNonDefaulted, valueId);
|
|
1625
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1537
1626
|
},
|
|
1538
1627
|
);
|
|
1539
1628
|
const setOrDelTables = (tables) =>
|
|
@@ -49,6 +49,7 @@ const TRANSACTION = 'Transaction';
|
|
|
49
49
|
const OPEN = 'open';
|
|
50
50
|
const MESSAGE = 'message';
|
|
51
51
|
const ERROR = 'error';
|
|
52
|
+
const REQUIRED = 'required';
|
|
52
53
|
const T = 't';
|
|
53
54
|
const V = 'v';
|
|
54
55
|
const UNDEFINED = '\uFFFC';
|
|
@@ -982,7 +983,9 @@ const defaultSorter = (sortKey1, sortKey2) =>
|
|
|
982
983
|
(sortKey1 ?? 0) < (sortKey2 ?? 0) ? -1 : 1;
|
|
983
984
|
|
|
984
985
|
const createIndexes = getCreateFunction((store) => {
|
|
986
|
+
const hasIndexListeners = mapNew();
|
|
985
987
|
const sliceIdsListeners = mapNew();
|
|
988
|
+
const hasSliceListeners = mapNew();
|
|
986
989
|
const sliceRowIdsListeners = mapNew();
|
|
987
990
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
988
991
|
() => indexes,
|
|
@@ -1021,6 +1024,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1021
1024
|
sliceIdSorter,
|
|
1022
1025
|
rowIdSorter = defaultSorter,
|
|
1023
1026
|
) => {
|
|
1027
|
+
const hadIndex = hasIndex(indexId);
|
|
1024
1028
|
const sliceIdArraySorter = isUndefined(sliceIdSorter)
|
|
1025
1029
|
? void 0
|
|
1026
1030
|
: ([id1], [id2]) => sliceIdSorter(id1, id2);
|
|
@@ -1037,8 +1041,14 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1037
1041
|
) => {
|
|
1038
1042
|
let sliceIdsChanged = 0;
|
|
1039
1043
|
const changedSlices = setNew();
|
|
1044
|
+
const hadSlices = mapNew();
|
|
1040
1045
|
const unsortedSlices = setNew();
|
|
1041
1046
|
const index = getIndex(indexId);
|
|
1047
|
+
const setHadSlice = (sliceId) => {
|
|
1048
|
+
if (!collHas(hadSlices, sliceId)) {
|
|
1049
|
+
mapSet(hadSlices, sliceId, collHas(index, sliceId));
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1042
1052
|
collForEach(
|
|
1043
1053
|
changedSliceIds,
|
|
1044
1054
|
([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
|
|
@@ -1050,6 +1060,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1050
1060
|
: 0,
|
|
1051
1061
|
);
|
|
1052
1062
|
collForEach(oldSliceIds, (oldSliceId) => {
|
|
1063
|
+
setHadSlice(oldSliceId);
|
|
1053
1064
|
setAdd(changedSlices, oldSliceId);
|
|
1054
1065
|
ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
|
|
1055
1066
|
collDel(oldSlice, rowId);
|
|
@@ -1060,6 +1071,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1060
1071
|
});
|
|
1061
1072
|
});
|
|
1062
1073
|
collForEach(newSliceIds, (newSliceId) => {
|
|
1074
|
+
setHadSlice(newSliceId);
|
|
1063
1075
|
setAdd(changedSlices, newSliceId);
|
|
1064
1076
|
if (!collHas(index, newSliceId)) {
|
|
1065
1077
|
mapSet(index, newSliceId, setNew());
|
|
@@ -1121,6 +1133,12 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1121
1133
|
if (sliceIdsChanged) {
|
|
1122
1134
|
callListeners(sliceIdsListeners, [indexId]);
|
|
1123
1135
|
}
|
|
1136
|
+
mapForEach(hadSlices, (sliceId, hadSlice) => {
|
|
1137
|
+
const hasSliceNow = collHas(index, sliceId);
|
|
1138
|
+
if (hadSlice != hasSliceNow) {
|
|
1139
|
+
callListeners(hasSliceListeners, [indexId, sliceId], hasSliceNow);
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1124
1142
|
collForEach(changedSlices, (sliceId) =>
|
|
1125
1143
|
callListeners(sliceRowIdsListeners, [indexId, sliceId]),
|
|
1126
1144
|
);
|
|
@@ -1128,6 +1146,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1128
1146
|
getRowCellFunction(getSliceIdOrIds),
|
|
1129
1147
|
ifNotUndefined(getSortKey, getRowCellFunction),
|
|
1130
1148
|
);
|
|
1149
|
+
if (!hadIndex) {
|
|
1150
|
+
callListeners(hasIndexListeners, [indexId], true);
|
|
1151
|
+
}
|
|
1131
1152
|
return indexes;
|
|
1132
1153
|
};
|
|
1133
1154
|
const forEachIndex = (indexCallback) =>
|
|
@@ -1151,7 +1172,20 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1151
1172
|
);
|
|
1152
1173
|
};
|
|
1153
1174
|
const delIndexDefinition = (indexId) => {
|
|
1175
|
+
const index = getIndex(indexId);
|
|
1176
|
+
const hadIndex = hasIndex(indexId);
|
|
1177
|
+
const sliceIds = hadIndex ? mapKeys(index) : [];
|
|
1154
1178
|
delDefinition(indexId);
|
|
1179
|
+
if (hadIndex) {
|
|
1180
|
+
callListeners(hasIndexListeners, [indexId], false);
|
|
1181
|
+
if (sliceIds.length > 0) {
|
|
1182
|
+
callListeners(sliceIdsListeners, [indexId]);
|
|
1183
|
+
arrayForEach(sliceIds, (sliceId) => {
|
|
1184
|
+
callListeners(hasSliceListeners, [indexId, sliceId], false);
|
|
1185
|
+
callListeners(sliceRowIdsListeners, [indexId, sliceId]);
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1155
1189
|
return indexes;
|
|
1156
1190
|
};
|
|
1157
1191
|
const getSliceIds = (indexId) => mapKeys(getIndex(indexId));
|
|
@@ -1159,6 +1193,10 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1159
1193
|
collValues(mapGet(getIndex(indexId), sliceId));
|
|
1160
1194
|
const addSliceIdsListener = (indexId, listener) =>
|
|
1161
1195
|
addListener(listener, sliceIdsListeners, [indexId]);
|
|
1196
|
+
const addHasIndexListener = (indexId, listener) =>
|
|
1197
|
+
addListener(listener, hasIndexListeners, [indexId]);
|
|
1198
|
+
const addHasSliceListener = (indexId, sliceId, listener) =>
|
|
1199
|
+
addListener(listener, hasSliceListeners, [indexId, sliceId]);
|
|
1162
1200
|
const addSliceRowIdsListener = (indexId, sliceId, listener) =>
|
|
1163
1201
|
addListener(listener, sliceRowIdsListeners, [indexId, sliceId]);
|
|
1164
1202
|
const delListener = (listenerId) => {
|
|
@@ -1182,7 +1220,9 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
1182
1220
|
getSliceIds,
|
|
1183
1221
|
getSliceRowIds,
|
|
1184
1222
|
addIndexIdsListener,
|
|
1223
|
+
addHasIndexListener,
|
|
1185
1224
|
addSliceIdsListener,
|
|
1225
|
+
addHasSliceListener,
|
|
1186
1226
|
addSliceRowIdsListener,
|
|
1187
1227
|
delListener,
|
|
1188
1228
|
destroy,
|
|
@@ -1289,6 +1329,7 @@ const createStore = () => {
|
|
|
1289
1329
|
const valuesSchemaMap = mapNew();
|
|
1290
1330
|
const valuesDefaulted = mapNew();
|
|
1291
1331
|
const valuesNonDefaulted = setNew();
|
|
1332
|
+
const valuesRequiredNonDefaulted = setNew();
|
|
1292
1333
|
const tablePoolFunctions = mapNew();
|
|
1293
1334
|
const tableCellIds = mapNew();
|
|
1294
1335
|
const tablesMap = mapNew();
|
|
@@ -1341,7 +1382,7 @@ const createStore = () => {
|
|
|
1341
1382
|
const validateCellOrValueSchema = (schema) => {
|
|
1342
1383
|
if (
|
|
1343
1384
|
!objValidate(schema, (_child, id2) =>
|
|
1344
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
|
|
1385
|
+
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1345
1386
|
)
|
|
1346
1387
|
) {
|
|
1347
1388
|
return false;
|
|
@@ -1376,20 +1417,32 @@ const createStore = () => {
|
|
|
1376
1417
|
(row, rowId) => validateRow(tableId, rowId, row),
|
|
1377
1418
|
() => cellInvalid(tableId),
|
|
1378
1419
|
);
|
|
1379
|
-
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
(
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1420
|
+
const validateRow = (tableId, rowId, row, skipDefaults) => {
|
|
1421
|
+
const rowWithDefaults = skipDefaults
|
|
1422
|
+
? row
|
|
1423
|
+
: addDefaultsToRow(row, tableId, rowId);
|
|
1424
|
+
return (
|
|
1425
|
+
objValidate(
|
|
1426
|
+
rowWithDefaults,
|
|
1427
|
+
(cell, cellId) =>
|
|
1428
|
+
ifNotUndefined(
|
|
1429
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1430
|
+
(validCell) => {
|
|
1431
|
+
row[cellId] = validCell;
|
|
1432
|
+
return true;
|
|
1433
|
+
},
|
|
1434
|
+
() => false,
|
|
1435
|
+
),
|
|
1436
|
+
() => cellInvalid(tableId, rowId),
|
|
1437
|
+
) &&
|
|
1438
|
+
(skipDefaults
|
|
1439
|
+
? true
|
|
1440
|
+
: arrayEvery(
|
|
1441
|
+
collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
|
|
1442
|
+
(cellId) => objHas(rowWithDefaults, cellId),
|
|
1443
|
+
))
|
|
1392
1444
|
);
|
|
1445
|
+
};
|
|
1393
1446
|
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
|
1394
1447
|
hasTablesSchema
|
|
1395
1448
|
? ifNotUndefined(
|
|
@@ -1415,20 +1468,31 @@ const createStore = () => {
|
|
|
1415
1468
|
: isUndefined(getCellOrValueType(cell))
|
|
1416
1469
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1417
1470
|
: encodeIfJson(cell);
|
|
1418
|
-
const validateValues = (values, skipDefaults) =>
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
(
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1471
|
+
const validateValues = (values, skipDefaults) => {
|
|
1472
|
+
const valuesWithDefaults = skipDefaults
|
|
1473
|
+
? values
|
|
1474
|
+
: addDefaultsToValues(values);
|
|
1475
|
+
return (
|
|
1476
|
+
objValidate(
|
|
1477
|
+
valuesWithDefaults,
|
|
1478
|
+
(value, valueId) =>
|
|
1479
|
+
ifNotUndefined(
|
|
1480
|
+
getValidatedValue(valueId, value),
|
|
1481
|
+
(validValue) => {
|
|
1482
|
+
values[valueId] = validValue;
|
|
1483
|
+
return true;
|
|
1484
|
+
},
|
|
1485
|
+
() => false,
|
|
1486
|
+
),
|
|
1487
|
+
() => valueInvalid(),
|
|
1488
|
+
) &&
|
|
1489
|
+
(skipDefaults
|
|
1490
|
+
? true
|
|
1491
|
+
: arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
|
|
1492
|
+
objHas(valuesWithDefaults, valueId),
|
|
1493
|
+
))
|
|
1431
1494
|
);
|
|
1495
|
+
};
|
|
1432
1496
|
const getValidatedValue = (valueId, value) =>
|
|
1433
1497
|
hasValuesSchema
|
|
1434
1498
|
? ifNotUndefined(
|
|
@@ -1499,6 +1563,7 @@ const createStore = () => {
|
|
|
1499
1563
|
(_tablesSchema, tableId, tableSchema) => {
|
|
1500
1564
|
const rowDefaulted = mapNew();
|
|
1501
1565
|
const rowNonDefaulted = setNew();
|
|
1566
|
+
const rowRequiredNonDefaulted = setNew();
|
|
1502
1567
|
mapMatch(
|
|
1503
1568
|
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
|
1504
1569
|
tableSchema,
|
|
@@ -1506,12 +1571,23 @@ const createStore = () => {
|
|
|
1506
1571
|
mapSet(tableSchemaMap, cellId, cellSchema);
|
|
1507
1572
|
ifNotUndefined(
|
|
1508
1573
|
cellSchema[DEFAULT],
|
|
1509
|
-
(
|
|
1510
|
-
|
|
1574
|
+
(defaultCell) => {
|
|
1575
|
+
mapSet(rowDefaulted, cellId, defaultCell);
|
|
1576
|
+
},
|
|
1577
|
+
() => {
|
|
1578
|
+
setAdd(rowNonDefaulted, cellId);
|
|
1579
|
+
if (cellSchema[REQUIRED] === true) {
|
|
1580
|
+
setAdd(rowRequiredNonDefaulted, cellId);
|
|
1581
|
+
}
|
|
1582
|
+
},
|
|
1511
1583
|
);
|
|
1512
1584
|
},
|
|
1513
1585
|
);
|
|
1514
|
-
mapSet(tablesSchemaRowCache, tableId, [
|
|
1586
|
+
mapSet(tablesSchemaRowCache, tableId, [
|
|
1587
|
+
rowDefaulted,
|
|
1588
|
+
rowNonDefaulted,
|
|
1589
|
+
rowRequiredNonDefaulted,
|
|
1590
|
+
]);
|
|
1515
1591
|
},
|
|
1516
1592
|
(_tablesSchema, tableId) => {
|
|
1517
1593
|
mapSet(tablesSchemaMap, tableId);
|
|
@@ -1526,14 +1602,27 @@ const createStore = () => {
|
|
|
1526
1602
|
mapSet(valuesSchemaMap, valueId, valueSchema);
|
|
1527
1603
|
ifNotUndefined(
|
|
1528
1604
|
valueSchema[DEFAULT],
|
|
1529
|
-
(
|
|
1530
|
-
|
|
1605
|
+
(defaultValue) => {
|
|
1606
|
+
mapSet(valuesDefaulted, valueId, defaultValue);
|
|
1607
|
+
collDel(valuesNonDefaulted, valueId);
|
|
1608
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1609
|
+
},
|
|
1610
|
+
() => {
|
|
1611
|
+
mapSet(valuesDefaulted, valueId);
|
|
1612
|
+
setAdd(valuesNonDefaulted, valueId);
|
|
1613
|
+
if (valueSchema[REQUIRED] === true) {
|
|
1614
|
+
setAdd(valuesRequiredNonDefaulted, valueId);
|
|
1615
|
+
} else {
|
|
1616
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1617
|
+
}
|
|
1618
|
+
},
|
|
1531
1619
|
);
|
|
1532
1620
|
},
|
|
1533
1621
|
(_valuesSchema, valueId) => {
|
|
1534
1622
|
mapSet(valuesSchemaMap, valueId);
|
|
1535
1623
|
mapSet(valuesDefaulted, valueId);
|
|
1536
1624
|
collDel(valuesNonDefaulted, valueId);
|
|
1625
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1537
1626
|
},
|
|
1538
1627
|
);
|
|
1539
1628
|
const setOrDelTables = (tables) =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "9.1.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@automerge/automerge-repo": "^2.5.6",
|
|
27
|
-
"@cloudflare/workers-types": "^5.
|
|
27
|
+
"@cloudflare/workers-types": "^5.20260708.1",
|
|
28
28
|
"@electric-sql/pglite": "^0.5.4",
|
|
29
29
|
"@libsql/client": "^0.17.4",
|
|
30
|
-
"@powersync/common": "^1.57.
|
|
30
|
+
"@powersync/common": "^1.57.1",
|
|
31
31
|
"@sinclair/typebox": "^0.34.49",
|
|
32
32
|
"@sqlite.org/sqlite-wasm": "^3.53.0-build1",
|
|
33
33
|
"@vlcn.io/crsqlite-wasm": "^0.16.0",
|
|
34
|
-
"arktype": "^2.2.
|
|
34
|
+
"arktype": "^2.2.3",
|
|
35
35
|
"bun": "^1.3.14",
|
|
36
36
|
"effect": "^3.21.4",
|
|
37
37
|
"electric-sql": "^0.12.1",
|
|
38
|
-
"expo": "^57.0.
|
|
38
|
+
"expo": "^57.0.4",
|
|
39
39
|
"expo-sqlite": "^57.0.0",
|
|
40
40
|
"partykit": "^0.0.115",
|
|
41
41
|
"partysocket": "^1.3.0",
|