|
@@ -1,7 +1,14 @@
|
|
|
import { defineVersion } from "verzod"
|
|
|
import { z } from "zod"
|
|
|
|
|
|
-import { V8_SCHEMA } from "./8"
|
|
|
+import { HoppRESTRequestVariables } from "./2"
|
|
|
+import { HoppRESTHeaders, HoppRESTParams } from "./7"
|
|
|
+import {
|
|
|
+ HoppRESTAuth,
|
|
|
+ HoppRESTResponseHeaders,
|
|
|
+ V8_SCHEMA,
|
|
|
+ ValidCodes,
|
|
|
+} from "./8"
|
|
|
|
|
|
export const FormDataKeyValue = z
|
|
|
.object({
|
|
@@ -52,19 +59,78 @@ export const HoppRESTReqBody = z.union([
|
|
|
|
|
|
export type HoppRESTReqBody = z.infer<typeof HoppRESTReqBody>
|
|
|
|
|
|
+/**
|
|
|
+ * The original request that was made to get this response
|
|
|
+ * Only the necessary fields are saved
|
|
|
+ */
|
|
|
+export const HoppRESTResponseOriginalRequest = z.object({
|
|
|
+ v: z.literal("2"),
|
|
|
+ name: z.string(),
|
|
|
+ method: z.string(),
|
|
|
+ endpoint: z.string(),
|
|
|
+ headers: HoppRESTHeaders,
|
|
|
+ params: HoppRESTParams,
|
|
|
+ body: HoppRESTReqBody,
|
|
|
+ auth: HoppRESTAuth,
|
|
|
+ requestVariables: HoppRESTRequestVariables,
|
|
|
+})
|
|
|
+
|
|
|
+export type HoppRESTResponseOriginalRequest = z.infer<
|
|
|
+ typeof HoppRESTResponseOriginalRequest
|
|
|
+>
|
|
|
+
|
|
|
+export const HoppRESTRequestResponse = z.object({
|
|
|
+ name: z.string(),
|
|
|
+ originalRequest: HoppRESTResponseOriginalRequest,
|
|
|
+ status: z.string(),
|
|
|
+ code: z.optional(ValidCodes),
|
|
|
+ headers: HoppRESTResponseHeaders,
|
|
|
+ body: z.string(),
|
|
|
+})
|
|
|
+
|
|
|
+export type HoppRESTRequestResponse = z.infer<typeof HoppRESTRequestResponse>
|
|
|
+
|
|
|
+/**
|
|
|
+ * The responses saved for a request
|
|
|
+ * The key is the name of the response saved by the user
|
|
|
+ * The value is the response
|
|
|
+ */
|
|
|
+export const HoppRESTRequestResponses = z.record(
|
|
|
+ z.string(),
|
|
|
+ HoppRESTRequestResponse
|
|
|
+)
|
|
|
+
|
|
|
+export type HoppRESTRequestResponses = z.infer<typeof HoppRESTRequestResponses>
|
|
|
+
|
|
|
export const V9_SCHEMA = V8_SCHEMA.extend({
|
|
|
v: z.literal("9"),
|
|
|
body: HoppRESTReqBody,
|
|
|
+ responses: HoppRESTRequestResponses,
|
|
|
})
|
|
|
|
|
|
export default defineVersion({
|
|
|
schema: V9_SCHEMA,
|
|
|
initial: false,
|
|
|
up(old: z.infer<typeof V8_SCHEMA>) {
|
|
|
- // No migration, the new contentType added to each formdata field is optional
|
|
|
+ // update the version number of response original request
|
|
|
+ const responses = Object.fromEntries(
|
|
|
+ Object.entries(old.responses).map(([key, response]) => [
|
|
|
+ key,
|
|
|
+ {
|
|
|
+ ...response,
|
|
|
+ originalRequest: {
|
|
|
+ ...response.originalRequest,
|
|
|
+ v: "2" as const,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ])
|
|
|
+ )
|
|
|
+
|
|
|
+ // No migration for body, the new contentType added to each formdata field is optional
|
|
|
return {
|
|
|
...old,
|
|
|
v: "9" as const,
|
|
|
+ responses,
|
|
|
}
|
|
|
},
|
|
|
})
|