jacquard_api/place_stream/beta/
request.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::{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 = "place.stream.beta.request",
36 tag = "$type",
37 bound(deserialize = "S: Deserialize<'de> + BosStr")
38)]
39pub struct Request<S: BosStr = DefaultStr> {
40 pub created_at: Datetime,
42 pub feature: S,
44 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
45 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
46}
47
48#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
51#[serde(rename_all = "camelCase")]
52pub struct RequestGetRecordOutput<S: BosStr = DefaultStr> {
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub cid: Option<Cid<S>>,
55 pub uri: AtUri<S>,
56 pub value: Request<S>,
57}
58
59impl<S: BosStr> Request<S> {
60 pub fn uri(uri: S) -> Result<RecordUri<S, RequestRecord>, UriError> {
61 RecordUri::try_from_uri(AtUri::new(uri)?)
62 }
63}
64
65#[derive(Debug, Serialize, Deserialize)]
68pub struct RequestRecord;
69impl XrpcResp for RequestRecord {
70 const NSID: &'static str = "place.stream.beta.request";
71 const ENCODING: &'static str = "application/json";
72 type Output<S: BosStr> = RequestGetRecordOutput<S>;
73 type Err = RecordError;
74}
75
76impl<S: BosStr> From<RequestGetRecordOutput<S>> for Request<S> {
77 fn from(output: RequestGetRecordOutput<S>) -> Self {
78 output.value
79 }
80}
81
82impl<S: BosStr> Collection for Request<S> {
83 const NSID: &'static str = "place.stream.beta.request";
84 type Record = RequestRecord;
85}
86
87impl Collection for RequestRecord {
88 const NSID: &'static str = "place.stream.beta.request";
89 type Record = RequestRecord;
90}
91
92impl<S: BosStr> LexiconSchema for Request<S> {
93 fn nsid() -> &'static str {
94 "place.stream.beta.request"
95 }
96 fn def_name() -> &'static str {
97 "main"
98 }
99 fn lexicon_doc() -> LexiconDoc<'static> {
100 lexicon_doc_place_stream_beta_request()
101 }
102 fn validate(&self) -> Result<(), ConstraintError> {
103 Ok(())
104 }
105}
106
107pub mod request_state {
108
109 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
110 #[allow(unused)]
111 use ::core::marker::PhantomData;
112 mod sealed {
113 pub trait Sealed {}
114 }
115 pub trait State: sealed::Sealed {
117 type CreatedAt;
118 type Feature;
119 }
120 pub struct Empty(());
122 impl sealed::Sealed for Empty {}
123 impl State for Empty {
124 type CreatedAt = Unset;
125 type Feature = Unset;
126 }
127 pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
129 impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
130 impl<St: State> State for SetCreatedAt<St> {
131 type CreatedAt = Set<members::created_at>;
132 type Feature = St::Feature;
133 }
134 pub struct SetFeature<St: State = Empty>(PhantomData<fn() -> St>);
136 impl<St: State> sealed::Sealed for SetFeature<St> {}
137 impl<St: State> State for SetFeature<St> {
138 type CreatedAt = St::CreatedAt;
139 type Feature = Set<members::feature>;
140 }
141 #[allow(non_camel_case_types)]
143 pub mod members {
144 pub struct created_at(());
146 pub struct feature(());
148 }
149}
150
151pub struct RequestBuilder<St: request_state::State, S: BosStr = DefaultStr> {
153 _state: PhantomData<fn() -> St>,
154 _fields: (Option<Datetime>, Option<S>),
155 _type: PhantomData<fn() -> S>,
156}
157
158impl Request<DefaultStr> {
159 pub fn new() -> RequestBuilder<request_state::Empty, DefaultStr> {
161 RequestBuilder::new()
162 }
163}
164
165impl<S: BosStr> Request<S> {
166 pub fn builder() -> RequestBuilder<request_state::Empty, S> {
168 RequestBuilder::builder()
169 }
170}
171
172impl RequestBuilder<request_state::Empty, DefaultStr> {
173 pub fn new() -> Self {
175 RequestBuilder {
176 _state: PhantomData,
177 _fields: (None, None),
178 _type: PhantomData,
179 }
180 }
181}
182
183impl<S: BosStr> RequestBuilder<request_state::Empty, S> {
184 pub fn builder() -> Self {
186 RequestBuilder {
187 _state: PhantomData,
188 _fields: (None, None),
189 _type: PhantomData,
190 }
191 }
192}
193
194impl<St, S: BosStr> RequestBuilder<St, S>
195where
196 St: request_state::State,
197 St::CreatedAt: request_state::IsUnset,
198{
199 pub fn created_at(
201 mut self,
202 value: impl Into<Datetime>,
203 ) -> RequestBuilder<request_state::SetCreatedAt<St>, S> {
204 self._fields.0 = Option::Some(value.into());
205 RequestBuilder {
206 _state: PhantomData,
207 _fields: self._fields,
208 _type: PhantomData,
209 }
210 }
211}
212
213impl<St, S: BosStr> RequestBuilder<St, S>
214where
215 St: request_state::State,
216 St::Feature: request_state::IsUnset,
217{
218 pub fn feature(
220 mut self,
221 value: impl Into<S>,
222 ) -> RequestBuilder<request_state::SetFeature<St>, S> {
223 self._fields.1 = Option::Some(value.into());
224 RequestBuilder {
225 _state: PhantomData,
226 _fields: self._fields,
227 _type: PhantomData,
228 }
229 }
230}
231
232impl<St, S: BosStr> RequestBuilder<St, S>
233where
234 St: request_state::State,
235 St::CreatedAt: request_state::IsSet,
236 St::Feature: request_state::IsSet,
237{
238 pub fn build(self) -> Request<S> {
240 Request {
241 created_at: self._fields.0.unwrap(),
242 feature: self._fields.1.unwrap(),
243 extra_data: Default::default(),
244 }
245 }
246 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Request<S> {
248 Request {
249 created_at: self._fields.0.unwrap(),
250 feature: self._fields.1.unwrap(),
251 extra_data: Some(extra_data),
252 }
253 }
254}
255
256fn lexicon_doc_place_stream_beta_request() -> LexiconDoc<'static> {
257 #[allow(unused_imports)]
258 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
259 use jacquard_lexicon::lexicon::*;
260 use alloc::collections::BTreeMap;
261 LexiconDoc {
262 lexicon: Lexicon::Lexicon1,
263 id: CowStr::new_static("place.stream.beta.request"),
264 defs: {
265 let mut map = BTreeMap::new();
266 map.insert(
267 SmolStr::new_static("main"),
268 LexUserType::Record(LexRecord {
269 description: Some(
270 CowStr::new_static(
271 "Requests access to a named beta feature on this network. Published in the requester's own repo, so the requesting account is the record's authority — there is no separate subject field. Operators index these to surface who is waiting for access; granting access is a separate place.stream.beta.invite record issued by the operator-trusted issuer. Each (requester, feature) pair gets its own record.",
272 ),
273 ),
274 key: Some(CowStr::new_static("tid")),
275 record: LexRecordRecord::Object(LexObject {
276 required: Some(
277 vec![
278 SmolStr::new_static("feature"),
279 SmolStr::new_static("createdAt")
280 ],
281 ),
282 properties: {
283 #[allow(unused_mut)]
284 let mut map = BTreeMap::new();
285 map.insert(
286 SmolStr::new_static("createdAt"),
287 LexObjectProperty::String(LexString {
288 description: Some(
289 CowStr::new_static(
290 "Client-declared timestamp when this request was made.",
291 ),
292 ),
293 format: Some(LexStringFormat::Datetime),
294 ..Default::default()
295 }),
296 );
297 map.insert(
298 SmolStr::new_static("feature"),
299 LexObjectProperty::String(LexString {
300 description: Some(
301 CowStr::new_static(
302 "Identifier of the beta feature being requested (e.g. \"vod\"). Mirrors the `feature` field on place.stream.beta.invite.",
303 ),
304 ),
305 ..Default::default()
306 }),
307 );
308 map
309 },
310 ..Default::default()
311 }),
312 ..Default::default()
313 }),
314 );
315 map
316 },
317 ..Default::default()
318 }
319}