prisma-yup-generator icon indicating copy to clipboard operation
prisma-yup-generator copied to clipboard

decorator comments to specify validator

Open Morriz opened this issue 3 years ago • 4 comments

Problem

Hi, Prisma only has simple validation for database fields, but Yup/Joi etc allow have richer validators such as email/regex etc. How much work would it be to put the desired validator+args in decorator comments and apply them in the generator to the ones already picked up?

Suggested solution

Example could be:

/// @PrismaYupGen email.nullable
// or 
/// @PrismaYupGen min(1).max(10)

To keep it simple I removed () from validator without args.

Hope to inspire :)

Morriz avatar May 29 '22 02:05 Morriz

Hello @Morriz and thank you for the suggestion.

It actually seems like a great addition to the library. I'll give it a try soon to see if I could implement it with the current state of the project.

I'll let you know soon :)

omar-dulaimi avatar May 29 '22 06:05 omar-dulaimi

Awesome! By the way, maybe the namespace could be @PrismaValGen to keep it generic, but only if it is possible to express the validators generically of course. It might be a headache to map them to the respective adapters

Morriz avatar May 29 '22 14:05 Morriz

Any updates here? Did you maybe try to create a PoC for this?

Morriz avatar Aug 07 '22 20:08 Morriz

Unfortunately, I hadn't had a chance to, and not sure if I will anytime soon.

So if you feel adventurous, you can work on it. I'll answer any questions you have.

omar-dulaimi avatar Aug 08 '22 01:08 omar-dulaimi