TinyBase logoTinyBase β

toValuesSchema

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

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

A mapping of value IDs to ArkType schemas.

returnsValuesSchema

A TinyBase ValuesSchema.

This method extracts basic type information and default values from ArkType schemas.

Example

This example converts ArkType value schemas.

import {type} from 'arktype';
import {createStore} from 'tinybase';
import {createArkTypeSchematizer} from 'tinybase/schematizers/schematizer-arktype';

const schematizer = createArkTypeSchematizer();

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

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

Since

v7.1.0