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.
- 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-solid/index.d.ts +42 -0
- package/@types/ui-solid/with-schemas/index.d.ts +101 -32
- package/@types/ui-svelte/index.d.ts +34 -0
- package/@types/ui-svelte/with-schemas/index.d.ts +34 -0
- 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 +2 -2
- 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
|
@@ -490,6 +490,14 @@ const getIndexesIds = () => {
|
|
|
490
490
|
|
|
491
491
|
const getIndexIds = (indexesOrIndexesId) =>
|
|
492
492
|
createListenable(resolveIndexes(indexesOrIndexesId), INDEX + IDS, EMPTY_ARR);
|
|
493
|
+
const hasIndex = (indexId, indexesOrIndexesId) =>
|
|
494
|
+
createListenable(
|
|
495
|
+
resolveIndexes(indexesOrIndexesId),
|
|
496
|
+
INDEX,
|
|
497
|
+
false,
|
|
498
|
+
() => [maybeGet(indexId)],
|
|
499
|
+
1,
|
|
500
|
+
);
|
|
493
501
|
const getSliceIds = (indexId, indexesOrIndexesId) =>
|
|
494
502
|
createListenable(
|
|
495
503
|
resolveIndexes(indexesOrIndexesId),
|
|
@@ -497,6 +505,14 @@ const getSliceIds = (indexId, indexesOrIndexesId) =>
|
|
|
497
505
|
EMPTY_ARR,
|
|
498
506
|
() => [maybeGet(indexId)],
|
|
499
507
|
);
|
|
508
|
+
const hasSlice = (indexId, sliceId, indexesOrIndexesId) =>
|
|
509
|
+
createListenable(
|
|
510
|
+
resolveIndexes(indexesOrIndexesId),
|
|
511
|
+
SLICE,
|
|
512
|
+
false,
|
|
513
|
+
() => [maybeGet(indexId), maybeGet(sliceId)],
|
|
514
|
+
1,
|
|
515
|
+
);
|
|
500
516
|
const getSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
|
|
501
517
|
createListenable(
|
|
502
518
|
resolveIndexes(indexesOrIndexesId),
|
|
@@ -2600,7 +2616,9 @@ export {
|
|
|
2600
2616
|
getValueIds,
|
|
2601
2617
|
getValues,
|
|
2602
2618
|
hasCell,
|
|
2619
|
+
hasIndex,
|
|
2603
2620
|
hasRow,
|
|
2621
|
+
hasSlice,
|
|
2604
2622
|
hasTable,
|
|
2605
2623
|
hasTableCell,
|
|
2606
2624
|
hasTables,
|
|
@@ -43,6 +43,7 @@ const RELATIONSHIP = 'Relationship';
|
|
|
43
43
|
const REMOTE_ROW_ID = 'Remote' + ROW + 'Id';
|
|
44
44
|
const QUERY = 'Query';
|
|
45
45
|
const EXTRA = 'extra';
|
|
46
|
+
const REQUIRED = 'required';
|
|
46
47
|
const UNDEFINED = '\uFFFC';
|
|
47
48
|
const JSON_PREFIX = '\uFFFD';
|
|
48
49
|
const id = (key) => EMPTY_STRING + key;
|
|
@@ -1177,6 +1178,7 @@ const createStore = () => {
|
|
|
1177
1178
|
const valuesSchemaMap = mapNew();
|
|
1178
1179
|
const valuesDefaulted = mapNew();
|
|
1179
1180
|
const valuesNonDefaulted = setNew();
|
|
1181
|
+
const valuesRequiredNonDefaulted = setNew();
|
|
1180
1182
|
const tablePoolFunctions = mapNew();
|
|
1181
1183
|
const tableCellIds = mapNew();
|
|
1182
1184
|
const tablesMap = mapNew();
|
|
@@ -1229,7 +1231,7 @@ const createStore = () => {
|
|
|
1229
1231
|
const validateCellOrValueSchema = (schema) => {
|
|
1230
1232
|
if (
|
|
1231
1233
|
!objValidate(schema, (_child, id2) =>
|
|
1232
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
|
|
1234
|
+
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1233
1235
|
)
|
|
1234
1236
|
) {
|
|
1235
1237
|
return false;
|
|
@@ -1264,20 +1266,32 @@ const createStore = () => {
|
|
|
1264
1266
|
(row, rowId) => validateRow(tableId, rowId, row),
|
|
1265
1267
|
() => cellInvalid(tableId),
|
|
1266
1268
|
);
|
|
1267
|
-
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
(
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1269
|
+
const validateRow = (tableId, rowId, row, skipDefaults) => {
|
|
1270
|
+
const rowWithDefaults = skipDefaults
|
|
1271
|
+
? row
|
|
1272
|
+
: addDefaultsToRow(row, tableId, rowId);
|
|
1273
|
+
return (
|
|
1274
|
+
objValidate(
|
|
1275
|
+
rowWithDefaults,
|
|
1276
|
+
(cell, cellId) =>
|
|
1277
|
+
ifNotUndefined(
|
|
1278
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1279
|
+
(validCell) => {
|
|
1280
|
+
row[cellId] = validCell;
|
|
1281
|
+
return true;
|
|
1282
|
+
},
|
|
1283
|
+
() => false,
|
|
1284
|
+
),
|
|
1285
|
+
() => cellInvalid(tableId, rowId),
|
|
1286
|
+
) &&
|
|
1287
|
+
(skipDefaults
|
|
1288
|
+
? true
|
|
1289
|
+
: arrayEvery(
|
|
1290
|
+
collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
|
|
1291
|
+
(cellId) => objHas(rowWithDefaults, cellId),
|
|
1292
|
+
))
|
|
1280
1293
|
);
|
|
1294
|
+
};
|
|
1281
1295
|
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
|
1282
1296
|
hasTablesSchema
|
|
1283
1297
|
? ifNotUndefined(
|
|
@@ -1303,20 +1317,31 @@ const createStore = () => {
|
|
|
1303
1317
|
: isUndefined(getCellOrValueType(cell))
|
|
1304
1318
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1305
1319
|
: encodeIfJson(cell);
|
|
1306
|
-
const validateValues = (values, skipDefaults) =>
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
(
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1320
|
+
const validateValues = (values, skipDefaults) => {
|
|
1321
|
+
const valuesWithDefaults = skipDefaults
|
|
1322
|
+
? values
|
|
1323
|
+
: addDefaultsToValues(values);
|
|
1324
|
+
return (
|
|
1325
|
+
objValidate(
|
|
1326
|
+
valuesWithDefaults,
|
|
1327
|
+
(value, valueId) =>
|
|
1328
|
+
ifNotUndefined(
|
|
1329
|
+
getValidatedValue(valueId, value),
|
|
1330
|
+
(validValue) => {
|
|
1331
|
+
values[valueId] = validValue;
|
|
1332
|
+
return true;
|
|
1333
|
+
},
|
|
1334
|
+
() => false,
|
|
1335
|
+
),
|
|
1336
|
+
() => valueInvalid(),
|
|
1337
|
+
) &&
|
|
1338
|
+
(skipDefaults
|
|
1339
|
+
? true
|
|
1340
|
+
: arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
|
|
1341
|
+
objHas(valuesWithDefaults, valueId),
|
|
1342
|
+
))
|
|
1319
1343
|
);
|
|
1344
|
+
};
|
|
1320
1345
|
const getValidatedValue = (valueId, value) =>
|
|
1321
1346
|
hasValuesSchema
|
|
1322
1347
|
? ifNotUndefined(
|
|
@@ -1387,6 +1412,7 @@ const createStore = () => {
|
|
|
1387
1412
|
(_tablesSchema, tableId, tableSchema) => {
|
|
1388
1413
|
const rowDefaulted = mapNew();
|
|
1389
1414
|
const rowNonDefaulted = setNew();
|
|
1415
|
+
const rowRequiredNonDefaulted = setNew();
|
|
1390
1416
|
mapMatch(
|
|
1391
1417
|
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
|
1392
1418
|
tableSchema,
|
|
@@ -1394,12 +1420,23 @@ const createStore = () => {
|
|
|
1394
1420
|
mapSet(tableSchemaMap, cellId, cellSchema);
|
|
1395
1421
|
ifNotUndefined(
|
|
1396
1422
|
cellSchema[DEFAULT],
|
|
1397
|
-
(
|
|
1398
|
-
|
|
1423
|
+
(defaultCell) => {
|
|
1424
|
+
mapSet(rowDefaulted, cellId, defaultCell);
|
|
1425
|
+
},
|
|
1426
|
+
() => {
|
|
1427
|
+
setAdd(rowNonDefaulted, cellId);
|
|
1428
|
+
if (cellSchema[REQUIRED] === true) {
|
|
1429
|
+
setAdd(rowRequiredNonDefaulted, cellId);
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1399
1432
|
);
|
|
1400
1433
|
},
|
|
1401
1434
|
);
|
|
1402
|
-
mapSet(tablesSchemaRowCache, tableId, [
|
|
1435
|
+
mapSet(tablesSchemaRowCache, tableId, [
|
|
1436
|
+
rowDefaulted,
|
|
1437
|
+
rowNonDefaulted,
|
|
1438
|
+
rowRequiredNonDefaulted,
|
|
1439
|
+
]);
|
|
1403
1440
|
},
|
|
1404
1441
|
(_tablesSchema, tableId) => {
|
|
1405
1442
|
mapSet(tablesSchemaMap, tableId);
|
|
@@ -1414,14 +1451,27 @@ const createStore = () => {
|
|
|
1414
1451
|
mapSet(valuesSchemaMap, valueId, valueSchema);
|
|
1415
1452
|
ifNotUndefined(
|
|
1416
1453
|
valueSchema[DEFAULT],
|
|
1417
|
-
(
|
|
1418
|
-
|
|
1454
|
+
(defaultValue) => {
|
|
1455
|
+
mapSet(valuesDefaulted, valueId, defaultValue);
|
|
1456
|
+
collDel(valuesNonDefaulted, valueId);
|
|
1457
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1458
|
+
},
|
|
1459
|
+
() => {
|
|
1460
|
+
mapSet(valuesDefaulted, valueId);
|
|
1461
|
+
setAdd(valuesNonDefaulted, valueId);
|
|
1462
|
+
if (valueSchema[REQUIRED] === true) {
|
|
1463
|
+
setAdd(valuesRequiredNonDefaulted, valueId);
|
|
1464
|
+
} else {
|
|
1465
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1466
|
+
}
|
|
1467
|
+
},
|
|
1419
1468
|
);
|
|
1420
1469
|
},
|
|
1421
1470
|
(_valuesSchema, valueId) => {
|
|
1422
1471
|
mapSet(valuesSchemaMap, valueId);
|
|
1423
1472
|
mapSet(valuesDefaulted, valueId);
|
|
1424
1473
|
collDel(valuesNonDefaulted, valueId);
|
|
1474
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1425
1475
|
},
|
|
1426
1476
|
);
|
|
1427
1477
|
const setOrDelTables = (tables) =>
|
|
@@ -43,6 +43,7 @@ const RELATIONSHIP = 'Relationship';
|
|
|
43
43
|
const REMOTE_ROW_ID = 'Remote' + ROW + 'Id';
|
|
44
44
|
const QUERY = 'Query';
|
|
45
45
|
const EXTRA = 'extra';
|
|
46
|
+
const REQUIRED = 'required';
|
|
46
47
|
const UNDEFINED = '\uFFFC';
|
|
47
48
|
const JSON_PREFIX = '\uFFFD';
|
|
48
49
|
const id = (key) => EMPTY_STRING + key;
|
|
@@ -1177,6 +1178,7 @@ const createStore = () => {
|
|
|
1177
1178
|
const valuesSchemaMap = mapNew();
|
|
1178
1179
|
const valuesDefaulted = mapNew();
|
|
1179
1180
|
const valuesNonDefaulted = setNew();
|
|
1181
|
+
const valuesRequiredNonDefaulted = setNew();
|
|
1180
1182
|
const tablePoolFunctions = mapNew();
|
|
1181
1183
|
const tableCellIds = mapNew();
|
|
1182
1184
|
const tablesMap = mapNew();
|
|
@@ -1229,7 +1231,7 @@ const createStore = () => {
|
|
|
1229
1231
|
const validateCellOrValueSchema = (schema) => {
|
|
1230
1232
|
if (
|
|
1231
1233
|
!objValidate(schema, (_child, id2) =>
|
|
1232
|
-
arrayHas([TYPE, DEFAULT, ALLOW_NULL], id2),
|
|
1234
|
+
arrayHas([TYPE, DEFAULT, ALLOW_NULL, REQUIRED], id2),
|
|
1233
1235
|
)
|
|
1234
1236
|
) {
|
|
1235
1237
|
return false;
|
|
@@ -1264,20 +1266,32 @@ const createStore = () => {
|
|
|
1264
1266
|
(row, rowId) => validateRow(tableId, rowId, row),
|
|
1265
1267
|
() => cellInvalid(tableId),
|
|
1266
1268
|
);
|
|
1267
|
-
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
(
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1269
|
+
const validateRow = (tableId, rowId, row, skipDefaults) => {
|
|
1270
|
+
const rowWithDefaults = skipDefaults
|
|
1271
|
+
? row
|
|
1272
|
+
: addDefaultsToRow(row, tableId, rowId);
|
|
1273
|
+
return (
|
|
1274
|
+
objValidate(
|
|
1275
|
+
rowWithDefaults,
|
|
1276
|
+
(cell, cellId) =>
|
|
1277
|
+
ifNotUndefined(
|
|
1278
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
|
1279
|
+
(validCell) => {
|
|
1280
|
+
row[cellId] = validCell;
|
|
1281
|
+
return true;
|
|
1282
|
+
},
|
|
1283
|
+
() => false,
|
|
1284
|
+
),
|
|
1285
|
+
() => cellInvalid(tableId, rowId),
|
|
1286
|
+
) &&
|
|
1287
|
+
(skipDefaults
|
|
1288
|
+
? true
|
|
1289
|
+
: arrayEvery(
|
|
1290
|
+
collValues(mapGet(tablesSchemaRowCache, tableId)?.[2]),
|
|
1291
|
+
(cellId) => objHas(rowWithDefaults, cellId),
|
|
1292
|
+
))
|
|
1280
1293
|
);
|
|
1294
|
+
};
|
|
1281
1295
|
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
|
1282
1296
|
hasTablesSchema
|
|
1283
1297
|
? ifNotUndefined(
|
|
@@ -1303,20 +1317,31 @@ const createStore = () => {
|
|
|
1303
1317
|
: isUndefined(getCellOrValueType(cell))
|
|
1304
1318
|
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1305
1319
|
: encodeIfJson(cell);
|
|
1306
|
-
const validateValues = (values, skipDefaults) =>
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
(
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1320
|
+
const validateValues = (values, skipDefaults) => {
|
|
1321
|
+
const valuesWithDefaults = skipDefaults
|
|
1322
|
+
? values
|
|
1323
|
+
: addDefaultsToValues(values);
|
|
1324
|
+
return (
|
|
1325
|
+
objValidate(
|
|
1326
|
+
valuesWithDefaults,
|
|
1327
|
+
(value, valueId) =>
|
|
1328
|
+
ifNotUndefined(
|
|
1329
|
+
getValidatedValue(valueId, value),
|
|
1330
|
+
(validValue) => {
|
|
1331
|
+
values[valueId] = validValue;
|
|
1332
|
+
return true;
|
|
1333
|
+
},
|
|
1334
|
+
() => false,
|
|
1335
|
+
),
|
|
1336
|
+
() => valueInvalid(),
|
|
1337
|
+
) &&
|
|
1338
|
+
(skipDefaults
|
|
1339
|
+
? true
|
|
1340
|
+
: arrayEvery(collValues(valuesRequiredNonDefaulted), (valueId) =>
|
|
1341
|
+
objHas(valuesWithDefaults, valueId),
|
|
1342
|
+
))
|
|
1319
1343
|
);
|
|
1344
|
+
};
|
|
1320
1345
|
const getValidatedValue = (valueId, value) =>
|
|
1321
1346
|
hasValuesSchema
|
|
1322
1347
|
? ifNotUndefined(
|
|
@@ -1387,6 +1412,7 @@ const createStore = () => {
|
|
|
1387
1412
|
(_tablesSchema, tableId, tableSchema) => {
|
|
1388
1413
|
const rowDefaulted = mapNew();
|
|
1389
1414
|
const rowNonDefaulted = setNew();
|
|
1415
|
+
const rowRequiredNonDefaulted = setNew();
|
|
1390
1416
|
mapMatch(
|
|
1391
1417
|
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
|
1392
1418
|
tableSchema,
|
|
@@ -1394,12 +1420,23 @@ const createStore = () => {
|
|
|
1394
1420
|
mapSet(tableSchemaMap, cellId, cellSchema);
|
|
1395
1421
|
ifNotUndefined(
|
|
1396
1422
|
cellSchema[DEFAULT],
|
|
1397
|
-
(
|
|
1398
|
-
|
|
1423
|
+
(defaultCell) => {
|
|
1424
|
+
mapSet(rowDefaulted, cellId, defaultCell);
|
|
1425
|
+
},
|
|
1426
|
+
() => {
|
|
1427
|
+
setAdd(rowNonDefaulted, cellId);
|
|
1428
|
+
if (cellSchema[REQUIRED] === true) {
|
|
1429
|
+
setAdd(rowRequiredNonDefaulted, cellId);
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1399
1432
|
);
|
|
1400
1433
|
},
|
|
1401
1434
|
);
|
|
1402
|
-
mapSet(tablesSchemaRowCache, tableId, [
|
|
1435
|
+
mapSet(tablesSchemaRowCache, tableId, [
|
|
1436
|
+
rowDefaulted,
|
|
1437
|
+
rowNonDefaulted,
|
|
1438
|
+
rowRequiredNonDefaulted,
|
|
1439
|
+
]);
|
|
1403
1440
|
},
|
|
1404
1441
|
(_tablesSchema, tableId) => {
|
|
1405
1442
|
mapSet(tablesSchemaMap, tableId);
|
|
@@ -1414,14 +1451,27 @@ const createStore = () => {
|
|
|
1414
1451
|
mapSet(valuesSchemaMap, valueId, valueSchema);
|
|
1415
1452
|
ifNotUndefined(
|
|
1416
1453
|
valueSchema[DEFAULT],
|
|
1417
|
-
(
|
|
1418
|
-
|
|
1454
|
+
(defaultValue) => {
|
|
1455
|
+
mapSet(valuesDefaulted, valueId, defaultValue);
|
|
1456
|
+
collDel(valuesNonDefaulted, valueId);
|
|
1457
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1458
|
+
},
|
|
1459
|
+
() => {
|
|
1460
|
+
mapSet(valuesDefaulted, valueId);
|
|
1461
|
+
setAdd(valuesNonDefaulted, valueId);
|
|
1462
|
+
if (valueSchema[REQUIRED] === true) {
|
|
1463
|
+
setAdd(valuesRequiredNonDefaulted, valueId);
|
|
1464
|
+
} else {
|
|
1465
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1466
|
+
}
|
|
1467
|
+
},
|
|
1419
1468
|
);
|
|
1420
1469
|
},
|
|
1421
1470
|
(_valuesSchema, valueId) => {
|
|
1422
1471
|
mapSet(valuesSchemaMap, valueId);
|
|
1423
1472
|
mapSet(valuesDefaulted, valueId);
|
|
1424
1473
|
collDel(valuesNonDefaulted, valueId);
|
|
1474
|
+
collDel(valuesRequiredNonDefaulted, valueId);
|
|
1425
1475
|
},
|
|
1426
1476
|
);
|
|
1427
1477
|
const setOrDelTables = (tables) =>
|
package/with-schemas/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) =>
|