Required Schema Fields
Schemas can now mark a Cell or Value as required without providing a default value (#173). Full writes now reject Rows or Values that omit a required non-default field, while preserving the existing rule that a default also implies 'requiredness' (and will be filled automatically if omitted).
import {createStore} from 'tinybase';
const requiredSchemaStore = createStore().setTablesSchema({
pets: {
species: {type: 'string', required: true},
sold: {type: 'boolean', default: false},
},
});
requiredSchemaStore.setRow('pets', 'fido', {species: 'dog'});
console.log(requiredSchemaStore.getRow('pets', 'fido'));
// -> {species: 'dog', sold: false}
requiredSchemaStore.setRow('pets', 'felix', {});
console.log(requiredSchemaStore.hasRow('pets', 'felix'));
// -> false
console.log(requiredSchemaStore.getRow('pets', 'felix'));
// -> {}Custom Sorting
This release adds custom sorting for sorted Row Id APIs, so applications can opt into numeric or domain-specific ordering without changing TinyBase's existing alphanumeric default behavior.
The getSortedRowIds method and addSortedRowIdsListener method now support a custom sorter function in the SortedRowIdsArgs object. The useSortedRowIds hook and getSortedRowIds Svelte function also accept the sorter positionally (#190, #213).
const numericSortStore = createStore();
['1', '10', '2'].forEach((rowId) =>
numericSortStore.setRow('pets', rowId, {sold: false}),
);
const numericRowIdSorter = (sortKey1, sortKey2) =>
Number(sortKey1) - Number(sortKey2);
console.log(
numericSortStore.getSortedRowIds({
tableId: 'pets',
sorter: numericRowIdSorter,
}),
);
// -> ['1', '2', '10']Breaking change: In the ui-solid and ui-svelte modules, the positional Store argument for useSortedRowIds and getSortedRowIds respectively has moved one slot later to make room for a positional custom sorter. If you pass a Store as the final positional argument, add undefined before it, or switch to the object argument form.
Index Presence Helpers
The Indexes interface already exposes the hasIndex method and hasSlice method. This release also adds reactive helpers for UI integrations: useHasIndex and useHasSlice for React and Solid, and hasIndex and hasSlice for Svelte (#163). The Indexes interface also now exposes a addHasIndexListener method and addHasSliceListener method.