chore(monorepo): delta, january, quark

This commit is contained in:
Paul Makles
2022-06-02 00:04:22 +01:00
parent 5d8432e267
commit 2ce610e1e7
232 changed files with 18094 additions and 554 deletions

View File

@@ -0,0 +1,6 @@
use crate::Result;
#[async_trait]
pub trait AbstractMigrations: Sync + Send {
async fn migrate_database(&self) -> Result<()>;
}

View File

@@ -0,0 +1,16 @@
use crate::models::attachment::File;
use crate::Result;
#[async_trait]
pub trait AbstractAttachment: Sync + Send {
async fn find_and_use_attachment(
&self,
id: &str,
tag: &str,
parent_type: &str,
parent_id: &str,
) -> Result<File>;
async fn insert_attachment(&self, attachment: &File) -> Result<()>;
async fn mark_attachment_as_reported(&self, id: &str) -> Result<()>;
async fn mark_attachment_as_deleted(&self, id: &str) -> Result<()>;
}

View File

@@ -0,0 +1,61 @@
use std::collections::HashSet;
use crate::models::channel::{Channel, FieldsChannel, PartialChannel};
use crate::{OverrideField, Result};
#[async_trait]
pub trait AbstractChannel: Sync + Send {
/// Fetch a channel by its id
async fn fetch_channel(&self, id: &str) -> Result<Channel>;
/// Fetch channels by their ids
async fn fetch_channels<'a>(&self, ids: &'a [String]) -> Result<Vec<Channel>>;
/// Insert a new channel into the database
async fn insert_channel(&self, channel: &Channel) -> Result<()>;
/// Update an existing channel using some data
/// ! TODO: we need separate Channel::update which also sends out the relevant events
/// ! also applies to other methods I guess, try to restrict event bound methods to
/// ! the models themselves instead of the abstract database
async fn update_channel(
&self,
id: &str,
channel: &PartialChannel,
remove: Vec<FieldsChannel>,
) -> Result<()>;
/// Delete a channel by its id
///
/// This will also delete all associated messages and files.
async fn delete_channel(&self, channel: &Channel) -> Result<()>;
/// Find all direct messages that a user is involved in
///
/// Returns group DMs, any DMs marked as "active" and saved messages.
async fn find_direct_messages(&self, user_id: &str) -> Result<Vec<Channel>>;
/// Find a direct message channel between two users
async fn find_direct_message_channel(&self, user_a: &str, user_b: &str) -> Result<Channel>;
/// Find a saved message channel owned by a user
async fn find_saved_messages_channel(&self, user_id: &str) -> Result<Channel>;
/// Add user to a group
async fn add_user_to_group(&self, channel: &str, user: &str) -> Result<()>;
/// Remove a user from a group
async fn remove_user_from_group(&self, channel: &str, user: &str) -> Result<()>;
/// Set role permission for a channel
/// ! FIXME: may want to refactor to just use normal updates
async fn set_channel_role_permission(
&self,
channel: &str,
role: &str,
permissions: OverrideField,
) -> Result<()>;
/// Validate existence of channels
async fn check_channels_exist(&self, channels: &HashSet<String>) -> Result<bool>;
}

View File

@@ -0,0 +1,17 @@
use crate::models::Invite;
use crate::Result;
#[async_trait]
pub trait AbstractChannelInvite: Sync + Send {
/// Fetch an invite by its id
async fn fetch_invite(&self, code: &str) -> Result<Invite>;
/// Insert a new invite into the database
async fn insert_invite(&self, invite: &Invite) -> Result<()>;
/// Delete an invite by its id
async fn delete_invite(&self, code: &str) -> Result<()>;
/// Fetch all invites for a server
async fn fetch_invites_for_server(&self, server: &str) -> Result<Vec<Invite>>;
}

View File

@@ -0,0 +1,22 @@
use crate::models::channel_unread::ChannelUnread;
use crate::Result;
#[async_trait]
pub trait AbstractChannelUnread: Sync + Send {
/// Acknowledge a message.
async fn acknowledge_message(&self, channel: &str, user: &str, message: &str) -> Result<()>;
/// Acknowledge many channels.
async fn acknowledge_channels(&self, user: &str, channels: &[String]) -> Result<()>;
/// Add a mention.
async fn add_mention_to_unread<'a>(
&self,
channel: &str,
user: &str,
ids: &[String],
) -> Result<()>;
/// Fetch all channel unreads for a user.
async fn fetch_unreads(&self, user: &str) -> Result<Vec<ChannelUnread>>;
}

View File

@@ -0,0 +1,45 @@
use crate::models::message::{AppendMessage, Message, MessageSort, PartialMessage};
use crate::Result;
#[async_trait]
pub trait AbstractMessage: Sync + Send {
/// Fetch a message by its id
async fn fetch_message(&self, id: &str) -> Result<Message>;
/// Insert a new message into the database
async fn insert_message(&self, message: &Message) -> Result<()>;
/// Update a given message with new information
async fn update_message(&self, id: &str, message: &PartialMessage) -> Result<()>;
/// Append information to a given message
async fn append_message(&self, id: &str, append: &AppendMessage) -> Result<()>;
/// Delete a message from the database by its id
async fn delete_message(&self, id: &str) -> Result<()>;
/// Delete messages from a channel by their ids and corresponding channel id
async fn delete_messages(&self, channel: &str, ids: Vec<String>) -> Result<()>;
/// Fetch multiple messages
async fn fetch_messages(
&self,
channel: &str,
limit: Option<i64>,
before: Option<String>,
after: Option<String>,
sort: Option<MessageSort>,
nearby: Option<String>,
) -> Result<Vec<Message>>;
/// Search for messages
async fn search_messages(
&self,
channel: &str,
query: &str,
limit: Option<i64>,
before: Option<String>,
after: Option<String>,
sort: MessageSort,
) -> Result<Vec<Message>>;
}

View File

@@ -0,0 +1,64 @@
mod admin {
pub mod migrations;
}
mod autumn {
pub mod attachment;
}
mod channels {
pub mod channel;
pub mod channel_invite;
pub mod channel_unread;
pub mod message;
}
mod servers {
pub mod server;
pub mod server_ban;
pub mod server_member;
}
mod users {
pub mod bot;
pub mod user;
pub mod user_settings;
}
pub use admin::migrations::AbstractMigrations;
pub use autumn::attachment::AbstractAttachment;
pub use channels::channel::AbstractChannel;
pub use channels::channel_invite::AbstractChannelInvite;
pub use channels::channel_unread::AbstractChannelUnread;
pub use channels::message::AbstractMessage;
pub use servers::server::AbstractServer;
pub use servers::server_ban::AbstractServerBan;
pub use servers::server_member::AbstractServerMember;
pub use users::bot::AbstractBot;
pub use users::user::AbstractUser;
pub use users::user_settings::AbstractUserSettings;
// pub trait AbstractEventEmitter {}
// + AbstractEventEmitter
pub trait AbstractDatabase:
Sync
+ Send
+ AbstractMigrations
+ AbstractAttachment
+ AbstractChannel
+ AbstractChannelInvite
+ AbstractChannelUnread
+ AbstractMessage
+ AbstractServer
+ AbstractServerBan
+ AbstractServerMember
+ AbstractBot
+ AbstractUser
+ AbstractUserSettings
{
}

View File

@@ -0,0 +1,42 @@
use crate::models::server::{FieldsRole, FieldsServer, PartialRole, PartialServer, Role, Server};
use crate::Result;
#[async_trait]
pub trait AbstractServer: Sync + Send {
/// Fetch a server by its id
async fn fetch_server(&self, id: &str) -> Result<Server>;
/// Fetch a servers by their ids
async fn fetch_servers<'a>(&self, ids: &'a [String]) -> Result<Vec<Server>>;
/// Insert a new server into database
async fn insert_server(&self, server: &Server) -> Result<()>;
/// Update a server with new information
async fn update_server(
&self,
id: &str,
server: &PartialServer,
remove: Vec<FieldsServer>,
) -> Result<()>;
/// Delete a server by its id
async fn delete_server(&self, server: &Server) -> Result<()>;
/// Insert a new role into server object
async fn insert_role(&self, server_id: &str, role_id: &str, role: &Role) -> Result<()>;
/// Update an existing role on a server
async fn update_role(
&self,
server_id: &str,
role_id: &str,
role: &PartialRole,
remove: Vec<FieldsRole>,
) -> Result<()>;
/// Delete a role from a server
///
/// Also updates channels and members.
async fn delete_role(&self, server_id: &str, role_id: &str) -> Result<()>;
}

View File

@@ -0,0 +1,18 @@
use crate::models::server_member::MemberCompositeKey;
use crate::models::ServerBan;
use crate::Result;
#[async_trait]
pub trait AbstractServerBan: Sync + Send {
/// Fetch a server ban by server and user id
async fn fetch_ban(&self, server: &str, user: &str) -> Result<ServerBan>;
/// Fetch all bans in a server
async fn fetch_bans(&self, server: &str) -> Result<Vec<ServerBan>>;
/// Insert new ban into database
async fn insert_ban(&self, ban: &ServerBan) -> Result<()>;
/// Delete a ban from the database
async fn delete_ban(&self, id: &MemberCompositeKey) -> Result<()>;
}

View File

@@ -0,0 +1,37 @@
use crate::models::server_member::{FieldsMember, Member, MemberCompositeKey, PartialMember};
use crate::Result;
#[async_trait]
pub trait AbstractServerMember: Sync + Send {
/// Fetch a server member by their id
async fn fetch_member(&self, server: &str, user: &str) -> Result<Member>;
/// Insert a new server member into the database
async fn insert_member(&self, member: &Member) -> Result<()>;
/// Update information for a server member
async fn update_member(
&self,
id: &MemberCompositeKey,
member: &PartialMember,
remove: Vec<FieldsMember>,
) -> Result<()>;
/// Delete a server member by their id
async fn delete_member(&self, id: &MemberCompositeKey) -> Result<()>;
/// Fetch all members in a server
async fn fetch_all_members<'a>(&self, server: &str) -> Result<Vec<Member>>;
/// Fetch all memberships for a user
async fn fetch_all_memberships<'a>(&self, user: &str) -> Result<Vec<Member>>;
/// Fetch multiple members by their ids
async fn fetch_members<'a>(&self, server: &str, ids: &'a [String]) -> Result<Vec<Member>>;
/// Fetch member count of a server
async fn fetch_member_count(&self, server: &str) -> Result<usize>;
/// Fetch server count of a user
async fn fetch_server_count(&self, user: &str) -> Result<usize>;
}

View File

@@ -0,0 +1,26 @@
use crate::models::bot::{Bot, FieldsBot, PartialBot};
use crate::Result;
#[async_trait]
pub trait AbstractBot: Sync + Send {
/// Fetch a bot by its id
async fn fetch_bot(&self, id: &str) -> Result<Bot>;
/// Fetch a bot by its token
async fn fetch_bot_by_token(&self, token: &str) -> Result<Bot>;
/// Insert new bot into the database
async fn insert_bot(&self, bot: &Bot) -> Result<()>;
/// Update bot with new information
async fn update_bot(&self, id: &str, bot: &PartialBot, remove: Vec<FieldsBot>) -> Result<()>;
/// Delete a bot from the database
async fn delete_bot(&self, id: &str) -> Result<()>;
/// Fetch bots owned by a user
async fn fetch_bots_by_user(&self, user_id: &str) -> Result<Vec<Bot>>;
/// Get the number of bots owned by a user
async fn get_number_of_bots_by_user(&self, user_id: &str) -> Result<usize>;
}

View File

@@ -0,0 +1,56 @@
use crate::models::user::{FieldsUser, PartialUser, RelationshipStatus, User};
use crate::Result;
#[async_trait]
pub trait AbstractUser: Sync + Send {
/// Fetch a user from the database
async fn fetch_user(&self, id: &str) -> Result<User>;
/// Fetch a user from the database by their username
async fn fetch_user_by_username(&self, username: &str) -> Result<User>;
/// Fetch a user from the database by their session token
async fn fetch_user_by_token(&self, token: &str) -> Result<User>;
/// Insert a new user into the database
async fn insert_user(&self, user: &User) -> Result<()>;
/// Update a user by their id given some data
async fn update_user(
&self,
id: &str,
user: &PartialUser,
remove: Vec<FieldsUser>,
) -> Result<()>;
/// Delete a user by their id
async fn delete_user(&self, id: &str) -> Result<()>;
/// Fetch multiple users by their ids
async fn fetch_users<'a>(&self, ids: &'a [String]) -> Result<Vec<User>>;
/// Check whether a username is already in use by another user
async fn is_username_taken(&self, username: &str) -> Result<bool>;
/// Fetch ids of users that both users are friends with
async fn fetch_mutual_user_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
/// Fetch ids of channels that both users are in
async fn fetch_mutual_channel_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
/// Fetch ids of servers that both users share
async fn fetch_mutual_server_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
/// Set relationship with another user
///
/// This should use pull_relationship if relationship is None.
async fn set_relationship(
&self,
user_id: &str,
target_id: &str,
relationship: &RelationshipStatus,
) -> Result<()>;
/// Remove relationship with another user
async fn pull_relationship(&self, user_id: &str, target_id: &str) -> Result<()>;
}

View File

@@ -0,0 +1,14 @@
use crate::models::UserSettings;
use crate::Result;
#[async_trait]
pub trait AbstractUserSettings: Sync + Send {
/// Fetch a subset of user settings
async fn fetch_user_settings(&'_ self, id: &str, filter: &'_ [String]) -> Result<UserSettings>;
/// Update a subset of user settings
async fn set_user_settings(&self, id: &str, settings: &UserSettings) -> Result<()>;
/// Delete all user settings
async fn delete_user_settings(&self, id: &str) -> Result<()>;
}