@d3vtool/ex-frame
Version:
This library enhances Express.js by providing a more organized structure for web API projects, along with improved control and error handling capabilities.
48 lines (47 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.All = exports.Unlink = exports.Link = exports.Connect = exports.Trace = exports.Options = exports.Head = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
exports.ParentRoute = ParentRoute;
function createHttpMethodDecorator(method, route) {
return function (_targetFn, _propertyKey, descriptor) {
if (descriptor?.value) {
descriptor.value["httpMethod"] = method;
descriptor.value["route"] = route;
return;
}
throw new Error(`'${method.charAt(0).toUpperCase() + method.slice(1)}' decorator cannot be used here.`);
};
}
const Get = (route) => createHttpMethodDecorator('get', route);
exports.Get = Get;
const Post = (route) => createHttpMethodDecorator('post', route);
exports.Post = Post;
const Put = (route) => createHttpMethodDecorator('put', route);
exports.Put = Put;
const Delete = (route) => createHttpMethodDecorator('delete', route);
exports.Delete = Delete;
const Patch = (route) => createHttpMethodDecorator('patch', route);
exports.Patch = Patch;
const Head = (route) => createHttpMethodDecorator('head', route);
exports.Head = Head;
const Options = (route) => createHttpMethodDecorator('options', route);
exports.Options = Options;
const Trace = (route) => createHttpMethodDecorator('trace', route);
exports.Trace = Trace;
const Connect = (route) => createHttpMethodDecorator('connect', route);
exports.Connect = Connect;
const Link = (route) => createHttpMethodDecorator('link', route);
exports.Link = Link;
const Unlink = (route) => createHttpMethodDecorator('unlink', route);
exports.Unlink = Unlink;
const All = (route) => createHttpMethodDecorator('all', route);
exports.All = All;
function ParentRoute(route) {
return function (targetFn, _propertyKey, descriptor) {
if (descriptor?.value) {
throw new Error("'ParentRoute' decorator cannot use be used here.");
}
targetFn["parentHttpMethod"] = "use";
targetFn["parentRoute"] = route;
};
}