@nestia/core 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +90 -81
  2. package/package.json +5 -1
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Nestia Core
2
2
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/nestia/blob/master/LICENSE)
3
3
  [![npm version](https://img.shields.io/npm/v/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)
4
- [![Downloads](https://img.shields.io/npm/dm/typia.svg)](https://www.npmjs.com/package/@nestia/core)
4
+ [![Downloads](https://img.shields.io/npm/dm/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)
5
5
  [![Build Status](https://github.com/samchon/typia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
6
6
  [![Guide Documents](https://img.shields.io/badge/wiki-documentation-forestgreen)](https://github.com/samchon/nestia/wiki)
7
7
 
@@ -9,13 +9,14 @@
9
9
  npx nestia setup
10
10
  ```
11
11
 
12
- Super-easy and super-fast validator decorators for NestJS.
12
+ super-fast validation decorators for NestJS.
13
13
 
14
- `@nestia/core` is a transformer library of NestJS, supporing super-easy and super-fast validation decorators, by using [typia](https://github.com/samchon/typia). Comparing validation speed with `class-validator`, `@nestia/core` is maximum **15,000x times faster** and it even supports every TypeScript types.
14
+ `@nestia/core` is a transformer library of NestJS, supporting super-fast 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 even much safer.
15
15
 
16
- Furthermore, `@nestia/core` can use pure interface typed DTO with **only one line**. Therefore, it does not require any extra dedication like defining JSON schema (`@nestjs/swagger`) or using class definition with decorator function calls (`class-validator`). Just enjoy **super-easy** and **super-fast** through with pure TypeScript types.
16
+ Furthermore, `@nestia/core` can use pure interface typed DTO with **only one line**.
17
+
18
+ Therefore, it does not require any extra dedication like defining JSON schema (`@nestjs/swagger`) or using class definition with decorator function calls (`class-validator`). Just enjoy the **superfast** decorator with pure TypeScript type.
17
19
 
18
- #### `BbsArticlesController.ts`
19
20
  ```typescript
20
21
  import { Controller } from "@nestjs/common";
21
22
  import { TypedBody, TypedRoute } from "@nestia/core";
@@ -25,92 +26,59 @@ import { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
25
26
  @Controller("bbs/articles")
26
27
  export class BbsArticlesController {
27
28
  /**
28
- * `TypedRoute.Post()`: safe `JSON.stringify()` with type validation.
29
- *
30
- * Furthermore, its 10x times faster than native `JSON.stringify()` function.
29
+ * Store a new content.
30
+ *
31
+ * @param inupt Content to store
32
+ * @returns Newly archived article
31
33
  */
32
- @TypedRoute.Post()
34
+ @TypedRoute.Post() // 10x faster and safer JSON.stringify()
33
35
  public async store(
34
- /**
35
- * Super-fast request body validator through `TypedBody()`.
36
- *
37
- * It also requires only one line.
38
- */
39
- @TypedBody() input: IBbsArticle.IStore
36
+ @TypedBody() input: IBbsArticle.IStore // supoer-fast validator
40
37
  ): Promise<IBbsArticle>;
41
38
  }
42
39
  ```
43
40
 
44
- #### `IBbsArticle.ts`
45
- ```typescript
46
- /**
47
- * You don't need any extra dedication like:
48
- *
49
- * - `@nestjs/swagger`: JSON schema definition
50
- * - `class-transformer`: class definition with decorator function class
51
- *
52
- * Just enjoy the pure interface type as DTO
53
- */
54
- export interface IBbsArticle {
55
- /**
56
- * @format uuid
57
- */
58
- id: string;
59
- writer: string;
60
- title: string;
61
- content: string;
62
- created_at: string;
63
- }
64
- export namespace IBbsArticle {
65
- export interface IStore {
66
- writer: string;
67
- title: string;
68
- content: string;
69
- }
70
- }
71
- ```
72
-
73
- #### `typia` vs. `class-validator`
74
- ![Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/is.svg)
75
-
76
- > Measured on [Intel i5-1135g7, Surface Pro 8](https://github.com/samchon/typia/tree/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz#is)
77
41
 
78
42
 
79
43
 
44
+ ## Setup
45
+ ### Boilerplate Project
46
+ ```bash
47
+ npx nestia start <directory>
48
+ ```
80
49
 
50
+ Just run above command, then boilerplate project would be constructed.
81
51
 
82
- ## Setup
83
52
  ### Setup Wizard
84
53
  ```bash
85
54
  # setup both @nestia/core and @nestia/sdk
86
55
  npx nestia setup
87
56
 
88
57
  # setup @nestia/core only
89
- npx nestia setup
58
+ npx @nestia/core setup
90
59
  ```
91
60
 
92
61
  When you run `npx nestia setup` command, all installation and configuration processes would be automatically done. If you want to setup `@nestia/core` only, run `npx @nestia/core setup` command instead.
93
62
 
94
- After the setup has been completed, you can compile your backend server code by using `ttsc` command. If you want to run your TypeScript file directly through `ts-node`, add `-C ttypescript` argument like below:
63
+ After the setup has been fully completed, you can compile your backend server code by using `ttsc` command. If you want to run your TypeScript file directly through `ts-node`, add `-C ttypescript` argument like below:
95
64
 
96
65
  ```bash
97
66
  npx ttsc
98
67
  npx ts-node -C ttypescript src/index.ts
99
68
  ```
100
69
 
101
- > In the automated setup process, you can specialize package manager like `yarn` instead of `npm` by adding `--module yarn` argument. You also can specialize transformation compiler by using [`--module ts-patch`](https://github.com/nonara/ts-patch) argument. Default compiler is [`ttypescrpit`](https://github.com/cevek/ttypescript).
102
- >
103
- > ```bash
104
- > npx nestia setup \
105
- > --compiler (ttypescript|ts-patch)
106
- > --module (npm|pnpm|yarn)
107
- >
108
- > npx nestia setup
109
- > npx nestia setup --module yarn
110
- > npx nestia setup --compiler ts-patch
111
- > ```
112
-
113
- ### NPM Packages
70
+ Also, you can specify package manager by `--manage` argument like below:
71
+
72
+ ```bash
73
+ npx @nestia/core setup --manager npm
74
+ npx @nestia/core setup --manager pnpm
75
+ npx @nestia/core setup --manager yarn
76
+ ```
77
+
78
+ ### Manual Setup
79
+ If you want to install and setup `@nestia/core` manually, read [Guide Documents - Setup](https://github.com/samchon/nestia/wiki/Setup).
80
+
81
+ <!-- ### NPM Packages
114
82
  If you want to install and configure manually, install `@nestia/core` module first.
115
83
 
116
84
  Also, you need additional devDependencies to compile the TypeScript code with transformation. Therefore, install those all libraries `typescript`, `ttypescript` and `ts-node`. Inform that, `ttypescript` is not mis-writing. Do not forget to install the `ttypescript`.
@@ -162,7 +130,7 @@ export function stringify<T>(input: T): string; // unsafe, but very fast
162
130
  export function assertStringify<T>(input: T): string; // assert + stringify
163
131
  export function isStringify<T>(input: T): string | null; // is + stringify
164
132
  export function validateStringify<T>(input: T): IValidation<T>; // validate +
165
- ```
133
+ ``` -->
166
134
 
167
135
 
168
136
 
@@ -177,31 +145,27 @@ import { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
177
145
  @Controller("bbs/articles")
178
146
  export class BbsArticlesController {
179
147
  /**
180
- * `TypedRoute.Post()`: safe `JSON.stringify()` with type validation.
181
- *
182
- * Furthermore, its 10x times faster than native `JSON.stringify()` function.
148
+ * Store a new content.
149
+ *
150
+ * @param inupt Content to store
151
+ * @returns Newly archived article
183
152
  */
184
- @TypedRoute.Post()
153
+ @TypedRoute.Post() // 10x faster and safer JSON.stringify()
185
154
  public async store(
186
- /**
187
- * Super-fast request body validator through `TypedBody()`.
188
- *
189
- * It also requires only one line.
190
- */
191
- @TypedBody() input: IBbsArticle.IStore
155
+ @TypedBody() input: IBbsArticle.IStore // supoer-fast validator
192
156
  ): Promise<IBbsArticle>;
193
157
  }
194
158
  ```
195
159
 
196
160
  ### TypedBody
197
- `TypedBody` is a decorator function for `application/json` typed request body.
161
+ `TypedBody()` is a decorator function of `application/json` typed request body.
198
162
 
199
- Also, it supports super-fast validation pipe, which is 15,000x times faster then ordinary `nest.Body()` decorator using `class-validator`.
163
+ Also, it supports super-fast validation pipe using, which is maximum 15,000x times faster then ordinary `nest.Body()` decorator using `class-validator`.
200
164
 
201
165
  ### TypedRoute
202
- `TypedRoute` is a decorator function for `application/json` typed reponse body.
166
+ `TypedRoute()` is a decorator function of `application/json` typed reponse body.
203
167
 
204
- Also, it supports safe and fast JSON stringify pipe, which is maximum 10x times faster than native `JSON.stringify()` function and it is even type safe.
168
+ 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.
205
169
 
206
170
  ### Encryption
207
171
  `@nestia/core` supports special decorator functions `EncryptedBody` and `EncryptedRout`. They're almost same with [TypedBody](#typedbody) and [TypedRoute](#typedroute), but there's only one thing different - it encrypts JSON data through AES-128/256 algorithm.
@@ -211,6 +175,49 @@ Also, it supports safe and fast JSON stringify pipe, which is maximum 10x times
211
175
  - PKCS #5 Padding
212
176
  - Base64 Encoding
213
177
 
178
+ ### Comment Tags
179
+ You can enhance DTO type validation by writing comment tags.
180
+
181
+ If you want to know about it detaily, visit [Guide Documents of typia](https://github.com/samchon/typia/wiki/Runtime-Validators#comment-tags).
182
+
183
+ ```typescript
184
+ export interface IBbsArticle {
185
+ /**
186
+ * @format uuid
187
+ */
188
+ id: string;
189
+
190
+ writer: IBbsArticle.IWriter;
191
+
192
+ /**
193
+ * @minItems 1
194
+ */
195
+ contents: IBbsArticle.IContent[];
196
+ }
197
+ export namespace IBbsArticle {
198
+ export interface IWriter {
199
+ /**
200
+ * @minLength 3
201
+ */
202
+ name: string;
203
+
204
+ /**
205
+ * @format email
206
+ */
207
+ email: string;
208
+
209
+ /**
210
+ * @pattern ^0[0-9]{7,16}
211
+ */
212
+ mobile: string;
213
+
214
+ /**
215
+ * @minimum 18
216
+ */
217
+ age: number;
218
+ }
219
+ }
220
+ ```
214
221
 
215
222
 
216
223
 
@@ -222,9 +229,11 @@ npx nestia swagger
222
229
  npx nestia sdk
223
230
  ```
224
231
 
225
- When you adapt this `@nestia/core`, you can't use `@nestjs/swagger` more. Instead, I support `@nestia/sdk`, which is much more stable and powerful then before. Through this `@nestia/sdk` module, you can generate `swagger.json` and even generating SDK library is possible.
232
+ Automatic *SDK* and *Swagger* generator for `@nestia/core`.
233
+
234
+ With `@nestia/core`, you can boost up validation speed maximum **15,000x times faster**. However, as `@nestjs/swagger` does not support `@nestia/core`, you can't generate swagger documents from `@nestjs/swagger` more.
226
235
 
227
- For reference, SDK (Software Development Kit) library means a library which can be utilized by TypeScript client developer conveniently. When you generate SDK library through `@nestia/sdk`, `@nestia/sdk` will analyze your backend server code and generate codes like below:
236
+ Instead, I provide you `@nestia/sdk` module, which can generate not only swagger documents, but also SDK (Software Development Kit) library.
228
237
 
229
238
  #### `BbsArticlesController.ts`
230
239
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/core",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Super-fast validation decorators of NestJS",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -60,6 +60,10 @@
60
60
  "rxjs": "*",
61
61
  "typia": "^3.4.7"
62
62
  },
63
+ "peerDependencies": {
64
+ "ttypescript": ">= 1.5.15",
65
+ "typescript": ">= 4.5.2"
66
+ },
63
67
  "files": [
64
68
  "README.md",
65
69
  "LICENSE",