0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-21 12:11:37 -05:00

🐛 Add schema validation for color changes

This commit is contained in:
Andrey Antukh 2024-08-26 17:39:16 +02:00
parent 3ddecef5a7
commit 05750c3b38
3 changed files with 39 additions and 12 deletions
common/src/app/common

View file

@ -154,12 +154,12 @@
[:add-color
[:map {:title "AddColorChange"}
[:type [:= :add-color]]
[:color :any]]]
[:color ::ctc/color]]]
[:mod-color
[:map {:title "ModColorChange"}
[:type [:= :mod-color]]
[:color :any]]]
[:color ::ctc/color]]]
[:del-color
[:map {:title "DelColorChange"}

View file

@ -619,20 +619,27 @@
{:title "contains"
:description "contains predicate"}}))})
(define! ::inst
(def type:inst
{:type ::inst
:pred inst?
:type-properties
{:title "inst"
:description "Satisfies Inst protocol"
:error/message "expected to be number in safe range"
:error/message "should be an instant"
:gen/gen (->> (sg/small-int)
(sg/fmap (fn [v] (tm/instant v))))
::oapi/type "number"
::oapi/format "int64"}})
(sg/fmap (fn [v] (tm/parse-instant v))))
(define! ::fn
[:schema fn?])
:decode/string tm/parse-instant
:encode/string tm/format-instant
:decode/json tm/parse-instant
:encode/json tm/format-instant
::oapi/type "string"
::oapi/format "iso"}})
(register! ::inst type:inst)
(register! ::fn
[:schema fn?])
(define! ::word-string
{:type ::word-string

View file

@ -12,6 +12,7 @@
["luxon" :as lxn])
:clj
(:import
java.time.format.DateTimeFormatter
java.time.Instant
java.time.Duration)))
@ -26,10 +27,29 @@
#?(:clj (Instant/now)
:cljs (.local ^js DateTime)))
(defn instant
(defn instant?
[o]
#?(:clj (instance? Instant o)
:cljs (instance? DateTime o)))
(defn parse-instant
[s]
#?(:clj (Instant/ofEpochMilli s)
:cljs (.fromMillis ^js DateTime s #js {:zone "local" :setZone false})))
(cond
(instant? s)
s
(int? s)
#?(:clj (Instant/ofEpochMilli s)
:cljs (.fromMillis ^js DateTime s #js {:zone "local" :setZone false}))
(string? s)
#?(:clj (Instant/parse s)
:cljs (.fromISO ^js DateTime s))))
(defn format-instant
[v]
#?(:clj (.format DateTimeFormatter/ISO_INSTANT ^Instant v)
:cljs (.toISO ^js v)))
#?(:cljs
(extend-protocol IComparable