feat(interfaces): add pipeline executor interface
All checks were successful
Auto Changelog & Release / detect-version-change (push) Has been skipped
Auto Changelog & Release / changelog-only (push) Has been skipped
Auto Changelog & Release / release (push) Has been skipped
Test http-kernel / Run Tests (pull_request) Successful in 13s

- Introduce `IPipelineExecutor` to define pipeline execution
- Add `PipelineExecutorFactory` for instantiating pipeline executors
- Export new types in the interfaces module for external use
This commit is contained in:
2025-05-10 16:50:41 +02:00
parent 8f94cc915c
commit 927a9081d4
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import { Handler, Middleware } from '../Types/mod.ts';
import { IContext } from './IContext.ts';
import { IPipelineExecutorConfig } from './IPipelineExecutorConfig.ts';
/**
* Constructor type for a class implementing the IPipelineExecutor interface.
*
* This can be used for dependency injection, factory-based initialization,
* or dynamic instantiation of pipeline executors.
*
* @template TContext - The extended context type passed through the pipeline.
*/
export interface PipelineExecutorFactory<TContext extends IContext = IContext> {
/**
* Creates a new instance of a pipeline executor.
*
* @param config - Configuration used to control error handling,
* response decoration and lifecycle hooks.
*/
new (
config: IPipelineExecutorConfig<TContext>,
): IPipelineExecutor<TContext>;
}
/**
* Defines the contract for executing a middleware and handler pipeline.
*
* The pipeline is responsible for:
* - Executing middleware in order with `next()` chaining
* - Invoking the final handler
* - Applying optional lifecycle hooks
* - Producing and decorating a Response
*
* @template TContext - The context type flowing through the pipeline.
*/
export interface IPipelineExecutor<TContext extends IContext = IContext> {
/**
* Executes the middleware pipeline and returns the final Response.
*
* @param ctx - The context object representing the current HTTP request state.
* @param middleware - An ordered array of middleware functions to be executed.
* @param handler - The final route handler to be called after all middleware.
* @returns A Promise resolving to the final HTTP Response.
*/
run(
ctx: TContext,
middleware: Middleware<TContext>[],
handler: Handler<TContext>,
): Promise<Response>;
}

View File

@@ -5,6 +5,10 @@ export type { IHttpErrorHandlers } from './IHttpErrorHandlers.ts';
export type { IHttpKernel } from './IHttpKernel.ts';
export type { IHttpKernelConfig } from './IHttpKernelConfig.ts';
export type { IInternalRoute } from './IInternalRoute.ts';
export type {
IPipelineExecutor,
PipelineExecutorFactory,
} from './IPipelineExecutor.ts';
export type { IPipelineExecutorConfig } from './IPipelineExecutorConfig.ts';
export type { IPipelineHooks } from './IPipelineHooks.ts';
export type { IRouteBuilder, IRouteBuilderFactory } from './IRouteBuilder.ts';