app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 723f20450b59f8ad077aa898849536bf251973cb
parent 7c11beb9e9f84f2d48b5f92c73314efb408b7a27
Author: triesap <triesap@radroots.dev>
Date:   Mon, 19 Jan 2026 17:12:03 +0000

app: add datastore config builder

- add AppDatastoreConfig with idb and key maps
- default datastore config to IDB_CONFIG_DATASTORE
- embed datastore config in AppConfig
- add unit tests for datastore defaults

Diffstat:
Mapp/src/config.rs | 39++++++++++++++++++++++++++++++++++-----
Mapp/src/lib.rs | 1+
2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/app/src/config.rs b/app/src/config.rs @@ -2,7 +2,11 @@ use std::collections::BTreeMap; -use radroots_studio_app_core::idb::{RadrootsClientIdbConfig, IDB_CONFIG_KEYSTORE_NOSTR}; +use radroots_studio_app_core::idb::{ + RadrootsClientIdbConfig, + IDB_CONFIG_DATASTORE, + IDB_CONFIG_KEYSTORE_NOSTR, +}; pub type AppDatastoreKeyParam = fn(&str) -> String; pub type AppDatastoreKeyMap = BTreeMap<&'static str, &'static str>; @@ -40,15 +44,31 @@ impl AppKeystoreConfig { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct AppConfig { +pub struct AppDatastoreConfig { + pub idb_config: RadrootsClientIdbConfig, pub key_maps: AppKeyMapConfig, +} + +impl AppDatastoreConfig { + pub fn default_config(key_maps: AppKeyMapConfig) -> Self { + Self { + idb_config: IDB_CONFIG_DATASTORE, + key_maps, + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct AppConfig { + pub datastore: AppDatastoreConfig, pub keystore: AppKeystoreConfig, } impl AppConfig { pub fn empty() -> Self { + let key_maps = AppKeyMapConfig::empty(); Self { - key_maps: AppKeyMapConfig::empty(), + datastore: AppDatastoreConfig::default_config(key_maps), keystore: AppKeystoreConfig::default_config(), } } @@ -68,10 +88,11 @@ mod tests { app_config_default, app_config_from_env, AppConfig, + AppDatastoreConfig, AppKeyMapConfig, AppKeystoreConfig, }; - use radroots_studio_app_core::idb::IDB_CONFIG_KEYSTORE_NOSTR; + use radroots_studio_app_core::idb::{IDB_CONFIG_DATASTORE, IDB_CONFIG_KEYSTORE_NOSTR}; #[test] fn key_map_config_defaults_empty() { @@ -84,7 +105,7 @@ mod tests { #[test] fn app_config_defaults_empty() { let config = AppConfig::empty(); - assert!(config.key_maps.key_map.is_empty()); + assert!(config.datastore.key_maps.key_map.is_empty()); } #[test] @@ -99,4 +120,12 @@ mod tests { let config = AppKeystoreConfig::default_config(); assert_eq!(config.nostr_store, IDB_CONFIG_KEYSTORE_NOSTR); } + + #[test] + fn datastore_config_defaults_to_idb_store() { + let key_maps = AppKeyMapConfig::empty(); + let config = AppDatastoreConfig::default_config(key_maps); + assert_eq!(config.idb_config, IDB_CONFIG_DATASTORE); + assert!(config.key_maps.key_map.is_empty()); + } } diff --git a/app/src/lib.rs b/app/src/lib.rs @@ -12,6 +12,7 @@ pub use config::{ app_config_default, app_config_from_env, AppConfig, + AppDatastoreConfig, AppDatastoreKeyMap, AppDatastoreKeyObjMap, AppDatastoreKeyParam,