diff --git a/backend/src/app/http/websocket.clj b/backend/src/app/http/websocket.clj index 864de2987..fdcb968af 100644 --- a/backend/src/app/http/websocket.clj +++ b/backend/src/app/http/websocket.clj @@ -279,9 +279,8 @@ message) (def ^:private schema:params - (sm/define - [:map {:title "params"} - [:session-id ::sm/uuid]])) + [:map {:title "params"} + [:session-id ::sm/uuid]]) (defn- http-handler [cfg {:keys [params ::session/profile-id] :as request}] diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 79381d34f..e158d196e 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -174,38 +174,34 @@ ;; --- COMMAND QUERY: get-file (by id) (def schema:file - (sm/define - [:map {:title "File"} - [:id ::sm/uuid] - [:features ::cfeat/features] - [:has-media-trimmed ::sm/boolean] - [:comment-thread-seqn [::sm/int {:min 0}]] - [:name [:string {:max 250}]] - [:revn [::sm/int {:min 0}]] - [:modified-at ::dt/instant] - [:is-shared ::sm/boolean] - [:project-id ::sm/uuid] - [:created-at ::dt/instant] - [:data {:optional true} :any]])) + [:map {:title "File"} + [:id ::sm/uuid] + [:features ::cfeat/features] + [:has-media-trimmed ::sm/boolean] + [:comment-thread-seqn [::sm/int {:min 0}]] + [:name [:string {:max 250}]] + [:revn [::sm/int {:min 0}]] + [:modified-at ::dt/instant] + [:is-shared ::sm/boolean] + [:project-id ::sm/uuid] + [:created-at ::dt/instant] + [:data {:optional true} :any]]) (def schema:permissions-mixin - (sm/define - [:map {:title "PermissionsMixin"} - [:permissions ::perms/permissions]])) + [:map {:title "PermissionsMixin"} + [:permissions ::perms/permissions]]) (def schema:file-with-permissions - (sm/define - [:merge {:title "FileWithPermissions"} - schema:file - schema:permissions-mixin])) + [:merge {:title "FileWithPermissions"} + schema:file + schema:permissions-mixin]) (def ^:private schema:get-file - (sm/define - [:map {:title "get-file"} - [:features {:optional true} ::cfeat/features] - [:id ::sm/uuid] - [:project-id {:optional true} ::sm/uuid]])) + [:map {:title "get-file"} + [:features {:optional true} ::cfeat/features] + [:id ::sm/uuid] + [:project-id {:optional true} ::sm/uuid]]) (defn- migrate-file [{:keys [::db/conn] :as cfg} {:keys [id] :as file}] @@ -914,10 +910,9 @@ (def ^:private schema:set-file-shared - (sm/define - [:map {:title "set-file-shared"} - [:id ::sm/uuid] - [:is-shared ::sm/boolean]])) + [:map {:title "set-file-shared"} + [:id ::sm/uuid] + [:is-shared ::sm/boolean]]) (sv/defmethod ::set-file-shared {::doc/added "1.17" @@ -944,9 +939,8 @@ (def ^:private schema:delete-file - (sm/define - [:map {:title "delete-file"} - [:id ::sm/uuid]])) + [:map {:title "delete-file"} + [:id ::sm/uuid]]) (defn- delete-file [{:keys [::db/conn] :as cfg} {:keys [profile-id id] :as params}] @@ -978,10 +972,9 @@ (def ^:private schema:link-file-to-library - (sm/define - [:map {:title "link-file-to-library"} - [:file-id ::sm/uuid] - [:library-id ::sm/uuid]])) + [:map {:title "link-file-to-library"} + [:file-id ::sm/uuid] + [:library-id ::sm/uuid]]) (sv/defmethod ::link-file-to-library {::doc/added "1.17" diff --git a/backend/src/app/rpc/commands/files_thumbnails.clj b/backend/src/app/rpc/commands/files_thumbnails.clj index 8e9c2da1c..2ff3d34a4 100644 --- a/backend/src/app/rpc/commands/files_thumbnails.clj +++ b/backend/src/app/rpc/commands/files_thumbnails.clj @@ -179,18 +179,16 @@ (def ^:private schema:get-file-data-for-thumbnail - (sm/define - [:map {:title "get-file-data-for-thumbnail"} - [:file-id ::sm/uuid] - [:features {:optional true} ::cfeat/features]])) + [:map {:title "get-file-data-for-thumbnail"} + [:file-id ::sm/uuid] + [:features {:optional true} ::cfeat/features]]) (def ^:private schema:partial-file - (sm/define - [:map {:title "PartialFile"} - [:id ::sm/uuid] - [:revn {:min 0} ::sm/int] - [:page :any]])) + [:map {:title "PartialFile"} + [:id ::sm/uuid] + [:revn {:min 0} ::sm/int] + [:page :any]]) (sv/defmethod ::get-file-data-for-thumbnail "Retrieves the data for generate the thumbnail of the file. Used diff --git a/backend/src/app/rpc/commands/management.clj b/backend/src/app/rpc/commands/management.clj index 30d0d3460..fc71a509d 100644 --- a/backend/src/app/rpc/commands/management.clj +++ b/backend/src/app/rpc/commands/management.clj @@ -88,10 +88,9 @@ (def ^:private schema:duplicate-file - (sm/define - [:map {:title "duplicate-file"} - [:file-id ::sm/uuid] - [:name {:optional true} [:string {:max 250}]]])) + [:map {:title "duplicate-file"} + [:file-id ::sm/uuid] + [:name {:optional true} [:string {:max 250}]]]) (sv/defmethod ::duplicate-file "Duplicate a single file in the same team." @@ -150,10 +149,9 @@ (def ^:private schema:duplicate-project - (sm/define - [:map {:title "duplicate-project"} - [:project-id ::sm/uuid] - [:name {:optional true} [:string {:max 250}]]])) + [:map {:title "duplicate-project"} + [:project-id ::sm/uuid] + [:name {:optional true} [:string {:max 250}]]]) (sv/defmethod ::duplicate-project "Duplicate an entire project with all the files" @@ -327,10 +325,9 @@ (def ^:private schema:move-files - (sm/define - [:map {:title "move-files"} - [:ids ::sm/set-of-uuid] - [:project-id ::sm/uuid]])) + [:map {:title "move-files"} + [:ids ::sm/set-of-uuid] + [:project-id ::sm/uuid]]) (sv/defmethod ::move-files "Move a set of files from one project to other." diff --git a/backend/src/app/rpc/commands/profile.clj b/backend/src/app/rpc/commands/profile.clj index 69a093aa2..7b39abd15 100644 --- a/backend/src/app/rpc/commands/profile.clj +++ b/backend/src/app/rpc/commands/profile.clj @@ -109,11 +109,10 @@ (def ^:private schema:update-profile - (sm/define - [:map {:title "update-profile"} - [:fullname [::sm/word-string {:max 250}]] - [:lang {:optional true} [:string {:max 8}]] - [:theme {:optional true} [:string {:max 250}]]])) + [:map {:title "update-profile"} + [:fullname [::sm/word-string {:max 250}]] + [:lang {:optional true} [:string {:max 8}]] + [:theme {:optional true} [:string {:max 250}]]]) (sv/defmethod ::update-profile {::doc/added "1.0" @@ -154,11 +153,10 @@ (def ^:private schema:update-profile-password - (sm/define - [:map {:title "update-profile-password"} - [:password [::sm/word-string {:max 500}]] - ;; Social registered users don't have old-password - [:old-password {:optional true} [:maybe [::sm/word-string {:max 500}]]]])) + [:map {:title "update-profile-password"} + [:password [::sm/word-string {:max 500}]] + ;; Social registered users don't have old-password + [:old-password {:optional true} [:maybe [::sm/word-string {:max 500}]]]]) (sv/defmethod ::update-profile-password {::doc/added "1.0" @@ -209,9 +207,8 @@ (def ^:private schema:update-profile-photo - (sm/define - [:map {:title "update-profile-photo"} - [:file ::media/upload]])) + [:map {:title "update-profile-photo"} + [:file ::media/upload]]) (sv/defmethod ::update-profile-photo {:doc/added "1.1" @@ -278,9 +275,8 @@ (def ^:private schema:request-email-change - (sm/define - [:map {:title "request-email-change"} - [:email ::sm/email]])) + [:map {:title "request-email-change"} + [:email ::sm/email]]) (sv/defmethod ::request-email-change {::doc/added "1.0" diff --git a/backend/src/app/rpc/quotes.clj b/backend/src/app/rpc/quotes.clj index c42a2de81..bdcab5df3 100644 --- a/backend/src/app/rpc/quotes.clj +++ b/backend/src/app/rpc/quotes.clj @@ -26,14 +26,13 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (def ^:private schema:quote - (sm/define - [:map {:title "Quote"} - [::team-id {:optional true} ::sm/uuid] - [::project-id {:optional true} ::sm/uuid] - [::file-id {:optional true} ::sm/uuid] - [::incr {:optional true} [::sm/int {:min 0}]] - [::id :keyword] - [::profile-id ::sm/uuid]])) + [:map {:title "Quote"} + [::team-id {:optional true} ::sm/uuid] + [::project-id {:optional true} ::sm/uuid] + [::file-id {:optional true} ::sm/uuid] + [::incr {:optional true} [::sm/int {:min 0}]] + [::id :keyword] + [::profile-id ::sm/uuid]]) (def ^:private enabled (volatile! true)) diff --git a/backend/src/app/setup/templates.clj b/backend/src/app/setup/templates.clj index 3c70c7dbc..7082f4d81 100644 --- a/backend/src/app/setup/templates.clj +++ b/backend/src/app/setup/templates.clj @@ -21,16 +21,14 @@ (def ^:private schema:template - (sm/define - [:map {:title "Template"} - [:id ::sm/word-string] - [:name ::sm/word-string] - [:file-uri ::sm/word-string]])) + [:map {:title "Template"} + [:id ::sm/word-string] + [:name ::sm/word-string] + [:file-uri ::sm/word-string]]) (def ^:private schema:templates - (sm/define - [:vector schema:template])) + [:vector schema:template]) (defmethod ig/init-key ::setup/templates [_ _] diff --git a/frontend/src/app/main/data/comments.cljs b/frontend/src/app/main/data/comments.cljs index 0a441068f..0229db75a 100644 --- a/frontend/src/app/main/data/comments.cljs +++ b/frontend/src/app/main/data/comments.cljs @@ -19,33 +19,31 @@ [potok.v2.core :as ptk])) (def ^:private schema:comment-thread - (sm/define - [:map {:title "CommentThread"} - [:id ::sm/uuid] - [:page-id ::sm/uuid] - [:file-id ::sm/uuid] - [:project-id ::sm/uuid] - [:owner-id ::sm/uuid] - [:page-name :string] - [:file-name :string] - [:seqn :int] - [:content :string] - [:participants ::sm/set-of-uuid] - [:created-at ::sm/inst] - [:modified-at ::sm/inst] - [:position ::gpt/point] - [:count-unread-comments {:optional true} :int] - [:count-comments {:optional true} :int]])) + [:map {:title "CommentThread"} + [:id ::sm/uuid] + [:page-id ::sm/uuid] + [:file-id ::sm/uuid] + [:project-id ::sm/uuid] + [:owner-id ::sm/uuid] + [:page-name :string] + [:file-name :string] + [:seqn :int] + [:content :string] + [:participants ::sm/set-of-uuid] + [:created-at ::sm/inst] + [:modified-at ::sm/inst] + [:position ::gpt/point] + [:count-unread-comments {:optional true} :int] + [:count-comments {:optional true} :int]]) (def ^:private schema:comment - (sm/define - [:map {:title "Comment"} - [:id ::sm/uuid] - [:thread-id ::sm/uuid] - [:owner-id ::sm/uuid] - [:created-at ::sm/inst] - [:modified-at ::sm/inst] - [:content :string]])) + [:map {:title "Comment"} + [:id ::sm/uuid] + [:thread-id ::sm/uuid] + [:owner-id ::sm/uuid] + [:created-at ::sm/inst] + [:modified-at ::sm/inst] + [:content :string]]) (def check-comment-thread! (sm/check-fn schema:comment-thread)) @@ -84,12 +82,11 @@ (def ^:private schema:create-thread-on-workspace - (sm/define - [:map {:title "created-thread-on-workspace"} - [:page-id ::sm/uuid] - [:file-id ::sm/uuid] - [:position ::gpt/point] - [:content :string]])) + [:map {:title "created-thread-on-workspace"} + [:page-id ::sm/uuid] + [:file-id ::sm/uuid] + [:position ::gpt/point] + [:content :string]]) (defn create-thread-on-workspace [params] @@ -136,13 +133,12 @@ (def ^:private schema:create-thread-on-viewer - (sm/define - [:map {:title "created-thread-on-viewer"} - [:page-id ::sm/uuid] - [:file-id ::sm/uuid] - [:frame-id ::sm/uuid] - [:position ::gpt/point] - [:content :string]])) + [:map {:title "created-thread-on-viewer"} + [:page-id ::sm/uuid] + [:file-id ::sm/uuid] + [:frame-id ::sm/uuid] + [:position ::gpt/point] + [:content :string]]) (defn create-thread-on-viewer [params] @@ -469,11 +465,10 @@ (def ^:private schema:create-draft - (sm/define - [:map {:title "create-draft"} - [:page-id ::sm/uuid] - [:file-id ::sm/uuid] - [:position ::gpt/point]])) + [:map {:title "create-draft"} + [:page-id ::sm/uuid] + [:file-id ::sm/uuid] + [:position ::gpt/point]]) (defn create-draft [params] diff --git a/frontend/src/app/main/data/shortcuts.cljs b/frontend/src/app/main/data/shortcuts.cljs index 55ea364a3..34f6e0496 100644 --- a/frontend/src/app/main/data/shortcuts.cljs +++ b/frontend/src/app/main/data/shortcuts.cljs @@ -129,12 +129,11 @@ (def ^:private schema:shortcuts - (sm/define - [:map-of :keyword - [:map - [:command [:or :string [:vector :any]]] - [:fn {:optional true} fn?] - [:tooltip {:optional true} :string]]])) + [:map-of :keyword + [:map + [:command [:or :string [:vector :any]]] + [:fn {:optional true} fn?] + [:tooltip {:optional true} :string]]]) (def check-shortcuts! (sm/check-fn schema:shortcuts)) diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index 2ea229577..73726c591 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -32,14 +32,13 @@ (def ^:private schema:profile - (sm/define - [:map {:title "Profile"} - [:id ::sm/uuid] - [:created-at {:optional true} :any] - [:fullname {:optional true} :string] - [:email {:optional true} :string] - [:lang {:optional true} :string] - [:theme {:optional true} :string]])) + [:map {:title "Profile"} + [:id ::sm/uuid] + [:created-at {:optional true} :any] + [:fullname {:optional true} :string] + [:email {:optional true} :string] + [:lang {:optional true} :string] + [:theme {:optional true} :string]]) (def check-profile! (sm/check-fn schema:profile)) @@ -253,10 +252,9 @@ (rx/catch on-error)))))) (def ^:private schema:login-with-ldap - (sm/define - [:map - [:email ::sm/email] - [:password :string]])) + [:map {:title "login-with-ldap"} + [:email ::sm/email] + [:password :string]]) (defn login-with-ldap [params] @@ -486,6 +484,7 @@ ;; TODO: for the release 1.13 we should skip fetching profile and just use ;; the response value of update-profile-props RPC call + ;; FIXME ptk/WatchEvent (watch [_ _ _] (->> (rp/cmd! :update-profile-props {:props props}) @@ -595,9 +594,8 @@ (def ^:private schema:request-profile-recovery - (sm/define - [:map {:title "request-profile-recovery" :closed true} - [:email ::sm/email]])) + [:map {:title "request-profile-recovery" :closed true} + [:email ::sm/email]]) (defn request-profile-recovery [data] @@ -621,10 +619,9 @@ (def ^:private schema:recover-profile - (sm/define - [:map {:title "recover-profile" :closed true} - [:password :string] - [:token :string]])) + [:map {:title "recover-profile" :closed true} + [:password :string] + [:token :string]]) (defn recover-profile [data] diff --git a/frontend/src/app/main/data/viewer.cljs b/frontend/src/app/main/data/viewer.cljs index 68757d15d..d2a9bdd59 100644 --- a/frontend/src/app/main/data/viewer.cljs +++ b/frontend/src/app/main/data/viewer.cljs @@ -49,11 +49,10 @@ (def ^:private schema:initialize - (sm/define - [:map {:title "initialize"} - [:file-id ::sm/uuid] - [:share-id {:optional true} [:maybe ::sm/uuid]] - [:page-id {:optional true} ::sm/uuid]])) + [:map {:title "initialize"} + [:file-id ::sm/uuid] + [:share-id {:optional true} [:maybe ::sm/uuid]] + [:page-id {:optional true} ::sm/uuid]]) (defn initialize [{:keys [file-id share-id interactions-show?] :as params}] @@ -102,11 +101,10 @@ (def ^:private schema:fetch-bundle - (sm/define - [:map {:title "fetch-bundle"} - [:page-id ::sm/uuid] - [:file-id ::sm/uuid] - [:share-id {:optional true} ::sm/uuid]])) + [:map {:title "fetch-bundle"} + [:page-id ::sm/uuid] + [:file-id ::sm/uuid] + [:share-id {:optional true} ::sm/uuid]]) (defn- fetch-bundle [{:keys [file-id share-id] :as params}] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index a557992bb..2a60496b2 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1676,17 +1676,19 @@ (def ^:private schema:paste-data - (sm/define - [:map {:title "paste-data"} - [:type [:= :copied-shapes]] - [:features ::sm/set-of-strings] - [:version :int] - [:file-id ::sm/uuid] - [:selected ::sm/set-of-uuid] - [:objects - [:map-of ::sm/uuid :map]] - [:images [:set :map]] - [:position {:optional true} ::gpt/point]])) + [:map {:title "paste-data"} + [:type [:= :copied-shapes]] + [:features ::sm/set-of-strings] + [:version :int] + [:file-id ::sm/uuid] + [:selected ::sm/set-of-uuid] + [:objects + [:map-of ::sm/uuid :map]] + [:images [:set :map]] + [:position {:optional true} ::gpt/point]]) + +(def validate-paste-data! + (sm/validate-fn schema:paste-data)) (defn- paste-transit [{:keys [images] :as pdata}] @@ -1711,9 +1713,8 @@ (let [file-id (:current-file-id state) features (features/get-team-enabled-features state)] - (sm/validate! schema:paste-data pdata - {:hint "invalid paste data" - :code :invalid-paste-data}) + (validate-paste-data! pdata {:hint "invalid paste data" + :code :invalid-paste-data}) (cfeat/check-paste-features! features (:features pdata)) (if (= file-id (:file-id pdata)) diff --git a/frontend/src/app/main/data/workspace/media.cljs b/frontend/src/app/main/data/workspace/media.cljs index f14c74e17..a75012717 100644 --- a/frontend/src/app/main/data/workspace/media.cljs +++ b/frontend/src/app/main/data/workspace/media.cljs @@ -200,14 +200,13 @@ (def ^:private schema:process-media-objects - (sm/define - [:map {:title "process-media-objects"} - [:file-id ::sm/uuid] - [:local? :boolean] - [:name {:optional true} :string] - [:data {:optional true} :any] ; FIXME - [:uris {:optional true} [:sequential :string]] - [:mtype {:optional true} :string]])) + [:map {:title "process-media-objects"} + [:file-id ::sm/uuid] + [:local? :boolean] + [:name {:optional true} :string] + [:data {:optional true} :any] ; FIXME + [:uris {:optional true} [:sequential :string]] + [:mtype {:optional true} :string]]) (defn- process-media-objects [{:keys [uris on-error] :as params}] @@ -427,10 +426,9 @@ (def ^:private schema:clone-media-object - (sm/define - [:map {:title "clone-media-object"} - [:file-id ::sm/uuid] - [:object-id ::sm/uuid]])) + [:map {:title "clone-media-object"} + [:file-id ::sm/uuid] + [:object-id ::sm/uuid]]) (defn clone-media-object [{:keys [file-id object-id] :as params}] diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index b756579de..e602618e1 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -198,21 +198,23 @@ (def ^:private schema:handle-file-change - (sm/define - [:map {:title "handle-file-change"} - [:type :keyword] - [:profile-id ::sm/uuid] - [:file-id ::sm/uuid] - [:session-id ::sm/uuid] - [:revn :int] - [:changes ::cpc/changes]])) + [:map {:title "handle-file-change"} + [:type :keyword] + [:profile-id ::sm/uuid] + [:file-id ::sm/uuid] + [:session-id ::sm/uuid] + [:revn :int] + [:changes ::cpc/changes]]) + +(def ^:private check-file-change-params! + (sm/check-fn schema:handle-file-change)) (defn handle-file-change [{:keys [file-id changes revn] :as msg}] (dm/assert! "expected valid parameters" - (sm/check! schema:handle-file-change msg)) + (check-file-change-params! msg)) (ptk/reify ::handle-file-change IDeref @@ -230,23 +232,24 @@ :redo-changes (vec changes) :undo-changes []}))))) -(def ^:private - schema:handle-library-change - (sm/define - [:map {:title "handle-library-change"} - [:type :keyword] - [:profile-id ::sm/uuid] - [:file-id ::sm/uuid] - [:session-id ::sm/uuid] - [:revn :int] - [:modified-at ::sm/inst] - [:changes ::cpc/changes]])) +(def ^:private schema:handle-library-change + [:map {:title "handle-library-change"} + [:type :keyword] + [:profile-id ::sm/uuid] + [:file-id ::sm/uuid] + [:session-id ::sm/uuid] + [:revn :int] + [:modified-at ::sm/inst] + [:changes ::cpc/changes]]) + +(def ^:private check-library-change-params! + (sm/check-fn schema:handle-library-change)) (defn handle-library-change [{:keys [file-id modified-at changes revn] :as msg}] (dm/assert! "expected valid arguments" - (sm/check! schema:handle-library-change msg)) + (check-library-change-params! msg)) (ptk/reify ::handle-library-change ptk/WatchEvent diff --git a/frontend/src/app/main/data/workspace/path/common.cljs b/frontend/src/app/main/data/workspace/path/common.cljs index 8edd06ffe..483302177 100644 --- a/frontend/src/app/main/data/workspace/path/common.cljs +++ b/frontend/src/app/main/data/workspace/path/common.cljs @@ -27,20 +27,19 @@ (def ^:private schema:path-content - (sm/define - [:vector {:title "PathContent"} - [:map {:title "PathContentEntry"} - [:command [::sm/one-of valid-commands]] - ;; FIXME: remove the `?` from prop name - [:relative? {:optional true} :boolean] - [:params {:optional true} - [:map {:title "PathContentEntryParams"} - [:x :double] - [:y :double] - [:c1x {:optional true} :double] - [:c1y {:optional true} :double] - [:c2x {:optional true} :double] - [:c2y {:optional true} :double]]]]])) + [:vector {:title "PathContent"} + [:map {:title "PathContentEntry"} + [:command [::sm/one-of valid-commands]] + ;; FIXME: remove the `?` from prop name + [:relative? {:optional true} :boolean] + [:params {:optional true} + [:map {:title "PathContentEntryParams"} + [:x :double] + [:y :double] + [:c1x {:optional true} :double] + [:c1y {:optional true} :double] + [:c2x {:optional true} :double] + [:c2y {:optional true} :double]]]]]) (def check-path-content! (sm/check-fn schema:path-content)) diff --git a/frontend/src/app/main/data/workspace/undo.cljs b/frontend/src/app/main/data/workspace/undo.cljs index 41f3fe1a1..529965fbb 100644 --- a/frontend/src/app/main/data/workspace/undo.cljs +++ b/frontend/src/app/main/data/workspace/undo.cljs @@ -26,10 +26,9 @@ (def ^:private schema:undo-entry - (sm/define - [:map {:title "undo-entry"} - [:undo-changes [:vector ::cpc/change]] - [:redo-changes [:vector ::cpc/change]]])) + [:map {:title "undo-entry"} + [:undo-changes [:vector ::cpc/change]] + [:redo-changes [:vector ::cpc/change]]]) (def check-undo-entry! (sm/check-fn schema:undo-entry)) diff --git a/frontend/src/app/worker.cljs b/frontend/src/app/worker.cljs index 4b36decc9..f308d6179 100644 --- a/frontend/src/app/worker.cljs +++ b/frontend/src/app/worker.cljs @@ -24,24 +24,27 @@ ;; --- Messages Handling -(def ^:private - schema:message - (sm/define - [:map {:title "WorkerMessage"} - [:sender-id ::sm/uuid] - [:payload - [:map - [:cmd :keyword]]] - [:buffer? {:optional true} :boolean]])) +(def ^:private schema:message + [:map {:title "WorkerMessage"} + [:sender-id ::sm/uuid] + [:payload + [:map + [:cmd :keyword]]] + [:buffer? {:optional true} :boolean]]) + +(def ^:private check-message! + (sm/check-fn schema:message)) (def buffer (rx/subject)) (defn- handle-message "Process the message and returns to the client" [{:keys [sender-id payload transfer] :as message}] + (dm/assert! "expected valid message" - (sm/check! schema:message message)) + (check-message! message)) + (letfn [(post [msg] (let [msg (-> msg (assoc :reply-to sender-id) (wm/encode))] (.postMessage js/self msg)))