A library for ATProtocol identities.

feature: atproto-client delete_record method added

Signed-off-by: Nick Gerakines <nick.gerakines@gmail.com>

Changed files
+78
crates
atproto-client
+78
crates/atproto-client/src/com_atproto_repo.rs
··· 10 10 //! - **`list_records()`**: List records in a collection with pagination support 11 11 //! - **`create_record()`**: Create a new record in a repository 12 12 //! - **`put_record()`**: Update or create a record with a specific key 13 + //! - **`delete_record()`**: Delete a record from a repository 13 14 //! 14 15 //! ## Request/Response Types 15 16 //! 16 17 //! - **`CreateRecordRequest`**: Parameters for creating new records 17 18 //! - **`PutRecordRequest`**: Parameters for updating/creating records with specific keys 19 + //! - **`DeleteRecordRequest`**: Parameters for deleting records 18 20 //! - **`GetRecordResponse`**: Response containing record data or error 19 21 //! - **`ListRecordsResponse`**: Paginated list of records with cursor support 20 22 //! - **`CreateRecordResponse`**: Response with created record URI and CID 21 23 //! - **`PutRecordResponse`**: Response with updated record URI and CID 24 + //! - **`DeleteRecordResponse`**: Response with commit information or error 22 25 //! 23 26 //! ## Authentication 24 27 //! ··· 405 408 .await 406 409 .and_then(|value| serde_json::from_value(value).map_err(|err| err.into())) 407 410 } 411 + 412 + /// Request to delete a record from an AT Protocol repository. 413 + #[cfg_attr(debug_assertions, derive(Debug))] 414 + #[derive(Serialize, Deserialize, Clone)] 415 + pub struct DeleteRecordRequest { 416 + /// Repository identifier (DID) 417 + pub repo: String, 418 + /// Collection NSID (e.g., "app.bsky.feed.post") 419 + pub collection: String, 420 + 421 + /// Record key to delete 422 + #[serde(rename = "rkey")] 423 + pub record_key: String, 424 + 425 + /// Optional commit CID to swap (for atomic updates) 426 + #[serde( 427 + skip_serializing_if = "Option::is_none", 428 + default, 429 + rename = "swapCommit" 430 + )] 431 + pub swap_commit: Option<String>, 432 + 433 + /// Optional record CID to swap (for atomic updates) 434 + #[serde( 435 + skip_serializing_if = "Option::is_none", 436 + default, 437 + rename = "swapRecord" 438 + )] 439 + pub swap_record: Option<String>, 440 + } 441 + 442 + /// Response from deleting a record in an AT Protocol repository. 443 + #[cfg_attr(debug_assertions, derive(Debug))] 444 + #[derive(Deserialize, Clone)] 445 + #[serde(untagged)] 446 + pub enum DeleteRecordResponse { 447 + /// Successfully deleted record with commit information 448 + Commit { 449 + /// Commit information as a map of fields 450 + #[serde(flatten)] 451 + commit: HashMap<String, serde_json::Value>, 452 + }, 453 + 454 + /// Error response from the server 455 + Error(SimpleError), 456 + } 457 + 458 + /// Deletes a record from an AT Protocol repository. 459 + /// 460 + /// # Arguments 461 + /// 462 + /// * `http_client` - HTTP client for making requests 463 + /// * `dpop_auth` - DPoP authentication credentials 464 + /// * `base_url` - Base URL of the AT Protocol server 465 + /// * `record` - Record deletion request with repository, collection, and key 466 + /// 467 + /// # Returns 468 + /// 469 + /// The deletion response with commit information or an error 470 + pub async fn delete_record( 471 + http_client: &reqwest::Client, 472 + dpop_auth: &DPoPAuth, 473 + base_url: &str, 474 + record: DeleteRecordRequest, 475 + ) -> Result<DeleteRecordResponse> { 476 + let mut url_builder = URLBuilder::new(base_url); 477 + url_builder.path("/xrpc/com.atproto.repo.deleteRecord"); 478 + let url = url_builder.build(); 479 + 480 + let value = serde_json::to_value(record)?; 481 + 482 + post_dpop_json(http_client, dpop_auth, &url, value) 483 + .await 484 + .and_then(|value| serde_json::from_value(value).map_err(|err| err.into())) 485 + }