plus-midwayjs
Version:
58 lines (57 loc) • 2.76 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlusUrlTagData = void 0;
const core_1 = require("@midwayjs/core");
const tag_1 = require("../decorator/tag");
const _ = require("lodash");
let PlusUrlTagData = class PlusUrlTagData {
constructor() {
this.data = {};
}
async init() {
const tags = (0, core_1.listModule)(tag_1.PLUS_URL_TAG_KEY);
for (const controller of tags) {
// class的标记
const controllerOption = (0, core_1.getClassMetadata)(core_1.CONTROLLER_KEY, controller);
const tagOption = (0, core_1.getClassMetadata)(tag_1.PLUS_URL_TAG_KEY, controller);
if (tagOption === null || tagOption === void 0 ? void 0 : tagOption.key) {
const data = this.data[tagOption.key] || [];
this.data[tagOption.key] = _.uniq(data.concat(((tagOption === null || tagOption === void 0 ? void 0 : tagOption.value) || []).map((e) => {
return controllerOption.prefix + '/' + e;
})));
}
// 方法标记
const listPropertyMetas = (0, core_1.listPropertyDataFromClass)(tag_1.PLUS_METHOD_TAG_KEY, controller);
const requestMetas = (0, core_1.getClassMetadata)(core_1.WEB_ROUTER_KEY, controller);
for (const propertyMeta of listPropertyMetas) {
const _data = this.data[propertyMeta.tag] || [];
const requestMeta = _.find(requestMetas, { method: propertyMeta.key });
if (requestMeta) {
this.data[propertyMeta.tag] = _.uniq(_data.concat(controllerOption.prefix + requestMeta.path));
}
}
}
}
/**
* 根据键获得
* @param key
* @param type
*/
byKey(key, type) {
var _a;
return (_a = this.data[key]) === null || _a === void 0 ? void 0 : _a.filter((e) => {
return type ? _.startsWith(e, `/${type}/`) : true;
});
}
};
PlusUrlTagData = __decorate([
(0, core_1.Provide)(),
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
], PlusUrlTagData);
exports.PlusUrlTagData = PlusUrlTagData;