| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- (ns frontend.db.rtc.const
- "RTC constants/schema"
- (:require [malli.util :as mu]
- [malli.core :as m]
- [malli.transform :as mt]))
- (def general-attrs-schema-coll
- [[:updated-at {:optional true} :int]
- [:created-at {:optional true} :int]
- [:alias {:optional true} [:maybe [:sequential :uuid]]]
- [:type {:optional true} [:maybe [:sequential :string]]]
- [:schema {:optional true} [:maybe :string]]
- [:tags {:optional true} [:maybe [:sequential :uuid]]]
- [:properties {:optional true} [:maybe :string ; transit-json-string
- ]]])
- (def general-attr-set
- (into #{} (map first) general-attrs-schema-coll))
- (def block-type-schema [:enum "property" "class" "whiteboard" "object" "hidden" "enum value"])
- (def op-schema
- [:multi {:dispatch first :decode/string #(update % 0 keyword)}
- [:move
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:target-uuid :uuid]
- [:sibling? :boolean]]]]
- [:remove
- [:cat :keyword
- [:map
- [:block-uuids [:sequential :uuid]]]]]
- [:update
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:target-uuid {:optional true} :uuid]
- [:sibling? {:optional true} :boolean]
- [:content {:optional true} :string]
- [:updated-at {:optional true} :int]
- [:created-at {:optional true} :int]
- [:tags {:optional true} [:map
- [:add {:optional true} [:maybe [:set :uuid]]]
- [:retract {:optional true} [:maybe [:set :uuid]]]]]
- [:alias {:optional true} [:map
- [:add {:optional true} [:maybe [:set :uuid]]]
- [:retract {:optional true} [:maybe [:set :uuid]]]]]
- [:type {:optional true} [:map
- [:add {:optional true} [:maybe [:set block-type-schema]]]
- [:retract {:optional true} [:maybe [:set block-type-schema]]]]]
- [:schema {:optional true} :string ;transit-string
- ]
- [:properties {:optional true} [:map
- [:add {:optional true} [:sequential [:cat :uuid :string ;; transit-string
- ]]]
- [:retract {:optional true} [:set :uuid]]]]]]]
- [:update-page
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:page-name :string]
- [:original-name :string]]]]
- [:remove-page
- [:cat :keyword
- [:map
- [:block-uuid :uuid]]]]])
- (def data-from-ws-schema
- [:map
- [:req-id :string]
- [:t {:optional true} :int]
- [:t-before {:optional true} :int]
- [:failed-ops {:optional true} [:sequential op-schema]]
- [:s3-presign-url {:optional true} :string]
- [:affected-blocks {:optional true}
- [:map-of :uuid
- [:multi {:dispatch :op :decode/string #(update % :op keyword)}
- [:move
- (apply conj
- [:map {:closed true}
- [:op :keyword]
- [:self :uuid]
- [:parents [:sequential :uuid]]
- [:left :uuid]
- [:content {:optional true} :string]]
- general-attrs-schema-coll)]
- [:remove
- [:map {:closed true}
- [:op :keyword]
- [:block-uuid :uuid]]]
- [:update-attrs
- (apply conj
- [:map {:closed true}
- [:op :keyword]
- [:self :uuid]
- [:parents {:optional true} [:sequential :uuid]]
- [:left {:optional true} :uuid]
- [:content {:optional true} :string]]
- general-attrs-schema-coll)]
- [:update-page
- (apply conj
- [:map {:closed true}
- [:op :keyword]
- [:self :uuid]
- [:page-name :string]
- [:original-name :string]]
- general-attrs-schema-coll)]
- [:remove-page
- [:map {:closed true}
- [:op :keyword]
- [:block-uuid :uuid]]]]]]
- [:ex-data {:optional true} [:map [:type :keyword]]]
- [:ex-message {:optional true} :any]])
- (def data-from-ws-coercer (m/coercer data-from-ws-schema mt/string-transformer))
- (def data-from-ws-validator (m/validator data-from-ws-schema))
- (def data-to-ws-schema
- (mu/closed-schema
- [:multi {:dispatch :action}
- ["list-graphs"
- [:map
- [:req-id :string]
- [:action :string]]]
- ["register-graph-updates"
- [:map
- [:req-id :string]
- [:action :string]
- [:graph-uuid :string]]]
- ["apply-ops"
- [:map
- [:req-id :string]
- [:action :string]
- [:graph-uuid :string]
- [:ops [:sequential op-schema]]
- [:t-before :int]]]
- ["presign-put-temp-s3-obj"
- [:map
- [:req-id :string]
- [:action :string]]]
- ["full-download-graph"
- [:map
- [:req-id :string]
- [:action :string]
- [:graph-uuid :string]]]
- ["full-upload-graph"
- [:map
- [:req-id :string]
- [:action :string]
- [:s3-key :string]]]
- ["grant-access"
- [:map
- [:req-id :string]
- [:action :string]
- [:graph-uuid :uuid]
- [:target-user-uuids {:optional true} [:sequential :uuid]]
- [:target-user-emails {:optional true} [:sequential :string]]]]
- ["query-block-content-versions"
- [:map
- [:req-id :string]
- [:action :string]
- [:graph-uuid :string]
- [:block-uuids [:sequential :uuid]]]]]))
- (def data-to-ws-encoder (m/encoder data-to-ws-schema mt/string-transformer))
- (def data-to-ws-coercer (m/coercer data-to-ws-schema mt/string-transformer))
|