From 8b6cbe8536ba7a2508d262b236ef780ef35360d3 Mon Sep 17 00:00:00 2001 From: Kiyo5hi <44930252+Kiyo5hi@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:04:25 -0700 Subject: [PATCH] chore(deps): upgraded to treaty 2 --- bun.lockb | Bin 24788 -> 25314 bytes index.test.ts | 6 +++--- index.ts | 28 ++++++++++++++-------------- package.json | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/bun.lockb b/bun.lockb index 6d4f6fd2fb54b68fe6e1705bbca3cb3f88959c5f..341bd7d09f6aeaf571b529764d03c9ba904a057f 100755 GIT binary patch delta 3021 zcmcImYgAKL7QQ!xnt+#pJR^c43WQ)FB)lOZz^Xum0)jk5UJ6Q;1i^89wF$IX>kDv; zB34BiEzF=JpjB`LMbviHDvVl%B2wDfzqc}LS59&c1(LC8X>1)9{9I(^mp+{{#hP^2o9nac=*Kb{bS zvshuGH=-rtY(xvhsfcEX&#_9HxD(MFu?3NipQy`YNJ-YAxoRhVL3$co&`FuqndA~x z%dg*YN!&qBwQ#TYhKvtwEpFTkEPwD@mtT89ojw#-1Wv~n&!BE2RHGnch37HS=hEk(TxGE9ILeGv1O0YE*M3}H)pOMrk0hh~% zo`VjfysM8q3fyT@#tRNiH;|C-5I;>y<>FFklRtp_EIt^r*z~%^k28!pBgULDzjNXv zQ?sTK#7FOWmFShf=WRf59}6r83eKZ757-W|a2BmB2RZ2s^=Pf&QDDWBlS0Vk z#e#(+1wZiQVWRPcqk(DJ*jV?n|5V3kmkO72(^Z2*k$V)Lt}k}YYrVxc{pfHLQR2<< zS+%YAmlJaP7xJye1r2#~zqUMjP<>of``N+Xb~x{t?SDPB$cNiGf8?KioT#}C8H(NI zPwwWD-G}|6uP!a2j@TYAPG6tQ9~O_~C;!Rucq1ta8B~55@1hQ7uxn3lFX(|Rem3aZ z$-%*if_r?qiasE;!tB!PkGWTw(A?ZsB3ZI-O7M>Z-SN@cKj#(M6OS$!T1@9zeYfq6 z*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E(+FuGHIWM8!DPB3zeBRP zfwc_MAd^TXIM;e&-{`x3ZeCo%K8#2u!IB^_L^-e<~!HMi%-@B{G>L;50bud1MU;^}Jcu zmVud}y4DkasUCIYHemmIU}*pB(bQ@7+~&D4~{S z?F3o_&DzGBj}4QNN*IfAN~dzH-NS|2Xtir%(9y{pYk$%GEMVRJ*Qd}XBi0T?Ev{y) zz2n|L8L{>#XOEEJ$_WbfltE_%*POUeHH}n4Y0@&Ni=SnVTkbr?CPg 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" },