diff --git a/bun.lockb b/bun.lockb index 6d4f6fd..341bd7d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.test.ts b/index.test.ts index 6bf264d..20efd0f 100644 --- a/index.test.ts +++ b/index.test.ts @@ -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("http://localhost:3000"); - const conn = client["Alice"].subscribe(); + const client = treaty("http://localhost:3000"); + const conn = client.index.subscribe({ query: { userId: "Alice" } }); await new Promise((resolve) => { conn.addEventListener("open", resolve, { once: true }); diff --git a/index.ts b/index.ts index a553842..0fa060b 100644 --- a/index.ts +++ b/index.ts @@ -78,23 +78,23 @@ 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, }, }, }); @@ -102,16 +102,16 @@ const app = new Elysia().use(loggerMiddleware).ws("/:userId", { 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, }, }, }); @@ -119,16 +119,16 @@ const app = new Elysia().use(loggerMiddleware).ws("/:userId", { 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]; diff --git a/package.json b/package.json index e96dc1e..a18c5ae 100644 --- a/package.json +++ b/package.json @@ -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" },