@dooboostore/simple-boot-http-server
Version:
back end http server frameworks
198 lines • 8.74 kB
JavaScript
import 'reflect-metadata';
import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';
import { HttpMethod } from '../codes/HttpMethod';
export var UrlMappingSituationType;
(function (UrlMappingSituationType) {
UrlMappingSituationType["REQ_JSON_BODY"] = "SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_JSON_BODY";
UrlMappingSituationType["REQ_FORM_URL_BODY"] = "SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_FORM_URL_BODY";
})(UrlMappingSituationType || (UrlMappingSituationType = {}));
const MappingMetadataKey = Symbol('MappingMetadataKey');
const process = (config, target, propertyKey, descriptor) => {
var _a;
const saveMappingConfigs = ((_a = ReflectUtils.getMetadata(MappingMetadataKey, target.constructor)) !== null && _a !== void 0 ? _a : []);
saveMappingConfigs.push({ propertyKey, config });
ReflectUtils.defineMetadata(MappingMetadataKey, saveMappingConfigs, target.constructor);
ReflectUtils.defineMetadata(MappingMetadataKey, config, target, propertyKey);
};
export function UrlMapping(configOrtarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.GET }, configOrtarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
process(configOrtarget, target, propertyKey, descriptor);
};
}
}
export const getUrlMapping = (target, propertyKey) => {
return ReflectUtils.getMetadata(MappingMetadataKey, target, propertyKey);
};
export const getUrlMappings = (target) => {
if (target !== null && undefined !== target && typeof target === 'object') {
target = target.constructor;
}
return ReflectUtils.getMetadata(MappingMetadataKey, target);
};
export function GET(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.GET }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.GET;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getGET = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getGETS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.GET; });
};
export function POST(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.POST }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.POST;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getPOST = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getPOSTS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.POST; });
};
export function DELETE(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.DELETE }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.DELETE;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getDELETE = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getDELETES = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.DELETE; });
};
export function PUT(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.PUT }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.PUT;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getPUT = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getPUTS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.PUT; });
};
export function PATCH(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.PATCH }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.PATCH;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getPATCH = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getPATCHS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.GET; });
};
export function OPTIONS(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.OPTIONS }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.OPTIONS;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getOPTIONS = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getOPTIONSS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.OPTIONS; });
};
export function HEAD(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.HEAD }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.HEAD;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getHEAD = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getHEADS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.GET; });
};
export function TRACE(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.TRACE }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.TRACE;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getTRACE = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getTRACES = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.TRACE; });
};
export function CONNECT(configOrTarget, propertyKey, descriptor) {
if (propertyKey && descriptor) {
process({ method: HttpMethod.CONNECT }, configOrTarget, propertyKey, descriptor);
}
else {
return (target, propertyKey, descriptor) => {
configOrTarget.method = HttpMethod.CONNECT;
process(configOrTarget, target, propertyKey, descriptor);
};
}
}
export const getCONNECT = (target, propertyKey) => {
return getUrlMapping(target, propertyKey);
};
export const getCONNECTS = (target) => {
var _a;
return (_a = getUrlMappings(target)) === null || _a === void 0 ? void 0 : _a.filter(it => { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.method.toUpperCase()) === HttpMethod.CONNECT; });
};
//# sourceMappingURL=MethodMapping.js.map