malli

Daniel Ben Itzhak 2025-01-22T11:56:17.381409Z

Hello Is there a way to remove a key from a schema or to create a mask and remove fields by merging the mask with the schema?

✅ 1
opqdonut 2025-01-22T12:02:41.447979Z

malli.util/dissoc

opqdonut 2025-01-22T12:02:56.215909Z

malli.util/select-keys

Daniel Ben Itzhak 2025-01-22T12:04:58.966259Z

Thank you @joel.kaasinen 🙏 malli.util/dissoc seems just what I need

✅ 1
Daniel Ben Itzhak 2025-01-22T14:22:03.633019Z

@joel.kaasinen from what I can see there is no dissoc in or way to remove a key inside a nested map, Would you a recursive function or is there a more idomatic / library supported way of doing it?

2025-01-22T18:44:52.444479Z

try combining the utils like (malli.util/update-in s [...] malli.util/dissoc ...)

🔥 1
Daniel Ben Itzhak 2025-01-23T07:51:11.637949Z

Thx @ambrosebs

👍 1
2025-01-22T17:48:00.806829Z

Hello, Claude told me that I can do something like (! {:exception true}) to throw on bad parameters when instrumenting functions. I tried it, it works. I haven't found documentation for this behavior though. Is that something that is actually supported?

2025-01-22T20:56:40.434599Z

Looking in the source at ! , it says to see malli.core/-instrument for supported options. I don't see an :exception option there. It does call malli.core/-fail by default which throws an exception. Maybe this is working by accident and that :exception key is not used?

2025-01-22T21:52:34.386949Z

Yeah malli.core/-failsthrows, when you use malli.instrument/intrument you get an exception for calling a specced fn with bad args, but when I just did () without the {:exception true} bit I did get error messages but no exception thrown...

2025-01-22T21:59:10.046659Z

Ok. I don't see that :exception option anywhere.

2025-01-22T22:00:02.554759Z

yeah I know, it must work by accident somehow, I search the whole repo on github and found the keyword only once...

2025-01-22T22:00:12.686189Z

and it wasn't relevant...

2025-01-22T22:00:18.656729Z

Looks like with no args, the options default to {:report (pretty/reporter)}

2025-01-22T22:01:39.433249Z

it does

2025-01-22T22:01:47.619139Z

And then in core/-nstrument it uses :report if present otherwise defaults to -fail

2025-01-22T22:02:13.386839Z

([props f options]
   (let [props (-> props
                   (update :scope #(or % #{:input :output :guard}))
                   (update :report #(or % -fail!)))
         s (-> props :schema (schema options))]
     (or (-instrument-f s props f options)
         (-fail! ::instrument-requires-function-schema {:schema s}))))

2025-01-22T22:03:13.385949Z

yeah, the -fail function is suposed to be redifined also, and is supposed to throw right after using that :report fn option, it just didn't throw the exception for me

2025-01-22T20:58:26.329489Z

What would be the best way to customize malli's internal caching of validator and explainer functions to take a ttl? The explainers in particular seem to get huge with large multi schemas.

2025-01-28T12:34:11.941029Z

I didn't get a chance yet. My first thought about the configuration is we might want both a global default to start and later add in the ability to override per schema. I'm not sure where the config would live. Caching is sort of a deployment concern and not part of the schema definition itself so am wondering if there is some way to keep it orthognal.

2025-01-23T12:56:58.815829Z

Thanks! I will experiment a bit.I saw that the Cache protocol assumes an atom but hand't considered using IAtom.

2025-01-23T00:33:46.549669Z

perhaps you could iterate over your registry and add-watch on every reachable -cache

(defn -add-ttl-cache-watcher [s ttl]
  (add-watch (-cache s) ::cache-ttl (fn [_ a o n]
                                      (cond
                                        (and (not (:validator o)) (:validator n))
                                        (future (Thread/sleep ttl)
                                                (swap! a dissoc :validator))

                                        (and (not (:explainer o)) (:explainer n))
                                        (future (Thread/sleep ttl)
                                                (swap! a dissoc :explainer)))))) 

2025-01-23T00:34:33.935909Z

or alter-var-root malli.core/-cache to something similar. I don't think there's a great way atm.

2025-01-23T00:37:15.559769Z

for the latter you can probably override -cache to be a core.cache cache, as long as you wrap it in an IAtom

2025-01-23T00:47:47.920999Z

looks like :ref has another internal cache that probably shouldn't be erased.

👍 1
2025-01-27T16:05:00.877819Z

@millettjon how'd it go? I wonder if we can flesh out the configuration of caches.

ikitommi 2025-02-16T09:13:08.120859Z

configuration in general: I would personally like to change the global (swappable) registry with global (swppable) options => one could easily configure from one place how these things work. .e.g

(malli.core/set-default-options!
 {:registry (malli.core/schemas)
  :malli.sci/options ...
  :malli.core/cache ...})

👍 1
ikitommi 2025-02-16T09:15:25.738259Z

from 2020… https://github.com/metosin/malli/issues/228