zoedsoupe/peri

[FEATURE] Type refinements as Keyword

Opened this issue · 4 comments

dvv commented

Description
Right now we can not AFAICS apply several constraints to a type, e.g.:

{:string, {:min, 1}, {:max, 2}}

Would IMO be nice to handle such cases in form of Keyword options:

{:string, min: 1, max: 2}

Motivation
To handle richer validation technique.

Alternatives
None AFAICS

interesting! the example you gave could be easily solved with a new directive for the :string type like it exists for the :integer one. something like {:range, min, max},

do you have any other examples that could be benefit with these keyword (aka multiple) validation directives?

dvv commented

Nope, nothing ATM

i was thinking and there're some constraints that doesn't make semantical sense to be together, and those will cause unexpected results, like:

{:integer, gt: 3, lt: 2}

so probably we want to filter and parse what are valid constraints, and i don't think this should be tackled right now.

do you think in any other simpler solution for this problem?

i'll try to make a simple poc on this