drej 0.4.0 → 0.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/src/index.ts DELETED
@@ -1,35 +0,0 @@
1
- export { DrejClient, DrejError, WorkflowRun } from "./client";
2
- export type {
3
- DrejClientOptions,
4
- Resources,
5
- ImageAuth,
6
- ImageSpec,
7
- Sandbox,
8
- SandboxState,
9
- SandboxStatus,
10
- CreateSandboxOptions,
11
- ListSandboxesOptions,
12
- Snapshot,
13
- SnapshotState,
14
- ListSnapshotsOptions,
15
- SSEEvent,
16
- SSEEventType,
17
- CodeContext,
18
- ExecuteCodeOptions,
19
- ExecuteCommandOptions,
20
- CommandStatus,
21
- FileInfo,
22
- DirectoryEntry,
23
- FileReplacement,
24
- Metrics,
25
- DiagnosticLog,
26
- DiagnosticEvent,
27
- WorkflowEvent,
28
- WorkflowEventKind,
29
- StepDef,
30
- SnapshotConfig,
31
- RunOptions,
32
- } from "./client";
33
-
34
- export { workflow, WorkflowBuilder, SandboxStepBuilder } from "./workflow";
35
- export type { SandboxOpts, LoopItem } from "./workflow";
package/src/workflow.ts DELETED
@@ -1,214 +0,0 @@
1
- import type { StepDef, ImageSpec, Resources, Predicate } from "./client";
2
-
3
- // Placeholder that serialises to {{name}} inside template literals.
4
- // Used as the `item` parameter in forEach callbacks so users write
5
- // `s.exec(`upload ${item}`)` instead of `s.exec("upload {{item}}")`.
6
- class LoopVar {
7
- constructor(private name: string) {}
8
- toString() {
9
- return `{{${this.name}}}`;
10
- }
11
- }
12
-
13
- export type LoopItem = { toString(): string };
14
-
15
- export type SandboxOpts = {
16
- image?: ImageSpec;
17
- snapshotId?: string;
18
- timeout?: number;
19
- entrypoint?: string[];
20
- env?: Record<string, string>;
21
- metadata?: Record<string, string>;
22
- resourceLimits?: Resources;
23
- };
24
-
25
- type ForEachOpts = {
26
- concurrency?: number;
27
- as?: string;
28
- };
29
-
30
- type ForEachSource = unknown[] | { from: string };
31
- type ForEachCallback = (s: SandboxStepBuilder, item: LoopItem) => SandboxStepBuilder | string;
32
-
33
- function wrapSteps(steps: StepDef[]): StepDef {
34
- return steps.length === 1 ? steps[0] : { type: "sequence", steps };
35
- }
36
-
37
- // ── SandboxStepBuilder ────────────────────────────────────────────────────────
38
-
39
- export class SandboxStepBuilder {
40
- protected _steps: StepDef[] = [];
41
-
42
- exec(command: string, opts?: { cwd?: string; envs?: Record<string, string> }): this {
43
- this._steps.push({ type: "exec_command", command, ...opts });
44
- return this;
45
- }
46
-
47
- writeFile(path: string, content: string, encoding?: "utf8" | "base64"): this {
48
- this._steps.push({ type: "write_file", path, content, ...(encoding ? { encoding } : {}) });
49
- return this;
50
- }
51
-
52
- retry(
53
- maxAttempts: number,
54
- fn: (s: SandboxStepBuilder) => SandboxStepBuilder,
55
- opts?: { delayMs?: number; backoff?: "fixed" | "exponential" },
56
- ): this {
57
- const inner = new SandboxStepBuilder();
58
- fn(inner);
59
- this._steps.push({ type: "retry", step: wrapSteps(inner.build()), maxAttempts, ...opts });
60
- return this;
61
- }
62
-
63
- forEach(source: ForEachSource, fn: ForEachCallback): this;
64
- forEach(source: ForEachSource, opts: ForEachOpts, fn: ForEachCallback): this;
65
- forEach(
66
- source: ForEachSource,
67
- optsOrFn: ForEachOpts | ForEachCallback,
68
- fn?: ForEachCallback,
69
- ): this {
70
- const opts: ForEachOpts = typeof optsOrFn === "function" ? {} : optsOrFn;
71
- const callback: ForEachCallback = typeof optsOrFn === "function" ? optsOrFn : fn!;
72
-
73
- const varName = opts.as ?? "item";
74
- const loopVar = new LoopVar(varName);
75
- const inner = new SandboxStepBuilder();
76
- const result = callback(inner, loopVar);
77
-
78
- const steps: StepDef[] =
79
- typeof result === "string"
80
- ? [{ type: "exec_command", command: result }]
81
- : result.build();
82
-
83
- this._steps.push({
84
- type: "loop",
85
- as: varName,
86
- steps,
87
- ...(Array.isArray(source) ? { items: source } : { over: source.from }),
88
- ...(opts.concurrency !== undefined && opts.concurrency > 1 ? { concurrently: true } : {}),
89
- });
90
-
91
- return this;
92
- }
93
-
94
- when(
95
- condition: Predicate,
96
- thenFn: (s: SandboxStepBuilder) => SandboxStepBuilder,
97
- elseFn?: (s: SandboxStepBuilder) => SandboxStepBuilder,
98
- ): this {
99
- const thenBuilder = new SandboxStepBuilder();
100
- thenFn(thenBuilder);
101
-
102
- const elseSteps = elseFn
103
- ? (() => {
104
- const b = new SandboxStepBuilder();
105
- elseFn(b);
106
- return b.build();
107
- })()
108
- : undefined;
109
-
110
- this._steps.push({
111
- type: "conditional",
112
- condition,
113
- then: thenBuilder.build(),
114
- ...(elseSteps ? { else: elseSteps } : {}),
115
- });
116
-
117
- return this;
118
- }
119
-
120
- parallel(fn: (p: SandboxParallelBuilder) => SandboxParallelBuilder): this {
121
- const pb = new SandboxParallelBuilder();
122
- fn(pb);
123
- this._steps.push({ type: "parallel", steps: pb.build() });
124
- return this;
125
- }
126
-
127
- build(): StepDef[] {
128
- return [...this._steps];
129
- }
130
- }
131
-
132
- // ── SandboxParallelBuilder ────────────────────────────────────────────────────
133
- // Used inside a sandbox scope — branches share the same sandbox, no new ones.
134
-
135
- class SandboxParallelBuilder {
136
- private _branches: StepDef[] = [];
137
-
138
- branch(fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this {
139
- const sb = new SandboxStepBuilder();
140
- fn(sb);
141
- this._branches.push(wrapSteps(sb.build()));
142
- return this;
143
- }
144
-
145
- build(): StepDef[] {
146
- return this._branches;
147
- }
148
- }
149
-
150
- // ── WorkflowParallelBuilder ───────────────────────────────────────────────────
151
- // Used at the top-level workflow scope — each branch can own its own sandbox.
152
-
153
- class WorkflowParallelBuilder {
154
- private _branches: StepDef[] = [];
155
-
156
- sandbox(opts: SandboxOpts, fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this {
157
- const sb = new SandboxStepBuilder();
158
- fn(sb);
159
- this._branches.push({
160
- type: "sequence",
161
- steps: [
162
- { type: "create_sandbox", entrypoint: ["tail", "-f", "/dev/null"], ...opts },
163
- ...sb.build(),
164
- { type: "delete_sandbox" },
165
- ],
166
- });
167
- return this;
168
- }
169
-
170
- branch(fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this {
171
- const sb = new SandboxStepBuilder();
172
- fn(sb);
173
- this._branches.push(wrapSteps(sb.build()));
174
- return this;
175
- }
176
-
177
- build(): StepDef[] {
178
- return this._branches;
179
- }
180
- }
181
-
182
- // ── WorkflowBuilder ───────────────────────────────────────────────────────────
183
-
184
- export class WorkflowBuilder {
185
- private _steps: StepDef[] = [];
186
-
187
- constructor(private _name: string) {}
188
-
189
- sandbox(opts: SandboxOpts, fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this {
190
- const sb = new SandboxStepBuilder();
191
- fn(sb);
192
- this._steps.push(
193
- { type: "create_sandbox", entrypoint: ["tail", "-f", "/dev/null"], ...opts },
194
- ...sb.build(),
195
- { type: "delete_sandbox" },
196
- );
197
- return this;
198
- }
199
-
200
- parallel(fn: (p: WorkflowParallelBuilder) => WorkflowParallelBuilder): this {
201
- const pb = new WorkflowParallelBuilder();
202
- fn(pb);
203
- this._steps.push({ type: "parallel", steps: pb.build() });
204
- return this;
205
- }
206
-
207
- build(): { name: string; steps: StepDef[] } {
208
- return { name: this._name, steps: this._steps };
209
- }
210
- }
211
-
212
- export function workflow(name: string): WorkflowBuilder {
213
- return new WorkflowBuilder(name);
214
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "strict": true,
7
- "noEmit": true,
8
- "skipLibCheck": true,
9
- "declaration": true
10
- },
11
- "include": ["src"]
12
- }