windmill-ts 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/generator/flows.js +45 -19
- package/dist/src/generator/flows.js.map +1 -1
- package/dist/src/generator/preamble.js +0 -42
- package/dist/src/generator/preamble.js.map +1 -1
- package/dist/src/generator/scripts.js +45 -23
- package/dist/src/generator/scripts.js.map +1 -1
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -3,40 +3,66 @@ import { listFlows } from "../windmill/flows.js";
|
|
|
3
3
|
import { getContext } from "./context.js";
|
|
4
4
|
import { generateSchemas } from "./common.js";
|
|
5
5
|
const mapName = "flows";
|
|
6
|
-
const preamble = dedent `
|
|
7
|
-
export const runFlow = <Path extends keyof typeof ${mapName}>(
|
|
8
|
-
flowPath: Path,
|
|
9
|
-
args: z.input<(typeof ${mapName})[Path]>,
|
|
10
|
-
) => {
|
|
11
|
-
const schema = ${mapName}[flowPath];
|
|
12
|
-
|
|
13
|
-
return wmill.runFlow(flowPath, schema.parse(args));
|
|
14
|
-
};
|
|
15
|
-
|
|
6
|
+
const preamble = dedent `
|
|
16
7
|
type RunFlowAsyncOptions = {
|
|
17
8
|
scheduledFor?: Date | null;
|
|
18
9
|
detached?: boolean;
|
|
10
|
+
/** Override the worker tag for this run */
|
|
11
|
+
tag?: string;
|
|
19
12
|
};
|
|
20
13
|
|
|
21
|
-
|
|
14
|
+
type RunFlowOptions = RunFlowAsyncOptions & {
|
|
15
|
+
/** Log status messages while waiting for the job to complete */
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// NOTE: We use raw fetch here because JobService.runFlowByPath doesn't
|
|
20
|
+
// expose the root_job parameter, which is needed for proper job hierarchy tracking.
|
|
21
|
+
export const runFlowAsync = async <Path extends keyof typeof ${mapName}>(
|
|
22
22
|
flowPath: Path,
|
|
23
23
|
args: z.input<(typeof ${mapName})[Path]>,
|
|
24
24
|
options?: RunFlowAsyncOptions,
|
|
25
25
|
) => {
|
|
26
|
-
const { scheduledFor, detached =
|
|
26
|
+
const { scheduledFor, detached = true, tag } = options ?? {};
|
|
27
27
|
const schema = ${mapName}[flowPath];
|
|
28
28
|
|
|
29
|
-
const runner = detached
|
|
30
|
-
? runDetached
|
|
31
|
-
: <T extends unknown>(cb: () => Promise<T>) => cb();
|
|
32
|
-
|
|
33
29
|
const scheduledInSeconds = Math.ceil(
|
|
34
30
|
Math.max((scheduledFor?.getTime() ?? 0) - Date.now(), 0) / 1000,
|
|
35
31
|
);
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
33
|
+
const params: Record<string, string> = {};
|
|
34
|
+
if (scheduledInSeconds) params["scheduled_in_secs"] = String(scheduledInSeconds);
|
|
35
|
+
if (tag) params["tag"] = tag;
|
|
36
|
+
if (!detached) {
|
|
37
|
+
const parentJobId = process.env["WM_JOB_ID"];
|
|
38
|
+
if (parentJobId) params["parent_job"] = parentJobId;
|
|
39
|
+
const rootJobId = process.env["WM_ROOT_FLOW_JOB_ID"];
|
|
40
|
+
if (rootJobId) params["root_job"] = rootJobId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const url = new URL(\`\${wmill.OpenAPI.BASE}/w/\${process.env["WM_WORKSPACE"]}/jobs/run/f/\${flowPath}\`);
|
|
44
|
+
url.search = new URLSearchParams(params).toString();
|
|
45
|
+
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
"Authorization": \`Bearer \${wmill.OpenAPI.TOKEN}\`,
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(schema.parse(args)),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return response.text();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const runFlow = async <Path extends keyof typeof ${mapName}>(
|
|
59
|
+
flowPath: Path,
|
|
60
|
+
args: z.input<(typeof ${mapName})[Path]>,
|
|
61
|
+
options?: RunFlowOptions,
|
|
62
|
+
) => {
|
|
63
|
+
const { verbose, ...asyncOptions } = options ?? {};
|
|
64
|
+
const jobId = await runFlowAsync(flowPath, args, asyncOptions);
|
|
65
|
+
return wmill.waitJob(jobId, verbose);
|
|
40
66
|
};
|
|
41
67
|
|
|
42
68
|
export const getFlowArgsSchema = <Path extends keyof typeof ${mapName}>(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../src/generator/flows.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,QAAQ,GAAG,MAAM,CAAA
|
|
1
|
+
{"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../src/generator/flows.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,QAAQ,GAAG,MAAM,CAAA;;;;;;;;;;;;;;;iEAe0C,OAAO;;4BAE5C,OAAO;;;;qBAId,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4DA+BgC,OAAO;;4BAEvC,OAAO;;;;;;;;gEAQ6B,OAAO;;;aAG1D,OAAO;;;wCAGoB,OAAO;;kEAEmB,OAAO;CACxE,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;IACxD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAG,CAAC;IAExC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEtB,OAAO,eAAe,CAAC;QACrB,SAAS,EAAE,SAAS,EAAE;QACtB,OAAO;QACP,QAAQ;QACR,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS;KAClC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import dedent from "dedent";
|
|
2
2
|
import { getContext } from "./context.js";
|
|
3
|
-
export const envStorageName = "envStorage";
|
|
4
3
|
const preamble = dedent `
|
|
5
4
|
// This file is auto-generated by windmill-ts, do not modify it manually
|
|
6
5
|
import { z } from 'zod';
|
|
7
6
|
import * as wmill from 'windmill-client';
|
|
8
|
-
import type { AsyncLocalStorage } from 'node:async_hooks';
|
|
9
7
|
${
|
|
10
8
|
/* NOTE: Windmill has JSX enabled, so <T> is illegal.
|
|
11
9
|
The usual way to fix this is <T,>, but some formatters/editors
|
|
@@ -27,46 +25,6 @@ const preamble = dedent `
|
|
|
27
25
|
}
|
|
28
26
|
}) as T;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
let ${envStorageName}: AsyncLocalStorage<Record<string, string | undefined>> | null = null;
|
|
32
|
-
|
|
33
|
-
if (typeof process !== 'undefined') {
|
|
34
|
-
const { AsyncLocalStorage } = await import('node:async_hooks');
|
|
35
|
-
${envStorageName} = new AsyncLocalStorage();
|
|
36
|
-
|
|
37
|
-
const originalProcessEnv = process.env;
|
|
38
|
-
process.env = new Proxy(originalProcessEnv, {
|
|
39
|
-
get: (target, prop, receiver) => {
|
|
40
|
-
const store = ${envStorageName}!.getStore();
|
|
41
|
-
if (store != null && prop in store && typeof prop === 'string') {
|
|
42
|
-
return store[prop];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return Reflect.get(target, prop, receiver);
|
|
46
|
-
},
|
|
47
|
-
set: (target, prop, value, receiver) => {
|
|
48
|
-
if (typeof prop === 'string') {
|
|
49
|
-
target[prop] = value;
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return Reflect.set(target, prop, value, receiver);
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const runDetached = async <T extends unknown>(cb: () => Promise<T>) => {
|
|
59
|
-
if (${envStorageName} == null) {
|
|
60
|
-
console.warn("Calling \`runDetached\` in a non-Node environment is unsupported.");
|
|
61
|
-
|
|
62
|
-
return cb();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return ${envStorageName}.run(
|
|
66
|
-
{ WM_JOB_ID: undefined, WM_ROOT_FLOW_JOB_ID: undefined },
|
|
67
|
-
() => cb(),
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
28
|
`;
|
|
71
29
|
export const writePreamble = async () => {
|
|
72
30
|
const { write } = getContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preamble.js","sourceRoot":"","sources":["../../../src/generator/preamble.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,
|
|
1
|
+
{"version":3,"file":"preamble.js","sourceRoot":"","sources":["../../../src/generator/preamble.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,QAAQ,GAAG,MAAM,CAAA;;;;IAInB;AACA;;qEAEqE,CAAC,EACxE;;;;;;;;;;;;;;;;;;CAkBD,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;IACtC,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,EAAG,CAAC;IAEhC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;AACxB,CAAC,CAAC"}
|
|
@@ -3,44 +3,66 @@ import { listScripts } from "../windmill/scripts.js";
|
|
|
3
3
|
import { getContext } from "./context.js";
|
|
4
4
|
import { generateSchemas } from "./common.js";
|
|
5
5
|
const mapName = "scripts";
|
|
6
|
-
const preamble = dedent `
|
|
7
|
-
export const runScript = <Path extends keyof typeof ${mapName}>(
|
|
8
|
-
scriptPath: Path,
|
|
9
|
-
args: z.input<(typeof ${mapName})[Path]>,
|
|
10
|
-
) => {
|
|
11
|
-
const schema = ${mapName}[scriptPath];
|
|
12
|
-
|
|
13
|
-
return wmill.runScriptByPath(scriptPath, schema.parse(args));
|
|
14
|
-
};
|
|
15
|
-
|
|
6
|
+
const preamble = dedent `
|
|
16
7
|
type RunScriptAsyncOptions = {
|
|
17
8
|
scheduledFor?: Date | null;
|
|
18
9
|
detached?: boolean;
|
|
10
|
+
/** Override the worker tag for this run */
|
|
11
|
+
tag?: string;
|
|
19
12
|
};
|
|
20
13
|
|
|
21
|
-
|
|
14
|
+
type RunScriptOptions = RunScriptAsyncOptions & {
|
|
15
|
+
/** Log status messages while waiting for the job to complete */
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// NOTE: We use raw fetch here because JobService.runScriptByPath doesn't
|
|
20
|
+
// expose the root_job parameter, which is needed for proper job hierarchy tracking.
|
|
21
|
+
export const runScriptAsync = async <Path extends keyof typeof ${mapName}>(
|
|
22
22
|
scriptPath: Path,
|
|
23
23
|
args: z.input<(typeof ${mapName})[Path]>,
|
|
24
24
|
options?: RunScriptAsyncOptions,
|
|
25
25
|
) => {
|
|
26
|
-
const { scheduledFor, detached = false } = options ?? {};
|
|
26
|
+
const { scheduledFor, detached = false, tag } = options ?? {};
|
|
27
27
|
const schema = ${mapName}[scriptPath];
|
|
28
28
|
|
|
29
|
-
const runner = detached
|
|
30
|
-
? runDetached
|
|
31
|
-
: <T extends unknown>(cb: () => Promise<T>) => cb();
|
|
32
|
-
|
|
33
29
|
const scheduledInSeconds = Math.ceil(
|
|
34
30
|
Math.max((scheduledFor?.getTime() ?? 0) - Date.now(), 0) / 1000,
|
|
35
31
|
);
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
|
|
33
|
+
const params: Record<string, string> = {};
|
|
34
|
+
if (scheduledInSeconds) params["scheduled_in_secs"] = String(scheduledInSeconds);
|
|
35
|
+
if (tag) params["tag"] = tag;
|
|
36
|
+
if (!detached) {
|
|
37
|
+
const parentJobId = process.env["WM_JOB_ID"];
|
|
38
|
+
if (parentJobId) params["parent_job"] = parentJobId;
|
|
39
|
+
const rootJobId = process.env["WM_ROOT_FLOW_JOB_ID"];
|
|
40
|
+
if (rootJobId) params["root_job"] = rootJobId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const url = new URL(\`\${wmill.OpenAPI.BASE}/w/\${process.env["WM_WORKSPACE"]}/jobs/run/p/\${scriptPath}\`);
|
|
44
|
+
url.search = new URLSearchParams(params).toString();
|
|
45
|
+
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
"Authorization": \`Bearer \${wmill.OpenAPI.TOKEN}\`,
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(schema.parse(args)),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return response.text();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const runScript = async <Path extends keyof typeof ${mapName}>(
|
|
59
|
+
scriptPath: Path,
|
|
60
|
+
args: z.input<(typeof ${mapName})[Path]>,
|
|
61
|
+
options?: RunScriptOptions,
|
|
62
|
+
) => {
|
|
63
|
+
const { verbose, ...asyncOptions } = options ?? {};
|
|
64
|
+
const jobId = await runScriptAsync(scriptPath, args, asyncOptions);
|
|
65
|
+
return wmill.waitJob(jobId, verbose);
|
|
44
66
|
};
|
|
45
67
|
|
|
46
68
|
export const getScriptArgsSchema = <Path extends keyof typeof ${mapName}>(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/generator/scripts.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B,MAAM,QAAQ,GAAG,MAAM,CAAA
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/generator/scripts.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B,MAAM,QAAQ,GAAG,MAAM,CAAA;;;;;;;;;;;;;;;mEAe4C,OAAO;;4BAE9C,OAAO;;;;qBAId,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8DA+BkC,OAAO;;4BAEzC,OAAO;;;;;;;;kEAQ+B,OAAO;;;aAG5D,OAAO;;;0CAGsB,OAAO;;sEAEqB,OAAO;CAC5E,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;IAC1D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAG,CAAC;IAExC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEtB,OAAO,eAAe,CAAC;QACrB,SAAS,EAAE,WAAW,EAAE;QACxB,OAAO;QACP,QAAQ;QACR,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS;KACpC,CAAC,CAAC;AACL,CAAC,CAAC"}
|