From a5433fbc74f4c140db0c27c14cb3f1a14abe860e Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 8 Mar 2026 11:38:16 -0700 Subject: [PATCH] Remove unused yaak-proxy-models crate Replaced by a purpose-built ProxyEntry model to be added to yaak-proxy-lib, which better handles multi-protocol capture (HTTP, gRPC, GraphQL, WebSocket) without REST-specific assumptions. Co-Authored-By: Claude Sonnet 4.6 --- Cargo.lock | 17 -- Cargo.toml | 2 - crates-proxy/yaak-proxy-models/Cargo.toml | 18 -- .../migrations/00000001_init.sql | 35 ---- crates-proxy/yaak-proxy-models/src/error.rs | 1 - crates-proxy/yaak-proxy-models/src/lib.rs | 73 -------- crates-proxy/yaak-proxy-models/src/models.rs | 160 ------------------ 7 files changed, 306 deletions(-) delete mode 100644 crates-proxy/yaak-proxy-models/Cargo.toml delete mode 100644 crates-proxy/yaak-proxy-models/migrations/00000001_init.sql delete mode 100644 crates-proxy/yaak-proxy-models/src/error.rs delete mode 100644 crates-proxy/yaak-proxy-models/src/lib.rs delete mode 100644 crates-proxy/yaak-proxy-models/src/models.rs diff --git a/Cargo.lock b/Cargo.lock index 8f863d87..78730d75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10602,23 +10602,6 @@ dependencies = [ "yaak-rpc", ] -[[package]] -name = "yaak-proxy-models" -version = "0.1.0" -dependencies = [ - "chrono", - "include_dir", - "log 0.4.29", - "r2d2", - "r2d2_sqlite", - "rusqlite", - "sea-query", - "serde", - "serde_json", - "thiserror 2.0.17", - "yaak-database", -] - [[package]] name = "yaak-rpc" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 19990e8a..30af53cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ members = [ "crates/yaak-api", "crates/yaak-proxy", # Proxy-specific crates - "crates-proxy/yaak-proxy-models", "crates-proxy/yaak-proxy-lib", # CLI crates "crates-cli/yaak-cli", @@ -79,7 +78,6 @@ yaak-api = { path = "crates/yaak-api" } yaak-proxy = { path = "crates/yaak-proxy" } # Internal crates - proxy -yaak-proxy-models = { path = "crates-proxy/yaak-proxy-models" } yaak-proxy-lib = { path = "crates-proxy/yaak-proxy-lib" } # Internal crates - Tauri-specific diff --git a/crates-proxy/yaak-proxy-models/Cargo.toml b/crates-proxy/yaak-proxy-models/Cargo.toml deleted file mode 100644 index d73e6905..00000000 --- a/crates-proxy/yaak-proxy-models/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "yaak-proxy-models" -version = "0.1.0" -edition = "2024" -publish = false - -[dependencies] -chrono = { version = "0.4.38", features = ["serde"] } -include_dir = "0.7" -log = { workspace = true } -r2d2 = "0.8.10" -r2d2_sqlite = { version = "0.25.0" } -rusqlite = { version = "0.32.1", features = ["bundled", "chrono"] } -sea-query = { version = "0.32.1", features = ["with-chrono", "attr"] } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } -thiserror = { workspace = true } -yaak-database = { workspace = true } diff --git a/crates-proxy/yaak-proxy-models/migrations/00000001_init.sql b/crates-proxy/yaak-proxy-models/migrations/00000001_init.sql deleted file mode 100644 index eb92e876..00000000 --- a/crates-proxy/yaak-proxy-models/migrations/00000001_init.sql +++ /dev/null @@ -1,35 +0,0 @@ --- Proxy version of http_responses, duplicated from client. --- No workspace_id/request_id foreign keys — proxy captures raw traffic. -CREATE TABLE proxy_http_responses ( - id TEXT NOT NULL PRIMARY KEY, - model TEXT DEFAULT 'proxy_http_response' NOT NULL, - proxy_request_id INTEGER NOT NULL, - created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, - updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, - elapsed INTEGER NOT NULL DEFAULT 0, - elapsed_headers INTEGER NOT NULL DEFAULT 0, - elapsed_dns INTEGER NOT NULL DEFAULT 0, - status INTEGER NOT NULL DEFAULT 0, - status_reason TEXT, - url TEXT NOT NULL, - headers TEXT NOT NULL DEFAULT '[]', - request_headers TEXT NOT NULL DEFAULT '[]', - error TEXT, - body_path TEXT, - content_length INTEGER, - content_length_compressed INTEGER, - request_content_length INTEGER, - remote_addr TEXT, - version TEXT, - state TEXT DEFAULT 'initialized' NOT NULL -); -CREATE INDEX idx_proxy_http_responses_created_at ON proxy_http_responses (created_at DESC); - --- Inline body storage (proxy keeps everything self-contained in one DB file) -CREATE TABLE proxy_http_response_bodies ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - response_id TEXT NOT NULL REFERENCES proxy_http_responses(id) ON DELETE CASCADE, - body_type TEXT NOT NULL, - data BLOB NOT NULL, - UNIQUE(response_id, body_type) -); diff --git a/crates-proxy/yaak-proxy-models/src/error.rs b/crates-proxy/yaak-proxy-models/src/error.rs deleted file mode 100644 index 2e4bfc78..00000000 --- a/crates-proxy/yaak-proxy-models/src/error.rs +++ /dev/null @@ -1 +0,0 @@ -pub use yaak_database::error::{Error, Result}; diff --git a/crates-proxy/yaak-proxy-models/src/lib.rs b/crates-proxy/yaak-proxy-models/src/lib.rs deleted file mode 100644 index 3ce268b0..00000000 --- a/crates-proxy/yaak-proxy-models/src/lib.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::error::{Error, Result}; -use include_dir::{Dir, include_dir}; -use log::info; -use r2d2::Pool; -use r2d2_sqlite::SqliteConnectionManager; -use std::fs::create_dir_all; -use std::path::Path; -use std::sync::{Arc, Mutex}; -use std::time::Duration; -use yaak_database::{ConnectionOrTx, DbContext}; - -pub mod error; -pub mod models; - -static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/migrations"); - -/// Manages the proxy session database pool. -/// Use `connect()` to get a `DbContext` for running queries. -#[derive(Debug, Clone)] -pub struct ProxyDb { - pool: Arc>>, -} - -impl ProxyDb { - pub fn connect(&self) -> DbContext<'_> { - let conn = self - .pool - .lock() - .expect("Failed to gain lock on proxy DB") - .get() - .expect("Failed to get proxy DB connection from pool"); - DbContext::new(ConnectionOrTx::Connection(conn)) - } -} - -pub fn init_standalone(db_path: impl AsRef) -> Result { - let db_path = db_path.as_ref(); - - if let Some(parent) = db_path.parent() { - create_dir_all(parent)?; - } - - info!("Initializing proxy session database {db_path:?}"); - let manager = SqliteConnectionManager::file(db_path); - let pool = Pool::builder() - .max_size(100) - .connection_timeout(Duration::from_secs(10)) - .build(manager) - .map_err(|e| Error::Database(e.to_string()))?; - - pool.get()?.execute_batch( - "PRAGMA journal_mode=WAL; - PRAGMA foreign_keys=ON;", - )?; - - yaak_database::run_migrations(&pool, &MIGRATIONS_DIR)?; - - Ok(ProxyDb { pool: Arc::new(Mutex::new(pool)) }) -} - -pub fn init_in_memory() -> Result { - let manager = SqliteConnectionManager::memory(); - let pool = Pool::builder() - .max_size(1) - .build(manager) - .map_err(|e| Error::Database(e.to_string()))?; - - pool.get()?.execute_batch("PRAGMA foreign_keys=ON;")?; - - yaak_database::run_migrations(&pool, &MIGRATIONS_DIR)?; - - Ok(ProxyDb { pool: Arc::new(Mutex::new(pool)) }) -} diff --git a/crates-proxy/yaak-proxy-models/src/models.rs b/crates-proxy/yaak-proxy-models/src/models.rs deleted file mode 100644 index 84a5926b..00000000 --- a/crates-proxy/yaak-proxy-models/src/models.rs +++ /dev/null @@ -1,160 +0,0 @@ -use chrono::NaiveDateTime; -use rusqlite::Row; -use sea_query::Order::Desc; -use sea_query::{IntoColumnRef, IntoIden, IntoTableRef, Order, SimpleExpr, enum_def}; -use serde::{Deserialize, Serialize}; -use yaak_database::{ - UpsertModelInfo, UpdateSource, Result as DbResult, - generate_prefixed_id, upsert_date, -}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum HttpResponseState { - Initialized, - Connected, - Closed, -} - -impl Default for HttpResponseState { - fn default() -> Self { - Self::Initialized - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct HttpResponseHeader { - pub name: String, - pub value: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Default)] -#[serde(default, rename_all = "camelCase")] -#[enum_def(table_name = "proxy_http_responses")] -pub struct HttpResponse { - pub model: String, - pub id: String, - pub proxy_request_id: i64, - pub created_at: NaiveDateTime, - pub updated_at: NaiveDateTime, - pub elapsed: i32, - pub elapsed_headers: i32, - pub elapsed_dns: i32, - pub status: i32, - pub status_reason: Option, - pub url: String, - pub headers: Vec, - pub request_headers: Vec, - pub error: Option, - pub body_path: Option, - pub content_length: Option, - pub content_length_compressed: Option, - pub request_content_length: Option, - pub remote_addr: Option, - pub version: Option, - pub state: HttpResponseState, -} - -impl UpsertModelInfo for HttpResponse { - fn table_name() -> impl IntoTableRef + IntoIden { - HttpResponseIden::Table - } - - fn id_column() -> impl IntoIden + Eq + Clone { - HttpResponseIden::Id - } - - fn generate_id() -> String { - generate_prefixed_id("rs") - } - - fn order_by() -> (impl IntoColumnRef, Order) { - (HttpResponseIden::CreatedAt, Desc) - } - - fn get_id(&self) -> String { - self.id.clone() - } - - fn insert_values( - self, - source: &UpdateSource, - ) -> DbResult)>> { - use HttpResponseIden::*; - Ok(vec![ - (CreatedAt, upsert_date(source, self.created_at)), - (UpdatedAt, upsert_date(source, self.updated_at)), - (ProxyRequestId, self.proxy_request_id.into()), - (BodyPath, self.body_path.into()), - (ContentLength, self.content_length.into()), - (ContentLengthCompressed, self.content_length_compressed.into()), - (Elapsed, self.elapsed.into()), - (ElapsedHeaders, self.elapsed_headers.into()), - (ElapsedDns, self.elapsed_dns.into()), - (Error, self.error.into()), - (Headers, serde_json::to_string(&self.headers)?.into()), - (RemoteAddr, self.remote_addr.into()), - (RequestContentLength, self.request_content_length.into()), - (RequestHeaders, serde_json::to_string(&self.request_headers)?.into()), - (State, serde_json::to_value(&self.state)?.as_str().into()), - (Status, self.status.into()), - (StatusReason, self.status_reason.into()), - (Url, self.url.into()), - (Version, self.version.into()), - ]) - } - - fn update_columns() -> Vec { - vec![ - HttpResponseIden::UpdatedAt, - HttpResponseIden::BodyPath, - HttpResponseIden::ContentLength, - HttpResponseIden::ContentLengthCompressed, - HttpResponseIden::Elapsed, - HttpResponseIden::ElapsedHeaders, - HttpResponseIden::ElapsedDns, - HttpResponseIden::Error, - HttpResponseIden::Headers, - HttpResponseIden::RemoteAddr, - HttpResponseIden::RequestContentLength, - HttpResponseIden::RequestHeaders, - HttpResponseIden::State, - HttpResponseIden::Status, - HttpResponseIden::StatusReason, - HttpResponseIden::Url, - HttpResponseIden::Version, - ] - } - - fn from_row(r: &Row) -> rusqlite::Result - where - Self: Sized, - { - let headers: String = r.get("headers")?; - let request_headers: String = r.get("request_headers")?; - let state: String = r.get("state")?; - Ok(Self { - id: r.get("id")?, - model: r.get("model")?, - proxy_request_id: r.get("proxy_request_id")?, - created_at: r.get("created_at")?, - updated_at: r.get("updated_at")?, - error: r.get("error")?, - url: r.get("url")?, - content_length: r.get("content_length")?, - content_length_compressed: r.get("content_length_compressed").unwrap_or_default(), - version: r.get("version")?, - elapsed: r.get("elapsed")?, - elapsed_headers: r.get("elapsed_headers")?, - elapsed_dns: r.get("elapsed_dns").unwrap_or_default(), - remote_addr: r.get("remote_addr")?, - status: r.get("status")?, - status_reason: r.get("status_reason")?, - state: serde_json::from_str(format!(r#""{state}""#).as_str()).unwrap_or_default(), - body_path: r.get("body_path")?, - headers: serde_json::from_str(headers.as_str()).unwrap_or_default(), - request_content_length: r.get("request_content_length").unwrap_or_default(), - request_headers: serde_json::from_str(request_headers.as_str()).unwrap_or_default(), - }) - } -}