mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 10:36:10 +02:00
♻️ Clean assertion and schema chechking API
This commit is contained in:
parent
45f3a67950
commit
002b1679c3
13 changed files with 161 additions and 168 deletions
|
@ -1725,8 +1725,8 @@
|
|||
[:images [:set :map]]
|
||||
[:position {:optional true} ::gpt/point]])
|
||||
|
||||
(def validate-paste-data!
|
||||
(sm/validate-fn schema:paste-data))
|
||||
(def paste-data-valid?
|
||||
(sm/lazy-validator schema:paste-data))
|
||||
|
||||
(defn- paste-transit
|
||||
[{:keys [images] :as pdata}]
|
||||
|
@ -1751,8 +1751,10 @@
|
|||
(let [file-id (:current-file-id state)
|
||||
features (features/get-team-enabled-features state)]
|
||||
|
||||
(validate-paste-data! pdata {:hint "invalid paste data"
|
||||
:code :invalid-paste-data})
|
||||
(when-not (paste-data-valid? pdata)
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-paste-data
|
||||
:hibt "invalid paste data found"))
|
||||
|
||||
(cfeat/check-paste-features! features (:features pdata))
|
||||
(if (= file-id (:file-id pdata))
|
||||
|
|
|
@ -465,16 +465,16 @@
|
|||
(defn change-color-in-selected
|
||||
[operations new-color old-color]
|
||||
|
||||
(dm/verify!
|
||||
"expected valid change color operations"
|
||||
(dm/assert!
|
||||
"expected valid color operations"
|
||||
(check-change-color-operations! operations))
|
||||
|
||||
(dm/verify!
|
||||
"expected a valid color struct for new-color param"
|
||||
(dm/assert!
|
||||
"expected valid color structure"
|
||||
(ctc/check-color! new-color))
|
||||
|
||||
(dm/verify!
|
||||
"expected a valid color struct for old-color param"
|
||||
(dm/assert!
|
||||
"expected valid color structure"
|
||||
(ctc/check-color! old-color))
|
||||
|
||||
(ptk/reify ::change-color-in-selected
|
||||
|
@ -498,7 +498,7 @@
|
|||
[color stroke?]
|
||||
|
||||
(dm/assert!
|
||||
"should be a valid color"
|
||||
"expected valid color structure"
|
||||
(ctc/check-color! color))
|
||||
|
||||
(ptk/reify ::apply-color-from-palette
|
||||
|
|
|
@ -193,9 +193,17 @@
|
|||
|
||||
(defn rename-color
|
||||
[file-id id new-name]
|
||||
(dm/verify! (uuid? file-id))
|
||||
(dm/verify! (uuid? id))
|
||||
(dm/verify! (string? new-name))
|
||||
(dm/assert!
|
||||
"expected valid uuid for `id`"
|
||||
(uuid? id))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid uuid for `file-id`"
|
||||
(uuid? file-id))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid string for `new-name`"
|
||||
(string? new-name))
|
||||
|
||||
(ptk/reify ::rename-color
|
||||
ptk/WatchEvent
|
||||
|
@ -243,8 +251,15 @@
|
|||
|
||||
(defn rename-media
|
||||
[id new-name]
|
||||
(dm/verify! (uuid? id))
|
||||
(dm/verify! (string? new-name))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid uuid for `id`"
|
||||
(uuid? id))
|
||||
|
||||
(dm/assert!
|
||||
"expected valid string for `new-name`"
|
||||
(string? new-name))
|
||||
|
||||
(ptk/reify ::rename-media
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
|
@ -261,8 +276,11 @@
|
|||
(rx/of (dch/commit-changes changes))))))))
|
||||
|
||||
(defn delete-media
|
||||
[{:keys [id] :as params}]
|
||||
(dm/assert! (uuid? id))
|
||||
[{:keys [id]}]
|
||||
(dm/assert!
|
||||
"expected valid uuid for `id`"
|
||||
(uuid? id))
|
||||
|
||||
(ptk/reify ::delete-media
|
||||
ev/Event
|
||||
(-data [_] {:id id})
|
||||
|
@ -435,8 +453,14 @@
|
|||
(defn rename-component
|
||||
"Rename the component with the given id, in the current file library."
|
||||
[id new-name]
|
||||
(dm/verify! (uuid? id))
|
||||
(dm/verify! (string? new-name))
|
||||
(dm/assert!
|
||||
"expected an uuid instance"
|
||||
(uuid? id))
|
||||
|
||||
(dm/assert!
|
||||
"expected string for new-name"
|
||||
(string? new-name))
|
||||
|
||||
(ptk/reify ::rename-component
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
|
@ -487,8 +511,11 @@
|
|||
|
||||
(defn delete-component
|
||||
"Delete the component with the given id, from the current file library."
|
||||
[{:keys [id] :as params}]
|
||||
(dm/assert! (uuid? id))
|
||||
[{:keys [id]}]
|
||||
(dm/assert!
|
||||
"expected valid uuid for `id`"
|
||||
(uuid? id))
|
||||
|
||||
(ptk/reify ::delete-component
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
|
@ -1129,7 +1156,9 @@
|
|||
(defn touch-component
|
||||
"Update the modified-at attribute of the component to now"
|
||||
[id]
|
||||
(dm/verify! (uuid? id))
|
||||
(dm/assert!
|
||||
"expected valid uuid for `id`"
|
||||
(uuid? id))
|
||||
(ptk/reify ::touch-component
|
||||
cljs.core/IDeref
|
||||
(-deref [_] [id])
|
||||
|
|
|
@ -98,8 +98,8 @@
|
|||
(add-shape shape {}))
|
||||
([shape {:keys [no-select? no-update-layout?]}]
|
||||
|
||||
(dm/verify!
|
||||
"expected a valid shape"
|
||||
(dm/assert!
|
||||
"expected valid shape"
|
||||
(cts/check-shape! shape))
|
||||
|
||||
(ptk/reify ::add-shape
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue