// file: kb-app-demo-desktop/src/demo_config.rs // version: 3 //! Configuration demo payload and state projection. use ts_rs::TS; // rust-rules: derive-import /// Serializable payload shown by the configuration demo page. #[derive(Clone, Debug, serde::Serialize, TS)] #[ts( export, export_to = "../frontend/ts/bindings/kb_app_demo_desktop/demo_config/DemoConfigPayload.ts" )] pub(crate) struct DemoConfigPayload { /// Path used to load the configuration file. pub(crate) config_path: std::string::String, /// Active profile name. pub(crate) active_profile_name: std::string::String, /// Active profile environment. pub(crate) environment: std::string::String, /// Entire parsed configuration. pub(crate) app_config: ks_config::AppConfig, /// Active profile configuration. pub(crate) active_profile: ks_config::ProfileConfig, /// Embedded JSON Schema text used during loading. pub(crate) schema_json: std::string::String, } /// Builds the configuration payload from shared application state. pub(crate) fn demo_config_payload(state: &crate::AppState) -> crate::DemoConfigPayload { return crate::DemoConfigPayload { config_path: state.config_path().to_owned(), active_profile_name: state.active_profile().name.clone(), environment: state.active_profile().app.environment.clone(), app_config: state.app_config().clone(), active_profile: state.active_profile().clone(), schema_json: ks_config::config_json_schema_text().to_owned(), }; } #[cfg(test)] mod tests { use ts_rs::TS; // rust-rules: trait-import #[test] fn payload_binding_uses_desktop_path() { let config = ts_rs::Config::default(); let declaration = ::decl(&config); assert!(declaration.contains("DemoConfigPayload")); } }