Fork me on GitHub

Hi, is there some tool like but generates datomic schema from malli instead of spec ?

Ben Sless05:06:41

I tried writing one once, I guess you could port some ideas from here and write a transformer like there is for json schema


Are you saying porting ideas from the above repo?


I don’t think Malli’s transformers can do 1-to-n replacements (eg. single value to map), although I haven’t tested the behavior for such case. That said, I don’t think it should be that hard to create equivalent behavior with some helper functions and whatnot, plus one area of malli I haven’t explored is the raw walk api, which may work just fine for this 🙂


Should work. E.g.: [:map {:decode/string (fn [s] (if (string? s) (js/JSON.parse s) s))} [:foo :keyword]] Decode function for the map schema is run before checking map properties, and decoding those. At least I've used this in cases where API takes comma separated string, and it is decoded to seq/vec and then items are coerced to keywords or such. Not sure if this answers the original question, but 1-to-n transfomer tranformations should work.

👍 1

(decoding is one use/type of transformer)


Okay, that’s great. Tangentially, I just did a Thing™ which I didn’t mean to but can be abused to do something like this 😅 I’ll create another thread about it since it’s sort of a pre-release now.


There’s that post. So yeah, can be abused like so:

(require '[malli.core :as malli])
(require '[muotti.core :as muotti])
(require '[muotti.malli :as mm])

  (mm/transformer (muotti/->transformer 
                    {:transformations {[:int :string] {:transformer (constantly {:a 1 :b "wow"})}}})))
Obviously custom schema registry support needs to be added to make this even remotely sensible :rolling_on_the_floor_laughing:


Just released, a graph-based value transformation chain library which has integration with malli’s transformers.

awesome 2
🏆 2

Malli support is still somewhat in progress as malli has tons of schemas and some can be considered quite subjective (eg. for value transformation, what does [:and pos? :double] mean, if input is “3”) but maybe those can be supported eventually as well. For now core types are supported.


And this is a sort of pre-release for now which is why I put this here, not #announcements - have to let the dust settle first 🙂


Looks great! like byte-streams, but for (literal) data. Malli will have effective and derived types, will simplify things a lot,


Thanks! 😸 Figuring out which schemas to support and how is going to be an on-going process, I think - I’m going to exclusively avoid doing validation with muotti, naturally. My intention is to start using this in an actual project quite soonish, so I’m hoping that’ll let me refine the native support and providing sensible defaults. And as curiosity, muotti was made almost entirely during a few train trips between Helsinki and Tampere… 🙂