Skip to main content

ryo_analysis/query/
specflow_common.rs

1//! SpecFlow Common Types
2//!
3//! Shared type definitions used by both SpecFlowGraphV2 and any legacy code.
4
5use serde::{Deserialize, Serialize};
6
7// ============================================================================
8// Source Types
9// ============================================================================
10
11/// Source of spec information.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
13pub enum SpecSource {
14    /// From `type X = Spec<G, T>` (strict, compile-time)
15    TypeAlias,
16    /// From `@spec:group(G)` comment (flexible, advisory)
17    Comment,
18    /// Inferred by analysis
19    Inferred,
20}
21
22// ============================================================================
23// Constraint Types
24// ============================================================================
25
26/// Constraint kinds.
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub enum ConstraintKind {
29    /// Value range constraint (e.g., UserId > 0)
30    Range {
31        /// Inclusive lower bound; `None` means unbounded below.
32        min: Option<i64>,
33        /// Inclusive upper bound; `None` means unbounded above.
34        max: Option<i64>,
35    },
36    /// Pattern constraint (e.g., Email matches regex)
37    Pattern(String),
38    /// Invariant expression (@spec:invariant)
39    Invariant(String),
40    /// Dependency constraint (`DependsOn<T>`)
41    DependsOn(String),
42    /// Intent (@spec:intent)
43    Intent(IntentKind),
44    /// Custom constraint (@spec:custom-key(value))
45    Custom {
46        /// Custom directive key (the `custom-<key>` portion).
47        key: String,
48        /// Value payload as written in the source comment.
49        value: String,
50    },
51}
52
53/// Intent kinds.
54#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
55pub enum IntentKind {
56    /// Design rationale
57    Design,
58    /// Performance consideration
59    Performance,
60    /// Security requirement
61    Security,
62    /// Business rule
63    Business,
64    /// Custom intent description
65    Custom(String),
66}
67
68// ============================================================================
69// Comment Directive
70// ============================================================================
71
72/// Comment-based spec directive.
73///
74/// Represents `@spec:*` directives parsed from comments.
75/// Users can convert from ryo-spec types to this enum.
76#[derive(Debug, Clone, PartialEq, Eq)]
77pub enum CommentDirective {
78    /// `@spec:group(name)` - Assign to a semantic group
79    Group(String),
80
81    /// `@spec:related(A, B, ...)` - Related types (bidirectional)
82    Related(Vec<String>),
83
84    /// `@spec:depends-on(A, B, ...)` - Depends on other specs
85    DependsOn(Vec<String>),
86
87    /// `@spec:part-of(Parent)` - Part of a larger spec
88    PartOf(String),
89
90    /// `@spec:invariant(description)` - Domain invariant
91    Invariant(String),
92
93    /// `@spec:intent(description)` - Design intent
94    Intent(String),
95
96    /// `@spec:custom-key(value)` - Custom directive
97    Custom {
98        /// Custom directive key (the `custom-<key>` portion).
99        key: String,
100        /// Value payload as written in the source comment.
101        value: String,
102    },
103}