feat(pipeline): add configuration and hooks for pipeline execution

- Introduce `IPipelineExecutorConfig` to enable customizable pipeline behavior
- Add `IPipelineHooks` interface for tracing and monitoring lifecycle events
- Define callback types for pipeline start, step execution, and completion
- Export new types and interfaces for broader integration within the system
This commit is contained in:
2025-05-10 16:21:16 +02:00
parent 0846dbb758
commit 3f114bb68d
5 changed files with 126 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { IContext } from '../Interfaces/mod.ts';
/**
* A callback invoked when the middleware pipeline starts.
*
* @template TContext - The context type passed throughout the pipeline.
* @param ctx - The context object for the current request.
*/
export type OnPipelineStart<TContext extends IContext> = (
ctx: TContext,
) => void;
/**
* A callback invoked immediately before a middleware or handler is executed.
*
* @template TContext - The context type passed throughout the pipeline.
* @param name - Optional name of the current middleware or handler, if defined.
* @param ctx - The context object for the current request.
*/
export type OnStepStart<TContext extends IContext> = (
name: string | undefined,
ctx: TContext,
) => void;
/**
* A callback invoked immediately after a middleware or handler has completed.
*
* @template TContext - The context type passed throughout the pipeline.
* @param name - Optional name of the current middleware or handler, if defined.
* @param ctx - The context object for the current request.
* @param duration - Execution time in milliseconds.
*/
export type OnStepEnd<TContext extends IContext> = (
name: string | undefined,
ctx: TContext,
duration: number,
) => void;
/**
* A callback invoked after the entire pipeline has completed execution.
*
* @template TContext - The context type passed throughout the pipeline.
* @param ctx - The context object for the current request.
* @param totalDuration - Total execution time of the pipeline in milliseconds.
*/
export type OnPipelineEnd<TContext extends IContext> = (
ctx: TContext,
totalDuration: number,
) => void;

View File

@@ -39,6 +39,12 @@ export type { HttpStatusCode } from './HttpStatusCode.ts';
export { isMiddleware } from './Middleware.ts';
export type { Middleware } from './Middleware.ts';
export type { Params } from './Params.ts';
export type {
OnPipelineEnd,
OnPipelineStart,
OnStepEnd,
OnStepStart,
} from './PipelineHooks.ts';
export type { Query } from './Query.ts';
export type { RegisterRoute } from './RegisterRoute.ts';
export type { ResponseDecorator } from './ResponseDecorator.ts';