55 lines
2.2 KiB
Rust
55 lines
2.2 KiB
Rust
// file: crates/ksp-app-config-desk/src/dto_common.rs
|
|
// version: 2
|
|
|
|
//! Common Tauri DTOs shared by Config Desk commands.
|
|
|
|
use ts_rs::TS; // rust-rules: trait-import
|
|
|
|
/// Safe command error projection that never serializes arbitrary KSP error context or source values.
|
|
#[derive(Clone, Debug, serde::Serialize, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_config_desk/dto_common/CommandErrorDto.ts")]
|
|
pub(crate) struct CommandErrorDto {
|
|
/// Stable KSP error domain.
|
|
pub(crate) domain: String,
|
|
/// Stable KSP error code within the domain.
|
|
pub(crate) code: String,
|
|
/// Human-readable error message without arbitrary context fields.
|
|
pub(crate) message: String,
|
|
}
|
|
|
|
impl CommandErrorDto {
|
|
/// Builds a bounded safe projection from a KSP error.
|
|
#[must_use]
|
|
pub(crate) fn from_error(error: &ksp_core_lib::Error) -> Self {
|
|
return Self {
|
|
domain: error.code().domain().to_owned(),
|
|
code: error.code().code().to_owned(),
|
|
message: error.message().to_owned(),
|
|
};
|
|
}
|
|
}
|
|
|
|
/// Initial application/runtime snapshot exposed to the frontend.
|
|
#[derive(Clone, Debug, serde::Serialize, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_config_desk/dto_common/AppSnapshotDto.ts")]
|
|
pub(crate) struct AppSnapshotDto {
|
|
/// Cargo application version.
|
|
pub(crate) application_version: String,
|
|
/// Number of files registered by the Config registry.
|
|
pub(crate) config_document_count: u32,
|
|
/// Active configured Logging profile, or `None` while the transient fallback runtime is active.
|
|
pub(crate) active_logging_profile: std::option::Option<String>,
|
|
/// Monotonic runtime generation, initialized to one after the first Logging runtime install.
|
|
pub(crate) logging_generation: u32,
|
|
/// Whether Config Desk had to install its transient in-memory Logging fallback.
|
|
pub(crate) fallback_logging_active: bool,
|
|
/// Safe startup diagnostic that caused fallback Logging, when applicable.
|
|
pub(crate) startup_diagnostic: std::option::Option<CommandErrorDto>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "../unit_tests/dto_common.rs"]
|
|
mod tests;
|