#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Datetime;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct DraftView<S: BosStr = DefaultStr> {
pub content: S,
pub created_at: Datetime,
pub tid: S,
pub updated_at: Datetime,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct PutDraft<S: BosStr = DefaultStr> {
pub content: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub tid: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct PutDraftOutput<S: BosStr = DefaultStr> {
#[serde(flatten)]
pub value: Data<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
)]
#[serde(tag = "error", content = "message")]
pub enum PutDraftError {
#[serde(rename = "DraftNotFound")]
DraftNotFound(Option<SmolStr>),
#[serde(untagged)]
Other {
error: SmolStr,
message: Option<SmolStr>,
},
}
impl core::fmt::Display for PutDraftError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::DraftNotFound(msg) => {
write!(f, "DraftNotFound")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Other { error, message } => {
write!(f, "{}", error)?;
if let Some(msg) = message {
write!(f, ": {}", msg)?;
}
Ok(())
}
}
}
}
impl<S: BosStr> LexiconSchema for DraftView<S> {
fn nsid() -> &'static str {
"at.unthread.document.putDraft"
}
fn def_name() -> &'static str {
"draftView"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_at_unthread_document_putDraft()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub struct PutDraftResponse;
impl jacquard_common::xrpc::XrpcResp for PutDraftResponse {
const NSID: &'static str = "at.unthread.document.putDraft";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = PutDraftOutput<S>;
type Err = PutDraftError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for PutDraft<S> {
const NSID: &'static str = "at.unthread.document.putDraft";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Response = PutDraftResponse;
}
pub struct PutDraftRequest;
impl jacquard_common::xrpc::XrpcEndpoint for PutDraftRequest {
const PATH: &'static str = "/xrpc/at.unthread.document.putDraft";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Request<S: BosStr> = PutDraft<S>;
type Response = PutDraftResponse;
}
pub mod draft_view_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Content;
type UpdatedAt;
type Tid;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Content = Unset;
type UpdatedAt = Unset;
type Tid = Unset;
type CreatedAt = Unset;
}
pub struct SetContent<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetContent<St> {}
impl<St: State> State for SetContent<St> {
type Content = Set<members::content>;
type UpdatedAt = St::UpdatedAt;
type Tid = St::Tid;
type CreatedAt = St::CreatedAt;
}
pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
impl<St: State> State for SetUpdatedAt<St> {
type Content = St::Content;
type UpdatedAt = Set<members::updated_at>;
type Tid = St::Tid;
type CreatedAt = St::CreatedAt;
}
pub struct SetTid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTid<St> {}
impl<St: State> State for SetTid<St> {
type Content = St::Content;
type UpdatedAt = St::UpdatedAt;
type Tid = Set<members::tid>;
type CreatedAt = St::CreatedAt;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type Content = St::Content;
type UpdatedAt = St::UpdatedAt;
type Tid = St::Tid;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct content(());
pub struct updated_at(());
pub struct tid(());
pub struct created_at(());
}
}
pub struct DraftViewBuilder<S: BosStr, St: draft_view_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<Datetime>, Option<S>, Option<Datetime>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> DraftView<S> {
pub fn new() -> DraftViewBuilder<S, draft_view_state::Empty> {
DraftViewBuilder::new()
}
}
impl<S: BosStr> DraftViewBuilder<S, draft_view_state::Empty> {
pub fn new() -> Self {
DraftViewBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DraftViewBuilder<S, St>
where
St: draft_view_state::State,
St::Content: draft_view_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<S>,
) -> DraftViewBuilder<S, draft_view_state::SetContent<St>> {
self._fields.0 = Option::Some(value.into());
DraftViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DraftViewBuilder<S, St>
where
St: draft_view_state::State,
St::CreatedAt: draft_view_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> DraftViewBuilder<S, draft_view_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
DraftViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DraftViewBuilder<S, St>
where
St: draft_view_state::State,
St::Tid: draft_view_state::IsUnset,
{
pub fn tid(mut self, value: impl Into<S>) -> DraftViewBuilder<S, draft_view_state::SetTid<St>> {
self._fields.2 = Option::Some(value.into());
DraftViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DraftViewBuilder<S, St>
where
St: draft_view_state::State,
St::UpdatedAt: draft_view_state::IsUnset,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> DraftViewBuilder<S, draft_view_state::SetUpdatedAt<St>> {
self._fields.3 = Option::Some(value.into());
DraftViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DraftViewBuilder<S, St>
where
St: draft_view_state::State,
St::Content: draft_view_state::IsSet,
St::UpdatedAt: draft_view_state::IsSet,
St::Tid: draft_view_state::IsSet,
St::CreatedAt: draft_view_state::IsSet,
{
pub fn build(self) -> DraftView<S> {
DraftView {
content: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
tid: self._fields.2.unwrap(),
updated_at: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> DraftView<S> {
DraftView {
content: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
tid: self._fields.2.unwrap(),
updated_at: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_at_unthread_document_putDraft() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("at.unthread.document.putDraft"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("draftView"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("tid"),
SmolStr::new_static("content"),
SmolStr::new_static("createdAt"),
SmolStr::new_static("updatedAt"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tid"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::XrpcProcedure(LexXrpcProcedure {
input: Some(LexXrpcBody {
encoding: CowStr::new_static("application/json"),
schema: Some(
LexXrpcBodySchema::Object(LexObject {
required: Some(vec![SmolStr::new_static("content")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Markdown content of the draft."),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"TID of an existing draft to update. Omit to create a new draft.",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
),
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}