Fork me on GitHub
#malli
<
2023-12-13
>
Sam11:12:39

How do you express how schemas evolve? For example, I validate the input to guarantee-language with this schema:

;;input to guarantee-language
[:map 
  [:language {optional true} :string]
  [...]]
For the output schema, I would like to say it's the input schema of guarantee-lang but [:language {optional true} :string] is replaced with [:language :string] . Since it's just vector I could do this myself in a presumably ugly way, but I wanted to know if there's a standard way to do it.

bortexz12:12:43

You can use malli.util/required-keys (mu/required-keys guarantee-language [:language])

Sam12:12:38

Great, I see that malli.util has some other neat functionality for that too. Thank you!

eval202013:12:15

I wrote malli-select (linked in Malli’s README) to allow for selection of required map-attributes. It handles maybe’s/collections etc. supports pruning (of optionals) and raises when you try to select an unknown path.

💪 2
Sam13:12:54

Thanks! This is quite the rabbit hole.

escherize22:12:13

@U04V6FEES I tried out the deps-try thing (pretty cool), and use malli a lot. are you getting much use out of malli-select in practice?

eval202010:12:33

@U051GFP2V thanks. Yeah, for a pet-project I have a video-entity that starts out as just a youtube-id and gets extended in several steps (title, duration, playable?, seconds played, completed? etc.). Having one schema that shows the total picture of a video and then being able to quickly create subset-schemas for processes that do small updates is very helpful. Also generating test-data is a breeze this way, especially with a little glue-code that injects the :gen/* properties: https://twitter.com/DontBeEval/status/1703024976947744980

nice 1