1use crate::{CliOverridesPatch, ConfigOverride, FlagState};
2use std::{path::PathBuf, process::ExitStatus};
3
4#[derive(Clone, Debug, Eq, PartialEq)]
6pub enum AppServerCodegenTarget {
7 TypeScript { prettier: Option<PathBuf> },
9 JsonSchema,
11}
12
13impl AppServerCodegenTarget {
14 pub(crate) fn subcommand(&self) -> &'static str {
15 match self {
16 AppServerCodegenTarget::TypeScript { .. } => "generate-ts",
17 AppServerCodegenTarget::JsonSchema => "generate-json-schema",
18 }
19 }
20
21 pub(crate) fn prettier(&self) -> Option<&PathBuf> {
22 match self {
23 AppServerCodegenTarget::TypeScript { prettier } => prettier.as_ref(),
24 AppServerCodegenTarget::JsonSchema => None,
25 }
26 }
27}
28
29#[derive(Clone, Debug, Eq, PartialEq)]
31pub struct AppServerCodegenRequest {
32 pub target: AppServerCodegenTarget,
34 pub out_dir: PathBuf,
36 pub experimental: bool,
38 pub overrides: CliOverridesPatch,
40}
41
42impl AppServerCodegenRequest {
43 pub fn typescript(out_dir: impl Into<PathBuf>) -> Self {
45 Self {
46 target: AppServerCodegenTarget::TypeScript { prettier: None },
47 out_dir: out_dir.into(),
48 experimental: false,
49 overrides: CliOverridesPatch::default(),
50 }
51 }
52
53 pub fn json_schema(out_dir: impl Into<PathBuf>) -> Self {
55 Self {
56 target: AppServerCodegenTarget::JsonSchema,
57 out_dir: out_dir.into(),
58 experimental: false,
59 overrides: CliOverridesPatch::default(),
60 }
61 }
62
63 pub fn experimental(mut self, enable: bool) -> Self {
65 self.experimental = enable;
66 self
67 }
68
69 pub fn prettier(mut self, prettier: impl Into<PathBuf>) -> Self {
71 if let AppServerCodegenTarget::TypeScript { prettier: slot } = &mut self.target {
72 *slot = Some(prettier.into());
73 }
74 self
75 }
76
77 pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
79 self.overrides = overrides;
80 self
81 }
82
83 pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
85 self.overrides
86 .config_overrides
87 .push(ConfigOverride::new(key, value));
88 self
89 }
90
91 pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
93 self.overrides
94 .config_overrides
95 .push(ConfigOverride::from_raw(raw));
96 self
97 }
98
99 pub fn profile(mut self, profile: impl Into<String>) -> Self {
101 let profile = profile.into();
102 self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
103 self
104 }
105
106 pub fn oss(mut self, enable: bool) -> Self {
108 self.overrides.oss = if enable {
109 FlagState::Enable
110 } else {
111 FlagState::Disable
112 };
113 self
114 }
115
116 pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
118 self.overrides.feature_toggles.enable.push(name.into());
119 self
120 }
121
122 pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
124 self.overrides.feature_toggles.disable.push(name.into());
125 self
126 }
127
128 pub fn search(mut self, enable: bool) -> Self {
130 self.overrides.search = if enable {
131 FlagState::Enable
132 } else {
133 FlagState::Disable
134 };
135 self
136 }
137}
138
139#[derive(Clone, Debug, Eq, PartialEq)]
141pub struct AppServerProxyRequest {
142 pub socket_path: Option<PathBuf>,
144 pub working_dir: Option<PathBuf>,
146 pub overrides: CliOverridesPatch,
148}
149
150impl AppServerProxyRequest {
151 pub fn new() -> Self {
153 Self {
154 socket_path: None,
155 working_dir: None,
156 overrides: CliOverridesPatch::default(),
157 }
158 }
159
160 pub fn socket_path(mut self, socket_path: impl Into<PathBuf>) -> Self {
162 self.socket_path = Some(socket_path.into());
163 self
164 }
165
166 pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
168 self.working_dir = Some(dir.into());
169 self
170 }
171
172 pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
174 self.overrides = overrides;
175 self
176 }
177
178 pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
180 self.overrides
181 .config_overrides
182 .push(ConfigOverride::new(key, value));
183 self
184 }
185
186 pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
188 self.overrides
189 .config_overrides
190 .push(ConfigOverride::from_raw(raw));
191 self
192 }
193
194 pub fn profile(mut self, profile: impl Into<String>) -> Self {
196 let profile = profile.into();
197 self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
198 self
199 }
200
201 pub fn oss(mut self, enable: bool) -> Self {
203 self.overrides.oss = if enable {
204 FlagState::Enable
205 } else {
206 FlagState::Disable
207 };
208 self
209 }
210
211 pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
213 self.overrides.feature_toggles.enable.push(name.into());
214 self
215 }
216
217 pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
219 self.overrides.feature_toggles.disable.push(name.into());
220 self
221 }
222
223 pub fn search(mut self, enable: bool) -> Self {
225 self.overrides.search = if enable {
226 FlagState::Enable
227 } else {
228 FlagState::Disable
229 };
230 self
231 }
232}
233
234impl Default for AppServerProxyRequest {
235 fn default() -> Self {
236 Self::new()
237 }
238}
239
240#[derive(Clone, Debug, Eq, PartialEq)]
242pub struct AppServerRequest {
243 pub listen: Option<String>,
245 pub ws_audience: Option<String>,
247 pub ws_auth: Option<String>,
249 pub ws_issuer: Option<String>,
251 pub ws_max_clock_skew_seconds: Option<u64>,
253 pub ws_shared_secret_file: Option<PathBuf>,
255 pub ws_token_file: Option<PathBuf>,
257 pub ws_token_sha256: Option<String>,
259 pub working_dir: Option<PathBuf>,
261 pub overrides: CliOverridesPatch,
263}
264
265impl AppServerRequest {
266 pub fn new() -> Self {
268 Self {
269 listen: None,
270 ws_audience: None,
271 ws_auth: None,
272 ws_issuer: None,
273 ws_max_clock_skew_seconds: None,
274 ws_shared_secret_file: None,
275 ws_token_file: None,
276 ws_token_sha256: None,
277 working_dir: None,
278 overrides: CliOverridesPatch::default(),
279 }
280 }
281
282 pub fn listen(mut self, listen: impl Into<String>) -> Self {
283 let listen = listen.into();
284 self.listen = (!listen.trim().is_empty()).then_some(listen);
285 self
286 }
287
288 pub fn ws_audience(mut self, value: impl Into<String>) -> Self {
289 let value = value.into();
290 self.ws_audience = (!value.trim().is_empty()).then_some(value);
291 self
292 }
293
294 pub fn ws_auth(mut self, value: impl Into<String>) -> Self {
295 let value = value.into();
296 self.ws_auth = (!value.trim().is_empty()).then_some(value);
297 self
298 }
299
300 pub fn ws_issuer(mut self, value: impl Into<String>) -> Self {
301 let value = value.into();
302 self.ws_issuer = (!value.trim().is_empty()).then_some(value);
303 self
304 }
305
306 pub fn ws_max_clock_skew_seconds(mut self, value: u64) -> Self {
307 self.ws_max_clock_skew_seconds = Some(value);
308 self
309 }
310
311 pub fn ws_shared_secret_file(mut self, path: impl Into<PathBuf>) -> Self {
312 self.ws_shared_secret_file = Some(path.into());
313 self
314 }
315
316 pub fn ws_token_file(mut self, path: impl Into<PathBuf>) -> Self {
317 self.ws_token_file = Some(path.into());
318 self
319 }
320
321 pub fn ws_token_sha256(mut self, value: impl Into<String>) -> Self {
322 let value = value.into();
323 self.ws_token_sha256 = (!value.trim().is_empty()).then_some(value);
324 self
325 }
326
327 pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
328 self.working_dir = Some(dir.into());
329 self
330 }
331
332 pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
333 self.overrides = overrides;
334 self
335 }
336
337 pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
338 self.overrides
339 .config_overrides
340 .push(ConfigOverride::new(key, value));
341 self
342 }
343
344 pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
345 self.overrides
346 .config_overrides
347 .push(ConfigOverride::from_raw(raw));
348 self
349 }
350
351 pub fn profile(mut self, profile: impl Into<String>) -> Self {
352 let profile = profile.into();
353 self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
354 self
355 }
356
357 pub fn oss(mut self, enable: bool) -> Self {
358 self.overrides.oss = if enable {
359 FlagState::Enable
360 } else {
361 FlagState::Disable
362 };
363 self
364 }
365
366 pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
367 self.overrides.feature_toggles.enable.push(name.into());
368 self
369 }
370
371 pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
372 self.overrides.feature_toggles.disable.push(name.into());
373 self
374 }
375
376 pub fn search(mut self, enable: bool) -> Self {
377 self.overrides.search = if enable {
378 FlagState::Enable
379 } else {
380 FlagState::Disable
381 };
382 self
383 }
384}
385
386impl Default for AppServerRequest {
387 fn default() -> Self {
388 Self::new()
389 }
390}
391
392#[derive(Clone, Debug)]
394pub struct AppServerCodegenOutput {
395 pub status: ExitStatus,
397 pub stdout: String,
399 pub stderr: String,
401 pub out_dir: PathBuf,
403}