toValuesSchema
The toValuesSchema method converts a mapping of ArkType schemas into a TinyBase ValuesSchema.
toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema| Type | Description | |
|---|---|---|
schemas | {[valueId: string]: any} | A mapping of value IDs to ArkType schemas. |
| returns | ValuesSchema | A TinyBase |
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