Fork me on GitHub
#malli
<
2020-02-06
>
eoliphant18:02:47

will malli eventually do, for lack of a better term, a keyset coerce/conform? I try to use open keysets as much as possible, but always struggle the best way to handle stuff like the following

(-> {:a .. b:.. :c .. :d} ; say input from api call
     validate ; we only care about :a,:b and :c but ignore :d
     do-something-with-a-and-b ; fine with a s/keys [:a :b] or m/validate equivalent precondition
     do-something-with-c ; fine with a s/keys [:c]
     (select-keys [:a ::c]) ; or (transform my-schema)
     (write-a-b-c-to-datomic) ; at this point I want a closed schema/spec precond, that could potentially narrow the keys on the way in? 

ikitommi19:02:10

@eoliphant would something like (mu/select-keys map-of-abc [:a :b]) be good? you can always make maps closed, to either fail on extra keys or to strip extra keys in transform

ikitommi19:02:55

e.g. select-keys, but for schemas

eoliphant19:02:42

hmm yeah, perhaps strip extra on transform is the way to go? again, just been thinking about this, in terms of a structural coercion, but that might not be the best approach

ikitommi19:02:11

I think it's the way to go: open schemas are great , but external systems like db's aren't always happy with extra stuff in. We are at least stripping data away at the boundaries.

ikitommi19:02:55

there is malli.transform/strip-extra-keys-transformerfor this

1
eoliphant19:02:23

especially for stuff like datomic lets you do maps, etc all the way down, but it gets understandably upset if you pass in attributes it doesn’t know about 😉