ATProto Personal Data Server storage for OCaml
4
fork

Configure Feed

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

fix(requests,pds): rename get->find, apply dune fmt formatting

+20 -20
+2 -2
README.md
··· 41 41 Pds.put repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" record_bytes; 42 42 43 43 (* Read records *) 44 - let data = Pds.get repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" in 44 + let data = Pds.find repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" in 45 45 46 46 (* List collection *) 47 47 let records = Pds.list repo ~collection:"app.bsky.feed.post" in ··· 70 70 71 71 ### Records 72 72 73 - - `Pds.get t ~collection ~rkey` - Read a record 73 + - `Pds.find t ~collection ~rkey` - Read a record 74 74 - `Pds.put t ~collection ~rkey data` - Write a record 75 75 - `Pds.delete t ~collection ~rkey` - Delete a record 76 76 - `Pds.list t ~collection` - List records in a collection
+1 -1
lib/blob_store.ml
··· 40 40 let size = Int64.of_int (String.length data) in 41 41 { Atp.Blob_ref.cid; mime_type; size } 42 42 43 - let get t cid = 43 + let find t cid = 44 44 let path = blob_path t cid in 45 45 try Some (Eio.Path.load path) 46 46 with Eio.Io (Eio.Fs.E (Eio.Fs.Not_found _), _) -> None
+2 -2
lib/blob_store.mli
··· 23 23 val put : t -> mime_type:string -> string -> Atp.Blob_ref.t 24 24 (** [put t ~mime_type data] stores [data] and returns a blob reference. *) 25 25 26 - val get : t -> Atp.Cid.t -> string option 27 - (** [get t cid] retrieves blob data by CID. *) 26 + val find : t -> Atp.Cid.t -> string option 27 + (** [find t cid] retrieves blob data by CID. *) 28 28 29 29 val delete : t -> Atp.Cid.t -> unit 30 30 (** [delete t cid] removes a blob. *)
+2 -2
lib/pds.ml
··· 108 108 109 109 (* Records *) 110 110 111 - let get t ~collection ~rkey = 111 + let find t ~collection ~rkey = 112 112 match checkout t with 113 113 | None -> None 114 114 | Some mst -> ( ··· 159 159 (* Blobs *) 160 160 161 161 let put_blob t ~mime_type data = Blob_store.put t.blobs ~mime_type data 162 - let blob t cid = Blob_store.get t.blobs cid 162 + let blob t cid = Blob_store.find t.blobs cid 163 163 164 164 (* CAR Import/Export *) 165 165
+2 -2
lib/pds.mli
··· 53 53 Records are stored in the MST with keys of the form [collection/rkey], e.g., 54 54 ["app.bsky.feed.post/abc123"]. *) 55 55 56 - val get : t -> collection:string -> rkey:string -> string option 57 - (** [get t ~collection ~rkey] reads a record's DAG-CBOR bytes. *) 56 + val find : t -> collection:string -> rkey:string -> string option 57 + (** [find t ~collection ~rkey] reads a record's DAG-CBOR bytes. *) 58 58 59 59 val put : t -> collection:string -> rkey:string -> string -> unit 60 60 (** [put t ~collection ~rkey data] writes a record (DAG-CBOR bytes). Creates a
+8 -8
test/test_blob_store.ml
··· 34 34 let store = Pds.Blob_store.v path in 35 35 let data = "Hello, blob store!" in 36 36 let blob_ref = Pds.Blob_store.put store ~mime_type:"text/plain" data in 37 - let result = Pds.Blob_store.get store blob_ref.cid in 37 + let result = Pds.Blob_store.find store blob_ref.cid in 38 38 Alcotest.(check (option string)) "roundtrip data" (Some data) result 39 39 40 40 let test_put_returns_correct_size () = ··· 59 59 with_temp_dir @@ fun path -> 60 60 let store = Pds.Blob_store.v path in 61 61 let fake_cid = Atp.Cid.v `Raw "nonexistent data" in 62 - let result = Pds.Blob_store.get store fake_cid in 62 + let result = Pds.Blob_store.find store fake_cid in 63 63 Alcotest.(check (option string)) "missing CID returns None" None result 64 64 65 65 let test_mem_true_for_stored () = ··· 93 93 Alcotest.(check bool) 94 94 "gone after delete" false 95 95 (Pds.Blob_store.mem store blob_ref.cid); 96 - let result = Pds.Blob_store.get store blob_ref.cid in 96 + let result = Pds.Blob_store.find store blob_ref.cid in 97 97 Alcotest.(check (option string)) "get after delete returns None" None result 98 98 99 99 let test_binary_data () = ··· 103 103 let blob_ref = 104 104 Pds.Blob_store.put store ~mime_type:"application/octet-stream" data 105 105 in 106 - let result = Pds.Blob_store.get store blob_ref.cid in 106 + let result = Pds.Blob_store.find store blob_ref.cid in 107 107 Alcotest.(check (option string)) "binary data preserved" (Some data) result 108 108 109 109 let test_multiple_mime_types () = ··· 128 128 (fun (mime_type, data) blob_ref -> 129 129 Alcotest.(check string) 130 130 "mime type" mime_type blob_ref.Atp.Blob_ref.mime_type; 131 - let result = Pds.Blob_store.get store blob_ref.cid in 131 + let result = Pds.Blob_store.find store blob_ref.cid in 132 132 Alcotest.(check (option string)) 133 133 (Fmt.str "data for %s" mime_type) 134 134 (Some data) result) ··· 141 141 let blob_ref = 142 142 Pds.Blob_store.put store ~mime_type:"application/octet-stream" data 143 143 in 144 - let result = Pds.Blob_store.get store blob_ref.cid in 144 + let result = Pds.Blob_store.find store blob_ref.cid in 145 145 Alcotest.(check (option string)) "large blob roundtrip" (Some data) result; 146 146 Alcotest.(check int64) "large blob size" (Int64.of_int 100_000) blob_ref.size 147 147 ··· 152 152 let blob_ref = 153 153 Pds.Blob_store.put store ~mime_type:"application/octet-stream" data 154 154 in 155 - let result = Pds.Blob_store.get store blob_ref.cid in 155 + let result = Pds.Blob_store.find store blob_ref.cid in 156 156 Alcotest.(check (option string)) "empty blob roundtrip" (Some data) result; 157 157 Alcotest.(check int64) "empty blob size" 0L blob_ref.size 158 158 ··· 167 167 "same CID for same data" 168 168 (Atp.Cid.to_string ref1.cid) 169 169 (Atp.Cid.to_string ref2.cid); 170 - let result = Pds.Blob_store.get store ref1.cid in 170 + let result = Pds.Blob_store.find store ref1.cid in 171 171 Alcotest.(check (option string)) "still retrievable" (Some data) result 172 172 173 173 let test_delete_missing_is_noop () =
+3 -3
test/test_pds.ml
··· 58 58 Atp.Dagcbor.encode_string (`Map [ ("text", `String "Hello world") ]) 59 59 in 60 60 Pds.put repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" data; 61 - let result = Pds.get repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" in 61 + let result = Pds.find repo ~collection:"app.bsky.feed.post" ~rkey:"abc123" in 62 62 Alcotest.(check (option string)) "record retrieved" (Some data) result 63 63 64 64 let test_get_missing_record () = 65 65 with_temp_repo @@ fun repo -> 66 66 let result = 67 - Pds.get repo ~collection:"app.bsky.feed.post" ~rkey:"nonexistent" 67 + Pds.find repo ~collection:"app.bsky.feed.post" ~rkey:"nonexistent" 68 68 in 69 69 Alcotest.(check (option string)) "missing record returns None" None result 70 70 ··· 73 73 let data = Atp.Dagcbor.encode_string (`String "test") in 74 74 Pds.put repo ~collection:"test.collection" ~rkey:"key1" data; 75 75 Pds.delete repo ~collection:"test.collection" ~rkey:"key1"; 76 - let result = Pds.get repo ~collection:"test.collection" ~rkey:"key1" in 76 + let result = Pds.find repo ~collection:"test.collection" ~rkey:"key1" in 77 77 Alcotest.(check (option string)) "deleted record returns None" None result 78 78 79 79 let test_list_collection () =