{"size": 3576, "ext": "js", "max_stars_repo_path": "packages/express/dist/ExpressAdapter.js", "max_stars_repo_name": "Pluto8195/bull-board", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/express/dist/ExpressAdapter.js", "max_issues_repo_name": "Pluto8195/bull-board", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/express/dist/ExpressAdapter.js", "max_forks_repo_name": "Pluto8195/bull-board", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 37.25, "max_line_length": 141, "alphanum_fraction": 0.5883668904}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpressAdapter = void 0;
const express_1 = __importStar(require("express"));
const ejs_1 = __importDefault(require("ejs"));
const wrapAsync_1 = require("./helpers/wrapAsync");
class ExpressAdapter {
    constructor() {
        this.basePath = '';
        this.app = express_1.default();
    }
    setBasePath(path) {
        this.basePath = path;
        return this;
    }
    setStaticPath(staticsRoute, staticsPath) {
        this.app.use(staticsRoute, express_1.default.static(staticsPath));
        return this;
    }
    setViewsPath(viewPath) {
        this.app.set('view engine', 'ejs').set('views', viewPath);
        this.app.engine('ejs', ejs_1.default.renderFile);
        return this;
    }
    setErrorHandler(handler) {
        this.errorHandler = handler;
        return this;
    }
    setApiRoutes(routes) {
        if (!this.errorHandler) {
            throw new Error(`Please call 'setErrorHandler' before using 'registerPlugin'`);
        }
        else if (!this.bullBoardQueues) {
            throw new Error(`Please call 'setQueues' before using 'registerPlugin'`);
        }
        const router = express_1.Router();
        routes.forEach((route) => (Array.isArray(route.method) ? route.method : [route.method]).forEach((method) => {
            router[method](route.route, wrapAsync_1.wrapAsync(async (req, res) => {
                const response = await route.handler({
                    queues: this.bullBoardQueues,
                    query: req.query,
                    params: req.params,
                });
                res.status(response.status || 200).json(response.body);
            }));
        }));
        router.use((err, _req, res, next) => {
            if (!this.errorHandler) {
                return next();
            }
            const response = this.errorHandler(err);
            return res.status(response.status).send(response.body);
        });
        this.app.use(router);
        return this;
    }
    setEntryRoute(routeDef) {
        const { name } = routeDef.handler();
        const viewHandler = (_req, res) => {
            res.render(name, { basePath: this.basePath });
        };
        this.app[routeDef.method](routeDef.route, viewHandler);
        return this;
    }
    setQueues(bullBoardQueues) {
        this.bullBoardQueues = bullBoardQueues;
        return this;
    }
    getRouter() {
        return this.app;
    }
}
exports.ExpressAdapter = ExpressAdapter;
//# sourceMappingURL=ExpressAdapter.js.map