// SPDX-License-Identifier: EUPL-1.2 import type { DocIndex } from "./query"; import type { XmlNode } from "./xml"; export type Severity = "fatal" | "warning"; /** Rule families shown in reports and on rule pages. */ export type RuleSource = "XML" | "UBL-STRUCTURE" | "EN16931" | "UBL-SYNTAX" | "PEPPOL" | "PROFILE"; export interface RuleDefinition { readonly id: string; readonly severity: Severity; readonly source: RuleSource; /** Short statement of the requirement, written for this product. */ readonly message: string; } export interface Finding { readonly ruleId: string; readonly severity: Severity; /** Element location such as `/Invoice/cac:InvoiceLine[2]/cbc:ID`. */ readonly location: string; readonly line: number; readonly message: string; } /** * CEN artefact release to evaluate. Peppol BIS Billing 3.0.22 bundles 1.3.16, so the Peppol * rule set runs 1.3.16; the plain EN 16931 rule set runs 1.3.17. */ export type CenRelease = "1.3.16" | "1.3.17"; export interface RuleContext { readonly root: XmlNode; readonly isCreditNote: boolean; readonly index: DocIndex; readonly cen: CenRelease; /** Records a violation of `ruleId` at `node`. Unknown ids throw, so a typo cannot hide a rule. */ emit(ruleId: string, node: XmlNode, detail?: string): void; } export type RuleSet = (context: RuleContext) => void; /** `[id, severity, message]` rows keep rule tables compact. */ export type RuleRow = readonly [id: string, severity: Severity, message: string]; export function defineRules(source: RuleSource, rows: readonly RuleRow[]): RuleDefinition[] { return rows.map(([id, severity, message]) => ({ id, severity, source, message })); }