malli

Ryan 2025-03-24T14:19:15.741089Z

Is there a good way to get invalid-schema error explanations in CLJS land? I looked at the dev mode stuff but hit a bit of a dead end trying to get it to run in a shadow-cljs-supplied JS repl.

opqdonut 2025-03-24T14:28:26.864099Z

you should be able to call malli.error/humanize in cljs

opqdonut 2025-03-24T14:28:38.057179Z

the implementation is CLJC, as is most of malli

👍 1
opqdonut 2025-03-24T14:30:03.647399Z

there's also http://malli.dev.cljs, but I haven't used it

Ryan 2025-03-24T15:01:38.666729Z

Thanks! Ill try it

Ryan 2025-03-24T15:32:04.973439Z

Another probably stupidly simple question: doing a schema for a regular US postal address and want to assert there can be no :address3 if there is no :address2 on the root of the map. Any clues? do I just wrap the three scenarios in an :or?

valtteri 2025-03-24T19:04:47.428709Z

:or and :fn are likely the alternatives. I'd probably use :or

valtteri 2025-03-24T19:08:37.435489Z

So either

[:or
   [:map {:closed true}
    [:address1 :string]
    [:address2 :string]
    [:address3 :string]]
   [:map {:closed true}
    [:address1 :string]
    [:address2 :string]]
   [:map {:closed true}
    [:address1 :string]]]
[:and
   [:map
    [:address1 :string]
    [:address2 :string]
    [:address3 :string]]
   [:fn (fn [{:keys [address1 address2 address3]}]
        ;; your logic here
          )]]

🙏 1
2025-03-24T19:39:23.966669Z

^^^ is the solution today. You might be interested in watching this PR, which I'm hoping to wrap up soon https://github.com/metosin/malli/pull/1161 Will be:

[:and
 [:map
  [:address1 :string]
  [:address2 {:optional true} :string]
  [:address3 {:optional true} :string]]
 [:implies [:has :address3] [:has :address2]]]

👏 2
Ryan 2025-03-24T20:49:35.779949Z

@ambrosebs golly, every time I have a malli issue you either think of a great way to solve it, or already have thought of it! Thanks!

❤️ 1
Ryan 2025-03-24T20:50:37.382409Z

@valtteri aha, you know that concrete example of using a fn to do it just turned on many lightbulbs here!

👍 1