jacquard_api/app_bsky/graph/
block.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::collection::{Collection, RecordError};
19use jacquard_common::types::string::{Did, AtUri, Cid, Datetime};
20use jacquard_common::types::uri::{RecordUri, UriError};
21use jacquard_common::types::value::Data;
22use jacquard_common::xrpc::XrpcResp;
23use jacquard_derive::{IntoStatic, lexicon};
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27#[allow(unused_imports)]
28use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
29use serde::{Serialize, Deserialize};
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(
34 rename_all = "camelCase",
35 rename = "app.bsky.graph.block",
36 tag = "$type",
37 bound(deserialize = "S: Deserialize<'de> + BosStr")
38)]
39pub struct Block<S: BosStr = DefaultStr> {
40 pub created_at: Datetime,
41 pub subject: Did<S>,
43 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
44 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
45}
46
47#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
50#[serde(rename_all = "camelCase")]
51pub struct BlockGetRecordOutput<S: BosStr = DefaultStr> {
52 #[serde(skip_serializing_if = "Option::is_none")]
53 pub cid: Option<Cid<S>>,
54 pub uri: AtUri<S>,
55 pub value: Block<S>,
56}
57
58impl<S: BosStr> Block<S> {
59 pub fn uri(uri: S) -> Result<RecordUri<S, BlockRecord>, UriError> {
60 RecordUri::try_from_uri(AtUri::new(uri)?)
61 }
62}
63
64#[derive(Debug, Serialize, Deserialize)]
67pub struct BlockRecord;
68impl XrpcResp for BlockRecord {
69 const NSID: &'static str = "app.bsky.graph.block";
70 const ENCODING: &'static str = "application/json";
71 type Output<S: BosStr> = BlockGetRecordOutput<S>;
72 type Err = RecordError;
73}
74
75impl<S: BosStr> From<BlockGetRecordOutput<S>> for Block<S> {
76 fn from(output: BlockGetRecordOutput<S>) -> Self {
77 output.value
78 }
79}
80
81impl<S: BosStr> Collection for Block<S> {
82 const NSID: &'static str = "app.bsky.graph.block";
83 type Record = BlockRecord;
84}
85
86impl Collection for BlockRecord {
87 const NSID: &'static str = "app.bsky.graph.block";
88 type Record = BlockRecord;
89}
90
91impl<S: BosStr> LexiconSchema for Block<S> {
92 fn nsid() -> &'static str {
93 "app.bsky.graph.block"
94 }
95 fn def_name() -> &'static str {
96 "main"
97 }
98 fn lexicon_doc() -> LexiconDoc<'static> {
99 lexicon_doc_app_bsky_graph_block()
100 }
101 fn validate(&self) -> Result<(), ConstraintError> {
102 Ok(())
103 }
104}
105
106pub mod block_state {
107
108 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
109 #[allow(unused)]
110 use ::core::marker::PhantomData;
111 mod sealed {
112 pub trait Sealed {}
113 }
114 pub trait State: sealed::Sealed {
116 type CreatedAt;
117 type Subject;
118 }
119 pub struct Empty(());
121 impl sealed::Sealed for Empty {}
122 impl State for Empty {
123 type CreatedAt = Unset;
124 type Subject = Unset;
125 }
126 pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
128 impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
129 impl<St: State> State for SetCreatedAt<St> {
130 type CreatedAt = Set<members::created_at>;
131 type Subject = St::Subject;
132 }
133 pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
135 impl<St: State> sealed::Sealed for SetSubject<St> {}
136 impl<St: State> State for SetSubject<St> {
137 type CreatedAt = St::CreatedAt;
138 type Subject = Set<members::subject>;
139 }
140 #[allow(non_camel_case_types)]
142 pub mod members {
143 pub struct created_at(());
145 pub struct subject(());
147 }
148}
149
150pub struct BlockBuilder<St: block_state::State, S: BosStr = DefaultStr> {
152 _state: PhantomData<fn() -> St>,
153 _fields: (Option<Datetime>, Option<Did<S>>),
154 _type: PhantomData<fn() -> S>,
155}
156
157impl Block<DefaultStr> {
158 pub fn new() -> BlockBuilder<block_state::Empty, DefaultStr> {
160 BlockBuilder::new()
161 }
162}
163
164impl<S: BosStr> Block<S> {
165 pub fn builder() -> BlockBuilder<block_state::Empty, S> {
167 BlockBuilder::builder()
168 }
169}
170
171impl BlockBuilder<block_state::Empty, DefaultStr> {
172 pub fn new() -> Self {
174 BlockBuilder {
175 _state: PhantomData,
176 _fields: (None, None),
177 _type: PhantomData,
178 }
179 }
180}
181
182impl<S: BosStr> BlockBuilder<block_state::Empty, S> {
183 pub fn builder() -> Self {
185 BlockBuilder {
186 _state: PhantomData,
187 _fields: (None, None),
188 _type: PhantomData,
189 }
190 }
191}
192
193impl<St, S: BosStr> BlockBuilder<St, S>
194where
195 St: block_state::State,
196 St::CreatedAt: block_state::IsUnset,
197{
198 pub fn created_at(
200 mut self,
201 value: impl Into<Datetime>,
202 ) -> BlockBuilder<block_state::SetCreatedAt<St>, S> {
203 self._fields.0 = Option::Some(value.into());
204 BlockBuilder {
205 _state: PhantomData,
206 _fields: self._fields,
207 _type: PhantomData,
208 }
209 }
210}
211
212impl<St, S: BosStr> BlockBuilder<St, S>
213where
214 St: block_state::State,
215 St::Subject: block_state::IsUnset,
216{
217 pub fn subject(
219 mut self,
220 value: impl Into<Did<S>>,
221 ) -> BlockBuilder<block_state::SetSubject<St>, S> {
222 self._fields.1 = Option::Some(value.into());
223 BlockBuilder {
224 _state: PhantomData,
225 _fields: self._fields,
226 _type: PhantomData,
227 }
228 }
229}
230
231impl<St, S: BosStr> BlockBuilder<St, S>
232where
233 St: block_state::State,
234 St::CreatedAt: block_state::IsSet,
235 St::Subject: block_state::IsSet,
236{
237 pub fn build(self) -> Block<S> {
239 Block {
240 created_at: self._fields.0.unwrap(),
241 subject: self._fields.1.unwrap(),
242 extra_data: Default::default(),
243 }
244 }
245 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Block<S> {
247 Block {
248 created_at: self._fields.0.unwrap(),
249 subject: self._fields.1.unwrap(),
250 extra_data: Some(extra_data),
251 }
252 }
253}
254
255fn lexicon_doc_app_bsky_graph_block() -> LexiconDoc<'static> {
256 #[allow(unused_imports)]
257 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
258 use jacquard_lexicon::lexicon::*;
259 use alloc::collections::BTreeMap;
260 LexiconDoc {
261 lexicon: Lexicon::Lexicon1,
262 id: CowStr::new_static("app.bsky.graph.block"),
263 defs: {
264 let mut map = BTreeMap::new();
265 map.insert(
266 SmolStr::new_static("main"),
267 LexUserType::Record(LexRecord {
268 description: Some(
269 CowStr::new_static(
270 "Record declaring a 'block' relationship against another account. NOTE: blocks are public in Bluesky; see blog posts for details.",
271 ),
272 ),
273 key: Some(CowStr::new_static("tid")),
274 record: LexRecordRecord::Object(LexObject {
275 required: Some(
276 vec![
277 SmolStr::new_static("subject"),
278 SmolStr::new_static("createdAt")
279 ],
280 ),
281 properties: {
282 #[allow(unused_mut)]
283 let mut map = BTreeMap::new();
284 map.insert(
285 SmolStr::new_static("createdAt"),
286 LexObjectProperty::String(LexString {
287 format: Some(LexStringFormat::Datetime),
288 ..Default::default()
289 }),
290 );
291 map.insert(
292 SmolStr::new_static("subject"),
293 LexObjectProperty::String(LexString {
294 description: Some(
295 CowStr::new_static("DID of the account to be blocked."),
296 ),
297 format: Some(LexStringFormat::Did),
298 ..Default::default()
299 }),
300 );
301 map
302 },
303 ..Default::default()
304 }),
305 ..Default::default()
306 }),
307 );
308 map
309 },
310 ..Default::default()
311 }
312}