robomotion 0.1.3

Official Rust SDK for building Robomotion RPA packages
Documentation
//! Custom port definitions.

use serde::{Deserialize, Serialize};

/// Custom port definition for nodes.
///
/// Ports allow nodes to have custom input/output connections beyond the
/// standard input/output ports.
///
/// # Example
/// ```ignore
/// struct MyNode {
///     // Custom input port on the left
///     files_port: Port,
///
///     // Custom output port on the right
///     done_port: Port,
/// }
/// ```
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Port {
    /// Connected node GUIDs
    #[serde(default)]
    pub connections: Vec<String>,
}

impl Port {
    /// Create a new empty port.
    pub fn new() -> Self {
        Self::default()
    }

    /// Get the list of connected node GUIDs.
    pub fn connections(&self) -> &[String] {
        &self.connections
    }

    /// Check if this port has any connections.
    pub fn is_connected(&self) -> bool {
        !self.connections.is_empty()
    }
}

/// Port specification for node spec generation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortSpec {
    pub direction: String,
    pub position: String,
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub color: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<Vec<String>>,
}

/// Information about a connected node.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeInfo {
    /// Type of the node (e.g., "Namespace.NodeName")
    #[serde(rename = "type")]
    pub node_type: String,

    /// Version of the node
    pub version: String,

    /// Node configuration
    pub config: serde_json::Value,
}