feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import * as SaxonJS from 'saxon-js';
|
||||
import type { ValidationResult } from './validation.types.js';
|
||||
|
||||
/**
|
||||
@@ -30,9 +29,7 @@ export class SchematronValidator {
|
||||
*/
|
||||
public async loadSchematron(source: string, isFilePath: boolean = true): Promise<void> {
|
||||
if (isFilePath) {
|
||||
// Load from file
|
||||
const smartfile = await import('@push.rocks/smartfile');
|
||||
this.schematronRules = await smartfile.SmartFile.fromFilePath(source).then(f => f.contentBuffer.toString());
|
||||
this.schematronRules = await plugins.fs.readFile(source, 'utf-8');
|
||||
} else {
|
||||
// Use provided string
|
||||
this.schematronRules = source;
|
||||
@@ -58,14 +55,15 @@ export class SchematronValidator {
|
||||
const xslt = this.generateXSLTFromSchematron(this.schematronRules);
|
||||
|
||||
// Compile the XSLT with Saxon-JS
|
||||
this.compiledStylesheet = await SaxonJS.compile({
|
||||
this.compiledStylesheet = await plugins.SaxonJS.compile({
|
||||
stylesheetText: xslt,
|
||||
warnings: 'silent'
|
||||
});
|
||||
|
||||
this.isCompiled = true;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to compile Schematron: ${error.message}`);
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
throw new Error(`Failed to compile Schematron: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ export class SchematronValidator {
|
||||
|
||||
try {
|
||||
// Transform the XML with the compiled Schematron XSLT
|
||||
const transformResult = await SaxonJS.transform({
|
||||
const transformResult = await plugins.SaxonJS.transform({
|
||||
stylesheetInternal: this.compiledStylesheet,
|
||||
sourceText: xmlContent,
|
||||
destination: 'serialized',
|
||||
@@ -108,11 +106,12 @@ export class SchematronValidator {
|
||||
|
||||
return results;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
results.push({
|
||||
ruleId: 'SCHEMATRON-ERROR',
|
||||
source: 'SCHEMATRON',
|
||||
severity: 'error',
|
||||
message: `Schematron validation failed: ${error.message}`,
|
||||
message: `Schematron validation failed: ${errorMessage}`,
|
||||
btReference: undefined,
|
||||
bgReference: undefined
|
||||
});
|
||||
@@ -323,7 +322,8 @@ export class HybridValidator {
|
||||
try {
|
||||
results.push(...validator.validate(xmlContent));
|
||||
} catch (error) {
|
||||
console.warn(`TS validator failed: ${error.message}`);
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.warn(`TS validator failed: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,8 @@ export class HybridValidator {
|
||||
const schematronResults = await this.schematronValidator.validate(xmlContent, options);
|
||||
results.push(...schematronResults);
|
||||
} catch (error) {
|
||||
console.warn(`Schematron validation failed: ${error.message}`);
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.warn(`Schematron validation failed: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,4 +346,4 @@ export class HybridValidator {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user