tauri_plugin_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}
53
54#[derive(Debug, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct ParameterInfo {
57    pub name: String,
58    pub rust_type: String,
59    pub typescript_type: String,
60    pub is_optional: bool,
61}
62
63// New: Struct field information for better type generation
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(rename_all = "camelCase")]
66pub struct StructInfo {
67    pub name: String,
68    pub fields: Vec<FieldInfo>,
69    pub file_path: String,
70    pub is_enum: bool,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(rename_all = "camelCase")]
75pub struct FieldInfo {
76    pub name: String,
77    pub rust_type: String,
78    pub typescript_type: String,
79    pub is_optional: bool,
80    pub is_public: bool,
81    pub validator_attributes: Option<ValidatorAttributes>,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct ValidatorAttributes {
87    pub length: Option<LengthConstraint>,
88    pub range: Option<RangeConstraint>,
89    pub email: bool,
90    pub url: bool,
91    pub custom_message: Option<String>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(rename_all = "camelCase")]
96pub struct LengthConstraint {
97    pub min: Option<u64>,
98    pub max: Option<u64>,
99    pub message: Option<String>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct RangeConstraint {
105    pub min: Option<f64>,
106    pub max: Option<f64>,
107    pub message: Option<String>,
108}