Plugins
validation
Validate writes with zod, valibot or any Standard Schema.
import { validation } from "better-supabase/plugins/validation";
import { validators } from "./generated.zod.ts";
const betterSupabase = defineSupabase(schema).use(
validation({ schemas: validators }),
);validators is generated by zod(), valibot() or standardSchema() (no
validation library needed) and maps each table to
its insert and update schemas. You can also pass your own, per table:
validation({
schemas: {
customers: { insert: customerForm, update: customerForm.partial() },
},
});- Inserts and upserts use
insert; updates useupdate. - Validation runs on app-cased rows, after the other plugins, 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