🐛 Add migration for fix undecoded path content

This commit is contained in:
Andrey Antukh 2025-07-02 16:45:40 +02:00
parent 898182e3d5
commit a2b8f19ff3
7 changed files with 73 additions and 59 deletions

View file

@ -1319,17 +1319,34 @@
(d/update-when :components d/update-vals update-container) (d/update-when :components d/update-vals update-container)
(d/without-nils)))) (d/without-nils))))
(defmethod migrate-data "0003-convert-path-content" (defmethod migrate-data "0003-convert-path-content-v2"
[data _] [data _]
(some-> cfeat/*new* (swap! conj "fdata/path-data")) (some-> cfeat/*new* (swap! conj "fdata/path-data"))
(letfn [(update-object [object] (let [decode-segments
(sm/decoder path/schema:segments sm/json-transformer)
update-object
(fn [object]
(if (or (cfh/bool-shape? object) (if (or (cfh/bool-shape? object)
(cfh/path-shape? object)) (cfh/path-shape? object))
(update object :content path/content) (let [content (get object :content)
content (cond
(path/content? content)
content
(nil? content)
(path/content [])
:else
(-> content
(decode-segments)
(path/content)))]
(assoc object :content content))
object)) object))
(update-container [container] update-container
(fn [container]
(d/update-when container :objects d/update-vals update-object))] (d/update-when container :objects d/update-vals update-object))]
(-> data (-> data
@ -1558,7 +1575,7 @@
"0002-normalize-bool-content-v2" "0002-normalize-bool-content-v2"
"0002-clean-shape-interactions" "0002-clean-shape-interactions"
"0003-fix-root-shape" "0003-fix-root-shape"
"0003-convert-path-content" "0003-convert-path-content-v2"
"0004-clean-shadow-color" "0004-clean-shadow-color"
"0005-deprecate-image-type" "0005-deprecate-image-type"
"0006-fix-old-texts-fills" "0006-fix-old-texts-fills"

View file

@ -26,6 +26,9 @@
(def ^:const bool-style-properties bool/style-properties) (def ^:const bool-style-properties bool/style-properties)
(def ^:const default-bool-fills bool/default-fills) (def ^:const default-bool-fills bool/default-fills)
(def schema:content impl/schema:content)
(def schema:segments impl/schema:segments)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TRANSFORMATIONS ;; TRANSFORMATIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -48,9 +51,9 @@
[data] [data]
(impl/from-string data)) (impl/from-string data))
(defn check-path-content (defn check-content
[content] [content]
(impl/check-content-like content)) (impl/check-content content))
(defn get-byte-size (defn get-byte-size
"Get byte size of a path content" "Get byte size of a path content"
@ -76,7 +79,7 @@
(defn apply-content-modifiers (defn apply-content-modifiers
"Apply delta modifiers over the path content" "Apply delta modifiers over the path content"
[content modifiers] [content modifiers]
(assert (impl/check-content-like content)) (assert (impl/check-content content))
(letfn [(apply-to-index [content [index params]] (letfn [(apply-to-index [content [index params]]
(if (contains? content index) (if (contains? content index)

View file

@ -507,18 +507,6 @@
(= (:command e1) :move-to))))} (= (:command e1) :move-to))))}
schema:segment]) schema:segment])
(def schema:content-like
[:sequential schema:segment])
(def check-content-like
(sm/check-fn schema:content-like))
(def check-segment
(sm/check-fn schema:segment))
(def ^:private check-segments
(sm/check-fn schema:segments))
(defn path-data? (defn path-data?
[o] [o]
(instance? PathData o)) (instance? PathData o))
@ -526,11 +514,8 @@
(declare from-string) (declare from-string)
(declare from-plain) (declare from-plain)
;; Mainly used on backend: features/components_v2.clj (def schema:content
(sm/register! ::path/segment schema:segment) (sm/type-schema
(sm/register! ::path/segments schema:segments)
(sm/register!
{:type ::path/content {:type ::path/content
:compile :compile
(fn [_ _ _] (fn [_ _ _]
@ -553,10 +538,19 @@
(from-plain))) (from-plain)))
:else :else
s))}}))}) s))}}))}))
(def check-path-content (def check-plain-content
(sm/check-fn ::path/content)) (sm/check-fn schema:segments))
(def check-segment
(sm/check-fn schema:segment))
(def ^:private check-segments
(sm/check-fn schema:segments))
(def check-content
(sm/check-fn schema:content))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CONSTRUCTORS & PREDICATES ;; CONSTRUCTORS & PREDICATES

View file

@ -246,7 +246,7 @@
[:map {:title "BoolAttrs"} [:map {:title "BoolAttrs"}
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]] [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
[:bool-type [::sm/one-of bool-types]] [:bool-type [::sm/one-of bool-types]]
[:content ::path/content]]) [:content path/schema:content]])
(def ^:private schema:rect-attrs (def ^:private schema:rect-attrs
[:map {:title "RectAttrs"}]) [:map {:title "RectAttrs"}])
@ -271,7 +271,7 @@
(def ^:private schema:path-attrs (def ^:private schema:path-attrs
[:map {:title "PathAttrs"} [:map {:title "PathAttrs"}
[:content ::path/content]]) [:content path/schema:content]])
(def ^:private schema:text-attrs (def ^:private schema:text-attrs
[:map {:title "TextAttrs"} [:map {:title "TextAttrs"}

View file

@ -113,10 +113,10 @@
{:num 500}))) {:num 500})))
(t/deftest shape-path-content-json-roundtrip (t/deftest shape-path-content-json-roundtrip
(let [encode (sm/encoder ::path/content (sm/json-transformer)) (let [encode (sm/encoder path/schema:content (sm/json-transformer))
decode (sm/decoder ::path/content (sm/json-transformer))] decode (sm/decoder path/schema:content (sm/json-transformer))]
(smt/check! (smt/check!
(smt/for [path-content (sg/generator ::path/content)] (smt/for [path-content (sg/generator path/schema:content)]
(let [path-content-1 (encode path-content) (let [path-content-1 (encode path-content)
path-content-2 (json-roundtrip path-content-1) path-content-2 (json-roundtrip path-content-1)
path-content-3 (decode path-content-2)] path-content-3 (decode path-content-2)]

View file

@ -19,8 +19,8 @@
"Generates changes to update the new content of the shape" "Generates changes to update the new content of the shape"
[it objects page-id shape old-content new-content] [it objects page-id shape old-content new-content]
(assert (path/check-path-content old-content)) (assert (path/content? old-content))
(assert (path/check-path-content new-content)) (assert (path/content? new-content))
(let [shape-id (:id shape) (let [shape-id (:id shape)

View file

@ -305,7 +305,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [content (some-> (dm/get-in state [:workspace-drawing :object :content]) (let [content (some-> (dm/get-in state [:workspace-drawing :object :content])
(path/check-path-content))] (path/check-content))]
(if (> (count content) 1) (if (> (count content) 1)
(assoc-in state [:workspace-drawing :object :initialized?] true) (assoc-in state [:workspace-drawing :object :initialized?] true)
state))) state)))