@watasu/sdk 0.1.6 → 0.1.24
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/README.md +104 -8
- package/dist/commands.d.ts +26 -4
- package/dist/commands.js +54 -15
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +8 -0
- package/dist/filesystem.d.ts +53 -13
- package/dist/filesystem.js +128 -12
- package/dist/git.d.ts +27 -0
- package/dist/git.js +43 -2
- package/dist/index.d.ts +12 -6
- package/dist/index.js +6 -3
- package/dist/process.d.ts +56 -0
- package/dist/process.js +137 -0
- package/dist/processSocket.d.ts +1 -0
- package/dist/processSocket.js +3 -0
- package/dist/pty.d.ts +5 -1
- package/dist/pty.js +9 -7
- package/dist/sandbox.d.ts +118 -19
- package/dist/sandbox.js +246 -42
- package/dist/template.d.ts +232 -0
- package/dist/template.js +624 -0
- package/dist/terminal.d.ts +41 -0
- package/dist/terminal.js +74 -0
- package/dist/transport.d.ts +1 -0
- package/dist/transport.js +3 -0
- package/package.json +1 -1
package/dist/terminal.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Captured terminal output. */
|
|
2
|
+
export class TerminalOutput {
|
|
3
|
+
_data = '';
|
|
4
|
+
get data() { return this._data; }
|
|
5
|
+
addData(data) {
|
|
6
|
+
this._data += data;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** A running terminal session in a sandbox. */
|
|
10
|
+
export class Terminal {
|
|
11
|
+
terminalID;
|
|
12
|
+
handle;
|
|
13
|
+
output;
|
|
14
|
+
onExit;
|
|
15
|
+
finished;
|
|
16
|
+
waitPromise;
|
|
17
|
+
constructor(terminalID, handle, output, onExit) {
|
|
18
|
+
this.terminalID = terminalID;
|
|
19
|
+
this.handle = handle;
|
|
20
|
+
this.output = output;
|
|
21
|
+
this.onExit = onExit;
|
|
22
|
+
this.finished = this.wait();
|
|
23
|
+
}
|
|
24
|
+
get data() { return this.output.data; }
|
|
25
|
+
async kill() {
|
|
26
|
+
await this.handle.kill();
|
|
27
|
+
}
|
|
28
|
+
async wait() {
|
|
29
|
+
if (this.waitPromise)
|
|
30
|
+
return this.waitPromise;
|
|
31
|
+
this.waitPromise = this.waitOnce();
|
|
32
|
+
return this.waitPromise;
|
|
33
|
+
}
|
|
34
|
+
async waitOnce() {
|
|
35
|
+
await this.handle.wait().catch((error) => {
|
|
36
|
+
if (typeof error?.stdout === 'string')
|
|
37
|
+
this.output.addData(error.stdout);
|
|
38
|
+
else
|
|
39
|
+
throw error;
|
|
40
|
+
});
|
|
41
|
+
await this.onExit?.();
|
|
42
|
+
return this.output;
|
|
43
|
+
}
|
|
44
|
+
async sendData(data) {
|
|
45
|
+
await this.handle.sendStdin(data);
|
|
46
|
+
}
|
|
47
|
+
async resize({ cols, rows }) {
|
|
48
|
+
await this.handle.resize({ cols, rows });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Manager for starting terminal sessions. */
|
|
52
|
+
export class TerminalManager {
|
|
53
|
+
pty;
|
|
54
|
+
constructor(pty) {
|
|
55
|
+
this.pty = pty;
|
|
56
|
+
}
|
|
57
|
+
async start(opts = {}) {
|
|
58
|
+
const output = new TerminalOutput();
|
|
59
|
+
const handle = await this.pty.create({
|
|
60
|
+
cmd: opts.cmd,
|
|
61
|
+
cwd: opts.cwd,
|
|
62
|
+
rootDir: opts.rootDir,
|
|
63
|
+
envVars: opts.envVars,
|
|
64
|
+
size: opts.size,
|
|
65
|
+
timeout: opts.timeout,
|
|
66
|
+
onData: async (bytes) => {
|
|
67
|
+
const data = new TextDecoder().decode(bytes);
|
|
68
|
+
output.addData(data);
|
|
69
|
+
await opts.onData?.(data);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
return new Terminal(String(handle.pid), handle, output, opts.onExit);
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/transport.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class ControlClient {
|
|
|
5
5
|
constructor(config: ConnectionConfig);
|
|
6
6
|
get(path: string, opts?: RequestOpts): Promise<JsonRecord>;
|
|
7
7
|
post(path: string, opts?: RequestOpts): Promise<JsonRecord>;
|
|
8
|
+
put(path: string, opts?: RequestOpts): Promise<JsonRecord>;
|
|
8
9
|
patch(path: string, opts?: RequestOpts): Promise<JsonRecord>;
|
|
9
10
|
delete(path: string, opts?: RequestOpts): Promise<JsonRecord>;
|
|
10
11
|
private request;
|
package/dist/transport.js
CHANGED
|
@@ -10,6 +10,9 @@ export class ControlClient {
|
|
|
10
10
|
post(path, opts = {}) {
|
|
11
11
|
return this.request(path, { ...opts, method: 'POST' });
|
|
12
12
|
}
|
|
13
|
+
put(path, opts = {}) {
|
|
14
|
+
return this.request(path, { ...opts, method: 'PUT' });
|
|
15
|
+
}
|
|
13
16
|
patch(path, opts = {}) {
|
|
14
17
|
return this.request(path, { ...opts, method: 'PATCH' });
|
|
15
18
|
}
|