Improve file data type constructor

This commit is contained in:
Andrey Antukh 2025-07-22 13:33:33 +02:00
parent a77edc5aa2
commit 6c7fef29a8

View file

@ -16,6 +16,7 @@
[app.common.geom.shapes.tree-seq :as gsts] [app.common.geom.shapes.tree-seq :as gsts]
[app.common.logging :as l] [app.common.logging :as l]
[app.common.schema :as sm] [app.common.schema :as sm]
[app.common.time :as dt]
[app.common.types.color :as ctc] [app.common.types.color :as ctc]
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl] [app.common.types.components-list :as ctkl]
@ -93,12 +94,13 @@
[:map {:title "file"} [:map {:title "file"}
[:id ::sm/uuid] [:id ::sm/uuid]
[:name :string] [:name :string]
[:revn {:optional true} :int] [:revn :int]
[:vern {:optional true} :int] [:vern {:optional true} :int]
[:created-at {:optional true} ::sm/inst] [:created-at ::sm/inst]
[:modified-at {:optional true} ::sm/inst] [:modified-at ::sm/inst]
[:deleted-at {:optional true} ::sm/inst] [:deleted-at {:optional true} ::sm/inst]
[:project-id {:optional true} ::sm/uuid] [:project-id {:optional true} ::sm/uuid]
[:team-id {:optional true} ::sm/uuid]
[:is-shared {:optional true} ::sm/boolean] [:is-shared {:optional true} ::sm/boolean]
[:data {:optional true} schema:data] [:data {:optional true} schema:data]
[:version :int] [:version :int]
@ -145,33 +147,48 @@
(update :options merge {:components-v2 true (update :options merge {:components-v2 true
:base-font-size BASE-FONT-SIZE}))))) :base-font-size BASE-FONT-SIZE})))))
;; FIXME: we can't handle the "default" migrations for avoid providing
;; them all the time the file is created because we can't import file
;; migrations because of circular import issue; We need to split the
;; list of migrations and impl of migrations in separate namespaces
;; FIXME: refactor
(defn make-file (defn make-file
[{:keys [id project-id name revn is-shared features migrations [{:keys [id project-id name revn is-shared features migrations
ignore-sync-until modified-at deleted-at] ignore-sync-until created-at modified-at deleted-at]
:or {is-shared false revn 0}} :as params}
& {:keys [create-page page-id] & {:keys [create-page with-data page-id]
:or {create-page true}}] :or {create-page true with-data true}}]
(let [id (or id (uuid/next)) (let [id (or id (uuid/next))
data (if create-page created-at (or created-at (dt/now))
modified-at (or modified-at created-at)
features (d/nilv features #{})
data
(when with-data
(if create-page
(if page-id (if page-id
(make-file-data id page-id) (make-file-data id page-id)
(make-file-data id)) (make-file-data id))
(make-file-data id nil)) (make-file-data id nil)))
file (d/without-nils file
(d/without-nils
{:id id {:id id
:project-id project-id :project-id project-id
:name name :name name
:revn revn :revn (d/nilv revn 0)
:vern 0 :vern 0
:is-shared is-shared :is-shared (d/nilv is-shared false)
:version version :version (:version params version)
:data data :data data
:features features :features features
:migrations migrations :migrations migrations
:ignore-sync-until ignore-sync-until :ignore-sync-until ignore-sync-until
:created-at created-at
:modified-at modified-at :modified-at modified-at
:deleted-at deleted-at})] :deleted-at deleted-at})]