Define the resource contract
Model your domain entity with strict TypeScript types and Zod schemas. Separate create, update, and response shapes.
Zod schema defining entity properties, optional fields, and string constraints.
Strict Zod schemas for input validation and output types.
--- a/src/schemas/item.ts |
+++ b/src/schemas/item.ts |
@@ -1,4 +1,16 @@ |
-export interface Item { |
- id: any |
- title: any |
-} |
+import { z } from 'zod' |
+ |
+export const CreateItemSchema = z.object({ |
+ title: z.string().trim().min(3, 'Title must be at least 3 characters'), |
+ category: z.enum(['tool', 'spec', 'guide']), |
+ metadata: z.record(z.string()).optional(), |
+}) |
+ |
+export const ItemSchema = CreateItemSchema.extend({ |
+ id: z.string().uuid(), |
+ createdAt: z.string().datetime(), |
+ updatedAt: z.string().datetime(), |
+}) |
+ |
+export type CreateItemInput = z.infer<typeof CreateItemSchema> |
+export type Item = z.infer<typeof ItemSchema> |
Write your entity schema and export the inferred TypeScript type.
import { z } from "zod"
export const ItemSchema = z.object({ id: z.string().uuid(), title: z.string().min(3) })What is the most likely invalid input a malicious user might send?
No comments yet on this step. Be the first to share an insight!
Explore the Production Architecture in Real-Time
See how this track connects to Abeta's open-source primitives. Test live latency benchmarks, CRDT vector clocks, and hardware-accelerated nodes in the browser sandbox.