Files
khadhroony-solana-project/crates/ksp-app-backfill-desk/src/dto_common.rs

145 lines
7.0 KiB
Rust

// file: crates/ksp-app-backfill-desk/src/dto_common.rs
// version: 7
//! Common Tauri DTOs shared by the Backfill Desk shell.
use ts_rs::TS; // rust-rules: trait-import
/// Safe HTTP route exposed for operator selection before a Backfill run.
///
/// The route is identified only by the logical Transport role. Provider labels are safe metadata used for operator choice; endpoint URLs and credentials never
/// cross IPC.
#[derive(Clone, Debug, serde::Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_backfill_desk/dto_common/BackfillHttpRouteOptionDto.ts")]
pub(crate) struct BackfillHttpRouteOptionDto {
/// Whether more than one configured provider participates in this logical route.
pub(crate) pooled: bool,
/// Safe provider labels participating in the route, sorted and deduplicated.
pub(crate) providers: std::vec::Vec<String>,
/// Logical Transport role later passed to the Backfill runtime.
pub(crate) role: String,
}
/// Safe Program ID entry exposed only to populate the free-form address autocomplete dataset.
///
/// Every value is derived from the canonical `ksp-core-lib` registry. The frontend remains free to submit any valid Solana address; this DTO is advisory only.
#[derive(Clone, Debug, serde::Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_backfill_desk/dto_common/ProgramIdAutocompleteOptionDto.ts")]
pub(crate) struct ProgramIdAutocompleteOptionDto {
/// Stable KSP machine-readable Program ID code.
pub(crate) code: String,
/// Broad functional domain from the canonical registry.
pub(crate) domain: String,
/// Functional family from the canonical registry.
pub(crate) family: String,
/// Human-readable program name.
pub(crate) name: String,
/// Canonical Base58 Program ID used as the HTML datalist value.
pub(crate) program_id: String,
/// Owning protocol/project label from the canonical registry.
pub(crate) protocol: String,
}
/// Projects the canonical KSP Program ID registry to the safe autocomplete dataset.
#[must_use]
pub(crate) fn program_id_autocomplete_options() -> std::vec::Vec<crate::ProgramIdAutocompleteOptionDto> {
let entries = ksp_core_lib::entries();
let mut options = std::vec::Vec::with_capacity(entries.len());
for entry in entries {
options.push(crate::ProgramIdAutocompleteOptionDto {
code: entry.code().to_owned(),
domain: entry.domain().to_owned(),
family: entry.family().to_owned(),
name: entry.name().to_owned(),
program_id: entry.program_id().to_owned(),
protocol: entry.protocol().to_owned(),
});
}
return options;
}
/// Safe Backfill Desk options contract combining readiness, HTTP routes and Job-owned campaign bounds.
///
/// Endpoint URLs, credentials and physical routing details are intentionally absent.
#[derive(Clone, Debug, serde::Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_backfill_desk/dto_common/BackfillDeskOptionsDto.ts")]
pub(crate) struct BackfillDeskOptionsDto {
/// Stable commitment codes currently admitted by `ksp-job-backfill-lib`.
pub(crate) commitments: std::vec::Vec<String>,
/// Selectable logical HTTP routes that support both RPC methods required by the Backfill runtime.
pub(crate) http_routes: std::vec::Vec<BackfillHttpRouteOptionDto>,
/// Backend-owned maxima plus application defaults used by the campaign form.
pub(crate) limits: crate::BackfillRequestLimitsDto,
/// Whether the Transport and Store readiness gates jointly permit later Backfill composition.
pub(crate) composition_ready: bool,
/// Canonical KSP Program IDs exposed as a frontend autocomplete dataset; never an allow-list.
pub(crate) program_id_options: std::vec::Vec<crate::ProgramIdAutocompleteOptionDto>,
/// Distinct enabled HTTP cluster labels selected by the active Transport profile.
pub(crate) configured_networks: std::vec::Vec<String>,
/// Whether the selected Store network exactly matches the one coherent Transport network.
pub(crate) network_coherent: bool,
/// Safe startup diagnostic when Store configuration, opening or readiness could not be proven.
pub(crate) store_diagnostic: std::option::Option<CommandErrorDto>,
/// Logical network selected by the active Store profile, without backend connection details.
pub(crate) store_network: std::option::Option<String>,
/// Whether Store opened successfully and its bounded health probe proved readiness.
pub(crate) store_ready: bool,
/// Safe startup diagnostic when Transport configuration could not be resolved or constructed.
pub(crate) transport_diagnostic: std::option::Option<CommandErrorDto>,
/// Stable HTTP scope codes currently admitted by `ksp-job-backfill-lib`.
pub(crate) scope_kinds: std::vec::Vec<String>,
/// Whether Transport currently has one coherent network and at least one compatible available role.
pub(crate) transport_ready: bool,
}
/// 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_backfill_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 crate::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(),
};
}
}
/// Safe scaffold/runtime snapshot exposed to the Backfill Desk shell.
#[derive(Clone, Debug, serde::Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_backfill_desk/dto_common/ShellStatusDto.ts")]
pub(crate) struct ShellStatusDto {
/// Active configured Logging profile, or `None` while transient fallback Logging is active.
pub(crate) active_logging_profile: std::option::Option<String>,
/// Cargo application version.
pub(crate) application_version: String,
/// Number of logical Config resources registered by the current runtime.
pub(crate) config_document_count: u32,
/// Whether Backfill Desk had to install its transient in-memory Logging fallback.
pub(crate) fallback_logging_active: bool,
/// Current implementation phase exposed by the shell.
pub(crate) shell_phase: String,
/// 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;