tachijs
Version:
Highly testable dead simple web server written in Typescript
40 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const reflectMetadataIsAvailable = typeof Reflect.getMetadata !== 'undefined';
const handlerParamMetaMap = new Map();
function getHandlerParamMetaList(controller, propertyKey) {
if (!handlerParamMetaMap.has(controller))
return [];
const metaList = handlerParamMetaMap.get(controller).get(propertyKey);
if (metaList == null)
return [];
return metaList;
}
exports.getHandlerParamMetaList = getHandlerParamMetaList;
function setHandlerParamMetaList(controller, propertyKey, meta) {
if (!handlerParamMetaMap.has(controller)) {
handlerParamMetaMap.set(controller, new Map());
}
const propertyKeyMetaMap = handlerParamMetaMap.get(controller);
propertyKeyMetaMap.set(propertyKey, meta);
}
exports.setHandlerParamMetaList = setHandlerParamMetaList;
function handlerParam(selector) {
return function controllerDecorator(target, propertyKey, index) {
const previousHandlerParamList = getHandlerParamMetaList(target.constructor, propertyKey);
const handlerParamMeta = {
index,
selector
};
if (reflectMetadataIsAvailable) {
handlerParamMeta.paramType = Reflect.getMetadata('design:paramtypes', target, propertyKey)[index];
}
const meta = [
...previousHandlerParamList,
handlerParamMeta
];
setHandlerParamMetaList(target.constructor, propertyKey, meta);
};
}
exports.handlerParam = handlerParam;
//# sourceMappingURL=handlerParam.js.map