use crate::{value::Value, SemanticVersion};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug)]
pub struct Executor {
pub name: String,
pub min_version: Option<SemanticVersion>,
pub max_version: Option<SemanticVersion>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum TypeRef {
Scalar { id: String },
Array { id: String },
Map { key_id: String, value_id: String },
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Parameter {
pub id: Uuid,
pub name: String,
#[serde(rename = "type")]
pub ty: TypeRef,
#[serde(default)]
pub mutable: bool,
pub default_value: Option<Value>,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct ImportFunction {
pub module: String,
pub id: Uuid,
pub name: String,
pub parameters: Vec<Parameter>,
pub ret: TypeRef,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct ExportFunction {
pub id: Uuid,
pub name: String,
#[serde(default)]
pub parameters: Vec<Parameter>,
#[serde(default = "default_return_type")]
pub ret: TypeRef,
}
fn default_return_type() -> TypeRef {
TypeRef::Scalar {
id: "unit".to_string(),
}
}
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ImportSymbol {
Function(ImportFunction),
}
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ExportSymbol {
Function(ExportFunction),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Dependency {
pub name: String,
pub min_version: Option<SemanticVersion>,
pub max_version: Option<SemanticVersion>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ModuleDefinition {
pub id: Uuid,
pub name: String,
pub author: String,
pub description: Option<String>,
pub license: String,
pub version: SemanticVersion,
pub executor: Executor,
pub exports: Vec<ExportSymbol>,
pub imports: Vec<ImportSymbol>,
pub executable_mime: String,
}