Repository
validation
Validate writes with zod, valibot or any Standard Schema.
When gen.generators includes zod(), valibot() or standardSchema() (no
validation library needed), the generated schema validates every write with
the generated insert and update schemas. Nothing to install:
import { defineConfig, zod } from "better-supabase/config";
export default defineConfig({ gen: { generators: [zod()] } });To pass your own schemas, per table, install validation() yourself; it
replaces the one the generated schema installed:
import { validation } from "better-supabase";
import { validators } from "./generated.zod.ts";
const betterSupabase = defineSupabase(schema).use(
validation({
schemas: {
...validators,
customers: { insert: customerForm, update: customerForm.partial() },
},
}),
);- Inserts and upserts use
insert; updates useupdate. - Validation runs on app-cased rows, after the other extensions, and its output is what gets written. Transforms such as trimming apply.
- Failures return a
validationerror (422) with Standard Schema issues. Bulk writes prefix each path with the row index:[1, 'color']. - Nothing is sent when validation fails.
Any validator that implements Standard Schema works: zod, valibot, arktype, effect schema and more.
Last updated on