UNPKG

@methodus/server

Version:
67 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("reflect-metadata"); function pushParams(target, propertyKey, param) { const designType = Reflect.getMetadata('design:paramtypes', target, propertyKey); let typeName = (designType[param.index] !== undefined && designType[param.index].name) ? designType[param.index].name.toLowerCase() : 'any'; if (param.type) { typeName = param.type; } if (typeName === undefined) { typeName = 'object'; } target.methodus = target.methodus || {}; const name = target.name || target.constructor.name; target.methodus[name] = target.methodus[name] || { _events: {}, _descriptors: {} }; const mTarget = target.methodus[name]; mTarget._descriptors[propertyKey] = mTarget._descriptors[propertyKey] || { params: [] }; mTarget._descriptors[propertyKey].params.push(Object.assign({}, param, { type: typeName })); } function build(from, name, type, defaultValue) { return (target, propertyKey, parameterIndex) => { if (name) { pushParams(target, propertyKey, { type, from, index: parameterIndex, defaultValue, name }); } else { pushParams(target, propertyKey, { type, from, index: parameterIndex, defaultValue }); } }; } function Body(name, type) { return build('body', name, type); } exports.Body = Body; function Param(name) { return build('params', name); } exports.Param = Param; function Files(name) { return build('files', name); } exports.Files = Files; function Headers(name) { return build('headers', name); } exports.Headers = Headers; function Cookies(name) { return build('cookies', name); } exports.Cookies = Cookies; function Query(name, type, defaultValue) { return build('query', name, type, defaultValue); } exports.Query = Query; function SecurityContext(name, type) { return build('security_context', name, type); } exports.SecurityContext = SecurityContext; function Response(name) { return build('response', name); } exports.Response = Response; function Request(name) { return build('request', name); } exports.Request = Request; //# sourceMappingURL=params.js.map