0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-01 11:59:17 -05:00

🐛 Fix shape validation schema

This commit is contained in:
Andrey Antukh 2024-01-17 18:09:58 +01:00
parent 166d2b7b68
commit 5b84054eaa
5 changed files with 56 additions and 29 deletions

View file

@ -5,6 +5,7 @@
promesa.exec.csp/go-loop clojure.core/loop promesa.exec.csp/go-loop clojure.core/loop
rumext.v2/defc clojure.core/defn rumext.v2/defc clojure.core/defn
promesa.util/with-open clojure.core/with-open promesa.util/with-open clojure.core/with-open
app.common.schema.generators/let clojure.core/let
app.common.data/export clojure.core/def app.common.data/export clojure.core/def
app.common.data.macros/get-in clojure.core/get-in app.common.data.macros/get-in clojure.core/get-in
app.common.data.macros/with-open clojure.core/with-open app.common.data.macros/with-open clojure.core/with-open

View file

@ -6,4 +6,4 @@
(ns app.common.files.defaults) (ns app.common.files.defaults)
(def version 41) (def version 42)

View file

@ -577,21 +577,6 @@
(update :pages-index update-vals update-container) (update :pages-index update-vals update-container)
(update :components update-vals update-container)))) (update :components update-vals update-container))))
(defmethod migrate 30
[data]
(letfn [(update-object [object]
(if (and (cfh/frame-shape? object)
(not (:shapes object)))
(assoc object :shapes [])
object))
(update-container [container]
(d/update-when container :objects update-vals update-object))]
(-> data
(update :pages-index update-vals update-container)
(update :components update-vals update-container))))
(defmethod migrate 31 (defmethod migrate 31
[data] [data]
(letfn [(update-object [object] (letfn [(update-object [object]
@ -778,3 +763,22 @@
(-> data (-> data
(update :pages-index update-vals update-container) (update :pages-index update-vals update-container)
(update :components update-vals update-container)))) (update :components update-vals update-container))))
(defmethod migrate 42
[data]
(letfn [(update-object [object]
(if (and (or (cfh/frame-shape? object)
(cfh/group-shape? object)
(cfh/bool-shape? object))
(not (:shapes object)))
(assoc object :shapes [])
object))
(update-container [container]
(d/update-when container :objects update-vals update-object))]
(-> data
(update :pages-index update-vals update-container)
(update :components update-vals update-container))))

View file

@ -5,7 +5,7 @@
;; Copyright (c) KALEIDOS INC ;; Copyright (c) KALEIDOS INC
(ns app.common.schema.generators (ns app.common.schema.generators
(:refer-clojure :exclude [set subseq uuid for filter map]) (:refer-clojure :exclude [set subseq uuid for filter map let])
#?(:cljs (:require-macros [app.common.schema.generators])) #?(:cljs (:require-macros [app.common.schema.generators]))
(:require (:require
[app.common.schema.registry :as sr] [app.common.schema.registry :as sr]
@ -37,6 +37,10 @@
[& params] [& params]
`(tp/for-all ~@params)) `(tp/for-all ~@params))
(defmacro let
[& params]
`(tg/let ~@params))
(defn check! (defn check!
[p & {:keys [num] :or {num 20} :as options}] [p & {:keys [num] :or {num 20} :as options}]
(tc/quick-check num p (assoc options :reporter-fn default-reporter-fn :max-size 50))) (tc/quick-check num p (assoc options :reporter-fn default-reporter-fn :max-size 50)))
@ -124,6 +128,10 @@
[f g] [f g]
(tg/fmap f g)) (tg/fmap f g))
(defn mcat
[f g]
(tg/bind g f))
(defn tuple (defn tuple
[& opts] [& opts]
(apply tg/tuple opts)) (apply tg/tuple opts))

View file

@ -46,6 +46,7 @@
:bool :bool
:rect :rect
:path :path
:text
:circle :circle
:svg-raw :svg-raw
:image}) :image})
@ -199,7 +200,7 @@
(sm/define! ::group-attrs (sm/define! ::group-attrs
[:map {:title "GroupAttrs"} [:map {:title "GroupAttrs"}
[:type [:= :group]] [:type [:= :group]]
[:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]]) [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]])
(sm/define! ::frame-attrs (sm/define! ::frame-attrs
[:map {:title "FrameAttrs"} [:map {:title "FrameAttrs"}
@ -212,7 +213,7 @@
(sm/define! ::bool-attrs (sm/define! ::bool-attrs
[:map {:title "BoolAttrs"} [:map {:title "BoolAttrs"}
[:type [:= :bool]] [:type [:= :bool]]
[:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]] [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
;; FIXME: improve this schema ;; FIXME: improve this schema
[:bool-type :keyword] [:bool-type :keyword]
@ -271,63 +272,63 @@
(sm/define! ::shape-map (sm/define! ::shape-map
[:multi {:dispatch :type :title "Shape"} [:multi {:dispatch :type :title "Shape"}
[:group [:group
[:merge {:title "GroupShape"} [:and {:title "GroupShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::group-attrs ::group-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:frame [:frame
[:merge {:title "FrameShape"} [:and {:title "FrameShape"}
::minimal-shape-attrs ::minimal-shape-attrs
::frame-attrs ::frame-attrs
::ctsl/layout-attrs ::ctsl/layout-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:bool [:bool
[:merge {:title "BoolShape"} [:and {:title "BoolShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::bool-attrs ::bool-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:rect [:rect
[:merge {:title "RectShape"} [:and {:title "RectShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::rect-attrs ::rect-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:circle [:circle
[:merge {:title "CircleShape"} [:and {:title "CircleShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::circle-attrs ::circle-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:image [:image
[:merge {:title "ImageShape"} [:and {:title "ImageShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::image-attrs ::image-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:svg-raw [:svg-raw
[:merge {:title "SvgRawShape"} [:and {:title "SvgRawShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::svg-raw-attrs ::svg-raw-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:path [:path
[:merge {:title "PathShape"} [:and {:title "PathShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::path-attrs ::path-attrs
::ctsl/layout-child-attrs]] ::ctsl/layout-child-attrs]]
[:text [:text
[:merge {:title "TextShape"} [:and {:title "TextShape"}
::shape-attrs ::shape-attrs
::minimal-shape-attrs ::minimal-shape-attrs
::text-attrs ::text-attrs
@ -336,7 +337,20 @@
(sm/define! ::shape (sm/define! ::shape
[:and [:and
{:title "Shape" {:title "Shape"
:gen/gen (->> (sg/generator ::shape-map) :gen/gen (->> (sg/generator ::minimal-shape-attrs)
(sg/mcat (fn [{:keys [type] :as shape}]
(sg/let [attrs1 (sg/generator ::shape-attrs)
attrs2 (case type
:text (sg/generator ::text-attrs)
:path (sg/generator ::path-attrs)
:svg-raw (sg/generator ::svg-raw-attrs)
:image (sg/generator ::image-attrs)
:circle (sg/generator ::circle-attrs)
:rect (sg/generator ::rect-attrs)
:bool (sg/generator ::bool-attrs)
:group (sg/generator ::group-attrs)
:frame (sg/generator ::frame-attrs))]
(merge attrs1 shape attrs2))))
(sg/fmap map->Shape))} (sg/fmap map->Shape))}
::shape-map ::shape-map
[:fn shape?]]) [:fn shape?]])