Shared types for MOV backend and mobile
npm install @movapp/typesShared types for MOV backend and mobile applications using Zod for runtime validation and type safety.
```
src/
├── models/
│ └── user/ # User model types
│ ├── types.ts # Database model schemas
│ ├── requests.ts # API request schemas (create, update, etc.)
│ └── responses.ts # API response schemas
└── utils/
└── validation.ts # Validation helper functions
- Runtime Validation: All types are Zod schemas that can validate data at runtime
- Type Safety: TypeScript types are automatically inferred from schemas
- Error Handling: Built-in error messages and validation helpers
- Reusable: Schemas can be used in both backend and mobile
`typescript`
export const UserSchema = z.object({
id: z.string().uuid(),
username: z.string().min(1),
// ... other fields
});
export type User = z.infer
`typescript`
export const CreateUserRequestSchema = z.object({
username: z.string().min(1, "Username is required"),
phone: z.string().optional(),
});
export type CreateUserRequest = z.infer
`typescript`
export const CreateUserResponseSchema = z.object({
success: z.boolean(),
user: UserSchema,
message: z.string().optional(),
});
export type CreateUserResponse = z.infer
`bashInstall dependencies
npm install
#publish a new version of the package
npm publish
``