From da6a32ef8c11592e332537216621f4a1f8cc3bf6 Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Sun, 22 Dec 2024 19:34:16 +0530 Subject: [PATCH] mored some more helpers to fastn-wasm --- Cargo.lock | 9 ++-- fastn-ds/Cargo.toml | 3 -- fastn-ds/src/wasm/exports/http/mod.rs | 2 - fastn-ds/src/wasm/exports/mod.rs | 4 -- fastn-ds/src/wasm/exports/register.rs | 43 +++++-------------- v0.5/Cargo.toml | 8 +++- v0.5/fastn-wasm/Cargo.toml | 8 +++- .../exports => v0.5/fastn-wasm/src}/aws.rs | 0 .../exports => v0.5/fastn-wasm/src}/crypto.rs | 0 .../exports => v0.5/fastn-wasm/src}/ds.rs | 0 .../exports => v0.5/fastn-wasm/src}/env.rs | 0 v0.5/fastn-wasm/src/lib.rs | 7 +++ .../fastn-wasm/src}/send_request.rs | 0 13 files changed, 37 insertions(+), 47 deletions(-) rename {fastn-ds/src/wasm/exports => v0.5/fastn-wasm/src}/aws.rs (100%) rename {fastn-ds/src/wasm/exports => v0.5/fastn-wasm/src}/crypto.rs (100%) rename {fastn-ds/src/wasm/exports => v0.5/fastn-wasm/src}/ds.rs (100%) rename {fastn-ds/src/wasm/exports => v0.5/fastn-wasm/src}/env.rs (100%) rename {fastn-ds/src/wasm/exports/http => v0.5/fastn-wasm/src}/send_request.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index a6b3571076..5343a4d172 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1483,7 +1483,6 @@ dependencies = [ "async-trait", "bytes", "camino", - "chrono", "deadpool", "deadpool-postgres", "dirs", @@ -1494,9 +1493,7 @@ dependencies = [ "http 1.2.0", "ignore", "libsqlite3-sys", - "magic-crypt", "once_cell", - "rand", "reqwest", "rusqlite", "scc", @@ -1626,6 +1623,12 @@ dependencies = [ name = "fastn-wasm" version = "0.1.0" dependencies = [ + "chrono", + "ft-sys-shared", + "http 1.2.0", + "magic-crypt", + "rand", + "reqwest", "serde", "serde_json", "wasmtime", diff --git a/fastn-ds/Cargo.toml b/fastn-ds/Cargo.toml index fc38bd2932..cd18b6bc6a 100644 --- a/fastn-ds/Cargo.toml +++ b/fastn-ds/Cargo.toml @@ -21,14 +21,11 @@ async-lock.workspace = true http.workspace = true bytes.workspace = true camino.workspace = true -chrono.workspace = true libsqlite3-sys.workspace = true futures-util.workspace = true -magic-crypt.workspace = true async-trait.workspace = true tokio-postgres.workspace = true ignore.workspace = true -rand.workspace = true dirs.workspace = true tracing.workspace = true rusqlite.workspace = true diff --git a/fastn-ds/src/wasm/exports/http/mod.rs b/fastn-ds/src/wasm/exports/http/mod.rs index ea675b5545..2ca8ede8d7 100644 --- a/fastn-ds/src/wasm/exports/http/mod.rs +++ b/fastn-ds/src/wasm/exports/http/mod.rs @@ -1,7 +1,5 @@ mod get_request; -mod send_request; mod send_response; pub use get_request::get_request; -pub use send_request::send_request; pub use send_response::send_response; diff --git a/fastn-ds/src/wasm/exports/mod.rs b/fastn-ds/src/wasm/exports/mod.rs index 7f0013a5e8..65c4494174 100644 --- a/fastn-ds/src/wasm/exports/mod.rs +++ b/fastn-ds/src/wasm/exports/mod.rs @@ -1,7 +1,3 @@ -mod aws; -mod crypto; -mod ds; -mod env; mod http; mod pg; mod register; diff --git a/fastn-ds/src/wasm/exports/register.rs b/fastn-ds/src/wasm/exports/register.rs index b90877e1cd..900e8af43c 100644 --- a/fastn-ds/src/wasm/exports/register.rs +++ b/fastn-ds/src/wasm/exports/register.rs @@ -1,22 +1,14 @@ impl fastn_ds::wasm::Store { pub fn register_functions(&self, linker: &mut wasmtime::Linker) { // general utility functions - fastn_ds::func2!(linker, "env_print", fastn_ds::wasm::exports::env::print); - fastn_ds::func0ret!(linker, "env_now", fastn_ds::wasm::exports::env::now); - fastn_ds::func2ret!(linker, "env_var", fastn_ds::wasm::exports::env::var); - fastn_ds::func0ret!(linker, "env_random", fastn_ds::wasm::exports::env::random); + fastn_ds::func2!(linker, "env_print", fastn_wasm::env::print); + fastn_ds::func0ret!(linker, "env_now", fastn_wasm::env::now); + fastn_ds::func2ret!(linker, "env_var", fastn_wasm::env::var); + fastn_ds::func0ret!(linker, "env_random", fastn_wasm::env::random); // cryptography related stuff - fastn_ds::func2ret!( - linker, - "crypto_encrypt", - fastn_ds::wasm::exports::crypto::encrypt - ); - fastn_ds::func2ret!( - linker, - "crypto_decrypt", - fastn_ds::wasm::exports::crypto::decrypt - ); + fastn_ds::func2ret!(linker, "crypto_encrypt", fastn_wasm::crypto::encrypt); + fastn_ds::func2ret!(linker, "crypto_decrypt", fastn_wasm::crypto::decrypt); // sqlite fastn_ds::func2ret!( @@ -57,13 +49,7 @@ impl fastn_ds::wasm::Store { "http_get_request", fastn_ds::wasm::exports::http::get_request ); - - fastn_ds::func2ret!( - linker, - "http_send_request", - fastn_ds::wasm::exports::http::send_request - ); - + fastn_ds::func2ret!(linker, "http_send_request", fastn_wasm::send_request); fastn_ds::func2!( linker, "http_send_response", @@ -71,23 +57,14 @@ impl fastn_ds::wasm::Store { ); // document store related - fastn_ds::func2ret!( - linker, - "hostn_tejar_write", - fastn_ds::wasm::exports::ds::tejar_write - ); - - fastn_ds::func2ret!( - linker, - "hostn_tejar_read", - fastn_ds::wasm::exports::ds::tejar_read - ); + fastn_ds::func2ret!(linker, "hostn_tejar_write", fastn_wasm::ds::tejar_write); + fastn_ds::func2ret!(linker, "hostn_tejar_read", fastn_wasm::ds::tejar_read); // aws fastn_ds::func2ret!( linker, "hostn_aws_pre_signed_request", - fastn_ds::wasm::exports::aws::pre_signed_request + fastn_wasm::aws::pre_signed_request ); } } diff --git a/v0.5/Cargo.toml b/v0.5/Cargo.toml index 826c895dba..ae3c4d2be9 100644 --- a/v0.5/Cargo.toml +++ b/v0.5/Cargo.toml @@ -45,20 +45,26 @@ async-trait = "0.1" fastn-builtins = { path = "../fastn-builtins" } fastn-compiler = { path = "fastn-compiler" } fastn-continuation = { path = "fastn-continuation" } -fastn-resolved = { path = "../fastn-resolved" } fastn-package = { path = "fastn-package" } +fastn-resolved = { path = "../fastn-resolved" } fastn-router = { path = "fastn-router" } fastn-runtime = { path = "../fastn-runtime" } fastn-section = { path = "fastn-section" } fastn-unresolved = { path = "fastn-unresolved" } +ft-sys-shared = "0.1.4" +http = "1" http-body-util = "0.1" hyper = { version = "1.5.1", features = ["server", "http1"] } hyper-util = { version = "0.1.10", features = ["tokio"] } id-arena = "2" indexmap = "2" +rand = "0.8" +reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } serde = { version = "1", features = ["derive"] } serde_json = "1" string-interner = "0.18" tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] } wasmtime = "28" +chrono = { version = "0.4", features = ["serde"] } +magic-crypt = { version = "4", default-features = false } diff --git a/v0.5/fastn-wasm/Cargo.toml b/v0.5/fastn-wasm/Cargo.toml index c04bb76ac1..25ac593355 100644 --- a/v0.5/fastn-wasm/Cargo.toml +++ b/v0.5/fastn-wasm/Cargo.toml @@ -11,4 +11,10 @@ homepage.workspace = true [dependencies] wasmtime.workspace = true serde_json.workspace = true -serde.workspace = true \ No newline at end of file +serde.workspace = true +ft-sys-shared.workspace = true +rand.workspace = true +http.workspace = true +reqwest.workspace = true +chrono.workspace = true +magic-crypt.workspace = true \ No newline at end of file diff --git a/fastn-ds/src/wasm/exports/aws.rs b/v0.5/fastn-wasm/src/aws.rs similarity index 100% rename from fastn-ds/src/wasm/exports/aws.rs rename to v0.5/fastn-wasm/src/aws.rs diff --git a/fastn-ds/src/wasm/exports/crypto.rs b/v0.5/fastn-wasm/src/crypto.rs similarity index 100% rename from fastn-ds/src/wasm/exports/crypto.rs rename to v0.5/fastn-wasm/src/crypto.rs diff --git a/fastn-ds/src/wasm/exports/ds.rs b/v0.5/fastn-wasm/src/ds.rs similarity index 100% rename from fastn-ds/src/wasm/exports/ds.rs rename to v0.5/fastn-wasm/src/ds.rs diff --git a/fastn-ds/src/wasm/exports/env.rs b/v0.5/fastn-wasm/src/env.rs similarity index 100% rename from fastn-ds/src/wasm/exports/env.rs rename to v0.5/fastn-wasm/src/env.rs diff --git a/v0.5/fastn-wasm/src/lib.rs b/v0.5/fastn-wasm/src/lib.rs index 4966181e35..6707079e39 100644 --- a/v0.5/fastn-wasm/src/lib.rs +++ b/v0.5/fastn-wasm/src/lib.rs @@ -4,4 +4,11 @@ extern crate self as fastn_wasm; +pub mod aws; +pub mod crypto; +pub mod ds; +pub mod env; pub mod helpers; +pub mod send_request; + +pub use send_request::send_request; diff --git a/fastn-ds/src/wasm/exports/http/send_request.rs b/v0.5/fastn-wasm/src/send_request.rs similarity index 100% rename from fastn-ds/src/wasm/exports/http/send_request.rs rename to v0.5/fastn-wasm/src/send_request.rs