| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- (ns frontend.worker.rtc.const
- "RTC constants/schema"
- (:require [logseq.db.frontend.malli-schema :as db-malli-schema]
- [malli.core :as m]
- [malli.transform :as mt]
- [malli.util :as mu]))
- (goog-define RTC-E2E-TEST* false)
- (def RTC-E2E-TEST RTC-E2E-TEST*)
- (def block-pos-schema
- [:catn
- [:parent-uuid [:maybe :uuid]]
- [:order [:maybe db-malli-schema/block-order]]])
- (def av-schema
- [:cat
- :keyword
- [:or
- :uuid ;; reference type
- :string ;; all other type value convert to string by transit
- ]
- :int ;; t
- :boolean ;; add(true) or retract
- ])
- (def to-ws-op-schema
- [:multi {:dispatch first :decode/string #(update % 0 keyword)}
- [:move
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:pos block-pos-schema]]]]
- [:remove
- [:cat :keyword
- [:map
- [:block-uuids [:sequential :uuid]]]]]
- [:update-page
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:page-name :string]
- [:block/title :string]]]]
- [:remove-page
- [:cat :keyword
- [:map
- [:block-uuid :uuid]]]]
- [:update
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:db/ident {:optional true} :keyword]
- [:pos block-pos-schema]
- [:av-coll [:sequential av-schema]]
- [:card-one-attrs {:optional true} [:sequential :keyword]]]]]
- [:update-schema
- [:cat :keyword
- [:map
- [:block-uuid :uuid]
- [:db/ident :keyword]
- [:db/valueType :keyword]
- [:db/cardinality {:optional true} :keyword]
- [:db/index {:optional true} :boolean]]]]])
- (comment
- (def to-ws-ops-validator (m/validator [:sequential to-ws-op-schema])))
- (def to-ws-ops-decoder (m/decoder [:sequential to-ws-op-schema] mt/string-transformer))
- (def ^:private extra-attr-map-schema
- [:map-of
- :keyword
- [:or
- [:or :uuid :string]
- [:sequential [:or :uuid :string]]]])
- (def data-from-ws-schema
- "TODO: split this mix schema to multiple ones"
- [:map
- [:req-id :string]
- [:profile {:optional true} :map]
- [:t {:optional true} :int]
- [:t-before {:optional true} :int]
- [:failed-ops {:optional true} [:sequential to-ws-op-schema]]
- [:s3-presign-url {:optional true} :string]
- [:server-schema-version {:optional true} :int]
- [:server-builtin-db-idents {:optional true} [:set :keyword]]
- [:server-only-db-ident-blocks {:optional true} [:maybe :string] ;;transit
- ]
- [:users {:optional true} [:sequential
- [:map {:closed true}
- [:user/uuid :uuid]
- [:user/name :string]
- [:user/email :string]
- [:user/online? :boolean]
- [:user/avatar {:optional true} :string]
- [:graph<->user/user-type :keyword]]]]
- [:online-users {:optional true} [:sequential
- [:map {:closed true}
- [:user/uuid :uuid]
- [:user/name :string]
- [:user/email :string]
- [:user/avatar {:optional true} :string]]]]
- [:refed-blocks {:optional true}
- [:maybe
- [:sequential
- [:map
- [:block/uuid :uuid]
- [:db/ident {:optional true} :keyword]
- [:block/order {:optional true} db-malli-schema/block-order]
- [:block/parent {:optional true} :uuid]
- [::m/default extra-attr-map-schema]]]]]
- [:affected-blocks {:optional true}
- [:map-of :uuid
- [:multi {:dispatch :op :decode/string #(update % :op keyword)}
- [:move
- [:map {:closed true}
- [:op :keyword]
- [:self :uuid]
- [:parents [:sequential :uuid]]
- [:block/order {:optional true} db-malli-schema/block-order]
- [:hash {:optional true} :int]
- [:db/ident {:optional true} :keyword]]]
- [:remove
- [:map
- [:op :keyword]
- [:block-uuid :uuid]]]
- [:update-attrs
- [:map
- [:op :keyword]
- [:self :uuid]
- [:parents {:optional true} [:sequential :uuid]]
- [:block/order {:optional true} db-malli-schema/block-order]
- [:hash {:optional true} :int]
- [:db/ident {:optional true} :keyword]
- [::m/default extra-attr-map-schema]]]
- [:move+update-attrs
- [:map
- [:op :keyword]
- [:self :uuid]
- [:parents {:optional true} [:sequential :uuid]]
- [:block/order {:optional true} db-malli-schema/block-order]
- [:hash {:optional true} :int]
- [:db/ident {:optional true} :keyword]
- [::m/default extra-attr-map-schema]]]
- [:update-page
- [:map
- [:op :keyword]
- [:self :uuid]
- [:block/title :string]
- [:db/ident {:optional true} :keyword]
- [:block/order {:optional true} db-malli-schema/block-order]
- [::m/default extra-attr-map-schema]]]
- [:remove-page
- [:map
- [:op :keyword]
- [:block-uuid :uuid]]]]]]
- [:asset-uuid->url {:optional true} [:map-of :uuid :string]]
- [:uploaded-assets {:optional true} [:map-of :uuid :map]]
- [:ex-data {:optional true} [:map [:type :keyword]]]
- [:ex-message {:optional true} :string]])
- (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))
- (defn- with-shared-schema-attrs
- [malli-schema]
- (let [[head api-schema-seq] (split-at 2 malli-schema)]
- (vec
- (concat
- head
- (map
- (fn [api-schema]
- (let [[api-name [type']] api-schema]
- (if (= :map type')
- [api-name (vec (concat (second api-schema) [[:req-id :string]
- [:action :string]
- [:profile {:optional true} :boolean]]))]
- api-schema)))
- api-schema-seq)))))
- (def ^:large-vars/data-var data-to-ws-schema
- (mu/closed-schema
- (with-shared-schema-attrs
- [:multi {:dispatch :action}
- ["list-graphs"
- [:map]]
- ["register-graph-updates"
- [:map
- [:graph-uuid :string]]]
- ["apply-ops"
- [:or
- [:map
- [:req-id :string]
- [:action :string]
- [:profile {:optional true} :boolean]
- [:graph-uuid :string]
- [:ops [:sequential to-ws-op-schema]]
- [:t-before :int]]
- [:map
- [:req-id :string]
- [:action :string]
- [:profile {:optional true} :boolean]
- [:s3-key :string]]]]
- ["presign-put-temp-s3-obj"
- [:map]]
- ["upload-graph"
- [:map
- [:s3-key :string]
- [:graph-name :string]]]
- ["download-graph"
- [:map
- [:graph-uuid :string]]]
- ["download-info-list"
- [:map
- [:graph-uuid :string]]]
- ["snapshot-list"
- [:map
- [:graph-uuid :string]]]
- ["snapshot-graph"
- [:map
- [:graph-uuid :string]]]
- ["grant-access"
- [:map
- [:graph-uuid :uuid]
- [:target-user-uuids {:optional true} [:sequential :uuid]]
- [:target-user-emails {:optional true} [:sequential :string]]]]
- ["get-users-info"
- [:map
- [:graph-uuid :uuid]]]
- ["inject-users-info"
- [:map
- [:graph-uuid :uuid]]]
- ["delete-graph"
- [:map
- [:graph-uuid :uuid]]]
- ["query-block-content-versions"
- [:map
- [:graph-uuid :string]
- [:block-uuids [:sequential :uuid]]]]
- ["calibrate-graph-skeleton"
- [:map
- [:graph-uuid :string]
- [:t :int]
- [:schema-version :int]
- [:db-ident-blocks [:sequential
- [:map
- [:db/ident :keyword]
- [::m/default extra-attr-map-schema]]]]]]
- ["get-graph-skeleton"
- [:map
- [:graph-uuid :string]]]
- ["get-assets-upload-urls"
- [:map
- [:graph-uuid :string]
- [:asset-uuid->metadata [:map-of :uuid [:map-of :string :string]]]]]
- ["get-assets-download-urls"
- [:map
- [:graph-uuid :string]
- [:asset-uuids [:sequential :uuid]]]]
- ["delete-assets"
- [:map
- [:graph-uuid :string]
- [:asset-uuids [:sequential :uuid]]]]
- ["get-user-devices"
- [:map]]
- ["add-user-device"
- [:map
- [:device-name :string]]]
- ["remove-user-device"
- [:map
- [:device-uuid :uuid]]]
- ["update-user-device-name"
- [:map
- [:device-uuid :uuid]
- [:device-name :string]]]
- ["add-device-public-key"
- [:map
- [:device-uuid :uuid]
- [:key-name :string]
- [:public-key :string]]]
- ["remove-device-public-key"
- [:map
- [:device-uuid :uuid]
- [:key-name :string]]]
- ["sync-encrypted-aes-key"
- [:map
- [:device-uuid->encrypted-aes-key [:map-of :uuid :string]]
- [:graph-uuid :uuid]]]])))
- (def data-to-ws-encoder (m/encoder data-to-ws-schema (mt/transformer
- mt/string-transformer
- (mt/key-transformer {:encode m/-keyword->string}))))
- (def data-to-ws-coercer (m/coercer data-to-ws-schema mt/string-transformer nil
- #(do
- (prn ::data-to-ws-schema %)
- (m/-fail! ::data-to-ws-schema %))))
|