mirror of
https://github.com/penpot/penpot.git
synced 2026-08-08 05:48:50 +00:00
✨ Validate graph ingest projections with Malli
This commit is contained in:
parent
275c77471d
commit
38488c2612
@ -10,6 +10,7 @@
|
||||
[app.binfile.common :as bfc]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.logging :as l]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.db :as db]
|
||||
[app.graph.ladybug :as ladybug]
|
||||
[app.graph.project.document :as project.document]
|
||||
@ -28,6 +29,12 @@
|
||||
(ex/raise :type :not-found
|
||||
:code :file-not-found
|
||||
:file-id (str file-id)))
|
||||
(when-not (:data file)
|
||||
(ex/raise :type :validation
|
||||
:code :file-without-data
|
||||
:hint "file has no data to project"
|
||||
:file-id (str file-id)))
|
||||
(ctf/check-file-data (:data file))
|
||||
(when reset-db?
|
||||
(ladybug/reset-db-path! db-path))
|
||||
(l/inf :hint "graph ingest"
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
[app.common.logging :as l]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.graph.ladybug :as ladybug]
|
||||
[app.graph.project.specs :as specs]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(def root-frame-id
|
||||
@ -37,6 +38,10 @@
|
||||
attrs))]
|
||||
(str "CREATE (n:`" table "` {" props "});")))
|
||||
|
||||
(defn- validated-node-statement
|
||||
[check-fn table attrs]
|
||||
(create-node-statement table (check-fn attrs)))
|
||||
|
||||
(defn- merge-edge-statement
|
||||
[from-table from-id to-table to-id position]
|
||||
(str "MATCH (c:`" from-table "` {`id`: " (ladybug/format-uuid from-id) "}), "
|
||||
@ -67,7 +72,8 @@
|
||||
root (get objects root-frame-id)
|
||||
top-level-ids (when root (vec (reverse (:shapes root))))
|
||||
statements' (conj statements
|
||||
(create-node-statement "Page" (page-attrs page position))
|
||||
(validated-node-statement specs/check-page "Page"
|
||||
(page-attrs page position))
|
||||
(merge-edge-statement "Page" page-id "Document" doc-id position))
|
||||
stats' (update stats :pages inc)]
|
||||
(if (seq top-level-ids)
|
||||
@ -76,8 +82,9 @@
|
||||
(if-let [shape (get objects shape-id)]
|
||||
(if-let [table (shape-table shape)]
|
||||
[(-> stmts
|
||||
(conj (create-node-statement table {:id (:id shape)
|
||||
:name (:name shape)})
|
||||
(conj (validated-node-statement specs/check-shape-node table
|
||||
{:id (:id shape)
|
||||
:name (:name shape)})
|
||||
(merge-edge-statement table (:id shape)
|
||||
"Page" page-id shape-pos)))
|
||||
(update st :shapes inc)]
|
||||
@ -98,7 +105,8 @@
|
||||
[data file]
|
||||
(let [doc-id (or (:id data) (:id file))
|
||||
pages (seq (reverse (:pages data)))
|
||||
initial [(create-node-statement "Document" (document-attrs file data))]
|
||||
initial [(validated-node-statement specs/check-document "Document"
|
||||
(document-attrs file data))]
|
||||
[statements stats]
|
||||
(if (empty? pages)
|
||||
[initial {:documents 1 :pages 0 :shapes 0}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user