UNPKG

@overture-stack/lyric

Version:
63 lines (62 loc) 3.19 kB
import { type Unit } from 'bytes'; import { z } from 'zod'; import { type DataRecord, type ParseSchemaError, type Schema, type UnprocessedDataRecord } from '@overture-stack/lectern-client'; import { type BatchError } from './types.js'; export declare const SUPPORTED_FILE_EXTENSIONS: z.ZodEnum<["tsv", "csv"]>; export type SupportedFileExtension = z.infer<typeof SUPPORTED_FILE_EXTENSIONS>; export declare const columnSeparatorValue: { readonly tsv: "\t"; readonly csv: ","; }; /** * Determines the separator character for a given file based on its extension. * @param file The name of the file whose extension determines the separator character. * @returns The separator character associated with the file extension, or `undefined` if * the file extension is invalid or unrecognized. */ export declare const getSeparatorCharacter: (file: Express.Multer.File) => string | undefined; /** * Maps a record array to an object with keys from headers, formatting each value for compatibility. * @param headers An array of header names, used as keys for the returned object. * @param record An array of values corresponding to each header, to be formatted and mapped. * @returns An `UnprocessedDataRecord` object where each header in `headers` is a key, * and each value is the corresponding entry in `record` formatted for compatibility. */ export declare const mapRecordToHeaders: (headers: string[], record: string[]) => UnprocessedDataRecord; /** * Reads only first line of the file * Usefull when file is too large and we're only interested in column names * @param file A file we want to read * @returns a string with the content of the first line of the file */ export declare const readHeaders: (file: Express.Multer.File) => Promise<string>; /** * Reads a text file and parses it to typed records. * Returns all records (valid or not) and a separate list of per-row schema validation errors. * Supported file types: .tsv and .csv */ export declare const readTextFile: (file: Express.Multer.File, schema: Schema) => Promise<{ records: DataRecord[]; errors: ParseSchemaError[]; }>; export declare function getSizeInBytes(size: string | number): number; /** * Formats a file size from bytes to a specified unit with a defined precision. * * @param sizeInBytes - The file size in bytes to be formatted. * @param unit - The unit to which the size should be converted (e.g., 'MB', 'GB'). * @param precision - The number of decimal places to include in the formatted output. * @returns The file size formatted as a string in the specified unit with the given precision. Returns null if sizeInBytes is not a Finite number. * */ export declare const formatByteSize: (sizeInBytes: number, unit: Unit, precision: number) => string | null; type FileProcessingResult = { validFiles: Express.Multer.File[]; fileErrors: BatchError[]; }; /** * Validates an array of uploaded files in parallel, checking extension and required headers. * Returns files that passed validation and batch errors for those that did not. */ export declare const processFiles: (files: Express.Multer.File[]) => Promise<FileProcessingResult>; export {};