@vercel/sandbox 0.0.15 → 0.0.17

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@0.0.15 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.17 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc
4
4
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@0.0.15 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.17 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @vercel/sandbox
2
2
 
3
+ ## 0.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - Sandboxes can now expose up to 4 ports ([#99](https://github.com/vercel/sandbox-sdk/pull/99))
8
+
9
+ This applies to all SDK versions, but this SDK release documents the limit.
10
+
11
+ - Fix bug in Sandbox.writeFile, add support for absolute paths ([#97](https://github.com/vercel/sandbox-sdk/pull/97))
12
+
13
+ ## 0.0.16
14
+
15
+ ### Patch Changes
16
+
17
+ - Add sandbox.status property ([#95](https://github.com/vercel/sandbox-sdk/pull/95))
18
+
3
19
  ## 0.0.15
4
20
 
5
21
  ### Patch Changes
@@ -9,20 +9,21 @@ export declare class APIClient extends BaseClient {
9
9
  teamId: string;
10
10
  token: string;
11
11
  });
12
- protected request(path: string, params?: RequestParams): Promise<import("node-fetch").Response>;
12
+ protected request(path: string, params?: RequestParams): Promise<Response>;
13
13
  getSandbox(params: {
14
14
  sandboxId: string;
15
15
  }): Promise<Parsed<{
16
16
  sandbox: {
17
17
  region: string;
18
- timeout: number;
19
18
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
20
19
  id: string;
21
20
  memory: number;
22
21
  vcpus: number;
23
22
  runtime: string;
23
+ timeout: number;
24
24
  requestedAt: number;
25
25
  createdAt: number;
26
+ cwd: string;
26
27
  updatedAt: number;
27
28
  duration?: number | undefined;
28
29
  startedAt?: number | undefined;
@@ -30,9 +31,9 @@ export declare class APIClient extends BaseClient {
30
31
  stoppedAt?: number | undefined;
31
32
  };
32
33
  routes: {
33
- port: number;
34
34
  url: string;
35
35
  subdomain: string;
36
+ port: number;
36
37
  }[];
37
38
  }>>;
38
39
  createSandbox(params: {
@@ -57,14 +58,15 @@ export declare class APIClient extends BaseClient {
57
58
  }): Promise<Parsed<{
58
59
  sandbox: {
59
60
  region: string;
60
- timeout: number;
61
61
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
62
62
  id: string;
63
63
  memory: number;
64
64
  vcpus: number;
65
65
  runtime: string;
66
+ timeout: number;
66
67
  requestedAt: number;
67
68
  createdAt: number;
69
+ cwd: string;
68
70
  updatedAt: number;
69
71
  duration?: number | undefined;
70
72
  startedAt?: number | undefined;
@@ -72,9 +74,9 @@ export declare class APIClient extends BaseClient {
72
74
  stoppedAt?: number | undefined;
73
75
  };
74
76
  routes: {
75
- port: number;
76
77
  url: string;
77
78
  subdomain: string;
79
+ port: number;
78
80
  }[];
79
81
  }>>;
80
82
  runCommand(params: {
@@ -87,10 +89,10 @@ export declare class APIClient extends BaseClient {
87
89
  }): Promise<Parsed<{
88
90
  command: {
89
91
  name: string;
90
- cwd: string;
91
92
  args: string[];
92
93
  id: string;
93
94
  startedAt: number;
95
+ cwd: string;
94
96
  sandboxId: string;
95
97
  exitCode: number | null;
96
98
  };
@@ -112,16 +114,19 @@ export declare class APIClient extends BaseClient {
112
114
  }): Promise<Parsed<{}>>;
113
115
  getFileWriter(params: {
114
116
  sandboxId: string;
117
+ extractDir: string;
115
118
  }): {
116
- response: Promise<import("node-fetch").Response>;
119
+ response: Promise<Response>;
117
120
  writer: FileWriter;
118
121
  };
119
122
  writeFiles(params: {
120
123
  sandboxId: string;
124
+ cwd: string;
121
125
  files: {
122
126
  path: string;
123
127
  content: Buffer;
124
128
  }[];
129
+ extractDir: string;
125
130
  }): Promise<void>;
126
131
  readFile(params: {
127
132
  sandboxId: string;
@@ -135,10 +140,10 @@ export declare class APIClient extends BaseClient {
135
140
  }): Promise<Parsed<{
136
141
  command: {
137
142
  name: string;
138
- cwd: string;
139
143
  args: string[];
140
144
  id: string;
141
145
  startedAt: number;
146
+ cwd: string;
142
147
  sandboxId: string;
143
148
  exitCode: number | null;
144
149
  };
@@ -12,6 +12,8 @@ const version_1 = require("../version");
12
12
  const consume_readable_1 = require("../utils/consume-readable");
13
13
  const jsonlines_1 = __importDefault(require("jsonlines"));
14
14
  const os_1 = __importDefault(require("os"));
15
+ const stream_1 = require("stream");
16
+ const normalizePath_1 = require("../utils/normalizePath");
15
17
  class APIClient extends base_client_1.BaseClient {
16
18
  constructor(params) {
17
19
  super({
@@ -77,7 +79,10 @@ class APIClient extends base_client_1.BaseClient {
77
79
  response: (async () => {
78
80
  return this.request(`/v1/sandboxes/${params.sandboxId}/fs/write`, {
79
81
  method: "POST",
80
- headers: { "content-type": "application/gzip" },
82
+ headers: {
83
+ "content-type": "application/gzip",
84
+ "x-cwd": params.extractDir,
85
+ },
81
86
  body: await (0, consume_readable_1.consumeReadable)(writer.readable),
82
87
  });
83
88
  })(),
@@ -87,9 +92,17 @@ class APIClient extends base_client_1.BaseClient {
87
92
  async writeFiles(params) {
88
93
  const { writer, response } = this.getFileWriter({
89
94
  sandboxId: params.sandboxId,
95
+ extractDir: params.extractDir,
90
96
  });
91
97
  for (const file of params.files) {
92
- await writer.addFile({ name: file.path, content: file.content });
98
+ await writer.addFile({
99
+ name: (0, normalizePath_1.normalizePath)({
100
+ filePath: file.path,
101
+ extractDir: params.extractDir,
102
+ cwd: params.cwd,
103
+ }),
104
+ content: file.content,
105
+ });
93
106
  }
94
107
  writer.end();
95
108
  await (0, base_client_1.parseOrThrow)(validators_1.EmptyResponse, await response);
@@ -102,7 +115,10 @@ class APIClient extends base_client_1.BaseClient {
102
115
  if (response.status === 404) {
103
116
  return null;
104
117
  }
105
- return response.body;
118
+ if (response.body === null) {
119
+ return null;
120
+ }
121
+ return stream_1.Readable.fromWeb(response.body);
106
122
  }
107
123
  async killCommand(params) {
108
124
  return (0, base_client_1.parseOrThrow)(validators_1.CommandResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/${params.commandId}/kill`, {
@@ -118,7 +134,12 @@ class APIClient extends base_client_1.BaseClient {
118
134
  message: "Expected a stream of logs",
119
135
  });
120
136
  }
121
- for await (const chunk of response.body.pipe(jsonlines_1.default.parse())) {
137
+ if (response.body === null) {
138
+ throw new api_error_1.APIError(response, {
139
+ message: "No response body",
140
+ });
141
+ }
142
+ for await (const chunk of stream_1.Readable.fromWeb(response.body).pipe(jsonlines_1.default.parse())) {
122
143
  yield validators_1.LogLine.parse(chunk);
123
144
  }
124
145
  }
@@ -1,4 +1,3 @@
1
- import type { Response } from "node-fetch";
2
1
  interface Options<ErrorData> {
3
2
  message?: string;
4
3
  json?: ErrorData;
@@ -2,7 +2,6 @@ import type { Options as RetryOptions } from "async-retry";
2
2
  import { APIError } from "./api-error";
3
3
  import { ZodType } from "zod";
4
4
  import { type RequestOptions } from "./with-retry";
5
- import nodeFetch, { type Response, type RequestInit } from "node-fetch";
6
5
  export interface RequestParams extends RequestInit {
7
6
  headers?: Record<string, string>;
8
7
  method?: string;
@@ -25,7 +24,7 @@ export declare class BaseClient {
25
24
  host: string;
26
25
  token?: string;
27
26
  });
28
- protected request(path: string, opts?: RequestParams): Promise<nodeFetch.Response>;
27
+ protected request(path: string, opts?: RequestParams): Promise<Response>;
29
28
  }
30
29
  export interface Parsed<Data> {
31
30
  response: Response;
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.BaseClient = void 0;
7
4
  exports.parse = parse;
@@ -9,7 +6,6 @@ exports.parseOrThrow = parseOrThrow;
9
6
  const api_error_1 = require("./api-error");
10
7
  const array_1 = require("../utils/array");
11
8
  const with_retry_1 = require("./with-retry");
12
- const node_fetch_1 = __importDefault(require("node-fetch"));
13
9
  /**
14
10
  * A base API client that provides a convenience wrapper for fetching where
15
11
  * we can pass query parameters as an object, support retries, debugging
@@ -17,7 +13,7 @@ const node_fetch_1 = __importDefault(require("node-fetch"));
17
13
  */
18
14
  class BaseClient {
19
15
  constructor(params) {
20
- this.fetch = (0, with_retry_1.withRetry)(node_fetch_1.default);
16
+ this.fetch = (0, with_retry_1.withRetry)(globalThis.fetch);
21
17
  this.host = params.host;
22
18
  this.debug = params.debug ?? process.env.DEBUG_FETCH === "true";
23
19
  this.token = params.token;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- export type SandboxData = z.infer<typeof Sandbox>;
2
+ export type SandboxMetaData = z.infer<typeof Sandbox>;
3
3
  export declare const Sandbox: z.ZodObject<{
4
4
  id: z.ZodString;
5
5
  memory: z.ZodNumber;
@@ -14,17 +14,19 @@ export declare const Sandbox: z.ZodObject<{
14
14
  stoppedAt: z.ZodOptional<z.ZodNumber>;
15
15
  duration: z.ZodOptional<z.ZodNumber>;
16
16
  createdAt: z.ZodNumber;
17
+ cwd: z.ZodString;
17
18
  updatedAt: z.ZodNumber;
18
19
  }, "strip", z.ZodTypeAny, {
19
20
  region: string;
20
- timeout: number;
21
21
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
22
22
  id: string;
23
23
  memory: number;
24
24
  vcpus: number;
25
25
  runtime: string;
26
+ timeout: number;
26
27
  requestedAt: number;
27
28
  createdAt: number;
29
+ cwd: string;
28
30
  updatedAt: number;
29
31
  duration?: number | undefined;
30
32
  startedAt?: number | undefined;
@@ -32,14 +34,15 @@ export declare const Sandbox: z.ZodObject<{
32
34
  stoppedAt?: number | undefined;
33
35
  }, {
34
36
  region: string;
35
- timeout: number;
36
37
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
37
38
  id: string;
38
39
  memory: number;
39
40
  vcpus: number;
40
41
  runtime: string;
42
+ timeout: number;
41
43
  requestedAt: number;
42
44
  createdAt: number;
45
+ cwd: string;
43
46
  updatedAt: number;
44
47
  duration?: number | undefined;
45
48
  startedAt?: number | undefined;
@@ -52,13 +55,13 @@ export declare const SandboxRoute: z.ZodObject<{
52
55
  subdomain: z.ZodString;
53
56
  port: z.ZodNumber;
54
57
  }, "strip", z.ZodTypeAny, {
55
- port: number;
56
58
  url: string;
57
59
  subdomain: string;
58
- }, {
59
60
  port: number;
61
+ }, {
60
62
  url: string;
61
63
  subdomain: string;
64
+ port: number;
62
65
  }>;
63
66
  export type CommandData = z.infer<typeof Command>;
64
67
  export declare const Command: z.ZodObject<{
@@ -71,18 +74,18 @@ export declare const Command: z.ZodObject<{
71
74
  startedAt: z.ZodNumber;
72
75
  }, "strip", z.ZodTypeAny, {
73
76
  name: string;
74
- cwd: string;
75
77
  args: string[];
76
78
  id: string;
77
79
  startedAt: number;
80
+ cwd: string;
78
81
  sandboxId: string;
79
82
  exitCode: number | null;
80
83
  }, {
81
84
  name: string;
82
- cwd: string;
83
85
  args: string[];
84
86
  id: string;
85
87
  startedAt: number;
88
+ cwd: string;
86
89
  sandboxId: string;
87
90
  exitCode: number | null;
88
91
  }>;
@@ -101,17 +104,19 @@ export declare const SandboxResponse: z.ZodObject<{
101
104
  stoppedAt: z.ZodOptional<z.ZodNumber>;
102
105
  duration: z.ZodOptional<z.ZodNumber>;
103
106
  createdAt: z.ZodNumber;
107
+ cwd: z.ZodString;
104
108
  updatedAt: z.ZodNumber;
105
109
  }, "strip", z.ZodTypeAny, {
106
110
  region: string;
107
- timeout: number;
108
111
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
109
112
  id: string;
110
113
  memory: number;
111
114
  vcpus: number;
112
115
  runtime: string;
116
+ timeout: number;
113
117
  requestedAt: number;
114
118
  createdAt: number;
119
+ cwd: string;
115
120
  updatedAt: number;
116
121
  duration?: number | undefined;
117
122
  startedAt?: number | undefined;
@@ -119,14 +124,15 @@ export declare const SandboxResponse: z.ZodObject<{
119
124
  stoppedAt?: number | undefined;
120
125
  }, {
121
126
  region: string;
122
- timeout: number;
123
127
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
124
128
  id: string;
125
129
  memory: number;
126
130
  vcpus: number;
127
131
  runtime: string;
132
+ timeout: number;
128
133
  requestedAt: number;
129
134
  createdAt: number;
135
+ cwd: string;
130
136
  updatedAt: number;
131
137
  duration?: number | undefined;
132
138
  startedAt?: number | undefined;
@@ -136,14 +142,15 @@ export declare const SandboxResponse: z.ZodObject<{
136
142
  }, "strip", z.ZodTypeAny, {
137
143
  sandbox: {
138
144
  region: string;
139
- timeout: number;
140
145
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
141
146
  id: string;
142
147
  memory: number;
143
148
  vcpus: number;
144
149
  runtime: string;
150
+ timeout: number;
145
151
  requestedAt: number;
146
152
  createdAt: number;
153
+ cwd: string;
147
154
  updatedAt: number;
148
155
  duration?: number | undefined;
149
156
  startedAt?: number | undefined;
@@ -153,14 +160,15 @@ export declare const SandboxResponse: z.ZodObject<{
153
160
  }, {
154
161
  sandbox: {
155
162
  region: string;
156
- timeout: number;
157
163
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
158
164
  id: string;
159
165
  memory: number;
160
166
  vcpus: number;
161
167
  runtime: string;
168
+ timeout: number;
162
169
  requestedAt: number;
163
170
  createdAt: number;
171
+ cwd: string;
164
172
  updatedAt: number;
165
173
  duration?: number | undefined;
166
174
  startedAt?: number | undefined;
@@ -183,17 +191,19 @@ export declare const SandboxAndRoutesResponse: z.ZodObject<{
183
191
  stoppedAt: z.ZodOptional<z.ZodNumber>;
184
192
  duration: z.ZodOptional<z.ZodNumber>;
185
193
  createdAt: z.ZodNumber;
194
+ cwd: z.ZodString;
186
195
  updatedAt: z.ZodNumber;
187
196
  }, "strip", z.ZodTypeAny, {
188
197
  region: string;
189
- timeout: number;
190
198
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
191
199
  id: string;
192
200
  memory: number;
193
201
  vcpus: number;
194
202
  runtime: string;
203
+ timeout: number;
195
204
  requestedAt: number;
196
205
  createdAt: number;
206
+ cwd: string;
197
207
  updatedAt: number;
198
208
  duration?: number | undefined;
199
209
  startedAt?: number | undefined;
@@ -201,14 +211,15 @@ export declare const SandboxAndRoutesResponse: z.ZodObject<{
201
211
  stoppedAt?: number | undefined;
202
212
  }, {
203
213
  region: string;
204
- timeout: number;
205
214
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
206
215
  id: string;
207
216
  memory: number;
208
217
  vcpus: number;
209
218
  runtime: string;
219
+ timeout: number;
210
220
  requestedAt: number;
211
221
  createdAt: number;
222
+ cwd: string;
212
223
  updatedAt: number;
213
224
  duration?: number | undefined;
214
225
  startedAt?: number | undefined;
@@ -221,25 +232,26 @@ export declare const SandboxAndRoutesResponse: z.ZodObject<{
221
232
  subdomain: z.ZodString;
222
233
  port: z.ZodNumber;
223
234
  }, "strip", z.ZodTypeAny, {
224
- port: number;
225
235
  url: string;
226
236
  subdomain: string;
227
- }, {
228
237
  port: number;
238
+ }, {
229
239
  url: string;
230
240
  subdomain: string;
241
+ port: number;
231
242
  }>, "many">;
232
243
  }, "strip", z.ZodTypeAny, {
233
244
  sandbox: {
234
245
  region: string;
235
- timeout: number;
236
246
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
237
247
  id: string;
238
248
  memory: number;
239
249
  vcpus: number;
240
250
  runtime: string;
251
+ timeout: number;
241
252
  requestedAt: number;
242
253
  createdAt: number;
254
+ cwd: string;
243
255
  updatedAt: number;
244
256
  duration?: number | undefined;
245
257
  startedAt?: number | undefined;
@@ -247,21 +259,22 @@ export declare const SandboxAndRoutesResponse: z.ZodObject<{
247
259
  stoppedAt?: number | undefined;
248
260
  };
249
261
  routes: {
250
- port: number;
251
262
  url: string;
252
263
  subdomain: string;
264
+ port: number;
253
265
  }[];
254
266
  }, {
255
267
  sandbox: {
256
268
  region: string;
257
- timeout: number;
258
269
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
259
270
  id: string;
260
271
  memory: number;
261
272
  vcpus: number;
262
273
  runtime: string;
274
+ timeout: number;
263
275
  requestedAt: number;
264
276
  createdAt: number;
277
+ cwd: string;
265
278
  updatedAt: number;
266
279
  duration?: number | undefined;
267
280
  startedAt?: number | undefined;
@@ -269,9 +282,9 @@ export declare const SandboxAndRoutesResponse: z.ZodObject<{
269
282
  stoppedAt?: number | undefined;
270
283
  };
271
284
  routes: {
272
- port: number;
273
285
  url: string;
274
286
  subdomain: string;
287
+ port: number;
275
288
  }[];
276
289
  }>;
277
290
  export declare const CommandResponse: z.ZodObject<{
@@ -285,38 +298,38 @@ export declare const CommandResponse: z.ZodObject<{
285
298
  startedAt: z.ZodNumber;
286
299
  }, "strip", z.ZodTypeAny, {
287
300
  name: string;
288
- cwd: string;
289
301
  args: string[];
290
302
  id: string;
291
303
  startedAt: number;
304
+ cwd: string;
292
305
  sandboxId: string;
293
306
  exitCode: number | null;
294
307
  }, {
295
308
  name: string;
296
- cwd: string;
297
309
  args: string[];
298
310
  id: string;
299
311
  startedAt: number;
312
+ cwd: string;
300
313
  sandboxId: string;
301
314
  exitCode: number | null;
302
315
  }>;
303
316
  }, "strip", z.ZodTypeAny, {
304
317
  command: {
305
318
  name: string;
306
- cwd: string;
307
319
  args: string[];
308
320
  id: string;
309
321
  startedAt: number;
322
+ cwd: string;
310
323
  sandboxId: string;
311
324
  exitCode: number | null;
312
325
  };
313
326
  }, {
314
327
  command: {
315
328
  name: string;
316
- cwd: string;
317
329
  args: string[];
318
330
  id: string;
319
331
  startedAt: number;
332
+ cwd: string;
320
333
  sandboxId: string;
321
334
  exitCode: number | null;
322
335
  };
@@ -333,38 +346,38 @@ export declare const CommandFinishedResponse: z.ZodObject<{
333
346
  exitCode: z.ZodNumber;
334
347
  }, "strip", z.ZodTypeAny, {
335
348
  name: string;
336
- cwd: string;
337
349
  args: string[];
338
350
  id: string;
339
351
  startedAt: number;
352
+ cwd: string;
340
353
  sandboxId: string;
341
354
  exitCode: number;
342
355
  }, {
343
356
  name: string;
344
- cwd: string;
345
357
  args: string[];
346
358
  id: string;
347
359
  startedAt: number;
360
+ cwd: string;
348
361
  sandboxId: string;
349
362
  exitCode: number;
350
363
  }>;
351
364
  }, "strip", z.ZodTypeAny, {
352
365
  command: {
353
366
  name: string;
354
- cwd: string;
355
367
  args: string[];
356
368
  id: string;
357
369
  startedAt: number;
370
+ cwd: string;
358
371
  sandboxId: string;
359
372
  exitCode: number;
360
373
  };
361
374
  }, {
362
375
  command: {
363
376
  name: string;
364
- cwd: string;
365
377
  args: string[];
366
378
  id: string;
367
379
  startedAt: number;
380
+ cwd: string;
368
381
  sandboxId: string;
369
382
  exitCode: number;
370
383
  };
@@ -374,9 +387,9 @@ export declare const LogLine: z.ZodObject<{
374
387
  stream: z.ZodEnum<["stdout", "stderr"]>;
375
388
  data: z.ZodString;
376
389
  }, "strip", z.ZodTypeAny, {
377
- data: string;
378
390
  stream: "stdout" | "stderr";
379
- }, {
380
391
  data: string;
392
+ }, {
381
393
  stream: "stdout" | "stderr";
394
+ data: string;
382
395
  }>;
@@ -16,6 +16,7 @@ exports.Sandbox = zod_1.z.object({
16
16
  stoppedAt: zod_1.z.number().optional(),
17
17
  duration: zod_1.z.number().optional(),
18
18
  createdAt: zod_1.z.number(),
19
+ cwd: zod_1.z.string(),
19
20
  updatedAt: zod_1.z.number(),
20
21
  });
21
22
  exports.SandboxRoute = zod_1.z.object({
@@ -1,4 +1,3 @@
1
- import type { RequestInit, Response } from "node-fetch";
2
1
  import type { Options as RetryOptions } from "async-retry";
3
2
  export interface RequestOptions {
4
3
  onRetry?(error: any, options: RequestOptions): void;
package/dist/command.d.ts CHANGED
@@ -3,8 +3,11 @@ import { Signal } from "./utils/resolveSignal";
3
3
  /**
4
4
  * A command executed in a Sandbox.
5
5
  *
6
- * You can {@link wait} on commands to access their {@link CommandFinished.exitCode}, and
7
- * iterate over their output with {@link logs}.
6
+ * For detached commands, you can {@link wait} to get a {@link CommandFinished} instance
7
+ * with the populated exit code. For non-detached commands, {@link Sandbox.runCommand}
8
+ * automatically waits and returns a {@link CommandFinished} instance.
9
+ *
10
+ * You can iterate over command output with {@link logs}.
8
11
  *
9
12
  * @see {@link Sandbox.runCommand} to start a command.
10
13
  *
@@ -61,15 +64,20 @@ export declare class Command {
61
64
  * to access output as a string.
62
65
  */
63
66
  logs(): AsyncIterable<{
64
- data: string;
65
67
  stream: "stdout" | "stderr";
68
+ data: string;
66
69
  }>;
67
70
  /**
68
71
  * Wait for a command to exit and populate its exit code.
69
72
  *
73
+ * This method is useful for detached commands where you need to wait
74
+ * for completion. For non-detached commands, {@link Sandbox.runCommand}
75
+ * automatically waits and returns a {@link CommandFinished} instance.
76
+ *
70
77
  * ```
71
- * await cmd.wait()
72
- * if (cmd.exitCode != 0) {
78
+ * const detachedCmd = await sandbox.runCommand({ cmd: 'sleep', args: ['5'], detached: true });
79
+ * const result = await detachedCmd.wait();
80
+ * if (result.exitCode !== 0) {
73
81
  * console.error("Something went wrong...")
74
82
  * }
75
83
  * ```
@@ -117,14 +125,16 @@ export declare class Command {
117
125
  /**
118
126
  * A command that has finished executing.
119
127
  *
120
- * Contains the exit code of the command.
128
+ * The exit code is immediately available and populated upon creation.
129
+ * Unlike {@link Command}, you don't need to call wait() - the command
130
+ * has already completed execution.
121
131
  *
122
132
  * @hideconstructor
123
133
  */
124
134
  export declare class CommandFinished extends Command {
125
135
  /**
126
- * The exit code of the command, if available. This is set after
127
- * {@link wait} has returned.
136
+ * The exit code of the command. This is always populated for
137
+ * CommandFinished instances.
128
138
  */
129
139
  exitCode: number;
130
140
  /**
@@ -140,4 +150,13 @@ export declare class CommandFinished extends Command {
140
150
  cmd: CommandData;
141
151
  exitCode: number;
142
152
  });
153
+ /**
154
+ * The wait method is not needed for CommandFinished instances since
155
+ * the command has already completed and exitCode is populated.
156
+ *
157
+ * @deprecated This method is redundant for CommandFinished instances.
158
+ * The exitCode is already available.
159
+ * @returns This CommandFinished instance.
160
+ */
161
+ wait(): Promise<CommandFinished>;
143
162
  }