From 3b49b858c8f8e343564caeb24876e4b87210a0fa Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Sun, 25 Dec 2022 04:19:01 +0900 Subject: [PATCH 01/12] docs(recipes/nestia): new library and new content --- content/recipes/nestia.md | 243 ++++++++++++++++++ src/app/homepage/menu/menu.component.ts | 1 + .../pages/recipes/nestia/nestia.component.ts | 10 + .../homepage/pages/recipes/recipes.module.ts | 6 + 4 files changed, 260 insertions(+) create mode 100644 content/recipes/nestia.md create mode 100644 src/app/homepage/pages/recipes/nestia/nestia.component.ts diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md new file mode 100644 index 0000000000..5cbf0bd6b7 --- /dev/null +++ b/content/recipes/nestia.md @@ -0,0 +1,243 @@ +### Nestia + +A set of helper libraries for NestJS, supporting the below features: + + - `@nestia/core` - 15,000x faster validation decorators using [typia](https://github.com/samchon/typia) + - `@nestia/sdk` - SDK and Swagger Documents generator for `@nestia/core` + - `nestia` - just CLI tool + +> info **info** `nestia` is a third party package and is not managed by the NestJS core team. Please, report any issues found with the library in the [appropriate repository](https://github.com/mikro-orm/nestjs). + + + + +#### Setup + +##### Boilerplate Project + +```bash +npx nestia start +``` + +Just run above command, then boilerplate project would be constructed. + +##### Setup Wizard + +```bash +npx nestia setup +``` + +When you want to use `nestia` in ordinary project, just type above command. + +All installation and configuration processes would be automatically done. + +Also, you can specify package manager or target `tsconfig.json` file like below: + +```bash +npx nestia setup --manager npm +npx nestia setup --manager pnpm +npx nestia setup --manager yarn + +npx nestia setup --project tsconfig.json +npx nestia setup --project tsconfig.test.json +``` + +After the setup, you can compile `@nestia/core` utilization code by using `ttsc` ([ttypescript](https://github.com/cevek/ttypescript)) command. If you want to run your TypeScript file directly through `ts-node`, add `-C ttypescript` argument like below: + +```bash +# COMPILE THROUGH TTYPESCRIPT +npx ttsc + +# RUN TS-NODE WITH TTYPESCRIPT +npx ts-node -C ttypescript src/index.ts +``` + +##### Manual Setup + +If you want to install and configure `nestia` manually, read [Guide Documents - Setup](https://github.com/samchon/nestia/wiki/Setup). + + + + + +#### `@nestia/core` + +Superfast validation decorators for NestJS. + + - 15,000x faster request body validation + - 10x 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 superfast validation decorators, by wrapping [typia](https://github.com/samchon/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. + +```typescript +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 { + /** + * Store a new content. + * + * @param inupt Content to store + * @returns Newly archived article + */ + @TypedRoute.Post() // 10x faster and safer JSON.stringify() + public async store( + @TypedBody() input: IBbsArticle.IStore // superfast validator + ): Promise; + // do not need DTO class definition, + // just fine with interface +} +``` + +##### TypedBody + +`TypedBody()` is a decorator function of `application/json` typed request body. + +Also, it supports superfast validation pipe, which is maximum **15,000x times faster** than `nest.Body()` function using `class-validator`. + +##### TypedRoute + +`TypedRoute` is a set of decorator functions for `application/json` typed response body. + +Also, it supports safe and fast JSON stringify function pipe, which is maximum 10x times faster than native `JSON.stringify()` function. Furthermore, it is **type safe** through validation. + + - `TypedRoute.Get()` + - `TypedRoute.Post()` + - `TypedRoute.Put()` + - `TypedRoute.Patch()` + - `TypedRoute.Delete()` + +##### Comment Tags + +You can enhance DTO type validation by writing comment tags. + +If you want to know more about it, read [Guide Documents of `typia`](https://github.com/samchon/typia/wiki/Runtime-Validators#comment-tags). + +```typescript +export interface IBbsArticle { + /** + * @format uuid + */ + id: string; + + writer: IBbsArticle.IWriter; + + /** + * @minItems 1 + */ + contents: IBbsArticle.IContent[]; +} +export namespace IBbsArticle { + export interface IWriter { + /** + * @minLength 3 + */ + name: string; + + /** + * @format email + */ + email: string; + + /** + * @pattern ^0[0-9]{7,16} + */ + mobile: string; + + /** + * @minimum 18 + */ + age: number; + } +} +``` + + + +#### `@nestia/sdk` + +Automatic *SDK* and *Swagger* generator for `@nestia/core`. + +##### Usage + +```bash +# BASIC COMMAND +npx nestia \ + --exclude \ + --out + +# EXAMPLES +npx nestia sdk "src/**/*.controller.ts" --out "src/api" +npx nestia swagger "src/controllers" --out "dist/swagger.json" +``` + +You can generate SDK (Software Development Kit) library or Swagger Documents from above commands. + +If you've configured `nestia.config.ts` file, you can generate them much easily like below. About the configuration file, read [Guide Documents - Configuration](https://github.com/samchon/nestia/wiki/Configuration) + +```bash +npx nestia sdk +npx nestia swagger +``` + +##### Demonstration + +When you run `npx nestia sdk` command, `@nestia/sdk` will generate below code. + +```typescript +import { Fetcher, IConnection } from "@nestia/fetcher"; +import { IBbsArticle } from "../../../structures/IBbsArticle"; + +/** + * Store a new content. + * + * @param input Content to store + * @returns Newly archived article + */ +export function store( + connection: api.IConnection, + input: IBbsArticle.IStore +): Promise { + return Fetcher.fetch( + connection, + store.ENCRYPTED, + store.METHOD, + store.path(), + input + ); +} +export namespace store { + export const METHOD = "POST" as const; + export function path(): string { + return "/bbs/articles"; + } +} +``` + +With the SDK library, client developers would get take advantages of TypeScript like below. + +If you want to learn how to distribute SDK library, visit and read [Guide Documents - Distribution](https://github.com/samchon/nestia/wiki/Distribution). + +```typescript +import api from "@bbs-api"; +import typia from "typia"; + +export async function test_bbs_article_store(connection: api.IConnection) { + const article: IBbsArticle = await api.functional.bbs.articles.store( + connection, + { + name: "John Doe", + title: "some title", + content: "some content", + } + ); + typia.assert(article); + console.log(article); +} +``` \ No newline at end of file diff --git a/src/app/homepage/menu/menu.component.ts b/src/app/homepage/menu/menu.component.ts index b37917abed..1df0d6a2c3 100644 --- a/src/app/homepage/menu/menu.component.ts +++ b/src/app/homepage/menu/menu.component.ts @@ -240,6 +240,7 @@ export class MenuComponent implements OnInit { { title: 'Prisma', path: '/recipes/prisma' }, { title: 'Serve static', path: '/recipes/serve-static' }, { title: 'Commander', path: '/recipes/nest-commander' }, + { title: `Nestia`, path: `/recipes/nestia` }, ], }, { diff --git a/src/app/homepage/pages/recipes/nestia/nestia.component.ts b/src/app/homepage/pages/recipes/nestia/nestia.component.ts new file mode 100644 index 0000000000..a33e084644 --- /dev/null +++ b/src/app/homepage/pages/recipes/nestia/nestia.component.ts @@ -0,0 +1,10 @@ + +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { BasePageComponent } from '../../page/page.component'; + +@Component({ + selector: 'app-nestia', + templateUrl: './nestia.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class NestiaComponent extends BasePageComponent {} diff --git a/src/app/homepage/pages/recipes/recipes.module.ts b/src/app/homepage/pages/recipes/recipes.module.ts index 6b4611fd60..27210ce1be 100644 --- a/src/app/homepage/pages/recipes/recipes.module.ts +++ b/src/app/homepage/pages/recipes/recipes.module.ts @@ -16,6 +16,7 @@ import { SqlTypeormComponent } from './sql-typeorm/sql-typeorm.component'; import { TerminusComponent } from './terminus/terminus.component'; import { RouterModuleComponent } from './router-module/router-module.component'; import { NestCommanderComponent } from './nest-commander/nest-commander.component'; +import { NestiaComponent } from './nestia/nestia.component'; const routes: Routes = [ { @@ -100,6 +101,11 @@ const routes: Routes = [ component: ReplComponent, data: { title: 'REPL' }, }, + { + path: 'nestia', + component: NestiaComponent, + data: { title: "Nestia" } + } ]; @NgModule({ From 90f77080b6bb5c0beb328693693a8c7dd2a6865a Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Sun, 25 Dec 2022 04:26:52 +0900 Subject: [PATCH 02/12] docs(recipes/nestia): error link fix --- content/recipes/nestia.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 5cbf0bd6b7..c81f2308b0 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -6,7 +6,7 @@ A set of helper libraries for NestJS, supporting the below features: - `@nestia/sdk` - SDK and Swagger Documents generator for `@nestia/core` - `nestia` - just CLI tool -> info **info** `nestia` is a third party package and is not managed by the NestJS core team. Please, report any issues found with the library in the [appropriate repository](https://github.com/mikro-orm/nestjs). +> info **info** `nestia` is a third party package and is not managed by the NestJS core team. Please, report any issues found with the library in the [appropriate repository](https://github.com/samchon/nestia). From f51980ee3e914b95f0269c49b9448a919891d18d Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:06:32 +0900 Subject: [PATCH 03/12] Update content/recipes/nestia.md Co-authored-by: Jay McDoniel --- content/recipes/nestia.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index c81f2308b0..0cc0c3b807 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -7,10 +7,6 @@ A set of helper libraries for NestJS, supporting the below features: - `nestia` - just CLI tool > info **info** `nestia` is a third party package and is not managed by the NestJS core team. Please, report any issues found with the library in the [appropriate repository](https://github.com/samchon/nestia). - - - - #### Setup ##### Boilerplate Project From ea53abe8fd3d7d7a0cf94a3f277035d907aea3ff Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:06:39 +0900 Subject: [PATCH 04/12] Update content/recipes/nestia.md Co-authored-by: Jay McDoniel --- content/recipes/nestia.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 0cc0c3b807..ea4839d7c2 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -51,11 +51,6 @@ npx ts-node -C ttypescript src/index.ts ##### Manual Setup If you want to install and configure `nestia` manually, read [Guide Documents - Setup](https://github.com/samchon/nestia/wiki/Setup). - - - - - #### `@nestia/core` Superfast validation decorators for NestJS. From 95f85fd69c916b013b371ebb04311e987a3b72e6 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:06:58 +0900 Subject: [PATCH 05/12] Update content/recipes/nestia.md Co-authored-by: Jay McDoniel --- content/recipes/nestia.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index ea4839d7c2..7c6c0c35eb 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -148,9 +148,6 @@ export namespace IBbsArticle { } } ``` - - - #### `@nestia/sdk` Automatic *SDK* and *Swagger* generator for `@nestia/core`. From ef89e6d4fcfe12e94e6be4176092c8d91b44e090 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:07:49 +0900 Subject: [PATCH 06/12] Update content/recipes/nestia.md Co-authored-by: Jay McDoniel --- content/recipes/nestia.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 7c6c0c35eb..8285b6694b 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -55,7 +55,7 @@ If you want to install and configure `nestia` manually, read [Guide Documents - Superfast validation decorators for NestJS. - - 15,000x faster request body validation + - 15,000x faster request body validation than class-validator - 10x faster JSON response, even type safe - Do not need DTO class definition, just fine with interface From 4e487438ec05509c1a842ec3437d465c8bb93ebc Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:08:10 +0900 Subject: [PATCH 07/12] Update content/recipes/nestia.md Co-authored-by: Jay McDoniel --- content/recipes/nestia.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 8285b6694b..c72e271c9e 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -56,7 +56,7 @@ If you want to install and configure `nestia` manually, read [Guide Documents - Superfast validation decorators for NestJS. - 15,000x faster request body validation than class-validator - - 10x faster JSON response, even type safe + - 10x faster JSON response than `JSON.stringify()` and it's type safe - Do not need DTO class definition, just fine with interface `@nestia/core` is a transformer library of NestJS, supporting superfast validation decorators, by wrapping [typia](https://github.com/samchon/typia). Comparing validation speed with `class-validator`, `typia` is maximum **15,000x times faster**, and it is even much safer. From 8d6a930eaaa2101b738c3dae30847978dcba6043 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:29:26 +0900 Subject: [PATCH 08/12] docs(recipes/nestia): add reason why using `ttsc` --- content/recipes/nestia.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index c72e271c9e..62a3d68d77 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -38,7 +38,7 @@ npx nestia setup --project tsconfig.json npx nestia setup --project tsconfig.test.json ``` -After the setup, you can compile `@nestia/core` utilization code by using `ttsc` ([ttypescript](https://github.com/cevek/ttypescript)) command. If you want to run your TypeScript file directly through `ts-node`, add `-C ttypescript` argument like below: +After the setup, you only can compile `@nestia/core` utilization code by using `ttsc` ([ttypescript](https://github.com/cevek/ttypescript)) command, because `@nestia/core` is a type of tranformer library generating validation code by analyzing DTO types. If you want to run your TypeScript file directly through `ts-node` without compilation, add `-C ttypescript` argument like below: ```bash # COMPILE THROUGH TTYPESCRIPT @@ -208,15 +208,18 @@ export namespace store { } ``` -With the SDK library, client developers would get take advantages of TypeScript like below. +With the SDK library, client developers can get benefits of TypeScript like below. If you want to learn how to distribute SDK library, visit and read [Guide Documents - Distribution](https://github.com/samchon/nestia/wiki/Distribution). ```typescript import api from "@bbs-api"; +import { IBbsArticle } from "@bbs-api/lib/structures/IBbsArticle"; import typia from "typia"; -export async function test_bbs_article_store(connection: api.IConnection) { +export async function some_test_code_by_client( + connection: api.IConnection +): Promise { const article: IBbsArticle = await api.functional.bbs.articles.store( connection, { @@ -227,5 +230,6 @@ export async function test_bbs_article_store(connection: api.IConnection) { ); typia.assert(article); console.log(article); + return article; } ``` \ No newline at end of file From c0d2ef3037d5d31632eec6c3553cb91a6ae35423 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:43:41 +0900 Subject: [PATCH 09/12] docs(recipes/nestia): remove last client example code --- content/recipes/nestia.md | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 62a3d68d77..61a26ee444 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -176,7 +176,7 @@ npx nestia swagger ##### Demonstration -When you run `npx nestia sdk` command, `@nestia/sdk` will generate below code. +When you run `npx nestia sdk` command, `@nestia/sdk` will generate an SDK library interacting with your backend server, composed with some codes like below. If you want to learn how to distribute and utilize the SDK library, visit and read [Guide Documents - Distribution](https://github.com/samchon/nestia/wiki/Distribution). ```typescript import { Fetcher, IConnection } from "@nestia/fetcher"; @@ -207,29 +207,3 @@ export namespace store { } } ``` - -With the SDK library, client developers can get benefits of TypeScript like below. - -If you want to learn how to distribute SDK library, visit and read [Guide Documents - Distribution](https://github.com/samchon/nestia/wiki/Distribution). - -```typescript -import api from "@bbs-api"; -import { IBbsArticle } from "@bbs-api/lib/structures/IBbsArticle"; -import typia from "typia"; - -export async function some_test_code_by_client( - connection: api.IConnection -): Promise { - const article: IBbsArticle = await api.functional.bbs.articles.store( - connection, - { - name: "John Doe", - title: "some title", - content: "some content", - } - ); - typia.assert(article); - console.log(article); - return article; -} -``` \ No newline at end of file From 9a8104fa7de8ba740daabd64845d8d71688eab90 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 27 Dec 2022 13:59:49 +0900 Subject: [PATCH 10/12] Update nestia.md --- content/recipes/nestia.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 61a26ee444..2b98499465 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -7,6 +7,7 @@ A set of helper libraries for NestJS, supporting the below features: - `nestia` - just CLI tool > info **info** `nestia` is a third party package and is not managed by the NestJS core team. Please, report any issues found with the library in the [appropriate repository](https://github.com/samchon/nestia). + #### Setup ##### Boilerplate Project From 69755bb02330f32a0b14934c9677c1211013211d Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Wed, 1 Feb 2023 13:00:47 +0900 Subject: [PATCH 11/12] docs(recipes/nestia): change guide documents link --- content/recipes/nestia.md | 105 ++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 34 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index 2b98499465..b66206bda5 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -2,9 +2,12 @@ A set of helper libraries for NestJS, supporting the below features: - - `@nestia/core` - 15,000x faster validation decorators using [typia](https://github.com/samchon/typia) - - `@nestia/sdk` - SDK and Swagger Documents generator for `@nestia/core` - - `nestia` - just CLI tool + - `@nestia/core`: **15,000x times faster** validation decorators + - `@nestia/sdk`: evolved **SDK** and **Swagger** generators + - SDK (Software Development Kit) + - interaction library for client developers + - almost same with `tRPC` + - `nestia`: just CLI (command line interface) tool > info **info** `nestia` is a third party package and is not managed by the NestJS core team. Please, report any issues found with the library in the [appropriate repository](https://github.com/samchon/nestia). @@ -51,7 +54,7 @@ npx ts-node -C ttypescript src/index.ts ##### Manual Setup -If you want to install and configure `nestia` manually, read [Guide Documents - Setup](https://github.com/samchon/nestia/wiki/Setup). +If you want to install and configure `nestia` manually, read [Guide Documents / Setup](https://github.com/samchon/nestia/wiki/Setup). #### `@nestia/core` Superfast validation decorators for NestJS. @@ -66,22 +69,30 @@ Furthermore, `@nestia/core` can use pure interface typed DTO with **only one lin ```typescript import { Controller } from "@nestjs/common"; -import { TypedBody, TypedRoute } from "@nestia/core"; +import { TypedBody, TypedParam, TypedRoute } from "@nestia/core"; import type { IBbsArticle } from "@bbs-api/structures/IBbsArticle"; -@Controller("bbs/articles") +@Controller("bbs/articles/:section") export class BbsArticlesController { - /** - * Store a new content. - * - * @param inupt Content to store - * @returns Newly archived article + /** + * Update article. + * + * When updating, this BBS system does not overwrite the content, but accumulate it. + * Therefore, whenever an article being updated, length of {@link IBbsArticle.contents} + * would be increased and accumulated. + * + * @param section Target section + * @param id Target articles id + * @param input Content to update + * @returns Newly created content info */ - @TypedRoute.Post() // 10x faster and safer JSON.stringify() - public async store( - @TypedBody() input: IBbsArticle.IStore // superfast validator - ): Promise; + @TypedRoute.Post(":id") // 10x faster and safer JSON.stringify() + public async update( + @TypedParam("section", "string") section: string, + @TypedParam("id", "uuid") id: strig, // type-safe parameter + @TypedBody() input: IBbsArticle.IUpdate // super-fast validator + ): Promise; // do not need DTO class definition, // just fine with interface } @@ -109,7 +120,7 @@ Also, it supports safe and fast JSON stringify function pipe, which is maximum 1 You can enhance DTO type validation by writing comment tags. -If you want to know more about it, read [Guide Documents of `typia`](https://github.com/samchon/typia/wiki/Runtime-Validators#comment-tags). +If you want to know more about it, read [Guide Documents / Core Library / Comment Tags](https://github.com/samchon/nestia/wiki/Core-Library#comment-tags). ```typescript export interface IBbsArticle { @@ -147,6 +158,8 @@ export namespace IBbsArticle { */ age: number; } + export interface IContent { ... } + export interface IUpdate { ... } } ``` #### `@nestia/sdk` @@ -168,7 +181,7 @@ npx nestia swagger "src/controllers" --out "dist/swagger.json" You can generate SDK (Software Development Kit) library or Swagger Documents from above commands. -If you've configured `nestia.config.ts` file, you can generate them much easily like below. About the configuration file, read [Guide Documents - Configuration](https://github.com/samchon/nestia/wiki/Configuration) +If you've configured `nestia.config.ts` file, you can generate them much easily like below. About the configuration file, read [Guide Documents / SDK Generator / Configuration](https://github.com/samchon/nestia/wiki/SDK-Generator#configuration) ```bash npx nestia sdk @@ -177,34 +190,58 @@ npx nestia swagger ##### Demonstration -When you run `npx nestia sdk` command, `@nestia/sdk` will generate an SDK library interacting with your backend server, composed with some codes like below. If you want to learn how to distribute and utilize the SDK library, visit and read [Guide Documents - Distribution](https://github.com/samchon/nestia/wiki/Distribution). +When you run `npx nestia sdk` command, `@nestia/sdk` will generate an SDK library interacting with your backend server, composed with some codes like below. If you want to learn how to distribute and utilize the SDK library, visit and read [Guide Documents / SDK Generator / Distribution](https://github.com/samchon/nestia/wiki/SDK-Generator#distribution). ```typescript -import { Fetcher, IConnection } from "@nestia/fetcher"; -import { IBbsArticle } from "../../../structures/IBbsArticle"; +import { Fetcher } from "@nestia/fetcher"; +import type { IConnection } from "@nestia/fetcher"; + +import type { IBbsArticle } from "../../../structures/IBbsArticle"; /** - * Store a new content. + * Update article. + * + * When updating, this BBS system does not overwrite the content, but accumulate it. + * Therefore, whenever an article being updated, length of {@link IBbsArticle.contents} + * would be increased and accumulated. + * + * @param connection connection Information of the remote HTTP(s) server with headers (+encryption password) + * @param section Target section + * @param id Target articles id + * @param input Content to update + * @returns Newly created content info * - * @param input Content to store - * @returns Newly archived article + * @controller BbsArticlesController.update() + * @path PUT /bbs/articles/:section/:id + * @nestia Generated by Nestia - https://github.com/samchon/nestia */ -export function store( - connection: api.IConnection, - input: IBbsArticle.IStore -): Promise { +export function update( + connection: IConnection, + section: string, + id: string, + input: IBbsArticle.IUpdate +): Promise { return Fetcher.fetch( connection, - store.ENCRYPTED, - store.METHOD, - store.path(), + update.ENCRYPTED, + update.METHOD, + update.path(section, id), input ); } -export namespace store { - export const METHOD = "POST" as const; - export function path(): string { - return "/bbs/articles"; +export namespace update { + export type Input = IBbsArticle.IUpdate; + export type Output = IBbsArticle.IContent; + + export const METHOD = "PUT" as const; + export const PATH: string = "/bbs/articles/:section/:id"; + export const ENCRYPTED: Fetcher.IEncrypted = { + request: false, + response: false, + }; + + export function path(section: string, id: string): string { + return `/bbs/articles/${encodeURIComponent(section)}/${encodeURIComponent(id)}`; } } ``` From 184f61b8c0fa4bc8cffdf8f9c8d5c26308c17bfd Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 10 Mar 2023 13:14:31 +0900 Subject: [PATCH 12/12] Revise nestia content by its updates --- content/recipes/nestia.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/content/recipes/nestia.md b/content/recipes/nestia.md index b66206bda5..fe9e3d5d1d 100644 --- a/content/recipes/nestia.md +++ b/content/recipes/nestia.md @@ -27,40 +27,42 @@ Just run above command, then boilerplate project would be constructed. npx nestia setup ``` -When you want to use `nestia` in ordinary project, just type above command. +Just type `npx nestia setup`, that's all. -All installation and configuration processes would be automatically done. - -Also, you can specify package manager or target `tsconfig.json` file like below: +If you've installed [ttypescript](https://github.com/cevek/ttypescript) during setup, you should compile `@nestia/core` utilization code through `ttsc` command, instead of `tsc`. ```bash -npx nestia setup --manager npm -npx nestia setup --manager pnpm -npx nestia setup --manager yarn +# COMPILE THROUGH TTYPESCRIPT +npx ttsc -npx nestia setup --project tsconfig.json -npx nestia setup --project tsconfig.test.json +# RUN TS-NODE WITH TTYPESCRIPT +npx ts-node -C ttypescript src/index.ts ``` -After the setup, you only can compile `@nestia/core` utilization code by using `ttsc` ([ttypescript](https://github.com/cevek/ttypescript)) command, because `@nestia/core` is a type of tranformer library generating validation code by analyzing DTO types. If you want to run your TypeScript file directly through `ts-node` without compilation, add `-C ttypescript` argument like below: +Otherwise, you've chosen [ts-patch](https://github.com/nonara/ts-patch), you can use original `tsc` command. However, [ts-patch](https://github.com/nonara/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](https://github.com/nonara/ts-patch). ```bash -# COMPILE THROUGH TTYPESCRIPT -npx ttsc +# USE ORIGINAL TSC COMMAND +tsc +npx ts-node src/index.ts -# RUN TS-NODE WITH TTYPESCRIPT -npx ts-node -C ttypescript src/index.ts +# WHENVER UPDATE +npm install --save-dev typescript@latest +npm run prepare ``` ##### Manual Setup If you want to install and configure `nestia` manually, read [Guide Documents / Setup](https://github.com/samchon/nestia/wiki/Setup). + #### `@nestia/core` Superfast validation decorators for NestJS. - - 15,000x faster request body validation than class-validator - - 10x faster JSON response than `JSON.stringify()` and it's type safe + - 15,000x faster request body validation than `class-validator` + - 50x faster JSON stringify than `class-transformer` - Do not need DTO class definition, just fine with interface `@nestia/core` is a transformer library of NestJS, supporting superfast validation decorators, by wrapping [typia](https://github.com/samchon/typia). Comparing validation speed with `class-validator`, `typia` is maximum **15,000x times faster**, and it is even much safer. @@ -87,7 +89,7 @@ export class BbsArticlesController { * @param input Content to update * @returns Newly created content info */ - @TypedRoute.Post(":id") // 10x faster and safer JSON.stringify() + @TypedRoute.Post(":id") // 50x faster and safer JSON.stringify() public async update( @TypedParam("section", "string") section: string, @TypedParam("id", "uuid") id: strig, // type-safe parameter