This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-10
Channels
- # announcements (9)
- # aws (11)
- # babashka (37)
- # beginners (97)
- # biff (2)
- # calva (73)
- # clj-kondo (17)
- # cljfx (3)
- # clojure (89)
- # clojure-europe (45)
- # clojure-norway (12)
- # clojurescript (17)
- # datahike (8)
- # datomic (13)
- # deps-new (4)
- # figwheel-main (1)
- # graalvm (2)
- # hyperfiddle (8)
- # introduce-yourself (6)
- # leiningen (38)
- # lsp (57)
- # malli (13)
- # nbb (46)
- # off-topic (40)
- # pathom (3)
- # polylith (8)
- # rum (4)
- # shadow-cljs (14)
- # spacemacs (1)
- # sql (11)
- # xtdb (10)
getting back to computer this week from the long summer vacation, happy to see there the lively discussions here. if there is something clearly not resolved / answered by someone (🙇 for everyone for helping others!), you can mention me in the thread. will try to read the new new issues & prs this week.
Hi, I need to change all keys in the schema from :keyword to :string. Is there an utility for this?
what do you mean by keys here: map keys in values? or in schemas? something else? example would help
Sure. Here's an example. I would like to achieve that I don't have to define the output-schema manually. In this case it would be enough to replace keyword with string and vice versa. But It would be great if I could somehow use a transformer to transform only schemas.
(require '[malli.core :as m])
(require '[malli.transform :as mt])
(def input-schema [:map [:name :string] [:type :keyword]])
(def output-schema [:map [:name :string] [:type :string]])
(defn encode
{:malli/schema [:=> [:cat input-schema] output-schema]}
[val]
(m/encode input-schema val mt/string-transformer))
would this help: https://github.com/metosin/malli/pull/737
Merged the error-value helpers into master. In case of validation error, you can get just the values in error and/or mask the valid values with something like …
, like expound does. Should be useful in pointing out (small set of) errors in huge values. feedback welcome, ping @mauricio.szabo:
(def Address
[:map {:closed true}
[:id :string]
[:tags [:set :keyword]]
[:numbers [:sequential :int]]
[:address [:map
[:street :string]
[:city :string]
[:zip :int]
[:lonlat [:tuple :double :double]]]]])
(def address
{:id "Lillan"
:EXTRA "KEY"
:tags #{:artesan "coffee" :garden "ground"}
:numbers (list 1 "2" 3 4 "5" 6 7)
:address {:street "Ahlmanintie 29"
:zip 33100
:lonlat [61.4858322, "23.7832851,17"]}})
(-> Address
(m/explain address)
(me/error-value {::me/mask-valid-values '...}))
;{:tags #{"coffee" "ground" ...},
; :numbers (... "2" ... ... "5" ... ...),
; :address {:lonlat [... "23.7832851,17"], :street ..., :zip ...},
; :EXTRA "KEY",
; :id ...}
next thing would be to integrate this into pretty explaning. I think it would be good to mask out valid values by default? and the options being: 1. mask valid values (default) 2. show full values 3. don’t show value at all
the tests also show how to do the same thing for individual errors. e.g. present errors one-by-one - like expound does.
Yes, I think masking valid values by default is good - it seems "prettier" this way, and makes for less noise IMHO
https://github.com/metosin/malli/pull/738, feedback and testing most welcome:
(malli.dev.pretty/explain
[:map
[:id :int]
[:tags [:set :keyword]]
[:address [:map
[:street :string]
[:city :string]
[:zip :int]
[:lonlat [:tuple :double :double]]]]]
{:id "123"
:EXTRA "KEY"
:tags #{:artesan "coffee" :garden}
:address {:street "Ahlmanintie 29"
:city "Tampere"
:zip 33100
:lonlat [61.4858322, 23.7832851]}})
=>Awesome!