From dfdd44b4ed587b2a6206546ce2b5b375c5cc6a27 Mon Sep 17 00:00:00 2001 From: James George Date: Thu, 15 Feb 2024 21:40:31 +0530 Subject: [PATCH] fix(persistence-service): update global environment variables schema (#3829) --- .../src/services/persistence/index.ts | 4 +- .../persistence/validation-schemas/index.ts | 48 +++++++------------ 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/packages/hoppscotch-common/src/services/persistence/index.ts b/packages/hoppscotch-common/src/services/persistence/index.ts index 84d318476..74291bebb 100644 --- a/packages/hoppscotch-common/src/services/persistence/index.ts +++ b/packages/hoppscotch-common/src/services/persistence/index.ts @@ -628,7 +628,7 @@ export class PersistenceService extends Service { private setupGlobalEnvsPersistence() { const globalEnvKey = "globalEnv" - let globalEnvData: Environment["variables"] = JSON.parse( + let globalEnvData: z.infer = JSON.parse( window.localStorage.getItem(globalEnvKey) || "[]" ) @@ -644,7 +644,7 @@ export class PersistenceService extends Service { ) } - setGlobalEnvVariables(globalEnvData) + setGlobalEnvVariables(globalEnvData as Environment["variables"]) globalEnv$.subscribe((vars) => { window.localStorage.setItem(globalEnvKey, JSON.stringify(vars)) diff --git a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts index b5854403d..b6ac61ac5 100644 --- a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts +++ b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts @@ -229,24 +229,24 @@ export const MQTT_REQUEST_SCHEMA = z.nullable( .strict() ) -export const GLOBAL_ENV_SCHEMA = z.union([ - z.array(z.never()), - - z.array( - z.union([ - z.object({ - key: z.string(), - secret: z.literal(true), - }), - z.object({ - key: z.string(), - value: z.string(), - secret: z.literal(false), - }), - ]) - ), +const EnvironmentVariablesSchema = z.union([ + z.object({ + key: z.string(), + value: z.string(), + secret: z.literal(false), + }), + z.object({ + key: z.string(), + secret: z.literal(true), + }), + z.object({ + key: z.string(), + value: z.string(), + }), ]) +export const GLOBAL_ENV_SCHEMA = z.array(EnvironmentVariablesSchema) + const OperationTypeSchema = z.enum([ "subscription", "query", @@ -364,22 +364,6 @@ const HoppTestDataSchema = z.lazy(() => .strict() ) -const EnvironmentVariablesSchema = z.union([ - z.object({ - key: z.string(), - value: z.string(), - secret: z.literal(false), - }), - z.object({ - key: z.string(), - secret: z.literal(true), - }), - z.object({ - key: z.string(), - value: z.string(), - }), -]) - export const SECRET_ENVIRONMENT_VARIABLE_SCHEMA = z.union([ z.object({}).strict(),