Add verify macro for true runtime spec asserts.

This commits mainly renames the old `assert` to `verify` and
adds new `assert` that laverages `:elide-asserts` on clojurescript
and *assert* value on clojure.

This approach enables an assert macro that does not performs
any runtime checks and compiles to more performant code in both
cases: development mode and production mode.
This commit is contained in:
Andrey Antukh 2020-01-31 19:08:45 +01:00
parent 391b926397
commit 8057fb54a6
14 changed files with 126 additions and 109 deletions

View file

@ -35,8 +35,8 @@
"Schedule the email for sending."
([email context] (send! db/pool email context))
([conn email context]
(us/assert fn? email)
(us/assert map? context)
(us/verify fn? email)
(us/verify map? context)
(let [defaults {:from (:email-from cfg/config)
:reply-to (:email-reply-to cfg/config)}
data (->> (merge defaults context)

View file

@ -43,8 +43,8 @@
width 200
height 200}
:as opts}]
(us/assert ::thumbnail-opts opts)
(us/assert fs/path? input)
(us/verify ::thumbnail-opts opts)
(us/verify fs/path? input)
(let [tmp (fs/create-tempfile :suffix (str "." format))
opr (doto (IMOperation.)
(.addImage)
@ -60,7 +60,7 @@
(defn make-thumbnail
[input {:keys [width height format quality] :as opts}]
(us/assert ::thumbnail-opts opts)
(us/verify ::thumbnail-opts opts)
(let [[filename ext] (fs/split-ext (fs/name input))
suffix (->> [width height quality format]
(interpose ".")

View file

@ -39,7 +39,7 @@
(defn- delete-project
"Clean deleted projects."
[{:keys [id] :as props}]
(us/assert ::delete-project props)
(us/verify ::delete-project props)
(db/with-atomic [conn db/pool]
(-> (db/query-one conn [sql:delete-project id])
(p/then (constantly nil)))))

View file

@ -266,7 +266,7 @@
(defn schedule!
[conn {:keys [name delay props queue key] :as options}]
(us/assert ::task-options options)
(us/verify ::task-options options)
(let [queue (if (string? queue) queue "default")
duration (-> (tm/duration delay)
(duration->pginterval))

View file

@ -90,7 +90,7 @@
([id extra-context]
(s/assert keyword? id)
(fn [context]
(us/assert ::context context)
(us/verify ::context context)
(when-let [spec (s/get-spec id)]
(s/assert spec context))