fix(common): ensure requests are translated to the latest version during import and search actions (#3931)
This commit is contained in:
@@ -1,15 +1,19 @@
|
|||||||
import { pipe, flow } from "fp-ts/function"
|
import {
|
||||||
import * as TE from "fp-ts/TaskEither"
|
HoppCollection,
|
||||||
|
HoppRESTRequest,
|
||||||
|
getDefaultGQLRequest,
|
||||||
|
getDefaultRESTRequest,
|
||||||
|
translateToNewRESTCollection,
|
||||||
|
} from "@hoppscotch/data"
|
||||||
|
import * as A from "fp-ts/Array"
|
||||||
import * as O from "fp-ts/Option"
|
import * as O from "fp-ts/Option"
|
||||||
import * as RA from "fp-ts/ReadonlyArray"
|
import * as RA from "fp-ts/ReadonlyArray"
|
||||||
import * as A from "fp-ts/Array"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { translateToNewRESTCollection, HoppCollection } from "@hoppscotch/data"
|
import { flow, pipe } from "fp-ts/function"
|
||||||
|
|
||||||
import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
import { HoppGQLRequest, translateToNewGQLCollection } from "@hoppscotch/data"
|
||||||
import { safeParseJSON } from "~/helpers/functional/json"
|
import { safeParseJSON } from "~/helpers/functional/json"
|
||||||
import { translateToNewGQLCollection } from "@hoppscotch/data"
|
import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
||||||
import { entityReference } from "verzod"
|
|
||||||
import { z } from "zod"
|
|
||||||
|
|
||||||
export const hoppRESTImporter = (content: string[]) =>
|
export const hoppRESTImporter = (content: string[]) =>
|
||||||
pipe(
|
pipe(
|
||||||
@@ -32,8 +36,24 @@ export const hoppRESTImporter = (content: string[]) =>
|
|||||||
* else translate it into one.
|
* else translate it into one.
|
||||||
*/
|
*/
|
||||||
const validateCollection = (collection: unknown) => {
|
const validateCollection = (collection: unknown) => {
|
||||||
const result = entityReference(HoppCollection).safeParse(collection)
|
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)
|
||||||
if (result.success) return O.some(result.data)
|
|
||||||
|
if (collectionSchemaParsedResult.type === "ok") {
|
||||||
|
const requests = collectionSchemaParsedResult.value.requests.map(
|
||||||
|
(request) => {
|
||||||
|
const requestSchemaParsedResult = HoppRESTRequest.safeParse(request)
|
||||||
|
|
||||||
|
return requestSchemaParsedResult.type === "ok"
|
||||||
|
? requestSchemaParsedResult.value
|
||||||
|
: getDefaultRESTRequest()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return O.some({
|
||||||
|
...collectionSchemaParsedResult.value,
|
||||||
|
requests,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return O.some(translateToNewRESTCollection(collection))
|
return O.some(translateToNewRESTCollection(collection))
|
||||||
}
|
}
|
||||||
@@ -64,9 +84,24 @@ export const hoppGQLImporter = (content: string) =>
|
|||||||
* @returns the collection if it is valid, else a translated version of the collection
|
* @returns the collection if it is valid, else a translated version of the collection
|
||||||
*/
|
*/
|
||||||
export const validateGQLCollection = (collection: unknown) => {
|
export const validateGQLCollection = (collection: unknown) => {
|
||||||
const result = z.array(entityReference(HoppCollection)).safeParse(collection)
|
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)
|
||||||
|
|
||||||
if (result.success) return O.some(result.data)
|
if (collectionSchemaParsedResult.type === "ok") {
|
||||||
|
const requests = collectionSchemaParsedResult.value.requests.map(
|
||||||
|
(request) => {
|
||||||
|
const requestSchemaParsedResult = HoppGQLRequest.safeParse(request)
|
||||||
|
|
||||||
|
return requestSchemaParsedResult.type === "ok"
|
||||||
|
? requestSchemaParsedResult.value
|
||||||
|
: getDefaultGQLRequest()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return O.some({
|
||||||
|
...collectionSchemaParsedResult.value,
|
||||||
|
requests,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return O.some(translateToNewGQLCollection(collection))
|
return O.some(translateToNewGQLCollection(collection))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
import { ref } from "vue"
|
import {
|
||||||
|
HoppRESTAuth,
|
||||||
|
HoppRESTHeader,
|
||||||
|
HoppRESTRequest,
|
||||||
|
getDefaultRESTRequest,
|
||||||
|
} from "@hoppscotch/data"
|
||||||
|
import axios from "axios"
|
||||||
|
import { Service } from "dioc"
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
|
import { Ref, ref } from "vue"
|
||||||
|
|
||||||
import { runGQLQuery } from "../backend/GQLClient"
|
import { runGQLQuery } from "../backend/GQLClient"
|
||||||
import {
|
import {
|
||||||
GetCollectionChildrenDocument,
|
GetCollectionChildrenDocument,
|
||||||
@@ -7,15 +17,10 @@ import {
|
|||||||
GetSingleRequestDocument,
|
GetSingleRequestDocument,
|
||||||
} from "../backend/graphql"
|
} from "../backend/graphql"
|
||||||
import { TeamCollection } from "./TeamCollection"
|
import { TeamCollection } from "./TeamCollection"
|
||||||
import { HoppRESTAuth, HoppRESTHeader } from "@hoppscotch/data"
|
|
||||||
|
|
||||||
import * as E from "fp-ts/Either"
|
import { platform } from "~/platform"
|
||||||
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
|
||||||
import { TeamRequest } from "./TeamRequest"
|
import { TeamRequest } from "./TeamRequest"
|
||||||
import { Service } from "dioc"
|
|
||||||
import axios from "axios"
|
|
||||||
import { Ref } from "vue"
|
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
type CollectionSearchMeta = {
|
type CollectionSearchMeta = {
|
||||||
isSearchResult?: boolean
|
isSearchResult?: boolean
|
||||||
@@ -150,12 +155,21 @@ function convertToTeamTree(
|
|||||||
if (isAlreadyInserted) return
|
if (isAlreadyInserted) return
|
||||||
|
|
||||||
if (parentCollection) {
|
if (parentCollection) {
|
||||||
|
const requestSchemaParsedResult = HoppRESTRequest.safeParse(
|
||||||
|
request.request
|
||||||
|
)
|
||||||
|
|
||||||
|
const effectiveRequest =
|
||||||
|
requestSchemaParsedResult.type === "ok"
|
||||||
|
? requestSchemaParsedResult.value
|
||||||
|
: getDefaultRESTRequest()
|
||||||
|
|
||||||
parentCollection.requests = parentCollection.requests || []
|
parentCollection.requests = parentCollection.requests || []
|
||||||
parentCollection.requests.push({
|
parentCollection.requests.push({
|
||||||
id: request.id,
|
id: request.id,
|
||||||
collectionID: request.collectionID,
|
collectionID: request.collectionID,
|
||||||
title: request.title,
|
title: request.title,
|
||||||
request: request.request,
|
request: effectiveRequest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user