diff --git a/packages/server/src/jsRunner/vm/index.ts b/packages/server/src/jsRunner/vm/index.ts index 01e0daa354..cc50a5eeaa 100644 --- a/packages/server/src/jsRunner/vm/index.ts +++ b/packages/server/src/jsRunner/vm/index.ts @@ -1,3 +1,2 @@ export * from "./isolated-vm" export * from "./builtin-vm" -export * from "./vm2" diff --git a/packages/server/src/jsRunner/vm/vm2.ts b/packages/server/src/jsRunner/vm/vm2.ts deleted file mode 100644 index 5825025d26..0000000000 --- a/packages/server/src/jsRunner/vm/vm2.ts +++ /dev/null @@ -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(context: Record, 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 - } -} diff --git a/packages/server/src/threads/query.ts b/packages/server/src/threads/query.ts index 6cc07c1256..9366f2b12c 100644 --- a/packages/server/src/threads/query.ts +++ b/packages/server/src/threads/query.ts @@ -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