feat(derive): check form model structure

Add #[slhx::form] for user-authored form models, emit form field metadata into slhx.syms, and require form handlers to accept models that passed generated field compatibility checks.

req: form/001

req: form/004

req: form/006

req: codegen/004
This commit is contained in:
slhx agent
2026-05-25 23:44:43 +02:00
parent 34d6757ccd
commit 274b8e9e55
6 changed files with 423 additions and 16 deletions
+17
View File
@@ -591,6 +591,17 @@ fn __slhx_attr(tag: &str, attr: &str) -> Option<::std::string::String> {
for (handle_ident, form_ident) in &self.handle_forms {
out.push_str(&format!("handle_form\t{handle_ident}\t{form_ident}\n"));
}
for form in self.forms.values() {
for control in &form.controls {
out.push_str(&format!(
"form_field\t{}\t{}\t{}\t{}\n",
form.resource.ident,
control.name,
control.required,
form_control_is_multiple(&control.kind)
));
}
}
for (handle_ident, params) in &self.handle_params {
for param in params {
out.push_str(&format!("handle_param\t{handle_ident}\t{param}\n"));
@@ -939,6 +950,10 @@ fn stable_id(kind: &str, symbol: &str) -> u32 {
hash
}
fn form_control_is_multiple(kind: &ControlKind) -> bool {
matches!(kind, ControlKind::Select { multiple: true })
}
fn form_control_kind_expr(kind: &ControlKind) -> String {
match kind {
ControlKind::Text => "::slhx::FormControlKind::Text".to_string(),
@@ -1075,6 +1090,8 @@ mod tests {
let syms = std::fs::read_to_string(out.join("slhx.syms")).unwrap();
assert!(syms.contains("handle_form\tsave\tprofile\n"));
assert!(syms.contains("form_field\tprofile\ttitle\ttrue\tfalse\n"));
assert!(syms.contains("form_field\tprofile\tlabels\tfalse\ttrue\n"));
let _ = std::fs::remove_dir_all(&base);
}