import { AwilixContainer } from "awilix"; /** * Generic validation interface used to run validation logic on every line or record. * All different validation objects should implement this interface */ export interface ICsvValidator { /** * * @param value value of column or property * @param context includes contextual information such as line number, line, etc. */ validate: (value: TBuiltLine, context: CsvParserContext) => Promise; } export type CsvParserContext = LineContext & { column: string; }; export type LineContext = { lineNumber: number; line: TLine; }; /** * Abstract class implementation of the IValidator interface. * All validation objects part of the schema should extend this class. */ export declare abstract class AbstractCsvValidator implements ICsvValidator { protected readonly container: AwilixContainer; constructor(container: AwilixContainer); abstract validate(builtLine: TBuiltLine, context: CsvParserContext): Promise; } export type CsvSchemaColumn = (NameAsOptional extends false ? { name: string; } : { name?: string; }) & { required?: boolean; validator?: AbstractCsvValidator; } & ({ mapTo?: string; transform?: ColumnTransformer; } | { match?: RegExp; reducer?: ColumnReducer; transform?: ColumnTransformer; }); export type ColumnTransformer = (value: string, context: CsvParserContext) => unknown; export type ColumnReducer = (builtLine: TBuiltLine, key: string, value: string, context: CsvParserContext) => TBuiltLine; export type CsvSchema = { columns: CsvSchemaColumn[]; };