Entity Template¶
This template provides a standard structure for creating new domain entities in the PRS system using Zod for validation.
Usage Instructions¶
- Replace
EntityNamewith your entity name - Define validation schemas
- Export the schemas
Template Code¶
Key Features¶
- Zod Validation: Uses Zod for schema validation
- Strict Mode: Enforces strict validation (no unknown fields)
- Detailed Error Messages: Provides detailed error messages for validation failures
- Type Safety: Ensures type safety for all fields
- Default Values: Provides default values for certain fields
Common Schema Types¶
- createEntityNameSchema: Schema for creating a new entity
- updateEntityNameSchema: Schema for updating an existing entity
- getEntityNameByIdSchema: Schema for getting an entity by ID
- customActionSchema: Schema for custom actions on an entity
Validation Features¶
- String Validation: Length, regex patterns, trimming
- Number Validation: Min/max values, integer validation
- Enum Validation: Restricted set of values
- Boolean Validation: Type checking
- Array Validation: Item validation, length restrictions
- Object Validation: Nested object validation
- Optional Fields: Fields that can be omitted
Best Practices¶
- Use strict mode to prevent unknown fields
- Provide detailed error messages
- Use regex patterns for complex string validation
- Make update schema fields optional
- Use utility functions for common validation patterns