index.ts (hoppscotch-2.2.1) | : | index.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
import * as TE from "fp-ts/TaskEither" | import * as TE from "fp-ts/TaskEither" | |||
import type { Component } from "vue" | ||||
import { StepsOutputList } from "../steps" | import { StepsOutputList } from "../steps" | |||
/** | /** | |||
* A common error state to be used when the file formats are not expected | * A common error state to be used when the file formats are not expected | |||
*/ | */ | |||
export const IMPORTER_INVALID_FILE_FORMAT = | export const IMPORTER_INVALID_FILE_FORMAT = | |||
"importer_invalid_file_format" as const | "importer_invalid_file_format" as const | |||
export type HoppImporterError = typeof IMPORTER_INVALID_FILE_FORMAT | export type HoppImporterError = typeof IMPORTER_INVALID_FILE_FORMAT | |||
type HoppImporter<T, StepsType, Errors> = ( | type HoppImporter<T, StepsType, Errors> = ( | |||
stepValues: StepsOutputList<StepsType> | stepValues: StepsOutputList<StepsType> | |||
) => TE.TaskEither<Errors, T> | ) => TE.TaskEither<Errors, T> | |||
type HoppImporterApplicableTo = Array< | ||||
"team-collections" | "my-collections" | "url-import" | ||||
> | ||||
/** | /** | |||
* Definition for importers | * Definition for importers | |||
*/ | */ | |||
type HoppImporterDefintion<T, Y, E> = { | type HoppImporterDefinition<T, Y, E> = { | |||
/** | ||||
* the id | ||||
*/ | ||||
id: string | ||||
/** | /** | |||
* Name of the importer, shown on the Select Importer dropdown | * Name of the importer, shown on the Select Importer dropdown | |||
*/ | */ | |||
name: string | name: string | |||
/** | /** | |||
* Icon for importer button | * Icon for importer button | |||
*/ | */ | |||
icon: string | icon: Component | |||
/** | /** | |||
* Identifier for the importer | * Identifier for the importer | |||
*/ | */ | |||
applicableTo?: Array<"team-collections" | "my-collections"> | applicableTo: HoppImporterApplicableTo | |||
/** | /** | |||
* The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?) | * The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?) | |||
*/ | */ | |||
importer: HoppImporter<T, Y, E> | importer: HoppImporter<T, Y, E> | |||
/** | /** | |||
* The steps to fetch information required to run an importer | * The steps to fetch information required to run an importer | |||
*/ | */ | |||
steps: Y | steps: Y | |||
} | } | |||
/** | /** | |||
* Defines a Hoppscotch importer | * Defines a Hoppscotch importer | |||
*/ | */ | |||
export const defineImporter = <ReturnType, StepType, Errors>(input: { | export const defineImporter = <ReturnType, StepType, Errors>(input: { | |||
id: string | ||||
name: string | name: string | |||
icon: string | icon: Component | |||
importer: HoppImporter<ReturnType, StepType, Errors> | importer: HoppImporter<ReturnType, StepType, Errors> | |||
applicableTo?: Array<"team-collections" | "my-collections"> | applicableTo: HoppImporterApplicableTo | |||
steps: StepType | steps: StepType | |||
}) => { | }) => { | |||
return <HoppImporterDefintion<ReturnType, StepType, Errors>>{ | return <HoppImporterDefinition<ReturnType, StepType, Errors>>{ | |||
...input, | ...input, | |||
} | } | |||
} | } | |||
End of changes. 9 change blocks. | ||||
6 lines changed or deleted | 16 lines changed or added |