-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass the top-level inputs object to the predicate functions as a third argument. #102
base: master
Are you sure you want to change the base?
Conversation
Thanks for the great input @boyko |
@boyko @busypeoples 👋 this looks really great! i havent tested it out in my scenario just yet (busy @ work) but this could be it thanks a bunch 😄 |
Didn't have the time to run this. Will try to check it out today or tomorrow and then merge. |
The 2nd argument of the predicate is the "parent" object. I don't think that "allInputs" as 3rd argument is a good idea in general. I'd go for some kind of "composable validation specs". What I mean: Let's say, that you want to reuse your Example:
Of course you could use something like this with
But this doesn't look nice for deeply nested stuff. And it gets really hard when it comes to arrays:
Now you've got to access I think a much better solution would be if we were able to access Then you could simply write:
And this rule can now be applied to all objects with a Though I'm not sure if passing Another possibility would be something like this:
Maybe there are other solution, too, that are even nicer to use. EDIT: Another solution could be some kind of
|
For maximum flexibility, I really like the But for refs, we need #104 / #106 , I guess. Using The Example (pseudo code):
Now you want to create some rule for
Providing Looking at other validation libs: For example |
Hello and thanks for this great library!
A while ago I needed to validate a structure like this one:
where the car.owner needs to match person.id in order to
pass validation. Maybe I got it totally wrong but my first attempt was:
It failed because the predicate function is only passed the
car
object and not the whole input.This PR changed the validation function so that it passes the top-level input as a third argument to the predicate functions so that the above validation problem can be tackled like this: