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

View File

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

View File

@@ -29,6 +29,7 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
effectiveFinalHeaders: { key: string; value: string }[] effectiveFinalHeaders: { key: string; value: string }[]
effectiveFinalParams: { key: string; value: string }[] effectiveFinalParams: { key: string; value: string }[]
effectiveFinalBody: FormData | string | null 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) const effectiveFinalBody = getFinalBodyFromRequest(request, envVariables)
return { return {
...request, ...request,
effectiveFinalURL: parseTemplateString(request.endpoint, envVariables), effectiveFinalURL: parseTemplateString(
request.endpoint,
envVariables,
request.vars
),
effectiveFinalHeaders, effectiveFinalHeaders,
effectiveFinalParams, effectiveFinalParams,
effectiveFinalBody, 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_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>"
const REGEX_PATH_VAR = /{{([^>]*)}}/g // "{{myVariable}}"
/** /**
* How much times can we expand environment variables * How much times can we expand environment variables