1 #[cfg(feature = "full")]
2 use activitypub_federation::{
3 fetch::collection_id::CollectionId,
4 fetch::object_id::ObjectId,
8 #[cfg(feature = "full")]
9 use diesel_ltree::Ltree;
10 use serde::{Deserialize, Serialize};
13 fmt::{Display, Formatter},
16 #[cfg(feature = "full")]
20 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
21 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
22 #[cfg_attr(feature = "full", ts(export))]
24 pub struct PostId(pub i32);
26 impl fmt::Display for PostId {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 write!(f, "{}", self.0)
32 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
33 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
34 #[cfg_attr(feature = "full", ts(export))]
36 pub struct PersonId(pub i32);
38 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
39 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
40 #[cfg_attr(feature = "full", ts(export))]
42 pub struct CommentId(pub i32);
44 impl fmt::Display for CommentId {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 write!(f, "{}", self.0)
50 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
51 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
52 #[cfg_attr(feature = "full", ts(export))]
54 pub struct CommunityId(pub i32);
56 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
57 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
58 #[cfg_attr(feature = "full", ts(export))]
59 /// The local user id.
60 pub struct LocalUserId(pub i32);
62 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
63 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
64 #[cfg_attr(feature = "full", ts(export))]
65 /// The private message id.
66 pub struct PrivateMessageId(i32);
68 impl fmt::Display for PrivateMessageId {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 write!(f, "{}", self.0)
74 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
75 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
76 #[cfg_attr(feature = "full", ts(export))]
77 /// The person mention id.
78 pub struct PersonMentionId(i32);
80 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
81 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
82 #[cfg_attr(feature = "full", ts(export))]
83 /// The person block id.
84 pub struct PersonBlockId(i32);
86 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
87 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
88 #[cfg_attr(feature = "full", ts(export))]
89 /// The community block id.
90 pub struct CommunityBlockId(i32);
92 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
93 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
94 #[cfg_attr(feature = "full", ts(export))]
95 /// The comment report id.
96 pub struct CommentReportId(i32);
98 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
99 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
100 #[cfg_attr(feature = "full", ts(export))]
101 /// The post report id.
102 pub struct PostReportId(i32);
104 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
105 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
106 #[cfg_attr(feature = "full", ts(export))]
107 /// The private message report id.
108 pub struct PrivateMessageReportId(i32);
110 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
111 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
112 #[cfg_attr(feature = "full", ts(export))]
114 pub struct SiteId(i32);
116 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
117 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
118 #[cfg_attr(feature = "full", ts(export))]
120 pub struct LanguageId(pub i32);
122 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
123 #[cfg_attr(feature = "full", derive(DieselNewType))]
124 pub struct LocalUserLanguageId(pub i32);
126 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
127 #[cfg_attr(feature = "full", derive(DieselNewType))]
128 pub struct SiteLanguageId(pub i32);
130 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
131 #[cfg_attr(feature = "full", derive(DieselNewType))]
132 pub struct CommunityLanguageId(pub i32);
134 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
135 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
136 #[cfg_attr(feature = "full", ts(export))]
137 /// The comment reply id.
138 pub struct CommentReplyId(i32);
140 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
141 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
142 #[cfg_attr(feature = "full", ts(export))]
144 pub struct InstanceId(i32);
146 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
147 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
148 #[cfg_attr(feature = "full", ts(export))]
149 /// The local site id.
150 pub struct LocalSiteId(i32);
152 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
153 #[cfg_attr(feature = "full", derive(DieselNewType, TS))]
154 #[cfg_attr(feature = "full", ts(export))]
155 /// The custom emoji id.
156 pub struct CustomEmojiId(i32);
158 #[cfg(feature = "full")]
159 #[derive(Serialize, Deserialize)]
160 #[serde(remote = "Ltree")]
161 /// Do remote derivation for the Ltree struct
162 pub struct LtreeDef(pub String);
165 #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
166 #[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))]
167 #[cfg_attr(feature = "full", diesel(sql_type = diesel::sql_types::Text))]
168 pub struct DbUrl(pub(crate) Box<Url>);
171 pub fn inner(&self) -> &Url {
176 impl Display for DbUrl {
177 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
178 self.clone().0.fmt(f)
182 // the project doesnt compile with From
183 #[allow(clippy::from_over_into)]
184 impl Into<DbUrl> for Url {
185 fn into(self) -> DbUrl {
186 DbUrl(Box::new(self))
189 #[allow(clippy::from_over_into)]
190 impl Into<Url> for DbUrl {
191 fn into(self) -> Url {
196 #[cfg(feature = "full")]
197 impl<T> From<DbUrl> for ObjectId<T>
199 T: Object + Send + 'static,
200 for<'de2> <T as Object>::Kind: Deserialize<'de2>,
202 fn from(value: DbUrl) -> Self {
203 let url: Url = value.into();
208 #[cfg(feature = "full")]
209 impl<T> From<DbUrl> for CollectionId<T>
211 T: Collection + Send + 'static,
212 for<'de2> <T as Collection>::Kind: Deserialize<'de2>,
214 fn from(value: DbUrl) -> Self {
215 let url: Url = value.into();
216 CollectionId::from(url)
220 #[cfg(feature = "full")]
221 impl<T> From<CollectionId<T>> for DbUrl
224 for<'de2> <T as Collection>::Kind: Deserialize<'de2>,
226 fn from(value: CollectionId<T>) -> Self {
227 let url: Url = value.into();
232 impl Deref for DbUrl {
235 fn deref(&self) -> &Self::Target {
240 #[cfg(feature = "full")]
242 fn name() -> String {
245 fn dependencies() -> Vec<ts_rs::Dependency> {
248 fn transparent() -> bool {