Fork me on GitHub
#malli
<
2020-06-28
>
ikitommi11:06:36

About to add eager references too:

(def Schema
  [:and
   {:registry {::a ::b
               ::b ::c
               ::c [:schema pos-int?]}}
   [:and ::a ::b ::c]])

(m/form Schema)
;[:and {:registry #:user{:a :user/b
;                        :b :user/c
;                        :c [:schema pos-int?]}}
; [:and :user/a :user/b :user/c]]

(m/to-map-syntax Schema)
;{:type :and
; :properties {:registry #:user{:a :user/b
;                               :b :user/c
;                               :c [:schema pos-int?]}}
; :children [{:type :and
;             :children [{:type :schema
;                         :children [:user/a]}
;                        {:type :schema
;                         :children [:user/b]}
;                        {:type :schema
;                         :children [:user/c]}]}]}

ikitommi11:06:23

e.g. each registry hop retains the information the original linkage + :schema element to mark Entitys in a schema data graph.

ikitommi11:06:52

(all registry hops are internaly :schema too)

👍 3
ikitommi11:06:19

accept can be configured to automatically walk over those, if wanted.

ikitommi11:06:56

both :schema and :ref also implement the new

(defprotocol RefSchema
  (-deref [this] "returns the referenced schema"))

ikitommi12:06:19

… and for the given schema, the validation fn is just pos-int?

👍 3
ikitommi12:06:25

(m/validator Schema)
; #object[clojure.core$pos_int]

ikitommi12:06:42

which is kinda awesome 🙂