-
Notifications
You must be signed in to change notification settings - Fork 238
Description
Currently, class-transformer and class-validator are being used for transforming between classes and JSON and validation respectively. Both of these packages are maintained by the same party as a side project related issue. class-transformer has not seen an update within the last 2 years and class-validator has not seen an update within the last 6 months. Now, this does not mean that these packages are full of bugs, but the combination makes it a less than desirable dependency to have in AFJ. These packages are also used, not a 100% sure if it is required, by the custom modules that will be created for the core repository and by consumers. A combination of these factors, and the fact that once before a deadline they pushed a breaking change to a patch version..., makes me want to reconsider the validation / transformation libraries we use.
My initial proposal is to use zod. From the description, Zod is a "TypeScript-first schema validation with static type inference". Zod allows us to validate incoming JSON objects in a very intuitive and descriptive manner and it also allows us to transform these JSON instances into classes. The pattern for this is different from class-transformer and class-validator though. We need to create a schema which would contain the validation for the object. These schemes would then be, for us, tightly coupled to a class. Making this coupling might require some design work but I think it can be a way better experience for the creators of custom modules and for us as maintainers / consumers.
If there are other validation / transformation libraries it would definitely be good to list them here and consider those as well.
If I have some time in the near future I will try to create a validation and transformation abstraction and use it inside a module.