Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce abstraction for websocket #176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@types/node": "^22.2.0",
"@types/randombytes": "^2.0.3",
"@types/react": "^18.3.3",
"@types/ws": "^8.5.12",
"@typescript-eslint/typescript-estree": "^8.0.1",
"@vitest/browser": "^2.0.5",
"@vitest/coverage-v8": "^2.0.5",
Expand Down Expand Up @@ -93,7 +94,8 @@
"prolly-trees": "^1.0.4",
"randombytes": "^2.1.0",
"react": "^18.3.1",
"uuidv7": "^1.0.0"
"uuidv7": "^1.0.0",
"ws": "^8.18.0"
},
"bundle-phobia": {
"max-size": "390kB",
Expand Down
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/runtime/node-sys-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as path from "path";
import * as os from "os";
import * as url from "url";
import { toArrayBuffer } from "./gateways/file/utils.js";
import WebSocket from "ws";

export async function createNodeSysContainer(): Promise<NodeMap> {
// const nodePath = "node:path";
Expand All @@ -30,5 +31,8 @@ export async function createNodeSysContainer(): Promise<NodeMap> {
return toArrayBuffer(rs);
},
writefile: fs.writeFile as NodeMap["writefile"],
websocket: () => {
return WebSocket;
},
};
}
7 changes: 7 additions & 0 deletions src/runtime/sys-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
join: (...args: string[]) => string;
dirname: (path: string) => string;
homedir: () => string;
websocket: () => any;

Check failure on line 25 in src/runtime/sys-container.ts

View workflow job for this annotation

GitHub Actions / Quality Checks

Unexpected any. Specify a different type

Check failure on line 25 in src/runtime/sys-container.ts

View workflow job for this annotation

GitHub Actions / Quality Checks

Unexpected any. Specify a different type
// fileURLToPath: (url: string | URL) => string;
// assert: (condition: unknown, message?: string | Error) => void;
}
Expand Down Expand Up @@ -90,6 +91,7 @@
unlink: () => Promise.reject(new Error("SysContainer:unlink is not available in seeded state")),
writefile: () => Promise.reject(new Error("SysContainer:writefile is not available in seeded state")),
stat: () => Promise.reject(new Error("SysContainer:stat is not available in seeded state")),
websocket: () => Promise.reject(new Error("SysContainer:websocket is not available in seeded state")),
};

// readonly id = uuidv4();
Expand Down Expand Up @@ -190,6 +192,11 @@
return throwFalsy(this.freight).homedir();
};

websocket = () => {
this.logSeeded("websocket");
return throwFalsy(this.freight).websocket();
};

logSeeded(method: string) {
if (this.freight.state === "seeded") {
const err = new Error();
Expand Down
Loading