|
| 1 | +//! # ConfigurationProvider Trait |
| 2 | +//! |
| 3 | +//! Defines the abstract service trait for providing and updating configuration |
| 4 | +//! values. |
| 5 | +
|
| 6 | +use async_trait::async_trait; |
| 7 | +use serde_json::Value; |
| 8 | + |
| 9 | +use super::DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, ConfigurationTarget::ConfigurationTarget}; |
| 10 | +use crate::{Environment::Environment::Environment, Error::CommonError::CommonError}; |
| 11 | + |
| 12 | +/// An abstract service contract for an environment component that can provide |
| 13 | +/// the final, merged configuration values and handle requests to update those |
| 14 | +/// values in their persistent storage (e.g., `settings.json` files). |
| 15 | +#[async_trait] |
| 16 | +pub trait ConfigurationProvider: Environment + Send + Sync { |
| 17 | + /// Retrieves a configuration value for a given section or key, applying |
| 18 | + /// specified overrides. |
| 19 | + /// |
| 20 | + /// This method should return the final, effective value after merging all |
| 21 | + /// configuration sources (e.g., default, user, workspace) in the correct |
| 22 | + /// order of precedence. |
| 23 | + /// |
| 24 | + /// # Parameters |
| 25 | + /// |
| 26 | + /// * `Section`: An optional, dot-separated key to a specific configuration |
| 27 | + /// section. If `None`, the entire configuration object should be |
| 28 | + /// returned. |
| 29 | + /// * `Overrides`: A DTO specifying scope overrides (e.g., for a specific |
| 30 | + /// resource or language). |
| 31 | + /// |
| 32 | + /// # Returns |
| 33 | + /// |
| 34 | + /// A `Result` containing the requested configuration as a |
| 35 | + /// `serde_json::Value`. |
| 36 | + async fn GetConfigurationValue( |
| 37 | + &self, |
| 38 | + Section:Option<String>, |
| 39 | + Overrides:ConfigurationOverridesDTO, |
| 40 | + ) -> Result<Value, CommonError>; |
| 41 | + |
| 42 | + /// Updates a configuration value at a specific key and target scope. |
| 43 | + /// |
| 44 | + /// # Parameters |
| 45 | + /// |
| 46 | + /// * `Key`: The dot-separated configuration key to update. |
| 47 | + /// * `ValueToSet`: The new `serde_json::Value` to set for the key. |
| 48 | + /// * `Target`: The `ConfigurationTarget` enum specifying which scope to |
| 49 | + /// write to (e.g., User, WorkSpace). |
| 50 | + /// * `Overrides`: A DTO for scope overrides. |
| 51 | + /// * `ScopeToLanguage`: An optional flag related to language-specific |
| 52 | + /// settings. |
| 53 | + async fn UpdateConfigurationValue( |
| 54 | + &self, |
| 55 | + Key:String, |
| 56 | + ValueToSet:Value, |
| 57 | + Target:ConfigurationTarget, |
| 58 | + Overrides:ConfigurationOverridesDTO, |
| 59 | + ScopeToLanguage:Option<bool>, |
| 60 | + ) -> Result<(), CommonError>; |
| 61 | +} |
0 commit comments