UNPKG

openapi-connect

Version:
28 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addCustomRegistrators = void 0; const matches = require("lodash.matches"); function addCustomRegistrators(registrators, customMiddlewares) { const beforeAll = getCustomRegistrators(customMiddlewares, { before: 'all' }); const core = registrators .map(reg => wrapRegistrator(reg, customMiddlewares)) .reduce((acc, regs) => acc.concat(regs), []); const afterAll = getCustomRegistrators(customMiddlewares, { after: 'all' }); return beforeAll.concat(core).concat(afterAll); } exports.addCustomRegistrators = addCustomRegistrators; function wrapRegistrator(registrator, customMiddlewares) { if (!registrator.kind) { return [registrator]; } const before = getCustomRegistrators(customMiddlewares, { before: registrator.kind }); const after = getCustomRegistrators(customMiddlewares, { after: registrator.kind }); return before.concat([registrator]).concat(after); } const getCustomRegistrators = (middlewares, on) => middlewares.filter(matches({ on })).map(getCustomRegistrator); const getCustomRegistrator = (middleware) => ({ register: context => { context.app.use(middleware.handler); } }); //# sourceMappingURL=customRegistrator.js.map