1use serde::{Deserialize, Serialize};
2
3use crate::types::nsid::Nsid;
4
5pub mod aturi;
6pub mod blob;
7pub mod cid;
8pub mod collection;
9pub mod datetime;
10pub mod did;
11pub mod handle;
12pub mod ident;
13pub mod integer;
14pub mod language;
15pub mod link;
16pub mod nsid;
17pub mod recordkey;
18pub mod string;
19pub mod tid;
20pub mod uri;
21pub mod value;
22
23/// Trait for a constant string literal type
24pub trait Literal: Clone + Copy + PartialEq + Eq + Send + Sync + 'static {
25 /// The string literal
26 const LITERAL: &'static str;
27}
28
29pub const DISALLOWED_TLDS: &[&str] = &[
30 ".local",
31 ".arpa",
32 ".invalid",
33 ".localhost",
34 ".internal",
35 ".example",
36 ".alt",
37 // policy could concievably change on ".onion" some day
38 ".onion",
39 // NOTE: .test is allowed in testing and devopment. In practical terms
40 // "should" "never" actually resolve and get registered in production
41];
42
43pub fn ends_with(string: impl AsRef<str>, list: &[&str]) -> bool {
44 let string = string.as_ref();
45 for item in list {
46 if string.ends_with(item) {
47 return true;
48 }
49 }
50 false
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
54#[serde(rename_all = "kebab-case")]
55pub enum DataModelType {
56 Null,
57 Boolean,
58 Integer,
59 Bytes,
60 CidLink,
61 Blob,
62 Array,
63 Object,
64 #[serde(untagged)]
65 String(LexiconStringType),
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
69#[serde(rename_all = "kebab-case")]
70pub enum LexiconType {
71 Params,
72 Token,
73 Ref,
74 Union,
75 Unknown,
76 Record,
77 Query,
78 Procedure,
79 Subscription,
80 #[serde(untagged)]
81 DataModel(DataModelType),
82}
83
84#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
85#[serde(rename_all = "kebab-case")]
86pub enum LexiconStringType {
87 Datetime,
88 AtUri,
89 Did,
90 Handle,
91 AtIdentifier,
92 Nsid,
93 Cid,
94 Language,
95 Tid,
96 RecordKey,
97 Uri(UriType),
98 #[serde(untagged)]
99 String,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
103#[serde(tag = "type")]
104pub enum UriType {
105 Did,
106 At,
107 Https,
108 Wss,
109 Cid,
110 Dns,
111 Any,
112}