Specification Language
Field Validation & Invariants
Aegil implements dual-sided validation by compiling declarative field constraints into both client-side UI guards and server-side transaction boundaries. This ensures instant UI feedback on mobile and web while maintaining uncompromised database integrity against out-of-bounds inputs.
Defining validation rules
Section titled “Defining validation rules”namespace Store;
@entity({ table: "products" })model Product { @pk id: uuid;
@validate({ minLength: 3, maxLength: 80 }) name: string;
@validate({ minLength: 10, maxLength: 1000 }) description: string;
@validate({ min: 1, max: 100000 }) priceInCents: int;
@validate({ min: 0, max: 999 }) stockQuantity: int = 0;
@validate({ pattern: "^[A-Z]{3}-[0-9]{4}$" }) sku: string;
createdAt: utcDateTime;}Supported validation parameters
Section titled “Supported validation parameters”| Parameter | Applies to | Meaning | Example |
|---|---|---|---|
minLength |
string |
Minimum number of characters (inclusive). | @validate({ minLength: 3 }) |
maxLength |
string |
Maximum number of characters (inclusive). | @validate({ maxLength: 100 }) |
min |
int, float |
Minimum numeric value (inclusive). | @validate({ min: 1 }) |
max |
int, float |
Maximum numeric value (inclusive). | @validate({ max: 500 }) |
pattern |
string |
Regular expression the string must match. | @validate({ pattern: "^[a-z0-9_-]+$" }) |
Dual-sided enforcement
Section titled “Dual-sided enforcement”Aegil enforces validation at two independent layers:
- Client-side guard: The generated Flutter BLoC validates arguments before dispatching network requests. If validation fails, an error is surfaced immediately in the UI without a network round-trip.
- Server-side guard: The Serverpod endpoint validates inputs in the transaction pipeline. Even if a caller bypasses the client app and calls the API directly, invalid data is rejected before touching the database.
Automatic boundary testing in aegil verify
Section titled “Automatic boundary testing in aegil verify”When you run aegil verify, the dynamic invariant harness automatically generates and executes test cases for every boundary:
- Lower boundary: Tests
min(must succeed) andmin - 1(must fail). - Upper boundary: Tests
max(must succeed) andmax + 1(must fail). - String length: Tests strings of exact lengths
minLength,maxLength,minLength - 1, andmaxLength + 1.
You never have to write repetitive boundary unit tests by hand; Aegil generates and verifies them deterministically.
What could go wrong?
Section titled “What could go wrong?”| What you see | Why | What to do |
|---|---|---|
ERR_VALIDATION_SYNTAX |
A @validate decorator has invalid bounds (e.g. min > max or minLength < 0). |
Fix the bounds in the @validate decorator. |
| Invariant test failure | A hook or custom logic produced a value outside the declared @validate bounds. |
Update the hook logic to respect the bounds, or adjust the spec if requirements changed. |
Next steps
Section titled “Next steps”- Learn Row-Level Security & Policies.
- Learn State Machines & Workflows.
- Learn 5-Stage Verification Harness.