From f414245168cd0b86b43131ebc4b790da5fc1b368 Mon Sep 17 00:00:00 2001 From: ppom Date: Sun, 14 Dec 2025 12:00:00 +0100 Subject: [PATCH] Separate treedb into its own crate --- Cargo.lock | 16 ++ Cargo.toml | 27 +++- crates/treedb/Cargo.toml | 23 +++ {src/treedb => crates/treedb/src}/helpers.rs | 73 +-------- src/treedb/mod.rs => crates/treedb/src/lib.rs | 145 ++++++++---------- {src/treedb => crates/treedb/src}/raw.rs | 10 +- {src/concepts => crates/treedb/src}/time.rs | 0 plugins/reaction-plugin/src/shutdown.rs | 4 + src/concepts/config.rs | 11 +- src/concepts/mod.rs | 3 +- src/daemon/filter/mod.rs | 2 +- src/daemon/filter/state.rs | 79 ++++++++-- src/daemon/mod.rs | 10 +- src/lib.rs | 1 - src/tests.rs | 2 +- 15 files changed, 214 insertions(+), 192 deletions(-) create mode 100644 crates/treedb/Cargo.toml rename {src/treedb => crates/treedb/src}/helpers.rs (72%) rename src/treedb/mod.rs => crates/treedb/src/lib.rs (88%) rename {src/treedb => crates/treedb/src}/raw.rs (98%) rename {src/concepts => crates/treedb/src}/time.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 6722383..e8cd50e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2841,6 +2841,7 @@ dependencies = [ "tokio-util", "tracing", "tracing-subscriber", + "treedb", ] [[package]] @@ -3962,6 +3963,21 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "treedb" +version = "1.0.0" +dependencies = [ + "chrono", + "futures", + "serde", + "serde_json", + "tempfile", + "thiserror 1.0.69", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "try-lock" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index 682e1e6..b9c7a9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ assets = [ [dependencies] # Time types -chrono = { workspace = true } +chrono.workspace = true # CLI parsing clap = { version = "4.5.4", features = ["derive"] } # Unix interfaces @@ -48,17 +48,19 @@ serde_json.workspace = true serde_yaml = "0.9.34" jrsonnet-evaluator = "0.4.2" # Error macro -thiserror = "1.0.63" +thiserror.workspace = true # Async runtime & helpers futures = { workspace = true } tokio = { workspace = true, features = ["full", "tracing"] } tokio-util = { workspace = true, features = ["codec"] } # Async logging -tracing = "0.1.40" +tracing.workspace = true tracing-subscriber = "0.3.18" +# Database +treedb.workspace = true # Reaction plugin system -remoc = { workspace = true } -reaction-plugin = { workspace = true } +remoc.workspace = true +reaction-plugin.workspace = true [build-dependencies] clap = { version = "4.5.4", features = ["derive"] } @@ -69,13 +71,20 @@ tracing = "0.1.40" [dev-dependencies] rand = "0.8.5" -tempfile = "3.12.0" +treedb.workspace = true +treedb.features = ["test"] +tempfile.workspace = true assert_fs.workspace = true assert_cmd = "2.0.17" predicates = "3.1.3" [workspace] -members = ["plugins/reaction-plugin", "plugins/reaction-plugin-cluster", "plugins/reaction-plugin-virtual"] +members = [ + "crates/treedb", + "plugins/reaction-plugin", + "plugins/reaction-plugin-cluster", + "plugins/reaction-plugin-virtual" +] [workspace.dependencies] assert_fs = "1.1.3" @@ -84,6 +93,10 @@ futures = "0.3.30" remoc = { version = "0.18.3" } serde = { version = "1.0.203", features = ["derive"] } serde_json = { version = "1.0.117", features = ["arbitrary_precision"] } +tempfile = "3.12.0" +thiserror = "1.0.63" tokio = { version = "1.40.0" } tokio-util = { version = "0.7.12" } +tracing = "0.1.40" reaction-plugin = { path = "plugins/reaction-plugin" } +treedb = { path = "crates/treedb" } diff --git a/crates/treedb/Cargo.toml b/crates/treedb/Cargo.toml new file mode 100644 index 0000000..9f2c4d3 --- /dev/null +++ b/crates/treedb/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "treedb" +version = "1.0.0" +edition = "2024" + +[features] +test = [] + +[dependencies] +chrono.workspace = true +futures.workspace = true +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true +tokio.workspace = true +tokio.features = ["rt-multi-thread", "macros", "io-util", "time", "fs", "tracing"] +tokio-util.workspace = true +tokio-util.features = ["rt"] +tracing.workspace = true + +[dev-dependencies] +tempfile.workspace = true + diff --git a/src/treedb/helpers.rs b/crates/treedb/src/helpers.rs similarity index 72% rename from src/treedb/helpers.rs rename to crates/treedb/src/helpers.rs index 6645fe2..9e4c3b0 100644 --- a/src/treedb/helpers.rs +++ b/crates/treedb/src/helpers.rs @@ -6,7 +6,7 @@ use std::{ use chrono::DateTime; use serde_json::Value; -use crate::concepts::{Match, MatchTime, Time}; +use crate::time::Time; /// Tries to convert a [`Value`] into a [`String`] pub fn to_string(val: &Value) -> Result { @@ -50,8 +50,8 @@ pub fn to_time(val: &Value) -> Result { string_to_time(val.as_str().ok_or("not a string number")?) } -/// Tries to convert a [`Value`] into a [`Match`] -pub fn to_match(val: &Value) -> Result { +/// Tries to convert a [`Value`] into a [`Vec`] +pub fn to_match(val: &Value) -> Result, String> { val.as_array() .ok_or("not an array")? .iter() @@ -59,15 +59,6 @@ pub fn to_match(val: &Value) -> Result { .collect() } -/// Tries to convert a [`Value`] into a [`MatchTime`] -pub fn to_matchtime(val: &Value) -> Result { - let map = val.as_object().ok_or("not an object")?; - Ok(MatchTime { - m: to_match(map.get("m").ok_or("no m in object")?)?, - t: to_time(map.get("t").ok_or("no t in object")?)?, - }) -} - /// Tries to convert a [`Value`] into a [`BTreeSet