UNPKG

@overture-stack/lyric

Version:
40 lines (39 loc) 1.98 kB
import { type Schema } from '@overture-stack/lectern-client'; import { type SupportedFileExtension } from '../../utils/fileUtils.js'; import { type Result } from '../../utils/result.js'; import type { FilenameEntityPair } from '../../utils/schemas.js'; import type { ObjectValues } from '../../utils/types.js'; export declare const SUBMITTED_FILE_ERROR_CODES: { readonly FILE_READ_FAILURE: "FILE_READ_ERROR"; readonly UNSUPPORTED_FILETYPE: "UNSUPPORTED_FILETYPE"; readonly PARSING_FAILURE: "PARSING_ERROR"; readonly UNKNOWN_ENTITY: "UNKNOWN_ENTITY"; readonly INVALID_FILE_NAME: "INVALID_FILE_NAME"; readonly UNRECOGNIZED_HEADER: "UNRECOGNIZED_HEADER"; readonly MISSING_REQUIRED_HEADER: "MISSING_REQUIRED_HEADER"; readonly INCORRECT_SECTION: "INCORRECT_SECTION"; }; export type SubmittedFileErrorCode = ObjectValues<typeof SUBMITTED_FILE_ERROR_CODES>; export type SubmittedFileError = { code: SubmittedFileErrorCode; message: string; }; /** * Attempt to identify the file type from a submitted file. If the filetype is unsupported then this will return * a failure with the corresponding SubmittedFileError. * * Note: This function uses the file extension extracted from the filename to identify the file type. */ export declare function getSubmittedFileType(file: Express.Multer.File): Result<SupportedFileExtension, SubmittedFileError>; /** * Attempt to match a file with the schema entity that it has data for. * * This function will first check if a mapping was provided to match each filename to an entity. * If no match is found in the fileEntityMap, then the filename will be check for a match with a schema name (case insensitive). * If no match is found, then a Failure result will return with the `UNKNOWN_ENTITY` error code. */ export declare function getSubmittedFileEntity(params: { file: Express.Multer.File; schemas: Schema[]; fileEntityMap?: FilenameEntityPair[]; }): Result<Schema, SubmittedFileError>;