Skip to content

Commit

Permalink
[#38] Refactor :keyname-schemas to ::navigate interpreter
Browse files Browse the repository at this point in the history
Co-authored-by: @ghrpp <[email protected]>
Co-authored-by: @rublag_hs <[email protected]>
Co-authored-by: @kenichsberg <[email protected]>
Co-authored-by: @IvannikovG <[email protected]>
  • Loading branch information
5 people committed Jan 20, 2023
1 parent 5aef6ea commit dba5c9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
19 changes: 19 additions & 0 deletions src/zen/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
(defmethod compile-key :require [_ _ _] {:when map?})
(defmethod compile-key :values [_ _ _] {:when map?})
(defmethod compile-key :schema-key [_ _ _] {:when map?})
(defmethod compile-key :keyname-schemas [_ _ _] {:when map?})

(defmethod compile-key :scale [_ _ _] {:when number?})
(defmethod compile-key :precision [_ _ _] {:when number?})
Expand Down Expand Up @@ -347,3 +348,21 @@
vtx*))
vtx
schemas)))))


(register-compile-key-interpreter!
[:keyname-schemas ::navigate]
(fn [_ ztx {:keys [tags]}]
(fn [vtx data opts]
(let [rule-fn
(fn [vtx* [schema-key data*]]
(if-let [sch (and (qualified-ident? schema-key) (utils/get-symbol ztx (symbol schema-key)))]
;; TODO add test on nil case
(if (or (nil? tags)
(clojure.set/subset? tags (:zen/tags sch)))
(-> (validation.utils/node-vtx&log vtx* [:keyname-schemas schema-key] [schema-key])
((get-cached ztx sch false) data* opts)
(validation.utils/merge-vtx vtx*))
vtx*)
vtx*))]
(reduce rule-fn vtx data)))))
18 changes: 0 additions & 18 deletions src/zen/v2_validation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -450,24 +450,6 @@ Probably safe to remove if no one relies on them"
vtx
ks)))))

(defmethod compile-key :keyname-schemas
[_ ztx {:keys [tags]}]
{:when map?
:rule
(fn [vtx data opts]
(let [rule-fn
(fn [vtx* [schema-key data*]]
(if-let [sch (and (qualified-ident? schema-key) (utils/get-symbol ztx (symbol schema-key)))]
;; TODO add test on nil case
(if (or (nil? tags)
(clojure.set/subset? tags (:zen/tags sch)))
(-> (node-vtx&log vtx* [:keyname-schemas schema-key] [schema-key])
((get-cached ztx sch false) data* opts)
(merge-vtx vtx*))
vtx*)
vtx*))]
(reduce rule-fn vtx data)))})

(defmethod compile-key :default [schema-key ztx sch-params]
(cond
(qualified-ident? schema-key)
Expand Down

0 comments on commit dba5c9b

Please sign in to comment.