Validation
Field validation rules for Quickback definitions. Enforce data integrity with built-in validators.
Coming Soon
Field-level validation in defineTable() is a planned feature and is not yet available in the current compiler. Today, validation is available via Zod schemas in action definitions using the input field.
Current Validation: Action Input Schemas
You can validate input data in custom actions using Zod schemas:
// features/invoices/actions.ts
import { defineActions } from '@quickback/compiler';
import { z } from 'zod';
export default defineActions(invoices, {
approve: {
description: "Approve invoice for payment",
input: z.object({
notes: z.string().min(1).max(500).optional(),
amount: z.number().positive(),
}),
access: { roles: ["admin", "finance"] },
execute: async ({ db, record, ctx, input }) => {
// input is validated against the Zod schema before execution
return record;
},
},
});Planned: defineTable Validation
In a future release, defineTable() will support field-level validation rules enforced at the API level when creating or updating records.
Planned Validators
| Validator | Description | Example |
|---|---|---|
minLength | Minimum string length | minLength: 3 |
maxLength | Maximum string length | maxLength: 255 |
min | Minimum number value | min: 0 |
max | Maximum number value | max: 100 |
pattern | Regex pattern match | pattern: '^[a-z]+$' |
enum | Allowed values list | enum: ['draft', 'published'] |
Planned Usage
// NOT YET AVAILABLE — planned syntax
export default defineTable(posts, {
firewall: { organization: {} },
guards: {
createable: ["title", "content", "status"],
updatable: ["title", "content", "status"],
},
validation: {
title: { minLength: 1, maxLength: 255 },
status: { enum: ["draft", "published", "archived"] },
},
crud: {
list: { access: { roles: ["member"] } },
create: { access: { roles: ["member"] } },
update: { access: { roles: ["member"] } },
},
});