Windmill-1.ts
· 934 B · TypeScript
Raw
//import any dependency from npm
import * as wmill from "windmill-client"
import * as cowsay from 'cowsay@1.5.0';
// fill the type, or use the +Resource type to get a type-safe reference to a resource
type Postgresql = {
host: string;
port: number;
user: string;
dbname: string;
sslmode: string;
password: string;
};
export async function main(
a: number,
b: "my" | "enum",
c: Postgresql,
d = "inferred type string from default arg",
e = { nested: "object" }
//f: wmill.Base64
) {
const email = process.env["WM_EMAIL"];
// variables are permissioned and by path
let variable = await wmill.getVariable("f/company-folder/my_secret");
const lastTimeRun = await wmill.getState();
// logs are printed and always inspectable
console.log(cowsay.say({ text: "hello " + email + " " + lastTimeRun }));
await wmill.setState(Date.now());
// return is serialized as JSON
return { foo: d, variable };
}
1 | //import any dependency from npm |
2 | import * as wmill from "windmill-client" |
3 | import * as cowsay from 'cowsay@1.5.0'; |
4 | |
5 | // fill the type, or use the +Resource type to get a type-safe reference to a resource |
6 | type Postgresql = { |
7 | host: string; |
8 | port: number; |
9 | user: string; |
10 | dbname: string; |
11 | sslmode: string; |
12 | password: string; |
13 | }; |
14 | |
15 | export async function main( |
16 | a: number, |
17 | b: "my" | "enum", |
18 | c: Postgresql, |
19 | d = "inferred type string from default arg", |
20 | e = { nested: "object" } |
21 | //f: wmill.Base64 |
22 | ) { |
23 | const email = process.env["WM_EMAIL"]; |
24 | // variables are permissioned and by path |
25 | let variable = await wmill.getVariable("f/company-folder/my_secret"); |
26 | const lastTimeRun = await wmill.getState(); |
27 | // logs are printed and always inspectable |
28 | console.log(cowsay.say({ text: "hello " + email + " " + lastTimeRun })); |
29 | await wmill.setState(Date.now()); |
30 | |
31 | // return is serialized as JSON |
32 | return { foo: d, variable }; |
33 | } |