@gigadrive/sdk 0.9.4 → 0.10.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 +52 -0
- package/dist/index.d.mts +1262 -4
- package/dist/index.d.ts +1262 -4
- package/dist/index.js +1549 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1525 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -327,6 +327,58 @@ await jobs.consume(async (job) => processJob(job.id), { maxMessages: 10, stopWhe
|
|
|
327
327
|
|
|
328
328
|
`client.queues` exposes the full REST surface (queues, messages, dead letters, schedules), and `createWorkflowQueue()` runs the [Workflow SDK](https://workflow-sdk.dev) on Gigadrive Network queues.
|
|
329
329
|
|
|
330
|
+
## microVMs
|
|
331
|
+
|
|
332
|
+
microVMs are isolated Linux machines you create on demand: run commands, move
|
|
333
|
+
files in and out, and expose ports on public preview URLs. Use them for code
|
|
334
|
+
execution, agent sandboxes, CI steps and previews.
|
|
335
|
+
|
|
336
|
+
```ts
|
|
337
|
+
import { MicroVM } from '@gigadrive/sdk';
|
|
338
|
+
|
|
339
|
+
await using vm = await MicroVM.create({ image: 'node22', ports: [3000], timeout: '10m' });
|
|
340
|
+
|
|
341
|
+
await vm.files.write('server.js', 'require("http").createServer((_, r) => r.end("hi")).listen(3000)');
|
|
342
|
+
const { exitCode, stdout } = await vm.run('node --version');
|
|
343
|
+
const server = await vm.spawn('node', ['server.js']);
|
|
344
|
+
console.log(await vm.waitForPort(3000)); // https://3000-<slug>.vm.gigadrive.app
|
|
345
|
+
// Leaving the block stops the microVM.
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
`MicroVM.create` resolves its client like `GigadriveClient` (pass `client` to use
|
|
349
|
+
your own) and its application from `applicationId`, the client's
|
|
350
|
+
`applicationId` or `GIGADRIVE_APPLICATION_ID`. Inside a Gigadrive deployment
|
|
351
|
+
nothing needs configuring. Built-in images: `node22`, `node24`, `python3.13`,
|
|
352
|
+
`python3.12`, `bun1`, `debian12`, `ubuntu24.04`.
|
|
353
|
+
|
|
354
|
+
| Task | Call |
|
|
355
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
356
|
+
| Create, connect, list | `MicroVM.create({ image, vcpus, memoryMb, diskMb, timeout, ports, env, metadata, network })`, `MicroVM.get(id)`, `for await (const vm of MicroVM.list())` |
|
|
357
|
+
| Run and wait | `vm.run('ls -la')`, `vm.run('npm', ['test'], { cwd, env, user, sudo, timeout, onStdout, onStderr, stdin, throwOnError, signal })` → `{ exitCode, signal, timedOut, stdout, stderr, truncated, durationMs }` |
|
|
358
|
+
| Run in the background | `vm.spawn(cmd, args, { stdin, pty, onStdout })` → `Command`: `logs()`, `output()`, `stdout()`, `stderr()`, `wait()`, `kill(signal)`, `write(data)`, `end()`, `resize(cols, rows)` |
|
|
359
|
+
| Reattach | `vm.commands.get(commandId)`, `vm.commands.list()` |
|
|
360
|
+
| Files | `vm.files.write(path, string \| Uint8Array \| Blob \| ReadableStream)`, `writeMany`, `read`, `readText`, `readStream`, `list(path, { recursive })`, `stat`, `exists`, `mkdir`, `remove`, `move` |
|
|
361
|
+
| Ports | `vm.url(port)`, `vm.waitForPort(port)` |
|
|
362
|
+
| Lifetime | `vm.extendTimeout('30m')`, `vm.stop()`, `vm.delete()`, `await using vm = ...` |
|
|
363
|
+
| Images | `client.microvms.images.create({ name, from: 'python:3.13' \| { dockerfile } })`, `.waitUntilReady(id)`, `.list()`, `.get(id)`, `.delete(id)` |
|
|
364
|
+
|
|
365
|
+
Command output stays in the microVM, so `command.logs()` can be read from
|
|
366
|
+
another process with `vm.commands.get(id)`, and a dropped connection resumes
|
|
367
|
+
at the next unread byte. A non-zero exit code is a normal result; pass
|
|
368
|
+
`throwOnError: true` to get a `CommandFailedError`. Other typed errors:
|
|
369
|
+
`MicroVmNotRunningError`, `MicroVmNotFoundError`, `MicroVmFileNotFoundError`,
|
|
370
|
+
`MicroVmQuotaExceededError`, `MicroVmBusyError`, `MicroVmUnreachableError`,
|
|
371
|
+
`MicroVmImageNotReadyError`, `MicroVmPortNotExposedError`,
|
|
372
|
+
`MicroVmTimeoutError`, `MicroVmStartError` and `MicroVmImageBuildError`.
|
|
373
|
+
Reads and log streams are retried with backoff while a microVM answers
|
|
374
|
+
`microvm_busy`. A microVM lives at most 24 hours (`MICROVM_MAX_TIMEOUT_MS`),
|
|
375
|
+
or less on your plan.
|
|
376
|
+
|
|
377
|
+
`client.microvms` is the low-level REST surface, one method per route
|
|
378
|
+
(`create`, `list`, `listAll`, `get`, `extendTimeout`, `stop`, `delete`,
|
|
379
|
+
`commands.*`, `files.*`, `images.*`). The SDK uses only `fetch`, so it runs in
|
|
380
|
+
Node.js 18+, Bun, Deno, edge runtimes and Gigadrive Functions.
|
|
381
|
+
|
|
330
382
|
## Pagination
|
|
331
383
|
|
|
332
384
|
List endpoints accept `page` / `perPage` / `cursor` and return `{ items, total }`
|