@drej/workflow 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/README.md +133 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @drej/workflow
2
+
3
+ Lazy pipeline builder for [drej](https://drej.dev) — retry, conditional branching, fan-out, and parallel sandboxes, all flushed in one `await`.
4
+
5
+ ```bash
6
+ bun add @drej/workflow
7
+ ```
8
+
9
+ **[Full documentation →](https://docs.drej.dev/docs/workflow)**
10
+
11
+ ---
12
+
13
+ ## How it works
14
+
15
+ `workflow(client).sandbox(opts, fn)` returns a builder. The `fn` callback receives a `SandboxBuilder` — all methods on it queue operations synchronously. Nothing runs until you `await .pipe()` or `.result()`.
16
+
17
+ ```ts
18
+ import { workflow } from "@drej/workflow";
19
+
20
+ await workflow(client)
21
+ .sandbox({ image: "node:20-slim", resources: { cpu: "1", memory: "512Mi" } }, (sb) => {
22
+ sb.exec("npm ci");
23
+ sb.exec("npm run build");
24
+ sb.exec("npm test");
25
+ })
26
+ .pipe(process.stdout);
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Retry
32
+
33
+ ```ts
34
+ sb.retry(
35
+ 3,
36
+ (r) => {
37
+ r.exec("flaky-network-call");
38
+ },
39
+ { delayMs: 500, backoff: "exponential" },
40
+ );
41
+ ```
42
+
43
+ ## Conditional branching
44
+
45
+ The predicate receives `{ stdout, exitCode, vars }` from the previous step.
46
+
47
+ ```ts
48
+ sb.exec("test -f /app/build.sh", { strict: false });
49
+ sb.when(
50
+ (ctx) => ctx.exitCode === 0,
51
+ (s) => s.exec("bash /app/build.sh"),
52
+ (s) => s.exec("echo 'no build script'"),
53
+ );
54
+ ```
55
+
56
+ ## Fan-out
57
+
58
+ ```ts
59
+ sb.forEach(
60
+ ["a.ts", "b.ts", "c.ts"],
61
+ (s, file) => {
62
+ s.exec(`tsc --noEmit ${file}`);
63
+ },
64
+ { concurrency: 4 },
65
+ );
66
+ ```
67
+
68
+ ## Capture a value
69
+
70
+ `sb.readFile(path, as)` stores file contents in `vars[as]` on the result object.
71
+
72
+ ```ts
73
+ const { vars } = await workflow(client)
74
+ .sandbox({ image: "node:20-slim", resources: { cpu: "500m", memory: "256Mi" } }, (sb) => {
75
+ sb.exec(`node -e "require('fs').writeFileSync('/out.txt', process.version)"`);
76
+ sb.readFile("/out.txt", "nodeVersion");
77
+ })
78
+ .result();
79
+
80
+ console.log(vars.nodeVersion); // "v20.x.x"
81
+ ```
82
+
83
+ ## Parallel sandboxes
84
+
85
+ Run the same builder across multiple configs simultaneously:
86
+
87
+ ```ts
88
+ await workflow(client)
89
+ .parallel(
90
+ [
91
+ { image: "node:18-slim", resources: { cpu: "500m", memory: "256Mi" } },
92
+ { image: "node:20-slim", resources: { cpu: "500m", memory: "256Mi" } },
93
+ { image: "node:22-slim", resources: { cpu: "500m", memory: "256Mi" } },
94
+ ],
95
+ (sb) => {
96
+ sb.exec("node --version");
97
+ sb.exec("npm ci && npm test");
98
+ },
99
+ )
100
+ .pipe(process.stdout);
101
+ ```
102
+
103
+ ## Sequential pipeline
104
+
105
+ Pass work across sandboxes in order, each starting fresh:
106
+
107
+ ```ts
108
+ await workflow(client)
109
+ .sequence([
110
+ {
111
+ image: "node:20-slim",
112
+ resources: { cpu: "1", memory: "512Mi" },
113
+ run: (sb) => {
114
+ sb.exec("npm ci");
115
+ sb.exec("npm run build");
116
+ },
117
+ },
118
+ {
119
+ image: "alpine:3",
120
+ resources: { cpu: "500m", memory: "256Mi" },
121
+ run: (sb) => {
122
+ sb.exec("ls /app/dist");
123
+ },
124
+ },
125
+ ])
126
+ .pipe(process.stdout);
127
+ ```
128
+
129
+ ---
130
+
131
+ ## License
132
+
133
+ Apache 2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drej/workflow",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "files": [
5
5
  "dist"
6
6
  ],