refactor: revamp the importers & exporters systems to be reused (#3425)

Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
Akash K
2023-12-06 21:24:29 +05:30
committed by GitHub
parent d9c75ed79e
commit ab7c29d228
90 changed files with 2399 additions and 1892 deletions

View File

@@ -16,12 +16,18 @@ import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data"
import { appendRESTCollections } from "~/newstore/collections"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import { URLImporters } from "~/helpers/import-export/import/importers"
import { IMPORTER_INVALID_FILE_FORMAT } from "~/helpers/import-export/import"
import { OPENAPI_DEREF_ERROR } from "~/helpers/import-export/import/openapi"
import { isOfType } from "~/helpers/functional/primtive"
import { TELeftType } from "~/helpers/functional/taskEither"
import {
hoppRESTImporter,
hoppPostmanImporter,
hoppInsomniaImporter,
hoppOpenAPIImporter,
} from "~/helpers/import-export/import/importers"
const route = useRoute()
const router = useRouter()
const toast = useToast()
@@ -30,16 +36,33 @@ const t = useI18n()
const IMPORTER_INVALID_TYPE = "importer_invalid_type" as const
const IMPORTER_INVALID_FETCH = "importer_invalid_fetch" as const
// TODO: move this to importers after moving the importer metadatas from respective components to imports/*.ts file
const URLImporters = [
{
id: "hoppscotch",
importer: hoppRESTImporter,
},
{
id: "postman",
importer: hoppPostmanImporter,
},
{
id: "insomnia",
importer: hoppInsomniaImporter,
},
{
id: "openapi",
importer: hoppOpenAPIImporter,
},
]
const importCollections = (url: unknown, type: unknown) =>
pipe(
TE.Do,
TE.bind("importer", () =>
pipe(
URLImporters,
RA.findFirst(
(importer) =>
importer.applicableTo.includes("url-import") && importer.id === type
),
RA.findFirst((importer) => importer.id === type),
TE.fromOption(() => IMPORTER_INVALID_TYPE)
)
),
@@ -56,7 +79,7 @@ const importCollections = (url: unknown, type: unknown) =>
content.data,
TO.fromPredicate(isOfType("string")),
TE.fromTaskOption(() => IMPORTER_INVALID_FILE_FORMAT),
TE.chain((data) => importer.importer([data]))
TE.chain((data) => importer.importer(data))
)
)
)

View File

@@ -210,7 +210,7 @@ export default defineComponent({
const loadingCurrentUser = computed(() => {
if (!probableUser.value) return false
else if (!currentUser.value) return true
else return false
return false
})
return {
@@ -264,21 +264,20 @@ export default defineComponent({
getErrorMessage(error: GQLError<GetInviteDetailsError>) {
if (error.type === "network_error") {
return this.t("error.network_error")
} else {
switch (error.error) {
case "team_invite/not_valid_viewer":
return this.t("team.not_valid_viewer")
case "team_invite/not_found":
return this.t("team.not_found")
case "team_invite/no_invite_found":
return this.t("team.no_invite_found")
case "team_invite/already_member":
return this.t("team.already_member")
case "team_invite/email_do_not_match":
return this.t("team.email_do_not_match")
default:
return this.t("error.something_went_wrong")
}
}
switch (error.error) {
case "team_invite/not_valid_viewer":
return this.t("team.not_valid_viewer")
case "team_invite/not_found":
return this.t("team.not_found")
case "team_invite/no_invite_found":
return this.t("team.no_invite_found")
case "team_invite/already_member":
return this.t("team.already_member")
case "team_invite/email_do_not_match":
return this.t("team.email_do_not_match")
default:
return this.t("error.something_went_wrong")
}
},
},

View File

@@ -235,7 +235,7 @@ const probableUser = useReadonlyStream(
const loadingCurrentUser = computed(() => {
if (!probableUser.value) return false
else if (!currentUser.value) return true
else return false
return false
})
const displayName = ref(currentUser.value?.displayName || "")