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/dist/index.d.ts +124 -0
- package/dist/index.js +1096 -0
- package/package.json +20 -4
- package/CHANGELOG.md +0 -80
- package/src/client.ts +0 -684
- package/src/index.ts +0 -35
- package/src/workflow.ts +0 -214
- package/tsconfig.json +0 -12
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { StepDef, Predicate, IStorageAdapter, SnapshotConfig, LedgerEntry } from '@drej/core';
|
|
2
|
+
export { IStorageAdapter, LedgerEvent, SnapshotConfig, StepDef } from '@drej/core';
|
|
3
|
+
import { ImageSpec, Resources, CreateSandboxOptions, Sandbox, ListSandboxesOptions, Snapshot, ListSnapshotsOptions, DiagnosticLog, DiagnosticEvent } from '@drej/opensandbox';
|
|
4
|
+
export { CreateSandboxOptions, DiagnosticEvent, DiagnosticLog, ImageAuth, ImageSpec, ListSandboxesOptions, ListSnapshotsOptions, Resources, Sandbox, SandboxState, SandboxStatus, Snapshot, SnapshotState } from '@drej/opensandbox';
|
|
5
|
+
|
|
6
|
+
type LoopItem = {
|
|
7
|
+
toString(): string;
|
|
8
|
+
};
|
|
9
|
+
type SandboxOpts = {
|
|
10
|
+
image?: ImageSpec;
|
|
11
|
+
snapshotId?: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
entrypoint?: string[];
|
|
14
|
+
env?: Record<string, string>;
|
|
15
|
+
metadata?: Record<string, string>;
|
|
16
|
+
resourceLimits?: Resources;
|
|
17
|
+
};
|
|
18
|
+
type ForEachOpts = {
|
|
19
|
+
concurrency?: number;
|
|
20
|
+
as?: string;
|
|
21
|
+
};
|
|
22
|
+
type ForEachSource = unknown[] | {
|
|
23
|
+
from: string;
|
|
24
|
+
};
|
|
25
|
+
type ForEachCallback = (s: SandboxStepBuilder, item: LoopItem) => SandboxStepBuilder | string;
|
|
26
|
+
declare class SandboxStepBuilder {
|
|
27
|
+
protected _steps: StepDef[];
|
|
28
|
+
exec(command: string, opts?: {
|
|
29
|
+
cwd?: string;
|
|
30
|
+
envs?: Record<string, string>;
|
|
31
|
+
}): this;
|
|
32
|
+
writeFile(path: string, content: string, encoding?: "utf8" | "base64"): this;
|
|
33
|
+
retry(maxAttempts: number, fn: (s: SandboxStepBuilder) => SandboxStepBuilder, opts?: {
|
|
34
|
+
delayMs?: number;
|
|
35
|
+
backoff?: "fixed" | "exponential";
|
|
36
|
+
}): this;
|
|
37
|
+
forEach(source: ForEachSource, fn: ForEachCallback): this;
|
|
38
|
+
forEach(source: ForEachSource, opts: ForEachOpts, fn: ForEachCallback): this;
|
|
39
|
+
when(condition: Predicate, thenFn: (s: SandboxStepBuilder) => SandboxStepBuilder, elseFn?: (s: SandboxStepBuilder) => SandboxStepBuilder): this;
|
|
40
|
+
parallel(fn: (p: SandboxParallelBuilder) => SandboxParallelBuilder): this;
|
|
41
|
+
build(): StepDef[];
|
|
42
|
+
}
|
|
43
|
+
declare class SandboxParallelBuilder {
|
|
44
|
+
private _branches;
|
|
45
|
+
branch(fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this;
|
|
46
|
+
build(): StepDef[];
|
|
47
|
+
}
|
|
48
|
+
declare class WorkflowParallelBuilder {
|
|
49
|
+
private _branches;
|
|
50
|
+
sandbox(opts: SandboxOpts, fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this;
|
|
51
|
+
branch(fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this;
|
|
52
|
+
build(): StepDef[];
|
|
53
|
+
}
|
|
54
|
+
declare class WorkflowBuilder {
|
|
55
|
+
private _name;
|
|
56
|
+
private _steps;
|
|
57
|
+
constructor(_name: string);
|
|
58
|
+
sandbox(opts: SandboxOpts, fn: (s: SandboxStepBuilder) => SandboxStepBuilder): this;
|
|
59
|
+
parallel(fn: (p: WorkflowParallelBuilder) => WorkflowParallelBuilder): this;
|
|
60
|
+
build(): {
|
|
61
|
+
name: string;
|
|
62
|
+
steps: StepDef[];
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
declare function workflow(name: string): WorkflowBuilder;
|
|
66
|
+
|
|
67
|
+
declare class DrejError extends Error {
|
|
68
|
+
readonly status: number;
|
|
69
|
+
constructor(message: string, status: number);
|
|
70
|
+
}
|
|
71
|
+
interface DrejClientOptions {
|
|
72
|
+
/** OpenSandbox server URL */
|
|
73
|
+
baseUrl: string;
|
|
74
|
+
/** OpenSandbox API key (empty string for local dev) */
|
|
75
|
+
apiKey?: string;
|
|
76
|
+
/** Storage adapter for persisting workflow events. Use @drej/sqlite, @drej/postgres, or implement IStorageAdapter. */
|
|
77
|
+
adapter: IStorageAdapter;
|
|
78
|
+
}
|
|
79
|
+
interface RunOptions {
|
|
80
|
+
snapshotConfig?: SnapshotConfig;
|
|
81
|
+
}
|
|
82
|
+
type WorkflowEvent = LedgerEntry;
|
|
83
|
+
declare class WorkflowRun implements AsyncIterable<WorkflowEvent> {
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly id: string;
|
|
86
|
+
private readonly _events;
|
|
87
|
+
constructor(name: string, id: string, _events: AsyncGenerator<WorkflowEvent>);
|
|
88
|
+
[Symbol.asyncIterator](): AsyncIterator<WorkflowEvent>;
|
|
89
|
+
}
|
|
90
|
+
declare class DrejClient {
|
|
91
|
+
private readonly control;
|
|
92
|
+
private readonly adapter;
|
|
93
|
+
constructor(options: DrejClientOptions);
|
|
94
|
+
/** Call once before first use when using a DB-backed adapter. */
|
|
95
|
+
connect(): Promise<void>;
|
|
96
|
+
/** Releases adapter resources (e.g. closes DB connection pool). */
|
|
97
|
+
close(): Promise<void>;
|
|
98
|
+
createSandbox(options: CreateSandboxOptions): Promise<Sandbox>;
|
|
99
|
+
listSandboxes(options?: ListSandboxesOptions): Promise<Sandbox[]>;
|
|
100
|
+
getSandbox(id: string): Promise<Sandbox>;
|
|
101
|
+
deleteSandbox(id: string): Promise<void>;
|
|
102
|
+
pauseSandbox(id: string): Promise<void>;
|
|
103
|
+
resumeSandbox(id: string): Promise<void>;
|
|
104
|
+
renewSandbox(id: string): Promise<void>;
|
|
105
|
+
waitForRunning(id: string, options?: {
|
|
106
|
+
timeoutMs?: number;
|
|
107
|
+
pollIntervalMs?: number;
|
|
108
|
+
}): Promise<Sandbox>;
|
|
109
|
+
createSnapshot(sandboxId: string): Promise<Snapshot>;
|
|
110
|
+
listSnapshots(options?: ListSnapshotsOptions): Promise<Snapshot[]>;
|
|
111
|
+
getSnapshot(id: string): Promise<Snapshot>;
|
|
112
|
+
deleteSnapshot(id: string): Promise<void>;
|
|
113
|
+
getDiagnosticLogs(sandboxId: string): Promise<DiagnosticLog[]>;
|
|
114
|
+
getDiagnosticEvents(sandboxId: string): Promise<DiagnosticEvent[]>;
|
|
115
|
+
run(w: WorkflowBuilder, options?: RunOptions): Promise<WorkflowRun>;
|
|
116
|
+
replayFromSnapshot(name: string, runId: string, w: WorkflowBuilder): Promise<WorkflowRun>;
|
|
117
|
+
resumeRun(name: string, runId: string, w: WorkflowBuilder): Promise<WorkflowRun>;
|
|
118
|
+
listRuns(workflowName: string): Promise<string[]>;
|
|
119
|
+
getRunLedger(workflowName: string, runId: string): Promise<WorkflowEvent[]>;
|
|
120
|
+
private _execute;
|
|
121
|
+
private _makeStream;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { DrejClient, type DrejClientOptions, DrejError, type LoopItem, type RunOptions, type SandboxOpts, SandboxStepBuilder, WorkflowBuilder, type WorkflowEvent, WorkflowRun, workflow };
|