import type { Readable } from 'stream'; import type { ImportIssue } from '../types.js'; export interface CsvLimits { /** Data rows (not the header, not blank rows). More is `FILE_TOO_LARGE`. */ maxRows: number; /** Characters in one cell (ALL-12). */ maxCellLength: number; /** Bytes in one row, line break included. A constant, not a setting. */ maxRowBytes: number; } export declare const DEFAULT_CSV_LIMITS: Readonly; /** The column the "file with errors" download adds (ALL-19). */ export declare const ERRORS_COLUMN = "_errors"; export interface CsvRow { /** The row as a spreadsheet shows it: the first line of the file is row 1. */ rowNumber: number; /** * The cells as written, not trimmed. They line up with the header's * `columns`, unless the row has a `ROW_WIDTH` issue: then they are the cells * of the file as they are. */ cells: string[]; /** The row has an issue of severity `error`; later stages leave it alone. */ hasError: boolean; } /** * What `readCsv` yields, in file order. The issues of a row come before the * row itself, so a consumer that sees the row has seen all of its issues. */ export type CsvEvent = { type: 'header'; /** The row number of the header (1, unless blank lines come first). */ rowNumber: number; /** Trimmed names. `_errors` is left out. A blank name stays blank. */ columns: string[]; } | { type: 'row'; row: CsvRow; } | { type: 'issue'; issue: ImportIssue; } /** Always the last event. `stopped`: a file-level issue ended the reading. */ | { type: 'end'; dataRows: number; stopped: boolean; }; /** * Reads a CSV file as a stream of events, row by row, in constant memory. * * It does the work that belongs to the file and not to an entity: UTF-8 and the * byte order mark, the delimiter, the header, the width of every row, blank * lines, the size of a row, the number of rows, and the limits on a cell. It * does not know what the columns mean; turning cells into values is the job of * the stage after it. * * Problems are reported as events and not thrown. A problem with the file as a * whole (`stopped` on the last event) ends the reading. A failing `source` * (the database, a socket) is not a problem with the file and is thrown. * Stopping the iteration early destroys the source. */ export declare function readCsv(source: Readable, limitOverrides?: Partial): AsyncGenerator;