0.1.0-pre.004
This commit is contained in:
73
kb-store/src/contracts/dto/ledger.rs
Normal file
73
kb-store/src/contracts/dto/ledger.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
// file: kb-store/src/contracts/dto/ledger.rs
|
||||
// version: 1
|
||||
|
||||
//! Processing ledger storage DTOs.
|
||||
|
||||
/// Processing ledger mark request contract.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct ProcessingLedgerMark {
|
||||
/// Processing stage name, for example `raw_ingest`, `core_extract` or `decode`.
|
||||
pub stage: std::string::String,
|
||||
/// Processing module name.
|
||||
pub module_name: std::string::String,
|
||||
/// Processing module version.
|
||||
pub module_version: std::string::String,
|
||||
/// Stable input key, usually a signature or notification id.
|
||||
pub input_key: std::string::String,
|
||||
}
|
||||
|
||||
impl ProcessingLedgerMark {
|
||||
/// Builds a processing ledger mark request after minimal validation.
|
||||
pub fn new(
|
||||
stage: impl std::convert::Into<std::string::String>,
|
||||
module_name: impl std::convert::Into<std::string::String>,
|
||||
module_version: impl std::convert::Into<std::string::String>,
|
||||
input_key: impl std::convert::Into<std::string::String>,
|
||||
) -> kb_core::Result<Self> {
|
||||
let stage_value = stage.into();
|
||||
let module_name_value = module_name.into();
|
||||
let module_version_value = module_version.into();
|
||||
let input_key_value = input_key.into();
|
||||
if stage_value.trim().is_empty() {
|
||||
return std::result::Result::Err(kb_core::Error::db(
|
||||
"processing ledger stage must not be empty",
|
||||
));
|
||||
}
|
||||
if module_name_value.trim().is_empty() {
|
||||
return std::result::Result::Err(kb_core::Error::db(
|
||||
"processing ledger module name must not be empty",
|
||||
));
|
||||
}
|
||||
if module_version_value.trim().is_empty() {
|
||||
return std::result::Result::Err(kb_core::Error::db(
|
||||
"processing ledger module version must not be empty",
|
||||
));
|
||||
}
|
||||
if input_key_value.trim().is_empty() {
|
||||
return std::result::Result::Err(kb_core::Error::db(
|
||||
"processing ledger input key must not be empty",
|
||||
));
|
||||
}
|
||||
return std::result::Result::Ok(Self {
|
||||
stage: stage_value,
|
||||
module_name: module_name_value,
|
||||
module_version: module_version_value,
|
||||
input_key: input_key_value,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn ledger_mark_rejects_empty_input_key() {
|
||||
let result = crate::ProcessingLedgerMark::new("decode", "module", "1", " ");
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ledger_mark_accepts_minimal_values() {
|
||||
let result = crate::ProcessingLedgerMark::new("decode", "module", "1", "signature");
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user