Fork me on GitHub
#malli
<
2020-10-16
>
ikitommi15:10:35

Did a PR on making :schema and :ref schemas behave better: https://github.com/metosin/malli/pull/282. It has a BREAKING CHANGE as m/deref would be recursive and does not throw.

ikitommi15:10:48

these work after the PR: 1. mu/merge and mu/union with references:

(mu/merge
  [:schema [:map [:x int?]]]
  [:map [:y int?]])
; => [:map [:x int?] [:y int?]]
2. mu/subschemas with both :ref & :schemas:
(mu/subschemas
  [:ref {:registry {"Address" [:map
                               [:street :string]
                               [:address [:ref "Address"]]
                               [:neighbor [:ref "Neighbor"]]]
                    "Country" [:map [:name [:= "finland"]]]
                    "Neighbor" [:ref "Address"]}}
   "Address"])
;[{:path [], :in [], :schema [:ref {:registry {"Address" [:map
;                                                         [:street :string]
;                                                         [:address [:ref "Address"]]
;                                                         [:neighbor [:ref "Neighbor"]]]
;                                              "Country" [:map [:name [:= "finland"]]]
;                                              "Neighbor" [:ref "Address"]}}
;                             "Address"]}
; {:path [0 0], :in [], :schema [:map
;                                [:street :string]
;                                [:address [:ref "Address"]]
;                                [:neighbor [:ref "Neighbor"]]]}
; {:path [0 0 :street], :in [:street], :schema :string}
; {:path [0 0 :address], :in [:address], :schema [:ref "Address"]}
; {:path [0 0 :neighbor], :in [:neighbor], :schema [:ref "Neighbor"]}]

ikitommi15:10:09

if you are in business of generating forms from schemas, mu/subschemas is your best friend.

👍 3
ikitommi15:10:23

m/walk can be configured with ::m/walk-refs and ::m/walk-schema-refs to walk over none, some of all references. Does not StackOverFlow, walks a given reference just once. cheers.

dangercoder21:10:16

is there some kind of way to speed up m/validate? I have a real edge case, I automatically generated a schema for a structure that potentially can contain 1294 fields (a tree structure...) when I ran validate it took a few seconds on a empty map.

dangercoder21:10:41

would it run quicker if I used a registry for things that are "common"?

borkdude21:10:02

I think malli supports something like lazy validation and/or lazy schemas - I've seen this being mentioned in a conversation with ikitommi and jeroenvandijk

👍 6
jeroenvandijk23:10:18

@jarvinenemil not sure if it is still idiomatic Malli and it can be more optimized, but here is how you could do lazy loading (see lookup-type) https://github.com/jeroenvandijk/aws.cloudformation.malli/blob/master/src/adgoji/aws/cloudformation/malli/validation.clj

👍 3