jacquard_api/sh_weaver/edit/
draft.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::collection::{Collection, RecordError};
18use jacquard_common::types::string::{AtUri, Cid, Datetime};
19use jacquard_common::types::uri::{RecordUri, UriError};
20use jacquard_common::xrpc::XrpcResp;
21use jacquard_derive::{IntoStatic, lexicon};
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Serialize, Deserialize};
28#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "sh.weaver.edit.draft", tag = "$type")]
33pub struct Draft<'a> {
34 pub created_at: Datetime,
35}
36
37#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
40#[serde(rename_all = "camelCase")]
41pub struct DraftGetRecordOutput<'a> {
42 #[serde(skip_serializing_if = "Option::is_none")]
43 #[serde(borrow)]
44 pub cid: Option<Cid<'a>>,
45 #[serde(borrow)]
46 pub uri: AtUri<'a>,
47 #[serde(borrow)]
48 pub value: Draft<'a>,
49}
50
51impl<'a> Draft<'a> {
52 pub fn uri(
53 uri: impl Into<CowStr<'a>>,
54 ) -> Result<RecordUri<'a, DraftRecord>, UriError> {
55 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
56 }
57}
58
59#[derive(Debug, Serialize, Deserialize)]
62pub struct DraftRecord;
63impl XrpcResp for DraftRecord {
64 const NSID: &'static str = "sh.weaver.edit.draft";
65 const ENCODING: &'static str = "application/json";
66 type Output<'de> = DraftGetRecordOutput<'de>;
67 type Err<'de> = RecordError<'de>;
68}
69
70impl From<DraftGetRecordOutput<'_>> for Draft<'_> {
71 fn from(output: DraftGetRecordOutput<'_>) -> Self {
72 use jacquard_common::IntoStatic;
73 output.value.into_static()
74 }
75}
76
77impl Collection for Draft<'_> {
78 const NSID: &'static str = "sh.weaver.edit.draft";
79 type Record = DraftRecord;
80}
81
82impl Collection for DraftRecord {
83 const NSID: &'static str = "sh.weaver.edit.draft";
84 type Record = DraftRecord;
85}
86
87impl<'a> LexiconSchema for Draft<'a> {
88 fn nsid() -> &'static str {
89 "sh.weaver.edit.draft"
90 }
91 fn def_name() -> &'static str {
92 "main"
93 }
94 fn lexicon_doc() -> LexiconDoc<'static> {
95 lexicon_doc_sh_weaver_edit_draft()
96 }
97 fn validate(&self) -> Result<(), ConstraintError> {
98 Ok(())
99 }
100}
101
102pub mod draft_state {
103
104 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
105 #[allow(unused)]
106 use ::core::marker::PhantomData;
107 mod sealed {
108 pub trait Sealed {}
109 }
110 pub trait State: sealed::Sealed {
112 type CreatedAt;
113 }
114 pub struct Empty(());
116 impl sealed::Sealed for Empty {}
117 impl State for Empty {
118 type CreatedAt = Unset;
119 }
120 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
122 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
123 impl<S: State> State for SetCreatedAt<S> {
124 type CreatedAt = Set<members::created_at>;
125 }
126 #[allow(non_camel_case_types)]
128 pub mod members {
129 pub struct created_at(());
131 }
132}
133
134pub struct DraftBuilder<'a, S: draft_state::State> {
136 _state: PhantomData<fn() -> S>,
137 _fields: (Option<Datetime>,),
138 _lifetime: PhantomData<&'a ()>,
139}
140
141impl<'a> Draft<'a> {
142 pub fn new() -> DraftBuilder<'a, draft_state::Empty> {
144 DraftBuilder::new()
145 }
146}
147
148impl<'a> DraftBuilder<'a, draft_state::Empty> {
149 pub fn new() -> Self {
151 DraftBuilder {
152 _state: PhantomData,
153 _fields: (None,),
154 _lifetime: PhantomData,
155 }
156 }
157}
158
159impl<'a, S> DraftBuilder<'a, S>
160where
161 S: draft_state::State,
162 S::CreatedAt: draft_state::IsUnset,
163{
164 pub fn created_at(
166 mut self,
167 value: impl Into<Datetime>,
168 ) -> DraftBuilder<'a, draft_state::SetCreatedAt<S>> {
169 self._fields.0 = Option::Some(value.into());
170 DraftBuilder {
171 _state: PhantomData,
172 _fields: self._fields,
173 _lifetime: PhantomData,
174 }
175 }
176}
177
178impl<'a, S> DraftBuilder<'a, S>
179where
180 S: draft_state::State,
181 S::CreatedAt: draft_state::IsSet,
182{
183 pub fn build(self) -> Draft<'a> {
185 Draft {
186 created_at: self._fields.0.unwrap(),
187 extra_data: Default::default(),
188 }
189 }
190 pub fn build_with_data(
192 self,
193 extra_data: BTreeMap<
194 jacquard_common::deps::smol_str::SmolStr,
195 jacquard_common::types::value::Data<'a>,
196 >,
197 ) -> Draft<'a> {
198 Draft {
199 created_at: self._fields.0.unwrap(),
200 extra_data: Some(extra_data),
201 }
202 }
203}
204
205fn lexicon_doc_sh_weaver_edit_draft() -> LexiconDoc<'static> {
206 #[allow(unused_imports)]
207 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
208 use jacquard_lexicon::lexicon::*;
209 use alloc::collections::BTreeMap;
210 LexiconDoc {
211 lexicon: Lexicon::Lexicon1,
212 id: CowStr::new_static("sh.weaver.edit.draft"),
213 defs: {
214 let mut map = BTreeMap::new();
215 map.insert(
216 SmolStr::new_static("main"),
217 LexUserType::Record(LexRecord {
218 description: Some(
219 CowStr::new_static(
220 "Stub record for unpublished drafts. Acts as an anchor for edit.root/diff records and enables draft discovery via listRecords.",
221 ),
222 ),
223 key: Some(CowStr::new_static("tid")),
224 record: LexRecordRecord::Object(LexObject {
225 required: Some(vec![SmolStr::new_static("createdAt")]),
226 properties: {
227 #[allow(unused_mut)]
228 let mut map = BTreeMap::new();
229 map.insert(
230 SmolStr::new_static("createdAt"),
231 LexObjectProperty::String(LexString {
232 format: Some(LexStringFormat::Datetime),
233 ..Default::default()
234 }),
235 );
236 map
237 },
238 ..Default::default()
239 }),
240 ..Default::default()
241 }),
242 );
243 map
244 },
245 ..Default::default()
246 }
247}