Skip to content

Commit

Permalink
refactor: rename mechanics to structural in BundleElement and related…
Browse files Browse the repository at this point in the history
… structures
  • Loading branch information
olichwiruk committed Dec 11, 2024
1 parent fa8674f commit 554e8b7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion oca/src/facade/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Facade {
.validate_ocafile(ocafile)
.map_err(|errs| vec![Error::ValidationError(errs)])?;

Ok(BundleElement::Mechanics(self.build(&oca_build)?))
Ok(BundleElement::Structural(self.build(&oca_build)?))
}
}
/*
Expand Down
20 changes: 10 additions & 10 deletions oca/src/facade/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use oca_bundle_semantics::state::oca::OCABundle;
use oca_bundle_semantics::state::oca::OCABundle as StructuralBundle;
use said::derivation::HashFunctionCode;
use said::{sad::SerializationFormats, sad::SAD};
use said::version::SerializationInfo;
use serde::{Deserialize, Serialize};

#[derive(Debug)]
pub enum BundleElement {
Mechanics(OCABundle),
Structural(StructuralBundle),
Transformation(transformation_file::state::Transformation),
}

Expand All @@ -17,7 +17,7 @@ pub struct Bundle {
#[serde(rename = "d")]
pub said: Option<said::SelfAddressingIdentifier>,
#[serde(rename = "m")]
pub mechanics: Option<OCABundle>,
pub structural: Option<StructuralBundle>,
#[serde(rename = "t")]
pub transformations: Vec<transformation_file::state::Transformation>,
}
Expand All @@ -26,20 +26,20 @@ impl Bundle {
pub fn new() -> Self {
Self {
said: None,
mechanics: None,
structural: None,
transformations: vec![],
}
}

pub fn add(&mut self, element: BundleElement) {
match element {
BundleElement::Mechanics(mechanics) => self.add_mechanics(mechanics),
BundleElement::Structural(structural) => self.add_structural(structural),
BundleElement::Transformation(transformation) => self.add_transformation(transformation),
}
}

fn add_mechanics(&mut self, mechanics: OCABundle) {
self.mechanics = Some(mechanics);
fn add_structural(&mut self, structural: StructuralBundle) {
self.structural = Some(structural);
}

fn add_transformation(&mut self, transformation: transformation_file::state::Transformation) {
Expand All @@ -56,8 +56,8 @@ impl Bundle {
let code = HashFunctionCode::Blake3_256;
let format = SerializationFormats::JSON;

let mechanics = self.mechanics.as_ref().unwrap();
let mechanics_str = String::from_utf8(mechanics.encode(&code, &format).unwrap()).unwrap();
let structural = self.structural.as_ref().unwrap();
let structural_str = String::from_utf8(structural.encode(&code, &format).unwrap()).unwrap();

let mut transformations_str = String::new();
let mut transformations_iter = self.transformations.iter().peekable();
Expand All @@ -72,7 +72,7 @@ impl Bundle {

let result = format!(
r#"{{"d":"","m":{},"t":[{}]}}"#,
mechanics_str,
structural_str,
transformations_str
);

Expand Down
16 changes: 8 additions & 8 deletions oca/src/facade/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,23 +454,23 @@ ADD ENTRY en ATTRS list="refs:ENrf7niTCnz7HD-Ci88rlxHlxkpQ2NIZNNv08fQnXANI" el={
"#.to_string();
let oca_bundle = facade.build_from_ocafile(ocafile_input);
let oca_bundle = oca_bundle.unwrap();
if let BundleElement::Mechanics(mechanics) = oca_bundle {
let ocafile = facade.parse_oca_bundle_to_ocafile(&mechanics)?;
let new_mechanics = facade.build_from_ocafile(ocafile);
match new_mechanics {
Ok(BundleElement::Mechanics(new_mechanics)) => {
assert_eq!(mechanics.said, new_mechanics.said);
if let BundleElement::Structural(structural) = oca_bundle {
let ocafile = facade.parse_oca_bundle_to_ocafile(&structural)?;
let new_structural = facade.build_from_ocafile(ocafile);
match new_structural {
Ok(BundleElement::Structural(new_structural)) => {
assert_eq!(structural.said, new_structural.said);
}
Ok(_) => {
panic!("Expected BundleElement::Mechanics")
panic!("Expected BundleElement::Structural")
}
Err(e) => {
println!("{:#?}", e);
panic!("Faild to load oca bundle");
}
}
} else {
panic!("Expected BundleElement::Mechanics")
panic!("Expected BundleElement::Structural")
}


Expand Down
22 changes: 11 additions & 11 deletions tests/build_from_ocafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables

let result = facade.build_from_ocafile(ocafile)?;

assert!(matches!(result, BundleElement::Mechanics(_)));
if let BundleElement::Mechanics(result) = result {
assert!(matches!(result, BundleElement::Structural(_)));
if let BundleElement::Structural(result) = result {
assert_eq!(
result.said.clone().unwrap().to_string(),
"EKHBds6myKVIsQuT7Zr23M8Xk_gwq-2SaDRUprvqOXxa"
Expand All @@ -47,7 +47,7 @@ ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables
assert_eq!(search_result.metadata.total, 1);
Ok(())
} else {
panic!("Expected BundleElement::Mechanics")
panic!("Expected BundleElement::Structural")
}
}

Expand All @@ -74,14 +74,14 @@ ADD ATTRIBUTE x=Text
.to_string();
let result = facade.build_from_ocafile(ocafile)?;

if let BundleElement::Mechanics(result) = result {
if let BundleElement::Structural(result) = result {
assert_eq!(
result.said.unwrap().to_string(),
"EAMguWL--P5gad3xZoT2fd-qjoBDVkK82pb7KET1lrS1"
);
Ok(())
} else {
panic!("Expected BundleElement::Mechanics")
panic!("Expected BundleElement::Structural")
}
}

Expand Down Expand Up @@ -114,10 +114,10 @@ ADD ATTRIBUTE C=Array[refn:second]
.to_string();
let result = facade.build_from_ocafile(ocafile).unwrap();

assert!(matches!(result, BundleElement::Mechanics(_)));
if let BundleElement::Mechanics(mechanics) = result {
assert!(matches!(result, BundleElement::Structural(_)));
if let BundleElement::Structural(structural) = result {
assert_eq!(
mechanics.said.unwrap().to_string(),
structural.said.unwrap().to_string(),
"EGv65yGtFZG5CSRaS4q46dC3UWsW3vycbMFOqPFPvhWi"
);
}
Expand All @@ -129,10 +129,10 @@ ADD ATTRIBUTE x=Text
.to_string();

let result = facade.build_from_ocafile(from_ocafile).unwrap();
assert!(matches!(result, BundleElement::Mechanics(_)));
if let BundleElement::Mechanics(mechanics) = result {
assert!(matches!(result, BundleElement::Structural(_)));
if let BundleElement::Structural(structural) = result {
assert_eq!(
mechanics.said.unwrap().to_string(),
structural.said.unwrap().to_string(),
"EE-Ru8mxNWhql7Q2ibY2-uuK9cIKxR2S9rc-eRkEeBwO"
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ ADD CHARACTER_ENCODING ATTRS first_name="utf-8" last_name="utf-8" hgt="utf-8" wg

let result_source = facade.build_from_ocafile(ocafile_source)?;
let mut source_said: Option<_> = None;
if let BundleElement::Mechanics(ref mechanics) = result_source {
source_said = mechanics.said.clone();
if let BundleElement::Structural(ref structural) = result_source {
source_said = structural.said.clone();
}
bundle.add(result_source);

let result_target = facade.build_from_ocafile(ocafile_target)?;
let mut target_said: Option<_> = None;
if let BundleElement::Mechanics(ref mechanics) = result_target {
target_said = mechanics.said.clone();
if let BundleElement::Structural(ref structural) = result_target {
target_said = structural.said.clone();
}

let ocafile_link = format!(r#"
Expand Down

0 comments on commit 554e8b7

Please sign in to comment.