toValuesSchema
The toValuesSchema method converts a mapping of Effect Schema schemas into a TinyBase ValuesSchema.
toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema| Type | Description | |
|---|---|---|
schemas | {[valueId: string]: any} | A mapping of value IDs to Effect Schema schemas. |
| returns | ValuesSchema | A TinyBase |
This method extracts basic type information (string, number, boolean), nullable flags, and optional flags from Effect schemas. Default values are not supported as they exist in Effect's runtime transformations, not in the schema AST.
Example
This example converts Effect Schema schemas to TinyBase values.
import {Boolean, Number} from 'effect/Schema';
import {createStore} from 'tinybase';
import {createEffectSchematizer} from 'tinybase/schematizers/schematizer-effect';
const schematizer = createEffectSchematizer();
const valuesSchema = schematizer.toValuesSchema({
open: Boolean,
employees: Number,
});
const store = createStore().setValuesSchema(valuesSchema);
store.setValues({open: true, employees: 3});
console.log(store.getValues());
// -> {open: true, employees: 3}
Since
v7.1.0