feat: introduce APIs to update envs from tests and recursive resolution

This commit is contained in:
Andrew Bastin
2022-02-19 02:20:28 +05:30
parent 3cb47d3812
commit 59c6e21636
20 changed files with 1392 additions and 168 deletions

View File

@@ -1,29 +1,19 @@
import { runPreRequestScript } from "@hoppscotch/js-sandbox"
import { Environment } from "@hoppscotch/data"
import {
getCurrentEnvironment,
getGlobalVariables,
} from "~/newstore/environments"
export const getCombinedEnvVariables = () => {
const variables: { key: string; value: string }[] = [...getGlobalVariables()]
for (const variable of getCurrentEnvironment().variables) {
const index = variables.findIndex((v) => variable.key === v.key)
if (index === -1) {
variables.push({
key: variable.key,
value: variable.value,
})
} else {
variables[index].value = variable.value
}
}
return variables
}
export const getCombinedEnvVariables = () => ({
global: getGlobalVariables(),
selected: getCurrentEnvironment().variables,
})
export const getFinalEnvsFromPreRequest = (
script: string,
envs: { key: string; value: string }[]
envs: {
global: Environment["variables"]
selected: Environment["variables"]
}
) => runPreRequestScript(script, envs)