refactor(types): unify handler and middleware definitions

- Consolidates `Handler` and `Middleware` types under `Types` module
- Replaces `IHandler` and `IMiddleware` interfaces with typed functions
- Simplifies imports and improves code organization
- Enhances debugging with named handlers and middlewares
This commit is contained in:
2025-05-08 19:03:18 +02:00
parent 56633cd95b
commit 8235680904
10 changed files with 71 additions and 66 deletions

View File

@@ -1,20 +1,20 @@
import {
IContext,
IHandler,
IHttpKernel,
IHttpKernelConfig,
IInternalRoute,
IMiddleware,
IRouteBuilder,
IRouteDefinition,
isHandler,
isMiddleware,
} from './Interfaces/mod.ts';
import {
DeepPartial,
Handler,
HTTP_404_NOT_FOUND,
HTTP_500_INTERNAL_SERVER_ERROR,
HttpStatusTextMap,
isHandler,
isMiddleware,
Middleware,
} from './Types/mod.ts';
import { RouteBuilder } from './RouteBuilder.ts';
import { createEmptyContext, normalizeError } from './Utils/mod.ts';
@@ -151,8 +151,8 @@ export class HttpKernel<TContext extends IContext = IContext>
*/
private async executePipeline(
ctx: TContext,
middleware: IMiddleware<TContext>[],
handler: IHandler<TContext>,
middleware: Middleware<TContext>[],
handler: Handler<TContext>,
): Promise<Response> {
const handleInternalError = (ctx: TContext, err?: unknown) =>
this.cfg.httpErrorHandlers[HTTP_500_INTERNAL_SERVER_ERROR](