@@ -340,6 +340,7 @@ export const BunAdapter: ElysiaAdapter = {
340340 createStaticRoute ( app . router . response ) ,
341341 mapRoutes ( app )
342342 ) ,
343+ // @ts -ignore
343344 app . config . serve ?. routes
344345 ) ,
345346 websocket : {
@@ -360,6 +361,7 @@ export const BunAdapter: ElysiaAdapter = {
360361 createStaticRoute ( app . router . response ) ,
361362 mapRoutes ( app )
362363 ) ,
364+ // @ts -ignore
363365 app . config . serve ?. routes
364366 ) ,
365367 websocket : {
@@ -402,6 +404,7 @@ export const BunAdapter: ElysiaAdapter = {
402404 } ) ,
403405 mapRoutes ( app )
404406 ) ,
407+ // @ts -ignore
405408 app . config . serve ?. routes
406409 )
407410 } )
@@ -428,15 +431,21 @@ export const BunAdapter: ElysiaAdapter = {
428431 // eslint-disable-next-line @typescript-eslint/no-unused-vars
429432 const { parse, body, response, ...rest } = options
430433
431- const validateMessage = getSchemaValidator ( body , {
434+ const messageValidator = getSchemaValidator ( body , {
432435 // @ts -expect-error private property
433436 modules : app . definitions . typebox ,
434437 // @ts -expect-error private property
435438 models : app . definitions . type as Record < string , TSchema > ,
436439 normalize : app . config . normalize
437440 } )
438441
439- const validateResponse = getSchemaValidator ( response as any , {
442+ const validateMessage = messageValidator ?
443+ messageValidator . provider === 'standard'
444+ ? ( data : unknown ) => messageValidator . schema [ '~standard' ] . validate ( data ) . issues
445+ : ( data : unknown ) => messageValidator . Check ( data ) === false
446+ : undefined
447+
448+ const responseValidator = getSchemaValidator ( response as any , {
440449 // @ts -expect-error private property
441450 modules : app . definitions . typebox ,
442451 // @ts -expect-error private property
@@ -456,7 +465,7 @@ export const BunAdapter: ElysiaAdapter = {
456465 const { set, path, qi, headers, query, params } = context
457466
458467 // @ts -ignore
459- context . validator = validateResponse
468+ context . validator = responseValidator
460469
461470 if ( options . upgrade ) {
462471 if ( typeof options . upgrade === 'function' ) {
@@ -484,7 +493,7 @@ export const BunAdapter: ElysiaAdapter = {
484493 set . headers [ 'set-cookie' ]
485494 ) as any
486495
487- const handleResponse = createHandleWSResponse ( validateResponse )
496+ const handleResponse = createHandleWSResponse ( responseValidator )
488497 const parseMessage = createWSMessageParser ( parse as any )
489498
490499 let _id : string | undefined
@@ -535,7 +544,7 @@ export const BunAdapter: ElysiaAdapter = {
535544
536545 return ( _id = randomId ( ) )
537546 } ,
538- validator : validateResponse ,
547+ validator : responseValidator ,
539548 ping ( ws : ServerWebSocket < any > , data ?: unknown ) {
540549 options . ping ?.( ws as any , data )
541550 } ,
@@ -560,18 +569,17 @@ export const BunAdapter: ElysiaAdapter = {
560569 ) => {
561570 const message = await parseMessage ( ws , _message )
562571
563- if ( validateMessage ?. Check ( message ) === false ) {
572+ if ( validateMessage && validateMessage ( message ) ) {
564573 const validationError = new ValidationError (
565574 'message' ,
566- validateMessage ,
575+ messageValidator ! ,
567576 message
568577 )
569578
570- if ( ! hasCustomErrorHandlers ) {
579+ if ( ! hasCustomErrorHandlers )
571580 return void ws . send (
572581 validationError . message as string
573582 )
574- }
575583
576584 return handleErrors ( ws , validationError )
577585 }
0 commit comments