Fork me on GitHub
#malli
<
2023-01-23
>
mkvlr09:01:38

hey 👋 thanks a lot for malli, it’s very useful. We’re looking at unsing function inline schemas in our codebase and wondering about a few things: 1. what should I expect from the clj-kondo integration? Should I expect and error given the following spec & call

(mx/defn transact! [{:as system :keys [datomic]} :- [:map [:datomic some?]] tx-data :- sequential?]
  ,,,)
(transact! {} [])
2. is there a way to assert only the presense of certain keys in a map, without the some? above? Can I maybe even https://cljdoc.org/d/metosin/malli/0.10.1/doc/readme?q=keys#destructuring? 3. when do I need to call mi/instrument!? It seems I need to call it again after I change a defn with inline function schemas, is that right?

borkdude09:01:48

@U5H74UNSF 1. Try running ()

👍 2
mkvlr09:01:33

@U04V15CAJ that’s for the clj-kondo integration?

borkdude09:01:35

also for automatic instrumentation

mkvlr09:01:44

see the docstring now but not seeing an effect yet

borkdude10:01:26

you need to make a few edits before it has an effect, to re-trigger clojure-lsp / clj-kondo

mkvlr10:01:27

or I see an output on the REPL buffer now

borkdude10:01:44

I'll try locally

mkvlr10:01:24

but calling the function with invalid args doesn’t error, only after I call (mi/instrument!) again

👍 2
borkdude10:01:57

works here:

mkvlr10:01:13

very cool

borkdude10:01:40

I only have to re-evaluate the defn and then make 1 additional edit to re-trigger linting

ikitommi14:01:54

re-evaluating the mx/defn should automatically re-create clj-kondo configs when dev/start! is running.

escherize16:01:05

@U5H74UNSF — Do you mean that calling a function with mx/defn with the wrong args doesn’t immediately fail?

escherize16:01:12

I had that problem, and fixed it by having the instrumentation call baked into the macro: https://github.com/metabase/metabase/blob/master/src/metabase/util/malli.clj#L53-L78

escherize16:01:01

then it behaves like s/defn. I think there was talk of including somethng like this (mx/defn ^:always-check …) but I havn’t kept up with it.

escherize16:01:45

IF we are talking about adding options to mx/defn, tho. My wish list would have: 1. “always check args and return value.” 2. It’d be cool to have a way to say “just make the shell of a function, which takes the args, checks them against the schema, and returns a generated value from the schema.” I know it’s mechanically not difficult, just needs to be hooked up. Maybe I should make an issue.

ikitommi16:01:40

Issue welcome, agree that both would be good additions.

🆗 2
escherize17:01:36

I broke it into 2, since I’ve written #1 already. Had some open questions though. 1) https://github.com/metosin/malli/issues/823 2) https://github.com/metosin/malli/issues/824

dvingo17:01:42

Put together a PR for 1) here https://github.com/metosin/malli/pull/702/files#diff-08fdf5164d5d2562ba6f3e187911a9db8086c3d06a3d048cd8045818b2d960e5R94 main motivation at that point was for better cljs DX, which isn't needed anymore, but having a form that is always instrumented is definitely useful

geraldodev14:01:30

Is it possible to compare schemas ?

ikitommi14:01:07

did you check malli.util/equals?

ikitommi14:01:51

undocumented, not super performant, just checks the forms are equals…

geraldodev14:01:04

No, I've looked into documentation trying to find something like equals. Thank you.

geraldodev14:01:09

Shouldn't (mu/equals [:map [:foo [:maybe :string]] [:bar :some]] [:map [:bar :some] [:foo [:maybe :string]]]) be considered equal ?

ikitommi14:01:34

if ordering matters, they are not equal. But I see the value in having a utility for deep-equals, ignoring order.

ikitommi14:01:18

but, no such too at the moment.

geraldodev14:01:38

I was manually running mp/provide to infer the type to inject on reitit to get on the other side with some swagger generator to typescript, so a not positional equals would help.