From cf205eea39b973a1b70064c90b4b2825f59be60e Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Sun, 22 Dec 2024 19:16:46 +0530 Subject: [PATCH] helpers moved to fastn-wasm --- Cargo.lock | 196 +++++++++--------- Cargo.toml | 3 +- fastn-ds/Cargo.toml | 1 + fastn-ds/src/wasm/exports/crypto.rs | 8 +- fastn-ds/src/wasm/exports/env.rs | 10 +- fastn-ds/src/wasm/exports/http/get_request.rs | 2 +- .../src/wasm/exports/http/send_request.rs | 4 +- .../src/wasm/exports/http/send_response.rs | 2 +- fastn-ds/src/wasm/exports/pg/batch_execute.rs | 4 +- fastn-ds/src/wasm/exports/pg/connect.rs | 2 +- fastn-ds/src/wasm/exports/pg/execute.rs | 4 +- fastn-ds/src/wasm/exports/pg/query.rs | 4 +- .../src/wasm/exports/sqlite/batch_execute.rs | 4 +- fastn-ds/src/wasm/exports/sqlite/connect.rs | 2 +- fastn-ds/src/wasm/exports/sqlite/execute.rs | 4 +- fastn-ds/src/wasm/exports/sqlite/query.rs | 4 +- fastn-ds/src/wasm/mod.rs | 1 - v0.5/Cargo.lock | 4 + v0.5/Cargo.toml | 2 + v0.5/fastn-wasm/Cargo.toml | 14 ++ .../wasm => v0.5/fastn-wasm/src}/helpers.rs | 5 +- v0.5/fastn-wasm/src/lib.rs | 7 + 22 files changed, 155 insertions(+), 132 deletions(-) create mode 100644 v0.5/fastn-wasm/Cargo.toml rename {fastn-ds/src/wasm => v0.5/fastn-wasm/src}/helpers.rs (96%) create mode 100644 v0.5/fastn-wasm/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ff204061e5..3ca7381000 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -541,6 +547,9 @@ name = "bumpalo" version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +dependencies = [ + "allocator-api2", +] [[package]] name = "byteorder" @@ -826,18 +835,18 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ba4f80548f22dc9c43911907b5e322c5555544ee85f785115701e6a28c9abe1" +checksum = "ac89549be94911dd0e839b4a7db99e9ed29c17517e1c026f61066884c168aa3c" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-bitset" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "005884e3649c3e5ff2dc79e8a94b138f11569cc08a91244a292714d2a86e9156" +checksum = "b9bd49369f76c77e34e641af85d0956869237832c118964d08bf5f51f210875a" dependencies = [ "serde", "serde_derive", @@ -845,9 +854,9 @@ dependencies = [ [[package]] name = "cranelift-codegen" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4036255ec33ce9a37495dfbcfc4e1118fd34e693eff9a1e106336b7cd16a9b" +checksum = "fd96ce9cf8efebd7f5ab8ced5a0ce44250280bbae9f593d74a6d7effc3582a35" dependencies = [ "bumpalo", "cranelift-bforest", @@ -869,33 +878,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ca74f4b68319da11d39e894437cb6e20ec7c2e11fbbda823c3bf207beedff7" +checksum = "5a68e358827afe4bfb6239fcbf6fbd5ac56206ece8a99c8f5f9bbd518773281a" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897e54f433a0269c4187871aa06d452214d5515d228d5bdc22219585e9eef895" +checksum = "e184c9767afbe73d50c55ec29abcf4c32f9baf0d9d22b86d58c4d55e06dee181" [[package]] name = "cranelift-control" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29cb4018f5bf59fb53f515fa9d80e6f8c5ce19f198dc538984ebd23ecf8965ec" +checksum = "5cc7664f2a66f053e33f149e952bb5971d138e3af637f5097727ed6dc0ed95dd" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305399fd781a2953ac78c1396f02ff53144f39c33eb7fc7789cf4e8936d13a96" +checksum = "118597e3a9cf86c3556fa579a7a23b955fa18231651a52a77a2475d305a9cf84" dependencies = [ "cranelift-bitset", "serde", @@ -904,9 +913,9 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9230b460a128d53653456137751d27baf567947a3ab8c0c4d6e31fd08036d81e" +checksum = "7638ea1efb069a0aa18d8ee67401b6b0d19f6bfe5de5e9ede348bfc80bb0d8c7" dependencies = [ "cranelift-codegen", "log", @@ -916,15 +925,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b961e24ae3ec9813a24a15ae64bbd2a42e4de4d79a7f3225a412e3b94e78d1c8" +checksum = "15c53e1152a0b01c4ed2b1e0535602b8e86458777dd9d18b28732b16325c7dc0" [[package]] name = "cranelift-native" -version = "0.114.0" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5bd76df6c9151188dfa428c863b33da5b34561b67f43c0cf3f24a794f9fa1f" +checksum = "7b7d8f895444fa52dd7bdd0bed11bf007a7fb43af65a6deac8fcc4094c6372f7" dependencies = [ "cranelift-codegen", "libc", @@ -1479,6 +1488,7 @@ dependencies = [ "deadpool-postgres", "dirs", "fastn-utils", + "fastn-wasm", "ft-sys-shared", "futures-util", "http 1.2.0", @@ -1612,6 +1622,15 @@ dependencies = [ "wasmtime", ] +[[package]] +name = "fastn-wasm" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "wasmtime", +] + [[package]] name = "fbt" version = "0.1.18" @@ -1924,7 +1943,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", - "serde", ] [[package]] @@ -1934,6 +1952,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "foldhash", + "serde", ] [[package]] @@ -2978,9 +2997,9 @@ dependencies = [ [[package]] name = "pulley-interpreter" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b8d81cf799e20564931e9867ca32de545188c6ee4c2e0f6e41d32f0c7dc6fb" +checksum = "403a1a95f4c18a45c86c7bff13df00347afd0abcbf2e54af273c837339ffcf77" dependencies = [ "cranelift-bitset", "log", @@ -3152,14 +3171,15 @@ dependencies = [ [[package]] name = "regalloc2" -version = "0.10.2" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12908dbeb234370af84d0579b9f68258a0f67e201412dd9a2814e6f45b2fc0f0" +checksum = "145c1c267e14f20fb0f88aa76a1c5ffec42d592c1d28b3cd9148ae35916158d3" dependencies = [ - "hashbrown 0.14.5", + "allocator-api2", + "bumpalo", + "hashbrown 0.15.2", "log", "rustc-hash", - "slice-group-by", "smallvec", ] @@ -3580,12 +3600,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "slice-group-by" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" - [[package]] name = "slug" version = "0.1.6" @@ -4296,16 +4310,6 @@ version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" -[[package]] -name = "wasm-encoder" -version = "0.219.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29cbbd772edcb8e7d524a82ee8cef8dd046fc14033796a754c3ad246d019fa54" -dependencies = [ - "leb128", - "wasmparser 0.219.1", -] - [[package]] name = "wasm-encoder" version = "0.221.2" @@ -4313,21 +4317,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c17a3bd88f2155da63a1f2fcb8a56377a24f0b6dfed12733bb5f544e86f690c5" dependencies = [ "leb128", - "wasmparser 0.221.2", -] - -[[package]] -name = "wasmparser" -version = "0.219.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c771866898879073c53b565a6c7b49953795159836714ac56a5befb581227c5" -dependencies = [ - "ahash", - "bitflags 2.6.0", - "hashbrown 0.14.5", - "indexmap", - "semver", - "serde", + "wasmparser", ] [[package]] @@ -4337,26 +4327,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9845c470a2e10b61dd42c385839cdd6496363ed63b5c9e420b5488b77bd22083" dependencies = [ "bitflags 2.6.0", + "hashbrown 0.15.2", "indexmap", "semver", + "serde", ] [[package]] name = "wasmprinter" -version = "0.219.1" +version = "0.221.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228cdc1f30c27816da225d239ce4231f28941147d34713dee8f1fff7cb330e54" +checksum = "a80742ff1b9e6d8c231ac7c7247782c6fc5bce503af760bca071811e5fc9ee56" dependencies = [ "anyhow", "termcolor", - "wasmparser 0.219.1", + "wasmparser", ] [[package]] name = "wasmtime" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b79302e3e084713249cc5622e8608e7410afdeeea8c8026d04f491d1fab0b4b" +checksum = "f639ecae347b9a2227e453a7b7671e84370a0b61f47a15e0390fe9b7725e47b3" dependencies = [ "addr2line", "anyhow", @@ -4391,8 +4383,8 @@ dependencies = [ "smallvec", "sptr", "target-lexicon", - "wasm-encoder 0.219.1", - "wasmparser 0.219.1", + "wasm-encoder", + "wasmparser", "wasmtime-asm-macros", "wasmtime-cache", "wasmtime-component-macro", @@ -4411,18 +4403,18 @@ dependencies = [ [[package]] name = "wasmtime-asm-macros" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe53a24e7016a5222875d8ca3ad6024b464465985693c42098cd0bb710002c28" +checksum = "882a18800471cfc063c8b3ccf75723784acc3fd534009ac09421f2fac2fcdcec" dependencies = [ "cfg-if", ] [[package]] name = "wasmtime-cache" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0677a7e76c24746b68e3657f7cc50c0ff122ee7e97bbda6e710c1b790ebc93cb" +checksum = "368d974999abe6095341da9b9e2c0908a6272e796001e06b7022ad60b2d19710" dependencies = [ "anyhow", "base64 0.21.7", @@ -4440,9 +4432,9 @@ dependencies = [ [[package]] name = "wasmtime-component-macro" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e118acbd2bc09b32ad8606bc7cef793bf5019c1b107772e64dc6c76b5055d40b" +checksum = "eb5c0a77c9e1927c3d471f53cc13767c3d3438e5d5ffd394e3eb31c86445fd60" dependencies = [ "anyhow", "proc-macro2", @@ -4455,15 +4447,15 @@ dependencies = [ [[package]] name = "wasmtime-component-util" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6db4f3ee18c699629eabb9c64e77efe5a93a5137f098db7cab295037ba41c2" +checksum = "43702ca98bf5162eca0573db691ed9ecd36d716f8c6688410fe26ec16b6f9bcb" [[package]] name = "wasmtime-cranelift" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b87e6c78f562b50aff1afd87ff32a57e241424c846c1c8f3c5fd352d2d62906" +checksum = "20070aa5b75080a8932ec328419faf841df2bc6ceb16b55b0df2b952098392a2" dependencies = [ "anyhow", "cfg-if", @@ -4479,16 +4471,16 @@ dependencies = [ "smallvec", "target-lexicon", "thiserror 1.0.69", - "wasmparser 0.219.1", + "wasmparser", "wasmtime-environ", "wasmtime-versioned-export-macros", ] [[package]] name = "wasmtime-environ" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c25bfeaa16432d59a0706e2463d315ef4c9ebcfaf5605670b99d46373bdf9f27" +checksum = "2604ddb24879d4dc1dedcb7081d7a8e017259bce916fdae097a97db52cbaab80" dependencies = [ "anyhow", "cpp_demangle", @@ -4505,17 +4497,17 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasm-encoder 0.219.1", - "wasmparser 0.219.1", + "wasm-encoder", + "wasmparser", "wasmprinter", "wasmtime-component-util", ] [[package]] name = "wasmtime-fiber" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759ab0caa3821a6211743fe1eed448ab9df439e3af6c60dea15486c055611806" +checksum = "98593412d2b167ebe2b59d4a17a184978a72f976b53b3a0ec05629451079ac1d" dependencies = [ "anyhow", "cc", @@ -4528,9 +4520,9 @@ dependencies = [ [[package]] name = "wasmtime-jit-debug" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab2a056056e9ac6916c2b8e4743408560300c1355e078c344211f13210d449b3" +checksum = "2caed0122664573c2bbcde649515f9e1bc783b14f2ba74b999720cf0225e234d" dependencies = [ "object", "rustix", @@ -4539,9 +4531,9 @@ dependencies = [ [[package]] name = "wasmtime-jit-icache-coherence" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91b218a92866f74f35162f5d03a4e0f62cd0e1cc624285b1014275e5d4575fad" +checksum = "d40d7722b9e1fbeae135715710a8a2570b1e6cf72b74dd653962d89831c6c70d" dependencies = [ "anyhow", "cfg-if", @@ -4551,15 +4543,15 @@ dependencies = [ [[package]] name = "wasmtime-slab" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5f8acf677ee6b3b8ba400dd9753ea4769e56a95c4b30b045ac6d2d54b2f8ea" +checksum = "8579c335220b4ece9aa490a0e8b46de78cd342b195ab21ff981d095e14b52383" [[package]] name = "wasmtime-versioned-export-macros" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df09be00c38f49172ca9936998938476e3f2df782673a39ae2ef9fb0838341b6" +checksum = "d7de0a56fb0a69b185968f2d7a9ba54750920a806470dff7ad8de91ac06d277e" dependencies = [ "proc-macro2", "quote", @@ -4568,16 +4560,16 @@ dependencies = [ [[package]] name = "wasmtime-winch" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d6b5297bea14d8387c3974b2b011de628cc9b188f135cec752b74fd368964b" +checksum = "abd309943c443f5590d12f9aba9ba63c481091c955a0a14de0c2a9e0e3aaeca9" dependencies = [ "anyhow", "cranelift-codegen", "gimli", "object", "target-lexicon", - "wasmparser 0.219.1", + "wasmparser", "wasmtime-cranelift", "wasmtime-environ", "winch-codegen", @@ -4585,9 +4577,9 @@ dependencies = [ [[package]] name = "wasmtime-wit-bindgen" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf3963c9c29df91564d8bd181eb00d0dbaeafa1b2a01e15952bb7391166b704e" +checksum = "969f83022dac3435d6469edb582ceed04cfe32aa44dc3ef16e5cb55574633df8" dependencies = [ "anyhow", "heck", @@ -4605,7 +4597,7 @@ dependencies = [ "leb128", "memchr", "unicode-width 0.2.0", - "wasm-encoder 0.221.2", + "wasm-encoder", ] [[package]] @@ -4690,9 +4682,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "winch-codegen" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b42b678c8651ec4900d7600037d235429fc985c31cbc33515885ec0d2a9e158" +checksum = "9110decc2983ed94de904804dcd979ba59cbabc78a94fec6b1d8468ec513d0f6" dependencies = [ "anyhow", "cranelift-codegen", @@ -4700,7 +4692,7 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "wasmparser 0.219.1", + "wasmparser", "wasmtime-cranelift", "wasmtime-environ", ] @@ -4912,9 +4904,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.219.1" +version = "0.221.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a86f669283257e8e424b9a4fc3518e3ade0b95deb9fbc0f93a1876be3eda598" +checksum = "fbe1538eea6ea5ddbe5defd0dc82539ad7ba751e1631e9185d24a931f0a5adc8" dependencies = [ "anyhow", "id-arena", @@ -4925,7 +4917,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.219.1", + "wasmparser", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d622288dcd..1e9d098e37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ enum-iterator = "0.6" enum-iterator-derive = "0.6" fastn-ds.path = "fastn-ds" fastn-update.path = "fastn-update" +fastn-wasm.path = "v0.5/fastn-wasm" fastn-builtins.path = "fastn-builtins" fastn-resolved = { path = "fastn-resolved" } fastn-core.path = "fastn-core" @@ -128,7 +129,7 @@ tracing = "0.1" scc = "2" url = "2" walkdir = "2" -wasmtime = "27" +wasmtime = "28" zip = "2" prettify-js = "0.1.0" indexmap = { version = "2", features = ["serde"] } diff --git a/fastn-ds/Cargo.toml b/fastn-ds/Cargo.toml index f5a388adc3..fc38bd2932 100644 --- a/fastn-ds/Cargo.toml +++ b/fastn-ds/Cargo.toml @@ -10,6 +10,7 @@ homepage.workspace = true [dependencies] fastn-utils.workspace = true +fastn-wasm.workspace = true tokio.workspace = true thiserror.workspace = true actix-web.workspace = true diff --git a/fastn-ds/src/wasm/exports/crypto.rs b/fastn-ds/src/wasm/exports/crypto.rs index 60f44995fb..c6671f3669 100644 --- a/fastn-ds/src/wasm/exports/crypto.rs +++ b/fastn-ds/src/wasm/exports/crypto.rs @@ -5,11 +5,11 @@ pub async fn encrypt( ptr: i32, len: i32, ) -> wasmtime::Result { - let input = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let input = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; let secret_key = std::env::var("FASTN_SECRET_KEY").unwrap(); let mc_obj = magic_crypt::new_magic_crypt!(secret_key, 256); let o = mc_obj.encrypt_to_base64(input.as_str()).as_str().to_owned(); - fastn_ds::wasm::helpers::send_bytes(&o.into_bytes(), &mut caller).await + fastn_wasm::helpers::send_bytes(&o.into_bytes(), &mut caller).await } pub async fn decrypt( @@ -17,11 +17,11 @@ pub async fn decrypt( ptr: i32, len: i32, ) -> wasmtime::Result { - let input = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let input = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; let secret_key = std::env::var("FASTN_SECRET_KEY").unwrap(); let mc_obj = magic_crypt::new_magic_crypt!(secret_key, 256); let o = mc_obj .decrypt_base64_to_string(input) .map_err(|e| ft_sys_shared::DecryptionError::Generic(format!("{e:?}"))); - fastn_ds::wasm::helpers::send_json(o, &mut caller).await + fastn_wasm::helpers::send_json(o, &mut caller).await } diff --git a/fastn-ds/src/wasm/exports/env.rs b/fastn-ds/src/wasm/exports/env.rs index 71540cbf8e..7d1947e726 100644 --- a/fastn-ds/src/wasm/exports/env.rs +++ b/fastn-ds/src/wasm/exports/env.rs @@ -5,7 +5,7 @@ pub async fn print( ) -> wasmtime::Result<()> { println!( "wasm: {}", - fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)? + fastn_wasm::helpers::get_str(ptr, len, &mut caller)? ); Ok(()) @@ -16,18 +16,18 @@ pub async fn var( ptr: i32, len: i32, ) -> wasmtime::Result { - let key = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let key = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; let value = std::env::var(key).ok(); - fastn_ds::wasm::helpers::send_json(value, &mut caller).await + fastn_wasm::helpers::send_json(value, &mut caller).await } pub async fn now(mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>) -> wasmtime::Result { - fastn_ds::wasm::helpers::send_json(chrono::Utc::now(), &mut caller).await + fastn_wasm::helpers::send_json(chrono::Utc::now(), &mut caller).await } pub async fn random( mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>, ) -> wasmtime::Result { - fastn_ds::wasm::helpers::send_json(rand::random::(), &mut caller).await + fastn_wasm::helpers::send_json(rand::random::(), &mut caller).await } diff --git a/fastn-ds/src/wasm/exports/http/get_request.rs b/fastn-ds/src/wasm/exports/http/get_request.rs index 8033932bdb..2df2cc3122 100644 --- a/fastn-ds/src/wasm/exports/http/get_request.rs +++ b/fastn-ds/src/wasm/exports/http/get_request.rs @@ -2,7 +2,7 @@ pub async fn get_request( mut caller: wasmtime::Caller<'_, fastn_ds::wasm::Store>, ) -> wasmtime::Result { let req = caller.data().to_http(); - fastn_ds::wasm::helpers::send_json(req, &mut caller).await + fastn_wasm::helpers::send_json(req, &mut caller).await } impl fastn_ds::wasm::Store { diff --git a/fastn-ds/src/wasm/exports/http/send_request.rs b/fastn-ds/src/wasm/exports/http/send_request.rs index 989a5318e3..b1d8253cef 100644 --- a/fastn-ds/src/wasm/exports/http/send_request.rs +++ b/fastn-ds/src/wasm/exports/http/send_request.rs @@ -3,7 +3,7 @@ pub async fn send_request( ptr: i32, len: i32, ) -> wasmtime::Result { - let r: ft_sys_shared::Request = fastn_ds::wasm::helpers::get_json(ptr, len, &mut caller)?; + let r: ft_sys_shared::Request = fastn_wasm::helpers::get_json(ptr, len, &mut caller)?; let mut headers = reqwest::header::HeaderMap::new(); for (header_name, header_value) in r.headers { @@ -27,5 +27,5 @@ pub async fn send_request( } let response = response.body(reqwest_response.bytes().await?)?; - fastn_ds::wasm::helpers::send_json(ft_sys_shared::Request::from(response), &mut caller).await + fastn_wasm::helpers::send_json(ft_sys_shared::Request::from(response), &mut caller).await } diff --git a/fastn-ds/src/wasm/exports/http/send_response.rs b/fastn-ds/src/wasm/exports/http/send_response.rs index c65fc87b34..b7a67af836 100644 --- a/fastn-ds/src/wasm/exports/http/send_response.rs +++ b/fastn-ds/src/wasm/exports/http/send_response.rs @@ -3,7 +3,7 @@ pub async fn send_response( ptr: i32, len: i32, ) -> wasmtime::Result<()> { - let r = fastn_ds::wasm::helpers::get_json(ptr, len, &mut caller)?; + let r = fastn_wasm::helpers::get_json(ptr, len, &mut caller)?; caller.data_mut().store_response(r); Ok(()) } diff --git a/fastn-ds/src/wasm/exports/pg/batch_execute.rs b/fastn-ds/src/wasm/exports/pg/batch_execute.rs index feb0b15711..d44c95fb00 100644 --- a/fastn-ds/src/wasm/exports/pg/batch_execute.rs +++ b/fastn-ds/src/wasm/exports/pg/batch_execute.rs @@ -4,9 +4,9 @@ pub async fn batch_execute( ptr: i32, len: i32, ) -> wasmtime::Result { - let q = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let q = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; let res = caller.data_mut().pg_batch_execute(conn, q).await?; - fastn_ds::wasm::helpers::send_json(res, &mut caller).await + fastn_wasm::helpers::send_json(res, &mut caller).await } impl fastn_ds::wasm::Store { diff --git a/fastn-ds/src/wasm/exports/pg/connect.rs b/fastn-ds/src/wasm/exports/pg/connect.rs index 7e64dce50e..409943a6d4 100644 --- a/fastn-ds/src/wasm/exports/pg/connect.rs +++ b/fastn-ds/src/wasm/exports/pg/connect.rs @@ -3,7 +3,7 @@ pub async fn connect( ptr: i32, len: i32, ) -> wasmtime::Result { - let db_url = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let db_url = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; caller.data_mut().pg_connect(db_url.as_str()).await } diff --git a/fastn-ds/src/wasm/exports/pg/execute.rs b/fastn-ds/src/wasm/exports/pg/execute.rs index 8cd7810d56..eea1ed9f4b 100644 --- a/fastn-ds/src/wasm/exports/pg/execute.rs +++ b/fastn-ds/src/wasm/exports/pg/execute.rs @@ -5,9 +5,9 @@ pub async fn execute( len: i32, ) -> wasmtime::Result { let q: fastn_ds::wasm::exports::pg::Query = - fastn_ds::wasm::helpers::get_json(ptr, len, &mut caller)?; + fastn_wasm::helpers::get_json(ptr, len, &mut caller)?; let res = caller.data_mut().pg_execute(conn, q).await?; - fastn_ds::wasm::helpers::send_json(res, &mut caller).await + fastn_wasm::helpers::send_json(res, &mut caller).await } impl fastn_ds::wasm::Store { diff --git a/fastn-ds/src/wasm/exports/pg/query.rs b/fastn-ds/src/wasm/exports/pg/query.rs index 6f9b579416..0db2ed8ad2 100644 --- a/fastn-ds/src/wasm/exports/pg/query.rs +++ b/fastn-ds/src/wasm/exports/pg/query.rs @@ -5,9 +5,9 @@ pub async fn query( len: i32, ) -> wasmtime::Result { let q: fastn_ds::wasm::exports::pg::Query = - fastn_ds::wasm::helpers::get_json(ptr, len, &mut caller)?; + fastn_wasm::helpers::get_json(ptr, len, &mut caller)?; let res = caller.data_mut().pg_query(conn, q).await?; - fastn_ds::wasm::helpers::send_json(res, &mut caller).await + fastn_wasm::helpers::send_json(res, &mut caller).await } #[derive(serde::Serialize, Debug)] diff --git a/fastn-ds/src/wasm/exports/sqlite/batch_execute.rs b/fastn-ds/src/wasm/exports/sqlite/batch_execute.rs index ff7bd66fd7..819daa4ed5 100644 --- a/fastn-ds/src/wasm/exports/sqlite/batch_execute.rs +++ b/fastn-ds/src/wasm/exports/sqlite/batch_execute.rs @@ -5,9 +5,9 @@ pub async fn batch_execute( ptr: i32, len: i32, ) -> wasmtime::Result { - let q = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let q = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; let res = caller.data_mut().sqlite_batch_execute(q).await?; - fastn_ds::wasm::helpers::send_json(res, &mut caller).await + fastn_wasm::helpers::send_json(res, &mut caller).await } impl fastn_ds::wasm::Store { diff --git a/fastn-ds/src/wasm/exports/sqlite/connect.rs b/fastn-ds/src/wasm/exports/sqlite/connect.rs index a0508b115e..f4e4c6a906 100644 --- a/fastn-ds/src/wasm/exports/sqlite/connect.rs +++ b/fastn-ds/src/wasm/exports/sqlite/connect.rs @@ -3,7 +3,7 @@ pub async fn connect( ptr: i32, len: i32, ) -> wasmtime::Result { - let db_url = fastn_ds::wasm::helpers::get_str(ptr, len, &mut caller)?; + let db_url = fastn_wasm::helpers::get_str(ptr, len, &mut caller)?; println!("sqlite_connect: {db_url}"); caller.data_mut().sqlite_connect(db_url.as_str()).await } diff --git a/fastn-ds/src/wasm/exports/sqlite/execute.rs b/fastn-ds/src/wasm/exports/sqlite/execute.rs index 25f60c9110..fad7e57026 100644 --- a/fastn-ds/src/wasm/exports/sqlite/execute.rs +++ b/fastn-ds/src/wasm/exports/sqlite/execute.rs @@ -6,9 +6,9 @@ pub async fn execute( len: i32, ) -> wasmtime::Result { let q: fastn_ds::wasm::exports::sqlite::Query = - fastn_ds::wasm::helpers::get_json(ptr, len, &mut caller)?; + fastn_wasm::helpers::get_json(ptr, len, &mut caller)?; let res = caller.data_mut().sqlite_execute(q).await?; - fastn_ds::wasm::helpers::send_json(res, &mut caller).await + fastn_wasm::helpers::send_json(res, &mut caller).await } impl fastn_ds::wasm::Store { diff --git a/fastn-ds/src/wasm/exports/sqlite/query.rs b/fastn-ds/src/wasm/exports/sqlite/query.rs index 28040e9b8f..f2ed2cea23 100644 --- a/fastn-ds/src/wasm/exports/sqlite/query.rs +++ b/fastn-ds/src/wasm/exports/sqlite/query.rs @@ -6,9 +6,9 @@ pub async fn query( ptr: i32, len: i32, ) -> wasmtime::Result { - let q: Query = fastn_ds::wasm::helpers::get_json(ptr, len, &mut caller)?; + let q: Query = fastn_wasm::helpers::get_json(ptr, len, &mut caller)?; let res = caller.data_mut().sqlite_query(q).await?; - fastn_ds::wasm::helpers::send_json(res, &mut caller).await + fastn_wasm::helpers::send_json(res, &mut caller).await } #[derive(serde::Deserialize, Debug)] diff --git a/fastn-ds/src/wasm/mod.rs b/fastn-ds/src/wasm/mod.rs index f23047a733..24c18a0170 100644 --- a/fastn-ds/src/wasm/mod.rs +++ b/fastn-ds/src/wasm/mod.rs @@ -1,5 +1,4 @@ pub mod exports; -pub mod helpers; pub mod macros; mod store; diff --git a/v0.5/Cargo.lock b/v0.5/Cargo.lock index 45fabe54b4..7db4dcaaa7 100644 --- a/v0.5/Cargo.lock +++ b/v0.5/Cargo.lock @@ -290,6 +290,10 @@ dependencies = [ name = "fastn-update" version = "0.1.0" +[[package]] +name = "fastn-wasm" +version = "0.1.0" + [[package]] name = "fnv" version = "1.0.7" diff --git a/v0.5/Cargo.toml b/v0.5/Cargo.toml index d5bc0c49cb..826c895dba 100644 --- a/v0.5/Cargo.toml +++ b/v0.5/Cargo.toml @@ -9,6 +9,7 @@ members = [ "fastn-static", "fastn-unresolved", "fastn-update", + "fastn-wasm", ] exclude = [] resolver = "2" @@ -59,4 +60,5 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" string-interner = "0.18" tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] } +wasmtime = "28" diff --git a/v0.5/fastn-wasm/Cargo.toml b/v0.5/fastn-wasm/Cargo.toml new file mode 100644 index 0000000000..c04bb76ac1 --- /dev/null +++ b/v0.5/fastn-wasm/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "fastn-wasm" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +description.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true + +[dependencies] +wasmtime.workspace = true +serde_json.workspace = true +serde.workspace = true \ No newline at end of file diff --git a/fastn-ds/src/wasm/helpers.rs b/v0.5/fastn-wasm/src/helpers.rs similarity index 96% rename from fastn-ds/src/wasm/helpers.rs rename to v0.5/fastn-wasm/src/helpers.rs index d7887e85e6..2d6829daea 100644 --- a/fastn-ds/src/wasm/helpers.rs +++ b/v0.5/fastn-wasm/src/helpers.rs @@ -1,4 +1,7 @@ -pub async fn str(str: &str, caller: &mut wasmtime::Caller<'_, S>) -> wasmtime::Result { +pub async fn str( + str: &str, + caller: &mut wasmtime::Caller<'_, S>, +) -> wasmtime::Result { send_bytes(str.as_bytes(), caller).await } diff --git a/v0.5/fastn-wasm/src/lib.rs b/v0.5/fastn-wasm/src/lib.rs new file mode 100644 index 0000000000..4966181e35 --- /dev/null +++ b/v0.5/fastn-wasm/src/lib.rs @@ -0,0 +1,7 @@ +#![allow(clippy::derive_partial_eq_without_eq, clippy::get_first)] +#![deny(unused_crate_dependencies)] +#![warn(clippy::used_underscore_binding)] + +extern crate self as fastn_wasm; + +pub mod helpers;