Fork me on GitHub
#malli
<
2021-09-19
>
WonderLastking14:09:55

Hi there, i'm using malli 0.6.1 to do some validation in a front-end (cljs)/back-end(clj) application. So I have a .cljc namespace where I do the validations. While this works right with clj, when I use it in cljs I see a warning message

Wrong number of args (3) passed to malli.core/-fail!

ikitommi16:09:25

fixed in master

👍 2
ikitommi16:09:53

closed the performance Issue (https://github.com/metosin/malli/issues/513) - schema creation & transformation is now mostly an order of magnitude faster:

(def schema
  [:map
   [:x boolean?]
   [:y {:optional true} int?]
   [:z [:map
        [:x boolean?]
        [:y {:optional true} int?]]]])

(def schema (m/schema ?schema))

;; 44µs -> 3.4µs (13x)
(bench (m/schema ?schema))

;; 4.2µs -> 830ns (4.5x)
(bench (mu/assoc schema :w :string))

;; 134µs -> 15µs (9x)
(bench (mu/merge schema schema))

;; 51µs -> 3.9µs (13x)
(bench (mu/closed-schema schema))

😲 2
ikitommi16:09:36

… and opened a new one, to add first-class support for the (compact) map-syntax: https://github.com/metosin/malli/issues/543. This is really important in for building large schema systems a) via inferring or b) to be run on slow js-runtimes. Initial design (which is already 15x faster 🚀)

(def ?schema
  [:map
   [:x boolean?]
   [:y {:optional true} int?]
   [:z [:map
        [:x boolean?]
        [:y {:optional true} int?]]]])

(m/form ?schema)
;[:map
; [:x boolean?]
; [:y {:optional true} int?]
; [:z [:map
;      [:x boolean?]
;      [:y {:optional true} int?]]]]

(m/ast ?schema)
;{:type :map,
; :keys {:x {:order 0
;            :value {:type boolean?}},
;        :y {:order 1, :value {:type int?}
;            :properties {:optional true}},
;        :z {:order 2,
;            :value {:type :map,
;                    :keys {:x {:order 0
;                               :value {:type boolean?}},
;                           :y {:order 1
;                               :value {:type int?}
;                               :properties {:optional true}}}}}}}

(-> ?schema
    (m/schema) ;; 3.7µs
    (m/ast) ;; 1.1µs
    (m/schema) ;; 250ns (15x)
    (m/form)
    (= (m/form ?schema)))
; => true

🎉 10
ikitommi16:09:02

it’s still fully generic, like the mu/to-map-syntax & mu/from-map-syntax , but using a new support protocol, schemas can do whatever they want. The new ast can be used as “I know what I’m doing” kinda way => no parsing & checks needed.