diff --git a/src/possum.gleam b/src/possum.gleam index f67e2d6..4c3e04b 100644 --- a/src/possum.gleam +++ b/src/possum.gleam @@ -338,7 +338,7 @@ pub fn get_session_info(request: request.Request(_)) -> request.Request(_) { /// let request = /// request.new() /// |> request.set_host("personal.data-server.pds") -/// |> possum.authorized("my-access-token") +/// |> possum.authorized("access-token") /// ``` /// pub fn authorized( @@ -412,7 +412,7 @@ pub fn describe_repository( /// |> request.set_host("personal.data-server.pds") /// |> possum.authorized("access-token") /// |> possum.create_record( -/// did: did, +/// did, /// rkey: "wibble", /// collection: "wibble.wobble.woo", /// record: [], @@ -439,8 +439,8 @@ pub fn describe_repository( pub fn create_record( request: request.Request(_), did: did.Did, - rkey rkey: option.Option(String), collection collection: String, + rkey rkey: option.Option(String), record record: List(#(String, json.Json)), swap_commit swap_commit: option.Option(String), validate validate: option.Option(Bool), @@ -490,7 +490,7 @@ pub fn create_record( /// request.new() /// |> request.set_host("personal.data-server.pds") /// |> possum.get_record( -/// repository: did, +/// did, /// rkey: "3mn6n3lvibc2b", /// collection: "site.standard.document", /// cursor: option.None, @@ -513,8 +513,8 @@ pub fn create_record( pub fn get_record( request: request.Request(_), did: did.Did, - rkey rkey: String, collection collection: String, + rkey rkey: String, cid cid: option.Option(String), ) -> request.Request(_) { let query = [ @@ -547,7 +547,7 @@ pub fn get_record( /// request.new() /// |> request.set_host("personal.data-server.pds") /// |> possum.list_records( -/// did: did, +/// did, /// collection: "site.standard.document", /// limit: option.Some(3), /// cursor: option.None, @@ -641,3 +641,75 @@ pub fn list_standard_documents( reverse: option.None, ) } + +/// Delete a repository record, or ensure it doesn't exist. +/// Requires auth, implemented by PDS. +/// +/// - **collection**: The NSID of the record collection. +/// - **repo**: The handle or DID of the repo (aka, current account). +/// - **rkey**: The Record Key. +/// - **swapCommit**: Compare and swap with the previous commit by CID. +/// - **swapRecord**: Compare and swap with the previous record by CID. +/// +/// ## Examples +/// +/// ```gleam +/// import gleam/http/request +/// import possum +/// +/// let request = +/// request.new() +/// |> request.set_host("personal.data-server.pds") +/// |> possum.authorized("access-token") +/// |> possum.delete_record( +/// did, +/// collection: "target.collection.data", +/// rkey: "wibble-wobble", +/// swap_commit: option.None, +/// swap_record: option.None, +/// ) +/// ``` +/// +/// ## Response +/// +/// ```json +/// { +/// "commit": { +/// "cid": "string", +/// "rev": "string" +/// } +/// } +/// ``` +/// +/// Endpoint Docs: [/xrpc/com.atproto.repo.deleteRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.deleteRecord) +pub fn delete_record( + request: request.Request(_), + did: did.Did, + collection collection: String, + rkey rkey: String, + swap_commit swap_commit: option.Option(String), + swap_record swap_record: option.Option(String), +) -> request.Request(_) { + let body = [ + #("repo", json.string(did.to_string(did))), + #("collection", json.string(collection)), + #("rkey", json.string(rkey)), + ] + + let body = case swap_commit { + option.Some(value) -> [#("swapCommit", json.string(value)), ..body] + option.None -> body + } + + let body = case swap_record { + option.Some(value) -> [#("swapRecord", json.string(value)), ..body] + option.None -> body + } + + request + |> request.prepend_header("accept", "application/json") + |> request.prepend_header("content-type", "application/json") + |> request.set_body(json.to_string(json.object(body))) + |> request.set_method(http.Post) + |> request.set_path(com_atproto_repo <> ".deleteRecord") +}