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)) window.localStorage.setItem("restRequest", JSON.stringify(reqClone))
}) })
console.log("localRequest", localRequest)
} }
export function setupLocalPersistence() { export function setupLocalPersistence() {

View File

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