From 21d8b8fb2e272bc2e1a97b233c1eeb24e5d96434 Mon Sep 17 00:00:00 2001 From: Jason Casareno Date: Wed, 3 Aug 2022 17:04:13 -0700 Subject: [PATCH] Added TODO Comments + File Deletion --- .../components/http/Parameters.vue | 6 +- packages/hoppscotch-data/src/environment.ts | 3 + packages/hoppscotch-data/src/variables.ts | 78 ------------------- 3 files changed, 8 insertions(+), 79 deletions(-) delete mode 100644 packages/hoppscotch-data/src/variables.ts diff --git a/packages/hoppscotch-app/components/http/Parameters.vue b/packages/hoppscotch-app/components/http/Parameters.vue index 31c887c92..6a0be351c 100644 --- a/packages/hoppscotch-app/components/http/Parameters.vue +++ b/packages/hoppscotch-app/components/http/Parameters.vue @@ -6,4 +6,8 @@ - + diff --git a/packages/hoppscotch-data/src/environment.ts b/packages/hoppscotch-data/src/environment.ts index 15804de3b..c3cc2242c 100644 --- a/packages/hoppscotch-data/src/environment.ts +++ b/packages/hoppscotch-data/src/environment.ts @@ -85,6 +85,9 @@ export function parseTemplateStringE( depth++ } + /** + * TODO: Create an error statement for variables + */ while (result.match(REGEX_MY_VAR) != null && errorBound <= ENV_MAX_EXPAND_LIMIT) { result = decodeURI(encodeURI(result)).replace( REGEX_MY_VAR, diff --git a/packages/hoppscotch-data/src/variables.ts b/packages/hoppscotch-data/src/variables.ts deleted file mode 100644 index 8b217d300..000000000 --- a/packages/hoppscotch-data/src/variables.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { pipe } from "fp-ts/function" -import * as E from "fp-ts/Either" -import {parseTemplateStringE} from "./environment"; - -export type Environment = { - name: string - variables: { - key: string - value: string - }[] -} - -export type Variables = { - key: string - value: string -}[] - -const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<>" -const REGEX_MY_VAR = /{{([^}]*)}}/g // "{{myVariable}}" - -/** - * How much times can we expand environment variables - */ -const ENV_MAX_EXPAND_LIMIT = 10 - -/** - * Error state when there is a suspected loop while - * recursively expanding variables - */ -const ENV_EXPAND_LOOP = "ENV_EXPAND_LOOP" as const - -export function parseTemplateStringEV( - str: string, - variables: Environment["variables"], - myVariables: Variables -) { - if (!variables || !str || !myVariables) { - return E.right(str) - } - - let result = str - let depth = 0 - let errorBound = 0 - - while (result.match(REGEX_ENV_VAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) { - result = decodeURI(encodeURI(result)).replace( - REGEX_ENV_VAR, - (_, p1) => variables.find((x) => x.key === p1)?.value || "" - ) - depth++ - } - - /** - * TODO: Create an error statement for variables - */ - while (result.match(REGEX_MY_VAR) != null && errorBound <= ENV_MAX_EXPAND_LIMIT) { - result = decodeURI(encodeURI(result)).replace( - REGEX_MY_VAR, - (_, p1) => myVariables.find((x) => x.key === p1)?.value || "" - ) - errorBound++ - } - - return depth <= ENV_MAX_EXPAND_LIMIT && errorBound <= ENV_MAX_EXPAND_LIMIT ? E.right(result) : E.left(ENV_EXPAND_LOOP); -} - -/** - * @deprecated Use `parseTemplateStringEV` instead - */ -export const parseTemplateStringV = ( - str: string, - variables: Environment["variables"], - myVariables: Variables -) => - pipe( - parseTemplateStringEV(str, variables, myVariables), - E.getOrElse(() => str) - )