Skip to content

v7.1.0

Choose a tag to compare

@jamesgpearce jamesgpearce released this 11 Dec 07:30
· 81 commits to main since this release

This release introduces Schematizers, a new system for converting schemas from popular validation libraries into TinyBase's schema format.

Schematizers provide a bridge between external schema validation libraries (like Zod, TypeBox, and Valibot) and TinyBase's TablesSchema and ValuesSchema formats. Instead of manually writing TinyBase schemas, you can now convert existing schemas at runtime:

import {createStore} from 'tinybase';
import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
import {z} from 'zod';

const schematizer = createZodSchematizer();

const zodSchema = {
  pets: z.object({
    species: z.string(),
    age: z.number(),
    sold: z.boolean().default(false),
  }),
};

const schematizedStore = createStore().setTablesSchema(
  schematizer.toTablesSchema(zodSchema),
);

schematizedStore.setRow('pets', 'fido', {species: 'dog', age: 3});
console.log(schematizedStore.getRow('pets', 'fido'));
// -> {species: 'dog', age: 3, sold: false}

Schematizers perform best-effort conversions, extracting basic type information (string, number, boolean), defaults, and nullable settings from your schemas.

This release includes support for:

For more information, see the Using Schematizers guide.