|
1 | 1 | (ns frontend.worker.rtc.const
|
2 |
| - "RTC constants/schema" |
3 |
| - (:require [logseq.db.frontend.malli-schema :as db-malli-schema] |
4 |
| - [malli.core :as m] |
5 |
| - [malli.transform :as mt] |
6 |
| - [malli.util :as mu])) |
| 2 | + "RTC constants") |
7 | 3 |
|
8 | 4 | (goog-define RTC-E2E-TEST* false)
|
9 | 5 | (def RTC-E2E-TEST RTC-E2E-TEST*)
|
10 |
| - |
11 |
| -(def block-pos-schema |
12 |
| - [:catn |
13 |
| - [:parent-uuid [:maybe :uuid]] |
14 |
| - [:order [:maybe db-malli-schema/block-order]]]) |
15 |
| - |
16 |
| -(def av-schema |
17 |
| - [:cat |
18 |
| - :keyword |
19 |
| - [:or |
20 |
| - :uuid ;; reference type |
21 |
| - :string ;; all other type value convert to string by transit |
22 |
| - ] |
23 |
| - :int ;; t |
24 |
| - :boolean ;; add(true) or retract |
25 |
| - ]) |
26 |
| - |
27 |
| -(def to-ws-op-schema |
28 |
| - [:multi {:dispatch first :decode/string #(update % 0 keyword)} |
29 |
| - [:move |
30 |
| - [:cat :keyword |
31 |
| - [:map |
32 |
| - [:block-uuid :uuid] |
33 |
| - [:pos block-pos-schema]]]] |
34 |
| - [:remove |
35 |
| - [:cat :keyword |
36 |
| - [:map |
37 |
| - [:block-uuids [:sequential :uuid]]]]] |
38 |
| - [:update-page |
39 |
| - [:cat :keyword |
40 |
| - [:map |
41 |
| - [:block-uuid :uuid] |
42 |
| - [:page-name :string] |
43 |
| - [:block/title :string]]]] |
44 |
| - [:remove-page |
45 |
| - [:cat :keyword |
46 |
| - [:map |
47 |
| - [:block-uuid :uuid]]]] |
48 |
| - [:update |
49 |
| - [:cat :keyword |
50 |
| - [:map |
51 |
| - [:block-uuid :uuid] |
52 |
| - [:db/ident {:optional true} :keyword] |
53 |
| - [:pos block-pos-schema] |
54 |
| - [:av-coll [:sequential av-schema]] |
55 |
| - [:card-one-attrs {:optional true} [:sequential :keyword]]]]] |
56 |
| - [:update-schema |
57 |
| - [:cat :keyword |
58 |
| - [:map |
59 |
| - [:block-uuid :uuid] |
60 |
| - [:db/ident :keyword] |
61 |
| - [:db/valueType :keyword] |
62 |
| - [:db/cardinality {:optional true} :keyword] |
63 |
| - [:db/index {:optional true} :boolean]]]]]) |
64 |
| - |
65 |
| -(comment |
66 |
| - (def to-ws-ops-validator (m/validator [:sequential to-ws-op-schema]))) |
67 |
| - |
68 |
| -(def to-ws-ops-decoder (m/decoder [:sequential to-ws-op-schema] mt/string-transformer)) |
69 |
| - |
70 |
| -(def ^:private extra-attr-map-schema |
71 |
| - [:map-of |
72 |
| - :keyword |
73 |
| - [:or |
74 |
| - [:or :uuid :string] |
75 |
| - [:sequential [:or :uuid :string]]]]) |
76 |
| - |
77 |
| -(def data-from-ws-schema |
78 |
| - "TODO: split this mix schema to multiple ones" |
79 |
| - [:map |
80 |
| - [:req-id :string] |
81 |
| - [:profile {:optional true} :map] |
82 |
| - [:t {:optional true} :int] |
83 |
| - [:t-before {:optional true} :int] |
84 |
| - [:failed-ops {:optional true} [:sequential to-ws-op-schema]] |
85 |
| - [:s3-presign-url {:optional true} :string] |
86 |
| - [:server-schema-version {:optional true} :int] |
87 |
| - [:server-builtin-db-idents {:optional true} [:set :keyword]] |
88 |
| - [:server-only-db-ident-blocks {:optional true} [:maybe :string] ;;transit |
89 |
| - ] |
90 |
| - [:users {:optional true} [:sequential |
91 |
| - [:map {:closed true} |
92 |
| - [:user/uuid :uuid] |
93 |
| - [:user/name :string] |
94 |
| - [:user/email :string] |
95 |
| - [:user/online? :boolean] |
96 |
| - [:user/avatar {:optional true} :string] |
97 |
| - [:graph<->user/user-type :keyword]]]] |
98 |
| - [:online-users {:optional true} [:sequential |
99 |
| - [:map {:closed true} |
100 |
| - [:user/uuid :uuid] |
101 |
| - [:user/name :string] |
102 |
| - [:user/email :string] |
103 |
| - [:user/avatar {:optional true} :string]]]] |
104 |
| - [:refed-blocks {:optional true} |
105 |
| - [:maybe |
106 |
| - [:sequential |
107 |
| - [:map |
108 |
| - [:block/uuid :uuid] |
109 |
| - [:db/ident {:optional true} :keyword] |
110 |
| - [:block/order {:optional true} db-malli-schema/block-order] |
111 |
| - [:block/parent {:optional true} :uuid] |
112 |
| - [::m/default extra-attr-map-schema]]]]] |
113 |
| - [:affected-blocks {:optional true} |
114 |
| - [:map-of :uuid |
115 |
| - [:multi {:dispatch :op :decode/string #(update % :op keyword)} |
116 |
| - [:move |
117 |
| - [:map {:closed true} |
118 |
| - [:op :keyword] |
119 |
| - [:self :uuid] |
120 |
| - [:parents [:sequential :uuid]] |
121 |
| - [:block/order {:optional true} db-malli-schema/block-order] |
122 |
| - [:hash {:optional true} :int] |
123 |
| - [:db/ident {:optional true} :keyword]]] |
124 |
| - [:remove |
125 |
| - [:map |
126 |
| - [:op :keyword] |
127 |
| - [:block-uuid :uuid]]] |
128 |
| - [:update-attrs |
129 |
| - [:map |
130 |
| - [:op :keyword] |
131 |
| - [:self :uuid] |
132 |
| - [:parents {:optional true} [:sequential :uuid]] |
133 |
| - [:block/order {:optional true} db-malli-schema/block-order] |
134 |
| - [:hash {:optional true} :int] |
135 |
| - [:db/ident {:optional true} :keyword] |
136 |
| - [::m/default extra-attr-map-schema]]] |
137 |
| - [:move+update-attrs |
138 |
| - [:map |
139 |
| - [:op :keyword] |
140 |
| - [:self :uuid] |
141 |
| - [:parents {:optional true} [:sequential :uuid]] |
142 |
| - [:block/order {:optional true} db-malli-schema/block-order] |
143 |
| - [:hash {:optional true} :int] |
144 |
| - [:db/ident {:optional true} :keyword] |
145 |
| - [::m/default extra-attr-map-schema]]] |
146 |
| - [:update-page |
147 |
| - [:map |
148 |
| - [:op :keyword] |
149 |
| - [:self :uuid] |
150 |
| - [:block/title :string] |
151 |
| - [:db/ident {:optional true} :keyword] |
152 |
| - [:block/order {:optional true} db-malli-schema/block-order] |
153 |
| - [::m/default extra-attr-map-schema]]] |
154 |
| - [:remove-page |
155 |
| - [:map |
156 |
| - [:op :keyword] |
157 |
| - [:block-uuid :uuid]]]]]] |
158 |
| - [:asset-uuid->url {:optional true} [:map-of :uuid :string]] |
159 |
| - [:uploaded-assets {:optional true} [:map-of :uuid :map]] |
160 |
| - [:ex-data {:optional true} [:map [:type :keyword]]] |
161 |
| - [:ex-message {:optional true} :string]]) |
162 |
| - |
163 |
| -(def data-from-ws-coercer (m/coercer data-from-ws-schema mt/string-transformer)) |
164 |
| -(def data-from-ws-validator (m/validator data-from-ws-schema)) |
165 |
| - |
166 |
| -(defn- with-shared-schema-attrs |
167 |
| - [malli-schema] |
168 |
| - (let [[head api-schema-seq] (split-at 2 malli-schema)] |
169 |
| - (vec |
170 |
| - (concat |
171 |
| - head |
172 |
| - (map |
173 |
| - (fn [api-schema] |
174 |
| - (let [[api-name [type']] api-schema] |
175 |
| - (if (= :map type') |
176 |
| - [api-name (vec (concat (second api-schema) [[:req-id :string] |
177 |
| - [:action :string] |
178 |
| - [:profile {:optional true} :boolean]]))] |
179 |
| - api-schema))) |
180 |
| - api-schema-seq))))) |
181 |
| - |
182 |
| -(def ^:large-vars/data-var data-to-ws-schema |
183 |
| - (mu/closed-schema |
184 |
| - (with-shared-schema-attrs |
185 |
| - [:multi {:dispatch :action} |
186 |
| - ["list-graphs" |
187 |
| - [:map]] |
188 |
| - ["register-graph-updates" |
189 |
| - [:map |
190 |
| - [:graph-uuid :string]]] |
191 |
| - ["apply-ops" |
192 |
| - [:or |
193 |
| - [:map |
194 |
| - [:req-id :string] |
195 |
| - [:action :string] |
196 |
| - [:profile {:optional true} :boolean] |
197 |
| - [:graph-uuid :string] |
198 |
| - [:ops [:sequential to-ws-op-schema]] |
199 |
| - [:t-before :int]] |
200 |
| - [:map |
201 |
| - [:req-id :string] |
202 |
| - [:action :string] |
203 |
| - [:profile {:optional true} :boolean] |
204 |
| - [:s3-key :string]]]] |
205 |
| - ["presign-put-temp-s3-obj" |
206 |
| - [:map]] |
207 |
| - ["upload-graph" |
208 |
| - [:map |
209 |
| - [:s3-key :string] |
210 |
| - [:graph-name :string]]] |
211 |
| - ["download-graph" |
212 |
| - [:map |
213 |
| - [:graph-uuid :string]]] |
214 |
| - ["download-info-list" |
215 |
| - [:map |
216 |
| - [:graph-uuid :string]]] |
217 |
| - ["snapshot-list" |
218 |
| - [:map |
219 |
| - [:graph-uuid :string]]] |
220 |
| - ["snapshot-graph" |
221 |
| - [:map |
222 |
| - [:graph-uuid :string]]] |
223 |
| - ["grant-access" |
224 |
| - [:map |
225 |
| - [:graph-uuid :uuid] |
226 |
| - [:target-user-uuids {:optional true} [:sequential :uuid]] |
227 |
| - [:target-user-emails {:optional true} [:sequential :string]]]] |
228 |
| - ["get-users-info" |
229 |
| - [:map |
230 |
| - [:graph-uuid :uuid]]] |
231 |
| - ["inject-users-info" |
232 |
| - [:map |
233 |
| - [:graph-uuid :uuid]]] |
234 |
| - ["delete-graph" |
235 |
| - [:map |
236 |
| - [:graph-uuid :uuid]]] |
237 |
| - ["query-block-content-versions" |
238 |
| - [:map |
239 |
| - [:graph-uuid :string] |
240 |
| - [:block-uuids [:sequential :uuid]]]] |
241 |
| - ["calibrate-graph-skeleton" |
242 |
| - [:map |
243 |
| - [:graph-uuid :string] |
244 |
| - [:t :int] |
245 |
| - [:schema-version :int] |
246 |
| - [:db-ident-blocks [:sequential |
247 |
| - [:map |
248 |
| - [:db/ident :keyword] |
249 |
| - [::m/default extra-attr-map-schema]]]]]] |
250 |
| - ["get-graph-skeleton" |
251 |
| - [:map |
252 |
| - [:graph-uuid :string]]] |
253 |
| - ["get-assets-upload-urls" |
254 |
| - [:map |
255 |
| - [:graph-uuid :string] |
256 |
| - [:asset-uuid->metadata [:map-of :uuid [:map-of :string :string]]]]] |
257 |
| - ["get-assets-download-urls" |
258 |
| - [:map |
259 |
| - [:graph-uuid :string] |
260 |
| - [:asset-uuids [:sequential :uuid]]]] |
261 |
| - ["delete-assets" |
262 |
| - [:map |
263 |
| - [:graph-uuid :string] |
264 |
| - [:asset-uuids [:sequential :uuid]]]] |
265 |
| - ["get-user-devices" |
266 |
| - [:map]] |
267 |
| - ["add-user-device" |
268 |
| - [:map |
269 |
| - [:device-name :string]]] |
270 |
| - ["remove-user-device" |
271 |
| - [:map |
272 |
| - [:device-uuid :uuid]]] |
273 |
| - ["update-user-device-name" |
274 |
| - [:map |
275 |
| - [:device-uuid :uuid] |
276 |
| - [:device-name :string]]] |
277 |
| - ["add-device-public-key" |
278 |
| - [:map |
279 |
| - [:device-uuid :uuid] |
280 |
| - [:key-name :string] |
281 |
| - [:public-key :string]]] |
282 |
| - ["remove-device-public-key" |
283 |
| - [:map |
284 |
| - [:device-uuid :uuid] |
285 |
| - [:key-name :string]]] |
286 |
| - ["sync-encrypted-aes-key" |
287 |
| - [:map |
288 |
| - [:device-uuid->encrypted-aes-key [:map-of :uuid :string]] |
289 |
| - [:graph-uuid :uuid]]]]))) |
290 |
| - |
291 |
| -(def data-to-ws-encoder (m/encoder data-to-ws-schema (mt/transformer |
292 |
| - mt/string-transformer |
293 |
| - (mt/key-transformer {:encode m/-keyword->string})))) |
294 |
| -(def data-to-ws-coercer (m/coercer data-to-ws-schema mt/string-transformer nil |
295 |
| - #(do |
296 |
| - (prn ::data-to-ws-schema %) |
297 |
| - (m/-fail! ::data-to-ws-schema %)))) |
0 commit comments