Open eoliphan opened 2 years ago
The thing that makes spec integrate so well is the fact that specs and o'doyle attributes are both qualified keywords, so i can associate them together without any extra code. Not sure how to do this using libraries like malli since it doesn't use qualified keywords in this way.
You could define spec functions that use malli inside them though. For example...
;; normal spec
(s/def ::x number?)
(s/def ::y number?)
(s/def ::position (s/keys :req-un [::x ::y]))
;; spec using malli to validate
(def Position [:map [:x number?] [:y number?]])
(s/def ::position #(m/validate Position %))
But in this case the spec error would just say that the ::position
spec failed but wouldn't give details about why it failed, so maybe not that useful.
So, one thing about Malli (despite the fact that most of the examples are more like Schema) is that the registry approach is well, pluggable lol. We actually chose to use it in a more, spec'ish fashion, since we liked spec's registry approach but wanted something a bit more programmable (come on Spec2!). We've a facade namespace coupled with a mutable registry. So we already do stuff like (ourspec/register! ::x number?)
and so on. You can also basically bundle up a bunch of schemas (Position, RayGun, etc) and pass those around as well. But to your point, generalized support (w/o shimming through spec) would be more complex. You'd need to be able to pass in a registry, etc. Will do some poking around in the code.
SN. This is great stuff. After using Drools and Jess (so having to LISP anyway) in the Java world, then Clara which is awesome, but feels 'objecty' at times, O'Doyle really hits the spot. We're full-stack clojure, Fulcro, Pathom, Datomic, etc so this just slots right in.
That is great to hear :D As for your custom registry, in that case you should be able to hook it in by overwriting the spec for odoyle.rules/insert
. Right now it's using a custom conformer which gets the spec for the given attribute and tries to validate it. I think you could write your own conformer that pretty much does the same thing, except reads from your own registry and validates / throws errors via malli.
Ok cool. I'll check that out
I also want to use mall, I was planning on using their custom :properties
to add a fully qualified keyword and pull those out.
Would be nice to be able to use say malli instead of spec