TinyBase logoTinyBase β

toValuesSchema

The toValuesSchema method converts a mapping of Effect Schema schemas into a TinyBase ValuesSchema.

toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema
TypeDescription
schemas{[valueId: string]: any}

A mapping of value IDs to Effect Schema schemas.

returnsValuesSchema

A TinyBase ValuesSchema.

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