spin_manifest/schema/
common.rsuse std::fmt::Display;
use serde::{Deserialize, Serialize};
use wasm_pkg_common::{package::PackageRef, registry::Registry};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Variable {
#[serde(default, skip_serializing_if = "is_false")]
pub required: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default: Option<String>,
#[serde(default, skip_serializing_if = "is_false")]
pub secret: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields, untagged)]
pub enum ComponentSource {
Local(String),
Remote {
url: String,
digest: String,
},
Registry {
registry: Option<Registry>,
package: PackageRef,
version: String,
},
}
impl Display for ComponentSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ComponentSource::Local(path) => write!(f, "{path:?}"),
ComponentSource::Remote { url, digest } => write!(f, "{url:?} with digest {digest:?}"),
ComponentSource::Registry {
registry,
package,
version,
} => {
let registry_suffix = match registry {
None => "default registry".to_owned(),
Some(r) => format!("registry {r:?}"),
};
write!(f, "\"{package}@{version}\" from {registry_suffix}")
}
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields, untagged)]
pub enum WasiFilesMount {
Pattern(String),
Placement {
source: String,
destination: String,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ComponentBuildConfig {
pub command: Commands,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub workdir: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub watch: Vec<String>,
}
impl ComponentBuildConfig {
pub fn commands(&self) -> impl Iterator<Item = &String> {
let as_vec = match &self.command {
Commands::Single(cmd) => vec![cmd],
Commands::Multiple(cmds) => cmds.iter().collect(),
};
as_vec.into_iter()
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Commands {
Single(String),
Multiple(Vec<String>),
}
fn is_false(v: &bool) -> bool {
!*v
}