malli

https://github.com/metosin/malli :malli:
ikitommi 2020-09-10T15:16:49.178700Z

@jhacks currently no, but should be. wrote an issue about it: https://github.com/metosin/malli/issues/254 & will fix that soon.

ikitommi 2020-09-10T15:19:45.181700Z

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.

ikitommi 2020-09-10T15:22:34.184500Z

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.

ikitommi 2020-09-10T17:50:29.185300Z

looks legit.

ikitommi 2020-09-10T18:00:29.187800Z

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 😉

❤️ 1
😄 1
ikitommi 2020-09-10T18:06:03.190400Z

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.

👏 1
ikitommi 2020-09-10T18:15:57.191200Z

123 loc 🙂

🎉 1
borkdude 2020-09-10T19:14:52.192300Z

looks awesome

2020-09-10T21:39:27.197200Z

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?

jhacks 2020-09-10T22:52:06.197600Z

@ikitommi Thanks for the very informative response. https://github.com/metosin/malli/issues/254 looks great! Also, sequence/regex schemas! Wohoo!

2020-09-10T23:44:33.198700Z

@ikitommi now, you can finally use Malli itself to validate Malli’s models.

👍 1
2020-09-10T23:48:17.199300Z

micromallist