use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComponentIR {
pub id: String,
pub name: String,
pub route: Option<RouteIR>,
pub static_segments: Vec<String>,
pub dynamic_segments: Vec<DynamicSegment>,
pub events: Vec<EventIR>,
pub actions: Vec<ActionIR>,
pub state_fields: Vec<StateFieldIR>,
pub form_schemas: Vec<FormSchemaIR>,
pub permissions: Vec<String>,
pub children: Vec<String>,
pub is_island: bool,
pub style: Option<CompiledStyle>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DynamicSegment {
pub id: String,
pub expr: String,
pub deps: Vec<String>,
pub segment_type: SegmentType,
pub then_body: Option<SegmentBody>,
pub else_if_bodies: Vec<(String, SegmentBody)>,
pub else_body: Option<SegmentBody>,
pub loop_body: Option<LoopBody>,
pub permission_body: Option<SegmentBody>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SegmentBody {
pub static_segments: Vec<String>,
pub dynamic_segments: Vec<DynamicSegment>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoopBody {
pub item_var: String,
pub index_var: Option<String>,
pub body: SegmentBody,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SegmentType {
Text,
Html,
Attribute { element_id: String, attr_name: String },
Conditional,
Loop,
Permission,
}
impl DynamicSegment {
pub fn new(id: String, expr: String, deps: Vec<String>, segment_type: SegmentType) -> Self {
Self {
id,
expr,
deps,
segment_type,
then_body: None,
else_if_bodies: Vec::new(),
else_body: None,
loop_body: None,
permission_body: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceIR {
pub name: String,
pub collection_name: String,
pub tenant_scoped: bool,
pub primary_key: String,
pub fields: Vec<ResourceFieldIR>,
pub indexes: Vec<ResourceIndexIR>,
pub permissions: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceFieldIR {
pub name: String,
pub ty: String,
pub required: bool,
pub unique: bool,
pub searchable: bool,
pub readonly: bool,
pub default: Option<String>,
pub min: Option<usize>,
pub max: Option<usize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceIndexIR {
pub field: String,
pub unique: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventIR {
pub id: String,
pub event_type: String,
pub handler: String,
pub component_id: String,
pub modifiers: Vec<String>,
pub element_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActionIR {
pub name: String,
pub is_async: bool,
pub params: Vec<ParamIR>,
pub permission: Option<String>,
pub audit: Option<String>,
pub body: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParamIR {
pub name: String,
pub ty: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StateFieldIR {
pub name: String,
pub ty: String,
pub default: Option<String>,
pub secret: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FormSchemaIR {
pub name: String,
pub fields: Vec<FormFieldIR>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FormFieldIR {
pub name: String,
pub ty: String,
pub required: bool,
pub min: Option<usize>,
pub max: Option<usize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouteIR {
pub path: String,
pub method: String,
pub layout: Option<String>,
pub auth: String,
pub tenant: String,
pub permission: Option<String>,
pub cache: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompiledStyle {
pub css: String,
pub scoped: bool,
pub scope_id: Option<String>,
}