UNPKG

@fin.cx/einvoice

Version:

A TypeScript module for creating, manipulating, and embedding XML data within PDF files specifically tailored for electronic invoice (einvoice) packages.

65 lines (56 loc) 1.67 kB
import { ValidationLevel } from '../../interfaces/common.js'; import type { ValidationResult, ValidationError } from '../../interfaces/common.js'; /** * Base validator class that defines common validation functionality * for all invoice format validators */ export abstract class BaseValidator { protected xml: string; protected errors: ValidationError[] = []; constructor(xml: string) { this.xml = xml; } /** * Validates XML against the specified level of validation * @param level Validation level (syntax, semantic, business) * @returns Result of validation */ abstract validate(level?: ValidationLevel): ValidationResult; /** * Gets all validation errors found during validation * @returns Array of validation errors */ public getValidationErrors(): ValidationError[] { return this.errors; } /** * Checks if the document is valid * @returns True if no validation errors were found */ public isValid(): boolean { return this.errors.length === 0; } /** * Validates XML against schema * @returns True if schema validation passed */ protected abstract validateSchema(): boolean; /** * Validates business rules * @returns True if business rule validation passed */ protected abstract validateBusinessRules(): boolean; /** * Adds an error to the validation errors list * @param code Error code * @param message Error message * @param location Location in the XML where the error occurred */ protected addError(code: string, message: string, location: string = ''): void { this.errors.push({ code, message, location }); } }