v0.5.1-pre.008
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: ks-config/src/composition.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
//! Binary composition configuration and resolution into the shared runtime profile contract.
|
||||
|
||||
@@ -13,7 +13,7 @@ const DEFAULT_WALLET_CONFIG_PATH: &str = "config/wallet.config.json";
|
||||
const DEFAULT_EXECUTION_CONFIG_PATH: &str = "config/execution.config.json";
|
||||
|
||||
/// Root composition document used by a binary to select shared configuration profiles.
|
||||
#[derive(Clone, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize)]
|
||||
#[derive(Clone, serde::Deserialize, Eq, PartialEq)]
|
||||
pub struct CompositionConfigDocument {
|
||||
/// Active binary composition profile name.
|
||||
pub active_profile: std::string::String,
|
||||
@@ -24,7 +24,7 @@ pub struct CompositionConfigDocument {
|
||||
}
|
||||
|
||||
/// Paths of shared configuration documents consumed by one binary composition.
|
||||
#[derive(Clone, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize)]
|
||||
#[derive(Clone, serde::Deserialize, Eq, PartialEq)]
|
||||
pub struct CompositionConfigSources {
|
||||
/// Logging configuration document path relative to the workspace root unless absolute.
|
||||
pub logging: std::string::String,
|
||||
@@ -41,12 +41,12 @@ pub struct CompositionConfigSources {
|
||||
}
|
||||
|
||||
/// Named composition profile with optional overrides of each shared document default.
|
||||
#[derive(Clone, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize)]
|
||||
#[derive(Clone, serde::Deserialize, Eq, PartialEq)]
|
||||
pub struct CompositionProfileConfig {
|
||||
/// Composition profile code.
|
||||
pub name: std::string::String,
|
||||
/// Application metadata retained until the application-specific split is completed.
|
||||
pub app: crate::AppSectionConfig,
|
||||
/// Optional binary-owned application settings opaque to the shared composition layer.
|
||||
pub application: std::option::Option<serde_json::Value>,
|
||||
/// Optional logging profile override.
|
||||
pub logging_profile: std::option::Option<std::string::String>,
|
||||
/// Optional transport profile override.
|
||||
@@ -59,12 +59,10 @@ pub struct CompositionProfileConfig {
|
||||
pub wallet_profile: std::option::Option<std::string::String>,
|
||||
/// Optional execution profile override.
|
||||
pub execution_profile: std::option::Option<std::string::String>,
|
||||
/// Desktop demo flags retained until the application-specific split is completed.
|
||||
pub demo: crate::DemoConfig,
|
||||
}
|
||||
|
||||
/// Resolved application configuration and the source documents needed by a binary.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct ComposedAppConfig {
|
||||
/// Parsed binary composition document.
|
||||
pub composition: CompositionConfigDocument,
|
||||
@@ -127,9 +125,9 @@ pub fn validate_composition_json_schema(raw_json: &str) -> ks_core::Result<()> {
|
||||
};
|
||||
return match validator.validate(&instance) {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(()),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::new(
|
||||
std::result::Result::Err(_) => std::result::Result::Err(ks_core::Error::new(
|
||||
"composition_config_schema_validation_failed",
|
||||
error.to_string(),
|
||||
"composition configuration does not satisfy its schema",
|
||||
)),
|
||||
};
|
||||
}
|
||||
@@ -142,10 +140,10 @@ pub fn parse_composition_json(raw_json: &str) -> ks_core::Result<CompositionConf
|
||||
}
|
||||
let document = match serde_json::from_str::<CompositionConfigDocument>(raw_json) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
std::result::Result::Err(_) => {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"composition_config_json_decode_failed",
|
||||
error.to_string(),
|
||||
"composition configuration could not be decoded",
|
||||
));
|
||||
},
|
||||
};
|
||||
@@ -291,7 +289,6 @@ pub fn compose_app_config(
|
||||
};
|
||||
profiles.push(crate::ProfileConfig {
|
||||
name: profile.name.clone(),
|
||||
app: profile.app.clone(),
|
||||
database: store_profile.database.clone(),
|
||||
solana: crate::SolanaConfig {
|
||||
http_endpoints: transport_profile.http_endpoints,
|
||||
@@ -300,7 +297,6 @@ pub fn compose_app_config(
|
||||
},
|
||||
wallet: wallet_profile,
|
||||
execution: execution_profile.config.clone(),
|
||||
demo: profile.demo.clone(),
|
||||
});
|
||||
}
|
||||
let config = crate::AppConfig {
|
||||
@@ -437,20 +433,13 @@ pub fn read_default_shared_app_config_with_environment(
|
||||
},
|
||||
profiles: vec![CompositionProfileConfig {
|
||||
name: profile_name.clone(),
|
||||
app: crate::AppSectionConfig {
|
||||
name: "khadhroony-solana".to_string(),
|
||||
environment: profile_name,
|
||||
},
|
||||
application: std::option::Option::None,
|
||||
logging_profile: std::option::Option::None,
|
||||
transport_profile: std::option::Option::None,
|
||||
listeners_profile: std::option::Option::None,
|
||||
store_profile: std::option::Option::None,
|
||||
wallet_profile: std::option::Option::None,
|
||||
execution_profile: std::option::Option::None,
|
||||
demo: crate::DemoConfig {
|
||||
live_demo_enabled: false,
|
||||
trading_demo_enabled: false,
|
||||
},
|
||||
}],
|
||||
};
|
||||
return compose_app_config(&composition, &transport, &listeners, &store, &wallet, &execution);
|
||||
@@ -593,7 +582,7 @@ mod tests {
|
||||
const DEFAULT_COMPOSITION: &str =
|
||||
include_str!("../../config/kb-app-demo-desktop.default.config.json");
|
||||
const EXAMPLE_COMPOSITION: &str =
|
||||
include_str!("../../config/example.kb-app-demo-desktop.default.config.json");
|
||||
include_str!("../../config/exemples/example.kb-app-demo-desktop.default.config.json");
|
||||
|
||||
#[test]
|
||||
fn default_and_example_compositions_validate() {
|
||||
@@ -613,6 +602,7 @@ mod tests {
|
||||
panic!("local Devnet composition must resolve: {error}")
|
||||
},
|
||||
};
|
||||
assert!(profile.application.is_some());
|
||||
assert!(profile.logging_profile.is_none());
|
||||
assert!(profile.transport_profile.is_none());
|
||||
assert!(profile.store_profile.is_none());
|
||||
|
||||
Reference in New Issue
Block a user