windmill-ts 0.6.3 → 0.7.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
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import dedent from "dedent";
|
|
2
2
|
import { getContext } from "./context.js";
|
|
3
|
+
export const envStorageName = "envStorage";
|
|
3
4
|
const preamble = dedent `
|
|
4
5
|
// This file is auto-generated by windmill-ts, do not modify it manually
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
import * as wmill from 'windmill-client';
|
|
8
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
9
|
${
|
|
8
10
|
/* NOTE: Windmill has JSX enabled, so <T> is illegal.
|
|
9
11
|
The usual way to fix this is <T,>, but some formatters/editors
|
|
@@ -26,17 +28,28 @@ const preamble = dedent `
|
|
|
26
28
|
}) as T;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
const originalRootFlowJobId = process.env["WM_ROOT_FLOW_JOB_ID"];
|
|
31
|
-
delete (process.env as Record<string, string | undefined>)[
|
|
32
|
-
"WM_ROOT_FLOW_JOB_ID"
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const result = await cb();
|
|
31
|
+
const ${envStorageName} = new AsyncLocalStorage<Record<string, string | undefined>>();
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
const originalProcessEnv = process.env;
|
|
34
|
+
process.env = new Proxy(originalProcessEnv, {
|
|
35
|
+
get: (target, prop, receiver) => {
|
|
36
|
+
const store = ${envStorageName}.getStore();
|
|
37
|
+
if (store != null && prop in store && typeof prop === 'string') {
|
|
38
|
+
return store[prop];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return Reflect.get(target, prop, receiver);
|
|
42
|
+
},
|
|
43
|
+
set: (target, prop, value, receiver) => {
|
|
44
|
+
return Reflect.set(target, prop, value, receiver);
|
|
45
|
+
}
|
|
46
|
+
})
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
export const runDetached = async <T extends unknown>(cb: () => Promise<T>) => {
|
|
49
|
+
return ${envStorageName}.run(
|
|
50
|
+
{ WM_JOB_ID: undefined, WM_ROOT_FLOW_JOB_ID: undefined },
|
|
51
|
+
() => cb(),
|
|
52
|
+
);
|
|
40
53
|
};
|
|
41
54
|
`;
|
|
42
55
|
export const writePreamble = async () => {
|
|
@@ -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,QAAQ,GAAG,MAAM,CAAA
|
|
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,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C,MAAM,QAAQ,GAAG,MAAM,CAAA;;;;;IAKnB;AACA;;qEAEqE,CAAC,EACxE;;;;;;;;;;;;;;;;;;;UAmBQ,cAAc;;;;;sBAKF,cAAc;;;;;;;;;;;;;aAavB,cAAc;;;;;CAK1B,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"}
|
|
@@ -14,6 +14,7 @@ const preamble = dedent `
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
type RunScriptAsyncOptions = {
|
|
17
|
+
scheduledFor?: Date | null;
|
|
17
18
|
detached?: boolean;
|
|
18
19
|
};
|
|
19
20
|
|
|
@@ -22,14 +23,25 @@ const preamble = dedent `
|
|
|
22
23
|
args: z.input<(typeof ${mapName})[Path]>,
|
|
23
24
|
options?: RunScriptAsyncOptions,
|
|
24
25
|
) => {
|
|
25
|
-
const { detached = false } = options ?? {};
|
|
26
|
+
const { scheduledFor, detached = false } = options ?? {};
|
|
26
27
|
const schema = ${mapName}[scriptPath];
|
|
27
28
|
|
|
28
29
|
const runner = detached
|
|
29
30
|
? runDetached
|
|
30
31
|
: <T extends unknown>(cb: () => Promise<T>) => cb();
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
const scheduledInSeconds = Math.ceil(
|
|
34
|
+
Math.max((scheduledFor?.getTime() ?? 0) - Date.now(), 0) / 1000,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return runner(() =>
|
|
38
|
+
wmill.runScriptAsync(
|
|
39
|
+
scriptPath,
|
|
40
|
+
null,
|
|
41
|
+
schema.parse(args),
|
|
42
|
+
scheduledInSeconds,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
33
45
|
};
|
|
34
46
|
|
|
35
47
|
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;wDACiC,OAAO;;4BAEnC,OAAO;;qBAEd,OAAO
|
|
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;wDACiC,OAAO;;4BAEnC,OAAO;;qBAEd,OAAO;;;;;;;;;;6DAUiC,OAAO;;4BAExC,OAAO;;;;qBAId,OAAO;;;;;;;;;;;;;;;;;;;;kEAoBsC,OAAO;;;aAG5D,OAAO;;;0CAGsB,OAAO;CAChD,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;IAC1D,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,EAAG,CAAC;IAEhC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEtB,OAAO,eAAe,CAAC;QACrB,SAAS,EAAE,WAAW,EAAE;QACxB,OAAO;QACP,QAAQ;KACT,CAAC,CAAC;AACL,CAAC,CAAC"}
|