parpaing 2.0.2 → 2.1.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/README.md +3 -3
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,9 +37,9 @@ await parpaing.delete(id);
|
|
|
37
37
|
| Method | Route | Returns |
|
|
38
38
|
|---|---|---|
|
|
39
39
|
| `info()` | `GET /info` | Version, engines, capacity, sandbox count |
|
|
40
|
-
| `create(options?)` | `POST /sandboxes` | The sandbox and its
|
|
41
|
-
| `list()` | `GET /sandboxes` | `[{ id, state }]
|
|
42
|
-
| `get(id)` | `GET /sandboxes/:id` | The sandbox and its
|
|
40
|
+
| `create(options?)` | `POST /sandboxes` | The sandbox, its limits and its labels (`options.labels`) |
|
|
41
|
+
| `list(labels?)` | `GET /sandboxes?label=key=value` | `[{ id, state, labels }]`, only those carrying every label given |
|
|
42
|
+
| `get(id)` | `GET /sandboxes/:id` | The sandbox, its limits and its labels |
|
|
43
43
|
| `delete(id)` | `DELETE /sandboxes/:id` | |
|
|
44
44
|
| `exec(id, cmd)` | `start`, then `output` with `follow` to the end | `{ exitCode, stdout, stderr, skipped? }` |
|
|
45
45
|
| `exec(id, cmd, { onOutput })` | the same | `{ exitCode, skipped? }`, the output live |
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface NewSandbox {
|
|
|
17
17
|
disk?: number;
|
|
18
18
|
/** Seconds to wait if the machine lacks free memory, 0 by default. */
|
|
19
19
|
wait?: number;
|
|
20
|
+
/** Up to 32 key-value pairs to find the sandbox by with `list()`, such as `{ user: "alice" }`. Fixed at creation. */
|
|
21
|
+
labels?: Record<string, string>;
|
|
20
22
|
}
|
|
21
23
|
export interface Sandbox {
|
|
22
24
|
id: string;
|
|
@@ -27,6 +29,7 @@ export interface Sandbox {
|
|
|
27
29
|
cpus: number | null;
|
|
28
30
|
processes: number | null;
|
|
29
31
|
disk: number | null;
|
|
32
|
+
labels: Record<string, string>;
|
|
30
33
|
}
|
|
31
34
|
export interface CommandResult {
|
|
32
35
|
exitCode: number;
|
|
@@ -96,9 +99,11 @@ export declare class Parpaing {
|
|
|
96
99
|
info(): Promise<Info>;
|
|
97
100
|
/** Starts a sandbox; a missing image is downloaded first. */
|
|
98
101
|
create(options?: NewSandbox): Promise<Sandbox>;
|
|
99
|
-
|
|
102
|
+
/** Every sandbox, or with `labels` only those carrying all of them. */
|
|
103
|
+
list(labels?: Record<string, string>): Promise<{
|
|
100
104
|
id: string;
|
|
101
105
|
state: State;
|
|
106
|
+
labels: Record<string, string>;
|
|
102
107
|
}[]>;
|
|
103
108
|
get(id: string): Promise<Sandbox>;
|
|
104
109
|
delete(id: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -59,8 +59,12 @@ export class Parpaing {
|
|
|
59
59
|
async create(options = {}) {
|
|
60
60
|
return (await this.#call("POST", "/sandboxes", { json: options })).json();
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
/** Every sandbox, or with `labels` only those carrying all of them. */
|
|
63
|
+
async list(labels = {}) {
|
|
64
|
+
const query = new URLSearchParams(Object.entries(labels).map(([key, value]) => ["label", `${key}=${value}`])).toString();
|
|
65
|
+
const sandboxes = await (await this.#call("GET", `/sandboxes${query && `?${query}`}`)).json();
|
|
66
|
+
// Checked here too: a parpaing older than labels ignores the filter and answers every sandbox.
|
|
67
|
+
return sandboxes.filter((sandbox) => Object.entries(labels).every(([key, value]) => sandbox.labels?.[key] === value));
|
|
64
68
|
}
|
|
65
69
|
async get(id) {
|
|
66
70
|
return (await this.#call("GET", `/sandboxes/${encodeURIComponent(id)}`)).json();
|