UNPKG

@overture-stack/lyric

Version:
70 lines (69 loc) 3.62 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 parse it to a JSON format. * Records are parsed to match schema field types. * Supported files: .tsv and .csv * @param {Express.Multer.File} file A file to read * @param {Schema} schema Schema to parse data with * @returns a JSON format objet */ 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[]; }; /** * Processes an array of uploaded files, filtering valid `.tsv` files and checking for required headers * * @param {Express.Multer.File[]} files An array of `Express.Multer.File` objects representing the uploaded files. * @returns A `Promise<FileProcessingResult>` that resolves to an object containing two arrays: * - `validFiles`: Files that have a `.tsv` extension and contain the `systemId` header. * - `fileErrors`: Files that either have an invalid extension or are missing the required `systemId` header. */ export declare function processFiles(files: Express.Multer.File[]): Promise<FileProcessingResult>; export {};