typst table creation

This commit is contained in:
Filipriec
2026-08-30 20:49:30 +02:00
parent fedf89d94a
commit 04b45e125c
7 changed files with 572 additions and 3 deletions

View File

@@ -13,4 +13,5 @@ pub mod navigation;
mod search;
pub mod session;
pub mod transport;
pub mod typst;
pub mod value;

View File

@@ -120,6 +120,8 @@ mod tests {
let mut second = Request::new(());
operation.add_metadata(&mut first).unwrap();
operation.add_metadata(&mut second).unwrap();
assert_eq!(first.metadata(), second.metadata());
for key in ["idempotency-key", "operation-created-at"] {
assert_eq!(first.metadata().get(key), second.metadata().get(key));
}
}
}

48
komp-app/src/typst.rs Normal file
View File

@@ -0,0 +1,48 @@
pub use common::typst_contract::{TypstContract, TypstContractError};
use common::proto::komp_ac::document_data::TypstTemplateVersion;
/// Parses the first meaningful declaration from stored Typst source for the
/// admin mapping workflow. It must be the literal `komp_ac_fields` tuple;
/// only whitespace and comments may precede it. The server independently runs
/// the same shared parser before accepting a submitted mapping.
pub fn parse_contract(source: &str) -> Result<TypstContract, TypstContractError> {
common::typst_contract::parse(source)
}
/// Parses the source carried by an immutable template-version response. Admin
/// workflows should retain `version.id` separately and send it back when they
/// submit the reviewed table mapping.
pub fn parse_template_version(
version: &TypstTemplateVersion,
) -> Result<TypstContract, TypstContractError> {
parse_contract(&version.source_code)
}
#[cfg(test)]
mod tests {
use super::{parse_contract, parse_template_version};
use common::proto::komp_ac::document_data::TypstTemplateVersion;
#[test]
fn exposes_typst_fields_to_client_workflows() {
let contract = parse_contract(
r#"#let komp_ac_fields = ("invoice.number", "items[].quantity")"#,
)
.unwrap();
assert_eq!(
contract.field_paths,
["invoice.number", "items[].quantity"]
);
let version = TypstTemplateVersion {
id: 42,
source_code: r#"#let komp_ac_fields = ("invoice.number",)"#.to_string(),
..Default::default()
};
assert_eq!(
parse_template_version(&version).unwrap().field_paths,
["invoice.number"]
);
}
}