Remove vm2 wrapper
This commit is contained in:
parent
40aff20af9
commit
b9afe1b926
|
@ -1,3 +1,2 @@
|
|||
export * from "./isolated-vm"
|
||||
export * from "./builtin-vm"
|
||||
export * from "./vm2"
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import vm2 from "vm2"
|
||||
import { VM } from "@budibase/types"
|
||||
|
||||
const JS_TIMEOUT_MS = 1000
|
||||
|
||||
export class VM2 implements VM {
|
||||
vm: vm2.VM
|
||||
results: { out: string }
|
||||
|
||||
constructor() {
|
||||
this.vm = new vm2.VM({
|
||||
timeout: JS_TIMEOUT_MS,
|
||||
})
|
||||
this.results = { out: "" }
|
||||
this.vm.setGlobal("fetch", fetch)
|
||||
this.vm.setGlobal("results", this.results)
|
||||
}
|
||||
|
||||
withContext<T>(context: Record<string, any>, executeWithContext: () => T): T {
|
||||
this.vm.setGlobals(context)
|
||||
try {
|
||||
return executeWithContext()
|
||||
} finally {
|
||||
for (const key in context) {
|
||||
this.vm.setGlobal(key, undefined)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
execute(script: string) {
|
||||
const code = `let fn = () => {\n${script}\n}; results.out = fn();`
|
||||
const vmScript = new vm2.VMScript(code)
|
||||
this.vm.run(vmScript)
|
||||
return this.results.out
|
||||
}
|
||||
}
|
|
@ -7,20 +7,18 @@ import {
|
|||
QueryVariable,
|
||||
QueryResponse,
|
||||
} from "./definitions"
|
||||
import { IsolatedVM, VM2 } from "../jsRunner/vm"
|
||||
import { IsolatedVM } from "../jsRunner/vm"
|
||||
import { getIntegration } from "../integrations"
|
||||
import { processStringSync } from "@budibase/string-templates"
|
||||
import { context, cache, auth } from "@budibase/backend-core"
|
||||
import { getGlobalIDFromUserMetadataID } from "../db/utils"
|
||||
import sdk from "../sdk"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import { Datasource, Query, SourceName, VM } from "@budibase/types"
|
||||
import { Datasource, Query, SourceName } from "@budibase/types"
|
||||
|
||||
import { isSQL } from "../integrations/utils"
|
||||
import { interpolateSQL } from "../integrations/queries/sql"
|
||||
|
||||
const USE_ISOLATED_VM = true
|
||||
|
||||
class QueryRunner {
|
||||
datasource: Datasource
|
||||
queryVerb: string
|
||||
|
@ -129,23 +127,17 @@ class QueryRunner {
|
|||
|
||||
// transform as required
|
||||
if (transformer) {
|
||||
let runner: VM
|
||||
if (!USE_ISOLATED_VM) {
|
||||
runner = new VM2()
|
||||
} else {
|
||||
transformer = `(function(){\n${transformer}\n})();`
|
||||
let vm = new IsolatedVM()
|
||||
if (datasource.source === SourceName.MONGODB) {
|
||||
vm = vm.withParsingBson(rows)
|
||||
}
|
||||
runner = vm
|
||||
transformer = `(function(){\n${transformer}\n})();`
|
||||
let vm = new IsolatedVM()
|
||||
if (datasource.source === SourceName.MONGODB) {
|
||||
vm = vm.withParsingBson(rows)
|
||||
}
|
||||
|
||||
const ctx = {
|
||||
data: rows,
|
||||
params: enrichedParameters,
|
||||
}
|
||||
rows = runner.withContext(ctx, () => runner.execute(transformer))
|
||||
rows = vm.withContext(ctx, () => vm.execute(transformer))
|
||||
}
|
||||
|
||||
// if the request fails we retry once, invalidating the cached value
|
||||
|
|
Loading…
Reference in New Issue