malli

https://github.com/metosin/malli :malli:
anonimitoraf 2021-04-21T06:38:12.483600Z

Thanks for the update! Looks good!

Ivan Fedorov 2021-04-21T06:51:35.483900Z

I mean codegen. I want to describe malli schema and then have all the goodies (pull vectors, pathom resolvers, etc) generated. I may end up doing it myself, just asking if you have seen anything like this already.

πŸ’― 2
nilern 2021-04-21T09:32:31.485100Z

Let's not forget https://github.com/kwrooijen/gungnir

2021-04-21T12:00:45.487300Z

I'm just trying malli for the first time today, and it looks pretty great already

2021-04-21T12:01:53.488700Z

one thing I didn't quite understand though, if I annotate a function with (m/=> ... is there a way to actually force that check at runtime to make it fail when the schema doesn't match? I only see that related with generating a clj-kondo config, which is great but I thought that run-time assertions would be also there, even if disabled by default maybe

nilern 2021-04-21T12:06:33.490100Z

https://github.com/metosin/malli/issues/349 but @setzer22 has a working implementation https://github.com/setzer22/malli-instrument

πŸ‘‹ 1
Setzer22 2021-04-21T12:09:10.493500Z

Yes, I've been using my implementation for a couple of weeks now πŸ‘ The base features are working, but sometimes malli has trouble generating human readable descriptions of errors

Setzer22 2021-04-21T12:09:37.494Z

if you give it a try, please report any issues!

2021-04-21T12:14:27.494400Z

ah nice, yeah no rush was just wondering if I missed something from the docs

ikitommi 2021-04-21T12:42:22.496Z

@setzer22 yes, there is an open PR about robust humanized errors. Few combinations that don’t work, but the idea to fix it seems legit.

Setzer22 2021-04-21T12:54:48.497400Z

@ikitommi Good to know!

2021-04-21T13:15:43.499100Z

another thing I noticed is that there isn't a way to just throw an exception if something fails to validate. I ended up with something like

(let [my-map ...
       errors (m/explain schema my-map)]
  (if (nil? errors) my-map (throw (ex-info "validation failed" errors)))
but isnt't there an easier way to do that?

nilern 2021-04-21T13:22:23.499400Z

We should have an assert...

nilern 2021-04-21T13:27:05.499800Z

There wasn't even an issue so I made one https://github.com/metosin/malli/issues/420

πŸ‘ 1
nilern 2021-04-21T13:56:48.001700Z

Hmm hard to make an efficient assert that makes the validator and explainer behind the scenes. Especially Cljs would be tricky.

nilern 2021-04-22T13:08:18.011900Z

Yeah I figured you just forgot. And I did mean the assert macro would create the validator

nilern 2021-04-22T13:10:02.012100Z

It is probably ok to not do that in dev mode although sometimes assertion overhead is too much even then

2021-04-21T15:47:43.002500Z

mm maybe you don't always need the explainer

2021-04-21T15:47:59.002700Z

would be nice I guess but not sure it needs to be the default

nilern 2021-04-21T15:56:28.002900Z

Dropping the explainer does not make it any easier.

yuhan 2021-04-21T17:34:06.003100Z

Thanks for creating the issue! it must have slipped my mind. Do you mean caching a validator at the assert's compile time? I would be worried about the validator then going out of sync when you redefine the schema during dev time

yuhan 2021-04-21T17:38:44.003300Z

Maybe the *assert* dynamic var could have 3 levels: β€’ runtime validate (slowest but correct) β€’ compile-time validator (more efficient, use if schemas are fixed) β€’ compiles to nil