This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-02
Channels
- # announcements (3)
- # asami (29)
- # babashka (62)
- # beginners (131)
- # biff (7)
- # calva (31)
- # cider (5)
- # clerk (14)
- # clj-kondo (3)
- # cljsrn (12)
- # clojars (18)
- # clojure (72)
- # clojure-austin (17)
- # clojure-dev (6)
- # clojure-europe (31)
- # clojure-indonesia (1)
- # clojure-nl (1)
- # clojure-norway (18)
- # clojure-sweden (11)
- # clojure-uk (6)
- # clr (47)
- # conjure (42)
- # cursive (88)
- # datalevin (2)
- # datomic (25)
- # emacs (42)
- # exercism (1)
- # fulcro (10)
- # funcool (8)
- # gratitude (2)
- # honeysql (16)
- # introduce-yourself (5)
- # jobs-discuss (26)
- # leiningen (5)
- # lsp (31)
- # malli (21)
- # matcher-combinators (14)
- # missionary (2)
- # nbb (1)
- # off-topic (40)
- # pathom (38)
- # portal (2)
- # re-frame (7)
- # reagent (18)
- # reitit (1)
- # releases (5)
- # shadow-cljs (62)
- # sql (12)
- # testing (4)
- # xtdb (37)
Conundrum: how can we make sure a user's pred implementation in custom simple schema is correct? Is it enough that it returns truthy value, or is boolean strictly required? The validator doc string guarantees it returns a function which returns a boolean, but it's pretty easy to violate this. Thoughts?
clearly, the only solution is a self-describing meta-schema for all Malli schemas 😉
thanks to Thomas Heller, I was able to simplify the implementation of clj-kondo support in cljs https://github.com/metosin/malli/pull/833 (this supersedes my prior PR for this) this also updates the general instructions for use with cljs to use preloads which vastly simplifies dev vs release config
Very cool, thanks for working on this! I'm not currently doing much CLJS work, but I remember there were some rough edges in getting the dev experience right.
for sure! I've definitely learned a ton about shadow-cljs and the cljs compiler in general working on this. I think the big improvement since the early implementation is instrumenting at runtime (also a T Heller suggestion :) ) that happened with this PR https://github.com/metosin/malli/pull/755 it's more deterministic as you're not having to think about what is a macro and what is not
Hi guys, the error/fn
key takes a function with 2 arities, what is the second argument for?
options, https://github.com/metosin/malli/blob/master/src/malli/error.cljc#L136-L139
Hi, how can I make a schema which encodes a boolean to a string and vice versa? I tried:
(def int-boolean-schema
(m/-simple-schema
(fn [_ _]
{:type :int-boolean
:type-properties {:decode/string
(fn [s]
(when-not (clojure.string/blank? s)
(get {"0" false "1" true} s)))
:encode/string
(fn [v]
(prn "val" v)
(if (true? v)
"1"
"0"))}})))
Decoding and encoding true
works as expected, but encoding false
returns nil
without entering the :encode/string
functions.
;; correct:
(m/decode [:int-boolean] "0" mt/string-transformer)
=> false
;; correct:
(m/decode [:int-boolean] "1" mt/string-transformer)
=> true
;; correct:
(m/encode [:int-boolean] true mt/string-transformer)
=> "1"
;; wrong, it should be "0":
(m/decode [:int-boolean] false mt/string-transformer)
=> nil
Shouldn't this work?
(m/schema [:map {:registry {:my/int [:int {:doc "My int, it's very special"}]}}
[:key [:my/int {:foo "bar"}]]])
throws invalid schema exception
:malli.core/invalid-schema
{:type :malli.core/invalid-schema,
:message :malli.core/invalid-schema,
:data {:schema [:int {:doc "My int, it's very special"}]}}
If I remove the properties from either the registry or the map type it's fine. Maybe properties should be merged?I think I ran into something similar before (I didn't figure out why it fails yet):
(m/schema [:comment {:some :prop}]
{:registry (merge (m/default-schemas) {:comment :int})})
=> [:int {:some :prop}]
does not work:
(m/schema [:comment {:some :prop}]
{:registry (merge (m/default-schemas) {:comment [:map [:a :int]]})})
Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:138).
:malli.core/invalid-schema {:schema [:map [:a :int]]}
I suspect stepping through malli.core/schema with these inputs will shed some light on this. I'll take a look when time permits.
I ran into this again and looked into what's going on. have a fix here: https://github.com/metosin/malli/pull/848
Nice!
so it isn't supported to use the vector form in the registry. Will need to change strategies in our apps to handle this desired behavior