Nestia Core Library
Super-fast validation decorators for NestJS.
- 15,000x faster request body validation
- 50x faster JSON response, even type safe
- Do not need DTO class definition, just fine with interface
@nestia/core
is a transformer library of NestJS, supporting super-fast validation decorators, by wrapping typia. Comparing validation speed with class-validator
, typia is maximum 15,000x times faster and it is even much safer.
Furthermore, @nestia/core
can use pure interface typed DTO with only one line. With @nestia/core
, you don't need any extra dedication like defining JSON schema (@nestjs/swagger
), or using class definition with decorator function calls (class-validator
). Just enjoy the superfast decorators with pure TypeScript type.
import { Controller } from "@nestjs/common";
import { TypedBody, TypedRoute } from "@nestia/core";
import type { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
@Controller("bbs/articles")
export class BbsArticlesController {
@TypedRoute.Post()
public async store(
@TypedBody() input: IBbsArticle.IStore
): Promise<IBbsArticle>;
}
Setup
Boilerplate Project
npx nestia start <directory>
Just run above command, then boilerplate project would be constructed.
Setup Wizard
npx nestia setup
npx @nestia/core setup
Just type npx nestia setup
, that's all.
If you've installed ttypescript during setup, you should compile @nestia/core
utilization code through ttsc
command, instead of tsc
.
npx ttsc
npx ts-node -C ttypescript src/index.ts
Otherwise, you've chosen ts-patch, you can use original tsc
command. However, ts-patch hacks node_modules/typescript
source code. Also, whenever update typescript
version, you've to run npm run prepare
command repeatedly.
By the way, when using @nest/cli
, you must just choose ts-patch.
tsc
npx ts-node src/index.ts
npm install --save-dev typescript@latest
npm run prepare
Manual Setup
If you want to install and configure @nestia/core
manually, read Guide Documents - Setup.
Features
import { Controller } from "@nestjs/common";
import { TypedBody, TypedRoute } from "@nestia/core";
import { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
@Controller("bbs/articles")
export class BbsArticlesController {
@TypedRoute.Put(":id")
public async store(
@TypedParam("section", "string") section: string,
@TypedParam("id", "uuid") id: string,
@TypedBody() input: IBbsArticle.IUpdate
): Promise<IBbsArticle.IContent>;
}
About detailed features, read Guide Documents
- Decorators
- Enhancements
- Advanced Usage