]> Untitled Git - lemmy.git/blob - crates/db_schema/src/lib.rs
Adding typescript generation for API. Fixes #2824 (#2827)
[lemmy.git] / crates / db_schema / src / lib.rs
1 #![recursion_limit = "256"]
2
3 #[cfg(feature = "full")]
4 #[macro_use]
5 extern crate diesel;
6 #[cfg(feature = "full")]
7 #[macro_use]
8 extern crate diesel_derive_newtype;
9
10 #[cfg(feature = "full")]
11 #[macro_use]
12 extern crate diesel_derive_enum;
13
14 // this is used in tests
15 #[cfg(feature = "full")]
16 #[macro_use]
17 extern crate diesel_migrations;
18
19 #[cfg(feature = "full")]
20 #[macro_use]
21 extern crate async_trait;
22
23 pub mod aggregates;
24 #[cfg(feature = "full")]
25 pub mod impls;
26 pub mod newtypes;
27 #[cfg(feature = "full")]
28 #[rustfmt::skip]
29 pub mod schema;
30 pub mod source;
31 #[cfg(feature = "full")]
32 pub mod traits;
33 #[cfg(feature = "full")]
34 pub mod utils;
35
36 use serde::{Deserialize, Serialize};
37 use strum_macros::{Display, EnumString};
38 #[cfg(feature = "full")]
39 use ts_rs::TS;
40
41 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
42 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
43 #[cfg_attr(
44   feature = "full",
45   ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
46 )]
47 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
48 #[cfg_attr(feature = "full", ts(export))]
49 pub enum SortType {
50   Active,
51   Hot,
52   New,
53   Old,
54   TopDay,
55   TopWeek,
56   TopMonth,
57   TopYear,
58   TopAll,
59   MostComments,
60   NewComments,
61 }
62
63 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
64 #[cfg_attr(feature = "full", derive(TS))]
65 #[cfg_attr(feature = "full", ts(export))]
66 pub enum CommentSortType {
67   Hot,
68   Top,
69   New,
70   Old,
71 }
72
73 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
74 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
75 #[cfg_attr(
76   feature = "full",
77   ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum"
78 )]
79 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
80 #[cfg_attr(feature = "full", ts(export))]
81 pub enum ListingType {
82   All,
83   Local,
84   Subscribed,
85 }
86
87 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
88 #[cfg_attr(feature = "full", derive(DbEnum, TS))]
89 #[cfg_attr(
90   feature = "full",
91   ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum"
92 )]
93 #[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
94 #[cfg_attr(feature = "full", ts(export))]
95 pub enum RegistrationMode {
96   Closed,
97   RequireApplication,
98   Open,
99 }
100
101 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
102 #[cfg_attr(feature = "full", derive(TS))]
103 #[cfg_attr(feature = "full", ts(export))]
104 pub enum SearchType {
105   All,
106   Comments,
107   Posts,
108   Communities,
109   Users,
110   Url,
111 }
112
113 #[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
114 #[cfg_attr(feature = "full", derive(TS))]
115 #[cfg_attr(feature = "full", ts(export))]
116 pub enum SubscribedType {
117   Subscribed,
118   NotSubscribed,
119   Pending,
120 }
121
122 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
123 #[cfg_attr(feature = "full", derive(TS))]
124 #[cfg_attr(feature = "full", ts(export))]
125 pub enum ModlogActionType {
126   All,
127   ModRemovePost,
128   ModLockPost,
129   ModFeaturePost,
130   ModRemoveComment,
131   ModRemoveCommunity,
132   ModBanFromCommunity,
133   ModAddCommunity,
134   ModTransferCommunity,
135   ModAdd,
136   ModBan,
137   ModHideCommunity,
138   AdminPurgePerson,
139   AdminPurgeCommunity,
140   AdminPurgePost,
141   AdminPurgeComment,
142 }
143
144 #[derive(
145   EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq,
146 )]
147 #[cfg_attr(feature = "full", derive(TS))]
148 #[cfg_attr(feature = "full", ts(export))]
149 pub enum PostFeatureType {
150   #[default]
151   Local,
152   Community,
153 }