diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 020a3a5..c33ecff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,31 +96,6 @@ jobs: - name: "Build project" run: cargo build --verbose --all-features - package: - name: "[RUST] Package" - needs: build - runs-on: ubuntu-latest - steps: - - name: "Checkout code" - uses: actions/checkout@v6 - - - name: "Install Rust toolchain" - uses: dtolnay/rust-toolchain@stable - - - name: "Cache cargo registry" - uses: actions/cache@v5 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo- - - - name: "Build project" - run: cargo package --allow-dirty --verbose --all-features - report: name: "[RUST] Report" needs: [build] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3afe868..9360ca8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,24 +25,6 @@ jobs: - run: npm run build - run: npm publish - publish-rs-reader: - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/pkg-') - defaults: - run: - working-directory: "./crates/package" - steps: - - name: Checkout Code - uses: actions/checkout@v6 - - name: Set version - run: | - VERSION=$(echo "${{ github.ref_name }}" | sed 's/^pkg-//') - sed -i "s/version = \"0.0.0\"/version = \"$VERSION\"/" Cargo.toml - - name: Cargo Login - run: cargo login ${{secrets.CRATES_IO_PUBLISH}} - - name: Publish crate - run: cargo publish --allow-dirty - publish-defintions: permissions: contents: write diff --git a/Cargo.lock b/Cargo.lock index c45a89e..7a1a397 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,17 +313,6 @@ dependencies = [ "zip", ] -[[package]] -name = "code0-definition-reader" -version = "0.0.0" -dependencies = [ - "log", - "serde", - "serde_json", - "tucana", - "walkdir", -] - [[package]] name = "colorchoice" version = "1.0.4" diff --git a/Cargo.toml b/Cargo.toml index 926bb51..1b4b6e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/cli", "crates/package"] +members = ["crates/cli"] resolver = "3" [workspace.package] diff --git a/README.md b/README.md index 0b3d48d..fa9baeb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Definitions -This repository contains all definitions for Code0. These definitions will be used to create a Flow. It also contains a CLI tool for managing definitions and a reader for reading all definitions. +This repository contains all definitions for Code0. These definitions will be used to create a Flow. It also contains a CLI tool for managing definitions. ## Definition CLI @@ -88,84 +88,3 @@ for (const feature in features) { const functions = fearture.runtimeFunctions; //runtimeFunctions of this feature } ``` - -## 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 -Crate: [code0-definition-reader](https://crates.io/crates/code0-definition-reader) on crates.io -### Install Package -```bash -cargo add code0-definition-reader -``` - -### Basic Usage - -```rs -use code0_definition_reader::Reader; - -fn main() { - // Create a reader with default configuration - let reader = Reader::configure( - "./path/to/definitions".to_string(), // Path to definitions directory - false, // should_break: continue on errors - Vec::new(), // accepted_features: empty = all features - None // accepted_version: None = all versions - ); - - // Read all features - match reader.read_features() { - Ok(features) => { - for feature in features { - println!("Loaded feature: {}", feature.name); - println!(" - Data Types: {}", feature.data_types.len()); - println!(" - Flow Types: {}", feature.flow_types.len()); - println!(" - Functions: {}", feature.functions.len()); - } - } - Err(err) => { - eprintln!("Failed to read features: {:?}", err); - } - } -} -``` - -### Advanced Usage - Filter Specific Features - -```rs -use code0_definition_reader::Reader; - -fn main() { - let reader = Reader::configure( - "./definitions".to_string(), - false, - vec!["http".to_string(), "database".to_string()], // Only load http and database features - None - ); - - match reader.read_features() { - Ok(features) => { - for feature in features { - println!("Feature: {}", feature.name); - - // Access data types - for data_type in &feature.data_types { - println!(" DataType: {}", data_type.identifier); - } - - // Access flow types - for flow_type in &feature.flow_types { - println!(" FlowType: {}", flow_type.identifier); - } - - // Access runtime functions - for function in &feature.functions { - println!(" Function: {}", function.runtime_name); - } - } - } - Err(err) => { - eprintln!("Failed to read features: {:?}", err); - } - } -} -``` diff --git a/crates/package/Cargo.toml b/crates/package/Cargo.toml deleted file mode 100644 index 3bae6d1..0000000 --- a/crates/package/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "code0-definition-reader" -version = "0.0.0" -edition = "2024" -description = "The rust crate for reading the internal Code0-Definitions" -repository = "https://github.com/code0-tech/code0-definitions" -homepage = "https://code0.tech" -license = "Apache-2.0" -readme = "../../README.md" - -[dependencies] -walkdir = {workspace = true} -serde_json = {workspace = true} -serde = {workspace = true} -tucana = {workspace = true} -log = {workspace = true} \ No newline at end of file diff --git a/crates/package/src/enum/mod.rs b/crates/package/src/enum/mod.rs deleted file mode 100644 index e98e7c8..0000000 --- a/crates/package/src/enum/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod reader_error; diff --git a/crates/package/src/enum/reader_error.rs b/crates/package/src/enum/reader_error.rs deleted file mode 100644 index 9c62cd0..0000000 --- a/crates/package/src/enum/reader_error.rs +++ /dev/null @@ -1,24 +0,0 @@ -use serde_json; -use std::io; -use std::path::PathBuf; - -#[derive(Debug)] -pub enum ReaderError { - JsonError { - path: PathBuf, - error: serde_json::Error, - }, - ReadFeatureError { - path: String, - source: Box, - }, - ReadDirectoryError { - path: PathBuf, - error: io::Error, - }, - ReadFileError { - path: PathBuf, - error: io::Error, - }, - DirectoryEntryError(io::Error), -} diff --git a/crates/package/src/lib.rs b/crates/package/src/lib.rs deleted file mode 100644 index 8e8c2d1..0000000 --- a/crates/package/src/lib.rs +++ /dev/null @@ -1,174 +0,0 @@ -mod r#enum; -mod r#struct; - -use crate::r#enum::reader_error::ReaderError; -use crate::r#struct::feature::Feature; -use serde::de::DeserializeOwned; -use std::fs; -use std::path::Path; -use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition, Version}; -use walkdir::WalkDir; - -pub struct Reader { - should_break: bool, - accepted_features: Vec, - accepted_version: Option, - path: String, -} - -impl Reader { - pub fn configure( - path: String, - should_break: bool, - accepted_features: Vec, - accepted_version: Option, - ) -> Self { - Self { - should_break, - accepted_features, - accepted_version, - path, - } - } - - pub fn read_features(&self) -> Result, ReaderError> { - let definitions = Path::new(&self.path); - - match self.read_feature_content(definitions) { - Ok(features) => { - log::info!("Loaded Successfully {} features", features.len()); - Ok(features) - } - Err(err) => { - log::error!("Failed to read features from {}", &self.path); - Err(ReaderError::ReadFeatureError { - path: self.path.to_string(), - source: Box::new(err), - }) - } - } - } - - fn read_feature_content(&self, dir: &Path) -> Result, ReaderError> { - let mut features: Vec = Vec::new(); - let readdir = match fs::read_dir(dir) { - Ok(readdir) => readdir, - Err(err) => { - log::error!("Failed to read directory {}: {}", dir.display(), err); - return Err(ReaderError::ReadDirectoryError { - path: dir.to_path_buf(), - error: err, - }); - } - }; - - for entry_result in readdir { - let entry = match entry_result { - Ok(entry) => entry, - Err(err) => { - log::error!("Failed to read directory entry: {}", err); - return Err(ReaderError::DirectoryEntryError(err)); - } - }; - - let path = entry.path(); - - if path.is_dir() { - let feature_name = path - .file_name() - .unwrap_or_default() - .to_string_lossy() - .to_string(); - - if !self.accepted_features.is_empty() - && !self.accepted_features.contains(&feature_name) - { - log::info!("Skipping feature: {}", feature_name); - continue; - } - - let data_types_path = path.join("data_type"); - let data_types: Vec = - self.collect_definitions(&data_types_path)?; - - let flow_types_path = path.join("flow_type"); - 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() - .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, - data_types, - flow_types, - functions, - }; - - features.push(feature); - } - } - - Ok(features) - } - - fn collect_definitions(&self, dir: &Path) -> Result, ReaderError> - where - T: DeserializeOwned, - { - let mut definitions = Vec::new(); - - if !dir.exists() { - return Ok(definitions); - } - - for entry in WalkDir::new(dir).into_iter().filter_map(Result::ok) { - let path = entry.path(); - - if path.is_file() && path.extension().is_some_and(|ext| ext == "json") { - let content = match fs::read_to_string(path) { - Ok(content) => content, - Err(err) => { - log::error!("Failed to read file {}: {}", path.display(), err); - return Err(ReaderError::ReadFileError { - path: path.to_path_buf(), - error: err, - }); - } - }; - - match serde_json::from_str::(&content) { - Ok(def) => definitions.push(def), - Err(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); - } - } - } - } - } - - Ok(definitions) - } -} diff --git a/crates/package/src/struct/feature.rs b/crates/package/src/struct/feature.rs deleted file mode 100644 index 8f815cc..0000000 --- a/crates/package/src/struct/feature.rs +++ /dev/null @@ -1,10 +0,0 @@ -use serde::Deserialize; -use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition}; - -#[derive(Deserialize, Debug, Clone)] -pub struct Feature { - pub name: String, - pub data_types: Vec, - pub flow_types: Vec, - pub functions: Vec, -} diff --git a/crates/package/src/struct/mod.rs b/crates/package/src/struct/mod.rs deleted file mode 100644 index c193906..0000000 --- a/crates/package/src/struct/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod feature;