UNPKG

@mvx/mvc

Version:

@mvx/mvc is mvc framework on server, base on koa, @tsdi frameworks

80 lines (78 loc) 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MvcRoute = exports.RouteUrlArgToken = void 0; const tslib_1 = require("tslib"); const ioc_1 = require("@tsdi/ioc"); const MvcMiddleware_1 = require("../middlewares/MvcMiddleware"); const RouteChecker_1 = require("../services/RouteChecker"); exports.RouteUrlArgToken = ioc_1.tokenId('route_url'); let MvcRoute = class MvcRoute extends MvcMiddleware_1.MvcMiddleware { constructor(url) { super(); if (url) { this.metaUrl = url; } } get url() { if (!this._url) { this._url = this.vaildify(this.metaUrl, true); } return this._url; } set url(val) { this._url = val; } getChecker() { if (!this.checker) { this.checker = this.getInjector().get(RouteChecker_1.RouteChecker); } return this.checker; } getReqRoute(ctx) { return this.getChecker().getReqRoute(ctx); } vaildify(routePath, foreNull = false) { return this.getChecker().vaildify(routePath, foreNull); } match(ctx) { if (ctx.status && ctx.status !== 404) { return false; } return this.getChecker().isActiveRoute(ctx, this.url); } async execute(ctx, next) { if (this.match(ctx)) { await this.navigate(ctx, next); } else { return await next(); } } toHandle(handleType) { var _a, _b, _c, _d; if (handleType instanceof ioc_1.Action) { return handleType.toAction(); } else if (ioc_1.isClass(handleType)) { const ist = (_a = this.getInjector().get(handleType)) !== null && _a !== void 0 ? _a : this.getInjector().getContainer().getTypeReflects().getInjector(handleType).getInstance(handleType); return (_b = ist === null || ist === void 0 ? void 0 : ist.toAction) === null || _b === void 0 ? void 0 : _b.call(ist); } else if (ioc_1.isToken(handleType)) { return (_d = (_c = this.getInjector().get(handleType)) === null || _c === void 0 ? void 0 : _c.toAction) === null || _d === void 0 ? void 0 : _d.call(_c); } else if (ioc_1.isFunction(handleType)) { return handleType; } return null; } static ρAnn() { return { "name": "MvcRoute", "params": { "constructor": ["url"], "getReqRoute": ["ctx"], "vaildify": ["routePath", "foreNull"], "match": ["ctx"], "execute": ["ctx", "next"], "navigate": ["ctx", "next"], "toHandle": ["handleType"] } }; } }; MvcRoute.ρNPT = true; MvcRoute = tslib_1.__decorate([ ioc_1.Abstract(), tslib_1.__metadata("design:paramtypes", [String]) ], MvcRoute); exports.MvcRoute = MvcRoute; //# sourceMappingURL=../sourcemaps/router/Route.js.map