use std::path::PathBuf;
use std::sync::Arc;
use meerkat_core::config::ConfigError;
use meerkat_core::{Config, ConfigDelta, ConfigStore, FileConfigStore, MemoryConfigStore};
#[derive(Clone)]
pub struct SdkConfigStore {
store: Arc<dyn ConfigStore>,
}
impl SdkConfigStore {
pub fn new() -> Self {
let mut config = Config::default();
let _ = config.apply_env_overrides();
Self {
store: Arc::new(MemoryConfigStore::new(config, meerkat_models::canonical())),
}
}
pub fn with_config(config: Config) -> Self {
let mut config = config;
let _ = config.apply_env_overrides();
Self {
store: Arc::new(MemoryConfigStore::new(config, meerkat_models::canonical())),
}
}
pub fn with_path(path: impl Into<PathBuf>) -> Self {
Self {
store: Arc::new(FileConfigStore::new(
path.into(),
meerkat_models::canonical(),
)),
}
}
pub async fn get(&self) -> Result<Config, ConfigError> {
let mut config = self.store.get().await?;
let _ = config.apply_env_overrides();
Ok(config)
}
pub async fn set(&self, config: Config) -> Result<(), ConfigError> {
self.store.set(config).await
}
pub async fn patch(&self, delta: ConfigDelta) -> Result<Config, ConfigError> {
self.store.patch(delta).await
}
pub fn inner(&self) -> Arc<dyn ConfigStore> {
Arc::clone(&self.store)
}
}
impl Default for SdkConfigStore {
fn default() -> Self {
Self::new()
}
}