v9.5
Schema Enums
CellSchema and ValueSchema can now use an enum property instead of type to allow only specific primitive values (as requested in issue #38). Enums must be non-empty, can mix strings, finite numbers, and booleans, and continue to use allowNull when null is also valid.
import {createStore} from 'tinybase';
const enumStore = createStore().setValuesSchema({
status: {enum: ['available', 'adopted'], default: 'available'},
rating: {enum: ['good', 5, true], allowNull: true},
});
enumStore.setValues({status: 'adopted', rating: true});
enumStore.setValue('status', 'missing');
console.log(enumStore.getValues());
// -> {status: 'available', rating: true}Each schema entry must use exactly one of type or enum. Defaults are used only when they are enum members, or are null when null is allowed. The schema-aware Store APIs infer exact unions from enum members, and the Zod, Valibot, ArkType, Effect Schema, TypeBox, and Yup schematizers now preserve supported primitive enum and literal constraints in the schemas they produce.
Schema Type Unions
CellSchema and ValueSchema can now accept a non-empty array in the type property to list one or more allowed broad types (as requested in issue #223):
const unionStore = createStore().setValuesSchema({
reference: {type: ['string', 'number'], default: 'unknown'},
response: {type: ['boolean', 'object'], allowNull: true},
});
unionStore.setValues({reference: 42, response: {accepted: true}});
unionStore.setValue('reference', false);
console.log(unionStore.getValues());
// -> {reference: 'unknown', response: {accepted: true}}A type array can contain string, number, boolean, object, and array. Multiple type names form a union, and repeated names have no additional effect. null continues to be represented by allowNull: true, and defaults are used only when they match one of the listed types. Each schema entry still uses exactly one of type or enum: a type array allows every value of its listed types, while an enum allows only its listed values.
The schema-aware Store APIs infer the corresponding TypeScript unions. The ArkType, Effect Schema, TypeBox, Valibot, and Zod schematizers also preserve supported broad type unions, while continuing to preserve literal-only unions as exact enums.
Schema-Aware Type Fixes
This release also corrects a number of declarations on the /with-schemas type surface. These are type-level fixes only, and require no changes to your runtime code:
- The six schematizer factory functions were previously exported from their
/with-schemasentry points as types rather than as values, so they could not actually be called from those entry points. They are now exported correctly, both individually and from the tinybase/schematizers/with-schemas module: the createArkTypeSchematizer function, createEffectSchematizer function, createTypeBoxSchematizer function, createValibotSchematizer function, createYupSchematizer function, and createZodSchematizer function. - The
extraCellsBeforeandextraCellsAfterprops were missing from the schema-aware declarations of the DOM table components, and are now available in the React, Solid, and Svelte packages. - ResultCell was declared as
string | number | boolean | null, and so did not admit the object and array Cells introduced in v8.0. It is now simply Cell, and the Aggregate, AggregateAdd, AggregateRemove, AggregateReplace, and Having types have been aligned to match. - The
requestIdparameter of the Send and Receive types is now correctly IdOrNull rather than Id, matching what synchronizer implementations are actually passed.