toValuesSchema
The toValuesSchema method converts a mapping of Zod schemas into a TinyBase ValuesSchema.
toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema| Type | Description | |
|---|---|---|
schemas | {[valueId: string]: any} | A mapping of value IDs to Zod schemas. |
| returns | ValuesSchema | A TinyBase |
This method extracts basic type information and default values from Zod schemas.
Example
This example converts Zod value schemas.
import {createStore} from 'tinybase';
import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
import {z} from 'zod';
const schematizer = createZodSchematizer();
const valuesSchema = schematizer.toValuesSchema({
theme: z.string().default('light'),
count: z.number(),
});
const store = createStore().setValuesSchema(valuesSchema);
console.log(store.getValues());
// -> {theme: 'light'}
Since
v7.1.0