malli

https://github.com/metosin/malli :malli:
ikitommi 2020-06-28T11:23:36.149500Z

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

ikitommi 2020-06-28T11:25:23.150900Z

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

ikitommi 2020-06-28T11:25:52.151400Z

(all registry hops are internaly :schema too)

👍 1
ikitommi 2020-06-28T11:26:19.151800Z

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

ikitommi 2020-06-28T11:26:56.152500Z

both :schema and :ref also implement the new

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

ikitommi 2020-06-28T12:16:19.001900Z

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

👍 1
ikitommi 2020-06-28T12:16:25.002200Z

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

ikitommi 2020-06-28T12:16:42.002700Z

which is kinda awesome 🙂