Sheet document v2, report v3 / v2 / identity, migration map, sheet snapshot, branding, PDF labels and archive envelope ported from the Zod schemas with their exact semantics: strict objects where Zod is strict, optional fields absent (never null), nullable fields required, integers as JavaScript numbers, UTF-16 caps, hand-checked patterns, url crate for .url(), lone surrogate escapes read as U+FFFD (L1, owner confirmation pending). Fields in Zod schema order (PDF labels in the engine dictionary order): the curated and legacy sheets, the demo report and the three frozen archive envelopes print byte for byte as their Zod / attachment form. ts-rs types regenerated; plan rev 2 after three plan challenges.
117 lines
4.6 KiB
Rust
117 lines
4.6 KiB
Rust
//! The static strings the PDF engine prints, in both locales, frozen into the archive
|
|
//! (`archive/labels.ts`): exactly 25 keys, strict, each at most 256 UTF-16 units.
|
|
|
|
use serde::de::Error as _;
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
#[cfg(feature = "ts")]
|
|
use ts_rs::TS;
|
|
|
|
use crate::domain::js;
|
|
|
|
/// The 25 keys, in the order of `PDF_LABEL_KEYS`.
|
|
pub const PDF_LABEL_KEYS: [&str; 25] = [
|
|
"pdf.empty",
|
|
"pdf.eyebrow.observation",
|
|
"pdf.eyebrow.synthesis",
|
|
"pdf.owner_prefix",
|
|
"pdf.section.comment",
|
|
"pdf.section.conclusion",
|
|
"pdf.section.findings_prefix",
|
|
"pdf.section.free_findings",
|
|
"pdf.section.next_appointment",
|
|
"pdf.section.recommendations",
|
|
"pdf.section.severity",
|
|
"pdf.section.zones",
|
|
"pdf.siret_prefix",
|
|
"pdf.subject",
|
|
"pdf.title.conclusion",
|
|
"pdf.title.suffix.bilan",
|
|
"pdf.view.detail_prefix",
|
|
"pdf.view.general",
|
|
"severity.mild",
|
|
"severity.moderate",
|
|
"severity.severe",
|
|
"lateral.left",
|
|
"lateral.right",
|
|
"footer.powered_by",
|
|
"footer.in_partnership",
|
|
];
|
|
|
|
const LABEL_MAX: usize = 256;
|
|
|
|
fn label<'de, D: Deserializer<'de>>(d: D) -> Result<String, D::Error> {
|
|
let text = String::deserialize(d)?;
|
|
if js::utf16_len(&text) <= LABEL_MAX {
|
|
Ok(text)
|
|
} else {
|
|
Err(D::Error::custom("label over 256 characters"))
|
|
}
|
|
}
|
|
|
|
/// Fields in the order of the engine dictionaries (`packages/pdf/src/i18n`), which is the
|
|
/// order every shipped attachment carries.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct PdfLabels {
|
|
#[serde(rename = "pdf.eyebrow.observation", deserialize_with = "label")]
|
|
pub pdf_eyebrow_observation: String,
|
|
#[serde(rename = "pdf.eyebrow.synthesis", deserialize_with = "label")]
|
|
pub pdf_eyebrow_synthesis: String,
|
|
#[serde(rename = "pdf.title.conclusion", deserialize_with = "label")]
|
|
pub pdf_title_conclusion: String,
|
|
#[serde(rename = "pdf.section.zones", deserialize_with = "label")]
|
|
pub pdf_section_zones: String,
|
|
#[serde(rename = "pdf.section.findings_prefix", deserialize_with = "label")]
|
|
pub pdf_section_findings_prefix: String,
|
|
#[serde(rename = "pdf.section.free_findings", deserialize_with = "label")]
|
|
pub pdf_section_free_findings: String,
|
|
#[serde(rename = "pdf.section.severity", deserialize_with = "label")]
|
|
pub pdf_section_severity: String,
|
|
#[serde(rename = "pdf.section.comment", deserialize_with = "label")]
|
|
pub pdf_section_comment: String,
|
|
#[serde(rename = "pdf.section.conclusion", deserialize_with = "label")]
|
|
pub pdf_section_conclusion: String,
|
|
#[serde(rename = "pdf.section.recommendations", deserialize_with = "label")]
|
|
pub pdf_section_recommendations: String,
|
|
#[serde(rename = "pdf.section.next_appointment", deserialize_with = "label")]
|
|
pub pdf_section_next_appointment: String,
|
|
#[serde(rename = "pdf.view.general", deserialize_with = "label")]
|
|
pub pdf_view_general: String,
|
|
#[serde(rename = "pdf.view.detail_prefix", deserialize_with = "label")]
|
|
pub pdf_view_detail_prefix: String,
|
|
#[serde(rename = "pdf.empty", deserialize_with = "label")]
|
|
pub pdf_empty: String,
|
|
#[serde(rename = "pdf.owner_prefix", deserialize_with = "label")]
|
|
pub pdf_owner_prefix: String,
|
|
#[serde(rename = "pdf.siret_prefix", deserialize_with = "label")]
|
|
pub pdf_siret_prefix: String,
|
|
#[serde(rename = "pdf.title.suffix.bilan", deserialize_with = "label")]
|
|
pub pdf_title_suffix_bilan: String,
|
|
#[serde(rename = "pdf.subject", deserialize_with = "label")]
|
|
pub pdf_subject: String,
|
|
#[serde(rename = "severity.mild", deserialize_with = "label")]
|
|
pub severity_mild: String,
|
|
#[serde(rename = "severity.moderate", deserialize_with = "label")]
|
|
pub severity_moderate: String,
|
|
#[serde(rename = "severity.severe", deserialize_with = "label")]
|
|
pub severity_severe: String,
|
|
#[serde(rename = "lateral.left", deserialize_with = "label")]
|
|
pub lateral_left: String,
|
|
#[serde(rename = "lateral.right", deserialize_with = "label")]
|
|
pub lateral_right: String,
|
|
#[serde(rename = "footer.powered_by", deserialize_with = "label")]
|
|
pub footer_powered_by: String,
|
|
#[serde(rename = "footer.in_partnership", deserialize_with = "label")]
|
|
pub footer_in_partnership: String,
|
|
}
|
|
|
|
/// Strict: every key present in both locales, no extra key.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct PdfLabelSet {
|
|
pub fr: PdfLabels,
|
|
pub en: PdfLabels,
|
|
}
|