0

Run Code

by
Published today

Run code that is not deployed, in any Windmill language, and return its result. It runs as the flow's user, with the given args.

Script windmill Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
import * as wmill from "windmill-client"
4

5
// windmill-client errors only carry the status text: throw the response body, which says why
6
wmill.OpenAPI.interceptors.response.use(async (response) => {
7
  if (!response.ok) {
8
    throw new Error(`${response.status} ${await response.text()}`)
9
  }
10
  return response
11
})
12

13
/**
14
 * Run Code
15
 * Run code that is not deployed, in any Windmill language, and return its result. It runs as the flow's user, with the given args.
16
 */
17
export async function main(
18
  language:
19
    | "bun"
20
    | "python3"
21
    | "deno"
22
    | "go"
23
    | "bash"
24
    | "powershell"
25
    | "postgresql"
26
    | "mysql"
27
    | "bigquery"
28
    | "snowflake"
29
    | "mssql"
30
    | "oracledb"
31
    | "graphql"
32
    | "nativets"
33
    | "bunnative"
34
    | "php"
35
    | "rust"
36
    | "ansible"
37
    | "csharp"
38
    | "nu"
39
    | "java"
40
    | "ruby"
41
    | "rlang"
42
    | "duckdb",
43
  content: string,
44
  args: { [key: string]: any } | undefined
45
) {
46
  return await wmill.JobService.runScriptPreviewAndWaitResult({
47
    workspace: wmill.getWorkspace(),
48
    requestBody: { language, content, args: args ?? {} },
49
  })
50
}
51