use crate::generated::catalog as g;
pub fn limit(name: &str) -> Option<usize> {
let i = g::LIMIT_NAMES.iter().position(|n| *n == name)?;
g::LIMIT_VALUES.get(i)?.parse().ok()
}
pub const MAX_COMPONENTS: usize = 20_000;
pub const MAX_DEPTH: usize = 48;
pub const MAX_MESSAGE_BYTES: usize = 4_194_304;
pub const MAX_TEMPLATE_ITEMS: usize = 10_000;
pub const MAX_POINTER_BYTES: usize = 1024;
pub const MAX_POINTER_SEGMENTS: usize = 64;
pub const USED_TWICE_ISSUE: &str = "id used twice; only its first place renders";
pub fn depth_issue() -> String {
format!("nesting deeper than {MAX_DEPTH} levels")
}
pub fn components_issue() -> String {
format!("surface: more than {MAX_COMPONENTS} components; the rest is dropped")
}
pub fn template_items_issue() -> String {
format!("template: more than {MAX_TEMPLATE_ITEMS} items; the rest is not rendered")
}
pub fn message_bytes_issue() -> String {
format!("message larger than {MAX_MESSAGE_BYTES} bytes")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_constants_are_limits_json() {
for (name, v) in [
("maxComponents", MAX_COMPONENTS),
("maxDepth", MAX_DEPTH),
("maxMessageBytes", MAX_MESSAGE_BYTES),
("maxTemplateItems", MAX_TEMPLATE_ITEMS),
("maxPointerBytes", MAX_POINTER_BYTES),
("maxPointerSegments", MAX_POINTER_SEGMENTS),
] {
assert_eq!(limit(name), Some(v), "{name}");
}
assert_eq!(g::LIMIT_NAMES.len(), 6);
}
}