From 6c0a930c76189facc3bd913c5e99b5600f15457d Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Mon, 30 Dec 2024 13:18:00 +0530 Subject: [PATCH] removed actix dependencies from fastn-wasm --- Cargo.lock | 3 +- fastn-core/Cargo.toml | 29 ++++++++++--------- fastn-core/src/commands/serve.rs | 17 ++++++++++- fastn-core/src/lib.rs | 1 + fastn-ds/src/lib.rs | 8 ++++-- v0.5/Cargo.lock | 2 +- v0.5/Cargo.toml | 2 -- v0.5/fastn-wasm/Cargo.toml | 32 ++++++++++----------- v0.5/fastn-wasm/src/lib.rs | 2 +- v0.5/fastn-wasm/src/process_http_request.rs | 15 ---------- v0.5/fastn-wasm/src/store.rs | 4 +-- 11 files changed, 58 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2f0cd00b..2f2ecf1d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1422,6 +1422,7 @@ dependencies = [ name = "fastn-core" version = "0.1.0" dependencies = [ + "actix-http", "actix-web", "antidote", "async-recursion", @@ -1615,8 +1616,6 @@ dependencies = [ name = "fastn-wasm" version = "0.1.0" dependencies = [ - "actix-http", - "actix-web", "async-lock", "bytes", "chrono", diff --git a/fastn-core/Cargo.toml b/fastn-core/Cargo.toml index b5f7080f3..d952f7c50 100644 --- a/fastn-core/Cargo.toml +++ b/fastn-core/Cargo.toml @@ -12,34 +12,38 @@ default = ["use-config-json"] use-config-json = [] [dependencies] +actix-http.workspace = true actix-web.workspace = true antidote.workspace = true async-recursion.workspace = true -scc.workspace = true -camino.workspace = true -chrono.workspace = true async-trait.workspace = true -http.workspace = true bytes.workspace = true +camino.workspace = true +chrono.workspace = true clap.workspace = true colored.workspace = true +deadpool.workspace = true diffy.workspace = true dirs.workspace = true env_logger.workspace = true -fastn-js.workspace = true fastn-ds.workspace = true -fastn-utils.workspace = true +fastn-expr.workspace = true +fastn-js.workspace = true fastn-observer.workspace = true fastn-package.workspace = true -ftd.workspace = true -ftd-p1.workspace = true -ftd-ast.workspace = true +fastn-resolved.workspace = true +fastn-runtime.workspace = true +fastn-utils.workspace = true +fastn-wasm.workspace = true ft-sys-shared.workspace = true +ftd-ast.workspace = true +ftd-p1.workspace = true +ftd.workspace = true futures-core.workspace = true futures-util.workspace = true futures.workspace = true +http.workspace = true ignore.workspace = true -deadpool.workspace = true indoc.workspace = true itertools.workspace = true mime_guess.workspace = true @@ -47,6 +51,7 @@ once_cell.workspace = true realm-lang.workspace = true regex.workspace = true reqwest.workspace = true +scc.workspace = true serde.workspace = true serde_json.workspace = true sha2.workspace = true @@ -56,10 +61,6 @@ tokio.workspace = true tracing.workspace = true url.workspace = true zip.workspace = true -fastn-expr.workspace = true -fastn-resolved.workspace = true -fastn-runtime.workspace = true -fastn-wasm.workspace = true [dev-dependencies] fbt-lib.workspace = true diff --git a/fastn-core/src/commands/serve.rs b/fastn-core/src/commands/serve.rs index ee874478b..ef8107b3a 100644 --- a/fastn-core/src/commands/serve.rs +++ b/fastn-core/src/commands/serve.rs @@ -526,7 +526,7 @@ async fn handle_endpoints( .handle_wasm(url, req, endpoint.mountpoint.to_string(), session_id) .await { - Ok(r) => Some(Ok(fastn_wasm::to_response(r))), + Ok(r) => Some(Ok(to_response(r))), Err(e) => return Some(Err(e.into())), }; } @@ -549,6 +549,21 @@ async fn handle_endpoints( Some(Ok(actix_response)) } +pub fn to_response(req: ft_sys_shared::Request) -> actix_web::HttpResponse { + println!("{req:?}"); + let mut builder = actix_web::HttpResponse::build(req.method.parse().unwrap()); + let mut resp = builder.status(req.method.parse().unwrap()).body(req.body); + + for (k, v) in req.headers { + resp.headers_mut().insert( + k.parse().unwrap(), + actix_http::header::HeaderValue::from_bytes(v.as_slice()).unwrap(), + ); + } + + resp +} + async fn handle_apps( config: &fastn_core::Config, req: &fastn_core::http::Request, diff --git a/fastn-core/src/lib.rs b/fastn-core/src/lib.rs index 4a0f6966f..5103dd5c2 100644 --- a/fastn-core/src/lib.rs +++ b/fastn-core/src/lib.rs @@ -1,5 +1,6 @@ #![recursion_limit = "256"] #![deny(unused_extern_crates)] +#![warn(unused_extern_crates)] extern crate self as fastn_core; diff --git a/fastn-ds/src/lib.rs b/fastn-ds/src/lib.rs index cca2acdb4..ba9051b2f 100644 --- a/fastn-ds/src/lib.rs +++ b/fastn-ds/src/lib.rs @@ -503,8 +503,12 @@ impl DocumentStore { headers, body: req.body().to_vec(), }; - let store = - fastn_wasm::Store::new(req, self.pg_pools.clone(), db_path, fastn_wasm::StoreImpl); + let store = fastn_wasm::Store::new( + req, + self.pg_pools.clone().into_inner(), + db_path, + fastn_wasm::StoreImpl, + ); Ok(fastn_wasm::process_http_request(&wasm_url, module, store).await?) } diff --git a/v0.5/Cargo.lock b/v0.5/Cargo.lock index a42d8a48a..e69e0c590 100644 --- a/v0.5/Cargo.lock +++ b/v0.5/Cargo.lock @@ -1059,7 +1059,6 @@ version = "0.1.0" name = "fastn-wasm" version = "0.1.0" dependencies = [ - "actix-http", "actix-web", "async-lock", "bytes", @@ -1078,6 +1077,7 @@ dependencies = [ "scc", "serde", "serde_json", + "thiserror 2.0.9", "tokio-postgres", "tracing", "wasmtime", diff --git a/v0.5/Cargo.toml b/v0.5/Cargo.toml index c674cf310..8cb999fe2 100644 --- a/v0.5/Cargo.toml +++ b/v0.5/Cargo.toml @@ -40,8 +40,6 @@ homepage = "https://fastn.com" # and create its own [dependencies.] section. Also, document it with why are you not # using the latest dependency, and what is the plan to move to the latest version. -actix-web = "4" -actix-http = "3" arcstr = "1" async-lock = "3" async-trait = "0.1" diff --git a/v0.5/fastn-wasm/Cargo.toml b/v0.5/fastn-wasm/Cargo.toml index ce7810ef2..e70b26273 100644 --- a/v0.5/fastn-wasm/Cargo.toml +++ b/v0.5/fastn-wasm/Cargo.toml @@ -9,26 +9,24 @@ repository.workspace = true homepage.workspace = true [dependencies] -actix-http.workspace = true -wasmtime.workspace = true -serde_json.workspace = true -serde.workspace = true +async-lock.workspace = true +bytes.workspace = true +chrono.workspace = true +deadpool-postgres.workspace = true +deadpool.workspace = true ft-sys-shared.workspace = true -rand.workspace = true +futures-util.workspace = true http.workspace = true -reqwest.workspace = true -chrono.workspace = true +libsqlite3-sys.workspace = true magic-crypt.workspace = true -async-lock.workspace = true -actix-web.workspace = true -tracing.workspace = true -thiserror.workspace = true -deadpool.workspace = true -deadpool-postgres.workspace = true -scc.workspace = true once_cell.workspace = true +rand.workspace = true +reqwest.workspace = true rusqlite.workspace = true -libsqlite3-sys.workspace = true +scc.workspace = true +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true tokio-postgres.workspace = true -bytes.workspace = true -futures-util.workspace = true +tracing.workspace = true +wasmtime.workspace = true diff --git a/v0.5/fastn-wasm/src/lib.rs b/v0.5/fastn-wasm/src/lib.rs index 5d0c17a19..e1d986323 100644 --- a/v0.5/fastn-wasm/src/lib.rs +++ b/v0.5/fastn-wasm/src/lib.rs @@ -19,7 +19,7 @@ mod sqlite; mod store; pub use create_pool::create_pool; -pub use process_http_request::{process_http_request, to_response}; +pub use process_http_request::process_http_request; pub(crate) use store::Conn; pub use store::{ConnectionExt, SQLError, Store, StoreExt, StoreImpl}; diff --git a/v0.5/fastn-wasm/src/process_http_request.rs b/v0.5/fastn-wasm/src/process_http_request.rs index 1b90785bd..61c60480a 100644 --- a/v0.5/fastn-wasm/src/process_http_request.rs +++ b/v0.5/fastn-wasm/src/process_http_request.rs @@ -18,21 +18,6 @@ pub async fn process_http_request( .ok_or(WasmError::EndpointDidNotReturnResponse)?) } -pub fn to_response(req: ft_sys_shared::Request) -> actix_web::HttpResponse { - println!("{req:?}"); - let mut builder = actix_web::HttpResponse::build(req.method.parse().unwrap()); - let mut resp = builder.status(req.method.parse().unwrap()).body(req.body); - - for (k, v) in req.headers { - resp.headers_mut().insert( - k.parse().unwrap(), - actix_http::header::HeaderValue::from_bytes(v.as_slice()).unwrap(), - ); - } - - resp -} - pub async fn handle( mut wasm_store: wasmtime::Store, module: wasmtime::Module, diff --git a/v0.5/fastn-wasm/src/store.rs b/v0.5/fastn-wasm/src/store.rs index 1ce2d6f35..dbdad0bd1 100644 --- a/v0.5/fastn-wasm/src/store.rs +++ b/v0.5/fastn-wasm/src/store.rs @@ -1,7 +1,7 @@ pub struct Store { pub req: ft_sys_shared::Request, pub clients: std::sync::Arc>>, - pub pg_pools: actix_web::web::Data>, + pub pg_pools: std::sync::Arc>, pub sqlite: Option>>>, pub response: Option, pub db_url: String, @@ -37,7 +37,7 @@ pub struct Conn { impl Store { pub fn new( req: ft_sys_shared::Request, - pg_pools: actix_web::web::Data>, + pg_pools: std::sync::Arc>, db_url: String, inner: STORE, ) -> Store {