From 66e6a46198360894cf472f7c2aac7266b53efc9f Mon Sep 17 00:00:00 2001 From: MecryTv Date: Thu, 13 Nov 2025 23:28:01 +0100 Subject: [PATCH 1/5] [feat] update README.md Rust Definition Package --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6226674..4255b29 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,10 @@ for (const feature in features) { ``` ## Rust Definition Package +This package is a Rust crate designed to read and parse Code0 definition files (JSON) from a directory structure. It loads all features, including their data types, flow types, and runtime functions, providing them as idiomatic Rust structs. +### Package Resources +Create: [code0-definition-reader](https://crates.io/crates/code0-definition-reader) on crates.io ### Install Package ```bash cargo add code0-definition-reader @@ -99,14 +102,23 @@ cargo add code0-definition-reader ### Usage ```rs -use code0_definition_reader::Definition; +use code0_definition_reader::Reader; -let features = Definition::new("./path/to/definitions"); +let reader = Reader::configure( + String::new(), // Path required for configure + false, // should_break + Vec::new(), // accepted_features + None // accepted_versions +); + +let features = reader.read_features("./path/to/definitions"); for feature in features { - let name = feature.name(); //name of the feature (e.g. rest) - let data_types = feature.data_types(); //dataTypes of this feature - let flow_types = feature.flow_types(); //flowTypes of this feature - let functions = feature.runtime_functions(); //runtimeFunctions of this feature + let name = &feature.name; // name of the feature (e.g., http) + let data_types = &feature.data_types; // dataTypes of this feature + let flow_types = &feature.flow_types; // flowTypes of this feature + let functions = &feature.functions; // runtimeFunctions of this feature + + println!("Loaded feature: {}", name); } ``` From 0e86c47694ff5d4072cd8388c92406c4e18944ca Mon Sep 17 00:00:00 2001 From: MecryTv Date: Sun, 16 Nov 2025 00:09:16 +0100 Subject: [PATCH 2/5] [fix] Definition Description & Package Resource Name --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4255b29..2036eb1 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,9 @@ for (const feature in features) { ``` ## Rust Definition Package -This package is a Rust crate designed to read and parse Code0 definition files (JSON) from a directory structure. It loads all features, including their data types, flow types, and runtime functions, providing them as idiomatic Rust structs. - +This package is a Rust crate designed to read and parse CodeZero definition files (JSON) from a directory structure. It loads all features, including data-types, flow-types, and runtime-functions, providing them as idiomatic Rust structs. ### Package Resources -Create: [code0-definition-reader](https://crates.io/crates/code0-definition-reader) on crates.io +Crete: [code0-definition-reader](https://crates.io/crates/code0-definition-reader) on crates.io ### Install Package ```bash cargo add code0-definition-reader From c3095cde8ef051e8a87ba2ddd64d19a9299ee501 Mon Sep 17 00:00:00 2001 From: MecryTv Date: Sun, 16 Nov 2025 00:09:44 +0100 Subject: [PATCH 3/5] [fix] Definition Description & Package Resource Name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2036eb1..ed438e1 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ for (const feature in features) { ## Rust Definition Package This package is a Rust crate designed to read and parse CodeZero definition files (JSON) from a directory structure. It loads all features, including data-types, flow-types, and runtime-functions, providing them as idiomatic Rust structs. ### Package Resources -Crete: [code0-definition-reader](https://crates.io/crates/code0-definition-reader) on crates.io +Crate: [code0-definition-reader](https://crates.io/crates/code0-definition-reader) on crates.io ### Install Package ```bash cargo add code0-definition-reader From b743919d7d659fc046ba3082a456033c2f09b8bd Mon Sep 17 00:00:00 2001 From: MecryTv Date: Tue, 18 Nov 2025 16:22:02 +0100 Subject: [PATCH 4/5] [fix] Add Reader Struct Options --- crates/package/src/lib.rs | 51 ++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/crates/package/src/lib.rs b/crates/package/src/lib.rs index c6546bd..3b9bcb3 100644 --- a/crates/package/src/lib.rs +++ b/crates/package/src/lib.rs @@ -12,7 +12,7 @@ use walkdir::WalkDir; pub struct Reader { should_break: bool, accepted_features: Vec, - accepted_versions: Option, + accepted_version: Option, path: String, } @@ -21,18 +21,18 @@ impl Reader { path: String, should_break: bool, accepted_features: Vec, - accepted_versions: Option, + accepted_version: Option, ) -> Self { Self { should_break, accepted_features, - accepted_versions, + accepted_version, path, } } - pub fn read_features(&self, path: &str) -> Result, ReaderError> { - let definitions = Path::new(path); + pub fn read_features(&self) -> Result, ReaderError> { + let definitions = Path::new(&self.path); match self.read_feature_content(definitions) { Ok(features) => { @@ -40,9 +40,9 @@ impl Reader { Ok(features) } Err(err) => { - log::error!("Failed to read features from {}", path); + log::error!("Failed to read features from {}", &self.path); Err(ReaderError::ReadFeatureError { - path: path.to_string(), + path: self.path.to_string(), source: Box::new(err), }) } @@ -95,8 +95,23 @@ impl Reader { let flow_types: Vec = self.collect_definitions(&flow_types_path)?; let functions_path = path.join("runtime_definition"); - let functions: Vec = - self.collect_definitions(&functions_path)?; + let functions = match self.collect_definitions::(&functions_path) { + Ok(func) => { + func.into_iter() + .filter(|v| v.version == self.accepted_version) + .collect() + }, + Err(err) => { + if self.should_break { + return Err(ReaderError::ReadFeatureError { + path: functions_path.to_string_lossy().to_string(), + source: Box::new(err), + }) + } else { + continue; + } + } + }; let feature = Feature { name: feature_name, @@ -140,11 +155,19 @@ impl Reader { match serde_json::from_str::(&content) { Ok(def) => definitions.push(def), Err(e) => { - log::error!("Failed to parse JSON in file {}: {}", path.display(), e); - return Err(ReaderError::JsonError { - path: path.to_path_buf(), - error: e, - }); + if self.should_break { + log::error!("Failed to parse JSON in file {}: {}", path.display(), e); + return Err(ReaderError::JsonError { + path: path.to_path_buf(), + error: e, + }); + } else { + log::warn!( + "Skipping invalid JSON file {}: {}", + path.display(), + e + ); + } } } } From 60cd20d9ee2a1c1ae05a5f4127739aaa190d44f1 Mon Sep 17 00:00:00 2001 From: MecryTv Date: Tue, 18 Nov 2025 16:23:26 +0100 Subject: [PATCH 5/5] [ref] cargo clippy & format --- crates/package/src/lib.rs | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/crates/package/src/lib.rs b/crates/package/src/lib.rs index 3b9bcb3..8e8c2d1 100644 --- a/crates/package/src/lib.rs +++ b/crates/package/src/lib.rs @@ -95,23 +95,23 @@ impl Reader { let flow_types: Vec = self.collect_definitions(&flow_types_path)?; let functions_path = path.join("runtime_definition"); - let functions = match self.collect_definitions::(&functions_path) { - Ok(func) => { - func.into_iter() + let functions = + match self.collect_definitions::(&functions_path) { + Ok(func) => func + .into_iter() .filter(|v| v.version == self.accepted_version) - .collect() - }, - Err(err) => { - if self.should_break { - return Err(ReaderError::ReadFeatureError { - path: functions_path.to_string_lossy().to_string(), - source: Box::new(err), - }) - } else { - continue; + .collect(), + Err(err) => { + if self.should_break { + return Err(ReaderError::ReadFeatureError { + path: functions_path.to_string_lossy().to_string(), + source: Box::new(err), + }); + } else { + continue; + } } - } - }; + }; let feature = Feature { name: feature_name, @@ -162,11 +162,7 @@ impl Reader { error: e, }); } else { - log::warn!( - "Skipping invalid JSON file {}: {}", - path.display(), - e - ); + log::warn!("Skipping invalid JSON file {}: {}", path.display(), e); } } }