File tree Expand file tree Collapse file tree 5 files changed +89
-23
lines changed Expand file tree Collapse file tree 5 files changed +89
-23
lines changed Original file line number Diff line number Diff line change 1
- # 1.3.16 - 22 Aug 2025
1
+ # 1.3.17 - 23 Aug 2025
2
+ Bug fix:
3
+ - [ #1353 ] ( https://github.com/elysiajs/elysia/issues/1353 ) normalize encodeSchema with Transform
4
+
5
+ # 1.3.16 - 23 Aug 2025
2
6
Improvement:
3
7
- ` sse ` now infer type
4
8
- ` sse ` now accepts ` ReadableStream ` to return stream as ` text/event-stream `
Original file line number Diff line number Diff line change 1
1
import { Elysia , sse , t } from '../src'
2
- import { streamResponse } from '../src/adapter/utils'
3
2
import { req } from '../test/utils'
4
3
5
- const app = new Elysia ( )
6
- . get ( '/' , function ( ) {
7
- return new ReadableStream ( {
8
- async start ( controller ) {
9
- controller . enqueue ( 'a' )
10
- await Bun . sleep ( 100 )
11
- controller . enqueue ( 'b' )
12
- await Bun . sleep ( 100 )
13
- controller . close ( )
14
- }
4
+ const app = new Elysia ( ) . get (
5
+ '/' ,
6
+ ( ) => ( {
7
+ hasMore : true ,
8
+ total : 1 ,
9
+ offset : 0 ,
10
+ totalPages : 1 ,
11
+ currentPage : 1 ,
12
+ items : [ { username : 'Bob' , secret : 'shhh' } ]
13
+ } ) ,
14
+ {
15
+ response : t . Object ( {
16
+ hasMore : t . Boolean ( ) ,
17
+ items : t . Array (
18
+ t . Object ( {
19
+ username : t . String ( )
20
+ } )
21
+ ) ,
22
+ total : t
23
+ . Transform ( t . Number ( ) )
24
+ . Decode ( ( x ) => x )
25
+ . Encode ( ( x ) => x ) ,
26
+ offset : t . Number ( { minimum : 0 } ) ,
27
+ totalPages : t . Number ( ) ,
28
+ currentPage : t . Number ( { minimum : 1 } )
15
29
} )
16
- } )
17
- . listen ( 3000 )
30
+ }
31
+ )
32
+ . listen ( 3000 )
18
33
19
- const response = await app . handle ( req ( '/' ) )
20
-
21
- for await ( const a of streamResponse ( response ) ) {
22
- console . log ( a )
23
- }
34
+ const data = await app . handle ( req ( '/' ) ) . then ( ( x ) => x . text ( ) )
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " elysia" ,
3
3
"description" : " Ergonomic Framework for Human" ,
4
- "version" : " 1.3.16 " ,
4
+ "version" : " 1.3.17 " ,
5
5
"author" : {
6
6
"name" : " saltyAom" ,
7
7
"url" : " https://github.com/SaltyAom" ,
Original file line number Diff line number Diff line change @@ -262,10 +262,14 @@ const composeValidationFactory = ({
262
262
! appliedCleaner && normalize && ! noValidate
263
263
264
264
// Encode call TypeCheck.Check internally
265
- if ( encodeSchema && value . hasTransform )
265
+ if ( encodeSchema && value . hasTransform ) {
266
266
code +=
267
267
`try{` +
268
- `${ name } =validator.response[${ status } ].Encode(${ name } )\n` +
268
+ `${ name } =validator.response[${ status } ].Encode(${ name } )\n`
269
+
270
+ if ( ! appliedCleaner ) code += clean ( { ignoreTryCatch : true } )
271
+
272
+ code +=
269
273
`c.set.status=${ status } ` +
270
274
`}catch{` +
271
275
( applyErrorCleaner
@@ -277,7 +281,7 @@ const composeValidationFactory = ({
277
281
`}`
278
282
: `throw new ValidationError('response',validator.response[${ status } ],${ name } )` ) +
279
283
`}`
280
- else {
284
+ } else {
281
285
if ( ! appliedCleaner ) code += clean ( )
282
286
283
287
if ( ! noValidate )
Original file line number Diff line number Diff line change @@ -508,6 +508,53 @@ describe('Normalize', () => {
508
508
] )
509
509
} )
510
510
511
+ it ( 'normalize encodeSchema with Transform' , async ( ) => {
512
+ const app = new Elysia ( ) . get (
513
+ '/' ,
514
+ ( ) => ( {
515
+ hasMore : true ,
516
+ total : 1 ,
517
+ offset : 0 ,
518
+ totalPages : 1 ,
519
+ currentPage : 1 ,
520
+ items : [ { username : 'Bob' , secret : 'shhh' } ]
521
+ } ) ,
522
+ {
523
+ // I don't know why but it must be this exact shape
524
+ response : t . Object ( {
525
+ hasMore : t . Boolean ( ) ,
526
+ items : t . Array (
527
+ t . Object ( {
528
+ username : t . String ( )
529
+ } )
530
+ ) ,
531
+ total : t
532
+ . Transform ( t . Number ( ) )
533
+ . Decode ( ( x ) => x )
534
+ . Encode ( ( x ) => x ) ,
535
+ offset : t . Number ( { minimum : 0 } ) ,
536
+ totalPages : t . Number ( ) ,
537
+ currentPage : t . Number ( { minimum : 1 } )
538
+ } )
539
+ }
540
+ )
541
+
542
+ const data = await app . handle ( req ( '/' ) ) . then ( ( x ) => x . json ( ) )
543
+
544
+ expect ( data ) . toEqual ( {
545
+ hasMore : true ,
546
+ items : [
547
+ {
548
+ username : 'Bob'
549
+ }
550
+ ] ,
551
+ total : 1 ,
552
+ offset : 0 ,
553
+ totalPages : 1 ,
554
+ currentPage : 1
555
+ } )
556
+ } )
557
+
511
558
// it('normalize response with getter fields on class', async () => {
512
559
// const app = new Elysia({
513
560
// normalize: true
You can’t perform that action at this time.
0 commit comments