use crate::{CliOverridesPatch, ConfigOverride, FlagState};
use std::{path::PathBuf, process::ExitStatus};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AppServerCodegenTarget {
TypeScript { prettier: Option<PathBuf> },
JsonSchema,
}
impl AppServerCodegenTarget {
pub(crate) fn subcommand(&self) -> &'static str {
match self {
AppServerCodegenTarget::TypeScript { .. } => "generate-ts",
AppServerCodegenTarget::JsonSchema => "generate-json-schema",
}
}
pub(crate) fn prettier(&self) -> Option<&PathBuf> {
match self {
AppServerCodegenTarget::TypeScript { prettier } => prettier.as_ref(),
AppServerCodegenTarget::JsonSchema => None,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AppServerCodegenRequest {
pub target: AppServerCodegenTarget,
pub out_dir: PathBuf,
pub experimental: bool,
pub overrides: CliOverridesPatch,
}
impl AppServerCodegenRequest {
pub fn typescript(out_dir: impl Into<PathBuf>) -> Self {
Self {
target: AppServerCodegenTarget::TypeScript { prettier: None },
out_dir: out_dir.into(),
experimental: false,
overrides: CliOverridesPatch::default(),
}
}
pub fn json_schema(out_dir: impl Into<PathBuf>) -> Self {
Self {
target: AppServerCodegenTarget::JsonSchema,
out_dir: out_dir.into(),
experimental: false,
overrides: CliOverridesPatch::default(),
}
}
pub fn experimental(mut self, enable: bool) -> Self {
self.experimental = enable;
self
}
pub fn prettier(mut self, prettier: impl Into<PathBuf>) -> Self {
if let AppServerCodegenTarget::TypeScript { prettier: slot } = &mut self.target {
*slot = Some(prettier.into());
}
self
}
pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
self.overrides = overrides;
self
}
pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::new(key, value));
self
}
pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::from_raw(raw));
self
}
pub fn profile(mut self, profile: impl Into<String>) -> Self {
let profile = profile.into();
self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
self
}
pub fn oss(mut self, enable: bool) -> Self {
self.overrides.oss = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.enable.push(name.into());
self
}
pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.disable.push(name.into());
self
}
pub fn search(mut self, enable: bool) -> Self {
self.overrides.search = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AppServerProxyRequest {
pub socket_path: Option<PathBuf>,
pub working_dir: Option<PathBuf>,
pub overrides: CliOverridesPatch,
}
impl AppServerProxyRequest {
pub fn new() -> Self {
Self {
socket_path: None,
working_dir: None,
overrides: CliOverridesPatch::default(),
}
}
pub fn socket_path(mut self, socket_path: impl Into<PathBuf>) -> Self {
self.socket_path = Some(socket_path.into());
self
}
pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.working_dir = Some(dir.into());
self
}
pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
self.overrides = overrides;
self
}
pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::new(key, value));
self
}
pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::from_raw(raw));
self
}
pub fn profile(mut self, profile: impl Into<String>) -> Self {
let profile = profile.into();
self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
self
}
pub fn oss(mut self, enable: bool) -> Self {
self.overrides.oss = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.enable.push(name.into());
self
}
pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.disable.push(name.into());
self
}
pub fn search(mut self, enable: bool) -> Self {
self.overrides.search = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
}
impl Default for AppServerProxyRequest {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AppServerRequest {
pub listen: Option<String>,
pub ws_audience: Option<String>,
pub ws_auth: Option<String>,
pub ws_issuer: Option<String>,
pub ws_max_clock_skew_seconds: Option<u64>,
pub ws_shared_secret_file: Option<PathBuf>,
pub ws_token_file: Option<PathBuf>,
pub ws_token_sha256: Option<String>,
pub working_dir: Option<PathBuf>,
pub overrides: CliOverridesPatch,
}
impl AppServerRequest {
pub fn new() -> Self {
Self {
listen: None,
ws_audience: None,
ws_auth: None,
ws_issuer: None,
ws_max_clock_skew_seconds: None,
ws_shared_secret_file: None,
ws_token_file: None,
ws_token_sha256: None,
working_dir: None,
overrides: CliOverridesPatch::default(),
}
}
pub fn listen(mut self, listen: impl Into<String>) -> Self {
let listen = listen.into();
self.listen = (!listen.trim().is_empty()).then_some(listen);
self
}
pub fn ws_audience(mut self, value: impl Into<String>) -> Self {
let value = value.into();
self.ws_audience = (!value.trim().is_empty()).then_some(value);
self
}
pub fn ws_auth(mut self, value: impl Into<String>) -> Self {
let value = value.into();
self.ws_auth = (!value.trim().is_empty()).then_some(value);
self
}
pub fn ws_issuer(mut self, value: impl Into<String>) -> Self {
let value = value.into();
self.ws_issuer = (!value.trim().is_empty()).then_some(value);
self
}
pub fn ws_max_clock_skew_seconds(mut self, value: u64) -> Self {
self.ws_max_clock_skew_seconds = Some(value);
self
}
pub fn ws_shared_secret_file(mut self, path: impl Into<PathBuf>) -> Self {
self.ws_shared_secret_file = Some(path.into());
self
}
pub fn ws_token_file(mut self, path: impl Into<PathBuf>) -> Self {
self.ws_token_file = Some(path.into());
self
}
pub fn ws_token_sha256(mut self, value: impl Into<String>) -> Self {
let value = value.into();
self.ws_token_sha256 = (!value.trim().is_empty()).then_some(value);
self
}
pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.working_dir = Some(dir.into());
self
}
pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
self.overrides = overrides;
self
}
pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::new(key, value));
self
}
pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::from_raw(raw));
self
}
pub fn profile(mut self, profile: impl Into<String>) -> Self {
let profile = profile.into();
self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
self
}
pub fn oss(mut self, enable: bool) -> Self {
self.overrides.oss = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.enable.push(name.into());
self
}
pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.disable.push(name.into());
self
}
pub fn search(mut self, enable: bool) -> Self {
self.overrides.search = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
}
impl Default for AppServerRequest {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug)]
pub struct AppServerCodegenOutput {
pub status: ExitStatus,
pub stdout: String,
pub stderr: String,
pub out_dir: PathBuf,
}