UNPKG

co-compose

Version:

AdonisJS and Koa style middleware layer with ability to run parallel middleware

41 lines (40 loc) 1 kB
"use strict"; /* * co-componse * * (c) Harminder Virk <virk@adonisjs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Middleware = void 0; const Runnable_1 = require("./Runnable"); /** * Exposes the API to register middleware and later execute * them using the runner. */ class Middleware { constructor() { this.list = []; } /** * Register an array of middleware to executed * later. */ register(list) { if (!Array.isArray(list)) { throw new Error('middleware.register expects an array of middleware'); } this.list = this.list.concat(list); return this; } /** * Returns an instance of runner to execute * the middleware */ runner() { return new Runnable_1.Runnable(this.list); } } exports.Middleware = Middleware;