update
This commit is contained in:
50
ts/formats/factories/decoder.factory.ts
Normal file
50
ts/formats/factories/decoder.factory.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { BaseDecoder } from '../base/base.decoder.js';
|
||||
import { InvoiceFormat } from '../../interfaces/common.js';
|
||||
import { FormatDetector } from '../utils/format.detector.js';
|
||||
|
||||
// Import specific decoders
|
||||
// import { XRechnungDecoder } from '../ubl/xrechnung/xrechnung.decoder.js';
|
||||
import { FacturXDecoder } from '../cii/facturx/facturx.decoder.js';
|
||||
// import { ZUGFeRDDecoder } from '../cii/zugferd/zugferd.decoder.js';
|
||||
|
||||
/**
|
||||
* Factory to create the appropriate decoder based on the XML format
|
||||
*/
|
||||
export class DecoderFactory {
|
||||
/**
|
||||
* Creates a decoder for the specified XML content
|
||||
* @param xml XML content to decode
|
||||
* @returns Appropriate decoder instance
|
||||
*/
|
||||
public static createDecoder(xml: string): BaseDecoder {
|
||||
const format = FormatDetector.detectFormat(xml);
|
||||
|
||||
switch (format) {
|
||||
case InvoiceFormat.UBL:
|
||||
// return new UBLDecoder(xml);
|
||||
throw new Error('UBL decoder not yet implemented');
|
||||
|
||||
case InvoiceFormat.XRECHNUNG:
|
||||
// return new XRechnungDecoder(xml);
|
||||
throw new Error('XRechnung decoder not yet implemented');
|
||||
|
||||
case InvoiceFormat.CII:
|
||||
// For now, use Factur-X decoder for generic CII
|
||||
return new FacturXDecoder(xml);
|
||||
|
||||
case InvoiceFormat.ZUGFERD:
|
||||
// For now, use Factur-X decoder for ZUGFeRD
|
||||
return new FacturXDecoder(xml);
|
||||
|
||||
case InvoiceFormat.FACTURX:
|
||||
return new FacturXDecoder(xml);
|
||||
|
||||
case InvoiceFormat.FATTURAPA:
|
||||
// return new FatturaPADecoder(xml);
|
||||
throw new Error('FatturaPA decoder not yet implemented');
|
||||
|
||||
default:
|
||||
throw new Error(`Unsupported invoice format: ${format}`);
|
||||
}
|
||||
}
|
||||
}
|
48
ts/formats/factories/encoder.factory.ts
Normal file
48
ts/formats/factories/encoder.factory.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { BaseEncoder } from '../base/base.encoder.js';
|
||||
import { InvoiceFormat } from '../../interfaces/common.js';
|
||||
import type { ExportFormat } from '../../interfaces/common.js';
|
||||
|
||||
// Import specific encoders
|
||||
// import { XRechnungEncoder } from '../ubl/xrechnung/xrechnung.encoder.js';
|
||||
import { FacturXEncoder } from '../cii/facturx/facturx.encoder.js';
|
||||
// import { ZUGFeRDEncoder } from '../cii/zugferd/zugferd.encoder.js';
|
||||
|
||||
/**
|
||||
* Factory to create the appropriate encoder based on the target format
|
||||
*/
|
||||
export class EncoderFactory {
|
||||
/**
|
||||
* Creates an encoder for the specified format
|
||||
* @param format Target format for encoding
|
||||
* @returns Appropriate encoder instance
|
||||
*/
|
||||
public static createEncoder(format: ExportFormat | InvoiceFormat): BaseEncoder {
|
||||
switch (format.toLowerCase()) {
|
||||
case InvoiceFormat.UBL:
|
||||
case 'ubl':
|
||||
// return new UBLEncoder();
|
||||
throw new Error('UBL encoder not yet implemented');
|
||||
|
||||
case InvoiceFormat.XRECHNUNG:
|
||||
case 'xrechnung':
|
||||
// return new XRechnungEncoder();
|
||||
throw new Error('XRechnung encoder not yet implemented');
|
||||
|
||||
case InvoiceFormat.CII:
|
||||
// For now, use Factur-X encoder for generic CII
|
||||
return new FacturXEncoder();
|
||||
|
||||
case InvoiceFormat.ZUGFERD:
|
||||
case 'zugferd':
|
||||
// For now, use Factur-X encoder for ZUGFeRD
|
||||
return new FacturXEncoder();
|
||||
|
||||
case InvoiceFormat.FACTURX:
|
||||
case 'facturx':
|
||||
return new FacturXEncoder();
|
||||
|
||||
default:
|
||||
throw new Error(`Unsupported invoice format for encoding: ${format}`);
|
||||
}
|
||||
}
|
||||
}
|
51
ts/formats/factories/validator.factory.ts
Normal file
51
ts/formats/factories/validator.factory.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { BaseValidator } from '../base/base.validator.js';
|
||||
import { InvoiceFormat } from '../../interfaces/common.js';
|
||||
import { FormatDetector } from '../utils/format.detector.js';
|
||||
|
||||
// Import specific validators
|
||||
// import { UBLValidator } from '../ubl/ubl.validator.js';
|
||||
// import { XRechnungValidator } from '../ubl/xrechnung/xrechnung.validator.js';
|
||||
import { FacturXValidator } from '../cii/facturx/facturx.validator.js';
|
||||
// import { ZUGFeRDValidator } from '../cii/zugferd/zugferd.validator.js';
|
||||
|
||||
/**
|
||||
* Factory to create the appropriate validator based on the XML format
|
||||
*/
|
||||
export class ValidatorFactory {
|
||||
/**
|
||||
* Creates a validator for the specified XML content
|
||||
* @param xml XML content to validate
|
||||
* @returns Appropriate validator instance
|
||||
*/
|
||||
public static createValidator(xml: string): BaseValidator {
|
||||
const format = FormatDetector.detectFormat(xml);
|
||||
|
||||
switch (format) {
|
||||
case InvoiceFormat.UBL:
|
||||
// return new UBLValidator(xml);
|
||||
throw new Error('UBL validator not yet implemented');
|
||||
|
||||
case InvoiceFormat.XRECHNUNG:
|
||||
// return new XRechnungValidator(xml);
|
||||
throw new Error('XRechnung validator not yet implemented');
|
||||
|
||||
case InvoiceFormat.CII:
|
||||
// For now, use Factur-X validator for generic CII
|
||||
return new FacturXValidator(xml);
|
||||
|
||||
case InvoiceFormat.ZUGFERD:
|
||||
// For now, use Factur-X validator for ZUGFeRD
|
||||
return new FacturXValidator(xml);
|
||||
|
||||
case InvoiceFormat.FACTURX:
|
||||
return new FacturXValidator(xml);
|
||||
|
||||
case InvoiceFormat.FATTURAPA:
|
||||
// return new FatturaPAValidator(xml);
|
||||
throw new Error('FatturaPA validator not yet implemented');
|
||||
|
||||
default:
|
||||
throw new Error(`Unsupported invoice format: ${format}`);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user