@foal/core
Version:
Full-featured Node.js framework, with no complexity
117 lines (116 loc) • 3.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.All = All;
exports.Head = Head;
exports.Options = Options;
exports.Get = Get;
exports.Post = Post;
exports.Put = Put;
exports.Patch = Patch;
exports.Delete = Delete;
// 3p
require("reflect-metadata");
/**
* Decorator specifying that a controller method handles requests matching all HTTP verbs.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function All(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'ALL', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles HEAD requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Head(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'HEAD', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles OPTIONS requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Options(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'OPTIONS', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles GET requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Get(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'GET', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles POST requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Post(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'POST', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles PUT requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Put(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'PUT', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles PATCH requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Patch(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'PATCH', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}
/**
* Decorator specifying that a controller method handles DELETE requests.
*
* @export
* @param {string} [path] - The path of the request.
* @returns The decorator.
*/
function Delete(path) {
return (target, propertyKey) => {
Reflect.defineMetadata('httpMethod', 'DELETE', target, propertyKey);
Reflect.defineMetadata('path', path, target, propertyKey);
};
}