@@ -22,6 +22,9 @@ import {
2222 isApiGatewayV2Event ,
2323 isAlbEvent ,
2424 App ,
25+ SourceAgnosticMiddleware ,
26+ SourceAgnosticHandler ,
27+ SourceAgnosticErrorHandler ,
2528} from './index' ;
2629import {
2730 APIGatewayProxyEvent ,
@@ -99,11 +102,7 @@ const testEventTypeGuards = () => {
99102 }
100103} ;
101104
102- const sourceAgnosticMiddleware : Middleware < any , RequestContext > = (
103- req ,
104- res ,
105- next
106- ) => {
105+ const sourceAgnosticMiddleware : SourceAgnosticMiddleware = ( req , res , next ) => {
107106 if ( isApiGatewayContext ( req . requestContext ) ) {
108107 expectType < string > ( req . requestContext . requestId ) ;
109108 const sourceIp = req . requestContext . identity . sourceIp ;
@@ -190,7 +189,7 @@ const testRequestTypeGuards = () => {
190189 }
191190} ;
192191
193- const sourceAgnosticHandler : HandlerFunction < UserResponse , RequestContext > = (
192+ const sourceAgnosticHandler : SourceAgnosticHandler < UserResponse > = (
194193 req ,
195194 res
196195) => {
@@ -614,3 +613,53 @@ const testDefaultTypes = () => {
614613 ) ;
615614 expectType < Promise < any > > ( apiGwV2Result ) ;
616615} ;
616+
617+ const testSourceAgnosticTypes = ( ) => {
618+ // Test source-agnostic handler with minimal type parameters
619+ const simpleSourceAgnosticHandler : SourceAgnosticHandler = ( req , res ) => {
620+ expectType < RequestContext > ( req . requestContext ) ;
621+ res . json ( { message : 'ok' } ) ;
622+ } ;
623+
624+ // Test source-agnostic handler with response type
625+ const typedSourceAgnosticHandler : SourceAgnosticHandler < UserResponse > = (
626+ req ,
627+ res
628+ ) => {
629+ res . json ( {
630+ id : '1' ,
631+ name : 'John' ,
632+ 633+ } ) ;
634+ } ;
635+
636+ // Test source-agnostic middleware with minimal type parameters
637+ const simpleSourceAgnosticMiddleware : SourceAgnosticMiddleware = (
638+ req ,
639+ res ,
640+ next
641+ ) => {
642+ expectType < RequestContext > ( req . requestContext ) ;
643+ next ( ) ;
644+ } ;
645+
646+ // Test source-agnostic error handler
647+ const sourceAgnosticErrorHandler : SourceAgnosticErrorHandler = (
648+ error ,
649+ req ,
650+ res ,
651+ next
652+ ) => {
653+ expectType < RequestContext > ( req . requestContext ) ;
654+ res . status ( 500 ) . json ( { error : error . message } ) ;
655+ } ;
656+
657+ // Test using source-agnostic types with API
658+ api . get ( '/source-agnostic' , simpleSourceAgnosticHandler ) ;
659+ api . post (
660+ '/source-agnostic' ,
661+ simpleSourceAgnosticMiddleware ,
662+ typedSourceAgnosticHandler
663+ ) ;
664+ api . use ( sourceAgnosticErrorHandler ) ;
665+ } ;
0 commit comments