Fork me on GitHub
#malli
<
2022-01-31
>
Brett Rowberry17:01:10

when inferring malli schemas from data, I can tell it how to handle strings as uuids, for example, as shown here https://github.com/metosin/malli/pull/597 some string values may be inst or other types - is there a way to have it handle those as well?

ikitommi18:01:53

sure, anything you can present transformers works here. Check how inst? is handled in malli.transform

Brett Rowberry17:02:12

sorry, I should have given a better example

(require '[malli.provider :as mp])
(require '[malli.transform :as mt])

(mp/provide
 [{:my-uuid "caa71a26-5fe1-11ec-bf63-0242ac130002"
   :my-inst "2021-01-01T00:00:00Z"}]
 {::mp/value-decoders {'string? {:uuid mt/-string->uuid}}})
;; can I treat :my-uuid as a uuid and :my-inst as an inst?

ikitommi18:02:01

with master:

(require '[malli.provider :as mp])
(require '[malli.transform :as mt])

(mp/provide
 [{:my-uuid "caa71a26-5fe1-11ec-bf63-0242ac130002"
   :my-inst "2021-01-01T00:00:00Z"}]
 {::mp/value-decoders {'string? {:uuid mt/-string->uuid
                                 'inst? mt/-string->date}}})
; => [:map [:my-uuid :uuid] [:my-inst inst?]]

Brett Rowberry23:02:39

so this would be after 0.8.0

ikitommi07:02:37

if you use deps, you can depend on the lastest commit on master to try this out. for leiningen - in the next release.

Brett Rowberry14:02:30

we're using some custom bazel thing, so I'll have to wait for the jar. thank you so much for this feature! type providers were so awesome in F# - I really appreciate having something similar in Clojure!

ikitommi13:02:37

[metosin/malli "0.8.1"]

ikitommi13:02:54

and good to hear, it is useful 🙂

ikitommi18:02:01

with master:

(require '[malli.provider :as mp])
(require '[malli.transform :as mt])

(mp/provide
 [{:my-uuid "caa71a26-5fe1-11ec-bf63-0242ac130002"
   :my-inst "2021-01-01T00:00:00Z"}]
 {::mp/value-decoders {'string? {:uuid mt/-string->uuid
                                 'inst? mt/-string->date}}})
; => [:map [:my-uuid :uuid] [:my-inst inst?]]