jacquard_api/sh_tangled/repo/pull/
comment.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::{Did, 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
29#[lexicon]
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
31#[serde(
32 rename_all = "camelCase",
33 rename = "sh.tangled.repo.pull.comment",
34 tag = "$type"
35)]
36pub struct Comment<'a> {
37 #[serde(borrow)]
38 pub body: CowStr<'a>,
39 pub created_at: Datetime,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub mentions: Option<Vec<Did<'a>>>,
43 #[serde(borrow)]
44 pub pull: AtUri<'a>,
45 #[serde(skip_serializing_if = "Option::is_none")]
46 #[serde(borrow)]
47 pub references: Option<Vec<AtUri<'a>>>,
48}
49
50#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
53#[serde(rename_all = "camelCase")]
54pub struct CommentGetRecordOutput<'a> {
55 #[serde(skip_serializing_if = "Option::is_none")]
56 #[serde(borrow)]
57 pub cid: Option<Cid<'a>>,
58 #[serde(borrow)]
59 pub uri: AtUri<'a>,
60 #[serde(borrow)]
61 pub value: Comment<'a>,
62}
63
64impl<'a> Comment<'a> {
65 pub fn uri(
66 uri: impl Into<CowStr<'a>>,
67 ) -> Result<RecordUri<'a, CommentRecord>, UriError> {
68 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
69 }
70}
71
72#[derive(Debug, Serialize, Deserialize)]
75pub struct CommentRecord;
76impl XrpcResp for CommentRecord {
77 const NSID: &'static str = "sh.tangled.repo.pull.comment";
78 const ENCODING: &'static str = "application/json";
79 type Output<'de> = CommentGetRecordOutput<'de>;
80 type Err<'de> = RecordError<'de>;
81}
82
83impl From<CommentGetRecordOutput<'_>> for Comment<'_> {
84 fn from(output: CommentGetRecordOutput<'_>) -> Self {
85 use jacquard_common::IntoStatic;
86 output.value.into_static()
87 }
88}
89
90impl Collection for Comment<'_> {
91 const NSID: &'static str = "sh.tangled.repo.pull.comment";
92 type Record = CommentRecord;
93}
94
95impl Collection for CommentRecord {
96 const NSID: &'static str = "sh.tangled.repo.pull.comment";
97 type Record = CommentRecord;
98}
99
100impl<'a> LexiconSchema for Comment<'a> {
101 fn nsid() -> &'static str {
102 "sh.tangled.repo.pull.comment"
103 }
104 fn def_name() -> &'static str {
105 "main"
106 }
107 fn lexicon_doc() -> LexiconDoc<'static> {
108 lexicon_doc_sh_tangled_repo_pull_comment()
109 }
110 fn validate(&self) -> Result<(), ConstraintError> {
111 Ok(())
112 }
113}
114
115pub mod comment_state {
116
117 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
118 #[allow(unused)]
119 use ::core::marker::PhantomData;
120 mod sealed {
121 pub trait Sealed {}
122 }
123 pub trait State: sealed::Sealed {
125 type Body;
126 type Pull;
127 type CreatedAt;
128 }
129 pub struct Empty(());
131 impl sealed::Sealed for Empty {}
132 impl State for Empty {
133 type Body = Unset;
134 type Pull = Unset;
135 type CreatedAt = Unset;
136 }
137 pub struct SetBody<S: State = Empty>(PhantomData<fn() -> S>);
139 impl<S: State> sealed::Sealed for SetBody<S> {}
140 impl<S: State> State for SetBody<S> {
141 type Body = Set<members::body>;
142 type Pull = S::Pull;
143 type CreatedAt = S::CreatedAt;
144 }
145 pub struct SetPull<S: State = Empty>(PhantomData<fn() -> S>);
147 impl<S: State> sealed::Sealed for SetPull<S> {}
148 impl<S: State> State for SetPull<S> {
149 type Body = S::Body;
150 type Pull = Set<members::pull>;
151 type CreatedAt = S::CreatedAt;
152 }
153 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
155 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
156 impl<S: State> State for SetCreatedAt<S> {
157 type Body = S::Body;
158 type Pull = S::Pull;
159 type CreatedAt = Set<members::created_at>;
160 }
161 #[allow(non_camel_case_types)]
163 pub mod members {
164 pub struct body(());
166 pub struct pull(());
168 pub struct created_at(());
170 }
171}
172
173pub struct CommentBuilder<'a, S: comment_state::State> {
175 _state: PhantomData<fn() -> S>,
176 _fields: (
177 Option<CowStr<'a>>,
178 Option<Datetime>,
179 Option<Vec<Did<'a>>>,
180 Option<AtUri<'a>>,
181 Option<Vec<AtUri<'a>>>,
182 ),
183 _lifetime: PhantomData<&'a ()>,
184}
185
186impl<'a> Comment<'a> {
187 pub fn new() -> CommentBuilder<'a, comment_state::Empty> {
189 CommentBuilder::new()
190 }
191}
192
193impl<'a> CommentBuilder<'a, comment_state::Empty> {
194 pub fn new() -> Self {
196 CommentBuilder {
197 _state: PhantomData,
198 _fields: (None, None, None, None, None),
199 _lifetime: PhantomData,
200 }
201 }
202}
203
204impl<'a, S> CommentBuilder<'a, S>
205where
206 S: comment_state::State,
207 S::Body: comment_state::IsUnset,
208{
209 pub fn body(
211 mut self,
212 value: impl Into<CowStr<'a>>,
213 ) -> CommentBuilder<'a, comment_state::SetBody<S>> {
214 self._fields.0 = Option::Some(value.into());
215 CommentBuilder {
216 _state: PhantomData,
217 _fields: self._fields,
218 _lifetime: PhantomData,
219 }
220 }
221}
222
223impl<'a, S> CommentBuilder<'a, S>
224where
225 S: comment_state::State,
226 S::CreatedAt: comment_state::IsUnset,
227{
228 pub fn created_at(
230 mut self,
231 value: impl Into<Datetime>,
232 ) -> CommentBuilder<'a, comment_state::SetCreatedAt<S>> {
233 self._fields.1 = Option::Some(value.into());
234 CommentBuilder {
235 _state: PhantomData,
236 _fields: self._fields,
237 _lifetime: PhantomData,
238 }
239 }
240}
241
242impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
243 pub fn mentions(mut self, value: impl Into<Option<Vec<Did<'a>>>>) -> Self {
245 self._fields.2 = value.into();
246 self
247 }
248 pub fn maybe_mentions(mut self, value: Option<Vec<Did<'a>>>) -> Self {
250 self._fields.2 = value;
251 self
252 }
253}
254
255impl<'a, S> CommentBuilder<'a, S>
256where
257 S: comment_state::State,
258 S::Pull: comment_state::IsUnset,
259{
260 pub fn pull(
262 mut self,
263 value: impl Into<AtUri<'a>>,
264 ) -> CommentBuilder<'a, comment_state::SetPull<S>> {
265 self._fields.3 = Option::Some(value.into());
266 CommentBuilder {
267 _state: PhantomData,
268 _fields: self._fields,
269 _lifetime: PhantomData,
270 }
271 }
272}
273
274impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
275 pub fn references(mut self, value: impl Into<Option<Vec<AtUri<'a>>>>) -> Self {
277 self._fields.4 = value.into();
278 self
279 }
280 pub fn maybe_references(mut self, value: Option<Vec<AtUri<'a>>>) -> Self {
282 self._fields.4 = value;
283 self
284 }
285}
286
287impl<'a, S> CommentBuilder<'a, S>
288where
289 S: comment_state::State,
290 S::Body: comment_state::IsSet,
291 S::Pull: comment_state::IsSet,
292 S::CreatedAt: comment_state::IsSet,
293{
294 pub fn build(self) -> Comment<'a> {
296 Comment {
297 body: self._fields.0.unwrap(),
298 created_at: self._fields.1.unwrap(),
299 mentions: self._fields.2,
300 pull: self._fields.3.unwrap(),
301 references: self._fields.4,
302 extra_data: Default::default(),
303 }
304 }
305 pub fn build_with_data(
307 self,
308 extra_data: BTreeMap<
309 jacquard_common::deps::smol_str::SmolStr,
310 jacquard_common::types::value::Data<'a>,
311 >,
312 ) -> Comment<'a> {
313 Comment {
314 body: self._fields.0.unwrap(),
315 created_at: self._fields.1.unwrap(),
316 mentions: self._fields.2,
317 pull: self._fields.3.unwrap(),
318 references: self._fields.4,
319 extra_data: Some(extra_data),
320 }
321 }
322}
323
324fn lexicon_doc_sh_tangled_repo_pull_comment() -> LexiconDoc<'static> {
325 #[allow(unused_imports)]
326 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
327 use jacquard_lexicon::lexicon::*;
328 use alloc::collections::BTreeMap;
329 LexiconDoc {
330 lexicon: Lexicon::Lexicon1,
331 id: CowStr::new_static("sh.tangled.repo.pull.comment"),
332 defs: {
333 let mut map = BTreeMap::new();
334 map.insert(
335 SmolStr::new_static("main"),
336 LexUserType::Record(LexRecord {
337 key: Some(CowStr::new_static("tid")),
338 record: LexRecordRecord::Object(LexObject {
339 required: Some(
340 vec![
341 SmolStr::new_static("pull"), SmolStr::new_static("body"),
342 SmolStr::new_static("createdAt")
343 ],
344 ),
345 properties: {
346 #[allow(unused_mut)]
347 let mut map = BTreeMap::new();
348 map.insert(
349 SmolStr::new_static("body"),
350 LexObjectProperty::String(LexString {
351 ..Default::default()
352 }),
353 );
354 map.insert(
355 SmolStr::new_static("createdAt"),
356 LexObjectProperty::String(LexString {
357 format: Some(LexStringFormat::Datetime),
358 ..Default::default()
359 }),
360 );
361 map.insert(
362 SmolStr::new_static("mentions"),
363 LexObjectProperty::Array(LexArray {
364 items: LexArrayItem::String(LexString {
365 format: Some(LexStringFormat::Did),
366 ..Default::default()
367 }),
368 ..Default::default()
369 }),
370 );
371 map.insert(
372 SmolStr::new_static("pull"),
373 LexObjectProperty::String(LexString {
374 format: Some(LexStringFormat::AtUri),
375 ..Default::default()
376 }),
377 );
378 map.insert(
379 SmolStr::new_static("references"),
380 LexObjectProperty::Array(LexArray {
381 items: LexArrayItem::String(LexString {
382 format: Some(LexStringFormat::AtUri),
383 ..Default::default()
384 }),
385 ..Default::default()
386 }),
387 );
388 map
389 },
390 ..Default::default()
391 }),
392 ..Default::default()
393 }),
394 );
395 map
396 },
397 ..Default::default()
398 }
399}