0.5.1-pre.006
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
// file: ks-config/src/settings.rs
|
||||
// version: 20
|
||||
// version: 21
|
||||
|
||||
//! Typed configuration models shared by applications and workers.
|
||||
//! Resolved runtime configuration models retained during the `0.5.1` source-document split.
|
||||
|
||||
use ts_rs::TS; // rust-rules: derive-import
|
||||
|
||||
const CONFIG_JSON_SCHEMA: &str = include_str!("../../config/schemas/app.config.schema.json");
|
||||
const CONFIG_JSON_SCHEMA: &str =
|
||||
include_str!("../../config/schemas/resolved.app.config.schema.json");
|
||||
|
||||
/// Root configuration containing every named profile.
|
||||
/// Resolved runtime configuration containing every composed named profile.
|
||||
#[derive(Clone, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/ks_config/settings/AppConfig.ts")]
|
||||
pub struct AppConfig {
|
||||
/// Active profile name.
|
||||
pub active_profile: std::string::String,
|
||||
/// Named profiles available in this configuration file.
|
||||
/// Named profiles reconstructed from the active binary composition and shared documents.
|
||||
pub profiles: std::vec::Vec<ProfileConfig>,
|
||||
}
|
||||
|
||||
/// Configuration profile selected by the root active profile name.
|
||||
/// Resolved runtime profile selected by the root active profile name.
|
||||
#[derive(Clone, Debug, serde::Deserialize, Eq, PartialEq, serde::Serialize, TS)]
|
||||
#[ts(
|
||||
export,
|
||||
@@ -382,12 +383,12 @@ pub struct DemoConfig {
|
||||
pub trading_demo_enabled: bool,
|
||||
}
|
||||
|
||||
/// Returns the embedded JSON Schema text used for configuration validation.
|
||||
/// Returns the embedded JSON Schema text used for resolved runtime contract validation.
|
||||
pub fn config_json_schema_text() -> &'static str {
|
||||
return CONFIG_JSON_SCHEMA;
|
||||
}
|
||||
|
||||
/// Parses the embedded JSON Schema into a JSON value.
|
||||
/// Parses the embedded resolved runtime JSON Schema into a JSON value.
|
||||
pub fn config_json_schema_value() -> ks_core::Result<serde_json::Value> {
|
||||
let schema_result = serde_json::from_str::<serde_json::Value>(CONFIG_JSON_SCHEMA);
|
||||
return match schema_result {
|
||||
@@ -399,7 +400,7 @@ pub fn config_json_schema_value() -> ks_core::Result<serde_json::Value> {
|
||||
};
|
||||
}
|
||||
|
||||
/// Validates a raw JSON configuration string against the embedded JSON Schema.
|
||||
/// Validates a raw resolved runtime JSON string against the embedded compatibility schema.
|
||||
pub fn validate_config_json_schema(raw_json: &str) -> ks_core::Result<()> {
|
||||
let schema = match config_json_schema_value() {
|
||||
std::result::Result::Ok(schema) => schema,
|
||||
@@ -433,7 +434,7 @@ pub fn validate_config_json_schema(raw_json: &str) -> ks_core::Result<()> {
|
||||
};
|
||||
}
|
||||
|
||||
/// Parses the application configuration from a JSON string and validates it.
|
||||
/// Parses the resolved runtime application contract from a JSON string and validates it.
|
||||
pub fn parse_config_json(raw_json: &str) -> ks_core::Result<AppConfig> {
|
||||
match validate_config_json_schema(raw_json) {
|
||||
std::result::Result::Ok(()) => (),
|
||||
@@ -454,7 +455,7 @@ pub fn parse_config_json(raw_json: &str) -> ks_core::Result<AppConfig> {
|
||||
};
|
||||
}
|
||||
|
||||
/// Reads and parses the application configuration from a filesystem path.
|
||||
/// Reads and parses a resolved runtime application snapshot from a filesystem path.
|
||||
pub fn read_config_json_file(path: &std::path::Path) -> ks_core::Result<AppConfig> {
|
||||
let raw_json = match std::fs::read_to_string(path) {
|
||||
std::result::Result::Ok(content) => content,
|
||||
@@ -468,7 +469,7 @@ pub fn read_config_json_file(path: &std::path::Path) -> ks_core::Result<AppConfi
|
||||
return parse_config_json(&raw_json);
|
||||
}
|
||||
|
||||
/// Loads the workspace environment, resolves placeholders and parses one configuration file.
|
||||
/// Loads the workspace environment, resolves placeholders and parses one resolved runtime snapshot.
|
||||
pub fn read_config_json_file_with_environment(
|
||||
path: &std::path::Path,
|
||||
workspace_root: &std::path::Path,
|
||||
@@ -700,7 +701,7 @@ fn validate_solana(config: &SolanaConfig) -> ks_core::Result<()> {
|
||||
return validate_listeners(&config.listeners);
|
||||
}
|
||||
|
||||
fn validate_http_endpoint(config: &HttpEndpointConfig) -> ks_core::Result<()> {
|
||||
pub(crate) fn validate_http_endpoint(config: &HttpEndpointConfig) -> ks_core::Result<()> {
|
||||
match validate_endpoint_common(&config.name, &config.provider, &config.cluster, &config.roles) {
|
||||
std::result::Result::Ok(()) => (),
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
@@ -731,7 +732,7 @@ fn validate_http_endpoint(config: &HttpEndpointConfig) -> ks_core::Result<()> {
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn validate_ws_endpoint(config: &WsEndpointConfig) -> ks_core::Result<()> {
|
||||
pub(crate) fn validate_ws_endpoint(config: &WsEndpointConfig) -> ks_core::Result<()> {
|
||||
match validate_endpoint_common(&config.name, &config.provider, &config.cluster, &config.roles) {
|
||||
std::result::Result::Ok(()) => (),
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
@@ -826,7 +827,7 @@ fn validate_endpoint_role(config: &EndpointRoleConfig) -> ks_core::Result<()> {
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn validate_listeners(config: &ListenerConfig) -> ks_core::Result<()> {
|
||||
pub(crate) fn validate_listeners(config: &ListenerConfig) -> ks_core::Result<()> {
|
||||
match require_non_empty(&config.default_commitment, "solana.listeners.default_commitment") {
|
||||
std::result::Result::Ok(()) => (),
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
@@ -1015,7 +1016,7 @@ fn validate_wallet_execution_pair(
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn require_non_empty(value: &str, field_name: &str) -> ks_core::Result<()> {
|
||||
pub(crate) fn require_non_empty(value: &str, field_name: &str) -> ks_core::Result<()> {
|
||||
if value.trim().is_empty() {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"config_field_empty",
|
||||
@@ -1045,14 +1046,18 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: &str = include_str!("../../config/app.config.json");
|
||||
const EXAMPLE_CONFIG: &str = include_str!("../../config/example.app.config.json");
|
||||
const DEFAULT_CONFIG: &str =
|
||||
include_str!("../../test-fixtures/config/resolved.app.config.json");
|
||||
const EXAMPLE_CONFIG: &str =
|
||||
include_str!("../../test-fixtures/config/example.resolved.app.config.json");
|
||||
|
||||
fn parse_default_value() -> serde_json::Value {
|
||||
let result = serde_json::from_str::<serde_json::Value>(DEFAULT_CONFIG);
|
||||
match result {
|
||||
std::result::Result::Ok(value) => return value,
|
||||
std::result::Result::Err(error) => panic!("default app config must be valid JSON: {error}"),
|
||||
std::result::Result::Err(error) => {
|
||||
panic!("default app config must be valid JSON: {error}")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user