UNPKG

@jschmold/kor

Version:

`npm i mocha ts-node typedoc typescript --global`

51 lines (50 loc) 2.06 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var express_1 = require("express"); var _1 = require("."); function Routeable(baseUrl, parent, options) { console.debug("New routeable " + baseUrl + " | " + (parent == null ? 'Root' : parent.name)); return function (constructor) { constructor.prototype._routing = __assign({}, constructor.prototype._routing, { options: options, baseUrl: baseUrl, parentRoute: parent }); }; } exports.Routeable = Routeable; function Route(type, arg) { if (type === void 0) { type = 'all'; } console.debug("New route [" + type + "]" + arg.toString()); return function (target, propertyKey, descriptor) { var proto = target.prototype || target.constructor.prototype; if (proto._routing == null) proto._routing = { routes: [] }; if (Array.isArray(proto._routing.routes) === false) proto._routing.routes = []; proto._routing.routes.push([type, arg, descriptor.value]); }; } exports.Route = Route; function bindRouteable(cls) { var proto = (cls.prototype || cls.constructor.prototype); var routing = proto._routing; var actor = express_1.Router(routing.options); var parent = routing.parentRouter || _1.Kor.router; parent.use(routing.baseUrl, actor); console.debug("[ROUTEABLE] " + cls.name + " "); console.debug(" " + routing.baseUrl); for (var _i = 0, _a = routing.routes; _i < _a.length; _i++) { var route = _a[_i]; actor[route[0]](route[1], route[2]); console.debug(" + [" + route[0].toUpperCase() + "] " + route[1]); } } exports.bindRouteable = bindRouteable;