Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: using PkgType in GraphNode #38

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@
],
"python.analysis.typeCheckingMode": "basic",
"rust-analyzer.check.command": "clippy",
"rust-analyzer.inlayHints.bindingModeHints.enable": true,
"rust-analyzer.inlayHints.closureCaptureHints.enable": true,
"rust-analyzer.inlayHints.closureReturnTypeHints.enable": "always",
"rust-analyzer.inlayHints.discriminantHints.enable": "always",
"rust-analyzer.inlayHints.expressionAdjustmentHints.enable": "always",
"rust-analyzer.inlayHints.implicitDrops.enable": true,
"rust-analyzer.inlayHints.lifetimeElisionHints.enable": "always",
"rust-analyzer.inlayHints.lifetimeElisionHints.useParameterNames": true,
"rust-analyzer.inlayHints.rangeExclusiveHints.enable": true,
"rust-analyzer.linkedProjects": [
"${workspaceFolder}/core/src/ten_manager/Cargo.toml",
"${workspaceFolder}/core/src/ten_rust/Cargo.toml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Graph {
self.nodes
.iter()
.find_map(|node| {
if node.node_type == "extension"
if node.node_type == PkgType::Extension
&& node.name.as_str() == extension
&& node.app.as_str() == app
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//
use anyhow::Result;

use crate::pkg_info::graph::{Graph, GraphMessageFlow};
use crate::pkg_info::{
graph::{Graph, GraphMessageFlow},
pkg_type::PkgType,
};

impl Graph {
fn check_if_dest_of_connection_are_defined_in_nodes(
Expand Down Expand Up @@ -47,7 +50,7 @@ impl Graph {

let mut all_extensions: Vec<String> = Vec::new();
for node in &self.nodes {
if node.node_type.as_str() == "extension" {
if node.node_type == PkgType::Extension {
let unique_ext_name = format!(
"{}:{}:{}",
node.app.as_str(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
use anyhow::Result;

use crate::pkg_info::graph::Graph;
use crate::pkg_info::{graph::Graph, pkg_type::PkgType};

impl Graph {
pub fn check_if_nodes_duplicated(&self) -> Result<()> {
Expand All @@ -15,8 +15,8 @@ impl Graph {
let mut all_extension_groups: Vec<String> = Vec::new();

for (node_idx, node) in self.nodes.iter().enumerate() {
match node.node_type.as_str() {
"extension" => {
match node.node_type {
PkgType::Extension => {
let unique_ext_name = format!(
"{}:{}:{}",
node.app.as_str(),
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Graph {
}
}

"extension_group" => {
PkgType::ExtensionGroup => {
let unique_ext_group_name =
format!("{}:{}", node.app.as_str(), node.name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use std::collections::HashMap;

use anyhow::Result;

use crate::pkg_info::{graph::Graph, PkgInfo};
use crate::pkg_info::{graph::Graph, pkg_type::PkgType, PkgInfo};

impl Graph {
pub fn check_if_nodes_have_installed(
&self,
all_needed_pkgs: &HashMap<String, Vec<PkgInfo>>,
) -> Result<()> {
// app, node_type, node_addon
let mut not_installed_pkgs: Vec<(String, String, String)> = Vec::new();
let mut not_installed_pkgs: Vec<(String, PkgType, String)> = Vec::new();

for node in &self.nodes {
if !all_needed_pkgs.contains_key(node.app.as_str()) {
Expand All @@ -29,7 +29,7 @@ impl Graph {

let pkgs_in_app = all_needed_pkgs.get(node.app.as_str()).unwrap();
let found = pkgs_in_app.iter().find(|pkg| {
pkg.pkg_identity.pkg_type.to_string() == node.node_type
pkg.pkg_identity.pkg_type == node.node_type
&& pkg.pkg_identity.name == node.addon
&& pkg.is_local_installed
});
Expand Down
9 changes: 6 additions & 3 deletions core/src/ten_rust/src/pkg_info/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::{
pkg_type::PkgType,
predefined_graphs::{
connection::{PkgConnection, PkgDestination, PkgMessageFlow},
node::PkgNode,
Expand Down Expand Up @@ -76,7 +77,7 @@ impl Graph {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GraphNode {
#[serde(rename = "type")]
pub node_type: String,
pub node_type: PkgType,
pub name: String,
pub addon: String,

Expand All @@ -95,7 +96,9 @@ pub struct GraphNode {
impl GraphNode {
fn validate_and_complete(&mut self) -> Result<()> {
// extension node must specify extension_group name.
if self.node_type == "extension" && self.extension_group.is_none() {
if self.node_type == PkgType::Extension
&& self.extension_group.is_none()
{
return Err(anyhow::anyhow!(
"Node '{}' of type 'extension' must have an 'extension_group' defined.",
self.name
Expand All @@ -109,7 +112,7 @@ impl GraphNode {
impl From<PkgNode> for GraphNode {
fn from(pkg_node: PkgNode) -> Self {
GraphNode {
node_type: pkg_node.node_type.to_string(),
node_type: pkg_node.node_type.clone(),
name: pkg_node.name.clone(),
addon: pkg_node.addon.clone(),
extension_group: pkg_node.extension_group.clone(),
Expand Down
4 changes: 1 addition & 3 deletions core/src/ten_rust/src/pkg_info/predefined_graphs/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
use std::str::FromStr;

use crate::pkg_info::{graph::GraphNode, pkg_type::PkgType, PkgInfo};

#[derive(Debug, Clone)]
Expand All @@ -28,7 +26,7 @@ pub struct PkgNode {
impl From<GraphNode> for PkgNode {
fn from(manifest_node: GraphNode) -> Self {
PkgNode {
node_type: PkgType::from_str(&manifest_node.node_type).unwrap(),
node_type: manifest_node.node_type,
name: manifest_node.name,
addon: manifest_node.addon,
extension_group: manifest_node.extension_group,
Expand Down
Loading