Fork me on GitHub
#malli
<
2019-12-16
>
rschmukler17:12:03

@ikitommi awesome cleanup on malli.core. Code looks 😍

ikitommi17:12:53

actually, the logic to convert from keywords should be somewhere. JSON Parsers keywordize the keys. If keys are defined to be int?, They are seen as :12 etc. The string->int doesn't work here

rschmukler17:12:25

Ah! I can look into re-adding that to the json transformer then

ikitommi17:12:40

.. and string too

rschmukler17:12:00

Okay, should I just add it to the string transformer then?

rschmukler17:12:29

@ikitommi I think we should consider dropping the schema-based type checks and instead leave that to the transformer functions. ie. sometimes we check (if (or (map? x) (nil? x)) (transform x)) - especially on decode, it might not be the same shape at all...

rschmukler17:12:58

Consider a JSON body that returns [x y z] and wanting to decode that into a map... or similarly wanting to use malli to decode CSV rows into maps

rschmukler17:12:03

(decode [:map {:decode/row (fn [row]
                               {:name (nth row 0)
                                :age (nth row 1)})}
           [:name string?]
           [:age int?]]
          ["Bob" "42"]
          (malli.transform/transformer
           malli.transform/string-transformer
           {:name :row}))

rschmukler17:12:10

Ideally that'd work

rschmukler17:12:36

I think it should be the transformer's responsibility to handle (or not handle) arbitrary data

rschmukler18:12:19

@ikitommi re-added the coercion behavior to string + json transformer. Still marked the commit as breaking since it'll break people who were relying on the keyword->string coercion in their transformers... but I updated the message + commit body to tell as much.

ikitommi18:12:13

@rschmukler agree on pushing the checks to transformers. Currently, the check is only done before the whole chain. If the first step changes the type, with the current solution, the next will blow anyway.

ikitommi18:12:37

147 looks good. I was told not to pull in before the EPL2 license is in place, need still few approvals.

ikitommi18:12:32

I think the current :malli.core/map-key target (and impl) can be removed - same can be done with anonymous transformer with :map target.

rschmukler19:12:01

@ikitommi Alright sounds good. I think I've got a elegant solution to the transformer chain checks

👍 4