bvisor 0.0.1

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 ADDED
@@ -0,0 +1,12 @@
1
+ # bVisor Node SDK
2
+
3
+ Node.js bindings for bVisor. Linux only.
4
+
5
+ ## Dev
6
+
7
+ Requires: Zig 0.16+, Docker
8
+
9
+ ```bash
10
+ npm run dev # builds native binaries (zig build), then runs test.ts in a linux container
11
+ ```
12
+
@@ -0,0 +1 @@
1
+ export { Sandbox } from "./src/sandbox";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sandbox = void 0;
4
+ var sandbox_1 = require("./src/sandbox");
5
+ Object.defineProperty(exports, "Sandbox", { enumerable: true, get: function () { return sandbox_1.Sandbox; } });
@@ -0,0 +1,5 @@
1
+ declare const __external: unique symbol;
2
+ export type External<T> = unknown & {
3
+ [__external]: T;
4
+ };
5
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { External } from "./napi";
2
+ /** FFI contract: typed interface for the native Zig module loaded via require(). */
3
+ export interface NativeModule {
4
+ createSandbox(): External<"Sandbox">;
5
+ sandboxRunCmd(sandbox: External<"Sandbox">, command: string): {
6
+ stdout: External<"Stream">;
7
+ stderr: External<"Stream">;
8
+ };
9
+ streamNext(stream: External<"Stream">): Uint8Array | null;
10
+ }
11
+ export declare const native: NativeModule;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.native = void 0;
4
+ const os_1 = require("os");
5
+ const detect_libc_1 = require("detect-libc");
6
+ if ((0, os_1.platform)() !== "linux") {
7
+ throw new Error("bVisor only supports Linux");
8
+ }
9
+ const libc = (0, detect_libc_1.familySync)() === detect_libc_1.MUSL ? "musl" : "gnu";
10
+ exports.native = require(`@bvisor/linux-${(0, os_1.arch)()}-${libc}`);
@@ -0,0 +1,11 @@
1
+ export declare class Sandbox {
2
+ private ptr;
3
+ constructor();
4
+ runCmd(command: string): Output;
5
+ }
6
+ export interface Output {
7
+ stdoutStream: ReadableStream<Uint8Array>;
8
+ stderrStream: ReadableStream<Uint8Array>;
9
+ stdout: () => Promise<string>;
10
+ stderr: () => Promise<string>;
11
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sandbox = void 0;
4
+ const native_1 = require("./native");
5
+ class Stream {
6
+ constructor(ptr) {
7
+ this.ptr = ptr;
8
+ }
9
+ toReadableStream() {
10
+ const self = this;
11
+ return new ReadableStream({
12
+ async pull(controller) {
13
+ // TODO: make streamNext return a promise
14
+ const chunk = native_1.native.streamNext(self.ptr);
15
+ if (chunk) {
16
+ controller.enqueue(chunk);
17
+ }
18
+ else {
19
+ controller.close();
20
+ }
21
+ },
22
+ });
23
+ }
24
+ }
25
+ class Sandbox {
26
+ constructor() {
27
+ this.ptr = native_1.native.createSandbox();
28
+ }
29
+ runCmd(command) {
30
+ const result = native_1.native.sandboxRunCmd(this.ptr, command);
31
+ return createOutput(new Stream(result.stdout).toReadableStream(), new Stream(result.stderr).toReadableStream());
32
+ }
33
+ }
34
+ exports.Sandbox = Sandbox;
35
+ function createOutput(stdoutStream, stderrStream) {
36
+ return {
37
+ stdoutStream,
38
+ stderrStream,
39
+ stdout: () => new Response(stdoutStream).text(),
40
+ stderr: () => new Response(stderrStream).text(),
41
+ };
42
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "bvisor",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist/"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build",
12
+ "predev": "cd ../../.. && zig build",
13
+ "dev": "docker run --rm -v .:/app -w /app oven/bun:alpine sh -c 'bun install && bun test.ts'"
14
+ },
15
+ "dependencies": {
16
+ "detect-libc": "^2.0.3"
17
+ },
18
+ "optionalDependencies": {
19
+ "@bvisor/linux-arm64-musl": "0.0.1",
20
+ "@bvisor/linux-arm64-gnu": "0.0.1",
21
+ "@bvisor/linux-x64-musl": "0.0.1",
22
+ "@bvisor/linux-x64-gnu": "0.0.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^25.2.0",
26
+ "typescript": "^5.0.0"
27
+ }
28
+ }