UNPKG

@d3vtool/kazejs

Version:

A flexible Node.js web framework built with TypeScript, focusing on dependency injection, routing, middleware, and schema validation. Supports dynamic routes, global middleware, static files, and customizable error handling for scalable apps.

53 lines (52 loc) 2.17 kB
"use strict"; 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("'Get' decorator cannot use be used here."); } targetFn["parentRoute"] = route; }; } /* else { // (targetFn as any)["httpMethod"] = "get"; (targetFn as any)["routeGrp"] = route; } */