0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-01 01:21:21 -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

View file

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

View file

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

View file

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