chore: lint + bump deps
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import { pipe } from "fp-ts/lib/function";
|
||||
import { chain, TaskEither, tryCatch, right, left } from "fp-ts/lib/TaskEither";
|
||||
import * as qjs from "quickjs-emscripten";
|
||||
import clone from "lodash/clone";
|
||||
import { pipe } from "fp-ts/lib/function"
|
||||
import { chain, TaskEither, tryCatch, right, left } from "fp-ts/lib/TaskEither"
|
||||
import * as qjs from "quickjs-emscripten"
|
||||
import clone from "lodash/clone"
|
||||
|
||||
type EnvEntry = {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
key: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export const execPreRequestScript = (
|
||||
preRequestScript: string,
|
||||
env: EnvEntry[]
|
||||
): TaskEither<string, EnvEntry[]> => pipe(
|
||||
tryCatch(
|
||||
async () => await qjs.getQuickJS(),
|
||||
(reason) => `QuickJS initialization failed: ${reason}`
|
||||
),
|
||||
chain(
|
||||
(QuickJS) => {
|
||||
): TaskEither<string, EnvEntry[]> =>
|
||||
pipe(
|
||||
tryCatch(
|
||||
async () => await qjs.getQuickJS(),
|
||||
(reason) => `QuickJS initialization failed: ${reason}`
|
||||
),
|
||||
chain((QuickJS) => {
|
||||
const finalEnv = clone(env)
|
||||
|
||||
const vm = QuickJS.createVm()
|
||||
@@ -26,30 +26,35 @@ export const execPreRequestScript = (
|
||||
|
||||
const envHandle = vm.newObject()
|
||||
|
||||
const envSetFuncHandle = vm.newFunction("set", (keyHandle, valueHandle) => {
|
||||
const key = vm.dump(keyHandle)
|
||||
const value = vm.dump(valueHandle)
|
||||
const envSetFuncHandle = vm.newFunction(
|
||||
"set",
|
||||
(keyHandle, valueHandle) => {
|
||||
const key = vm.dump(keyHandle)
|
||||
const value = vm.dump(valueHandle)
|
||||
|
||||
if (typeof key !== "string") return {
|
||||
error: vm.newString("Expected key to be a string")
|
||||
if (typeof key !== "string")
|
||||
return {
|
||||
error: vm.newString("Expected key to be a string"),
|
||||
}
|
||||
|
||||
if (typeof value !== "string")
|
||||
return {
|
||||
error: vm.newString("Expected value to be a string"),
|
||||
}
|
||||
|
||||
const keyIndex = finalEnv.findIndex((env) => env.key === key)
|
||||
|
||||
if (keyIndex === -1) {
|
||||
finalEnv.push({ key, value })
|
||||
} else {
|
||||
finalEnv[keyIndex] = { key, value }
|
||||
}
|
||||
|
||||
return {
|
||||
value: vm.undefined,
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof value !== "string") return {
|
||||
error: vm.newString("Expected value to be a string")
|
||||
}
|
||||
|
||||
const keyIndex = finalEnv.findIndex((env) => env.key === key)
|
||||
|
||||
if (keyIndex === -1) {
|
||||
finalEnv.push({ key, value })
|
||||
} else {
|
||||
finalEnv[keyIndex] = { key, value }
|
||||
}
|
||||
|
||||
return {
|
||||
value: vm.undefined
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
vm.setProp(envHandle, "set", envSetFuncHandle)
|
||||
envSetFuncHandle.dispose()
|
||||
@@ -72,6 +77,5 @@ export const execPreRequestScript = (
|
||||
vm.dispose()
|
||||
|
||||
return right(finalEnv)
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user