types.rs (1934B)
1 //! Shared types for the Beegram network layer 2 //! 3 //! Record types are auto-generated from TrailBase schemas. 4 //! See the `generated` module for schema-derived types. 5 6 use serde::{Deserialize, Serialize}; 7 8 // Re-export auto-generated types from TrailBase schemas 9 pub use crate::generated::{Chat, Message, NewChat, NewChatParticipation, NewMessage, UserChat}; 10 11 /// Base URL for the TrailBase API 12 pub const BASE_URL: &str = "http://localhost:4000"; 13 14 /// Maximum number of message IDs to cache for deduplication 15 pub const MAX_MESSAGE_CACHE: usize = 50; 16 17 /// Maximum SSE buffer size (64KB) 18 pub const MAX_SSE_BUFFER_SIZE: usize = 65536; 19 20 /// Maximum reconnect delay in milliseconds 21 pub const MAX_RECONNECT_DELAY_MS: u64 = 30000; 22 23 // ==================== Auth Types ==================== 24 25 /// Login request payload 26 #[derive(Debug, Serialize)] 27 pub struct LoginRequest { 28 pub email: String, 29 pub password: String, 30 } 31 32 /// Login response from the API 33 #[derive(Debug, Deserialize)] 34 pub struct LoginResponse { 35 pub auth_token: String, 36 } 37 38 // ==================== SSE Types ==================== 39 40 /// SSE event wrapper from TrailBase 41 #[derive(Debug, Deserialize)] 42 pub struct SseEventWrapper { 43 #[serde(rename = "Insert")] 44 pub insert: Option<serde_json::Value>, 45 } 46 47 // ==================== Error Types ==================== 48 49 /// Network error types 50 #[derive(Debug, thiserror::Error)] 51 pub enum NetworkError { 52 #[error("TrailBase client error: {0}")] 53 TrailBase(#[from] trailbase_client::Error), 54 55 #[error("JSON error: {0}")] 56 Json(#[from] serde_json::Error), 57 58 #[error("API error: {status} - {message}")] 59 Api { status: u16, message: String }, 60 61 #[error("Missing field: {0}")] 62 MissingField(String), 63 64 #[error("Invalid response: {0}")] 65 InvalidResponse(String), 66 } 67 68 /// Credential storage error types 69 #[derive(Debug, thiserror::Error)] 70 pub enum KeychainError { 71 #[error("No token found")] 72 NotFound, 73 }