use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum DistributionKind {
Library,
Specs,
Application,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ProjectionPackage {
pub kind: DistributionKind,
pub package_name: String,
pub dependencies: Vec<ProjectionDependency>,
pub modules: Vec<ProjectionModule>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ProjectionDependency {
pub package_name: String,
pub modules: Vec<ProjectionModule>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ProjectionModule {
pub path: Vec<String>,
pub types: Vec<TypeDeclaration>,
pub values: Vec<ValueSpecification>,
pub doc: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "declaration", rename_all = "kebab-case")]
pub enum TypeDeclaration {
Alias {
source_name: String,
name: String,
type_params: Vec<String>,
value: TypeExpr,
doc: Option<String>,
},
Opaque {
source_name: String,
name: String,
type_params: Vec<String>,
doc: Option<String>,
},
Custom {
source_name: String,
name: String,
type_params: Vec<String>,
constructors: Vec<Constructor>,
doc: Option<String>,
},
Incomplete {
source_name: String,
name: String,
type_params: Vec<String>,
incompleteness: IncompletenessKind,
partial_type: Option<TypeExpr>,
doc: Option<String>,
},
}
impl TypeDeclaration {
pub fn name(&self) -> &str {
match self {
Self::Alias { name, .. }
| Self::Opaque { name, .. }
| Self::Custom { name, .. }
| Self::Incomplete { name, .. } => name,
}
}
pub fn source_name(&self) -> &str {
match self {
Self::Alias { source_name, .. }
| Self::Opaque { source_name, .. }
| Self::Custom { source_name, .. }
| Self::Incomplete { source_name, .. } => source_name,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum IncompletenessKind {
Draft,
Hole,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Constructor {
pub source_name: String,
pub name: String,
pub arguments: Vec<NamedType>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct NamedType {
pub name: String,
pub tpe: TypeExpr,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "type", content = "value", rename_all = "kebab-case")]
pub enum TypeExpr {
Variable(String),
Reference {
source_name: String,
arguments: Vec<TypeExpr>,
},
Tuple(Vec<TypeExpr>),
Record(Vec<NamedType>),
ExtensibleRecord {
variable: String,
fields: Vec<NamedType>,
},
Function {
input: Box<TypeExpr>,
output: Box<TypeExpr>,
},
Unit,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ValueSpecification {
pub source_name: String,
pub name: String,
pub inputs: Vec<NamedType>,
pub output: Option<TypeExpr>,
pub value_kind: ValueKind,
pub entry_point: Option<EntryPointMetadata>,
pub doc: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum ValueKind {
Function,
Constant,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum EntryPointKind {
Main,
Command,
Handler,
Job,
Policy,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct EntryPointMetadata {
pub identifier: String,
pub kind: EntryPointKind,
pub doc: Option<String>,
}