Modified HoppRESTRequest data structure

This commit is contained in:
Jason Casareno
2022-07-21 14:21:45 -07:00
parent 21021a3cd9
commit 9b60dc5f2d
2 changed files with 30 additions and 1 deletions

View File

@@ -321,6 +321,8 @@ function setupRequestPersistence() {
}
window.localStorage.setItem("restRequest", JSON.stringify(reqClone))
})
console.log("localRequest", localRequest)
}
export function setupLocalPersistence() {

View File

@@ -8,7 +8,7 @@ import { lodashIsEqualEq, mapThenEq, undefinedEq } from "../utils/eq"
export * from "./content-types"
export * from "./HoppRESTAuth"
export const RESTReqSchemaVersion = "1"
export const RESTReqSchemaVersion = "2"
export type HoppRESTParam = {
key: string
@@ -16,6 +16,11 @@ export type HoppRESTParam = {
active: boolean
}
export type HoppRESTVar = {
key: string
value: string
}
export type HoppRESTHeader = {
key: string
value: string
@@ -51,6 +56,7 @@ export interface HoppRESTRequest {
method: string
endpoint: string
params: HoppRESTParam[]
vars: HoppRESTVar[]
headers: HoppRESTHeader[]
preRequestScript: string
testScript: string
@@ -74,6 +80,10 @@ export const HoppRESTRequestEq = Eq.struct<HoppRESTRequest>({
(arr) => arr.filter((p) => p.key !== "" && p.value !== ""),
lodashIsEqualEq
),
vars: mapThenEq(
(arr) => arr.filter((p) => p.key !== "" && p.value !== ""),
lodashIsEqualEq
),
method: S.Eq,
name: S.Eq,
preRequestScript: S.Eq,
@@ -126,6 +136,9 @@ export function safelyExtractRESTRequest(
if (x.hasOwnProperty("params") && Array.isArray(x.params))
req.params = x.params // TODO: Deep nested checks
if (x.hasOwnProperty("vars") && Array.isArray(x.vars))
req.vars = x.vars // TODO: Deep nested checks
if (x.hasOwnProperty("headers") && Array.isArray(x.headers))
req.headers = x.headers // TODO: Deep nested checks
}
@@ -186,6 +199,19 @@ export function translateToNewRequest(x: any): HoppRESTRequest {
})
)
const vars: HoppRESTVar[] = (x?.vars ?? []).map(
({
key,
value,
}: {
key: string
value: string
}) => ({
key,
value,
})
)
const name = x?.name ?? "Untitled request"
const method = x?.method ?? ""
@@ -201,6 +227,7 @@ export function translateToNewRequest(x: any): HoppRESTRequest {
endpoint,
headers,
params,
vars,
method,
preRequestScript,
testScript,