import { FileEntity } from '../interfaces'; import { IFileProcessor, ProcessorInfo } from '../interfaces/file-processor.interface'; import { ProcessOptions, ProcessResult } from '../interfaces/processor-options.interface'; /** * CSV 处理器配置 */ export interface CsvProcessorOptions extends ProcessOptions { /** 字段分隔符 */ delimiter?: string; /** 引号字符 */ quote?: string; /** 转义字符 */ escape?: string; /** 是否有标题行 */ headers?: boolean; /** 跳过空行数 */ skipLines?: number; /** 跳过空字段 */ skipEmpty?: boolean; /** 严格模式(字段数必须一致) */ strict?: boolean; /** 修剪字段值 */ trim?: boolean; /** 最大行数 */ maxRows?: number; /** 编码 */ encoding?: string; /** DTO类(用于装饰器映射) */ dto?: new () => any; /** 是否使用装饰器映射 */ useDecorators?: boolean; /** 是否将解析结果存入 file_metadata */ saveToMetadata?: boolean; /** 元数据存储键名 */ metadataKey?: string; } /** * CSV 处理结果 */ export interface CsvProcessResult extends ProcessResult { /** CSV 数据 */ data: any[]; /** 表头(如果有) */ headers?: string[]; /** 行数 */ rowCount: number; /** 列数 */ columnCount: number; /** 错误信息 */ errors?: { row: number; errors: string[]; data: any; }[]; /** 成功的行数 */ successCount?: number; /** 失败的行数 */ errorCount?: number; /** 原始数据(用于调试) */ rawRecords?: any[]; /** 是否已保存到元数据 */ savedToMetadata?: boolean; /** 元数据存储键名 */ metadataKey?: string; } /** * CSV 文件处理器 * 解析 CSV 文件并转换为 JSON 格式,支持装饰器映射 */ export declare class CsvProcessor implements IFileProcessor { readonly name = "csv"; readonly supportedTypes: string[]; private readonly logger; /** * 验证是否为 CSV 文件 */ validate(buffer: Buffer): Promise; /** * 处理CSV文件(流式处理优化版) */ process(file: FileEntity, options?: CsvProcessorOptions): Promise; /** * 使用装饰器处理单行数据 */ private processRowWithDecorators; /** * 获取处理器信息 */ getInfo(): ProcessorInfo; /** * 健康检查 */ healthCheck(): Promise; /** * 清理资源 */ cleanup(): Promise; }