UNPKG

tspace-spear

Version:

tspace-spear is a lightweight, high-performance API framework for Node.js that leverages the native HTTP server and supports uWebSockets.js (C++) for maximum speed and efficiency.

102 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Options = exports.Head = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0; const methodDecorator = (method) => { return (path) => { return (target, propertyKey) => { const controller = target.constructor; const routers = Reflect.hasMetadata("routers", controller) ? Reflect.getMetadata("routers", controller) : []; routers.push({ method, path, handler: propertyKey, }); Reflect.defineMetadata("routers", routers, controller); }; }; }; /** * Maps a controller method to an HTTP GET route. * * @example * ```ts * \@Get('/users') * async list(ctx: T.Context) { * return [{ id: 1, name: "John" }]; * } * ``` */ exports.Get = methodDecorator('get'); /** * Maps a controller method to an HTTP POST route. * * @example * ```ts * \@Post('/users') * async create(ctx: T.Context) { * return { success: true }; * } * ``` */ exports.Post = methodDecorator('post'); /** * Maps a controller method to an HTTP PUT route. * * Used for replacing a resource. * * @example * ```ts * \@Put('/users/:id') * async update(ctx: T.Context) {} * ``` */ exports.Put = methodDecorator('put'); /** * Maps a controller method to an HTTP PATCH route. * * Used for partially updating a resource. * * @example * ```ts * \@Patch('/users/:id') * async patch(ctx: T.Context) {} * ``` */ exports.Patch = methodDecorator('patch'); /** * Maps a controller method to an HTTP DELETE route. * * @example * ```ts * \@Delete('/users/:id') * async remove(ctx: T.Context) {} * ``` */ exports.Delete = methodDecorator('delete'); /** * Maps a controller method to an HTTP HEAD route. * * HEAD responses contain only headers and no response body. * * @example * ```ts * \@Head('/health') * async health(ctx: T.Context) {} * ``` */ exports.Head = methodDecorator('head'); /** * Maps a controller method to an HTTP OPTIONS route. * * Typically used for CORS preflight requests. * * @example * ```ts * \@Options('/users') * async options(ctx: T.Context) {} * ``` */ exports.Options = methodDecorator('options'); //# sourceMappingURL=methods.js.map