TinyBase logoTinyBase β

toValuesSchema

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

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

A mapping of value IDs to Valibot schemas.

returnsValuesSchema

A TinyBase ValuesSchema.

This method extracts basic type information and unions, primitive picklists and literal unions, fallback values, and required flags from Valibot schemas.

Example

This example converts Valibot value schemas.

import {createStore} from 'tinybase';
import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
import {fallback, number, string} from 'valibot';

const schematizer = createValibotSchematizer();

const valuesSchema = schematizer.toValuesSchema({
  theme: fallback(string(), 'light'),
  count: number(),
});

const store = createStore().setValuesSchema(valuesSchema);
store.setValues({count: 1});
console.log(store.getValues());
// -> {theme: 'light', count: 1}

Since

v7.1.0