Skip to content

Commit 73e51a8

Browse files
committed
refactor: split rtc malli-schema into its own ns
1 parent 6105476 commit 73e51a8

File tree

8 files changed

+321
-318
lines changed

8 files changed

+321
-318
lines changed

src/main/frontend/worker/rtc/client.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"Fns about push local updates"
33
(:require [clojure.string :as string]
44
[datascript.core :as d]
5+
[frontend.common.missionary :as c.m]
56
[frontend.worker.rtc.client-op :as client-op]
6-
[frontend.worker.rtc.const :as rtc-const]
77
[frontend.worker.rtc.exception :as r.ex]
88
[frontend.worker.rtc.log-and-state :as rtc-log-and-state]
9+
[frontend.worker.rtc.malli-schema :as rtc-schema]
910
[frontend.worker.rtc.remote-update :as r.remote-update]
1011
[frontend.worker.rtc.skeleton :as r.skeleton]
1112
[frontend.worker.rtc.ws :as ws]
1213
[frontend.worker.rtc.ws-util :as ws-util]
13-
[frontend.common.missionary :as c.m]
1414
[missionary.core :as m]))
1515

1616
(defn- register-graph-updates
@@ -330,7 +330,7 @@
330330
(m/sp
331331
(let [block-ops-map-coll (client-op/get&remove-all-block-ops repo)]
332332
(when-let [block-uuid->remote-ops (not-empty (gen-block-uuid->remote-ops @conn block-ops-map-coll))]
333-
(when-let [ops-for-remote (rtc-const/to-ws-ops-decoder
333+
(when-let [ops-for-remote (rtc-schema/to-ws-ops-decoder
334334
(sort-remote-ops
335335
block-uuid->remote-ops))]
336336
(let [local-tx (client-op/get-local-tx repo)

src/main/frontend/worker/rtc/client_op.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
(ns frontend.worker.rtc.client-op
22
"Store client-ops in a persisted datascript"
33
(:require [datascript.core :as d]
4-
[frontend.worker.rtc.const :as rtc-const]
5-
[frontend.worker.state :as worker-state]
64
[frontend.common.missionary :as c.m]
5+
[frontend.worker.rtc.malli-schema :as rtc-schema]
6+
[frontend.worker.state :as worker-state]
77
[logseq.db.sqlite.util :as sqlite-util]
88
[malli.core :as ma]
99
[malli.transform :as mt]
@@ -41,7 +41,7 @@
4141
[:t :int]
4242
[:value [:map
4343
[:block-uuid :uuid]
44-
[:av-coll [:sequential rtc-const/av-schema]]]]]]
44+
[:av-coll [:sequential rtc-schema/av-schema]]]]]]
4545

4646
[:update-asset
4747
[:catn
+1-293
Original file line numberDiff line numberDiff line change
@@ -1,297 +1,5 @@
11
(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")
73

84
(goog-define RTC-E2E-TEST* false)
95
(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

Comments
 (0)