refactor(types)!: blow up big lib.rs into submods

This commit is contained in:
oxalica 2024-09-25 11:15:31 -04:00
parent 066061e2ec
commit 8551540798
14 changed files with 778 additions and 745 deletions

View file

@ -3,10 +3,12 @@ use std::path::PathBuf;
use anyhow::{ensure, Context};
use blah_types::identity::UserIdentityDesc;
use blah_types::{
ChatPayload, Id, MemberPermission, PubKey, RoomAttrs, RoomMetadata, ServerPermission,
SignedChatMsg, Signee, UserKey, WithMsgId,
use blah_types::msg::{
ChatPayload, MemberPermission, RoomAttrs, ServerPermission, SignedChatMsg, SignedChatMsgWithId,
WithMsgId,
};
use blah_types::server::RoomMetadata;
use blah_types::{Id, PubKey, Signee, UserKey};
use parking_lot::Mutex;
use rusqlite::{named_params, params, prepare_cached_and_bind, Connection, OpenFlags, Row};
use serde::Deserialize;
@ -127,7 +129,7 @@ impl Database {
}
}
fn parse_msg(rid: Id, row: &Row<'_>) -> Result<WithMsgId<SignedChatMsg>> {
fn parse_msg(rid: Id, row: &Row<'_>) -> Result<SignedChatMsgWithId> {
Ok(WithMsgId {
cid: row.get("cid")?,
msg: SignedChatMsg {
@ -366,7 +368,7 @@ pub trait TransactionOps {
after_cid: Id,
before_cid: Id,
page_len: NonZero<u32>,
) -> Result<Vec<WithMsgId<SignedChatMsg>>> {
) -> Result<Vec<SignedChatMsgWithId>> {
prepare_cached_and_bind!(
self.conn(),
r"

View file

@ -9,7 +9,8 @@ use std::time::Duration;
use anyhow::{bail, Context as _, Result};
use axum::extract::ws::{Message, WebSocket};
use blah_types::{AuthPayload, Signed, SignedChatMsg};
use blah_types::msg::{AuthPayload, SignedChatMsg};
use blah_types::Signed;
use futures_util::future::Either;
use futures_util::stream::SplitSink;
use futures_util::{stream_select, SinkExt as _, Stream, StreamExt};

View file

@ -6,7 +6,8 @@ use std::time::{Duration, SystemTime};
use axum::http::header;
use axum::response::{IntoResponse, Response};
use axum::Json;
use blah_types::{Id, SignedChatMsg, WithMsgId};
use blah_types::msg::{SignedChatMsgWithId, WithMsgId};
use blah_types::Id;
use serde::{Deserialize, Serialize};
use url::Url;
@ -32,7 +33,7 @@ impl Default for Config {
pub struct FeedData {
pub rid: Id,
pub title: String,
pub msgs: Vec<WithMsgId<SignedChatMsg>>,
pub msgs: Vec<SignedChatMsgWithId>,
pub self_url: Url,
pub next_url: Option<Url>,
}

View file

@ -10,12 +10,13 @@ use axum::response::Response;
use axum::routing::{get, post};
use axum::{Json, Router};
use axum_extra::extract::WithRejection as R;
use blah_types::{
get_timestamp, ChatPayload, CreateGroup, CreatePeerChat, CreateRoomPayload, DeleteRoomPayload,
Id, MemberPermission, RoomAdminOp, RoomAdminPayload, RoomAttrs, RoomMetadata, ServerPermission,
Signed, SignedChatMsg, UserKey, UserRegisterPayload, WithMsgId, X_BLAH_DIFFICULTY,
X_BLAH_NONCE,
use blah_types::msg::{
ChatPayload, CreateGroup, CreatePeerChat, CreateRoomPayload, DeleteRoomPayload,
MemberPermission, RoomAdminOp, RoomAdminPayload, RoomAttrs, ServerPermission,
SignedChatMsgWithId, UserRegisterPayload,
};
use blah_types::server::{RoomMetadata, X_BLAH_DIFFICULTY, X_BLAH_NONCE};
use blah_types::{get_timestamp, Id, Signed, UserKey};
use database::{Transaction, TransactionOps};
use feed::FeedData;
use id::IdExt;
@ -345,7 +346,7 @@ impl Pagination {
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoomMsgs {
pub msgs: Vec<WithMsgId<SignedChatMsg>>,
pub msgs: Vec<SignedChatMsgWithId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub skip_token: Option<Id>,
}
@ -460,7 +461,7 @@ fn query_room_msgs(
txn: &Transaction<'_>,
rid: Id,
pagination: Pagination,
) -> Result<(Vec<WithMsgId<SignedChatMsg>>, Option<Id>), ApiError> {
) -> Result<(Vec<SignedChatMsgWithId>, Option<Id>), ApiError> {
let page_len = pagination.effective_page_len(st);
let msgs = txn.list_room_msgs(
rid,

View file

@ -8,7 +8,8 @@ use axum::extract::{FromRef, FromRequest, FromRequestParts, Request};
use axum::http::{header, request, StatusCode};
use axum::response::{IntoResponse, Response};
use axum::{async_trait, Json};
use blah_types::{AuthPayload, Signed, UserKey};
use blah_types::msg::AuthPayload;
use blah_types::{Signed, UserKey};
use serde::de::DeserializeOwned;
use serde::Serialize;

View file

@ -4,7 +4,9 @@ use std::time::{Duration, Instant};
use anyhow::{anyhow, ensure};
use axum::http::{HeaderMap, HeaderName, StatusCode};
use blah_types::identity::{IdUrl, UserIdentityDesc};
use blah_types::{get_timestamp, Signed, UserRegisterPayload, X_BLAH_DIFFICULTY, X_BLAH_NONCE};
use blah_types::msg::UserRegisterPayload;
use blah_types::server::{X_BLAH_DIFFICULTY, X_BLAH_NONCE};
use blah_types::{get_timestamp, Signed};
use http_body_util::BodyExt;
use parking_lot::Mutex;
use rand::rngs::OsRng;