refactor: import/export new architecture
This commit is contained in:
10
packages/hoppscotch-app/helpers/import-export/export/hopp.ts
Normal file
10
packages/hoppscotch-app/helpers/import-export/export/hopp.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import { pipe } from "fp-ts/function"
|
||||||
|
import * as TE from "fp-ts/TaskEither"
|
||||||
|
import { HoppExporter } from "."
|
||||||
|
import { Collection } from "~/newstore/collections"
|
||||||
|
|
||||||
|
const exporter: HoppExporter<Collection<HoppRESTRequest>> = (content) =>
|
||||||
|
pipe(content, JSON.stringify, TE.right)
|
||||||
|
|
||||||
|
export default exporter
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import * as TE from "fp-ts/TaskEither"
|
||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import { Collection } from "~/newstore/collections"
|
||||||
|
|
||||||
|
export type HoppExporter<T> = (content: T) => TE.TaskEither<string, string>
|
||||||
|
|
||||||
|
export type HoppExporterDefintion<T> = {
|
||||||
|
name: string
|
||||||
|
exporter: () => Promise<HoppExporter<T>>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RESTCollectionExporters: HoppExporterDefintion<
|
||||||
|
Collection<HoppRESTRequest>
|
||||||
|
>[] = [
|
||||||
|
{
|
||||||
|
name: "Hoppscotch REST Collection JSON",
|
||||||
|
exporter: () => import("./hopp").then((m) => m.default),
|
||||||
|
},
|
||||||
|
]
|
||||||
20
packages/hoppscotch-app/helpers/import-export/import/hopp.ts
Normal file
20
packages/hoppscotch-app/helpers/import-export/import/hopp.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import { pipe } from "fp-ts/function"
|
||||||
|
import * as TE from "fp-ts/TaskEither"
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
|
import { HoppImporter, IMPORTER_INVALID_FILE_FORMAT } from "."
|
||||||
|
import {
|
||||||
|
Collection,
|
||||||
|
translateToNewRESTCollection,
|
||||||
|
} from "~/newstore/collections"
|
||||||
|
|
||||||
|
const importer: HoppImporter<Collection<HoppRESTRequest>> = (content) =>
|
||||||
|
pipe(
|
||||||
|
E.tryCatch(
|
||||||
|
() => translateToNewRESTCollection(content),
|
||||||
|
() => IMPORTER_INVALID_FILE_FORMAT
|
||||||
|
),
|
||||||
|
TE.fromEither
|
||||||
|
)
|
||||||
|
|
||||||
|
export default importer
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import * as TE from "fp-ts/TaskEither"
|
||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import { Collection } from "~/newstore/collections"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error state to be used when the file formats do not match
|
||||||
|
*/
|
||||||
|
export const IMPORTER_INVALID_FILE_FORMAT =
|
||||||
|
"importer_invalid_file_format" as const
|
||||||
|
|
||||||
|
export type HoppImporterError = typeof IMPORTER_INVALID_FILE_FORMAT
|
||||||
|
|
||||||
|
export type HoppImporter<T> = (
|
||||||
|
content: string
|
||||||
|
) => TE.TaskEither<HoppImporterError, T>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition for importers
|
||||||
|
*/
|
||||||
|
export type HoppImporterDefintion<T> = {
|
||||||
|
/**
|
||||||
|
* Name of the importer, shown on the Select Importer dropdown
|
||||||
|
*/
|
||||||
|
name: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?)
|
||||||
|
*/
|
||||||
|
importer: () => Promise<HoppImporter<T>>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RESTCollectionImporters: HoppImporterDefintion<
|
||||||
|
Collection<HoppRESTRequest>
|
||||||
|
>[] = [
|
||||||
|
{
|
||||||
|
name: "Hoppscotch REST Collection",
|
||||||
|
importer: () => import("./hopp").then((m) => m.default),
|
||||||
|
},
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user