1use firebase_auth::FirebaseUser;
2use serde::Serialize;
3use socketioxide::SocketIo;
4use sqlx::PgPool;
5use thiserror::Error;
6use tokio::sync::watch;
7use ts_rs::TS;
8use uuid::Uuid;
9
10#[derive(Clone)]
14pub struct AppState {
15 pub db: PgPool,
17
18 pub automerge_io: SocketIo,
20
21 pub app_status: watch::Receiver<AppStatus>,
22}
23
24#[derive(Clone, Debug, PartialEq, Eq)]
25pub enum AppStatus {
26 Starting,
27 Migrating,
28 Running,
29 #[allow(dead_code)]
30 Failed(String),
31}
32
33#[derive(Clone)]
35pub struct AppCtx {
36 pub state: AppState,
38
39 pub user: Option<FirebaseUser>,
41}
42
43#[derive(Clone, Debug, Serialize, TS)]
45pub struct Paginated<T> {
46 pub total: i32,
48
49 pub offset: i32,
51
52 pub items: Vec<T>,
54}
55
56#[derive(Error, Debug)]
58pub enum AppError {
59 #[error("SQL database error: {0}")]
61 Db(#[from] sqlx::Error),
62
63 #[error("Error receiving acknowledgment from socket: {0}")]
65 Ack(#[from] socketioxide::AckError<()>),
66
67 #[error("Request with invalid data: {0}")]
69 Invalid(String),
70
71 #[error("Authentication credentials were not provided")]
73 Unauthorized,
74
75 #[error("Automerge server error: {0}")]
77 AutomergeServer(String),
78
79 #[error("Not authorized to access ref: {0}")]
82 Forbidden(Uuid),
83}