validate
validate copied to clipboard
Is it possible to write async custom validators?
First of all, thanks for making validate
available 😄
I could not determine from the readme whether it is possible to write async custom validators (a validator which relies on looking up a database record, for example). Is that possible?
No, not currently. For my use case it didn't make much sense because of concurrency issues etc. Do you have a specific use case in mind?
It is fairly common in web apps I build to include database queries as a part of some validation rules.
Additionally, separate from async validation, object-level validation (validating a few fields together) is a common requirement.
Yeah, I do the same thing, but I like to delegate that stuff to the db layer to avoid race conditions.
You can validate fields together (sort of) by doing something like this:
const something = (val, ctx) => val > ctx.some.other.path;
schema.path('some.path').use({ something })