Skip to content

Commit

Permalink
[#38] Move key priority to compile-key
Browse files Browse the repository at this point in the history
  • Loading branch information
KGOH committed Feb 14, 2023
1 parent bb64524 commit 4cf3d82
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/zen/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
[clojure.set]))


(defn rule-priority [k]
(cond
(= k :keys) 0
(= k :key) 10
(= k :values) 1
(= k :validation-type) 1000
:else 100))


(defmulti compile-key (fn [k ztx kfg] k))


Expand Down Expand Up @@ -97,10 +88,8 @@

(defn compile-schema [ztx schema]
(let [rulesets (->> schema
(keep (fn [[k v]]
(-> (safe-compile-key k ztx v)
(assoc ::priority (rule-priority k)))))
(sort-by ::priority))
(keep (fn [[k v]] (safe-compile-key k ztx v)))
(sort-by #(:priority % 100)))

compiled-schema-fn
(fn compiled-schema-fn [vtx data opts]
Expand Down Expand Up @@ -163,12 +152,12 @@
(compiled-schema-fn vtx data opts)))


(defmethod compile-key :keys [_ _ _] {:when map?})
(defmethod compile-key :key [_ _ _] {:when map?})
(defmethod compile-key :keys [_ _ _] {:when map? :priority 0})
(defmethod compile-key :key [_ _ _] {:when map? :priority 10})
(defmethod compile-key :exclusive-keys [_ _ _] {:when map?})
(defmethod compile-key :validation-type [_ _ _] {:when map?})
(defmethod compile-key :validation-type [_ _ _] {:when map? :priority 1000})
(defmethod compile-key :require [_ _ _] {:when map?})
(defmethod compile-key :values [_ _ _] {:when map?})
(defmethod compile-key :values [_ _ _] {:when map? :priority 1})
(defmethod compile-key :schema-key [_ _ _] {:when map?})
(defmethod compile-key :keyname-schemas [_ _ _] {:when map?})
(defmethod compile-key :key-schema [_ _ _] {:when map?})
Expand Down

0 comments on commit 4cf3d82

Please sign in to comment.