feat: add typing for importer errors

This commit is contained in:
Andrew Bastin
2022-01-03 10:06:20 +05:30
parent d6ec3158bc
commit e9e791ce90

View File

@@ -2,21 +2,21 @@ import * as TE from "fp-ts/TaskEither"
import { StepsOutputList } from "../steps"
/**
* The error state to be used when the file formats do not match
* A common error state to be used when the file formats are not expected
*/
export const IMPORTER_INVALID_FILE_FORMAT =
"importer_invalid_file_format" as const
export type HoppImporterError = typeof IMPORTER_INVALID_FILE_FORMAT
type HoppImporter<T, StepsType> = (
type HoppImporter<T, StepsType, Errors> = (
stepValues: StepsOutputList<StepsType>
) => TE.TaskEither<HoppImporterError, T>
) => TE.TaskEither<Errors, T>
/**
* Definition for importers
*/
type HoppImporterDefintion<T, Y> = {
type HoppImporterDefintion<T, Y, E> = {
/**
* Name of the importer, shown on the Select Importer dropdown
*/
@@ -25,7 +25,7 @@ type HoppImporterDefintion<T, Y> = {
/**
* The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?)
*/
importer: HoppImporter<T, Y>
importer: HoppImporter<T, Y, E>
/**
* The steps to fetch information required to run an importer
@@ -36,12 +36,12 @@ type HoppImporterDefintion<T, Y> = {
/**
* Defines a Hoppscotch importer
*/
export const defineImporter = <ReturnType, StepType>(input: {
export const defineImporter = <ReturnType, StepType, Errors>(input: {
name: string
importer: HoppImporter<ReturnType, StepType>
importer: HoppImporter<ReturnType, StepType, Errors>
steps: StepType
}) => {
return <HoppImporterDefintion<ReturnType, StepType>>{
return <HoppImporterDefintion<ReturnType, StepType, Errors>>{
...input,
}
}