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), default values, and nullable 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.setValue('count', 42);
console.log(store.getValues());
// -> {theme: 'light', count: 42}
Since
v7.1.0