"use strict";
require('reflect-metadata');
var namings = require('./namings');
function createHttpMethodFunction(httpMethod) {
return function (target, key, descriptor) {
Reflect.defineMetadata(httpMethod, true, descriptor.value);
};
}
/**
* Publish a method as an http endpoint for GET requests. If no Path is specified the path will be /.
* The decorator is only allowed on methods.
* @returns the decorated function
*/
function GET() { return createHttpMethodFunction(namings.getMethod); }
exports.GET = GET;
/**
* Publish a method as an http endpoint for POST requests. If no Path is specified the path will be /.
* The decorator is only allowed on methods.
* @returns the decorated function
*/
function POST() { return createHttpMethodFunction(namings.postMethod); }
exports.POST = POST;
/**
* Publish a method as an http endpoint for PUT requests. If no Path is specified the path will be /.
* The decorator is only allowed on methods.
* @returns the decorated function
*/
function PUT() { return createHttpMethodFunction(namings.putMethod); }
exports.PUT = PUT;
/**
* Publish a method as an http endpoint for DELETE requests. If no Path is specified the path will be /.
* The decorator is only allowed on methods.
* @returns the decorated function
*/
function DELETE() { return createHttpMethodFunction(namings.deleteMethod); }
exports.DELETE = DELETE;
/**
* Specify the Path for teh ressource. If the decorator is present at class level all methods paths will be
* prefixed with this path.
* @param path The path for the class or method. The path must not be start with /.
* The slash will be added automatically.
* @returns the decorated function
*/
function Path(path) {
return function (target, propertyKey, descriptor) {
if (!propertyKey && !descriptor) {
// add meta data to the class itself - e.g. target is the constructor and propertyKey and descriptor are undefined
return Reflect.defineMetadata(namings.path, path, target);
}
else {
// add meta data to a function
return Reflect.defineMetadata(namings.path, path, descriptor.value);
}
};
}
exports.Path = Path;
/**
* Description of a parameter decorator.
*/
var ParamDescription = (function () {
function ParamDescription() {
}
return ParamDescription;
}());
exports.ParamDescription = ParamDescription;
function createParamDecorator(name, pathParamKey) {
return function (target, propertyKey, parameterIndex) {
var existingPathParams = Reflect.getOwnMetadata(pathParamKey, target, propertyKey) || [];
existingPathParams.push({ pathParam: name, index: parameterIndex });
Reflect.defineMetadata(pathParamKey, existingPathParams, target, propertyKey);
};
}
/**
* Specifies how a method parameter is evealuated. In this case the value will be taken
* from the parameter that is specified in the path decorator.
* @param name the name in the path that should be used to provide the parameter to the method.
* @returns the decorated function
*/
function PathParam(name) { return createParamDecorator(name, namings.pathParam); }
exports.PathParam = PathParam;
/**
* Specifies how a method parameter is evealuated. In this case the value will be taken
* from a http header.
* @param name the name in the http header that should be used to provide the parameter to the method.
* @returns the decorated function
*/
function HeaderParam(name) { return createParamDecorator(name, namings.headerParam); }
exports.HeaderParam = HeaderParam;
//# sourceMappingURL=decorators.js.map