basic get command works with items from 0/config defined in test-config.toml
This commit is contained in:
157
Cargo.lock
generated
157
Cargo.lock
generated
@@ -309,12 +309,6 @@ version = "3.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
@@ -327,16 +321,6 @@ version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||
|
||||
[[package]]
|
||||
name = "cbor"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e56053652b4b5c0ded5ae6183c7cd547ad2dd6bcce149658bef052a4995533bd"
|
||||
dependencies = [
|
||||
"byteorder 0.5.3",
|
||||
"rustc-serialize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.97"
|
||||
@@ -367,6 +351,33 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"ciborium-ll",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-io"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-ll"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"half",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.4"
|
||||
@@ -469,6 +480,12 @@ version = "0.8.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
@@ -557,6 +574,12 @@ dependencies = [
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.9"
|
||||
@@ -685,7 +708,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
|
||||
dependencies = [
|
||||
"fallible-iterator",
|
||||
"indexmap",
|
||||
"indexmap 1.9.3",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
@@ -695,12 +718,28 @@ version = "0.28.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "headers"
|
||||
version = "0.3.9"
|
||||
@@ -882,7 +921,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"hashbrown 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.14.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1002,7 +1051,7 @@ dependencies = [
|
||||
"axum",
|
||||
"axum-extra",
|
||||
"axum-macros",
|
||||
"cbor",
|
||||
"ciborium",
|
||||
"clap",
|
||||
"colored",
|
||||
"console_error_panic_hook",
|
||||
@@ -1011,7 +1060,9 @@ dependencies = [
|
||||
"home",
|
||||
"log",
|
||||
"nix",
|
||||
"serde",
|
||||
"tokio",
|
||||
"toml",
|
||||
"uuid",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-cli",
|
||||
@@ -1301,12 +1352,6 @@ version = "0.1.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-serialize"
|
||||
version = "0.3.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.34"
|
||||
@@ -1377,18 +1422,18 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.202"
|
||||
version = "1.0.203"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
|
||||
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.202"
|
||||
version = "1.0.203"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
|
||||
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1416,6 +1461,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
@@ -1660,6 +1714,40 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c"
|
||||
dependencies = [
|
||||
"indexmap 2.2.6",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.4.13"
|
||||
@@ -1744,7 +1832,7 @@ version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9"
|
||||
dependencies = [
|
||||
"byteorder 1.5.0",
|
||||
"byteorder",
|
||||
"bytes",
|
||||
"data-encoding",
|
||||
"http",
|
||||
@@ -2310,6 +2398,15 @@ version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86c949fede1d13936a99f14fafd3e76fd642b556dd2ce96287fbe2e0151bfac6"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.7.0"
|
||||
|
||||
@@ -17,7 +17,7 @@ path = "src/platform/os/main.rs"
|
||||
required-features = [ "os-target" ]
|
||||
|
||||
[features]
|
||||
os-target = [ "clap", "home", "env_logger", "daemonize", "nix" ]
|
||||
os-target = [ "clap", "home", "env_logger", "daemonize", "nix", "toml" ]
|
||||
wasm-target = [ "wasm-bindgen", "console_error_panic_hook", "wasm-bindgen-cli" ]
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ colored = "2.0.0"
|
||||
uuid = "1.3.0"
|
||||
log = "0.4.20"
|
||||
tokio = { version = "1.21.0", features = ["sync"] }
|
||||
cbor = "0.4.1"
|
||||
ciborium = { version = "0.2.2", default-features = false }
|
||||
serde = "1.0.203"
|
||||
|
||||
# wasm dependencies
|
||||
wasm-bindgen = { version = "0.2.84", optional = true }
|
||||
@@ -40,6 +41,7 @@ home = { version = "0.5.9", optional = true }
|
||||
env_logger = { version = "0.10.1", optional = true }
|
||||
daemonize = { version = "0.5.0", optional = true }
|
||||
nix = { version = "0.27.1", features = ["signal"], optional = true }
|
||||
toml = { version = "0.8.13", features = ["parse"], optional = true }
|
||||
|
||||
# bare dependencies
|
||||
|
||||
|
||||
@@ -89,6 +89,9 @@ in {
|
||||
*/
|
||||
(fenix.packages.${system}.combine [ wasmToolchain osToolchain ])
|
||||
];
|
||||
shellHook = ''
|
||||
export MIZE_CONFIG_FILE=${self}/default-config.toml
|
||||
'';
|
||||
};
|
||||
|
||||
}) // {
|
||||
|
||||
@@ -103,7 +103,13 @@ impl MizeError {
|
||||
}
|
||||
|
||||
pub fn log(self) -> MizeError {
|
||||
error!("MizeError encountered: {}", self.messages.join("\n"));
|
||||
error!("MizeError envountered!");
|
||||
if let Some(ref location) = self.code_location {
|
||||
error!("[ {} ] {}", "LOCATION".yellow(), location);
|
||||
};
|
||||
for msg in &self.messages {
|
||||
error!("[ {} ] {}", "MSG".yellow(), msg);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
@@ -209,7 +215,9 @@ impl<T, E, S> IntoMizeResult<T, S> for Result<T, E> where E: std::fmt::Display {
|
||||
|
||||
match self {
|
||||
Ok(val) => MizeResult::Ok(val),
|
||||
Err(err) => MizeResult::Err(MizeError::new().category("misc").msg(format!("From any Error: {}", err))),
|
||||
Err(err) => MizeResult::Err(MizeError::new()
|
||||
.category("misc")
|
||||
.msg(format!("From {}: {}", std::any::type_name_of_val(&err), err))),
|
||||
}
|
||||
}
|
||||
#[track_caller]
|
||||
@@ -217,7 +225,10 @@ impl<T, E, S> IntoMizeResult<T, S> for Result<T, E> where E: std::fmt::Display {
|
||||
let caller_location = std::panic::Location::caller();
|
||||
match self {
|
||||
Ok(val) => MizeResult::Ok(val),
|
||||
Err(err) => MizeResult::Err(MizeError::new().category("misc").msg(format!("{}", msg)).msg(format!("From any Error: {}", err))),
|
||||
Err(err) => MizeResult::Err(MizeError::new()
|
||||
.category("misc")
|
||||
.msg(format!("{}", msg))
|
||||
.msg(format!("From {}: {}", std::any::type_name_of_val(&err), err))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,34 @@
|
||||
use std::hash::Hash;
|
||||
use core::fmt;
|
||||
use std::{fmt::write, hash::Hash};
|
||||
|
||||
|
||||
#[derive(Hash, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||
pub struct MizeId {
|
||||
path: Vec<String>
|
||||
}
|
||||
|
||||
impl From<String> for MizeId {
|
||||
fn from(value: String) -> Self {
|
||||
MizeId{path: vec![value]}
|
||||
impl MizeId {
|
||||
pub fn store_part(&self) -> &str {
|
||||
self.path.first()
|
||||
.expect("an empty MizeId found, that should absolutely not be possible!!!!").as_str()
|
||||
}
|
||||
pub fn as_vec(self) -> Vec<String> {
|
||||
self.path
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MizeId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.path.join("/"))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<String>> From<T> for MizeId {
|
||||
fn from(value: T) -> Self {
|
||||
let string = value.into();
|
||||
let path: Vec<String> = string.split("/").map(|v| v.to_owned()).collect();
|
||||
return MizeId { path }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use core::fmt;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::create_dir;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use log::{trace, debug, info, warn, error};
|
||||
use uuid::Uuid;
|
||||
use std::fs::File;
|
||||
@@ -21,15 +23,17 @@ pub mod subscription;
|
||||
static MSG_CHANNEL_SIZE: usize = 200;
|
||||
|
||||
/// The Instance type is the heart of the mize system
|
||||
#[derive(Clone)]
|
||||
pub struct Instance<S: Store> {
|
||||
// question vec of stores???
|
||||
// would mean replication logic and such things is handeled by the instance
|
||||
// i think it would be better thogh to then implement a ReplicatedStore
|
||||
store: S,
|
||||
peers: Vec<Box<dyn Connection>>,
|
||||
subs: HashMap<MizeId, Subscription>
|
||||
pub store: S,
|
||||
peers: Arc<Mutex<Vec<Box<dyn Connection>>>>,
|
||||
subs: Arc<Mutex<HashMap<MizeId, Subscription>>>,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
pub enum RealmId {
|
||||
Uuid(Uuid),
|
||||
@@ -38,21 +42,27 @@ pub enum RealmId {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
impl<S: Store> Instance<S> {
|
||||
// new() opens a
|
||||
pub async fn new() -> MizeResult<Instance<MemStore>> {
|
||||
impl Instance<MemStore> {
|
||||
pub fn new() -> MizeResult<Instance<MemStore>> {
|
||||
trace!("[ {} ] Instance::new()", "CALL".yellow());
|
||||
|
||||
let memstore = MemStore::new();
|
||||
let instance = Instance {store: memstore, peers: Vec::new(), subs: HashMap::new()};
|
||||
let instance = Instance {store: memstore, peers: Arc::new(Mutex::new(Vec::new())), subs: Arc::new(Mutex::new(HashMap::new())) };
|
||||
|
||||
|
||||
// platform specific init code
|
||||
// TODO
|
||||
if cfg!(feature = "os-target") { // on os platforms
|
||||
crate::platform::os::os_instance_init(instance.clone())?
|
||||
}
|
||||
|
||||
// end of platform specific init code
|
||||
|
||||
|
||||
return Ok(instance);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Store> Instance<S> {
|
||||
pub fn new_item(self) -> MizeResult<Item<S>> {
|
||||
let id = self.store.new_id()?;
|
||||
return Ok(Item {id, instance: self});
|
||||
@@ -63,9 +73,14 @@ impl<S: Store> Instance<S> {
|
||||
}
|
||||
|
||||
pub fn set<I: Into<MizeId>, V: Into<ItemData>>(self, id: I, value: V) -> MizeResult<()> {
|
||||
self.store.set(id.into(), value)
|
||||
self.store.set(&id.into(), value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<S: Store> fmt::Debug for Instance<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Mize Instance with subs: {:?}", self.subs,)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ pub trait Store {
|
||||
// is implemented, so that there can be a multithreaded implementation
|
||||
//fn get(self, id: MizeId) -> MizeResult<Item<Self>> where Self: Sized;
|
||||
|
||||
fn set<T: Into<ItemData>>(self, id: MizeId, data: T) -> MizeResult<()>;
|
||||
fn set<T: Into<ItemData>>(self, id: &MizeId, data: T) -> MizeResult<()>;
|
||||
|
||||
// in the future should implement transactions, ....
|
||||
|
||||
@@ -19,6 +19,8 @@ pub trait Store {
|
||||
fn get_backlinks(self, item: Item<Self>) -> MizeResult<Vec<MizeId>> where Self: Sized;
|
||||
|
||||
fn new_id(&self) -> MizeResult<MizeId>;
|
||||
|
||||
fn get_value_raw(&self, id: &MizeId) -> MizeResult<Vec<u8>>;
|
||||
}
|
||||
|
||||
/// references an item that is stored in a store
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Subscription;
|
||||
|
||||
@@ -8,10 +8,11 @@ use crate::error::{MizeError, MizeResult, IntoMizeResult};
|
||||
use crate::instance::Instance;
|
||||
use crate::instance::store::Store;
|
||||
use crate::id::MizeId;
|
||||
use cbor::Cbor as CborValue;
|
||||
use ciborium::Value as CborValue;
|
||||
|
||||
|
||||
// a item always has to do with a Instance, which takes care of how it is updated
|
||||
#[derive(Debug)]
|
||||
pub struct Item<S: Store + Sized> {
|
||||
pub id: MizeId,
|
||||
pub instance: Instance<S>
|
||||
@@ -22,16 +23,31 @@ pub struct Item<S: Store + Sized> {
|
||||
pub type ItemData = CborValue;
|
||||
|
||||
impl<S: Store> Item<S> {
|
||||
pub fn id(self) -> MizeId {
|
||||
self.id
|
||||
pub fn id(&self) -> &MizeId {
|
||||
&self.id
|
||||
}
|
||||
|
||||
pub fn value_raw(self) -> MizeResult<Vec<u8>> {
|
||||
pub fn value_raw(&self) -> MizeResult<Vec<u8>> {
|
||||
// this will call from the instance which gets the value from the store
|
||||
Ok(Vec::new())
|
||||
self.instance.store.get_value_raw(&self.id())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Store> Display for Item<S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.value_raw() {
|
||||
Ok(value) => match String::from_utf8(value) {
|
||||
Ok(string) => write!(f, "{}", string),
|
||||
Err(_) => write!(f, "{:?}", self.value_raw()),
|
||||
}
|
||||
Err(err) => {err.log(); Ok(())},
|
||||
};
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -1,35 +1,101 @@
|
||||
use std::collections::HashMap;
|
||||
use cbor::Cbor as CborValue;
|
||||
use std::iter::Map;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use ciborium::Value as CborValue;
|
||||
use log::trace;
|
||||
|
||||
use crate::id::MizeId;
|
||||
use crate::instance::store::Store;
|
||||
use crate::error::MizeResult;
|
||||
use crate::error::{MizeError, MizeResult, IntoMizeResult};
|
||||
use crate::item::{Item, ItemData};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MemStore {
|
||||
map: HashMap<MizeId, CborValue>,
|
||||
inner: Arc<Mutex<MemStoreInner>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MemStoreInner {
|
||||
map: HashMap<u64, CborValue>,
|
||||
next_id: u64,
|
||||
}
|
||||
|
||||
impl Store for MemStore {
|
||||
fn set<T: Into<ItemData>>(mut self, id: MizeId, data: T) -> MizeResult<()> {
|
||||
self.map.insert(id, data.into());
|
||||
fn set<T: Into<ItemData>>(mut self, id: &MizeId, data: T) -> MizeResult<()> {
|
||||
let mut inner = self.inner.lock()?;
|
||||
|
||||
|
||||
inner.map.insert(id_to_u64(id)?, data.into());
|
||||
return Ok(())
|
||||
}
|
||||
fn get_links(self, item: Item<Self>) -> MizeResult<Vec<MizeId>> {
|
||||
let inner = self.inner.lock()?;
|
||||
|
||||
Ok(Vec::new())
|
||||
}
|
||||
fn get_backlinks(self, item: Item<Self>) -> MizeResult<Vec<MizeId>> {
|
||||
let inner = self.inner.lock()?;
|
||||
|
||||
Ok(Vec::new())
|
||||
}
|
||||
fn new_id(&self) -> MizeResult<MizeId> {
|
||||
let id_string = format!("{}", self.next_id);
|
||||
let inner = self.inner.lock()?;
|
||||
|
||||
let id_string = format!("{}", inner.next_id);
|
||||
return Ok(id_string.into());
|
||||
}
|
||||
fn get_value_raw(&self, id: &MizeId) -> MizeResult<Vec<u8>> {
|
||||
let inner = self.inner.lock()?;
|
||||
|
||||
let cbor_val = inner.map.get(&id_to_u64(id)?)
|
||||
.ok_or(MizeError::new()
|
||||
.msg(format!("Item with store_part: {}, id: {} does not exist in MemStore", id_to_u64(id)?, id)))?;
|
||||
|
||||
let mut id_without_first = id.clone().as_vec();
|
||||
id_without_first.remove(0);
|
||||
get_raw_from_cbor(cbor_val.to_owned(), id_without_first)
|
||||
}
|
||||
}
|
||||
|
||||
impl MemStore {
|
||||
pub fn new() -> MemStore {
|
||||
return MemStore { map: HashMap::new(), next_id: 0 };
|
||||
let inner = MemStoreInner { map: HashMap::new(), next_id: 0 };
|
||||
return MemStore { inner: Arc::new(Mutex::new(inner)) };
|
||||
}
|
||||
}
|
||||
|
||||
fn id_to_u64(id: &MizeId) -> MizeResult<u64> {
|
||||
id.store_part()
|
||||
.parse()
|
||||
.mize_result_msg(format!("Could not parse the store_part of mizeid {} into a u64 for the MemStore", id))
|
||||
}
|
||||
|
||||
fn get_raw_from_cbor(value: CborValue, mut path: Vec<String>) -> MizeResult<Vec<u8>> {
|
||||
match value {
|
||||
CborValue::Bytes(vec) => Ok(vec),
|
||||
CborValue::Text(string) => Ok(string.into_bytes()),
|
||||
CborValue::Map(map) => {
|
||||
let mut inner_val: CborValue = CborValue::Null;
|
||||
trace!("map: {:?}", map);
|
||||
for (key, val) in map.into_iter() {
|
||||
let first_path_string = path.first()
|
||||
.ok_or(MizeError::new().msg("get_raw_from_cbor: path is empty"))?;
|
||||
|
||||
if let CborValue::Text(key_text) = key {
|
||||
if key_text == *first_path_string {
|
||||
inner_val = val
|
||||
}
|
||||
}
|
||||
}
|
||||
if inner_val == CborValue::Null {
|
||||
return Err(MizeError::new().msg(format!("get_raw_from_cbor: Path {} not Found", path.join("/"))))
|
||||
}
|
||||
path.remove(0);
|
||||
get_raw_from_cbor(inner_val, path)
|
||||
},
|
||||
_ => Err(MizeError::new().msg("get_raw_from_cbor: value is not Bytes, Text or Map")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use cbor::Cbor as CborValue;
|
||||
use ciborium::Value as CborValue;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MizeMessage {
|
||||
|
||||
11
src/lib.rs
11
src/lib.rs
@@ -3,9 +3,8 @@
|
||||
|
||||
static PROTO_VERSION: u8 = 1;
|
||||
|
||||
// the core part houses the code that can run on any platform
|
||||
/*
|
||||
pub mod core {
|
||||
// the core part has the code that can run on any platform
|
||||
mod core {
|
||||
pub mod memstore;
|
||||
pub mod instance;
|
||||
pub mod item;
|
||||
@@ -16,11 +15,15 @@ pub mod core {
|
||||
}
|
||||
|
||||
pub use core::*;
|
||||
// */
|
||||
|
||||
|
||||
// platform specific stuff
|
||||
pub mod platform {
|
||||
#[cfg(feature = "wasm-target")]
|
||||
pub mod wasm;
|
||||
|
||||
//#[cfg(feature = "os-target")]
|
||||
pub mod os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use clap::ArgMatches;
|
||||
use mize::error::MizeResult;
|
||||
|
||||
pub fn call(sub_matches: &ArgMatches) {
|
||||
pub fn call(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3,22 +3,22 @@ use std::path::PathBuf;
|
||||
use clap::ArgMatches;
|
||||
use home::home_dir;
|
||||
|
||||
use mize::error::{MizeResultTrait, IntoMizeResult, MizeError};
|
||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||
use mize::instance::Instance;
|
||||
|
||||
|
||||
|
||||
pub fn get(sub_matches: &ArgMatches) {
|
||||
let instance_folder_path = match sub_matches.get_one::<String>("store") {
|
||||
Some(a) => PathBuf::from(a),
|
||||
None => {
|
||||
let mut home_dir = home_dir()
|
||||
.ok_or(MizeError::new().category("io").category("env").msg("could not get the home directory, where the mize store is by default")).critical();
|
||||
home_dir.push(".mize");
|
||||
home_dir
|
||||
},
|
||||
};
|
||||
println!("unfinished");
|
||||
//let instance = Instance::new(instance_folder_path);
|
||||
pub fn get(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
let instance = Instance::new()?;
|
||||
|
||||
let id = sub_matches.get_one::<String>("id")
|
||||
.ok_or(MizeError::new().msg("No id Argument specified"))?;
|
||||
|
||||
let item = instance.get(id)?;
|
||||
|
||||
println!("{}", item);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use clap::ArgMatches;
|
||||
use mize::error::MizeResult;
|
||||
|
||||
pub fn mount(sub_matches: &ArgMatches) {
|
||||
pub fn mount(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ use std::fs::File;
|
||||
use log::{trace, debug, info, warn, error};
|
||||
use nix::sys::signal::{self, Signal};
|
||||
|
||||
use mize::error::{MizeResultTrait, IntoMizeResult, MizeError};
|
||||
use mize::error::{MizeResultTrait, IntoMizeResult, MizeError, MizeResult};
|
||||
use mize::instance::Instance;
|
||||
|
||||
|
||||
pub fn daemon(sub_matches: &ArgMatches) {
|
||||
println!("not implemented");
|
||||
pub fn run(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
let instance = Instance::new();
|
||||
/*
|
||||
let instance_path = match sub_matches.get_one::<String>("store") {
|
||||
Some(a) => PathBuf::from(a),
|
||||
@@ -63,4 +64,5 @@ pub fn daemon(sub_matches: &ArgMatches) {
|
||||
},
|
||||
}
|
||||
*/
|
||||
return Ok(());
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
use clap::ArgMatches;
|
||||
|
||||
pub fn serve(sub_matches: &ArgMatches) {
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
use clap::ArgMatches;
|
||||
use mize::error::MizeResult;
|
||||
|
||||
pub fn set(sub_matches: &ArgMatches) {
|
||||
pub fn set(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
use clap::ArgMatches;
|
||||
use mize::error::MizeResult;
|
||||
use mize::instance::Instance;
|
||||
|
||||
pub fn show(sub_matches: &ArgMatches) {
|
||||
pub fn show(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
let instance = Instance::new()?;
|
||||
|
||||
println!("0/config/test is: {}", instance.get("0/config/test")?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
6
src/platform/os/cli/stop.rs
Normal file
6
src/platform/os/cli/stop.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use clap::ArgMatches;
|
||||
use mize::error::MizeResult;
|
||||
|
||||
pub fn stop(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use std::path::PathBuf;
|
||||
use clap::{ArgAction, ArgMatches};
|
||||
use clap::{Arg, crate_version, Command};
|
||||
|
||||
use mize::error::MizeError;
|
||||
use tokio::sync::{Mutex, mpsc};
|
||||
use std::sync::Arc;
|
||||
use log::Level;
|
||||
@@ -17,16 +18,16 @@ use std::env;
|
||||
use log::{trace, debug, info, warn, error};
|
||||
|
||||
mod cli {
|
||||
pub mod daemon;
|
||||
pub mod serve;
|
||||
pub mod run;
|
||||
pub mod stop;
|
||||
pub mod get;
|
||||
pub mod set;
|
||||
pub mod show;
|
||||
pub mod mount;
|
||||
pub mod call;
|
||||
|
||||
pub use daemon::daemon;
|
||||
pub use serve::serve;
|
||||
pub use run::run;
|
||||
pub use stop::stop;
|
||||
pub use get::get;
|
||||
pub use set::set;
|
||||
pub use show::show;
|
||||
@@ -51,12 +52,12 @@ fn main() {
|
||||
|
||||
|
||||
// match command
|
||||
match cli_matches.subcommand() {
|
||||
let result = match cli_matches.subcommand() {
|
||||
// mi daemon
|
||||
Some(("daemon", sub_matches)) => cli::daemon(sub_matches),
|
||||
Some(("daemon", sub_matches)) => cli::run(sub_matches),
|
||||
|
||||
// mi serve
|
||||
Some(("serve", sub_matches)) => cli::serve(sub_matches),
|
||||
Some(("serve", sub_matches)) => cli::stop(sub_matches),
|
||||
|
||||
// mi mount
|
||||
Some(("mount", sub_matches)) => cli::mount(sub_matches),
|
||||
@@ -74,12 +75,14 @@ fn main() {
|
||||
Some(("call", sub_matches)) => cli::call(sub_matches),
|
||||
|
||||
// some unknown command passed
|
||||
Some((cmd, sub_matches)) => error!("The subcommand: {} is not known. use --help to list availavle commands", cmd),
|
||||
Some((cmd, sub_matches)) => Err(MizeError::new().msg(format!("The subcommand: {} is not known. use --help to list availavle commands", cmd))),
|
||||
|
||||
None => error!("No subcommand was passed. use --help to list availavle comamnds."),
|
||||
None => Err(MizeError::new().msg("No subcommand was passed. use --help to list availavle comamnds.")),
|
||||
};
|
||||
|
||||
if let Err(err) = result {
|
||||
err.log();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn init_logger(cli_matches: &ArgMatches) {
|
||||
@@ -282,24 +285,12 @@ fn cli_matches() -> clap::ArgMatches {
|
||||
.help("set the log-level to OFF")
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("daemon")
|
||||
.aliases(["da"])
|
||||
.arg(&store_arg)
|
||||
.about("Starts the mize daemon. Has subcommands to stop, etc")
|
||||
Command::new("run")
|
||||
.aliases(["r"])
|
||||
.about("Run a MiZe Instance")
|
||||
)
|
||||
.subcommand(Command::new("stop")
|
||||
.about("Stops the mize daemon if one is running")
|
||||
)
|
||||
.subcommand(Command::new("kill"))
|
||||
.about("Stops the mize daemon with a signal")
|
||||
.alias("k")
|
||||
.subcommand(Command::new("status")
|
||||
.alias("st")
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("serve")
|
||||
.aliases(["se"])
|
||||
.arg(&store_arg)
|
||||
.about("Stop a MiZe Instance")
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("mount")
|
||||
|
||||
32
src/platform/os/mod.rs
Normal file
32
src/platform/os/mod.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use ciborium::Value as CborValue;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
|
||||
use crate::id::MizeId;
|
||||
use crate::instance::store::Store;
|
||||
use crate::instance::Instance;
|
||||
use crate::error::{IntoMizeResult, MizeError, MizeResult};
|
||||
|
||||
|
||||
pub fn os_instance_init<S: Store>(instance: Instance<S>) -> MizeResult<()> {
|
||||
// this is the code, that runs to initialize an Instance on a system with an os present.
|
||||
|
||||
// load MIZE_CONFIG_FILE as the instance, which is item 0
|
||||
let config_file_path = std::env::var("MIZE_CONFIG_FILE")
|
||||
.mize_result_msg("Could not get the MIZE_CONFIG_FILE Environment Variable")?;
|
||||
|
||||
let toml_string = fs::read_to_string(&config_file_path)
|
||||
.mize_result_msg(format!("Could not read file {} as mize config", &config_file_path))?;
|
||||
|
||||
let toml_deserializer = toml::Deserializer::new(&toml_string.as_str());
|
||||
|
||||
let config = CborValue::deserialize(toml_deserializer)
|
||||
.mize_result_msg(format!("Could not deserialize the content of MIZE_CONFIG_FILE at {}", &config_file_path))?;
|
||||
|
||||
instance.set("0", config)?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
|
||||
4
test-config.toml
Normal file
4
test-config.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
[config]
|
||||
namespace = "test.c2vi.dev"
|
||||
test = "hello from test item"
|
||||
Reference in New Issue
Block a user