#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct PutRecord<'a> {
#[serde(borrow)]
pub collection: jacquard_common::types::string::Nsid<'a>,
#[serde(borrow)]
pub record: jacquard_common::types::value::Data<'a>,
#[serde(borrow)]
pub repo: jacquard_common::types::ident::AtIdentifier<'a>,
#[serde(borrow)]
pub rkey: jacquard_common::types::string::RecordKey<
jacquard_common::types::string::Rkey<'a>,
>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub swap_commit: std::option::Option<jacquard_common::types::string::Cid<'a>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub swap_record: std::option::Option<jacquard_common::types::string::Cid<'a>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
pub validate: std::option::Option<bool>,
}
pub mod put_record_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Collection;
type Rkey;
type Repo;
type Record;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Collection = Unset;
type Rkey = Unset;
type Repo = Unset;
type Record = Unset;
}
pub struct SetCollection<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCollection<S> {}
impl<S: State> State for SetCollection<S> {
type Collection = Set<members::collection>;
type Rkey = S::Rkey;
type Repo = S::Repo;
type Record = S::Record;
}
pub struct SetRkey<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRkey<S> {}
impl<S: State> State for SetRkey<S> {
type Collection = S::Collection;
type Rkey = Set<members::rkey>;
type Repo = S::Repo;
type Record = S::Record;
}
pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRepo<S> {}
impl<S: State> State for SetRepo<S> {
type Collection = S::Collection;
type Rkey = S::Rkey;
type Repo = Set<members::repo>;
type Record = S::Record;
}
pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRecord<S> {}
impl<S: State> State for SetRecord<S> {
type Collection = S::Collection;
type Rkey = S::Rkey;
type Repo = S::Repo;
type Record = Set<members::record>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct collection(());
pub struct rkey(());
pub struct repo(());
pub struct record(());
}
}
pub struct PutRecordBuilder<'a, S: put_record_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::types::string::Nsid<'a>>,
::core::option::Option<jacquard_common::types::value::Data<'a>>,
::core::option::Option<jacquard_common::types::ident::AtIdentifier<'a>>,
::core::option::Option<
jacquard_common::types::string::RecordKey<
jacquard_common::types::string::Rkey<'a>,
>,
>,
::core::option::Option<jacquard_common::types::string::Cid<'a>>,
::core::option::Option<jacquard_common::types::string::Cid<'a>>,
::core::option::Option<bool>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> PutRecord<'a> {
pub fn new() -> PutRecordBuilder<'a, put_record_state::Empty> {
PutRecordBuilder::new()
}
}
impl<'a> PutRecordBuilder<'a, put_record_state::Empty> {
pub fn new() -> Self {
PutRecordBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None, None, None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> PutRecordBuilder<'a, S>
where
S: put_record_state::State,
S::Collection: put_record_state::IsUnset,
{
pub fn collection(
mut self,
value: impl Into<jacquard_common::types::string::Nsid<'a>>,
) -> PutRecordBuilder<'a, put_record_state::SetCollection<S>> {
self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
PutRecordBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> PutRecordBuilder<'a, S>
where
S: put_record_state::State,
S::Record: put_record_state::IsUnset,
{
pub fn record(
mut self,
value: impl Into<jacquard_common::types::value::Data<'a>>,
) -> PutRecordBuilder<'a, put_record_state::SetRecord<S>> {
self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
PutRecordBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> PutRecordBuilder<'a, S>
where
S: put_record_state::State,
S::Repo: put_record_state::IsUnset,
{
pub fn repo(
mut self,
value: impl Into<jacquard_common::types::ident::AtIdentifier<'a>>,
) -> PutRecordBuilder<'a, put_record_state::SetRepo<S>> {
self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
PutRecordBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> PutRecordBuilder<'a, S>
where
S: put_record_state::State,
S::Rkey: put_record_state::IsUnset,
{
pub fn rkey(
mut self,
value: impl Into<
jacquard_common::types::string::RecordKey<
jacquard_common::types::string::Rkey<'a>,
>,
>,
) -> PutRecordBuilder<'a, put_record_state::SetRkey<S>> {
self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
PutRecordBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: put_record_state::State> PutRecordBuilder<'a, S> {
pub fn swap_commit(
mut self,
value: impl Into<Option<jacquard_common::types::string::Cid<'a>>>,
) -> Self {
self.__unsafe_private_named.4 = value.into();
self
}
pub fn maybe_swap_commit(
mut self,
value: Option<jacquard_common::types::string::Cid<'a>>,
) -> Self {
self.__unsafe_private_named.4 = value;
self
}
}
impl<'a, S: put_record_state::State> PutRecordBuilder<'a, S> {
pub fn swap_record(
mut self,
value: impl Into<Option<jacquard_common::types::string::Cid<'a>>>,
) -> Self {
self.__unsafe_private_named.5 = value.into();
self
}
pub fn maybe_swap_record(
mut self,
value: Option<jacquard_common::types::string::Cid<'a>>,
) -> Self {
self.__unsafe_private_named.5 = value;
self
}
}
impl<'a, S: put_record_state::State> PutRecordBuilder<'a, S> {
pub fn validate(mut self, value: impl Into<Option<bool>>) -> Self {
self.__unsafe_private_named.6 = value.into();
self
}
pub fn maybe_validate(mut self, value: Option<bool>) -> Self {
self.__unsafe_private_named.6 = value;
self
}
}
impl<'a, S> PutRecordBuilder<'a, S>
where
S: put_record_state::State,
S::Collection: put_record_state::IsSet,
S::Rkey: put_record_state::IsSet,
S::Repo: put_record_state::IsSet,
S::Record: put_record_state::IsSet,
{
pub fn build(self) -> PutRecord<'a> {
PutRecord {
collection: self.__unsafe_private_named.0.unwrap(),
record: self.__unsafe_private_named.1.unwrap(),
repo: self.__unsafe_private_named.2.unwrap(),
rkey: self.__unsafe_private_named.3.unwrap(),
swap_commit: self.__unsafe_private_named.4,
swap_record: self.__unsafe_private_named.5,
validate: self.__unsafe_private_named.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: std::collections::BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> PutRecord<'a> {
PutRecord {
collection: self.__unsafe_private_named.0.unwrap(),
record: self.__unsafe_private_named.1.unwrap(),
repo: self.__unsafe_private_named.2.unwrap(),
rkey: self.__unsafe_private_named.3.unwrap(),
swap_commit: self.__unsafe_private_named.4,
swap_record: self.__unsafe_private_named.5,
validate: self.__unsafe_private_named.6,
extra_data: Some(extra_data),
}
}
}
#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct PutRecordOutput<'a> {
#[serde(borrow)]
pub cid: jacquard_common::types::string::Cid<'a>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub commit: std::option::Option<crate::com_atproto::repo::CommitMeta<'a>>,
#[serde(borrow)]
pub uri: jacquard_common::types::string::AtUri<'a>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub validation_status: std::option::Option<PutRecordOutputValidationStatus<'a>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PutRecordOutputValidationStatus<'a> {
Valid,
Unknown,
Other(jacquard_common::CowStr<'a>),
}
impl<'a> PutRecordOutputValidationStatus<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Valid => "valid",
Self::Unknown => "unknown",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for PutRecordOutputValidationStatus<'a> {
fn from(s: &'a str) -> Self {
match s {
"valid" => Self::Valid,
"unknown" => Self::Unknown,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> From<String> for PutRecordOutputValidationStatus<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"valid" => Self::Valid,
"unknown" => Self::Unknown,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for PutRecordOutputValidationStatus<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for PutRecordOutputValidationStatus<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for PutRecordOutputValidationStatus<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for PutRecordOutputValidationStatus<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for PutRecordOutputValidationStatus<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for PutRecordOutputValidationStatus<'_> {
type Output = PutRecordOutputValidationStatus<'static>;
fn into_static(self) -> Self::Output {
match self {
PutRecordOutputValidationStatus::Valid => {
PutRecordOutputValidationStatus::Valid
}
PutRecordOutputValidationStatus::Unknown => {
PutRecordOutputValidationStatus::Unknown
}
PutRecordOutputValidationStatus::Other(v) => {
PutRecordOutputValidationStatus::Other(v.into_static())
}
}
}
}
#[jacquard_derive::open_union]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic,
jacquard_derive::IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum PutRecordError<'a> {
#[serde(rename = "InvalidSwap")]
InvalidSwap(std::option::Option<jacquard_common::CowStr<'a>>),
}
impl core::fmt::Display for PutRecordError<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidSwap(msg) => {
write!(f, "InvalidSwap")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
pub struct PutRecordResponse;
impl jacquard_common::xrpc::XrpcResp for PutRecordResponse {
const NSID: &'static str = "com.atproto.repo.putRecord";
const ENCODING: &'static str = "application/json";
type Output<'de> = PutRecordOutput<'de>;
type Err<'de> = PutRecordError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for PutRecord<'a> {
const NSID: &'static str = "com.atproto.repo.putRecord";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = PutRecordResponse;
}
pub struct PutRecordRequest;
impl jacquard_common::xrpc::XrpcEndpoint for PutRecordRequest {
const PATH: &'static str = "/xrpc/com.atproto.repo.putRecord";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<'de> = PutRecord<'de>;
type Response = PutRecordResponse;
}