objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

new ocamlformat version

futurGH f498dc1c b7ea924f

+293 -297
+1 -1
.ocamlformat
··· 1 1 profile = ocamlformat 2 - version = 0.27.0 2 + version = 0.28.1
+2 -2
ipld/lib/dag_cbor.ml
··· 197 197 write_type_and_argument t 5 (Int64.of_int len) ; 198 198 ordered_map_keys m 199 199 |> List.iter (fun k -> 200 - write_string t k ; 201 - write_value t (String_map.find k m) ) 200 + write_string t k ; 201 + write_value t (String_map.find k m) ) 202 202 | `Link cid -> 203 203 write_cid t cid 204 204
+4 -4
ipld/test/test_dag_cbor.ml
··· 3 3 let rec stringify_map m = 4 4 String_map.bindings m 5 5 |> List.map (fun (k, v) -> 6 - Format.sprintf "\"%s\": %s" k (stringify_ipld_value v) ) 6 + Format.sprintf "\"%s\": %s" k (stringify_ipld_value v) ) 7 7 |> String.concat ", " |> Format.sprintf "{%s}" 8 8 9 9 and stringify_ipld_value (value : Dag_cbor.value) = ··· 109 109 Hashtbl.add cases (to_base_16 (Dag_cbor.encode `Null)) (Bytes.of_string "f6") ; 110 110 cases 111 111 |> Hashtbl.iter (fun key value -> 112 - Alcotest.(check bytes) 113 - ("encoded bytes for " ^ key) 114 - value (Bytes.of_string key) ) 112 + Alcotest.(check bytes) 113 + ("encoded bytes for " ^ key) 114 + value (Bytes.of_string key) ) 115 115 116 116 let test_round_trip () = 117 117 let test_cid =
+34 -33
mist/lib/mst.ml
··· 239 239 | None, [] -> 240 240 Lwt.return 0 241 241 | Some left, [] -> ( 242 - match%lwt retrieve_node_raw t left with 243 - | Some node -> 244 - let%lwt height = get_node_height t node in 245 - Lwt.return (height + 1) 246 - | None -> 247 - failwith ("couldn't find node " ^ Cid.to_string left) ) 242 + match%lwt retrieve_node_raw t left with 243 + | Some node -> 244 + let%lwt height = get_node_height t node in 245 + Lwt.return (height + 1) 246 + | None -> 247 + failwith ("couldn't find node " ^ Cid.to_string left) ) 248 248 | _, leaf :: _ -> ( 249 249 match leaf.p with 250 250 | 0 -> ··· 497 497 let%lwt blocks = 498 498 match Util.at_index index seq with 499 499 | Some (Leaf (k, v, _)) when k = key -> ( 500 - (* include the found leaf block to prove existence *) 501 - match%lwt Store.get_bytes t.blockstore v with 502 - | Some leaf_bytes -> 503 - Lwt.return (Block_map.set v leaf_bytes Block_map.empty) 504 - | None -> 505 - Lwt.return Block_map.empty ) 500 + (* include the found leaf block to prove existence *) 501 + match%lwt 502 + Store.get_bytes t.blockstore v 503 + with 504 + | Some leaf_bytes -> 505 + Lwt.return (Block_map.set v leaf_bytes Block_map.empty) 506 + | None -> 507 + Lwt.return Block_map.empty ) 506 508 | _ -> ( 507 509 let prev = 508 510 if index - 1 >= 0 then Util.at_index (index - 1) seq else None ··· 529 531 let%lwt bm = 530 532 match left_leaf with 531 533 | Some cid_left -> ( 532 - match%lwt Store.get_bytes t.blockstore cid_left with 533 - | Some b -> 534 - Lwt.return 535 - (Block_map.set cid_left b Block_map.empty) 536 - | None -> 537 - Lwt.return Block_map.empty ) 534 + match%lwt Store.get_bytes t.blockstore cid_left with 535 + | Some b -> 536 + Lwt.return (Block_map.set cid_left b Block_map.empty) 537 + | None -> 538 + Lwt.return Block_map.empty ) 538 539 | None -> 539 540 Lwt.return Block_map.empty 540 541 in 541 542 let%lwt bm = 542 543 match right_leaf with 543 544 | Some cid_right -> ( 544 - match%lwt Store.get_bytes t.blockstore cid_right with 545 - | Some b -> 546 - Lwt.return (Block_map.set cid_right b bm) 547 - | None -> 548 - Lwt.return bm ) 545 + match%lwt Store.get_bytes t.blockstore cid_right with 546 + | Some b -> 547 + Lwt.return (Block_map.set cid_right b bm) 548 + | None -> 549 + Lwt.return bm ) 549 550 | None -> 550 551 Lwt.return bm 551 552 in ··· 571 572 | Some (Tree c) -> 572 573 proof_for_left_sibling t c key 573 574 | Some (Leaf (_, v_left, _)) -> ( 574 - match%lwt Store.get_bytes t.blockstore v_left with 575 - | Some b -> 576 - Lwt.return (Block_map.set v_left b Block_map.empty) 577 - | None -> 578 - Lwt.return Block_map.empty ) 575 + match%lwt Store.get_bytes t.blockstore v_left with 576 + | Some b -> 577 + Lwt.return (Block_map.set v_left b Block_map.empty) 578 + | None -> 579 + Lwt.return Block_map.empty ) 579 580 | _ -> 580 581 Lwt.return Block_map.empty 581 582 in ··· 612 613 | Some (Tree c) -> 613 614 proof_for_right_sibling t c key 614 615 | Some (Leaf (_, v_right, _)) -> ( 615 - match%lwt Store.get_bytes t.blockstore v_right with 616 - | Some b -> 617 - Lwt.return (Block_map.set v_right b Block_map.empty) 618 - | None -> 619 - Lwt.return Block_map.empty ) 616 + match%lwt Store.get_bytes t.blockstore v_right with 617 + | Some b -> 618 + Lwt.return (Block_map.set v_right b Block_map.empty) 619 + | None -> 620 + Lwt.return Block_map.empty ) 620 621 | _ -> 621 622 Lwt.return Block_map.empty ) 622 623 | None ->
+7 -7
mist/test/test_util.ml
··· 8 8 Hashtbl.add cases "app.bsky.feed.post/9adeb165882c" 8 ; 9 9 cases 10 10 |> Hashtbl.iter (fun key value -> 11 - Alcotest.(check int) 12 - ("leading zeros on hash " ^ key) 13 - value 14 - (leading_zeros_on_hash key) ) 11 + Alcotest.(check int) 12 + ("leading zeros on hash " ^ key) 13 + value 14 + (leading_zeros_on_hash key) ) 15 15 16 16 let test_shared_prefix_length () = 17 17 let cases = Hashtbl.create 5 in ··· 22 22 Hashtbl.add cases ("2653ae71", "0653ae71") 0 ; 23 23 cases 24 24 |> Hashtbl.iter (fun (a, b) value -> 25 - Alcotest.(check int) 26 - ("prefix length between " ^ a ^ " and " ^ b) 27 - value (shared_prefix_length a b) ) 25 + Alcotest.(check int) 26 + ("prefix length between " ^ a ^ " and " ^ b) 27 + value (shared_prefix_length a b) ) 28 28 29 29 let () = 30 30 Alcotest.run "util"
+6 -6
pegasus/lib/api/identity/resolveHandle.ml
··· 14 14 Dream.json @@ Yojson.Safe.to_string 15 15 @@ response_to_yojson {did= actor.did} 16 16 | None -> ( 17 - match%lwt Id_resolver.Handle.resolve handle with 18 - | Ok did -> 19 - Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson {did} 20 - | Error e -> 21 - Errors.log_exn (Failure e) ; 22 - Errors.internal_error ~msg:"could not resolve handle" () ) ) 17 + match%lwt Id_resolver.Handle.resolve handle with 18 + | Ok did -> 19 + Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson {did} 20 + | Error e -> 21 + Errors.log_exn (Failure e) ; 22 + Errors.internal_error ~msg:"could not resolve handle" () ) )
+54 -57
pegasus/lib/api/identity/updateHandle.ml
··· 15 15 | Error e -> 16 16 raise e 17 17 | Ok () -> ( 18 - match%lwt Data_store.get_actor_by_identifier handle db with 19 - | Some _ -> 20 - Errors.invalid_request ~name:"InvalidHandle" 21 - "handle already in use" 22 - | None -> 23 - let%lwt () = Data_store.update_actor_handle ~did ~handle db in 24 - let%lwt _ = 25 - if String.starts_with ~prefix:"did:plc:" did then 26 - match%lwt Plc.get_audit_log did with 27 - | Error e -> 28 - Dream.error (fun log -> log ~request:req "%s" e) ; 29 - Errors.internal_error ~msg:"failed to fetch did doc" () 30 - | Ok log -> ( 31 - let latest = List.rev log |> List.hd in 32 - let aka = 33 - match 34 - List.mem ("at://" ^ handle) 35 - latest.operation.also_known_as 36 - with 37 - | true -> 38 - latest.operation.also_known_as 39 - | false -> 40 - ("at://" ^ handle) :: latest.operation.also_known_as 41 - in 42 - let%lwt signing_key = 43 - match%lwt Data_store.get_actor_by_identifier did db with 44 - | Some {signing_key; _} -> 45 - Lwt.return @@ Kleidos.parse_multikey_str signing_key 46 - | _ -> 47 - Errors.internal_error () 48 - in 49 - let signed = 50 - Plc.sign_operation signing_key 51 - (Operation 52 - { type'= "plc_operation" 53 - ; prev= Some latest.cid 54 - ; also_known_as= aka 55 - ; rotation_keys= latest.operation.rotation_keys 56 - ; verification_methods= 57 - latest.operation.verification_methods 58 - ; services= latest.operation.services } ) 59 - in 60 - match%lwt Plc.submit_operation did signed with 61 - | Ok _ -> 62 - Lwt.return_unit 63 - | Error (status, msg) -> 64 - Dream.error (fun log -> 65 - log ~request:req "%d %s" status msg ) ; 66 - Errors.internal_error 67 - ~msg:"failed to submit plc operation" () ) 68 - else Lwt.return_unit 69 - in 70 - let () = 71 - Ttl_cache.String_cache.remove Id_resolver.Did.cache did 72 - in 73 - let%lwt _ = Sequencer.sequence_identity db ~did ~handle () in 74 - Dream.empty `OK ) ) 18 + match%lwt Data_store.get_actor_by_identifier handle db with 19 + | Some _ -> 20 + Errors.invalid_request ~name:"InvalidHandle" "handle already in use" 21 + | None -> 22 + let%lwt () = Data_store.update_actor_handle ~did ~handle db in 23 + let%lwt _ = 24 + if String.starts_with ~prefix:"did:plc:" did then 25 + match%lwt Plc.get_audit_log did with 26 + | Error e -> 27 + Dream.error (fun log -> log ~request:req "%s" e) ; 28 + Errors.internal_error ~msg:"failed to fetch did doc" () 29 + | Ok log -> ( 30 + let latest = List.rev log |> List.hd in 31 + let aka = 32 + match 33 + List.mem ("at://" ^ handle) 34 + latest.operation.also_known_as 35 + with 36 + | true -> 37 + latest.operation.also_known_as 38 + | false -> 39 + ("at://" ^ handle) :: latest.operation.also_known_as 40 + in 41 + let%lwt signing_key = 42 + match%lwt Data_store.get_actor_by_identifier did db with 43 + | Some {signing_key; _} -> 44 + Lwt.return @@ Kleidos.parse_multikey_str signing_key 45 + | _ -> 46 + Errors.internal_error () 47 + in 48 + let signed = 49 + Plc.sign_operation signing_key 50 + (Operation 51 + { type'= "plc_operation" 52 + ; prev= Some latest.cid 53 + ; also_known_as= aka 54 + ; rotation_keys= latest.operation.rotation_keys 55 + ; verification_methods= 56 + latest.operation.verification_methods 57 + ; services= latest.operation.services } ) 58 + in 59 + match%lwt Plc.submit_operation did signed with 60 + | Ok _ -> 61 + Lwt.return_unit 62 + | Error (status, msg) -> 63 + Dream.error (fun log -> 64 + log ~request:req "%d %s" status msg ) ; 65 + Errors.internal_error 66 + ~msg:"failed to submit plc operation" () ) 67 + else Lwt.return_unit 68 + in 69 + let () = Ttl_cache.String_cache.remove Id_resolver.Did.cache did in 70 + let%lwt _ = Sequencer.sequence_identity db ~did ~handle () in 71 + Dream.empty `OK ) )
+87 -87
pegasus/lib/api/oauth_/authorize.ml
··· 37 37 Yojson.Safe.from_string req_record.request_data 38 38 |> par_request_of_yojson 39 39 |> Result.map_error (fun _ -> 40 - Errors.internal_error 41 - ~msg:"failed to parse par request" () ) 40 + Errors.internal_error ~msg:"failed to parse par request" 41 + () ) 42 42 |> Result.get_ok 43 43 in 44 44 let%lwt _client = ··· 103 103 | None -> 104 104 Errors.auth_required "missing authentication" 105 105 | Some user_did -> ( 106 - match%lwt Dream.form ctx.req with 107 - | `Ok fields -> ( 108 - let action = List.assoc_opt "action" fields in 109 - let code = List.assoc_opt "code" fields in 110 - let request_uri = List.assoc_opt "request_uri" fields in 111 - match (action, code, request_uri) with 112 - | Some "deny", _, Some request_uri -> ( 113 - let prefix = Constants.request_uri_prefix in 114 - let request_id = 115 - String.sub request_uri (String.length prefix) 116 - (String.length request_uri - String.length prefix) 117 - in 118 - let%lwt req_record = 119 - Queries.get_par_request ctx.db request_id 120 - in 121 - match req_record with 122 - | Some rec_ -> 123 - let req = 124 - Yojson.Safe.from_string rec_.request_data 125 - |> par_request_of_yojson |> Result.get_ok 106 + match%lwt Dream.form ctx.req with 107 + | `Ok fields -> ( 108 + let action = List.assoc_opt "action" fields in 109 + let code = List.assoc_opt "code" fields in 110 + let request_uri = List.assoc_opt "request_uri" fields in 111 + match (action, code, request_uri) with 112 + | Some "deny", _, Some request_uri -> ( 113 + let prefix = Constants.request_uri_prefix in 114 + let request_id = 115 + String.sub request_uri (String.length prefix) 116 + (String.length request_uri - String.length prefix) 117 + in 118 + let%lwt req_record = 119 + Queries.get_par_request ctx.db request_id 120 + in 121 + match req_record with 122 + | Some rec_ -> 123 + let req = 124 + Yojson.Safe.from_string rec_.request_data 125 + |> par_request_of_yojson |> Result.get_ok 126 + in 127 + let params = 128 + [ ("error", "access_denied") 129 + ; ("error_description", "Unable to authorize user.") 130 + ; ("state", req.state) 131 + ; ("iss", "https://" ^ Env.hostname) ] 132 + in 133 + let query = 134 + String.concat "&" 135 + (List.map 136 + (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v) 137 + params ) 138 + in 139 + Dream.redirect ctx.req (req.redirect_uri ^ "?" ^ query) 140 + | None -> 141 + Errors.invalid_request "request expired" ) 142 + | Some "allow", Some code, Some _request_uri -> ( 143 + let%lwt code_record = Queries.get_auth_code ctx.db code in 144 + match code_record with 145 + | None -> 146 + Errors.invalid_request "invalid code" 147 + | Some code_rec -> ( 148 + if code_rec.authorized_by <> None then 149 + Errors.invalid_request "code already authorized" 150 + else if code_rec.used then 151 + Errors.invalid_request "code already used" 152 + else if Util.now_ms () > code_rec.expires_at then 153 + Errors.invalid_request "code expired" 154 + else 155 + let%lwt () = 156 + Queries.activate_auth_code ctx.db code user_did 126 157 in 127 - let params = 128 - [ ("error", "access_denied") 129 - ; ("error_description", "Unable to authorize user.") 130 - ; ("state", req.state) 131 - ; ("iss", "https://" ^ Env.hostname) ] 132 - in 133 - let query = 134 - String.concat "&" 135 - (List.map 136 - (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v) 137 - params ) 158 + let%lwt req_record = 159 + Queries.get_par_request ctx.db code_rec.request_id 138 160 in 139 - Dream.redirect ctx.req (req.redirect_uri ^ "?" ^ query) 140 - | None -> 141 - Errors.invalid_request "request expired" ) 142 - | Some "allow", Some code, Some _request_uri -> ( 143 - let%lwt code_record = Queries.get_auth_code ctx.db code in 144 - match code_record with 145 - | None -> 146 - Errors.invalid_request "invalid code" 147 - | Some code_rec -> ( 148 - if code_rec.authorized_by <> None then 149 - Errors.invalid_request "code already authorized" 150 - else if code_rec.used then 151 - Errors.invalid_request "code already used" 152 - else if Util.now_ms () > code_rec.expires_at then 153 - Errors.invalid_request "code expired" 154 - else 155 - let%lwt () = 156 - Queries.activate_auth_code ctx.db code user_did 157 - in 158 - let%lwt req_record = 159 - Queries.get_par_request ctx.db code_rec.request_id 160 - in 161 - match req_record with 162 - | None -> 163 - Errors.internal_error ~msg:"request not found" () 164 - | Some rec_ -> 165 - let req = 166 - Yojson.Safe.from_string rec_.request_data 167 - |> par_request_of_yojson |> Result.get_ok 168 - in 169 - let params = 170 - [ ("code", code) 171 - ; ("state", req.state) 172 - ; ("iss", "https://" ^ Env.hostname) ] 173 - in 174 - let query = 175 - String.concat "&" 176 - (List.map 177 - (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v) 178 - params ) 179 - in 180 - let separator = 181 - match req.response_mode with 182 - | Some "fragment" -> 183 - "#" 184 - | _ -> 185 - "?" 186 - in 187 - Dream.redirect ctx.req 188 - (req.redirect_uri ^ separator ^ query) ) ) 189 - | _ -> 190 - Errors.invalid_request "invalid request" ) 191 - | _ -> 192 - Errors.invalid_request "invalid request" ) ) 161 + match req_record with 162 + | None -> 163 + Errors.internal_error ~msg:"request not found" () 164 + | Some rec_ -> 165 + let req = 166 + Yojson.Safe.from_string rec_.request_data 167 + |> par_request_of_yojson |> Result.get_ok 168 + in 169 + let params = 170 + [ ("code", code) 171 + ; ("state", req.state) 172 + ; ("iss", "https://" ^ Env.hostname) ] 173 + in 174 + let query = 175 + String.concat "&" 176 + (List.map 177 + (fun (k, v) -> k ^ "=" ^ Uri.pct_encode v) 178 + params ) 179 + in 180 + let separator = 181 + match req.response_mode with 182 + | Some "fragment" -> 183 + "#" 184 + | _ -> 185 + "?" 186 + in 187 + Dream.redirect ctx.req 188 + (req.redirect_uri ^ separator ^ query) ) ) 189 + | _ -> 190 + Errors.invalid_request "invalid request" ) 191 + | _ -> 192 + Errors.invalid_request "invalid request" ) )
+10 -10
pegasus/lib/api/repo/createAccount.ml
··· 57 57 let%lwt did = 58 58 match input.did with 59 59 | Some did -> ( 60 - match%lwt Data_store.get_actor_by_identifier did ctx.db with 61 - | Some _ -> 62 - Errors.invalid_request "an account with that did already exists" 63 - | None -> 64 - Lwt.return did ) 60 + match%lwt Data_store.get_actor_by_identifier did ctx.db with 61 + | Some _ -> 62 + Errors.invalid_request "an account with that did already exists" 63 + | None -> 64 + Lwt.return did ) 65 65 | None -> ( 66 66 let sk_did = Kleidos.K256.pubkey_to_did_key signing_pubkey in 67 67 let rotation_did_keys = ··· 79 79 let%lwt _ = 80 80 match input.invite_code with 81 81 | Some code -> ( 82 - match%lwt Data_store.use_invite ~code ctx.db with 83 - | Some _ -> 84 - Lwt.return () 85 - | None -> 86 - failwith "failed to use invite code" ) 82 + match%lwt Data_store.use_invite ~code ctx.db with 83 + | Some _ -> 84 + Lwt.return () 85 + | None -> 86 + failwith "failed to use invite code" ) 87 87 | None -> 88 88 Lwt.return () 89 89 in
+24 -24
pegasus/lib/auth.ml
··· 151 151 fun {req; db} -> 152 152 match parse_bearer req with 153 153 | Ok jwt -> ( 154 - match%lwt verify_bearer_jwt db jwt "com.atproto.access" with 155 - | Ok {sub= did; _} -> ( 156 - match%lwt Data_store.get_actor_by_identifier did db with 157 - | Some {deactivated_at= None; _} -> 158 - Lwt.return_ok (Access {did}) 159 - | Some {deactivated_at= Some _; _} -> 160 - Lwt.return_error 161 - @@ Errors.auth_required ~name:"AccountDeactivated" 162 - "account is deactivated" 163 - | None -> 164 - Lwt.return_error @@ Errors.auth_required "invalid credentials" ) 165 - | Error _ -> 154 + match%lwt verify_bearer_jwt db jwt "com.atproto.access" with 155 + | Ok {sub= did; _} -> ( 156 + match%lwt Data_store.get_actor_by_identifier did db with 157 + | Some {deactivated_at= None; _} -> 158 + Lwt.return_ok (Access {did}) 159 + | Some {deactivated_at= Some _; _} -> 160 + Lwt.return_error 161 + @@ Errors.auth_required ~name:"AccountDeactivated" 162 + "account is deactivated" 163 + | None -> 166 164 Lwt.return_error @@ Errors.auth_required "invalid credentials" ) 165 + | Error _ -> 166 + Lwt.return_error @@ Errors.auth_required "invalid credentials" ) 167 167 | Error _ -> 168 168 Lwt.return_error @@ Errors.auth_required "invalid authorization header" 169 169 ··· 220 220 fun {req; db} -> 221 221 match parse_bearer req with 222 222 | Ok jwt -> ( 223 - match%lwt verify_bearer_jwt db jwt "com.atproto.refresh" with 224 - | Ok {sub= did; jti; _} -> ( 225 - match%lwt Data_store.get_actor_by_identifier did db with 226 - | Some {deactivated_at= None; _} -> 227 - Lwt.return_ok (Refresh {did; jti}) 228 - | Some {deactivated_at= Some _; _} -> 229 - Lwt.return_error 230 - @@ Errors.auth_required ~name:"AccountDeactivated" 231 - "account is deactivated" 232 - | None -> 233 - Lwt.return_error @@ Errors.auth_required "invalid credentials" ) 234 - | Error "" | Error _ -> 223 + match%lwt verify_bearer_jwt db jwt "com.atproto.refresh" with 224 + | Ok {sub= did; jti; _} -> ( 225 + match%lwt Data_store.get_actor_by_identifier did db with 226 + | Some {deactivated_at= None; _} -> 227 + Lwt.return_ok (Refresh {did; jti}) 228 + | Some {deactivated_at= Some _; _} -> 229 + Lwt.return_error 230 + @@ Errors.auth_required ~name:"AccountDeactivated" 231 + "account is deactivated" 232 + | None -> 235 233 Lwt.return_error @@ Errors.auth_required "invalid credentials" ) 234 + | Error "" | Error _ -> 235 + Lwt.return_error @@ Errors.auth_required "invalid credentials" ) 236 236 | Error _ -> 237 237 Lwt.return_error @@ Errors.auth_required "invalid authorization header" 238 238
+11 -11
pegasus/lib/repository.ml
··· 180 180 let%lwt map = get_map t in 181 181 String_map.bindings map 182 182 |> List.filter (fun (path, _) -> 183 - String.starts_with ~prefix:(path ^ "/") collection ) 183 + String.starts_with ~prefix:(path ^ "/") collection ) 184 184 |> Lwt_list.fold_left_s 185 185 (fun acc (path, cid) -> 186 186 match%lwt User_store.get_record t.db path with ··· 320 320 let%lwt () = 321 321 match old_cid with 322 322 | Some _ -> ( 323 - match%lwt User_store.get_record t.db path with 324 - | Some record -> 325 - let refs = 326 - Util.find_blob_refs record.value 327 - |> List.map (fun (r : Mist.Blob_ref.t) -> r.ref) 328 - in 329 - let%lwt () = User_store.clear_blob_refs t.db path refs in 330 - Lwt.return_unit 331 - | None -> 332 - Lwt.return_unit ) 323 + match%lwt User_store.get_record t.db path with 324 + | Some record -> 325 + let refs = 326 + Util.find_blob_refs record.value 327 + |> List.map (fun (r : Mist.Blob_ref.t) -> r.ref) 328 + in 329 + let%lwt () = User_store.clear_blob_refs t.db path refs in 330 + Lwt.return_unit 331 + | None -> 332 + Lwt.return_unit ) 333 333 | None -> 334 334 Lwt.return_unit 335 335 in
+28 -28
pegasus/lib/sequencer.ml
··· 330 330 let blobs = 331 331 j |> member "blobs" |> to_list 332 332 |> List.filter_map (fun x -> 333 - match Cid.of_yojson x with Ok c -> Some c | _ -> None ) 333 + match Cid.of_yojson x with Ok c -> Some c | _ -> None ) 334 334 in 335 335 let prev_data = 336 336 match j |> member "prevData" with ··· 342 342 let ops = 343 343 j |> member "ops" |> to_list 344 344 |> List.map (fun opj -> 345 - let action = 346 - match opj |> member "action" |> to_string with 347 - | "create" -> 348 - `Create 349 - | "update" -> 350 - `Update 351 - | "delete" -> 352 - `Delete 353 - | _ -> 354 - `Create 355 - in 356 - let path = opj |> member "path" |> to_string in 357 - let cid = 358 - match opj |> member "cid" with 359 - | `Null -> 360 - None 361 - | v -> ( 362 - match Cid.of_yojson v with Ok c -> Some c | _ -> None ) 363 - in 364 - let prev = 365 - match opj |> member "prev" with 366 - | `Null -> 367 - None 368 - | v -> ( 369 - match Cid.of_yojson v with Ok c -> Some c | _ -> None ) 370 - in 371 - {action; path; cid; prev} ) 345 + let action = 346 + match opj |> member "action" |> to_string with 347 + | "create" -> 348 + `Create 349 + | "update" -> 350 + `Update 351 + | "delete" -> 352 + `Delete 353 + | _ -> 354 + `Create 355 + in 356 + let path = opj |> member "path" |> to_string in 357 + let cid = 358 + match opj |> member "cid" with 359 + | `Null -> 360 + None 361 + | v -> ( 362 + match Cid.of_yojson v with Ok c -> Some c | _ -> None ) 363 + in 364 + let prev = 365 + match opj |> member "prev" with 366 + | `Null -> 367 + None 368 + | v -> ( 369 + match Cid.of_yojson v with Ok c -> Some c | _ -> None ) 370 + in 371 + {action; path; cid; prev} ) 372 372 in 373 373 Ok 374 374 { rebase
+2 -2
pegasus/lib/user_store.ml
··· 386 386 let get_record t path : record option Lwt.t = 387 387 Util.use_pool t.db @@ Queries.get_record ~path 388 388 >|= Option.map (fun (cid, data, since) -> 389 - {path; cid; value= Lex.of_cbor data; since} ) 389 + {path; cid; value= Lex.of_cbor data; since} ) 390 390 391 391 let list_records t ?(limit = 100) ?(cursor = "") ?(reverse = false) collection : 392 392 record list Lwt.t = ··· 395 395 in 396 396 Util.use_pool t.db @@ fn ~collection ~limit ~cursor 397 397 >|= List.map (fun (path, cid, data, since) -> 398 - {path; cid; value= Lex.of_cbor data; since} ) 398 + {path; cid; value= Lex.of_cbor data; since} ) 399 399 400 400 let put_record t record path : (Cid.t * bytes) Lwt.t = 401 401 let cid, data = Lex.to_cbor_block record in
+15 -17
pegasus/lib/util.ml
··· 287 287 let is_none = function None -> true | _ -> false 288 288 289 289 let validate_handle handle = 290 - let front = 291 - String.sub handle 0 292 - (String.length handle - (String.length Env.hostname + 1)) 293 - in 294 - if String.contains front '.' then 295 - Error 296 - (Errors.InvalidRequestError 297 - ("InvalidHandle", "invalid characters in handle") ) 298 - else 299 - match String.length front with 300 - | l when l < 3 -> 301 - Error 302 - (Errors.InvalidRequestError ("InvalidHandle", "handle too short")) 303 - | l when l > 18 -> 304 - Error (Errors.InvalidRequestError ("InvalidHandle", "handle too long")) 305 - | _ -> 306 - Ok () 290 + let front = 291 + String.sub handle 0 (String.length handle - (String.length Env.hostname + 1)) 292 + in 293 + if String.contains front '.' then 294 + Error 295 + (Errors.InvalidRequestError 296 + ("InvalidHandle", "invalid characters in handle") ) 297 + else 298 + match String.length front with 299 + | l when l < 3 -> 300 + Error (Errors.InvalidRequestError ("InvalidHandle", "handle too short")) 301 + | l when l > 18 -> 302 + Error (Errors.InvalidRequestError ("InvalidHandle", "handle too long")) 303 + | _ -> 304 + Ok () 307 305 308 306 let mkfile_p path ~perm = 309 307 Core_unix.mkdir_p (Filename.dirname path) ~perm:0o755 ;
+8 -8
pegasus/lib/xrpc.ml
··· 12 12 let auth = Auth.Verifiers.of_t auth in 13 13 match%lwt auth init with 14 14 | Ok creds -> ( 15 - try%lwt hdlr {req= init.req; db= init.db; auth= creds} 16 - with e -> 17 - ( match is_xrpc_error e with 18 - | true -> 19 - () 20 - | false -> 21 - log_exn ~req:init.req e ) ; 22 - exn_to_response e ) 15 + try%lwt hdlr {req= init.req; db= init.db; auth= creds} 16 + with e -> 17 + ( match is_xrpc_error e with 18 + | true -> 19 + () 20 + | false -> 21 + log_exn ~req:init.req e ) ; 22 + exn_to_response e ) 23 23 | Error e -> 24 24 exn_to_response e 25 25