@nova-ts/core
Version:
A serverside framework used to build scalable application
154 lines (101 loc) β’ 3.95 kB
Markdown
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
```
```