const.cljs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. (ns frontend.db.rtc.const
  2. "RTC constants/schema"
  3. (:require [malli.util :as mu]
  4. [malli.core :as m]
  5. [malli.transform :as mt]))
  6. (def general-attrs-schema-coll
  7. [[:updated-at {:optional true} :int]
  8. [:created-at {:optional true} :int]
  9. [:alias {:optional true} [:maybe [:sequential :uuid]]]
  10. [:type {:optional true} [:maybe [:sequential :string]]]
  11. [:schema {:optional true} [:maybe :string]]
  12. [:tags {:optional true} [:maybe [:sequential :uuid]]]
  13. [:properties {:optional true} [:maybe :string ; transit-json-string
  14. ]]])
  15. (def general-attr-set
  16. (into #{} (map first) general-attrs-schema-coll))
  17. (def block-type-schema [:enum "property" "class" "whiteboard" "object" "hidden" "enum value"])
  18. (def op-schema
  19. [:multi {:dispatch first :decode/string #(update % 0 keyword)}
  20. [:move
  21. [:cat :keyword
  22. [:map
  23. [:block-uuid :uuid]
  24. [:target-uuid :uuid]
  25. [:sibling? :boolean]]]]
  26. [:remove
  27. [:cat :keyword
  28. [:map
  29. [:block-uuids [:sequential :uuid]]]]]
  30. [:update
  31. [:cat :keyword
  32. [:map
  33. [:block-uuid :uuid]
  34. [:target-uuid {:optional true} :uuid]
  35. [:sibling? {:optional true} :boolean]
  36. [:content {:optional true} :string]
  37. [:updated-at {:optional true} :int]
  38. [:created-at {:optional true} :int]
  39. [:tags {:optional true} [:map
  40. [:add {:optional true} [:maybe [:set :uuid]]]
  41. [:retract {:optional true} [:maybe [:set :uuid]]]]]
  42. [:alias {:optional true} [:map
  43. [:add {:optional true} [:maybe [:set :uuid]]]
  44. [:retract {:optional true} [:maybe [:set :uuid]]]]]
  45. [:type {:optional true} [:map
  46. [:add {:optional true} [:maybe [:set block-type-schema]]]
  47. [:retract {:optional true} [:maybe [:set block-type-schema]]]]]
  48. [:schema {:optional true} :string ;transit-string
  49. ]
  50. [:properties {:optional true} [:map
  51. [:add {:optional true} [:sequential [:cat :uuid :string ;; transit-string
  52. ]]]
  53. [:retract {:optional true} [:set :uuid]]]]]]]
  54. [:update-page
  55. [:cat :keyword
  56. [:map
  57. [:block-uuid :uuid]
  58. [:page-name :string]
  59. [:original-name :string]]]]
  60. [:remove-page
  61. [:cat :keyword
  62. [:map
  63. [:block-uuid :uuid]]]]])
  64. (def data-from-ws-schema
  65. [:map
  66. [:req-id :string]
  67. [:t {:optional true} :int]
  68. [:t-before {:optional true} :int]
  69. [:failed-ops {:optional true} [:sequential op-schema]]
  70. [:s3-presign-url {:optional true} :string]
  71. [:affected-blocks {:optional true}
  72. [:map-of :uuid
  73. [:multi {:dispatch :op :decode/string #(update % :op keyword)}
  74. [:move
  75. (apply conj
  76. [:map {:closed true}
  77. [:op :keyword]
  78. [:self :uuid]
  79. [:parents [:sequential :uuid]]
  80. [:left :uuid]
  81. [:content {:optional true} :string]]
  82. general-attrs-schema-coll)]
  83. [:remove
  84. [:map {:closed true}
  85. [:op :keyword]
  86. [:block-uuid :uuid]]]
  87. [:update-attrs
  88. (apply conj
  89. [:map {:closed true}
  90. [:op :keyword]
  91. [:self :uuid]
  92. [:parents {:optional true} [:sequential :uuid]]
  93. [:left {:optional true} :uuid]
  94. [:content {:optional true} :string]]
  95. general-attrs-schema-coll)]
  96. [:update-page
  97. (apply conj
  98. [:map {:closed true}
  99. [:op :keyword]
  100. [:self :uuid]
  101. [:page-name :string]
  102. [:original-name :string]]
  103. general-attrs-schema-coll)]
  104. [:remove-page
  105. [:map {:closed true}
  106. [:op :keyword]
  107. [:block-uuid :uuid]]]]]]
  108. [:ex-data {:optional true} [:map [:type :keyword]]]
  109. [:ex-message {:optional true} :any]])
  110. (def data-from-ws-coercer (m/coercer data-from-ws-schema mt/string-transformer))
  111. (def data-from-ws-validator (m/validator data-from-ws-schema))
  112. (def data-to-ws-schema
  113. (mu/closed-schema
  114. [:multi {:dispatch :action}
  115. ["list-graphs"
  116. [:map
  117. [:req-id :string]
  118. [:action :string]]]
  119. ["register-graph-updates"
  120. [:map
  121. [:req-id :string]
  122. [:action :string]
  123. [:graph-uuid :string]]]
  124. ["apply-ops"
  125. [:map
  126. [:req-id :string]
  127. [:action :string]
  128. [:graph-uuid :string]
  129. [:ops [:sequential op-schema]]
  130. [:t-before :int]]]
  131. ["presign-put-temp-s3-obj"
  132. [:map
  133. [:req-id :string]
  134. [:action :string]]]
  135. ["full-download-graph"
  136. [:map
  137. [:req-id :string]
  138. [:action :string]
  139. [:graph-uuid :string]]]
  140. ["full-upload-graph"
  141. [:map
  142. [:req-id :string]
  143. [:action :string]
  144. [:s3-key :string]]]
  145. ["grant-access"
  146. [:map
  147. [:req-id :string]
  148. [:action :string]
  149. [:graph-uuid :uuid]
  150. [:target-user-uuids {:optional true} [:sequential :uuid]]
  151. [:target-user-emails {:optional true} [:sequential :string]]]]
  152. ["query-block-content-versions"
  153. [:map
  154. [:req-id :string]
  155. [:action :string]
  156. [:graph-uuid :string]
  157. [:block-uuids [:sequential :uuid]]]]]))
  158. (def data-to-ws-encoder (m/encoder data-to-ws-schema mt/string-transformer))
  159. (def data-to-ws-coercer (m/coercer data-to-ws-schema mt/string-transformer))