Skip to content

Commit

Permalink
feat: allow chaining use/error
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Nov 26, 2024
1 parent f4f1061 commit 41992e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/@wroud/flow-middleware/src/FlowMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ export class FlowMiddleware<Data = Record<string, any>>
* Registers a middleware globally.
* @param {Middleware<Data>} middleware - The middleware function to register.
*/
public use(...middleware: IMiddleware<Data>[]): void {
public use(...middleware: IMiddleware<Data>[]): this {
this.middlewares.push(...middleware);
return this;
}

/**
* Registers an error-handling middleware globally.
* @param {ErrorMiddleware<Data>} errorMiddleware - The error middleware function to register.
*/
public error(...errorMiddleware: IErrorMiddleware<Data>[]): void {
public error(...errorMiddleware: IErrorMiddleware<Data>[]): this {
this.errorMiddlewares.push(...errorMiddleware);
return this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export interface IFlowMiddleware<Data = Record<string, any>> {
* Registers a middleware globally.
* @param {Middleware<Data>} middleware - The middleware function to register.
*/
use(...middleware: IMiddleware<Data>[]): void;
use(...middleware: IMiddleware<Data>[]): this;

/**
* Registers an error-handling middleware globally.
* @param {ErrorMiddleware<Data>} errorMiddleware - The error middleware function to register.
*/
error(...errorMiddleware: IErrorMiddleware<Data>[]): void;
error(...errorMiddleware: IErrorMiddleware<Data>[]): this;

/**
* Creates a new MiddlewareRequest instance.
Expand Down

0 comments on commit 41992e1

Please sign in to comment.