malli

https://github.com/metosin/malli :malli:
ikitommi 2020-10-16T15:23:35.183900Z

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.

ikitommi 2020-10-16T15:26:48.186Z

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"]}]

ikitommi 2020-10-16T15:28:09.187100Z

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

👍 1
ikitommi 2020-10-16T15:29:23.188600Z

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.

dangercoder 2020-10-16T21:02:16.194200Z

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.

dangercoder 2020-10-16T21:03:41.195200Z

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

borkdude 2020-10-16T21:04:02.195600Z

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

👍 2
2020-10-16T23:41:18.204200Z

@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

👍 1