diff --git a/bun.lock b/bun.lock index 1df2679..2e32397 100644 --- a/bun.lock +++ b/bun.lock @@ -14,7 +14,7 @@ "@eslint/plugin-kit": "^0.7.2", "@types/bun": "^1.3.14", "@types/node": "^22.10.2", - "elysia": "2.0.0-beta.4", + "elysia": "2.0.0-beta.21", "eslint": "9.17.0", "tsdown": "^0.22.3", "tsx": "^4.19.2", @@ -22,7 +22,7 @@ "vitest": "^4.1.9", }, "peerDependencies": { - "elysia": ">= 2.0.0-beta.1", + "elysia": ">= 2.0.0-beta.11", }, }, }, @@ -283,7 +283,7 @@ "dts-resolver": ["dts-resolver@3.0.0", "", { "peerDependencies": { "oxc-resolver": ">=11.0.0" }, "optionalPeers": ["oxc-resolver"] }, "sha512-1T1f+z+4tl9XD+m+0HBgWoL/nm0bOIffyWaUuUSBlFg/86IWvfx+wjNaO/ybU0AJzG9/Mi5hBUgGV6zCmWEN7Q=="], - "elysia": ["elysia@2.0.0-beta.4", "", { "dependencies": { "deuri": "^3.0.0", "memoirist": "1.2.2" }, "peerDependencies": { "@types/bun": ">= 1.3.0", "exact-mirror": ">= 1.2.2", "openapi-types": ">= 12.0.0", "typebox": ">= 1.3.0", "typescript": ">= 5.7.0" }, "optionalPeers": ["@types/bun", "openapi-types", "typescript"] }, "sha512-pFjjP+uANO9kMLvN3QKQphCH5atwOTCC/lMhvj+fDhV3BWiwGTDNDyZPMpu0nmtcUIgjrlVyDajhuzMkYoBUGg=="], + "elysia": ["elysia@2.0.0-beta.21", "", { "dependencies": { "deuri": "^3.0.0", "memoirist": "1.2.2" }, "peerDependencies": { "@types/bun": ">= 1.3.0", "exact-mirror": ">= 1.2.6", "openapi-types": ">= 12.0.0", "typebox": ">= 1.3.0", "typescript": ">= 5.7.0" }, "optionalPeers": ["@types/bun", "typescript"] }, "sha512-We7n78g3a3TqRONxYqnVZ0qhKgB58anw6tiFZetO/+etFbgqR4HN9V62Z0XI9u7Isy4EfMRkRrsWYjSo5YsQtg=="], "empathic": ["empathic@2.0.1", "", {}, "sha512-YGRs8knHhKHVShLkFET/rWAU8kmHbOV5LwN938RHI0pljAJ1Gf6SzXsSmRaEzcXTtOOmVqJ5+WtQPL5uigY50Q=="], @@ -411,6 +411,8 @@ "obug": ["obug@2.1.4", "", {}, "sha512-4a+OsYv9UktOJKE+l1A4OufDgdRF9PifWj+tJnHURo/P+WOxpG4GzUFL9qCalmWauao6ogiG+QvnCovwPoyAWA=="], + "openapi-types": ["openapi-types@12.1.3", "", {}, "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw=="], + "optionator": ["optionator@0.9.4", "", { "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" } }, "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g=="], "p-limit": ["p-limit@3.1.0", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="], diff --git a/package.json b/package.json index 5090f4e..1dbc939 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "srvx": "^0.12.4" }, "peerDependencies": { - "elysia": ">= 2.0.0-beta.1" + "elysia": ">= 2.0.0-beta.11" }, "devDependencies": { "@elysia/cors": "^1.4.0", @@ -24,7 +24,7 @@ "@eslint/plugin-kit": "^0.7.2", "@types/bun": "^1.3.14", "@types/node": "^22.10.2", - "elysia": "2.0.0-beta.4", + "elysia": "2.0.0-beta.21", "eslint": "9.17.0", "tsdown": "^0.22.3", "tsx": "^4.19.2", diff --git a/src/adapter.ts b/src/adapter.ts index 82f98c2..a8dd253 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -36,8 +36,6 @@ export const createNodeAdapter = ( createAdapter({ ...options, ...WebStandardAdapter, - name: '@elysia/node', - websocket: !!ws, response: { compact: mapCompactResponse, map: mapResponse diff --git a/src/handle.ts b/src/handle.ts index b8447b6..c7e83e3 100644 --- a/src/handle.ts +++ b/src/handle.ts @@ -116,7 +116,7 @@ function mapResponseWithSet( return handleFile(response as Blob, set, request) case 'ElysiaStatus': - set.status = (response as ElysiaStatus<200>).code + set.status = (response as ElysiaStatus<200>).status if ((response as ElysiaStatus<200>).headers) Object.assign( materializeSetHeaders(set), @@ -178,7 +178,7 @@ export function mapResponse( return mapResponseWithSet(response, set, request, owned) if (response instanceof ElysiaStatus) { - set.status = (response as ElysiaStatus<200>).code + set.status = (response as ElysiaStatus<200>).status if ((response as ElysiaStatus<200>).headers) Object.assign(set.headers, (response as ElysiaStatus<200>).headers) @@ -252,7 +252,7 @@ export function mapCompactResponse( return mapResponse( (response as ElysiaStatus<200>).response, { - status: (response as ElysiaStatus<200>).code, + status: (response as ElysiaStatus<200>).status, headers: (response as ElysiaStatus<200>).headers ? Object.assign( nullObject(), @@ -349,7 +349,7 @@ function mapFallback( if (response instanceof ElysiaStatus) { if (set) { - set.status = response.code + set.status = response.status if (response.headers) set.headers = { ...set.headers, ...response.headers } return mapResponse(response.response, set, request, owned) @@ -357,7 +357,7 @@ function mapFallback( return mapResponse( (response as ElysiaStatus<200>).response, { - status: (response as ElysiaStatus<200>).code, + status: (response as ElysiaStatus<200>).status, headers: response.headers ? { ...response.headers } : {} } as Context['set'], request, diff --git a/test/adapter.test.ts b/test/adapter.test.ts index 31d6ffa..0676dec 100644 --- a/test/adapter.test.ts +++ b/test/adapter.test.ts @@ -1,10 +1,42 @@ import assert from 'node:assert/strict' import test from 'node:test' +import { Elysia, status } from 'elysia' + import { node as http } from '../src' import { node as websocket } from '../src/websocket' test('configures websocket support', () => { - assert.equal(http().websocket, false) - assert.equal(websocket().websocket, true) + assert.equal(http().setup, undefined) + assert.equal(typeof websocket().setup, 'function') +}) + +test('keeps the status code of an ElysiaStatus', async () => { + const app = new Elysia({ adapter: http() }) + .get('/value', () => status(201, { created: true })) + .get('/text', () => status(418, "I'm a teapot")) + .get('/thrown', () => { + throw status(409, 'conflict') + }) + .get('/set', ({ set }) => { + set.headers['x-test'] = '1' + return status(202, 'accepted') + }) + .guard({ beforeHandle: ({ status }) => status(401) }, (app) => + app.get('/guarded', () => 'secret') + ) + + for (const [path, code] of [ + ['/value', 201], + ['/text', 418], + ['/thrown', 409], + ['/set', 202], + ['/guarded', 401] + ] as const) { + const response = await app.handle( + new Request(`http://localhost${path}`) + ) + + assert.equal(response.status, code, path) + } })