malli

https://github.com/metosin/malli :malli:
ikitommi 2020-05-28T05:26:26.458Z

@jstuartmilne something like:

(m/accept
  [:map
   [:user map?]
   [:profile map?]
   [:nested [:map [:x [:tuple {:deleteMe true} string? string?]]]]
   [:token [string? {:deleteMe true}]]]
  (fn [schema children _ options]
    (if-not (:deleteMe (m/properties schema))
      (let [children (filterv (if (m/map-entries schema) last identity) children)]
        (m/into-schema (m/name schema) (m/properties schema) children options)))))
; => [:map [:user map?] [:profile map?] [:nested :map]]

ikitommi 2020-05-28T05:27:46.459600Z

e.g. check if the schema has the property, remove if it has. if not, you have to remove the nil childs as it’s currently not valid syntax. There are two child syntaxes: the normal and the (map)entry-one. need to handled differently.

ikitommi 2020-05-28T05:28:20.460300Z

that doesn’t drop the empty nodes, e.g. :map without any keys is valid, same with empty :tuple etc.

ikitommi 2020-05-28T10:09:21.461Z

anyone interested in doing malli.xml? something like:

(def User [:map [:users [:vector [:map [:user string?]]]]])

(m/decode User "<users><user>simo</user></users>" malli.xml/xml-transformer)
; => {:users [{:user "simo"}]}

(m/encode User {:users [{:user "simo"}]} malli.xml/xml-transformer)
; => "<users><user>simo</user></users>"

👍 2
ikitommi 2020-05-28T10:09:32.461100Z

related: https://github.com/metosin/muuntaja/pull/114

sudakatux 2020-05-28T12:06:05.462400Z

Thank u so much.Ive been struggling witth that