chore: update types
This commit is contained in:
@@ -8,7 +8,7 @@ export const getDefaultRESTRequest = (): HoppRESTRequest => ({
|
|||||||
headers: [],
|
headers: [],
|
||||||
method: "GET",
|
method: "GET",
|
||||||
auth: {
|
auth: {
|
||||||
authType: "none",
|
authType: "inherit",
|
||||||
authActive: true,
|
authActive: true,
|
||||||
},
|
},
|
||||||
preRequestScript: "",
|
preRequestScript: "",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { HoppRESTRequest } from "@hoppscotch/data"
|
|||||||
import { HoppRESTResponse } from "../types/HoppRESTResponse"
|
import { HoppRESTResponse } from "../types/HoppRESTResponse"
|
||||||
import { HoppTestResult } from "../types/HoppTestResult"
|
import { HoppTestResult } from "../types/HoppTestResult"
|
||||||
import { RESTOptionTabs } from "~/components/http/RequestOptions.vue"
|
import { RESTOptionTabs } from "~/components/http/RequestOptions.vue"
|
||||||
|
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
|
||||||
|
|
||||||
export type HoppRESTSaveContext =
|
export type HoppRESTSaveContext =
|
||||||
| {
|
| {
|
||||||
@@ -80,4 +81,10 @@ export type HoppRESTDocument = {
|
|||||||
* Options tab preference for the current tab's document
|
* Options tab preference for the current tab's document
|
||||||
*/
|
*/
|
||||||
optionTabPreference?: RESTOptionTabs
|
optionTabPreference?: RESTOptionTabs
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The inherited properties from the parent collection
|
||||||
|
* (if any)
|
||||||
|
*/
|
||||||
|
inheritedProperties?: HoppInheritedProperty
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
|
||||||
|
export type HoppInheritedProperty = {
|
||||||
|
parentId: string
|
||||||
|
parentName: string
|
||||||
|
auth?: HoppRESTRequest["auth"]
|
||||||
|
headers?: HoppRESTRequest["headers"]
|
||||||
|
}
|
||||||
@@ -17,6 +17,11 @@ const defaultRESTCollectionState = {
|
|||||||
name: "My Collection",
|
name: "My Collection",
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
|
auth: {
|
||||||
|
authType: "inherit",
|
||||||
|
authActive: false,
|
||||||
|
},
|
||||||
|
headers: [],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -27,6 +32,11 @@ const defaultGraphqlCollectionState = {
|
|||||||
name: "My GraphQL Collection",
|
name: "My GraphQL Collection",
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
|
auth: {
|
||||||
|
authType: "inherit",
|
||||||
|
authActive: false,
|
||||||
|
},
|
||||||
|
headers: [],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -132,6 +142,15 @@ const restCollectionDispatchers = defineDispatchers({
|
|||||||
name,
|
name,
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
|
auth: {
|
||||||
|
authType: "inherit",
|
||||||
|
authActive: false,
|
||||||
|
auth: {
|
||||||
|
authType: "inherit",
|
||||||
|
authActive: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
headers: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
const newState = state
|
const newState = state
|
||||||
@@ -690,8 +709,12 @@ const gqlCollectionDispatchers = defineDispatchers({
|
|||||||
name,
|
name,
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
|
auth: {
|
||||||
|
authType: "inherit",
|
||||||
|
authActive: false,
|
||||||
|
},
|
||||||
|
headers: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
const newState = state
|
const newState = state
|
||||||
const indexPaths = path.split("/").map((x) => parseInt(x))
|
const indexPaths = path.split("/").map((x) => parseInt(x))
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { GQL_REQ_SCHEMA_VERSION, HoppGQLRequest, translateToGQLRequest } from "../graphql";
|
import {
|
||||||
import { HoppRESTRequest, translateToNewRequest } from "../rest";
|
GQL_REQ_SCHEMA_VERSION,
|
||||||
|
HoppGQLRequest,
|
||||||
|
translateToGQLRequest,
|
||||||
|
} from "../graphql"
|
||||||
|
import { HoppRESTRequest, translateToNewRequest } from "../rest"
|
||||||
|
|
||||||
const CURRENT_COLL_SCHEMA_VER = 1
|
const CURRENT_COLL_SCHEMA_VER = 1
|
||||||
|
|
||||||
type SupportedReqTypes =
|
type SupportedReqTypes = HoppRESTRequest | HoppGQLRequest
|
||||||
| HoppRESTRequest
|
|
||||||
| HoppGQLRequest
|
|
||||||
|
|
||||||
export type HoppCollection<T extends SupportedReqTypes> = {
|
export type HoppCollection<T extends SupportedReqTypes> = {
|
||||||
v: number
|
v: number
|
||||||
@@ -13,6 +15,9 @@ export type HoppCollection<T extends SupportedReqTypes> = {
|
|||||||
folders: HoppCollection<T>[]
|
folders: HoppCollection<T>[]
|
||||||
requests: T[]
|
requests: T[]
|
||||||
|
|
||||||
|
auth: T["auth"]
|
||||||
|
headers: T["headers"]
|
||||||
|
|
||||||
id?: string // For Firestore ID data
|
id?: string // For Firestore ID data
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +32,7 @@ export function makeCollection<T extends SupportedReqTypes>(
|
|||||||
): HoppCollection<T> {
|
): HoppCollection<T> {
|
||||||
return {
|
return {
|
||||||
v: CURRENT_COLL_SCHEMA_VER,
|
v: CURRENT_COLL_SCHEMA_VER,
|
||||||
...x
|
...x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,10 +51,15 @@ export function translateToNewRESTCollection(
|
|||||||
const folders = (x.folders ?? []).map(translateToNewRESTCollection)
|
const folders = (x.folders ?? []).map(translateToNewRESTCollection)
|
||||||
const requests = (x.requests ?? []).map(translateToNewRequest)
|
const requests = (x.requests ?? []).map(translateToNewRequest)
|
||||||
|
|
||||||
|
const auth = x.auth ?? "None"
|
||||||
|
const headers = x.headers ?? []
|
||||||
|
|
||||||
const obj = makeCollection<HoppRESTRequest>({
|
const obj = makeCollection<HoppRESTRequest>({
|
||||||
name,
|
name,
|
||||||
folders,
|
folders,
|
||||||
requests,
|
requests,
|
||||||
|
auth,
|
||||||
|
headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (x.id) obj.id = x.id
|
if (x.id) obj.id = x.id
|
||||||
@@ -72,14 +82,18 @@ export function translateToNewGQLCollection(
|
|||||||
const folders = (x.folders ?? []).map(translateToNewGQLCollection)
|
const folders = (x.folders ?? []).map(translateToNewGQLCollection)
|
||||||
const requests = (x.requests ?? []).map(translateToGQLRequest)
|
const requests = (x.requests ?? []).map(translateToGQLRequest)
|
||||||
|
|
||||||
|
const auth = x.auth ?? "None"
|
||||||
|
const headers = x.headers ?? []
|
||||||
|
|
||||||
const obj = makeCollection<HoppGQLRequest>({
|
const obj = makeCollection<HoppGQLRequest>({
|
||||||
name,
|
name,
|
||||||
folders,
|
folders,
|
||||||
requests,
|
requests,
|
||||||
|
auth,
|
||||||
|
headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (x.id) obj.id = x.id
|
if (x.id) obj.id = x.id
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export {
|
|||||||
HoppRESTAuth,
|
HoppRESTAuth,
|
||||||
HoppRESTAuthAPIKey,
|
HoppRESTAuthAPIKey,
|
||||||
HoppRESTAuthBasic,
|
HoppRESTAuthBasic,
|
||||||
|
HoppRESTAuthInherit,
|
||||||
HoppRESTAuthBearer,
|
HoppRESTAuthBearer,
|
||||||
HoppRESTAuthNone,
|
HoppRESTAuthNone,
|
||||||
HoppRESTAuthOAuth2,
|
HoppRESTAuthOAuth2,
|
||||||
|
|||||||
@@ -3,27 +3,29 @@ import { z } from "zod"
|
|||||||
|
|
||||||
import { V0_SCHEMA } from "./0"
|
import { V0_SCHEMA } from "./0"
|
||||||
|
|
||||||
export const FormDataKeyValue = z.object({
|
export const FormDataKeyValue = z
|
||||||
key: z.string(),
|
.object({
|
||||||
active: z.boolean()
|
key: z.string(),
|
||||||
}).and(
|
active: z.boolean(),
|
||||||
z.union([
|
})
|
||||||
z.object({
|
.and(
|
||||||
isFile: z.literal(true),
|
z.union([
|
||||||
value: z.array(z.instanceof(Blob).nullable())
|
z.object({
|
||||||
}),
|
isFile: z.literal(true),
|
||||||
z.object({
|
value: z.array(z.instanceof(Blob).nullable()),
|
||||||
isFile: z.literal(false),
|
}),
|
||||||
value: z.string()
|
z.object({
|
||||||
})
|
isFile: z.literal(false),
|
||||||
])
|
value: z.string(),
|
||||||
)
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
export type FormDataKeyValue = z.infer<typeof FormDataKeyValue>
|
export type FormDataKeyValue = z.infer<typeof FormDataKeyValue>
|
||||||
|
|
||||||
export const HoppRESTReqBodyFormData = z.object({
|
export const HoppRESTReqBodyFormData = z.object({
|
||||||
contentType: z.literal("multipart/form-data"),
|
contentType: z.literal("multipart/form-data"),
|
||||||
body: z.array(FormDataKeyValue)
|
body: z.array(FormDataKeyValue),
|
||||||
})
|
})
|
||||||
|
|
||||||
export type HoppRESTReqBodyFormData = z.infer<typeof HoppRESTReqBodyFormData>
|
export type HoppRESTReqBodyFormData = z.infer<typeof HoppRESTReqBodyFormData>
|
||||||
@@ -31,11 +33,11 @@ export type HoppRESTReqBodyFormData = z.infer<typeof HoppRESTReqBodyFormData>
|
|||||||
export const HoppRESTReqBody = z.union([
|
export const HoppRESTReqBody = z.union([
|
||||||
z.object({
|
z.object({
|
||||||
contentType: z.literal(null),
|
contentType: z.literal(null),
|
||||||
body: z.literal(null).catch(null)
|
body: z.literal(null).catch(null),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
contentType: z.literal("multipart/form-data"),
|
contentType: z.literal("multipart/form-data"),
|
||||||
body: z.array(FormDataKeyValue).catch([])
|
body: z.array(FormDataKeyValue).catch([]),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
contentType: z.union([
|
contentType: z.union([
|
||||||
@@ -48,14 +50,14 @@ export const HoppRESTReqBody = z.union([
|
|||||||
z.literal("text/html"),
|
z.literal("text/html"),
|
||||||
z.literal("text/plain"),
|
z.literal("text/plain"),
|
||||||
]),
|
]),
|
||||||
body: z.string().catch("")
|
body: z.string().catch(""),
|
||||||
})
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
export type HoppRESTReqBody = z.infer<typeof HoppRESTReqBody>
|
export type HoppRESTReqBody = z.infer<typeof HoppRESTReqBody>
|
||||||
|
|
||||||
export const HoppRESTAuthNone = z.object({
|
export const HoppRESTAuthNone = z.object({
|
||||||
authType: z.literal("none")
|
authType: z.literal("none"),
|
||||||
})
|
})
|
||||||
|
|
||||||
export type HoppRESTAuthNone = z.infer<typeof HoppRESTAuthNone>
|
export type HoppRESTAuthNone = z.infer<typeof HoppRESTAuthNone>
|
||||||
@@ -96,17 +98,26 @@ export const HoppRESTAuthAPIKey = z.object({
|
|||||||
|
|
||||||
export type HoppRESTAuthAPIKey = z.infer<typeof HoppRESTAuthAPIKey>
|
export type HoppRESTAuthAPIKey = z.infer<typeof HoppRESTAuthAPIKey>
|
||||||
|
|
||||||
export const HoppRESTAuth = z.discriminatedUnion("authType", [
|
export const HoppRESTAuthInherit = z.object({
|
||||||
HoppRESTAuthNone,
|
authType: z.literal("inherit"),
|
||||||
HoppRESTAuthBasic,
|
})
|
||||||
HoppRESTAuthBearer,
|
|
||||||
HoppRESTAuthOAuth2,
|
export type HoppRESTAuthInherit = z.infer<typeof HoppRESTAuthInherit>
|
||||||
HoppRESTAuthAPIKey
|
|
||||||
]).and(
|
export const HoppRESTAuth = z
|
||||||
z.object({
|
.discriminatedUnion("authType", [
|
||||||
authActive: z.boolean(),
|
HoppRESTAuthNone,
|
||||||
})
|
HoppRESTAuthInherit,
|
||||||
)
|
HoppRESTAuthBasic,
|
||||||
|
HoppRESTAuthBearer,
|
||||||
|
HoppRESTAuthOAuth2,
|
||||||
|
HoppRESTAuthAPIKey,
|
||||||
|
])
|
||||||
|
.and(
|
||||||
|
z.object({
|
||||||
|
authActive: z.boolean(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
export type HoppRESTAuth = z.infer<typeof HoppRESTAuth>
|
export type HoppRESTAuth = z.infer<typeof HoppRESTAuth>
|
||||||
|
|
||||||
@@ -114,7 +125,7 @@ export const HoppRESTParams = z.array(
|
|||||||
z.object({
|
z.object({
|
||||||
key: z.string().catch(""),
|
key: z.string().catch(""),
|
||||||
value: z.string().catch(""),
|
value: z.string().catch(""),
|
||||||
active: z.boolean().catch(true)
|
active: z.boolean().catch(true),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -124,7 +135,7 @@ export const HoppRESTHeaders = z.array(
|
|||||||
z.object({
|
z.object({
|
||||||
key: z.string().catch(""),
|
key: z.string().catch(""),
|
||||||
value: z.string().catch(""),
|
value: z.string().catch(""),
|
||||||
active: z.boolean().catch(true)
|
active: z.boolean().catch(true),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -144,17 +155,21 @@ const V1_SCHEMA = z.object({
|
|||||||
|
|
||||||
auth: HoppRESTAuth,
|
auth: HoppRESTAuth,
|
||||||
|
|
||||||
body: HoppRESTReqBody
|
body: HoppRESTReqBody,
|
||||||
})
|
})
|
||||||
|
|
||||||
function parseRequestBody(x: z.infer<typeof V0_SCHEMA>): z.infer<typeof V1_SCHEMA>["body"] {
|
function parseRequestBody(
|
||||||
|
x: z.infer<typeof V0_SCHEMA>
|
||||||
|
): z.infer<typeof V1_SCHEMA>["body"] {
|
||||||
return {
|
return {
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
body: x.contentType === "application/json" ? x.rawParams ?? "" : "",
|
body: x.contentType === "application/json" ? x.rawParams ?? "" : "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseOldAuth(x: z.infer<typeof V0_SCHEMA>): z.infer<typeof V1_SCHEMA>["auth"] {
|
export function parseOldAuth(
|
||||||
|
x: z.infer<typeof V0_SCHEMA>
|
||||||
|
): z.infer<typeof V1_SCHEMA>["auth"] {
|
||||||
if (!x.auth || x.auth === "None")
|
if (!x.auth || x.auth === "None")
|
||||||
return {
|
return {
|
||||||
authType: "none",
|
authType: "none",
|
||||||
@@ -183,7 +198,16 @@ export default defineVersion({
|
|||||||
initial: false,
|
initial: false,
|
||||||
schema: V1_SCHEMA,
|
schema: V1_SCHEMA,
|
||||||
up(old: z.infer<typeof V0_SCHEMA>) {
|
up(old: z.infer<typeof V0_SCHEMA>) {
|
||||||
const { url, path, headers, params, name, method, preRequestScript, testScript } = old
|
const {
|
||||||
|
url,
|
||||||
|
path,
|
||||||
|
headers,
|
||||||
|
params,
|
||||||
|
name,
|
||||||
|
method,
|
||||||
|
preRequestScript,
|
||||||
|
testScript,
|
||||||
|
} = old
|
||||||
|
|
||||||
const endpoint = `${url}${path}`
|
const endpoint = `${url}${path}`
|
||||||
const body = parseRequestBody(old)
|
const body = parseRequestBody(old)
|
||||||
|
|||||||
Reference in New Issue
Block a user