tauri_typegen/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Deserialize, Serialize)]
4#[serde(rename_all = "camelCase")]
5pub struct PingRequest {
6    pub value: Option<String>,
7}
8
9#[derive(Debug, Clone, Default, Deserialize, Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct PingResponse {
12    pub value: Option<String>,
13}
14
15#[derive(Debug, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct GenerateModelsRequest {
18    pub project_path: String,
19    pub output_path: Option<String>,
20    pub validation_library: Option<String>,
21}
22
23#[derive(Debug, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct GenerateModelsResponse {
26    pub generated_files: Vec<String>,
27    pub commands_found: i32,
28    pub types_generated: i32,
29}
30
31#[derive(Debug, Serialize, Deserialize)]
32#[serde(rename_all = "camelCase")]
33pub struct AnalyzeCommandsRequest {
34    pub project_path: String,
35}
36
37#[derive(Debug, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct AnalyzeCommandsResponse {
40    pub commands: Vec<CommandInfo>,
41}
42
43#[derive(Debug, Serialize, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct CommandInfo {
46    pub name: String,
47    pub file_path: String,
48    pub line_number: usize,
49    pub parameters: Vec<ParameterInfo>,
50    pub return_type: String,
51    pub is_async: bool,
52    pub channels: Vec<ChannelInfo>,
53}
54
55#[derive(Debug, Serialize, Deserialize)]
56#[serde(rename_all = "camelCase")]
57pub struct ParameterInfo {
58    pub name: String,
59    pub rust_type: String,
60    pub typescript_type: String,
61    pub is_optional: bool,
62}
63
64// New: Struct field information for better type generation
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(rename_all = "camelCase")]
67pub struct StructInfo {
68    pub name: String,
69    pub fields: Vec<FieldInfo>,
70    pub file_path: String,
71    pub is_enum: bool,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(rename_all = "camelCase")]
76pub struct FieldInfo {
77    pub name: String,
78    pub rust_type: String,
79    pub typescript_type: String,
80    pub is_optional: bool,
81    pub is_public: bool,
82    pub validator_attributes: Option<ValidatorAttributes>,
83    /// The serialized name after applying serde rename/rename_all transformations.
84    /// If None, the field name will be used.
85    #[serde(default, skip_serializing_if = "Option::is_none")]
86    pub serialized_name: Option<String>,
87}
88
89impl FieldInfo {
90    /// Get the effective serialized name, falling back to name if serialized_name is None
91    pub fn get_serialized_name(&self) -> &str {
92        self.serialized_name.as_deref().unwrap_or(&self.name)
93    }
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(rename_all = "camelCase")]
98pub struct ValidatorAttributes {
99    pub length: Option<LengthConstraint>,
100    pub range: Option<RangeConstraint>,
101    pub email: bool,
102    pub url: bool,
103    pub custom_message: Option<String>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(rename_all = "camelCase")]
108pub struct LengthConstraint {
109    pub min: Option<u64>,
110    pub max: Option<u64>,
111    pub message: Option<String>,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(rename_all = "camelCase")]
116pub struct RangeConstraint {
117    pub min: Option<f64>,
118    pub max: Option<f64>,
119    pub message: Option<String>,
120}
121
122// Event information for frontend event listeners
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(rename_all = "camelCase")]
125pub struct EventInfo {
126    pub event_name: String,
127    pub payload_type: String,
128    pub typescript_payload_type: String,
129    pub file_path: String,
130    pub line_number: usize,
131}
132
133// Channel information for streaming data from Rust to frontend
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(rename_all = "camelCase")]
136pub struct ChannelInfo {
137    pub parameter_name: String,
138    pub message_type: String,
139    pub typescript_message_type: String,
140    pub command_name: String,
141    pub file_path: String,
142    pub line_number: usize,
143}