💄 Fix code style consistency on schema declarations on file ns

This commit is contained in:
Andrey Antukh 2023-07-06 15:41:53 +02:00
parent ab0245279f
commit dfc2ab56a9
4 changed files with 48 additions and 63 deletions

View file

@ -305,17 +305,17 @@
;; --- COMMAND QUERY: get-file (by id) ;; --- COMMAND QUERY: get-file (by id)
(sm/def! ::features (def schema:features
[:schema [:schema
{:title "FileFeatures" {:title "FileFeatures"
::smdj/inline true ::smdj/inline true
:gen/gen (sg/subseq supported-features)} :gen/gen (sg/subseq supported-features)}
::sm/set-of-strings]) ::sm/set-of-strings])
(sm/def! ::file (def schema:file
[:map {:title "File"} [:map {:title "File"}
[:id ::sm/uuid] [:id ::sm/uuid]
[:features ::features] [:features schema:features]
[:has-media-trimmed :boolean] [:has-media-trimmed :boolean]
[:comment-thread-seqn {:min 0} :int] [:comment-thread-seqn {:min 0} :int]
[:name :string] [:name :string]
@ -326,18 +326,18 @@
[:created-at ::dt/instant] [:created-at ::dt/instant]
[:data {:optional true} :any]]) [:data {:optional true} :any]])
(sm/def! ::permissions-mixin (def schema:permissions-mixin
[:map {:title "PermissionsMixin"} [:map {:title "PermissionsMixin"}
[:permissions ::perms/permissions]]) [:permissions ::perms/permissions]])
(sm/def! ::file-with-permissions (def schema:file-with-permissions
[:merge {:title "FileWithPermissions"} [:merge {:title "FileWithPermissions"}
::file schema:file
::permissions-mixin]) schema:permissions-mixin])
(sm/def! ::get-file (def schema:get-file
[:map {:title "get-file"} [:map {:title "get-file"}
[:features {:optional true} ::features] [:features {:optional true} schema:features]
[:id ::sm/uuid] [:id ::sm/uuid]
[:project-id {:optional true} ::sm/uuid]]) [:project-id {:optional true} ::sm/uuid]])
@ -377,8 +377,8 @@
{::doc/added "1.17" {::doc/added "1.17"
::cond/get-object #(get-minimal-file %1 (:id %2)) ::cond/get-object #(get-minimal-file %1 (:id %2))
::cond/key-fn get-file-etag ::cond/key-fn get-file-etag
::sm/params ::get-file ::sm/params schema:get-file
::sm/result ::file-with-permissions} ::sm/result schema:file-with-permissions}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id features project-id] :as params}] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id features project-id] :as params}]
(dm/with-open [conn (db/open pool)] (dm/with-open [conn (db/open pool)]
(let [perms (get-permissions conn profile-id id)] (let [perms (get-permissions conn profile-id id)]
@ -390,14 +390,14 @@
;; --- COMMAND QUERY: get-file-fragment (by id) ;; --- COMMAND QUERY: get-file-fragment (by id)
(sm/def! ::file-fragment (def schema:file-fragment
[:map {:title "FileFragment"} [:map {:title "FileFragment"}
[:id ::sm/uuid] [:id ::sm/uuid]
[:file-id ::sm/uuid] [:file-id ::sm/uuid]
[:created-at ::dt/instant] [:created-at ::dt/instant]
[:content any?]]) [:content any?]])
(sm/def! ::get-file-fragment (def schema:get-file-fragment
[:map {:title "get-file-fragment"} [:map {:title "get-file-fragment"}
[:file-id ::sm/uuid] [:file-id ::sm/uuid]
[:fragment-id ::sm/uuid] [:fragment-id ::sm/uuid]
@ -411,8 +411,8 @@
(sv/defmethod ::get-file-fragment (sv/defmethod ::get-file-fragment
"Retrieve a file by its ID. Only authenticated users." "Retrieve a file by its ID. Only authenticated users."
{::doc/added "1.17" {::doc/added "1.17"
::sm/params ::get-file-fragment ::sm/params schema:get-file-fragment
::sm/result ::file-fragment} ::sm/result schema:file-fragment}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id] }] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id] }]
(dm/with-open [conn (db/open pool)] (dm/with-open [conn (db/open pool)]
(let [perms (get-permissions conn profile-id file-id share-id)] (let [perms (get-permissions conn profile-id file-id share-id)]
@ -447,12 +447,18 @@
(assoc :thumbnail-uri (resolve-public-uri media-id))) (assoc :thumbnail-uri (resolve-public-uri media-id)))
(dissoc row :media-id)))))) (dissoc row :media-id))))))
(def schema:get-project-files
[:map {:title "get-project-files"}
[:project-id ::sm/uuid]])
(def schema:files
[:vector schema:file])
(sv/defmethod ::get-project-files (sv/defmethod ::get-project-files
"Get all files for the specified project." "Get all files for the specified project."
{::doc/added "1.17" {::doc/added "1.17"
::sm/params [:map {:title "get-project-files"} ::sm/params schema:get-project-files
[:project-id ::sm/uuid]] ::sm/result schema:files}
::sm/result [:vector ::file]}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id]}] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id]}]
(dm/with-open [conn (db/open pool)] (dm/with-open [conn (db/open pool)]
(projects/check-read-permissions! conn profile-id project-id) (projects/check-read-permissions! conn profile-id project-id)
@ -463,11 +469,14 @@
(declare get-has-file-libraries) (declare get-has-file-libraries)
(def schema:has-file-libraries
[:map {:title "has-file-libraries"}
[:file-id ::sm/uuid]])
(sv/defmethod ::has-file-libraries (sv/defmethod ::has-file-libraries
"Checks if the file has libraries. Returns a boolean" "Checks if the file has libraries. Returns a boolean"
{::doc/added "1.15.1" {::doc/added "1.15.1"
::sm/params [:map {:title "has-file-libraries"} ::sm/params schema:has-file-libraries
[:file-id ::sm/uuid]]
::sm/result :boolean} ::sm/result :boolean}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id]}] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id]}]
(dm/with-open [conn (db/open pool)] (dm/with-open [conn (db/open pool)]
@ -522,13 +531,13 @@
(uuid? object-id) (uuid? object-id)
(prune-objects object-id)))) (prune-objects object-id))))
(sm/def! ::get-page (def schema:get-page
[:map {:title "GetPage"} [:map {:title "GetPage"}
[:file-id ::sm/uuid] [:file-id ::sm/uuid]
[:page-id {:optional true} ::sm/uuid] [:page-id {:optional true} ::sm/uuid]
[:share-id {:optional true} ::sm/uuid] [:share-id {:optional true} ::sm/uuid]
[:object-id {:optional true} ::sm/uuid] [:object-id {:optional true} ::sm/uuid]
[:features {:optional true} ::features]]) [:features {:optional true} schema:features]])
(sv/defmethod ::get-page (sv/defmethod ::get-page
"Retrieves the page data from file and returns it. If no page-id is "Retrieves the page data from file and returns it. If no page-id is
@ -541,7 +550,7 @@
Mainly used for rendering purposes." Mainly used for rendering purposes."
{::doc/added "1.17" {::doc/added "1.17"
::sm/params ::get-page} ::sm/params schema:get-page}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id share-id] :as params}] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id share-id] :as params}]
(dm/with-open [conn (db/open pool)] (dm/with-open [conn (db/open pool)]
(let [perms (get-permissions conn profile-id file-id share-id)] (let [perms (get-permissions conn profile-id file-id share-id)]

View file

@ -215,18 +215,25 @@
:always :always
(update :objects assoc-thumbnails page-id thumbs)))))) (update :objects assoc-thumbnails page-id thumbs))))))
(def ^:private schema:get-file-data-for-thumbnail
[:map {:title "get-file-data-for-thumbnail"}
[:file-id ::sm/uuid]
[:features {:optional true} files/schema:features]])
(def ^:private schema:partial-file
[:map {:title "PartialFile"}
[:id ::sm/uuid]
[:revn {:min 0} :int]
[:page :any]])
(sv/defmethod ::get-file-data-for-thumbnail (sv/defmethod ::get-file-data-for-thumbnail
"Retrieves the data for generate the thumbnail of the file. Used "Retrieves the data for generate the thumbnail of the file. Used
mainly for render thumbnails on dashboard." mainly for render thumbnails on dashboard."
{::doc/added "1.17" {::doc/added "1.17"
::sm/params [:map {:title "get-file-data-for-thumbnail"} ::sm/params schema:get-file-data-for-thumbnail
[:file-id ::sm/uuid] ::sm/result schema:partial-file}
[:features {:optional true} ::files/features]]
::sm/result [:map {:title "PartialFile"}
[:id ::sm/uuid]
[:revn {:min 0} :int]
[:page :any]]}
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id features] :as props}] [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id features] :as props}]
(dm/with-open [conn (db/open pool)] (dm/with-open [conn (db/open pool)]
(files/check-read-permissions! conn profile-id file-id) (files/check-read-permissions! conn profile-id file-id)

View file

@ -14,7 +14,6 @@
[app.common.pages.changes :as cpc] [app.common.pages.changes :as cpc]
[app.common.schema :as sm] [app.common.schema :as sm]
[app.common.schema.generators :as smg] [app.common.schema.generators :as smg]
[app.common.spec :as us]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
@ -32,37 +31,7 @@
[app.util.objects-map :as omap] [app.util.objects-map :as omap]
[app.util.pointer-map :as pmap] [app.util.pointer-map :as pmap]
[app.util.services :as sv] [app.util.services :as sv]
[app.util.time :as dt] [app.util.time :as dt]))
[clojure.spec.alpha :as s]))
;; --- SPECS
(s/def ::changes
(s/coll-of map? :kind vector?))
(s/def ::hint-origin ::us/keyword)
(s/def ::hint-events
(s/every ::us/keyword :kind vector?))
(s/def ::change-with-metadata
(s/keys :req-un [::changes]
:opt-un [::hint-origin
::hint-events]))
(s/def ::changes-with-metadata
(s/every ::change-with-metadata :kind vector?))
(s/def ::session-id ::us/uuid)
(s/def ::revn ::us/integer)
(s/def ::update-file
(s/and
(s/keys :req [::rpc/profile-id]
:req-un [::files/id ::session-id ::revn]
:opt-un [::changes ::changes-with-metadata ::features])
(fn [o]
(or (contains? o :changes)
(contains? o :changes-with-metadata)))))
;; --- SCHEMA ;; --- SCHEMA

View file

@ -83,7 +83,7 @@
[:map {:title "get-view-only-bundle"} [:map {:title "get-view-only-bundle"}
[:file-id ::sm/uuid] [:file-id ::sm/uuid]
[:share-id {:optional true} ::sm/uuid] [:share-id {:optional true} ::sm/uuid]
[:features {:optional true} ::files/features]]) [:features {:optional true} files/schema:features]])
(sv/defmethod ::get-view-only-bundle (sv/defmethod ::get-view-only-bundle
{::rpc/auth false {::rpc/auth false