@jhacks currently no, but should be. wrote an issue about it: https://github.com/metosin/malli/issues/254 & will fix that soon.
renaming (& moving) the malli.error/ErrorSchema
as malli.core/Humanized
would make humanized errors more first class and would enable setting those easily when creating custom schemas - either via helpers of by reifying the protocols. Closure DCE will remove those anyway if not used in an app.
could also move the Generator protocol (not impls!) into core. Currently - if one want’s to implement fully custom Schma impl (like regal
does), the lib must include all the support namespaces to access the Protocols. This drags is a lot of code that the end user might not need, making initial load time slower on clj and making the bundle size bigger on cljs.
looks legit.
big thanks to @vincent.cantin for the initial work on the issue! it’s now a full rewrite (protocols & vectors), but took the internal syntax from minimallist. minimallist inspired by malli, inspired by minimallist 😉
quite happy with the internal design. both validation and parsing use the same code, but when validating, the parsing results are not realized. that given example is 40µs
on spec (both validation & parsing), malli is now: 6µs
when parsing and 3µs
on validation. not optimized yet, I think it could be made much faster still.
123 loc 🙂
looks awesome
I was considering making an issue to ask, but trying here first — is there a particular way you’d recommend doing a map on (or otherwise delegating to) existing schemas, @ikitommi? Some examples are: • Validating JS objects with a spec for their keys/values by using some of the implementation of [:map-of …] on a (decently efficient) cljs-bean.core/bean • ^ similarly with JS arrays • Ideally I’d like to pass the underlying explainer’s output through and be able to humanize the aggregate schema, which I’m especially having trouble with. So far I’ve done things like:
(defn transform-spec [transform inner-spec]
(let [explainer (m/explainer inner-spec)]
[:fn {:error/fn (fn [{:keys [value]} _] (explainer value))}
#(m/validate inner-spec (transform %))]))
; and
(defn js-obj [& map-spec]
(let [inner-spec (into [:map] map-spec)
explainer (m/explainer inner-spec)]
[:fn {:error/fn (fn [{:keys [value]}] (explainer value))}
#(->> (bean %) (m/validate inner-spec))]))
… but I’m breaking the explainer output no matter how I slice it.
The best approach for now I imagine is to directly implement the protocol(s) and do a bunch of delegation to the underlying schemas, but wondering if combinators/transformers are possible?@ikitommi Thanks for the very informative response. https://github.com/metosin/malli/issues/254 looks great! Also, sequence/regex schemas! Wohoo!
@ikitommi now, you can finally use Malli itself to validate Malli’s models.
micromallist