feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -16,10 +16,15 @@ export class DecoderFactory {
|
||||
* Creates a decoder for the specified XML content
|
||||
* @param xml XML content to decode
|
||||
* @param skipValidation Whether to skip EN16931 validation
|
||||
* @param formatHint Optional pre-detected format to avoid re-detecting large XML inputs
|
||||
* @returns Appropriate decoder instance
|
||||
*/
|
||||
public static createDecoder(xml: string, skipValidation: boolean = false): BaseDecoder {
|
||||
const format = FormatDetector.detectFormat(xml);
|
||||
public static createDecoder(
|
||||
xml: string,
|
||||
skipValidation: boolean = false,
|
||||
formatHint?: InvoiceFormat,
|
||||
): BaseDecoder {
|
||||
const format = formatHint ?? FormatDetector.detectFormat(xml);
|
||||
|
||||
switch (format) {
|
||||
case InvoiceFormat.UBL:
|
||||
|
||||
@@ -59,28 +59,34 @@ export class ValidatorFactory {
|
||||
/**
|
||||
* Creates a validator for the specified XML content
|
||||
* @param xml XML content to validate
|
||||
* @param formatHint Optional pre-detected format to avoid re-detecting large XML inputs
|
||||
* @param parsedDocument Optional parsed XML document to avoid parsing twice
|
||||
* @returns Appropriate validator instance
|
||||
*/
|
||||
public static createValidator(xml: string): BaseValidator {
|
||||
public static createValidator(
|
||||
xml: string,
|
||||
formatHint?: InvoiceFormat,
|
||||
parsedDocument?: Document,
|
||||
): BaseValidator {
|
||||
try {
|
||||
const format = FormatDetector.detectFormat(xml);
|
||||
const format = formatHint ?? FormatDetector.detectFormat(xml);
|
||||
|
||||
switch (format) {
|
||||
case InvoiceFormat.UBL:
|
||||
return new EN16931UBLValidator(xml);
|
||||
return new EN16931UBLValidator(xml, parsedDocument);
|
||||
|
||||
case InvoiceFormat.XRECHNUNG:
|
||||
return new XRechnungValidator(xml);
|
||||
return new XRechnungValidator(xml, parsedDocument);
|
||||
|
||||
case InvoiceFormat.CII:
|
||||
// For now, use Factur-X validator for generic CII
|
||||
return new FacturXValidator(xml);
|
||||
return new FacturXValidator(xml, parsedDocument);
|
||||
|
||||
case InvoiceFormat.ZUGFERD:
|
||||
return new ZUGFeRDValidator(xml);
|
||||
return new ZUGFeRDValidator(xml, parsedDocument);
|
||||
|
||||
case InvoiceFormat.FACTURX:
|
||||
return new FacturXValidator(xml);
|
||||
return new FacturXValidator(xml, parsedDocument);
|
||||
|
||||
case InvoiceFormat.FATTURAPA:
|
||||
return new FatturaPAValidator(xml);
|
||||
@@ -131,4 +137,4 @@ class GenericValidator extends BaseValidator {
|
||||
protected validateBusinessRules(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user