tangled-api 0.1.0

Lexicon-generated XRPC client for Tangled and AT Protocol APIs
Documentation
// @generated by `cargo xtask codegen` — do not edit.
// source: lexicons/com/atproto/repo/createRecord.json (com.atproto.repo.createRecord)

#![allow(clippy::all)]

pub const NSID: &str = "com.atproto.repo.createRecord";

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Input {
    /// The NSID of the record collection.
    pub collection: String,
    /// The record itself. Must contain a $type field.
    pub record: serde_json::Value,
    /// The handle or DID of the repo (aka, current account).
    pub repo: String,
    /// The Record Key.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub rkey: Option<String>,
    /// Compare and swap with the previous commit by CID.
    #[serde(
        rename = "swapCommit",
        skip_serializing_if = "Option::is_none",
        default
    )]
    pub swap_commit: Option<String>,
    /// Can be set to 'false' to skip Lexicon schema validation of record data, 'true' to require it, or leave unset to validate only for known Lexicons.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub validate: Option<bool>,
}

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Output {
    pub cid: String,
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub commit: Option<crate::lexicon::com::atproto::repo::defs::CommitMeta>,
    pub uri: String,
    #[serde(
        rename = "validationStatus",
        skip_serializing_if = "Option::is_none",
        default
    )]
    pub validation_status: Option<String>,
}

/// Create a single new repository record. Requires auth, implemented by PDS.
///
/// Errors:
/// - `InvalidSwap`: Indicates that 'swapCommit' didn't match current repo commit.
pub fn create_record(
    http: &reqwest::Client,
    base: &str,
    input: &Input,
) -> reqwest::RequestBuilder {
    let rb = http.post(crate::xrpc::xrpc_url(base, NSID));
    let rb = rb.header(reqwest::header::ACCEPT, "application/json");
    let rb = rb.json(input);
    rb
}