ryo-analysis 0.1.0

Code graph and discovery engine for the RYO project
Documentation
//! SpecFlow Common Types
//!
//! Shared type definitions used by both SpecFlowGraphV2 and any legacy code.

use serde::{Deserialize, Serialize};

// ============================================================================
// Source Types
// ============================================================================

/// Source of spec information.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SpecSource {
    /// From `type X = Spec<G, T>` (strict, compile-time)
    TypeAlias,
    /// From `@spec:group(G)` comment (flexible, advisory)
    Comment,
    /// Inferred by analysis
    Inferred,
}

// ============================================================================
// Constraint Types
// ============================================================================

/// Constraint kinds.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConstraintKind {
    /// Value range constraint (e.g., UserId > 0)
    Range {
        /// Inclusive lower bound; `None` means unbounded below.
        min: Option<i64>,
        /// Inclusive upper bound; `None` means unbounded above.
        max: Option<i64>,
    },
    /// Pattern constraint (e.g., Email matches regex)
    Pattern(String),
    /// Invariant expression (@spec:invariant)
    Invariant(String),
    /// Dependency constraint (`DependsOn<T>`)
    DependsOn(String),
    /// Intent (@spec:intent)
    Intent(IntentKind),
    /// Custom constraint (@spec:custom-key(value))
    Custom {
        /// Custom directive key (the `custom-<key>` portion).
        key: String,
        /// Value payload as written in the source comment.
        value: String,
    },
}

/// Intent kinds.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum IntentKind {
    /// Design rationale
    Design,
    /// Performance consideration
    Performance,
    /// Security requirement
    Security,
    /// Business rule
    Business,
    /// Custom intent description
    Custom(String),
}

// ============================================================================
// Comment Directive
// ============================================================================

/// Comment-based spec directive.
///
/// Represents `@spec:*` directives parsed from comments.
/// Users can convert from ryo-spec types to this enum.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommentDirective {
    /// `@spec:group(name)` - Assign to a semantic group
    Group(String),

    /// `@spec:related(A, B, ...)` - Related types (bidirectional)
    Related(Vec<String>),

    /// `@spec:depends-on(A, B, ...)` - Depends on other specs
    DependsOn(Vec<String>),

    /// `@spec:part-of(Parent)` - Part of a larger spec
    PartOf(String),

    /// `@spec:invariant(description)` - Domain invariant
    Invariant(String),

    /// `@spec:intent(description)` - Design intent
    Intent(String),

    /// `@spec:custom-key(value)` - Custom directive
    Custom {
        /// Custom directive key (the `custom-<key>` portion).
        key: String,
        /// Value payload as written in the source comment.
        value: String,
    },
}