toValuesSchema
The toValuesSchema method converts a mapping of TypeBox schemas into a TinyBase ValuesSchema.
toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema| Type | Description | |
|---|---|---|
schemas | {[valueId: string]: any} | A mapping of value IDs to TypeBox schemas. |
| returns | ValuesSchema | A TinyBase |
This method extracts basic type information (string, number, boolean), string enums, default values, nullable flags, and required flags from TypeBox schemas.
Example
This example converts TypeBox schemas to TinyBase ValuesSchema format.
import {Type} from '@sinclair/typebox';
import {createStore} from 'tinybase';
import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
const schematizer = createTypeBoxSchematizer();
const valuesSchema = schematizer.toValuesSchema({
theme: Type.String({default: 'light'}),
count: Type.Number(),
isOpen: Type.Boolean(),
});
const store = createStore().setValuesSchema(valuesSchema);
store.setValues({count: 42, isOpen: true});
console.log(store.getValues());
// -> {theme: 'light', count: 42, isOpen: true}
Since
v7.1.0