Closed hikinine closed 1 month ago
On my domain layer I usually adapt controller inputs into aggregate/entities/value object/etc
I do have a schema that ensure every entity props to match the desired type. Lets say
const schema = { isActive: z.boolean(), auth: z.instanceOf(Authentication), profile: instanceOf(Profile), email: z.string() } export interface UserProps { isActive: boolean auth: Authentication profile: Profile email: string //... } export class User extends Entity<User> { static schema = schema } const user = new User({ isActive: true, profile: new Profile({...}), email: 'whatever@gmail.com', ... })
When I do construct an entity object, it auto runs an type validation based on schema checking if props match schema.
How hard is to just pass an interface and validation be done? Without an schema, pure interface.
If an primitive was provided, check if matchs If an class was provided, check by instanceof
Thanks in advance
You can use below typia functions:
typia
typia.is<T>() function auto-casts to the T type when valid. typia.assertGuard<T>() function auto-casts when no type error.
typia.is<T>()
T
typia.assertGuard<T>()
Related documents:
On my domain layer I usually adapt controller inputs into aggregate/entities/value object/etc
I do have a schema that ensure every entity props to match the desired type. Lets say
When I do construct an entity object, it auto runs an type validation based on schema checking if props match schema.
Question
How hard is to just pass an interface and validation be done? Without an schema, pure interface.
If an primitive was provided, check if matchs If an class was provided, check by instanceof
Thanks in advance