objective categorical abstract machine language personal data server
67
fork

Configure Feed

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

Make Cid.to_string only return string or fail

futur.blue a36a66d5 5daed9f5

verified
+57 -67
+7 -15
ipld/lib/cid.ml
··· 107 107 let to_string cid = 108 108 match Multibase.encode `Base32 (Bytes.to_string cid.bytes) with 109 109 | Ok str -> 110 - Ok str 110 + str 111 111 | Error (`Msg msg) -> 112 - Error msg 112 + failwith msg 113 113 | Error (`Unsupported t) -> 114 - Error 114 + failwith 115 115 (Printf.sprintf "Unsupported multibase %s" 116 116 (Multibase.Encoding.to_string t) ) 117 117 ··· 130 130 Buffer.add_bytes buf cid.bytes ; 131 131 Buffer.to_bytes buf 132 132 133 - let compare a b = 134 - match [to_string a; to_string b] with 135 - | [Ok a; Ok b] -> 136 - String.compare a b 137 - | _ -> 138 - failwith "CID comparison failed" 133 + let as_cid str = Result.get_ok @@ of_string str 139 134 140 - let equal a b = 141 - match [to_string a; to_string b] with 142 - | [Ok a; Ok b] -> 143 - String.equal a b 144 - | _ -> 145 - failwith "CID comparison failed" 135 + let compare a b = String.compare (to_string a) (to_string b) 136 + 137 + let equal a b = String.equal (to_string a) (to_string b) 146 138 147 139 let hash = Hashtbl.hash
+2 -3
ipld/test/test_cid.ml
··· 235 235 Alcotest.(check bytes) "bytes" (bytes_from_list [1; 113; 18; 0]) cid.bytes 236 236 237 237 let test_create () = 238 - let cid = Cid.(create Dcbor (Bytes.of_string "abc")) in 239 - let str = Result.get_ok (Cid.to_string cid) in 238 + let cid = Cid.(create Dcbor (Bytes.of_string "abc") |> to_string) in 240 239 Alcotest.(check string) 241 - "digest" "bafyreif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu" str 240 + "digest" "bafyreif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu" cid 242 241 243 242 let test_create_empty_string () = 244 243 let cid = Cid.(create_empty Dcbor) in
+48 -49
ipld/test/test_dag_cbor.ml
··· 28 28 | `Link cid -> 29 29 Format.sprintf "%s" 30 30 (stringify_map 31 - (StringMap.singleton "$link" 32 - (`String (Result.get_ok (Cid.to_string cid))) ) ) 31 + (StringMap.singleton "$link" (`String (Cid.to_string cid))) ) 33 32 | `Null -> 34 33 Format.sprintf "null" 35 34 ··· 52 51 | `Array a, `Array b -> 53 52 Array.for_all2 ipld_value_eq a b 54 53 | `Link a, `Link b -> 55 - Result.get_ok @@ Cid.to_string a = Result.get_ok @@ Cid.to_string b 54 + Cid.to_string a = Cid.to_string b 56 55 | `Null, `Null -> 57 56 true 58 57 | _ -> ··· 200 199 |> add "$type" (`String "blob") 201 200 |> add "ref" 202 201 (`Link 203 - (Result.get_ok 204 - (Cid.of_string 205 - "bafkreic6hvmy3ymbo25wxsvylu77r57uwhtnviu7vmhfsns3ab4xfal5ou" ) ) 206 - ) 202 + (Result.get_ok 203 + (Cid.of_string 204 + "bafkreic6hvmy3ymbo25wxsvylu77r57uwhtnviu7vmhfsns3ab4xfal5ou" ) ) 205 + ) 207 206 |> add "mimeType" (`String "image/jpeg") 208 207 |> add "size" (`Integer 645553L) ) 209 208 in ··· 212 211 empty 213 212 |> add "alt" 214 213 (`String 215 - "a photoshopped picture of kit with a microphone. kit is saying \ 216 - \"meow\"" ) 214 + "a photoshopped picture of kit with a microphone. kit is saying \ 215 + \"meow\"" ) 217 216 |> add "aspectRatio" (`Map record1_embed_images_0_aspect_ratio) 218 217 |> add "image" (`Map record1_embed_images_0_image) ) 219 218 in ··· 237 236 Alcotest.(check string) 238 237 "atproto record 1 encodes correctly" 239 238 "bafyreicbb3p4hmtm7iw3k7kiydzqp7qhufq3jdc5sbc4gxa4mxqd6bywba" 240 - Cid.(create Dcbor encoded1 |> to_string |> Result.get_ok) ; 239 + Cid.(create Dcbor encoded1 |> to_string) ; 241 240 let record2_embed_images_0_aspect_ratio : Dag_cbor.value StringMap.t = 242 241 StringMap.( 243 242 empty |> add "height" (`Integer 2000L) |> add "width" (`Integer 1500L) ) ··· 248 247 |> add "$type" (`String "blob") 249 248 |> add "ref" 250 249 (`Link 251 - ( Result.get_ok 252 - @@ Cid.of_string 253 - "bafkreibdqy5qcefkcuvopnkt2tip5wzouscmp6duz377cneknktnsgfewe" 254 - ) ) 250 + ( Result.get_ok 251 + @@ Cid.of_string 252 + "bafkreibdqy5qcefkcuvopnkt2tip5wzouscmp6duz377cneknktnsgfewe" 253 + ) ) 255 254 |> add "mimeType" (`String "image/jpeg") 256 255 |> add "size" (`Integer 531257L) ) 257 256 in ··· 273 272 empty 274 273 |> add "features" 275 274 (`Array 276 - [| `Map 277 - ( StringMap.empty 278 - |> StringMap.add "$type" 279 - (`String "app.bsky.richtext.facet#tag") 280 - |> StringMap.add "tag" (`String "写真") ) |] ) 275 + [| `Map 276 + ( StringMap.empty 277 + |> StringMap.add "$type" 278 + (`String "app.bsky.richtext.facet#tag") 279 + |> StringMap.add "tag" (`String "写真") ) |] ) 281 280 |> add "index" 282 281 (`Map 283 - ( StringMap.empty 284 - |> StringMap.add "byteEnd" (`Integer 109L) 285 - |> StringMap.add "byteStart" (`Integer 100L) ) ) ) 282 + ( StringMap.empty 283 + |> StringMap.add "byteEnd" (`Integer 109L) 284 + |> StringMap.add "byteStart" (`Integer 100L) ) ) ) 286 285 in 287 286 let record2_facets_1 : Dag_cbor.value StringMap.t = 288 287 StringMap.( 289 288 empty 290 289 |> add "features" 291 290 (`Array 292 - [| `Map 293 - ( StringMap.empty 294 - |> StringMap.add "$type" 295 - (`String "app.bsky.richtext.facet#tag") 296 - |> StringMap.add "tag" (`String "日の出") ) |] ) 291 + [| `Map 292 + ( StringMap.empty 293 + |> StringMap.add "$type" 294 + (`String "app.bsky.richtext.facet#tag") 295 + |> StringMap.add "tag" (`String "日の出") ) |] ) 297 296 |> add "index" 298 297 (`Map 299 - ( StringMap.empty 300 - |> StringMap.add "byteEnd" (`Integer 122L) 301 - |> StringMap.add "byteStart" (`Integer 110L) ) ) ) 298 + ( StringMap.empty 299 + |> StringMap.add "byteEnd" (`Integer 122L) 300 + |> StringMap.add "byteStart" (`Integer 110L) ) ) ) 302 301 in 303 302 let record2_facets_2 : Dag_cbor.value StringMap.t = 304 303 StringMap.( 305 304 empty 306 305 |> add "features" 307 306 (`Array 308 - [| `Map 309 - ( StringMap.empty 310 - |> StringMap.add "$type" 311 - (`String "app.bsky.richtext.facet#tag") 312 - |> StringMap.add "tag" (`String "日常") ) |] ) 307 + [| `Map 308 + ( StringMap.empty 309 + |> StringMap.add "$type" 310 + (`String "app.bsky.richtext.facet#tag") 311 + |> StringMap.add "tag" (`String "日常") ) |] ) 313 312 |> add "index" 314 313 (`Map 315 - ( StringMap.empty 316 - |> StringMap.add "byteEnd" (`Integer 132L) 317 - |> StringMap.add "byteStart" (`Integer 123L) ) ) ) 314 + ( StringMap.empty 315 + |> StringMap.add "byteEnd" (`Integer 132L) 316 + |> StringMap.add "byteStart" (`Integer 123L) ) ) ) 318 317 in 319 318 let record2_facets_3 : Dag_cbor.value StringMap.t = 320 319 StringMap.( 321 320 empty 322 321 |> add "features" 323 322 (`Array 324 - [| `Map 325 - ( StringMap.empty 326 - |> StringMap.add "$type" 327 - (`String "app.bsky.richtext.facet#tag") 328 - |> StringMap.add "tag" (`String "キリトリセカイ") ) |] ) 323 + [| `Map 324 + ( StringMap.empty 325 + |> StringMap.add "$type" 326 + (`String "app.bsky.richtext.facet#tag") 327 + |> StringMap.add "tag" (`String "キリトリセカイ") ) |] ) 329 328 |> add "index" 330 329 (`Map 331 - ( StringMap.empty 332 - |> StringMap.add "byteEnd" (`Integer 157L) 333 - |> StringMap.add "byteStart" (`Integer 133L) ) ) ) 330 + ( StringMap.empty 331 + |> StringMap.add "byteEnd" (`Integer 157L) 332 + |> StringMap.add "byteStart" (`Integer 133L) ) ) ) 334 333 in 335 334 let record2_facets = 336 335 [| `Map record2_facets_0 ··· 346 345 |> add "langs" (`Array [|`String "ja"|]) 347 346 |> add "text" 348 347 (`String 349 - "おはようございます☀️\n今日の日の出です\n寒かったけど綺麗でしたよ✨\n\n#写真\n#日の出\n#日常\n#キリトリセカイ" 350 - ) 348 + "おはようございます☀️\n今日の日の出です\n寒かったけど綺麗でしたよ✨\n\n#写真\n#日の出\n#日常\n#キリトリセカイ" 349 + ) 351 350 |> add "embed" (`Map record2_embed) 352 351 |> add "facets" (`Array record2_facets) ) 353 352 in ··· 356 355 Alcotest.(check string) 357 356 "atproto record 2 encodes correctly" 358 357 "bafyreiarjuvb3oppjnouaiasitt2tekkhhge6qsd4xegutblzgmihmnrhi" 359 - Cid.(create Dcbor encoded2 |> to_string |> Result.get_ok) 358 + Cid.(create Dcbor encoded2 |> to_string) 360 359 361 360 let test_invalid_numbers () = 362 361 Alcotest.check_raises "encode rejects out of range positive integer"