mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-29 19:41:39 +03:00
temp remove sqlite and kv before runtime
This commit is contained in:
parent
46057abcf4
commit
36cca2220b
@ -373,8 +373,11 @@ fn handle_local_request(
|
||||
let Some(payload) = get_payload() else {
|
||||
return Err(anyhow::anyhow!("no metadata found!"));
|
||||
};
|
||||
println!("got metadata 1");
|
||||
let metadata = String::from_utf8(payload.bytes)?;
|
||||
println!("from bytes");
|
||||
let metadata = serde_json::from_str::<kt::PackageMetadata>(&metadata)?;
|
||||
println!("parsed metadata");
|
||||
|
||||
let listing_data = PackageListing {
|
||||
name: metadata.package,
|
||||
|
504
modules/key_value/key_value/Cargo.lock
generated
504
modules/key_value/key_value/Cargo.lock
generated
@ -1,504 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "key_value"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"uqbar_process_lib",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leb128"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
|
||||
|
||||
[[package]]
|
||||
name = "spdx"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "uqbar_process_lib"
|
||||
version = "0.3.0"
|
||||
source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=5e1b94a#5e1b94ae2f85c66da33ec52117a72b90d53c4d22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"http",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
|
||||
dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.10.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"spdx",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.116.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"wit-component",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
]
|
@ -1,31 +0,0 @@
|
||||
[package]
|
||||
name = "key_value"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bincode = "1.3.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "5e1b94a" }
|
||||
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.component]
|
||||
package = "uqbar:process"
|
||||
|
||||
[package.metadata.component.target]
|
||||
path = "wit"
|
||||
|
||||
[package.metadata.component.dependencies]
|
@ -1 +0,0 @@
|
||||
../../key_value_types.rs
|
@ -1,191 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
// use serde::{Deserialize, Serialize};
|
||||
|
||||
use uqbar_process_lib::{Address, ProcessId, Request, Response};
|
||||
use uqbar_process_lib::kernel_types as kt;
|
||||
use uqbar_process_lib::uqbar::process::standard as wit;
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "../../../wit",
|
||||
world: "process",
|
||||
exports: {
|
||||
world: Component,
|
||||
},
|
||||
});
|
||||
|
||||
mod key_value_types;
|
||||
use key_value_types as kv;
|
||||
|
||||
const PREFIX: &str = "key_value-";
|
||||
|
||||
type DbToProcess = HashMap<String, ProcessId>;
|
||||
|
||||
fn make_vfs_cap(kind: &str, drive: &str) -> String {
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
"kind": kind,
|
||||
"drive": drive,
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn make_db_cap(kind: &str, db: &str) -> String {
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
"kind": kind,
|
||||
"db": db,
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn forward_if_have_cap(
|
||||
our: &Address,
|
||||
operation_type: &str,
|
||||
db: &str,
|
||||
ipc: Vec<u8>,
|
||||
db_to_process: &mut DbToProcess,
|
||||
) -> anyhow::Result<()> {
|
||||
if wit::has_capability(&make_db_cap(operation_type, db)) {
|
||||
// forward
|
||||
let Some(process_id) = db_to_process.get(db) else {
|
||||
return Err(kv::KeyValueError::DbDoesNotExist.into());
|
||||
};
|
||||
Request::new()
|
||||
.target(wit::Address {
|
||||
node: our.node.clone(),
|
||||
process: process_id.clone(),
|
||||
})
|
||||
// .target(Address::new(our.node.clone(), process_id.clone()))?
|
||||
.inherit(true)
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
return Ok(());
|
||||
} else {
|
||||
// reject
|
||||
return Err(kv::KeyValueError::NoCap.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_message(our: &Address, db_to_process: &mut DbToProcess) -> anyhow::Result<()> {
|
||||
let (source, message) = wit::receive().unwrap();
|
||||
|
||||
if our.node != source.node {
|
||||
return Err(kv::KeyValueError::RejectForeign.into());
|
||||
}
|
||||
|
||||
match message {
|
||||
wit::Message::Response(_) => {
|
||||
return Err(kv::KeyValueError::UnexpectedResponse.into());
|
||||
}
|
||||
wit::Message::Request(wit::Request { ipc, .. }) => {
|
||||
match serde_json::from_slice(&ipc)? {
|
||||
kv::KeyValueMessage::New { ref db } => {
|
||||
// TODO: make atomic
|
||||
// (1): create vfs drive
|
||||
// (2): spin up worker, granting vfs caps
|
||||
// (3): issue new caps
|
||||
// (4): persist
|
||||
|
||||
if db_to_process.contains_key(db) {
|
||||
return Err(kv::KeyValueError::DbAlreadyExists.into());
|
||||
}
|
||||
|
||||
// (1)
|
||||
let vfs_address = Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::new(Some("vfs"), "sys", "uqbar"),
|
||||
};
|
||||
let vfs_drive = format!("{}{}", PREFIX, db);
|
||||
let _ = Request::new()
|
||||
.target(vfs_address.clone())
|
||||
.ipc(serde_json::to_vec(&kt::VfsRequest {
|
||||
drive: vfs_drive.clone(),
|
||||
action: kt::VfsAction::New,
|
||||
})?)
|
||||
.send_and_await_response(15)??;
|
||||
|
||||
// (2)
|
||||
let vfs_read = wit::get_capability(
|
||||
&vfs_address,
|
||||
&make_vfs_cap("read", &vfs_drive)
|
||||
).ok_or(anyhow::anyhow!("New failed: no vfs 'read' capability found"))?;
|
||||
let vfs_write = wit::get_capability(
|
||||
&vfs_address,
|
||||
&make_vfs_cap("write", &vfs_drive)
|
||||
).ok_or(anyhow::anyhow!("New failed: no vfs 'write' capability found"))?;
|
||||
let messaging = wit::get_capability(
|
||||
&source,
|
||||
&"\"messaging\"".into(),
|
||||
).ok_or(anyhow::anyhow!("New failed: no source 'messaging' capability found"))?;
|
||||
let spawned_process_id = match wit::spawn(
|
||||
None,
|
||||
"/key_value_worker.wasm",
|
||||
&wit::OnPanic::None, // TODO: notify us
|
||||
&wit::Capabilities::Some(vec![vfs_read, vfs_write, messaging]),
|
||||
false, // not public
|
||||
) {
|
||||
Ok(spawned_process_id) => spawned_process_id,
|
||||
Err(e) => {
|
||||
wit::print_to_terminal(0, &format!("couldn't spawn: {}", e));
|
||||
panic!("couldn't spawn"); // TODO
|
||||
}
|
||||
};
|
||||
// grant caps
|
||||
wit::create_capability(&source.process, &make_db_cap("read", db));
|
||||
wit::create_capability(&source.process, &make_db_cap("write", db));
|
||||
// initialize worker
|
||||
Request::new()
|
||||
.target(wit::Address {
|
||||
node: our.node.clone(),
|
||||
process: spawned_process_id.clone(),
|
||||
})
|
||||
.ipc(ipc.clone())
|
||||
.send()?;
|
||||
|
||||
// (4)
|
||||
db_to_process.insert(db.into(), spawned_process_id);
|
||||
// TODO: persistence?
|
||||
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
}
|
||||
kv::KeyValueMessage::Write { ref db, .. } => {
|
||||
forward_if_have_cap(our, "write", db, ipc, db_to_process)?;
|
||||
}
|
||||
kv::KeyValueMessage::Read { ref db, .. } => {
|
||||
forward_if_have_cap(our, "read", db, ipc, db_to_process)?;
|
||||
}
|
||||
kv::KeyValueMessage::Err { error } => {
|
||||
return Err(error.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Component;
|
||||
impl Guest for Component {
|
||||
fn init(our: String) {
|
||||
wit::print_to_terminal(0, "key_value: begin");
|
||||
|
||||
let our = Address::from_str(&our).unwrap();
|
||||
let mut db_to_process: DbToProcess = HashMap::new();
|
||||
|
||||
loop {
|
||||
match handle_message(&our, &mut db_to_process) {
|
||||
Ok(()) => {}
|
||||
Err(e) => {
|
||||
wit::print_to_terminal(0, format!("key_value: error: {:?}", e,).as_str());
|
||||
if let Some(e) = e.downcast_ref::<kv::KeyValueError>() {
|
||||
Response::new()
|
||||
.ipc(serde_json::to_vec(&e).unwrap())
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum KeyValueMessage {
|
||||
New { db: String },
|
||||
Write { db: String, key: Vec<u8> },
|
||||
Read { db: String, key: Vec<u8> },
|
||||
Err { error: KeyValueError },
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum KeyValueError {
|
||||
#[error("DbDoesNotExist")]
|
||||
DbDoesNotExist,
|
||||
#[error("DbAlreadyExists")]
|
||||
DbAlreadyExists,
|
||||
#[error("NoCap")]
|
||||
NoCap,
|
||||
#[error("RejectForeign")]
|
||||
RejectForeign,
|
||||
#[error("UnexpectedResponse")]
|
||||
UnexpectedResponse,
|
||||
}
|
644
modules/key_value/key_value_worker/Cargo.lock
generated
644
modules/key_value/key_value_worker/Cargo.lock
generated
@ -1,644 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "key_value_worker"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"redb",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"uqbar_process_lib",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leb128"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.32.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-build-config"
|
||||
version = "0.19.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"target-lexicon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redb"
|
||||
version = "1.2.0"
|
||||
source = "git+https://github.com/uqbar-dao/redb?rev=8e192d9#8e192d945295e1ddd331003bae215cd8d1564c4b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pyo3-build-config",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
|
||||
|
||||
[[package]]
|
||||
name = "spdx"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-lexicon"
|
||||
version = "0.12.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"pin-project-lite",
|
||||
"tokio-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "uqbar_process_lib"
|
||||
version = "0.3.0"
|
||||
source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=5e1b94a#5e1b94ae2f85c66da33ec52117a72b90d53c4d22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"http",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
|
||||
dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.10.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"spdx",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.116.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"wit-component",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
]
|
@ -1,32 +0,0 @@
|
||||
[package]
|
||||
name = "key_value_worker"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bincode = "1.3.3"
|
||||
redb = { git = "https://github.com/uqbar-dao/redb", rev = "8e192d9" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "5e1b94a" }
|
||||
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.component]
|
||||
package = "uqbar:process"
|
||||
|
||||
[package.metadata.component.target]
|
||||
path = "wit"
|
||||
|
||||
[package.metadata.component.dependencies]
|
@ -1 +0,0 @@
|
||||
../key_value_types.rs
|
@ -1 +0,0 @@
|
||||
../../key_value_types.rs
|
@ -1,206 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use redb::ReadableTable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use uqbar_process_lib::{Address, create_capability, ProcessId, Response};
|
||||
use uqbar_process_lib::uqbar::process::standard as wit;
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "../../../wit",
|
||||
world: "process",
|
||||
exports: {
|
||||
world: Component,
|
||||
},
|
||||
});
|
||||
|
||||
mod key_value_types;
|
||||
use key_value_types as kv;
|
||||
|
||||
const PREFIX: &str = "key_value-";
|
||||
const TABLE: redb::TableDefinition<&[u8], &[u8]> = redb::TableDefinition::new("process");
|
||||
|
||||
fn get_payload_wrapped() -> Option<(Option<String>, Vec<u8>)> {
|
||||
match wit::get_payload() {
|
||||
None => None,
|
||||
Some(wit::Payload { mime, bytes }) => Some((mime, bytes)),
|
||||
}
|
||||
}
|
||||
|
||||
fn send_and_await_response_wrapped(
|
||||
target_node: String,
|
||||
target_process: String,
|
||||
target_package: String,
|
||||
target_publisher: String,
|
||||
request_ipc: Vec<u8>,
|
||||
request_metadata: Option<String>,
|
||||
payload: Option<(Option<String>, Vec<u8>)>,
|
||||
timeout: u64,
|
||||
) -> (Vec<u8>, Option<String>) {
|
||||
let payload = match payload {
|
||||
None => None,
|
||||
Some((mime, bytes)) => Some(wit::Payload { mime, bytes }),
|
||||
};
|
||||
let (
|
||||
_,
|
||||
wit::Message::Response((wit::Response { ipc, metadata, .. }, _)),
|
||||
) = wit::send_and_await_response(
|
||||
&wit::Address {
|
||||
node: target_node,
|
||||
process: ProcessId::new(
|
||||
Some(&target_process),
|
||||
&target_package,
|
||||
&target_publisher,
|
||||
),
|
||||
},
|
||||
&wit::Request {
|
||||
inherit: false,
|
||||
expects_response: Some(timeout),
|
||||
ipc: request_ipc,
|
||||
metadata: request_metadata,
|
||||
},
|
||||
match payload {
|
||||
None => None,
|
||||
Some(ref p) => Some(p),
|
||||
},
|
||||
).unwrap() else {
|
||||
panic!("");
|
||||
};
|
||||
(ipc, metadata)
|
||||
}
|
||||
|
||||
fn handle_message (
|
||||
our: &wit::Address,
|
||||
db_handle: &mut Option<redb::Database>,
|
||||
) -> anyhow::Result<()> {
|
||||
let (source, message) = wit::receive().unwrap();
|
||||
|
||||
if our.node != source.node {
|
||||
return Err(kv::KeyValueError::RejectForeign.into());
|
||||
}
|
||||
|
||||
match message {
|
||||
wit::Message::Response(_) => { unimplemented!() },
|
||||
wit::Message::Request(wit::Request { ipc, .. }) => {
|
||||
match serde_json::from_slice(&ipc)? {
|
||||
kv::KeyValueMessage::New { db } => {
|
||||
let vfs_drive = format!("{}{}", PREFIX, db);
|
||||
match db_handle {
|
||||
Some(_) => {
|
||||
return Err(kv::KeyValueError::DbAlreadyExists.into());
|
||||
},
|
||||
None => {
|
||||
wit::print_to_terminal(1, "key_value_worker: Create");
|
||||
*db_handle = Some(redb::Database::create(
|
||||
format!("/{}.redb", db),
|
||||
our.node.clone(),
|
||||
vfs_drive,
|
||||
get_payload_wrapped,
|
||||
send_and_await_response_wrapped,
|
||||
)?);
|
||||
wit::print_to_terminal(1, "key_value_worker: Create done");
|
||||
},
|
||||
}
|
||||
},
|
||||
kv::KeyValueMessage::Write { ref key, .. } => {
|
||||
let Some(db_handle) = db_handle else {
|
||||
return Err(kv::KeyValueError::DbDoesNotExist.into());
|
||||
};
|
||||
|
||||
let wit::Payload { ref bytes, .. } = wit::get_payload()
|
||||
.ok_or(anyhow::anyhow!("couldnt get bytes for Write"))?;
|
||||
|
||||
let write_txn = db_handle.begin_write()?;
|
||||
{
|
||||
let mut table = write_txn.open_table(TABLE)?;
|
||||
table.insert(&key[..], &bytes[..])?;
|
||||
}
|
||||
write_txn.commit()?;
|
||||
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
},
|
||||
kv::KeyValueMessage::Read { ref key, .. } => {
|
||||
let Some(db_handle) = db_handle else {
|
||||
return Err(kv::KeyValueError::DbDoesNotExist.into());
|
||||
};
|
||||
|
||||
let read_txn = db_handle.begin_read()?;
|
||||
|
||||
let table = read_txn.open_table(TABLE)?;
|
||||
|
||||
match table.get(&key[..])? {
|
||||
None => {
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
},
|
||||
Some(v) => {
|
||||
let bytes = v.value().to_vec();
|
||||
wit::print_to_terminal(
|
||||
1,
|
||||
&format!(
|
||||
"key_value_worker: key, val: {:?}, {}",
|
||||
key,
|
||||
if bytes.len() < 100 {
|
||||
format!("{:?}", bytes)
|
||||
} else {
|
||||
"<elided>".into()
|
||||
},
|
||||
),
|
||||
);
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.payload(wit::Payload {
|
||||
mime: None,
|
||||
bytes,
|
||||
})
|
||||
.send()?;
|
||||
},
|
||||
};
|
||||
},
|
||||
kv::KeyValueMessage::Err { error } => {
|
||||
return Err(error.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
struct Component;
|
||||
impl Guest for Component {
|
||||
fn init(our: String) {
|
||||
wit::print_to_terminal(1, "key_value_worker: begin");
|
||||
|
||||
let our = Address::from_str(&our).unwrap();
|
||||
let mut db_handle: Option<redb::Database> = None;
|
||||
|
||||
let vfs_address = ProcessId::from_str("vfs:sys:uqbar").unwrap();
|
||||
create_capability(
|
||||
&vfs_address,
|
||||
&"\"messaging\"".into(),
|
||||
);
|
||||
|
||||
loop {
|
||||
match handle_message(&our, &mut db_handle) {
|
||||
Ok(()) => {},
|
||||
Err(e) => {
|
||||
wit::print_to_terminal(0, format!(
|
||||
"key_value_worker: error: {:?}",
|
||||
e,
|
||||
).as_str());
|
||||
if let Some(e) = e.downcast_ref::<kv::KeyValueError>() {
|
||||
Response::new()
|
||||
.ipc(serde_json::to_vec(&e).unwrap())
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
panic!("");
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
[
|
||||
{
|
||||
"process_name": "key_value",
|
||||
"process_wasm_path": "/key_value.wasm",
|
||||
"on_panic": "Restart",
|
||||
"request_networking": false,
|
||||
"request_messaging": [
|
||||
"vfs:sys:uqbar"
|
||||
],
|
||||
"public": true
|
||||
}
|
||||
]
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"package": "key_value",
|
||||
"publisher": "uqbar",
|
||||
"version": [0, 1, 0]
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
[
|
||||
{
|
||||
"process_name": "sqlite",
|
||||
"process_wasm_path": "/sqlite.wasm",
|
||||
"on_panic": "Restart",
|
||||
"request_networking": false,
|
||||
"request_messaging": [
|
||||
"vfs:sys:uqbar"
|
||||
],
|
||||
"public": true
|
||||
}
|
||||
]
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"package": "sqlite",
|
||||
"publisher": "uqbar"
|
||||
}
|
504
modules/sqlite/sqlite/Cargo.lock
generated
504
modules/sqlite/sqlite/Cargo.lock
generated
@ -1,504 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "leb128"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
|
||||
|
||||
[[package]]
|
||||
name = "spdx"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"uqbar_process_lib",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "uqbar_process_lib"
|
||||
version = "0.3.0"
|
||||
source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=5e1b94a#5e1b94ae2f85c66da33ec52117a72b90d53c4d22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"http",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
|
||||
dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.10.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"spdx",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.116.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"wit-component",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
]
|
@ -1,31 +0,0 @@
|
||||
[package]
|
||||
name = "sqlite"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bincode = "1.3.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "5e1b94a" }
|
||||
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.component]
|
||||
package = "uqbar:process"
|
||||
|
||||
[package.metadata.component.target]
|
||||
path = "wit"
|
||||
|
||||
[package.metadata.component.dependencies]
|
@ -1,250 +0,0 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use uqbar_process_lib::{Address, ProcessId, Request, Response};
|
||||
use uqbar_process_lib::kernel_types as kt;
|
||||
use uqbar_process_lib::uqbar::process::standard as wit;
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "../../../wit",
|
||||
world: "process",
|
||||
exports: {
|
||||
world: Component,
|
||||
},
|
||||
});
|
||||
|
||||
mod sqlite_types;
|
||||
use sqlite_types as sq;
|
||||
|
||||
const PREFIX: &str = "sqlite-";
|
||||
|
||||
type DbToProcess = HashMap<String, ProcessId>;
|
||||
|
||||
fn make_vfs_cap(kind: &str, drive: &str) -> String {
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
"kind": kind,
|
||||
"drive": drive,
|
||||
})).unwrap()
|
||||
}
|
||||
|
||||
fn make_db_cap(kind: &str, db: &str) -> String {
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
"kind": kind,
|
||||
"db": db,
|
||||
})).unwrap()
|
||||
}
|
||||
|
||||
fn forward_if_have_cap(
|
||||
our: &Address,
|
||||
operation_type: &str,
|
||||
// operation_type: OperationType,
|
||||
db: &str,
|
||||
ipc: Vec<u8>,
|
||||
db_to_process: &mut DbToProcess,
|
||||
) -> anyhow::Result<()> {
|
||||
if wit::has_capability(&make_db_cap(operation_type, db)) {
|
||||
// forward
|
||||
let Some(process_id) = db_to_process.get(db) else {
|
||||
return Err(sq::SqliteError::DbDoesNotExist.into());
|
||||
};
|
||||
Request::new()
|
||||
.target(wit::Address {
|
||||
node: our.node.clone(),
|
||||
process: process_id.clone(),
|
||||
})
|
||||
// .target(Address::new(our.node.clone(), process_id.clone()))?
|
||||
.inherit(true)
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
return Ok(());
|
||||
} else {
|
||||
// reject
|
||||
return Err(sq::SqliteError::NoCap.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_message (
|
||||
our: &Address,
|
||||
db_to_process: &mut DbToProcess,
|
||||
read_keywords: &HashSet<String>,
|
||||
write_keywords: &HashSet<String>,
|
||||
) -> anyhow::Result<()> {
|
||||
let (source, message) = wit::receive().unwrap();
|
||||
|
||||
if our.node != source.node {
|
||||
return Err(sq::SqliteError::RejectForeign.into());
|
||||
}
|
||||
|
||||
match message {
|
||||
wit::Message::Response(_) => {
|
||||
return Err(sq::SqliteError::UnexpectedResponse.into());
|
||||
},
|
||||
wit::Message::Request(wit::Request { ipc, .. }) => {
|
||||
match serde_json::from_slice(&ipc)? {
|
||||
sq::SqliteMessage::New { ref db } => {
|
||||
// TODO: make atomic
|
||||
// (1): create vfs drive
|
||||
// (2): spin up worker, granting vfs caps & msg_cap
|
||||
// (3): issue new caps
|
||||
|
||||
if db_to_process.contains_key(db) {
|
||||
return Err(sq::SqliteError::DbAlreadyExists.into());
|
||||
}
|
||||
|
||||
// (1)
|
||||
let vfs_address = Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::new(Some("vfs"), "sys", "uqbar"),
|
||||
};
|
||||
|
||||
let vfs_drive = format!("{}{}", PREFIX, db);
|
||||
let _ = Request::new()
|
||||
.target(vfs_address.clone())
|
||||
.ipc(serde_json::to_vec(&kt::VfsRequest {
|
||||
drive: vfs_drive.clone(),
|
||||
action: kt::VfsAction::New,
|
||||
})?)
|
||||
.send_and_await_response(15)??;
|
||||
|
||||
// (2)
|
||||
let vfs_read = wit::get_capability(
|
||||
&vfs_address,
|
||||
&make_vfs_cap("read", &vfs_drive),
|
||||
).ok_or(anyhow::anyhow!("New failed: no vfs 'read' capability found"))?;
|
||||
|
||||
let vfs_write = wit::get_capability(
|
||||
&vfs_address,
|
||||
&make_vfs_cap("write", &vfs_drive),
|
||||
).ok_or(anyhow::anyhow!("New failed: no vfs 'write' capability found"))?;
|
||||
|
||||
let msg_cap = wit::get_capability(
|
||||
&source,
|
||||
&"\"messaging\"".into(),
|
||||
).ok_or(anyhow::anyhow!("New failed: no msg capability passed"))?;
|
||||
|
||||
let spawned_process_id = match wit::spawn(
|
||||
None,
|
||||
"/sqlite_worker.wasm",
|
||||
&wit::OnPanic::None,
|
||||
&wit::Capabilities::Some(vec![vfs_read, vfs_write, msg_cap]),
|
||||
false, // not public
|
||||
) {
|
||||
Ok(spawned_process_id) => spawned_process_id,
|
||||
Err(e) => {
|
||||
wit::print_to_terminal(0, &format!("couldn't spawn: {}", e));
|
||||
panic!("couldn't spawn"); // TODO
|
||||
},
|
||||
};
|
||||
// grant caps
|
||||
wit::create_capability(&source.process, &make_db_cap("read", db));
|
||||
wit::create_capability(&source.process, &make_db_cap("write", db));
|
||||
// initialize worker
|
||||
Request::new()
|
||||
.target(wit::Address {
|
||||
node: our.node.clone(),
|
||||
process: spawned_process_id.clone(),
|
||||
})
|
||||
.ipc(ipc.clone())
|
||||
.send()?;
|
||||
|
||||
db_to_process.insert(db.into(), spawned_process_id);
|
||||
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
},
|
||||
sq::SqliteMessage::Write { ref db, ref statement, .. } => {
|
||||
let first_word = statement
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.map(|word| word.to_uppercase())
|
||||
.unwrap_or("".to_string());
|
||||
if !write_keywords.contains(&first_word) {
|
||||
return Err(sq::SqliteError::NotAWriteKeyword.into())
|
||||
}
|
||||
forward_if_have_cap(our, "write", db, ipc, db_to_process)?;
|
||||
},
|
||||
sq::SqliteMessage::Read { ref db, ref query } => {
|
||||
let first_word = query
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.map(|word| word.to_uppercase())
|
||||
.unwrap_or("".to_string());
|
||||
if !read_keywords.contains(&first_word) {
|
||||
return Err(sq::SqliteError::NotAReadKeyword.into())
|
||||
}
|
||||
forward_if_have_cap(our, "read", db, ipc, db_to_process)?;
|
||||
},
|
||||
sq::SqliteMessage::Commit { ref db, .. } => {
|
||||
forward_if_have_cap(our, "write", db, ipc, db_to_process)?;
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
struct Component;
|
||||
impl Guest for Component {
|
||||
fn init(our: String) {
|
||||
wit::print_to_terminal(0, "sqlite: begin");
|
||||
|
||||
let our = Address::from_str(&our).unwrap();
|
||||
|
||||
let mut db_to_process: DbToProcess = HashMap::new();
|
||||
|
||||
let read_keywords: HashSet<String> = [
|
||||
"ANALYZE",
|
||||
"ATTACH",
|
||||
"BEGIN",
|
||||
"EXPLAIN",
|
||||
"PRAGMA",
|
||||
"SELECT",
|
||||
"VALUES",
|
||||
"WITH",
|
||||
]
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect();
|
||||
let write_keywords: HashSet<String> = [
|
||||
"ALTER",
|
||||
"ANALYZE",
|
||||
"COMMIT",
|
||||
"CREATE",
|
||||
"DELETE",
|
||||
"DETACH",
|
||||
"DROP",
|
||||
"END",
|
||||
"INSERT",
|
||||
"REINDEX",
|
||||
"RELEASE",
|
||||
"RENAME",
|
||||
"REPLACE",
|
||||
"ROLLBACK",
|
||||
"SAVEPOINT",
|
||||
"UPDATE",
|
||||
"VACUUM",
|
||||
]
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect();
|
||||
|
||||
loop {
|
||||
match handle_message(&our, &mut db_to_process, &read_keywords, &write_keywords) {
|
||||
Ok(()) => {},
|
||||
Err(e) => {
|
||||
wit::print_to_terminal(0, format!(
|
||||
"sqlite: error: {:?}",
|
||||
e,
|
||||
).as_str());
|
||||
if let Some(e) = e.downcast_ref::<sq::SqliteError>() {
|
||||
Response::new()
|
||||
.ipc(serde_json::to_vec(&e).unwrap())
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../sqlite_types.rs
|
@ -1,41 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum SqliteMessage {
|
||||
New { db: String },
|
||||
Write { db: String, statement: String, tx_id: Option<u64> },
|
||||
Read { db: String, query: String },
|
||||
Commit { db: String, tx_id: u64 },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum SqlValue {
|
||||
Integer(i64),
|
||||
Real(f64),
|
||||
Text(String),
|
||||
Blob(Vec<u8>),
|
||||
Boolean(bool),
|
||||
Null,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum SqliteError {
|
||||
#[error("DbDoesNotExist")]
|
||||
DbDoesNotExist,
|
||||
#[error("DbAlreadyExists")]
|
||||
DbAlreadyExists,
|
||||
#[error("NoTx")]
|
||||
NoTx,
|
||||
#[error("NoCap")]
|
||||
NoCap,
|
||||
#[error("RejectForeign")]
|
||||
RejectForeign,
|
||||
#[error("UnexpectedResponse")]
|
||||
UnexpectedResponse,
|
||||
#[error("NotAWriteKeyword")]
|
||||
NotAWriteKeyword,
|
||||
#[error("NotAReadKeyword")]
|
||||
NotAReadKeyword,
|
||||
#[error("Invalid Parameters")]
|
||||
InvalidParameters,
|
||||
}
|
610
modules/sqlite/sqlite_worker/Cargo.lock
generated
610
modules/sqlite/sqlite_worker/Cargo.lock
generated
@ -1,610 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-streaming-iterator"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"allocator-api2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashlink"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "leb128"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.26.0"
|
||||
source = "git+https://github.com/uqbar-dao/rusqlite?rev=8fb20a9#8fb20a9dedf4bea626036af8b43c92b050a24d9f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusqlite"
|
||||
version = "0.29.0"
|
||||
source = "git+https://github.com/uqbar-dao/rusqlite?rev=8fb20a9#8fb20a9dedf4bea626036af8b43c92b050a24d9f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"fallible-iterator",
|
||||
"fallible-streaming-iterator",
|
||||
"hashlink",
|
||||
"libsqlite3-sys",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
|
||||
|
||||
[[package]]
|
||||
name = "spdx"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite_worker"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
"bincode",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"uqbar_process_lib",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "uqbar_process_lib"
|
||||
version = "0.3.0"
|
||||
source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=5e1b94a#5e1b94ae2f85c66da33ec52117a72b90d53c4d22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"http",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
|
||||
dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.10.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"spdx",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.116.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"wit-component",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
]
|
@ -1,33 +0,0 @@
|
||||
[package]
|
||||
name = "sqlite_worker"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
base64 = "0.13"
|
||||
bincode = "1.3.3"
|
||||
rusqlite = { git = "https://github.com/uqbar-dao/rusqlite", rev = "8fb20a9", features = ["bundled", "wasm32-wasi-vfs"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "5e1b94a" }
|
||||
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.component]
|
||||
package = "uqbar:process"
|
||||
|
||||
[package.metadata.component.target]
|
||||
path = "wit"
|
||||
|
||||
[package.metadata.component.dependencies]
|
@ -1,66 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
crossplatform_wget() {
|
||||
curl -L "${1}" -o $(basename "${1}")
|
||||
}
|
||||
|
||||
crossplatform_realpath_inner() {
|
||||
python3 -c "import os; print(os.path.realpath('$1'))"
|
||||
}
|
||||
|
||||
crossplatform_realpath() {
|
||||
if [ -e "$1" ] || [ -L "$1" ]; then
|
||||
crossplatform_realpath_inner "$1"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# cd sqlite
|
||||
# cargo build --release --no-default-features --target wasm32-wasi
|
||||
#
|
||||
# cd ../sqlite_worker
|
||||
|
||||
# Get special clang compiler required to build & link sqlite3 C lib.
|
||||
mkdir -p target
|
||||
cd target
|
||||
|
||||
WASI_VERSION=20
|
||||
WASI_VERSION_FULL=${WASI_VERSION}.0
|
||||
CC_PATH=$(crossplatform_realpath ./wasi-sdk-${WASI_VERSION_FULL}/bin/clang)
|
||||
|
||||
# Determine operating system
|
||||
OS_TYPE="$(uname)"
|
||||
if [ "$OS_TYPE" = "Darwin" ]; then
|
||||
WASI_PLATFORM="macos"
|
||||
elif [ "$OS_TYPE" = "Linux" ]; then
|
||||
WASI_PLATFORM="linux"
|
||||
else
|
||||
echo "sqlite_worker build failed: Unsupported OS: $OS_TYPE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e "$CC_PATH" ]; then
|
||||
$(crossplatform_wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-${WASI_PLATFORM}.tar.gz)
|
||||
tar xvf wasi-sdk-${WASI_VERSION_FULL}-${WASI_PLATFORM}.tar.gz
|
||||
fi
|
||||
|
||||
CC_PATH=$(crossplatform_realpath ./wasi-sdk-${WASI_VERSION_FULL}/bin/clang)
|
||||
|
||||
cd ..
|
||||
|
||||
# We write env vars to `.cargo/config.toml` here because:
|
||||
# 1. Doing `export foo=/path && export bar=/path2 && RUSTFLAGS=baz cargo build ...`
|
||||
# does not properly pass the RUSTFLAGS (cargo bug?).
|
||||
# 2. Specifying `~/path` inside `.cargo/config.toml` doesn't expand.
|
||||
mkdir -p .cargo
|
||||
|
||||
# Write to the .cargo/config.toml file
|
||||
cat <<EOF > .cargo/config.toml
|
||||
[env]
|
||||
CC_wasm32_wasi = "$CC_PATH"
|
||||
CARGO_TARGET_WASM32_WASI_LINKER = "$CC_PATH"
|
||||
EOF
|
||||
|
||||
RUSTFLAGS="-C target-feature=-crt-static -C link-arg=-Wl,--no-entry,--export=init,--export=cabi_realloc" cargo build --release --no-default-features --target wasm32-wasi
|
||||
|
@ -1,575 +0,0 @@
|
||||
use core::ffi::{c_char, c_int, c_ulonglong, CStr};
|
||||
use std::ffi::CString;
|
||||
|
||||
use rusqlite::{types::FromSql, types::FromSqlError, types::ToSql, types::ValueRef};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use uqbar_process_lib::{Address, create_capability, ProcessId, Response};
|
||||
use uqbar_process_lib::uqbar::process::standard as wit;
|
||||
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "../../../wit",
|
||||
world: "process",
|
||||
exports: {
|
||||
world: Component,
|
||||
},
|
||||
});
|
||||
|
||||
mod sqlite_types;
|
||||
use sqlite_types as sq;
|
||||
|
||||
const PREFIX: &str = "sqlite-";
|
||||
|
||||
impl ToSql for sq::SqlValue {
|
||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
||||
match self {
|
||||
sq::SqlValue::Integer(i) => i.to_sql(),
|
||||
sq::SqlValue::Real(f) => f.to_sql(),
|
||||
sq::SqlValue::Text(ref s) => s.to_sql(),
|
||||
sq::SqlValue::Blob(ref b) => b.to_sql(),
|
||||
sq::SqlValue::Boolean(b) => b.to_sql(),
|
||||
sq::SqlValue::Null => Ok(rusqlite::types::ToSqlOutput::Owned(rusqlite::types::Value::Null)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromSql for sq::SqlValue {
|
||||
fn column_result(value: ValueRef<'_>) -> Result<Self, FromSqlError> {
|
||||
match value {
|
||||
ValueRef::Integer(i) => Ok(sq::SqlValue::Integer(i)),
|
||||
ValueRef::Real(f) => Ok(sq::SqlValue::Real(f)),
|
||||
ValueRef::Text(t) => {
|
||||
let text_str = std::str::from_utf8(t).map_err(|_| FromSqlError::InvalidType)?;
|
||||
Ok(sq::SqlValue::Text(text_str.to_string()))
|
||||
},
|
||||
ValueRef::Blob(b) => Ok(sq::SqlValue::Blob(b.to_vec())),
|
||||
_ => Err(FromSqlError::InvalidType),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CPreOptionStr {
|
||||
is_empty: c_int, // 0 -> string is empty
|
||||
string: CString,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct COptionStr {
|
||||
is_empty: c_int, // 0 -> string is empty
|
||||
string: *mut c_char,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct CBytes {
|
||||
data: *mut u8,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CPayload {
|
||||
is_empty: c_int, // 0 -> payload is empty
|
||||
mime: *mut COptionStr,
|
||||
bytes: *mut CBytes,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CPrePayload {
|
||||
is_empty: c_int, // 0 -> payload is empty
|
||||
mime: COptionStr,
|
||||
bytes: CBytes,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CProcessId {
|
||||
process_name: *const c_char,
|
||||
package_name: *const c_char,
|
||||
publisher_node: *const c_char,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CIpcMetadata {
|
||||
ipc: *mut COptionStr,
|
||||
metadata: *mut COptionStr,
|
||||
}
|
||||
|
||||
impl CPreOptionStr {
|
||||
fn new(s: Option<Vec<u8>>) -> Self {
|
||||
let (is_empty, string) = match s {
|
||||
None => (0, CString::new("").unwrap()),
|
||||
Some(s) => (1, CString::new(s).unwrap()),
|
||||
};
|
||||
CPreOptionStr {
|
||||
is_empty,
|
||||
string,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl COptionStr {
|
||||
fn new(s: Option<Vec<u8>>) -> Self {
|
||||
let (is_empty, string) = match s {
|
||||
None => (0, CString::new("").unwrap()),
|
||||
Some(s) => (1, CString::new(s).unwrap()),
|
||||
};
|
||||
COptionStr {
|
||||
is_empty,
|
||||
string: string.as_ptr() as *mut c_char,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_coptionstr_to_bytes(s: *const COptionStr) -> Vec<u8> {
|
||||
if unsafe { (*s).is_empty == 0 } {
|
||||
vec![]
|
||||
} else {
|
||||
from_cstr_to_string(unsafe { (*s).string }).as_bytes().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
fn from_coptionstr_to_option_string(s: *const COptionStr) -> Option<String> {
|
||||
if unsafe { (*s).is_empty == 0 } {
|
||||
None
|
||||
} else {
|
||||
Some(from_cstr_to_string(unsafe { (*s).string }))
|
||||
}
|
||||
}
|
||||
|
||||
impl CBytes {
|
||||
fn new(mut bytes: Vec<u8>) -> Self {
|
||||
CBytes {
|
||||
data: bytes.as_mut_ptr(),
|
||||
len: bytes.len(),
|
||||
}
|
||||
}
|
||||
|
||||
fn new_empty() -> Self {
|
||||
CBytes::new(Vec::with_capacity(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for CBytes {
|
||||
fn from(bytes: Vec<u8>) -> Self {
|
||||
CBytes::new(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CBytes> for Vec<u8> {
|
||||
fn from(bytes: CBytes) -> Self {
|
||||
let bytes = unsafe { Vec::from_raw_parts(bytes.data, bytes.len, bytes.len) };
|
||||
bytes
|
||||
}
|
||||
}
|
||||
|
||||
fn from_cbytes_to_vec_u8(bytes: *mut CBytes) -> Vec<u8> {
|
||||
// let bytes = unsafe { Vec::from_raw_parts((*bytes).data, (*bytes).len, (*bytes).len) };
|
||||
let bytes = unsafe { std::slice::from_raw_parts((*bytes).data, (*bytes).len) };
|
||||
let bytes = bytes.to_vec();
|
||||
bytes
|
||||
}
|
||||
|
||||
impl From<Option<wit::Payload>> for CPrePayload {
|
||||
fn from(p: Option<wit::Payload>) -> Self {
|
||||
let (is_empty, mime, bytes) = match p {
|
||||
None => (0, COptionStr::new(None), CBytes::new_empty()),
|
||||
Some(wit::Payload { mime, bytes }) => {
|
||||
let mime = match mime {
|
||||
Some(s) => Some(s.as_bytes().to_vec()),
|
||||
None => None,
|
||||
};
|
||||
(1, COptionStr::new(mime), CBytes::new(bytes))
|
||||
}
|
||||
};
|
||||
CPrePayload {
|
||||
is_empty,
|
||||
mime,
|
||||
bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CPayload> for Option<wit::Payload> {
|
||||
fn from(p: CPayload) -> Self {
|
||||
if p.is_empty == 0 {
|
||||
None
|
||||
} else {
|
||||
let mime = from_coptionstr_to_option_string(p.mime);
|
||||
let bytes = from_cbytes_to_vec_u8(p.bytes);
|
||||
Some(wit::Payload {
|
||||
mime,
|
||||
bytes,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_cpayload_to_option_payload(p: *const CPayload) -> Option<wit::Payload> {
|
||||
if unsafe { (*p).is_empty == 0 } {
|
||||
None
|
||||
} else {
|
||||
let mime = unsafe { from_coptionstr_to_option_string((*p).mime) };
|
||||
let bytes = unsafe { from_cbytes_to_vec_u8((*p).bytes) };
|
||||
Some(wit::Payload {
|
||||
mime,
|
||||
bytes,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn from_cprocessid_to_processid(pid: *const CProcessId) -> ProcessId {
|
||||
ProcessId {
|
||||
process_name: from_cstr_to_string(unsafe { (*pid).process_name }),
|
||||
package_name: from_cstr_to_string(unsafe { (*pid).package_name }),
|
||||
publisher_node: from_cstr_to_string(unsafe { (*pid).publisher_node }),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_cstr_to_string(s: *const c_char) -> String {
|
||||
let cstr = unsafe { CStr::from_ptr(s) };
|
||||
cstr.to_str().unwrap().into()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_payload_wrapped(return_val: *mut CPayload) {
|
||||
// TODO: remove this logic; just here to avoid writing to invalid places
|
||||
// in memory due to an fs bug where chunk size may be bigger than requested
|
||||
let max_len = unsafe { (*(*return_val).bytes).len.clone() };
|
||||
|
||||
let payload = wit::get_payload();
|
||||
let mime_len = {
|
||||
match payload {
|
||||
None => None,
|
||||
Some(ref payload) => {
|
||||
match payload.mime {
|
||||
None => None,
|
||||
Some(ref mime) => {
|
||||
Some(mime.len())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
unsafe {
|
||||
match payload {
|
||||
None => {},
|
||||
Some(payload) => {
|
||||
(*return_val).is_empty = 1;
|
||||
match payload.mime {
|
||||
None => {},
|
||||
Some(mime) => {
|
||||
(*(*return_val).mime).is_empty = 1;
|
||||
let Some(mime_len) = mime_len else { panic!("") };
|
||||
let mime = CString::new(mime).unwrap();
|
||||
std::ptr::copy_nonoverlapping(
|
||||
mime.as_ptr(),
|
||||
(*(*return_val).mime).string,
|
||||
mime_len + 1,
|
||||
);
|
||||
},
|
||||
}
|
||||
(*(*return_val).bytes).len = std::cmp::min(max_len, payload.bytes.len());
|
||||
std::ptr::copy_nonoverlapping(
|
||||
payload.bytes.as_ptr(),
|
||||
(*(*return_val).bytes).data,
|
||||
std::cmp::min(max_len, payload.bytes.len()),
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CIpcMetadata {
|
||||
fn copy_to_ptr(ptr: *mut CIpcMetadata, ipc: CPreOptionStr, metadata: CPreOptionStr) {
|
||||
unsafe {
|
||||
(*(*ptr).ipc).is_empty = ipc.is_empty;
|
||||
if ipc.is_empty == 1 {
|
||||
std::ptr::copy_nonoverlapping(
|
||||
ipc.string.as_ptr(),
|
||||
(*(*ptr).ipc).string,
|
||||
ipc.string.as_bytes_with_nul().len(),
|
||||
);
|
||||
}
|
||||
(*(*ptr).metadata).is_empty = metadata.is_empty;
|
||||
if metadata.is_empty == 1 {
|
||||
std::ptr::copy_nonoverlapping(
|
||||
metadata.string.as_ptr(),
|
||||
(*(*ptr).metadata).string,
|
||||
metadata.string.as_bytes_with_nul().len(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn send_and_await_response_wrapped(
|
||||
target_node: *const c_char,
|
||||
target_process: *const CProcessId,
|
||||
request_ipc: *const COptionStr,
|
||||
request_metadata: *const COptionStr,
|
||||
payload: *const CPayload,
|
||||
timeout: c_ulonglong,
|
||||
return_val: *mut CIpcMetadata,
|
||||
) {
|
||||
let target_node = from_cstr_to_string(target_node);
|
||||
let target_process = from_cprocessid_to_processid(target_process);
|
||||
let payload = from_cpayload_to_option_payload(payload);
|
||||
let request_ipc = from_coptionstr_to_bytes(request_ipc);
|
||||
let request_metadata = from_coptionstr_to_option_string(request_metadata);
|
||||
let (
|
||||
_,
|
||||
wit::Message::Response((wit::Response { ipc, metadata, .. }, _)),
|
||||
) = wit::send_and_await_response(
|
||||
&wit::Address {
|
||||
node: target_node,
|
||||
process: target_process,
|
||||
},
|
||||
&wit::Request {
|
||||
inherit: false,
|
||||
expects_response: Some(timeout),
|
||||
ipc: request_ipc,
|
||||
metadata: request_metadata,
|
||||
},
|
||||
match payload {
|
||||
None => None,
|
||||
Some(ref p) => Some(p),
|
||||
},
|
||||
).unwrap() else {
|
||||
panic!("");
|
||||
};
|
||||
let ipc = CPreOptionStr::new(Some(ipc));
|
||||
let metadata = CPreOptionStr::new(match metadata {
|
||||
None => None,
|
||||
Some(s) => Some(s.as_bytes().to_vec())
|
||||
});
|
||||
|
||||
CIpcMetadata::copy_to_ptr(return_val, ipc, metadata);
|
||||
}
|
||||
|
||||
fn json_to_sqlite(value: &serde_json::Value) -> Result<sq::SqlValue, sq::SqliteError> {
|
||||
match value {
|
||||
serde_json::Value::Number(n) => {
|
||||
if let Some(int_val) = n.as_i64() {
|
||||
Ok(sq::SqlValue::Integer(int_val))
|
||||
} else if let Some(float_val) = n.as_f64() {
|
||||
Ok(sq::SqlValue::Real(float_val))
|
||||
} else {
|
||||
Err(sq::SqliteError::InvalidParameters)
|
||||
}
|
||||
},
|
||||
serde_json::Value::String(s) => {
|
||||
match base64::decode(&s) {
|
||||
Ok(decoded_bytes) => {
|
||||
// Convert to SQLite Blob if it's a valid base64 string
|
||||
Ok(sq::SqlValue::Blob(decoded_bytes))
|
||||
},
|
||||
Err(_) => {
|
||||
// If it's not base64, just use the string itself
|
||||
Ok(sq::SqlValue::Text(s.clone()))
|
||||
}
|
||||
}
|
||||
},
|
||||
serde_json::Value::Bool(b) => {
|
||||
Ok(sq::SqlValue::Boolean(*b))
|
||||
},
|
||||
serde_json::Value::Null => {
|
||||
Ok(sq::SqlValue::Null)
|
||||
},
|
||||
_ => {
|
||||
Err(sq::SqliteError::InvalidParameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_message(
|
||||
our: &wit::Address,
|
||||
conn: &mut Option<rusqlite::Connection>,
|
||||
txs: &mut HashMap<u64, Vec<(String, Vec<sq::SqlValue>)>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let (source, message) = wit::receive().unwrap();
|
||||
|
||||
if our.node != source.node {
|
||||
return Err(sq::SqliteError::RejectForeign.into());
|
||||
}
|
||||
|
||||
match message {
|
||||
wit::Message::Response(_) => { unimplemented!() },
|
||||
wit::Message::Request(wit::Request { ipc, .. }) => {
|
||||
match serde_json::from_slice(&ipc)? {
|
||||
sq::SqliteMessage::New { db } => {
|
||||
let vfs_drive = format!("{}{}", PREFIX, db);
|
||||
|
||||
match conn {
|
||||
Some(_) => {
|
||||
return Err(sq::SqliteError::DbAlreadyExists.into());
|
||||
},
|
||||
None => {
|
||||
let flags = rusqlite::OpenFlags::default();
|
||||
*conn = Some(rusqlite::Connection::open_with_flags_and_vfs(
|
||||
format!(
|
||||
"{}:{}:/{}.sql",
|
||||
our.node,
|
||||
vfs_drive,
|
||||
db,
|
||||
),
|
||||
flags,
|
||||
"uqbar",
|
||||
)?);
|
||||
},
|
||||
}
|
||||
},
|
||||
sq::SqliteMessage::Write { ref statement, tx_id, .. } => {
|
||||
let Some(ref conn) = conn else {
|
||||
return Err(sq::SqliteError::DbDoesNotExist.into());
|
||||
};
|
||||
|
||||
let parameters: Vec<sq::SqlValue> = match wit::get_payload() {
|
||||
None => vec![],
|
||||
Some(wit::Payload { mime: _, ref bytes }) => {
|
||||
let json_params = serde_json::from_slice::<serde_json::Value>(bytes)?;
|
||||
match json_params {
|
||||
serde_json::Value::Array(vec) => {
|
||||
vec.iter().map(|value| json_to_sqlite(value)).collect::<Result<Vec<_>, _>>()?
|
||||
},
|
||||
_ => {
|
||||
return Err(sq::SqliteError::InvalidParameters.into());
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
match tx_id {
|
||||
Some(tx_id) => {
|
||||
txs.entry(tx_id)
|
||||
.or_insert_with(Vec::new)
|
||||
.push((statement.clone(), parameters));
|
||||
},
|
||||
None => {
|
||||
let mut stmt = conn.prepare(statement)?;
|
||||
stmt.execute(rusqlite::params_from_iter(parameters.iter()))?;
|
||||
},
|
||||
};
|
||||
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
},
|
||||
sq::SqliteMessage::Commit { ref tx_id, .. } => {
|
||||
let Some(queries) = txs.remove(tx_id) else {
|
||||
return Err(sq::SqliteError::NoTx.into());
|
||||
};
|
||||
|
||||
let Some(ref mut conn) = conn else {
|
||||
return Err(sq::SqliteError::DbDoesNotExist.into());
|
||||
};
|
||||
|
||||
let tx = conn.transaction()?;
|
||||
for (query, params) in queries {
|
||||
tx.execute(&query, rusqlite::params_from_iter(params.iter()))?;
|
||||
}
|
||||
|
||||
tx.commit()?;
|
||||
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.send()?;
|
||||
},
|
||||
sq::SqliteMessage::Read { ref query, .. } => {
|
||||
let Some(ref db_handle) = conn else {
|
||||
return Err(sq::SqliteError::DbDoesNotExist.into());
|
||||
};
|
||||
|
||||
let parameters: Vec<sq::SqlValue> = match wit::get_payload() {
|
||||
None => vec![],
|
||||
Some(wit::Payload { mime: _, ref bytes }) => {
|
||||
let json_params = serde_json::from_slice::<serde_json::Value>(bytes)?;
|
||||
match json_params {
|
||||
serde_json::Value::Array(vec) => {
|
||||
vec.iter().map(|value| json_to_sqlite(value)).collect::<Result<Vec<_>, _>>()?
|
||||
},
|
||||
_ => {
|
||||
return Err(sq::SqliteError::InvalidParameters.into());
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let mut statement = db_handle.prepare(query)?;
|
||||
let column_names: Vec<String> = statement
|
||||
.column_names()
|
||||
.iter()
|
||||
.map(|c| c.to_string())
|
||||
.collect();
|
||||
|
||||
let results: Vec<HashMap<String, serde_json::Value>> = statement
|
||||
.query_map(rusqlite::params_from_iter(parameters.iter()), |row| {
|
||||
let mut map = HashMap::new();
|
||||
for (i, column_name) in column_names.iter().enumerate() {
|
||||
let value: sq::SqlValue = row.get(i)?;
|
||||
let value_json = match value {
|
||||
sq::SqlValue::Integer(int) => serde_json::Value::Number(int.into()),
|
||||
sq::SqlValue::Real(real) => serde_json::Value::Number(serde_json::Number::from_f64(real).unwrap()),
|
||||
sq::SqlValue::Text(text) => serde_json::Value::String(text),
|
||||
sq::SqlValue::Blob(blob) => serde_json::Value::String(base64::encode(blob)), // or another representation if you prefer
|
||||
_ => serde_json::Value::Null,
|
||||
};
|
||||
map.insert(column_name.clone(), value_json);
|
||||
}
|
||||
Ok(map)
|
||||
})?
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let results = serde_json::json!(results).to_string();
|
||||
let results_bytes = results.as_bytes().to_vec();
|
||||
|
||||
Response::new()
|
||||
.ipc(ipc)
|
||||
.payload(wit::Payload {
|
||||
mime: None,
|
||||
bytes: results_bytes,
|
||||
})
|
||||
.send()?;
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
struct Component;
|
||||
impl Guest for Component {
|
||||
fn init(our: String) {
|
||||
wit::print_to_terminal(1, "sqlite_worker: begin");
|
||||
let our = Address::from_str(&our).unwrap();
|
||||
|
||||
let mut conn: Option<rusqlite::Connection> = None;
|
||||
let mut txs: HashMap<u64, Vec<(String, Vec<sq::SqlValue>)>> = HashMap::new();
|
||||
|
||||
let vfs_address = ProcessId::from_str("vfs:sys:uqbar").unwrap();
|
||||
create_capability(
|
||||
&vfs_address,
|
||||
&"\"messaging\"".into(),
|
||||
);
|
||||
|
||||
loop {
|
||||
match handle_message(&our, &mut conn, &mut txs) {
|
||||
Ok(()) => {},
|
||||
Err(e) => {
|
||||
// TODO: should we send an error on failure?
|
||||
wit::print_to_terminal(0, format!(
|
||||
"sqlite_worker: error: {:?}",
|
||||
e,
|
||||
).as_str());
|
||||
if let Some(e) = e.downcast_ref::<sq::SqliteError>() {
|
||||
Response::new()
|
||||
.ipc(serde_json::to_vec(&e).unwrap())
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../sqlite_types.rs
|
Loading…
Reference in New Issue
Block a user