1pub mod mcp;
7pub mod msw;
8pub mod python;
9pub mod react_query;
10pub mod rust;
11pub mod sdk;
12pub mod typescript;
13pub mod util;
14
15use crate::config::McpGenerateConfig;
16use odk_schema::CompiledSchema;
17use std::collections::BTreeMap;
18use std::fmt;
19
20#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum Target {
23 Sdk,
24 ReactQuery,
25 Msw,
26 Mcp,
27 Python,
28 Typescript,
29 Rust,
30}
31
32impl Target {
33 pub fn parse(s: &str) -> Option<Self> {
35 match s.to_lowercase().as_str() {
36 "sdk" => Some(Target::Sdk),
37 "react-query" | "reactquery" => Some(Target::ReactQuery),
38 "msw" => Some(Target::Msw),
39 "mcp" => Some(Target::Mcp),
40 "python" | "py" => Some(Target::Python),
41 "typescript" | "ts" => Some(Target::Typescript),
42 "rust" | "rs" => Some(Target::Rust),
43 _ => None,
44 }
45 }
46
47 pub fn parse_list(s: &str) -> Result<Vec<Self>, String> {
49 let mut targets = Vec::new();
50 for part in s.split(',') {
51 let trimmed = part.trim();
52 if trimmed.is_empty() {
53 continue;
54 }
55 match Self::parse(trimmed) {
56 Some(t) => {
57 if !targets.contains(&t) {
58 targets.push(t);
59 }
60 }
61 None => {
62 return Err(format!(
63 "Unknown target: '{}'. Available: sdk, react-query, msw, mcp, python, typescript, rust",
64 trimmed
65 ));
66 }
67 }
68 }
69 Ok(targets)
70 }
71}
72
73impl fmt::Display for Target {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 match self {
76 Target::Sdk => write!(f, "sdk"),
77 Target::ReactQuery => write!(f, "react-query"),
78 Target::Msw => write!(f, "msw"),
79 Target::Mcp => write!(f, "mcp"),
80 Target::Python => write!(f, "python"),
81 Target::Typescript => write!(f, "typescript"),
82 Target::Rust => write!(f, "rust"),
83 }
84 }
85}
86
87pub fn generate(
92 schema: &CompiledSchema,
93 targets: &[Target],
94 mcp_config: Option<&McpGenerateConfig>,
95) -> BTreeMap<String, String> {
96 let mut output = BTreeMap::new();
97
98 let needs_sdk = targets.contains(&Target::Sdk)
100 || targets.contains(&Target::ReactQuery)
101 || targets.contains(&Target::Msw);
102
103 if needs_sdk {
104 output.extend(sdk::generate(schema));
105 }
106
107 if targets.contains(&Target::ReactQuery) {
108 output.extend(react_query::generate(schema));
109 }
110
111 if targets.contains(&Target::Msw) {
112 output.extend(msw::generate(schema));
113 }
114
115 if targets.contains(&Target::Python) {
116 output.extend(python::generate(schema));
117 }
118
119 if targets.contains(&Target::Typescript) {
120 output.extend(typescript::generate(schema));
121 }
122
123 if targets.contains(&Target::Rust) {
124 output.extend(rust::generate(schema));
125 }
126
127 if targets.contains(&Target::Mcp) {
128 if let Some(cfg) = mcp_config {
129 output.extend(mcp::generate_with_config(schema, cfg));
130 } else {
131 output.extend(mcp::generate(schema));
132 }
133 }
134
135 output
136}