UNPKG

@nova-ts/core

Version:

A serverside framework used to build scalable application

154 lines (101 loc) β€’ 3.95 kB
Here’s the updated `README.md` for `@nova-ts/core`, now including the **new features** you’ve introduced β€” such as filters, response manipulation, `NovaFilterExecutor`, and more. --- ````markdown # @nova-ts/core > 🧩 Core runtime package for the NovaTS web framework β€” built for clean, decorator-driven TypeScript APIs on top of Express. --- ## ✨ Features - βœ… Decorator-based routing (`@GetMapping`, `@PostMapping`, etc.) - βœ… Controller and method-level metadata mapping - βœ… Parameter decorators (`@PathVariable`, `@RequestParam`, `@RequestBody`, `@RequestHeader`, `@Request`) - βœ… Dependency injection friendly (via `@nova-ts/context`) - βœ… Runtime controller resolver - βœ… Express route binding via `HttpFactory` - βœ… Easy application bootstrap with `InitializeApplication` - βœ… Global and route-level filter support (`@Filter`) - βœ… Response transformation decorator (`@Response`) - βœ… Custom request pipeline via `NovaFilterExecutor` - βœ… Seamless controller invocation flow with `NovaControllerInvoker` --- ## πŸ“¦ Installation ```bash npm install @nova-ts/core ```` You will also need `@nova-ts/context` and optionally `express` for app configuration: ```bash npm install @nova-ts/context ``` --- ## πŸš€ Getting Started ```ts // main.ts import { autoBind } from "@nova-ts/context"; import { ApplicationFactory } from "@nova-ts/core"; await autoBind("./dist/dev"); const Application = new ApplicationFactory(); Application.setPort(8080); await Application.InitializeApplication(); Application.startApplication(); ``` --- ## 🧱 Example Usage ```ts // user.controller.ts import { Controller, GetMapping, PostMapping, PathVariable, Body, Filter, Response } from '@nova-ts/core'; import { LoggerFilter } from './filters/logger.filter'; import { MaskEmailResponse } from './responses/mask-email.response'; @Controller('/users') @Filter(LoggerFilter) export class UserController { @GetMapping('/{id}') @Response(MaskEmailResponse) getUser(@PathVariable('id') id: string) { return { id, name: 'John Doe', email: 'john@example.com' }; } @PostMapping('/') createUser(@RequestBody() user: any) { return { success: true, data: user }; } } ``` --- ## 🧩 Core API ### Routing & Controllers * `@Controller(path: string)` – Defines a controller with a base path. * `@GetMapping(path: string)` – Maps a method to a `GET` route. * `@PostMapping(path: string)` – Maps a method to a `POST` route. ### Parameter Decorators * `@PathVariable(name: string)` – Gets a URL path variable. * `@RequestParam(name: string)` – Gets a query parameter. * `@RequestBody()` – Gets the parsed request body. * `@RequestHeader(name: string)` – Gets a specific header. * `@Request()` – Gets the raw `Express.Request` object. ### Filters and Response Mapping * `@Filter(FilterClass)` – Attaches a request filter to a controller or route. * `@Response(ResponseMapperClass)` – Maps the controller result to a custom response format. --- ## πŸ”§ Advanced ### `HttpFactory(app: Express.Application)` Binds controllers and routes dynamically to an Express instance. ### `NovaControllerResolver` Internally used to map method parameters based on metadata. ### `NovaControllerInvoker` Handles invocation of controller methods with resolved parameters. ### `NovaFilterExecutor` Executes request filters and controls the flow of controller logic, enabling middleware-like extensibility. --- ## πŸ“š Related Packages * [`@nova-ts/context`](https://www.npmjs.com/package/@nova-ts/context) – Dependency injection system * `@nova-ts/cli` – Project scaffolding (coming soon) --- ## πŸ› οΈ Development ```bash # Clone and build the package npm run build ``` --- ## πŸ“„ License MIT Β© 2025 Inbanithi107 ``` --- ```