workflow 2.0.6 → 4.0.1-beta.1
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/LICENSE.md +21 -0
- package/README.md +53 -0
- package/bin/run.js +3 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/builtins.d.ts +9 -0
- package/dist/internal/builtins.d.ts.map +1 -0
- package/dist/internal/builtins.js +18 -0
- package/dist/internal/builtins.js.map +1 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +2 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/observability.d.ts +6 -0
- package/dist/internal/observability.d.ts.map +1 -0
- package/dist/internal/observability.js +6 -0
- package/dist/internal/observability.js.map +1 -0
- package/dist/internal/private.d.ts +6 -0
- package/dist/internal/private.d.ts.map +1 -0
- package/dist/internal/private.js +6 -0
- package/dist/internal/private.js.map +1 -0
- package/dist/internal/serialization.d.ts +2 -0
- package/dist/internal/serialization.d.ts.map +1 -0
- package/dist/internal/serialization.js +2 -0
- package/dist/internal/serialization.js.map +1 -0
- package/dist/next.d.ts +2 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +2 -0
- package/dist/next.js.map +1 -0
- package/dist/nitro.d.ts +4 -0
- package/dist/nitro.d.ts.map +1 -0
- package/dist/nitro.js +4 -0
- package/dist/nitro.js.map +1 -0
- package/dist/rollup-plugin.d.ts +2 -0
- package/dist/rollup-plugin.d.ts.map +1 -0
- package/dist/rollup-plugin.js +2 -0
- package/dist/rollup-plugin.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -0
- package/dist/stdlib.d.ts +35 -0
- package/dist/stdlib.d.ts.map +1 -0
- package/dist/stdlib.js +47 -0
- package/dist/stdlib.js.map +1 -0
- package/dist/workflow.d.ts +3 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +3 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +59 -31
- package/CHANGELOG.md +0 -160
- package/Readme.md +0 -4
- package/cli.js +0 -15
- package/dist/cli.js +0 -210
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vercel, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://useworkflow.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://useworkflow.dev/workflow-circle-symbol-dark.svg">
|
|
5
|
+
<img alt="Workflow DevKit logo" src="https://useworkflow.dev/workflow-circle-symbol-light.svg" height="128">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
<h1>Workflow Development Kit</h1>
|
|
9
|
+
|
|
10
|
+
<a href="https://vercel.com"><img alt="Vercel logo" src="https://img.shields.io/badge/MADE%20BY%20Vercel-000000.svg?style=for-the-badge&logo=Vercel&labelColor=000"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/next"><img alt="NPM version" src="https://img.shields.io/npm/v/workflow?style=for-the-badge&labelColor=000000"></a>
|
|
12
|
+
<a href="https://github.com/vercel/workflow/blob/canary/license.md"><img alt="License" src="https://img.shields.io/npm/l/workflow.svg?style=for-the-badge&labelColor=000000"></a>
|
|
13
|
+
<a href="https://github.com/vercel/workflow/discussions"><img alt="Join the community on GitHub" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=Github&labelColor=000000&logoWidth=20"></a>
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
The **Workflow Development Kit** lets you easily add durability, reliability, and observability to async JavaScript. Build apps and AI Agents that can suspend, resume, and maintain state with ease.
|
|
20
|
+
|
|
21
|
+
Visit [https://useworkflow.dev](https://useworkflow.dev) to view the full documentation.
|
|
22
|
+
|
|
23
|
+
## Community
|
|
24
|
+
|
|
25
|
+
The Workflow DevKit community can be found on [GitHub Discussions](https://github.com/vercel/workflow/discussions) where you can ask questions, voice ideas, and share your projects with other people.
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
|
|
29
|
+
Contributions to Workflow DevKit are welcome and highly appreciated. Please use GitHub [issues](https://github.com/vercel/workflow/issues) and [discussions](https://github.com/vercel/workflow/discussions) to collaborate with the team and the wider community.
|
|
30
|
+
|
|
31
|
+
## Authors
|
|
32
|
+
|
|
33
|
+
Workflow DevKit was built by engineers at [Vercel](https://vercel.com) and the [Open Source Community](https://github.com/vercel/workflow/graphs/contributors).
|
|
34
|
+
|
|
35
|
+
The initial core contributing engineers are
|
|
36
|
+
|
|
37
|
+
- Adrian Lam ([@adriandlam](https://github.com/adriandlam))
|
|
38
|
+
- Dillon Mulroy ([@dmmulroy](https://github.com/dmmulroy))
|
|
39
|
+
- Gal Schlezinger ([@Schniz](https://github.com/Schniz))
|
|
40
|
+
- JJ Kasper ([@ijjk](https://github.com/ijjk))
|
|
41
|
+
- Nathan Rajlich ([@TooTallNate](https://github.com/TooTallNate))
|
|
42
|
+
- Peter Wielander ([@VaguelySerious](https://github.com/VaguelySerious))
|
|
43
|
+
- Pranay Prakash ([@pranaygp](https://github.com/pranaygp))
|
|
44
|
+
|
|
45
|
+
The Workflow DevKit Logo was designed by Cecilio Ruiz [@ceciliorz](https://x.com/ceciliorz)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Security
|
|
50
|
+
|
|
51
|
+
If you believe you have found a security vulnerability in Workflow DevKit, we encourage you to **_responsibly disclose this and NOT open a public issue_**.
|
|
52
|
+
|
|
53
|
+
To participate in our Open Source Software Bug Bounty program, please email [responsible.disclosure@vercel.com](mailto:responsible.disclosure@vercel.com). We will add you to the program and provide further instructions for submitting your report.
|
package/bin/run.js
ADDED
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,cAAc,EACd,MAAM,EACN,GAAG,EACH,UAAU,EACV,aAAa,EACb,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,EACL,KAAK,WAAW,GACjB,MAAM,wBAAwB,CAAC"}
|
package/dist/api.js
ADDED
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,MAAM,EACN,GAAG,EACH,UAAU,EACV,aAAa,EACb,OAAO,EAEP,KAAK,GAEN,MAAM,wBAAwB,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// CommonJS wrapper for dual SDK/TypeScript plugin functionality
|
|
3
|
+
// Allows workflow to work as both:
|
|
4
|
+
// 1. An SDK: import { ... } from 'workflow'
|
|
5
|
+
// 2. A TypeScript Language Service plugin
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const node_module_1 = require("node:module");
|
|
8
|
+
const requireFromHere = (0, node_module_1.createRequire)(__filename);
|
|
9
|
+
const sdk = requireFromHere('./index.js');
|
|
10
|
+
function createTSPlugin(options) {
|
|
11
|
+
// The package is being used as a TypeScript Language Service plugin
|
|
12
|
+
if (options &&
|
|
13
|
+
'typescript' in options &&
|
|
14
|
+
typeof options.typescript === 'object') {
|
|
15
|
+
const pluginInit = requireFromHere('@workflow/typescript-plugin');
|
|
16
|
+
return pluginInit(options);
|
|
17
|
+
}
|
|
18
|
+
// Not being used as a TS plugin
|
|
19
|
+
throw new Error('workflow should be imported using named exports, not called as a function.\nUse: import { ... } from "workflow"');
|
|
20
|
+
}
|
|
21
|
+
// Export all named exports from the SDK
|
|
22
|
+
Object.keys(sdk).forEach((key) => {
|
|
23
|
+
createTSPlugin[key] = sdk[key];
|
|
24
|
+
});
|
|
25
|
+
module.exports = createTSPlugin;
|
|
26
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,mCAAmC;AACnC,4CAA4C;AAC5C,0CAA0C;;AAE1C,6CAA4C;AAC5C,MAAM,eAAe,GAAG,IAAA,2BAAa,EAAC,UAAU,CAAC,CAAC;AAElD,MAAM,GAAG,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;AAE1C,SAAS,cAAc,CAAC,OAAY;IAClC,oEAAoE;IACpE,IACE,OAAO;QACP,YAAY,IAAI,OAAO;QACvB,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,EACtC,CAAC;QACD,MAAM,UAAU,GAAG,eAAe,CAAC,6BAA6B,CAAC,CAAC;QAClE,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,gCAAgC;IAChC,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;AACJ,CAAC;AAED,wCAAwC;AACxC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;IAC9B,cAAsB,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These are the built-in steps that are "automatically available" in the workflow scope. They are
|
|
3
|
+
* similar to "stdlib" except that are not meant to be imported by users, but are instead "just available"
|
|
4
|
+
* alongside user defined steps. They are used internally by the runtime
|
|
5
|
+
*/
|
|
6
|
+
export declare function __builtin_response_array_buffer(res: Response): Promise<ArrayBuffer>;
|
|
7
|
+
export declare function __builtin_response_json(res: Response): Promise<unknown>;
|
|
8
|
+
export declare function __builtin_response_text(res: Response): Promise<string>;
|
|
9
|
+
//# sourceMappingURL=builtins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../src/internal/builtins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,QAAQ,wBAGlE;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,QAAQ,oBAG1D;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,QAAQ,mBAG1D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These are the built-in steps that are "automatically available" in the workflow scope. They are
|
|
3
|
+
* similar to "stdlib" except that are not meant to be imported by users, but are instead "just available"
|
|
4
|
+
* alongside user defined steps. They are used internally by the runtime
|
|
5
|
+
*/
|
|
6
|
+
export async function __builtin_response_array_buffer(res) {
|
|
7
|
+
'use step';
|
|
8
|
+
return res.arrayBuffer();
|
|
9
|
+
}
|
|
10
|
+
export async function __builtin_response_json(res) {
|
|
11
|
+
'use step';
|
|
12
|
+
return res.json();
|
|
13
|
+
}
|
|
14
|
+
export async function __builtin_response_text(res) {
|
|
15
|
+
'use step';
|
|
16
|
+
return res.text();
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=builtins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtins.js","sourceRoot":"","sources":["../../src/internal/builtins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,GAAa;IACjE,UAAU,CAAC;IACX,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,GAAa;IACzD,UAAU,CAAC;IACX,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,GAAa;IACzD,UAAU,CAAC;IACX,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../../src/internal/observability.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observability.js","sourceRoot":"","sources":["../../src/internal/observability.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private.d.ts","sourceRoot":"","sources":["../../src/internal/private.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private.js","sourceRoot":"","sources":["../../src/internal/private.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../src/internal/serialization.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../src/internal/serialization.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/next.js
ADDED
package/dist/next.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.js","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/nitro.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro.d.ts","sourceRoot":"","sources":["../src/nitro.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,cAAc,iBAAiB,CAAC;AAChC,eAAe,aAAa,CAAC"}
|
package/dist/nitro.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro.js","sourceRoot":"","sources":["../src/nitro.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,cAAc,iBAAiB,CAAC;AAChC,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin.d.ts","sourceRoot":"","sources":["../src/rollup-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin.js","sourceRoot":"","sources":["../src/rollup-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC"}
|
package/dist/stdlib.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the "standard library" of steps that we make available to all workflow users.
|
|
3
|
+
* The can be imported like so: `import { sleep, fetch } from 'workflow'`. and used in workflow.
|
|
4
|
+
* The need to be exported directly in this package and cannot live in `core` to prevent
|
|
5
|
+
* circular dependencies post-compilation.
|
|
6
|
+
*/
|
|
7
|
+
import { type StringValue } from 'ms';
|
|
8
|
+
/**
|
|
9
|
+
* Sleep within a workflow for a given duration.
|
|
10
|
+
*
|
|
11
|
+
* @param duration - The duration to sleep for, this is a string in the format
|
|
12
|
+
* of `"1000ms"`, `"1s"`, `"1m"`, `"1h"`, or `"1d"`.
|
|
13
|
+
* @overload
|
|
14
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sleep(duration: StringValue): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Sleep within a workflow until a specific date.
|
|
19
|
+
*
|
|
20
|
+
* @param date - The date to sleep until, this must be a future date.
|
|
21
|
+
* @overload
|
|
22
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
23
|
+
*/
|
|
24
|
+
export declare function sleep(date: Date): Promise<void>;
|
|
25
|
+
export declare namespace sleep {
|
|
26
|
+
var maxRetries: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A hoisted `fetch()` function that is executed as a "step" function,
|
|
30
|
+
* for use within workflow functions.
|
|
31
|
+
*
|
|
32
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
|
33
|
+
*/
|
|
34
|
+
export declare function fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response>;
|
|
35
|
+
//# sourceMappingURL=stdlib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdlib.d.ts","sourceRoot":"","sources":["../src/stdlib.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAW,EAAE,KAAK,WAAW,EAAE,MAAM,IAAI,CAAC;AAQ1C;;;;;;;GAOG;AACH,wBAAsB,KAAK,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;yBAAjC,KAAK;;;AAiC3B;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,qBAGvE"}
|
package/dist/stdlib.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the "standard library" of steps that we make available to all workflow users.
|
|
3
|
+
* The can be imported like so: `import { sleep, fetch } from 'workflow'`. and used in workflow.
|
|
4
|
+
* The need to be exported directly in this package and cannot live in `core` to prevent
|
|
5
|
+
* circular dependencies post-compilation.
|
|
6
|
+
*/
|
|
7
|
+
import { RetryableError } from '@workflow/errors';
|
|
8
|
+
import ms from 'ms';
|
|
9
|
+
import { getStepMetadata } from './index.js';
|
|
10
|
+
// vqs has a max message visibility lifespan, the workflow sleep function
|
|
11
|
+
// will retry repeatedly until the user requested duration is reached.
|
|
12
|
+
// (Eventually make this configurable based on the queue backend adapter)
|
|
13
|
+
const MAX_SLEEP_DURATION_SECONDS = ms('23h') / 1000;
|
|
14
|
+
export async function sleep(param) {
|
|
15
|
+
'use step';
|
|
16
|
+
const { stepStartedAt } = getStepMetadata();
|
|
17
|
+
const durationMs = typeof param === 'string'
|
|
18
|
+
? ms(param)
|
|
19
|
+
: param.getTime() - Number(stepStartedAt);
|
|
20
|
+
if (typeof durationMs !== 'number' || durationMs < 0) {
|
|
21
|
+
const message = param instanceof Date
|
|
22
|
+
? `Invalid sleep date: "${param}". Expected a future date.`
|
|
23
|
+
: `Invalid sleep duration: "${param}". Expected a valid duration string like "1s", "1m", "1h", etc.`;
|
|
24
|
+
throw new Error(message);
|
|
25
|
+
}
|
|
26
|
+
const endAt = +stepStartedAt + durationMs;
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
if (now < endAt) {
|
|
29
|
+
const remainingSeconds = (endAt - now) / 1000;
|
|
30
|
+
const retryAfter = Math.min(remainingSeconds, MAX_SLEEP_DURATION_SECONDS);
|
|
31
|
+
throw new RetryableError(`Sleeping for ${ms(retryAfter * 1000, { long: true })}`, {
|
|
32
|
+
retryAfter,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
sleep.maxRetries = Infinity;
|
|
37
|
+
/**
|
|
38
|
+
* A hoisted `fetch()` function that is executed as a "step" function,
|
|
39
|
+
* for use within workflow functions.
|
|
40
|
+
*
|
|
41
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
|
42
|
+
*/
|
|
43
|
+
export async function fetch(...args) {
|
|
44
|
+
'use step';
|
|
45
|
+
return globalThis.fetch(...args);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=stdlib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdlib.js","sourceRoot":"","sources":["../src/stdlib.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAwB,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,yEAAyE;AACzE,sEAAsE;AACtE,yEAAyE;AACzE,MAAM,0BAA0B,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAqBpD,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,KAAyB;IACnD,UAAU,CAAC;IACX,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,EAAE,CAAC;IAC5C,MAAM,UAAU,GACd,OAAO,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;QACX,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;IAE9C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,OAAO,GACX,KAAK,YAAY,IAAI;YACnB,CAAC,CAAC,wBAAwB,KAAK,4BAA4B;YAC3D,CAAC,CAAC,4BAA4B,KAAK,iEAAiE,CAAC;QACzG,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,aAAa,GAAG,UAAU,CAAC;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,GAAG,GAAG,KAAK,EAAE,CAAC;QAChB,MAAM,gBAAgB,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,0BAA0B,CAAC,CAAC;QAC1E,MAAM,IAAI,cAAc,CACtB,gBAAgB,EAAE,CAAC,UAAU,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,EACvD;YACE,UAAU;SACX,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AACD,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,GAAG,IAAyC;IACtE,UAAU,CAAC;IACX,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC"}
|
package/dist/workflow.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,41 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workflow",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Workflow-
|
|
5
|
-
"
|
|
3
|
+
"version": "4.0.1-beta.1",
|
|
4
|
+
"description": "Workflow DevKit - Build durable, resilient, and observable workflows",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"workflow": "./bin/run.js",
|
|
9
|
+
"wf": "./bin/run.js"
|
|
10
|
+
},
|
|
6
11
|
"files": [
|
|
7
12
|
"dist",
|
|
8
|
-
"
|
|
13
|
+
"bin"
|
|
9
14
|
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
12
17
|
},
|
|
18
|
+
"license": "MIT",
|
|
13
19
|
"repository": {
|
|
14
20
|
"type": "git",
|
|
15
|
-
"url": "
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
21
|
+
"url": "https://github.com/vercel/workflow.git",
|
|
22
|
+
"directory": "packages/workflow"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"workflow": "./dist/workflow.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./api": "./dist/api.js",
|
|
31
|
+
"./internal/errors": "./dist/internal/errors.js",
|
|
32
|
+
"./internal/serialization": "./dist/internal/serialization.js",
|
|
33
|
+
"./internal/builtins": "./dist/internal/builtins.js",
|
|
34
|
+
"./internal/private": "./dist/internal/private.js",
|
|
35
|
+
"./next": "./dist/next.js",
|
|
36
|
+
"./nitro": "./dist/nitro.js",
|
|
37
|
+
"./rollup-plugin": "./dist/rollup-plugin.js",
|
|
38
|
+
"./runtime": "./dist/runtime.js"
|
|
30
39
|
},
|
|
31
|
-
"homepage": "https://github.com/havardh/workflow#readme",
|
|
32
40
|
"dependencies": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"workflow
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
"ms": "2.1.3",
|
|
42
|
+
"@workflow/cli": "4.0.1-beta.1",
|
|
43
|
+
"@workflow/core": "4.0.1-beta.1",
|
|
44
|
+
"@workflow/errors": "4.0.1-beta.1",
|
|
45
|
+
"@workflow/typescript-plugin": "4.0.1-beta.1",
|
|
46
|
+
"@workflow/next": "4.0.1-beta.1",
|
|
47
|
+
"@workflow/nitro": "4.0.1-beta.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/ms": "^2.1.0",
|
|
51
|
+
"@types/node": "24.6.2",
|
|
52
|
+
"@workflow/tsconfig": "4.0.1-beta.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@opentelemetry/api": "1"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"@opentelemetry/api": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsc && chmod +x bin/run.js",
|
|
64
|
+
"clean": "tsc --build --clean && rm -r dist ||:",
|
|
65
|
+
"dev": "tsc --watch",
|
|
66
|
+
"test": "vitest run src",
|
|
67
|
+
"typecheck": "tsc --noEmit"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
<a name="2.0.6"></a>
|
|
7
|
-
## [2.0.6](https://github.com/havardh/workflow/compare/workflow@2.0.5...workflow@2.0.6) (2018-09-26)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### Bug Fixes
|
|
11
|
-
|
|
12
|
-
* **workflow:** add missing import of dev flag ([1d00f58](https://github.com/havardh/workflow/commit/1d00f58))
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<a name="2.0.5"></a>
|
|
19
|
-
## [2.0.5](https://github.com/havardh/workflow/compare/workflow@2.0.4...workflow@2.0.5) (2018-09-26)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
* **workflow:** disable workflow home check in dev mode ([d991a15](https://github.com/havardh/workflow/commit/d991a15))
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<a name="2.0.4"></a>
|
|
31
|
-
## [2.0.4](https://github.com/havardh/workflow/compare/workflow@2.0.3...workflow@2.0.4) (2018-09-26)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### Bug Fixes
|
|
35
|
-
|
|
36
|
-
* **workflow:** wait on createWorkflowHome before running npm install ([7de33cc](https://github.com/havardh/workflow/commit/7de33cc))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<a name="2.0.3"></a>
|
|
43
|
-
## [2.0.3](https://github.com/havardh/workflow/compare/workflow@2.0.2...workflow@2.0.3) (2018-09-25)
|
|
44
|
-
|
|
45
|
-
**Note:** Version bump only for package workflow
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<a name="2.0.2"></a>
|
|
52
|
-
## [2.0.2](https://github.com/havardh/workflow/compare/workflow@2.0.1...workflow@2.0.2) (2018-09-25)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### Bug Fixes
|
|
56
|
-
|
|
57
|
-
* **workflow:** make create-workflow-home version fixed ([bfba80e](https://github.com/havardh/workflow/commit/bfba80e))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<a name="2.0.1"></a>
|
|
64
|
-
## [2.0.1](https://github.com/havardh/workflow/compare/workflow@2.0.0...workflow@2.0.1) (2018-09-25)
|
|
65
|
-
|
|
66
|
-
**Note:** Version bump only for package workflow
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
<a name="2.0.0"></a>
|
|
73
|
-
# [2.0.0](https://github.com/havardh/workflow/compare/workflow@1.1.6...workflow@2.0.0) (2018-09-18)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
### Features
|
|
77
|
-
|
|
78
|
-
* use only named exports for all files. ([ca77860](https://github.com/havardh/workflow/commit/ca77860))
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
### BREAKING CHANGES
|
|
82
|
-
|
|
83
|
-
* changes the api exported by most modules.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<a name="1.1.6"></a>
|
|
90
|
-
## [1.1.6](https://github.com/havardh/workflow/compare/workflow@1.1.5...workflow@1.1.6) (2018-09-18)
|
|
91
|
-
|
|
92
|
-
**Note:** Version bump only for package workflow
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<a name="1.1.5"></a>
|
|
99
|
-
## [1.1.5](https://github.com/havardh/workflow/compare/workflow@1.1.4...workflow@1.1.5) (2018-09-12)
|
|
100
|
-
|
|
101
|
-
**Note:** Version bump only for package workflow
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<a name="1.1.4"></a>
|
|
108
|
-
## [1.1.4](https://github.com/havardh/workflow/compare/workflow@1.1.3...workflow@1.1.4) (2018-09-11)
|
|
109
|
-
|
|
110
|
-
**Note:** Version bump only for package workflow
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<a name="1.1.3"></a>
|
|
117
|
-
## [1.1.3](https://github.com/havardh/workflow/compare/workflow@1.1.2...workflow@1.1.3) (2018-09-11)
|
|
118
|
-
|
|
119
|
-
**Note:** Version bump only for package workflow
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
<a name="1.1.2"></a>
|
|
126
|
-
## [1.1.2](https://github.com/havardh/workflow/compare/workflow@1.1.1...workflow@1.1.2) (2018-09-11)
|
|
127
|
-
|
|
128
|
-
**Note:** Version bump only for package workflow
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
<a name="1.1.1"></a>
|
|
135
|
-
## [1.1.1](https://github.com/havardh/workflow/compare/workflow@1.1.0...workflow@1.1.1) (2018-09-10)
|
|
136
|
-
|
|
137
|
-
**Note:** Version bump only for package workflow
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
<a name="1.1.0"></a>
|
|
144
|
-
# 1.1.0 (2018-09-10)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
### Bug Fixes
|
|
148
|
-
|
|
149
|
-
* make cli's executable ([f7ef385](https://github.com/havardh/workflow/commit/f7ef385))
|
|
150
|
-
* prefer npx and fallback to yarn and npm in workflow ([2fe6d0a](https://github.com/havardh/workflow/commit/2fe6d0a))
|
|
151
|
-
* remove dev depenencies from packages ([87eba92](https://github.com/havardh/workflow/commit/87eba92))
|
|
152
|
-
* resolve style issues ([266600f](https://github.com/havardh/workflow/commit/266600f))
|
|
153
|
-
* update depencies according to rollup missing deps ([5eaef7e](https://github.com/havardh/workflow/commit/5eaef7e))
|
|
154
|
-
* update dependencies of packages ([e0358bd](https://github.com/havardh/workflow/commit/e0358bd))
|
|
155
|
-
* update the workflow package.json ([a35d482](https://github.com/havardh/workflow/commit/a35d482))
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### Features
|
|
159
|
-
|
|
160
|
-
* implement workflow package ([220805e](https://github.com/havardh/workflow/commit/220805e))
|
package/Readme.md
DELETED
package/cli.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-env node */
|
|
3
|
-
/* eslint-disable global-require */
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
module.exports = require('./dist/cli');
|
|
7
|
-
} catch (error) {
|
|
8
|
-
if (error.code === 'MODULE_NOT_FOUND') {
|
|
9
|
-
require('babel-register');
|
|
10
|
-
require('ts-node').register(require('../../tsconfig.json'));
|
|
11
|
-
module.exports = require('./src/cli');
|
|
12
|
-
} else {
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
}
|
package/dist/cli.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
-
|
|
5
|
-
var shell = _interopDefault(require('shelljs'));
|
|
6
|
-
var child_process = require('child_process');
|
|
7
|
-
var os = _interopDefault(require('os'));
|
|
8
|
-
var path = require('path');
|
|
9
|
-
var prompt = _interopDefault(require('prompt'));
|
|
10
|
-
require('cross-spawn');
|
|
11
|
-
var WorkflowCmd = require('workflow-cmd/cli');
|
|
12
|
-
var util = require('util');
|
|
13
|
-
var execa = _interopDefault(require('execa'));
|
|
14
|
-
var createWorkflowHome = require('create-workflow-home');
|
|
15
|
-
|
|
16
|
-
function args(args) {
|
|
17
|
-
const parsedArgs = {
|
|
18
|
-
named: {},
|
|
19
|
-
positional: []
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const argsLength = args.length;
|
|
23
|
-
for (let i = 2; i < argsLength; i++) {
|
|
24
|
-
const arg = args[i];
|
|
25
|
-
if (arg[0] === '-') {
|
|
26
|
-
const name = getArgName(arg);
|
|
27
|
-
if (args[i + 1] === undefined) {
|
|
28
|
-
parsedArgs.named[name] = true;
|
|
29
|
-
} else {
|
|
30
|
-
parsedArgs.named[name] = args[i + 1];
|
|
31
|
-
}
|
|
32
|
-
i++;
|
|
33
|
-
} else {
|
|
34
|
-
parsedArgs.positional.push(arg);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return parsedArgs;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getArgName(arg) {
|
|
42
|
-
let sliceIndex;
|
|
43
|
-
const isWordArg = arg[1] === '-';
|
|
44
|
-
if (isWordArg) {
|
|
45
|
-
if (arg.length === 3) throw new Error(`expected ${arg} to be a word arg`);
|
|
46
|
-
sliceIndex = 2;
|
|
47
|
-
} else {
|
|
48
|
-
sliceIndex = 1;
|
|
49
|
-
}
|
|
50
|
-
return arg.slice(sliceIndex, arg.length);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* eslint-disable import/prefer-default-export */
|
|
54
|
-
|
|
55
|
-
function which(cmd) {
|
|
56
|
-
return shell.exec(`which ${cmd}`, { silent: true, async: false });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* eslint-env node */
|
|
60
|
-
|
|
61
|
-
const platform = process.platform;
|
|
62
|
-
|
|
63
|
-
function isRunningI3() {
|
|
64
|
-
try {
|
|
65
|
-
child_process.execSync("i3-msg 'exec echo 1'", { stdio: 'ignore' });
|
|
66
|
-
return true;
|
|
67
|
-
} catch (e) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function isRunningWmctrl() {
|
|
73
|
-
return which('wmctrl').code === 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const wm = (() => {
|
|
77
|
-
switch (platform) {
|
|
78
|
-
case 'win32':
|
|
79
|
-
case 'darwin':
|
|
80
|
-
return 'default';
|
|
81
|
-
case 'linux':
|
|
82
|
-
{
|
|
83
|
-
if (isRunningI3()) {
|
|
84
|
-
return 'i3';
|
|
85
|
-
} else if (isRunningWmctrl()) {
|
|
86
|
-
return 'wmctrl';
|
|
87
|
-
}
|
|
88
|
-
return 'unknown';
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return 'unknown';
|
|
92
|
-
})();
|
|
93
|
-
|
|
94
|
-
const dev = process.env.WORKFLOW_DEV_MODE === 'true';
|
|
95
|
-
const homedir = process.env.WORKFLOW_HOME;
|
|
96
|
-
const devhomedir = process.env.WORKFLOW_DEV_HOME;
|
|
97
|
-
|
|
98
|
-
const { config } = args(process.argv).named;
|
|
99
|
-
|
|
100
|
-
let configPath;
|
|
101
|
-
let baseFolder;
|
|
102
|
-
(() => {
|
|
103
|
-
if (dev) {
|
|
104
|
-
if (devhomedir) {
|
|
105
|
-
baseFolder = devhomedir;
|
|
106
|
-
configPath = path.join(devhomedir, 'config.js');
|
|
107
|
-
} else {
|
|
108
|
-
baseFolder = path.join(__dirname, '..', '..', 'workflow-template', 'config.js');
|
|
109
|
-
configPath = path.join(baseFolder, 'config.js');
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
if (config) {
|
|
113
|
-
baseFolder = path.dirname(config);
|
|
114
|
-
configPath = config;
|
|
115
|
-
} else if (homedir) {
|
|
116
|
-
baseFolder = homedir;
|
|
117
|
-
configPath = path.join(baseFolder, 'config.js');
|
|
118
|
-
} else {
|
|
119
|
-
configPath = path.join(os.homedir(), '.workflow', 'config.js');
|
|
120
|
-
baseFolder = `${os.homedir()}/.workflow`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
})();
|
|
124
|
-
|
|
125
|
-
/* eslint-env node */
|
|
126
|
-
|
|
127
|
-
function isValidWorkflowHome(path$$1) {
|
|
128
|
-
try {
|
|
129
|
-
const { name } = require(path.resolve(path$$1, 'package.json'));
|
|
130
|
-
if (name === 'workflow-user-home') {
|
|
131
|
-
return true;
|
|
132
|
-
} else {
|
|
133
|
-
throw new Error(`Invalid workflow-home package name: '${name}'
|
|
134
|
-
expected 'workflow-user-home'`);
|
|
135
|
-
}
|
|
136
|
-
} catch (error) {
|
|
137
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/* eslint-env node */
|
|
146
|
-
|
|
147
|
-
(async function cli([node, cmd, ...args]) {
|
|
148
|
-
if (!dev) {
|
|
149
|
-
if (!isValidWorkflowHome(baseFolder)) {
|
|
150
|
-
await initWorkflowHome(baseFolder);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
WorkflowCmd.cli(node, cmd, args);
|
|
155
|
-
})(process.argv).catch(err => console.error(err.toString()));
|
|
156
|
-
|
|
157
|
-
async function initWorkflowHome(path$$1) {
|
|
158
|
-
console.log();
|
|
159
|
-
console.log('It looks like you are using workflow for the first time.');
|
|
160
|
-
console.log();
|
|
161
|
-
console.log('Workflow requires a workflow-home directory.');
|
|
162
|
-
console.log('The workflow-home directory defaults to ' + path.join(os.homedir(), '.workflow'));
|
|
163
|
-
console.log('The default location can be overriden by the environment variable WORKFLOW_HOME');
|
|
164
|
-
console.log();
|
|
165
|
-
if (homedir) {
|
|
166
|
-
console.log('You have overriden the location to be:', path.resolve(homedir));
|
|
167
|
-
console.log();
|
|
168
|
-
}
|
|
169
|
-
if (devhomedir) {
|
|
170
|
-
console.log('You have overriden the dev location to be:', path.resolve(devhomedir));
|
|
171
|
-
console.log();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (await promptYesNo('Would you like to initialize a workflow-home directory at: ' + path.resolve(path$$1))) {
|
|
175
|
-
await createWorkflowHome.createWorkflowHome(path$$1);
|
|
176
|
-
|
|
177
|
-
console.log();
|
|
178
|
-
console.log('Running `npm install`');
|
|
179
|
-
await execa('npm', ['i'], { stdio: 'inherit', cwd: path$$1 });
|
|
180
|
-
|
|
181
|
-
console.log();
|
|
182
|
-
console.log('workflow was successfully installed. ');
|
|
183
|
-
console.log();
|
|
184
|
-
console.log('Try the example with `workflow Example.js`');
|
|
185
|
-
} else {
|
|
186
|
-
console.log();
|
|
187
|
-
console.log('Process aborted and no workflow-home was created.');
|
|
188
|
-
console.log('Workflow will not work until you set up a workflow-home folder.');
|
|
189
|
-
process.exit(1);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async function promptYesNo(question) {
|
|
194
|
-
const schema = {
|
|
195
|
-
properties: {
|
|
196
|
-
answer: {
|
|
197
|
-
type: 'string',
|
|
198
|
-
pattern: '^[ynYN]$',
|
|
199
|
-
description: question + ' (y/n)',
|
|
200
|
-
default: 'y'
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
prompt.start();
|
|
206
|
-
|
|
207
|
-
const { answer } = await util.promisify(prompt.get)(schema);
|
|
208
|
-
|
|
209
|
-
return answer === 'y' || answer === 'Y';
|
|
210
|
-
}
|