Skip to content

Commit bc882d4

Browse files
committed
📘 doc: document changelog
1 parent 7f8f55c commit bc882d4

File tree

3 files changed

+52
-58
lines changed

3 files changed

+52
-58
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# 1.4.22
22
Improvement:
33
- use imperative check for `replaceURLPath` instead of allocating `new URL`
4+
- reduce ts-ignore/ts-expect-error on promise map handler
45

56
Bug fix:
67
- [#1671](https://github.com/elysiajs/elysia/issues/1671) mount produces incorrect URL path when Elysia instance has prefix option
78
- [https://github.com/elysiajs/elysia/issues/1617](https://github.com/elysiajs/elysia/issues/1617), [#1623](https://github.com/elysiajs/elysia/pull/1623) AOT compilation removes beforeHandle when using arrow function expression
89
- [#1667](https://github.com/elysiajs/elysia/issues/1667) skip body parsing on mount with dynamic mode
10+
- [#1662](https://github.com/elysiajs/elysia/pull/1662) custom thenable fallback in `mapCompactResponse` causing runtime crash with undefined variable
911
- [#1661](https://github.com/elysiajs/elysia/pull/1661), [#1663](https://github.com/elysiajs/elysia/pull/1663) fix SSE double-wrapping bug when returning pre-formatted Response
1012
- ValueError with summary missing types
1113
- Elysia not using Bun.routes by default

src/adapter/bun/handler.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export const mapResponse = (
3737
return new Response(JSON.stringify(response), set as any)
3838

3939
case 'ElysiaFile':
40-
return handleFile(
41-
(response as ElysiaFile).value as File,
42-
set
43-
)
40+
return handleFile((response as ElysiaFile).value as File, set)
4441

4542
case 'File':
4643
return handleFile(response as File, set)
@@ -122,10 +119,8 @@ export const mapResponse = (
122119
)
123120
return handleStream(response as any, set, request) as any
124121

125-
// @ts-expect-error
126-
if (typeof response?.then === 'function')
127-
// @ts-expect-error
128-
return response.then((x) => mapResponse(x, set)) as any
122+
if (typeof (response as Promise<unknown>)?.then === 'function')
123+
return (response as Promise<unknown>).then((x) => mapResponse(x, set)) as any
129124

130125
// @ts-expect-error
131126
if (typeof response?.toResponse === 'function')
@@ -206,10 +201,9 @@ export const mapEarlyResponse = (
206201
return handleResponse(response as Response, set, request)
207202

208203
case 'Promise':
209-
// @ts-ignore
210204
return (response as Promise<unknown>).then((x) =>
211205
mapEarlyResponse(x, set)
212-
)
206+
) as any
213207

214208
case 'Error':
215209
return errorToResponse(response as Error, set)
@@ -262,10 +256,10 @@ export const mapEarlyResponse = (
262256
)
263257
return handleStream(response as any, set, request) as any
264258

265-
// @ts-expect-error
266-
if (typeof response?.then === 'function')
267-
// @ts-expect-error
268-
return response.then((x) => mapEarlyResponse(x, set)) as any
259+
if (typeof (response as Promise<unknown>)?.then === 'function')
260+
return (response as Promise<unknown>).then((x) =>
261+
mapEarlyResponse(x, set)
262+
) as any
269263

270264
// @ts-expect-error
271265
if (typeof response?.toResponse === 'function')
@@ -328,11 +322,10 @@ export const mapEarlyResponse = (
328322
return response as Response
329323

330324
case 'Promise':
331-
// @ts-ignore
332325
return (response as Promise<unknown>).then((x) => {
333326
const r = mapEarlyResponse(x, set)
334327
if (r !== undefined) return r
335-
})
328+
}) as any
336329

337330
case 'Error':
338331
return errorToResponse(response as Error, set)
@@ -381,10 +374,10 @@ export const mapEarlyResponse = (
381374
)
382375
return handleStream(response as any, set, request) as any
383376

384-
// @ts-expect-error
385-
if (typeof response?.then === 'function')
386-
// @ts-expect-error
387-
return response.then((x) => mapEarlyResponse(x, set)) as any
377+
if (typeof (response as Promise<unknown>)?.then === 'function')
378+
return (response as Promise<unknown>).then((x) =>
379+
mapEarlyResponse(x, set)
380+
) as any
388381

389382
// @ts-expect-error
390383
if (typeof response?.toResponse === 'function')
@@ -458,7 +451,7 @@ export const mapCompactResponse = (
458451
return errorToResponse(response as Error)
459452

460453
case 'Promise':
461-
return (response as any as Promise<unknown>).then((x) =>
454+
return (response as Promise<unknown>).then((x) =>
462455
mapCompactResponse(x, request)
463456
) as any
464457

@@ -501,12 +494,12 @@ export const mapCompactResponse = (
501494
)
502495
return handleStream(response as any, undefined, request) as any
503496

504-
// @ts-expect-error
505-
if (typeof response?.then === 'function')
506-
// @ts-expect-error
507-
return response.then((x) => mapCompactResponse(x, request)) as any
497+
if (typeof (response as Promise<unknown>)?.then === 'function')
498+
return (response as Promise<unknown>).then((x) =>
499+
mapCompactResponse(x, request)
500+
) as any
508501

509-
// @ts-expect-error
502+
// @ts-expect-errors
510503
if (typeof response?.toResponse === 'function')
511504
return mapCompactResponse((response as any).toResponse())
512505

@@ -532,15 +525,14 @@ export const errorToResponse = (error: Error, set?: Context['set']) => {
532525
// @ts-expect-error
533526
const raw = error.toResponse()
534527
const targetSet =
535-
set ?? ({ headers: {}, status: 200, redirect: '' } as Context['set'])
528+
set ??
529+
({ headers: {}, status: 200, redirect: '' } as Context['set'])
536530
const apply = (resolved: unknown) => {
537531
if (resolved instanceof Response) targetSet.status = resolved.status
538532
return mapResponse(resolved, targetSet)
539533
}
540534

541-
return typeof raw?.then === 'function'
542-
? raw.then(apply)
543-
: apply(raw)
535+
return typeof raw?.then === 'function' ? raw.then(apply) : apply(raw)
544536
}
545537

546538
return new Response(

src/adapter/web-standard/handler.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Cookie } from '../../cookies'
1313
import { ElysiaCustomStatusResponse } from '../../error'
1414

1515
import type { Context } from '../../context'
16-
import type { AnyLocalHook } from '../../types'
16+
import type { AnyLocalHook, MaybePromise } from '../../types'
1717

1818
const handleElysiaFile = (
1919
file: ElysiaFile,
@@ -149,10 +149,10 @@ export const mapResponse = (
149149
)
150150
return handleStream(response as any, set, request) as any
151151

152-
// @ts-expect-error
153-
if (typeof response?.then === 'function')
154-
// @ts-expect-error
155-
return response.then((x) => mapResponse(x, set)) as any
152+
if (typeof (response as Promise<unknown>)?.then === 'function')
153+
return (response as Promise<unknown>).then((x) =>
154+
mapResponse(x, set)
155+
) as any
156156

157157
// @ts-expect-error
158158
if (typeof response?.toResponse === 'function')
@@ -234,10 +234,9 @@ export const mapEarlyResponse = (
234234
return handleResponse(response as Response, set, request)
235235

236236
case 'Promise':
237-
// @ts-ignore
238237
return (response as Promise<unknown>).then((x) =>
239238
mapEarlyResponse(x, set)
240-
)
239+
) as any
241240

242241
case 'Error':
243242
return errorToResponse(response as Error, set)
@@ -290,10 +289,10 @@ export const mapEarlyResponse = (
290289
)
291290
return handleStream(response as any, set, request) as any
292291

293-
// @ts-expect-error
294-
if (typeof response?.then === 'function')
295-
// @ts-expect-error
296-
return response.then((x) => mapEarlyResponse(x, set)) as any
292+
if (typeof (response as Promise<unknown>)?.then === 'function')
293+
return (response as Promise<unknown>).then((x) =>
294+
mapEarlyResponse(x, set)
295+
) as any
297296

298297
// @ts-expect-error
299298
if (typeof response?.toResponse === 'function')
@@ -357,11 +356,10 @@ export const mapEarlyResponse = (
357356
return response as Response
358357

359358
case 'Promise':
360-
// @ts-ignore
361359
return (response as Promise<unknown>).then((x) => {
362360
const r = mapEarlyResponse(x, set)
363361
if (r !== undefined) return r
364-
})
362+
}) as any
365363

366364
case 'Error':
367365
return errorToResponse(response as Error, set)
@@ -410,10 +408,10 @@ export const mapEarlyResponse = (
410408
)
411409
return handleStream(response as any, set, request) as any
412410

413-
// @ts-expect-error
414-
if (typeof response?.then === 'function')
415-
// @ts-expect-error
416-
return response.then((x) => mapEarlyResponse(x, set)) as any
411+
if (typeof (response as Promise<unknown>)?.then === 'function')
412+
return (response as Promise<unknown>).then((x) =>
413+
mapEarlyResponse(x, set)
414+
) as any
417415

418416
// @ts-expect-error
419417
if (typeof response?.toResponse === 'function')
@@ -534,10 +532,10 @@ export const mapCompactResponse = (
534532
)
535533
return handleStream(response as any, undefined, request) as any
536534

537-
// @ts-expect-error
538-
if (typeof response?.then === 'function')
539-
// @ts-expect-error
540-
return response.then((x) => mapCompactResponse(x, request)) as any
535+
if (typeof (response as Promise<unknown>)?.then === 'function')
536+
return (response as Promise<unknown>).then((x) =>
537+
mapCompactResponse(x, request)
538+
) as any
541539

542540
// @ts-expect-error
543541
if (typeof response?.toResponse === 'function')
@@ -559,21 +557,23 @@ export const mapCompactResponse = (
559557
}
560558
}
561559

562-
export const errorToResponse = (error: Error, set?: Context['set']) => {
563-
// @ts-expect-error
560+
export const errorToResponse = (
561+
error: Error & { toResponse?(): MaybePromise<Response> },
562+
set?: Context['set']
563+
) => {
564564
if (typeof error?.toResponse === 'function') {
565-
// @ts-expect-error
566565
const raw = error.toResponse()
567566
const targetSet =
568-
set ?? ({ headers: {}, status: 200, redirect: '' } as Context['set'])
567+
set ??
568+
({ headers: {}, status: 200, redirect: '' } as Context['set'])
569+
569570
const apply = (resolved: unknown) => {
570571
if (resolved instanceof Response) targetSet.status = resolved.status
571572
return mapResponse(resolved, targetSet)
572573
}
573574

574-
return typeof raw?.then === 'function'
575-
? raw.then(apply)
576-
: apply(raw)
575+
// @ts-ignore
576+
return typeof raw?.then === 'function' ? raw.then(apply) : apply(raw)
577577
}
578578

579579
return new Response(

0 commit comments

Comments
 (0)