@mvx/mvc
Version:
@mvx/mvc is mvc framework on server, base on koa, @tsdi frameworks
97 lines (95 loc) • 3.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MvcRoute = exports.RouteUrlArgToken = void 0;
var tslib_1 = require("tslib");
var ioc_1 = require("@tsdi/ioc");
var MvcMiddleware_1 = require("../middlewares/MvcMiddleware");
var RouteChecker_1 = require("../services/RouteChecker");
exports.RouteUrlArgToken = ioc_1.tokenId('route_url');
var MvcRoute = /** @class */ (function (_super) {
tslib_1.__extends(MvcRoute, _super);
function MvcRoute(url) {
var _this = _super.call(this) || this;
if (url) {
_this.metaUrl = url;
}
return _this;
}
Object.defineProperty(MvcRoute.prototype, "url", {
get: function () {
if (!this._url) {
this._url = this.vaildify(this.metaUrl, true);
}
return this._url;
},
set: function (val) {
this._url = val;
},
enumerable: false,
configurable: true
});
MvcRoute.prototype.getChecker = function () {
if (!this.checker) {
this.checker = this.getInjector().get(RouteChecker_1.RouteChecker);
}
return this.checker;
};
MvcRoute.prototype.getReqRoute = function (ctx) {
return this.getChecker().getReqRoute(ctx);
};
MvcRoute.prototype.vaildify = function (routePath, foreNull) {
if (foreNull === void 0) { foreNull = false; }
return this.getChecker().vaildify(routePath, foreNull);
};
MvcRoute.prototype.match = function (ctx) {
if (ctx.status && ctx.status !== 404) {
return false;
}
return this.getChecker().isActiveRoute(ctx, this.url);
};
MvcRoute.prototype.execute = function (ctx, next) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.match(ctx)) return [3 /*break*/, 2];
return [4 /*yield*/, this.navigate(ctx, next)];
case 1:
_a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, next()];
case 3: return [2 /*return*/, _a.sent()];
case 4: return [2 /*return*/];
}
});
});
};
MvcRoute.prototype.toHandle = function (handleType) {
var _a, _b, _c, _d;
if (handleType instanceof ioc_1.Action) {
return handleType.toAction();
}
else if (ioc_1.isClass(handleType)) {
var 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;
};
MvcRoute.ρAnn = function () {
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);
return MvcRoute;
}(MvcMiddleware_1.MvcMiddleware));
exports.MvcRoute = MvcRoute;
//# sourceMappingURL=../sourcemaps/router/Route.js.map