malli

itaied 2024-12-12T16:07:49.176479Z

hey all, new to malli what's the best way to write / express the following:

(def ProductDepotAction [:or
                         [:map
                          [:type [:enum :add]]
                          [:data #'AddProduct]]
                         [:map
                          [:type [:enum :edit]]
                          [:data #'EditProduct]]
                         [:map
                          [:type [:enum :remove]]
                          [:data #'RemoveProduct]]])

(m/validate ProductDepotAction {:type :add
                                :data {:id "1"
                                       :name "cookie"
                                       :price 20.0
                                       :seller-id "2"}})

ikitommi 2024-12-12T16:37:14.336289Z

welcome! try :multi https://github.com/metosin/malli?tab=readme-ov-file#multi-schemas

❤️ 1
🙌 1
itaied 2024-12-12T20:09:14.979919Z

Cool!

itaied 2024-12-12T21:27:54.034579Z

how can i flatten my map and use the previous defined structures (like merge)?

(def AddProduct [:map
                 [:id :string]
                 [:name :string]
                 [:description {:optional true} :string]
                 [:price :double]
                 [:seller-id :string]])

(def ProductDepotAction [:multi {:dispatch :action}
                         [:add [:map
                                [:action :keyword]
                                [:data #'AddProduct]]]])
[:map [:action :keyword] #'AddProduct]

2025-01-13T16:37:28.512059Z

[:merge [:map COMMON] [:multi DIFFERENCES]]

2024-12-12T19:17:39.743029Z

Hi folks, I have some schemas that will cause the error pretty printer to stack overflow. Whats the best way to debug this? Or is there a way to prevent the error pretty printer from throwing this stack overflow.

ikitommi 2024-12-12T19:49:07.873319Z

should not do it. Please share / report bug

2024-12-12T19:53:42.022319Z

Okay, will do. Thanks @ikitommi.

2024-12-13T15:26:50.682199Z

https://github.com/metosin/malli/issues/1149 Error report.