TinyBase logoTinyBase β

toValuesSchema

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

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

A mapping of value IDs to Zod schemas.

returnsValuesSchema

A TinyBase ValuesSchema.

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