1pub mod list_options;
9pub mod remove_options;
10pub mod upsert_option;
11
12
13#[allow(unused_imports)]
14use alloc::collections::BTreeMap;
15
16#[allow(unused_imports)]
17use core::marker::PhantomData;
18use jacquard_common::CowStr;
19
20#[allow(unused_imports)]
21use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
22use jacquard_common::types::string::{Did, Nsid, Datetime};
23use jacquard_common::types::value::Data;
24use jacquard_derive::{IntoStatic, lexicon};
25use jacquard_lexicon::lexicon::LexiconDoc;
26use jacquard_lexicon::schema::LexiconSchema;
27
28#[allow(unused_imports)]
29use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
30use serde::{Serialize, Deserialize};
31
32#[lexicon]
33#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
34#[serde(rename_all = "camelCase")]
35pub struct DefsOption<'a> {
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub created_at: Option<Datetime>,
38 #[serde(borrow)]
39 pub created_by: Did<'a>,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub description: Option<CowStr<'a>>,
43 #[serde(borrow)]
44 pub did: Did<'a>,
45 #[serde(borrow)]
46 pub key: Nsid<'a>,
47 #[serde(borrow)]
48 pub last_updated_by: Did<'a>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 #[serde(borrow)]
51 pub manager_role: Option<DefsOptionManagerRole<'a>>,
52 #[serde(borrow)]
53 pub scope: DefsOptionScope<'a>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub updated_at: Option<Datetime>,
56 #[serde(borrow)]
57 pub value: Data<'a>,
58}
59
60
61#[derive(Debug, Clone, PartialEq, Eq, Hash)]
62pub enum DefsOptionManagerRole<'a> {
63 RoleModerator,
64 RoleTriage,
65 RoleAdmin,
66 RoleVerifier,
67 Other(CowStr<'a>),
68}
69
70impl<'a> DefsOptionManagerRole<'a> {
71 pub fn as_str(&self) -> &str {
72 match self {
73 Self::RoleModerator => "tools.ozone.team.defs#roleModerator",
74 Self::RoleTriage => "tools.ozone.team.defs#roleTriage",
75 Self::RoleAdmin => "tools.ozone.team.defs#roleAdmin",
76 Self::RoleVerifier => "tools.ozone.team.defs#roleVerifier",
77 Self::Other(s) => s.as_ref(),
78 }
79 }
80}
81
82impl<'a> From<&'a str> for DefsOptionManagerRole<'a> {
83 fn from(s: &'a str) -> Self {
84 match s {
85 "tools.ozone.team.defs#roleModerator" => Self::RoleModerator,
86 "tools.ozone.team.defs#roleTriage" => Self::RoleTriage,
87 "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin,
88 "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier,
89 _ => Self::Other(CowStr::from(s)),
90 }
91 }
92}
93
94impl<'a> From<String> for DefsOptionManagerRole<'a> {
95 fn from(s: String) -> Self {
96 match s.as_str() {
97 "tools.ozone.team.defs#roleModerator" => Self::RoleModerator,
98 "tools.ozone.team.defs#roleTriage" => Self::RoleTriage,
99 "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin,
100 "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier,
101 _ => Self::Other(CowStr::from(s)),
102 }
103 }
104}
105
106impl<'a> core::fmt::Display for DefsOptionManagerRole<'a> {
107 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
108 write!(f, "{}", self.as_str())
109 }
110}
111
112impl<'a> AsRef<str> for DefsOptionManagerRole<'a> {
113 fn as_ref(&self) -> &str {
114 self.as_str()
115 }
116}
117
118impl<'a> serde::Serialize for DefsOptionManagerRole<'a> {
119 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
120 where
121 S: serde::Serializer,
122 {
123 serializer.serialize_str(self.as_str())
124 }
125}
126
127impl<'de, 'a> serde::Deserialize<'de> for DefsOptionManagerRole<'a>
128where
129 'de: 'a,
130{
131 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
132 where
133 D: serde::Deserializer<'de>,
134 {
135 let s = <&'de str>::deserialize(deserializer)?;
136 Ok(Self::from(s))
137 }
138}
139
140impl<'a> Default for DefsOptionManagerRole<'a> {
141 fn default() -> Self {
142 Self::Other(Default::default())
143 }
144}
145
146impl jacquard_common::IntoStatic for DefsOptionManagerRole<'_> {
147 type Output = DefsOptionManagerRole<'static>;
148 fn into_static(self) -> Self::Output {
149 match self {
150 DefsOptionManagerRole::RoleModerator => DefsOptionManagerRole::RoleModerator,
151 DefsOptionManagerRole::RoleTriage => DefsOptionManagerRole::RoleTriage,
152 DefsOptionManagerRole::RoleAdmin => DefsOptionManagerRole::RoleAdmin,
153 DefsOptionManagerRole::RoleVerifier => DefsOptionManagerRole::RoleVerifier,
154 DefsOptionManagerRole::Other(v) => {
155 DefsOptionManagerRole::Other(v.into_static())
156 }
157 }
158 }
159}
160
161
162#[derive(Debug, Clone, PartialEq, Eq, Hash)]
163pub enum DefsOptionScope<'a> {
164 Instance,
165 Personal,
166 Other(CowStr<'a>),
167}
168
169impl<'a> DefsOptionScope<'a> {
170 pub fn as_str(&self) -> &str {
171 match self {
172 Self::Instance => "instance",
173 Self::Personal => "personal",
174 Self::Other(s) => s.as_ref(),
175 }
176 }
177}
178
179impl<'a> From<&'a str> for DefsOptionScope<'a> {
180 fn from(s: &'a str) -> Self {
181 match s {
182 "instance" => Self::Instance,
183 "personal" => Self::Personal,
184 _ => Self::Other(CowStr::from(s)),
185 }
186 }
187}
188
189impl<'a> From<String> for DefsOptionScope<'a> {
190 fn from(s: String) -> Self {
191 match s.as_str() {
192 "instance" => Self::Instance,
193 "personal" => Self::Personal,
194 _ => Self::Other(CowStr::from(s)),
195 }
196 }
197}
198
199impl<'a> core::fmt::Display for DefsOptionScope<'a> {
200 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
201 write!(f, "{}", self.as_str())
202 }
203}
204
205impl<'a> AsRef<str> for DefsOptionScope<'a> {
206 fn as_ref(&self) -> &str {
207 self.as_str()
208 }
209}
210
211impl<'a> serde::Serialize for DefsOptionScope<'a> {
212 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
213 where
214 S: serde::Serializer,
215 {
216 serializer.serialize_str(self.as_str())
217 }
218}
219
220impl<'de, 'a> serde::Deserialize<'de> for DefsOptionScope<'a>
221where
222 'de: 'a,
223{
224 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
225 where
226 D: serde::Deserializer<'de>,
227 {
228 let s = <&'de str>::deserialize(deserializer)?;
229 Ok(Self::from(s))
230 }
231}
232
233impl<'a> Default for DefsOptionScope<'a> {
234 fn default() -> Self {
235 Self::Other(Default::default())
236 }
237}
238
239impl jacquard_common::IntoStatic for DefsOptionScope<'_> {
240 type Output = DefsOptionScope<'static>;
241 fn into_static(self) -> Self::Output {
242 match self {
243 DefsOptionScope::Instance => DefsOptionScope::Instance,
244 DefsOptionScope::Personal => DefsOptionScope::Personal,
245 DefsOptionScope::Other(v) => DefsOptionScope::Other(v.into_static()),
246 }
247 }
248}
249
250impl<'a> LexiconSchema for DefsOption<'a> {
251 fn nsid() -> &'static str {
252 "tools.ozone.setting.defs"
253 }
254 fn def_name() -> &'static str {
255 "option"
256 }
257 fn lexicon_doc() -> LexiconDoc<'static> {
258 lexicon_doc_tools_ozone_setting_defs()
259 }
260 fn validate(&self) -> Result<(), ConstraintError> {
261 if let Some(ref value) = self.description {
262 #[allow(unused_comparisons)]
263 if <str>::len(value.as_ref()) > 10240usize {
264 return Err(ConstraintError::MaxLength {
265 path: ValidationPath::from_field("description"),
266 max: 10240usize,
267 actual: <str>::len(value.as_ref()),
268 });
269 }
270 }
271 if let Some(ref value) = self.description {
272 {
273 let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
274 if count > 1024usize {
275 return Err(ConstraintError::MaxGraphemes {
276 path: ValidationPath::from_field("description"),
277 max: 1024usize,
278 actual: count,
279 });
280 }
281 }
282 }
283 Ok(())
284 }
285}
286
287pub mod defs_option_state {
288
289 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
290 #[allow(unused)]
291 use ::core::marker::PhantomData;
292 mod sealed {
293 pub trait Sealed {}
294 }
295 pub trait State: sealed::Sealed {
297 type Scope;
298 type Key;
299 type LastUpdatedBy;
300 type Did;
301 type CreatedBy;
302 type Value;
303 }
304 pub struct Empty(());
306 impl sealed::Sealed for Empty {}
307 impl State for Empty {
308 type Scope = Unset;
309 type Key = Unset;
310 type LastUpdatedBy = Unset;
311 type Did = Unset;
312 type CreatedBy = Unset;
313 type Value = Unset;
314 }
315 pub struct SetScope<S: State = Empty>(PhantomData<fn() -> S>);
317 impl<S: State> sealed::Sealed for SetScope<S> {}
318 impl<S: State> State for SetScope<S> {
319 type Scope = Set<members::scope>;
320 type Key = S::Key;
321 type LastUpdatedBy = S::LastUpdatedBy;
322 type Did = S::Did;
323 type CreatedBy = S::CreatedBy;
324 type Value = S::Value;
325 }
326 pub struct SetKey<S: State = Empty>(PhantomData<fn() -> S>);
328 impl<S: State> sealed::Sealed for SetKey<S> {}
329 impl<S: State> State for SetKey<S> {
330 type Scope = S::Scope;
331 type Key = Set<members::key>;
332 type LastUpdatedBy = S::LastUpdatedBy;
333 type Did = S::Did;
334 type CreatedBy = S::CreatedBy;
335 type Value = S::Value;
336 }
337 pub struct SetLastUpdatedBy<S: State = Empty>(PhantomData<fn() -> S>);
339 impl<S: State> sealed::Sealed for SetLastUpdatedBy<S> {}
340 impl<S: State> State for SetLastUpdatedBy<S> {
341 type Scope = S::Scope;
342 type Key = S::Key;
343 type LastUpdatedBy = Set<members::last_updated_by>;
344 type Did = S::Did;
345 type CreatedBy = S::CreatedBy;
346 type Value = S::Value;
347 }
348 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
350 impl<S: State> sealed::Sealed for SetDid<S> {}
351 impl<S: State> State for SetDid<S> {
352 type Scope = S::Scope;
353 type Key = S::Key;
354 type LastUpdatedBy = S::LastUpdatedBy;
355 type Did = Set<members::did>;
356 type CreatedBy = S::CreatedBy;
357 type Value = S::Value;
358 }
359 pub struct SetCreatedBy<S: State = Empty>(PhantomData<fn() -> S>);
361 impl<S: State> sealed::Sealed for SetCreatedBy<S> {}
362 impl<S: State> State for SetCreatedBy<S> {
363 type Scope = S::Scope;
364 type Key = S::Key;
365 type LastUpdatedBy = S::LastUpdatedBy;
366 type Did = S::Did;
367 type CreatedBy = Set<members::created_by>;
368 type Value = S::Value;
369 }
370 pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>);
372 impl<S: State> sealed::Sealed for SetValue<S> {}
373 impl<S: State> State for SetValue<S> {
374 type Scope = S::Scope;
375 type Key = S::Key;
376 type LastUpdatedBy = S::LastUpdatedBy;
377 type Did = S::Did;
378 type CreatedBy = S::CreatedBy;
379 type Value = Set<members::value>;
380 }
381 #[allow(non_camel_case_types)]
383 pub mod members {
384 pub struct scope(());
386 pub struct key(());
388 pub struct last_updated_by(());
390 pub struct did(());
392 pub struct created_by(());
394 pub struct value(());
396 }
397}
398
399pub struct DefsOptionBuilder<'a, S: defs_option_state::State> {
401 _state: PhantomData<fn() -> S>,
402 _fields: (
403 Option<Datetime>,
404 Option<Did<'a>>,
405 Option<CowStr<'a>>,
406 Option<Did<'a>>,
407 Option<Nsid<'a>>,
408 Option<Did<'a>>,
409 Option<DefsOptionManagerRole<'a>>,
410 Option<DefsOptionScope<'a>>,
411 Option<Datetime>,
412 Option<Data<'a>>,
413 ),
414 _lifetime: PhantomData<&'a ()>,
415}
416
417impl<'a> DefsOption<'a> {
418 pub fn new() -> DefsOptionBuilder<'a, defs_option_state::Empty> {
420 DefsOptionBuilder::new()
421 }
422}
423
424impl<'a> DefsOptionBuilder<'a, defs_option_state::Empty> {
425 pub fn new() -> Self {
427 DefsOptionBuilder {
428 _state: PhantomData,
429 _fields: (None, None, None, None, None, None, None, None, None, None),
430 _lifetime: PhantomData,
431 }
432 }
433}
434
435impl<'a, S: defs_option_state::State> DefsOptionBuilder<'a, S> {
436 pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
438 self._fields.0 = value.into();
439 self
440 }
441 pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
443 self._fields.0 = value;
444 self
445 }
446}
447
448impl<'a, S> DefsOptionBuilder<'a, S>
449where
450 S: defs_option_state::State,
451 S::CreatedBy: defs_option_state::IsUnset,
452{
453 pub fn created_by(
455 mut self,
456 value: impl Into<Did<'a>>,
457 ) -> DefsOptionBuilder<'a, defs_option_state::SetCreatedBy<S>> {
458 self._fields.1 = Option::Some(value.into());
459 DefsOptionBuilder {
460 _state: PhantomData,
461 _fields: self._fields,
462 _lifetime: PhantomData,
463 }
464 }
465}
466
467impl<'a, S: defs_option_state::State> DefsOptionBuilder<'a, S> {
468 pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
470 self._fields.2 = value.into();
471 self
472 }
473 pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
475 self._fields.2 = value;
476 self
477 }
478}
479
480impl<'a, S> DefsOptionBuilder<'a, S>
481where
482 S: defs_option_state::State,
483 S::Did: defs_option_state::IsUnset,
484{
485 pub fn did(
487 mut self,
488 value: impl Into<Did<'a>>,
489 ) -> DefsOptionBuilder<'a, defs_option_state::SetDid<S>> {
490 self._fields.3 = Option::Some(value.into());
491 DefsOptionBuilder {
492 _state: PhantomData,
493 _fields: self._fields,
494 _lifetime: PhantomData,
495 }
496 }
497}
498
499impl<'a, S> DefsOptionBuilder<'a, S>
500where
501 S: defs_option_state::State,
502 S::Key: defs_option_state::IsUnset,
503{
504 pub fn key(
506 mut self,
507 value: impl Into<Nsid<'a>>,
508 ) -> DefsOptionBuilder<'a, defs_option_state::SetKey<S>> {
509 self._fields.4 = Option::Some(value.into());
510 DefsOptionBuilder {
511 _state: PhantomData,
512 _fields: self._fields,
513 _lifetime: PhantomData,
514 }
515 }
516}
517
518impl<'a, S> DefsOptionBuilder<'a, S>
519where
520 S: defs_option_state::State,
521 S::LastUpdatedBy: defs_option_state::IsUnset,
522{
523 pub fn last_updated_by(
525 mut self,
526 value: impl Into<Did<'a>>,
527 ) -> DefsOptionBuilder<'a, defs_option_state::SetLastUpdatedBy<S>> {
528 self._fields.5 = Option::Some(value.into());
529 DefsOptionBuilder {
530 _state: PhantomData,
531 _fields: self._fields,
532 _lifetime: PhantomData,
533 }
534 }
535}
536
537impl<'a, S: defs_option_state::State> DefsOptionBuilder<'a, S> {
538 pub fn manager_role(
540 mut self,
541 value: impl Into<Option<DefsOptionManagerRole<'a>>>,
542 ) -> Self {
543 self._fields.6 = value.into();
544 self
545 }
546 pub fn maybe_manager_role(
548 mut self,
549 value: Option<DefsOptionManagerRole<'a>>,
550 ) -> Self {
551 self._fields.6 = value;
552 self
553 }
554}
555
556impl<'a, S> DefsOptionBuilder<'a, S>
557where
558 S: defs_option_state::State,
559 S::Scope: defs_option_state::IsUnset,
560{
561 pub fn scope(
563 mut self,
564 value: impl Into<DefsOptionScope<'a>>,
565 ) -> DefsOptionBuilder<'a, defs_option_state::SetScope<S>> {
566 self._fields.7 = Option::Some(value.into());
567 DefsOptionBuilder {
568 _state: PhantomData,
569 _fields: self._fields,
570 _lifetime: PhantomData,
571 }
572 }
573}
574
575impl<'a, S: defs_option_state::State> DefsOptionBuilder<'a, S> {
576 pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
578 self._fields.8 = value.into();
579 self
580 }
581 pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
583 self._fields.8 = value;
584 self
585 }
586}
587
588impl<'a, S> DefsOptionBuilder<'a, S>
589where
590 S: defs_option_state::State,
591 S::Value: defs_option_state::IsUnset,
592{
593 pub fn value(
595 mut self,
596 value: impl Into<Data<'a>>,
597 ) -> DefsOptionBuilder<'a, defs_option_state::SetValue<S>> {
598 self._fields.9 = Option::Some(value.into());
599 DefsOptionBuilder {
600 _state: PhantomData,
601 _fields: self._fields,
602 _lifetime: PhantomData,
603 }
604 }
605}
606
607impl<'a, S> DefsOptionBuilder<'a, S>
608where
609 S: defs_option_state::State,
610 S::Scope: defs_option_state::IsSet,
611 S::Key: defs_option_state::IsSet,
612 S::LastUpdatedBy: defs_option_state::IsSet,
613 S::Did: defs_option_state::IsSet,
614 S::CreatedBy: defs_option_state::IsSet,
615 S::Value: defs_option_state::IsSet,
616{
617 pub fn build(self) -> DefsOption<'a> {
619 DefsOption {
620 created_at: self._fields.0,
621 created_by: self._fields.1.unwrap(),
622 description: self._fields.2,
623 did: self._fields.3.unwrap(),
624 key: self._fields.4.unwrap(),
625 last_updated_by: self._fields.5.unwrap(),
626 manager_role: self._fields.6,
627 scope: self._fields.7.unwrap(),
628 updated_at: self._fields.8,
629 value: self._fields.9.unwrap(),
630 extra_data: Default::default(),
631 }
632 }
633 pub fn build_with_data(
635 self,
636 extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
637 ) -> DefsOption<'a> {
638 DefsOption {
639 created_at: self._fields.0,
640 created_by: self._fields.1.unwrap(),
641 description: self._fields.2,
642 did: self._fields.3.unwrap(),
643 key: self._fields.4.unwrap(),
644 last_updated_by: self._fields.5.unwrap(),
645 manager_role: self._fields.6,
646 scope: self._fields.7.unwrap(),
647 updated_at: self._fields.8,
648 value: self._fields.9.unwrap(),
649 extra_data: Some(extra_data),
650 }
651 }
652}
653
654fn lexicon_doc_tools_ozone_setting_defs() -> LexiconDoc<'static> {
655 #[allow(unused_imports)]
656 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
657 use jacquard_lexicon::lexicon::*;
658 use alloc::collections::BTreeMap;
659 LexiconDoc {
660 lexicon: Lexicon::Lexicon1,
661 id: CowStr::new_static("tools.ozone.setting.defs"),
662 defs: {
663 let mut map = BTreeMap::new();
664 map.insert(
665 SmolStr::new_static("option"),
666 LexUserType::Object(LexObject {
667 required: Some(
668 vec![
669 SmolStr::new_static("key"), SmolStr::new_static("value"),
670 SmolStr::new_static("did"), SmolStr::new_static("scope"),
671 SmolStr::new_static("createdBy"),
672 SmolStr::new_static("lastUpdatedBy")
673 ],
674 ),
675 properties: {
676 #[allow(unused_mut)]
677 let mut map = BTreeMap::new();
678 map.insert(
679 SmolStr::new_static("createdAt"),
680 LexObjectProperty::String(LexString {
681 format: Some(LexStringFormat::Datetime),
682 ..Default::default()
683 }),
684 );
685 map.insert(
686 SmolStr::new_static("createdBy"),
687 LexObjectProperty::String(LexString {
688 format: Some(LexStringFormat::Did),
689 ..Default::default()
690 }),
691 );
692 map.insert(
693 SmolStr::new_static("description"),
694 LexObjectProperty::String(LexString {
695 max_length: Some(10240usize),
696 max_graphemes: Some(1024usize),
697 ..Default::default()
698 }),
699 );
700 map.insert(
701 SmolStr::new_static("did"),
702 LexObjectProperty::String(LexString {
703 format: Some(LexStringFormat::Did),
704 ..Default::default()
705 }),
706 );
707 map.insert(
708 SmolStr::new_static("key"),
709 LexObjectProperty::String(LexString {
710 format: Some(LexStringFormat::Nsid),
711 ..Default::default()
712 }),
713 );
714 map.insert(
715 SmolStr::new_static("lastUpdatedBy"),
716 LexObjectProperty::String(LexString {
717 format: Some(LexStringFormat::Did),
718 ..Default::default()
719 }),
720 );
721 map.insert(
722 SmolStr::new_static("managerRole"),
723 LexObjectProperty::String(LexString { ..Default::default() }),
724 );
725 map.insert(
726 SmolStr::new_static("scope"),
727 LexObjectProperty::String(LexString { ..Default::default() }),
728 );
729 map.insert(
730 SmolStr::new_static("updatedAt"),
731 LexObjectProperty::String(LexString {
732 format: Some(LexStringFormat::Datetime),
733 ..Default::default()
734 }),
735 );
736 map.insert(
737 SmolStr::new_static("value"),
738 LexObjectProperty::Unknown(LexUnknown {
739 ..Default::default()
740 }),
741 );
742 map
743 },
744 ..Default::default()
745 }),
746 );
747 map
748 },
749 ..Default::default()
750 }
751}