index.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import * as TE from "fp-ts/TaskEither"
  2. import { StepsOutputList } from "../steps"
  3. /**
  4. * A common error state to be used when the file formats are not expected
  5. */
  6. export const IMPORTER_INVALID_FILE_FORMAT =
  7. "importer_invalid_file_format" as const
  8. export type HoppImporterError = typeof IMPORTER_INVALID_FILE_FORMAT
  9. type HoppImporter<T, StepsType, Errors> = (
  10. stepValues: StepsOutputList<StepsType>
  11. ) => TE.TaskEither<Errors, T>
  12. /**
  13. * Definition for importers
  14. */
  15. type HoppImporterDefinition<T, Y, E> = {
  16. /**
  17. * Name of the importer, shown on the Select Importer dropdown
  18. */
  19. name: string
  20. /**
  21. * Icon for importer button
  22. */
  23. icon: string
  24. /**
  25. * Identifier for the importer
  26. */
  27. applicableTo?: Array<"team-collections" | "my-collections">
  28. /**
  29. * The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?)
  30. */
  31. importer: HoppImporter<T, Y, E>
  32. /**
  33. * The steps to fetch information required to run an importer
  34. */
  35. steps: Y
  36. }
  37. /**
  38. * Defines a Hoppscotch importer
  39. */
  40. export const defineImporter = <ReturnType, StepType, Errors>(input: {
  41. name: string
  42. icon: string
  43. importer: HoppImporter<ReturnType, StepType, Errors>
  44. applicableTo?: Array<"team-collections" | "my-collections">
  45. steps: StepType
  46. }) => {
  47. return <HoppImporterDefinition<ReturnType, StepType, Errors>>{
  48. ...input,
  49. }
  50. }