🔥 Remove usage of public usage of sm/define funcion

This commit is contained in:
Andrey Antukh 2024-09-10 17:34:21 +02:00 committed by Alonso Torres
parent cdcff62232
commit b882b9e283
17 changed files with 216 additions and 244 deletions

View file

@ -279,9 +279,8 @@
message) message)
(def ^:private schema:params (def ^:private schema:params
(sm/define [:map {:title "params"}
[:map {:title "params"} [:session-id ::sm/uuid]])
[:session-id ::sm/uuid]]))
(defn- http-handler (defn- http-handler
[cfg {:keys [params ::session/profile-id] :as request}] [cfg {:keys [params ::session/profile-id] :as request}]

View file

@ -174,38 +174,34 @@
;; --- COMMAND QUERY: get-file (by id) ;; --- COMMAND QUERY: get-file (by id)
(def schema:file (def schema:file
(sm/define [:map {:title "File"}
[:map {:title "File"} [:id ::sm/uuid]
[:id ::sm/uuid] [:features ::cfeat/features]
[:features ::cfeat/features] [:has-media-trimmed ::sm/boolean]
[:has-media-trimmed ::sm/boolean] [:comment-thread-seqn [::sm/int {:min 0}]]
[:comment-thread-seqn [::sm/int {:min 0}]] [:name [:string {:max 250}]]
[:name [:string {:max 250}]] [:revn [::sm/int {:min 0}]]
[:revn [::sm/int {:min 0}]] [:modified-at ::dt/instant]
[:modified-at ::dt/instant] [:is-shared ::sm/boolean]
[:is-shared ::sm/boolean] [:project-id ::sm/uuid]
[:project-id ::sm/uuid] [:created-at ::dt/instant]
[:created-at ::dt/instant] [:data {:optional true} :any]])
[:data {:optional true} :any]]))
(def schema:permissions-mixin (def schema:permissions-mixin
(sm/define [:map {:title "PermissionsMixin"}
[:map {:title "PermissionsMixin"} [:permissions ::perms/permissions]])
[:permissions ::perms/permissions]]))
(def schema:file-with-permissions (def schema:file-with-permissions
(sm/define [:merge {:title "FileWithPermissions"}
[:merge {:title "FileWithPermissions"} schema:file
schema:file schema:permissions-mixin])
schema:permissions-mixin]))
(def ^:private (def ^:private
schema:get-file schema:get-file
(sm/define [:map {:title "get-file"}
[:map {:title "get-file"} [:features {:optional true} ::cfeat/features]
[:features {:optional true} ::cfeat/features] [:id ::sm/uuid]
[:id ::sm/uuid] [:project-id {:optional true} ::sm/uuid]])
[:project-id {:optional true} ::sm/uuid]]))
(defn- migrate-file (defn- migrate-file
[{:keys [::db/conn] :as cfg} {:keys [id] :as file}] [{:keys [::db/conn] :as cfg} {:keys [id] :as file}]
@ -914,10 +910,9 @@
(def ^:private (def ^:private
schema:set-file-shared schema:set-file-shared
(sm/define [:map {:title "set-file-shared"}
[:map {:title "set-file-shared"} [:id ::sm/uuid]
[:id ::sm/uuid] [:is-shared ::sm/boolean]])
[:is-shared ::sm/boolean]]))
(sv/defmethod ::set-file-shared (sv/defmethod ::set-file-shared
{::doc/added "1.17" {::doc/added "1.17"
@ -944,9 +939,8 @@
(def ^:private (def ^:private
schema:delete-file schema:delete-file
(sm/define [:map {:title "delete-file"}
[:map {:title "delete-file"} [:id ::sm/uuid]])
[:id ::sm/uuid]]))
(defn- delete-file (defn- delete-file
[{:keys [::db/conn] :as cfg} {:keys [profile-id id] :as params}] [{:keys [::db/conn] :as cfg} {:keys [profile-id id] :as params}]
@ -978,10 +972,9 @@
(def ^:private (def ^:private
schema:link-file-to-library schema:link-file-to-library
(sm/define [:map {:title "link-file-to-library"}
[:map {:title "link-file-to-library"} [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:library-id ::sm/uuid]])
[:library-id ::sm/uuid]]))
(sv/defmethod ::link-file-to-library (sv/defmethod ::link-file-to-library
{::doc/added "1.17" {::doc/added "1.17"

View file

@ -179,18 +179,16 @@
(def ^:private (def ^:private
schema:get-file-data-for-thumbnail schema:get-file-data-for-thumbnail
(sm/define [:map {:title "get-file-data-for-thumbnail"}
[:map {:title "get-file-data-for-thumbnail"} [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:features {:optional true} ::cfeat/features]])
[:features {:optional true} ::cfeat/features]]))
(def ^:private (def ^:private
schema:partial-file schema:partial-file
(sm/define [:map {:title "PartialFile"}
[:map {:title "PartialFile"} [:id ::sm/uuid]
[:id ::sm/uuid] [:revn {:min 0} ::sm/int]
[:revn {:min 0} ::sm/int] [:page :any]])
[: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

View file

@ -88,10 +88,9 @@
(def ^:private (def ^:private
schema:duplicate-file schema:duplicate-file
(sm/define [:map {:title "duplicate-file"}
[:map {:title "duplicate-file"} [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:name {:optional true} [:string {:max 250}]]])
[:name {:optional true} [:string {:max 250}]]]))
(sv/defmethod ::duplicate-file (sv/defmethod ::duplicate-file
"Duplicate a single file in the same team." "Duplicate a single file in the same team."
@ -150,10 +149,9 @@
(def ^:private (def ^:private
schema:duplicate-project schema:duplicate-project
(sm/define [:map {:title "duplicate-project"}
[:map {:title "duplicate-project"} [:project-id ::sm/uuid]
[:project-id ::sm/uuid] [:name {:optional true} [:string {:max 250}]]])
[:name {:optional true} [:string {:max 250}]]]))
(sv/defmethod ::duplicate-project (sv/defmethod ::duplicate-project
"Duplicate an entire project with all the files" "Duplicate an entire project with all the files"
@ -327,10 +325,9 @@
(def ^:private (def ^:private
schema:move-files schema:move-files
(sm/define [:map {:title "move-files"}
[:map {:title "move-files"} [:ids ::sm/set-of-uuid]
[:ids ::sm/set-of-uuid] [:project-id ::sm/uuid]])
[:project-id ::sm/uuid]]))
(sv/defmethod ::move-files (sv/defmethod ::move-files
"Move a set of files from one project to other." "Move a set of files from one project to other."

View file

@ -109,11 +109,10 @@
(def ^:private (def ^:private
schema:update-profile schema:update-profile
(sm/define [:map {:title "update-profile"}
[:map {:title "update-profile"} [:fullname [::sm/word-string {:max 250}]]
[:fullname [::sm/word-string {:max 250}]] [:lang {:optional true} [:string {:max 8}]]
[:lang {:optional true} [:string {:max 8}]] [:theme {:optional true} [:string {:max 250}]]])
[:theme {:optional true} [:string {:max 250}]]]))
(sv/defmethod ::update-profile (sv/defmethod ::update-profile
{::doc/added "1.0" {::doc/added "1.0"
@ -154,11 +153,10 @@
(def ^:private (def ^:private
schema:update-profile-password schema:update-profile-password
(sm/define [:map {:title "update-profile-password"}
[:map {:title "update-profile-password"} [:password [::sm/word-string {:max 500}]]
[:password [::sm/word-string {:max 500}]] ;; Social registered users don't have old-password
;; Social registered users don't have old-password [:old-password {:optional true} [:maybe [::sm/word-string {:max 500}]]]])
[:old-password {:optional true} [:maybe [::sm/word-string {:max 500}]]]]))
(sv/defmethod ::update-profile-password (sv/defmethod ::update-profile-password
{::doc/added "1.0" {::doc/added "1.0"
@ -209,9 +207,8 @@
(def ^:private (def ^:private
schema:update-profile-photo schema:update-profile-photo
(sm/define [:map {:title "update-profile-photo"}
[:map {:title "update-profile-photo"} [:file ::media/upload]])
[:file ::media/upload]]))
(sv/defmethod ::update-profile-photo (sv/defmethod ::update-profile-photo
{:doc/added "1.1" {:doc/added "1.1"
@ -278,9 +275,8 @@
(def ^:private (def ^:private
schema:request-email-change schema:request-email-change
(sm/define [:map {:title "request-email-change"}
[:map {:title "request-email-change"} [:email ::sm/email]])
[:email ::sm/email]]))
(sv/defmethod ::request-email-change (sv/defmethod ::request-email-change
{::doc/added "1.0" {::doc/added "1.0"

View file

@ -26,14 +26,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:private schema:quote (def ^:private schema:quote
(sm/define [:map {:title "Quote"}
[:map {:title "Quote"} [::team-id {:optional true} ::sm/uuid]
[::team-id {:optional true} ::sm/uuid] [::project-id {:optional true} ::sm/uuid]
[::project-id {:optional true} ::sm/uuid] [::file-id {:optional true} ::sm/uuid]
[::file-id {:optional true} ::sm/uuid] [::incr {:optional true} [::sm/int {:min 0}]]
[::incr {:optional true} [::sm/int {:min 0}]] [::id :keyword]
[::id :keyword] [::profile-id ::sm/uuid]])
[::profile-id ::sm/uuid]]))
(def ^:private enabled (volatile! true)) (def ^:private enabled (volatile! true))

View file

@ -21,16 +21,14 @@
(def ^:private (def ^:private
schema:template schema:template
(sm/define [:map {:title "Template"}
[:map {:title "Template"} [:id ::sm/word-string]
[:id ::sm/word-string] [:name ::sm/word-string]
[:name ::sm/word-string] [:file-uri ::sm/word-string]])
[:file-uri ::sm/word-string]]))
(def ^:private (def ^:private
schema:templates schema:templates
(sm/define [:vector schema:template])
[:vector schema:template]))
(defmethod ig/init-key ::setup/templates (defmethod ig/init-key ::setup/templates
[_ _] [_ _]

View file

@ -19,33 +19,31 @@
[potok.v2.core :as ptk])) [potok.v2.core :as ptk]))
(def ^:private schema:comment-thread (def ^:private schema:comment-thread
(sm/define [:map {:title "CommentThread"}
[:map {:title "CommentThread"} [:id ::sm/uuid]
[:id ::sm/uuid] [:page-id ::sm/uuid]
[:page-id ::sm/uuid] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:project-id ::sm/uuid]
[:project-id ::sm/uuid] [:owner-id ::sm/uuid]
[:owner-id ::sm/uuid] [:page-name :string]
[:page-name :string] [:file-name :string]
[:file-name :string] [:seqn :int]
[:seqn :int] [:content :string]
[:content :string] [:participants ::sm/set-of-uuid]
[:participants ::sm/set-of-uuid] [:created-at ::sm/inst]
[:created-at ::sm/inst] [:modified-at ::sm/inst]
[:modified-at ::sm/inst] [:position ::gpt/point]
[:position ::gpt/point] [:count-unread-comments {:optional true} :int]
[:count-unread-comments {:optional true} :int] [:count-comments {:optional true} :int]])
[:count-comments {:optional true} :int]]))
(def ^:private schema:comment (def ^:private schema:comment
(sm/define [:map {:title "Comment"}
[:map {:title "Comment"} [:id ::sm/uuid]
[:id ::sm/uuid] [:thread-id ::sm/uuid]
[:thread-id ::sm/uuid] [:owner-id ::sm/uuid]
[:owner-id ::sm/uuid] [:created-at ::sm/inst]
[:created-at ::sm/inst] [:modified-at ::sm/inst]
[:modified-at ::sm/inst] [:content :string]])
[:content :string]]))
(def check-comment-thread! (def check-comment-thread!
(sm/check-fn schema:comment-thread)) (sm/check-fn schema:comment-thread))
@ -84,12 +82,11 @@
(def ^:private (def ^:private
schema:create-thread-on-workspace schema:create-thread-on-workspace
(sm/define [:map {:title "created-thread-on-workspace"}
[:map {:title "created-thread-on-workspace"} [:page-id ::sm/uuid]
[:page-id ::sm/uuid] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:position ::gpt/point]
[:position ::gpt/point] [:content :string]])
[:content :string]]))
(defn create-thread-on-workspace (defn create-thread-on-workspace
[params] [params]
@ -136,13 +133,12 @@
(def ^:private (def ^:private
schema:create-thread-on-viewer schema:create-thread-on-viewer
(sm/define [:map {:title "created-thread-on-viewer"}
[:map {:title "created-thread-on-viewer"} [:page-id ::sm/uuid]
[:page-id ::sm/uuid] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:frame-id ::sm/uuid]
[:frame-id ::sm/uuid] [:position ::gpt/point]
[:position ::gpt/point] [:content :string]])
[:content :string]]))
(defn create-thread-on-viewer (defn create-thread-on-viewer
[params] [params]
@ -469,11 +465,10 @@
(def ^:private (def ^:private
schema:create-draft schema:create-draft
(sm/define [:map {:title "create-draft"}
[:map {:title "create-draft"} [:page-id ::sm/uuid]
[:page-id ::sm/uuid] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:position ::gpt/point]])
[:position ::gpt/point]]))
(defn create-draft (defn create-draft
[params] [params]

View file

@ -129,12 +129,11 @@
(def ^:private (def ^:private
schema:shortcuts schema:shortcuts
(sm/define [:map-of :keyword
[:map-of :keyword [:map
[:map [:command [:or :string [:vector :any]]]
[:command [:or :string [:vector :any]]] [:fn {:optional true} fn?]
[:fn {:optional true} fn?] [:tooltip {:optional true} :string]]])
[:tooltip {:optional true} :string]]]))
(def check-shortcuts! (def check-shortcuts!
(sm/check-fn schema:shortcuts)) (sm/check-fn schema:shortcuts))

View file

@ -32,14 +32,13 @@
(def ^:private (def ^:private
schema:profile schema:profile
(sm/define [:map {:title "Profile"}
[:map {:title "Profile"} [:id ::sm/uuid]
[:id ::sm/uuid] [:created-at {:optional true} :any]
[:created-at {:optional true} :any] [:fullname {:optional true} :string]
[:fullname {:optional true} :string] [:email {:optional true} :string]
[:email {:optional true} :string] [:lang {:optional true} :string]
[:lang {:optional true} :string] [:theme {:optional true} :string]])
[:theme {:optional true} :string]]))
(def check-profile! (def check-profile!
(sm/check-fn schema:profile)) (sm/check-fn schema:profile))
@ -253,10 +252,9 @@
(rx/catch on-error)))))) (rx/catch on-error))))))
(def ^:private schema:login-with-ldap (def ^:private schema:login-with-ldap
(sm/define [:map {:title "login-with-ldap"}
[:map [:email ::sm/email]
[:email ::sm/email] [:password :string]])
[:password :string]]))
(defn login-with-ldap (defn login-with-ldap
[params] [params]
@ -486,6 +484,7 @@
;; TODO: for the release 1.13 we should skip fetching profile and just use ;; TODO: for the release 1.13 we should skip fetching profile and just use
;; the response value of update-profile-props RPC call ;; the response value of update-profile-props RPC call
;; FIXME
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(->> (rp/cmd! :update-profile-props {:props props}) (->> (rp/cmd! :update-profile-props {:props props})
@ -595,9 +594,8 @@
(def ^:private (def ^:private
schema:request-profile-recovery schema:request-profile-recovery
(sm/define [:map {:title "request-profile-recovery" :closed true}
[:map {:title "request-profile-recovery" :closed true} [:email ::sm/email]])
[:email ::sm/email]]))
(defn request-profile-recovery (defn request-profile-recovery
[data] [data]
@ -621,10 +619,9 @@
(def ^:private (def ^:private
schema:recover-profile schema:recover-profile
(sm/define [:map {:title "recover-profile" :closed true}
[:map {:title "recover-profile" :closed true} [:password :string]
[:password :string] [:token :string]])
[:token :string]]))
(defn recover-profile (defn recover-profile
[data] [data]

View file

@ -49,11 +49,10 @@
(def ^:private (def ^:private
schema:initialize schema:initialize
(sm/define [:map {:title "initialize"}
[:map {:title "initialize"} [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:share-id {:optional true} [:maybe ::sm/uuid]]
[:share-id {:optional true} [:maybe ::sm/uuid]] [:page-id {:optional true} ::sm/uuid]])
[:page-id {:optional true} ::sm/uuid]]))
(defn initialize (defn initialize
[{:keys [file-id share-id interactions-show?] :as params}] [{:keys [file-id share-id interactions-show?] :as params}]
@ -102,11 +101,10 @@
(def ^:private (def ^:private
schema:fetch-bundle schema:fetch-bundle
(sm/define [:map {:title "fetch-bundle"}
[:map {:title "fetch-bundle"} [:page-id ::sm/uuid]
[:page-id ::sm/uuid] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:share-id {:optional true} ::sm/uuid]])
[:share-id {:optional true} ::sm/uuid]]))
(defn- fetch-bundle (defn- fetch-bundle
[{:keys [file-id share-id] :as params}] [{:keys [file-id share-id] :as params}]

View file

@ -1676,17 +1676,19 @@
(def ^:private (def ^:private
schema:paste-data schema:paste-data
(sm/define [:map {:title "paste-data"}
[:map {:title "paste-data"} [:type [:= :copied-shapes]]
[:type [:= :copied-shapes]] [:features ::sm/set-of-strings]
[:features ::sm/set-of-strings] [:version :int]
[:version :int] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:selected ::sm/set-of-uuid]
[:selected ::sm/set-of-uuid] [:objects
[:objects [:map-of ::sm/uuid :map]]
[:map-of ::sm/uuid :map]] [:images [:set :map]]
[:images [:set :map]] [:position {:optional true} ::gpt/point]])
[:position {:optional true} ::gpt/point]]))
(def validate-paste-data!
(sm/validate-fn schema:paste-data))
(defn- paste-transit (defn- paste-transit
[{:keys [images] :as pdata}] [{:keys [images] :as pdata}]
@ -1711,9 +1713,8 @@
(let [file-id (:current-file-id state) (let [file-id (:current-file-id state)
features (features/get-team-enabled-features state)] features (features/get-team-enabled-features state)]
(sm/validate! schema:paste-data pdata (validate-paste-data! pdata {:hint "invalid paste data"
{:hint "invalid paste data" :code :invalid-paste-data})
:code :invalid-paste-data})
(cfeat/check-paste-features! features (:features pdata)) (cfeat/check-paste-features! features (:features pdata))
(if (= file-id (:file-id pdata)) (if (= file-id (:file-id pdata))

View file

@ -200,14 +200,13 @@
(def ^:private (def ^:private
schema:process-media-objects schema:process-media-objects
(sm/define [:map {:title "process-media-objects"}
[:map {:title "process-media-objects"} [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:local? :boolean]
[:local? :boolean] [:name {:optional true} :string]
[:name {:optional true} :string] [:data {:optional true} :any] ; FIXME
[:data {:optional true} :any] ; FIXME [:uris {:optional true} [:sequential :string]]
[:uris {:optional true} [:sequential :string]] [:mtype {:optional true} :string]])
[:mtype {:optional true} :string]]))
(defn- process-media-objects (defn- process-media-objects
[{:keys [uris on-error] :as params}] [{:keys [uris on-error] :as params}]
@ -427,10 +426,9 @@
(def ^:private (def ^:private
schema:clone-media-object schema:clone-media-object
(sm/define [:map {:title "clone-media-object"}
[:map {:title "clone-media-object"} [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:object-id ::sm/uuid]])
[:object-id ::sm/uuid]]))
(defn clone-media-object (defn clone-media-object
[{:keys [file-id object-id] :as params}] [{:keys [file-id object-id] :as params}]

View file

@ -198,21 +198,23 @@
(def ^:private (def ^:private
schema:handle-file-change schema:handle-file-change
(sm/define [:map {:title "handle-file-change"}
[:map {:title "handle-file-change"} [:type :keyword]
[:type :keyword] [:profile-id ::sm/uuid]
[:profile-id ::sm/uuid] [:file-id ::sm/uuid]
[:file-id ::sm/uuid] [:session-id ::sm/uuid]
[:session-id ::sm/uuid] [:revn :int]
[:revn :int] [:changes ::cpc/changes]])
[:changes ::cpc/changes]]))
(def ^:private check-file-change-params!
(sm/check-fn schema:handle-file-change))
(defn handle-file-change (defn handle-file-change
[{:keys [file-id changes revn] :as msg}] [{:keys [file-id changes revn] :as msg}]
(dm/assert! (dm/assert!
"expected valid parameters" "expected valid parameters"
(sm/check! schema:handle-file-change msg)) (check-file-change-params! msg))
(ptk/reify ::handle-file-change (ptk/reify ::handle-file-change
IDeref IDeref
@ -230,23 +232,24 @@
:redo-changes (vec changes) :redo-changes (vec changes)
:undo-changes []}))))) :undo-changes []})))))
(def ^:private (def ^:private schema:handle-library-change
schema:handle-library-change [:map {:title "handle-library-change"}
(sm/define [:type :keyword]
[:map {:title "handle-library-change"} [:profile-id ::sm/uuid]
[:type :keyword] [:file-id ::sm/uuid]
[:profile-id ::sm/uuid] [:session-id ::sm/uuid]
[:file-id ::sm/uuid] [:revn :int]
[:session-id ::sm/uuid] [:modified-at ::sm/inst]
[:revn :int] [:changes ::cpc/changes]])
[:modified-at ::sm/inst]
[:changes ::cpc/changes]])) (def ^:private check-library-change-params!
(sm/check-fn schema:handle-library-change))
(defn handle-library-change (defn handle-library-change
[{:keys [file-id modified-at changes revn] :as msg}] [{:keys [file-id modified-at changes revn] :as msg}]
(dm/assert! (dm/assert!
"expected valid arguments" "expected valid arguments"
(sm/check! schema:handle-library-change msg)) (check-library-change-params! msg))
(ptk/reify ::handle-library-change (ptk/reify ::handle-library-change
ptk/WatchEvent ptk/WatchEvent

View file

@ -27,20 +27,19 @@
(def ^:private (def ^:private
schema:path-content schema:path-content
(sm/define [:vector {:title "PathContent"}
[:vector {:title "PathContent"} [:map {:title "PathContentEntry"}
[:map {:title "PathContentEntry"} [:command [::sm/one-of valid-commands]]
[:command [::sm/one-of valid-commands]] ;; FIXME: remove the `?` from prop name
;; FIXME: remove the `?` from prop name [:relative? {:optional true} :boolean]
[:relative? {:optional true} :boolean] [:params {:optional true}
[:params {:optional true} [:map {:title "PathContentEntryParams"}
[:map {:title "PathContentEntryParams"} [:x :double]
[:x :double] [:y :double]
[:y :double] [:c1x {:optional true} :double]
[:c1x {:optional true} :double] [:c1y {:optional true} :double]
[:c1y {:optional true} :double] [:c2x {:optional true} :double]
[:c2x {:optional true} :double] [:c2y {:optional true} :double]]]]])
[:c2y {:optional true} :double]]]]]))
(def check-path-content! (def check-path-content!
(sm/check-fn schema:path-content)) (sm/check-fn schema:path-content))

View file

@ -26,10 +26,9 @@
(def ^:private (def ^:private
schema:undo-entry schema:undo-entry
(sm/define [:map {:title "undo-entry"}
[:map {:title "undo-entry"} [:undo-changes [:vector ::cpc/change]]
[:undo-changes [:vector ::cpc/change]] [:redo-changes [:vector ::cpc/change]]])
[:redo-changes [:vector ::cpc/change]]]))
(def check-undo-entry! (def check-undo-entry!
(sm/check-fn schema:undo-entry)) (sm/check-fn schema:undo-entry))

View file

@ -24,24 +24,27 @@
;; --- Messages Handling ;; --- Messages Handling
(def ^:private (def ^:private schema:message
schema:message [:map {:title "WorkerMessage"}
(sm/define [:sender-id ::sm/uuid]
[:map {:title "WorkerMessage"} [:payload
[:sender-id ::sm/uuid] [:map
[:payload [:cmd :keyword]]]
[:map [:buffer? {:optional true} :boolean]])
[:cmd :keyword]]]
[:buffer? {:optional true} :boolean]])) (def ^:private check-message!
(sm/check-fn schema:message))
(def buffer (rx/subject)) (def buffer (rx/subject))
(defn- handle-message (defn- handle-message
"Process the message and returns to the client" "Process the message and returns to the client"
[{:keys [sender-id payload transfer] :as message}] [{:keys [sender-id payload transfer] :as message}]
(dm/assert! (dm/assert!
"expected valid message" "expected valid message"
(sm/check! schema:message message)) (check-message! message))
(letfn [(post [msg] (letfn [(post [msg]
(let [msg (-> msg (assoc :reply-to sender-id) (wm/encode))] (let [msg (-> msg (assoc :reply-to sender-id) (wm/encode))]
(.postMessage js/self msg))) (.postMessage js/self msg)))