typst-community/valkyrie

Add back `min` and `max` schema parameters

Closed this issue · 1 comments

Previously the number, integer, float, string, and array schemas had the parameters min and max.

I propose adding these back, those range checks are fairly convenient, especially combined with z.<schema>.with(min: ...) for schema adaption. The main downside of not having them now is that nested schema validation cannot perform easy length checks.

As mentioned on discord, definitely agree. The last version where it existed was here:

min: min,
max: max,
length: length,
descendents-schema: descendents-schema,
assertions: (
(
precondition: "min",
condition: (self, it)=>it.len()>=self.min,
message: (self) => "Array length must be at least " + str(self.min),
),
(
precondition: "max",
condition: (self, it)=>it.len()<=self.max,
message: (self) => "Array length must be at most " + str(self.max),
),
(
precondition: "length",
condition: (self, it)=>it.len()==self.length,
message: (self) => "Array length must be exactly " + str(self.length),
),
..assertions
),

I'll make a branch and see about bringing this sort of way of handling it back