···12121313(* returns bindings sorted in dag-cbor canonical order *)
1414let ordered_map_bindings (m : 'a String_map.t) : (string * 'a) list =
1515- String_map.bindings m |> List.sort (fun (a, _) (b, _) -> dag_cbor_key_compare a b)
1515+ String_map.bindings m
1616+ |> List.sort (fun (a, _) (b, _) -> dag_cbor_key_compare a b)
16171718let type_info_length len =
1819 if len < 24 then 1
···201202 let len = String_map.cardinal m in
202203 write_type_and_argument t 5 (Int64.of_int len) ;
203204 ordered_map_bindings m
204204- |> List.iter (fun (k, v) ->
205205- write_string t k ;
206206- write_value t v )
205205+ |> List.iter (fun (k, v) -> write_string t k ; write_value t v)
207206 | `Link cid ->
208207 write_cid t cid
209208
+88-63
mist/bench/bench_mst.ml
···33module Mem_mst = Mst.Make (Storage.Memory_blockstore)
44module String_map = Dag_cbor.String_map
5566-type timing_result = {name: string; iterations: int; total_s: float; per_iter_s: float}
66+type timing_result =
77+ {name: string; iterations: int; total_s: float; per_iter_s: float}
7889let time_it name f : timing_result Lwt.t =
910 let start = Unix.gettimeofday () in
···1415let time_it_n name n f : timing_result Lwt.t =
1516 let start = Unix.gettimeofday () in
1617 let%lwt () =
1717- let rec loop i = if i >= n then Lwt.return_unit else f () >>= fun _ -> loop (i + 1) in
1818+ let rec loop i =
1919+ if i >= n then Lwt.return_unit else f () >>= fun _ -> loop (i + 1)
2020+ in
1821 loop 0
1922 in
2023 let elapsed = Unix.gettimeofday () -. start in
2121- Lwt.return {name; iterations= n; total_s= elapsed; per_iter_s= elapsed /. float_of_int n}
2424+ Lwt.return
2525+ { name
2626+ ; iterations= n
2727+ ; total_s= elapsed
2828+ ; per_iter_s= elapsed /. float_of_int n }
22292330let print_result r =
2431 if r.iterations = 1 then Printf.printf " %-50s %10.4f s\n%!" r.name r.total_s
2532 else
2626- Printf.printf " %-50s %10.4f s total, %10.6f s/iter (%d iters)\n%!" r.name r.total_s
2727- r.per_iter_s r.iterations
3333+ Printf.printf " %-50s %10.4f s total, %10.6f s/iter (%d iters)\n%!" r.name
3434+ r.total_s r.per_iter_s r.iterations
28352936let print_header name = Printf.printf "\n=== %s ===\n%!" name
3037···8491 let store = Storage.Memory_blockstore.create () in
8592 let%lwt data = generate_bulk_data store size in
8693 let%lwt r =
8787- time_it (Printf.sprintf "of_assoc %d records" size) (fun () -> Mem_mst.of_assoc store data)
9494+ time_it (Printf.sprintf "of_assoc %d records" size) (fun () ->
9595+ Mem_mst.of_assoc store data )
8896 in
8997 print_result r ; Lwt.return_unit )
9098 sizes
···98106 let shuffled = shuffle data in
99107 (* incremental add *)
100108 let%lwt mst_base =
101101- match%lwt Mem_mst.create_empty store with Ok mst -> Lwt.return mst | Error e -> raise e
109109+ match%lwt Mem_mst.create_empty store with
110110+ | Ok mst ->
111111+ Lwt.return mst
112112+ | Error e ->
113113+ raise e
102114 in
103115 let%lwt r1 =
104104- time_it
105105- (Printf.sprintf "add (incremental) %d records" size)
106106- (fun () -> Lwt_list.fold_left_s (fun t (k, v) -> Mem_mst.add t k v) mst_base shuffled)
116116+ time_it (Printf.sprintf "add (incremental) %d records" size) (fun () ->
117117+ Lwt_list.fold_left_s
118118+ (fun t (k, v) -> Mem_mst.add t k v)
119119+ mst_base shuffled )
107120 in
108121 print_result r1 ;
109122 (* add_rebuild for comparison *)
110123 let%lwt mst_base2 =
111111- match%lwt Mem_mst.create_empty store with Ok mst -> Lwt.return mst | Error e -> raise e
124124+ match%lwt Mem_mst.create_empty store with
125125+ | Ok mst ->
126126+ Lwt.return mst
127127+ | Error e ->
128128+ raise e
112129 in
113130 let%lwt r2 =
114114- time_it
115115- (Printf.sprintf "add_rebuild %d records" size)
116116- (fun () ->
117117- Lwt_list.fold_left_s (fun t (k, v) -> Mem_mst.add_rebuild t k v) mst_base2 shuffled )
131131+ time_it (Printf.sprintf "add_rebuild %d records" size) (fun () ->
132132+ Lwt_list.fold_left_s
133133+ (fun t (k, v) -> Mem_mst.add_rebuild t k v)
134134+ mst_base2 shuffled )
118135 in
119136 print_result r2 ;
120137 let speedup = r2.total_s /. r1.total_s in
···130147 let store = Storage.Memory_blockstore.create () in
131148 let%lwt data = generate_bulk_data store tree_size in
132149 let%lwt mst = Mem_mst.of_assoc store data in
133133- let to_delete = shuffle data |> List.filteri (fun i _ -> i < delete_count) in
150150+ let to_delete =
151151+ shuffle data |> List.filteri (fun i _ -> i < delete_count)
152152+ in
134153 (* incremental delete *)
135154 let%lwt r1 =
136155 time_it
137156 (Printf.sprintf "delete (incr) %d from %d" delete_count tree_size)
138138- (fun () -> Lwt_list.fold_left_s (fun t (k, _) -> Mem_mst.delete t k) mst to_delete)
157157+ (fun () ->
158158+ Lwt_list.fold_left_s
159159+ (fun t (k, _) -> Mem_mst.delete t k)
160160+ mst to_delete )
139161 in
140162 print_result r1 ;
141163 (* rebuild the tree for delete_rebuild test *)
···144166 time_it
145167 (Printf.sprintf "delete_rebuild %d from %d" delete_count tree_size)
146168 (fun () ->
147147- Lwt_list.fold_left_s (fun t (k, _) -> Mem_mst.delete_rebuild t k) mst2 to_delete )
169169+ Lwt_list.fold_left_s
170170+ (fun t (k, _) -> Mem_mst.delete_rebuild t k)
171171+ mst2 to_delete )
148172 in
149173 print_result r2 ;
150174 let speedup = r2.total_s /. r1.total_s in
···163187 let%lwt mst = Mem_mst.of_assoc store data in
164188 let%lwt extra_data = generate_bulk_data store iterations in
165189 let%lwt r =
166166- time_it_n
167167- (Printf.sprintf "single add to %d-record tree" size)
168168- iterations
169169- (fun () ->
190190+ time_it_n (Printf.sprintf "single add to %d-record tree" size)
191191+ iterations (fun () ->
170192 let k, v = List.nth extra_data (Random.int iterations) in
171193 Mem_mst.add mst k v >|= fun _ -> () )
172194 in
···184206 let shuffled = shuffle data in
185207 let idx = ref 0 in
186208 let%lwt r =
187187- time_it_n
188188- (Printf.sprintf "single delete from %d-record tree" size)
189189- (min iterations size)
190190- (fun () ->
209209+ time_it_n (Printf.sprintf "single delete from %d-record tree" size)
210210+ (min iterations size) (fun () ->
191211 let k, _ = List.nth shuffled !idx in
192212 idx := !idx + 1 ;
193213 Mem_mst.delete mst k >|= fun _ -> () )
···203223 let%lwt data = generate_bulk_data store size in
204224 let%lwt mst = Mem_mst.of_assoc store data in
205225 let%lwt r1 =
206206- time_it (Printf.sprintf "build_map %d records" size) (fun () -> Mem_mst.build_map mst)
226226+ time_it (Printf.sprintf "build_map %d records" size) (fun () ->
227227+ Mem_mst.build_map mst )
207228 in
208229 print_result r1 ;
209230 let%lwt r2 =
210210- time_it
211211- (Printf.sprintf "leaves_of_root %d records" size)
212212- (fun () -> Mem_mst.leaves_of_root mst)
231231+ time_it (Printf.sprintf "leaves_of_root %d records" size) (fun () ->
232232+ Mem_mst.leaves_of_root mst )
213233 in
214234 print_result r2 ;
215235 let%lwt r3 =
216216- time_it (Printf.sprintf "leaf_count %d records" size) (fun () -> Mem_mst.leaf_count mst)
236236+ time_it (Printf.sprintf "leaf_count %d records" size) (fun () ->
237237+ Mem_mst.leaf_count mst )
217238 in
218239 print_result r3 ;
219240 let%lwt r4 =
220220- time_it (Printf.sprintf "all_nodes %d records" size) (fun () -> Mem_mst.all_nodes mst)
241241+ time_it (Printf.sprintf "all_nodes %d records" size) (fun () ->
242242+ Mem_mst.all_nodes mst )
221243 in
222244 print_result r4 ;
223245 let%lwt r5 =
224224- time_it
225225- (Printf.sprintf "collect_nodes_and_leaves %d records" size)
226226- (fun () -> Mem_mst.collect_nodes_and_leaves mst)
246246+ time_it (Printf.sprintf "collect_nodes_and_leaves %d records" size)
247247+ (fun () -> Mem_mst.collect_nodes_and_leaves mst )
227248 in
228249 print_result r5 ; Lwt.return_unit )
229250 sizes
···236257 let%lwt data = generate_bulk_data store size in
237258 let%lwt mst = Mem_mst.of_assoc store data in
238259 let%lwt r1 =
239239- time_it
240240- (Printf.sprintf "to_blocks_stream consume %d" size)
241241- (fun () ->
260260+ time_it (Printf.sprintf "to_blocks_stream consume %d" size) (fun () ->
242261 let stream = Mem_mst.to_blocks_stream mst in
243262 Lwt_seq.fold_left_s (fun count _ -> Lwt.return (count + 1)) 0 stream )
244263 in
245264 print_result r1 ;
246265 let%lwt r2 =
247247- time_it
248248- (Printf.sprintf "to_ordered_stream consume %d" size)
249249- (fun () ->
266266+ time_it (Printf.sprintf "to_ordered_stream consume %d" size) (fun () ->
250267 let stream = Mem_mst.to_ordered_stream mst in
251268 Lwt_seq.fold_left_s (fun count _ -> Lwt.return (count + 1)) 0 stream )
252269 in
···266283 in
267284 let%lwt r =
268285 time_it
269269- (Printf.sprintf "proof_for_key %d proofs, %d-record tree" num_proofs size)
270270- (fun () ->
286286+ (Printf.sprintf "proof_for_key %d proofs, %d-record tree" num_proofs
287287+ size ) (fun () ->
271288 Lwt_list.iter_s
272289 (fun k -> Mem_mst.proof_for_key mst mst.root k >|= fun _ -> ())
273290 test_keys )
274291 in
275292 print_result r ;
276276- Printf.printf " (%.6f s per proof)\n%!" (r.total_s /. float_of_int num_proofs) ;
293293+ Printf.printf " (%.6f s per proof)\n%!"
294294+ (r.total_s /. float_of_int num_proofs) ;
277295 Lwt.return_unit )
278296 sizes
279297···286304 let%lwt mst1 = Mem_mst.of_assoc store data in
287305 let%lwt mst2 = Mem_mst.of_assoc store (shuffle data) in
288306 let%lwt r =
289289- time_it
290290- (Printf.sprintf "equal (identical trees) %d records" size)
291291- (fun () -> Mem_mst.equal mst1 mst2)
307307+ time_it (Printf.sprintf "equal (identical trees) %d records" size)
308308+ (fun () -> Mem_mst.equal mst1 mst2 )
292309 in
293310 print_result r ; Lwt.return_unit )
294311 sizes
···306323 let pending_adds = ref (shuffle extra_data) in
307324 let%lwt r =
308325 time_it
309309- (Printf.sprintf "mixed %d ops on %d-record tree"
310310- num_ops initial_size )
326326+ (Printf.sprintf "mixed %d ops on %d-record tree" num_ops initial_size)
311327 (fun () ->
312328 let rec loop mst i =
313329 if i >= num_ops then Lwt.return mst
···345361 loop mst 0 )
346362 in
347363 print_result r ;
348348- Printf.printf " (%.6f s per op avg)\n%!" (r.total_s /. float_of_int num_ops) ;
364364+ Printf.printf " (%.6f s per op avg)\n%!"
365365+ (r.total_s /. float_of_int num_ops) ;
349366 Lwt.return_unit )
350367 configs
351368···361378 let%lwt batch_data = generate_bulk_data store batch_size in
362379 let%lwt r1 =
363380 time_it
364364- (Printf.sprintf "batch add (incremental) %d to %d tree" batch_size tree_size)
365365- (fun () -> Lwt_list.fold_left_s (fun t (k, v) -> Mem_mst.add t k v) mst batch_data)
381381+ (Printf.sprintf "batch add (incremental) %d to %d tree" batch_size
382382+ tree_size ) (fun () ->
383383+ Lwt_list.fold_left_s
384384+ (fun t (k, v) -> Mem_mst.add t k v)
385385+ mst batch_data )
366386 in
367387 print_result r1 ;
368388 let%lwt r2 =
369389 time_it
370370- (Printf.sprintf "batch add (rebuild) %d to %d tree" batch_size tree_size)
371371- (fun () -> Mem_mst.of_assoc store (initial_data @ batch_data))
390390+ (Printf.sprintf "batch add (rebuild) %d to %d tree" batch_size
391391+ tree_size ) (fun () ->
392392+ Mem_mst.of_assoc store (initial_data @ batch_data) )
372393 in
373394 print_result r2 ;
374395 let speedup = r2.total_s /. r1.total_s in
375375- Printf.printf " -> incremental is %.2fx %s for batch of %d\n%!" (abs_float speedup)
396396+ Printf.printf " -> incremental is %.2fx %s for batch of %d\n%!"
397397+ (abs_float speedup)
376398 (if speedup > 1.0 then "faster" else "slower")
377399 batch_size ;
378400 Lwt.return_unit )
···401423 print_result r1 ;
402424 (* last n keys *)
403425 let late_keys =
404404- List.filteri (fun i _ -> i >= List.length sorted_keys - num_lookups) sorted_keys
426426+ List.filteri
427427+ (fun i _ -> i >= List.length sorted_keys - num_lookups)
428428+ sorted_keys
405429 in
406430 let%lwt r2 =
407431 time_it
···413437 in
414438 print_result r2 ;
415439 (* random keys *)
416416- let random_keys = shuffle sorted_keys |> List.filteri (fun i _ -> i < num_lookups) in
440440+ let random_keys =
441441+ shuffle sorted_keys |> List.filteri (fun i _ -> i < num_lookups)
442442+ in
417443 let%lwt r3 =
418444 time_it
419445 (Printf.sprintf "proof random keys (%d from %d tree)" num_lookups size)
···442468 in
443469 let iterations = 100 in
444470 let%lwt r =
445445- time_it_n
446446- (Printf.sprintf "serialize root node (%d-record tree)" size)
447447- iterations
448448- (fun () -> Mem_mst.serialize mst root_node >|= fun _ -> ())
471471+ time_it_n (Printf.sprintf "serialize root node (%d-record tree)" size)
472472+ iterations (fun () ->
473473+ Mem_mst.serialize mst root_node >|= fun _ -> () )
449474 in
450475 print_result r ; Lwt.return_unit )
451476 sizes
···459484 let%lwt mst = Mem_mst.of_assoc store data in
460485 let iterations = 1000 in
461486 let%lwt r =
462462- time_it_n (Printf.sprintf "layer query (%d-record tree)" size) iterations (fun () ->
463463- Mem_mst.layer mst >|= fun _ -> () )
487487+ time_it_n (Printf.sprintf "layer query (%d-record tree)" size)
488488+ iterations (fun () -> Mem_mst.layer mst >|= fun _ -> () )
464489 in
465490 print_result r ; Lwt.return_unit )
466491 sizes
···88 let open Yojson.Safe.Util in
99 try
1010 match json |> member "$type" |> to_string with
1111- | "app.bsky.unspecced.defs#threadItemPost" ->
1212- (match App_bsky_unspecced_defs.thread_item_post_of_yojson json with
1313- | Ok v -> Ok (ThreadItemPost v)
1414- | Error e -> Error e)
1515- | _ -> Ok (Unknown json)
1111+ | "app.bsky.unspecced.defs#threadItemPost" -> (
1212+ match App_bsky_unspecced_defs.thread_item_post_of_yojson json with
1313+ | Ok v ->
1414+ Ok (ThreadItemPost v)
1515+ | Error e ->
1616+ Error e )
1717+ | _ ->
1818+ Ok (Unknown json)
1619 with _ -> Error "failed to parse union"
17201821let value_to_yojson = function
1919- | ThreadItemPost v ->
2020- (match App_bsky_unspecced_defs.thread_item_post_to_yojson v with
2121- | `Assoc fields -> `Assoc (("$type", `String "app.bsky.unspecced.defs#threadItemPost") :: fields)
2222- | other -> other)
2323- | Unknown j -> j
2222+ | ThreadItemPost v -> (
2323+ match App_bsky_unspecced_defs.thread_item_post_to_yojson v with
2424+ | `Assoc fields ->
2525+ `Assoc
2626+ (("$type", `String "app.bsky.unspecced.defs#threadItemPost") :: fields)
2727+ | other ->
2828+ other )
2929+ | Unknown j ->
3030+ j
24312525-type thread_item =
2626- {
2727- uri: string;
2828- depth: int;
2929- value: value;
3030- }
3232+type thread_item = {uri: string; depth: int; value: value}
3133[@@deriving yojson {strict= false}]
32343335(** (NOTE: this endpoint is under development and WILL change without notice. Don't use it until it is moved out of `unspecced` or your application WILL break) Get additional posts under a thread e.g. replies hidden by threadgate. Based on an anchor post at any depth of the tree, returns top-level replies below that anchor. It does not include ancestors nor the anchor itself. This should be called after exhausting `app.bsky.unspecced.getPostThreadV2`. Does not require auth, but additional metadata and filtering will be applied for authed requests. *)
···3537 let nsid = "app.bsky.unspecced.getPostThreadOtherV2"
36383739 type params =
3838- {
3939- anchor: string;
4040- prioritize_followed_users: bool option [@key "prioritizeFollowedUsers"] [@default None];
4141- }
4242-[@@deriving yojson {strict= false}]
4040+ { anchor: string
4141+ ; prioritize_followed_users: bool option
4242+ [@key "prioritizeFollowedUsers"] [@default None] }
4343+ [@@deriving yojson {strict= false}]
43444444- type output =
4545- {
4646- thread: thread_item list;
4747- }
4848-[@@deriving yojson {strict= false}]
4545+ type output = {thread: thread_item list} [@@deriving yojson {strict= false}]
49465050- let call
5151- ~anchor
5252- ?prioritize_followed_users
5353- (client : Hermes.client) : output Lwt.t =
4747+ let call ~anchor ?prioritize_followed_users (client : Hermes.client) :
4848+ output Lwt.t =
5449 let params : params = {anchor; prioritize_followed_users} in
5550 Hermes.query client nsid (params_to_yojson params) output_of_yojson
5651end
5757-
···11(* generated from com.atproto.moderation.createReport *)
2233-type mod_tool =
44- {
55- name: string;
66- meta: Yojson.Safe.t option [@default None];
77- }
33+type mod_tool = {name: string; meta: Yojson.Safe.t option [@default None]}
84[@@deriving yojson {strict= false}]
95106(** Submit a moderation report regarding an atproto account or record. Implemented by moderation services (with PDS proxying), and requires auth. *)
···128 let nsid = "com.atproto.moderation.createReport"
1391410 type params = unit
1111+1512 let params_to_yojson () = `Assoc []
16131714 type subject =
1818- | RepoRef of Com_atproto_admin_defs.repo_ref
1919- | StrongRef of Com_atproto_repo_strongRef.main
2020- | Unknown of Yojson.Safe.t
1515+ | RepoRef of Com_atproto_admin_defs.repo_ref
1616+ | StrongRef of Com_atproto_repo_strongRef.main
1717+ | Unknown of Yojson.Safe.t
21182222-let subject_of_yojson json =
2323- let open Yojson.Safe.Util in
2424- try
2525- match json |> member "$type" |> to_string with
2626- | "com.atproto.admin.defs#repoRef" ->
2727- (match Com_atproto_admin_defs.repo_ref_of_yojson json with
2828- | Ok v -> Ok (RepoRef v)
2929- | Error e -> Error e)
3030- | "com.atproto.repo.strongRef" ->
3131- (match Com_atproto_repo_strongRef.main_of_yojson json with
3232- | Ok v -> Ok (StrongRef v)
3333- | Error e -> Error e)
3434- | _ -> Ok (Unknown json)
3535- with _ -> Error "failed to parse union"
1919+ let subject_of_yojson json =
2020+ let open Yojson.Safe.Util in
2121+ try
2222+ match json |> member "$type" |> to_string with
2323+ | "com.atproto.admin.defs#repoRef" -> (
2424+ match Com_atproto_admin_defs.repo_ref_of_yojson json with
2525+ | Ok v ->
2626+ Ok (RepoRef v)
2727+ | Error e ->
2828+ Error e )
2929+ | "com.atproto.repo.strongRef" -> (
3030+ match Com_atproto_repo_strongRef.main_of_yojson json with
3131+ | Ok v ->
3232+ Ok (StrongRef v)
3333+ | Error e ->
3434+ Error e )
3535+ | _ ->
3636+ Ok (Unknown json)
3737+ with _ -> Error "failed to parse union"
36383737-let subject_to_yojson = function
3838- | RepoRef v ->
3939- (match Com_atproto_admin_defs.repo_ref_to_yojson v with
4040- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.admin.defs#repoRef") :: fields)
4141- | other -> other)
4242- | StrongRef v ->
4343- (match Com_atproto_repo_strongRef.main_to_yojson v with
4444- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.strongRef") :: fields)
4545- | other -> other)
4646- | Unknown j -> j
3939+ let subject_to_yojson = function
4040+ | RepoRef v -> (
4141+ match Com_atproto_admin_defs.repo_ref_to_yojson v with
4242+ | `Assoc fields ->
4343+ `Assoc (("$type", `String "com.atproto.admin.defs#repoRef") :: fields)
4444+ | other ->
4545+ other )
4646+ | StrongRef v -> (
4747+ match Com_atproto_repo_strongRef.main_to_yojson v with
4848+ | `Assoc fields ->
4949+ `Assoc (("$type", `String "com.atproto.repo.strongRef") :: fields)
5050+ | other ->
5151+ other )
5252+ | Unknown j ->
5353+ j
47544848-type input =
4949- {
5050- reason_type: Com_atproto_moderation_defs.reason_type [@key "reasonType"];
5151- reason: string option [@default None];
5252- subject: subject;
5353- mod_tool: mod_tool option [@key "modTool"] [@default None];
5454- }
5555+ type input =
5656+ { reason_type: Com_atproto_moderation_defs.reason_type [@key "reasonType"]
5757+ ; reason: string option [@default None]
5858+ ; subject: subject
5959+ ; mod_tool: mod_tool option [@key "modTool"] [@default None] }
5560 [@@deriving yojson {strict= false}]
56615762 type output =
5858- {
5959- id: int;
6060- reason_type: Com_atproto_moderation_defs.reason_type [@key "reasonType"];
6161- reason: string option [@default None];
6262- subject: subject;
6363- reported_by: string [@key "reportedBy"];
6464- created_at: string [@key "createdAt"];
6565- }
6666-[@@deriving yojson {strict= false}]
6363+ { id: int
6464+ ; reason_type: Com_atproto_moderation_defs.reason_type [@key "reasonType"]
6565+ ; reason: string option [@default None]
6666+ ; subject: subject
6767+ ; reported_by: string [@key "reportedBy"]
6868+ ; created_at: string [@key "createdAt"] }
6969+ [@@deriving yojson {strict= false}]
67706868- let call
6969- ~reason_type
7070- ?reason
7171- ~subject
7272- ?mod_tool
7373- (client : Hermes.client) : output Lwt.t =
7171+ let call ~reason_type ?reason ~subject ?mod_tool (client : Hermes.client) :
7272+ output Lwt.t =
7473 let params = () in
7575- let input = Some ({reason_type; reason; subject; mod_tool} |> input_to_yojson) in
7676- Hermes.procedure client nsid (params_to_yojson params) input output_of_yojson
7474+ let input =
7575+ Some ({reason_type; reason; subject; mod_tool} |> input_to_yojson)
7676+ in
7777+ Hermes.procedure client nsid (params_to_yojson params) input
7878+ output_of_yojson
7779end
7878-
+12-5
pegasus/lexicons/com_atproto_moderation_defs.ml
···2233(** string type with known values *)
44type reason_type = string
55+56let reason_type_of_yojson = function
66- | `String s -> Ok s
77- | _ -> Error "reason_type: expected string"
77+ | `String s ->
88+ Ok s
99+ | _ ->
1010+ Error "reason_type: expected string"
1111+812let reason_type_to_yojson s = `String s
9131014(** Spam: frequent unwanted promotion, replies, mentions *)
···30343135(** string type with known values: Tag describing a type of subject that might be reported. *)
3236type subject_type = string
3737+3338let subject_type_of_yojson = function
3434- | `String s -> Ok s
3535- | _ -> Error "subject_type: expected string"
3636-let subject_type_to_yojson s = `String s
3939+ | `String s ->
4040+ Ok s
4141+ | _ ->
4242+ Error "subject_type: expected string"
37434444+let subject_type_to_yojson s = `String s
+129-115
pegasus/lexicons/com_atproto_repo_applyWrites.ml
···11(* generated from com.atproto.repo.applyWrites *)
2233type delete_result = unit
44+45let delete_result_of_yojson _ = Ok ()
66+57let delete_result_to_yojson () = `Assoc []
6879type update_result =
88- {
99- uri: string;
1010- cid: string;
1111- validation_status: string option [@key "validationStatus"] [@default None];
1010+ { uri: string
1111+ ; cid: string
1212+ ; validation_status: string option [@key "validationStatus"] [@default None]
1213 }
1314[@@deriving yojson {strict= false}]
14151516type create_result =
1616- {
1717- uri: string;
1818- cid: string;
1919- validation_status: string option [@key "validationStatus"] [@default None];
1717+ { uri: string
1818+ ; cid: string
1919+ ; validation_status: string option [@key "validationStatus"] [@default None]
2020 }
2121[@@deriving yojson {strict= false}]
22222323-type delete =
2424- {
2525- collection: string;
2626- rkey: string;
2727- }
2323+type delete = {collection: string; rkey: string}
2824[@@deriving yojson {strict= false}]
29253030-type update =
3131- {
3232- collection: string;
3333- rkey: string;
3434- value: Yojson.Safe.t;
3535- }
2626+type update = {collection: string; rkey: string; value: Yojson.Safe.t}
3627[@@deriving yojson {strict= false}]
37283829type create =
3939- {
4040- collection: string;
4141- rkey: string option [@default None];
4242- value: Yojson.Safe.t;
4343- }
3030+ {collection: string; rkey: string option [@default None]; value: Yojson.Safe.t}
4431[@@deriving yojson {strict= false}]
45324633(** Apply a batch transaction of repository creates, updates, and deletes. Requires auth, implemented by PDS. *)
···4835 let nsid = "com.atproto.repo.applyWrites"
49365037 type params = unit
3838+5139 let params_to_yojson () = `Assoc []
52405353- type writes_item =
5454- | Create of create
5555- | Update of update
5656- | Delete of delete
4141+ type writes_item = Create of create | Update of update | Delete of delete
57425858-let writes_item_of_yojson json =
5959- let open Yojson.Safe.Util in
6060- try
6161- match json |> member "$type" |> to_string with
6262- | "com.atproto.repo.applyWrites#create" ->
6363- (match create_of_yojson json with
6464- | Ok v -> Ok (Create v)
6565- | Error e -> Error e)
6666- | "com.atproto.repo.applyWrites#update" ->
6767- (match update_of_yojson json with
6868- | Ok v -> Ok (Update v)
6969- | Error e -> Error e)
7070- | "com.atproto.repo.applyWrites#delete" ->
7171- (match delete_of_yojson json with
7272- | Ok v -> Ok (Delete v)
7373- | Error e -> Error e)
7474- | t -> Error ("unknown union type: " ^ t)
7575- with _ -> Error "failed to parse union"
4343+ let writes_item_of_yojson json =
4444+ let open Yojson.Safe.Util in
4545+ try
4646+ match json |> member "$type" |> to_string with
4747+ | "com.atproto.repo.applyWrites#create" -> (
4848+ match create_of_yojson json with
4949+ | Ok v ->
5050+ Ok (Create v)
5151+ | Error e ->
5252+ Error e )
5353+ | "com.atproto.repo.applyWrites#update" -> (
5454+ match update_of_yojson json with
5555+ | Ok v ->
5656+ Ok (Update v)
5757+ | Error e ->
5858+ Error e )
5959+ | "com.atproto.repo.applyWrites#delete" -> (
6060+ match delete_of_yojson json with
6161+ | Ok v ->
6262+ Ok (Delete v)
6363+ | Error e ->
6464+ Error e )
6565+ | t ->
6666+ Error ("unknown union type: " ^ t)
6767+ with _ -> Error "failed to parse union"
76687777-let writes_item_to_yojson = function
7878- | Create v ->
7979- (match create_to_yojson v with
8080- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.applyWrites#create") :: fields)
8181- | other -> other)
8282- | Update v ->
8383- (match update_to_yojson v with
8484- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.applyWrites#update") :: fields)
8585- | other -> other)
8686- | Delete v ->
8787- (match delete_to_yojson v with
8888- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.applyWrites#delete") :: fields)
8989- | other -> other)
6969+ let writes_item_to_yojson = function
7070+ | Create v -> (
7171+ match create_to_yojson v with
7272+ | `Assoc fields ->
7373+ `Assoc
7474+ (("$type", `String "com.atproto.repo.applyWrites#create") :: fields)
7575+ | other ->
7676+ other )
7777+ | Update v -> (
7878+ match update_to_yojson v with
7979+ | `Assoc fields ->
8080+ `Assoc
8181+ (("$type", `String "com.atproto.repo.applyWrites#update") :: fields)
8282+ | other ->
8383+ other )
8484+ | Delete v -> (
8585+ match delete_to_yojson v with
8686+ | `Assoc fields ->
8787+ `Assoc
8888+ (("$type", `String "com.atproto.repo.applyWrites#delete") :: fields)
8989+ | other ->
9090+ other )
90919191-type input =
9292- {
9393- repo: string;
9494- validate: bool option [@default None];
9595- writes: writes_item list;
9696- swap_commit: string option [@key "swapCommit"] [@default None];
9797- }
9292+ type input =
9393+ { repo: string
9494+ ; validate: bool option [@default None]
9595+ ; writes: writes_item list
9696+ ; swap_commit: string option [@key "swapCommit"] [@default None] }
9897 [@@deriving yojson {strict= false}]
999810099 type results_item =
101101- | CreateResult of create_result
102102- | UpdateResult of update_result
103103- | DeleteResult of delete_result
100100+ | CreateResult of create_result
101101+ | UpdateResult of update_result
102102+ | DeleteResult of delete_result
104103105105-let results_item_of_yojson json =
106106- let open Yojson.Safe.Util in
107107- try
108108- match json |> member "$type" |> to_string with
109109- | "com.atproto.repo.applyWrites#createResult" ->
110110- (match create_result_of_yojson json with
111111- | Ok v -> Ok (CreateResult v)
112112- | Error e -> Error e)
113113- | "com.atproto.repo.applyWrites#updateResult" ->
114114- (match update_result_of_yojson json with
115115- | Ok v -> Ok (UpdateResult v)
116116- | Error e -> Error e)
117117- | "com.atproto.repo.applyWrites#deleteResult" ->
118118- (match delete_result_of_yojson json with
119119- | Ok v -> Ok (DeleteResult v)
120120- | Error e -> Error e)
121121- | t -> Error ("unknown union type: " ^ t)
122122- with _ -> Error "failed to parse union"
104104+ let results_item_of_yojson json =
105105+ let open Yojson.Safe.Util in
106106+ try
107107+ match json |> member "$type" |> to_string with
108108+ | "com.atproto.repo.applyWrites#createResult" -> (
109109+ match create_result_of_yojson json with
110110+ | Ok v ->
111111+ Ok (CreateResult v)
112112+ | Error e ->
113113+ Error e )
114114+ | "com.atproto.repo.applyWrites#updateResult" -> (
115115+ match update_result_of_yojson json with
116116+ | Ok v ->
117117+ Ok (UpdateResult v)
118118+ | Error e ->
119119+ Error e )
120120+ | "com.atproto.repo.applyWrites#deleteResult" -> (
121121+ match delete_result_of_yojson json with
122122+ | Ok v ->
123123+ Ok (DeleteResult v)
124124+ | Error e ->
125125+ Error e )
126126+ | t ->
127127+ Error ("unknown union type: " ^ t)
128128+ with _ -> Error "failed to parse union"
123129124124-let results_item_to_yojson = function
125125- | CreateResult v ->
126126- (match create_result_to_yojson v with
127127- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.applyWrites#createResult") :: fields)
128128- | other -> other)
129129- | UpdateResult v ->
130130- (match update_result_to_yojson v with
131131- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.applyWrites#updateResult") :: fields)
132132- | other -> other)
133133- | DeleteResult v ->
134134- (match delete_result_to_yojson v with
135135- | `Assoc fields -> `Assoc (("$type", `String "com.atproto.repo.applyWrites#deleteResult") :: fields)
136136- | other -> other)
130130+ let results_item_to_yojson = function
131131+ | CreateResult v -> (
132132+ match create_result_to_yojson v with
133133+ | `Assoc fields ->
134134+ `Assoc
135135+ ( ("$type", `String "com.atproto.repo.applyWrites#createResult")
136136+ :: fields )
137137+ | other ->
138138+ other )
139139+ | UpdateResult v -> (
140140+ match update_result_to_yojson v with
141141+ | `Assoc fields ->
142142+ `Assoc
143143+ ( ("$type", `String "com.atproto.repo.applyWrites#updateResult")
144144+ :: fields )
145145+ | other ->
146146+ other )
147147+ | DeleteResult v -> (
148148+ match delete_result_to_yojson v with
149149+ | `Assoc fields ->
150150+ `Assoc
151151+ ( ("$type", `String "com.atproto.repo.applyWrites#deleteResult")
152152+ :: fields )
153153+ | other ->
154154+ other )
137155138138-type output =
139139- {
140140- commit: Com_atproto_repo_defs.commit_meta option [@default None];
141141- results: results_item list option [@default None];
142142- }
143143-[@@deriving yojson {strict= false}]
156156+ type output =
157157+ { commit: Com_atproto_repo_defs.commit_meta option [@default None]
158158+ ; results: results_item list option [@default None] }
159159+ [@@deriving yojson {strict= false}]
144160145145- let call
146146- ~repo
147147- ?validate
148148- ~writes
149149- ?swap_commit
150150- (client : Hermes.client) : output Lwt.t =
161161+ let call ~repo ?validate ~writes ?swap_commit (client : Hermes.client) :
162162+ output Lwt.t =
151163 let params = () in
152152- let input = Some ({repo; validate; writes; swap_commit} |> input_to_yojson) in
153153- Hermes.procedure client nsid (params_to_yojson params) input output_of_yojson
164164+ let input =
165165+ Some ({repo; validate; writes; swap_commit} |> input_to_yojson)
166166+ in
167167+ Hermes.procedure client nsid (params_to_yojson params) input
168168+ output_of_yojson
154169end
155155-
···55 let nsid = "com.atproto.server.updateEmail"
6677 type params = unit
88+89 let params_to_yojson () = `Assoc []
9101011 type input =
1111- {
1212- email: string;
1313- email_auth_factor: bool option [@key "emailAuthFactor"] [@default None];
1414- token: string option [@default None];
1515- }
1212+ { email: string
1313+ ; email_auth_factor: bool option [@key "emailAuthFactor"] [@default None]
1414+ ; token: string option [@default None] }
1615 [@@deriving yojson {strict= false}]
17161817 type output = unit
1818+1919 let output_of_yojson _ = Ok ()
20202121- let call
2222- ~email
2323- ?email_auth_factor
2424- ?token
2525- (client : Hermes.client) : output Lwt.t =
2121+ let call ~email ?email_auth_factor ?token (client : Hermes.client) :
2222+ output Lwt.t =
2623 let params = () in
2724 let input = Some ({email; email_auth_factor; token} |> input_to_yojson) in
2828- Hermes.procedure client nsid (params_to_yojson params) input output_of_yojson
2525+ Hermes.procedure client nsid (params_to_yojson params) input
2626+ output_of_yojson
2927end
3030-
+6-3
pegasus/lexicons/com_atproto_sync_defs.ml
···2233(** string type with known values *)
44type host_status = string
55+56let host_status_of_yojson = function
66- | `String s -> Ok s
77- | _ -> Error "host_status: expected string"
88-let host_status_to_yojson s = `String s
77+ | `String s ->
88+ Ok s
99+ | _ ->
1010+ Error "host_status: expected string"
9111212+let host_status_to_yojson s = `String s
+2-11
pegasus/lexicons/com_atproto_sync_getBlob.ml
···44module Main = struct
55 let nsid = "com.atproto.sync.getBlob"
6677- type params =
88- {
99- did: string;
1010- cid: string;
1111- }
1212-[@@deriving yojson {strict= false}]
77+ type params = {did: string; cid: string} [@@deriving yojson {strict= false}]
138149 (** raw bytes output with content type *)
1510 type output = bytes * string
16111717- let call
1818- ~did
1919- ~cid
2020- (client : Hermes.client) : output Lwt.t =
1212+ let call ~did ~cid (client : Hermes.client) : output Lwt.t =
2113 let params : params = {did; cid} in
2214 Hermes.query_bytes client nsid (params_to_yojson params)
2315end
2424-
+6-10
pegasus/lexicons/com_atproto_sync_getBlocks.ml
···55 let nsid = "com.atproto.sync.getBlocks"
6677 type params =
88- {
99- did: string;
1010- cids: string list [@of_yojson Hermes_util.query_string_list_of_yojson] [@to_yojson Hermes_util.query_string_list_to_yojson];
1111- }
1212-[@@deriving yojson {strict= false}]
88+ { did: string
99+ ; cids: string list
1010+ [@of_yojson Hermes_util.query_string_list_of_yojson]
1111+ [@to_yojson Hermes_util.query_string_list_to_yojson] }
1212+ [@@deriving yojson {strict= false}]
13131414 (** raw bytes output with content type *)
1515 type output = bytes * string
16161717- let call
1818- ~did
1919- ~cids
2020- (client : Hermes.client) : output Lwt.t =
1717+ let call ~did ~cids (client : Hermes.client) : output Lwt.t =
2118 let params : params = {did; cids} in
2219 Hermes.query_bytes client nsid (params_to_yojson params)
2320end
2424-
+2-9
pegasus/lexicons/com_atproto_sync_getCheckout.ml
···44module Main = struct
55 let nsid = "com.atproto.sync.getCheckout"
6677- type params =
88- {
99- did: string;
1010- }
1111-[@@deriving yojson {strict= false}]
77+ type params = {did: string} [@@deriving yojson {strict= false}]
128139 (** raw bytes output with content type *)
1410 type output = bytes * string
15111616- let call
1717- ~did
1818- (client : Hermes.client) : output Lwt.t =
1212+ let call ~did (client : Hermes.client) : output Lwt.t =
1913 let params : params = {did} in
2014 Hermes.query_bytes client nsid (params_to_yojson params)
2115end
2222-
+3-14
pegasus/lexicons/com_atproto_sync_getHead.ml
···44module Main = struct
55 let nsid = "com.atproto.sync.getHead"
6677- type params =
88- {
99- did: string;
1010- }
1111-[@@deriving yojson {strict= false}]
77+ type params = {did: string} [@@deriving yojson {strict= false}]
1281313- type output =
1414- {
1515- root: string;
1616- }
1717-[@@deriving yojson {strict= false}]
99+ type output = {root: string} [@@deriving yojson {strict= false}]
18101919- let call
2020- ~did
2121- (client : Hermes.client) : output Lwt.t =
1111+ let call ~did (client : Hermes.client) : output Lwt.t =
2212 let params : params = {did} in
2313 Hermes.query client nsid (params_to_yojson params) output_of_yojson
2414end
2525-
···183183 Lwt.return_true
184184185185let rename_credential ~id ~did ~name db =
186186- let%lwt () = Util.Sqlite.use_pool db @@ Queries.rename_passkey ~id ~did ~name in
186186+ let%lwt () =
187187+ Util.Sqlite.use_pool db @@ Queries.rename_passkey ~id ~did ~name
188188+ in
187189 Lwt.return_true
188190189191let generate_registration_options ~did ~email ~existing_credentials db =
+9-3
pegasus/lib/security_key.ml
···196196 Lwt.return (id, secret_b32, uri)
197197198198let verify_setup ~id ~did ~code db =
199199- match%lwt Util.Sqlite.use_pool db @@ Queries.get_security_key_by_id id did with
199199+ match%lwt
200200+ Util.Sqlite.use_pool db @@ Queries.get_security_key_by_id id did
201201+ with
200202 | None ->
201203 Lwt.return_error "Security key not found"
202204 | Some sk -> (
···240242 try_keys keys
241243242244let resync_key ~id ~did ~code1 ~code2 db =
243243- match%lwt Util.Sqlite.use_pool db @@ Queries.get_security_key_by_id id did with
245245+ match%lwt
246246+ Util.Sqlite.use_pool db @@ Queries.get_security_key_by_id id did
247247+ with
244248 | None ->
245249 Lwt.return_error "Security key not found"
246250 | Some sk -> (
···263267 Util.Sqlite.use_pool db @@ Queries.get_security_keys_by_did ~did
264268265269let delete_key ~id ~did db =
266266- let%lwt () = Util.Sqlite.use_pool db @@ Queries.delete_security_key ~id ~did in
270270+ let%lwt () =
271271+ Util.Sqlite.use_pool db @@ Queries.delete_security_key ~id ~did
272272+ in
267273 Lwt.return_true
268274269275let has_security_keys ~did db =
+5-2
pegasus/lib/totp.ml
···106106 codes
107107108108 let regenerate ~did db =
109109- let%lwt () = Util.Sqlite.use_pool db @@ Queries.delete_backup_codes_by_did ~did in
109109+ let%lwt () =
110110+ Util.Sqlite.use_pool db @@ Queries.delete_backup_codes_by_did ~did
111111+ in
110112 let codes = generate_codes () in
111113 let%lwt () = store_codes ~did ~codes db in
112114 Lwt.return (List.map format_code codes)
···263265 if verify_code ~secret ~code then
264266 let now = Util.Time.now_ms () in
265267 let%lwt () =
266266- Util.Sqlite.use_pool db @@ Queries.verify_totp_secret ~did ~verified_at:now
268268+ Util.Sqlite.use_pool db
269269+ @@ Queries.verify_totp_secret ~did ~verified_at:now
267270 in
268271 Lwt.return_ok ()
269272 else Lwt.return_error "Invalid verification code"
+13-15
pegasus/lib/util/constants.ml
···11- let data_dir =
22- Core.Filename.to_absolute_exn Env.data_dir
33- ~relative_to:(Core_unix.getcwd ())
11+let data_dir =
22+ Core.Filename.to_absolute_exn Env.data_dir ~relative_to:(Core_unix.getcwd ())
4355- let pegasus_db_filepath = Filename.concat data_dir "pegasus.db"
44+let pegasus_db_filepath = Filename.concat data_dir "pegasus.db"
6577- let pegasus_db_location = "sqlite3://" ^ pegasus_db_filepath |> Uri.of_string
66+let pegasus_db_location = "sqlite3://" ^ pegasus_db_filepath |> Uri.of_string
8799- let user_db_filepath did =
1010- let dirname = Filename.concat data_dir "store" in
1111- let filename = Str.global_replace (Str.regexp ":") "_" did in
1212- Filename.concat dirname filename ^ ".db"
88+let user_db_filepath did =
99+ let dirname = Filename.concat data_dir "store" in
1010+ let filename = Str.global_replace (Str.regexp ":") "_" did in
1111+ Filename.concat dirname filename ^ ".db"
13121414- let user_db_location did =
1515- "sqlite3://" ^ user_db_filepath did |> Uri.of_string
1313+let user_db_location did = "sqlite3://" ^ user_db_filepath did |> Uri.of_string
16141717- let user_blobs_location did =
1818- did
1919- |> Str.global_replace (Str.regexp ":") "_"
2020- |> (Filename.concat data_dir "blobs" |> Filename.concat)
1515+let user_blobs_location did =
1616+ did
1717+ |> Str.global_replace (Str.regexp ":") "_"
1818+ |> (Filename.concat data_dir "blobs" |> Filename.concat)
+32-32
pegasus/lib/util/rapper_.ml
···11- module CID : Rapper.CUSTOM with type t = Cid.t = struct
22- type t = Cid.t
11+module CID : Rapper.CUSTOM with type t = Cid.t = struct
22+ type t = Cid.t
3344- let t =
55- let encode cid =
66- try Ok (Cid.to_string cid) with e -> Error (Printexc.to_string e)
77- in
88- Caqti_type.(custom ~encode ~decode:Cid.of_string string)
99- end
44+ let t =
55+ let encode cid =
66+ try Ok (Cid.to_string cid) with e -> Error (Printexc.to_string e)
77+ in
88+ Caqti_type.(custom ~encode ~decode:Cid.of_string string)
99+end
10101111- module Blob : Rapper.CUSTOM with type t = bytes = struct
1212- type t = bytes
1111+module Blob : Rapper.CUSTOM with type t = bytes = struct
1212+ type t = bytes
13131414- let t =
1515- let encode blob =
1616- try Ok (Bytes.to_string blob) with e -> Error (Printexc.to_string e)
1717- in
1818- let decode blob =
1919- try Ok (Bytes.of_string blob) with e -> Error (Printexc.to_string e)
2020- in
2121- Caqti_type.(custom ~encode ~decode string)
2222- end
1414+ let t =
1515+ let encode blob =
1616+ try Ok (Bytes.to_string blob) with e -> Error (Printexc.to_string e)
1717+ in
1818+ let decode blob =
1919+ try Ok (Bytes.of_string blob) with e -> Error (Printexc.to_string e)
2020+ in
2121+ Caqti_type.(custom ~encode ~decode string)
2222+end
23232424- module Json : Rapper.CUSTOM with type t = Yojson.Safe.t = struct
2525- type t = Yojson.Safe.t
2424+module Json : Rapper.CUSTOM with type t = Yojson.Safe.t = struct
2525+ type t = Yojson.Safe.t
26262727- let t =
2828- let encode json =
2929- try Ok (Yojson.Safe.to_string json ~std:true)
3030- with e -> Error (Printexc.to_string e)
3131- in
3232- let decode json =
3333- try Ok (Yojson.Safe.from_string json)
3434- with e -> Error (Printexc.to_string e)
3535- in
3636- Caqti_type.(custom ~encode ~decode string)
3737- end
2727+ let t =
2828+ let encode json =
2929+ try Ok (Yojson.Safe.to_string json ~std:true)
3030+ with e -> Error (Printexc.to_string e)
3131+ in
3232+ let decode json =
3333+ try Ok (Yojson.Safe.from_string json)
3434+ with e -> Error (Printexc.to_string e)
3535+ in
3636+ Caqti_type.(custom ~encode ~decode string)
3737+end
+39-43
pegasus/lib/util/syntax.ml
···11- let unwrap m =
22- match%lwt m with
33- | Ok x ->
44- Lwt.return x
55- | Error e ->
66- raise (Caqti_error.Exn e)
11+let unwrap m =
22+ match%lwt m with Ok x -> Lwt.return x | Error e -> raise (Caqti_error.Exn e)
7388- (* unwraps an Lwt result, raising an exception if there's an error *)
99- let ( let$! ) m f =
1010- match%lwt m with Ok x -> f x | Error e -> raise (Caqti_error.Exn e)
44+(* unwraps an Lwt result, raising an exception if there's an error *)
55+let ( let$! ) m f =
66+ match%lwt m with Ok x -> f x | Error e -> raise (Caqti_error.Exn e)
1171212- (* unwraps an Lwt result, raising an exception if there's an error *)
1313- let ( >$! ) m f =
1414- match%lwt m with
1515- | Ok x ->
1616- Lwt.return (f x)
1717- | Error e ->
1818- raise (Caqti_error.Exn e)
88+(* unwraps an Lwt result, raising an exception if there's an error *)
99+let ( >$! ) m f =
1010+ match%lwt m with
1111+ | Ok x ->
1212+ Lwt.return (f x)
1313+ | Error e ->
1414+ raise (Caqti_error.Exn e)
19152020- let at_uri_regexp =
2121- Re.Pcre.re
2222- {|^at:\/\/([a-zA-Z0-9._:%-]+)(?:\/([a-zA-Z0-9-.]+)(?:\/([a-zA-Z0-9._~:@!$&%')(*+,;=-]+))?)?(?:#(\/[a-zA-Z0-9._~:@!$&%')(*+,;=\-[\]\/\\]*))?$|}
2323- |> Re.compile
1616+let at_uri_regexp =
1717+ Re.Pcre.re
1818+ {|^at:\/\/([a-zA-Z0-9._:%-]+)(?:\/([a-zA-Z0-9-.]+)(?:\/([a-zA-Z0-9._~:@!$&%')(*+,;=-]+))?)?(?:#(\/[a-zA-Z0-9._~:@!$&%')(*+,;=\-[\]\/\\]*))?$|}
1919+ |> Re.compile
24202525- type at_uri =
2626- {repo: string; collection: string; rkey: string; fragment: string option}
2121+type at_uri =
2222+ {repo: string; collection: string; rkey: string; fragment: string option}
27232828- let parse_at_uri uri =
2929- match Re.exec_opt at_uri_regexp uri with
3030- | None ->
3131- None
3232- | Some m -> (
3333- try
3434- Some
3535- { repo= Re.Group.get m 1
3636- ; collection= Re.Group.get m 2
3737- ; rkey= Re.Group.get m 3
3838- ; fragment= Re.Group.get_opt m 4 }
3939- with _ -> None )
2424+let parse_at_uri uri =
2525+ match Re.exec_opt at_uri_regexp uri with
2626+ | None ->
2727+ None
2828+ | Some m -> (
2929+ try
3030+ Some
3131+ { repo= Re.Group.get m 1
3232+ ; collection= Re.Group.get m 2
3333+ ; rkey= Re.Group.get m 3
3434+ ; fragment= Re.Group.get_opt m 4 }
3535+ with _ -> None )
40364141- let make_at_uri ~repo ~collection ~rkey ~fragment =
4242- Printf.sprintf "at://%s/%s/%s%s" repo collection rkey
4343- (Option.value ~default:"" fragment)
3737+let make_at_uri ~repo ~collection ~rkey ~fragment =
3838+ Printf.sprintf "at://%s/%s/%s%s" repo collection rkey
3939+ (Option.value ~default:"" fragment)
44404545- let nsid_authority nsid =
4646- match String.rindex_opt nsid '.' with
4747- | None ->
4848- nsid
4949- | Some idx ->
5050- String.sub nsid 0 idx
4141+let nsid_authority nsid =
4242+ match String.rindex_opt nsid '.' with
4343+ | None ->
4444+ nsid
4545+ | Some idx ->
4646+ String.sub nsid 0 idx
+75-75
pegasus/lib/util/types.ml
···11- type string_or_null = string option
11+type string_or_null = string option
2233- let string_or_null_to_yojson = function Some s -> `String s | None -> `Null
33+let string_or_null_to_yojson = function Some s -> `String s | None -> `Null
4455- let string_or_null_of_yojson = function
66- | `String s ->
77- Ok (Some s)
88- | `Null ->
99- Ok None
1010- | _ ->
1111- Error "invalid field value"
55+let string_or_null_of_yojson = function
66+ | `String s ->
77+ Ok (Some s)
88+ | `Null ->
99+ Ok None
1010+ | _ ->
1111+ Error "invalid field value"
12121313- type string_or_strings = [`String of string | `Strings of string list]
1313+type string_or_strings = [`String of string | `Strings of string list]
14141515- let string_or_strings_to_yojson = function
1616- | `String c ->
1717- `String c
1818- | `Strings cs ->
1919- `List (List.map (fun c -> `String c) cs)
1515+let string_or_strings_to_yojson = function
1616+ | `String c ->
1717+ `String c
1818+ | `Strings cs ->
1919+ `List (List.map (fun c -> `String c) cs)
20202121- let string_or_strings_of_yojson = function
2222- | `String c ->
2323- Ok (`Strings [c])
2424- | `List cs ->
2525- Ok (`Strings (Yojson.Safe.Util.filter_string cs))
2626- | _ ->
2727- Error "invalid field value"
2121+let string_or_strings_of_yojson = function
2222+ | `String c ->
2323+ Ok (`Strings [c])
2424+ | `List cs ->
2525+ Ok (`Strings (Yojson.Safe.Util.filter_string cs))
2626+ | _ ->
2727+ Error "invalid field value"
28282929- type string_map = (string * string) list
2929+type string_map = (string * string) list
30303131- let string_map_to_yojson = function
3232- | [] ->
3333- `Assoc []
3434- | m ->
3535- `Assoc (List.map (fun (k, v) -> (k, `String v)) m)
3131+let string_map_to_yojson = function
3232+ | [] ->
3333+ `Assoc []
3434+ | m ->
3535+ `Assoc (List.map (fun (k, v) -> (k, `String v)) m)
36363737- let string_map_of_yojson = function
3838- | `Null ->
3939- Ok []
4040- | `Assoc m ->
4141- Ok
4242- (List.filter_map
4343- (fun (k, v) ->
4444- match (k, v) with _, `String s -> Some (k, s) | _, _ -> None )
4545- m )
4646- | _ ->
4747- Error "invalid field value"
3737+let string_map_of_yojson = function
3838+ | `Null ->
3939+ Ok []
4040+ | `Assoc m ->
4141+ Ok
4242+ (List.filter_map
4343+ (fun (k, v) ->
4444+ match (k, v) with _, `String s -> Some (k, s) | _, _ -> None )
4545+ m )
4646+ | _ ->
4747+ Error "invalid field value"
48484949- type string_or_string_map = [`String of string | `String_map of string_map]
4949+type string_or_string_map = [`String of string | `String_map of string_map]
50505151- let string_or_string_map_to_yojson = function
5252- | `String c ->
5353- `String c
5454- | `String_map m ->
5555- `Assoc (List.map (fun (k, v) -> (k, `String v)) m)
5151+let string_or_string_map_to_yojson = function
5252+ | `String c ->
5353+ `String c
5454+ | `String_map m ->
5555+ `Assoc (List.map (fun (k, v) -> (k, `String v)) m)
56565757- let string_or_string_map_of_yojson = function
5858- | `String c ->
5959- Ok (`String c)
6060- | `Assoc m ->
6161- string_map_of_yojson (`Assoc m) |> Result.map (fun m -> `String_map m)
6262- | _ ->
6363- Error "invalid field value"
5757+let string_or_string_map_of_yojson = function
5858+ | `String c ->
5959+ Ok (`String c)
6060+ | `Assoc m ->
6161+ string_map_of_yojson (`Assoc m) |> Result.map (fun m -> `String_map m)
6262+ | _ ->
6363+ Error "invalid field value"
64646565- type string_or_string_map_or_either_list =
6666- [ `String of string
6767- | `String_map of string_map
6868- | `List of string_or_string_map list ]
6565+type string_or_string_map_or_either_list =
6666+ [ `String of string
6767+ | `String_map of string_map
6868+ | `List of string_or_string_map list ]
69697070- let string_or_string_map_or_either_list_to_yojson = function
7171- | `String c ->
7272- `String c
7373- | `String_map m ->
7474- `Assoc (List.map (fun (k, v) -> (k, `String v)) m)
7575- | `List l ->
7676- `List (List.map string_or_string_map_to_yojson l)
7070+let string_or_string_map_or_either_list_to_yojson = function
7171+ | `String c ->
7272+ `String c
7373+ | `String_map m ->
7474+ `Assoc (List.map (fun (k, v) -> (k, `String v)) m)
7575+ | `List l ->
7676+ `List (List.map string_or_string_map_to_yojson l)
77777878- let string_or_string_map_or_either_list_of_yojson = function
7979- | `String c ->
8080- Ok (`String c)
8181- | `Assoc m ->
8282- string_map_of_yojson (`Assoc m) |> Result.map (fun m -> `String_map m)
8383- | `List l ->
8484- Ok
8585- (`List
8686- ( List.map string_or_string_map_of_yojson l
8787- |> List.filter_map (function Ok x -> Some x | Error _ -> None) ) )
8888- | _ ->
8989- Error "invalid field value"
7878+let string_or_string_map_or_either_list_of_yojson = function
7979+ | `String c ->
8080+ Ok (`String c)
8181+ | `Assoc m ->
8282+ string_map_of_yojson (`Assoc m) |> Result.map (fun m -> `String_map m)
8383+ | `List l ->
8484+ Ok
8585+ (`List
8686+ ( List.map string_or_string_map_of_yojson l
8787+ |> List.filter_map (function Ok x -> Some x | Error _ -> None) ) )
8888+ | _ ->
8989+ Error "invalid field value"
-7
pegasus/lib/util/util.ml
···11module Constants = Constants
22-32module Syntax = Syntax
44-53module Rapper = Rapper_
66-74module Types = Types
88-95module Sqlite = Sqlite_
1010-116module Time = Time
1212-137module Http = Http_
1414-158module Html = Html
1691710(* returns all blob refs in a record *)