Skip to content

Commit

Permalink
removed actix dependencies from fastn-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 30, 2024
1 parent 2489945 commit 6c0a930
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 57 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions fastn-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,46 @@ 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
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
Expand All @@ -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
Expand Down
17 changes: 16 additions & 1 deletion fastn-core/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
};
}
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions fastn-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![recursion_limit = "256"]
#![deny(unused_extern_crates)]
#![warn(unused_extern_crates)]

extern crate self as fastn_core;

Expand Down
8 changes: 6 additions & 2 deletions fastn-ds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}

Expand Down
2 changes: 1 addition & 1 deletion v0.5/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions v0.5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ homepage = "https://fastn.com"
# and create its own [dependencies.<name>] 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"
Expand Down
32 changes: 15 additions & 17 deletions v0.5/fastn-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion v0.5/fastn-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
15 changes: 0 additions & 15 deletions v0.5/fastn-wasm/src/process_http_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ pub async fn process_http_request<STORE: fastn_wasm::StoreExt>(
.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<S: Send>(
mut wasm_store: wasmtime::Store<S>,
module: wasmtime::Module,
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-wasm/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub struct Store<STORE: StoreExt> {
pub req: ft_sys_shared::Request,
pub clients: std::sync::Arc<async_lock::Mutex<Vec<Conn>>>,
pub pg_pools: actix_web::web::Data<scc::HashMap<String, deadpool_postgres::Pool>>,
pub pg_pools: std::sync::Arc<scc::HashMap<String, deadpool_postgres::Pool>>,
pub sqlite: Option<std::sync::Arc<async_lock::Mutex<Box<dyn ConnectionExt>>>>,
pub response: Option<ft_sys_shared::Request>,
pub db_url: String,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub struct Conn {
impl<STORE: StoreExt> Store<STORE> {
pub fn new(
req: ft_sys_shared::Request,
pg_pools: actix_web::web::Data<scc::HashMap<String, deadpool_postgres::Pool>>,
pg_pools: std::sync::Arc<scc::HashMap<String, deadpool_postgres::Pool>>,
db_url: String,
inner: STORE,
) -> Store<STORE> {
Expand Down

0 comments on commit 6c0a930

Please sign in to comment.