1#[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
29#[lexicon]
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
31#[serde(rename_all = "camelCase", rename = "network.slices.lexicon", tag = "$type")]
32pub struct Lexicon<'a> {
33 pub created_at: Datetime,
35 #[serde(borrow)]
37 pub definitions: CowStr<'a>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 #[serde(borrow)]
41 pub description: Option<CowStr<'a>>,
42 #[serde(skip_serializing_if = "Option::is_none")]
44 #[serde(default = "_default_lexicon_excluded_from_sync")]
45 pub excluded_from_sync: Option<bool>,
46 #[serde(borrow)]
48 pub nsid: CowStr<'a>,
49 #[serde(borrow)]
51 pub slice: AtUri<'a>,
52 #[serde(skip_serializing_if = "Option::is_none")]
54 pub updated_at: Option<Datetime>,
55}
56
57#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
60#[serde(rename_all = "camelCase")]
61pub struct LexiconGetRecordOutput<'a> {
62 #[serde(skip_serializing_if = "Option::is_none")]
63 #[serde(borrow)]
64 pub cid: Option<Cid<'a>>,
65 #[serde(borrow)]
66 pub uri: AtUri<'a>,
67 #[serde(borrow)]
68 pub value: Lexicon<'a>,
69}
70
71impl<'a> Lexicon<'a> {
72 pub fn uri(
73 uri: impl Into<CowStr<'a>>,
74 ) -> Result<RecordUri<'a, LexiconRecord>, UriError> {
75 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
76 }
77}
78
79#[derive(Debug, Serialize, Deserialize)]
82pub struct LexiconRecord;
83impl XrpcResp for LexiconRecord {
84 const NSID: &'static str = "network.slices.lexicon";
85 const ENCODING: &'static str = "application/json";
86 type Output<'de> = LexiconGetRecordOutput<'de>;
87 type Err<'de> = RecordError<'de>;
88}
89
90impl From<LexiconGetRecordOutput<'_>> for Lexicon<'_> {
91 fn from(output: LexiconGetRecordOutput<'_>) -> Self {
92 use jacquard_common::IntoStatic;
93 output.value.into_static()
94 }
95}
96
97impl Collection for Lexicon<'_> {
98 const NSID: &'static str = "network.slices.lexicon";
99 type Record = LexiconRecord;
100}
101
102impl Collection for LexiconRecord {
103 const NSID: &'static str = "network.slices.lexicon";
104 type Record = LexiconRecord;
105}
106
107impl<'a> LexiconSchema for Lexicon<'a> {
108 fn nsid() -> &'static str {
109 "network.slices.lexicon"
110 }
111 fn def_name() -> &'static str {
112 "main"
113 }
114 fn lexicon_doc() -> LexiconDoc<'static> {
115 lexicon_doc_network_slices_lexicon()
116 }
117 fn validate(&self) -> Result<(), ConstraintError> {
118 if let Some(ref value) = self.description {
119 #[allow(unused_comparisons)]
120 if <str>::len(value.as_ref()) > 500usize {
121 return Err(ConstraintError::MaxLength {
122 path: ValidationPath::from_field("description"),
123 max: 500usize,
124 actual: <str>::len(value.as_ref()),
125 });
126 }
127 }
128 {
129 let value = &self.nsid;
130 #[allow(unused_comparisons)]
131 if <str>::len(value.as_ref()) > 256usize {
132 return Err(ConstraintError::MaxLength {
133 path: ValidationPath::from_field("nsid"),
134 max: 256usize,
135 actual: <str>::len(value.as_ref()),
136 });
137 }
138 }
139 Ok(())
140 }
141}
142
143fn _default_lexicon_excluded_from_sync() -> Option<bool> {
144 Some(false)
145}
146
147pub mod lexicon_state {
148
149 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
150 #[allow(unused)]
151 use ::core::marker::PhantomData;
152 mod sealed {
153 pub trait Sealed {}
154 }
155 pub trait State: sealed::Sealed {
157 type CreatedAt;
158 type Slice;
159 type Definitions;
160 type Nsid;
161 }
162 pub struct Empty(());
164 impl sealed::Sealed for Empty {}
165 impl State for Empty {
166 type CreatedAt = Unset;
167 type Slice = Unset;
168 type Definitions = Unset;
169 type Nsid = Unset;
170 }
171 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
173 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
174 impl<S: State> State for SetCreatedAt<S> {
175 type CreatedAt = Set<members::created_at>;
176 type Slice = S::Slice;
177 type Definitions = S::Definitions;
178 type Nsid = S::Nsid;
179 }
180 pub struct SetSlice<S: State = Empty>(PhantomData<fn() -> S>);
182 impl<S: State> sealed::Sealed for SetSlice<S> {}
183 impl<S: State> State for SetSlice<S> {
184 type CreatedAt = S::CreatedAt;
185 type Slice = Set<members::slice>;
186 type Definitions = S::Definitions;
187 type Nsid = S::Nsid;
188 }
189 pub struct SetDefinitions<S: State = Empty>(PhantomData<fn() -> S>);
191 impl<S: State> sealed::Sealed for SetDefinitions<S> {}
192 impl<S: State> State for SetDefinitions<S> {
193 type CreatedAt = S::CreatedAt;
194 type Slice = S::Slice;
195 type Definitions = Set<members::definitions>;
196 type Nsid = S::Nsid;
197 }
198 pub struct SetNsid<S: State = Empty>(PhantomData<fn() -> S>);
200 impl<S: State> sealed::Sealed for SetNsid<S> {}
201 impl<S: State> State for SetNsid<S> {
202 type CreatedAt = S::CreatedAt;
203 type Slice = S::Slice;
204 type Definitions = S::Definitions;
205 type Nsid = Set<members::nsid>;
206 }
207 #[allow(non_camel_case_types)]
209 pub mod members {
210 pub struct created_at(());
212 pub struct slice(());
214 pub struct definitions(());
216 pub struct nsid(());
218 }
219}
220
221pub struct LexiconBuilder<'a, S: lexicon_state::State> {
223 _state: PhantomData<fn() -> S>,
224 _fields: (
225 Option<Datetime>,
226 Option<CowStr<'a>>,
227 Option<CowStr<'a>>,
228 Option<bool>,
229 Option<CowStr<'a>>,
230 Option<AtUri<'a>>,
231 Option<Datetime>,
232 ),
233 _lifetime: PhantomData<&'a ()>,
234}
235
236impl<'a> Lexicon<'a> {
237 pub fn new() -> LexiconBuilder<'a, lexicon_state::Empty> {
239 LexiconBuilder::new()
240 }
241}
242
243impl<'a> LexiconBuilder<'a, lexicon_state::Empty> {
244 pub fn new() -> Self {
246 LexiconBuilder {
247 _state: PhantomData,
248 _fields: (None, None, None, None, None, None, None),
249 _lifetime: PhantomData,
250 }
251 }
252}
253
254impl<'a, S> LexiconBuilder<'a, S>
255where
256 S: lexicon_state::State,
257 S::CreatedAt: lexicon_state::IsUnset,
258{
259 pub fn created_at(
261 mut self,
262 value: impl Into<Datetime>,
263 ) -> LexiconBuilder<'a, lexicon_state::SetCreatedAt<S>> {
264 self._fields.0 = Option::Some(value.into());
265 LexiconBuilder {
266 _state: PhantomData,
267 _fields: self._fields,
268 _lifetime: PhantomData,
269 }
270 }
271}
272
273impl<'a, S> LexiconBuilder<'a, S>
274where
275 S: lexicon_state::State,
276 S::Definitions: lexicon_state::IsUnset,
277{
278 pub fn definitions(
280 mut self,
281 value: impl Into<CowStr<'a>>,
282 ) -> LexiconBuilder<'a, lexicon_state::SetDefinitions<S>> {
283 self._fields.1 = Option::Some(value.into());
284 LexiconBuilder {
285 _state: PhantomData,
286 _fields: self._fields,
287 _lifetime: PhantomData,
288 }
289 }
290}
291
292impl<'a, S: lexicon_state::State> LexiconBuilder<'a, S> {
293 pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
295 self._fields.2 = value.into();
296 self
297 }
298 pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
300 self._fields.2 = value;
301 self
302 }
303}
304
305impl<'a, S: lexicon_state::State> LexiconBuilder<'a, S> {
306 pub fn excluded_from_sync(mut self, value: impl Into<Option<bool>>) -> Self {
308 self._fields.3 = value.into();
309 self
310 }
311 pub fn maybe_excluded_from_sync(mut self, value: Option<bool>) -> Self {
313 self._fields.3 = value;
314 self
315 }
316}
317
318impl<'a, S> LexiconBuilder<'a, S>
319where
320 S: lexicon_state::State,
321 S::Nsid: lexicon_state::IsUnset,
322{
323 pub fn nsid(
325 mut self,
326 value: impl Into<CowStr<'a>>,
327 ) -> LexiconBuilder<'a, lexicon_state::SetNsid<S>> {
328 self._fields.4 = Option::Some(value.into());
329 LexiconBuilder {
330 _state: PhantomData,
331 _fields: self._fields,
332 _lifetime: PhantomData,
333 }
334 }
335}
336
337impl<'a, S> LexiconBuilder<'a, S>
338where
339 S: lexicon_state::State,
340 S::Slice: lexicon_state::IsUnset,
341{
342 pub fn slice(
344 mut self,
345 value: impl Into<AtUri<'a>>,
346 ) -> LexiconBuilder<'a, lexicon_state::SetSlice<S>> {
347 self._fields.5 = Option::Some(value.into());
348 LexiconBuilder {
349 _state: PhantomData,
350 _fields: self._fields,
351 _lifetime: PhantomData,
352 }
353 }
354}
355
356impl<'a, S: lexicon_state::State> LexiconBuilder<'a, S> {
357 pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
359 self._fields.6 = value.into();
360 self
361 }
362 pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
364 self._fields.6 = value;
365 self
366 }
367}
368
369impl<'a, S> LexiconBuilder<'a, S>
370where
371 S: lexicon_state::State,
372 S::CreatedAt: lexicon_state::IsSet,
373 S::Slice: lexicon_state::IsSet,
374 S::Definitions: lexicon_state::IsSet,
375 S::Nsid: lexicon_state::IsSet,
376{
377 pub fn build(self) -> Lexicon<'a> {
379 Lexicon {
380 created_at: self._fields.0.unwrap(),
381 definitions: self._fields.1.unwrap(),
382 description: self._fields.2,
383 excluded_from_sync: self._fields.3.or_else(|| Some(false)),
384 nsid: self._fields.4.unwrap(),
385 slice: self._fields.5.unwrap(),
386 updated_at: self._fields.6,
387 extra_data: Default::default(),
388 }
389 }
390 pub fn build_with_data(
392 self,
393 extra_data: BTreeMap<
394 jacquard_common::deps::smol_str::SmolStr,
395 jacquard_common::types::value::Data<'a>,
396 >,
397 ) -> Lexicon<'a> {
398 Lexicon {
399 created_at: self._fields.0.unwrap(),
400 definitions: self._fields.1.unwrap(),
401 description: self._fields.2,
402 excluded_from_sync: self._fields.3.or_else(|| Some(false)),
403 nsid: self._fields.4.unwrap(),
404 slice: self._fields.5.unwrap(),
405 updated_at: self._fields.6,
406 extra_data: Some(extra_data),
407 }
408 }
409}
410
411fn lexicon_doc_network_slices_lexicon() -> LexiconDoc<'static> {
412 #[allow(unused_imports)]
413 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
414 use jacquard_lexicon::lexicon::*;
415 use alloc::collections::BTreeMap;
416 LexiconDoc {
417 lexicon: Lexicon::Lexicon1,
418 id: CowStr::new_static("network.slices.lexicon"),
419 defs: {
420 let mut map = BTreeMap::new();
421 map.insert(
422 SmolStr::new_static("main"),
423 LexUserType::Record(LexRecord {
424 key: Some(CowStr::new_static("tid")),
425 record: LexRecordRecord::Object(LexObject {
426 required: Some(
427 vec![
428 SmolStr::new_static("nsid"),
429 SmolStr::new_static("definitions"),
430 SmolStr::new_static("createdAt"),
431 SmolStr::new_static("slice")
432 ],
433 ),
434 properties: {
435 #[allow(unused_mut)]
436 let mut map = BTreeMap::new();
437 map.insert(
438 SmolStr::new_static("createdAt"),
439 LexObjectProperty::String(LexString {
440 description: Some(
441 CowStr::new_static("When the lexicon was created"),
442 ),
443 format: Some(LexStringFormat::Datetime),
444 ..Default::default()
445 }),
446 );
447 map.insert(
448 SmolStr::new_static("definitions"),
449 LexObjectProperty::String(LexString {
450 description: Some(
451 CowStr::new_static("The lexicon schema definitions as JSON"),
452 ),
453 ..Default::default()
454 }),
455 );
456 map.insert(
457 SmolStr::new_static("description"),
458 LexObjectProperty::String(LexString {
459 description: Some(
460 CowStr::new_static(
461 "Human-readable description of the lexicon",
462 ),
463 ),
464 max_length: Some(500usize),
465 ..Default::default()
466 }),
467 );
468 map.insert(
469 SmolStr::new_static("excludedFromSync"),
470 LexObjectProperty::Boolean(LexBoolean {
471 ..Default::default()
472 }),
473 );
474 map.insert(
475 SmolStr::new_static("nsid"),
476 LexObjectProperty::String(LexString {
477 description: Some(
478 CowStr::new_static("Namespaced identifier for the lexicon"),
479 ),
480 max_length: Some(256usize),
481 ..Default::default()
482 }),
483 );
484 map.insert(
485 SmolStr::new_static("slice"),
486 LexObjectProperty::String(LexString {
487 description: Some(
488 CowStr::new_static(
489 "AT-URI reference to the slice this lexicon belongs to",
490 ),
491 ),
492 format: Some(LexStringFormat::AtUri),
493 ..Default::default()
494 }),
495 );
496 map.insert(
497 SmolStr::new_static("updatedAt"),
498 LexObjectProperty::String(LexString {
499 description: Some(
500 CowStr::new_static("When the lexicon was last updated"),
501 ),
502 format: Some(LexStringFormat::Datetime),
503 ..Default::default()
504 }),
505 );
506 map
507 },
508 ..Default::default()
509 }),
510 ..Default::default()
511 }),
512 );
513 map
514 },
515 ..Default::default()
516 }
517}