// SPDX-License-Identifier: EUPL-1.2 // Single registry of every rule the engine can report. Rule pages, reports and the // coverage statement are generated from it; tests/engine/fingerprints.test.ts compares the // official rule identifiers and severities with fingerprints computed from the published // Schematron files. import { EN16931_MODEL_RULES } from "./rules-en16931"; import { EN16931_VAT_RULES } from "./rules-en16931-vat"; import { PEPPOL_RULES } from "./rules-peppol"; import { UBL_SYNTAX_RULES } from "./rules-ubl-syntax"; import { STRUCTURE_RULES } from "./structure"; import type { CenRelease, RuleDefinition, RuleRow } from "./types"; import { defineRules } from "./types"; export { ENGINE_VERSION, RULESET_RELEASES } from "./releases"; const XML_RULES: readonly RuleRow[] = [ ["RS-XML-01", "fatal", "The document is not well-formed XML."], ["RS-XML-02", "fatal", "DOCTYPE declarations and custom entities are not allowed."], ["RS-XML-03", "fatal", "The document must be encoded in UTF-8."], ["RS-XML-04", "fatal", "The document exceeds the processing limits of this validator."], ["RS-UBL-01", "fatal", "The root element must be a UBL 2.1 Invoice or CreditNote."] ]; const PROFILE_RULES: readonly RuleRow[] = [["RS-PRF-01", "fatal", "A field required by the validation profile is missing."]]; export const EN16931_RULES: readonly RuleDefinition[] = [ ...defineRules("EN16931", EN16931_MODEL_RULES), ...defineRules("EN16931", EN16931_VAT_RULES), ...defineRules("UBL-SYNTAX", UBL_SYNTAX_RULES) ]; export const PEPPOL_RULE_DEFINITIONS: readonly RuleDefinition[] = defineRules("PEPPOL", PEPPOL_RULES); export const RULES: readonly RuleDefinition[] = [ ...defineRules("XML", XML_RULES), ...defineRules("UBL-STRUCTURE", STRUCTURE_RULES), ...EN16931_RULES, ...PEPPOL_RULE_DEFINITIONS, ...defineRules("PROFILE", PROFILE_RULES) ]; export const RULE_INDEX: ReadonlyMap = new Map(RULES.map((rule) => [rule.id, rule])); const ONLY_IN_1316 = /^BR-A[FG]-\d{2}$/; const ONLY_IN_1317 = /^(BR-I[GP]-\d{2}|UBL-SR-5[78])$/; /** CEN assertions that a given release defines; the registry holds the union of both releases. */ export function cenRules(release: CenRelease): readonly RuleDefinition[] { const excluded = release === "1.3.16" ? ONLY_IN_1317 : ONLY_IN_1316; return EN16931_RULES.filter((rule) => !excluded.test(rule.id)); } /** Rules that have a page on the site: everything except the 673 generated UBL-CR rows. */ export function isDocumentedRule(rule: RuleDefinition): boolean { return !/^UBL-CR-\d{3}$/.test(rule.id) || ["UBL-CR-002", "UBL-CR-412", "UBL-CR-665", "UBL-CR-666", "UBL-CR-673"].includes(rule.id); }