Skip to content

Commit 0792b06

Browse files
committed
🔧 fix: day 1 patch
1 parent fc9b3a6 commit 0792b06

File tree

18 files changed

+550
-150
lines changed

18 files changed

+550
-150
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# 1.3.1 - 8 May 2025
2+
Bug fix:
3+
- [#1200](https://github.com/elysiajs/elysia/issues/1200) limited Bun Router to supported method
4+
- [#1199](https://github.com/elysiajs/elysia/issues/1199) object are not normalized when t.Transform is provided
5+
- [#1198](https://github.com/elysiajs/elysia/issues/1198), [#1188](https://github.com/elysiajs/elysia/issues/1188), [#1186](https://github.com/elysiajs/elysia/issues/1186) exclude wildcard route from Bun router
6+
- [#1197](https://github.com/elysiajs/elysia/issues/1197) leave incorrect union field as-is
7+
- [#1195](https://github.com/elysiajs/elysia/issues/1195) invalid onAfterHandle typing
8+
- [#1194](https://github.com/elysiajs/elysia/issues/1194) normalize array response
9+
- [#1193](https://github.com/elysiajs/elysia/issues/1193) undefine value.schema.noValidate
10+
- [#1192](https://github.com/elysiajs/elysia/issues/1192) using a macro inside a group does not call the handler when using the `precompile` option
11+
- [#1190](https://github.com/elysiajs/elysia/issues/1190) derive and resolve handlers not being executed on WS context
12+
- [#1189](https://github.com/elysiajs/elysia/issues/1189) Type Inference Issue with Eden Treaty Group Endpoints
13+
- [#1185](https://github.com/elysiajs/elysia/issues/1185) path is missing from Context when Bun System Router is used
14+
- [#1184](https://github.com/elysiajs/elysia/issues/1184) Missing `mapEarlyResponse` on Bun System Router
15+
16+
Change:
17+
- update `exact-mirror` to `0.1.2`
18+
119
# 1.3.0 - 5 May 2025
220
Feature:
321
- add `exactMirror`

bun.lock

Lines changed: 173 additions & 67 deletions
Large diffs are not rendered by default.

example/a.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { Elysia, t } from '../src'
2+
import { req } from '../test/utils'
23

34
const app = new Elysia()
4-
.get('/', ({ request }) => {
5-
request.url
5+
.onRequest(() => 'a')
6+
.get('/:hash', async ({ params: { hash }, error, set }) => {
7+
const file = Bun.file('example/teapot.webp')
8+
9+
return file
610
})
711
.listen(3000)
812

9-
// console.log(app.routes[0].compile().toString())
13+
console.log(app.routes[0].compile().toString())

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",
@@ -179,7 +179,7 @@
179179
},
180180
"dependencies": {
181181
"cookie": "^1.0.2",
182-
"exact-mirror": "0.1.1",
182+
"exact-mirror": "0.1.2",
183183
"fast-decode-uri-component": "^1.0.1"
184184
},
185185
"devDependencies": {

src/adapter/bun/compose.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ELYSIA_TRACE } from '../../trace'
77

88
import type { AnyElysia } from '../..'
99
import type { InternalRoute } from '../../types'
10+
import { mapEarlyResponse } from './handler'
1011

1112
const allocateIf = (value: string, condition: unknown) =>
1213
condition ? value : ''
@@ -108,6 +109,7 @@ export const createBunRouteHandler = (app: AnyElysia, route: InternalRoute) => {
108109
`decorator=data.decorator,` +
109110
'redirect=data.redirect,' +
110111
'route=data.route,' +
112+
'mapEarlyResponse=data.mapEarlyResponse,' +
111113
allocateIf('randomId=data.randomId,', hasTrace) +
112114
allocateIf(`ELYSIA_REQUEST_ID=data.ELYSIA_REQUEST_ID,`, hasTrace) +
113115
allocateIf(`ELYSIA_TRACE=data.ELYSIA_TRACE,`, hasTrace) +
@@ -147,6 +149,7 @@ export const createBunRouteHandler = (app: AnyElysia, route: InternalRoute) => {
147149
randomId: hasTrace ? randomId : undefined,
148150
ELYSIA_TRACE: hasTrace ? ELYSIA_TRACE : undefined,
149151
ELYSIA_REQUEST_ID: hasTrace ? ELYSIA_REQUEST_ID : undefined,
150-
trace: hasTrace ? app.event.trace?.map((x) => x?.fn ?? x) : undefined
152+
trace: hasTrace ? app.event.trace?.map((x) => x?.fn ?? x) : undefined,
153+
mapEarlyResponse: mapEarlyResponse
151154
})
152155
}

src/adapter/bun/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ const getPossibleParams = (path: string) => {
6565
return routes
6666
}
6767

68+
const supportedMethods = {
69+
GET: true,
70+
HEAD: true,
71+
OPTIONS: true,
72+
DELETE: true,
73+
PATCH: true,
74+
POST: true,
75+
PUT: true
76+
} as const
77+
6878
const mapRoutes = (app: AnyElysia) => {
6979
if (!app.config.aot || !app.config.systemRouter) return undefined
7080

@@ -96,7 +106,12 @@ const mapRoutes = (app: AnyElysia) => {
96106

97107
const method = route.method
98108

99-
if ((method === 'GET' && `WS_${route.path}` in tree) || method === 'WS')
109+
if (
110+
(method === 'GET' && `WS_${route.path}` in tree) ||
111+
method === 'WS' ||
112+
route.path.charCodeAt(route.path.length - 1) === 42 ||
113+
!(method in supportedMethods)
114+
)
100115
continue
101116

102117
if (method === 'ALL') {
@@ -375,7 +390,7 @@ export const BunAdapter: ElysiaAdapter = {
375390
...(app.event.error ?? []).map((x) =>
376391
typeof x === 'function' ? x : x.fn
377392
)
378-
]
393+
].filter((x) => x)
379394

380395
const handleErrors = !errorHandlers.length
381396
? () => {}

src/compose.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ const composeCleaner = ({
192192
}) => {
193193
if (!normalize || !schema.Clean || schema.hasAdditionalProperties) return ''
194194

195-
if (!ignoreTryCatch && (normalize === true || normalize === 'exactMirror'))
195+
if (normalize === true || normalize === 'exactMirror') {
196+
if (ignoreTryCatch)
197+
return `${name}=validator.${typeAlias}.Clean(${name})\n`
198+
196199
return (
197200
`try{` +
198201
`${name}=validator.${typeAlias}.Clean(${name})\n` +
199-
`}catch{` +
200-
// (schema.isOptional
201-
// ? ''
202-
// : `throw new ValidationError('${type}',validator.${typeAlias},${name})`) +
203-
`}`
202+
`}catch{}`
204203
)
204+
}
205205

206206
if (normalize === 'typebox')
207207
return `${name}=validator.${typeAlias}.Clean(${name})\n`
@@ -241,7 +241,7 @@ const composeValidationFactory = ({
241241
for (const [status, value] of Object.entries(validator.response!)) {
242242
code += `\ncase ${status}:if(${name} instanceof Response)break\n`
243243

244-
const noValidate = value.schema.noValidate === true
244+
const noValidate = value.schema?.noValidate === true
245245

246246
const appliedCleaner = noValidate || hasSanitize
247247

@@ -277,16 +277,12 @@ const composeValidationFactory = ({
277277
: `throw new ValidationError('response',validator.response[${status}],${name})`) +
278278
`}`
279279
else {
280+
if (!appliedCleaner) code += clean()
281+
280282
if (!noValidate)
281283
code +=
282-
`if(validator.response[${status}].Check(${name})===false){` +
283-
'c.set.status=422\n' +
284-
(applyErrorCleaner
285-
? `${clean()}\n` +
286-
`if(validator.response[${status}].Check(${name})===false)`
287-
: '') +
288-
`throw new ValidationError('response',validator.response[${status}],${name})` +
289-
'}' +
284+
`if(validator.response[${status}].Check(${name})===false)` +
285+
`throw new ValidationError('response',validator.response[${status}],${name})\n` +
290286
`c.set.status=${status}\n`
291287
}
292288

@@ -1213,7 +1209,7 @@ export const composeHandler = ({
12131209
if (validator.headers.isOptional)
12141210
fnLiteral += `if(isNotEmpty(c.headers)){`
12151211

1216-
if (validator.body?.schema.noValidate !== true)
1212+
if (validator.body?.schema?.noValidate !== true)
12171213
fnLiteral +=
12181214
`if(validator.headers.Check(c.headers) === false){` +
12191215
validation.validate('headers') +
@@ -1245,7 +1241,7 @@ export const composeHandler = ({
12451241
fnLiteral += `c.params['${key}']??=${parsed}\n`
12461242
}
12471243

1248-
if (validator.params?.schema.noValidate !== true)
1244+
if (validator.params?.schema?.noValidate !== true)
12491245
fnLiteral +=
12501246
`if(validator.params.Check(c.params)===false){` +
12511247
validation.validate('params') +
@@ -1285,7 +1281,7 @@ export const composeHandler = ({
12851281
if (validator.query.isOptional)
12861282
fnLiteral += `if(isNotEmpty(c.query)){`
12871283

1288-
if (validator.query?.schema.noValidate !== true)
1284+
if (validator.query?.schema?.noValidate !== true)
12891285
fnLiteral +=
12901286
`if(validator.query.Check(c.query)===false){` +
12911287
validation.validate('query') +
@@ -1355,7 +1351,7 @@ export const composeHandler = ({
13551351
normalize
13561352
})
13571353

1358-
if (validator.body?.schema.noValidate !== true) {
1354+
if (validator.body?.schema?.noValidate !== true) {
13591355
if (validator.body.isOptional)
13601356
fnLiteral +=
13611357
`if(isNotEmptyObject&&validator.body.Check(c.body)===false){` +
@@ -1375,7 +1371,7 @@ export const composeHandler = ({
13751371
normalize
13761372
})
13771373

1378-
if (validator.body?.schema.noValidate !== true) {
1374+
if (validator.body?.schema?.noValidate !== true) {
13791375
if (validator.body.isOptional)
13801376
fnLiteral +=
13811377
`if(isNotEmptyObject&&validator.body.Check(c.body)===false){` +
@@ -1517,7 +1513,7 @@ export const composeHandler = ({
15171513
if (cookieValidator.isOptional)
15181514
fnLiteral += `if(isNotEmpty(c.cookie)){`
15191515

1520-
if (validator.body?.schema.noValidate !== true) {
1516+
if (validator.body?.schema?.noValidate !== true) {
15211517
fnLiteral +=
15221518
`if(validator.cookie.Check(cookieValue)===false){` +
15231519
validation.validate('cookie', 'cookieValue') +
@@ -2034,7 +2030,7 @@ export const composeHandler = ({
20342030
'"use strict";\n' + fnLiteral
20352031
)({
20362032
handler,
2037-
hooks: lifeCycleToFn(hooks),
2033+
hooks: lifeCycleToFn({ ...hooks }),
20382034
validator: hasValidation ? validator : undefined,
20392035
// @ts-expect-error
20402036
handleError: app.handleError,
@@ -2215,6 +2211,7 @@ export const composeGeneralHandler = (app: AnyElysia) => {
22152211
let findDynamicRoute = router.http.root.WS
22162212
? `const route=router.find(r.method === "GET" && r.headers.get('upgrade')==='websocket'?'WS':r.method,p)`
22172213
: `const route=router.find(r.method,p)`
2214+
22182215
findDynamicRoute += router.http.root.ALL ? '??router.find("ALL",p)\n' : '\n'
22192216

22202217
findDynamicRoute += error404.code
@@ -2242,7 +2239,7 @@ export const composeGeneralHandler = (app: AnyElysia) => {
22422239
if ('WS' in methods)
22432240
switchMap +=
22442241
`if(r.headers.get('upgrade')==='websocket')` +
2245-
`return ht[${methods.WS}].handler(c)\n`
2242+
`return ht[${methods.WS}].composed(c)\n`
22462243

22472244
if ('GET' in methods)
22482245
switchMap += `return ht[${methods.GET}].composed(c)\n`

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ import type {
152152
PrettifySchema,
153153
MergeStandaloneSchema,
154154
IsNever,
155-
DocumentDecoration
155+
DocumentDecoration,
156+
AfterHandler
156157
} from './types'
157158

158159
export type AnyElysia = Elysia<any, any, any, any, any, any, any>
@@ -769,6 +770,7 @@ export default class Elysia<
769770
)
770771

771772
this.applyMacro(localHook)
773+
772774
const hooks = isNotEmpty(this.event)
773775
? mergeHook(this.event, localHookToLifeCycleStore(localHook))
774776
: lifeCycleToArray(localHookToLifeCycleStore(localHook))
@@ -1874,7 +1876,7 @@ export default class Elysia<
18741876
*/
18751877
onAfterHandle<const Schema extends RouteSchema>(
18761878
handler: MaybeArray<
1877-
OptionalHandler<
1879+
AfterHandler<
18781880
MergeSchema<
18791881
Schema,
18801882
MergeSchema<

src/schema.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const isOptional = (
7676

7777
export const hasAdditionalProperties = (
7878
_schema: TAnySchema | TypeCheck<any> | ElysiaTypeCheck<any>
79-
) => {
79+
): boolean => {
8080
if (!_schema) return false
8181

8282
// @ts-expect-error private property
@@ -112,6 +112,9 @@ export const hasAdditionalProperties = (
112112
return false
113113
}
114114

115+
if (schema.type === 'array' && schema.items && !Array.isArray(schema.items))
116+
return hasAdditionalProperties(schema.items)
117+
115118
return false
116119
}
117120

@@ -834,7 +837,7 @@ export const getSchemaValidator = <T extends TSchema | string | undefined>(
834837
Encode: (value: unknown) => Value.Encode(schema, value),
835838
get hasAdditionalProperties() {
836839
if ('~hasAdditionalProperties' in this)
837-
return this['~hasAdditionalProperties']
840+
return this['~hasAdditionalProperties'] as boolean
838841

839842
return (this['~hasAdditionalProperties'] =
840843
hasAdditionalProperties(schema))

src/sucrose.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,10 @@ export const inferBodyReference = (
462462
continue
463463
}
464464

465-
if (!inference.query && access('query', alias)) inference.query = true
466-
467465
if (
468466
!inference.query &&
469-
(code.includes('return ' + alias) ||
467+
(access('query', alias) ||
468+
code.includes('return ' + alias) ||
470469
code.includes('return ' + alias + '.query'))
471470
)
472471
inference.query = true
@@ -483,6 +482,10 @@ export const inferBodyReference = (
483482
if (!inference.server && access('server', alias))
484483
inference.server = true
485484

485+
if (!inference.route && access('route', alias)) inference.route = true
486+
if (!inference.url && access('url', alias)) inference.url = true
487+
if (!inference.path && access('path', alias)) inference.path = true
488+
486489
if (
487490
inference.query &&
488491
inference.headers &&
@@ -491,7 +494,8 @@ export const inferBodyReference = (
491494
inference.set &&
492495
inference.server &&
493496
inference.route &&
494-
inference.url
497+
inference.url &&
498+
inference.path
495499
)
496500
break
497501
}

0 commit comments

Comments
 (0)