Skip to content

Commit

Permalink
chore(deps): upgraded to treaty 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyo5hi committed Apr 4, 2024
1 parent 3bbc0ad commit 8b6cbe8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test, expect } from "bun:test";
import { randomUUID } from "node:crypto";
import { edenTreaty } from "@elysiajs/eden";
import { treaty } from "@elysiajs/eden";

import type { AppType } from ".";

test("isHealthy", async () => {
const client = edenTreaty<AppType>("http://localhost:3000");
const conn = client["Alice"].subscribe();
const client = treaty<AppType>("http://localhost:3000");
const conn = client.index.subscribe({ query: { userId: "Alice" } });

await new Promise<void>((resolve) => {
conn.addEventListener("open", resolve, { once: true });
Expand Down
28 changes: 14 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,57 +78,57 @@ async function processResponse(
}
}

const app = new Elysia().use(loggerMiddleware).ws("/:userId", {
const app = new Elysia().use(loggerMiddleware).ws("/", {
body: Type.Union(requestSchemas),
response: Type.Union([...responseSchemas, ServerErrorSchema]),
params: Type.Object({
query: Type.Object({
userId: Type.String(),
}),
open: async (ws) => {
if (ws.data.params.userId in ReservedUserId) {
if (ws.data.query.userId in ReservedUserId) {
ws.send({
requestId: "0",
to: ReservedUserId.UNKNOWN,
event: "error",
data: {
name: "ReservedUserIdError",
message: `userId is reserved: ${ws.data.params.userId}`,
message: `userId is reserved: ${ws.data.query.userId}`,
details: {
userId: ws.data.params.userId,
userId: ws.data.query.userId,
},
},
});
ws.close();
return;
}

if (connectionMap.has(ws.data.params.userId)) {
if (connectionMap.has(ws.data.query.userId)) {
ws.send({
requestId: "0",
to: ReservedUserId.UNKNOWN,
event: "error",
data: {
name: "UserConflictError",
message: `user already connected: ${ws.data.params.userId}`,
message: `user already connected: ${ws.data.query.userId}`,
details: {
userId: ws.data.params.userId,
userId: ws.data.query.userId,
},
},
});
ws.close();
return;
}

connectionLogger.info(`connection opened: ${ws.data.params.userId}`);
connectionMap.set(ws.data.params.userId, ws as Connection);
connectionLogger.info(`connection opened: ${ws.data.query.userId}`);
connectionMap.set(ws.data.query.userId, ws as Connection);
},
close: async (ws) => {
connectionLogger.info(`connection closed: ${ws.data.params.userId}`);
connectionMap.delete(ws.data.params.userId);
connectionLogger.info(`connection closed: ${ws.data.query.userId}`);
connectionMap.delete(ws.data.query.userId);
},
message: async (ws, msg) => {
if (ws.data.params.userId !== msg.from) {
throw new UserIdMismatchError(ws.data.params.userId, msg.from);
if (ws.data.query.userId !== msg.from) {
throw new UserIdMismatchError(ws.data.query.userId, msg.from);
}

const handler = handlers[msg.event];
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"module": "index.ts",
"type": "module",
"devDependencies": {
"@biomejs/biome": "1.6.1",
"@elysiajs/eden": "^1.0.7",
"@sinclair/typebox-codegen": "^0.9.8",
"@biomejs/biome": "1.6.4",
"@elysiajs/eden": "^1.0.11",
"@sinclair/typebox-codegen": "^0.9.9",
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"elysia": "^1.0.7",
"elysia": "^1.0.11",
"pino": "^8.19.0",
"pino-pretty": "^11.0.0"
},
Expand Down

0 comments on commit 8b6cbe8

Please sign in to comment.