@pujansrt/data-genie
Version:
High performant ETL engine written in TypeScript
55 lines (54 loc) • 2.53 kB
TypeScript
import { DataWriter, DataRecord } from '../core/interfaces';
/**
* TSVWriter class for writing data records to a Tab-Separated Values (TSV) file.
* It uses the 'csv-stringify' library, configured specifically for tab delimiters.
* Records are written incrementally, and a header row can be included.
*/
export declare class TSVWriter implements DataWriter {
private readonly filePath;
private readonly outputStream;
private stringifier;
private headerWritten;
private fieldNames;
private hasFieldNamesInFirstRow;
/**
* Constructs a new TSVWriter.
* @param filePath The path to the output TSV file.
*/
constructor(filePath: string);
/**
* Specifies whether the first row written should be a header row containing the field names.
* If true, `setFieldNames` can be used to explicitly define names, or they will be inferred
* from the first record.
* @param value True to write field names in the first row, false otherwise.
* @returns The current TSVWriter instance for chaining.
*/
setFieldNamesInFirstRow(value: boolean): this;
/**
* Explicitly sets the names of the fields. These names will be used for the header row
* (if `hasFieldNamesInFirstRow` is true) and to determine the order of values from `DataRecord`s.
* If not called, field names will be inferred from the first record's keys.
* @param names A list of string names for the fields (column headers).
* @returns The current TSVWriter instance for chaining.
*/
setFieldNames(...names: string[]): this;
/**
* Writes a single data record to the TSV file.
* Handles writing the header row if configured and not yet written.
* @param record The DataRecord object to write.
* @returns A Promise that resolves when the record has been written to the stream.
*/
write(record: DataRecord): Promise<void>;
/**
* Writes all data records from an asynchronous iterable to the TSV file.
* @param records An AsyncIterableIterator of DataRecord objects.
* @returns A Promise that resolves when all records have been written.
*/
writeAll(records: AsyncIterableIterator<DataRecord>): Promise<void>;
/**
* Closes the underlying write stream. This should be called when all data has been written
* to ensure all buffered data is flushed to the file and resources are released.
* @returns A Promise that resolves when the stream is closed.
*/
close(): Promise<void>;
}