1pub mod add_rule;
9pub mod query_events;
10pub mod query_rules;
11pub mod remove_rule;
12pub mod update_rule;
13
14
15#[allow(unused_imports)]
16use alloc::collections::BTreeMap;
17
18#[allow(unused_imports)]
19use core::marker::PhantomData;
20use jacquard_common::CowStr;
21
22#[allow(unused_imports)]
23use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
24use jacquard_common::types::string::{Did, Datetime};
25use jacquard_derive::{IntoStatic, lexicon};
26use jacquard_lexicon::lexicon::LexiconDoc;
27use jacquard_lexicon::schema::LexiconSchema;
28
29#[allow(unused_imports)]
30use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
31use serde::{Serialize, Deserialize};
32use crate::tools_ozone::safelink;
33
34#[derive(Debug, Clone, PartialEq, Eq, Hash)]
35pub enum ActionType<'a> {
36 Block,
37 Warn,
38 Whitelist,
39 Other(CowStr<'a>),
40}
41
42impl<'a> ActionType<'a> {
43 pub fn as_str(&self) -> &str {
44 match self {
45 Self::Block => "block",
46 Self::Warn => "warn",
47 Self::Whitelist => "whitelist",
48 Self::Other(s) => s.as_ref(),
49 }
50 }
51}
52
53impl<'a> From<&'a str> for ActionType<'a> {
54 fn from(s: &'a str) -> Self {
55 match s {
56 "block" => Self::Block,
57 "warn" => Self::Warn,
58 "whitelist" => Self::Whitelist,
59 _ => Self::Other(CowStr::from(s)),
60 }
61 }
62}
63
64impl<'a> From<String> for ActionType<'a> {
65 fn from(s: String) -> Self {
66 match s.as_str() {
67 "block" => Self::Block,
68 "warn" => Self::Warn,
69 "whitelist" => Self::Whitelist,
70 _ => Self::Other(CowStr::from(s)),
71 }
72 }
73}
74
75impl<'a> AsRef<str> for ActionType<'a> {
76 fn as_ref(&self) -> &str {
77 self.as_str()
78 }
79}
80
81impl<'a> core::fmt::Display for ActionType<'a> {
82 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83 write!(f, "{}", self.as_str())
84 }
85}
86
87impl<'a> serde::Serialize for ActionType<'a> {
88 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
89 where
90 S: serde::Serializer,
91 {
92 serializer.serialize_str(self.as_str())
93 }
94}
95
96impl<'de, 'a> serde::Deserialize<'de> for ActionType<'a>
97where
98 'de: 'a,
99{
100 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
101 where
102 D: serde::Deserializer<'de>,
103 {
104 let s = <&'de str>::deserialize(deserializer)?;
105 Ok(Self::from(s))
106 }
107}
108
109impl jacquard_common::IntoStatic for ActionType<'_> {
110 type Output = ActionType<'static>;
111 fn into_static(self) -> Self::Output {
112 match self {
113 ActionType::Block => ActionType::Block,
114 ActionType::Warn => ActionType::Warn,
115 ActionType::Whitelist => ActionType::Whitelist,
116 ActionType::Other(v) => ActionType::Other(v.into_static()),
117 }
118 }
119}
120
121#[lexicon]
124#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
125#[serde(rename_all = "camelCase")]
126pub struct Event<'a> {
127 #[serde(borrow)]
128 pub action: safelink::ActionType<'a>,
129 #[serde(skip_serializing_if = "Option::is_none")]
131 #[serde(borrow)]
132 pub comment: Option<CowStr<'a>>,
133 pub created_at: Datetime,
134 #[serde(borrow)]
136 pub created_by: Did<'a>,
137 #[serde(borrow)]
138 pub event_type: safelink::EventType<'a>,
139 pub id: i64,
141 #[serde(borrow)]
142 pub pattern: safelink::PatternType<'a>,
143 #[serde(borrow)]
144 pub reason: safelink::ReasonType<'a>,
145 #[serde(borrow)]
147 pub url: CowStr<'a>,
148}
149
150
151#[derive(Debug, Clone, PartialEq, Eq, Hash)]
152pub enum EventType<'a> {
153 AddRule,
154 UpdateRule,
155 RemoveRule,
156 Other(CowStr<'a>),
157}
158
159impl<'a> EventType<'a> {
160 pub fn as_str(&self) -> &str {
161 match self {
162 Self::AddRule => "addRule",
163 Self::UpdateRule => "updateRule",
164 Self::RemoveRule => "removeRule",
165 Self::Other(s) => s.as_ref(),
166 }
167 }
168}
169
170impl<'a> From<&'a str> for EventType<'a> {
171 fn from(s: &'a str) -> Self {
172 match s {
173 "addRule" => Self::AddRule,
174 "updateRule" => Self::UpdateRule,
175 "removeRule" => Self::RemoveRule,
176 _ => Self::Other(CowStr::from(s)),
177 }
178 }
179}
180
181impl<'a> From<String> for EventType<'a> {
182 fn from(s: String) -> Self {
183 match s.as_str() {
184 "addRule" => Self::AddRule,
185 "updateRule" => Self::UpdateRule,
186 "removeRule" => Self::RemoveRule,
187 _ => Self::Other(CowStr::from(s)),
188 }
189 }
190}
191
192impl<'a> AsRef<str> for EventType<'a> {
193 fn as_ref(&self) -> &str {
194 self.as_str()
195 }
196}
197
198impl<'a> core::fmt::Display for EventType<'a> {
199 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
200 write!(f, "{}", self.as_str())
201 }
202}
203
204impl<'a> serde::Serialize for EventType<'a> {
205 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
206 where
207 S: serde::Serializer,
208 {
209 serializer.serialize_str(self.as_str())
210 }
211}
212
213impl<'de, 'a> serde::Deserialize<'de> for EventType<'a>
214where
215 'de: 'a,
216{
217 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
218 where
219 D: serde::Deserializer<'de>,
220 {
221 let s = <&'de str>::deserialize(deserializer)?;
222 Ok(Self::from(s))
223 }
224}
225
226impl jacquard_common::IntoStatic for EventType<'_> {
227 type Output = EventType<'static>;
228 fn into_static(self) -> Self::Output {
229 match self {
230 EventType::AddRule => EventType::AddRule,
231 EventType::UpdateRule => EventType::UpdateRule,
232 EventType::RemoveRule => EventType::RemoveRule,
233 EventType::Other(v) => EventType::Other(v.into_static()),
234 }
235 }
236}
237
238
239#[derive(Debug, Clone, PartialEq, Eq, Hash)]
240pub enum PatternType<'a> {
241 Domain,
242 Url,
243 Other(CowStr<'a>),
244}
245
246impl<'a> PatternType<'a> {
247 pub fn as_str(&self) -> &str {
248 match self {
249 Self::Domain => "domain",
250 Self::Url => "url",
251 Self::Other(s) => s.as_ref(),
252 }
253 }
254}
255
256impl<'a> From<&'a str> for PatternType<'a> {
257 fn from(s: &'a str) -> Self {
258 match s {
259 "domain" => Self::Domain,
260 "url" => Self::Url,
261 _ => Self::Other(CowStr::from(s)),
262 }
263 }
264}
265
266impl<'a> From<String> for PatternType<'a> {
267 fn from(s: String) -> Self {
268 match s.as_str() {
269 "domain" => Self::Domain,
270 "url" => Self::Url,
271 _ => Self::Other(CowStr::from(s)),
272 }
273 }
274}
275
276impl<'a> AsRef<str> for PatternType<'a> {
277 fn as_ref(&self) -> &str {
278 self.as_str()
279 }
280}
281
282impl<'a> core::fmt::Display for PatternType<'a> {
283 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
284 write!(f, "{}", self.as_str())
285 }
286}
287
288impl<'a> serde::Serialize for PatternType<'a> {
289 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
290 where
291 S: serde::Serializer,
292 {
293 serializer.serialize_str(self.as_str())
294 }
295}
296
297impl<'de, 'a> serde::Deserialize<'de> for PatternType<'a>
298where
299 'de: 'a,
300{
301 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
302 where
303 D: serde::Deserializer<'de>,
304 {
305 let s = <&'de str>::deserialize(deserializer)?;
306 Ok(Self::from(s))
307 }
308}
309
310impl jacquard_common::IntoStatic for PatternType<'_> {
311 type Output = PatternType<'static>;
312 fn into_static(self) -> Self::Output {
313 match self {
314 PatternType::Domain => PatternType::Domain,
315 PatternType::Url => PatternType::Url,
316 PatternType::Other(v) => PatternType::Other(v.into_static()),
317 }
318 }
319}
320
321
322#[derive(Debug, Clone, PartialEq, Eq, Hash)]
323pub enum ReasonType<'a> {
324 Csam,
325 Spam,
326 Phishing,
327 None,
328 Other(CowStr<'a>),
329}
330
331impl<'a> ReasonType<'a> {
332 pub fn as_str(&self) -> &str {
333 match self {
334 Self::Csam => "csam",
335 Self::Spam => "spam",
336 Self::Phishing => "phishing",
337 Self::None => "none",
338 Self::Other(s) => s.as_ref(),
339 }
340 }
341}
342
343impl<'a> From<&'a str> for ReasonType<'a> {
344 fn from(s: &'a str) -> Self {
345 match s {
346 "csam" => Self::Csam,
347 "spam" => Self::Spam,
348 "phishing" => Self::Phishing,
349 "none" => Self::None,
350 _ => Self::Other(CowStr::from(s)),
351 }
352 }
353}
354
355impl<'a> From<String> for ReasonType<'a> {
356 fn from(s: String) -> Self {
357 match s.as_str() {
358 "csam" => Self::Csam,
359 "spam" => Self::Spam,
360 "phishing" => Self::Phishing,
361 "none" => Self::None,
362 _ => Self::Other(CowStr::from(s)),
363 }
364 }
365}
366
367impl<'a> AsRef<str> for ReasonType<'a> {
368 fn as_ref(&self) -> &str {
369 self.as_str()
370 }
371}
372
373impl<'a> core::fmt::Display for ReasonType<'a> {
374 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
375 write!(f, "{}", self.as_str())
376 }
377}
378
379impl<'a> serde::Serialize for ReasonType<'a> {
380 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
381 where
382 S: serde::Serializer,
383 {
384 serializer.serialize_str(self.as_str())
385 }
386}
387
388impl<'de, 'a> serde::Deserialize<'de> for ReasonType<'a>
389where
390 'de: 'a,
391{
392 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
393 where
394 D: serde::Deserializer<'de>,
395 {
396 let s = <&'de str>::deserialize(deserializer)?;
397 Ok(Self::from(s))
398 }
399}
400
401impl jacquard_common::IntoStatic for ReasonType<'_> {
402 type Output = ReasonType<'static>;
403 fn into_static(self) -> Self::Output {
404 match self {
405 ReasonType::Csam => ReasonType::Csam,
406 ReasonType::Spam => ReasonType::Spam,
407 ReasonType::Phishing => ReasonType::Phishing,
408 ReasonType::None => ReasonType::None,
409 ReasonType::Other(v) => ReasonType::Other(v.into_static()),
410 }
411 }
412}
413
414#[lexicon]
417#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
418#[serde(rename_all = "camelCase")]
419pub struct UrlRule<'a> {
420 #[serde(borrow)]
421 pub action: safelink::ActionType<'a>,
422 #[serde(skip_serializing_if = "Option::is_none")]
424 #[serde(borrow)]
425 pub comment: Option<CowStr<'a>>,
426 pub created_at: Datetime,
428 #[serde(borrow)]
430 pub created_by: Did<'a>,
431 #[serde(borrow)]
432 pub pattern: safelink::PatternType<'a>,
433 #[serde(borrow)]
434 pub reason: safelink::ReasonType<'a>,
435 pub updated_at: Datetime,
437 #[serde(borrow)]
439 pub url: CowStr<'a>,
440}
441
442impl<'a> LexiconSchema for Event<'a> {
443 fn nsid() -> &'static str {
444 "tools.ozone.safelink.defs"
445 }
446 fn def_name() -> &'static str {
447 "event"
448 }
449 fn lexicon_doc() -> LexiconDoc<'static> {
450 lexicon_doc_tools_ozone_safelink_defs()
451 }
452 fn validate(&self) -> Result<(), ConstraintError> {
453 Ok(())
454 }
455}
456
457impl<'a> LexiconSchema for UrlRule<'a> {
458 fn nsid() -> &'static str {
459 "tools.ozone.safelink.defs"
460 }
461 fn def_name() -> &'static str {
462 "urlRule"
463 }
464 fn lexicon_doc() -> LexiconDoc<'static> {
465 lexicon_doc_tools_ozone_safelink_defs()
466 }
467 fn validate(&self) -> Result<(), ConstraintError> {
468 Ok(())
469 }
470}
471
472pub mod event_state {
473
474 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
475 #[allow(unused)]
476 use ::core::marker::PhantomData;
477 mod sealed {
478 pub trait Sealed {}
479 }
480 pub trait State: sealed::Sealed {
482 type Id;
483 type CreatedBy;
484 type Action;
485 type EventType;
486 type Reason;
487 type CreatedAt;
488 type Url;
489 type Pattern;
490 }
491 pub struct Empty(());
493 impl sealed::Sealed for Empty {}
494 impl State for Empty {
495 type Id = Unset;
496 type CreatedBy = Unset;
497 type Action = Unset;
498 type EventType = Unset;
499 type Reason = Unset;
500 type CreatedAt = Unset;
501 type Url = Unset;
502 type Pattern = Unset;
503 }
504 pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
506 impl<S: State> sealed::Sealed for SetId<S> {}
507 impl<S: State> State for SetId<S> {
508 type Id = Set<members::id>;
509 type CreatedBy = S::CreatedBy;
510 type Action = S::Action;
511 type EventType = S::EventType;
512 type Reason = S::Reason;
513 type CreatedAt = S::CreatedAt;
514 type Url = S::Url;
515 type Pattern = S::Pattern;
516 }
517 pub struct SetCreatedBy<S: State = Empty>(PhantomData<fn() -> S>);
519 impl<S: State> sealed::Sealed for SetCreatedBy<S> {}
520 impl<S: State> State for SetCreatedBy<S> {
521 type Id = S::Id;
522 type CreatedBy = Set<members::created_by>;
523 type Action = S::Action;
524 type EventType = S::EventType;
525 type Reason = S::Reason;
526 type CreatedAt = S::CreatedAt;
527 type Url = S::Url;
528 type Pattern = S::Pattern;
529 }
530 pub struct SetAction<S: State = Empty>(PhantomData<fn() -> S>);
532 impl<S: State> sealed::Sealed for SetAction<S> {}
533 impl<S: State> State for SetAction<S> {
534 type Id = S::Id;
535 type CreatedBy = S::CreatedBy;
536 type Action = Set<members::action>;
537 type EventType = S::EventType;
538 type Reason = S::Reason;
539 type CreatedAt = S::CreatedAt;
540 type Url = S::Url;
541 type Pattern = S::Pattern;
542 }
543 pub struct SetEventType<S: State = Empty>(PhantomData<fn() -> S>);
545 impl<S: State> sealed::Sealed for SetEventType<S> {}
546 impl<S: State> State for SetEventType<S> {
547 type Id = S::Id;
548 type CreatedBy = S::CreatedBy;
549 type Action = S::Action;
550 type EventType = Set<members::event_type>;
551 type Reason = S::Reason;
552 type CreatedAt = S::CreatedAt;
553 type Url = S::Url;
554 type Pattern = S::Pattern;
555 }
556 pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
558 impl<S: State> sealed::Sealed for SetReason<S> {}
559 impl<S: State> State for SetReason<S> {
560 type Id = S::Id;
561 type CreatedBy = S::CreatedBy;
562 type Action = S::Action;
563 type EventType = S::EventType;
564 type Reason = Set<members::reason>;
565 type CreatedAt = S::CreatedAt;
566 type Url = S::Url;
567 type Pattern = S::Pattern;
568 }
569 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
571 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
572 impl<S: State> State for SetCreatedAt<S> {
573 type Id = S::Id;
574 type CreatedBy = S::CreatedBy;
575 type Action = S::Action;
576 type EventType = S::EventType;
577 type Reason = S::Reason;
578 type CreatedAt = Set<members::created_at>;
579 type Url = S::Url;
580 type Pattern = S::Pattern;
581 }
582 pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
584 impl<S: State> sealed::Sealed for SetUrl<S> {}
585 impl<S: State> State for SetUrl<S> {
586 type Id = S::Id;
587 type CreatedBy = S::CreatedBy;
588 type Action = S::Action;
589 type EventType = S::EventType;
590 type Reason = S::Reason;
591 type CreatedAt = S::CreatedAt;
592 type Url = Set<members::url>;
593 type Pattern = S::Pattern;
594 }
595 pub struct SetPattern<S: State = Empty>(PhantomData<fn() -> S>);
597 impl<S: State> sealed::Sealed for SetPattern<S> {}
598 impl<S: State> State for SetPattern<S> {
599 type Id = S::Id;
600 type CreatedBy = S::CreatedBy;
601 type Action = S::Action;
602 type EventType = S::EventType;
603 type Reason = S::Reason;
604 type CreatedAt = S::CreatedAt;
605 type Url = S::Url;
606 type Pattern = Set<members::pattern>;
607 }
608 #[allow(non_camel_case_types)]
610 pub mod members {
611 pub struct id(());
613 pub struct created_by(());
615 pub struct action(());
617 pub struct event_type(());
619 pub struct reason(());
621 pub struct created_at(());
623 pub struct url(());
625 pub struct pattern(());
627 }
628}
629
630pub struct EventBuilder<'a, S: event_state::State> {
632 _state: PhantomData<fn() -> S>,
633 _fields: (
634 Option<safelink::ActionType<'a>>,
635 Option<CowStr<'a>>,
636 Option<Datetime>,
637 Option<Did<'a>>,
638 Option<safelink::EventType<'a>>,
639 Option<i64>,
640 Option<safelink::PatternType<'a>>,
641 Option<safelink::ReasonType<'a>>,
642 Option<CowStr<'a>>,
643 ),
644 _lifetime: PhantomData<&'a ()>,
645}
646
647impl<'a> Event<'a> {
648 pub fn new() -> EventBuilder<'a, event_state::Empty> {
650 EventBuilder::new()
651 }
652}
653
654impl<'a> EventBuilder<'a, event_state::Empty> {
655 pub fn new() -> Self {
657 EventBuilder {
658 _state: PhantomData,
659 _fields: (None, None, None, None, None, None, None, None, None),
660 _lifetime: PhantomData,
661 }
662 }
663}
664
665impl<'a, S> EventBuilder<'a, S>
666where
667 S: event_state::State,
668 S::Action: event_state::IsUnset,
669{
670 pub fn action(
672 mut self,
673 value: impl Into<safelink::ActionType<'a>>,
674 ) -> EventBuilder<'a, event_state::SetAction<S>> {
675 self._fields.0 = Option::Some(value.into());
676 EventBuilder {
677 _state: PhantomData,
678 _fields: self._fields,
679 _lifetime: PhantomData,
680 }
681 }
682}
683
684impl<'a, S: event_state::State> EventBuilder<'a, S> {
685 pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
687 self._fields.1 = value.into();
688 self
689 }
690 pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
692 self._fields.1 = value;
693 self
694 }
695}
696
697impl<'a, S> EventBuilder<'a, S>
698where
699 S: event_state::State,
700 S::CreatedAt: event_state::IsUnset,
701{
702 pub fn created_at(
704 mut self,
705 value: impl Into<Datetime>,
706 ) -> EventBuilder<'a, event_state::SetCreatedAt<S>> {
707 self._fields.2 = Option::Some(value.into());
708 EventBuilder {
709 _state: PhantomData,
710 _fields: self._fields,
711 _lifetime: PhantomData,
712 }
713 }
714}
715
716impl<'a, S> EventBuilder<'a, S>
717where
718 S: event_state::State,
719 S::CreatedBy: event_state::IsUnset,
720{
721 pub fn created_by(
723 mut self,
724 value: impl Into<Did<'a>>,
725 ) -> EventBuilder<'a, event_state::SetCreatedBy<S>> {
726 self._fields.3 = Option::Some(value.into());
727 EventBuilder {
728 _state: PhantomData,
729 _fields: self._fields,
730 _lifetime: PhantomData,
731 }
732 }
733}
734
735impl<'a, S> EventBuilder<'a, S>
736where
737 S: event_state::State,
738 S::EventType: event_state::IsUnset,
739{
740 pub fn event_type(
742 mut self,
743 value: impl Into<safelink::EventType<'a>>,
744 ) -> EventBuilder<'a, event_state::SetEventType<S>> {
745 self._fields.4 = Option::Some(value.into());
746 EventBuilder {
747 _state: PhantomData,
748 _fields: self._fields,
749 _lifetime: PhantomData,
750 }
751 }
752}
753
754impl<'a, S> EventBuilder<'a, S>
755where
756 S: event_state::State,
757 S::Id: event_state::IsUnset,
758{
759 pub fn id(
761 mut self,
762 value: impl Into<i64>,
763 ) -> EventBuilder<'a, event_state::SetId<S>> {
764 self._fields.5 = Option::Some(value.into());
765 EventBuilder {
766 _state: PhantomData,
767 _fields: self._fields,
768 _lifetime: PhantomData,
769 }
770 }
771}
772
773impl<'a, S> EventBuilder<'a, S>
774where
775 S: event_state::State,
776 S::Pattern: event_state::IsUnset,
777{
778 pub fn pattern(
780 mut self,
781 value: impl Into<safelink::PatternType<'a>>,
782 ) -> EventBuilder<'a, event_state::SetPattern<S>> {
783 self._fields.6 = Option::Some(value.into());
784 EventBuilder {
785 _state: PhantomData,
786 _fields: self._fields,
787 _lifetime: PhantomData,
788 }
789 }
790}
791
792impl<'a, S> EventBuilder<'a, S>
793where
794 S: event_state::State,
795 S::Reason: event_state::IsUnset,
796{
797 pub fn reason(
799 mut self,
800 value: impl Into<safelink::ReasonType<'a>>,
801 ) -> EventBuilder<'a, event_state::SetReason<S>> {
802 self._fields.7 = Option::Some(value.into());
803 EventBuilder {
804 _state: PhantomData,
805 _fields: self._fields,
806 _lifetime: PhantomData,
807 }
808 }
809}
810
811impl<'a, S> EventBuilder<'a, S>
812where
813 S: event_state::State,
814 S::Url: event_state::IsUnset,
815{
816 pub fn url(
818 mut self,
819 value: impl Into<CowStr<'a>>,
820 ) -> EventBuilder<'a, event_state::SetUrl<S>> {
821 self._fields.8 = Option::Some(value.into());
822 EventBuilder {
823 _state: PhantomData,
824 _fields: self._fields,
825 _lifetime: PhantomData,
826 }
827 }
828}
829
830impl<'a, S> EventBuilder<'a, S>
831where
832 S: event_state::State,
833 S::Id: event_state::IsSet,
834 S::CreatedBy: event_state::IsSet,
835 S::Action: event_state::IsSet,
836 S::EventType: event_state::IsSet,
837 S::Reason: event_state::IsSet,
838 S::CreatedAt: event_state::IsSet,
839 S::Url: event_state::IsSet,
840 S::Pattern: event_state::IsSet,
841{
842 pub fn build(self) -> Event<'a> {
844 Event {
845 action: self._fields.0.unwrap(),
846 comment: self._fields.1,
847 created_at: self._fields.2.unwrap(),
848 created_by: self._fields.3.unwrap(),
849 event_type: self._fields.4.unwrap(),
850 id: self._fields.5.unwrap(),
851 pattern: self._fields.6.unwrap(),
852 reason: self._fields.7.unwrap(),
853 url: self._fields.8.unwrap(),
854 extra_data: Default::default(),
855 }
856 }
857 pub fn build_with_data(
859 self,
860 extra_data: BTreeMap<
861 jacquard_common::deps::smol_str::SmolStr,
862 jacquard_common::types::value::Data<'a>,
863 >,
864 ) -> Event<'a> {
865 Event {
866 action: self._fields.0.unwrap(),
867 comment: self._fields.1,
868 created_at: self._fields.2.unwrap(),
869 created_by: self._fields.3.unwrap(),
870 event_type: self._fields.4.unwrap(),
871 id: self._fields.5.unwrap(),
872 pattern: self._fields.6.unwrap(),
873 reason: self._fields.7.unwrap(),
874 url: self._fields.8.unwrap(),
875 extra_data: Some(extra_data),
876 }
877 }
878}
879
880fn lexicon_doc_tools_ozone_safelink_defs() -> LexiconDoc<'static> {
881 #[allow(unused_imports)]
882 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
883 use jacquard_lexicon::lexicon::*;
884 use alloc::collections::BTreeMap;
885 LexiconDoc {
886 lexicon: Lexicon::Lexicon1,
887 id: CowStr::new_static("tools.ozone.safelink.defs"),
888 defs: {
889 let mut map = BTreeMap::new();
890 map.insert(
891 SmolStr::new_static("actionType"),
892 LexUserType::String(LexString { ..Default::default() }),
893 );
894 map.insert(
895 SmolStr::new_static("event"),
896 LexUserType::Object(LexObject {
897 description: Some(
898 CowStr::new_static("An event for URL safety decisions"),
899 ),
900 required: Some(
901 vec![
902 SmolStr::new_static("id"), SmolStr::new_static("eventType"),
903 SmolStr::new_static("url"), SmolStr::new_static("pattern"),
904 SmolStr::new_static("action"), SmolStr::new_static("reason"),
905 SmolStr::new_static("createdBy"),
906 SmolStr::new_static("createdAt")
907 ],
908 ),
909 properties: {
910 #[allow(unused_mut)]
911 let mut map = BTreeMap::new();
912 map.insert(
913 SmolStr::new_static("action"),
914 LexObjectProperty::Ref(LexRef {
915 r#ref: CowStr::new_static("#actionType"),
916 ..Default::default()
917 }),
918 );
919 map.insert(
920 SmolStr::new_static("comment"),
921 LexObjectProperty::String(LexString {
922 description: Some(
923 CowStr::new_static("Optional comment about the decision"),
924 ),
925 ..Default::default()
926 }),
927 );
928 map.insert(
929 SmolStr::new_static("createdAt"),
930 LexObjectProperty::String(LexString {
931 format: Some(LexStringFormat::Datetime),
932 ..Default::default()
933 }),
934 );
935 map.insert(
936 SmolStr::new_static("createdBy"),
937 LexObjectProperty::String(LexString {
938 description: Some(
939 CowStr::new_static("DID of the user who created this rule"),
940 ),
941 format: Some(LexStringFormat::Did),
942 ..Default::default()
943 }),
944 );
945 map.insert(
946 SmolStr::new_static("eventType"),
947 LexObjectProperty::Ref(LexRef {
948 r#ref: CowStr::new_static("#eventType"),
949 ..Default::default()
950 }),
951 );
952 map.insert(
953 SmolStr::new_static("id"),
954 LexObjectProperty::Integer(LexInteger {
955 ..Default::default()
956 }),
957 );
958 map.insert(
959 SmolStr::new_static("pattern"),
960 LexObjectProperty::Ref(LexRef {
961 r#ref: CowStr::new_static("#patternType"),
962 ..Default::default()
963 }),
964 );
965 map.insert(
966 SmolStr::new_static("reason"),
967 LexObjectProperty::Ref(LexRef {
968 r#ref: CowStr::new_static("#reasonType"),
969 ..Default::default()
970 }),
971 );
972 map.insert(
973 SmolStr::new_static("url"),
974 LexObjectProperty::String(LexString {
975 description: Some(
976 CowStr::new_static("The URL that this rule applies to"),
977 ),
978 ..Default::default()
979 }),
980 );
981 map
982 },
983 ..Default::default()
984 }),
985 );
986 map.insert(
987 SmolStr::new_static("eventType"),
988 LexUserType::String(LexString { ..Default::default() }),
989 );
990 map.insert(
991 SmolStr::new_static("patternType"),
992 LexUserType::String(LexString { ..Default::default() }),
993 );
994 map.insert(
995 SmolStr::new_static("reasonType"),
996 LexUserType::String(LexString { ..Default::default() }),
997 );
998 map.insert(
999 SmolStr::new_static("urlRule"),
1000 LexUserType::Object(LexObject {
1001 description: Some(
1002 CowStr::new_static("Input for creating a URL safety rule"),
1003 ),
1004 required: Some(
1005 vec![
1006 SmolStr::new_static("url"), SmolStr::new_static("pattern"),
1007 SmolStr::new_static("action"), SmolStr::new_static("reason"),
1008 SmolStr::new_static("createdBy"),
1009 SmolStr::new_static("createdAt"),
1010 SmolStr::new_static("updatedAt")
1011 ],
1012 ),
1013 properties: {
1014 #[allow(unused_mut)]
1015 let mut map = BTreeMap::new();
1016 map.insert(
1017 SmolStr::new_static("action"),
1018 LexObjectProperty::Ref(LexRef {
1019 r#ref: CowStr::new_static("#actionType"),
1020 ..Default::default()
1021 }),
1022 );
1023 map.insert(
1024 SmolStr::new_static("comment"),
1025 LexObjectProperty::String(LexString {
1026 description: Some(
1027 CowStr::new_static("Optional comment about the decision"),
1028 ),
1029 ..Default::default()
1030 }),
1031 );
1032 map.insert(
1033 SmolStr::new_static("createdAt"),
1034 LexObjectProperty::String(LexString {
1035 description: Some(
1036 CowStr::new_static("Timestamp when the rule was created"),
1037 ),
1038 format: Some(LexStringFormat::Datetime),
1039 ..Default::default()
1040 }),
1041 );
1042 map.insert(
1043 SmolStr::new_static("createdBy"),
1044 LexObjectProperty::String(LexString {
1045 description: Some(
1046 CowStr::new_static("DID of the user added the rule."),
1047 ),
1048 format: Some(LexStringFormat::Did),
1049 ..Default::default()
1050 }),
1051 );
1052 map.insert(
1053 SmolStr::new_static("pattern"),
1054 LexObjectProperty::Ref(LexRef {
1055 r#ref: CowStr::new_static("#patternType"),
1056 ..Default::default()
1057 }),
1058 );
1059 map.insert(
1060 SmolStr::new_static("reason"),
1061 LexObjectProperty::Ref(LexRef {
1062 r#ref: CowStr::new_static("#reasonType"),
1063 ..Default::default()
1064 }),
1065 );
1066 map.insert(
1067 SmolStr::new_static("updatedAt"),
1068 LexObjectProperty::String(LexString {
1069 description: Some(
1070 CowStr::new_static(
1071 "Timestamp when the rule was last updated",
1072 ),
1073 ),
1074 format: Some(LexStringFormat::Datetime),
1075 ..Default::default()
1076 }),
1077 );
1078 map.insert(
1079 SmolStr::new_static("url"),
1080 LexObjectProperty::String(LexString {
1081 description: Some(
1082 CowStr::new_static("The URL or domain to apply the rule to"),
1083 ),
1084 ..Default::default()
1085 }),
1086 );
1087 map
1088 },
1089 ..Default::default()
1090 }),
1091 );
1092 map
1093 },
1094 ..Default::default()
1095 }
1096}
1097
1098pub mod url_rule_state {
1099
1100 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
1101 #[allow(unused)]
1102 use ::core::marker::PhantomData;
1103 mod sealed {
1104 pub trait Sealed {}
1105 }
1106 pub trait State: sealed::Sealed {
1108 type CreatedBy;
1109 type UpdatedAt;
1110 type Action;
1111 type Url;
1112 type Reason;
1113 type Pattern;
1114 type CreatedAt;
1115 }
1116 pub struct Empty(());
1118 impl sealed::Sealed for Empty {}
1119 impl State for Empty {
1120 type CreatedBy = Unset;
1121 type UpdatedAt = Unset;
1122 type Action = Unset;
1123 type Url = Unset;
1124 type Reason = Unset;
1125 type Pattern = Unset;
1126 type CreatedAt = Unset;
1127 }
1128 pub struct SetCreatedBy<S: State = Empty>(PhantomData<fn() -> S>);
1130 impl<S: State> sealed::Sealed for SetCreatedBy<S> {}
1131 impl<S: State> State for SetCreatedBy<S> {
1132 type CreatedBy = Set<members::created_by>;
1133 type UpdatedAt = S::UpdatedAt;
1134 type Action = S::Action;
1135 type Url = S::Url;
1136 type Reason = S::Reason;
1137 type Pattern = S::Pattern;
1138 type CreatedAt = S::CreatedAt;
1139 }
1140 pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
1142 impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
1143 impl<S: State> State for SetUpdatedAt<S> {
1144 type CreatedBy = S::CreatedBy;
1145 type UpdatedAt = Set<members::updated_at>;
1146 type Action = S::Action;
1147 type Url = S::Url;
1148 type Reason = S::Reason;
1149 type Pattern = S::Pattern;
1150 type CreatedAt = S::CreatedAt;
1151 }
1152 pub struct SetAction<S: State = Empty>(PhantomData<fn() -> S>);
1154 impl<S: State> sealed::Sealed for SetAction<S> {}
1155 impl<S: State> State for SetAction<S> {
1156 type CreatedBy = S::CreatedBy;
1157 type UpdatedAt = S::UpdatedAt;
1158 type Action = Set<members::action>;
1159 type Url = S::Url;
1160 type Reason = S::Reason;
1161 type Pattern = S::Pattern;
1162 type CreatedAt = S::CreatedAt;
1163 }
1164 pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
1166 impl<S: State> sealed::Sealed for SetUrl<S> {}
1167 impl<S: State> State for SetUrl<S> {
1168 type CreatedBy = S::CreatedBy;
1169 type UpdatedAt = S::UpdatedAt;
1170 type Action = S::Action;
1171 type Url = Set<members::url>;
1172 type Reason = S::Reason;
1173 type Pattern = S::Pattern;
1174 type CreatedAt = S::CreatedAt;
1175 }
1176 pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
1178 impl<S: State> sealed::Sealed for SetReason<S> {}
1179 impl<S: State> State for SetReason<S> {
1180 type CreatedBy = S::CreatedBy;
1181 type UpdatedAt = S::UpdatedAt;
1182 type Action = S::Action;
1183 type Url = S::Url;
1184 type Reason = Set<members::reason>;
1185 type Pattern = S::Pattern;
1186 type CreatedAt = S::CreatedAt;
1187 }
1188 pub struct SetPattern<S: State = Empty>(PhantomData<fn() -> S>);
1190 impl<S: State> sealed::Sealed for SetPattern<S> {}
1191 impl<S: State> State for SetPattern<S> {
1192 type CreatedBy = S::CreatedBy;
1193 type UpdatedAt = S::UpdatedAt;
1194 type Action = S::Action;
1195 type Url = S::Url;
1196 type Reason = S::Reason;
1197 type Pattern = Set<members::pattern>;
1198 type CreatedAt = S::CreatedAt;
1199 }
1200 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
1202 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
1203 impl<S: State> State for SetCreatedAt<S> {
1204 type CreatedBy = S::CreatedBy;
1205 type UpdatedAt = S::UpdatedAt;
1206 type Action = S::Action;
1207 type Url = S::Url;
1208 type Reason = S::Reason;
1209 type Pattern = S::Pattern;
1210 type CreatedAt = Set<members::created_at>;
1211 }
1212 #[allow(non_camel_case_types)]
1214 pub mod members {
1215 pub struct created_by(());
1217 pub struct updated_at(());
1219 pub struct action(());
1221 pub struct url(());
1223 pub struct reason(());
1225 pub struct pattern(());
1227 pub struct created_at(());
1229 }
1230}
1231
1232pub struct UrlRuleBuilder<'a, S: url_rule_state::State> {
1234 _state: PhantomData<fn() -> S>,
1235 _fields: (
1236 Option<safelink::ActionType<'a>>,
1237 Option<CowStr<'a>>,
1238 Option<Datetime>,
1239 Option<Did<'a>>,
1240 Option<safelink::PatternType<'a>>,
1241 Option<safelink::ReasonType<'a>>,
1242 Option<Datetime>,
1243 Option<CowStr<'a>>,
1244 ),
1245 _lifetime: PhantomData<&'a ()>,
1246}
1247
1248impl<'a> UrlRule<'a> {
1249 pub fn new() -> UrlRuleBuilder<'a, url_rule_state::Empty> {
1251 UrlRuleBuilder::new()
1252 }
1253}
1254
1255impl<'a> UrlRuleBuilder<'a, url_rule_state::Empty> {
1256 pub fn new() -> Self {
1258 UrlRuleBuilder {
1259 _state: PhantomData,
1260 _fields: (None, None, None, None, None, None, None, None),
1261 _lifetime: PhantomData,
1262 }
1263 }
1264}
1265
1266impl<'a, S> UrlRuleBuilder<'a, S>
1267where
1268 S: url_rule_state::State,
1269 S::Action: url_rule_state::IsUnset,
1270{
1271 pub fn action(
1273 mut self,
1274 value: impl Into<safelink::ActionType<'a>>,
1275 ) -> UrlRuleBuilder<'a, url_rule_state::SetAction<S>> {
1276 self._fields.0 = Option::Some(value.into());
1277 UrlRuleBuilder {
1278 _state: PhantomData,
1279 _fields: self._fields,
1280 _lifetime: PhantomData,
1281 }
1282 }
1283}
1284
1285impl<'a, S: url_rule_state::State> UrlRuleBuilder<'a, S> {
1286 pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
1288 self._fields.1 = value.into();
1289 self
1290 }
1291 pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
1293 self._fields.1 = value;
1294 self
1295 }
1296}
1297
1298impl<'a, S> UrlRuleBuilder<'a, S>
1299where
1300 S: url_rule_state::State,
1301 S::CreatedAt: url_rule_state::IsUnset,
1302{
1303 pub fn created_at(
1305 mut self,
1306 value: impl Into<Datetime>,
1307 ) -> UrlRuleBuilder<'a, url_rule_state::SetCreatedAt<S>> {
1308 self._fields.2 = Option::Some(value.into());
1309 UrlRuleBuilder {
1310 _state: PhantomData,
1311 _fields: self._fields,
1312 _lifetime: PhantomData,
1313 }
1314 }
1315}
1316
1317impl<'a, S> UrlRuleBuilder<'a, S>
1318where
1319 S: url_rule_state::State,
1320 S::CreatedBy: url_rule_state::IsUnset,
1321{
1322 pub fn created_by(
1324 mut self,
1325 value: impl Into<Did<'a>>,
1326 ) -> UrlRuleBuilder<'a, url_rule_state::SetCreatedBy<S>> {
1327 self._fields.3 = Option::Some(value.into());
1328 UrlRuleBuilder {
1329 _state: PhantomData,
1330 _fields: self._fields,
1331 _lifetime: PhantomData,
1332 }
1333 }
1334}
1335
1336impl<'a, S> UrlRuleBuilder<'a, S>
1337where
1338 S: url_rule_state::State,
1339 S::Pattern: url_rule_state::IsUnset,
1340{
1341 pub fn pattern(
1343 mut self,
1344 value: impl Into<safelink::PatternType<'a>>,
1345 ) -> UrlRuleBuilder<'a, url_rule_state::SetPattern<S>> {
1346 self._fields.4 = Option::Some(value.into());
1347 UrlRuleBuilder {
1348 _state: PhantomData,
1349 _fields: self._fields,
1350 _lifetime: PhantomData,
1351 }
1352 }
1353}
1354
1355impl<'a, S> UrlRuleBuilder<'a, S>
1356where
1357 S: url_rule_state::State,
1358 S::Reason: url_rule_state::IsUnset,
1359{
1360 pub fn reason(
1362 mut self,
1363 value: impl Into<safelink::ReasonType<'a>>,
1364 ) -> UrlRuleBuilder<'a, url_rule_state::SetReason<S>> {
1365 self._fields.5 = Option::Some(value.into());
1366 UrlRuleBuilder {
1367 _state: PhantomData,
1368 _fields: self._fields,
1369 _lifetime: PhantomData,
1370 }
1371 }
1372}
1373
1374impl<'a, S> UrlRuleBuilder<'a, S>
1375where
1376 S: url_rule_state::State,
1377 S::UpdatedAt: url_rule_state::IsUnset,
1378{
1379 pub fn updated_at(
1381 mut self,
1382 value: impl Into<Datetime>,
1383 ) -> UrlRuleBuilder<'a, url_rule_state::SetUpdatedAt<S>> {
1384 self._fields.6 = Option::Some(value.into());
1385 UrlRuleBuilder {
1386 _state: PhantomData,
1387 _fields: self._fields,
1388 _lifetime: PhantomData,
1389 }
1390 }
1391}
1392
1393impl<'a, S> UrlRuleBuilder<'a, S>
1394where
1395 S: url_rule_state::State,
1396 S::Url: url_rule_state::IsUnset,
1397{
1398 pub fn url(
1400 mut self,
1401 value: impl Into<CowStr<'a>>,
1402 ) -> UrlRuleBuilder<'a, url_rule_state::SetUrl<S>> {
1403 self._fields.7 = Option::Some(value.into());
1404 UrlRuleBuilder {
1405 _state: PhantomData,
1406 _fields: self._fields,
1407 _lifetime: PhantomData,
1408 }
1409 }
1410}
1411
1412impl<'a, S> UrlRuleBuilder<'a, S>
1413where
1414 S: url_rule_state::State,
1415 S::CreatedBy: url_rule_state::IsSet,
1416 S::UpdatedAt: url_rule_state::IsSet,
1417 S::Action: url_rule_state::IsSet,
1418 S::Url: url_rule_state::IsSet,
1419 S::Reason: url_rule_state::IsSet,
1420 S::Pattern: url_rule_state::IsSet,
1421 S::CreatedAt: url_rule_state::IsSet,
1422{
1423 pub fn build(self) -> UrlRule<'a> {
1425 UrlRule {
1426 action: self._fields.0.unwrap(),
1427 comment: self._fields.1,
1428 created_at: self._fields.2.unwrap(),
1429 created_by: self._fields.3.unwrap(),
1430 pattern: self._fields.4.unwrap(),
1431 reason: self._fields.5.unwrap(),
1432 updated_at: self._fields.6.unwrap(),
1433 url: self._fields.7.unwrap(),
1434 extra_data: Default::default(),
1435 }
1436 }
1437 pub fn build_with_data(
1439 self,
1440 extra_data: BTreeMap<
1441 jacquard_common::deps::smol_str::SmolStr,
1442 jacquard_common::types::value::Data<'a>,
1443 >,
1444 ) -> UrlRule<'a> {
1445 UrlRule {
1446 action: self._fields.0.unwrap(),
1447 comment: self._fields.1,
1448 created_at: self._fields.2.unwrap(),
1449 created_by: self._fields.3.unwrap(),
1450 pattern: self._fields.4.unwrap(),
1451 reason: self._fields.5.unwrap(),
1452 updated_at: self._fields.6.unwrap(),
1453 url: self._fields.7.unwrap(),
1454 extra_data: Some(extra_data),
1455 }
1456 }
1457}