Fixing final endpoint url (WIP)

This commit is contained in:
Jason Casareno
2022-07-29 16:06:20 -07:00
parent c9c5df36ab
commit d22bae2c60
4 changed files with 20 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ import { HoppReactiveEnvPlugin } from "~/helpers/editor/extensions/HoppEnvironme
import { useReadonlyStream } from "~/helpers/utils/composables"
import { AggregateEnvironment, aggregateEnvs$ } from "~/newstore/environments"
import { HoppReactiveVarPlugin } from "~/helpers/editor/extensions/HoppVariable"
import { restVars$ } from "~/newstore/RESTSession"
const props = withDefaults(
defineProps<{
@@ -114,6 +115,8 @@ const aggregateEnvs = useReadonlyStream(aggregateEnvs$, []) as Ref<
AggregateEnvironment[]
>
const aggregateVars = useReadonlyStream(restVars$, []) as Ref<HoppRESTVar[]>
const envVars = computed(() =>
props.envs
? props.envs.map((x) => ({
@@ -130,7 +133,7 @@ const varVars = computed(() =>
key: x.key,
value: x.value,
}))
: ([{ key: "size", value: "500" }] as HoppRESTVar[])
: aggregateVars.value
)
const envTooltipPlugin = new HoppReactiveEnvPlugin(envVars, view)

View File

@@ -77,6 +77,7 @@ export const runRESTRequest$ = (): TaskEither<
name: "Env",
variables: combineEnvVariables(envs),
})
console.log("effectiveRequest", effectiveRequest)
const stream = createRESTNetworkRequestStream(effectiveRequest)

View File

@@ -29,6 +29,7 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
effectiveFinalHeaders: { key: string; value: string }[]
effectiveFinalParams: { key: string; value: string }[]
effectiveFinalBody: FormData | string | null
effectiveFinalVars: { key: string; value: string }[]
}
/**
@@ -299,14 +300,21 @@ export function getEffectiveRESTRequest(
}))
)
const effectiveFinalVars = request.vars
const effectiveFinalBody = getFinalBodyFromRequest(request, envVariables)
return {
...request,
effectiveFinalURL: parseTemplateString(request.endpoint, envVariables),
effectiveFinalURL: parseTemplateString(
request.endpoint,
envVariables,
request.vars
),
effectiveFinalHeaders,
effectiveFinalParams,
effectiveFinalBody,
effectiveFinalVars,
}
}

View File

@@ -9,7 +9,13 @@ export type Environment = {
}[]
}
export type Variables = {
key: string
value: string
}[]
const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>"
const REGEX_PATH_VAR = /{{([^>]*)}}/g // "{{myVariable}}"
/**
* How much times can we expand environment variables