Skip to content

Commit

Permalink
remove extra code
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Jan 13, 2025
1 parent 5beb4b3 commit 8434543
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
43 changes: 23 additions & 20 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,6 @@
(fn [e] (when (= (nth e 0) key) (nth e 2))))
(-children schema)) default))

;;
;; parsers
;;

(defn -simple-parser [this]
(let [valid? (-validator this)]
(fn [x] (if (valid? x) x ::invalid))))

;;
;; entries
;;
Expand Down Expand Up @@ -570,9 +562,6 @@
(nil? x) (-no-op-transformer)
:else (-fail! ::invalid-transformer {:value x})))

(defn -simple-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))

(defn -parent-children-transformer [parent children transformer method options]
(let [parent-transformer (-value-transformer transformer parent method options)
child-transformers (into [] (keep #(-transformer % transformer method options)) children)
Expand Down Expand Up @@ -750,9 +739,12 @@
(let [validator (-validator this)]
(fn explain [x in acc]
(if-not (validator x) (conj acc (miu/-error path in this x)) acc))))
(-parser [this] (-simple-parser this))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-unparser [this] (-parser this))
(-transformer [this transformer method options] (-simple-transformer this transformer method options))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
(-walk [this walker path options] (-walk-leaf this walker path options))
(-properties [_] properties)
(-options [_] options)
Expand Down Expand Up @@ -1596,7 +1588,8 @@
(-parser [_] (fn [x] (if (contains? schema x) x ::invalid)))
(-unparser [this] (-parser this))
;; TODO: should we try to derive the type from values? e.g. [:enum 1 2] ~> int?
(-transformer [this transformer method options] (-simple-transformer this transformer method options))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
(-walk [this walker path options] (-walk-leaf this walker path options))
(-properties [_] properties)
(-options [_] options)
Expand Down Expand Up @@ -1643,8 +1636,11 @@
acc)
(catch #?(:clj Exception, :cljs js/Error) e
(conj acc (miu/-error path in this x (:type (ex-data e))))))))
(-transformer [this transformer method options] (-simple-transformer this transformer method options))
(-parser [this] (-simple-parser this))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
(-parser [this]
(let [valid? (-validator this)]
(fn [x] (if (valid? x) x ::invalid))))
(-unparser [this] (-parser this))
(-walk [this walker path options] (-walk-leaf this walker path options))
(-properties [_] properties)
Expand Down Expand Up @@ -1687,9 +1683,12 @@
acc)
(catch #?(:clj Exception, :cljs js/Error) e
(conj acc (miu/-error path in this x (:type (ex-data e))))))))
(-parser [this] (-simple-parser this))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-unparser [this] (-parser this))
(-transformer [this transformer method options] (-simple-transformer this transformer method options))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
(-walk [this walker path options] (-walk-leaf this walker path options))
(-properties [_] properties)
(-options [_] options)
Expand Down Expand Up @@ -2031,7 +2030,9 @@
(let [validator (-validator this)]
(fn explain [x in acc]
(if-not (validator x) (conj acc (miu/-error path in this x)) acc)))))
(-parser [this] (-simple-parser this))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-unparser [this] (-parser this))
(-transformer [_ _ _ _])
(-walk [this walker path options] (-walk-indexed this walker path options))
Expand Down Expand Up @@ -2111,7 +2112,9 @@
(let [validator (-validator this)]
(fn explain [x in acc]
(if-not (validator x) (conj acc (miu/-error path in this x)) acc)))))
(-parser [this] (-simple-parser this))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-unparser [this] (-parser this))
(-transformer [_ _ _ _])
(-walk [this walker path options] (-walk-indexed this walker path options))
Expand Down
4 changes: 1 addition & 3 deletions src/malli/error.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@
:uuid {:error/message {:en "should be a uuid"}}
:has {:error/fn {:en (fn [{:keys [schema value negated] :as error} options]
(if negated
(let [k (-> schema m/children first)]
(when true #_(contains? value k)
(negated (str "should not have key " (-pr-str k)))))
(negated (str "should not have key " (-> schema m/children first -pr-str)))
"missing required key"))}}
:> {:error/fn {:en (fn [{:keys [schema value negated] :as error} options]
(if negated
Expand Down

0 comments on commit 8434543

Please sign in to comment.