Fork me on GitHub
#malli
<
2020-06-11
>
pithyless07:06:58

I'm struggling to wrap my head around custom transformers and validators; is there some way to create a pipeline of validate -> transform -> validate (ala spec/conform ?) Or when defining a transform interceptor, can I in some way tell the the chain to stop executing further since some assumption is invalid?

ikitommi10:06:10

currently no way to stop the chain in interceptors @pithyless, could be added easily with reduced. There are Schemas that short-circuit in -transform like the :or.

ikitommi10:06:03

in reitit-malli, there is a Corcion protocol and impl which does transform + validate for requests and transform + validate + transform for responses.

ikitommi10:06:46

for responses, it’s basically doing: 1. apply defaults, strip extra keys 2. validate the result 3. encode to whatever (string, json, xml)

ikitommi10:06:08

If you have some minimal sample, could take a look.

pithyless11:06:05

^ the reitit Coercer case is the kind of thing I have in mind. I've been going back and forth on this, but malli has been forcing me to rethink my approach: perhaps, I should just assume there is only one canonical form of data inside my project runtime, and only at the boundaries do all the encoding/decoding via custom protocols (i.e. a custom Coercer protocol and implementation for reitit, datomic, etc.)

ikitommi11:06:27

the reitit code is here: https://github.com/metosin/reitit/blob/master/modules/reitit-malli/src/reitit/coercion/malli.cljc. Basically, at route(r) creation time, for each Schema, a reified Coercion is created, storing encoder, decoder, validator and explainer for that schema. At runtime, it’s just a calling those (optimized fns) in whatever order suits for the use case.

👍 3